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()) {
53 viewInitialized(config);
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);
65 BufferViewConfig *config = qobject_cast<BufferViewConfig *>(sender());
67 disconnect(config, 0, this, 0);
71 void BufferViewOverlay::viewInitialized(BufferViewConfig *config) {
73 qWarning() << "BufferViewOverlay::viewInitialized() received invalid view!";
76 disconnect(config, SIGNAL(initDone()), this, SLOT(viewInitialized()));
78 connect(config, SIGNAL(networkIdSet(const NetworkId &)), this, SLOT(update()));
79 connect(config, SIGNAL(addNewBuffersAutomaticallySet(bool)), this, SLOT(update()));
80 connect(config, SIGNAL(sortAlphabeticallySet(bool)), this, SLOT(update()));
81 connect(config, SIGNAL(hideInactiveBuffersSet(bool)), this, SLOT(update()));
82 connect(config, SIGNAL(allowedBufferTypesSet(int)), this, SLOT(update()));
83 connect(config, SIGNAL(minimumActivitySet(int)), this, SLOT(update()));
84 connect(config, SIGNAL(bufferListSet()), this, SLOT(update()));
85 connect(config, SIGNAL(bufferAdded(const BufferId &, int)), this, SLOT(update()));
86 connect(config, SIGNAL(bufferRemoved(const BufferId &)), this, SLOT(update()));
87 connect(config, SIGNAL(bufferPermanentlyRemoved(const BufferId &)), this, SLOT(update()));
89 // check if the view was removed in the meantime...
90 if(_bufferViewIds.contains(config->bufferViewId()))
94 void BufferViewOverlay::viewInitialized() {
95 BufferViewConfig *config = qobject_cast<BufferViewConfig *>(sender());
98 viewInitialized(config);
101 void BufferViewOverlay::update() {
105 _aboutToUpdate = true;
106 QCoreApplication::postEvent(this, new QEvent((QEvent::Type)_updateEventId));
109 void BufferViewOverlay::updateHelper() {
110 bool changed = false;
112 bool addBuffersAutomatically = false;
113 bool hideInactiveBuffers = true;
114 int allowedBufferTypes = 0;
115 int minimumActivity = -1;
116 QSet<NetworkId> networkIds;
117 QSet<BufferId> buffers;
118 QSet<BufferId> removedBuffers;
119 QSet<BufferId> tempRemovedBuffers;
121 if(Client::bufferViewManager()) {
122 BufferViewConfig *config = 0;
123 QSet<int>::const_iterator viewIter;
124 for(viewIter = _bufferViewIds.constBegin(); viewIter != _bufferViewIds.constEnd(); viewIter++) {
125 config = Client::bufferViewManager()->bufferViewConfig(*viewIter);
128 networkIds << config->networkId();
129 buffers += config->bufferList().toSet();
130 tempRemovedBuffers += config->temporarilyRemovedBuffers();
132 // in the overlay a buffer is removed it is removed from all views
133 if(removedBuffers.isEmpty())
134 removedBuffers = config->removedBuffers();
136 removedBuffers.intersect(config->removedBuffers());
139 addBuffersAutomatically |= config->addNewBuffersAutomatically();
140 hideInactiveBuffers &= config->hideInactiveBuffers();
141 allowedBufferTypes |= config->allowedBufferTypes();
142 if(minimumActivity == -1 || config->minimumActivity() < minimumActivity)
143 minimumActivity = config->minimumActivity();
147 changed |= (addBuffersAutomatically != _addBuffersAutomatically);
148 changed |= (hideInactiveBuffers != _hideInactiveBuffers);
149 changed |= (allowedBufferTypes != _allowedBufferTypes);
150 changed |= (minimumActivity != _minimumActivity);
151 changed |= (networkIds != _networkIds);
152 changed |= (buffers != _buffers);
153 changed |= (removedBuffers != _removedBuffers);
154 changed |= (tempRemovedBuffers != _tempRemovedBuffers);
156 _addBuffersAutomatically = addBuffersAutomatically;
157 _hideInactiveBuffers = hideInactiveBuffers;
158 _allowedBufferTypes = allowedBufferTypes;
159 _minimumActivity = minimumActivity;
160 _networkIds = networkIds;
162 _removedBuffers = removedBuffers;
163 _tempRemovedBuffers = tempRemovedBuffers;
169 void BufferViewOverlay::customEvent(QEvent *event) {
170 if(event->type() == _updateEventId) {
172 _aboutToUpdate = false;