Handle client state a bit more sanely
[quassel.git] / src / qtui / chatview.cpp
index 4c3994f..e7386ef 100644 (file)
@@ -36,7 +36,8 @@ ChatView::ChatView(BufferId bufferId, QWidget *parent)
   : QGraphicsView(parent),
     AbstractChatView(),
     _bufferContainer(0),
-    _currentScaleFactor(1)
+    _currentScaleFactor(1),
+    _invalidateFilter(false)
 {
   QList<BufferId> filterList;
   filterList.append(bufferId);
@@ -48,7 +49,8 @@ ChatView::ChatView(MessageFilter *filter, QWidget *parent)
   : QGraphicsView(parent),
     AbstractChatView(),
     _bufferContainer(0),
-    _currentScaleFactor(1)
+    _currentScaleFactor(1),
+    _invalidateFilter(false)
 {
   init(filter);
 }
@@ -76,8 +78,8 @@ void ChatView::init(MessageFilter *filter) {
   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()), filter, SLOT(invalidateFilter()));
+  if(Client::isConnected())
+    connect(Client::ignoreListManager(), SIGNAL(ignoreListChanged()), this, SLOT(invalidateFilter()));
 }
 
 bool ChatView::event(QEvent *event) {
@@ -89,8 +91,8 @@ bool ChatView::event(QEvent *event) {
     case Qt::Key_PageUp:
     case Qt::Key_PageDown:
       if(!verticalScrollBar()->isVisible()) {
-       scene()->requestBacklog();
-       return true;
+        scene()->requestBacklog();
+        return true;
       }
     default:
       break;
@@ -104,6 +106,11 @@ bool ChatView::event(QEvent *event) {
     }
   }
 
+  if(event->type() == QEvent::Show) {
+    if(_invalidateFilter)
+      invalidateFilter();
+  }
+
   return QGraphicsView::event(event);
 }
 
@@ -213,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;
+  }
+}