summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMontel Laurent <[email protected]>2015-11-18 09:17:08 +0100
committerMontel Laurent <[email protected]>2015-11-18 09:17:08 +0100
commit78fac0ea769b26a5c6e68e590ab8bba810079868 (patch)
tree64d486b129dc3a45855700ab886ccd5c7af3b31a
parent73a0c6464db894d91691508b2ce60d166138cd16 (diff)
Improve sorting
-rw-r--r--kmail/widgets/kactionmenuaccount.cpp26
-rw-r--r--kmail/widgets/kactionmenuaccount.h24
2 files changed, 50 insertions, 0 deletions
diff --git a/kmail/widgets/kactionmenuaccount.cpp b/kmail/widgets/kactionmenuaccount.cpp
index fe46c18..2a5b12a 100644
--- a/kmail/widgets/kactionmenuaccount.cpp
+++ b/kmail/widgets/kactionmenuaccount.cpp
@@ -39,6 +39,14 @@ KActionMenuAccount::~KActionMenuAccount()
}
+void KActionMenuAccount::setAccountOrder(const QStringList &identifier)
+{
+ if (mOrderIdentifier != identifier) {
+ mOrderIdentifier = identifier;
+ mInitialized = false;
+ }
+}
+
void KActionMenuAccount::slotSelectAccount(QAction *act)
{
if (!act) {
@@ -64,17 +72,35 @@ void KActionMenuAccount::slotCheckTransportMenu()
}
}
+
+bool orderAgentIdentifier(const AgentIdentifier &lhs, const AgentIdentifier &rhs)
+{
+ if ((lhs.mIndex == -1) && (rhs.mIndex == -1)) {
+ return lhs.mName < rhs.mName;
+ }
+ if (lhs.mIndex != rhs.mIndex) {
+ return lhs.mIndex < rhs.mIndex;
+ }
+ // we can't have same index but fallback
+ return true;
+}
+
void KActionMenuAccount::updateAccountMenu()
{
if (mInitialized) {
menu()->clear();
const Akonadi::AgentInstance::List lst = MailCommon::Util::agentInstances();
+ QVector<AgentIdentifier> vector;
+
QMap<QString, QString> listAgent;
Q_FOREACH (const Akonadi::AgentInstance &type, lst) {
// Explicitly make a copy, as we're not changing values of the list but only
// the local copy which is passed to action.
listAgent.insert(QString(type.name()).replace(QLatin1Char('&'), QStringLiteral("&&")), type.identifier());
+ AgentIdentifier id(type.identifier(), QString(type.name()).replace(QLatin1Char('&'), QStringLiteral("&&")));
+ vector << id;
}
+ qSort( vector.begin(), vector.end(), orderAgentIdentifier);
QMapIterator<QString, QString> i(listAgent);
while (i.hasNext()) {
i.next();
diff --git a/kmail/widgets/kactionmenuaccount.h b/kmail/widgets/kactionmenuaccount.h
index eacaf38..14fd990 100644
--- a/kmail/widgets/kactionmenuaccount.h
+++ b/kmail/widgets/kactionmenuaccount.h
@@ -20,6 +20,27 @@
#include <KActionMenu>
+class AgentIdentifier
+{
+public:
+ AgentIdentifier()
+ : mIndex(-1)
+ {
+
+ }
+
+ AgentIdentifier(const QString &identifier, const QString &name, int index = -1)
+ : mIdentifier(identifier),
+ mName(name),
+ mIndex(index)
+ {
+
+ }
+ QString mIdentifier;
+ QString mName;
+ int mIndex;
+};
+
class KActionMenuAccount : public KActionMenu
{
Q_OBJECT
@@ -27,11 +48,14 @@ public:
explicit KActionMenuAccount(QObject *parent = Q_NULLPTR);
~KActionMenuAccount();
+ void setAccountOrder(const QStringList &identifier);
+
private Q_SLOTS:
void updateAccountMenu();
void slotCheckTransportMenu();
void slotSelectAccount(QAction *act);
private:
+ QStringList mOrderIdentifier;
bool mInitialized;
};