From d1ea49cab3827e97530714d8d20a03895346ed4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Vr=C3=A1til?= Date: Sun, 5 Aug 2018 22:04:23 +0200 Subject: [PATCH] Add special rules for collection order for Unified Mailboxes agent Summary: Regardless of user's sort order preferences, always show the unified mailboxes agent first. The reason is that this is not a real mail resource, so it's hidden from various lists like the account sorting list etc. and I believe it is safe to assume that anyone who wants to use unified folders will want to have them at the top (it's all about easy access to folders after all). Reviewers: mlaurent Reviewed By: mlaurent Subscribers: ngraham, kde-pim Tags: #kde_pim Differential Revision: https://phabricator.kde.org/D15064 --- src/folder/entitycollectionorderproxymodel.cpp | 18 ++++++++++++------ src/util/mailutil.cpp | 5 +++++ src/util/mailutil.h | 2 ++ 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/folder/entitycollectionorderproxymodel.cpp b/src/folder/entitycollectionorderproxymodel.cpp index 4f97b98..133c813 100644 --- a/src/folder/entitycollectionorderproxymodel.cpp +++ b/src/folder/entitycollectionorderproxymodel.cpp @@ -59,6 +59,9 @@ public: 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 @@ public: } 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 @@ void EntityCollectionOrderProxyModel::clearRanks() 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 @@ bool EntityCollectionOrderProxyModel::lessThan(const QModelIndex &left, const QM 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.cpp b/src/util/mailutil.cpp index e7f38c4..a6e5578 100644 --- a/src/util/mailutil.cpp +++ b/src/util/mailutil.cpp @@ -178,6 +178,11 @@ bool MailCommon::Util::isMailAgent(const Akonadi::AgentInstance &instance, bool 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; diff --git a/src/util/mailutil.h b/src/util/mailutil.h index 2087f4f..58c6b24 100644 --- a/src/util/mailutil.h +++ b/src/util/mailutil.h @@ -74,6 +74,8 @@ Q_REQUIRED_RESULT MAILCOMMON_EXPORT Akonadi::AgentInstance::List agentInstances( 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. */