From f48d855945219c3a1897a17bf15830dfee104f0b Mon Sep 17 00:00:00 2001 From: Marcus Eggenberger Date: Sun, 15 Mar 2009 21:44:21 +0100 Subject: [PATCH] initial version of a bufferview overlay --- src/client/CMakeLists.txt | 2 + src/client/bufferviewoverlay.cpp | 144 +++++++++++++++++++++++++ src/client/bufferviewoverlay.h | 74 +++++++++++++ src/client/clientbufferviewmanager.cpp | 8 +- src/client/clientbufferviewmanager.h | 10 ++ 5 files changed, 237 insertions(+), 1 deletion(-) create mode 100644 src/client/bufferviewoverlay.cpp create mode 100644 src/client/bufferviewoverlay.h diff --git a/src/client/CMakeLists.txt b/src/client/CMakeLists.txt index d021e7e3..e7e9e4df 100644 --- a/src/client/CMakeLists.txt +++ b/src/client/CMakeLists.txt @@ -12,6 +12,7 @@ set(SOURCES backlogrequester.cpp buffermodel.cpp buffersettings.cpp + bufferviewoverlay.cpp client.cpp clientbacklogmanager.cpp clientbufferviewconfig.cpp @@ -32,6 +33,7 @@ set(MOC_HDRS abstractmessageprocessor.h abstractui.h buffermodel.h + bufferviewoverlay.h client.h clientbacklogmanager.h clientbufferviewconfig.h diff --git a/src/client/bufferviewoverlay.cpp b/src/client/bufferviewoverlay.cpp new file mode 100644 index 00000000..f07c4a3a --- /dev/null +++ b/src/client/bufferviewoverlay.cpp @@ -0,0 +1,144 @@ +/*************************************************************************** + * Copyright (C) 2005-08 by the Quassel Project * + * devel@quassel-irc.org * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) version 3. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#include "bufferviewoverlay.h" + +#include + +#include "client.h" +#include "bufferviewconfig.h" +#include "clientbufferviewmanager.h" + +const int BufferViewOverlay::_updateEventId = QEvent::registerEventType(); + +BufferViewOverlay::BufferViewOverlay(QObject *parent) + : QObject(parent), + _aboutToUpdate(false), + _addBuffersAutomatically(false), + _hideInactiveBuffers(false), + _allowedBufferTypes(0), + _minimumActivity(0) +{ +} + +void BufferViewOverlay::addView(int viewId) { + if(_bufferViewIds.contains(viewId)) + return; + + BufferViewConfig *config = Client::bufferViewManager()->bufferViewConfig(viewId); + if(!config) { + qDebug() << "BufferViewOverlay::addView(): no such buffer view:" << viewId; + return; + } + + _bufferViewIds << viewId; + if(config->isInitialized()) { + update(); + } else { + disconnect(config, SIGNAL(initDone()), this, SLOT(viewInitialized())); + connect(config, SIGNAL(initDone()), this, SLOT(viewInitialized())); + } +} + +void BufferViewOverlay::removeView(int viewId) { + if(!_bufferViewIds.contains(viewId)) + return; + + _bufferViewIds.remove(viewId); + update(); +} + +void BufferViewOverlay::viewInitialized() { + BufferViewConfig *config = qobject_cast(sender()); + Q_ASSERT(config); + + disconnect(config, SIGNAL(initDone()), this, SLOT(viewInitialized())); + + // check if the view was removed in the meantime... + if(_bufferViewIds.contains(config->bufferViewId())) + update(); +} + +void BufferViewOverlay::update() { + if(_aboutToUpdate) { + return; + } + _aboutToUpdate = true; +} + +void BufferViewOverlay::updateHelper() { + bool changed = false; + + bool addBuffersAutomatically = false; + bool hideInactiveBuffers = true; + int allowedBufferTypes = 0; + int minimumActivity = -1; + QSet networkIds; + QSet buffers; + QSet removedBuffers; + QSet tempRemovedBuffers; + + BufferViewConfig *config = 0; + QSet::const_iterator viewIter; + for(viewIter = _bufferViewIds.constBegin(); viewIter != _bufferViewIds.constEnd(); viewIter++) { + config = Client::bufferViewManager()->bufferViewConfig(*viewIter); + if(!config) + continue; + + networkIds << config->networkId(); + buffers += config->bufferList().toSet(); + removedBuffers += config->removedBuffers(); + tempRemovedBuffers += config->temporarilyRemovedBuffers(); + + addBuffersAutomatically |= config->addNewBuffersAutomatically(); + hideInactiveBuffers &= config->hideInactiveBuffers(); + allowedBufferTypes |= config->allowedBufferTypes(); + if(minimumActivity == -1 || config->minimumActivity() < minimumActivity) + minimumActivity = config->minimumActivity(); + } + + changed |= (addBuffersAutomatically != _addBuffersAutomatically); + changed |= (hideInactiveBuffers != _hideInactiveBuffers); + changed |= (allowedBufferTypes != _allowedBufferTypes); + changed |= (minimumActivity != _minimumActivity); + changed |= (networkIds != _networkIds); + changed |= (buffers != _buffers); + changed |= (removedBuffers != _removedBuffers); + changed |= (tempRemovedBuffers != _tempRemovedBuffers); + + _addBuffersAutomatically = addBuffersAutomatically; + _hideInactiveBuffers = hideInactiveBuffers; + _allowedBufferTypes = allowedBufferTypes; + _minimumActivity = minimumActivity; + _networkIds = networkIds; + _buffers = buffers; + _removedBuffers = removedBuffers; + _tempRemovedBuffers = tempRemovedBuffers; + + if(changed) + emit hasChanged(); +} + +void BufferViewOverlay::customEvent(QEvent *event) { + if(event->type() == _updateEventId) { + updateHelper(); + _aboutToUpdate = false; + } +} diff --git a/src/client/bufferviewoverlay.h b/src/client/bufferviewoverlay.h new file mode 100644 index 00000000..d5287136 --- /dev/null +++ b/src/client/bufferviewoverlay.h @@ -0,0 +1,74 @@ +/*************************************************************************** + * Copyright (C) 2005-08 by the Quassel Project * + * devel@quassel-irc.org * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) version 3. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#ifndef BUFFERVIEWOVERLAY_H +#define BUFFERVIEWOVERLAY_H + +#include + +#include "types.h" + +class ClientBufferViewConfig; + +class BufferViewOverlay : public QObject { + Q_OBJECT + +public: + BufferViewOverlay(QObject *parent = 0); + +public slots: + void addView(int viewId); + void removeView(int viewId); + + // updates propagated from the actual views + void update(); + +signals: + void hasChanged(); + +protected: + virtual void customEvent(QEvent *event); + +private slots: + void viewInitialized(); + +private: + inline bool allNetworks() const { return _networkIds.contains(NetworkId()); } + + void updateHelper(); + bool _aboutToUpdate; + + QSet _bufferViewIds; + + QSet _networkIds; + + bool _addBuffersAutomatically; + bool _hideInactiveBuffers; + int _allowedBufferTypes; + int _minimumActivity; + + QSet _buffers; + QSet _removedBuffers; + QSet _tempRemovedBuffers; + + static const int _updateEventId; +}; + +#endif //BUFFERVIEWOVERLAY_H diff --git a/src/client/clientbufferviewmanager.cpp b/src/client/clientbufferviewmanager.cpp index c46ff3ac..06e8a852 100644 --- a/src/client/clientbufferviewmanager.cpp +++ b/src/client/clientbufferviewmanager.cpp @@ -23,8 +23,11 @@ #include "clientbufferviewconfig.h" ClientBufferViewManager::ClientBufferViewManager(SignalProxy *proxy, QObject *parent) - : BufferViewManager(proxy, parent) + : BufferViewManager(proxy, parent), + _bufferViewOverlay(0) { + connect(this, SIGNAL(bufferViewConfigAdded(int)), this, SLOT(updateBufferViewOverlay())); + connect(this, SIGNAL(bufferViewConfigDeleted(int)), this, SLOT(updateBufferViewOverlay())); } BufferViewConfig *ClientBufferViewManager::bufferViewConfigFactory(int bufferViewConfigId) { @@ -43,3 +46,6 @@ ClientBufferViewConfig *ClientBufferViewManager::clientBufferViewConfig(int buff return static_cast(bufferViewConfig(bufferViewId)); } +void ClientBufferViewManager::updateBufferViewOverlay() { + +} diff --git a/src/client/clientbufferviewmanager.h b/src/client/clientbufferviewmanager.h index 6ecef78c..80d1754f 100644 --- a/src/client/clientbufferviewmanager.h +++ b/src/client/clientbufferviewmanager.h @@ -22,7 +22,9 @@ #define CLIENTBUFFERVIEWMANAGER_H #include "bufferviewmanager.h" + class ClientBufferViewConfig; +class BufferViewOverlay; class ClientBufferViewManager : public BufferViewManager { Q_OBJECT @@ -33,8 +35,16 @@ public: QList clientBufferViewConfigs() const; ClientBufferViewConfig *clientBufferViewConfig(int bufferViewId) const; + inline const BufferViewOverlay *bufferViewOverlay() const { return _bufferViewOverlay; } + protected: virtual BufferViewConfig *bufferViewConfigFactory(int bufferViewConfigId); + +private slots: + void updateBufferViewOverlay(); + +private: + BufferViewOverlay *_bufferViewOverlay; }; #endif //CLIENTBUFFERVIEWMANAGER_H -- 2.20.1