1 /***************************************************************************
2 * Copyright (C) 2005-09 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 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
21 #include "bufferviewconfig.h"
23 #include "bufferinfo.h"
25 BufferViewConfig::BufferViewConfig(int bufferViewId, QObject *parent)
26 : SyncableObject(parent),
27 _bufferViewId(bufferViewId),
28 _addNewBuffersAutomatically(true),
29 _sortAlphabetically(true),
30 _hideInactiveBuffers(false),
31 _disableDecoration(false),
32 _allowedBufferTypes(BufferInfo::StatusBuffer | BufferInfo::ChannelBuffer | BufferInfo::QueryBuffer | BufferInfo::GroupBuffer),
35 setObjectName(QString::number(bufferViewId));
38 BufferViewConfig::BufferViewConfig(int bufferViewId, const QVariantMap &properties, QObject *parent)
39 : SyncableObject(parent),
40 _bufferViewId(bufferViewId)
42 fromVariantMap(properties);
43 setObjectName(QString::number(bufferViewId));
46 void BufferViewConfig::setBufferViewName(const QString &bufferViewName) {
47 if(_bufferViewName == bufferViewName)
50 _bufferViewName = bufferViewName;
51 emit bufferViewNameSet(bufferViewName);
54 void BufferViewConfig::setNetworkId(const NetworkId &networkId) {
55 if(_networkId == networkId)
58 _networkId = networkId;
59 emit networkIdSet(networkId);
62 void BufferViewConfig::setAddNewBuffersAutomatically(bool addNewBuffersAutomatically) {
63 if(_addNewBuffersAutomatically == addNewBuffersAutomatically)
66 _addNewBuffersAutomatically = addNewBuffersAutomatically;
67 emit addNewBuffersAutomaticallySet(addNewBuffersAutomatically);
70 void BufferViewConfig::setSortAlphabetically(bool sortAlphabetically) {
71 if(_sortAlphabetically == sortAlphabetically)
74 _sortAlphabetically = sortAlphabetically;
75 emit sortAlphabeticallySet(sortAlphabetically);
78 void BufferViewConfig::setDisableDecoration(bool disableDecoration) {
79 if(_disableDecoration == disableDecoration)
82 _disableDecoration = disableDecoration;
83 emit disableDecorationSet(disableDecoration);
86 void BufferViewConfig::setAllowedBufferTypes(int bufferTypes) {
87 if(_allowedBufferTypes == bufferTypes)
90 _allowedBufferTypes = bufferTypes;
91 emit allowedBufferTypesSet(bufferTypes);
94 void BufferViewConfig::setMinimumActivity(int activity) {
95 if(_minimumActivity == activity)
98 _minimumActivity = activity;
99 emit minimumActivitySet(activity);
102 void BufferViewConfig::setHideInactiveBuffers(bool hideInactiveBuffers) {
103 if(_hideInactiveBuffers == hideInactiveBuffers)
106 _hideInactiveBuffers = hideInactiveBuffers;
107 emit hideInactiveBuffersSet(hideInactiveBuffers);
110 QVariantList BufferViewConfig::initBufferList() const {
111 QVariantList buffers;
113 foreach(BufferId bufferId, _buffers) {
114 buffers << qVariantFromValue(bufferId);
120 void BufferViewConfig::initSetBufferList(const QVariantList &buffers) {
123 foreach(QVariant buffer, buffers) {
124 _buffers << buffer.value<BufferId>();
127 // normaly initSeters don't need an emit. this one is to track changes in the settingspage
128 emit bufferListSet();
131 void BufferViewConfig::initSetBufferList(const QList<BufferId> &buffers) {
134 foreach(BufferId bufferId, buffers) {
135 _buffers << bufferId;
138 // normaly initSeters don't need an emit. this one is to track changes in the settingspage
139 emit bufferListSet();
142 QVariantList BufferViewConfig::initRemovedBuffers() const {
143 QVariantList removedBuffers;
145 foreach(BufferId bufferId, _removedBuffers) {
146 removedBuffers << qVariantFromValue(bufferId);
149 return removedBuffers;
152 void BufferViewConfig::initSetRemovedBuffers(const QVariantList &buffers) {
153 _removedBuffers.clear();
155 foreach(QVariant buffer, buffers) {
156 _removedBuffers << buffer.value<BufferId>();
160 QVariantList BufferViewConfig::initTemporarilyRemovedBuffers() const {
161 QVariantList temporarilyRemovedBuffers;
163 foreach(BufferId bufferId, _temporarilyRemovedBuffers) {
164 temporarilyRemovedBuffers << qVariantFromValue(bufferId);
167 return temporarilyRemovedBuffers;
170 void BufferViewConfig::initSetTemporarilyRemovedBuffers(const QVariantList &buffers) {
171 _temporarilyRemovedBuffers.clear();
173 foreach(QVariant buffer, buffers) {
174 _temporarilyRemovedBuffers << buffer.value<BufferId>();
178 void BufferViewConfig::addBuffer(const BufferId &bufferId, int pos) {
179 if(_buffers.contains(bufferId))
184 if(pos > _buffers.count())
185 pos = _buffers.count();
187 if(_removedBuffers.contains(bufferId))
188 _removedBuffers.remove(bufferId);
190 if(_temporarilyRemovedBuffers.contains(bufferId))
191 _temporarilyRemovedBuffers.remove(bufferId);
193 _buffers.insert(pos, bufferId);
194 emit bufferAdded(bufferId, pos);
197 void BufferViewConfig::moveBuffer(const BufferId &bufferId, int pos) {
198 if(!_buffers.contains(bufferId))
203 if(pos >= _buffers.count())
204 pos = _buffers.count() - 1;
206 _buffers.move(_buffers.indexOf(bufferId), pos);
207 emit bufferMoved(bufferId, pos);
210 void BufferViewConfig::removeBuffer(const BufferId &bufferId) {
211 if(_buffers.contains(bufferId))
212 _buffers.removeAt(_buffers.indexOf(bufferId));
214 if(_removedBuffers.contains(bufferId))
215 _removedBuffers.remove(bufferId);
217 _temporarilyRemovedBuffers << bufferId;
219 emit bufferRemoved(bufferId);
222 void BufferViewConfig::removeBufferPermanently(const BufferId &bufferId) {
223 if(_buffers.contains(bufferId))
224 _buffers.removeAt(_buffers.indexOf(bufferId));
226 if(_temporarilyRemovedBuffers.contains(bufferId))
227 _temporarilyRemovedBuffers.remove(bufferId);
229 _removedBuffers << bufferId;
231 emit bufferPermanentlyRemoved(bufferId);