Close notifications on buffer switch rather than activation change
authorManuel Nickschas <sputnick@quassel-irc.org>
Thu, 10 Sep 2009 19:23:50 +0000 (21:23 +0200)
committerManuel Nickschas <sputnick@quassel-irc.org>
Thu, 10 Sep 2009 19:31:24 +0000 (21:31 +0200)
We now properly close only the notifications that refer to the current buffer if you switch to
it or activate the window. Before, we closed all active notifications when the window got
activated (and only then).

src/client/buffermodel.h
src/qtui/mainwin.cpp
src/qtui/mainwin.h

index 9a94fbe..d863dc9 100644 (file)
 #include <QItemSelectionModel>
 
 #include "network.h"
 #include <QItemSelectionModel>
 
 #include "network.h"
+#include "networkmodel.h"
 #include "types.h"
 #include "selectionmodelsynchronizer.h"
 
 #include "types.h"
 #include "selectionmodelsynchronizer.h"
 
-class NetworkModel;
 class QAbstractItemView;
 
 class BufferModel : public QSortFilterProxyModel {
 class QAbstractItemView;
 
 class BufferModel : public QSortFilterProxyModel {
@@ -46,6 +46,7 @@ public:
   void synchronizeView(QAbstractItemView *view);
 
   inline QModelIndex currentIndex() { return standardSelectionModel()->currentIndex(); }
   void synchronizeView(QAbstractItemView *view);
 
   inline QModelIndex currentIndex() { return standardSelectionModel()->currentIndex(); }
+  inline BufferId currentBuffer() { return currentIndex().data(NetworkModel::BufferIdRole).value<BufferId>(); }
 
 public slots:
   void setCurrentIndex(const QModelIndex &newCurrent);
 
 public slots:
   void setCurrentIndex(const QModelIndex &newCurrent);
index 0431468..1f6d17e 100644 (file)
@@ -184,6 +184,8 @@ void MainWin::init() {
   QtUi::registerNotificationBackend(new KNotificationBackend(this));
 #endif /* HAVE_KDE */
 
   QtUi::registerNotificationBackend(new KNotificationBackend(this));
 #endif /* HAVE_KDE */
 
+  connect(bufferWidget(), SIGNAL(currentChanged(BufferId)), SLOT(currentBufferChanged(BufferId)));
+
   setDisconnectedState();  // Disable menus and stuff
 
 #ifdef HAVE_KDE
   setDisconnectedState();  // Disable menus and stuff
 
 #ifdef HAVE_KDE
@@ -868,8 +870,11 @@ void MainWin::showShortcutsDlg() {
 /********************************************************************************************************/
 
 bool MainWin::event(QEvent *event) {
 /********************************************************************************************************/
 
 bool MainWin::event(QEvent *event) {
-  if(event->type() == QEvent::WindowActivate)
-    QtUi::closeNotifications();
+  if(event->type() == QEvent::WindowActivate) {
+    BufferId buffer = Client::bufferModel()->currentBuffer();
+    if(buffer.isValid())
+      QtUi::closeNotifications(buffer);
+  }
   return QMainWindow::event(event);
 }
 
   return QMainWindow::event(event);
 }
 
@@ -977,7 +982,7 @@ void MainWin::messagesInserted(const QModelIndex &parent, int start, int end) {
     BufferId bufId = idx.data(ChatLineModel::BufferIdRole).value<BufferId>();
     BufferInfo::Type bufType = Client::networkModel()->bufferType(bufId);
 
     BufferId bufId = idx.data(ChatLineModel::BufferIdRole).value<BufferId>();
     BufferInfo::Type bufType = Client::networkModel()->bufferType(bufId);
 
-    if(hasFocus && bufId == _bufferWidget->currentBuffer())
+    if(hasFocus && bufId == Client::bufferModel()->currentBuffer())
       continue;
 
     if((flags & Message::Highlight || bufType == BufferInfo::QueryBuffer)
       continue;
 
     if((flags & Message::Highlight || bufType == BufferInfo::QueryBuffer)
@@ -1003,6 +1008,11 @@ void MainWin::messagesInserted(const QModelIndex &parent, int start, int end) {
   }
 }
 
   }
 }
 
+void MainWin::currentBufferChanged(BufferId buffer) {
+  if(buffer.isValid())
+    QtUi::closeNotifications(buffer);
+}
+
 void MainWin::clientNetworkCreated(NetworkId id) {
   const Network *net = Client::network(id);
   QAction *act = new QAction(net->networkName(), this);
 void MainWin::clientNetworkCreated(NetworkId id) {
   const Network *net = Client::network(id);
   QAction *act = new QAction(net->networkName(), this);
index 63c0ca0..361467a 100644 (file)
@@ -73,6 +73,8 @@ class MainWin
     void addBufferView(ClientBufferViewConfig *config);
     BufferView *allBuffersView() const;
 
     void addBufferView(ClientBufferViewConfig *config);
     BufferView *allBuffersView() const;
 
+    BufferWidget *bufferWidget() const { return _bufferWidget; }
+
     inline SystemTray *systemTray() const;
 
     bool event(QEvent *event);
     inline SystemTray *systemTray() const;
 
     bool event(QEvent *event);
@@ -111,6 +113,7 @@ class MainWin
     void addBufferView(int bufferViewConfigId);
     void awayLogDestroyed();
     void removeBufferView(int bufferViewConfigId);
     void addBufferView(int bufferViewConfigId);
     void awayLogDestroyed();
     void removeBufferView(int bufferViewConfigId);
+    void currentBufferChanged(BufferId);
     void messagesInserted(const QModelIndex &parent, int start, int end);
     void showAboutDlg();
     void showChannelList(NetworkId netId = NetworkId());
     void messagesInserted(const QModelIndex &parent, int start, int end);
     void showAboutDlg();
     void showChannelList(NetworkId netId = NetworkId());