1 /***************************************************************************
2 * Copyright (C) 2005-08 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),
41 _disableDecoration(false) // FIXME remove as soon as we have bumped the protocol version to v8
43 fromVariantMap(properties);
44 setObjectName(QString::number(bufferViewId));
47 void BufferViewConfig::setBufferViewName(const QString &bufferViewName) {
48 if(_bufferViewName == bufferViewName)
51 _bufferViewName = bufferViewName;
52 emit bufferViewNameSet(bufferViewName);
55 void BufferViewConfig::setNetworkId(const NetworkId &networkId) {
56 if(_networkId == networkId)
59 _networkId = networkId;
60 emit networkIdSet(networkId);
63 void BufferViewConfig::setAddNewBuffersAutomatically(bool addNewBuffersAutomatically) {
64 if(_addNewBuffersAutomatically == addNewBuffersAutomatically)
67 _addNewBuffersAutomatically = addNewBuffersAutomatically;
68 emit addNewBuffersAutomaticallySet(addNewBuffersAutomatically);
71 void BufferViewConfig::setSortAlphabetically(bool sortAlphabetically) {
72 if(_sortAlphabetically == sortAlphabetically)
75 _sortAlphabetically = sortAlphabetically;
76 emit sortAlphabeticallySet(sortAlphabetically);
79 void BufferViewConfig::setDisableDecoration(bool disableDecoration) {
80 if(_disableDecoration == disableDecoration)
83 _disableDecoration = disableDecoration;
84 emit disableDecorationSet(disableDecoration);
87 void BufferViewConfig::setAllowedBufferTypes(int bufferTypes) {
88 if(_allowedBufferTypes == bufferTypes)
91 _allowedBufferTypes = bufferTypes;
92 emit allowedBufferTypesSet(bufferTypes);
95 void BufferViewConfig::setMinimumActivity(int activity) {
96 if(_minimumActivity == activity)
99 _minimumActivity = activity;
100 emit minimumActivitySet(activity);
103 void BufferViewConfig::setHideInactiveBuffers(bool hideInactiveBuffers) {
104 if(_hideInactiveBuffers == hideInactiveBuffers)
107 _hideInactiveBuffers = hideInactiveBuffers;
108 emit hideInactiveBuffersSet(hideInactiveBuffers);
111 QVariantList BufferViewConfig::initBufferList() const {
112 QVariantList buffers;
114 foreach(BufferId bufferId, _buffers) {
115 buffers << qVariantFromValue(bufferId);
121 void BufferViewConfig::initSetBufferList(const QVariantList &buffers) {
124 foreach(QVariant buffer, buffers) {
125 _buffers << buffer.value<BufferId>();
128 // normaly initSeters don't need an emit. this one is to track changes in the settingspage
129 emit bufferListSet();
132 void BufferViewConfig::initSetBufferList(const QList<BufferId> &buffers) {
135 foreach(BufferId bufferId, buffers) {
136 _buffers << bufferId;
139 // normaly initSeters don't need an emit. this one is to track changes in the settingspage
140 emit bufferListSet();
143 QVariantList BufferViewConfig::initRemovedBuffers() const {
144 QVariantList removedBuffers;
146 foreach(BufferId bufferId, _removedBuffers) {
147 removedBuffers << qVariantFromValue(bufferId);
150 return removedBuffers;
153 void BufferViewConfig::initSetRemovedBuffers(const QVariantList &buffers) {
154 _removedBuffers.clear();
156 foreach(QVariant buffer, buffers) {
157 _removedBuffers << buffer.value<BufferId>();
161 QVariantList BufferViewConfig::initTemporarilyRemovedBuffers() const {
162 QVariantList temporarilyRemovedBuffers;
164 foreach(BufferId bufferId, _temporarilyRemovedBuffers) {
165 temporarilyRemovedBuffers << qVariantFromValue(bufferId);
168 return temporarilyRemovedBuffers;
171 void BufferViewConfig::initSetTemporarilyRemovedBuffers(const QVariantList &buffers) {
172 _temporarilyRemovedBuffers.clear();
174 foreach(QVariant buffer, buffers) {
175 _temporarilyRemovedBuffers << buffer.value<BufferId>();
179 void BufferViewConfig::addBuffer(const BufferId &bufferId, int pos) {
180 if(_buffers.contains(bufferId))
185 if(pos > _buffers.count())
186 pos = _buffers.count();
188 if(_removedBuffers.contains(bufferId))
189 _removedBuffers.remove(bufferId);
191 if(_temporarilyRemovedBuffers.contains(bufferId))
192 _temporarilyRemovedBuffers.remove(bufferId);
194 _buffers.insert(pos, bufferId);
195 emit bufferAdded(bufferId, pos);
198 void BufferViewConfig::moveBuffer(const BufferId &bufferId, int pos) {
199 if(!_buffers.contains(bufferId))
204 if(pos >= _buffers.count())
205 pos = _buffers.count() - 1;
207 _buffers.move(_buffers.indexOf(bufferId), pos);
208 emit bufferMoved(bufferId, pos);
211 void BufferViewConfig::removeBuffer(const BufferId &bufferId) {
212 if(_buffers.contains(bufferId))
213 _buffers.removeAt(_buffers.indexOf(bufferId));
215 if(_removedBuffers.contains(bufferId))
216 _removedBuffers.remove(bufferId);
218 _temporarilyRemovedBuffers << bufferId;
220 emit bufferRemoved(bufferId);
223 void BufferViewConfig::removeBufferPermanently(const BufferId &bufferId) {
224 if(_buffers.contains(bufferId))
225 _buffers.removeAt(_buffers.indexOf(bufferId));
227 if(_temporarilyRemovedBuffers.contains(bufferId))
228 _temporarilyRemovedBuffers.remove(bufferId);
230 _removedBuffers << bufferId;
232 emit bufferPermanentlyRemoved(bufferId);