Quassel IRC  Pre-Release
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
clientsettings.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005-2015 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 
39 {
40 }
41 
42 
43 /***********************************************************************************************/
44 
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 
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 
71 {
72  return localValue("LastAccount", 0).toInt();
73 }
74 
75 
77 {
78  setLocalValue("LastAccount", account.toInt());
79 }
80 
81 
83 {
84  return localValue("AutoConnectAccount", 0).toInt();
85 }
86 
87 
89 {
90  setLocalValue("AutoConnectAccount", account.toInt());
91 }
92 
93 
95 {
96  return localValue("AutoConnectOnStartup", false).toBool();
97 }
98 
99 
101 {
102  setLocalValue("AutoConnectOnStartup", b);
103 }
104 
105 
107 {
108  return localValue("AutoConnectToFixedAccount", false).toBool();
109 }
110 
111 
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 
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 
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 
227 {
228  removeLocalKey(QString("%1").arg(id.toInt()));
229 }
230 
231 
233 {
234  foreach(const QString &key, localChildGroups())
235  removeLocalKey(key);
236 }
237 
238 
239 /***********************************************************************************************/
240 // CoreConnectionSettings:
241 
243 
245 {
246  setLocalValue("NetworkDetectionMode", mode);
247 }
248 
249 
251 {
252  auto mode = localValue("NetworkDetectionMode", UseQNetworkConfigurationManager).toInt();
253  if (mode == 0)
254  mode = UseQNetworkConfigurationManager; // UseSolid is gone, map that to the new default
255  return static_cast<NetworkDetectionMode>(mode);
256 }
257 
258 
260 {
261  setLocalValue("AutoReconnect", autoReconnect);
262 }
263 
264 
266 {
267  return localValue("AutoReconnect", true).toBool();
268 }
269 
270 
272 {
273  setLocalValue("PingTimeoutInterval", interval);
274 }
275 
276 
278 {
279  return localValue("PingTimeoutInterval", 60).toInt();
280 }
281 
282 
284 {
285  setLocalValue("ReconnectInterval", interval);
286 }
287 
288 
290 {
291  return localValue("ReconnectInterval", 60).toInt();
292 }
293 
294 
295 /***********************************************************************************************/
296 // NotificationSettings:
297 
299 {
300 }
301 
302 
303 void NotificationSettings::setHighlightList(const QVariantList &highlightList)
304 {
305  setLocalValue("Highlights/CustomList", highlightList);
306 }
307 
308 
310 {
311  return localValue("Highlights/CustomList").toList();
312 }
313 
314 
316 {
317  setLocalValue("Highlights/HighlightNick", highlightNickType);
318 }
319 
320 
322 {
323  return (NotificationSettings::HighlightNickType)localValue("Highlights/HighlightNick", CurrentNick).toInt();
324 }
325 
326 
328 {
329  setLocalValue("Highlights/NicksCaseSensitive", cs);
330 }
331 
332 
334 {
335  return localValue("Highlights/NicksCaseSensitive", false).toBool();
336 }
337 
338 
339 // ========================================
340 // TabCompletionSettings
341 // ========================================
342 
344 {
345 }
346 
347 
349 {
350  setLocalValue("CompletionSuffix", suffix);
351 }
352 
353 
355 {
356  return localValue("CompletionSuffix", ": ").toString();
357 }
358 
359 
361 {
362  setLocalValue("AddSpaceMidSentence", space);
363 }
364 
365 
367 {
368  return localValue("AddSpaceMidSentence", false).toBool();
369 }
370 
371 
373 {
374  setLocalValue("SortMode", mode);
375 }
376 
377 
379 {
380  return static_cast<SortMode>(localValue("SortMode"), LastActivity);
381 }
382 
383 
384 void TabCompletionSettings::setCaseSensitivity(Qt::CaseSensitivity cs)
385 {
386  setLocalValue("CaseSensitivity", cs);
387 }
388 
389 
391 {
392  return (Qt::CaseSensitivity)localValue("CaseSensitivity", Qt::CaseInsensitive).toInt();
393 }
394 
395 
397 {
398  setLocalValue("UseLastSpokenTo", use);
399 }
400 
401 
403 {
404  return localValue("UseLastSpokenTo", false).toBool();
405 }
406 
407 
408 // ========================================
409 // ItemViewSettings
410 // ========================================
411 
413 {
414 }
415 
416 
418 {
419  return localValue("DisplayTopicInTooltip", false).toBool();
420 }
421 
422 
424 {
425  return localValue("MouseWheelChangesBuffer", false).toBool();
426 }