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 @@ -65,6 +65,7 @@ #include #include +#include using namespace Kleo; @@ -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,36 @@ } } +QStringList Kleo::CryptoConfigModule::sortComponentList(const QStringList &components) +{ + // components sorting algorithm: + // 1. components with hardcoded order - see below + // 2. other components sorted alphabetically + static const std::array order = { + QStringLiteral("gpg"), + QStringLiteral("gpgsm"), + QStringLiteral("gpg-agent"), + QStringLiteral("dirmngr"), + QStringLiteral("pinentry"), + QStringLiteral("scdaemon") + }; + + QStringList result, others; + for (const auto &item : order) { + if (components.contains(item)) { + result.append(item); + } + } + for (const auto &item : components) { + if (!result.contains(item)) { + others.append(item); + } + } + others.sort(); + result.append(others); + return result; +} + bool Kleo::CryptoConfigModule::hasError() const { return mComponentGUIs.empty();