diff --git a/src/ui/cryptoconfigmodule.h b/src/ui/cryptoconfigmodule.h --- a/src/ui/cryptoconfigmodule.h +++ b/src/ui/cryptoconfigmodule.h @@ -77,6 +77,7 @@ private: void init(Layout layout); + QStringList sortComponentList(const QStringList &components); private: QGpgME::CryptoConfig *mConfig = nullptr; diff --git a/src/ui/cryptoconfigmodule.cpp b/src/ui/cryptoconfigmodule.cpp --- a/src/ui/cryptoconfigmodule.cpp +++ b/src/ui/cryptoconfigmodule.cpp @@ -44,6 +44,7 @@ #include #include #include +#include #include @@ -161,7 +162,7 @@ addPage(w, configOK ? QString() : i18n("GpgConf Error")); } - const QStringList components = config->componentList(); + const QStringList components = sortComponentList(config->componentList()); for (QStringList::const_iterator it = components.begin(); it != components.end(); ++it) { //qCDebug(KLEO_UI_LOG) <<"Component" << (*it).toLocal8Bit() <<":"; QGpgME::CryptoConfigComponent *comp = config->component(*it); @@ -227,6 +228,37 @@ } } +QStringList Kleo::CryptoConfigModule::sortComponentList(const QStringList &components) { + // components sorting algorithm: + // 1. components with hardcoded order - see below + // 2. other components sorted alphabetically + const QStringList order = {"gpg", "gpgsm", "gpg-agent", "dirmngr", "pinentry", "scdaemon"}; + +#if QT_VERSION >= QT_VERSION_CHECK(5,14,0) + QSet input_set = QSet(components.begin(), components.end()); + QSet order_set = QSet(order.begin(), order.end()); +#else + QSet input_set = QSet::fromList(components); + QSet order_set = QSet::fromList(order); +#endif + + QStringList result; + + // add components with predefined order + for (const auto &item: order) { + if (input_set.contains(item)) { + result.append(item); + } + } + + // add the rest of components with sorting + QStringList others = (input_set - order_set).values(); + others.sort(); + result.append(others); + + return result; +} + bool Kleo::CryptoConfigModule::hasError() const { return mComponentGUIs.empty();