Commit d836c36b authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Modernize code

parent d7ca8188
Pipeline #60630 passed with stage
in 28 minutes and 58 seconds
......@@ -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<Akonadi::Collection>();
const auto favoriteCollection = index.data(EntityTreeModel::CollectionRole).value<Akonadi::Collection>();
QVERIFY(favoriteCollection.isValid());
collectionIds.push_back(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)
const QStringList folderNames = collectNames(mCollectionModel);
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"));
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<Collection>();
const auto newParentCollection = res2Index.data(EntityTreeModel::CollectionRole).value<Collection>();
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<Collection>();
auto collection = idx.data(EntityTreeModel::CollectionRole).value<Collection>();
QVERIFY2(collection.isValid(), qPrintable(idx.data().toString()));
}
}
......
......@@ -37,7 +37,7 @@ FilterAction::ReturnCode FilterActionAddHeader::process(ItemContext &context, bo
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());
if (!header) {
......
......@@ -51,7 +51,7 @@ FilterAction::ReturnCode FilterActionAddToAddressBook::process(ItemContext &cont
return ErrorButGoOn;
}
const KMime::Message::Ptr msg = context.item().payload<KMime::Message::Ptr>();
const auto msg = context.item().payload<KMime::Message::Ptr>();
QString headerLine;
switch (mHeaderType) {
......
......@@ -43,7 +43,7 @@ FilterAction::ReturnCode FilterActionForward::process(ItemContext &context, bool
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
// which applies to sent messages
if (MessageCore::StringUtil::addressIsInAddressList(mParameter, QStringList(msg->to()->asUnicodeString()))) {
......
......@@ -46,7 +46,7 @@ FilterAction::ReturnCode FilterActionRemoveHeader::process(ItemContext &context,
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());
bool headerRemove = false;
while (msg->removeHeader(param.constData())) {
......
......@@ -26,7 +26,7 @@ FilterAction::ReturnCode FilterActionReplyTo::process(ItemContext &context, bool
if (mParameter.isEmpty()) {
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");
KMime::Headers::Base *header = KMime::Headers::createHeader(replyTo);
if (!header) {
......
......@@ -56,7 +56,7 @@ FilterAction::ReturnCode FilterActionRewriteHeader::process(ItemContext &context
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());
KMime::Headers::Base *header = msg->headerByType(param.constData());
......
......@@ -24,7 +24,7 @@ FilterActionSendReceipt::FilterActionSendReceipt(QObject *parent)
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());
factory.setFolderIdentity(Util::folderIdentity(context.item()));
......
......@@ -56,7 +56,7 @@ FilterAction::ReturnCode FilterActionSetIdentity::process(ItemContext &context,
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;
if (auto hrd = msg->headerByType("X-KMail-Identity")) {
currentId = hrd->asUnicodeString().trimmed().toUInt();
......
......@@ -70,7 +70,7 @@ FilterAction::ReturnCode FilterActionSetTransport::process(ItemContext &context,
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");
header->fromUnicodeString(argsAsString(), "utf-8");
msg->setHeader(header);
......
......@@ -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<KMime::Message::Ptr>();
const auto aMsg = context.item().payload<KMime::Message::Ptr>();
Q_ASSERT(aMsg);
if (mParameter.isEmpty()) {
......
......@@ -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<Akonadi::Collection>();
const auto collection = model->data(index, Akonadi::EntityTreeModel::CollectionRole).value<Akonadi::Collection>();
if (!collection.isValid() || Util::isVirtualCollection(collection)) {
continue;
......
......@@ -424,7 +424,7 @@ bool FolderTreeView::trySelectNextUnreadFolder(const QModelIndex &current, Searc
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()) {
continue;
}
......@@ -491,7 +491,7 @@ bool FolderTreeView::isUnreadFolder(const QModelIndex &current, QModelIndex &ind
}
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.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<Akonadi::Collection>();
const auto collection = current.model()->data(current, Akonadi::EntityTreeModel::CollectionRole).value<Akonadi::Collection>();
return collection;
}
return Akonadi::Collection();
......
......@@ -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<Akonadi::Collection>();
const auto collection = index.model()->data(index, Akonadi::EntityTreeModel::CollectionRole).value<Akonadi::Collection>();
if (collection.isValid()) {
collections.append(collection);
}
......
......@@ -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<Akonadi::Collection>();
const auto collectionFirst = q->sourceModel()->data(firstIndex, Akonadi::EntityTreeModel::CollectionRole).value<Akonadi::Collection>();
if (collectionFirst.isValid() && collectionFirst.hasAttribute<Akonadi::CollectionQuotaAttribute>()) {
const auto *quota = collectionFirst.attribute<Akonadi::CollectionQuotaAttribute>();
......@@ -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<Akonadi::Collection>();
const auto collection = sourceModel()->data(rowIndex, Akonadi::EntityTreeModel::CollectionRole).value<Akonadi::Collection>();
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<Akonadi::Collection>();
const auto collection = sourceModel()->data(modelIndex, Akonadi::EntityTreeModel::CollectionRole).value<Akonadi::Collection>();
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<Akonadi::Collection>();
const auto collection = sourceModel()->data(rowIndex, Akonadi::EntityTreeModel::CollectionRole).value<Akonadi::Collection>();
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<Akonadi::Collection>();
const auto collection = sourceModel()->data(rowIndex, Akonadi::EntityTreeModel::CollectionRole).value<Akonadi::Collection>();
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<Akonadi::Collection>();
const auto collection = sourceModel()->data(rowIndex, Akonadi::EntityTreeModel::CollectionRole).value<Akonadi::Collection>();
if (!MailCommon::Util::isVirtualCollection(collection)) {
if (collection.parentCollection() == Akonadi::Collection::root()) {
qreal percentage = 0.0;
......
......@@ -229,7 +229,7 @@ void BackupJob::processMessage(const Akonadi::Item &item)
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);
const QByteArray messageData = message->encodedContent();
const qint64 messageSize = messageData.size();
......
......@@ -109,7 +109,7 @@ void ExpireJob::itemFetchResult(KJob *job)
continue;
}
const KMime::Message::Ptr mb = item.payload<KMime::Message::Ptr>();
const auto mb = item.payload<KMime::Message::Ptr>();
Akonadi::MessageStatus status;
status.setStatusFromFlags(item.flags());
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>()) {
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 dateValue = QDate::fromString(contents(), Qt::ISODate);
......
......@@ -37,7 +37,7 @@ bool SearchRuleNumerical::matches(const Akonadi::Item &item) const
return false;
}
const KMime::Message::Ptr msg = item.payload<KMime::Message::Ptr>();
const auto msg = item.payload<KMime::Message::Ptr>();
QString msgContents;
qint64 numericalMsgContents = 0;
......
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