diff --git a/src/folder/entitycollectionorderproxymodel.cpp b/src/folder/entitycollectionorderproxymodel.cpp --- a/src/folder/entitycollectionorderproxymodel.cpp +++ b/src/folder/entitycollectionorderproxymodel.cpp @@ -59,6 +59,9 @@ rank = 6; } else if (MailCommon::Util::isVirtualCollection(collection)) { rank = 200; + } else if (collection.parentCollection() == Akonadi::Collection::root() && MailCommon::Util::isUnifiedMailboxesAgent(collection)) { + // special treatment for Unified Mailboxes: they are *always* on top + rank = 0; } else if (!topLevelOrder.isEmpty()) { if (collection.parentCollection() == Akonadi::Collection::root()) { const QString resource = collection.resource(); @@ -69,7 +72,7 @@ } const int order = topLevelOrder.indexOf(resource); if (order != -1) { - rank = order; + rank = order + 1; /* top-level rank "0" belongs to Unified Mailboxes */ } } } @@ -121,11 +124,9 @@ bool EntityCollectionOrderProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const { + const auto leftData = left.data(Akonadi::EntityTreeModel::CollectionRole).value(); + const auto rightData = right.data(Akonadi::EntityTreeModel::CollectionRole).value(); if (!d->manualSortingActive) { - Akonadi::Collection leftData - = left.data(Akonadi::EntityTreeModel::CollectionRole).value(); - Akonadi::Collection rightData - = right.data(Akonadi::EntityTreeModel::CollectionRole).value(); const int rankLeft = d->collectionRank(leftData); const int rankRight = d->collectionRank(rightData); @@ -138,7 +139,12 @@ return QSortFilterProxyModel::lessThan(left, right); } - return EntityOrderProxyModel::lessThan(left, right); + + if (MailCommon::Util::isUnifiedMailboxesAgent(leftData)) { + return true; + } else { + return EntityOrderProxyModel::lessThan(left, right); + } } void EntityCollectionOrderProxyModel::setManualSortingActive(bool active) diff --git a/src/util/mailutil.h b/src/util/mailutil.h --- a/src/util/mailutil.h +++ b/src/util/mailutil.h @@ -74,6 +74,8 @@ Q_REQUIRED_RESULT MAILCOMMON_EXPORT bool isMailAgent(const Akonadi::AgentInstance &instance, bool excludeMailTransport = true); +Q_REQUIRED_RESULT MAILCOMMON_EXPORT bool isUnifiedMailboxesAgent(const Akonadi::Collection &col); + /** * Returns the identity of the folder that contains the given Akonadi::Item. */ diff --git a/src/util/mailutil.cpp b/src/util/mailutil.cpp --- a/src/util/mailutil.cpp +++ b/src/util/mailutil.cpp @@ -178,6 +178,11 @@ return false; } +bool MailCommon::Util::isUnifiedMailboxesAgent(const Akonadi::Collection &col) +{ + return col.resource() == QLatin1String("akonadi_unifiedmailbox_agent"); +} + uint MailCommon::Util::folderIdentity(const Akonadi::Item &item) { uint id = 0;