1 /***************************************************************************
2 * Copyright (C) 2005-2018 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 ***************************************************************************/
23 #include <QStringList>
25 #include "clientsettings.h"
27 #include <QHostAddress>
35 ClientSettings::ClientSettings(QString g) : Settings(g, Quassel::buildInfo().clientApplicationName)
40 ClientSettings::~ClientSettings()
45 /***********************************************************************************************/
47 CoreAccountSettings::CoreAccountSettings(QString subgroup)
48 : ClientSettings("CoreAccounts"),
49 _subgroup(std::move(subgroup))
54 void CoreAccountSettings::notify(const QString &key, QObject *receiver, const char *slot)
56 ClientSettings::notify(QString("%1/%2/%3").arg(Client::currentCoreAccount().accountId().toInt()).arg(_subgroup).arg(key), receiver, slot);
60 QList<AccountId> CoreAccountSettings::knownAccounts()
63 foreach(const QString &key, localChildGroups()) {
64 AccountId acc = key.toInt();
72 AccountId CoreAccountSettings::lastAccount()
74 return localValue("LastAccount", 0).toInt();
78 void CoreAccountSettings::setLastAccount(AccountId account)
80 setLocalValue("LastAccount", account.toInt());
84 AccountId CoreAccountSettings::autoConnectAccount()
86 return localValue("AutoConnectAccount", 0).toInt();
90 void CoreAccountSettings::setAutoConnectAccount(AccountId account)
92 setLocalValue("AutoConnectAccount", account.toInt());
96 bool CoreAccountSettings::autoConnectOnStartup()
98 return localValue("AutoConnectOnStartup", false).toBool();
102 void CoreAccountSettings::setAutoConnectOnStartup(bool b)
104 setLocalValue("AutoConnectOnStartup", b);
108 bool CoreAccountSettings::autoConnectToFixedAccount()
110 return localValue("AutoConnectToFixedAccount", false).toBool();
114 void CoreAccountSettings::setAutoConnectToFixedAccount(bool b)
116 setLocalValue("AutoConnectToFixedAccount", b);
120 void CoreAccountSettings::storeAccountData(AccountId id, const QVariantMap &data)
122 QString base = QString::number(id.toInt());
123 foreach(const QString &key, data.keys()) {
124 setLocalValue(base + "/" + key, data.value(key));
127 // FIXME Migration from 0.5 -> 0.6
128 removeLocalKey(QString("%1/Connection").arg(base));
132 QVariantMap CoreAccountSettings::retrieveAccountData(AccountId id)
135 QString base = QString::number(id.toInt());
136 foreach(const QString &key, localChildKeys(base)) {
137 map[key] = localValue(base + "/" + key);
140 // FIXME Migration from 0.5 -> 0.6
141 if (!map.contains("Uuid") && map.contains("Connection")) {
142 QVariantMap oldmap = map.value("Connection").toMap();
143 map["AccountName"] = oldmap.value("AccountName");
144 map["HostName"] = oldmap.value("Host");
145 map["Port"] = oldmap.value("Port");
146 map["User"] = oldmap.value("User");
147 map["Password"] = oldmap.value("Password");
148 map["StorePassword"] = oldmap.value("RememberPasswd");
149 map["UseSSL"] = oldmap.value("useSsl");
150 map["UseProxy"] = oldmap.value("useProxy");
151 map["ProxyHostName"] = oldmap.value("proxyHost");
152 map["ProxyPort"] = oldmap.value("proxyPort");
153 map["ProxyUser"] = oldmap.value("proxyUser");
154 map["ProxyPassword"] = oldmap.value("proxyPassword");
155 map["ProxyType"] = oldmap.value("proxyType");
156 map["Internal"] = oldmap.value("InternalAccount");
158 map["AccountId"] = id.toInt();
159 map["Uuid"] = QUuid::createUuid().toString();
166 void CoreAccountSettings::setAccountValue(const QString &key, const QVariant &value)
168 if (!Client::currentCoreAccount().isValid())
170 setLocalValue(QString("%1/%2/%3").arg(Client::currentCoreAccount().accountId().toInt()).arg(_subgroup).arg(key), value);
174 QVariant CoreAccountSettings::accountValue(const QString &key, const QVariant &def)
176 if (!Client::currentCoreAccount().isValid())
178 return localValue(QString("%1/%2/%3").arg(Client::currentCoreAccount().accountId().toInt()).arg(_subgroup).arg(key), def);
182 void CoreAccountSettings::setJumpKeyMap(const QHash<int, BufferId> &keyMap)
184 QVariantMap variants;
185 QHash<int, BufferId>::const_iterator mapIter = keyMap.constBegin();
186 while (mapIter != keyMap.constEnd()) {
187 variants[QString::number(mapIter.key())] = qVariantFromValue(mapIter.value());
190 setAccountValue("JumpKeyMap", variants);
194 QHash<int, BufferId> CoreAccountSettings::jumpKeyMap()
196 QHash<int, BufferId> keyMap;
197 QVariantMap variants = accountValue("JumpKeyMap", QVariant()).toMap();
198 QVariantMap::const_iterator mapIter = variants.constBegin();
199 while (mapIter != variants.constEnd()) {
200 keyMap[mapIter.key().toInt()] = mapIter.value().value<BufferId>();
207 void CoreAccountSettings::setBufferViewOverlay(const QSet<int> &viewIds)
209 QVariantList variants;
210 foreach(int viewId, viewIds) {
211 variants << qVariantFromValue(viewId);
213 setAccountValue("BufferViewOverlay", variants);
217 QSet<int> CoreAccountSettings::bufferViewOverlay()
220 QVariantList variants = accountValue("BufferViewOverlay").toList();
221 for (QVariantList::const_iterator iter = variants.constBegin(); iter != variants.constEnd(); ++iter) {
222 viewIds << iter->toInt();
228 void CoreAccountSettings::removeAccount(AccountId id)
230 removeLocalKey(QString("%1").arg(id.toInt()));
234 void CoreAccountSettings::clearAccounts()
236 foreach(const QString &key, localChildGroups())
241 /***********************************************************************************************/
242 // CoreConnectionSettings:
244 CoreConnectionSettings::CoreConnectionSettings() : ClientSettings("CoreConnection") {}
246 void CoreConnectionSettings::setNetworkDetectionMode(NetworkDetectionMode mode)
248 setLocalValue("NetworkDetectionMode", mode);
252 CoreConnectionSettings::NetworkDetectionMode CoreConnectionSettings::networkDetectionMode()
254 auto mode = localValue("NetworkDetectionMode", UseQNetworkConfigurationManager).toInt();
256 mode = UseQNetworkConfigurationManager; // UseSolid is gone, map that to the new default
257 return static_cast<NetworkDetectionMode>(mode);
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",
326 CurrentNick).toInt();
330 void NotificationSettings::setNicksCaseSensitive(bool cs)
332 setLocalValue("Highlights/NicksCaseSensitive", cs);
336 bool NotificationSettings::nicksCaseSensitive()
338 return localValue("Highlights/NicksCaseSensitive", false).toBool();
342 // ========================================
343 // TabCompletionSettings
344 // ========================================
346 TabCompletionSettings::TabCompletionSettings() : ClientSettings("TabCompletion")
351 void TabCompletionSettings::setCompletionSuffix(const QString &suffix)
353 setLocalValue("CompletionSuffix", suffix);
357 QString TabCompletionSettings::completionSuffix()
359 return localValue("CompletionSuffix", ": ").toString();
363 void TabCompletionSettings::setAddSpaceMidSentence(bool space)
365 setLocalValue("AddSpaceMidSentence", space);
369 bool TabCompletionSettings::addSpaceMidSentence()
371 return localValue("AddSpaceMidSentence", false).toBool();
375 void TabCompletionSettings::setSortMode(SortMode mode)
377 setLocalValue("SortMode", mode);
381 TabCompletionSettings::SortMode TabCompletionSettings::sortMode()
383 return static_cast<SortMode>(localValue("SortMode"), LastActivity);
387 void TabCompletionSettings::setCaseSensitivity(Qt::CaseSensitivity cs)
389 setLocalValue("CaseSensitivity", cs);
393 Qt::CaseSensitivity TabCompletionSettings::caseSensitivity()
395 return (Qt::CaseSensitivity)localValue("CaseSensitivity", Qt::CaseInsensitive).toInt();
399 void TabCompletionSettings::setUseLastSpokenTo(bool use)
401 setLocalValue("UseLastSpokenTo", use);
405 bool TabCompletionSettings::useLastSpokenTo()
407 return localValue("UseLastSpokenTo", false).toBool();
411 // ========================================
413 // ========================================
415 ItemViewSettings::ItemViewSettings(const QString &group) : ClientSettings(group)
420 bool ItemViewSettings::displayTopicInTooltip()
422 return localValue("DisplayTopicInTooltip", false).toBool();
426 bool ItemViewSettings::mouseWheelChangesBuffer()
428 return localValue("MouseWheelChangesBuffer", false).toBool();