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>
31 QHash<QString, QHash<QString, QVariant> > Settings::settingsCache;
32 QHash<QString, QHash<QString, SettingsChangeNotifier *> > Settings::settingsChangeNotifier;
34 // Settings::Settings(QString group_, QString appName_)
39 // /* we need to call the constructor immediately in order to set the path...
41 // QSettings(QCoreApplication::organizationName(), applicationName);
43 // // FIXME sandboxDir() is not currently working correctly...
44 // //if(Qtopia::sandboxDir().isEmpty()) QSettings();
45 // //else QSettings(Qtopia::sandboxDir() + "/etc/QuasselIRC.conf", QSettings::NativeFormat);
46 // // ...so we have to use a workaround:
47 // QString appPath = QCoreApplication::applicationFilePath();
48 // if(appPath.startsWith(Qtopia::packagePath())) {
49 // QString sandboxPath = appPath.left(Qtopia::packagePath().length() + 32);
50 // QSettings(sandboxPath + "/etc/QuasselIRC.conf", QSettings::IniFormat);
51 // qDebug() << sandboxPath + "/etc/QuasselIRC.conf";
53 // QSettings(QCoreApplication::organizationName(), applicationName);
59 void Settings::notify(const QString &key, QObject *receiver, const char *slot) {
60 QObject::connect(notifier(group, key), SIGNAL(valueChanged(const QVariant &)),
64 QStringList Settings::allLocalKeys() {
65 QSettings s(org(), appName);
67 QStringList res = s.allKeys();
72 QStringList Settings::localChildKeys(const QString &rootkey) {
77 g = QString("%1/%2").arg(group, rootkey);
79 QSettings s(org(), appName);
81 QStringList res = s.childKeys();
86 QStringList Settings::localChildGroups(const QString &rootkey) {
91 g = QString("%1/%2").arg(group, rootkey);
93 QSettings s(org(), appName);
95 QStringList res = s.childGroups();
100 void Settings::setLocalValue(const QString &key, const QVariant &data) {
101 QSettings s(org(), appName);
103 s.setValue(key, data);
105 setCacheValue(group, key, data);
106 if(hasNotifier(group, key)) {
107 emit notifier(group, key)->valueChanged(data);
111 const QVariant &Settings::localValue(const QString &key, const QVariant &def) {
112 if(!isCached(group, key)) {
113 QSettings s(org(), appName);
115 setCacheValue(group, key, s.value(key, def));
118 return cacheValue(group, key);
121 void Settings::removeLocalKey(const QString &key) {
122 QSettings s(org(), appName);
126 if(isCached(group, key))
127 settingsCache[group].remove(key);