3 // Originally part of QCad Community Edition by Andrew Mustun
4 // Extensively rewritten and refactored by James L. Hammons
5 // (C) 2010 Underground Software
7 // JLH = James L. Hammons <jlhamm@acm.org>
10 // --- ---------- -----------------------------------------------------------
11 // JLH 05/19/2010 Created this file. :-)
14 #include "rs_settings.h"
17 RS_Settings * RS_Settings::uniqueInstance = NULL;
19 RS_Settings::RS_Settings():
20 initialized(false), companyKey(""), appKey(""), group("")
27 RS_Settings::~RS_Settings()
29 // Needed since QList doesn't have AutoDelete...
30 while (!cache.isEmpty())
32 QString * value = *cache.begin();
33 cache.erase(cache.begin());
40 * @return Instance to the unique settings object.
42 RS_Settings * RS_Settings::instance()
44 if (uniqueInstance == NULL)
45 uniqueInstance = new RS_Settings();
47 return uniqueInstance;
53 * @param companyKey String that identifies the company. Must start
54 * with a "/". E.g. "/RibbonSoft"
55 * @param appKey String that identifies the application. Must start
56 * with a "/". E.g. "/QCad2"
58 void RS_Settings::init(const QString & comp, const QString & app)
64 //In Qt4, there is no such thing as a search path anymore...
65 //insertSearchPath(QSettings::Windows, companyKey + appKey);
66 //insertSearchPath(QSettings::Unix, "/usr/share/");
70 void RS_Settings::beginGroup(const QString & grp)
75 void RS_Settings::endGroup()
80 bool RS_Settings::writeEntry(const QString & key, int value)
82 QString s = QString("%1").arg(value);
83 return writeEntry(key, s);
86 bool RS_Settings::writeEntry(const QString & key, double value)
88 QString s = QString("%1").arg(value);
89 return writeEntry(key, s);
92 bool RS_Settings::writeEntry(const QString & key, const QString & value)
94 //[DONE, mostly]#warning "!!! Need to revamp outdated settings system !!!"
95 QSettings settings("Underground Software", "Architektonas");
97 // bool ret = s.writeEntry(QString("%1%2%3").arg(appKey).arg(group).arg(key), value);
98 settings.setValue(QString("%1%2").arg(group).arg(key), value);
99 addToCache(key, value);
102 // The old system told you if it failed or not, but the new assumes success
106 QString RS_Settings::readEntry(const QString & key, const QString & def, bool * ok)
109 QString entry = readEntryCache(key);
111 if (entry != QString::null)
114 QSettings settings("Underground Software", "Architektonas");
116 QString s = QString("%1%2").arg(group).arg(key);
119 *ok = settings.contains(s);
121 // ret = s.readEntry(QString("%1%2%3").arg(appKey).arg(group).arg(key), def, ok);
122 entry = settings.value(s, def).toString();
123 addToCache(key, entry);
128 int RS_Settings::readNumEntry(const QString & key, int def, bool * ok)
131 QString result = readEntryCache(key);
133 if (result != QString::null)
134 return result.toInt();
136 QSettings settings("Underground Software", "Architektonas");
138 // int ret = s.readNumEntry(QString("%1%2%3").arg(appKey).arg(group).arg(key), def, ok);
139 QString s = QString("%1%2").arg(group).arg(key);
142 *ok = settings.contains(s);
144 int entry = settings.value(s, def).toInt();
145 addToCache(key, QString("%1").arg(entry));
150 QString RS_Settings::readEntryCache(const QString & key)
152 QString * s = cache.value(key);
155 return QString::null;
160 void RS_Settings::addToCache(const QString & key, const QString & value)
162 cache.replace(key, new QString(value));