~ubuntu-branches/ubuntu/trusty/quassel/trusty-updates

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
/***************************************************************************
 *   Copyright (C) 2005-2014 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 "uisettings.h"

#include "action.h"
#include "actioncollection.h"

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


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

UiStyleSettings::UiStyleSettings() : UiSettings("UiStyle") {}
UiStyleSettings::UiStyleSettings(const QString &subGroup) : UiSettings(QString("UiStyle/%1").arg(subGroup))
{
}


void UiStyleSettings::setCustomFormat(UiStyle::FormatType ftype, QTextCharFormat format)
{
    setLocalValue(QString("Format/%1").arg(ftype), format);
}


QTextCharFormat UiStyleSettings::customFormat(UiStyle::FormatType ftype)
{
    return localValue(QString("Format/%1").arg(ftype), QTextFormat()).value<QTextFormat>().toCharFormat();
}


void UiStyleSettings::removeCustomFormat(UiStyle::FormatType ftype)
{
    removeLocalKey(QString("Format/%1").arg(ftype));
}


QList<UiStyle::FormatType> UiStyleSettings::availableFormats()
{
    QList<UiStyle::FormatType> formats;
    QStringList list = localChildKeys("Format");
    foreach(QString type, list) {
        formats << (UiStyle::FormatType)type.toInt();
    }
    return formats;
}


/**************************************************************************
 * SessionSettings
 **************************************************************************/

SessionSettings::SessionSettings(const QString &sessionId, const QString &group)
    : UiSettings(group), _sessionId(sessionId)
{
}


void SessionSettings::setValue(const QString &key, const QVariant &data)
{
    setLocalValue(QString("%1/%2").arg(_sessionId, key), data);
}


QVariant SessionSettings::value(const QString &key, const QVariant &def)
{
    return localValue(QString("%1/%2").arg(_sessionId, key), def);
}


void SessionSettings::removeKey(const QString &key)
{
    removeLocalKey(QString("%1/%2").arg(_sessionId, key));
}


void SessionSettings::cleanup()
{
    QStringList sessions = localChildGroups();
    QString str;
    SessionSettings s(sessionId());
    foreach(str, sessions) {
        // load session and check age
        s.setSessionId(str);
        if (s.sessionAge() > 3) {
            s.removeSession();
        }
    }
}


int SessionSettings::sessionAge()
{
    QVariant val = localValue(QString("%1/_sessionAge").arg(_sessionId), 0);
    bool b = false;
    int i = val.toInt(&b);
    if (b) {
        return i;
    }
    else {
        // no int saved, delete session
        //qDebug() << QString("deleting invalid session %1 (invalid session age found)").arg(_sessionId);
        removeSession();
    }
    return 10;
}


void SessionSettings::removeSession()
{
    QStringList keys = localChildKeys(sessionId());
    foreach(QString k, keys) {
        removeKey(k);
    }
}


void SessionSettings::setSessionAge(int age)
{
    setValue(QString("_sessionAge"), age);
}


void SessionSettings::sessionAging()
{
    QStringList sessions = localChildGroups();
    QString str;
    SessionSettings s(sessionId());
    foreach(str, sessions) {
        // load session and check age
        s.setSessionId(str);
        s.setSessionAge(s.sessionAge()+1);
    }
}


/**************************************************************************
 * ShortcutSettings
 **************************************************************************/

ShortcutSettings::ShortcutSettings() : UiSettings("Shortcuts")
{
}


void ShortcutSettings::clear()
{
    foreach(const QString &key, allLocalKeys())
    removeLocalKey(key);
}


QStringList ShortcutSettings::savedShortcuts()
{
    return localChildKeys();
}


QKeySequence ShortcutSettings::loadShortcut(const QString &name)
{
    return localValue(name, QKeySequence()).value<QKeySequence>();
}


void ShortcutSettings::saveShortcut(const QString &name, const QKeySequence &seq)
{
    setLocalValue(name, seq);
}