1 | /*************************************************************************** |
2 | * Copyright (C) 2005-2014 by the Quassel Project * |
3 | * devel@quassel-irc.org * |
4 | * * |
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. * |
9 | * * |
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. * |
14 | * * |
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 | ***************************************************************************/ |
20 | |
21 | #include <QStringList> |
22 | |
23 | #include "clientsettings.h" |
24 | |
25 | #include <QHostAddress> |
26 | #ifdef HAVE_SSL |
27 | #include <QSslSocket> |
28 | #endif |
29 | |
30 | #include "client.h" |
31 | #include "quassel.h" |
32 | |
33 | ClientSettings::ClientSettings(QString g) : Settings(g, Quassel::buildInfo().clientApplicationName) |
34 | { |
35 | } |
36 | |
37 | |
38 | ClientSettings::~ClientSettings() |
39 | { |
40 | } |
41 | |
42 | |
43 | /***********************************************************************************************/ |
44 | |
45 | CoreAccountSettings::CoreAccountSettings(const QString &subgroup) |
46 | : ClientSettings("CoreAccounts" ), |
47 | _subgroup(subgroup) |
48 | { |
49 | } |
50 | |
51 | |
52 | void CoreAccountSettings::notify(const QString &key, QObject *receiver, const char *slot) |
53 | { |
54 | ClientSettings::notify(QString("%1/%2/%3" ).arg(Client::currentCoreAccount().accountId().toInt()).arg(_subgroup).arg(key), receiver, slot); |
55 | } |
56 | |
57 | |
58 | QList<AccountId> CoreAccountSettings::knownAccounts() |
59 | { |
60 | QList<AccountId> ids; |
61 | foreach(const QString &key, localChildGroups()) { |
62 | AccountId acc = key.toInt(); |
63 | if (acc.isValid()) |
64 | ids << acc; |
65 | } |
66 | return ids; |
67 | } |
68 | |
69 | |
70 | AccountId CoreAccountSettings::lastAccount() |
71 | { |
72 | return localValue("LastAccount" , 0).toInt(); |
73 | } |
74 | |
75 | |
76 | void CoreAccountSettings::setLastAccount(AccountId account) |
77 | { |
78 | setLocalValue("LastAccount" , account.toInt()); |
79 | } |
80 | |
81 | |
82 | AccountId CoreAccountSettings::autoConnectAccount() |
83 | { |
84 | return localValue("AutoConnectAccount" , 0).toInt(); |
85 | } |
86 | |
87 | |
88 | void CoreAccountSettings::setAutoConnectAccount(AccountId account) |
89 | { |
90 | setLocalValue("AutoConnectAccount" , account.toInt()); |
91 | } |
92 | |
93 | |
94 | bool CoreAccountSettings::autoConnectOnStartup() |
95 | { |
96 | return localValue("AutoConnectOnStartup" , false).toBool(); |
97 | } |
98 | |
99 | |
100 | void CoreAccountSettings::setAutoConnectOnStartup(bool b) |
101 | { |
102 | setLocalValue("AutoConnectOnStartup" , b); |
103 | } |
104 | |
105 | |
106 | bool CoreAccountSettings::autoConnectToFixedAccount() |
107 | { |
108 | return localValue("AutoConnectToFixedAccount" , false).toBool(); |
109 | } |
110 | |
111 | |
112 | void CoreAccountSettings::setAutoConnectToFixedAccount(bool b) |
113 | { |
114 | setLocalValue("AutoConnectToFixedAccount" , b); |
115 | } |
116 | |
117 | |
118 | void CoreAccountSettings::storeAccountData(AccountId id, const QVariantMap &data) |
119 | { |
120 | QString base = QString::number(id.toInt()); |
121 | foreach(const QString &key, data.keys()) { |
122 | setLocalValue(base + "/" + key, data.value(key)); |
123 | } |
124 | |
125 | // FIXME Migration from 0.5 -> 0.6 |
126 | removeLocalKey(QString("%1/Connection" ).arg(base)); |
127 | } |
128 | |
129 | |
130 | QVariantMap CoreAccountSettings::retrieveAccountData(AccountId id) |
131 | { |
132 | QVariantMap map; |
133 | QString base = QString::number(id.toInt()); |
134 | foreach(const QString &key, localChildKeys(base)) { |
135 | map[key] = localValue(base + "/" + key); |
136 | } |
137 | |
138 | // FIXME Migration from 0.5 -> 0.6 |
139 | if (!map.contains("Uuid" ) && map.contains("Connection" )) { |
140 | QVariantMap oldmap = map.value("Connection" ).toMap(); |
141 | map["AccountName" ] = oldmap.value("AccountName" ); |
142 | map["HostName" ] = oldmap.value("Host" ); |
143 | map["Port" ] = oldmap.value("Port" ); |
144 | map["User" ] = oldmap.value("User" ); |
145 | map["Password" ] = oldmap.value("Password" ); |
146 | map["StorePassword" ] = oldmap.value("RememberPasswd" ); |
147 | map["UseSSL" ] = oldmap.value("useSsl" ); |
148 | map["UseProxy" ] = oldmap.value("useProxy" ); |
149 | map["ProxyHostName" ] = oldmap.value("proxyHost" ); |
150 | map["ProxyPort" ] = oldmap.value("proxyPort" ); |
151 | map["ProxyUser" ] = oldmap.value("proxyUser" ); |
152 | map["ProxyPassword" ] = oldmap.value("proxyPassword" ); |
153 | map["ProxyType" ] = oldmap.value("proxyType" ); |
154 | map["Internal" ] = oldmap.value("InternalAccount" ); |
155 | |
156 | map["AccountId" ] = id.toInt(); |
157 | map["Uuid" ] = QUuid::createUuid().toString(); |
158 | } |
159 | |
160 | return map; |
161 | } |
162 | |
163 | |
164 | void CoreAccountSettings::setAccountValue(const QString &key, const QVariant &value) |
165 | { |
166 | if (!Client::currentCoreAccount().isValid()) |
167 | return; |
168 | setLocalValue(QString("%1/%2/%3" ).arg(Client::currentCoreAccount().accountId().toInt()).arg(_subgroup).arg(key), value); |
169 | } |
170 | |
171 | |
172 | QVariant CoreAccountSettings::accountValue(const QString &key, const QVariant &def) |
173 | { |
174 | if (!Client::currentCoreAccount().isValid()) |
175 | return QVariant(); |
176 | return localValue(QString("%1/%2/%3" ).arg(Client::currentCoreAccount().accountId().toInt()).arg(_subgroup).arg(key), def); |
177 | } |
178 | |
179 | |
180 | void CoreAccountSettings::setJumpKeyMap(const QHash<int, BufferId> &keyMap) |
181 | { |
182 | QVariantMap variants; |
183 | QHash<int, BufferId>::const_iterator mapIter = keyMap.constBegin(); |
184 | while (mapIter != keyMap.constEnd()) { |
185 | variants[QString::number(mapIter.key())] = qVariantFromValue(mapIter.value()); |
186 | ++mapIter; |
187 | } |
188 | setAccountValue("JumpKeyMap" , variants); |
189 | } |
190 | |
191 | |
192 | QHash<int, BufferId> CoreAccountSettings::jumpKeyMap() |
193 | { |
194 | QHash<int, BufferId> keyMap; |
195 | QVariantMap variants = accountValue("JumpKeyMap" , QVariant()).toMap(); |
196 | QVariantMap::const_iterator mapIter = variants.constBegin(); |
197 | while (mapIter != variants.constEnd()) { |
198 | keyMap[mapIter.key().toInt()] = mapIter.value().value<BufferId>(); |
199 | ++mapIter; |
200 | } |
201 | return keyMap; |
202 | } |
203 | |
204 | |
205 | void CoreAccountSettings::setBufferViewOverlay(const QSet<int> &viewIds) |
206 | { |
207 | QVariantList variants; |
208 | foreach(int viewId, viewIds) { |
209 | variants << qVariantFromValue(viewId); |
210 | } |
211 | setAccountValue("BufferViewOverlay" , variants); |
212 | } |
213 | |
214 | |
215 | QSet<int> CoreAccountSettings::bufferViewOverlay() |
216 | { |
217 | QSet<int> viewIds; |
218 | QVariantList variants = accountValue("BufferViewOverlay" ).toList(); |
219 | for (QVariantList::const_iterator iter = variants.constBegin(); iter != variants.constEnd(); iter++) { |
220 | viewIds << iter->toInt(); |
221 | } |
222 | return viewIds; |
223 | } |
224 | |
225 | |
226 | void CoreAccountSettings::removeAccount(AccountId id) |
227 | { |
228 | removeLocalKey(QString("%1" ).arg(id.toInt())); |
229 | } |
230 | |
231 | |
232 | void CoreAccountSettings::clearAccounts() |
233 | { |
234 | foreach(const QString &key, localChildGroups()) |
235 | removeLocalKey(key); |
236 | } |
237 | |
238 | |
239 | /***********************************************************************************************/ |
240 | // CoreConnectionSettings: |
241 | |
242 | CoreConnectionSettings::CoreConnectionSettings() : ClientSettings("CoreConnection" ) {} |
243 | |
244 | void CoreConnectionSettings::setNetworkDetectionMode(NetworkDetectionMode mode) |
245 | { |
246 | setLocalValue("NetworkDetectionMode" , mode); |
247 | } |
248 | |
249 | |
250 | CoreConnectionSettings::NetworkDetectionMode CoreConnectionSettings::networkDetectionMode() |
251 | { |
252 | #ifdef HAVE_KDE |
253 | NetworkDetectionMode def = UseSolid; |
254 | #else |
255 | NetworkDetectionMode def = UsePingTimeout; |
256 | #endif |
257 | return (NetworkDetectionMode)localValue("NetworkDetectionMode" , def).toInt(); |
258 | } |
259 | |
260 | |
261 | void CoreConnectionSettings::setAutoReconnect(bool autoReconnect) |
262 | { |
263 | setLocalValue("AutoReconnect" , autoReconnect); |
264 | } |
265 | |
266 | |
267 | bool CoreConnectionSettings::autoReconnect() |
268 | { |
269 | return localValue("AutoReconnect" , true).toBool(); |
270 | } |
271 | |
272 | |
273 | void CoreConnectionSettings::setPingTimeoutInterval(int interval) |
274 | { |
275 | setLocalValue("PingTimeoutInterval" , interval); |
276 | } |
277 | |
278 | |
279 | int CoreConnectionSettings::pingTimeoutInterval() |
280 | { |
281 | return localValue("PingTimeoutInterval" , 60).toInt(); |
282 | } |
283 | |
284 | |
285 | void CoreConnectionSettings::setReconnectInterval(int interval) |
286 | { |
287 | setLocalValue("ReconnectInterval" , interval); |
288 | } |
289 | |
290 | |
291 | int CoreConnectionSettings::reconnectInterval() |
292 | { |
293 | return localValue("ReconnectInterval" , 60).toInt(); |
294 | } |
295 | |
296 | |
297 | /***********************************************************************************************/ |
298 | // NotificationSettings: |
299 | |
300 | NotificationSettings::NotificationSettings() : ClientSettings("Notification" ) |
301 | { |
302 | } |
303 | |
304 | |
305 | void NotificationSettings::setHighlightList(const QVariantList &highlightList) |
306 | { |
307 | setLocalValue("Highlights/CustomList" , highlightList); |
308 | } |
309 | |
310 | |
311 | QVariantList NotificationSettings::highlightList() |
312 | { |
313 | return localValue("Highlights/CustomList" ).toList(); |
314 | } |
315 | |
316 | |
317 | void NotificationSettings::setHighlightNick(NotificationSettings::HighlightNickType highlightNickType) |
318 | { |
319 | setLocalValue("Highlights/HighlightNick" , highlightNickType); |
320 | } |
321 | |
322 | |
323 | NotificationSettings::HighlightNickType NotificationSettings::highlightNick() |
324 | { |
325 | return (NotificationSettings::HighlightNickType)localValue("Highlights/HighlightNick" , CurrentNick).toInt(); |
326 | } |
327 | |
328 | |
329 | void NotificationSettings::setNicksCaseSensitive(bool cs) |
330 | { |
331 | setLocalValue("Highlights/NicksCaseSensitive" , cs); |
332 | } |
333 | |
334 | |
335 | bool NotificationSettings::nicksCaseSensitive() |
336 | { |
337 | return localValue("Highlights/NicksCaseSensitive" , false).toBool(); |
338 | } |
339 | |
340 | |
341 | // ======================================== |
342 | // TabCompletionSettings |
343 | // ======================================== |
344 | |
345 | TabCompletionSettings::TabCompletionSettings() : ClientSettings("TabCompletion" ) |
346 | { |
347 | } |
348 | |
349 | |
350 | void TabCompletionSettings::setCompletionSuffix(const QString &suffix) |
351 | { |
352 | setLocalValue("CompletionSuffix" , suffix); |
353 | } |
354 | |
355 | |
356 | QString TabCompletionSettings::completionSuffix() |
357 | { |
358 | return localValue("CompletionSuffix" , ": " ).toString(); |
359 | } |
360 | |
361 | |
362 | void TabCompletionSettings::setAddSpaceMidSentence(bool space) |
363 | { |
364 | setLocalValue("AddSpaceMidSentence" , space); |
365 | } |
366 | |
367 | |
368 | bool TabCompletionSettings::addSpaceMidSentence() |
369 | { |
370 | return localValue("AddSpaceMidSentence" , false).toBool(); |
371 | } |
372 | |
373 | |
374 | void TabCompletionSettings::setSortMode(SortMode mode) |
375 | { |
376 | setLocalValue("SortMode" , mode); |
377 | } |
378 | |
379 | |
380 | TabCompletionSettings::SortMode TabCompletionSettings::sortMode() |
381 | { |
382 | return static_cast<SortMode>(localValue("SortMode" ), LastActivity); |
383 | } |
384 | |
385 | |
386 | void TabCompletionSettings::setCaseSensitivity(Qt::CaseSensitivity cs) |
387 | { |
388 | setLocalValue("CaseSensitivity" , cs); |
389 | } |
390 | |
391 | |
392 | Qt::CaseSensitivity TabCompletionSettings::caseSensitivity() |
393 | { |
394 | return (Qt::CaseSensitivity)localValue("CaseSensitivity" , Qt::CaseInsensitive).toInt(); |
395 | } |
396 | |
397 | |
398 | void TabCompletionSettings::setUseLastSpokenTo(bool use) |
399 | { |
400 | setLocalValue("UseLastSpokenTo" , use); |
401 | } |
402 | |
403 | |
404 | bool TabCompletionSettings::useLastSpokenTo() |
405 | { |
406 | return localValue("UseLastSpokenTo" , false).toBool(); |
407 | } |
408 | |
409 | |
410 | // ======================================== |
411 | // ItemViewSettings |
412 | // ======================================== |
413 | |
414 | ItemViewSettings::ItemViewSettings(const QString &group) : ClientSettings(group) |
415 | { |
416 | } |
417 | |
418 | |
419 | bool ItemViewSettings::displayTopicInTooltip() |
420 | { |
421 | return localValue("DisplayTopicInTooltip" , false).toBool(); |
422 | } |
423 | |
424 | |
425 | bool ItemViewSettings::mouseWheelChangesBuffer() |
426 | { |
427 | return localValue("MouseWheelChangesBuffer" , false).toBool(); |
428 | } |
429 | |