Added some featues to the SignalProxy. Now SyncSlaves can request that objects residi...
[quassel.git] / src / common / settings.cpp
1 /***************************************************************************
2  *   Copyright (C) 2005-07 by the Quassel IRC Team                         *
3  *   devel@quassel-irc.org                                                 *
4  *                                                                         *
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.                                           *
9  *                                                                         *
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.                          *
14  *                                                                         *
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  ***************************************************************************/
20
21 #include <QSettings>
22 #include <QStringList>
23 #include <QDebug>
24
25 #ifdef Q_WS_QWS
26 #include <Qtopia>
27 #include <QCoreApplication>
28 #endif
29
30 #include "settings.h"
31
32 Settings::Settings(QString g) : group(g) {
33
34 #ifndef Q_WS_QWS
35   QSettings();
36 #else
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";
46   } else {
47     QSettings();
48   }
49 #endif
50 }
51
52 Settings::~Settings() {
53
54 }
55
56 void Settings::setGroup(QString g) {
57   group = g;
58
59 }
60
61 QStringList Settings::allLocalKeys() {
62   beginGroup(group);
63   QStringList res = allKeys();
64   endGroup();
65   return res;
66 }
67
68 QStringList Settings::localChildKeys(const QString &rootkey) {
69   QString g;
70   if(rootkey.isEmpty()) g = group;
71   else g = QString("%1/%2").arg(group, rootkey);
72   beginGroup(g);
73   QStringList res = childKeys();
74   endGroup();
75   return res;
76 }
77
78 QStringList Settings::localChildGroups(const QString &rootkey) {
79   QString g;
80   if(rootkey.isEmpty()) g = group;
81   else g = QString("%1/%2").arg(group, rootkey);
82   beginGroup(g);
83   QStringList res = childGroups();
84   endGroup();
85   return res;
86 }
87
88 void Settings::setLocalValue(const QString &key, const QVariant &data) {
89   beginGroup(group);
90   setValue(key, data);
91   endGroup();
92 }
93
94 QVariant Settings::localValue(const QString &key, const QVariant &def) {
95   beginGroup(group);
96   QVariant res = value(key, def);
97   endGroup();
98   return res;
99 }
100
101 void Settings::removeLocalKey(const QString &key) {
102   beginGroup(group);
103   remove(key);
104   endGroup();
105 }