some minor improvements to the NetworkModel and added a sanity check to TreeModel
[quassel.git] / src / client / clientsettings.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 "client.h"
22 #include "clientsettings.h"
23 #include "global.h"
24
25 #include <QStringList>
26
27 ClientSettings::ClientSettings(QString g) : Settings(g, Global::clientApplicationName) {
28
29
30 }
31
32 ClientSettings::~ClientSettings() {
33
34
35 }
36
37 QStringList ClientSettings::sessionKeys() {
38   return Client::sessionDataKeys();
39 }
40
41 void ClientSettings::setSessionValue(const QString &key, const QVariant &data) {
42   Client::storeSessionData(key, data);
43 }
44
45 QVariant ClientSettings::sessionValue(const QString &key, const QVariant &def) {
46   return Client::retrieveSessionData(key, def);
47 }
48
49 /***********************************************************************************************/
50
51 CoreAccountSettings::CoreAccountSettings() : ClientSettings("CoreAccounts") {
52
53
54 }
55
56 QStringList CoreAccountSettings::knownAccounts() {
57   return localChildKeys("Accounts");
58 }
59
60 QString CoreAccountSettings::lastAccount() {
61   return localValue("LastAccount", "").toString();
62 }
63
64 void CoreAccountSettings::setLastAccount(const QString &account) {
65   setLocalValue("LastAccount", account);
66 }
67
68 QString CoreAccountSettings::autoConnectAccount() {
69   return localValue("AutoConnectAccount", "").toString();
70 }
71
72 void CoreAccountSettings::setAutoConnectAccount(const QString &account) {
73   setLocalValue("AutoConnectAccount", account);
74 }
75
76 void CoreAccountSettings::storeAccount(const QString name, const QVariantMap &data) {
77   setLocalValue(QString("Accounts/%2").arg(name), data);
78 }
79
80 QVariantMap CoreAccountSettings::retrieveAccount(const QString &name) {
81   return localValue(QString("Accounts/%2").arg(name), QVariant()).toMap();
82 }
83
84 void CoreAccountSettings::storeAllAccounts(const QHash<QString, QVariantMap> accounts) {
85   removeLocalKey(QString("Accounts"));
86   foreach(QString name, accounts.keys()) {
87     storeAccount(name, accounts[name]);
88   }
89 }
90
91 QHash<QString, QVariantMap> CoreAccountSettings::retrieveAllAccounts() {
92   QHash<QString, QVariantMap> accounts;
93   foreach(QString name, knownAccounts()) {
94     accounts[name] = retrieveAccount(name);
95   }
96   return accounts;
97 }
98
99 void CoreAccountSettings::removeAccount(const QString &account) {
100   removeLocalKey(QString("Accounts/%1").arg(account));
101 }
102
103