cmake: avoid de-duplication of user's CXXFLAGS
[quassel.git] / src / common / bufferviewconfig.cpp
1 /***************************************************************************
2  *   Copyright (C) 2005-2022 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 BufferViewConfig::BufferViewConfig(int bufferViewId, QObject* parent)
24     : SyncableObject(parent)
25     , _bufferViewId(bufferViewId)
26 {
27     setObjectName(QString::number(bufferViewId));
28 }
29
30 BufferViewConfig::BufferViewConfig(int bufferViewId, const QVariantMap& properties, QObject* parent)
31     : SyncableObject(parent)
32     , _bufferViewId(bufferViewId)
33 {
34     fromVariantMap(properties);
35     setObjectName(QString::number(bufferViewId));
36 }
37
38 int BufferViewConfig::bufferViewId() const
39 {
40     return _bufferViewId;
41 }
42
43 QString BufferViewConfig::bufferViewName() const
44 {
45     return _bufferViewName;
46 }
47
48 NetworkId BufferViewConfig::networkId() const
49 {
50     return _networkId;
51 }
52
53 bool BufferViewConfig::addNewBuffersAutomatically() const
54 {
55     return _addNewBuffersAutomatically;
56 }
57
58 bool BufferViewConfig::sortAlphabetically() const
59 {
60     return _sortAlphabetically;
61 }
62
63 bool BufferViewConfig::disableDecoration() const
64 {
65     return _disableDecoration;
66 }
67
68 int BufferViewConfig::allowedBufferTypes() const
69 {
70     return _allowedBufferTypes;
71 }
72
73 int BufferViewConfig::minimumActivity() const
74 {
75     return _minimumActivity;
76 }
77
78 bool BufferViewConfig::hideInactiveBuffers() const
79 {
80     return _hideInactiveBuffers;
81 }
82
83 bool BufferViewConfig::hideInactiveNetworks() const
84 {
85     return _hideInactiveNetworks;
86 }
87
88 bool BufferViewConfig::showSearch() const
89 {
90     return _showSearch;
91 }
92
93 QList<BufferId> BufferViewConfig::bufferList() const
94 {
95     return _buffers;
96 }
97
98 QSet<BufferId> BufferViewConfig::removedBuffers() const
99 {
100     return _removedBuffers;
101 }
102
103 QSet<BufferId> BufferViewConfig::temporarilyRemovedBuffers() const
104 {
105     return _temporarilyRemovedBuffers;
106 }
107
108 QVariantList BufferViewConfig::initBufferList() const
109 {
110     QVariantList buffers;
111
112     foreach (BufferId bufferId, _buffers) {
113         buffers << QVariant::fromValue(bufferId);
114     }
115
116     return buffers;
117 }
118
119 void BufferViewConfig::initSetBufferList(const QVariantList& buffers)
120 {
121     _buffers.clear();
122
123     foreach (QVariant buffer, buffers) {
124         _buffers << buffer.value<BufferId>();
125     }
126
127     emit configChanged();  // used to track changes in the settingspage
128 }
129
130 QVariantList BufferViewConfig::initRemovedBuffers() const
131 {
132     QVariantList removedBuffers;
133
134     foreach (BufferId bufferId, _removedBuffers) {
135         removedBuffers << QVariant::fromValue(bufferId);
136     }
137
138     return removedBuffers;
139 }
140
141 void BufferViewConfig::initSetRemovedBuffers(const QVariantList& buffers)
142 {
143     _removedBuffers.clear();
144
145     foreach (QVariant buffer, buffers) {
146         _removedBuffers << buffer.value<BufferId>();
147     }
148 }
149
150 QVariantList BufferViewConfig::initTemporarilyRemovedBuffers() const
151 {
152     QVariantList temporarilyRemovedBuffers;
153
154     foreach (BufferId bufferId, _temporarilyRemovedBuffers) {
155         temporarilyRemovedBuffers << QVariant::fromValue(bufferId);
156     }
157
158     return temporarilyRemovedBuffers;
159 }
160
161 void BufferViewConfig::initSetTemporarilyRemovedBuffers(const QVariantList& buffers)
162 {
163     _temporarilyRemovedBuffers.clear();
164
165     foreach (QVariant buffer, buffers) {
166         _temporarilyRemovedBuffers << buffer.value<BufferId>();
167     }
168 }
169
170 void BufferViewConfig::setBufferViewName(const QString& bufferViewName)
171 {
172     if (_bufferViewName == bufferViewName)
173         return;
174
175     _bufferViewName = bufferViewName;
176     SYNC(ARG(bufferViewName))
177     emit bufferViewNameSet(bufferViewName);
178 }
179
180 void BufferViewConfig::setNetworkId(const NetworkId& networkId)
181 {
182     if (_networkId == networkId)
183         return;
184
185     _networkId = networkId;
186     SYNC(ARG(networkId))
187     emit networkIdSet(networkId);
188     emit configChanged();
189 }
190
191 void BufferViewConfig::setAddNewBuffersAutomatically(bool addNewBuffersAutomatically)
192 {
193     if (_addNewBuffersAutomatically == addNewBuffersAutomatically)
194         return;
195
196     _addNewBuffersAutomatically = addNewBuffersAutomatically;
197     SYNC(ARG(addNewBuffersAutomatically))
198     emit configChanged();
199 }
200
201 void BufferViewConfig::setSortAlphabetically(bool sortAlphabetically)
202 {
203     if (_sortAlphabetically == sortAlphabetically)
204         return;
205
206     _sortAlphabetically = sortAlphabetically;
207     SYNC(ARG(sortAlphabetically))
208     emit configChanged();
209 }
210
211 void BufferViewConfig::setDisableDecoration(bool disableDecoration)
212 {
213     if (_disableDecoration == disableDecoration)
214         return;
215
216     _disableDecoration = disableDecoration;
217     SYNC(ARG(disableDecoration))
218 }
219
220 void BufferViewConfig::setAllowedBufferTypes(int bufferTypes)
221 {
222     if (_allowedBufferTypes == bufferTypes)
223         return;
224
225     _allowedBufferTypes = bufferTypes;
226     SYNC(ARG(bufferTypes))
227     emit configChanged();
228 }
229
230 void BufferViewConfig::setMinimumActivity(int activity)
231 {
232     if (_minimumActivity == activity)
233         return;
234
235     _minimumActivity = activity;
236     SYNC(ARG(activity))
237     emit configChanged();
238 }
239
240 void BufferViewConfig::setHideInactiveBuffers(bool hideInactiveBuffers)
241 {
242     if (_hideInactiveBuffers == hideInactiveBuffers)
243         return;
244
245     _hideInactiveBuffers = hideInactiveBuffers;
246     SYNC(ARG(hideInactiveBuffers))
247     emit configChanged();
248 }
249
250 void BufferViewConfig::setHideInactiveNetworks(bool hideInactiveNetworks)
251 {
252     if (_hideInactiveNetworks == hideInactiveNetworks)
253         return;
254
255     _hideInactiveNetworks = hideInactiveNetworks;
256     SYNC(ARG(hideInactiveNetworks))
257     emit configChanged();
258 }
259
260 void BufferViewConfig::setShowSearch(bool showSearch)
261 {
262     if (_showSearch == showSearch) {
263         return;
264     }
265
266     _showSearch = showSearch;
267     SYNC(ARG(showSearch))
268     emit configChanged();
269 }
270
271 void BufferViewConfig::setBufferList(const QList<BufferId>& buffers)
272 {
273     _buffers = buffers;
274     emit configChanged();
275 }
276
277 void BufferViewConfig::addBuffer(const BufferId& bufferId, int pos)
278 {
279     if (_buffers.contains(bufferId))
280         return;
281
282     if (pos < 0)
283         pos = 0;
284     if (pos > _buffers.count())
285         pos = _buffers.count();
286
287     if (_removedBuffers.contains(bufferId))
288         _removedBuffers.remove(bufferId);
289
290     if (_temporarilyRemovedBuffers.contains(bufferId))
291         _temporarilyRemovedBuffers.remove(bufferId);
292
293     _buffers.insert(pos, bufferId);
294     SYNC(ARG(bufferId), ARG(pos))
295     emit bufferAdded(bufferId, pos);
296     emit configChanged();
297 }
298
299 void BufferViewConfig::moveBuffer(const BufferId& bufferId, int pos)
300 {
301     if (!_buffers.contains(bufferId))
302         return;
303
304     if (pos < 0)
305         pos = 0;
306     if (pos >= _buffers.count())
307         pos = _buffers.count() - 1;
308
309     _buffers.move(_buffers.indexOf(bufferId), pos);
310     SYNC(ARG(bufferId), ARG(pos))
311     emit bufferMoved(bufferId, pos);
312     emit configChanged();
313 }
314
315 void BufferViewConfig::removeBuffer(const BufferId& bufferId)
316 {
317     if (_buffers.contains(bufferId))
318         _buffers.removeAt(_buffers.indexOf(bufferId));
319
320     if (_removedBuffers.contains(bufferId))
321         _removedBuffers.remove(bufferId);
322
323     _temporarilyRemovedBuffers << bufferId;
324     SYNC(ARG(bufferId))
325     emit bufferRemoved(bufferId);
326     emit configChanged();
327 }
328
329 void BufferViewConfig::removeBufferPermanently(const BufferId& bufferId)
330 {
331     if (_buffers.contains(bufferId))
332         _buffers.removeAt(_buffers.indexOf(bufferId));
333
334     if (_temporarilyRemovedBuffers.contains(bufferId))
335         _temporarilyRemovedBuffers.remove(bufferId);
336
337     _removedBuffers << bufferId;
338
339     SYNC(ARG(bufferId))
340     emit bufferPermanentlyRemoved(bufferId);
341     emit configChanged();
342 }
343
344 void BufferViewConfig::requestSetBufferViewName(const QString& bufferViewName)
345 {
346     REQUEST(ARG(bufferViewName))
347 }
348
349 void BufferViewConfig::requestAddBuffer(const BufferId& bufferId, int pos)
350 {
351     REQUEST(ARG(bufferId), ARG(pos))
352 }
353
354 void BufferViewConfig::requestMoveBuffer(const BufferId& bufferId, int pos)
355 {
356     REQUEST(ARG(bufferId), ARG(pos))
357 }
358
359 void BufferViewConfig::requestRemoveBuffer(const BufferId& bufferId)
360 {
361     REQUEST(ARG(bufferId))
362 }
363
364 void BufferViewConfig::requestRemoveBufferPermanently(const BufferId& bufferId)
365 {
366     REQUEST(ARG(bufferId))
367 }