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(QString key, localChildGroups()) {
56 AccountId acc = key.toInt();
57 if(acc.isValid()) ids << acc;
62 AccountId CoreAccountSettings::lastAccount() {
63 return localValue("LastAccount", 0).toInt();
66 void CoreAccountSettings::setLastAccount(AccountId account) {
67 setLocalValue("LastAccount", account.toInt());
70 AccountId CoreAccountSettings::autoConnectAccount() {
71 return localValue("AutoConnectAccount", 0).toInt();
74 void CoreAccountSettings::setAutoConnectAccount(AccountId account) {
75 setLocalValue("AutoConnectAccount", account.toInt());
78 void CoreAccountSettings::storeAccountData(AccountId id, const QVariantMap &data) {
79 setLocalValue(QString("%1/Connection").arg(id.toInt()), data);
82 QVariantMap CoreAccountSettings::retrieveAccountData(AccountId id) {
83 return localValue(QString("%1/Connection").arg(id.toInt()), QVariant()).toMap();
86 void CoreAccountSettings::setAccountValue(const QString &key, const QVariant &value) {
87 if(!Client::currentCoreAccount().isValid()) return;
88 setLocalValue(QString("%1/%2/%3").arg(Client::currentCoreAccount().toInt()).arg(_subgroup).arg(key), value);
91 QVariant CoreAccountSettings::accountValue(const QString &key, const QVariant &def) {
92 if(!Client::currentCoreAccount().isValid()) return QVariant();
93 return localValue(QString("%1/%2/%3").arg(Client::currentCoreAccount().toInt()).arg(_subgroup).arg(key), def);
96 void CoreAccountSettings::setJumpKeyMap(const QHash<int, BufferId> &keyMap) {
98 QHash<int, BufferId>::const_iterator mapIter = keyMap.constBegin();
99 while(mapIter != keyMap.constEnd()) {
100 variants[QString::number(mapIter.key())] = qVariantFromValue(mapIter.value());
103 setLocalValue("JumpKeyMap", variants);
106 QHash<int, BufferId> CoreAccountSettings::jumpKeyMap() {
107 QHash<int, BufferId> keyMap;
108 QVariantMap variants = localValue("JumpKeyMap", QVariant()).toMap();
109 QVariantMap::const_iterator mapIter = variants.constBegin();
110 while(mapIter != variants.constEnd()) {
111 keyMap[mapIter.key().toInt()] = mapIter.value().value<BufferId>();
117 void CoreAccountSettings::removeAccount(AccountId id) {
118 removeLocalKey(QString("%1").arg(id.toInt()));
122 /***********************************************************************************************/
123 // NotificationSettings:
125 NotificationSettings::NotificationSettings() : ClientSettings("Notification") {
128 void NotificationSettings::setHighlightList(const QVariantList &highlightList) {
129 setLocalValue("Highlights/CustomList", highlightList);
132 QVariantList NotificationSettings::highlightList() {
133 return localValue("Highlights/CustomList").toList();
136 void NotificationSettings::setHighlightNick(NotificationSettings::HighlightNickType highlightNickType) {
137 setLocalValue("Highlights/HighlightNick", highlightNickType);
140 NotificationSettings::HighlightNickType NotificationSettings::highlightNick() {
141 return (NotificationSettings::HighlightNickType) localValue("Highlights/HighlightNick", CurrentNick).toInt();
144 void NotificationSettings::setNicksCaseSensitive(bool cs) {
145 setLocalValue("Highlights/NicksCaseSensitive", cs);
148 bool NotificationSettings::nicksCaseSensitive() {
149 return localValue("Highlights/NicksCaseSensitive", false).toBool();
153 // ========================================
154 // KnownHostsSettings
155 // ========================================
156 KnownHostsSettings::KnownHostsSettings()
157 : ClientSettings("KnownHosts")
161 QByteArray KnownHostsSettings::knownDigest(const QHostAddress &address) {
162 return localValue(address.toString(), QByteArray()).toByteArray();
165 void KnownHostsSettings::saveKnownHost(const QHostAddress &address, const QByteArray &certDigest) {
166 setLocalValue(address.toString(), certDigest);
169 bool KnownHostsSettings::isKnownHost(const QHostAddress &address, const QByteArray &certDigest) {
170 return certDigest == localValue(address.toString(), QByteArray()).toByteArray();
174 QByteArray KnownHostsSettings::knownDigest(const QSslSocket *socket) {
175 return knownDigest(socket->peerAddress());
178 void KnownHostsSettings::saveKnownHost(const QSslSocket *socket) {
180 saveKnownHost(socket->peerAddress(), socket->peerCertificate().digest());
183 bool KnownHostsSettings::isKnownHost(const QSslSocket *socket) {
185 return isKnownHost(socket->peerAddress(), socket->peerCertificate().digest());