Make IrcParser functional
[quassel.git] / src / core / corebufferviewmanager.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
21 #include "corebufferviewmanager.h"
22
23 #include "corebufferviewconfig.h"
24
25 #include "core.h"
26 #include "coresession.h"
27
28 INIT_SYNCABLE_OBJECT(CoreBufferViewManager)
29 CoreBufferViewManager::CoreBufferViewManager(SignalProxy *proxy, CoreSession *parent)
30   : BufferViewManager(proxy, parent),
31     _coreSession(parent)
32 {
33   QVariantMap views = Core::getUserSetting(_coreSession->user(), "BufferViews").toMap();
34   QVariantMap::iterator iter = views.begin();
35   QVariantMap::iterator iterEnd = views.end();
36   CoreBufferViewConfig *config = 0;
37   while(iter != iterEnd) {
38     config = new CoreBufferViewConfig(iter.key().toInt(), iter.value().toMap(), this);
39     addBufferViewConfig(config);
40     iter++;
41   }
42 }
43
44 void CoreBufferViewManager::saveBufferViews() {
45   QVariantMap views;
46
47   BufferViewConfigHash::const_iterator iter = bufferViewConfigHash().constBegin();
48   BufferViewConfigHash::const_iterator iterEnd = bufferViewConfigHash().constEnd();
49   while(iter != iterEnd) {
50     views[QString::number((*iter)->bufferViewId())] = (*iter)->toVariantMap();
51     iter++;
52   }
53
54   Core::setUserSetting(_coreSession->user(), "BufferViews", views);
55 }
56
57 void CoreBufferViewManager::requestCreateBufferView(const QVariantMap &properties) {
58   QString bufferViewName = properties["bufferViewName"].toString();
59   int maxId = -1;
60   BufferViewConfigHash::const_iterator iter = bufferViewConfigHash().constBegin();
61   BufferViewConfigHash::const_iterator iterEnd = bufferViewConfigHash().constEnd();
62   while(iter != iterEnd) {
63     if((*iter)->bufferViewName() == bufferViewName)
64       return;
65     
66     if((*iter)->bufferViewId() > maxId)
67       maxId = (*iter)->bufferViewId();
68     
69     iter++;
70   }
71   maxId++;
72
73   CoreBufferViewConfig *config = new CoreBufferViewConfig(maxId, properties);
74   addBufferViewConfig(config);
75 }
76
77 void CoreBufferViewManager::requestCreateBufferViews(const QVariantList &properties) {
78   QVariantList::const_iterator iter = properties.constBegin();
79   QVariantList::const_iterator iterEnd = properties.constEnd();
80   while(iter != iterEnd) {
81     requestCreateBufferView((*iter).toMap());
82     iter++;
83   }
84 }
85
86 void CoreBufferViewManager::requestDeleteBufferView(int bufferViewId) {
87   deleteBufferViewConfig(bufferViewId);
88 }
89
90 void CoreBufferViewManager::requestDeleteBufferViews(const QVariantList &bufferViews) {
91   foreach(QVariant bufferView, bufferViews) {
92     deleteBufferViewConfig(bufferView.toInt());
93   }
94 }