Make protocol messages structs instead of classes
[quassel.git] / src / common / bufferviewconfig.cpp
1 /***************************************************************************
2  *   Copyright (C) 2005-2013 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 "bufferviewconfig.h"
22
23 #include "bufferinfo.h"
24
25 INIT_SYNCABLE_OBJECT(BufferViewConfig)
26 BufferViewConfig::BufferViewConfig(int bufferViewId, QObject *parent)
27     : SyncableObject(parent),
28     _bufferViewId(bufferViewId),
29     _addNewBuffersAutomatically(true),
30     _sortAlphabetically(true),
31     _hideInactiveBuffers(false),
32     _disableDecoration(false),
33     _allowedBufferTypes(BufferInfo::StatusBuffer | BufferInfo::ChannelBuffer | BufferInfo::QueryBuffer | BufferInfo::GroupBuffer),
34     _minimumActivity(0)
35 {
36     setObjectName(QString::number(bufferViewId));
37 }
38
39
40 BufferViewConfig::BufferViewConfig(int bufferViewId, const QVariantMap &properties, QObject *parent)
41     : SyncableObject(parent),
42     _bufferViewId(bufferViewId)
43 {
44     fromVariantMap(properties);
45     setObjectName(QString::number(bufferViewId));
46 }
47
48
49 void BufferViewConfig::setBufferViewName(const QString &bufferViewName)
50 {
51     if (_bufferViewName == bufferViewName)
52         return;
53
54     _bufferViewName = bufferViewName;
55     SYNC(ARG(bufferViewName))
56     emit bufferViewNameSet(bufferViewName);
57 }
58
59
60 void BufferViewConfig::setNetworkId(const NetworkId &networkId)
61 {
62     if (_networkId == networkId)
63         return;
64
65     _networkId = networkId;
66     SYNC(ARG(networkId))
67     emit networkIdSet(networkId);
68     emit configChanged();
69 }
70
71
72 void BufferViewConfig::setAddNewBuffersAutomatically(bool addNewBuffersAutomatically)
73 {
74     if (_addNewBuffersAutomatically == addNewBuffersAutomatically)
75         return;
76
77     _addNewBuffersAutomatically = addNewBuffersAutomatically;
78     SYNC(ARG(addNewBuffersAutomatically))
79     emit configChanged();
80 }
81
82
83 void BufferViewConfig::setSortAlphabetically(bool sortAlphabetically)
84 {
85     if (_sortAlphabetically == sortAlphabetically)
86         return;
87
88     _sortAlphabetically = sortAlphabetically;
89     SYNC(ARG(sortAlphabetically))
90     emit configChanged();
91 }
92
93
94 void BufferViewConfig::setDisableDecoration(bool disableDecoration)
95 {
96     if (_disableDecoration == disableDecoration)
97         return;
98
99     _disableDecoration = disableDecoration;
100     SYNC(ARG(disableDecoration))
101 }
102
103
104 void BufferViewConfig::setAllowedBufferTypes(int bufferTypes)
105 {
106     if (_allowedBufferTypes == bufferTypes)
107         return;
108
109     _allowedBufferTypes = bufferTypes;
110     SYNC(ARG(bufferTypes))
111     emit configChanged();
112 }
113
114
115 void BufferViewConfig::setMinimumActivity(int activity)
116 {
117     if (_minimumActivity == activity)
118         return;
119
120     _minimumActivity = activity;
121     SYNC(ARG(activity))
122     emit configChanged();
123 }
124
125
126 void BufferViewConfig::setHideInactiveBuffers(bool hideInactiveBuffers)
127 {
128     if (_hideInactiveBuffers == hideInactiveBuffers)
129         return;
130
131     _hideInactiveBuffers = hideInactiveBuffers;
132     SYNC(ARG(hideInactiveBuffers))
133     emit configChanged();
134 }
135
136
137 QVariantList BufferViewConfig::initBufferList() const
138 {
139     QVariantList buffers;
140
141     foreach(BufferId bufferId, _buffers) {
142         buffers << qVariantFromValue(bufferId);
143     }
144
145     return buffers;
146 }
147
148
149 void BufferViewConfig::initSetBufferList(const QVariantList &buffers)
150 {
151     _buffers.clear();
152
153     foreach(QVariant buffer, buffers) {
154         _buffers << buffer.value<BufferId>();
155     }
156
157     emit configChanged(); // used to track changes in the settingspage
158 }
159
160
161 void BufferViewConfig::initSetBufferList(const QList<BufferId> &buffers)
162 {
163     _buffers.clear();
164
165     foreach(BufferId bufferId, buffers) {
166         _buffers << bufferId;
167     }
168
169     emit configChanged(); // used to track changes in the settingspage
170 }
171
172
173 QVariantList BufferViewConfig::initRemovedBuffers() const
174 {
175     QVariantList removedBuffers;
176
177     foreach(BufferId bufferId, _removedBuffers) {
178         removedBuffers << qVariantFromValue(bufferId);
179     }
180
181     return removedBuffers;
182 }
183
184
185 void BufferViewConfig::initSetRemovedBuffers(const QVariantList &buffers)
186 {
187     _removedBuffers.clear();
188
189     foreach(QVariant buffer, buffers) {
190         _removedBuffers << buffer.value<BufferId>();
191     }
192 }
193
194
195 QVariantList BufferViewConfig::initTemporarilyRemovedBuffers() const
196 {
197     QVariantList temporarilyRemovedBuffers;
198
199     foreach(BufferId bufferId, _temporarilyRemovedBuffers) {
200         temporarilyRemovedBuffers << qVariantFromValue(bufferId);
201     }
202
203     return temporarilyRemovedBuffers;
204 }
205
206
207 void BufferViewConfig::initSetTemporarilyRemovedBuffers(const QVariantList &buffers)
208 {
209     _temporarilyRemovedBuffers.clear();
210
211     foreach(QVariant buffer, buffers) {
212         _temporarilyRemovedBuffers << buffer.value<BufferId>();
213     }
214 }
215
216
217 void BufferViewConfig::addBuffer(const BufferId &bufferId, int pos)
218 {
219     if (_buffers.contains(bufferId))
220         return;
221
222     if (pos < 0)
223         pos = 0;
224     if (pos > _buffers.count())
225         pos = _buffers.count();
226
227     if (_removedBuffers.contains(bufferId))
228         _removedBuffers.remove(bufferId);
229
230     if (_temporarilyRemovedBuffers.contains(bufferId))
231         _temporarilyRemovedBuffers.remove(bufferId);
232
233     _buffers.insert(pos, bufferId);
234     SYNC(ARG(bufferId), ARG(pos))
235     emit bufferAdded(bufferId, pos);
236     emit configChanged();
237 }
238
239
240 void BufferViewConfig::moveBuffer(const BufferId &bufferId, int pos)
241 {
242     if (!_buffers.contains(bufferId))
243         return;
244
245     if (pos < 0)
246         pos = 0;
247     if (pos >= _buffers.count())
248         pos = _buffers.count() - 1;
249
250     _buffers.move(_buffers.indexOf(bufferId), pos);
251     SYNC(ARG(bufferId), ARG(pos))
252     emit bufferMoved(bufferId, pos);
253     emit configChanged();
254 }
255
256
257 void BufferViewConfig::removeBuffer(const BufferId &bufferId)
258 {
259     if (_buffers.contains(bufferId))
260         _buffers.removeAt(_buffers.indexOf(bufferId));
261
262     if (_removedBuffers.contains(bufferId))
263         _removedBuffers.remove(bufferId);
264
265     _temporarilyRemovedBuffers << bufferId;
266     SYNC(ARG(bufferId))
267     emit bufferRemoved(bufferId);
268     emit configChanged();
269 }
270
271
272 void BufferViewConfig::removeBufferPermanently(const BufferId &bufferId)
273 {
274     if (_buffers.contains(bufferId))
275         _buffers.removeAt(_buffers.indexOf(bufferId));
276
277     if (_temporarilyRemovedBuffers.contains(bufferId))
278         _temporarilyRemovedBuffers.remove(bufferId);
279
280     _removedBuffers << bufferId;
281
282     SYNC(ARG(bufferId))
283     emit bufferPermanentlyRemoved(bufferId);
284     emit configChanged();
285 }