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 ***************************************************************************/
21 #include <QStringList>
23 #include "clientsettings.h"
25 #include <QHostAddress>
34 ClientSettings::ClientSettings(QString g) : Settings(g, Quassel::buildInfo().clientApplicationName)
39 ClientSettings::~ClientSettings()
44 /***********************************************************************************************/
46 CoreAccountSettings::CoreAccountSettings(QString subgroup)
47 : ClientSettings("CoreAccounts"),
48 _subgroup(std::move(subgroup))
53 void CoreAccountSettings::notify(const QString &key, QObject *receiver, const char *slot)
55 ClientSettings::notify(QString("%1/%2/%3").arg(Client::currentCoreAccount().accountId().toInt()).arg(_subgroup).arg(key), receiver, slot);
59 QList<AccountId> CoreAccountSettings::knownAccounts()
62 foreach(const QString &key, localChildGroups()) {
63 AccountId acc = key.toInt();
71 AccountId CoreAccountSettings::lastAccount()
73 return localValue("LastAccount", 0).toInt();
77 void CoreAccountSettings::setLastAccount(AccountId account)
79 setLocalValue("LastAccount", account.toInt());
83 AccountId CoreAccountSettings::autoConnectAccount()
85 return localValue("AutoConnectAccount", 0).toInt();
89 void CoreAccountSettings::setAutoConnectAccount(AccountId account)
91 setLocalValue("AutoConnectAccount", account.toInt());
95 bool CoreAccountSettings::autoConnectOnStartup()
97 return localValue("AutoConnectOnStartup", false).toBool();
101 void CoreAccountSettings::setAutoConnectOnStartup(bool b)
103 setLocalValue("AutoConnectOnStartup", b);
107 bool CoreAccountSettings::autoConnectToFixedAccount()
109 return localValue("AutoConnectToFixedAccount", false).toBool();
113 void CoreAccountSettings::setAutoConnectToFixedAccount(bool b)
115 setLocalValue("AutoConnectToFixedAccount", b);
119 void CoreAccountSettings::storeAccountData(AccountId id, const QVariantMap &data)
121 QString base = QString::number(id.toInt());
122 foreach(const QString &key, data.keys()) {
123 setLocalValue(base + "/" + key, data.value(key));
126 // FIXME Migration from 0.5 -> 0.6
127 removeLocalKey(QString("%1/Connection").arg(base));
131 QVariantMap CoreAccountSettings::retrieveAccountData(AccountId id)
134 QString base = QString::number(id.toInt());
135 foreach(const QString &key, localChildKeys(base)) {
136 map[key] = localValue(base + "/" + key);
139 // FIXME Migration from 0.5 -> 0.6
140 if (!map.contains("Uuid") && map.contains("Connection")) {
141 QVariantMap oldmap = map.value("Connection").toMap();
142 map["AccountName"] = oldmap.value("AccountName");
143 map["HostName"] = oldmap.value("Host");
144 map["Port"] = oldmap.value("Port");
145 map["User"] = oldmap.value("User");
146 map["Password"] = oldmap.value("Password");
147 map["StorePassword"] = oldmap.value("RememberPasswd");
148 map["UseSSL"] = oldmap.value("useSsl");
149 map["UseProxy"] = oldmap.value("useProxy");
150 map["ProxyHostName"] = oldmap.value("proxyHost");
151 map["ProxyPort"] = oldmap.value("proxyPort");
152 map["ProxyUser"] = oldmap.value("proxyUser");
153 map["ProxyPassword"] = oldmap.value("proxyPassword");
154 map["ProxyType"] = oldmap.value("proxyType");
155 map["Internal"] = oldmap.value("InternalAccount");
157 map["AccountId"] = id.toInt();
158 map["Uuid"] = QUuid::createUuid().toString();
165 void CoreAccountSettings::setAccountValue(const QString &key, const QVariant &value)
167 if (!Client::currentCoreAccount().isValid())
169 setLocalValue(QString("%1/%2/%3").arg(Client::currentCoreAccount().accountId().toInt()).arg(_subgroup).arg(key), value);
173 QVariant CoreAccountSettings::accountValue(const QString &key, const QVariant &def)
175 if (!Client::currentCoreAccount().isValid())
177 return localValue(QString("%1/%2/%3").arg(Client::currentCoreAccount().accountId().toInt()).arg(_subgroup).arg(key), def);
181 void CoreAccountSettings::setJumpKeyMap(const QHash<int, BufferId> &keyMap)
183 QVariantMap variants;
184 QHash<int, BufferId>::const_iterator mapIter = keyMap.constBegin();
185 while (mapIter != keyMap.constEnd()) {
186 variants[QString::number(mapIter.key())] = qVariantFromValue(mapIter.value());
189 setAccountValue("JumpKeyMap", variants);
193 QHash<int, BufferId> CoreAccountSettings::jumpKeyMap()
195 QHash<int, BufferId> keyMap;
196 QVariantMap variants = accountValue("JumpKeyMap", QVariant()).toMap();
197 QVariantMap::const_iterator mapIter = variants.constBegin();
198 while (mapIter != variants.constEnd()) {
199 keyMap[mapIter.key().toInt()] = mapIter.value().value<BufferId>();
206 void CoreAccountSettings::setBufferViewOverlay(const QSet<int> &viewIds)
208 QVariantList variants;
209 foreach(int viewId, viewIds) {
210 variants << qVariantFromValue(viewId);
212 setAccountValue("BufferViewOverlay", variants);
216 QSet<int> CoreAccountSettings::bufferViewOverlay()
219 QVariantList variants = accountValue("BufferViewOverlay").toList();
220 for (QVariantList::const_iterator iter = variants.constBegin(); iter != variants.constEnd(); ++iter) {
221 viewIds << iter->toInt();
227 void CoreAccountSettings::removeAccount(AccountId id)
229 removeLocalKey(QString("%1").arg(id.toInt()));
233 void CoreAccountSettings::clearAccounts()
235 foreach(const QString &key, localChildGroups())
240 /***********************************************************************************************/
241 // CoreConnectionSettings:
243 CoreConnectionSettings::CoreConnectionSettings() : ClientSettings("CoreConnection") {}
245 void CoreConnectionSettings::setNetworkDetectionMode(NetworkDetectionMode mode)
247 setLocalValue("NetworkDetectionMode", mode);
251 CoreConnectionSettings::NetworkDetectionMode CoreConnectionSettings::networkDetectionMode()
253 auto mode = localValue("NetworkDetectionMode", UseQNetworkConfigurationManager).toInt();
255 mode = UseQNetworkConfigurationManager; // UseSolid is gone, map that to the new default
256 return static_cast<NetworkDetectionMode>(mode);
260 void CoreConnectionSettings::setAutoReconnect(bool autoReconnect)
262 setLocalValue("AutoReconnect", autoReconnect);
266 bool CoreConnectionSettings::autoReconnect()
268 return localValue("AutoReconnect", true).toBool();
272 void CoreConnectionSettings::setPingTimeoutInterval(int interval)
274 setLocalValue("PingTimeoutInterval", interval);
278 int CoreConnectionSettings::pingTimeoutInterval()
280 return localValue("PingTimeoutInterval", 60).toInt();
284 void CoreConnectionSettings::setReconnectInterval(int interval)
286 setLocalValue("ReconnectInterval", interval);
290 int CoreConnectionSettings::reconnectInterval()
292 return localValue("ReconnectInterval", 60).toInt();
296 /***********************************************************************************************/
297 // NotificationSettings:
299 NotificationSettings::NotificationSettings() : ClientSettings("Notification")
304 void NotificationSettings::setHighlightList(const QVariantList &highlightList)
306 setLocalValue("Highlights/CustomList", highlightList);
310 QVariantList NotificationSettings::highlightList()
312 return localValue("Highlights/CustomList").toList();
316 void NotificationSettings::setHighlightNick(NotificationSettings::HighlightNickType highlightNickType)
318 setLocalValue("Highlights/HighlightNick", highlightNickType);
322 NotificationSettings::HighlightNickType NotificationSettings::highlightNick()
324 return (NotificationSettings::HighlightNickType)localValue("Highlights/HighlightNick",
325 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();