diff --git a/src/ui/cryptoconfigmodule.h b/src/ui/cryptoconfigmodule.h --- a/src/ui/cryptoconfigmodule.h +++ b/src/ui/cryptoconfigmodule.h @@ -77,7 +77,11 @@ private: void init(Layout layout); - QStringList sortComponentList(const QStringList &components); + static QStringList sortConfigEntries(const QString *orderBegin, const QString *orderEnd, const QStringList &entries); + static QStringList sortComponentList(const QStringList &components); + +public: + static QStringList sortGroupList(const QString &moduleName, const QStringList &groups); 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 @@ -228,27 +228,18 @@ } } -QStringList Kleo::CryptoConfigModule::sortComponentList(const QStringList &components) +QStringList Kleo::CryptoConfigModule::sortConfigEntries(const QString *orderBegin, const QString *orderEnd, const QStringList &entries) { // components sorting algorithm: - // 1. components with hardcoded order - see below + // 1. components with predefined order (provided via orderBegin / orderEnd) // 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 (auto it = orderBegin; it != orderEnd; ++it) { + if (entries.contains(*it)) { + result.append(*it); } } - for (const auto &item : components) { + for (const auto &item : entries) { if (!result.contains(item)) { others.append(item); } @@ -258,6 +249,76 @@ return result; } +QStringList Kleo::CryptoConfigModule::sortComponentList(const QStringList &components) +{ + static const std::array order = { + QStringLiteral("gpg"), + QStringLiteral("gpgsm"), + QStringLiteral("gpg-agent"), + QStringLiteral("dirmngr"), + QStringLiteral("pinentry"), + QStringLiteral("scdaemon") + }; + return sortConfigEntries(order.begin(), order.end(), components); +} + +QStringList Kleo::CryptoConfigModule::sortGroupList(const QString &moduleName, const QStringList &groups) +{ + if (moduleName == QStringLiteral("gpg")) { + static const std::array order = { + QStringLiteral("Keyserver"), + QStringLiteral("Configuration"), + QStringLiteral("Monitor"), + QStringLiteral("Debug"), + }; + return sortConfigEntries(order.begin(), order.end(), groups); + } else if (moduleName == QStringLiteral("gpgsm")) { + static const std::array order = { + QStringLiteral("Security"), + QStringLiteral("Configuration"), + QStringLiteral("Monitor"), + QStringLiteral("Debug"), + }; + return sortConfigEntries(order.begin(), order.end(), groups); + } else if (moduleName == QStringLiteral("gpg-agent")) { + static const std::array order = { + QStringLiteral("Security"), + QStringLiteral("Passphrase policy"), + QStringLiteral("Configuration"), + QStringLiteral("Monitor"), + QStringLiteral("Debug"), + }; + return sortConfigEntries(order.begin(), order.end(), groups); + } else if (moduleName == QStringLiteral("dirmngr")) { + static const std::array order = { + QStringLiteral("Keyserver"), + QStringLiteral("HTTP"), + QStringLiteral("LDAP"), + QStringLiteral("OCSP"), + QStringLiteral("Tor"), + QStringLiteral("Enforcement"), + QStringLiteral("Configuration"), + QStringLiteral("Format"), + QStringLiteral("Monitor"), + QStringLiteral("Debug"), + }; + return sortConfigEntries(order.begin(), order.end(), groups); + } else if (moduleName == QStringLiteral("scdaemon")) { + static const std::array order = { + QStringLiteral("Monitor"), + QStringLiteral("Configuration"), + QStringLiteral("Security"), + QStringLiteral("Debug"), + }; + return sortConfigEntries(order.begin(), order.end(), groups); + } else { + qCDebug(KLEO_UI_LOG) << "Configuration groups order is not defined for " << moduleName; + QStringList result(groups); + result.sort(); + return result; + } +} + bool Kleo::CryptoConfigModule::hasError() const { return mComponentGUIs.empty(); @@ -307,7 +368,7 @@ mComponent(component) { QGridLayout *glay = new QGridLayout(this); - const QStringList groups = mComponent->groupList(); + const QStringList groups = module->sortGroupList(mComponent->name(), mComponent->groupList()); if (groups.size() > 1) { glay->setColumnMinimumWidth(0, KDHorizontalLine::indentHint()); for (QStringList::const_iterator it = groups.begin(), end = groups.end(); it != end; ++it) {