Adding proxy support to the core
[quassel.git] / src / common / bufferviewconfig.cpp
1 /***************************************************************************
2  *   Copyright (C) 2005-08 by the Quassel Project                          *
3  *   devel@quassel-irc.org                                                 *
4  *                                                                         *
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.                                           *
9  *                                                                         *
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.                          *
14  *                                                                         *
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  ***************************************************************************/
20
21 #include "bufferviewconfig.h"
22
23 #include "bufferinfo.h"
24
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),
33     _minimumActivity(0)
34 {
35   setObjectName(QString::number(bufferViewId));
36 }
37
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
42 {
43   fromVariantMap(properties);
44   setObjectName(QString::number(bufferViewId));
45 }
46
47 void BufferViewConfig::setBufferViewName(const QString &bufferViewName) {
48   if(_bufferViewName == bufferViewName)
49     return;
50
51   _bufferViewName = bufferViewName;
52   emit bufferViewNameSet(bufferViewName);
53 }
54
55 void BufferViewConfig::setNetworkId(const NetworkId &networkId) {
56   if(_networkId == networkId)
57     return;
58
59   _networkId = networkId;
60   emit networkIdSet(networkId);
61 }
62
63 void BufferViewConfig::setAddNewBuffersAutomatically(bool addNewBuffersAutomatically) {
64   if(_addNewBuffersAutomatically == addNewBuffersAutomatically)
65     return;
66
67   _addNewBuffersAutomatically = addNewBuffersAutomatically;
68   emit addNewBuffersAutomaticallySet(addNewBuffersAutomatically);
69 }
70
71 void BufferViewConfig::setSortAlphabetically(bool sortAlphabetically) {
72   if(_sortAlphabetically == sortAlphabetically)
73     return;
74
75   _sortAlphabetically = sortAlphabetically;
76   emit sortAlphabeticallySet(sortAlphabetically);
77 }
78
79 void BufferViewConfig::setDisableDecoration(bool disableDecoration) {
80   if(_disableDecoration == disableDecoration)
81     return;
82
83   _disableDecoration = disableDecoration;
84   emit disableDecorationSet(disableDecoration);
85 }
86
87 void BufferViewConfig::setAllowedBufferTypes(int bufferTypes) {
88   if(_allowedBufferTypes == bufferTypes)
89     return;
90
91   _allowedBufferTypes = bufferTypes;
92   emit allowedBufferTypesSet(bufferTypes);
93 }
94
95 void BufferViewConfig::setMinimumActivity(int activity) {
96   if(_minimumActivity == activity)
97     return;
98
99   _minimumActivity = activity;
100   emit minimumActivitySet(activity);
101 }
102
103 void BufferViewConfig::setHideInactiveBuffers(bool hideInactiveBuffers) {
104   if(_hideInactiveBuffers == hideInactiveBuffers)
105     return;
106
107   _hideInactiveBuffers = hideInactiveBuffers;
108   emit hideInactiveBuffersSet(hideInactiveBuffers);
109 }
110
111 QVariantList BufferViewConfig::initBufferList() const {
112   QVariantList buffers;
113
114   foreach(BufferId bufferId, _buffers) {
115     buffers << qVariantFromValue(bufferId);
116   }
117
118   return buffers;
119 }
120
121 void BufferViewConfig::initSetBufferList(const QVariantList &buffers) {
122   _buffers.clear();
123
124   foreach(QVariant buffer, buffers) {
125     _buffers << buffer.value<BufferId>();
126   }
127
128   // normaly initSeters don't need an emit. this one is to track changes in the settingspage
129   emit bufferListSet();
130 }
131
132 void BufferViewConfig::initSetBufferList(const QList<BufferId> &buffers) {
133   _buffers.clear();
134
135   foreach(BufferId bufferId, buffers) {
136     _buffers << bufferId;
137   }
138
139   // normaly initSeters don't need an emit. this one is to track changes in the settingspage
140   emit bufferListSet();
141 }
142
143 QVariantList BufferViewConfig::initRemovedBuffers() const {
144   QVariantList removedBuffers;
145
146   foreach(BufferId bufferId, _removedBuffers) {
147     removedBuffers << qVariantFromValue(bufferId);
148   }
149
150   return removedBuffers;
151 }
152
153 void BufferViewConfig::initSetRemovedBuffers(const QVariantList &buffers) {
154   _removedBuffers.clear();
155
156   foreach(QVariant buffer, buffers) {
157     _removedBuffers << buffer.value<BufferId>();
158   }
159 }
160
161 QVariantList BufferViewConfig::initTemporarilyRemovedBuffers() const {
162   QVariantList temporarilyRemovedBuffers;
163
164   foreach(BufferId bufferId, _temporarilyRemovedBuffers) {
165     temporarilyRemovedBuffers << qVariantFromValue(bufferId);
166   }
167
168   return temporarilyRemovedBuffers;
169 }
170
171 void BufferViewConfig::initSetTemporarilyRemovedBuffers(const QVariantList &buffers) {
172   _temporarilyRemovedBuffers.clear();
173
174   foreach(QVariant buffer, buffers) {
175     _temporarilyRemovedBuffers << buffer.value<BufferId>();
176   }
177 }
178
179 void BufferViewConfig::addBuffer(const BufferId &bufferId, int pos) {
180   if(_buffers.contains(bufferId))
181     return;
182
183   if(pos < 0)
184     pos = 0;
185   if(pos > _buffers.count())
186     pos = _buffers.count();
187
188   if(_removedBuffers.contains(bufferId))
189     _removedBuffers.remove(bufferId);
190
191   if(_temporarilyRemovedBuffers.contains(bufferId))
192     _temporarilyRemovedBuffers.remove(bufferId);
193
194   _buffers.insert(pos, bufferId);
195   emit bufferAdded(bufferId, pos);
196 }
197
198 void BufferViewConfig::moveBuffer(const BufferId &bufferId, int pos) {
199   if(!_buffers.contains(bufferId))
200     return;
201
202   if(pos < 0)
203     pos = 0;
204   if(pos >= _buffers.count())
205     pos = _buffers.count() - 1;
206
207   _buffers.move(_buffers.indexOf(bufferId), pos);
208   emit bufferMoved(bufferId, pos);
209 }
210
211 void BufferViewConfig::removeBuffer(const BufferId &bufferId) {
212   if(_buffers.contains(bufferId))
213     _buffers.removeAt(_buffers.indexOf(bufferId));
214
215   if(_removedBuffers.contains(bufferId))
216     _removedBuffers.remove(bufferId);
217
218   _temporarilyRemovedBuffers << bufferId;
219
220   emit bufferRemoved(bufferId);
221 }
222
223 void BufferViewConfig::removeBufferPermanently(const BufferId &bufferId) {
224   if(_buffers.contains(bufferId))
225     _buffers.removeAt(_buffers.indexOf(bufferId));
226
227   if(_temporarilyRemovedBuffers.contains(bufferId))
228     _temporarilyRemovedBuffers.remove(bufferId);
229
230   _removedBuffers << bufferId;
231
232   emit bufferPermanentlyRemoved(bufferId);
233 }