Modernize code

wilder
Laurent Montel 5 years ago
parent d7ca8188ae
commit d836c36bc0
  1. 2
      autotests/favoritestest.cpp
  2. 6
      autotests/foldertreewidgettest.cpp
  3. 2
      src/filter/filteractions/filteractionaddheader.cpp
  4. 2
      src/filter/filteractions/filteractionaddtoaddressbook.cpp
  5. 2
      src/filter/filteractions/filteractionforward.cpp
  6. 2
      src/filter/filteractions/filteractionremoveheader.cpp
  7. 2
      src/filter/filteractions/filteractionreplyto.cpp
  8. 2
      src/filter/filteractions/filteractionrewriteheader.cpp
  9. 2
      src/filter/filteractions/filteractionsendreceipt.cpp
  10. 2
      src/filter/filteractions/filteractionsetidentity.cpp
  11. 2
      src/filter/filteractions/filteractionsettransport.cpp
  12. 2
      src/filter/filteractions/filteractionwithcommand.cpp
  13. 2
      src/folder/foldercollectionmonitor.cpp
  14. 6
      src/folder/foldertreeview.cpp
  15. 2
      src/folder/foldertreewidget.cpp
  16. 13
      src/folder/foldertreewidgetproxymodel.cpp
  17. 2
      src/job/backupjob.cpp
  18. 2
      src/job/expirejob.cpp
  19. 2
      src/search/searchrule/searchruledate.cpp
  20. 2
      src/search/searchrule/searchrulenumerical.cpp
  21. 2
      src/search/searchrule/searchrulestring.cpp

@ -86,7 +86,7 @@ void FavoriteProxyTest::testReordering()
for (const QString &folderName : {QStringLiteral("res2"), QStringLiteral("res3")}) { for (const QString &folderName : {QStringLiteral("res2"), QStringLiteral("res3")}) {
const QModelIndex index = getIndex(folderName, model); const QModelIndex index = getIndex(folderName, model);
QVERIFY(index.isValid()); QVERIFY(index.isValid());
const Akonadi::Collection favoriteCollection = index.data(EntityTreeModel::CollectionRole).value<Akonadi::Collection>(); const auto favoriteCollection = index.data(EntityTreeModel::CollectionRole).value<Akonadi::Collection>();
QVERIFY(favoriteCollection.isValid()); QVERIFY(favoriteCollection.isValid());
collectionIds.push_back(favoriteCollection.id()); collectionIds.push_back(favoriteCollection.id());
order.push_back(QLatin1Char('c') + QString::number(favoriteCollection.id())); order.push_back(QLatin1Char('c') + QString::number(favoriteCollection.id()));

@ -169,7 +169,7 @@ private Q_SLOTS:
// Given a source folder with 2 levels of parents (res1/sub1/sub2) // Given a source folder with 2 levels of parents (res1/sub1/sub2)
const QStringList folderNames = collectNames(mCollectionModel); const QStringList folderNames = collectNames(mCollectionModel);
const QModelIndex res1Index = mCollectionModel->index(folderNames.indexOf("res1"), 0, QModelIndex()); const QModelIndex res1Index = mCollectionModel->index(folderNames.indexOf("res1"), 0, QModelIndex());
const Collection topLevelCollection = res1Index.data(EntityTreeModel::CollectionRole).value<Collection>(); const auto topLevelCollection = res1Index.data(EntityTreeModel::CollectionRole).value<Collection>();
QCOMPARE(topLevelCollection.name(), QStringLiteral("res1")); QCOMPARE(topLevelCollection.name(), QStringLiteral("res1"));
const int parentCount = 2; const int parentCount = 2;
Collection currentColl = topLevelCollection; Collection currentColl = topLevelCollection;
@ -186,7 +186,7 @@ private Q_SLOTS:
// ... and a dest folder in another resource // ... and a dest folder in another resource
const QPersistentModelIndex res2Index = mCollectionModel->index(folderNames.indexOf("res2"), 0, QModelIndex()); const QPersistentModelIndex res2Index = mCollectionModel->index(folderNames.indexOf("res2"), 0, QModelIndex());
const int origRowCount = mCollectionModel->rowCount(res2Index); const int origRowCount = mCollectionModel->rowCount(res2Index);
const Collection newParentCollection = res2Index.data(EntityTreeModel::CollectionRole).value<Collection>(); const auto newParentCollection = res2Index.data(EntityTreeModel::CollectionRole).value<Collection>();
QCOMPARE(newParentCollection.name(), QStringLiteral("res2")); QCOMPARE(newParentCollection.name(), QStringLiteral("res2"));
QTest::qWait(100); // #### akonadi bug? Without this, a warning "Only resources can modify remote identifiers" appears 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 idx = model->index(row, 0, parent);
QModelIndex col1idx = model->index(row, 1, parent); QModelIndex col1idx = model->index(row, 1, parent);
QCOMPARE(col1idx.sibling(col1idx.row(), 0), idx); QCOMPARE(col1idx.sibling(col1idx.row(), 0), idx);
Collection collection = idx.data(EntityTreeModel::CollectionRole).value<Collection>(); auto collection = idx.data(EntityTreeModel::CollectionRole).value<Collection>();
QVERIFY2(collection.isValid(), qPrintable(idx.data().toString())); QVERIFY2(collection.isValid(), qPrintable(idx.data().toString()));
} }
} }

