From e2de7c3125afa9232140505646cba7bb3c954dcf Mon Sep 17 00:00:00 2001 From: Jekyll Wu Date: Thu, 16 Feb 2012 07:45:44 +0800 Subject: [PATCH] The icon for activity/silence should stay on tab until interaction This is a follow-up of commit 5a24215022d6efb99b6dd400215e5f8fd9dc41c0 to deal with its side effect with the feature of monitoring activity/silence --- src/SessionController.cpp | 29 ++++++++++++++++++++++------- src/SessionController.h | 5 +++++ 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/src/SessionController.cpp b/src/SessionController.cpp index cba192f01..aabc1d047 100644 --- a/src/SessionController.cpp +++ b/src/SessionController.cpp @@ -97,6 +97,7 @@ SessionController::SessionController(Session* session , TerminalDisplay* view, Q , _switchProfileMenu(0) , _listenForScreenWindowUpdates(false) , _preventClose(false) + , _keepIconUntilInteraction(false) { Q_ASSERT(session); Q_ASSERT(view); @@ -161,11 +162,11 @@ SessionController::SessionController(Session* session , TerminalDisplay* view, Q // // the timer is owned by the session so that it will be destroyed along // with the session - QTimer* activityTimer = new QTimer(_session); - activityTimer->setSingleShot(true); - activityTimer->setInterval(2000); - connect(_view, SIGNAL(keyPressedSignal(QKeyEvent*)), activityTimer, SLOT(start())); - connect(activityTimer, SIGNAL(timeout()), this, SLOT(snapshot())); + _interactionTimer = new QTimer(_session); + _interactionTimer->setSingleShot(true); + _interactionTimer->setInterval(2000); + connect(_interactionTimer, SIGNAL(timeout()), this, SLOT(snapshot())); + connect(_view, SIGNAL(keyPressedSignal(QKeyEvent*)), this, SLOT(interactionHandler())); // take a snapshot of the session state periodically in the background QTimer* backgroundTimer = new QTimer(_session); @@ -200,6 +201,16 @@ void SessionController::trackOutput(QKeyEvent* event) _view->screenWindow()->setTrackOutput(true); } } +void SessionController::interactionHandler() +{ + // This flag is used to make sure those special icons indicating interest + // events (activity/silence/bell?) remain in the tab until user interaction + // happens. Otherwise, those special icons will quickly be replaced by + // normal icon when ::snapshot() is triggered + _keepIconUntilInteraction = false; + _interactionTimer->start(); +} + void SessionController::requireUrlFilterUpdate() { // this method is called every time the screen window's output changes, so do not @@ -1076,8 +1087,10 @@ void SessionController::updateSessionIcon() // Master Mode: set different icon, to warn the user to be careful setIcon(_broadcastIcon); } else { - // Not in Master Mode: use normal icon - setIcon(_sessionIcon); + if (!_keepIconUntilInteraction) { + // Not in Master Mode: use normal icon + setIcon(_sessionIcon); + } } } void SessionController::sessionTitleChanged() @@ -1162,8 +1175,10 @@ void SessionController::sessionStateChanged(int state) if (state == NOTIFYACTIVITY) { setIcon(_activityIcon); + _keepIconUntilInteraction = true; } else if (state == NOTIFYSILENCE) { setIcon(_silenceIcon); + _keepIconUntilInteraction = true; } else if (state == NOTIFYNORMAL) { if (_sessionIconName != _session->iconName()) { _sessionIconName = _session->iconName(); diff --git a/src/SessionController.h b/src/SessionController.h index 28867ec41..6749e4553 100644 --- a/src/SessionController.h +++ b/src/SessionController.h @@ -46,6 +46,7 @@ class Job; class QAction; class QTextCodec; class QKeyEvent; +class QTimer; class KCodecAction; class KUrl; @@ -225,6 +226,7 @@ private slots: void searchClosed(); // called when the user clicks on the // history search bar's close button + void interactionHandler(); void snapshot(); // called periodically as the user types // to take a snapshot of the state of the // foreground process in the terminal @@ -281,6 +283,7 @@ private: KAction* _findNextAction; KAction* _findPreviousAction; + QTimer* _interactionTimer; bool _urlFilterUpdateRequired; @@ -293,6 +296,8 @@ private: bool _listenForScreenWindowUpdates; bool _preventClose; + bool _keepIconUntilInteraction; + static QSet _allControllers; static int _lastControllerId; static KIcon _activityIcon;