1 /***************************************************************************
2 * Copyright (C) 2005-2018 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 "uisettings.h"
26 #include "actioncollection.h"
28 UiSettings::UiSettings(QString group)
29 : ClientSettings(std::move(group))
34 void UiSettings::setValue(const QString &key, const QVariant &data)
36 setLocalValue(key, data);
40 QVariant UiSettings::value(const QString &key, const QVariant &def) const
42 return localValue(key, def);
46 bool UiSettings::valueExists(const QString &key) const
48 return localKeyExists(key);
52 void UiSettings::remove(const QString &key)
57 /**************************************************************************/
59 UiStyleSettings::UiStyleSettings()
60 : UiSettings("UiStyle")
65 UiStyleSettings::UiStyleSettings(const QString &subGroup)
66 : UiSettings(QString("UiStyle/%1").arg(subGroup))
71 void UiStyleSettings::setCustomFormat(UiStyle::FormatType ftype, const QTextCharFormat &format)
73 setLocalValue(QString("Format/%1").arg(static_cast<quint32>(ftype)), format);
77 QTextCharFormat UiStyleSettings::customFormat(UiStyle::FormatType ftype) const
79 return localValue(QString("Format/%1").arg(static_cast<quint32>(ftype)), QTextFormat()).value<QTextFormat>().toCharFormat();
83 void UiStyleSettings::removeCustomFormat(UiStyle::FormatType ftype)
85 removeLocalKey(QString("Format/%1").arg(static_cast<quint32>(ftype)));
89 QList<UiStyle::FormatType> UiStyleSettings::availableFormats() const
91 QList<UiStyle::FormatType> formats;
92 QStringList list = localChildKeys("Format");
93 foreach(QString type, list) {
94 formats << (UiStyle::FormatType)type.toInt();
100 /**************************************************************************
102 **************************************************************************/
104 SessionSettings::SessionSettings(QString sessionId, QString group)
105 : UiSettings(std::move(group))
106 , _sessionId(std::move(sessionId))
111 void SessionSettings::setValue(const QString &key, const QVariant &data)
113 setLocalValue(QString("%1/%2").arg(_sessionId, key), data);
117 QVariant SessionSettings::value(const QString &key, const QVariant &def) const
119 return localValue(QString("%1/%2").arg(_sessionId, key), def);
123 void SessionSettings::removeKey(const QString &key)
125 removeLocalKey(QString("%1/%2").arg(_sessionId, key));
129 void SessionSettings::cleanup()
131 QStringList sessions = localChildGroups();
133 SessionSettings s(sessionId());
134 foreach(str, sessions) {
135 // load session and check age
137 if (s.sessionAge() > 3) {
144 QString SessionSettings::sessionId() const
150 void SessionSettings::setSessionId(QString sessionId)
152 _sessionId = std::move(sessionId);
156 int SessionSettings::sessionAge()
158 QVariant val = localValue(QString("%1/_sessionAge").arg(_sessionId), 0);
160 int i = val.toInt(&b);
165 // no int saved, delete session
166 //qDebug() << QString("deleting invalid session %1 (invalid session age found)").arg(_sessionId);
173 void SessionSettings::removeSession()
175 QStringList keys = localChildKeys(sessionId());
176 foreach(QString k, keys) {
182 void SessionSettings::setSessionAge(int age)
184 setValue(QString("_sessionAge"), age);
188 void SessionSettings::sessionAging()
190 QStringList sessions = localChildGroups();
192 SessionSettings s(sessionId());
193 foreach(str, sessions) {
194 // load session and check age
196 s.setSessionAge(s.sessionAge()+1);
201 /**************************************************************************
203 **************************************************************************/
205 ShortcutSettings::ShortcutSettings()
206 : UiSettings("Shortcuts")
211 void ShortcutSettings::clear()
213 for (auto &&key : allLocalKeys()) {
219 QStringList ShortcutSettings::savedShortcuts() const
221 return localChildKeys();
225 QKeySequence ShortcutSettings::loadShortcut(const QString &name) const
227 return localValue(name, QKeySequence()).value<QKeySequence>();
231 void ShortcutSettings::saveShortcut(const QString &name, const QKeySequence &seq)
233 setLocalValue(name, seq);