1 /***************************************************************************
2 * Copyright (C) 2005-09 by the Quassel Project *
3 * devel@quassel-irc.org *
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. *
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. *
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 ***************************************************************************/
21 #include <QStringList>
24 #include "clientsettings.h"
26 #include <QHostAddress>
35 ClientSettings::ClientSettings(QString g) : Settings(g, Quassel::buildInfo().clientApplicationName) {
38 ClientSettings::~ClientSettings() {
41 /***********************************************************************************************/
43 CoreAccountSettings::CoreAccountSettings(const QString &subgroup)
44 : ClientSettings("CoreAccounts"),
49 void CoreAccountSettings::notify(const QString &key, QObject *receiver, const char *slot) {
50 ClientSettings::notify(QString("%1/%2/%3").arg(Client::currentCoreAccount().toInt()).arg(_subgroup).arg(key), receiver, slot);
53 QList<AccountId> CoreAccountSettings::knownAccounts() {
55 foreach(const QString &key, localChildGroups()) {
56 AccountId acc = key.toInt();
63 AccountId CoreAccountSettings::lastAccount() {
64 return localValue("LastAccount", 0).toInt();
67 void CoreAccountSettings::setLastAccount(AccountId account) {
68 setLocalValue("LastAccount", account.toInt());
71 AccountId CoreAccountSettings::autoConnectAccount() {
72 return localValue("AutoConnectAccount", 0).toInt();
75 void CoreAccountSettings::setAutoConnectAccount(AccountId account) {
76 setLocalValue("AutoConnectAccount", account.toInt());
79 void CoreAccountSettings::storeAccountData(AccountId id, const QVariantMap &data) {
80 QString base = QString::number(id.toInt());
81 foreach(const QString &key, data.keys()) {
82 setLocalValue(base + "/" + key, data.value(key));
85 // FIXME Migration from 0.5 -> 0.6
86 removeLocalKey(QString("%1/Connection").arg(base));
89 QVariantMap CoreAccountSettings::retrieveAccountData(AccountId id) {
91 QString base = QString::number(id.toInt());
92 foreach(const QString &key, localChildKeys(base)) {
93 map[key] = localValue(base + "/" + key);
96 // FIXME Migration from 0.5 -> 0.6
97 if(!map.contains("Uuid") && map.contains("Connection")) {
98 QVariantMap oldmap = map.value("Connection").toMap();
99 map["AccountName"] = oldmap.value("AccountName");
100 map["HostName"] = oldmap.value("Host");
101 map["Port"] = oldmap.value("Port");
102 map["User"] = oldmap.value("User");
103 map["Password"] = oldmap.value("Password");
104 map["StorePassword"] = oldmap.value("RememberPasswd");
105 map["UseSSL"] = oldmap.value("useSsl");
106 map["UseProxy"] = oldmap.value("useProxy");
107 map["ProxyHostName"] = oldmap.value("proxyHost");
108 map["ProxyPort"] = oldmap.value("proxyPort");
109 map["ProxyUser"] = oldmap.value("proxyUser");
110 map["ProxyPassword"] = oldmap.value("proxyPassword");
111 map["ProxyType"] = oldmap.value("proxyType");
113 map["AccountId"] = id.toInt();
114 map["Uuid"] = QUuid::createUuid().toString();
120 void CoreAccountSettings::setAccountValue(const QString &key, const QVariant &value) {
121 if(!Client::currentCoreAccount().isValid())
123 setLocalValue(QString("%1/%2/%3").arg(Client::currentCoreAccount().toInt()).arg(_subgroup).arg(key), value);
126 QVariant CoreAccountSettings::accountValue(const QString &key, const QVariant &def) {
127 if(!Client::currentCoreAccount().isValid())
129 return localValue(QString("%1/%2/%3").arg(Client::currentCoreAccount().toInt()).arg(_subgroup).arg(key), def);
132 void CoreAccountSettings::setJumpKeyMap(const QHash<int, BufferId> &keyMap) {
133 QVariantMap variants;
134 QHash<int, BufferId>::const_iterator mapIter = keyMap.constBegin();
135 while(mapIter != keyMap.constEnd()) {
136 variants[QString::number(mapIter.key())] = qVariantFromValue(mapIter.value());
139 setAccountValue("JumpKeyMap", variants);
142 QHash<int, BufferId> CoreAccountSettings::jumpKeyMap() {
143 QHash<int, BufferId> keyMap;
144 QVariantMap variants = accountValue("JumpKeyMap", QVariant()).toMap();
145 QVariantMap::const_iterator mapIter = variants.constBegin();
146 while(mapIter != variants.constEnd()) {
147 keyMap[mapIter.key().toInt()] = mapIter.value().value<BufferId>();
153 void CoreAccountSettings::removeAccount(AccountId id) {
154 removeLocalKey(QString("%1").arg(id.toInt()));
158 /***********************************************************************************************/
159 // NotificationSettings:
161 NotificationSettings::NotificationSettings() : ClientSettings("Notification") {
164 void NotificationSettings::setHighlightList(const QVariantList &highlightList) {
165 setLocalValue("Highlights/CustomList", highlightList);
168 QVariantList NotificationSettings::highlightList() {
169 return localValue("Highlights/CustomList").toList();
172 void NotificationSettings::setHighlightNick(NotificationSettings::HighlightNickType highlightNickType) {
173 setLocalValue("Highlights/HighlightNick", highlightNickType);
176 NotificationSettings::HighlightNickType NotificationSettings::highlightNick() {
177 return (NotificationSettings::HighlightNickType) localValue("Highlights/HighlightNick", CurrentNick).toInt();
180 void NotificationSettings::setNicksCaseSensitive(bool cs) {
181 setLocalValue("Highlights/NicksCaseSensitive", cs);
184 bool NotificationSettings::nicksCaseSensitive() {
185 return localValue("Highlights/NicksCaseSensitive", false).toBool();
189 // ========================================
190 // KnownHostsSettings
191 // ========================================
192 KnownHostsSettings::KnownHostsSettings()
193 : ClientSettings("KnownHosts")
197 QByteArray KnownHostsSettings::knownDigest(const QHostAddress &address) {
198 return localValue(address.toString(), QByteArray()).toByteArray();
201 void KnownHostsSettings::saveKnownHost(const QHostAddress &address, const QByteArray &certDigest) {
202 setLocalValue(address.toString(), certDigest);
205 bool KnownHostsSettings::isKnownHost(const QHostAddress &address, const QByteArray &certDigest) {
206 return certDigest == localValue(address.toString(), QByteArray()).toByteArray();
210 QByteArray KnownHostsSettings::knownDigest(const QSslSocket *socket) {
211 return knownDigest(socket->peerAddress());
214 void KnownHostsSettings::saveKnownHost(const QSslSocket *socket) {
216 saveKnownHost(socket->peerAddress(), socket->peerCertificate().digest());
219 bool KnownHostsSettings::isKnownHost(const QSslSocket *socket) {
221 return isKnownHost(socket->peerAddress(), socket->peerCertificate().digest());
226 // ========================================
227 // TabCompletionSettings
228 // ========================================
230 TabCompletionSettings::TabCompletionSettings() : ClientSettings("TabCompletion") {
233 void TabCompletionSettings::setCompletionSuffix(const QString &suffix) {
234 setLocalValue("CompletionSuffix", suffix);
237 QString TabCompletionSettings::completionSuffix() {
238 return localValue("CompletionSuffix", ": ").toString();
241 void TabCompletionSettings::setSortMode(SortMode mode) {
242 setLocalValue("SortMode", mode);
245 TabCompletionSettings::SortMode TabCompletionSettings::sortMode() {
246 return static_cast<SortMode>(localValue("SortMode"), LastActivity);
249 void TabCompletionSettings::setCaseSensitivity(Qt::CaseSensitivity cs) {
250 setLocalValue("CaseSensitivity", cs);
253 Qt::CaseSensitivity TabCompletionSettings::caseSensitivity() {
254 return (Qt::CaseSensitivity)localValue("CaseSensitivity", Qt::CaseInsensitive).toInt();
257 void TabCompletionSettings::setUseLastSpokenTo(bool use) {
258 setLocalValue("UseLastSpokenTo", use);
261 bool TabCompletionSettings::useLastSpokenTo() {
262 return localValue("UseLastSpokenTo", false).toBool();
265 // ========================================
267 // ========================================
269 ItemViewSettings::ItemViewSettings(const QString &group) : ClientSettings(group) {
273 bool ItemViewSettings::displayTopicInTooltip() {
274 return localValue("DisplayTopicInTooltip", false).toBool();
277 bool ItemViewSettings::mouseWheelChangesBuffer() {
278 return localValue("MouseWheelChangesBuffer", false).toBool();