initial version of a bufferview overlay
authorMarcus Eggenberger <egs@quassel-irc.org>
Sun, 15 Mar 2009 20:44:21 +0000 (21:44 +0100)
committerMarcus Eggenberger <egs@quassel-irc.org>
Mon, 16 Mar 2009 17:09:07 +0000 (18:09 +0100)
src/client/CMakeLists.txt
src/client/bufferviewoverlay.cpp [new file with mode: 0644]
src/client/bufferviewoverlay.h [new file with mode: 0644]
src/client/clientbufferviewmanager.cpp
src/client/clientbufferviewmanager.h

index d021e7e..e7e9e4d 100644 (file)
@@ -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 (file)
index 0000000..f07c4a3
--- /dev/null
@@ -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 <QEvent>
+
+#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<BufferViewConfig *>(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<NetworkId> networkIds;
+  QSet<BufferId> buffers;
+  QSet<BufferId> removedBuffers;
+  QSet<BufferId> tempRemovedBuffers;
+  
+  BufferViewConfig *config = 0;
+  QSet<int>::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 (file)
index 0000000..d528713
--- /dev/null
@@ -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 <QObject>
+
+#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<int> _bufferViewIds;
+
+  QSet<NetworkId> _networkIds;
+
+  bool _addBuffersAutomatically;
+  bool _hideInactiveBuffers;
+  int _allowedBufferTypes;
+  int _minimumActivity;
+
+  QSet<BufferId> _buffers;
+  QSet<BufferId> _removedBuffers;
+  QSet<BufferId> _tempRemovedBuffers;
+
+  static const int _updateEventId;
+};
+
+#endif //BUFFERVIEWOVERLAY_H
index c46ff3a..06e8a85 100644 (file)
 #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<ClientBufferViewConfig *>(bufferViewConfig(bufferViewId));
 }
 
+void ClientBufferViewManager::updateBufferViewOverlay() {
+  
+}
index 6ecef78..80d1754 100644 (file)
@@ -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<ClientBufferViewConfig *> 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