/** \file OptionEngine.cpp \brief Define the class of the event dispatcher \author alpha_one_x86 \version 0.3 \date 2010 \licence GPL3, see the file COPYING */ #include #include #include #include #include #include #include #include "OptionEngine.h" /// \todo async the options write /// \brief Initiate the option, load from backend OptionEngine::OptionEngine() { ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"start"); //locate the settings #ifdef ULTRACOPIER_VERSION_PORTABLE resources=ResourcesManager::getInstance(); QString settingsFilePath=resources->getWritablePath(); if(settingsFilePath!="") settings = new QSettings(settingsFilePath+"Ultracopier.conf",QSettings::IniFormat); else settings = NULL; #else // ULTRACOPIER_VERSION_PORTABLE settings = new QSettings("Ultracopier","Ultracopier"); #endif // ULTRACOPIER_VERSION_PORTABLE if(settings!=NULL) { //do some write test if(settings->status()!=QSettings::NoError) { delete settings; settings=NULL; } else if(!settings->isWritable()) { delete settings; settings=NULL; } else { settings->setValue("test","test"); if(settings->status()!=QSettings::NoError) { delete settings; settings=NULL; } else { settings->remove("test"); if(settings->status()!=QSettings::NoError) { delete settings; settings=NULL; } } } } //set the backend if(settings==NULL) { #ifdef ULTRACOPIER_VERSION_PORTABLE resources->disableWritablePath(); #endif // ULTRACOPIER_VERSION_PORTABLE currentBackend=Memory; } else currentBackend=File; } /// \brief Destroy the option OptionEngine::~OptionEngine() { ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"start"); ResourcesManager::destroyInstanceAtTheLastCall(); } /// \brief To add option group to options bool OptionEngine::addOptionGroup(const QString &groupName,const QList > &KeysList) { ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"start(\""+groupName+"\",[...])"); //search if previous with the same name exists indexGroup=0; loop_size=GroupKeysList.size(); while(indexGroupbeginGroup(groupName); //browse all key, and append it to the key index=0; QList KeyListTemp; loop_size=KeysList.size(); while(indexcontains(theCurrentKey.variableName))//if file backend, load the default value from the file theCurrentKey.currentValue=settings->value(theCurrentKey.variableName); else //or if not found load the default value and set into the file { theCurrentKey.currentValue=theCurrentKey.defaultValue; //to switch default value if is unchanged //settings->setValue(theCurrentKey.variableName,theCurrentKey.defaultValue); } if(settings->status()!=QSettings::NoError) { ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Warning,"Have writing error, switch to memory only options"); #ifdef ULTRACOPIER_VERSION_PORTABLE resources->disableWritablePath(); #endif // ULTRACOPIER_VERSION_PORTABLE currentBackend=Memory; } GroupKeysList[indexGroup].KeysList << theCurrentKey; index++; } //if the backend is file, leave into the group if(currentBackend==File) settings->endGroup(); return true; } /// \brief To remove option group to options, remove the widget need be do into the calling object bool OptionEngine::removeOptionGroup(const QString &groupName) { ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"start, groupName: "+groupName); indexGroup=0; loop_size=GroupKeysList.size(); while(indexGroupbeginGroup(groupName); settings->setValue(variableName,value); settings->endGroup(); if(settings->status()!=QSettings::NoError) { ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Warning,"Have writing error, switch to memory only options"); #ifdef ULTRACOPIER_VERSION_PORTABLE resources->disableWritablePath(); #endif // ULTRACOPIER_VERSION_PORTABLE currentBackend=Memory; } } emit newOptionValue(groupName,variableName,value); } return; } indexGroupKey++; } ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Warning,"value not found, internal bug, groupName: \""+groupName+"\", variableName: \""+variableName+"\", value: \""+value.toString()+"\""); return; } indexGroup++; } ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Warning,"group \""+groupName+"\" not found, internal bug, groupName: \""+groupName+"\", variableName: \""+variableName+"\", value: \""+value.toString()+"\""); } //the reset of right value of widget need be do into the calling object void OptionEngine::internal_resetToDefaultValue() { ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"start"); int indexGroup=0; while(indexGroup