common: Fix BufferViewConfig upgrade defaults
[quassel.git] / src / common / bufferviewconfig.cpp
1 /***************************************************************************
2  *   Copyright (C) 2005-2018 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  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
19  ***************************************************************************/
20
21 #include "bufferviewconfig.h"
22
23 INIT_SYNCABLE_OBJECT(BufferViewConfig)
24 BufferViewConfig::BufferViewConfig(int bufferViewId, QObject *parent)
25     : SyncableObject(parent),
26     _bufferViewId(bufferViewId)
27 {
28     setObjectName(QString::number(bufferViewId));
29 }
30
31
32 BufferViewConfig::BufferViewConfig(int bufferViewId, const QVariantMap &properties, QObject *parent)
33     : SyncableObject(parent),
34     _bufferViewId(bufferViewId)
35 {
36     fromVariantMap(properties);
37     setObjectName(QString::number(bufferViewId));
38 }
39
40
41 void BufferViewConfig::setBufferViewName(const QString &bufferViewName)
42 {
43     if (_bufferViewName == bufferViewName)
44         return;
45
46     _bufferViewName = bufferViewName;
47     SYNC(ARG(bufferViewName))
48     emit bufferViewNameSet(bufferViewName);
49 }
50
51
52 void BufferViewConfig::setNetworkId(const NetworkId &networkId)
53 {
54     if (_networkId == networkId)
55         return;
56
57     _networkId = networkId;
58     SYNC(ARG(networkId))
59     emit networkIdSet(networkId);
60     emit configChanged();
61 }
62
63
64 void BufferViewConfig::setAddNewBuffersAutomatically(bool addNewBuffersAutomatically)
65 {
66     if (_addNewBuffersAutomatically == addNewBuffersAutomatically)
67         return;
68
69     _addNewBuffersAutomatically = addNewBuffersAutomatically;
70     SYNC(ARG(addNewBuffersAutomatically))
71     emit configChanged();
72 }
73
74
75 void BufferViewConfig::setSortAlphabetically(bool sortAlphabetically)
76 {
77     if (_sortAlphabetically == sortAlphabetically)
78         return;
79
80     _sortAlphabetically = sortAlphabetically;
81     SYNC(ARG(sortAlphabetically))
82     emit configChanged();
83 }
84
85
86 void BufferViewConfig::setDisableDecoration(bool disableDecoration)
87 {
88     if (_disableDecoration == disableDecoration)
89         return;
90
91     _disableDecoration = disableDecoration;
92     SYNC(ARG(disableDecoration))
93 }
94
95
96 void BufferViewConfig::setAllowedBufferTypes(int bufferTypes)
97 {
98     if (_allowedBufferTypes == bufferTypes)
99         return;
100
101     _allowedBufferTypes = bufferTypes;
102     SYNC(ARG(bufferTypes))
103     emit configChanged();
104 }
105
106
107 void BufferViewConfig::setMinimumActivity(int activity)
108 {
109     if (_minimumActivity == activity)
110         return;
111
112     _minimumActivity = activity;
113     SYNC(ARG(activity))
114     emit configChanged();
115 }
116
117
118 void BufferViewConfig::setHideInactiveBuffers(bool hideInactiveBuffers)
119 {
120     if (_hideInactiveBuffers == hideInactiveBuffers)
121         return;
122
123     _hideInactiveBuffers = hideInactiveBuffers;
124     SYNC(ARG(hideInactiveBuffers))
125     emit configChanged();
126 }
127
128 void BufferViewConfig::setHideInactiveNetworks(bool hideInactiveNetworks)
129 {
130     if (_hideInactiveNetworks == hideInactiveNetworks)
131         return;
132
133     _hideInactiveNetworks = hideInactiveNetworks;
134     SYNC(ARG(hideInactiveNetworks))
135     emit configChanged();
136 }
137
138 void BufferViewConfig::setShowSearch(bool showSearch) {
139     if (_showSearch == showSearch) {
140         return;
141     }
142
143     _showSearch = showSearch;
144     SYNC(ARG(showSearch))
145     emit configChanged();
146 }
147
148
149 QVariantList BufferViewConfig::initBufferList() const
150 {
151     QVariantList buffers;
152
153     foreach(BufferId bufferId, _buffers) {
154         buffers << qVariantFromValue(bufferId);
155     }
156
157     return buffers;
158 }
159
160
161 void BufferViewConfig::initSetBufferList(const QVariantList &buffers)
162 {
163     _buffers.clear();
164
165     foreach(QVariant buffer, buffers) {
166         _buffers << buffer.value<BufferId>();
167     }
168
169     emit configChanged(); // used to track changes in the settingspage
170 }
171
172
173 void BufferViewConfig::initSetBufferList(const QList<BufferId> &buffers)
174 {
175     _buffers.clear();
176
177     foreach(BufferId bufferId, buffers) {
178         _buffers << bufferId;
179     }
180
181     emit configChanged(); // used to track changes in the settingspage
182 }
183
184
185 QVariantList BufferViewConfig::initRemovedBuffers() const
186 {
187     QVariantList removedBuffers;
188
189     foreach(BufferId bufferId, _removedBuffers) {
190         removedBuffers << qVariantFromValue(bufferId);
191     }
192
193     return removedBuffers;
194 }
195
196
197 void BufferViewConfig::initSetRemovedBuffers(const QVariantList &buffers)
198 {
199     _removedBuffers.clear();
200
201     foreach(QVariant buffer, buffers) {
202         _removedBuffers << buffer.value<BufferId>();
203     }
204 }
205
206
207 QVariantList BufferViewConfig::initTemporarilyRemovedBuffers() const
208 {
209     QVariantList temporarilyRemovedBuffers;
210
211     foreach(BufferId bufferId, _temporarilyRemovedBuffers) {
212         temporarilyRemovedBuffers << qVariantFromValue(bufferId);
213     }
214
215     return temporarilyRemovedBuffers;
216 }
217
218
219 void BufferViewConfig::initSetTemporarilyRemovedBuffers(const QVariantList &buffers)
220 {
221     _temporarilyRemovedBuffers.clear();
222
223     foreach(QVariant buffer, buffers) {
224         _temporarilyRemovedBuffers << buffer.value<BufferId>();
225     }
226 }
227
228
229 void BufferViewConfig::addBuffer(const BufferId &bufferId, int pos)
230 {
231     if (_buffers.contains(bufferId))
232         return;
233
234     if (pos < 0)
235         pos = 0;
236     if (pos > _buffers.count())
237         pos = _buffers.count();
238
239     if (_removedBuffers.contains(bufferId))
240         _removedBuffers.remove(bufferId);
241
242     if (_temporarilyRemovedBuffers.contains(bufferId))
243         _temporarilyRemovedBuffers.remove(bufferId);
244
245     _buffers.insert(pos, bufferId);
246     SYNC(ARG(bufferId), ARG(pos))
247     emit bufferAdded(bufferId, pos);
248     emit configChanged();
249 }
250
251
252 void BufferViewConfig::moveBuffer(const BufferId &bufferId, int pos)
253 {
254     if (!_buffers.contains(bufferId))
255         return;
256
257     if (pos < 0)
258         pos = 0;
259     if (pos >= _buffers.count())
260         pos = _buffers.count() - 1;
261
262     _buffers.move(_buffers.indexOf(bufferId), pos);
263     SYNC(ARG(bufferId), ARG(pos))
264     emit bufferMoved(bufferId, pos);
265     emit configChanged();
266 }
267
268
269 void BufferViewConfig::removeBuffer(const BufferId &bufferId)
270 {
271     if (_buffers.contains(bufferId))
272         _buffers.removeAt(_buffers.indexOf(bufferId));
273
274     if (_removedBuffers.contains(bufferId))
275         _removedBuffers.remove(bufferId);
276
277     _temporarilyRemovedBuffers << bufferId;
278     SYNC(ARG(bufferId))
279     emit bufferRemoved(bufferId);
280     emit configChanged();
281 }
282
283
284 void BufferViewConfig::removeBufferPermanently(const BufferId &bufferId)
285 {
286     if (_buffers.contains(bufferId))
287         _buffers.removeAt(_buffers.indexOf(bufferId));
288
289     if (_temporarilyRemovedBuffers.contains(bufferId))
290         _temporarilyRemovedBuffers.remove(bufferId);
291
292     _removedBuffers << bufferId;
293
294     SYNC(ARG(bufferId))
295     emit bufferPermanentlyRemoved(bufferId);
296     emit configChanged();
297 }