1 /***************************************************************************
2 * Copyright (C) 2005-2014 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),
37 setObjectName(QString::number(bufferViewId));
41 BufferViewConfig::BufferViewConfig(int bufferViewId, const QVariantMap &properties, QObject *parent)
42 : SyncableObject(parent),
43 _bufferViewId(bufferViewId)
45 fromVariantMap(properties);
46 setObjectName(QString::number(bufferViewId));
50 void BufferViewConfig::setBufferViewName(const QString &bufferViewName)
52 if (_bufferViewName == bufferViewName)
55 _bufferViewName = bufferViewName;
56 SYNC(ARG(bufferViewName))
57 emit bufferViewNameSet(bufferViewName);
61 void BufferViewConfig::setNetworkId(const NetworkId &networkId)
63 if (_networkId == networkId)
66 _networkId = networkId;
68 emit networkIdSet(networkId);
73 void BufferViewConfig::setAddNewBuffersAutomatically(bool addNewBuffersAutomatically)
75 if (_addNewBuffersAutomatically == addNewBuffersAutomatically)
78 _addNewBuffersAutomatically = addNewBuffersAutomatically;
79 SYNC(ARG(addNewBuffersAutomatically))
84 void BufferViewConfig::setSortAlphabetically(bool sortAlphabetically)
86 if (_sortAlphabetically == sortAlphabetically)
89 _sortAlphabetically = sortAlphabetically;
90 SYNC(ARG(sortAlphabetically))
95 void BufferViewConfig::setDisableDecoration(bool disableDecoration)
97 if (_disableDecoration == disableDecoration)
100 _disableDecoration = disableDecoration;
101 SYNC(ARG(disableDecoration))
105 void BufferViewConfig::setAllowedBufferTypes(int bufferTypes)
107 if (_allowedBufferTypes == bufferTypes)
110 _allowedBufferTypes = bufferTypes;
111 SYNC(ARG(bufferTypes))
112 emit configChanged();
116 void BufferViewConfig::setMinimumActivity(int activity)
118 if (_minimumActivity == activity)
121 _minimumActivity = activity;
123 emit configChanged();
127 void BufferViewConfig::setHideInactiveBuffers(bool hideInactiveBuffers)
129 if (_hideInactiveBuffers == hideInactiveBuffers)
132 _hideInactiveBuffers = hideInactiveBuffers;
133 SYNC(ARG(hideInactiveBuffers))
134 emit configChanged();
137 void BufferViewConfig::setHideInactiveNetworks(bool hideInactiveNetworks)
139 if (_hideInactiveNetworks == hideInactiveNetworks)
142 _hideInactiveNetworks = hideInactiveNetworks;
143 SYNC(ARG(hideInactiveNetworks))
144 emit configChanged();
148 QVariantList BufferViewConfig::initBufferList() const
150 QVariantList buffers;
152 foreach(BufferId bufferId, _buffers) {
153 buffers << qVariantFromValue(bufferId);
160 void BufferViewConfig::initSetBufferList(const QVariantList &buffers)
164 foreach(QVariant buffer, buffers) {
165 _buffers << buffer.value<BufferId>();
168 emit configChanged(); // used to track changes in the settingspage
172 void BufferViewConfig::initSetBufferList(const QList<BufferId> &buffers)
176 foreach(BufferId bufferId, buffers) {
177 _buffers << bufferId;
180 emit configChanged(); // used to track changes in the settingspage
184 QVariantList BufferViewConfig::initRemovedBuffers() const
186 QVariantList removedBuffers;
188 foreach(BufferId bufferId, _removedBuffers) {
189 removedBuffers << qVariantFromValue(bufferId);
192 return removedBuffers;
196 void BufferViewConfig::initSetRemovedBuffers(const QVariantList &buffers)
198 _removedBuffers.clear();
200 foreach(QVariant buffer, buffers) {
201 _removedBuffers << buffer.value<BufferId>();
206 QVariantList BufferViewConfig::initTemporarilyRemovedBuffers() const
208 QVariantList temporarilyRemovedBuffers;
210 foreach(BufferId bufferId, _temporarilyRemovedBuffers) {
211 temporarilyRemovedBuffers << qVariantFromValue(bufferId);
214 return temporarilyRemovedBuffers;
218 void BufferViewConfig::initSetTemporarilyRemovedBuffers(const QVariantList &buffers)
220 _temporarilyRemovedBuffers.clear();
222 foreach(QVariant buffer, buffers) {
223 _temporarilyRemovedBuffers << buffer.value<BufferId>();
228 void BufferViewConfig::addBuffer(const BufferId &bufferId, int pos)
230 if (_buffers.contains(bufferId))
235 if (pos > _buffers.count())
236 pos = _buffers.count();
238 if (_removedBuffers.contains(bufferId))
239 _removedBuffers.remove(bufferId);
241 if (_temporarilyRemovedBuffers.contains(bufferId))
242 _temporarilyRemovedBuffers.remove(bufferId);
244 _buffers.insert(pos, bufferId);
245 SYNC(ARG(bufferId), ARG(pos))
246 emit bufferAdded(bufferId, pos);
247 emit configChanged();
251 void BufferViewConfig::moveBuffer(const BufferId &bufferId, int pos)
253 if (!_buffers.contains(bufferId))
258 if (pos >= _buffers.count())
259 pos = _buffers.count() - 1;
261 _buffers.move(_buffers.indexOf(bufferId), pos);
262 SYNC(ARG(bufferId), ARG(pos))
263 emit bufferMoved(bufferId, pos);
264 emit configChanged();
268 void BufferViewConfig::removeBuffer(const BufferId &bufferId)
270 if (_buffers.contains(bufferId))
271 _buffers.removeAt(_buffers.indexOf(bufferId));
273 if (_removedBuffers.contains(bufferId))
274 _removedBuffers.remove(bufferId);
276 _temporarilyRemovedBuffers << bufferId;
278 emit bufferRemoved(bufferId);
279 emit configChanged();
283 void BufferViewConfig::removeBufferPermanently(const BufferId &bufferId)
285 if (_buffers.contains(bufferId))
286 _buffers.removeAt(_buffers.indexOf(bufferId));
288 if (_temporarilyRemovedBuffers.contains(bufferId))
289 _temporarilyRemovedBuffers.remove(bufferId);
291 _removedBuffers << bufferId;
294 emit bufferPermanentlyRemoved(bufferId);
295 emit configChanged();