11#include <config-libkleo.h> 
   13#include "cryptoconfig.h" 
   14#include "cryptoconfig_p.h" 
   18#include <QGpgME/CryptoConfig> 
   19#include <QGpgME/Protocol> 
   21#include <unordered_map> 
   23using namespace QGpgME;
 
   25static std::unordered_map<std::string, std::unordered_map<std::string, int>> fakeCryptoConfigIntValues;
 
   26static std::unordered_map<std::string, std::unordered_map<std::string, QString>> fakeCryptoConfigStringValues;
 
   28bool Kleo::getCryptoConfigBoolValue(
const char *componentName, 
const char *entryName)
 
   30    const CryptoConfig *
const config = cryptoConfig();
 
   34    const CryptoConfigEntry *
const entry = getCryptoConfigEntry(config, componentName, entryName);
 
   35    if (entry && entry->argType() == CryptoConfigEntry::ArgType_None && !entry->isList()) {
 
   36        return entry->boolValue();
 
   41int Kleo::getCryptoConfigIntValue(
const char *componentName, 
const char *entryName, 
int defaultValue)
 
   43    if (!fakeCryptoConfigIntValues.empty()) {
 
   44        const auto componentIt = fakeCryptoConfigIntValues.find(componentName);
 
   45        if (componentIt != std::end(fakeCryptoConfigIntValues)) {
 
   46            const auto entryIt = componentIt->second.find(entryName);
 
   47            if (entryIt != std::end(componentIt->second)) {
 
   48                return entryIt->second;
 
   53    const CryptoConfig *
const config = cryptoConfig();
 
   57    const CryptoConfigEntry *
const entry = getCryptoConfigEntry(config, componentName, entryName);
 
   58    if (entry && entry->argType() == CryptoConfigEntry::ArgType_Int) {
 
   59        return entry->intValue();
 
   64QString Kleo::getCryptoConfigStringValue(
const char *componentName, 
const char *entryName)
 
   66    if (!fakeCryptoConfigStringValues.empty()) {
 
   67        const auto componentIt = fakeCryptoConfigStringValues.find(componentName);
 
   68        if (componentIt != std::end(fakeCryptoConfigStringValues)) {
 
   69            const auto entryIt = componentIt->second.find(entryName);
 
   70            if (entryIt != std::end(componentIt->second)) {
 
   71                return entryIt->second;
 
   76    const CryptoConfig *
const config = cryptoConfig();
 
   80    const CryptoConfigEntry *
const entry = getCryptoConfigEntry(config, componentName, entryName);
 
   81    if (entry && entry->argType() == CryptoConfigEntry::ArgType_String) {
 
   82        return entry->stringValue();
 
   87QList<QUrl> Kleo::getCryptoConfigUrlList(
const char *componentName, 
const char *entryName)
 
   89    const CryptoConfig *
const config = cryptoConfig();
 
   93    const CryptoConfigEntry *
const entry = getCryptoConfigEntry(config, componentName, entryName);
 
   94    if (entry && entry->isList() && (entry->argType() == CryptoConfigEntry::ArgType_LDAPURL || entry->argType() == CryptoConfigEntry::ArgType_Path)) {
 
   95        return entry->urlValueList();
 
  100void Kleo::Private::setFakeCryptoConfigIntValue(
const std::string &componentName, 
const std::string &entryName, 
int fakeValue)
 
  102    fakeCryptoConfigIntValues[componentName][entryName] = fakeValue;
 
  105void Kleo::Private::clearFakeCryptoConfigIntValue(
const std::string &componentName, 
const std::string &entryName)
 
  107    auto &entryMap = fakeCryptoConfigIntValues[componentName];
 
  108    entryMap.erase(entryName);
 
  109    if (entryMap.empty()) {
 
  110        fakeCryptoConfigIntValues.erase(componentName);
 
  114void Kleo::Private::setFakeCryptoConfigStringValue(
const std::string &componentName, 
const std::string &entryName, 
const QString &fakeValue)
 
  116    fakeCryptoConfigStringValues[componentName][entryName] = fakeValue;
 
  119void Kleo::Private::clearFakeCryptoConfigStringValue(
const std::string &componentName, 
const std::string &entryName)
 
  121    auto &entryMap = fakeCryptoConfigStringValues[componentName];
 
  122    entryMap.
erase(entryName);
 
  123    if (entryMap.empty()) {
 
  124        fakeCryptoConfigStringValues.erase(componentName);
 
iterator erase(const_iterator first, const_iterator last)