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 _allowedBufferTypes(BufferInfo::StatusBuffer | BufferInfo::ChannelBuffer | BufferInfo::QueryBuffer | BufferInfo::GroupBuffer),
34 setObjectName(QString::number(bufferViewId));
37 BufferViewConfig::BufferViewConfig(int bufferViewId, const QVariantMap &properties, QObject *parent)
38 : SyncableObject(parent),
39 _bufferViewId(bufferViewId)
41 fromVariantMap(properties);
42 setObjectName(QString::number(bufferViewId));
45 void BufferViewConfig::setBufferViewName(const QString &bufferViewName) {
46 if(_bufferViewName == bufferViewName)
49 _bufferViewName = bufferViewName;
50 emit bufferViewNameSet(bufferViewName);
53 void BufferViewConfig::setNetworkId(const NetworkId &networkId) {
54 if(_networkId == networkId)
57 _networkId = networkId;
58 emit networkIdSet(networkId);
61 void BufferViewConfig::setAddNewBuffersAutomatically(bool addNewBuffersAutomatically) {
62 if(_addNewBuffersAutomatically == addNewBuffersAutomatically)
65 _addNewBuffersAutomatically = addNewBuffersAutomatically;
66 emit addNewBuffersAutomaticallySet(addNewBuffersAutomatically);
69 void BufferViewConfig::setSortAlphabetically(bool sortAlphabetically) {
70 if(_sortAlphabetically == sortAlphabetically)
73 _sortAlphabetically = sortAlphabetically;
74 emit sortAlphabeticallySet(sortAlphabetically);
77 void BufferViewConfig::setAllowedBufferTypes(int bufferTypes) {
78 if(_allowedBufferTypes == bufferTypes)
81 _allowedBufferTypes = bufferTypes;
82 emit allowedBufferTypesSet(bufferTypes);
85 void BufferViewConfig::setMinimumActivity(int activity) {
86 if(_minimumActivity == activity)
89 _minimumActivity = activity;
90 emit minimumActivitySet(activity);
93 void BufferViewConfig::setHideInactiveBuffers(bool hideInactiveBuffers) {
94 if(_hideInactiveBuffers == hideInactiveBuffers)
97 _hideInactiveBuffers = hideInactiveBuffers;
98 emit hideInactiveBuffersSet(hideInactiveBuffers);
101 QVariantList BufferViewConfig::initBufferList() const {
102 QVariantList buffers;
104 foreach(BufferId bufferId, _buffers) {
105 buffers << qVariantFromValue(bufferId);
111 void BufferViewConfig::initSetBufferList(const QVariantList &buffers) {
114 foreach(QVariant buffer, buffers) {
115 _buffers << buffer.value<BufferId>();
118 // normaly initSeters don't need an emit. this one is to track changes in the settingspage
119 emit bufferListSet();
122 void BufferViewConfig::initSetBufferList(const QList<BufferId> &buffers) {
125 foreach(BufferId bufferId, buffers) {
126 _buffers << bufferId;
129 // normaly initSeters don't need an emit. this one is to track changes in the settingspage
130 emit bufferListSet();
133 QVariantList BufferViewConfig::initRemovedBuffers() const {
134 QVariantList removedBuffers;
136 foreach(BufferId bufferId, _removedBuffers) {
137 removedBuffers << qVariantFromValue(bufferId);
140 return removedBuffers;
143 void BufferViewConfig::initSetRemovedBuffers(const QVariantList &buffers) {
144 _removedBuffers.clear();
146 foreach(QVariant buffer, buffers) {
147 _removedBuffers << buffer.value<BufferId>();
151 QVariantList BufferViewConfig::initTemporarilyRemovedBuffers() const {
152 QVariantList temporarilyRemovedBuffers;
154 foreach(BufferId bufferId, _temporarilyRemovedBuffers) {
155 temporarilyRemovedBuffers << qVariantFromValue(bufferId);
158 return temporarilyRemovedBuffers;
161 void BufferViewConfig::initSetTemporarilyRemovedBuffers(const QVariantList &buffers) {
162 _temporarilyRemovedBuffers.clear();
164 foreach(QVariant buffer, buffers) {
165 _temporarilyRemovedBuffers << buffer.value<BufferId>();
169 void BufferViewConfig::addBuffer(const BufferId &bufferId, int pos) {
170 if(_buffers.contains(bufferId))
175 if(pos > _buffers.count())
176 pos = _buffers.count();
178 if(_removedBuffers.contains(bufferId))
179 _removedBuffers.remove(bufferId);
181 if(_temporarilyRemovedBuffers.contains(bufferId))
182 _temporarilyRemovedBuffers.remove(bufferId);
184 _buffers.insert(pos, bufferId);
185 emit bufferAdded(bufferId, pos);
188 void BufferViewConfig::moveBuffer(const BufferId &bufferId, int pos) {
189 if(!_buffers.contains(bufferId))
194 if(pos >= _buffers.count())
195 pos = _buffers.count() - 1;
197 _buffers.move(_buffers.indexOf(bufferId), pos);
198 emit bufferMoved(bufferId, pos);
201 void BufferViewConfig::removeBuffer(const BufferId &bufferId) {
202 if(_buffers.contains(bufferId))
203 _buffers.removeAt(_buffers.indexOf(bufferId));
205 if(_removedBuffers.contains(bufferId))
206 _removedBuffers.remove(bufferId);
208 _temporarilyRemovedBuffers << bufferId;
210 emit bufferRemoved(bufferId);
213 void BufferViewConfig::removeBufferPermanently(const BufferId &bufferId) {
214 if(_buffers.contains(bufferId))
215 _buffers.removeAt(_buffers.indexOf(bufferId));
217 if(_temporarilyRemovedBuffers.contains(bufferId))
218 _temporarilyRemovedBuffers.remove(bufferId);
220 _removedBuffers << bufferId;
222 emit bufferPermanentlyRemoved(bufferId);