File: clientsettings.cpp

package info (click to toggle)
quassel 1:0.13.1-5
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 25,640 kB
  • sloc: cpp: 66,953; perl: 15,837; ansic: 4,418; sql: 1,225; sh: 328; xml: 263; python: 224; makefile: 24
file content (427 lines) | stat: -rw-r--r-- 11,621 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
/***************************************************************************
 *   Copyright (C) 2005-2019 by the Quassel Project                        *
 *   devel@quassel-irc.org                                                 *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) version 3.                                           *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
 ***************************************************************************/

#include <QStringList>

#include "clientsettings.h"

#include <QHostAddress>
#ifdef HAVE_SSL
#include <QSslSocket>
#endif

#include "client.h"
#include "quassel.h"

ClientSettings::ClientSettings(QString g) : Settings(g, Quassel::buildInfo().clientApplicationName)
{
}


ClientSettings::~ClientSettings()
{
}


/***********************************************************************************************/

CoreAccountSettings::CoreAccountSettings(const QString &subgroup)
    : ClientSettings("CoreAccounts"),
    _subgroup(subgroup)
{
}


void CoreAccountSettings::notify(const QString &key, QObject *receiver, const char *slot)
{
    ClientSettings::notify(QString("%1/%2/%3").arg(Client::currentCoreAccount().accountId().toInt()).arg(_subgroup).arg(key), receiver, slot);
}


QList<AccountId> CoreAccountSettings::knownAccounts()
{
    QList<AccountId> ids;
    foreach(const QString &key, localChildGroups()) {
        AccountId acc = key.toInt();
        if (acc.isValid())
            ids << acc;
    }
    return ids;
}


AccountId CoreAccountSettings::lastAccount()
{
    return localValue("LastAccount", 0).toInt();
}


void CoreAccountSettings::setLastAccount(AccountId account)
{
    setLocalValue("LastAccount", account.toInt());
}


AccountId CoreAccountSettings::autoConnectAccount()
{
    return localValue("AutoConnectAccount", 0).toInt();
}


void CoreAccountSettings::setAutoConnectAccount(AccountId account)
{
    setLocalValue("AutoConnectAccount", account.toInt());
}


bool CoreAccountSettings::autoConnectOnStartup()
{
    return localValue("AutoConnectOnStartup", false).toBool();
}


void CoreAccountSettings::setAutoConnectOnStartup(bool b)
{
    setLocalValue("AutoConnectOnStartup", b);
}


bool CoreAccountSettings::autoConnectToFixedAccount()
{
    return localValue("AutoConnectToFixedAccount", false).toBool();
}


void CoreAccountSettings::setAutoConnectToFixedAccount(bool b)
{
    setLocalValue("AutoConnectToFixedAccount", b);
}


void CoreAccountSettings::storeAccountData(AccountId id, const QVariantMap &data)
{
    QString base = QString::number(id.toInt());
    foreach(const QString &key, data.keys()) {
        setLocalValue(base + "/" + key, data.value(key));
    }

    // FIXME Migration from 0.5 -> 0.6
    removeLocalKey(QString("%1/Connection").arg(base));
}


QVariantMap CoreAccountSettings::retrieveAccountData(AccountId id)
{
    QVariantMap map;
    QString base = QString::number(id.toInt());
    foreach(const QString &key, localChildKeys(base)) {
        map[key] = localValue(base + "/" + key);
    }

    // FIXME Migration from 0.5 -> 0.6
    if (!map.contains("Uuid") && map.contains("Connection")) {
        QVariantMap oldmap = map.value("Connection").toMap();
        map["AccountName"] = oldmap.value("AccountName");
        map["HostName"] = oldmap.value("Host");
        map["Port"] = oldmap.value("Port");
        map["User"] = oldmap.value("User");
        map["Password"] = oldmap.value("Password");
        map["StorePassword"] = oldmap.value("RememberPasswd");
        map["UseSSL"] = oldmap.value("useSsl");
        map["UseProxy"] = oldmap.value("useProxy");
        map["ProxyHostName"] = oldmap.value("proxyHost");
        map["ProxyPort"] = oldmap.value("proxyPort");
        map["ProxyUser"] = oldmap.value("proxyUser");
        map["ProxyPassword"] = oldmap.value("proxyPassword");
        map["ProxyType"] = oldmap.value("proxyType");
        map["Internal"] = oldmap.value("InternalAccount");

        map["AccountId"] = id.toInt();
        map["Uuid"] = QUuid::createUuid().toString();
    }

    return map;
}


void CoreAccountSettings::setAccountValue(const QString &key, const QVariant &value)
{
    if (!Client::currentCoreAccount().isValid())
        return;
    setLocalValue(QString("%1/%2/%3").arg(Client::currentCoreAccount().accountId().toInt()).arg(_subgroup).arg(key), value);
}


QVariant CoreAccountSettings::accountValue(const QString &key, const QVariant &def)
{
    if (!Client::currentCoreAccount().isValid())
        return QVariant();
    return localValue(QString("%1/%2/%3").arg(Client::currentCoreAccount().accountId().toInt()).arg(_subgroup).arg(key), def);
}


void CoreAccountSettings::setJumpKeyMap(const QHash<int, BufferId> &keyMap)
{
    QVariantMap variants;
    QHash<int, BufferId>::const_iterator mapIter = keyMap.constBegin();
    while (mapIter != keyMap.constEnd()) {
        variants[QString::number(mapIter.key())] = QVariant::fromValue(mapIter.value());
        ++mapIter;
    }
    setAccountValue("JumpKeyMap", variants);
}


