fixes #413 - Icons in Nicklist
[quassel.git] / src / qtui / sessionsettings.cpp
1 /***************************************************************************
2  *   Copyright (C) 2005-09 by the Quassel Project                          *
3  *   devel@quassel-irc.org                                                 *
4  *                                                                         *
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.                                           *
9  *                                                                         *
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.                          *
14  *                                                                         *
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  ***************************************************************************/
20 #include "sessionsettings.h"
21
22 #include <QStringList>
23
24 void SessionSettings::setValue(const QString &key, const QVariant &data) {
25   setLocalValue(QString("%1/%2").arg(_sessionId, key), data);
26 }
27
28 QVariant SessionSettings::value(const QString &key, const QVariant &def) {
29   return localValue(QString("%1/%2").arg(_sessionId, key), def);
30 }
31
32 void SessionSettings::removeKey(const QString &key) {
33   removeLocalKey(QString("%1/%2").arg(_sessionId, key));
34 }
35
36 void SessionSettings::cleanup() {
37   QStringList sessions = localChildGroups();
38   QString str;
39   SessionSettings s(sessionId());
40   foreach(str, sessions) {
41     // load session and check age
42     s.setSessionId(str);
43     if(s.sessionAge() > 3) {
44       s.removeSession();
45     }
46   }
47 }
48
49 int SessionSettings::sessionAge() {
50   QVariant val = localValue(QString("%1/_sessionAge").arg(_sessionId), 0);
51   bool b = false;
52   int i = val.toInt(&b);
53   if(b) {
54     return i;
55   } else {
56     // no int saved, delete session
57     //qDebug() << QString("deleting invalid session %1 (invalid session age found)").arg(_sessionId);
58     removeSession();
59   }
60   return 10;
61 }
62
63 void SessionSettings::removeSession() {
64   QStringList keys = localChildKeys(sessionId());
65   foreach(QString k, keys) {
66     removeKey(k);
67   }
68 }
69
70
71 SessionSettings::SessionSettings(const QString & sessionId, const QString & group)  : ClientSettings(group), _sessionId(sessionId) {
72 }
73
74 void SessionSettings::setSessionAge(int age) {
75   setValue(QString("_sessionAge"),age);
76 }
77
78 void SessionSettings::sessionAging() {
79   QStringList sessions = localChildGroups();
80   QString str;
81   SessionSettings s(sessionId());
82   foreach(str, sessions) {
83     // load session and check age
84     s.setSessionId(str);
85     s.setSessionAge(s.sessionAge()+1);
86   }
87 }
88