insilmaril@0
|
1 |
#include <iostream>
|
insilmaril@0
|
2 |
#include "settings.h"
|
insilmaril@0
|
3 |
#include "misc.h"
|
insilmaril@0
|
4 |
|
insilmaril@0
|
5 |
using namespace std;
|
insilmaril@0
|
6 |
/////////////////////////////////////////////////////////////////
|
insilmaril@0
|
7 |
// Settings
|
insilmaril@0
|
8 |
/////////////////////////////////////////////////////////////////
|
insilmaril@0
|
9 |
Settings::Settings()
|
insilmaril@0
|
10 |
{
|
insilmaril@0
|
11 |
clear();
|
insilmaril@0
|
12 |
}
|
insilmaril@0
|
13 |
|
insilmaril@0
|
14 |
Settings::~Settings()
|
insilmaril@0
|
15 |
{
|
insilmaril@0
|
16 |
}
|
insilmaril@0
|
17 |
|
insilmaril@0
|
18 |
void Settings::clear()
|
insilmaril@0
|
19 |
{
|
insilmaril@0
|
20 |
pathlist.clear();
|
insilmaril@0
|
21 |
keylist.clear();
|
insilmaril@0
|
22 |
valuelist.clear();
|
insilmaril@0
|
23 |
}
|
insilmaril@0
|
24 |
|
insilmaril@0
|
25 |
void Settings::clearLocal(const QString &s)
|
insilmaril@0
|
26 |
{
|
insilmaril@0
|
27 |
QStringList::Iterator itp=pathlist.begin();
|
insilmaril@0
|
28 |
QStringList::Iterator itk=keylist.begin();
|
insilmaril@0
|
29 |
QStringList::Iterator itv=valuelist.begin();
|
insilmaril@0
|
30 |
|
insilmaril@0
|
31 |
while (itp !=pathlist.end() )
|
insilmaril@0
|
32 |
{
|
insilmaril@0
|
33 |
if ((*itk).startsWith (s))
|
insilmaril@0
|
34 |
{
|
insilmaril@0
|
35 |
itp=pathlist.remove (itp);
|
insilmaril@0
|
36 |
itk=keylist.remove (itk);
|
insilmaril@0
|
37 |
itv=valuelist.remove (itv);
|
insilmaril@0
|
38 |
} else
|
insilmaril@0
|
39 |
{
|
insilmaril@0
|
40 |
itp++;
|
insilmaril@0
|
41 |
itk++;
|
insilmaril@0
|
42 |
itv++;
|
insilmaril@0
|
43 |
}
|
insilmaril@0
|
44 |
}
|
insilmaril@0
|
45 |
}
|
insilmaril@0
|
46 |
|
insilmaril@0
|
47 |
QString Settings::readLocalEntry ( const QString &fpath, const QString & key, const QString & def = QString::null )
|
insilmaril@0
|
48 |
{
|
insilmaril@0
|
49 |
QStringList::Iterator itp=pathlist.begin();
|
insilmaril@0
|
50 |
QStringList::Iterator itk=keylist.begin();
|
insilmaril@0
|
51 |
QStringList::Iterator itv=valuelist.begin();
|
insilmaril@0
|
52 |
|
insilmaril@0
|
53 |
// First search for value in settings saved in map
|
insilmaril@0
|
54 |
while (itp !=pathlist.end() )
|
insilmaril@0
|
55 |
{
|
insilmaril@0
|
56 |
if (*itp == fpath && *itk == key)
|
insilmaril@0
|
57 |
return *itv;
|
insilmaril@0
|
58 |
itp++;
|
insilmaril@0
|
59 |
itk++;
|
insilmaril@0
|
60 |
itv++;
|
insilmaril@0
|
61 |
}
|
insilmaril@0
|
62 |
|
insilmaril@0
|
63 |
// Fall back to global vym settings
|
insilmaril@0
|
64 |
bool ok;
|
insilmaril@0
|
65 |
return readEntry (key,def, &ok);
|
insilmaril@0
|
66 |
}
|
insilmaril@0
|
67 |
|
insilmaril@0
|
68 |
void Settings::setLocalEntry (const QString &fpath, const QString &key, const QString &value)
|
insilmaril@0
|
69 |
{
|
insilmaril@0
|
70 |
QStringList::Iterator itp=pathlist.begin();
|
insilmaril@0
|
71 |
QStringList::Iterator itk=keylist.begin();
|
insilmaril@0
|
72 |
QStringList::Iterator itv=valuelist.begin();
|
insilmaril@0
|
73 |
|
insilmaril@0
|
74 |
if (!fpath.isEmpty() && !key.isEmpty() && !value.isEmpty() )
|
insilmaril@0
|
75 |
{
|
insilmaril@0
|
76 |
// Search for existing entry first
|
insilmaril@0
|
77 |
while (itp !=pathlist.end() )
|
insilmaril@0
|
78 |
{
|
insilmaril@0
|
79 |
if (*itp == fpath && *itk == key)
|
insilmaril@0
|
80 |
{
|
insilmaril@0
|
81 |
*itv=value;
|
insilmaril@0
|
82 |
return;
|
insilmaril@0
|
83 |
}
|
insilmaril@0
|
84 |
itp++;
|
insilmaril@0
|
85 |
itk++;
|
insilmaril@0
|
86 |
itv++;
|
insilmaril@0
|
87 |
}
|
insilmaril@0
|
88 |
|
insilmaril@0
|
89 |
// If no entry exists, append a new one
|
insilmaril@0
|
90 |
pathlist.append (fpath);
|
insilmaril@0
|
91 |
keylist.append (key);
|
insilmaril@0
|
92 |
valuelist.append (value);
|
insilmaril@0
|
93 |
}
|
insilmaril@0
|
94 |
}
|
insilmaril@0
|
95 |
|
insilmaril@0
|
96 |
QString Settings::getXMLData (const QString &fpath)
|
insilmaril@0
|
97 |
{
|
insilmaril@0
|
98 |
QString s;
|
insilmaril@0
|
99 |
QStringList::Iterator itp=pathlist.begin();
|
insilmaril@0
|
100 |
QStringList::Iterator itk=keylist.begin();
|
insilmaril@0
|
101 |
QStringList::Iterator itv=valuelist.begin();
|
insilmaril@0
|
102 |
|
insilmaril@0
|
103 |
while (itp !=pathlist.end() )
|
insilmaril@0
|
104 |
{
|
insilmaril@0
|
105 |
if (*itp == fpath )
|
insilmaril@0
|
106 |
if (!(*itv).isEmpty())
|
insilmaril@0
|
107 |
s+=singleElement (
|
insilmaril@0
|
108 |
"setting",
|
insilmaril@0
|
109 |
attribut ("key",*itk)
|
insilmaril@0
|
110 |
+attribut ("value",*itv)
|
insilmaril@0
|
111 |
)+"\n";
|
insilmaril@0
|
112 |
itp++;
|
insilmaril@0
|
113 |
itk++;
|
insilmaril@0
|
114 |
itv++;
|
insilmaril@0
|
115 |
}
|
insilmaril@0
|
116 |
return s;
|
insilmaril@0
|
117 |
}
|
insilmaril@0
|
118 |
|
insilmaril@0
|
119 |
void Settings::write()
|
insilmaril@0
|
120 |
{
|
insilmaril@0
|
121 |
QStringList::Iterator itp=pathlist.begin();
|
insilmaril@0
|
122 |
QStringList::Iterator itk=keylist.begin();
|
insilmaril@0
|
123 |
QStringList::Iterator itv=valuelist.begin();
|
insilmaril@0
|
124 |
|
insilmaril@0
|
125 |
while (itp !=pathlist.end() )
|
insilmaril@0
|
126 |
{
|
insilmaril@0
|
127 |
itp++;
|
insilmaril@0
|
128 |
itk++;
|
insilmaril@0
|
129 |
itv++;
|
insilmaril@0
|
130 |
}
|
insilmaril@0
|
131 |
}
|
insilmaril@0
|
132 |
|