diff -r 7a96bd401351 -r 9aadd0f58300 settings.cpp --- a/settings.cpp Sun Jan 30 12:58:47 2005 +0000 +++ b/settings.cpp Tue Aug 15 11:42:10 2006 +0000 @@ -1,8 +1,114 @@ #include +#include #include "settings.h" -#include "misc.h" +#include "file.h" using namespace std; + +///////////////////////////////////////////////////////////////// +// SimpleSettings +///////////////////////////////////////////////////////////////// +SimpleSettings::SimpleSettings() +{ + clear(); +} + +SimpleSettings::~SimpleSettings() +{ +} + +void SimpleSettings::clear() +{ + keylist.clear(); + valuelist.clear(); +} + +void SimpleSettings::readSettings (const QString &path) +{ + QString s; + if (!loadStringFromDisk(path,s)) + { + qWarning ("SimpleSettings::readSettings() Couldn't read "+path); + return; + } + QStringList lines; + lines=QStringList::split (QRegExp("\n"),s,false); + int i; + QStringList::Iterator it=lines.begin(); + while (it !=lines.end() ) + { + i=(*it).find("=",0); + keylist.append((*it).left(i)); + valuelist.append((*it).right((*it).length()-i-1)); + it++; + } +} + +void SimpleSettings::writeSettings (const QString &path) +{ + QString s; + QStringList::Iterator itk=keylist.begin(); + QStringList::Iterator itv=valuelist.begin(); + + // First search for value in settings saved in map + while (itk !=keylist.end() ) + { + s+=*itk+"="+*itv+"\n"; + itk++; + itv++; + } + if (!saveStringToDisk(path,s)) + qWarning ("SimpleSettings::writeSettings() Couldn't write "+path); +} + +QString SimpleSettings::readEntry (const QString &key) +{ + QStringList::Iterator itk=keylist.begin(); + QStringList::Iterator itv=valuelist.begin(); + + // First search for value in settings saved in map + while (itk !=keylist.end() ) + { + if (*itk == key) + return *itv; + itk++; + itv++; + } + qWarning ("SimpleSettings::readEntry() Couldn't find key "+key); + return ""; +} + +void SimpleSettings::setEntry (const QString &key, const QString &value) +{ + QStringList::Iterator itk=keylist.begin(); + QStringList::Iterator itv=valuelist.begin(); + + if (!key.isEmpty() ) + { + // Search for existing entry first + while (itk !=keylist.end() ) + { + if (*itk == key) + { + if (!value.isEmpty()) + *itv=value; + else + *itv=""; + *itv=value; + return; + } + itk++; + itv++; + } + + // If no entry exists, append a new one + keylist.append (key); + valuelist.append (value); + } +} + + + ///////////////////////////////////////////////////////////////// // Settings ///////////////////////////////////////////////////////////////// @@ -11,6 +117,11 @@ clear(); } +Settings::Settings(const QString & organization, const QString & application ):QSettings (organization,application) +{ + clear(); +} + Settings::~Settings() { } @@ -116,17 +227,3 @@ return s; } -void Settings::write() -{ - QStringList::Iterator itp=pathlist.begin(); - QStringList::Iterator itk=keylist.begin(); - QStringList::Iterator itv=valuelist.begin(); - - while (itp !=pathlist.end() ) - { - itp++; - itk++; - itv++; - } -} -