diff options
| author | Pekka Vuorela <pvuorela@iki.fi> | 2025-09-24 12:25:00 +0300 |
|---|---|---|
| committer | Pekka Vuorela <pvuorela@iki.fi> | 2025-09-26 08:35:46 +0300 |
| commit | cfd671150df2a38c918a8c95ac8562834e78bd93 (patch) | |
| tree | bad32d98b59349256ec8707df60812250514a50d | |
| parent | e9e200dc699eda0f7393d755a5af580cb8544579 (diff) | |
Use qDeleteAll() more and some more cosmetic cleanups
For interesting detail ServiceActionQueue::clear() seemed badly done
and likely leaking memory.
Change-Id: Ibeb429bd46957dc1bac9e56f2bc8889a2e64b191
Reviewed-by: Damien Caliste <dcaliste@free.fr>
Reviewed-by: <matti.viljanen@kapsi.fi>
Reviewed-by: Pekka Vuorela <pvuorela@iki.fi>
| -rw-r--r-- | src/libraries/qmfclient/qmaildisconnected.cpp | 8 | ||||
| -rw-r--r-- | src/libraries/qmfclient/qmailstoresql_p.cpp | 89 | ||||
| -rw-r--r-- | src/libraries/qmfclient/support/qmailpluginmanager.cpp | 9 | ||||
| -rw-r--r-- | src/plugins/messageservices/imap/serviceactionqueue.cpp | 9 | ||||
| -rw-r--r-- | tests/tst_qmailcodec/tst_qmailcodec.cpp | 3 | ||||
| -rw-r--r-- | tests/tst_qmailmessage/tst_qmailmessage.cpp | 6 |
6 files changed, 57 insertions, 67 deletions
diff --git a/src/libraries/qmfclient/qmaildisconnected.cpp b/src/libraries/qmfclient/qmaildisconnected.cpp index 7efced7e..2ff4550f 100644 --- a/src/libraries/qmfclient/qmaildisconnected.cpp +++ b/src/libraries/qmfclient/qmaildisconnected.cpp @@ -378,9 +378,7 @@ void QMailDisconnected::moveToStandardFolder(const QMailMessageIdList& ids, QMai if (!messages.isEmpty()) { QMailStore::instance()->updateMessages(messages); - foreach (QMailMessageMetaData *messagePointer, messages) { - delete messagePointer; - } + qDeleteAll(messages); } } @@ -405,9 +403,7 @@ void QMailDisconnected::moveToFolder(const QMailMessageIdList& ids, const QMailF if (!messages.empty()) { QMailStore::instance()->updateMessages(messages); - foreach (QMailMessageMetaData *messagePointer, messages) { - delete messagePointer; - } + qDeleteAll(messages); } } diff --git a/src/libraries/qmfclient/qmailstoresql_p.cpp b/src/libraries/qmfclient/qmailstoresql_p.cpp index d32b7bab..4de29908 100644 --- a/src/libraries/qmfclient/qmailstoresql_p.cpp +++ b/src/libraries/qmfclient/qmailstoresql_p.cpp @@ -428,8 +428,8 @@ static QString messagePropertyName(QMailMessageKey::Property property) if (it != map.end()) return it.value(); - if ((property != QMailMessageKey::AncestorFolderIds) && - (property != QMailMessageKey::Custom)) + if ((property != QMailMessageKey::AncestorFolderIds) + && (property != QMailMessageKey::Custom)) qCWarning(lcMailStore) << "Unknown message property:" << property; return QString(); @@ -437,9 +437,9 @@ static QString messagePropertyName(QMailMessageKey::Property property) static bool caseInsensitiveProperty(QMailMessageKey::Property property) { - return ((property == QMailMessageKey::Sender) || - (property == QMailMessageKey::Recipients) || - (property == QMailMessageKey::Subject)); + return property == QMailMessageKey::Sender + || property == QMailMessageKey::Recipients + || property == QMailMessageKey::Subject; } typedef QMap<QMailAccountKey::Property, QString> AccountPropertyMap; @@ -476,8 +476,8 @@ static QString accountPropertyName(QMailAccountKey::Property property) static bool caseInsensitiveProperty(QMailAccountKey::Property property) { - return ((property == QMailAccountKey::Name) || - (property == QMailAccountKey::FromAddress)); + return property == QMailAccountKey::Name + || property == QMailAccountKey::FromAddress; } typedef QMap<QMailFolderKey::Property, QString> FolderPropertyMap; @@ -508,8 +508,8 @@ static QString folderPropertyName(QMailFolderKey::Property property) if (it != map.end()) return it.value(); - if ((property != QMailFolderKey::AncestorFolderIds) && - (property != QMailFolderKey::Custom)) + if ((property != QMailFolderKey::AncestorFolderIds) + && (property != QMailFolderKey::Custom)) qCWarning(lcMailStore) << "Unknown folder property:" << property; return QString(); @@ -517,8 +517,8 @@ static QString folderPropertyName(QMailFolderKey::Property property) static bool caseInsensitiveProperty(QMailFolderKey::Property property) { - return ((property == QMailFolderKey::Path) || - (property == QMailFolderKey::DisplayName)); + return property == QMailFolderKey::Path + || property == QMailFolderKey::DisplayName; } typedef QMap<QMailThreadKey::Property, QString> ThreadPropertyMap; @@ -558,8 +558,8 @@ static QString threadPropertyName(QMailThreadKey::Property property) static bool caseInsensitiveProperty(QMailThreadKey::Property property) { - return ((property == QMailThreadKey::Subject) || - (property == QMailThreadKey::Senders)); + return property == QMailThreadKey::Subject + || property == QMailThreadKey::Senders; } @@ -1929,8 +1929,10 @@ QString whereClauseItem<QMailMessageKey>(const QMailMessageKey &key, const QMail } bool bitwise((a.property == QMailMessageKey::Type) || (a.property == QMailMessageKey::Status)); - bool patternMatching((a.property == QMailMessageKey::Sender) || (a.property == QMailMessageKey::Recipients) || - (a.property == QMailMessageKey::ContentScheme) || (a.property == QMailMessageKey::ContentIdentifier)); + bool patternMatching((a.property == QMailMessageKey::Sender) + || (a.property == QMailMessageKey::Recipients) + || (a.property == QMailMessageKey::ContentScheme) + || (a.property == QMailMessageKey::ContentIdentifier)); bool noCase(caseInsensitiveProperty(a.property)); QString expression = columnExpression(columnName, a.op, a.valueList, patternMatching, bitwise, noCase); @@ -5921,8 +5923,8 @@ QMailStoreSql::AttemptResult QMailStoreSql::attemptAddMessage(QMailMessageMetaDa QMailThread thread(metaData->parentThreadId()); QString senders; const QMailAddress &newSender = metaData->from(); - const bool& newStartedMessage = thread.startedDate() > metaData->date(); - const bool& newLastMessage = thread.lastDate() < metaData->date(); + const bool newStartedMessage = thread.startedDate() > metaData->date(); + const bool newLastMessage = thread.lastDate() < metaData->date(); if (!thread.senders().contains(newSender)) { senders = QMailAddress::toStringList(QMailAddressList() << newSender @@ -6861,20 +6863,23 @@ QMailStoreSql::AttemptResult QMailStoreSql::attemptUpdateMessage(QMailMessageMet (metaData->parentFolderId() != parentFolderId)); // if message was moved to/from Trash or Draft folder we should update all threads values in an appropriate way if (movedToTrashOrDraft || movedFromTrashOrDraft) { - //It is easier to recalculate all thread values, because we must check all threads messages to understand should we - //change thread status or not. - const QMailThreadIdList idList = QMailThreadIdList() << metaData->parentThreadId(); - QMailThreadIdList deletedThreadIds; // FIXME: add deletedThreadIds as argument for updateMessage(). - if (!recalculateThreadsColumns(idList, deletedThreadIds)) - return DatabaseFailure; - APPEND_UNIQUE(all_modifiedThreads, metaData->parentThreadId()); + // It is easier to recalculate all thread values, because we must check all threads messages to understand should we + // change thread status or not. + const QMailThreadIdList idList = QMailThreadIdList() << metaData->parentThreadId(); + QMailThreadIdList deletedThreadIds; // FIXME: add deletedThreadIds as argument for updateMessage(). + if (!recalculateThreadsColumns(idList, deletedThreadIds)) + return DatabaseFailure; + APPEND_UNIQUE(all_modifiedThreads, metaData->parentThreadId()); } else { QMailThread thread(metaData->parentThreadId()); - const bool& updatePreview = (metaData->date() >= thread.lastDate()) && (thread.preview() != metaData->preview()) && !metaData->preview().isEmpty(); - const bool& updateSubject = (metaData->inResponseTo() == QMailMessageId()) && (metaData->date().toUTC() == thread.startedDate().toUTC()); - const bool& messageUnreadStatusChanged = (status & QMailMessage::Read) != (metaData->status() & QMailMessage::Read); - const bool& threadStatusChanged = (thread.status() & metaData->status()) != 0; - const bool& threadSendersChanged = !thread.senders().contains(metaData->from()) || metaData->date() > thread.lastDate(); + const bool updatePreview = (metaData->date() >= thread.lastDate()) + && (thread.preview() != metaData->preview()) + && !metaData->preview().isEmpty(); + const bool updateSubject = (metaData->inResponseTo() == QMailMessageId()) + && (metaData->date().toUTC() == thread.startedDate().toUTC()); + const bool messageUnreadStatusChanged = (status & QMailMessage::Read) != (metaData->status() & QMailMessage::Read); + const bool threadStatusChanged = (thread.status() & metaData->status()) != 0; + const bool threadSendersChanged = !thread.senders().contains(metaData->from()) || metaData->date() > thread.lastDate(); if (updatePreview || updateSubject || messageUnreadStatusChanged || threadStatusChanged || threadSendersChanged) { QString senders; @@ -7123,8 +7128,7 @@ QMailStoreSql::AttemptResult QMailStoreSql::attemptUpdateMessagesMetaData(const { QString sql(QLatin1String("SELECT parentthreadid FROM mailmessages WHERE id IN %1")); QVariantList bindValues; - foreach (const QMailMessageId &messageId, *updatedMessageIds) - { + foreach (const QMailMessageId &messageId, *updatedMessageIds) { bindValues << messageId.toULongLong(); } @@ -7181,16 +7185,16 @@ QMailStoreSql::AttemptResult QMailStoreSql::attemptUpdateMessagesStatus(const QM // perhaps, we need to update unreadcount column or status column in mailthreads table QVariantList bindMessagesIds; QVariantList bindMessagesIdsBatch; - foreach (const QMailMessageId& id, *updatedMessageIds) - { - const QMailThreadId &threadId = QMailMessageMetaData(id).parentThreadId(); + + foreach (const QMailMessageId &id, *updatedMessageIds) { + const QMailThreadId &threadId = QMailMessageMetaData(id).parentThreadId(); if (!modifiedThreadIds->contains(threadId) && threadId.isValid()) modifiedThreadIds->append(threadId); bindMessagesIds << id.toULongLong(); - } - if ( (status & QMailMessage::Read)) { - foreach (const QMailThreadId& threadId, *modifiedThreadIds) - { + } + + if (status & QMailMessage::Read) { + foreach (const QMailThreadId& threadId, *modifiedThreadIds) { if (threadId.isValid()) { QList<quint64> oldStatusList; @@ -7214,8 +7218,7 @@ QMailStoreSql::AttemptResult QMailStoreSql::attemptUpdateMessagesStatus(const QM oldStatusList.append(query.value(0).toULongLong()); } qlonglong unreadCount = 0; - foreach (const quint64& oldStatus, oldStatusList) - { + foreach (const quint64& oldStatus, oldStatusList) { if (set != bool(oldStatus & QMailMessage::Read)) { set ? --unreadCount : ++unreadCount; } @@ -8573,9 +8576,9 @@ bool QMailStoreSql::checkPreconditions(const QMailFolder& folder, bool update) } if (folder.parentAccountId().isValid()) { - if ((withAccountTables - ? !idExists(folder.parentAccountId()) - : !externalAccountIdExists(folder.parentAccountId()))) { + if (withAccountTables + ? !idExists(folder.parentAccountId()) + : !externalAccountIdExists(folder.parentAccountId())) { qCWarning(lcMailStore) << "Parent account does not exist!"; return false; } diff --git a/src/libraries/qmfclient/support/qmailpluginmanager.cpp b/src/libraries/qmfclient/support/qmailpluginmanager.cpp index fd5a0f97..5e22e018 100644 --- a/src/libraries/qmfclient/support/qmailpluginmanager.cpp +++ b/src/libraries/qmfclient/support/qmailpluginmanager.cpp @@ -148,15 +148,12 @@ QMailPluginManagerPrivate::QMailPluginManagerPrivate(const QString& path) QMailPluginManagerPrivate::~QMailPluginManagerPrivate() { - foreach (QPluginLoader *lib, pluginMap.values()) { - delete lib; - } + qDeleteAll(pluginMap.values()); } QMailPluginManager::QMailPluginManager(const QString& dir, QObject* parent) -: - QObject(parent), - d(new QMailPluginManagerPrivate(dir)) + : QObject(parent) + , d(new QMailPluginManagerPrivate(dir)) { } diff --git a/src/plugins/messageservices/imap/serviceactionqueue.cpp b/src/plugins/messageservices/imap/serviceactionqueue.cpp index 654badd6..5b90e695 100644 --- a/src/plugins/messageservices/imap/serviceactionqueue.cpp +++ b/src/plugins/messageservices/imap/serviceactionqueue.cpp @@ -68,8 +68,8 @@ void ServiceActionQueue::executeNextCommand() void ServiceActionQueue::activityChanged(QMailServiceAction::Activity activity) { - if ((activity == QMailServiceAction::Successful) || - (activity == QMailServiceAction::Failed)) { + if ((activity == QMailServiceAction::Successful) + || (activity == QMailServiceAction::Failed)) { delete _commands.takeFirst(); _running = false; _timer.start(0); @@ -78,10 +78,7 @@ void ServiceActionQueue::activityChanged(QMailServiceAction::Activity activity) void ServiceActionQueue::clear() { - for (int i = 0; i < _commands.size(); ++i) { - delete _commands.takeFirst(); - ++i; - } + qDeleteAll(_commands); _commands.clear(); _timer.stop(); _running = false; diff --git a/tests/tst_qmailcodec/tst_qmailcodec.cpp b/tests/tst_qmailcodec/tst_qmailcodec.cpp index a30723bf..b9e7b889 100644 --- a/tests/tst_qmailcodec/tst_qmailcodec.cpp +++ b/tests/tst_qmailcodec/tst_qmailcodec.cpp @@ -406,8 +406,7 @@ void tst_QMailCodec::line_lengths() QCOMPARE(reversed, plaintext); } - if (!qp2047_encoded.isEmpty()) - { + if (!qp2047_encoded.isEmpty()) { { QMailQuotedPrintableCodec codec(QMailQuotedPrintableCodec::Text, QMailQuotedPrintableCodec::Rfc2047, qp_line_length); encoded = codec.encode(plaintext, charset); diff --git a/tests/tst_qmailmessage/tst_qmailmessage.cpp b/tests/tst_qmailmessage/tst_qmailmessage.cpp index c2308c84..a0202b66 100644 --- a/tests/tst_qmailmessage/tst_qmailmessage.cpp +++ b/tests/tst_qmailmessage/tst_qmailmessage.cpp @@ -174,8 +174,7 @@ static void testHeader(const QString& name, void (QMailMessage::*setter)(const Q QCOMPARE(m.dataModified(), true); } - if (expandEncodedWords && !name.isNull()) - { + if (expandEncodedWords && !name.isNull()) { QString value3("This =?ISO-8859-1?Q?value?= contains =?ISO-8859-1?B?ZW5jb2RlZC13b3Jkcw==?="); QString value4("This value contains encoded-words"); @@ -352,8 +351,7 @@ void tst_QMailMessage::toRfc2822() QFETCH(QByteArray, rfc_body_text); QMailMessageBody::TransferEncoding te[3] = { QMailMessageBody::NoEncoding, QMailMessageBody::Base64, QMailMessageBody::QuotedPrintable }; - for (int i = 0; i < 2; ++i) - { + for (int i = 0; i < 2; ++i) { QMailMessage message; message.setFrom(QMailAddress(from)); message.setTo(QMailAddress::fromStringList(to)); |
