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 #include "bufferinfo.h"
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 _hideInactiveNetworks(false),
33 _disableDecoration(false),
34 _allowedBufferTypes(BufferInfo::StatusBuffer | BufferInfo::ChannelBuffer | BufferInfo::QueryBuffer | BufferInfo::GroupBuffer),
38 setObjectName(QString::number(bufferViewId));
42 BufferViewConfig::BufferViewConfig(int bufferViewId, const QVariantMap &properties, QObject *parent)
43 : SyncableObject(parent),
44 _bufferViewId(bufferViewId)
46 fromVariantMap(properties);
47 setObjectName(QString::number(bufferViewId));
51 void BufferViewConfig::setBufferViewName(const QString &bufferViewName)
53 if (_bufferViewName == bufferViewName)
56 _bufferViewName = bufferViewName;
57 SYNC(ARG(bufferViewName))
58 emit bufferViewNameSet(bufferViewName);
62 void BufferViewConfig::setNetworkId(const NetworkId &networkId)
64 if (_networkId == networkId)
67 _networkId = networkId;
69 emit networkIdSet(networkId);
74 void BufferViewConfig::setAddNewBuffersAutomatically(bool addNewBuffersAutomatically)
76 if (_addNewBuffersAutomatically == addNewBuffersAutomatically)
79 _addNewBuffersAutomatically = addNewBuffersAutomatically;
80 SYNC(ARG(addNewBuffersAutomatically))
85 void BufferViewConfig::setSortAlphabetically(bool sortAlphabetically)
87 if (_sortAlphabetically == sortAlphabetically)
90 _sortAlphabetically = sortAlphabetically;
91 SYNC(ARG(sortAlphabetically))
96 void BufferViewConfig::setDisableDecoration(bool disableDecoration)
98 if (_disableDecoration == disableDecoration)
101 _disableDecoration = disableDecoration;
102 SYNC(ARG(disableDecoration))
106 void BufferViewConfig::setAllowedBufferTypes(int bufferTypes)
108 if (_allowedBufferTypes == bufferTypes)
111 _allowedBufferTypes = bufferTypes;
112 SYNC(ARG(bufferTypes))
113 emit configChanged();
117 void BufferViewConfig::setMinimumActivity(int activity)
119 if (_minimumActivity == activity)
122 _minimumActivity = activity;
124 emit configChanged();
128 void BufferViewConfig::setHideInactiveBuffers(bool hideInactiveBuffers)
130 if (_hideInactiveBuffers == hideInactiveBuffers)
133 _hideInactiveBuffers = hideInactiveBuffers;
134 SYNC(ARG(hideInactiveBuffers))
135 emit configChanged();
138 void BufferViewConfig::setHideInactiveNetworks(bool hideInactiveNetworks)
140 if (_hideInactiveNetworks == hideInactiveNetworks)
143 _hideInactiveNetworks = hideInactiveNetworks;
144 SYNC(ARG(hideInactiveNetworks))
145 emit configChanged();
148 void BufferViewConfig::setShowSearch(bool showSearch) {
149 if (_showSearch == showSearch) {
153 _showSearch = showSearch;
154 SYNC(ARG(showSearch))
155 emit configChanged();
159 QVariantList BufferViewConfig::initBufferList() const
161 QVariantList buffers;
163 foreach(BufferId bufferId, _buffers) {
164 buffers << qVariantFromValue(bufferId);
171 void BufferViewConfig::initSetBufferList(const QVariantList &buffers)
175 foreach(QVariant buffer, buffers) {
176 _buffers << buffer.value<BufferId>();
179 emit configChanged(); // used to track changes in the settingspage
183 void BufferViewConfig::initSetBufferList(const QList<BufferId> &buffers)
187 foreach(BufferId bufferId, buffers) {
188 _buffers << bufferId;
191 emit configChanged(); // used to track changes in the settingspage
195 QVariantList BufferViewConfig::initRemovedBuffers() const
197 QVariantList removedBuffers;
199 foreach(BufferId bufferId, _removedBuffers) {
200 removedBuffers << qVariantFromValue(bufferId);
203 return removedBuffers;
207 void BufferViewConfig::initSetRemovedBuffers(const QVariantList &buffers)
209 _removedBuffers.clear();
211 foreach(QVariant buffer, buffers) {
212 _removedBuffers << buffer.value<BufferId>();
217 QVariantList BufferViewConfig::initTemporarilyRemovedBuffers() const
219 QVariantList temporarilyRemovedBuffers;
221 foreach(BufferId bufferId, _temporarilyRemovedBuffers) {
222 temporarilyRemovedBuffers << qVariantFromValue(bufferId);
225 return temporarilyRemovedBuffers;
229 void BufferViewConfig::initSetTemporarilyRemovedBuffers(const QVariantList &buffers)
231 _temporarilyRemovedBuffers.clear();
233 foreach(QVariant buffer, buffers) {
234 _temporarilyRemovedBuffers << buffer.value<BufferId>();
239 void BufferViewConfig::addBuffer(const BufferId &bufferId, int pos)
241 if (_buffers.contains(bufferId))
246 if (pos > _buffers.count())
247 pos = _buffers.count();
249 if (_removedBuffers.contains(bufferId))
250 _removedBuffers.remove(bufferId);
252 if (_temporarilyRemovedBuffers.contains(bufferId))
253 _temporarilyRemovedBuffers.remove(bufferId);
255 _buffers.insert(pos, bufferId);
256 SYNC(ARG(bufferId), ARG(pos))
257 emit bufferAdded(bufferId, pos);
258 emit configChanged();
262 void BufferViewConfig::moveBuffer(const BufferId &bufferId, int pos)
264 if (!_buffers.contains(bufferId))
269 if (pos >= _buffers.count())
270 pos = _buffers.count() - 1;
272 _buffers.move(_buffers.indexOf(bufferId), pos);
273 SYNC(ARG(bufferId), ARG(pos))
274 emit bufferMoved(bufferId, pos);
275 emit configChanged();
279 void BufferViewConfig::removeBuffer(const BufferId &bufferId)
281 if (_buffers.contains(bufferId))
282 _buffers.removeAt(_buffers.indexOf(bufferId));
284 if (_removedBuffers.contains(bufferId))
285 _removedBuffers.remove(bufferId);
287 _temporarilyRemovedBuffers << bufferId;
289 emit bufferRemoved(bufferId);
290 emit configChanged();
294 void BufferViewConfig::removeBufferPermanently(const BufferId &bufferId)
296 if (_buffers.contains(bufferId))
297 _buffers.removeAt(_buffers.indexOf(bufferId));
299 if (_temporarilyRemovedBuffers.contains(bufferId))
300 _temporarilyRemovedBuffers.remove(bufferId);
302 _removedBuffers << bufferId;
305 emit bufferPermanentlyRemoved(bufferId);
306 emit configChanged();