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