1.1 --- a/settings.cpp Sun Jan 30 12:58:47 2005 +0000
1.2 +++ b/settings.cpp Tue Aug 15 11:42:10 2006 +0000
1.3 @@ -1,8 +1,114 @@
1.4 #include <iostream>
1.5 +#include <qregexp.h>
1.6 #include "settings.h"
1.7 -#include "misc.h"
1.8 +#include "file.h"
1.9
1.10 using namespace std;
1.11 +
1.12 +/////////////////////////////////////////////////////////////////
1.13 +// SimpleSettings
1.14 +/////////////////////////////////////////////////////////////////
1.15 +SimpleSettings::SimpleSettings()
1.16 +{
1.17 + clear();
1.18 +}
1.19 +
1.20 +SimpleSettings::~SimpleSettings()
1.21 +{
1.22 +}
1.23 +
1.24 +void SimpleSettings::clear()
1.25 +{
1.26 + keylist.clear();
1.27 + valuelist.clear();
1.28 +}
1.29 +
1.30 +void SimpleSettings::readSettings (const QString &path)
1.31 +{
1.32 + QString s;
1.33 + if (!loadStringFromDisk(path,s))
1.34 + {
1.35 + qWarning ("SimpleSettings::readSettings() Couldn't read "+path);
1.36 + return;
1.37 + }
1.38 + QStringList lines;
1.39 + lines=QStringList::split (QRegExp("\n"),s,false);
1.40 + int i;
1.41 + QStringList::Iterator it=lines.begin();
1.42 + while (it !=lines.end() )
1.43 + {
1.44 + i=(*it).find("=",0);
1.45 + keylist.append((*it).left(i));
1.46 + valuelist.append((*it).right((*it).length()-i-1));
1.47 + it++;
1.48 + }
1.49 +}
1.50 +
1.51 +void SimpleSettings::writeSettings (const QString &path)
1.52 +{
1.53 + QString s;
1.54 + QStringList::Iterator itk=keylist.begin();
1.55 + QStringList::Iterator itv=valuelist.begin();
1.56 +
1.57 + // First search for value in settings saved in map
1.58 + while (itk !=keylist.end() )
1.59 + {
1.60 + s+=*itk+"="+*itv+"\n";
1.61 + itk++;
1.62 + itv++;
1.63 + }
1.64 + if (!saveStringToDisk(path,s))
1.65 + qWarning ("SimpleSettings::writeSettings() Couldn't write "+path);
1.66 +}
1.67 +
1.68 +QString SimpleSettings::readEntry (const QString &key)
1.69 +{
1.70 + QStringList::Iterator itk=keylist.begin();
1.71 + QStringList::Iterator itv=valuelist.begin();
1.72 +
1.73 + // First search for value in settings saved in map
1.74 + while (itk !=keylist.end() )
1.75 + {
1.76 + if (*itk == key)
1.77 + return *itv;
1.78 + itk++;
1.79 + itv++;
1.80 + }
1.81 + qWarning ("SimpleSettings::readEntry() Couldn't find key "+key);
1.82 + return "";
1.83 +}
1.84 +
1.85 +void SimpleSettings::setEntry (const QString &key, const QString &value)
1.86 +{
1.87 + QStringList::Iterator itk=keylist.begin();
1.88 + QStringList::Iterator itv=valuelist.begin();
1.89 +
1.90 + if (!key.isEmpty() )
1.91 + {
1.92 + // Search for existing entry first
1.93 + while (itk !=keylist.end() )
1.94 + {
1.95 + if (*itk == key)
1.96 + {
1.97 + if (!value.isEmpty())
1.98 + *itv=value;
1.99 + else
1.100 + *itv="";
1.101 + *itv=value;
1.102 + return;
1.103 + }
1.104 + itk++;
1.105 + itv++;
1.106 + }
1.107 +
1.108 + // If no entry exists, append a new one
1.109 + keylist.append (key);
1.110 + valuelist.append (value);
1.111 + }
1.112 +}
1.113 +
1.114 +
1.115 +
1.116 /////////////////////////////////////////////////////////////////
1.117 // Settings
1.118 /////////////////////////////////////////////////////////////////
1.119 @@ -11,6 +117,11 @@
1.120 clear();
1.121 }
1.122
1.123 +Settings::Settings(const QString & organization, const QString & application ):QSettings (organization,application)
1.124 +{
1.125 + clear();
1.126 +}
1.127 +
1.128 Settings::~Settings()
1.129 {
1.130 }
1.131 @@ -116,17 +227,3 @@
1.132 return s;
1.133 }
1.134
1.135 -void Settings::write()
1.136 -{
1.137 - QStringList::Iterator itp=pathlist.begin();
1.138 - QStringList::Iterator itk=keylist.begin();
1.139 - QStringList::Iterator itv=valuelist.begin();
1.140 -
1.141 - while (itp !=pathlist.end() )
1.142 - {
1.143 - itp++;
1.144 - itk++;
1.145 - itv++;
1.146 - }
1.147 -}
1.148 -