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 QString CoreAccountSettings::keyForNotify(const QString &key) const
51 return QString{"%1/%2/%3"}.arg(Client::currentCoreAccount().accountId().toInt()).arg(_subgroup).arg(key);
55 QList<AccountId> CoreAccountSettings::knownAccounts() const
58 foreach(const QString &key, localChildGroups()) {
59 AccountId acc = key.toInt();
67 AccountId CoreAccountSettings::lastAccount() const
69 return localValue("LastAccount", 0).toInt();
73 void CoreAccountSettings::setLastAccount(AccountId account)
75 setLocalValue("LastAccount", account.toInt());
79 AccountId CoreAccountSettings::autoConnectAccount() const
81 return localValue("AutoConnectAccount", 0).toInt();
85 void CoreAccountSettings::setAutoConnectAccount(AccountId account)
87 setLocalValue("AutoConnectAccount", account.toInt());
91 bool CoreAccountSettings::autoConnectOnStartup() const
93 return localValue("AutoConnectOnStartup", false).toBool();
97 void CoreAccountSettings::setAutoConnectOnStartup(bool b)
99 setLocalValue("AutoConnectOnStartup", b);
103 bool CoreAccountSettings::autoConnectToFixedAccount() const
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) const
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) const
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() const
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() const
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()
240 : ClientSettings("CoreConnection")
243 void CoreConnectionSettings::setNetworkDetectionMode(NetworkDetectionMode mode)
245 setLocalValue("NetworkDetectionMode", mode);
249 CoreConnectionSettings::NetworkDetectionMode CoreConnectionSettings::networkDetectionMode() const
251 auto mode = localValue("NetworkDetectionMode", UseQNetworkConfigurationManager).toInt();
253 mode = UseQNetworkConfigurationManager; // UseSolid is gone, map that to the new default
254 return static_cast<NetworkDetectionMode>(mode);
258 void CoreConnectionSettings::setAutoReconnect(bool autoReconnect)
260 setLocalValue("AutoReconnect", autoReconnect);
264 bool CoreConnectionSettings::autoReconnect() const
266 return localValue("AutoReconnect", true).toBool();
270 void CoreConnectionSettings::setPingTimeoutInterval(int interval)
272 setLocalValue("PingTimeoutInterval", interval);
276 int CoreConnectionSettings::pingTimeoutInterval() const
278 return localValue("PingTimeoutInterval", 60).toInt();
282 void CoreConnectionSettings::setReconnectInterval(int interval)
284 setLocalValue("ReconnectInterval", interval);
288 int CoreConnectionSettings::reconnectInterval() const
290 return localValue("ReconnectInterval", 60).toInt();
294 /***********************************************************************************************/
295 // NotificationSettings:
297 NotificationSettings::NotificationSettings()
298 : ClientSettings("Notification")
303 void NotificationSettings::setValue(const QString &key, const QVariant &data)
305 setLocalValue(key, data);
309 QVariant NotificationSettings::value(const QString &key, const QVariant &def) const
311 return localValue(key, def);
315 void NotificationSettings::remove(const QString &key)
321 void NotificationSettings::setHighlightList(const QVariantList &highlightList)
323 setLocalValue("Highlights/CustomList", highlightList);
327 QVariantList NotificationSettings::highlightList() const
329 return localValue("Highlights/CustomList").toList();
333 void NotificationSettings::setHighlightNick(NotificationSettings::HighlightNickType highlightNickType)
335 setLocalValue("Highlights/HighlightNick", highlightNickType);
339 NotificationSettings::HighlightNickType NotificationSettings::highlightNick() const
341 return (NotificationSettings::HighlightNickType)localValue("Highlights/HighlightNick",
342 CurrentNick).toInt();
346 void NotificationSettings::setNicksCaseSensitive(bool cs)
348 setLocalValue("Highlights/NicksCaseSensitive", cs);
352 bool NotificationSettings::nicksCaseSensitive() const
354 return localValue("Highlights/NicksCaseSensitive", false).toBool();
358 // ========================================
359 // TabCompletionSettings
360 // ========================================
362 TabCompletionSettings::TabCompletionSettings()
363 : ClientSettings("TabCompletion")
368 void TabCompletionSettings::setCompletionSuffix(const QString &suffix)
370 setLocalValue("CompletionSuffix", suffix);
374 QString TabCompletionSettings::completionSuffix() const
376 return localValue("CompletionSuffix", ": ").toString();
380 void TabCompletionSettings::setAddSpaceMidSentence(bool space)
382 setLocalValue("AddSpaceMidSentence", space);
386 bool TabCompletionSettings::addSpaceMidSentence() const
388 return localValue("AddSpaceMidSentence", false).toBool();
392 void TabCompletionSettings::setSortMode(SortMode mode)
394 setLocalValue("SortMode", mode);
398 TabCompletionSettings::SortMode TabCompletionSettings::sortMode() const
400 return static_cast<SortMode>(localValue("SortMode"), LastActivity);
404 void TabCompletionSettings::setCaseSensitivity(Qt::CaseSensitivity cs)
406 setLocalValue("CaseSensitivity", cs);
410 Qt::CaseSensitivity TabCompletionSettings::caseSensitivity() const
412 return (Qt::CaseSensitivity)localValue("CaseSensitivity", Qt::CaseInsensitive).toInt();
416 void TabCompletionSettings::setUseLastSpokenTo(bool use)
418 setLocalValue("UseLastSpokenTo", use);
422 bool TabCompletionSettings::useLastSpokenTo() const
424 return localValue("UseLastSpokenTo", false).toBool();
428 // ========================================
430 // ========================================
432 ItemViewSettings::ItemViewSettings(const QString &group) : ClientSettings(group)
437 bool ItemViewSettings::displayTopicInTooltip() const
439 return localValue("DisplayTopicInTooltip", false).toBool();
443 bool ItemViewSettings::mouseWheelChangesBuffer() const
445 return localValue("MouseWheelChangesBuffer", false).toBool();