@ -37,7 +37,7 @@ FilterAction::ReturnCode FilterActionAddHeader::process(ItemContext &context, bo
return ErrorButGoOn; return ErrorButGoOn;
} }
KMime::Message::Ptr msg = context.item().payload<KMime::Message::Ptr>(); auto msg = context.item().payload<KMime::Message::Ptr>();
KMime::Headers::Base *header = KMime::Headers::createHeader(mParameter.toLatin1()); KMime::Headers::Base *header = KMime::Headers::createHeader(mParameter.toLatin1());
if (!header) { if (!header) {

@ -51,7 +51,7 @@ FilterAction::ReturnCode FilterActionAddToAddressBook::process(ItemContext &cont
return ErrorButGoOn; return ErrorButGoOn;
} }
const KMime::Message::Ptr msg = context.item().payload<KMime::Message::Ptr>(); const auto msg = context.item().payload<KMime::Message::Ptr>();
QString headerLine; QString headerLine;
switch (mHeaderType) { switch (mHeaderType) {

@ -43,7 +43,7 @@ FilterAction::ReturnCode FilterActionForward::process(ItemContext &context, bool
return ErrorButGoOn; return ErrorButGoOn;
} }
const KMime::Message::Ptr msg = context.item().payload<KMime::Message::Ptr>(); const auto msg = context.item().payload<KMime::Message::Ptr>();
// avoid endless loops when this action is used in a filter // avoid endless loops when this action is used in a filter
// which applies to sent messages // which applies to sent messages
if (MessageCore::StringUtil::addressIsInAddressList(mParameter, QStringList(msg->to()->asUnicodeString()))) { if (MessageCore::StringUtil::addressIsInAddressList(mParameter, QStringList(msg->to()->asUnicodeString()))) {

@ -46,7 +46,7 @@ FilterAction::ReturnCode FilterActionRemoveHeader::process(ItemContext &context,
return ErrorButGoOn; return ErrorButGoOn;
} }
KMime::Message::Ptr msg = context.item().payload<KMime::Message::Ptr>(); auto msg = context.item().payload<KMime::Message::Ptr>();
const QByteArray param(mParameter.toLatin1()); const QByteArray param(mParameter.toLatin1());
bool headerRemove = false; bool headerRemove = false;
while (msg->removeHeader(param.constData())) { while (msg->removeHeader(param.constData())) {

@ -26,7 +26,7 @@ FilterAction::ReturnCode FilterActionReplyTo::process(ItemContext &context, bool
if (mParameter.isEmpty()) { if (mParameter.isEmpty()) {
return ErrorButGoOn; return ErrorButGoOn;
} }
const KMime::Message::Ptr msg = context.item().payload<KMime::Message::Ptr>(); const auto msg = context.item().payload<KMime::Message::Ptr>();
const QByteArray replyTo("Reply-To"); const QByteArray replyTo("Reply-To");
KMime::Headers::Base *header = KMime::Headers::createHeader(replyTo); KMime::Headers::Base *header = KMime::Headers::createHeader(replyTo);
if (!header) { if (!header) {

@ -56,7 +56,7 @@ FilterAction::ReturnCode FilterActionRewriteHeader::process(ItemContext &context
return ErrorButGoOn; return ErrorButGoOn;
} }
const KMime::Message::Ptr msg = context.item().payload<KMime::Message::Ptr>(); const auto msg = context.item().payload<KMime::Message::Ptr>();
const QByteArray param(mParameter.toLatin1()); const QByteArray param(mParameter.toLatin1());
KMime::Headers::Base *header = msg->headerByType(param.constData()); KMime::Headers::Base *header = msg->headerByType(param.constData());

@ -24,7 +24,7 @@ FilterActionSendReceipt::FilterActionSendReceipt(QObject *parent)
FilterAction::ReturnCode FilterActionSendReceipt::process(ItemContext &context, bool) const FilterAction::ReturnCode FilterActionSendReceipt::process(ItemContext &context, bool) const
{ {
const KMime::Message::Ptr msg = context.item().payload<KMime::Message::Ptr>(); const auto msg = context.item().payload<KMime::Message::Ptr>();
MessageComposer::MessageFactoryNG factory(msg, context.item().id()); MessageComposer::MessageFactoryNG factory(msg, context.item().id());
factory.setFolderIdentity(Util::folderIdentity(context.item())); factory.setFolderIdentity(Util::folderIdentity(context.item()));

@ -56,7 +56,7 @@ FilterAction::ReturnCode FilterActionSetIdentity::process(ItemContext &context,
return ErrorButGoOn; return ErrorButGoOn;
} }
const KMime::Message::Ptr msg = context.item().payload<KMime::Message::Ptr>(); const auto msg = context.item().payload<KMime::Message::Ptr>();
uint currentId = 0; uint currentId = 0;
if (auto hrd = msg->headerByType("X-KMail-Identity")) { if (auto hrd = msg->headerByType("X-KMail-Identity")) {
currentId = hrd->asUnicodeString().trimmed().toUInt(); currentId = hrd->asUnicodeString().trimmed().toUInt();

@ -70,7 +70,7 @@ FilterAction::ReturnCode FilterActionSetTransport::process(ItemContext &context,
return ErrorButGoOn; return ErrorButGoOn;
} }
const KMime::Message::Ptr msg = context.item().payload<KMime::Message::Ptr>(); const auto msg = context.item().payload<KMime::Message::Ptr>();
auto header = new KMime::Headers::Generic("X-KMail-Transport"); auto header = new KMime::Headers::Generic("X-KMail-Transport");
header->fromUnicodeString(argsAsString(), "utf-8"); header->fromUnicodeString(argsAsString(), "utf-8");
msg->setHeader(header); msg->setHeader(header);

@ -169,7 +169,7 @@ void substituteCommandLineArgsForItem(const Akonadi::Item &item, QString &comman
FilterAction::ReturnCode FilterActionWithCommand::genericProcess(ItemContext &context, bool withOutput) const FilterAction::ReturnCode FilterActionWithCommand::genericProcess(ItemContext &context, bool withOutput) const
{ {
const KMime::Message::Ptr aMsg = context.item().payload<KMime::Message::Ptr>(); const auto aMsg = context.item().payload<KMime::Message::Ptr>();
Q_ASSERT(aMsg); Q_ASSERT(aMsg);
if (mParameter.isEmpty()) { if (mParameter.isEmpty()) {

@ -74,7 +74,7 @@ void FolderCollectionMonitor::expireAllCollection(const QAbstractItemModel *mode
const int rowCount = model->rowCount(parentIndex); const int rowCount = model->rowCount(parentIndex);
for (int row = 0; row < rowCount; ++row) { for (int row = 0; row < rowCount; ++row) {
const QModelIndex index = model->index(row, 0, parentIndex); const QModelIndex index = model->index(row, 0, parentIndex);
const Akonadi::Collection collection = model->data(index, Akonadi::EntityTreeModel::CollectionRole).value<Akonadi::Collection>(); const auto collection = model->data(index, Akonadi::EntityTreeModel::CollectionRole).value<Akonadi::Collection>();
if (!collection.isValid() || Util::isVirtualCollection(collection)) { if (!collection.isValid() || Util::isVirtualCollection(collection)) {
continue; continue;

@ -424,7 +424,7 @@ bool FolderTreeView::trySelectNextUnreadFolder(const QModelIndex &current, Searc
return false; return false;
} }
const Akonadi::Collection collection = index.data(Akonadi::EntityTreeModel::CollectionRole).value<Akonadi::Collection>(); const auto collection = index.data(Akonadi::EntityTreeModel::CollectionRole).value<Akonadi::Collection>();
if (collection == Kernel::self()->trashCollectionFolder() || collection == Kernel::self()->outboxCollectionFolder()) { if (collection == Kernel::self()->trashCollectionFolder() || collection == Kernel::self()->outboxCollectionFolder()) {
continue; continue;
} }
@ -491,7 +491,7 @@ bool FolderTreeView::isUnreadFolder(const QModelIndex &current, QModelIndex &ind
} }
if (index.isValid()) { if (index.isValid()) {
const Akonadi::Collection collection = index.model()->data(current, Akonadi::EntityTreeModel::CollectionRole).value<Akonadi::Collection>(); const auto collection = index.model()->data(current, Akonadi::EntityTreeModel::CollectionRole).value<Akonadi::Collection>();
if (collection.isValid()) { if (collection.isValid()) {
if (collection.statistics().unreadCount() > 0) { if (collection.statistics().unreadCount() > 0) {
@ -537,7 +537,7 @@ Akonadi::Collection FolderTreeView::currentFolder() const
{ {
const QModelIndex current = currentIndex(); const QModelIndex current = currentIndex();
if (current.isValid()) { if (current.isValid()) {
const Akonadi::Collection collection = current.model()->data(current, Akonadi::EntityTreeModel::CollectionRole).value<Akonadi::Collection>(); const auto collection = current.model()->data(current, Akonadi::EntityTreeModel::CollectionRole).value<Akonadi::Collection>();
return collection; return collection;
} }
return Akonadi::Collection(); return Akonadi::Collection();

@ -215,7 +215,7 @@ Akonadi::Collection::List FolderTreeWidget::selectedCollections() const
const QModelIndexList selectedIndexes = selectionModel->selectedIndexes(); const QModelIndexList selectedIndexes = selectionModel->selectedIndexes();
for (const QModelIndex &index : selectedIndexes) { for (const QModelIndex &index : selectedIndexes) {
if (index.isValid()) { if (index.isValid()) {
const Akonadi::Collection collection = index.model()->data(index, Akonadi::EntityTreeModel::CollectionRole).value<Akonadi::Collection>(); const auto collection = index.model()->data(index, Akonadi::EntityTreeModel::CollectionRole).value<Akonadi::Collection>();
if (collection.isValid()) { if (collection.isValid()) {
collections.append(collection); collections.append(collection);
} }

@ -40,8 +40,7 @@ public:
for (int row = 0; row < rowCount; row++) { for (int row = 0; row < rowCount; row++) {
const QModelIndex firstIndex = q->mapToSource(index.model()->index(row, 0, index)); const QModelIndex firstIndex = q->mapToSource(index.model()->index(row, 0, index));
const Akonadi::Collection collectionFirst = const auto collectionFirst = q->sourceModel()->data(firstIndex, Akonadi::EntityTreeModel::CollectionRole).value<Akonadi::Collection>();
q->sourceModel()->data(firstIndex, Akonadi::EntityTreeModel::CollectionRole).value<Akonadi::Collection>();
if (collectionFirst.isValid() && collectionFirst.hasAttribute<Akonadi::CollectionQuotaAttribute>()) { if (collectionFirst.isValid() && collectionFirst.hasAttribute<Akonadi::CollectionQuotaAttribute>()) {
const auto *quota = collectionFirst.attribute<Akonadi::CollectionQuotaAttribute>(); const auto *quota = collectionFirst.attribute<Akonadi::CollectionQuotaAttribute>();
@ -108,7 +107,7 @@ Qt::ItemFlags FolderTreeWidgetProxyModel::flags(const QModelIndex &index) const
if (d->enableCheck) { if (d->enableCheck) {
const QModelIndex sourceIndex = mapToSource(index); const QModelIndex sourceIndex = mapToSource(index);
const QModelIndex rowIndex = sourceIndex.sibling(sourceIndex.row(), 0); const QModelIndex rowIndex = sourceIndex.sibling(sourceIndex.row(), 0);
const Akonadi::Collection collection = sourceModel()->data(rowIndex, Akonadi::EntityTreeModel::CollectionRole).value<Akonadi::Collection>(); const auto collection = sourceModel()->data(rowIndex, Akonadi::EntityTreeModel::CollectionRole).value<Akonadi::Collection>();
if (!MailCommon::Util::isVirtualCollection(collection)) { if (!MailCommon::Util::isVirtualCollection(collection)) {
const Akonadi::AgentInstance instance = Akonadi::AgentManager::self()->instance(collection.resource()); const Akonadi::AgentInstance instance = Akonadi::AgentManager::self()->instance(collection.resource());
if (instance.status() == Akonadi::AgentInstance::Broken) { 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 QModelIndex modelIndex = sourceModel()->index(sourceRow, 0, sourceParent);
const Akonadi::Collection collection = sourceModel()->data(modelIndex, Akonadi::EntityTreeModel::CollectionRole).value<Akonadi::Collection>(); const auto collection = sourceModel()->data(modelIndex, Akonadi::EntityTreeModel::CollectionRole).value<Akonadi::Collection>();
if (!d->checker.isWantedCollection(collection)) { if (!d->checker.isWantedCollection(collection)) {
return false; return false;
} }
@ -212,7 +211,7 @@ QVariant FolderTreeWidgetProxyModel::data(const QModelIndex &index, int role) co
if (role == Qt::ForegroundRole) { if (role == Qt::ForegroundRole) {
const QModelIndex sourceIndex = mapToSource(index); const QModelIndex sourceIndex = mapToSource(index);
const QModelIndex rowIndex = sourceIndex.sibling(sourceIndex.row(), 0); const QModelIndex rowIndex = sourceIndex.sibling(sourceIndex.row(), 0);
const Akonadi::Collection collection = sourceModel()->data(rowIndex, Akonadi::EntityTreeModel::CollectionRole).value<Akonadi::Collection>(); const auto collection = sourceModel()->data(rowIndex, Akonadi::EntityTreeModel::CollectionRole).value<Akonadi::Collection>();
if (!MailCommon::Util::isVirtualCollection(collection)) { if (!MailCommon::Util::isVirtualCollection(collection)) {
const Akonadi::AgentInstance instance = Akonadi::AgentManager::self()->instance(collection.resource()); 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) { } else if (role == Qt::DisplayRole) {
const QModelIndex sourceIndex = mapToSource(index); const QModelIndex sourceIndex = mapToSource(index);
const QModelIndex rowIndex = sourceIndex.sibling(sourceIndex.row(), 0); const QModelIndex rowIndex = sourceIndex.sibling(sourceIndex.row(), 0);
const Akonadi::Collection collection = sourceModel()->data(rowIndex, Akonadi::EntityTreeModel::CollectionRole).value<Akonadi::Collection>(); const auto collection = sourceModel()->data(rowIndex, Akonadi::EntityTreeModel::CollectionRole).value<Akonadi::Collection>();
if (!MailCommon::Util::isVirtualCollection(collection)) { if (!MailCommon::Util::isVirtualCollection(collection)) {
const Akonadi::AgentInstance instance = Akonadi::AgentManager::self()->instance(collection.resource()); const Akonadi::AgentInstance instance = Akonadi::AgentManager::self()->instance(collection.resource());
if (collection.parentCollection() == Akonadi::Collection::root()) { if (collection.parentCollection() == Akonadi::Collection::root()) {
@ -244,7 +243,7 @@ QVariant FolderTreeWidgetProxyModel::data(const QModelIndex &index, int role) co
} else if (role == Qt::DecorationRole) { } else if (role == Qt::DecorationRole) {
const QModelIndex sourceIndex = mapToSource(index); const QModelIndex sourceIndex = mapToSource(index);
const QModelIndex rowIndex = sourceIndex.sibling(sourceIndex.row(), 0); const QModelIndex rowIndex = sourceIndex.sibling(sourceIndex.row(), 0);
const Akonadi::Collection collection = sourceModel()->data(rowIndex, Akonadi::EntityTreeModel::CollectionRole).value<Akonadi::Collection>(); const auto collection = sourceModel()->data(rowIndex, Akonadi::EntityTreeModel::CollectionRole).value<Akonadi::Collection>();
if (!MailCommon::Util::isVirtualCollection(collection)) { if (!MailCommon::Util::isVirtualCollection(collection)) {
if (collection.parentCollection() == Akonadi::Collection::root()) { if (collection.parentCollection() == Akonadi::Collection::root()) {
qreal percentage = 0.0; qreal percentage = 0.0;

@ -229,7 +229,7 @@ void BackupJob::processMessage(const Akonadi::Item &item)
return; return;
} }
const KMime::Message::Ptr message = item.payload<KMime::Message::Ptr>(); const auto message = item.payload<KMime::Message::Ptr>();
qCDebug(MAILCOMMON_LOG) << "Processing message with subject " << message->subject(false); qCDebug(MAILCOMMON_LOG) << "Processing message with subject " << message->subject(false);
const QByteArray messageData = message->encodedContent(); const QByteArray messageData = message->encodedContent();
const qint64 messageSize = messageData.size(); const qint64 messageSize = messageData.size();

@ -109,7 +109,7 @@ void ExpireJob::itemFetchResult(KJob *job)
continue; continue;
} }
const KMime::Message::Ptr mb = item.payload<KMime::Message::Ptr>(); const auto mb = item.payload<KMime::Message::Ptr>();
Akonadi::MessageStatus status; Akonadi::MessageStatus status;
status.setStatusFromFlags(item.flags()); status.setStatusFromFlags(item.flags());
if ((status.isImportant() || status.isToAct() || status.isWatched()) && SettingsIf->excludeImportantMailFromExpiry()) { if ((status.isImportant() || status.isToAct() || status.isWatched()) && SettingsIf->excludeImportantMailFromExpiry()) {

@ -33,7 +33,7 @@ bool SearchRuleDate::matches(const Akonadi::Item &item) const
if (!item.hasPayload<KMime::Message::Ptr>()) { if (!item.hasPayload<KMime::Message::Ptr>()) {
return false; return false;
} }
const KMime::Message::Ptr msg = item.payload<KMime::Message::Ptr>(); const auto msg = item.payload<KMime::Message::Ptr>();
const QDate msgDate = msg->date()->dateTime().date(); const QDate msgDate = msg->date()->dateTime().date();
const QDate dateValue = QDate::fromString(contents(), Qt::ISODate); const QDate dateValue = QDate::fromString(contents(), Qt::ISODate);

@ -37,7 +37,7 @@ bool SearchRuleNumerical::matches(const Akonadi::Item &item) const
return false; return false;
} }
const KMime::Message::Ptr msg = item.payload<KMime::Message::Ptr>(); const auto msg = item.payload<KMime::Message::Ptr>();
QString msgContents; QString msgContents;
qint64 numericalMsgContents = 0; qint64 numericalMsgContents = 0;

@ -83,7 +83,7 @@ bool SearchRuleString::matches(const Akonadi::Item &item) const
return false; return false;
} }
const KMime::Message::Ptr msg = item.payload<KMime::Message::Ptr>(); const auto msg = item.payload<KMime::Message::Ptr>();
Q_ASSERT(msg.data()); Q_ASSERT(msg.data());
if (!msg->hasHeader("From")) { if (!msg->hasHeader("From")) {

Loading…
Cancel
Save