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