1 /***************************************************************************
2 * Copyright (C) 2005-2014 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"
24 #include "actioncollection.h"
26 UiSettings::UiSettings(const QString &group)
27 : ClientSettings(group)
32 /**************************************************************************/
34 UiStyleSettings::UiStyleSettings() : UiSettings("UiStyle") {}
35 UiStyleSettings::UiStyleSettings(const QString &subGroup) : UiSettings(QString("UiStyle/%1").arg(subGroup))
40 void UiStyleSettings::setCustomFormat(UiStyle::FormatType ftype, QTextCharFormat format)
42 setLocalValue(QString("Format/%1").arg(ftype), format);
46 QTextCharFormat UiStyleSettings::customFormat(UiStyle::FormatType ftype)
48 return localValue(QString("Format/%1").arg(ftype), QTextFormat()).value<QTextFormat>().toCharFormat();
52 void UiStyleSettings::removeCustomFormat(UiStyle::FormatType ftype)
54 removeLocalKey(QString("Format/%1").arg(ftype));
58 QList<UiStyle::FormatType> UiStyleSettings::availableFormats()
60 QList<UiStyle::FormatType> formats;
61 QStringList list = localChildKeys("Format");
62 foreach(QString type, list) {
63 formats << (UiStyle::FormatType)type.toInt();
69 /**************************************************************************
71 **************************************************************************/
73 SessionSettings::SessionSettings(const QString &sessionId, const QString &group)
74 : UiSettings(group), _sessionId(sessionId)
79 void SessionSettings::setValue(const QString &key, const QVariant &data)
81 setLocalValue(QString("%1/%2").arg(_sessionId, key), data);
85 QVariant SessionSettings::value(const QString &key, const QVariant &def)
87 return localValue(QString("%1/%2").arg(_sessionId, key), def);
91 void SessionSettings::removeKey(const QString &key)
93 removeLocalKey(QString("%1/%2").arg(_sessionId, key));
97 void SessionSettings::cleanup()
99 QStringList sessions = localChildGroups();
101 SessionSettings s(sessionId());
102 foreach(str, sessions) {
103 // load session and check age
105 if (s.sessionAge() > 3) {
112 int SessionSettings::sessionAge()
114 QVariant val = localValue(QString("%1/_sessionAge").arg(_sessionId), 0);
116 int i = val.toInt(&b);
121 // no int saved, delete session
122 //qDebug() << QString("deleting invalid session %1 (invalid session age found)").arg(_sessionId);
129 void SessionSettings::removeSession()
131 QStringList keys = localChildKeys(sessionId());
132 foreach(QString k, keys) {
138 void SessionSettings::setSessionAge(int age)
140 setValue(QString("_sessionAge"), age);
144 void SessionSettings::sessionAging()
146 QStringList sessions = localChildGroups();
148 SessionSettings s(sessionId());
149 foreach(str, sessions) {
150 // load session and check age
152 s.setSessionAge(s.sessionAge()+1);
157 /**************************************************************************
159 **************************************************************************/
161 ShortcutSettings::ShortcutSettings() : UiSettings("Shortcuts")
166 void ShortcutSettings::clear()
168 foreach(const QString &key, allLocalKeys())
173 QStringList ShortcutSettings::savedShortcuts()
175 return localChildKeys();
179 QKeySequence ShortcutSettings::loadShortcut(const QString &name)
181 return localValue(name, QKeySequence()).value<QKeySequence>();
185 void ShortcutSettings::saveShortcut(const QString &name, const QKeySequence &seq)
187 setLocalValue(name, seq);