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