8 /////////////////////////////////////////////////////////////////
10 /////////////////////////////////////////////////////////////////
11 SimpleSettings::SimpleSettings()
16 SimpleSettings::~SimpleSettings()
20 void SimpleSettings::clear()
26 void SimpleSettings::readSettings (const QString &path)
29 if (!loadStringFromDisk(path,s))
31 qWarning ("SimpleSettings::readSettings() Couldn't read "+path);
35 lines=QStringList::split (QRegExp("\n"),s,false);
37 QStringList::Iterator it=lines.begin();
38 while (it !=lines.end() )
41 keylist.append((*it).left(i));
42 valuelist.append((*it).right((*it).length()-i-1));
47 void SimpleSettings::writeSettings (const QString &path)
50 QStringList::Iterator itk=keylist.begin();
51 QStringList::Iterator itv=valuelist.begin();
53 // First search for value in settings saved in map
54 while (itk !=keylist.end() )
56 s+=*itk+"="+*itv+"\n";
60 if (!saveStringToDisk(path,s))
61 qWarning ("SimpleSettings::writeSettings() Couldn't write "+path);
65 QString SimpleSettings::readEntry (const QString &key)
67 QStringList::Iterator itk=keylist.begin();
68 QStringList::Iterator itv=valuelist.begin();
70 // First search for value in settings saved in map
71 while (itk !=keylist.end() )
78 qWarning ("SimpleSettings::readEntry() Couldn't find key "+key);
83 QString SimpleSettings::readEntry (const QString &key, const QString &def)
85 QStringList::Iterator itk=keylist.begin();
86 QStringList::Iterator itv=valuelist.begin();
88 // First search for value in settings saved in map
89 while (itk !=keylist.end() )
99 int SimpleSettings::readNumEntry (const QString &key, const int &def)
101 QStringList::Iterator itk=keylist.begin();
102 QStringList::Iterator itv=valuelist.begin();
104 // First search for value in settings saved in map
105 while (itk !=keylist.end() )
110 int i=(*itv).toInt(&ok,10);
122 void SimpleSettings::setEntry (const QString &key, const QString &value)
124 QStringList::Iterator itk=keylist.begin();
125 QStringList::Iterator itv=valuelist.begin();
129 // Search for existing entry first
130 while (itk !=keylist.end() )
134 if (!value.isEmpty())
145 // If no entry exists, append a new one
146 keylist.append (key);
147 valuelist.append (value);
153 /////////////////////////////////////////////////////////////////
155 /////////////////////////////////////////////////////////////////
161 Settings::Settings(const QString & organization, const QString & application ):QSettings (organization,application)
166 Settings::~Settings()
170 void Settings::clear()
177 void Settings::clearLocal(const QString &s)
179 QStringList::Iterator itp=pathlist.begin();
180 QStringList::Iterator itk=keylist.begin();
181 QStringList::Iterator itv=valuelist.begin();
183 while (itp !=pathlist.end() )
185 if ((*itk).startsWith (s))
187 itp=pathlist.remove (itp);
188 itk=keylist.remove (itk);
189 itv=valuelist.remove (itv);
199 QString Settings::readLocalEntry ( const QString &fpath, const QString & key, const QString & def = QString::null )
201 QStringList::Iterator itp=pathlist.begin();
202 QStringList::Iterator itk=keylist.begin();
203 QStringList::Iterator itv=valuelist.begin();
205 // First search for value in settings saved in map
206 while (itp !=pathlist.end() )
208 if (*itp == fpath && *itk == key)
215 // Fall back to global vym settings
217 return readEntry (key,def, &ok);
220 void Settings::setLocalEntry (const QString &fpath, const QString &key, const QString &value)
222 QStringList::Iterator itp=pathlist.begin();
223 QStringList::Iterator itk=keylist.begin();
224 QStringList::Iterator itv=valuelist.begin();
226 if (!fpath.isEmpty() && !key.isEmpty() && !value.isEmpty() )
228 // Search for existing entry first
229 while (itp !=pathlist.end() )
231 if (*itp == fpath && *itk == key)
241 // If no entry exists, append a new one
242 pathlist.append (fpath);
243 keylist.append (key);
244 valuelist.append (value);
248 QString Settings::getDataXML (const QString &fpath)
251 QStringList::Iterator itp=pathlist.begin();
252 QStringList::Iterator itk=keylist.begin();
253 QStringList::Iterator itv=valuelist.begin();
255 while (itp !=pathlist.end() )
258 if (!(*itv).isEmpty())
261 attribut ("key",*itk)
262 +attribut ("value",*itv)