1 /***************************************************************************
2 * Copyright (C) 2005-2019 by the Quassel Project *
3 * devel@quassel-irc.org *
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. *
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. *
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 ***************************************************************************/
21 #include "bufferviewconfig.h"
23 BufferViewConfig::BufferViewConfig(int bufferViewId, QObject* parent)
24 : SyncableObject(parent)
25 , _bufferViewId(bufferViewId)
27 setObjectName(QString::number(bufferViewId));
30 BufferViewConfig::BufferViewConfig(int bufferViewId, const QVariantMap& properties, QObject* parent)
31 : SyncableObject(parent)
32 , _bufferViewId(bufferViewId)
34 fromVariantMap(properties);
35 setObjectName(QString::number(bufferViewId));
38 int BufferViewConfig::bufferViewId() const
43 QString BufferViewConfig::bufferViewName() const
45 return _bufferViewName;
48 NetworkId BufferViewConfig::networkId() const
53 bool BufferViewConfig::addNewBuffersAutomatically() const
55 return _addNewBuffersAutomatically;
58 bool BufferViewConfig::sortAlphabetically() const
60 return _sortAlphabetically;
63 bool BufferViewConfig::disableDecoration() const
65 return _disableDecoration;
68 int BufferViewConfig::allowedBufferTypes() const
70 return _allowedBufferTypes;
73 int BufferViewConfig::minimumActivity() const
75 return _minimumActivity;
78 bool BufferViewConfig::hideInactiveBuffers() const
80 return _hideInactiveBuffers;
83 bool BufferViewConfig::hideInactiveNetworks() const
85 return _hideInactiveNetworks;
88 bool BufferViewConfig::showSearch() const
93 QList<BufferId> BufferViewConfig::bufferList() const
98 QSet<BufferId> BufferViewConfig::removedBuffers() const
100 return _removedBuffers;
103 QSet<BufferId> BufferViewConfig::temporarilyRemovedBuffers() const
105 return _temporarilyRemovedBuffers;
108 QVariantList BufferViewConfig::initBufferList() const
110 QVariantList buffers;
112 foreach (BufferId bufferId, _buffers) {
113 buffers << qVariantFromValue(bufferId);
119 void BufferViewConfig::initSetBufferList(const QVariantList& buffers)
123 foreach (QVariant buffer, buffers) {
124 _buffers << buffer.value<BufferId>();
127 emit configChanged(); // used to track changes in the settingspage
130 QVariantList BufferViewConfig::initRemovedBuffers() const
132 QVariantList removedBuffers;
134 foreach (BufferId bufferId, _removedBuffers) {
135 removedBuffers << qVariantFromValue(bufferId);
138 return removedBuffers;
141 void BufferViewConfig::initSetRemovedBuffers(const QVariantList& buffers)
143 _removedBuffers.clear();
145 foreach (QVariant buffer, buffers) {
146 _removedBuffers << buffer.value<BufferId>();
150 QVariantList BufferViewConfig::initTemporarilyRemovedBuffers() const
152 QVariantList temporarilyRemovedBuffers;
154 foreach (BufferId bufferId, _temporarilyRemovedBuffers) {
155 temporarilyRemovedBuffers << qVariantFromValue(bufferId);
158 return temporarilyRemovedBuffers;
161 void BufferViewConfig::initSetTemporarilyRemovedBuffers(const QVariantList& buffers)
163 _temporarilyRemovedBuffers.clear();
165 foreach (QVariant buffer, buffers) {
166 _temporarilyRemovedBuffers << buffer.value<BufferId>();
170 void BufferViewConfig::setBufferViewName(const QString& bufferViewName)
172 if (_bufferViewName == bufferViewName)
175 _bufferViewName = bufferViewName;
176 SYNC(ARG(bufferViewName))
177 emit bufferViewNameSet(bufferViewName);
180 void BufferViewConfig::setNetworkId(const NetworkId& networkId)
182 if (_networkId == networkId)
185 _networkId = networkId;
187 emit networkIdSet(networkId);
188 emit configChanged();
191 void BufferViewConfig::setAddNewBuffersAutomatically(bool addNewBuffersAutomatically)
193 if (_addNewBuffersAutomatically == addNewBuffersAutomatically)
196 _addNewBuffersAutomatically = addNewBuffersAutomatically;
197 SYNC(ARG(addNewBuffersAutomatically))
198 emit configChanged();
201 void BufferViewConfig::setSortAlphabetically(bool sortAlphabetically)
203 if (_sortAlphabetically == sortAlphabetically)
206 _sortAlphabetically = sortAlphabetically;
207 SYNC(ARG(sortAlphabetically))
208 emit configChanged();
211 void BufferViewConfig::setDisableDecoration(bool disableDecoration)
213 if (_disableDecoration == disableDecoration)
216 _disableDecoration = disableDecoration;
217 SYNC(ARG(disableDecoration))
220 void BufferViewConfig::setAllowedBufferTypes(int bufferTypes)
222 if (_allowedBufferTypes == bufferTypes)
225 _allowedBufferTypes = bufferTypes;
226 SYNC(ARG(bufferTypes))
227 emit configChanged();
230 void BufferViewConfig::setMinimumActivity(int activity)
232 if (_minimumActivity == activity)
235 _minimumActivity = activity;
237 emit configChanged();
240 void BufferViewConfig::setHideInactiveBuffers(bool hideInactiveBuffers)
242 if (_hideInactiveBuffers == hideInactiveBuffers)
245 _hideInactiveBuffers = hideInactiveBuffers;
246 SYNC(ARG(hideInactiveBuffers))
247 emit configChanged();
250 void BufferViewConfig::setHideInactiveNetworks(bool hideInactiveNetworks)
252 if (_hideInactiveNetworks == hideInactiveNetworks)
255 _hideInactiveNetworks = hideInactiveNetworks;
256 SYNC(ARG(hideInactiveNetworks))
257 emit configChanged();
260 void BufferViewConfig::setShowSearch(bool showSearch)
262 if (_showSearch == showSearch) {
266 _showSearch = showSearch;
267 SYNC(ARG(showSearch))
268 emit configChanged();
271 void BufferViewConfig::setBufferList(const QList<BufferId>& buffers)
274 emit configChanged();
277 void BufferViewConfig::addBuffer(const BufferId& bufferId, int pos)
279 if (_buffers.contains(bufferId))
284 if (pos > _buffers.count())
285 pos = _buffers.count();
287 if (_removedBuffers.contains(bufferId))
288 _removedBuffers.remove(bufferId);
290 if (_temporarilyRemovedBuffers.contains(bufferId))
291 _temporarilyRemovedBuffers.remove(bufferId);
293 _buffers.insert(pos, bufferId);
294 SYNC(ARG(bufferId), ARG(pos))
295 emit bufferAdded(bufferId, pos);
296 emit configChanged();
299 void BufferViewConfig::moveBuffer(const BufferId& bufferId, int pos)
301 if (!_buffers.contains(bufferId))
306 if (pos >= _buffers.count())
307 pos = _buffers.count() - 1;
309 _buffers.move(_buffers.indexOf(bufferId), pos);
310 SYNC(ARG(bufferId), ARG(pos))
311 emit bufferMoved(bufferId, pos);
312 emit configChanged();
315 void BufferViewConfig::removeBuffer(const BufferId& bufferId)
317 if (_buffers.contains(bufferId))
318 _buffers.removeAt(_buffers.indexOf(bufferId));
320 if (_removedBuffers.contains(bufferId))
321 _removedBuffers.remove(bufferId);
323 _temporarilyRemovedBuffers << bufferId;
325 emit bufferRemoved(bufferId);
326 emit configChanged();
329 void BufferViewConfig::removeBufferPermanently(const BufferId& bufferId)
331 if (_buffers.contains(bufferId))
332 _buffers.removeAt(_buffers.indexOf(bufferId));
334 if (_temporarilyRemovedBuffers.contains(bufferId))
335 _temporarilyRemovedBuffers.remove(bufferId);
337 _removedBuffers << bufferId;
340 emit bufferPermanentlyRemoved(bufferId);
341 emit configChanged();
344 void BufferViewConfig::requestSetBufferViewName(const QString& bufferViewName)
346 REQUEST(ARG(bufferViewName))
349 void BufferViewConfig::requestAddBuffer(const BufferId& bufferId, int pos)
351 REQUEST(ARG(bufferId), ARG(pos))
354 void BufferViewConfig::requestMoveBuffer(const BufferId& bufferId, int pos)
356 REQUEST(ARG(bufferId), ARG(pos))
359 void BufferViewConfig::requestRemoveBuffer(const BufferId& bufferId)
361 REQUEST(ARG(bufferId))
364 void BufferViewConfig::requestRemoveBufferPermanently(const BufferId& bufferId)
366 REQUEST(ARG(bufferId))