1 /***************************************************************************
2 * Copyright (C) 2005-08 by the Quassel Project *
3 * devel@quassel-irc.org *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) version 3. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
22 #include <QStringList>
30 QHash<QString, QHash<QString, QVariant> > Settings::settingsCache;
31 QHash<QString, QHash<QString, SettingsChangeNotifier *> > Settings::settingsChangeNotifier;
33 // Settings::Settings(QString group_, QString appName_)
38 // /* we need to call the constructor immediately in order to set the path...
40 // QSettings(QCoreApplication::organizationName(), applicationName);
42 // // FIXME sandboxDir() is not currently working correctly...
43 // //if(Qtopia::sandboxDir().isEmpty()) QSettings();
44 // //else QSettings(Qtopia::sandboxDir() + "/etc/QuasselIRC.conf", QSettings::NativeFormat);
45 // // ...so we have to use a workaround:
46 // QString appPath = QCoreApplication::applicationFilePath();
47 // if(appPath.startsWith(Qtopia::packagePath())) {
48 // QString sandboxPath = appPath.left(Qtopia::packagePath().length() + 32);
49 // QSettings(sandboxPath + "/etc/QuasselIRC.conf", QSettings::IniFormat);
50 // qDebug() << sandboxPath + "/etc/QuasselIRC.conf";
52 // QSettings(QCoreApplication::organizationName(), applicationName);
58 void Settings::notify(const QString &key, QObject *receiver, const char *slot) {
59 QObject::connect(notifier(group, key), SIGNAL(valueChanged(const QVariant &)),
63 QStringList Settings::allLocalKeys() {
64 QSettings s(org(), appName);
66 QStringList res = s.allKeys();
71 QStringList Settings::localChildKeys(const QString &rootkey) {
76 g = QString("%1/%2").arg(group, rootkey);
78 QSettings s(org(), appName);
80 QStringList res = s.childKeys();
85 QStringList Settings::localChildGroups(const QString &rootkey) {
90 g = QString("%1/%2").arg(group, rootkey);
92 QSettings s(org(), appName);
94 QStringList res = s.childGroups();
99 void Settings::setLocalValue(const QString &key, const QVariant &data) {
100 QSettings s(org(), appName);
102 s.setValue(key, data);
104 setCacheValue(group, key, data);
105 if(hasNotifier(group, key)) {
106 emit notifier(group, key)->valueChanged(data);
110 const QVariant &Settings::localValue(const QString &key, const QVariant &def) {
111 if(!isCached(group, key)) {
112 QSettings s(org(), appName);
114 setCacheValue(group, key, s.value(key, def));
117 return cacheValue(group, key);
120 void Settings::removeLocalKey(const QString &key) {
121 QSettings s(org(), appName);
125 if(isCached(group, key))
126 settingsCache[group].remove(key);