1 /***************************************************************************
2 * Copyright (C) 2005-08 by the Quassel Project *
3 * devel@quassel-irc.org *
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. *
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. *
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 ***************************************************************************/
21 #include "bufferviewoverlay.h"
26 #include "bufferviewconfig.h"
27 #include "clientbufferviewmanager.h"
29 const int BufferViewOverlay::_updateEventId = QEvent::registerEventType();
31 BufferViewOverlay::BufferViewOverlay(QObject *parent)
33 _aboutToUpdate(false),
34 _addBuffersAutomatically(false),
35 _hideInactiveBuffers(false),
36 _allowedBufferTypes(0),
41 void BufferViewOverlay::addView(int viewId) {
42 if(_bufferViewIds.contains(viewId))
45 BufferViewConfig *config = Client::bufferViewManager()->bufferViewConfig(viewId);
47 qDebug() << "BufferViewOverlay::addView(): no such buffer view:" << viewId;
51 _bufferViewIds << viewId;
52 if(config->isInitialized()) {
55 disconnect(config, SIGNAL(initDone()), this, SLOT(viewInitialized()));
56 connect(config, SIGNAL(initDone()), this, SLOT(viewInitialized()));
60 void BufferViewOverlay::removeView(int viewId) {
61 if(!_bufferViewIds.contains(viewId))
64 _bufferViewIds.remove(viewId);
68 void BufferViewOverlay::viewInitialized() {
69 BufferViewConfig *config = qobject_cast<BufferViewConfig *>(sender());
72 disconnect(config, SIGNAL(initDone()), this, SLOT(viewInitialized()));
74 // check if the view was removed in the meantime...
75 if(_bufferViewIds.contains(config->bufferViewId()))
79 void BufferViewOverlay::update() {
83 _aboutToUpdate = true;
86 void BufferViewOverlay::updateHelper() {
89 bool addBuffersAutomatically = false;
90 bool hideInactiveBuffers = true;
91 int allowedBufferTypes = 0;
92 int minimumActivity = -1;
93 QSet<NetworkId> networkIds;
94 QSet<BufferId> buffers;
95 QSet<BufferId> removedBuffers;
96 QSet<BufferId> tempRemovedBuffers;
98 BufferViewConfig *config = 0;
99 QSet<int>::const_iterator viewIter;
100 for(viewIter = _bufferViewIds.constBegin(); viewIter != _bufferViewIds.constEnd(); viewIter++) {
101 config = Client::bufferViewManager()->bufferViewConfig(*viewIter);
105 networkIds << config->networkId();
106 buffers += config->bufferList().toSet();
107 removedBuffers += config->removedBuffers();
108 tempRemovedBuffers += config->temporarilyRemovedBuffers();
110 addBuffersAutomatically |= config->addNewBuffersAutomatically();
111 hideInactiveBuffers &= config->hideInactiveBuffers();
112 allowedBufferTypes |= config->allowedBufferTypes();
113 if(minimumActivity == -1 || config->minimumActivity() < minimumActivity)
114 minimumActivity = config->minimumActivity();
117 changed |= (addBuffersAutomatically != _addBuffersAutomatically);
118 changed |= (hideInactiveBuffers != _hideInactiveBuffers);
119 changed |= (allowedBufferTypes != _allowedBufferTypes);
120 changed |= (minimumActivity != _minimumActivity);
121 changed |= (networkIds != _networkIds);
122 changed |= (buffers != _buffers);
123 changed |= (removedBuffers != _removedBuffers);
124 changed |= (tempRemovedBuffers != _tempRemovedBuffers);
126 _addBuffersAutomatically = addBuffersAutomatically;
127 _hideInactiveBuffers = hideInactiveBuffers;
128 _allowedBufferTypes = allowedBufferTypes;
129 _minimumActivity = minimumActivity;
130 _networkIds = networkIds;
132 _removedBuffers = removedBuffers;
133 _tempRemovedBuffers = tempRemovedBuffers;
139 void BufferViewOverlay::customEvent(QEvent *event) {
140 if(event->type() == _updateEventId) {
142 _aboutToUpdate = false;