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