1 /***************************************************************************
2 * Copyright (C) 2005-2022 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 "clientsettings.h"
25 #include <QHostAddress>
27 #include <QStringList>
32 ClientSettings::ClientSettings(QString g)
33 : Settings(g, Quassel::buildInfo().clientApplicationName)
36 /***********************************************************************************************/
38 CoreAccountSettings::CoreAccountSettings(QString subgroup)
39 : ClientSettings("CoreAccounts")
40 , _subgroup(std::move(subgroup))
43 QString CoreAccountSettings::keyForNotify(const QString& key) const
45 return QString{"%1/%2/%3"}.arg(Client::currentCoreAccount().accountId().toInt()).arg(_subgroup).arg(key);
48 QList<AccountId> CoreAccountSettings::knownAccounts() const
51 foreach (const QString& key, localChildGroups()) {
52 AccountId acc = key.toInt();
59 AccountId CoreAccountSettings::lastAccount() const
61 return localValue("LastAccount", 0).toInt();
64 void CoreAccountSettings::setLastAccount(AccountId account)
66 setLocalValue("LastAccount", account.toInt());
69 AccountId CoreAccountSettings::autoConnectAccount() const
71 return localValue("AutoConnectAccount", 0).toInt();
74 void CoreAccountSettings::setAutoConnectAccount(AccountId account)
76 setLocalValue("AutoConnectAccount", account.toInt());
79 bool CoreAccountSettings::autoConnectOnStartup() const
81 return localValue("AutoConnectOnStartup", false).toBool();
84 void CoreAccountSettings::setAutoConnectOnStartup(bool b)
86 setLocalValue("AutoConnectOnStartup", b);
89 bool CoreAccountSettings::autoConnectToFixedAccount() const
91 return localValue("AutoConnectToFixedAccount", false).toBool();
94 void CoreAccountSettings::setAutoConnectToFixedAccount(bool b)
96 setLocalValue("AutoConnectToFixedAccount", b);
99 void CoreAccountSettings::storeAccountData(AccountId id, const QVariantMap& data)
101 QString base = QString::number(id.toInt());
102 foreach (const QString& key, data.keys()) {
103 setLocalValue(base + "/" + key, data.value(key));
106 // FIXME Migration from 0.5 -> 0.6
107 removeLocalKey(QString("%1/Connection").arg(base));
110 QVariantMap CoreAccountSettings::retrieveAccountData(AccountId id) const
113 QString base = QString::number(id.toInt());
114 foreach (const QString& key, localChildKeys(base)) {
115 map[key] = localValue(base + "/" + key);
118 // FIXME Migration from 0.5 -> 0.6
119 if (!map.contains("Uuid") && map.contains("Connection")) {
120 QVariantMap oldmap = map.value("Connection").toMap();
121 map["AccountName"] = oldmap.value("AccountName");
122 map["HostName"] = oldmap.value("Host");
123 map["Port"] = oldmap.value("Port");
124 map["User"] = oldmap.value("User");
125 map["Password"] = oldmap.value("Password");
126 map["StorePassword"] = oldmap.value("RememberPasswd");
127 map["UseSSL"] = oldmap.value("useSsl");
128 map["UseProxy"] = oldmap.value("useProxy");
129 map["ProxyHostName"] = oldmap.value("proxyHost");
130 map["ProxyPort"] = oldmap.value("proxyPort");
131 map["ProxyUser"] = oldmap.value("proxyUser");
132 map["ProxyPassword"] = oldmap.value("proxyPassword");
133 map["ProxyType"] = oldmap.value("proxyType");
134 map["Internal"] = oldmap.value("InternalAccount");
136 map["AccountId"] = id.toInt();
137 map["Uuid"] = QUuid::createUuid().toString();
143 void CoreAccountSettings::setAccountValue(const QString& key, const QVariant& value)
145 if (!Client::currentCoreAccount().isValid())
147 setLocalValue(QString("%1/%2/%3").arg(Client::currentCoreAccount().accountId().toInt()).arg(_subgroup).arg(key), value);
150 QVariant CoreAccountSettings::accountValue(const QString& key, const QVariant& def) const
152 if (!Client::currentCoreAccount().isValid())
154 return localValue(QString("%1/%2/%3").arg(Client::currentCoreAccount().accountId().toInt()).arg(_subgroup).arg(key), def);
157 void CoreAccountSettings::setJumpKeyMap(const QHash<int, BufferId>& keyMap)
159 QVariantMap variants;
160 QHash<int, BufferId>::const_iterator mapIter = keyMap.constBegin();
161 while (mapIter != keyMap.constEnd()) {
162 variants[QString::number(mapIter.key())] = QVariant::fromValue(mapIter.value());
165 setAccountValue("JumpKeyMap", variants);
168 QHash<int, BufferId> CoreAccountSettings::jumpKeyMap() const
170 QHash<int, BufferId> keyMap;
171 QVariantMap variants = accountValue("JumpKeyMap", QVariant()).toMap();
172 QVariantMap::const_iterator mapIter = variants.constBegin();
173 while (mapIter != variants.constEnd()) {
174 keyMap[mapIter.key().toInt()] = mapIter.value().value<BufferId>();
180 void CoreAccountSettings::setBufferViewOverlay(const QSet<int>& viewIds)
182 QVariantList variants;
183 foreach (int viewId, viewIds) {
184 variants << QVariant::fromValue(viewId);
186 setAccountValue("BufferViewOverlay", variants);
189 QSet<int> CoreAccountSettings::bufferViewOverlay() const
192 QVariantList variants = accountValue("BufferViewOverlay").toList();
193 for (QVariantList::const_iterator iter = variants.constBegin(); iter != variants.constEnd(); ++iter) {
194 viewIds << iter->toInt();
199 void CoreAccountSettings::removeAccount(AccountId id)
201 removeLocalKey(QString("%1").arg(id.toInt()));
204 void CoreAccountSettings::clearAccounts()
206 foreach (const QString& key, localChildGroups())
210 /***********************************************************************************************/
211 // CoreConnectionSettings:
213 CoreConnectionSettings::CoreConnectionSettings()
214 : ClientSettings("CoreConnection")
217 void CoreConnectionSettings::setNetworkDetectionMode(NetworkDetectionMode mode)
219 setLocalValue("NetworkDetectionMode", mode);
222 CoreConnectionSettings::NetworkDetectionMode CoreConnectionSettings::networkDetectionMode() const
224 auto mode = localValue("NetworkDetectionMode", UseQNetworkConfigurationManager).toInt();
226 mode = UseQNetworkConfigurationManager; // UseSolid is gone, map that to the new default
227 return static_cast<NetworkDetectionMode>(mode);
230 void CoreConnectionSettings::setAutoReconnect(bool autoReconnect)
232 setLocalValue("AutoReconnect", autoReconnect);
235 bool CoreConnectionSettings::autoReconnect() const
237 return localValue("AutoReconnect", true).toBool();
240 void CoreConnectionSettings::setPingTimeoutInterval(int interval)
242 setLocalValue("PingTimeoutInterval", interval);
245 int CoreConnectionSettings::pingTimeoutInterval() const
247 return localValue("PingTimeoutInterval", 60).toInt();
250 void CoreConnectionSettings::setReconnectInterval(int interval)
252 setLocalValue("ReconnectInterval", interval);
255 int CoreConnectionSettings::reconnectInterval() const
257 return localValue("ReconnectInterval", 60).toInt();
260 /***********************************************************************************************/
261 // NotificationSettings:
263 NotificationSettings::NotificationSettings()
264 : ClientSettings("Notification")
267 void NotificationSettings::setValue(const QString& key, const QVariant& data)
269 setLocalValue(key, data);
272 QVariant NotificationSettings::value(const QString& key, const QVariant& def) const
274 return localValue(key, def);
277 void NotificationSettings::remove(const QString& key)
282 void NotificationSettings::setHighlightList(const QVariantList& highlightList)
284 setLocalValue("Highlights/CustomList", highlightList);
287 QVariantList NotificationSettings::highlightList() const
289 return localValue("Highlights/CustomList").toList();
292 void NotificationSettings::setHighlightNick(NotificationSettings::HighlightNickType highlightNickType)
294 setLocalValue("Highlights/HighlightNick", highlightNickType);
297 NotificationSettings::HighlightNickType NotificationSettings::highlightNick() const
299 return (NotificationSettings::HighlightNickType)localValue("Highlights/HighlightNick", NoNick).toInt();
302 void NotificationSettings::setNicksCaseSensitive(bool cs)
304 setLocalValue("Highlights/NicksCaseSensitive", cs);
307 bool NotificationSettings::nicksCaseSensitive() const
309 return localValue("Highlights/NicksCaseSensitive", false).toBool();
312 // ========================================
313 // TabCompletionSettings
314 // ========================================
316 TabCompletionSettings::TabCompletionSettings()
317 : ClientSettings("TabCompletion")
320 void TabCompletionSettings::setCompletionSuffix(const QString& suffix)
322 setLocalValue("CompletionSuffix", suffix);
325 QString TabCompletionSettings::completionSuffix() const
327 return localValue("CompletionSuffix", ": ").toString();
330 void TabCompletionSettings::setAddSpaceMidSentence(bool space)
332 setLocalValue("AddSpaceMidSentence", space);
335 bool TabCompletionSettings::addSpaceMidSentence() const
337 return localValue("AddSpaceMidSentence", false).toBool();
340 void TabCompletionSettings::setSortMode(SortMode mode)
342 setLocalValue("SortMode", mode);
345 TabCompletionSettings::SortMode TabCompletionSettings::sortMode() const
347 return static_cast<SortMode>(localValue("SortMode"), LastActivity);
350 void TabCompletionSettings::setCaseSensitivity(Qt::CaseSensitivity cs)
352 setLocalValue("CaseSensitivity", cs);
355 Qt::CaseSensitivity TabCompletionSettings::caseSensitivity() const
357 return (Qt::CaseSensitivity)localValue("CaseSensitivity", Qt::CaseInsensitive).toInt();
360 void TabCompletionSettings::setUseLastSpokenTo(bool use)
362 setLocalValue("UseLastSpokenTo", use);
365 bool TabCompletionSettings::useLastSpokenTo() const
367 return localValue("UseLastSpokenTo", false).toBool();
370 // ========================================
372 // ========================================
374 ItemViewSettings::ItemViewSettings(const QString& group)
375 : ClientSettings(group)
378 bool ItemViewSettings::displayTopicInTooltip() const
380 return localValue("DisplayTopicInTooltip", false).toBool();
383 bool ItemViewSettings::mouseWheelChangesBuffer() const
385 return localValue("MouseWheelChangesBuffer", false).toBool();