1 /***************************************************************************
2 * Copyright (C) 2005-2018 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 INIT_SYNCABLE_OBJECT(BufferViewConfig)
24 BufferViewConfig::BufferViewConfig(int bufferViewId, QObject *parent)
25 : SyncableObject(parent),
26 _bufferViewId(bufferViewId)
28 setObjectName(QString::number(bufferViewId));
32 BufferViewConfig::BufferViewConfig(int bufferViewId, const QVariantMap &properties, QObject *parent)
33 : SyncableObject(parent),
34 _bufferViewId(bufferViewId)
36 fromVariantMap(properties);
37 setObjectName(QString::number(bufferViewId));
41 void BufferViewConfig::setBufferViewName(const QString &bufferViewName)
43 if (_bufferViewName == bufferViewName)
46 _bufferViewName = bufferViewName;
47 SYNC(ARG(bufferViewName))
48 emit bufferViewNameSet(bufferViewName);
52 void BufferViewConfig::setNetworkId(const NetworkId &networkId)
54 if (_networkId == networkId)
57 _networkId = networkId;
59 emit networkIdSet(networkId);
64 void BufferViewConfig::setAddNewBuffersAutomatically(bool addNewBuffersAutomatically)
66 if (_addNewBuffersAutomatically == addNewBuffersAutomatically)
69 _addNewBuffersAutomatically = addNewBuffersAutomatically;
70 SYNC(ARG(addNewBuffersAutomatically))
75 void BufferViewConfig::setSortAlphabetically(bool sortAlphabetically)
77 if (_sortAlphabetically == sortAlphabetically)
80 _sortAlphabetically = sortAlphabetically;
81 SYNC(ARG(sortAlphabetically))
86 void BufferViewConfig::setDisableDecoration(bool disableDecoration)
88 if (_disableDecoration == disableDecoration)
91 _disableDecoration = disableDecoration;
92 SYNC(ARG(disableDecoration))
96 void BufferViewConfig::setAllowedBufferTypes(int bufferTypes)
98 if (_allowedBufferTypes == bufferTypes)
101 _allowedBufferTypes = bufferTypes;
102 SYNC(ARG(bufferTypes))
103 emit configChanged();
107 void BufferViewConfig::setMinimumActivity(int activity)
109 if (_minimumActivity == activity)
112 _minimumActivity = activity;
114 emit configChanged();
118 void BufferViewConfig::setHideInactiveBuffers(bool hideInactiveBuffers)
120 if (_hideInactiveBuffers == hideInactiveBuffers)
123 _hideInactiveBuffers = hideInactiveBuffers;
124 SYNC(ARG(hideInactiveBuffers))
125 emit configChanged();
128 void BufferViewConfig::setHideInactiveNetworks(bool hideInactiveNetworks)
130 if (_hideInactiveNetworks == hideInactiveNetworks)
133 _hideInactiveNetworks = hideInactiveNetworks;
134 SYNC(ARG(hideInactiveNetworks))
135 emit configChanged();
138 void BufferViewConfig::setShowSearch(bool showSearch) {
139 if (_showSearch == showSearch) {
143 _showSearch = showSearch;
144 SYNC(ARG(showSearch))
145 emit configChanged();
149 QVariantList BufferViewConfig::initBufferList() const
151 QVariantList buffers;
153 foreach(BufferId bufferId, _buffers) {
154 buffers << qVariantFromValue(bufferId);
161 void BufferViewConfig::initSetBufferList(const QVariantList &buffers)
165 foreach(QVariant buffer, buffers) {
166 _buffers << buffer.value<BufferId>();
169 emit configChanged(); // used to track changes in the settingspage
173 void BufferViewConfig::initSetBufferList(const QList<BufferId> &buffers)
177 foreach(BufferId bufferId, buffers) {
178 _buffers << bufferId;
181 emit configChanged(); // used to track changes in the settingspage
185 QVariantList BufferViewConfig::initRemovedBuffers() const
187 QVariantList removedBuffers;
189 foreach(BufferId bufferId, _removedBuffers) {
190 removedBuffers << qVariantFromValue(bufferId);
193 return removedBuffers;
197 void BufferViewConfig::initSetRemovedBuffers(const QVariantList &buffers)
199 _removedBuffers.clear();
201 foreach(QVariant buffer, buffers) {
202 _removedBuffers << buffer.value<BufferId>();
207 QVariantList BufferViewConfig::initTemporarilyRemovedBuffers() const
209 QVariantList temporarilyRemovedBuffers;
211 foreach(BufferId bufferId, _temporarilyRemovedBuffers) {
212 temporarilyRemovedBuffers << qVariantFromValue(bufferId);
215 return temporarilyRemovedBuffers;
219 void BufferViewConfig::initSetTemporarilyRemovedBuffers(const QVariantList &buffers)
221 _temporarilyRemovedBuffers.clear();
223 foreach(QVariant buffer, buffers) {
224 _temporarilyRemovedBuffers << buffer.value<BufferId>();
229 void BufferViewConfig::addBuffer(const BufferId &bufferId, int pos)
231 if (_buffers.contains(bufferId))
236 if (pos > _buffers.count())
237 pos = _buffers.count();
239 if (_removedBuffers.contains(bufferId))
240 _removedBuffers.remove(bufferId);
242 if (_temporarilyRemovedBuffers.contains(bufferId))
243 _temporarilyRemovedBuffers.remove(bufferId);
245 _buffers.insert(pos, bufferId);
246 SYNC(ARG(bufferId), ARG(pos))
247 emit bufferAdded(bufferId, pos);
248 emit configChanged();
252 void BufferViewConfig::moveBuffer(const BufferId &bufferId, int pos)
254 if (!_buffers.contains(bufferId))
259 if (pos >= _buffers.count())
260 pos = _buffers.count() - 1;
262 _buffers.move(_buffers.indexOf(bufferId), pos);
263 SYNC(ARG(bufferId), ARG(pos))
264 emit bufferMoved(bufferId, pos);
265 emit configChanged();
269 void BufferViewConfig::removeBuffer(const BufferId &bufferId)
271 if (_buffers.contains(bufferId))
272 _buffers.removeAt(_buffers.indexOf(bufferId));
274 if (_removedBuffers.contains(bufferId))
275 _removedBuffers.remove(bufferId);
277 _temporarilyRemovedBuffers << bufferId;
279 emit bufferRemoved(bufferId);
280 emit configChanged();
284 void BufferViewConfig::removeBufferPermanently(const BufferId &bufferId)
286 if (_buffers.contains(bufferId))
287 _buffers.removeAt(_buffers.indexOf(bufferId));
289 if (_temporarilyRemovedBuffers.contains(bufferId))
290 _temporarilyRemovedBuffers.remove(bufferId);
292 _removedBuffers << bufferId;
295 emit bufferPermanentlyRemoved(bufferId);
296 emit configChanged();