1 /***************************************************************************
2 * Copyright (C) 2005-2013 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 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
19 ***************************************************************************/
21 #include <QStringList>
23 #include "clientsettings.h"
25 #include <QHostAddress>
33 ClientSettings::ClientSettings(QString g) : Settings(g, Quassel::buildInfo().clientApplicationName)
38 ClientSettings::~ClientSettings()
43 /***********************************************************************************************/
45 CoreAccountSettings::CoreAccountSettings(const QString &subgroup)
46 : ClientSettings("CoreAccounts"),
52 void CoreAccountSettings::notify(const QString &key, QObject *receiver, const char *slot)
54 ClientSettings::notify(QString("%1/%2/%3").arg(Client::currentCoreAccount().accountId().toInt()).arg(_subgroup).arg(key), receiver, slot);
58 QList<AccountId> CoreAccountSettings::knownAccounts()
61 foreach(const QString &key, localChildGroups()) {
62 AccountId acc = key.toInt();
70 AccountId CoreAccountSettings::lastAccount()
72 return localValue("LastAccount", 0).toInt();
76 void CoreAccountSettings::setLastAccount(AccountId account)
78 setLocalValue("LastAccount", account.toInt());
82 AccountId CoreAccountSettings::autoConnectAccount()
84 return localValue("AutoConnectAccount", 0).toInt();
88 void CoreAccountSettings::setAutoConnectAccount(AccountId account)
90 setLocalValue("AutoConnectAccount", account.toInt());
94 bool CoreAccountSettings::autoConnectOnStartup()
96 return localValue("AutoConnectOnStartup", false).toBool();
100 void CoreAccountSettings::setAutoConnectOnStartup(bool b)
102 setLocalValue("AutoConnectOnStartup", b);
106 bool CoreAccountSettings::autoConnectToFixedAccount()
108 return localValue("AutoConnectToFixedAccount", false).toBool();
112 void CoreAccountSettings::setAutoConnectToFixedAccount(bool b)
114 setLocalValue("AutoConnectToFixedAccount", b);
118 void CoreAccountSettings::storeAccountData(AccountId id, const QVariantMap &data)
120 QString base = QString::number(id.toInt());
121 foreach(const QString &key, data.keys()) {
122 setLocalValue(base + "/" + key, data.value(key));
125 // FIXME Migration from 0.5 -> 0.6
126 removeLocalKey(QString("%1/Connection").arg(base));
130 QVariantMap CoreAccountSettings::retrieveAccountData(AccountId id)
133 QString base = QString::number(id.toInt());
134 foreach(const QString &key, localChildKeys(base)) {
135 map[key] = localValue(base + "/" + key);
138 // FIXME Migration from 0.5 -> 0.6
139 if (!map.contains("Uuid") && map.contains("Connection")) {
140 QVariantMap oldmap = map.value("Connection").toMap();
141 map["AccountName"] = oldmap.value("AccountName");
142 map["HostName"] = oldmap.value("Host");
143 map["Port"] = oldmap.value("Port");
144 map["User"] = oldmap.value("User");
145 map["Password"] = oldmap.value("Password");
146 map["StorePassword"] = oldmap.value("RememberPasswd");
147 map["UseSSL"] = oldmap.value("useSsl");
148 map["UseProxy"] = oldmap.value("useProxy");
149 map["ProxyHostName"] = oldmap.value("proxyHost");
150 map["ProxyPort"] = oldmap.value("proxyPort");
151 map["ProxyUser"] = oldmap.value("proxyUser");
152 map["ProxyPassword"] = oldmap.value("proxyPassword");
153 map["ProxyType"] = oldmap.value("proxyType");
154 map["Internal"] = oldmap.value("InternalAccount");
156 map["AccountId"] = id.toInt();
157 map["Uuid"] = QUuid::createUuid().toString();
164 void CoreAccountSettings::setAccountValue(const QString &key, const QVariant &value)
166 if (!Client::currentCoreAccount().isValid())
168 setLocalValue(QString("%1/%2/%3").arg(Client::currentCoreAccount().accountId().toInt()).arg(_subgroup).arg(key), value);
172 QVariant CoreAccountSettings::accountValue(const QString &key, const QVariant &def)
174 if (!Client::currentCoreAccount().isValid())
176 return localValue(QString("%1/%2/%3").arg(Client::currentCoreAccount().accountId().toInt()).arg(_subgroup).arg(key), def);
180 void CoreAccountSettings::setJumpKeyMap(const QHash<int, BufferId> &keyMap)
182 QVariantMap variants;
183 QHash<int, BufferId>::const_iterator mapIter = keyMap.constBegin();
184 while (mapIter != keyMap.constEnd()) {
185 variants[QString::number(mapIter.key())] = qVariantFromValue(mapIter.value());
188 setAccountValue("JumpKeyMap", variants);
192 QHash<int, BufferId> CoreAccountSettings::jumpKeyMap()
194 QHash<int, BufferId> keyMap;
195 QVariantMap variants = accountValue("JumpKeyMap", QVariant()).toMap();
196 QVariantMap::const_iterator mapIter = variants.constBegin();
197 while (mapIter != variants.constEnd()) {
198 keyMap[mapIter.key().toInt()] = mapIter.value().value<BufferId>();
205 void CoreAccountSettings::setBufferViewOverlay(const QSet<int> &viewIds)
207 QVariantList variants;
208 foreach(int viewId, viewIds) {
209 variants << qVariantFromValue(viewId);
211 setAccountValue("BufferViewOverlay", variants);
215 QSet<int> CoreAccountSettings::bufferViewOverlay()
218 QVariantList variants = accountValue("BufferViewOverlay").toList();
219 for (QVariantList::const_iterator iter = variants.constBegin(); iter != variants.constEnd(); iter++) {
220 viewIds << iter->toInt();
226 void CoreAccountSettings::removeAccount(AccountId id)
228 removeLocalKey(QString("%1").arg(id.toInt()));
232 void CoreAccountSettings::clearAccounts()
234 foreach(const QString &key, localChildGroups())
239 /***********************************************************************************************/
240 // CoreConnectionSettings:
242 CoreConnectionSettings::CoreConnectionSettings() : ClientSettings("CoreConnection") {}
244 void CoreConnectionSettings::setNetworkDetectionMode(NetworkDetectionMode mode)
246 setLocalValue("NetworkDetectionMode", mode);
250 CoreConnectionSettings::NetworkDetectionMode CoreConnectionSettings::networkDetectionMode()
253 NetworkDetectionMode def = UseSolid;
255 NetworkDetectionMode def = UsePingTimeout;
257 return (NetworkDetectionMode)localValue("NetworkDetectionMode", def).toInt();
261 void CoreConnectionSettings::setAutoReconnect(bool autoReconnect)
263 setLocalValue("AutoReconnect", autoReconnect);
267 bool CoreConnectionSettings::autoReconnect()
269 return localValue("AutoReconnect", true).toBool();
273 void CoreConnectionSettings::setPingTimeoutInterval(int interval)
275 setLocalValue("PingTimeoutInterval", interval);
279 int CoreConnectionSettings::pingTimeoutInterval()
281 return localValue("PingTimeoutInterval", 60).toInt();
285 void CoreConnectionSettings::setReconnectInterval(int interval)
287 setLocalValue("ReconnectInterval", interval);
291 int CoreConnectionSettings::reconnectInterval()
293 return localValue("ReconnectInterval", 60).toInt();
297 /***********************************************************************************************/
298 // NotificationSettings:
300 NotificationSettings::NotificationSettings() : ClientSettings("Notification")
305 void NotificationSettings::setHighlightList(const QVariantList &highlightList)
307 setLocalValue("Highlights/CustomList", highlightList);
311 QVariantList NotificationSettings::highlightList()
313 return localValue("Highlights/CustomList").toList();
317 void NotificationSettings::setHighlightNick(NotificationSettings::HighlightNickType highlightNickType)
319 setLocalValue("Highlights/HighlightNick", highlightNickType);
323 NotificationSettings::HighlightNickType NotificationSettings::highlightNick()
325 return (NotificationSettings::HighlightNickType)localValue("Highlights/HighlightNick", CurrentNick).toInt();
329 void NotificationSettings::setNicksCaseSensitive(bool cs)
331 setLocalValue("Highlights/NicksCaseSensitive", cs);
335 bool NotificationSettings::nicksCaseSensitive()
337 return localValue("Highlights/NicksCaseSensitive", false).toBool();
341 // ========================================
342 // TabCompletionSettings
343 // ========================================
345 TabCompletionSettings::TabCompletionSettings() : ClientSettings("TabCompletion")
350 void TabCompletionSettings::setCompletionSuffix(const QString &suffix)
352 setLocalValue("CompletionSuffix", suffix);
356 QString TabCompletionSettings::completionSuffix()
358 return localValue("CompletionSuffix", ": ").toString();
362 void TabCompletionSettings::setAddSpaceMidSentence(bool space)
364 setLocalValue("AddSpaceMidSentence", space);
368 bool TabCompletionSettings::addSpaceMidSentence()
370 return localValue("AddSpaceMidSentence", false).toBool();
374 void TabCompletionSettings::setSortMode(SortMode mode)
376 setLocalValue("SortMode", mode);
380 TabCompletionSettings::SortMode TabCompletionSettings::sortMode()
382 return static_cast<SortMode>(localValue("SortMode"), LastActivity);
386 void TabCompletionSettings::setCaseSensitivity(Qt::CaseSensitivity cs)
388 setLocalValue("CaseSensitivity", cs);
392 Qt::CaseSensitivity TabCompletionSettings::caseSensitivity()
394 return (Qt::CaseSensitivity)localValue("CaseSensitivity", Qt::CaseInsensitive).toInt();
398 void TabCompletionSettings::setUseLastSpokenTo(bool use)
400 setLocalValue("UseLastSpokenTo", use);
404 bool TabCompletionSettings::useLastSpokenTo()
406 return localValue("UseLastSpokenTo", false).toBool();
410 // ========================================
412 // ========================================
414 ItemViewSettings::ItemViewSettings(const QString &group) : ClientSettings(group)
419 bool ItemViewSettings::displayTopicInTooltip()
421 return localValue("DisplayTopicInTooltip", false).toBool();
425 bool ItemViewSettings::mouseWheelChangesBuffer()
427 return localValue("MouseWheelChangesBuffer", false).toBool();