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 emit bufferListSet();
121 void BufferViewConfig::initSetBufferList(const QList<BufferId> &buffers) {
124 foreach(BufferId bufferId, buffers) {
125 _buffers << bufferId;
128 emit bufferListSet();
131 void BufferViewConfig::addBuffer(const BufferId &bufferId, int pos) {
132 if(_buffers.contains(bufferId))
137 if(pos > _buffers.count())
138 pos = _buffers.count();
140 _buffers.insert(pos, bufferId);
141 emit bufferAdded(bufferId, pos);
144 void BufferViewConfig::moveBuffer(const BufferId &bufferId, int pos) {
145 if(!_buffers.contains(bufferId))
150 if(pos >= _buffers.count())
151 pos = _buffers.count() - 1;
153 _buffers.move(_buffers.indexOf(bufferId), pos);
154 emit bufferMoved(bufferId, pos);
157 void BufferViewConfig::removeBuffer(const BufferId &bufferId) {
158 if(!_buffers.contains(bufferId))
161 _buffers.removeAt(_buffers.indexOf(bufferId));
162 emit bufferRemoved(bufferId);