b5ca9167ca4e70c6a19d28603fb6c6ad425743e1
[quassel.git] / src / common / settings.cpp
1 /***************************************************************************
2  *   Copyright (C) 2005-07 by The Quassel 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) any later version.                                   *
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   /*
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   } else {
47     QSettings();
48   }
49   */
50   QSettings();
51 #endif
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() {
71   beginGroup(group);
72   QStringList res = childKeys();
73   endGroup();
74   return res;
75 }
76
77 QStringList Settings::localChildGroups() {
78   beginGroup(group);
79   QStringList res = childGroups();
80   endGroup();
81   return res;
82 }
83
84 void Settings::setLocalValue(const QString &key, const QVariant &data) {
85   beginGroup(group);
86   setValue(key, data);
87   endGroup();
88 }
89
90 QVariant Settings::localValue(const QString &key, const QVariant &def) {
91   beginGroup(group);
92   QVariant res = value(key, def);
93   endGroup();
94   return res;
95 }
96
97 void Settings::removeLocalKey(const QString &key) {
98   beginGroup(group);
99   remove(key);
100   endGroup();
101 }