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))
32 void UiSettings::setValue(const QString& key, const QVariant& data)
34 setLocalValue(key, data);
37 QVariant UiSettings::value(const QString& key, const QVariant& def) const
39 return localValue(key, def);
42 bool UiSettings::valueExists(const QString& key) const
44 return localKeyExists(key);
47 void UiSettings::remove(const QString& key)
52 /**************************************************************************/
54 UiStyleSettings::UiStyleSettings()
55 : UiSettings("UiStyle")
58 UiStyleSettings::UiStyleSettings(const QString& subGroup)
59 : UiSettings(QString("UiStyle/%1").arg(subGroup))
62 void UiStyleSettings::setCustomFormat(UiStyle::FormatType ftype, const QTextCharFormat& format)
64 setLocalValue(QString("Format/%1").arg(static_cast<quint32>(ftype)), format);
67 QTextCharFormat UiStyleSettings::customFormat(UiStyle::FormatType ftype) const
69 return localValue(QString("Format/%1").arg(static_cast<quint32>(ftype)), QTextFormat()).value<QTextFormat>().toCharFormat();
72 void UiStyleSettings::removeCustomFormat(UiStyle::FormatType ftype)
74 removeLocalKey(QString("Format/%1").arg(static_cast<quint32>(ftype)));
77 QList<UiStyle::FormatType> UiStyleSettings::availableFormats() const
79 QList<UiStyle::FormatType> formats;
80 QStringList list = localChildKeys("Format");
81 foreach (QString type, list) {
82 formats << (UiStyle::FormatType)type.toInt();
87 /**************************************************************************
89 **************************************************************************/
91 SessionSettings::SessionSettings(QString sessionId, QString group)
92 : UiSettings(std::move(group))
93 , _sessionId(std::move(sessionId))
96 void SessionSettings::setValue(const QString& key, const QVariant& data)
98 setLocalValue(QString("%1/%2").arg(_sessionId, key), data);
101 QVariant SessionSettings::value(const QString& key, const QVariant& def) const
103 return localValue(QString("%1/%2").arg(_sessionId, key), def);
106 void SessionSettings::removeKey(const QString& key)
108 removeLocalKey(QString("%1/%2").arg(_sessionId, key));
111 void SessionSettings::cleanup()
113 QStringList sessions = localChildGroups();
115 SessionSettings s(sessionId());
116 foreach (str, sessions) {
117 // load session and check age
119 if (s.sessionAge() > 3) {
125 QString SessionSettings::sessionId() const
130 void SessionSettings::setSessionId(QString sessionId)
132 _sessionId = std::move(sessionId);
135 int SessionSettings::sessionAge()
137 QVariant val = localValue(QString("%1/_sessionAge").arg(_sessionId), 0);
139 int i = val.toInt(&b);
144 // no int saved, delete session
145 // qDebug() << QString("deleting invalid session %1 (invalid session age found)").arg(_sessionId);
151 void SessionSettings::removeSession()
153 QStringList keys = localChildKeys(sessionId());
154 foreach (QString k, keys) {
159 void SessionSettings::setSessionAge(int age)
161 setValue(QString("_sessionAge"), age);
164 void SessionSettings::sessionAging()
166 QStringList sessions = localChildGroups();
168 SessionSettings s(sessionId());
169 foreach (str, sessions) {
170 // load session and check age
172 s.setSessionAge(s.sessionAge() + 1);
176 /**************************************************************************
178 **************************************************************************/
180 ShortcutSettings::ShortcutSettings()
181 : UiSettings("Shortcuts")
184 void ShortcutSettings::clear()
186 for (auto&& key : allLocalKeys()) {
191 QStringList ShortcutSettings::savedShortcuts() const
193 return localChildKeys();
196 QKeySequence ShortcutSettings::loadShortcut(const QString& name) const
198 return localValue(name, QKeySequence()).value<QKeySequence>();
201 void ShortcutSettings::saveShortcut(const QString& name, const QKeySequence& seq)
203 setLocalValue(name, seq);