QHash<int, BufferId> CoreAccountSettings::jumpKeyMap()
{
    QHash<int, BufferId> keyMap;
    QVariantMap variants = accountValue("JumpKeyMap", QVariant()).toMap();
    QVariantMap::const_iterator mapIter = variants.constBegin();
    while (mapIter != variants.constEnd()) {
        keyMap[mapIter.key().toInt()] = mapIter.value().value<BufferId>();
        ++mapIter;
    }
    return keyMap;
}


void CoreAccountSettings::setBufferViewOverlay(const QSet<int> &viewIds)
{
    QVariantList variants;
    foreach (int viewId, viewIds) {
        variants << QVariant::fromValue(viewId);
    }
    setAccountValue("BufferViewOverlay", variants);
}


QSet<int> CoreAccountSettings::bufferViewOverlay()
{
    QSet<int> viewIds;
    QVariantList variants = accountValue("BufferViewOverlay").toList();
    for (QVariantList::const_iterator iter = variants.constBegin(); iter != variants.constEnd(); ++iter) {
        viewIds << iter->toInt();
    }
    return viewIds;
}


void CoreAccountSettings::removeAccount(AccountId id)
{
    removeLocalKey(QString("%1").arg(id.toInt()));
}


void CoreAccountSettings::clearAccounts()
{
    foreach(const QString &key, localChildGroups())
    removeLocalKey(key);
}


/***********************************************************************************************/
// CoreConnectionSettings:

CoreConnectionSettings::CoreConnectionSettings() : ClientSettings("CoreConnection") {}

void CoreConnectionSettings::setNetworkDetectionMode(NetworkDetectionMode mode)
{
    setLocalValue("NetworkDetectionMode", mode);
}


CoreConnectionSettings::NetworkDetectionMode CoreConnectionSettings::networkDetectionMode()
{
    auto mode = localValue("NetworkDetectionMode", UseQNetworkConfigurationManager).toInt();
    if (mode == 0)
        mode = UseQNetworkConfigurationManager; // UseSolid is gone, map that to the new default
    return static_cast<NetworkDetectionMode>(mode);
}


void CoreConnectionSettings::setAutoReconnect(bool autoReconnect)
{
    setLocalValue("AutoReconnect", autoReconnect);
}


bool CoreConnectionSettings::autoReconnect()
{
    return localValue("AutoReconnect", true).toBool();
}


void CoreConnectionSettings::setPingTimeoutInterval(int interval)
{
    setLocalValue("PingTimeoutInterval", interval);
}


int CoreConnectionSettings::pingTimeoutInterval()
{
    return localValue("PingTimeoutInterval", 60).toInt();
}


void CoreConnectionSettings::setReconnectInterval(int interval)
{
    setLocalValue("ReconnectInterval", interval);
}


int CoreConnectionSettings::reconnectInterval()
{
    return localValue("ReconnectInterval", 60).toInt();
}


/***********************************************************************************************/
// NotificationSettings:

NotificationSettings::NotificationSettings() : ClientSettings("Notification")
{
}


void NotificationSettings::setHighlightList(const QVariantList &highlightList)
{
    setLocalValue("Highlights/CustomList", highlightList);
}


QVariantList NotificationSettings::highlightList()
{
    return localValue("Highlights/CustomList").toList();
}


void NotificationSettings::setHighlightNick(NotificationSettings::HighlightNickType highlightNickType)
{
    setLocalValue("Highlights/HighlightNick", highlightNickType);
}


NotificationSettings::HighlightNickType NotificationSettings::highlightNick()
{
    return (NotificationSettings::HighlightNickType)localValue("Highlights/HighlightNick",
                                                               CurrentNick).toInt();
}


void NotificationSettings::setNicksCaseSensitive(bool cs)
{
    setLocalValue("Highlights/NicksCaseSensitive", cs);
}


bool NotificationSettings::nicksCaseSensitive()
{
    return localValue("Highlights/NicksCaseSensitive", false).toBool();
}


// ========================================
//  TabCompletionSettings
// ========================================

TabCompletionSettings::TabCompletionSettings() : ClientSettings("TabCompletion")
{
}


void TabCompletionSettings::setCompletionSuffix(const QString &suffix)
{
    setLocalValue("CompletionSuffix", suffix);
}


QString TabCompletionSettings::completionSuffix()
{
    return localValue("CompletionSuffix", ": ").toString();
}


void TabCompletionSettings::setAddSpaceMidSentence(bool space)
{
    setLocalValue("AddSpaceMidSentence", space);
}


bool TabCompletionSettings::addSpaceMidSentence()
{
    return localValue("AddSpaceMidSentence", false).toBool();
}


void TabCompletionSettings::setSortMode(SortMode mode)
{
    setLocalValue("SortMode", mode);
}


TabCompletionSettings::SortMode TabCompletionSettings::sortMode()
{
    return static_cast<SortMode>(localValue("SortMode"), LastActivity);
}


void TabCompletionSettings::setCaseSensitivity(Qt::CaseSensitivity cs)
{
    setLocalValue("CaseSensitivity", cs);
}


Qt::CaseSensitivity TabCompletionSettings::caseSensitivity()
{
    return (Qt::CaseSensitivity)localValue("CaseSensitivity", Qt::CaseInsensitive).toInt();
}


void TabCompletionSettings::setUseLastSpokenTo(bool use)
{
    setLocalValue("UseLastSpokenTo", use);
}


bool TabCompletionSettings::useLastSpokenTo()
{
    return localValue("UseLastSpokenTo", false).toBool();
}


// ========================================
//  ItemViewSettings
// ========================================

ItemViewSettings::ItemViewSettings(const QString &group) : ClientSettings(group)
{
}


bool ItemViewSettings::displayTopicInTooltip()
{
    return localValue("DisplayTopicInTooltip", false).toBool();
}


bool ItemViewSettings::mouseWheelChangesBuffer()
{
    return localValue("MouseWheelChangesBuffer", false).toBool();
}