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
wilder
Daniel Vrátil 8 years ago
parent 34ad31f3f5
commit d1ea49cab3
  1. 18
      src/folder/entitycollectionorderproxymodel.cpp
  2. 5
      src/util/mailutil.cpp
  3. 2
      src/util/mailutil.h

@ -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<Akonadi::Collection>();
const auto rightData = right.data(Akonadi::EntityTreeModel::CollectionRole).value<Akonadi::Collection>();
if (!d->manualSortingActive) {
Akonadi::Collection leftData
= left.data(Akonadi::EntityTreeModel::CollectionRole).value<Akonadi::Collection>();
Akonadi::Collection rightData
= right.data(Akonadi::EntityTreeModel::CollectionRole).value<Akonadi::Collection>();
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)

@ -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;

@ -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.
*/

Loading…
Cancel
Save