From d836c36bc07b91584f88a1f15c0a39978da1e586 Mon Sep 17 00:00:00 2001 From: Laurent Montel Date: Mon, 3 May 2021 20:24:09 +0200 Subject: [PATCH] Modernize code --- autotests/favoritestest.cpp | 2 +- autotests/foldertreewidgettest.cpp | 6 +++--- src/filter/filteractions/filteractionaddheader.cpp | 2 +- .../filteractions/filteractionaddtoaddressbook.cpp | 2 +- src/filter/filteractions/filteractionforward.cpp | 2 +- .../filteractions/filteractionremoveheader.cpp | 2 +- src/filter/filteractions/filteractionreplyto.cpp | 2 +- .../filteractions/filteractionrewriteheader.cpp | 2 +- .../filteractions/filteractionsendreceipt.cpp | 2 +- .../filteractions/filteractionsetidentity.cpp | 2 +- .../filteractions/filteractionsettransport.cpp | 2 +- .../filteractions/filteractionwithcommand.cpp | 2 +- src/folder/foldercollectionmonitor.cpp | 2 +- src/folder/foldertreeview.cpp | 6 +++--- src/folder/foldertreewidget.cpp | 2 +- src/folder/foldertreewidgetproxymodel.cpp | 13 ++++++------- src/job/backupjob.cpp | 2 +- src/job/expirejob.cpp | 2 +- src/search/searchrule/searchruledate.cpp | 2 +- src/search/searchrule/searchrulenumerical.cpp | 2 +- src/search/searchrule/searchrulestring.cpp | 2 +- 21 files changed, 30 insertions(+), 31 deletions(-) diff --git a/autotests/favoritestest.cpp b/autotests/favoritestest.cpp index 197161b..8b8d018 100644 --- a/autotests/favoritestest.cpp +++ b/autotests/favoritestest.cpp @@ -86,7 +86,7 @@ void FavoriteProxyTest::testReordering() for (const QString &folderName : {QStringLiteral("res2"), QStringLiteral("res3")}) { const QModelIndex index = getIndex(folderName, model); QVERIFY(index.isValid()); - const Akonadi::Collection favoriteCollection = index.data(EntityTreeModel::CollectionRole).value(); + const auto favoriteCollection = index.data(EntityTreeModel::CollectionRole).value(); QVERIFY(favoriteCollection.isValid()); collectionIds.push_back(favoriteCollection.id()); order.push_back(QLatin1Char('c') + QString::number(favoriteCollection.id())); diff --git a/autotests/foldertreewidgettest.cpp b/autotests/foldertreewidgettest.cpp index 619c002..e240877 100644 --- a/autotests/foldertreewidgettest.cpp +++ b/autotests/foldertreewidgettest.cpp @@ -169,7 +169,7 @@ private Q_SLOTS: // Given a source folder with 2 levels of parents (res1/sub1/sub2) const QStringList folderNames = collectNames(mCollectionModel); const QModelIndex res1Index = mCollectionModel->index(folderNames.indexOf("res1"), 0, QModelIndex()); - const Collection topLevelCollection = res1Index.data(EntityTreeModel::CollectionRole).value(); + const auto topLevelCollection = res1Index.data(EntityTreeModel::CollectionRole).value(); QCOMPARE(topLevelCollection.name(), QStringLiteral("res1")); const int parentCount = 2; Collection currentColl = topLevelCollection; @@ -186,7 +186,7 @@ private Q_SLOTS: // ... and a dest folder in another resource const QPersistentModelIndex res2Index = mCollectionModel->index(folderNames.indexOf("res2"), 0, QModelIndex()); const int origRowCount = mCollectionModel->rowCount(res2Index); - const Collection newParentCollection = res2Index.data(EntityTreeModel::CollectionRole).value(); + const auto newParentCollection = res2Index.data(EntityTreeModel::CollectionRole).value(); QCOMPARE(newParentCollection.name(), QStringLiteral("res2")); QTest::qWait(100); // #### akonadi bug? Without this, a warning "Only resources can modify remote identifiers" appears @@ -231,7 +231,7 @@ private: QModelIndex idx = model->index(row, 0, parent); QModelIndex col1idx = model->index(row, 1, parent); QCOMPARE(col1idx.sibling(col1idx.row(), 0), idx); - Collection collection = idx.data(EntityTreeModel::CollectionRole).value(); + auto collection = idx.data(EntityTreeModel::CollectionRole).value(); QVERIFY2(collection.isValid(), qPrintable(idx.data().toString())); } } diff --git a/src/filter/filteractions/filteractionaddheader.cpp b/src/filter/filteractions/filteractionaddheader.cpp index a750610..0376e63 100644 --- a/src/filter/filteractions/filteractionaddheader.cpp +++ b/src/filter/filteractions/filteractionaddheader.cpp @@ -37,7 +37,7 @@ FilterAction::ReturnCode FilterActionAddHeader::process(ItemContext &context, bo return ErrorButGoOn; } - KMime::Message::Ptr msg = context.item().payload(); + auto msg = context.item().payload(); KMime::Headers::Base *header = KMime::Headers::createHeader(mParameter.toLatin1()); if (!header) { diff --git a/src/filter/filteractions/filteractionaddtoaddressbook.cpp b/src/filter/filteractions/filteractionaddtoaddressbook.cpp index c124e29..b93046a 100644 --- a/src/filter/filteractions/filteractionaddtoaddressbook.cpp +++ b/src/filter/filteractions/filteractionaddtoaddressbook.cpp @@ -51,7 +51,7 @@ FilterAction::ReturnCode FilterActionAddToAddressBook::process(ItemContext &cont return ErrorButGoOn; } - const KMime::Message::Ptr msg = context.item().payload(); + const auto msg = context.item().payload(); QString headerLine; switch (mHeaderType) { diff --git a/src/filter/filteractions/filteractionforward.cpp b/src/filter/filteractions/filteractionforward.cpp index 4cb3271..f8fccae 100644 --- a/src/filter/filteractions/filteractionforward.cpp +++ b/src/filter/filteractions/filteractionforward.cpp @@ -43,7 +43,7 @@ FilterAction::ReturnCode FilterActionForward::process(ItemContext &context, bool return ErrorButGoOn; } - const KMime::Message::Ptr msg = context.item().payload(); + const auto msg = context.item().payload(); // avoid endless loops when this action is used in a filter // which applies to sent messages if (MessageCore::StringUtil::addressIsInAddressList(mParameter, QStringList(msg->to()->asUnicodeString()))) { diff --git a/src/filter/filteractions/filteractionremoveheader.cpp b/src/filter/filteractions/filteractionremoveheader.cpp index e3e9d9e..db18913 100644 --- a/src/filter/filteractions/filteractionremoveheader.cpp +++ b/src/filter/filteractions/filteractionremoveheader.cpp @@ -46,7 +46,7 @@ FilterAction::ReturnCode FilterActionRemoveHeader::process(ItemContext &context, return ErrorButGoOn; } - KMime::Message::Ptr msg = context.item().payload(); + auto msg = context.item().payload(); const QByteArray param(mParameter.toLatin1()); bool headerRemove = false; while (msg->removeHeader(param.constData())) { diff --git a/src/filter/filteractions/filteractionreplyto.cpp b/src/filter/filteractions/filteractionreplyto.cpp index b1fd7a8..d31751d 100644 --- a/src/filter/filteractions/filteractionreplyto.cpp +++ b/src/filter/filteractions/filteractionreplyto.cpp @@ -26,7 +26,7 @@ FilterAction::ReturnCode FilterActionReplyTo::process(ItemContext &context, bool if (mParameter.isEmpty()) { return ErrorButGoOn; } - const KMime::Message::Ptr msg = context.item().payload(); + const auto msg = context.item().payload(); const QByteArray replyTo("Reply-To"); KMime::Headers::Base *header = KMime::Headers::createHeader(replyTo); if (!header) { diff --git a/src/filter/filteractions/filteractionrewriteheader.cpp b/src/filter/filteractions/filteractionrewriteheader.cpp index df29571..19a212a 100644 --- a/src/filter/filteractions/filteractionrewriteheader.cpp +++ b/src/filter/filteractions/filteractionrewriteheader.cpp @@ -56,7 +56,7 @@ FilterAction::ReturnCode FilterActionRewriteHeader::process(ItemContext &context return ErrorButGoOn; } - const KMime::Message::Ptr msg = context.item().payload(); + const auto msg = context.item().payload(); const QByteArray param(mParameter.toLatin1()); KMime::Headers::Base *header = msg->headerByType(param.constData()); diff --git a/src/filter/filteractions/filteractionsendreceipt.cpp b/src/filter/filteractions/filteractionsendreceipt.cpp index a62d546..6579a9a 100644 --- a/src/filter/filteractions/filteractionsendreceipt.cpp +++ b/src/filter/filteractions/filteractionsendreceipt.cpp @@ -24,7 +24,7 @@ FilterActionSendReceipt::FilterActionSendReceipt(QObject *parent) FilterAction::ReturnCode FilterActionSendReceipt::process(ItemContext &context, bool) const { - const KMime::Message::Ptr msg = context.item().payload(); + const auto msg = context.item().payload(); MessageComposer::MessageFactoryNG factory(msg, context.item().id()); factory.setFolderIdentity(Util::folderIdentity(context.item())); diff --git a/src/filter/filteractions/filteractionsetidentity.cpp b/src/filter/filteractions/filteractionsetidentity.cpp index 34cff0a..97cf43c 100644 --- a/src/filter/filteractions/filteractionsetidentity.cpp +++ b/src/filter/filteractions/filteractionsetidentity.cpp @@ -56,7 +56,7 @@ FilterAction::ReturnCode FilterActionSetIdentity::process(ItemContext &context, return ErrorButGoOn; } - const KMime::Message::Ptr msg = context.item().payload(); + const auto msg = context.item().payload(); uint currentId = 0; if (auto hrd = msg->headerByType("X-KMail-Identity")) { currentId = hrd->asUnicodeString().trimmed().toUInt(); diff --git a/src/filter/filteractions/filteractionsettransport.cpp b/src/filter/filteractions/filteractionsettransport.cpp index 50665a4..9da54d5 100644 --- a/src/filter/filteractions/filteractionsettransport.cpp +++ b/src/filter/filteractions/filteractionsettransport.cpp @@ -70,7 +70,7 @@ FilterAction::ReturnCode FilterActionSetTransport::process(ItemContext &context, return ErrorButGoOn; } - const KMime::Message::Ptr msg = context.item().payload(); + const auto msg = context.item().payload(); auto header = new KMime::Headers::Generic("X-KMail-Transport"); header->fromUnicodeString(argsAsString(), "utf-8"); msg->setHeader(header); diff --git a/src/filter/filteractions/filteractionwithcommand.cpp b/src/filter/filteractions/filteractionwithcommand.cpp index 3421e5a..279249b 100644 --- a/src/filter/filteractions/filteractionwithcommand.cpp +++ b/src/filter/filteractions/filteractionwithcommand.cpp @@ -169,7 +169,7 @@ void substituteCommandLineArgsForItem(const Akonadi::Item &item, QString &comman FilterAction::ReturnCode FilterActionWithCommand::genericProcess(ItemContext &context, bool withOutput) const { - const KMime::Message::Ptr aMsg = context.item().payload(); + const auto aMsg = context.item().payload(); Q_ASSERT(aMsg); if (mParameter.isEmpty()) { diff --git a/src/folder/foldercollectionmonitor.cpp b/src/folder/foldercollectionmonitor.cpp index e28ca87..6a03cae 100644 --- a/src/folder/foldercollectionmonitor.cpp +++ b/src/folder/foldercollectionmonitor.cpp @@ -74,7 +74,7 @@ void FolderCollectionMonitor::expireAllCollection(const QAbstractItemModel *mode const int rowCount = model->rowCount(parentIndex); for (int row = 0; row < rowCount; ++row) { const QModelIndex index = model->index(row, 0, parentIndex); - const Akonadi::Collection collection = model->data(index, Akonadi::EntityTreeModel::CollectionRole).value(); + const auto collection = model->data(index, Akonadi::EntityTreeModel::CollectionRole).value(); if (!collection.isValid() || Util::isVirtualCollection(collection)) { continue; diff --git a/src/folder/foldertreeview.cpp b/src/folder/foldertreeview.cpp index 3f6af1c..d14eb1a 100644 --- a/src/folder/foldertreeview.cpp +++ b/src/folder/foldertreeview.cpp @@ -424,7 +424,7 @@ bool FolderTreeView::trySelectNextUnreadFolder(const QModelIndex ¤t, Searc return false; } - const Akonadi::Collection collection = index.data(Akonadi::EntityTreeModel::CollectionRole).value(); + const auto collection = index.data(Akonadi::EntityTreeModel::CollectionRole).value(); if (collection == Kernel::self()->trashCollectionFolder() || collection == Kernel::self()->outboxCollectionFolder()) { continue; } @@ -491,7 +491,7 @@ bool FolderTreeView::isUnreadFolder(const QModelIndex ¤t, QModelIndex &ind } if (index.isValid()) { - const Akonadi::Collection collection = index.model()->data(current, Akonadi::EntityTreeModel::CollectionRole).value(); + const auto collection = index.model()->data(current, Akonadi::EntityTreeModel::CollectionRole).value(); if (collection.isValid()) { if (collection.statistics().unreadCount() > 0) { @@ -537,7 +537,7 @@ Akonadi::Collection FolderTreeView::currentFolder() const { const QModelIndex current = currentIndex(); if (current.isValid()) { - const Akonadi::Collection collection = current.model()->data(current, Akonadi::EntityTreeModel::CollectionRole).value(); + const auto collection = current.model()->data(current, Akonadi::EntityTreeModel::CollectionRole).value(); return collection; } return Akonadi::Collection(); diff --git a/src/folder/foldertreewidget.cpp b/src/folder/foldertreewidget.cpp index 6d8ce4d..f3e7c92 100644 --- a/src/folder/foldertreewidget.cpp +++ b/src/folder/foldertreewidget.cpp @@ -215,7 +215,7 @@ Akonadi::Collection::List FolderTreeWidget::selectedCollections() const const QModelIndexList selectedIndexes = selectionModel->selectedIndexes(); for (const QModelIndex &index : selectedIndexes) { if (index.isValid()) { - const Akonadi::Collection collection = index.model()->data(index, Akonadi::EntityTreeModel::CollectionRole).value(); + const auto collection = index.model()->data(index, Akonadi::EntityTreeModel::CollectionRole).value(); if (collection.isValid()) { collections.append(collection); } diff --git a/src/folder/foldertreewidgetproxymodel.cpp b/src/folder/foldertreewidgetproxymodel.cpp index 9f0ee61..4db0589 100644 --- a/src/folder/foldertreewidgetproxymodel.cpp +++ b/src/folder/foldertreewidgetproxymodel.cpp @@ -40,8 +40,7 @@ public: for (int row = 0; row < rowCount; row++) { const QModelIndex firstIndex = q->mapToSource(index.model()->index(row, 0, index)); - const Akonadi::Collection collectionFirst = - q->sourceModel()->data(firstIndex, Akonadi::EntityTreeModel::CollectionRole).value(); + const auto collectionFirst = q->sourceModel()->data(firstIndex, Akonadi::EntityTreeModel::CollectionRole).value(); if (collectionFirst.isValid() && collectionFirst.hasAttribute()) { const auto *quota = collectionFirst.attribute(); @@ -108,7 +107,7 @@ Qt::ItemFlags FolderTreeWidgetProxyModel::flags(const QModelIndex &index) const if (d->enableCheck) { const QModelIndex sourceIndex = mapToSource(index); const QModelIndex rowIndex = sourceIndex.sibling(sourceIndex.row(), 0); - const Akonadi::Collection collection = sourceModel()->data(rowIndex, Akonadi::EntityTreeModel::CollectionRole).value(); + const auto collection = sourceModel()->data(rowIndex, Akonadi::EntityTreeModel::CollectionRole).value(); if (!MailCommon::Util::isVirtualCollection(collection)) { const Akonadi::AgentInstance instance = Akonadi::AgentManager::self()->instance(collection.resource()); if (instance.status() == Akonadi::AgentInstance::Broken) { @@ -180,7 +179,7 @@ bool FolderTreeWidgetProxyModel::filterAcceptsRow(int sourceRow, const QModelInd { const QModelIndex modelIndex = sourceModel()->index(sourceRow, 0, sourceParent); - const Akonadi::Collection collection = sourceModel()->data(modelIndex, Akonadi::EntityTreeModel::CollectionRole).value(); + const auto collection = sourceModel()->data(modelIndex, Akonadi::EntityTreeModel::CollectionRole).value(); if (!d->checker.isWantedCollection(collection)) { return false; } @@ -212,7 +211,7 @@ QVariant FolderTreeWidgetProxyModel::data(const QModelIndex &index, int role) co if (role == Qt::ForegroundRole) { const QModelIndex sourceIndex = mapToSource(index); const QModelIndex rowIndex = sourceIndex.sibling(sourceIndex.row(), 0); - const Akonadi::Collection collection = sourceModel()->data(rowIndex, Akonadi::EntityTreeModel::CollectionRole).value(); + const auto collection = sourceModel()->data(rowIndex, Akonadi::EntityTreeModel::CollectionRole).value(); if (!MailCommon::Util::isVirtualCollection(collection)) { const Akonadi::AgentInstance instance = Akonadi::AgentManager::self()->instance(collection.resource()); @@ -228,7 +227,7 @@ QVariant FolderTreeWidgetProxyModel::data(const QModelIndex &index, int role) co } else if (role == Qt::DisplayRole) { const QModelIndex sourceIndex = mapToSource(index); const QModelIndex rowIndex = sourceIndex.sibling(sourceIndex.row(), 0); - const Akonadi::Collection collection = sourceModel()->data(rowIndex, Akonadi::EntityTreeModel::CollectionRole).value(); + const auto collection = sourceModel()->data(rowIndex, Akonadi::EntityTreeModel::CollectionRole).value(); if (!MailCommon::Util::isVirtualCollection(collection)) { const Akonadi::AgentInstance instance = Akonadi::AgentManager::self()->instance(collection.resource()); if (collection.parentCollection() == Akonadi::Collection::root()) { @@ -244,7 +243,7 @@ QVariant FolderTreeWidgetProxyModel::data(const QModelIndex &index, int role) co } else if (role == Qt::DecorationRole) { const QModelIndex sourceIndex = mapToSource(index); const QModelIndex rowIndex = sourceIndex.sibling(sourceIndex.row(), 0); - const Akonadi::Collection collection = sourceModel()->data(rowIndex, Akonadi::EntityTreeModel::CollectionRole).value(); + const auto collection = sourceModel()->data(rowIndex, Akonadi::EntityTreeModel::CollectionRole).value(); if (!MailCommon::Util::isVirtualCollection(collection)) { if (collection.parentCollection() == Akonadi::Collection::root()) { qreal percentage = 0.0; diff --git a/src/job/backupjob.cpp b/src/job/backupjob.cpp index aec4021..17ae3d2 100644 --- a/src/job/backupjob.cpp +++ b/src/job/backupjob.cpp @@ -229,7 +229,7 @@ void BackupJob::processMessage(const Akonadi::Item &item) return; } - const KMime::Message::Ptr message = item.payload(); + const auto message = item.payload(); qCDebug(MAILCOMMON_LOG) << "Processing message with subject " << message->subject(false); const QByteArray messageData = message->encodedContent(); const qint64 messageSize = messageData.size(); diff --git a/src/job/expirejob.cpp b/src/job/expirejob.cpp index d04658c..04a8a5e 100644 --- a/src/job/expirejob.cpp +++ b/src/job/expirejob.cpp @@ -109,7 +109,7 @@ void ExpireJob::itemFetchResult(KJob *job) continue; } - const KMime::Message::Ptr mb = item.payload(); + const auto mb = item.payload(); Akonadi::MessageStatus status; status.setStatusFromFlags(item.flags()); if ((status.isImportant() || status.isToAct() || status.isWatched()) && SettingsIf->excludeImportantMailFromExpiry()) { diff --git a/src/search/searchrule/searchruledate.cpp b/src/search/searchrule/searchruledate.cpp index 2899996..1b0d080 100644 --- a/src/search/searchrule/searchruledate.cpp +++ b/src/search/searchrule/searchruledate.cpp @@ -33,7 +33,7 @@ bool SearchRuleDate::matches(const Akonadi::Item &item) const if (!item.hasPayload()) { return false; } - const KMime::Message::Ptr msg = item.payload(); + const auto msg = item.payload(); const QDate msgDate = msg->date()->dateTime().date(); const QDate dateValue = QDate::fromString(contents(), Qt::ISODate); diff --git a/src/search/searchrule/searchrulenumerical.cpp b/src/search/searchrule/searchrulenumerical.cpp index fefe0bc..d0a47a2 100644 --- a/src/search/searchrule/searchrulenumerical.cpp +++ b/src/search/searchrule/searchrulenumerical.cpp @@ -37,7 +37,7 @@ bool SearchRuleNumerical::matches(const Akonadi::Item &item) const return false; } - const KMime::Message::Ptr msg = item.payload(); + const auto msg = item.payload(); QString msgContents; qint64 numericalMsgContents = 0; diff --git a/src/search/searchrule/searchrulestring.cpp b/src/search/searchrule/searchrulestring.cpp index eaad463..d21f84d 100644 --- a/src/search/searchrule/searchrulestring.cpp +++ b/src/search/searchrule/searchrulestring.cpp @@ -83,7 +83,7 @@ bool SearchRuleString::matches(const Akonadi::Item &item) const return false; } - const KMime::Message::Ptr msg = item.payload(); + const auto msg = item.payload(); Q_ASSERT(msg.data()); if (!msg->hasHeader("From")) {