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().accountId().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 bool CoreAccountSettings::autoConnectOnStartup() {
80 return localValue("AutoConnectOnStartup", false).toBool();
83 void CoreAccountSettings::setAutoConnectOnStartup(bool b) {
84 setLocalValue("AutoConnectOnStartup", b);
87 bool CoreAccountSettings::autoConnectToFixedAccount() {
88 return localValue("AutoConnectToFixedAccount", false).toBool();
91 void CoreAccountSettings::setAutoConnectToFixedAccount(bool b) {
92 setLocalValue("AutoConnectToFixedAccount", b);
95 void CoreAccountSettings::storeAccountData(AccountId id, const QVariantMap &data) {
96 QString base = QString::number(id.toInt());
97 foreach(const QString &key, data.keys()) {
98 setLocalValue(base + "/" + key, data.value(key));
101 // FIXME Migration from 0.5 -> 0.6
102 removeLocalKey(QString("%1/Connection").arg(base));
105 QVariantMap CoreAccountSettings::retrieveAccountData(AccountId id) {
107 QString base = QString::number(id.toInt());
108 foreach(const QString &key, localChildKeys(base)) {
109 map[key] = localValue(base + "/" + key);
112 // FIXME Migration from 0.5 -> 0.6
113 if(!map.contains("Uuid") && map.contains("Connection")) {
114 QVariantMap oldmap = map.value("Connection").toMap();
115 map["AccountName"] = oldmap.value("AccountName");
116 map["HostName"] = oldmap.value("Host");
117 map["Port"] = oldmap.value("Port");
118 map["User"] = oldmap.value("User");
119 map["Password"] = oldmap.value("Password");
120 map["StorePassword"] = oldmap.value("RememberPasswd");
121 map["UseSSL"] = oldmap.value("useSsl");
122 map["UseProxy"] = oldmap.value("useProxy");
123 map["ProxyHostName"] = oldmap.value("proxyHost");
124 map["ProxyPort"] = oldmap.value("proxyPort");
125 map["ProxyUser"] = oldmap.value("proxyUser");
126 map["ProxyPassword"] = oldmap.value("proxyPassword");
127 map["ProxyType"] = oldmap.value("proxyType");
128 map["Internal"] = oldmap.value("InternalAccount");
130 map["AccountId"] = id.toInt();
131 map["Uuid"] = QUuid::createUuid().toString();
137 void CoreAccountSettings::setAccountValue(const QString &key, const QVariant &value) {
138 if(!Client::currentCoreAccount().isValid())
140 setLocalValue(QString("%1/%2/%3").arg(Client::currentCoreAccount().accountId().toInt()).arg(_subgroup).arg(key), value);
143 QVariant CoreAccountSettings::accountValue(const QString &key, const QVariant &def) {
144 if(!Client::currentCoreAccount().isValid())
146 return localValue(QString("%1/%2/%3").arg(Client::currentCoreAccount().accountId().toInt()).arg(_subgroup).arg(key), def);
149 void CoreAccountSettings::setJumpKeyMap(const QHash<int, BufferId> &keyMap) {
150 QVariantMap variants;
151 QHash<int, BufferId>::const_iterator mapIter = keyMap.constBegin();
152 while(mapIter != keyMap.constEnd()) {
153 variants[QString::number(mapIter.key())] = qVariantFromValue(mapIter.value());
156 setAccountValue("JumpKeyMap", variants);
159 QHash<int, BufferId> CoreAccountSettings::jumpKeyMap() {
160 QHash<int, BufferId> keyMap;
161 QVariantMap variants = accountValue("JumpKeyMap", QVariant()).toMap();
162 QVariantMap::const_iterator mapIter = variants.constBegin();
163 while(mapIter != variants.constEnd()) {
164 keyMap[mapIter.key().toInt()] = mapIter.value().value<BufferId>();
170 void CoreAccountSettings::removeAccount(AccountId id) {
171 removeLocalKey(QString("%1").arg(id.toInt()));
174 void CoreAccountSettings::clearAccounts() {
175 foreach(const QString &key, localChildGroups())
179 /***********************************************************************************************/
180 // CoreConnectionSettings:
182 CoreConnectionSettings::CoreConnectionSettings() : ClientSettings("CoreConnection") {}
184 void CoreConnectionSettings::setNetworkDetectionMode(NetworkDetectionMode mode) {
185 setLocalValue("NetworkDetectionMode", mode);
188 CoreConnectionSettings::NetworkDetectionMode CoreConnectionSettings::networkDetectionMode() {
190 NetworkDetectionMode def = UseSolid;
192 NetworkDetectionMode def = UsePingTimeout;
194 return (NetworkDetectionMode)localValue("NetworkDetectionMode", def).toInt();
197 void CoreConnectionSettings::setAutoReconnect(bool autoReconnect) {
198 setLocalValue("AutoReconnect", autoReconnect);
201 bool CoreConnectionSettings::autoReconnect() {
202 return localValue("AutoReconnect", true).toBool();
205 void CoreConnectionSettings::setPingTimeoutInterval(int interval) {
206 setLocalValue("PingTimeoutInterval", interval);
209 int CoreConnectionSettings::pingTimeoutInterval() {
210 return localValue("PingTimeoutInterval", 60).toInt();
213 void CoreConnectionSettings::setReconnectInterval(int interval) {
214 setLocalValue("ReconnectInterval", interval);
217 int CoreConnectionSettings::reconnectInterval() {
218 return localValue("ReconnectInterval", 60).toInt();
221 /***********************************************************************************************/
222 // NotificationSettings:
224 NotificationSettings::NotificationSettings() : ClientSettings("Notification") {
227 void NotificationSettings::setHighlightList(const QVariantList &highlightList) {
228 setLocalValue("Highlights/CustomList", highlightList);
231 QVariantList NotificationSettings::highlightList() {
232 return localValue("Highlights/CustomList").toList();
235 void NotificationSettings::setHighlightNick(NotificationSettings::HighlightNickType highlightNickType) {
236 setLocalValue("Highlights/HighlightNick", highlightNickType);
239 NotificationSettings::HighlightNickType NotificationSettings::highlightNick() {
240 return (NotificationSettings::HighlightNickType) localValue("Highlights/HighlightNick", CurrentNick).toInt();
243 void NotificationSettings::setNicksCaseSensitive(bool cs) {
244 setLocalValue("Highlights/NicksCaseSensitive", cs);
247 bool NotificationSettings::nicksCaseSensitive() {
248 return localValue("Highlights/NicksCaseSensitive", false).toBool();
251 // ========================================
252 // TabCompletionSettings
253 // ========================================
255 TabCompletionSettings::TabCompletionSettings() : ClientSettings("TabCompletion") {
258 void TabCompletionSettings::setCompletionSuffix(const QString &suffix) {
259 setLocalValue("CompletionSuffix", suffix);
262 QString TabCompletionSettings::completionSuffix() {
263 return localValue("CompletionSuffix", ": ").toString();
266 void TabCompletionSettings::setSortMode(SortMode mode) {
267 setLocalValue("SortMode", mode);
270 TabCompletionSettings::SortMode TabCompletionSettings::sortMode() {
271 return static_cast<SortMode>(localValue("SortMode"), LastActivity);
274 void TabCompletionSettings::setCaseSensitivity(Qt::CaseSensitivity cs) {
275 setLocalValue("CaseSensitivity", cs);
278 Qt::CaseSensitivity TabCompletionSettings::caseSensitivity() {
279 return (Qt::CaseSensitivity)localValue("CaseSensitivity", Qt::CaseInsensitive).toInt();
282 void TabCompletionSettings::setUseLastSpokenTo(bool use) {
283 setLocalValue("UseLastSpokenTo", use);
286 bool TabCompletionSettings::useLastSpokenTo() {
287 return localValue("UseLastSpokenTo", false).toBool();
290 // ========================================
292 // ========================================
294 ItemViewSettings::ItemViewSettings(const QString &group) : ClientSettings(group) {
298 bool ItemViewSettings::displayTopicInTooltip() {
299 return localValue("DisplayTopicInTooltip", false).toBool();
302 bool ItemViewSettings::mouseWheelChangesBuffer() {
303 return localValue("MouseWheelChangesBuffer", false).toBool();