1 /***************************************************************************
2 * Copyright (C) 2005-2013 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 _disableDecoration(false),
33 _allowedBufferTypes(BufferInfo::StatusBuffer | BufferInfo::ChannelBuffer | BufferInfo::QueryBuffer | BufferInfo::GroupBuffer),
36 setObjectName(QString::number(bufferViewId));
40 BufferViewConfig::BufferViewConfig(int bufferViewId, const QVariantMap &properties, QObject *parent)
41 : SyncableObject(parent),
42 _bufferViewId(bufferViewId)
44 fromVariantMap(properties);
45 setObjectName(QString::number(bufferViewId));
49 void BufferViewConfig::setBufferViewName(const QString &bufferViewName)
51 if (_bufferViewName == bufferViewName)
54 _bufferViewName = bufferViewName;
55 SYNC(ARG(bufferViewName))
56 emit bufferViewNameSet(bufferViewName);
60 void BufferViewConfig::setNetworkId(const NetworkId &networkId)
62 if (_networkId == networkId)
65 _networkId = networkId;
67 emit networkIdSet(networkId);
72 void BufferViewConfig::setAddNewBuffersAutomatically(bool addNewBuffersAutomatically)
74 if (_addNewBuffersAutomatically == addNewBuffersAutomatically)
77 _addNewBuffersAutomatically = addNewBuffersAutomatically;
78 SYNC(ARG(addNewBuffersAutomatically))
83 void BufferViewConfig::setSortAlphabetically(bool sortAlphabetically)
85 if (_sortAlphabetically == sortAlphabetically)
88 _sortAlphabetically = sortAlphabetically;
89 SYNC(ARG(sortAlphabetically))
94 void BufferViewConfig::setDisableDecoration(bool disableDecoration)
96 if (_disableDecoration == disableDecoration)
99 _disableDecoration = disableDecoration;
100 SYNC(ARG(disableDecoration))
104 void BufferViewConfig::setAllowedBufferTypes(int bufferTypes)
106 if (_allowedBufferTypes == bufferTypes)
109 _allowedBufferTypes = bufferTypes;
110 SYNC(ARG(bufferTypes))
111 emit configChanged();
115 void BufferViewConfig::setMinimumActivity(int activity)
117 if (_minimumActivity == activity)
120 _minimumActivity = activity;
122 emit configChanged();
126 void BufferViewConfig::setHideInactiveBuffers(bool hideInactiveBuffers)
128 if (_hideInactiveBuffers == hideInactiveBuffers)
131 _hideInactiveBuffers = hideInactiveBuffers;
132 SYNC(ARG(hideInactiveBuffers))
133 emit configChanged();
137 QVariantList BufferViewConfig::initBufferList() const
139 QVariantList buffers;
141 foreach(BufferId bufferId, _buffers) {
142 buffers << qVariantFromValue(bufferId);
149 void BufferViewConfig::initSetBufferList(const QVariantList &buffers)
153 foreach(QVariant buffer, buffers) {
154 _buffers << buffer.value<BufferId>();
157 emit configChanged(); // used to track changes in the settingspage
161 void BufferViewConfig::initSetBufferList(const QList<BufferId> &buffers)
165 foreach(BufferId bufferId, buffers) {
166 _buffers << bufferId;
169 emit configChanged(); // used to track changes in the settingspage
173 QVariantList BufferViewConfig::initRemovedBuffers() const
175 QVariantList removedBuffers;
177 foreach(BufferId bufferId, _removedBuffers) {
178 removedBuffers << qVariantFromValue(bufferId);
181 return removedBuffers;
185 void BufferViewConfig::initSetRemovedBuffers(const QVariantList &buffers)
187 _removedBuffers.clear();
189 foreach(QVariant buffer, buffers) {
190 _removedBuffers << buffer.value<BufferId>();
195 QVariantList BufferViewConfig::initTemporarilyRemovedBuffers() const
197 QVariantList temporarilyRemovedBuffers;
199 foreach(BufferId bufferId, _temporarilyRemovedBuffers) {
200 temporarilyRemovedBuffers << qVariantFromValue(bufferId);
203 return temporarilyRemovedBuffers;
207 void BufferViewConfig::initSetTemporarilyRemovedBuffers(const QVariantList &buffers)
209 _temporarilyRemovedBuffers.clear();
211 foreach(QVariant buffer, buffers) {
212 _temporarilyRemovedBuffers << buffer.value<BufferId>();
217 void BufferViewConfig::addBuffer(const BufferId &bufferId, int pos)
219 if (_buffers.contains(bufferId))
224 if (pos > _buffers.count())
225 pos = _buffers.count();
227 if (_removedBuffers.contains(bufferId))
228 _removedBuffers.remove(bufferId);
230 if (_temporarilyRemovedBuffers.contains(bufferId))
231 _temporarilyRemovedBuffers.remove(bufferId);
233 _buffers.insert(pos, bufferId);
234 SYNC(ARG(bufferId), ARG(pos))
235 emit bufferAdded(bufferId, pos);
236 emit configChanged();
240 void BufferViewConfig::moveBuffer(const BufferId &bufferId, int pos)
242 if (!_buffers.contains(bufferId))
247 if (pos >= _buffers.count())
248 pos = _buffers.count() - 1;
250 _buffers.move(_buffers.indexOf(bufferId), pos);
251 SYNC(ARG(bufferId), ARG(pos))
252 emit bufferMoved(bufferId, pos);
253 emit configChanged();
257 void BufferViewConfig::removeBuffer(const BufferId &bufferId)
259 if (_buffers.contains(bufferId))
260 _buffers.removeAt(_buffers.indexOf(bufferId));
262 if (_removedBuffers.contains(bufferId))
263 _removedBuffers.remove(bufferId);
265 _temporarilyRemovedBuffers << bufferId;
267 emit bufferRemoved(bufferId);
268 emit configChanged();
272 void BufferViewConfig::removeBufferPermanently(const BufferId &bufferId)
274 if (_buffers.contains(bufferId))
275 _buffers.removeAt(_buffers.indexOf(bufferId));
277 if (_temporarilyRemovedBuffers.contains(bufferId))
278 _temporarilyRemovedBuffers.remove(bufferId);
280 _removedBuffers << bufferId;
283 emit bufferPermanentlyRemoved(bufferId);
284 emit configChanged();