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 /***********************************************************************************************/
42 CoreAccountSettings::CoreAccountSettings(QString subgroup)
43 : ClientSettings("CoreAccounts"),
44 _subgroup(std::move(subgroup))
49 void CoreAccountSettings::notify(const QString &key, QObject *receiver, const char *slot)
51 ClientSettings::notify(QString("%1/%2/%3").arg(Client::currentCoreAccount().accountId().toInt()).arg(_subgroup).arg(key), receiver, slot);
55 QList<AccountId> CoreAccountSettings::knownAccounts()
58 foreach(const QString &key, localChildGroups()) {
59 AccountId acc = key.toInt();
67 AccountId CoreAccountSettings::lastAccount()
69 return localValue("LastAccount", 0).toInt();
73 void CoreAccountSettings::setLastAccount(AccountId account)
75 setLocalValue("LastAccount", account.toInt());
79 AccountId CoreAccountSettings::autoConnectAccount()
81 return localValue("AutoConnectAccount", 0).toInt();
85 void CoreAccountSettings::setAutoConnectAccount(AccountId account)
87 setLocalValue("AutoConnectAccount", account.toInt());
91 bool CoreAccountSettings::autoConnectOnStartup()
93 return localValue("AutoConnectOnStartup", false).toBool();
97 void CoreAccountSettings::setAutoConnectOnStartup(bool b)
99 setLocalValue("AutoConnectOnStartup", b);
103 bool CoreAccountSettings::autoConnectToFixedAccount()
105 return localValue("AutoConnectToFixedAccount", false).toBool();
109 void CoreAccountSettings::setAutoConnectToFixedAccount(bool b)
111 setLocalValue("AutoConnectToFixedAccount", b);
115 void CoreAccountSettings::storeAccountData(AccountId id, const QVariantMap &data)
117 QString base = QString::number(id.toInt());
118 foreach(const QString &key, data.keys()) {
119 setLocalValue(base + "/" + key, data.value(key));
122 // FIXME Migration from 0.5 -> 0.6
123 removeLocalKey(QString("%1/Connection").arg(base));
127 QVariantMap CoreAccountSettings::retrieveAccountData(AccountId id)
130 QString base = QString::number(id.toInt());
131 foreach(const QString &key, localChildKeys(base)) {
132 map[key] = localValue(base + "/" + key);
135 // FIXME Migration from 0.5 -> 0.6
136 if (!map.contains("Uuid") && map.contains("Connection")) {
137 QVariantMap oldmap = map.value("Connection").toMap();
138 map["AccountName"] = oldmap.value("AccountName");
139 map["HostName"] = oldmap.value("Host");
140 map["Port"] = oldmap.value("Port");
141 map["User"] = oldmap.value("User");
142 map["Password"] = oldmap.value("Password");
143 map["StorePassword"] = oldmap.value("RememberPasswd");
144 map["UseSSL"] = oldmap.value("useSsl");
145 map["UseProxy"] = oldmap.value("useProxy");
146 map["ProxyHostName"] = oldmap.value("proxyHost");
147 map["ProxyPort"] = oldmap.value("proxyPort");
148 map["ProxyUser"] = oldmap.value("proxyUser");
149 map["ProxyPassword"] = oldmap.value("proxyPassword");
150 map["ProxyType"] = oldmap.value("proxyType");
151 map["Internal"] = oldmap.value("InternalAccount");
153 map["AccountId"] = id.toInt();
154 map["Uuid"] = QUuid::createUuid().toString();
161 void CoreAccountSettings::setAccountValue(const QString &key, const QVariant &value)
163 if (!Client::currentCoreAccount().isValid())
165 setLocalValue(QString("%1/%2/%3").arg(Client::currentCoreAccount().accountId().toInt()).arg(_subgroup).arg(key), value);
169 QVariant CoreAccountSettings::accountValue(const QString &key, const QVariant &def)
171 if (!Client::currentCoreAccount().isValid())
173 return localValue(QString("%1/%2/%3").arg(Client::currentCoreAccount().accountId().toInt()).arg(_subgroup).arg(key), def);
177 void CoreAccountSettings::setJumpKeyMap(const QHash<int, BufferId> &keyMap)
179 QVariantMap variants;
180 QHash<int, BufferId>::const_iterator mapIter = keyMap.constBegin();
181 while (mapIter != keyMap.constEnd()) {
182 variants[QString::number(mapIter.key())] = qVariantFromValue(mapIter.value());
185 setAccountValue("JumpKeyMap", variants);
189 QHash<int, BufferId> CoreAccountSettings::jumpKeyMap()
191 QHash<int, BufferId> keyMap;
192 QVariantMap variants = accountValue("JumpKeyMap", QVariant()).toMap();
193 QVariantMap::const_iterator mapIter = variants.constBegin();
194 while (mapIter != variants.constEnd()) {
195 keyMap[mapIter.key().toInt()] = mapIter.value().value<BufferId>();
202 void CoreAccountSettings::setBufferViewOverlay(const QSet<int> &viewIds)
204 QVariantList variants;
205 foreach(int viewId, viewIds) {
206 variants << qVariantFromValue(viewId);
208 setAccountValue("BufferViewOverlay", variants);
212 QSet<int> CoreAccountSettings::bufferViewOverlay()
215 QVariantList variants = accountValue("BufferViewOverlay").toList();
216 for (QVariantList::const_iterator iter = variants.constBegin(); iter != variants.constEnd(); ++iter) {
217 viewIds << iter->toInt();
223 void CoreAccountSettings::removeAccount(AccountId id)
225 removeLocalKey(QString("%1").arg(id.toInt()));
229 void CoreAccountSettings::clearAccounts()
231 foreach(const QString &key, localChildGroups())
236 /***********************************************************************************************/
237 // CoreConnectionSettings:
239 CoreConnectionSettings::CoreConnectionSettings() : ClientSettings("CoreConnection") {}
241 void CoreConnectionSettings::setNetworkDetectionMode(NetworkDetectionMode mode)
243 setLocalValue("NetworkDetectionMode", mode);
247 CoreConnectionSettings::NetworkDetectionMode CoreConnectionSettings::networkDetectionMode()
249 auto mode = localValue("NetworkDetectionMode", UseQNetworkConfigurationManager).toInt();
251 mode = UseQNetworkConfigurationManager; // UseSolid is gone, map that to the new default
252 return static_cast<NetworkDetectionMode>(mode);
256 void CoreConnectionSettings::setAutoReconnect(bool autoReconnect)
258 setLocalValue("AutoReconnect", autoReconnect);
262 bool CoreConnectionSettings::autoReconnect()
264 return localValue("AutoReconnect", true).toBool();
268 void CoreConnectionSettings::setPingTimeoutInterval(int interval)
270 setLocalValue("PingTimeoutInterval", interval);
274 int CoreConnectionSettings::pingTimeoutInterval()
276 return localValue("PingTimeoutInterval", 60).toInt();
280 void CoreConnectionSettings::setReconnectInterval(int interval)
282 setLocalValue("ReconnectInterval", interval);
286 int CoreConnectionSettings::reconnectInterval()
288 return localValue("ReconnectInterval", 60).toInt();
292 /***********************************************************************************************/
293 // NotificationSettings:
295 NotificationSettings::NotificationSettings() : ClientSettings("Notification")
300 void NotificationSettings::setHighlightList(const QVariantList &highlightList)
302 setLocalValue("Highlights/CustomList", highlightList);
306 QVariantList NotificationSettings::highlightList()
308 return localValue("Highlights/CustomList").toList();
312 void NotificationSettings::setHighlightNick(NotificationSettings::HighlightNickType highlightNickType)
314 setLocalValue("Highlights/HighlightNick", highlightNickType);
318 NotificationSettings::HighlightNickType NotificationSettings::highlightNick()
320 return (NotificationSettings::HighlightNickType)localValue("Highlights/HighlightNick",
321 CurrentNick).toInt();
325 void NotificationSettings::setNicksCaseSensitive(bool cs)
327 setLocalValue("Highlights/NicksCaseSensitive", cs);
331 bool NotificationSettings::nicksCaseSensitive()
333 return localValue("Highlights/NicksCaseSensitive", false).toBool();
337 // ========================================
338 // TabCompletionSettings
339 // ========================================
341 TabCompletionSettings::TabCompletionSettings() : ClientSettings("TabCompletion")
346 void TabCompletionSettings::setCompletionSuffix(const QString &suffix)
348 setLocalValue("CompletionSuffix", suffix);
352 QString TabCompletionSettings::completionSuffix()
354 return localValue("CompletionSuffix", ": ").toString();
358 void TabCompletionSettings::setAddSpaceMidSentence(bool space)
360 setLocalValue("AddSpaceMidSentence", space);
364 bool TabCompletionSettings::addSpaceMidSentence()
366 return localValue("AddSpaceMidSentence", false).toBool();
370 void TabCompletionSettings::setSortMode(SortMode mode)
372 setLocalValue("SortMode", mode);
376 TabCompletionSettings::SortMode TabCompletionSettings::sortMode()
378 return static_cast<SortMode>(localValue("SortMode"), LastActivity);
382 void TabCompletionSettings::setCaseSensitivity(Qt::CaseSensitivity cs)
384 setLocalValue("CaseSensitivity", cs);
388 Qt::CaseSensitivity TabCompletionSettings::caseSensitivity()
390 return (Qt::CaseSensitivity)localValue("CaseSensitivity", Qt::CaseInsensitive).toInt();
394 void TabCompletionSettings::setUseLastSpokenTo(bool use)
396 setLocalValue("UseLastSpokenTo", use);
400 bool TabCompletionSettings::useLastSpokenTo()
402 return localValue("UseLastSpokenTo", false).toBool();
406 // ========================================
408 // ========================================
410 ItemViewSettings::ItemViewSettings(const QString &group) : ClientSettings(group)
415 bool ItemViewSettings::displayTopicInTooltip()
417 return localValue("DisplayTopicInTooltip", false).toBool();
421 bool ItemViewSettings::mouseWheelChangesBuffer()
423 return localValue("MouseWheelChangesBuffer", false).toBool();