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 ***************************************************************************/
21 #include <QCoreApplication>
23 #include <QStringList>
32 static QHash<QString, QHash<QString, QVariant> > __settingsCache__;
34 Settings::Settings(QString g, QString applicationName)
37 : QSettings(QCoreApplication::organizationDomain(), applicationName),
39 : QSettings(QCoreApplication::organizationName(), applicationName),
44 /* we need to call the constructor immediately in order to set the path...
46 QSettings(QCoreApplication::organizationName(), applicationName);
48 // FIXME sandboxDir() is not currently working correctly...
49 //if(Qtopia::sandboxDir().isEmpty()) QSettings();
50 //else QSettings(Qtopia::sandboxDir() + "/etc/QuasselIRC.conf", QSettings::NativeFormat);
51 // ...so we have to use a workaround:
52 QString appPath = QCoreApplication::applicationFilePath();
53 if(appPath.startsWith(Qtopia::packagePath())) {
54 QString sandboxPath = appPath.left(Qtopia::packagePath().length() + 32);
55 QSettings(sandboxPath + "/etc/QuasselIRC.conf", QSettings::IniFormat);
56 qDebug() << sandboxPath + "/etc/QuasselIRC.conf";
58 QSettings(QCoreApplication::organizationName(), applicationName);
64 QStringList Settings::allLocalKeys() {
66 QStringList res = allKeys();
71 QStringList Settings::localChildKeys(const QString &rootkey) {
73 if(rootkey.isEmpty()) g = group;
74 else g = QString("%1/%2").arg(group, rootkey);
76 QStringList res = childKeys();
81 QStringList Settings::localChildGroups(const QString &rootkey) {
83 if(rootkey.isEmpty()) g = group;
84 else g = QString("%1/%2").arg(group, rootkey);
86 QStringList res = childGroups();
91 void Settings::setLocalValue(const QString &key, const QVariant &data) {
94 setCacheValue(group, key, data);
98 const QVariant &Settings::localValue(const QString &key, const QVariant &def) {
99 if(!isCached(group, key)) {
101 setCacheValue(group, key, value(key, def));
104 return cacheValue(group, key);
107 void Settings::removeLocalKey(const QString &key) {
114 void Settings::setCacheValue(const QString &group, const QString &key, const QVariant &data) {
115 ::__settingsCache__[group][key] = data;
118 const QVariant &Settings::cacheValue(const QString &group, const QString &key) {
119 return ::__settingsCache__[group][key];
122 bool Settings::isCached(const QString &group, const QString &key) {
123 return ::__settingsCache__.contains(group) && ::__settingsCache__[group].contains(key);