Fix Quassel not rejoining newly joined channels
[quassel.git] / src / qtui / chatview.cpp
index 2a999ea..f8fe6b8 100644 (file)
 #include "chatview.h"
 #include "client.h"
 #include "messagefilter.h"
-#include "quasselui.h"
+#include "qtui.h"
+#include "qtuistyle.h"
+#include "clientignorelistmanager.h"
 
 ChatView::ChatView(BufferId bufferId, QWidget *parent)
   : QGraphicsView(parent),
     AbstractChatView(),
     _bufferContainer(0),
-    _currentScaleFactor(1)
+    _currentScaleFactor(1),
+    _invalidateFilter(false)
 {
   QList<BufferId> filterList;
   filterList.append(bufferId);
@@ -46,7 +49,8 @@ ChatView::ChatView(MessageFilter *filter, QWidget *parent)
   : QGraphicsView(parent),
     AbstractChatView(),
     _bufferContainer(0),
-    _currentScaleFactor(1)
+    _currentScaleFactor(1),
+    _invalidateFilter(false)
 {
   init(filter);
 }
@@ -72,6 +76,10 @@ void ChatView::init(MessageFilter *filter) {
   setScene(_scene);
 
   connect(verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(verticalScrollbarChanged(int)));
+
+  // only connect if client is synched with a core
+  if(Client::isSynced())
+    connect(Client::ignoreListManager(), SIGNAL(ignoreListChanged()), this, SLOT(invalidateFilter()));
 }
 
 bool ChatView::event(QEvent *event) {
@@ -98,6 +106,11 @@ bool ChatView::event(QEvent *event) {
     }
   }
 
+  if(event->type() == QEvent::Show) {
+    if(_invalidateFilter)
+      invalidateFilter();
+  }
+
   return QGraphicsView::event(event);
 }
 
@@ -164,6 +177,10 @@ void ChatView::verticalScrollbarChanged(int newPos) {
     }
   }
   _lastScrollbarPos = newPos;
+
+  // FIXME: Fugly workaround for the ChatView scrolling up 1px on buffer switch
+  if(vbar->maximum() - newPos <= 2)
+    vbar->setValue(vbar->maximum());
 }
 
 MsgId ChatView::lastMsgId() const {
@@ -203,3 +220,16 @@ void ChatView::zoomOriginal() {
     _currentScaleFactor = 1;
     scene()->setWidth(viewport()->width() - 2);
 }
+
+void ChatView::invalidateFilter() {
+  // if this is the currently selected chatview
+  // invalidate immediately
+  if(isVisible()) {
+    _scene->filter()->invalidateFilter();
+    _invalidateFilter = false;
+  }
+  // otherwise invalidate whenever the view is shown
+  else {
+    _invalidateFilter = true;
+  }
+}