Merged revisions 10677-11457 via svnmerge from
[wvapps.git] / unity / kconfig / kconfigunibackend.cpp
blob5b98e6941063af6515845f8cf405668962662058
2 #include "kconfigunibackend.h"
3 #include "uniconfroot.h"
4 #include "wvlog.h"
6 //static UniConfRoot root();
7 static UniConfRoot root;
9 class KUniPriv
11 public:
12 WvLog log;
13 UniConf cfg;
14 KConfigBase *config;
15 bool did_read;
17 KUniPriv(KConfigBase *_config, WvStringParm _filename,
18 WvStringParm _restype, bool usekdeglobals);
19 ~KUniPriv();
20 void read();
21 void write();
25 KUniPriv::KUniPriv(KConfigBase *_config, WvStringParm _filename,
26 WvStringParm _restype, bool usekdeglobals)
27 : log(WvString("KU:%s:%s", _restype, _filename)), cfg(root)
29 did_read = false;
30 config = _config;
31 log("Creating. (globals=%s)\n", usekdeglobals);
33 static bool init = false;
34 if (!init)
36 init = true;
37 // root["kde/config"].mount("fast-reget:unix:/tmp/uniwrap");
38 // root["kde/config"].mount("fstree:/home/apenwarr/.kde/share/config");
42 // FIXME: do something with usekdeglobals
43 WvString restype(!!_restype ? _restype : WvString("NOTHING"));
44 WvString filename(!!_filename ? _filename : WvString("NOTHING"));
45 cfg = root["kde"][restype][filename];
46 if (!cfg.ismountpoint())
47 cfg.mount(WvString("ini:/home/apenwarr/.kde/share/%s/%s",
48 restype, filename), true);
50 // UniConf cfgx(cfg["KUniPriv wuz heer"]);
51 // cfgx.setmeint(cfgx.getmeint() + 1);
53 log("Created.\n");
57 KUniPriv::~KUniPriv()
59 log("Deleting.\n");
63 void KUniPriv::read()
65 if (did_read)
66 return; // UniConf doesn't need to reread more than once
68 log("Reading...");
70 // cfg.refresh();
72 UniConf::Iter group(cfg);
73 for (group.rewind(); group.next(); )
75 UniConf::RecursiveIter entry(*group);
76 for (entry.rewind(); entry.next(); )
78 QCString groupkey(group->key().printable().cstr());
79 QCString entkey(entry->fullkey(*group).printable().cstr());
81 KEntryKey key(groupkey, entkey);
82 KEntry val;
83 val.mValue = entry._value();
85 config->putData(key, val);
89 did_read = true;
91 log("read.\n");
95 void KUniPriv::write()
97 log("Writing...");
98 KEntryMap kmap = config->internalEntryMap();
100 for (KEntryMapIterator i = kmap.begin(); i != kmap.end(); ++i)
102 const KEntry &ent = *i;
103 #if 0
104 if (ent.bGlobal != bGlobal)
106 // wrong "globality" - might have to be saved later
107 bEntriesLeft = true;
108 continue;
110 #endif
112 WvString group(i.key().mGroup), key(i.key().mKey), val(ent.mValue);
113 if (val.isnull())
114 val = ""; // never accidentally *delete* keys
115 if (!!group && !!key)
117 if (cfg[group].xget(key) != val)
119 log("'[%s]%s' = '%s'\n", group, key, val);
120 cfg[group].xset(key, val);
125 // cfg.commit();
126 log("written.\n");
134 KConfigUniBackEnd::KConfigUniBackEnd(KConfigBase *_config,
135 const QString &_fileName, const char * _resType,
136 bool _useKDEGlobals)
137 : KConfigBackEnd(_config, _fileName, _resType, _useKDEGlobals)
139 priv = new KUniPriv(_config, _fileName, _resType, _useKDEGlobals);
143 KConfigUniBackEnd::~KConfigUniBackEnd()
145 if (priv) delete priv;
149 bool KConfigUniBackEnd::parseConfigFiles()
151 priv->read();
152 return true;
156 void KConfigUniBackEnd::sync(bool merge)
158 priv->write();