Commit d67cfb3c authored by LNJ's avatar LNJ 💬

Fix some clazy warnings

parent a17f832b
......@@ -29,12 +29,12 @@
*/
#include "AvatarFileStorage.h"
#include <QDir>
#include <QUrl>
#include <QStandardPaths>
// Qt
#include <QCryptographicHash>
#include <QDebug>
#include <QDir>
#include <QStandardPaths>
#include <QUrl>
AvatarFileStorage::AvatarFileStorage(QObject *parent) : QObject(parent)
{
......@@ -64,11 +64,9 @@ AvatarFileStorage::AvatarFileStorage(QObject *parent) : QObject(parent)
while (!line.isNull()) {
// get hash and jid from line (seperated by a blank)
QStringList list = line.split(' ', QString::SkipEmptyParts);
QString hash = list.at(0);
QString jid = list.at(1);
// set the hash for the jid
jidAvatarMap[jid] = hash;
jidAvatarMap[list.at(1)] = list.at(0);
// read the next line
line = stream.readLine();
......@@ -108,7 +106,7 @@ AvatarFileStorage::AddAvatarResult AvatarFileStorage::addAvatar(const QString &j
// write the avatar to disk:
// get the writable cache location for writing
QFile file(QStandardPaths::writableLocation(QStandardPaths::CacheLocation) +
QDir::separator() + QString("avatars") + QDir::separator() + result.hash);
QDir::separator() + QString("avatars") + QDir::separator() + result.hash);
if (!file.open(QIODevice::WriteOnly))
return result;
......@@ -131,14 +129,13 @@ void AvatarFileStorage::clearAvatar(QString &jid)
oldHash = jidAvatarMap[jid];
// if user had no avatar before, just return
if (oldHash.isEmpty()) {
if (oldHash.isEmpty())
return;
} else {
jidAvatarMap.remove(jid);
saveAvatarsFile();
cleanUp(oldHash);
emit avatarIdsChanged();
}
jidAvatarMap.remove(jid);
saveAvatarsFile();
cleanUp(oldHash);
emit avatarIdsChanged();
}
void AvatarFileStorage::cleanUp(QString &oldHash)
......@@ -147,12 +144,12 @@ void AvatarFileStorage::cleanUp(QString &oldHash)
return;
// check if the same avatar is still used by another account
if (jidAvatarMap.values().contains(oldHash))
if (std::find(jidAvatarMap.cbegin(), jidAvatarMap.cend(), oldHash) != jidAvatarMap.cend())
return;
// delete the old avatar locally
QString path = QStandardPaths::writableLocation(QStandardPaths::CacheLocation) +
QDir::separator() + QString("avatars");
QDir::separator() + QString("avatars");
QDir dir(path);
if (dir.exists(oldHash))
dir.remove(oldHash);
......@@ -194,7 +191,8 @@ void AvatarFileStorage::saveAvatarsFile()
return;
QTextStream out(&file);
for (const auto jid : jidAvatarMap.keys())
const QStringList jidAvatarKeys = jidAvatarMap.keys();
for (const auto &jid : jidAvatarKeys)
/* < HASH > < JID > */
out << jidAvatarMap[jid] << " " << jid << "\n";
}
......@@ -31,8 +31,8 @@
#include "ClientWorker.h"
// Qt
#include <QDebug>
#include <QSettings>
#include <QGuiApplication>
#include <QSettings>
#include <QSysInfo>
// QXmpp
#include <QXmppClient.h>
......@@ -40,15 +40,15 @@
#include <QXmppPresence.h>
#include <QXmppVersionManager.h>
// Kaidan
#include "DiscoveryManager.h"
#include "DownloadManager.h"
#include "Kaidan.h"
#include "LogHandler.h"
#include "MessageHandler.h"
#include "RegistrationManager.h"
#include "RosterManager.h"
#include "MessageHandler.h"
#include "DiscoveryManager.h"
#include "VCardManager.h"
#include "UploadManager.h"
#include "DownloadManager.h"
#include "VCardManager.h"
ClientWorker::ClientWorker(Caches *caches, Kaidan *kaidan, bool enableLogging, QGuiApplication *app,
QObject* parent)
......@@ -182,10 +182,11 @@ void ClientWorker::onConnectionError(QXmppClient::Error error)
QString ClientWorker::generateRandomString(unsigned int length) const
{
const QString resourceChars(KAIDAN_RESOURCE_RANDOM_CHARS);
QString randomString;
for (unsigned int i = 0; i < length; ++i)
randomString.append(KAIDAN_RESOURCE_RANDOM_CHARS.at(
qrand() % KAIDAN_RESOURCE_RANDOM_CHARS.length()));
randomString.append(resourceChars.at(qrand() % resourceChars.length()));
return randomString;
}
......
......@@ -33,19 +33,19 @@
// Qt
#include <QObject>
#include <QTimer>
#include <QSettings>
#include <QTimer>
class QGuiApplication;
// QXmpp
#include <QXmppClient.h>
// Kaidan
#include "Globals.h"
#include "Enums.h"
#include "AvatarFileStorage.h"
#include "Database.h"
#include "Enums.h"
#include "Globals.h"
#include "MessageModel.h"
#include "RosterModel.h"
#include "AvatarFileStorage.h"
#include "PresenceCache.h"
#include "RosterModel.h"
#include "TransferCache.h"
class LogHandler;
class Kaidan;
......@@ -128,7 +128,7 @@ public slots:
*
* @param creds The new credentials for the next connect
*/
void setCredentials(Credentials creds)
void setCredentials(ClientWorker::Credentials creds)
{
this->creds = creds;
}
......@@ -142,11 +142,11 @@ signals:
// emitted by 'Kaidan' to us:
void connectRequested();
void disconnectRequested();
void credentialsUpdated(Credentials creds);
void credentialsUpdated(ClientWorker::Credentials creds);
// emitted by us:
// connection state is directly connected (client -> kaidan) without this step
void disconnReasonChanged(DisconnectionReason reason);
void disconnReasonChanged(Enums::DisconnectionReason reason);
private slots:
/**
......
......@@ -318,8 +318,10 @@ void Database::convertDatabaseToV5()
void Database::convertDatabaseToV6()
{
QSqlQuery query(m_database);
for (QString column : {"'mediaSize' INTEGER", "'mediaContentType' TEXT",
"'mediaLastModified' INTEGER", "'mediaLocation' TEXT"}) {
for (const QString &column : {"'mediaSize' INTEGER",
"'mediaContentType' TEXT",
"'mediaLastModified' INTEGER",
"'mediaLocation' TEXT"}) {
Utils::execQuery(query, QString("ALTER TABLE 'Messages' ADD ").append(column));
}
}
......
......@@ -47,7 +47,7 @@ DiscoveryManager::DiscoveryManager(QXmppClient *client, QObject *parent)
#else
// Plasma Mobile packages won't differ from desktop builds, so we need to check the mobile
// variable on runtime.
if (!qgetenv("QT_QUICK_CONTROLS_MOBILE").isEmpty())
if (!qEnvironmentVariableIsEmpty("QT_QUICK_CONTROLS_MOBILE"))
manager->setClientType("phone");
else
manager->setClientType("pc");
......@@ -79,7 +79,8 @@ void DiscoveryManager::handleInfo(const QXmppDiscoveryIq&)
void DiscoveryManager::handleItems(const QXmppDiscoveryIq &iq)
{
// request info from all items
for (const QXmppDiscoveryIq::Item &item : iq.items()) {
const QList<QXmppDiscoveryIq::Item> items = iq.items();
for (const QXmppDiscoveryIq::Item &item : items) {
if (item.jid() == client->configuration().domain())
continue;
manager->requestInfo(item.jid());
......
......@@ -30,18 +30,18 @@
// Kaidan
#include "DownloadManager.h"
#include "Globals.h"
#include "Kaidan.h"
#include "TransferCache.h"
#include "MessageModel.h"
#include "Globals.h"
#include "TransferCache.h"
// C++
#include <utility>
// Qt
#include "QDir"
#include "QStandardPaths"
#include "QNetworkRequest"
#include "QNetworkReply"
#include "QNetworkAccessManager"
#include <QDir>
#include <QNetworkAccessManager>
#include <QNetworkReply>
#include <QNetworkRequest>
#include <QStandardPaths>
DownloadManager::DownloadManager(Kaidan *kaidan, TransferCache *transferCache,
MessageModel *model, QObject *parent)
......@@ -69,7 +69,7 @@ DownloadManager::~DownloadManager()
void DownloadManager::startDownload(const QString &msgId, const QString &url)
{
// don't download the same file twice and in parallel
if (downloads.keys().contains(msgId)) {
if (downloads.contains(msgId)) {
qWarning() << "Tried to download a file that is currently being "
"downloaded.";
return;
......
......@@ -31,8 +31,6 @@
#ifndef GLOBALS_H
#define GLOBALS_H
#include <QString>
// Application information
#define APPLICATION_DESCRIPTION "A simple, user-friendly Jabber/XMPP client"
......@@ -41,8 +39,8 @@
#define KAIDAN_SETTINGS_AUTH_RESOURCE "auth/resource"
#define KAIDAN_SETTINGS_AUTH_PASSWD "auth/password"
const QString KAIDAN_RESOURCE_RANDOM_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnop"
"qrstuvwxyz0123456789";
#define KAIDAN_RESOURCE_RANDOM_CHARS \
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
// XML namespaces
#define NS_SPOILERS "urn:xmpp:spoiler:0"
......
......@@ -32,13 +32,13 @@
#define KAIDAN_H
// Qt
#include <QColor>
#include <QObject>
#include <QString>
#include <QColor>
// Kaidan
#include "ClientWorker.h"
#include "Globals.h"
#include "Enums.h"
#include "Globals.h"
class QGuiApplication;
class Database;
......@@ -284,7 +284,7 @@ signals:
/**
* The upload progress of a file upload has changed
*/
void uploadProgressMade(QString msgId, unsigned long sent, unsigned long total);
void uploadProgressMade(QString msgId, quint64 sent, quint64 total);
/**
* An HTTP File Upload service was discovered
......@@ -362,12 +362,12 @@ public slots:
/**
* Sets the disconnection error/reason
*/
void setDisconnReason(DisconnectionReason reason);
void setDisconnReason(Enums::DisconnectionReason reason);
/**
* Receives messages from another instance of the application
*/
void receiveMessage(quint32, QByteArray msg)
void receiveMessage(quint32, const QByteArray &msg)
{
// currently we only send XMPP URIs
addOpenUri(msg);
......
......@@ -229,7 +229,7 @@ void MessageModel::addMessage(const Message &msg)
|| QXmppUtils::jidToBareJid(msg.to()) == m_chatPartner) {
// index where to add the new message
int i = 0;
for (const auto &message : m_messages) {
for (const auto &message : qAsConst(m_messages)) {
if (msg.stamp() > message.stamp()) {
insertMessage(i, msg);
return;
......
......@@ -135,7 +135,7 @@ void RegistrationManager::setClient(QXmppClient *client)
connect(disco, &QXmppDiscoveryManager::infoReceived,
this, &RegistrationManager::handleDiscoInfo);
connect(client, &QXmppClient::disconnected, [this] () {
connect(client, &QXmppClient::disconnected, this, [=] () {
setRegistrationSupported(false);
});
}
......
......@@ -57,7 +57,7 @@ RosterManager::RosterManager(Kaidan *kaidan,
this, &RosterManager::populateRoster);
connect(&manager, &QXmppRosterManager::itemAdded,
[this, vCardManager, model] (const QString &jid) {
this, [this, vCardManager, model] (const QString &jid) {
emit model->addItemRequested(RosterItem(manager.getRosterEntry(jid)));
vCardManager->fetchVCard(jid);
......@@ -111,7 +111,8 @@ void RosterManager::populateRoster()
qDebug() << "[client] [RosterManager] Populating roster";
// create a new list of contacts
QHash<QString, RosterItem> items;
for (const auto &jid : manager.getRosterBareJids()) {
const QStringList bareJids = manager.getRosterBareJids();
for (const auto &jid : bareJids) {
items[jid] = RosterItem(manager.getRosterEntry(jid));
if (avatarStorage->getHashOfJid(jid).isEmpty())
......
......@@ -140,7 +140,7 @@ void RosterModel::addItem(const RosterItem &item)
// index where to add the new contact
int i = 0;
for (const auto &itrItem : m_items) {
for (const auto &itrItem : qAsConst(m_items)) {
if (item.lastExchanged().toMSecsSinceEpoch() >= itrItem.lastExchanged().toMSecsSinceEpoch()) {
insertContact(i, item);
return;
......@@ -205,7 +205,7 @@ void RosterModel::updateItem(const QString &jid,
void RosterModel::replaceItems(const QHash<QString, RosterItem> &items)
{
QVector<RosterItem> newItems;
for (auto item : items.values()) {
for (auto item : items) {
// find old item
auto oldItem = std::find_if(
m_items.begin(),
......
......@@ -80,7 +80,8 @@ void Utils::execQuery(QSqlQuery &query,
{
prepareQuery(query, sql);
for (const auto &key : bindValues.keys())
const QStringList bindKeys = bindValues.keys();
for (const auto &key : bindKeys)
query.bindValue(key, bindValues.value(key));
execQuery(query);
......
......@@ -226,7 +226,7 @@ Q_DECL_EXPORT int main(int argc, char *argv[])
// send a possible link to the primary instance
if (!parser.positionalArguments().isEmpty())
app.sendMessage(parser.positionalArguments()[0].toUtf8());
app.sendMessage(parser.positionalArguments().first().toUtf8());
return 0;
}
#endif
......@@ -246,7 +246,7 @@ Q_DECL_EXPORT int main(int argc, char *argv[])
// open the XMPP-URI/link (if given)
if (!parser.positionalArguments().isEmpty())
kaidan.addOpenUri(parser.positionalArguments()[0].toUtf8());
kaidan.addOpenUri(parser.positionalArguments().first().toUtf8());
//
// QML-GUI
......@@ -258,11 +258,11 @@ Q_DECL_EXPORT int main(int argc, char *argv[])
QQmlApplicationEngine engine;
// QtQuickControls2 Style
if (qgetenv("QT_QUICK_CONTROLS_STYLE").isEmpty()) {
if (qEnvironmentVariableIsEmpty("QT_QUICK_CONTROLS_STYLE")) {
#ifdef Q_OS_WIN
QString defaultStyle = "Universal";
const QString defaultStyle = QStringLiteral("Universal");
#else
QString defaultStyle = "Material";
const QString defaultStyle = QStringLiteral("Material");
#endif
qDebug() << "QT_QUICK_CONTROLS_STYLE not set, setting to" << defaultStyle;
qputenv("QT_QUICK_CONTROLS_STYLE", defaultStyle.toLatin1());
......
......@@ -186,7 +186,8 @@ void QXmppHttpUpload::startUpload()
// other header fields
const QMap<QString, QString> &headers = m_slot.headerFields();
for (const QString &name : headers.keys())
const QStringList headerKeys = headers.keys();
for (const QString &name : headerKeys)
request.setRawHeader(name.toUtf8(), headers.value(name).toUtf8());
// open file
......@@ -204,12 +205,12 @@ void QXmppHttpUpload::startUpload()
this, &QXmppHttpUpload::uploadFailed);
// delete file object after upload
connect(m_putReply, &QNetworkReply::finished, [this, file] () {
connect(m_putReply, &QNetworkReply::finished, this, [=] () {
file->deleteLater();
m_started = false;
});
connect(m_putReply, QOverload<QNetworkReply::NetworkError>::of(&QNetworkReply::error),
[this, file] () {
this, [=] () {
file->deleteLater();
m_started = false;
});
......@@ -235,9 +236,8 @@ QXmppUploadManager::QXmppUploadManager()
QXmppUploadManager::~QXmppUploadManager()
{
for (QXmppHttpUpload *upload : m_uploads) {
for (QXmppHttpUpload *upload : qAsConst(m_uploads))
upload->abort();
}
}
/// Requests an upload slot and starts uploading the file
......@@ -299,7 +299,7 @@ void QXmppUploadManager::startNextUpload()
void QXmppUploadManager::handleSlot(const QXmppHttpUploadSlotIq &slot)
{
for (QXmppHttpUpload *upload : m_uploads) {
for (QXmppHttpUpload *upload : qAsConst(m_uploads)) {
if (upload->requestId() != slot.id())
continue;
......@@ -321,7 +321,7 @@ void QXmppUploadManager::handleSlot(const QXmppHttpUploadSlotIq &slot)
void QXmppUploadManager::handleRequestError(const QXmppHttpUploadRequestIq &request)
{
for (QXmppHttpUpload *upload : m_uploads) {
for (QXmppHttpUpload *upload : qAsConst(m_uploads)) {
if (upload->requestId() == request.id()) {
m_runningJobs--;
m_uploads.removeAll(upload);
......
......@@ -115,7 +115,8 @@ void QXmppUploadRequestManager::handleDiscoInfo(const QXmppDiscoveryIq &iq)
if (!iq.features().contains(ns_httpupload))
return;
for (const QXmppDiscoveryIq::Identity &identity : iq.identities()) {
const QList<QXmppDiscoveryIq::Identity> identities = iq.identities();
for (const auto &identity : identities) {
if (identity.category() == "store" && identity.type() == "file")
goto addService;
}
......@@ -127,7 +128,7 @@ addService:
// get size limit
bool isFormNsCorrect = false;
for (const QXmppDataForm::Field &field : iq.form().fields()) {
for (const QXmppDataForm::Field &field : qAsConst(iq.form().fields())) {
if (field.key() == "FORM_TYPE") {
isFormNsCorrect = field.value() == ns_httpupload;
} else if (isFormNsCorrect && field.key() == "max-file-size") {
......@@ -153,7 +154,7 @@ void QXmppUploadRequestManager::setClient(QXmppClient *client)
this, &QXmppUploadRequestManager::handleDiscoInfo);
// on client disconnect remove all upload services
connect(client, &QXmppClient::disconnected, [this] () {
connect(client, &QXmppClient::disconnected, this, [=] () {
m_uploadServices.clear();
emit serviceFoundChanged();
});
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment