9 /////////////////////////////////////////////////////////////////
11 /////////////////////////////////////////////////////////////////
12 SimpleSettings::SimpleSettings() { clear(); }
14 SimpleSettings::~SimpleSettings() {}
16 void SimpleSettings::clear()
22 bool SimpleSettings::readSettings(const QString &path)
25 if (!loadStringFromDisk(path, s)) {
26 qWarning() << "SimpleSettings::readSettings() Couldn't read " + path;
30 lines = s.split(QRegExp("\n"));
32 QStringList::Iterator it = lines.begin();
33 while (it != lines.end()) {
34 i = (*it).indexOf("=", 0);
35 keylist.append((*it).left(i));
36 valuelist.append((*it).right((*it).length() - i - 1));
42 void SimpleSettings::writeSettings(const QString &path)
45 QStringList::Iterator itk = keylist.begin();
46 QStringList::Iterator itv = valuelist.begin();
48 // First search for value in settings saved in map
49 while (itk != keylist.end()) {
50 s += *itk + "=" + *itv + "\n";
54 if (!saveStringToDisk(path, s))
55 qWarning() << "SimpleSettings::writeSettings() Couldn't write " + path;
59 QString SimpleSettings::readValue (const QString &key)
61 QStringList::Iterator itk=keylist.begin();
62 QStringList::Iterator itv=valuelist.begin();
64 // First search for value in settings saved in map
65 while (itk !=keylist.end() )
72 qWarning ("SimpleSettings::readValue() Couldn't find key "+key);
77 QString SimpleSettings::value(const QString &key, const QString &def)
79 QStringList::Iterator itk = keylist.begin();
80 QStringList::Iterator itv = valuelist.begin();
82 // First search for value in settings saved in map
83 while (itk != keylist.end()) {
92 int SimpleSettings::numValue(const QString &key, const int &def)
94 QStringList::Iterator itk = keylist.begin();
95 QStringList::Iterator itv = valuelist.begin();
97 // First search for value in settings saved in map
98 while (itk != keylist.end()) {
101 int i = (*itv).toInt(&ok, 10);
113 void SimpleSettings::setValue(const QString &key, const QString &value)
115 QStringList::Iterator itk = keylist.begin();
116 QStringList::Iterator itv = valuelist.begin();
118 if (!key.isEmpty()) {
119 // Search for existing Value first
120 while (itk != keylist.end()) {
122 if (!value.isEmpty())
133 // If no Value exists, append a new one
135 valuelist.append(value);
139 /////////////////////////////////////////////////////////////////
141 /////////////////////////////////////////////////////////////////
142 Settings::Settings() { clear(); }
144 Settings::Settings(const QString &organization, const QString &application)
145 : QSettings(organization, application)
150 Settings::~Settings() {}
152 void Settings::clear()
159 void Settings::clearLocal(const QString &fpath, const QString &key)
162 while (i < pathlist.count()) {
163 if (fpath == pathlist.at(i) && keylist.at(i).startsWith(key)) {
164 pathlist.removeAt(i);
166 valuelist.removeAt(i);
173 QVariant Settings::localValue(const QString &fpath, const QString &key,
176 // First search for value in settings saved in map
178 while (i < pathlist.count()) {
179 if (pathlist.at(i) == fpath && keylist.at(i) == key)
180 return valuelist.at(i);
184 // Fall back to global vym settings
185 return value(key, def);
188 void Settings::setLocalValue(const QString &fpath, const QString &key,
191 if (!fpath.isEmpty() && !key.isEmpty() && !value.isNull()) {
192 // Search for existing Value first
194 while (i < pathlist.count()) {
195 if (pathlist.at(i) == fpath && keylist.at(i) == key) {
196 valuelist[i] = value;
202 // If no Value exists, append a new one
203 pathlist.append(fpath);
205 valuelist.append(value);
209 QString Settings::getDataXML(const QString &fpath)
213 while (i < pathlist.count()) {
214 if (pathlist.at(i) == fpath)
215 if (!valuelist.at(i).isNull())
217 valueElement("setting",
218 getCDATA(valuelist.at(i).toString()),
219 attribut("key", keylist.at(i)));