Make BufferInfo qDebug()able as per EgS' request.
[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() {
69   beginGroup(group);
70   QStringList res = childKeys();
71   endGroup();
72   return res;
73 }
74
75 QStringList Settings::localChildGroups() {
76   beginGroup(group);
77   QStringList res = childGroups();
78   endGroup();
79   return res;
80 }
81
82 void Settings::setLocalValue(const QString &key, const QVariant &data) {
83   beginGroup(group);
84   setValue(key, data);
85   endGroup();
86 }
87
88 QVariant Settings::localValue(const QString &key, const QVariant &def) {
89   beginGroup(group);
90   QVariant res = value(key, def);
91   endGroup();
92   return res;
93 }
94
95 void Settings::removeLocalKey(const QString &key) {
96   beginGroup(group);
97   remove(key);
98   endGroup();
99 }