From 7582ce11d6fb8b5123f7ac4794c57e981a634e93 Mon Sep 17 00:00:00 2001 From: Manuel Nickschas Date: Tue, 13 Apr 2010 23:18:22 +0200 Subject: [PATCH] Close notifications on other connected clients as well Client now emits a bufferMarkedAsRead() signal that is used for triggering the closing of notifications. This is synced between clients. This requires both uptodate clients and core and will spam your log with warnings if one is too old (but continue to work like it used to). "Too old" means "does not contain this commit", i.e. a 0.6.0 client will work fine with a git master core and the other way round, but earlier versions won't. --- src/client/client.cpp | 6 ++++++ src/client/client.h | 9 +++++++++ src/common/buffersyncer.h | 4 ++++ src/core/corebuffersyncer.h | 2 ++ src/qtui/mainwin.cpp | 6 +++--- src/qtui/qtui.cpp | 7 +++++++ src/qtui/qtui.h | 8 +++++--- 7 files changed, 36 insertions(+), 6 deletions(-) diff --git a/src/client/client.cpp b/src/client/client.cpp index 07b3c265..c5d4e50c 100644 --- a/src/client/client.cpp +++ b/src/client/client.cpp @@ -321,6 +321,7 @@ void Client::setSyncedToCore() { connect(bufferSyncer(), SIGNAL(bufferRenamed(BufferId, QString)), this, SLOT(bufferRenamed(BufferId, QString))); connect(bufferSyncer(), SIGNAL(buffersPermanentlyMerged(BufferId, BufferId)), this, SLOT(buffersPermanentlyMerged(BufferId, BufferId))); connect(bufferSyncer(), SIGNAL(buffersPermanentlyMerged(BufferId, BufferId)), _messageModel, SLOT(buffersPermanentlyMerged(BufferId, BufferId))); + connect(bufferSyncer(), SIGNAL(bufferMarkedAsRead(BufferId)), SIGNAL(bufferMarkedAsRead(BufferId))); connect(networkModel(), SIGNAL(setLastSeenMsg(BufferId, MsgId)), bufferSyncer(), SLOT(requestSetLastSeenMsg(BufferId, const MsgId &))); signalProxy()->synchronize(bufferSyncer()); @@ -532,6 +533,11 @@ void Client::buffersPermanentlyMerged(BufferId bufferId1, BufferId bufferId2) { networkModel()->removeBuffer(bufferId2); } +void Client::markBufferAsRead(BufferId id) { + if(id.isValid()) + bufferSyncer()->requestMarkBufferAsRead(id); +} + void Client::logMessage(QtMsgType type, const char *msg) { fprintf(stderr, "%s\n", msg); fflush(stderr); diff --git a/src/client/client.h b/src/client/client.h index e401f463..30ef2d9f 100644 --- a/src/client/client.h +++ b/src/client/client.h @@ -171,6 +171,13 @@ signals: void logUpdated(const QString &msg); + //! Emitted when a buffer has been marked as read + /** This is currently triggered by setting lastSeenMsg, either local or remote, + * or by bringing the window to front. + * \param id The buffer that has been marked as read + */ + void bufferMarkedAsRead(BufferId id); + public slots: void disconnectFromCore(); @@ -178,6 +185,8 @@ public slots: void bufferRenamed(BufferId bufferId, const QString &newName); void buffersPermanentlyMerged(BufferId bufferId1, BufferId bufferId2); + void markBufferAsRead(BufferId id); + private slots: void setSyncedToCore(); void setDisconnectedFromCore(); diff --git a/src/common/buffersyncer.h b/src/common/buffersyncer.h index 55198288..3de31db7 100644 --- a/src/common/buffersyncer.h +++ b/src/common/buffersyncer.h @@ -58,12 +58,16 @@ public slots: virtual inline void requestPurgeBufferIds() { REQUEST(NO_ARG); } + virtual inline void requestMarkBufferAsRead(BufferId buffer) { REQUEST(ARG(buffer)) emit bufferMarkedAsRead(buffer); } + virtual inline void markBufferAsRead(BufferId buffer) { SYNC(ARG(buffer)) emit bufferMarkedAsRead(buffer); } + signals: void lastSeenMsgSet(BufferId buffer, const MsgId &msgId); void markerLineSet(BufferId buffer, const MsgId &msgId); void bufferRemoved(BufferId buffer); void bufferRenamed(BufferId buffer, QString newName); void buffersPermanentlyMerged(BufferId buffer1, BufferId buffer2); + void bufferMarkedAsRead(BufferId buffer); protected slots: bool setLastSeenMsg(BufferId buffer, const MsgId &msgId); diff --git a/src/core/corebuffersyncer.h b/src/core/corebuffersyncer.h index 89694bf6..cb58b0ac 100644 --- a/src/core/corebuffersyncer.h +++ b/src/core/corebuffersyncer.h @@ -47,6 +47,8 @@ public slots: virtual void requestPurgeBufferIds(); + virtual inline void requestMarkBufferAsRead(BufferId buffer) { markBufferAsRead(buffer); } + void storeDirtyIds(); protected: diff --git a/src/qtui/mainwin.cpp b/src/qtui/mainwin.cpp index b35cad82..e1d961cd 100644 --- a/src/qtui/mainwin.cpp +++ b/src/qtui/mainwin.cpp @@ -996,7 +996,7 @@ bool MainWin::event(QEvent *event) { if(event->type() == QEvent::WindowActivate) { BufferId buffer = Client::bufferModel()->currentBuffer(); if(buffer.isValid()) - QtUi::closeNotifications(buffer); + Client::instance()->markBufferAsRead(buffer); } return QMainWindow::event(event); } @@ -1067,14 +1067,14 @@ void MainWin::messagesInserted(const QModelIndex &parent, int start, int end) { else type = AbstractNotificationBackend::HighlightFocused; - QtUi::invokeNotification(bufId, type, sender, contents); + QtUi::instance()->invokeNotification(bufId, type, sender, contents); } } } void MainWin::currentBufferChanged(BufferId buffer) { if(buffer.isValid()) - QtUi::closeNotifications(buffer); + Client::instance()->markBufferAsRead(buffer); } void MainWin::clientNetworkCreated(NetworkId id) { diff --git a/src/qtui/qtui.cpp b/src/qtui/qtui.cpp index f3bb9a6d..88448486 100644 --- a/src/qtui/qtui.cpp +++ b/src/qtui/qtui.cpp @@ -62,6 +62,7 @@ QtUi::QtUi() : GraphicalUi() { connect(_mainWin, SIGNAL(connectToCore(const QVariantMap &)), this, SIGNAL(connectToCore(const QVariantMap &))); connect(_mainWin, SIGNAL(disconnectFromCore()), this, SIGNAL(disconnectFromCore())); + connect(Client::instance(), SIGNAL(bufferMarkedAsRead(BufferId)), SLOT(closeNotifications(BufferId))); } QtUi::~QtUi() { @@ -200,3 +201,9 @@ void QtUi::notificationActivated(uint notificationId) { activateMainWidget(); } + +void QtUi::bufferMarkedAsRead(BufferId bufferId) { + if(bufferId.isValid()) { + closeNotifications(bufferId); + } +} diff --git a/src/qtui/qtui.h b/src/qtui/qtui.h index 44c47411..437cc153 100644 --- a/src/qtui/qtui.h +++ b/src/qtui/qtui.h @@ -56,18 +56,20 @@ public: static void unregisterNotificationBackend(AbstractNotificationBackend *); static void unregisterAllNotificationBackends(); static const QList ¬ificationBackends(); - static uint invokeNotification(BufferId bufId, AbstractNotificationBackend::NotificationType type, const QString &sender, const QString &text); - static void closeNotification(uint notificationId); - static void closeNotifications(BufferId bufferId = BufferId()); static const QList &activeNotifications(); public slots: virtual void init(); + uint invokeNotification(BufferId bufId, AbstractNotificationBackend::NotificationType type, const QString &sender, const QString &text); + void closeNotification(uint notificationId); + void closeNotifications(BufferId bufferId = BufferId()); + protected slots: void connectedToCore(); void disconnectedFromCore(); void notificationActivated(uint notificationId); + void bufferMarkedAsRead(BufferId); protected: virtual void minimizeRestore(bool show); -- 2.20.1