SignalProxy now only allows syncing for classes derived from the new
[quassel.git] / src / common / settings.cpp
1 /***************************************************************************
2  *   Copyright (C) 2005-08 by the Quassel Project                          *
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 <QCoreApplication>
22 #include <QSettings>
23 #include <QStringList>
24 #include <QDebug>
25
26 #ifdef Q_WS_QWS
27 #include <Qtopia>
28 #endif
29
30 #include "settings.h"
31
32 Settings::Settings(QString g, QString applicationName) : QSettings(QCoreApplication::organizationName(), applicationName), group(g) {
33
34 /* we need to call the constructor immediately in order to set the path...
35 #ifndef Q_WS_QWS
36   QSettings(QCoreApplication::organizationName(), applicationName);
37 #else
38   // FIXME sandboxDir() is not currently working correctly...
39   //if(Qtopia::sandboxDir().isEmpty()) QSettings();
40   //else QSettings(Qtopia::sandboxDir() + "/etc/QuasselIRC.conf", QSettings::NativeFormat);
41   // ...so we have to use a workaround:
42   QString appPath = QCoreApplication::applicationFilePath();
43   if(appPath.startsWith(Qtopia::packagePath())) {
44     QString sandboxPath = appPath.left(Qtopia::packagePath().length() + 32);
45     QSettings(sandboxPath + "/etc/QuasselIRC.conf", QSettings::IniFormat);
46     qDebug() << sandboxPath + "/etc/QuasselIRC.conf";
47   } else {
48     QSettings(QCoreApplication::organizationName(), applicationName);
49   }
50 #endif
51 */
52 }
53
54 Settings::~Settings() {
55
56 }
57
58 void Settings::setGroup(QString g) {
59   group = g;
60
61 }
62
63 QStringList Settings::allLocalKeys() {
64   beginGroup(group);
65   QStringList res = allKeys();
66   endGroup();
67   return res;
68 }
69
70 QStringList Settings::localChildKeys(const QString &rootkey) {
71   QString g;
72   if(rootkey.isEmpty()) g = group;
73   else g = QString("%1/%2").arg(group, rootkey);
74   beginGroup(g);
75   QStringList res = childKeys();
76   endGroup();
77   return res;
78 }
79
80 QStringList Settings::localChildGroups(const QString &rootkey) {
81   QString g;
82   if(rootkey.isEmpty()) g = group;
83   else g = QString("%1/%2").arg(group, rootkey);
84   beginGroup(g);
85   QStringList res = childGroups();
86   endGroup();
87   return res;
88 }
89
90 void Settings::setLocalValue(const QString &key, const QVariant &data) {
91   beginGroup(group);
92   setValue(key, data);
93   endGroup();
94 }
95
96 QVariant Settings::localValue(const QString &key, const QVariant &def) {
97   beginGroup(group);
98   QVariant res = value(key, def);
99   endGroup();
100   return res;
101 }
102
103 void Settings::removeLocalKey(const QString &key) {
104   beginGroup(group);
105   remove(key);
106   endGroup();
107 }