1 /***************************************************************************
2 * Copyright (C) 2005-09 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 ***************************************************************************/
21 #include <QStringList>
25 QHash<QString, QHash<QString, QVariant> > Settings::settingsCache;
26 QHash<QString, QHash<QString, SettingsChangeNotifier *> > Settings::settingsChangeNotifier;
28 // Settings::Settings(QString group_, QString appName_)
33 // /* we need to call the constructor immediately in order to set the path...
35 // QSettings(QCoreApplication::organizationName(), applicationName);
37 // // FIXME sandboxDir() is not currently working correctly...
38 // //if(Qtopia::sandboxDir().isEmpty()) QSettings();
39 // //else QSettings(Qtopia::sandboxDir() + "/etc/QuasselIRC.conf", QSettings::NativeFormat);
40 // // ...so we have to use a workaround:
41 // QString appPath = QCoreApplication::applicationFilePath();
42 // if(appPath.startsWith(Qtopia::packagePath())) {
43 // QString sandboxPath = appPath.left(Qtopia::packagePath().length() + 32);
44 // QSettings(sandboxPath + "/etc/QuasselIRC.conf", QSettings::IniFormat);
45 // qDebug() << sandboxPath + "/etc/QuasselIRC.conf";
47 // QSettings(QCoreApplication::organizationName(), applicationName);
53 void Settings::notify(const QString &key, QObject *receiver, const char *slot) {
54 QObject::connect(notifier(group, key), SIGNAL(valueChanged(const QVariant &)),
58 QStringList Settings::allLocalKeys() {
59 QSettings s(fileName(), format());
61 QStringList res = s.allKeys();
66 QStringList Settings::localChildKeys(const QString &rootkey) {
71 g = QString("%1/%2").arg(group, rootkey);
73 QSettings s(fileName(), format());
75 QStringList res = s.childKeys();
80 QStringList Settings::localChildGroups(const QString &rootkey) {
85 g = QString("%1/%2").arg(group, rootkey);
87 QSettings s(fileName(), format());
89 QStringList res = s.childGroups();
94 void Settings::setLocalValue(const QString &key, const QVariant &data) {
95 QSettings s(fileName(), format());
97 s.setValue(key, data);
99 setCacheValue(group, key, data);
100 if(hasNotifier(group, key)) {
101 emit notifier(group, key)->valueChanged(data);
105 const QVariant &Settings::localValue(const QString &key, const QVariant &def) {
106 if(!isCached(group, key)) {
107 QSettings s(fileName(), format());
109 setCacheValue(group, key, s.value(key, def));
112 return cacheValue(group, key);
115 void Settings::removeLocalKey(const QString &key) {
116 QSettings s(fileName(), format());
120 if(isCached(group, key))
121 settingsCache[group].remove(key);