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 BufferViewConfig::BufferViewConfig(int bufferViewId, QObject *parent)
24 : SyncableObject(parent),
25 _bufferViewId(bufferViewId)
27 setObjectName(QString::number(bufferViewId));
31 BufferViewConfig::BufferViewConfig(int bufferViewId, const QVariantMap &properties, QObject *parent)
32 : SyncableObject(parent),
33 _bufferViewId(bufferViewId)
35 fromVariantMap(properties);
36 setObjectName(QString::number(bufferViewId));
40 void BufferViewConfig::setBufferViewName(const QString &bufferViewName)
42 if (_bufferViewName == bufferViewName)
45 _bufferViewName = bufferViewName;
46 SYNC(ARG(bufferViewName))
47 emit bufferViewNameSet(bufferViewName);
51 void BufferViewConfig::setNetworkId(const NetworkId &networkId)
53 if (_networkId == networkId)
56 _networkId = networkId;
58 emit networkIdSet(networkId);
63 void BufferViewConfig::setAddNewBuffersAutomatically(bool addNewBuffersAutomatically)
65 if (_addNewBuffersAutomatically == addNewBuffersAutomatically)
68 _addNewBuffersAutomatically = addNewBuffersAutomatically;
69 SYNC(ARG(addNewBuffersAutomatically))
74 void BufferViewConfig::setSortAlphabetically(bool sortAlphabetically)
76 if (_sortAlphabetically == sortAlphabetically)
79 _sortAlphabetically = sortAlphabetically;
80 SYNC(ARG(sortAlphabetically))
85 void BufferViewConfig::setDisableDecoration(bool disableDecoration)
87 if (_disableDecoration == disableDecoration)
90 _disableDecoration = disableDecoration;
91 SYNC(ARG(disableDecoration))
95 void BufferViewConfig::setAllowedBufferTypes(int bufferTypes)
97 if (_allowedBufferTypes == bufferTypes)
100 _allowedBufferTypes = bufferTypes;
101 SYNC(ARG(bufferTypes))
102 emit configChanged();
106 void BufferViewConfig::setMinimumActivity(int activity)
108 if (_minimumActivity == activity)
111 _minimumActivity = activity;
113 emit configChanged();
117 void BufferViewConfig::setHideInactiveBuffers(bool hideInactiveBuffers)
119 if (_hideInactiveBuffers == hideInactiveBuffers)
122 _hideInactiveBuffers = hideInactiveBuffers;
123 SYNC(ARG(hideInactiveBuffers))
124 emit configChanged();
127 void BufferViewConfig::setHideInactiveNetworks(bool hideInactiveNetworks)
129 if (_hideInactiveNetworks == hideInactiveNetworks)
132 _hideInactiveNetworks = hideInactiveNetworks;
133 SYNC(ARG(hideInactiveNetworks))
134 emit configChanged();
137 void BufferViewConfig::setShowSearch(bool showSearch) {
138 if (_showSearch == showSearch) {
142 _showSearch = showSearch;
143 SYNC(ARG(showSearch))
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();