diff options
author | Thomas Preud'homme <robotux@celest.fr> | 2018-02-23 23:49:48 +0000 |
---|---|---|
committer | Thomas Preud'homme <robotux@celest.fr> | 2018-02-23 23:49:48 +0000 |
commit | bd56579c7d9de94c17287adefa118290e6b7ba33 (patch) | |
tree | 666d7d0b6945b442573b7a3145969f66a53aa460 /OptionEngine.cpp | |
parent | b3c8bdcc0d1e4b2ab298847a7902b6d60410a5bc (diff) |
New upstream version 1.4.0.3
Diffstat (limited to 'OptionEngine.cpp')
-rw-r--r-- | OptionEngine.cpp | 103 |
1 files changed, 53 insertions, 50 deletions
diff --git a/OptionEngine.cpp b/OptionEngine.cpp index f86607f..ad2cf7c 100644 --- a/OptionEngine.cpp +++ b/OptionEngine.cpp @@ -19,7 +19,7 @@ OptionEngine::OptionEngine() { //locate the settings #ifdef ULTRACOPIER_VERSION_PORTABLE - QString settingsFilePath=ResourcesManager::resourcesManager->getWritablePath(); + QString settingsFilePath=QString::fromStdString(ResourcesManager::resourcesManager->getWritablePath()); if(settingsFilePath!="") settings = new QSettings(settingsFilePath+QStringLiteral("Ultracopier.conf"),QSettings::IniFormat); else @@ -77,23 +77,22 @@ OptionEngine::~OptionEngine() } /// \brief To add option group to options -bool OptionEngine::addOptionGroup(const QString &groupName,const QList<QPair<QString, QVariant> > &KeysList) +bool OptionEngine::addOptionGroup(const std::string &groupName,const std::vector<std::pair<std::string, std::string> > &KeysList) { - ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,QStringLiteral("start(\"")+groupName+QStringLiteral("\",[...])")); + ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,"start(\""+groupName+"\",[...])"); //search if previous with the same name exists - if(GroupKeysList.contains(groupName)) + if(GroupKeysList.find(groupName)!=GroupKeysList.cend()) { - ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,QStringLiteral("group already used previously")); + ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,"group already used previously"); return false; } //if the backend is file, enter into the group if(currentBackend==File) - settings->beginGroup(groupName); + settings->beginGroup(QString::fromStdString(groupName)); //browse all key, and append it to the key - int index=0; + unsigned int index=0; //QList<OptionEngineGroupKey> KeyListTemp; - const int &loop_size=KeysList.size(); - while(index<loop_size) + while(index<KeysList.size()) { OptionEngineGroupKey theCurrentKey; theCurrentKey.defaultValue=KeysList.at(index).second; @@ -102,9 +101,9 @@ bool OptionEngine::addOptionGroup(const QString &groupName,const QList<QPair<QSt theCurrentKey.currentValue=theCurrentKey.defaultValue; else { - if(settings->contains(KeysList.at(index).first))//if file backend, load the default value from the file + if(settings->contains(QString::fromStdString(KeysList.at(index).first)))//if file backend, load the default value from the file { - theCurrentKey.currentValue=settings->value(KeysList.at(index).first); + theCurrentKey.currentValue=settings->value(QString::fromStdString(KeysList.at(index).first)).toString().toStdString(); #ifdef ULTRACOPIER_DEBUG if(theCurrentKey.currentValue!=theCurrentKey.defaultValue) { @@ -114,7 +113,7 @@ bool OptionEngine::addOptionGroup(const QString &groupName,const QList<QPair<QSt } else #endif - ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Information,QString("The current key: %1, group: %2, have value: %3").arg(groupName).arg(KeysList.at(index).first).arg(theCurrentKey.currentValue.toString())); + ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Information,"The current key: "+groupName+", group: "+KeysList.at(index).first+", have value: "+theCurrentKey.currentValue); } #endif } @@ -143,53 +142,62 @@ bool OptionEngine::addOptionGroup(const QString &groupName,const QList<QPair<QSt } /// \brief To remove option group to options, remove the widget need be do into the calling object -bool OptionEngine::removeOptionGroup(const QString &groupName) +bool OptionEngine::removeOptionGroup(const std::string &groupName) { - ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,QStringLiteral("start, groupName: ")+groupName); - if(GroupKeysList.remove(groupName)!=1) - ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Critical,QStringLiteral("value not found, internal bug, groupName: ")+groupName); + ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,"start, groupName: "+groupName); + if(GroupKeysList.erase(groupName)!=1) + ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Critical,"value not found, internal bug, groupName: "+groupName); return false; } /// \brief To get option value -QVariant OptionEngine::getOptionValue(const QString &groupName,const QString &variableName) const +std::string OptionEngine::getOptionValue(const std::string &groupName,const std::string &variableName) const { - if(GroupKeysList.contains(groupName)) + if(GroupKeysList.find(groupName)!=GroupKeysList.cend()) { - if(GroupKeysList.value(groupName).contains(variableName)) - return GroupKeysList.value(groupName).value(variableName).currentValue; - QMessageBox::critical(NULL,"Internal error",tr("The variable was not found: %1 %2").arg(groupName).arg(variableName)); + const std::unordered_map<std::string,OptionEngineGroupKey> &optionEngineGroupKey=GroupKeysList.at(groupName); + if(optionEngineGroupKey.find(variableName)!=optionEngineGroupKey.cend()) + return optionEngineGroupKey.at(variableName).currentValue; + QMessageBox::critical(NULL,"Internal error",tr("The variable was not found: %1 %2") + .arg(QString::fromStdString(groupName)) + .arg(QString::fromStdString(variableName)) + ); ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Critical,"value not found, internal bug, groupName: "+groupName+", variableName: "+variableName); - return QVariant(); + return std::string(); } - QMessageBox::critical(NULL,"Internal error",tr("The variable was not found: %1 %2").arg(groupName).arg(variableName)); - ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Critical,QString("The variable was not found: %1 %2").arg(groupName).arg(variableName)); + QMessageBox::critical(NULL,"Internal error",tr("The variable was not found: %1 %2").arg(QString::fromStdString(groupName)).arg(QString::fromStdString(variableName))); + ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Critical,QString("The variable was not found: %1 %2") + .arg(QString::fromStdString(groupName)) + .arg(QString::fromStdString(variableName)) + .toStdString() + ); //return default value - return QVariant(); + return std::string(); } /// \brief To set option value -void OptionEngine::setOptionValue(const QString &groupName,const QString &variableName,const QVariant &value) +void OptionEngine::setOptionValue(const std::string &groupName,const std::string &variableName,const std::string &value) { - ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,QStringLiteral("groupName: \"")+groupName+QStringLiteral("\", variableName: \"")+variableName+QStringLiteral("\", value: \"")+value.toString()+QStringLiteral("\"")); + ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,"groupName: \""+groupName+"\", variableName: \""+variableName+"\", value: \""+value+"\""); - if(GroupKeysList.contains(groupName)) + if(GroupKeysList.find(groupName)!=GroupKeysList.cend()) { - if(GroupKeysList.value(groupName).contains(variableName)) + const std::unordered_map<std::string,OptionEngineGroupKey> &group=GroupKeysList.at(groupName); + if(group.find(variableName)!=group.cend()) { //prevent re-write the same value into the variable - if(GroupKeysList.value(groupName).value(variableName).currentValue==value) + if(group.at(variableName).currentValue==value) return; //write ONLY the new value GroupKeysList[groupName][variableName].currentValue=value; if(currentBackend==File) { - settings->beginGroup(groupName); - settings->setValue(variableName,value); + settings->beginGroup(QString::fromStdString(groupName)); + settings->setValue(QString::fromStdString(variableName),QString::fromStdString(value)); settings->endGroup(); if(settings->status()!=QSettings::NoError) { - ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Warning,QStringLiteral("Have writing error, switch to memory only options")); + ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Warning,"Have writing error, switch to memory only options"); #ifdef ULTRACOPIER_VERSION_PORTABLE ResourcesManager::resourcesManager->disableWritablePath(); #endif // ULTRACOPIER_VERSION_PORTABLE @@ -199,37 +207,32 @@ void OptionEngine::setOptionValue(const QString &groupName,const QString &variab emit newOptionValue(groupName,variableName,value); return; } - QMessageBox::critical(NULL,"Internal error",tr("The variable was not found: %1 %2").arg(groupName).arg(variableName)); + QMessageBox::critical(NULL,"Internal error",tr("The variable was not found: %1 %2").arg(QString::fromStdString(groupName)).arg(QString::fromStdString(variableName))); ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Critical,"value not found, internal bug, groupName: "+groupName+", variableName: "+variableName); return; } - QMessageBox::critical(NULL,"Internal error",tr("The variable was not found: %1 %2").arg(groupName).arg(variableName)); - ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Critical,QString("The variable was not found: %1 %2").arg(groupName).arg(variableName)); + QMessageBox::critical(NULL,"Internal error",tr("The variable was not found: %1 %2").arg(QString::fromStdString(groupName)).arg(QString::fromStdString(variableName))); + ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Critical,"The variable was not found: "+groupName+" "+variableName); } //the reset of right value of widget need be do into the calling object void OptionEngine::internal_resetToDefaultValue() { - ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,QStringLiteral("start")); + ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,"start"); - QHash<QString,QHash<QString,OptionEngineGroupKey> >::const_iterator i = GroupKeysList.constBegin(); - QHash<QString,QHash<QString,OptionEngineGroupKey> >::const_iterator i_end = GroupKeysList.constEnd(); - QHash<QString,OptionEngineGroupKey>::const_iterator j; - QHash<QString,OptionEngineGroupKey>::const_iterator j_end; - while (i != i_end) + for(auto& n:GroupKeysList) { - j = i.value().constBegin(); - j_end = i.value().constEnd(); - while (j != j_end) + const std::string &firstKey=n.first; + for(auto& m:n.second) { - if(j.value().currentValue!=j.value().defaultValue) + const std::string &secondKey=m.first; + OptionEngineGroupKey &o=m.second; + if(o.currentValue!=o.defaultValue) { - GroupKeysList[i.key()][j.key()].currentValue=j.value().defaultValue; - emit newOptionValue(i.key(),j.key(),j.value().currentValue); + o.currentValue=o.defaultValue; + emit newOptionValue(firstKey,secondKey,o.currentValue); } - ++j; } - ++i; } } |