7 bool loadStringFromDisk (const QString &fname, QString &s)
11 if ( !file.open( IO_ReadOnly ) ) return false;
13 QTextStream ts( &file );
14 ts.setEncoding (QTextStream::UnicodeUTF8);
16 s+=ts.readLine()+"\n";
21 bool saveStringToDisk (const QString &fname, const QString &s)
25 file.setName ( fname);
26 if ( !file.open( IO_WriteOnly ) )
32 // Write it finally, and write in UTF8, no matter what
33 QTextStream ts( &file );
34 ts.setEncoding (QTextStream::UnicodeUTF8);
40 /////////////////////////////////////////////////////////////////
42 /////////////////////////////////////////////////////////////////
43 SimpleSettings::SimpleSettings()
48 SimpleSettings::~SimpleSettings()
52 void SimpleSettings::clear()
58 void SimpleSettings::readSettings (const QString &path)
61 if (!loadStringFromDisk(path,s))
63 qWarning ("SimpleSettings::readSettings() Couldn't read "+path);
67 lines=QStringList::split (QRegExp("\n"),s,false);
69 QStringList::Iterator it=lines.begin();
70 while (it !=lines.end() )
73 keylist.append((*it).left(i));
74 valuelist.append((*it).right((*it).length()-i-1));
79 void SimpleSettings::writeSettings (const QString &path)
82 QStringList::Iterator itk=keylist.begin();
83 QStringList::Iterator itv=valuelist.begin();
85 // First search for value in settings saved in map
86 while (itk !=keylist.end() )
88 s+=*itk+"="+*itv+"\n";
92 if (!saveStringToDisk(path,s))
93 qWarning ("SimpleSettings::writeSettings() Couldn't write "+path);
96 QString SimpleSettings::readEntry (const QString &key)
98 QStringList::Iterator itk=keylist.begin();
99 QStringList::Iterator itv=valuelist.begin();
101 // First search for value in settings saved in map
102 while (itk !=keylist.end() )
109 qWarning ("SimpleSettings::readEntry() Couldn't find key "+key);
113 void SimpleSettings::setEntry (const QString &key, const QString &value)
115 QStringList::Iterator itk=keylist.begin();
116 QStringList::Iterator itv=valuelist.begin();
120 // Search for existing entry first
121 while (itk !=keylist.end() )
125 if (!value.isEmpty())
136 // If no entry exists, append a new one
137 keylist.append (key);
138 valuelist.append (value);
144 /////////////////////////////////////////////////////////////////
146 /////////////////////////////////////////////////////////////////
152 Settings::~Settings()
156 void Settings::clear()
163 void Settings::clearLocal(const QString &s)
165 QStringList::Iterator itp=pathlist.begin();
166 QStringList::Iterator itk=keylist.begin();
167 QStringList::Iterator itv=valuelist.begin();
169 while (itp !=pathlist.end() )
171 if ((*itk).startsWith (s))
173 itp=pathlist.remove (itp);
174 itk=keylist.remove (itk);
175 itv=valuelist.remove (itv);
185 QString Settings::readLocalEntry ( const QString &fpath, const QString & key, const QString & def = QString::null )
187 QStringList::Iterator itp=pathlist.begin();
188 QStringList::Iterator itk=keylist.begin();
189 QStringList::Iterator itv=valuelist.begin();
191 // First search for value in settings saved in map
192 while (itp !=pathlist.end() )
194 if (*itp == fpath && *itk == key)
201 // Fall back to global vym settings
203 return readEntry (key,def, &ok);
206 void Settings::setLocalEntry (const QString &fpath, const QString &key, const QString &value)
208 QStringList::Iterator itp=pathlist.begin();
209 QStringList::Iterator itk=keylist.begin();
210 QStringList::Iterator itv=valuelist.begin();
212 if (!fpath.isEmpty() && !key.isEmpty() && !value.isEmpty() )
214 // Search for existing entry first
215 while (itp !=pathlist.end() )
217 if (*itp == fpath && *itk == key)
227 // If no entry exists, append a new one
228 pathlist.append (fpath);
229 keylist.append (key);
230 valuelist.append (value);
234 QString Settings::getXMLData (const QString &fpath)
237 QStringList::Iterator itp=pathlist.begin();
238 QStringList::Iterator itk=keylist.begin();
239 QStringList::Iterator itv=valuelist.begin();
241 while (itp !=pathlist.end() )
244 if (!(*itv).isEmpty())
247 attribut ("key",*itk)
248 +attribut ("value",*itv)