1 /***************************************************************************
2 * Copyright (C) 2005-2019 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>
26 #include <QStringList>
28 # include <QSslSocket>
34 ClientSettings::ClientSettings(QString g)
35 : Settings(g, Quassel::buildInfo().clientApplicationName)
38 /***********************************************************************************************/
40 CoreAccountSettings::CoreAccountSettings(QString subgroup)
41 : ClientSettings("CoreAccounts")
42 , _subgroup(std::move(subgroup))
45 QString CoreAccountSettings::keyForNotify(const QString& key) const
47 return QString{"%1/%2/%3"}.arg(Client::currentCoreAccount().accountId().toInt()).arg(_subgroup).arg(key);
50 QList<AccountId> CoreAccountSettings::knownAccounts() const
53 foreach (const QString& key, localChildGroups()) {
54 AccountId acc = key.toInt();
61 AccountId CoreAccountSettings::lastAccount() const
63 return localValue("LastAccount", 0).toInt();
66 void CoreAccountSettings::setLastAccount(AccountId account)
68 setLocalValue("LastAccount", account.toInt());
71 AccountId CoreAccountSettings::autoConnectAccount() const
73 return localValue("AutoConnectAccount", 0).toInt();
76 void CoreAccountSettings::setAutoConnectAccount(AccountId account)
78 setLocalValue("AutoConnectAccount", account.toInt());
81 bool CoreAccountSettings::autoConnectOnStartup() const
83 return localValue("AutoConnectOnStartup", false).toBool();
86 void CoreAccountSettings::setAutoConnectOnStartup(bool b)
88 setLocalValue("AutoConnectOnStartup", b);
91 bool CoreAccountSettings::autoConnectToFixedAccount() const
93 return localValue("AutoConnectToFixedAccount", false).toBool();
96 void CoreAccountSettings::setAutoConnectToFixedAccount(bool b)
98 setLocalValue("AutoConnectToFixedAccount", b);
101 void CoreAccountSettings::storeAccountData(AccountId id, const QVariantMap& data)
103 QString base = QString::number(id.toInt());
104 foreach (const QString& key, data.keys()) {
105 setLocalValue(base + "/" + key, data.value(key));
108 // FIXME Migration from 0.5 -> 0.6
109 removeLocalKey(QString("%1/Connection").arg(base));
112 QVariantMap CoreAccountSettings::retrieveAccountData(AccountId id) const
115 QString base = QString::number(id.toInt());
116 foreach (const QString& key, localChildKeys(base)) {
117 map[key] = localValue(base + "/" + key);
120 // FIXME Migration from 0.5 -> 0.6
121 if (!map.contains("Uuid") && map.contains("Connection")) {
122 QVariantMap oldmap = map.value("Connection").toMap();
123 map["AccountName"] = oldmap.value("AccountName");
124 map["HostName"] = oldmap.value("Host");
125 map["Port"] = oldmap.value("Port");
126 map["User"] = oldmap.value("User");
127 map["Password"] = oldmap.value("Password");
128 map["StorePassword"] = oldmap.value("RememberPasswd");
129 map["UseSSL"] = oldmap.value("useSsl");
130 map["UseProxy"] = oldmap.value("useProxy");
131 map["ProxyHostName"] = oldmap.value("proxyHost");
132 map["ProxyPort"] = oldmap.value("proxyPort");
133 map["ProxyUser"] = oldmap.value("proxyUser");
134 map["ProxyPassword"] = oldmap.value("proxyPassword");
135 map["ProxyType"] = oldmap.value("proxyType");
136 map["Internal"] = oldmap.value("InternalAccount");
138 map["AccountId"] = id.toInt();
139 map["Uuid"] = QUuid::createUuid().toString();
145 void CoreAccountSettings::setAccountValue(const QString& key, const QVariant& value)
147 if (!Client::currentCoreAccount().isValid())
149 setLocalValue(QString("%1/%2/%3").arg(Client::currentCoreAccount().accountId().toInt()).arg(_subgroup).arg(key), value);
152 QVariant CoreAccountSettings::accountValue(const QString& key, const QVariant& def) const
154 if (!Client::currentCoreAccount().isValid())
156 return localValue(QString("%1/%2/%3").arg(Client::currentCoreAccount().accountId().toInt()).arg(_subgroup).arg(key), def);
159 void CoreAccountSettings::setJumpKeyMap(const QHash<int, BufferId>& keyMap)
161 QVariantMap variants;
162 QHash<int, BufferId>::const_iterator mapIter = keyMap.constBegin();
163 while (mapIter != keyMap.constEnd()) {
164 variants[QString::number(mapIter.key())] = qVariantFromValue(mapIter.value());
167 setAccountValue("JumpKeyMap", variants);
170 QHash<int, BufferId> CoreAccountSettings::jumpKeyMap() const
172 QHash<int, BufferId> keyMap;
173 QVariantMap variants = accountValue("JumpKeyMap", QVariant()).toMap();
174 QVariantMap::const_iterator mapIter = variants.constBegin();
175 while (mapIter != variants.constEnd()) {
176 keyMap[mapIter.key().toInt()] = mapIter.value().value<BufferId>();
182 void CoreAccountSettings::setBufferViewOverlay(const QSet<int>& viewIds)
184 QVariantList variants;
185 foreach (int viewId, viewIds) {
186 variants << qVariantFromValue(viewId);
188 setAccountValue("BufferViewOverlay", variants);
191 QSet<int> CoreAccountSettings::bufferViewOverlay() const
194 QVariantList variants = accountValue("BufferViewOverlay").toList();
195 for (QVariantList::const_iterator iter = variants.constBegin(); iter != variants.constEnd(); ++iter) {
196 viewIds << iter->toInt();
201 void CoreAccountSettings::removeAccount(AccountId id)
203 removeLocalKey(QString("%1").arg(id.toInt()));
206 void CoreAccountSettings::clearAccounts()
208 foreach (const QString& key, localChildGroups())
212 /***********************************************************************************************/
213 // CoreConnectionSettings:
215 CoreConnectionSettings::CoreConnectionSettings()
216 : ClientSettings("CoreConnection")
219 void CoreConnectionSettings::setNetworkDetectionMode(NetworkDetectionMode mode)
221 setLocalValue("NetworkDetectionMode", mode);
224 CoreConnectionSettings::NetworkDetectionMode CoreConnectionSettings::networkDetectionMode() const
226 auto mode = localValue("NetworkDetectionMode", UseQNetworkConfigurationManager).toInt();
228 mode = UseQNetworkConfigurationManager; // UseSolid is gone, map that to the new default
229 return static_cast<NetworkDetectionMode>(mode);
232 void CoreConnectionSettings::setAutoReconnect(bool autoReconnect)
234 setLocalValue("AutoReconnect", autoReconnect);
237 bool CoreConnectionSettings::autoReconnect() const
239 return localValue("AutoReconnect", true).toBool();
242 void CoreConnectionSettings::setPingTimeoutInterval(int interval)
244 setLocalValue("PingTimeoutInterval", interval);
247 int CoreConnectionSettings::pingTimeoutInterval() const
249 return localValue("PingTimeoutInterval", 60).toInt();
252 void CoreConnectionSettings::setReconnectInterval(int interval)
254 setLocalValue("ReconnectInterval", interval);
257 int CoreConnectionSettings::reconnectInterval() const
259 return localValue("ReconnectInterval", 60).toInt();
262 /***********************************************************************************************/
263 // NotificationSettings:
265 NotificationSettings::NotificationSettings()
266 : ClientSettings("Notification")
269 void NotificationSettings::setValue(const QString& key, const QVariant& data)
271 setLocalValue(key, data);
274 QVariant NotificationSettings::value(const QString& key, const QVariant& def) const
276 return localValue(key, def);
279 void NotificationSettings::remove(const QString& key)
284 void NotificationSettings::setHighlightList(const QVariantList& highlightList)
286 setLocalValue("Highlights/CustomList", highlightList);
289 QVariantList NotificationSettings::highlightList() const
291 return localValue("Highlights/CustomList").toList();
294 void NotificationSettings::setHighlightNick(NotificationSettings::HighlightNickType highlightNickType)
296 setLocalValue("Highlights/HighlightNick", highlightNickType);
299 NotificationSettings::HighlightNickType NotificationSettings::highlightNick() const
301 return (NotificationSettings::HighlightNickType)localValue("Highlights/HighlightNick", CurrentNick).toInt();
304 void NotificationSettings::setNicksCaseSensitive(bool cs)
306 setLocalValue("Highlights/NicksCaseSensitive", cs);
309 bool NotificationSettings::nicksCaseSensitive() const
311 return localValue("Highlights/NicksCaseSensitive", false).toBool();
314 // ========================================
315 // TabCompletionSettings
316 // ========================================
318 TabCompletionSettings::TabCompletionSettings()
319 : ClientSettings("TabCompletion")
322 void TabCompletionSettings::setCompletionSuffix(const QString& suffix)
324 setLocalValue("CompletionSuffix", suffix);
327 QString TabCompletionSettings::completionSuffix() const
329 return localValue("CompletionSuffix", ": ").toString();
332 void TabCompletionSettings::setAddSpaceMidSentence(bool space)
334 setLocalValue("AddSpaceMidSentence", space);
337 bool TabCompletionSettings::addSpaceMidSentence() const
339 return localValue("AddSpaceMidSentence", false).toBool();
342 void TabCompletionSettings::setSortMode(SortMode mode)
344 setLocalValue("SortMode", mode);
347 TabCompletionSettings::SortMode TabCompletionSettings::sortMode() const
349 return static_cast<SortMode>(localValue("SortMode"), LastActivity);
352 void TabCompletionSettings::setCaseSensitivity(Qt::CaseSensitivity cs)
354 setLocalValue("CaseSensitivity", cs);
357 Qt::CaseSensitivity TabCompletionSettings::caseSensitivity() const
359 return (Qt::CaseSensitivity)localValue("CaseSensitivity", Qt::CaseInsensitive).toInt();
362 void TabCompletionSettings::setUseLastSpokenTo(bool use)
364 setLocalValue("UseLastSpokenTo", use);
367 bool TabCompletionSettings::useLastSpokenTo() const
369 return localValue("UseLastSpokenTo", false).toBool();
372 // ========================================
374 // ========================================
376 ItemViewSettings::ItemViewSettings(const QString& group)
377 : ClientSettings(group)
380 bool ItemViewSettings::displayTopicInTooltip() const
382 return localValue("DisplayTopicInTooltip", false).toBool();
385 bool ItemViewSettings::mouseWheelChangesBuffer() const
387 return localValue("MouseWheelChangesBuffer", false).toBool();