1 /***************************************************************************
2 * Copyright (C) 2005-09 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 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
21 #include "uisettings.h"
23 UiSettings::UiSettings(const QString &group)
24 : ClientSettings(group)
28 /**************************************************************************/
30 UiStyleSettings::UiStyleSettings() : UiSettings("UiStyle") {}
31 UiStyleSettings::UiStyleSettings(const QString &subGroup) : UiSettings(QString("UiStyle/%1").arg(subGroup))
35 void UiStyleSettings::setCustomFormat(UiStyle::FormatType ftype, QTextCharFormat format) {
36 setLocalValue(QString("Format/%1").arg(ftype), format);
39 QTextCharFormat UiStyleSettings::customFormat(UiStyle::FormatType ftype) {
40 return localValue(QString("Format/%1").arg(ftype), QTextFormat()).value<QTextFormat>().toCharFormat();
43 void UiStyleSettings::removeCustomFormat(UiStyle::FormatType ftype) {
44 removeLocalKey(QString("Format/%1").arg(ftype));
47 QList<UiStyle::FormatType> UiStyleSettings::availableFormats() {
48 QList<UiStyle::FormatType> formats;
49 QStringList list = localChildKeys("Format");
50 foreach(QString type, list) {
51 formats << (UiStyle::FormatType)type.toInt();
56 /**************************************************************************
58 **************************************************************************/
60 SessionSettings::SessionSettings(const QString & sessionId, const QString & group)
61 : UiSettings(group), _sessionId(sessionId)
66 void SessionSettings::setValue(const QString &key, const QVariant &data) {
67 setLocalValue(QString("%1/%2").arg(_sessionId, key), data);
70 QVariant SessionSettings::value(const QString &key, const QVariant &def) {
71 return localValue(QString("%1/%2").arg(_sessionId, key), def);
74 void SessionSettings::removeKey(const QString &key) {
75 removeLocalKey(QString("%1/%2").arg(_sessionId, key));
78 void SessionSettings::cleanup() {
79 QStringList sessions = localChildGroups();
81 SessionSettings s(sessionId());
82 foreach(str, sessions) {
83 // load session and check age
85 if(s.sessionAge() > 3) {
91 int SessionSettings::sessionAge() {
92 QVariant val = localValue(QString("%1/_sessionAge").arg(_sessionId), 0);
94 int i = val.toInt(&b);
98 // no int saved, delete session
99 //qDebug() << QString("deleting invalid session %1 (invalid session age found)").arg(_sessionId);
105 void SessionSettings::removeSession() {
106 QStringList keys = localChildKeys(sessionId());
107 foreach(QString k, keys) {
112 void SessionSettings::setSessionAge(int age) {
113 setValue(QString("_sessionAge"),age);
116 void SessionSettings::sessionAging() {
117 QStringList sessions = localChildGroups();
119 SessionSettings s(sessionId());
120 foreach(str, sessions) {
121 // load session and check age
123 s.setSessionAge(s.sessionAge()+1);