From 0ddf722e08a5f18c115c84cd83e78b5c7ef8a3a3 Mon Sep 17 00:00:00 2001 From: Jekyll Wu Date: Sat, 27 Aug 2011 00:10:58 +0800 Subject: [PATCH] Disable clear & reset actions when the secondary screen is in use. BUG:204741 FIXED-IN: 4.8 --- src/Emulation.cpp | 7 +++++++ src/Emulation.h | 9 +++++++++ src/Session.cpp | 8 ++++++++ src/Session.h | 13 +++++++++++++ src/SessionController.cpp | 11 +++++++++++ src/SessionController.h | 5 +++++ src/ViewManager.cpp | 2 ++ 7 files changed, 55 insertions(+) diff --git a/src/Emulation.cpp b/src/Emulation.cpp index 30edd6d16..5473f9d0a 100644 --- a/src/Emulation.cpp +++ b/src/Emulation.cpp @@ -99,6 +99,11 @@ ScreenWindow* Emulation::createWindow() return window; } +void Emulation::checkScreenInUse() +{ + emit primaryScreenInUse( _currentScreen == _screen[0] ); +} + Emulation::~Emulation() { QListIterator windowIter(_windows); @@ -122,6 +127,8 @@ void Emulation::setScreen(int n) // tell all windows onto this emulation to switch to the newly active screen foreach(ScreenWindow* window,_windows) window->setScreen(_currentScreen); + + checkScreenInUse(); } } diff --git a/src/Emulation.h b/src/Emulation.h index cb5fbcfa8..7c22e843c 100644 --- a/src/Emulation.h +++ b/src/Emulation.h @@ -404,6 +404,12 @@ signals: */ void flowControlKeyPressed(bool suspendKeyPressed); + /** + * Emitted when the active screen is switched, to indicate whether the primary + * screen is in use. + */ + void primaryScreenInUse(bool use); + protected: virtual void setMode(int mode) = 0; virtual void resetMode(int mode) = 0; @@ -456,6 +462,9 @@ protected slots: */ void bufferedUpdate(); + // used to emit the primaryScreenInUse(bool) signal + void checkScreenInUse(); + private slots: // triggered by timer, causes the emulation to send an updated screen image to each diff --git a/src/Session.cpp b/src/Session.cpp index a9b849097..09f0e4a1a 100644 --- a/src/Session.cpp +++ b/src/Session.cpp @@ -140,6 +140,8 @@ Session::Session(QObject* parent) : this, SIGNAL(profileChangeCommandReceived(QString)) ); connect( _emulation, SIGNAL(flowControlKeyPressed(bool)) , this, SLOT(updateFlowControlState(bool)) ); + connect( _emulation, SIGNAL(primaryScreenInUse(bool)) , this, + SLOT(onPrimaryScreenInUse(bool)) ); //create new teletype for I/O with shell process openTeletype(-1); @@ -613,6 +615,12 @@ void Session::updateFlowControlState(bool suspended) display->outputSuspended(false); } } + +void Session::onPrimaryScreenInUse(bool use) +{ + emit primaryScreenInUse(use); +} + void Session::activityStateSet(int state) { if (state == NOTIFYBELL) diff --git a/src/Session.h b/src/Session.h index 2060bb52f..ea2702ecf 100644 --- a/src/Session.h +++ b/src/Session.h @@ -576,6 +576,15 @@ signals: */ void flowControlEnabledChanged(bool enabled); + /** + * Emitted when the active screen is swiched, to indicate whether the primary + * screen is in use. + * + * This signal serves as a relayer of Emulation::priamyScreenInUse(bool), + * making it usable for higher level component. + */ + void primaryScreenInUse( bool use); + private slots: void done(int, QProcess::ExitStatus); @@ -598,6 +607,10 @@ private slots: void updateFlowControlState(bool suspended); void updateWindowSize(int lines, int columns); + + // signal relayer + void onPrimaryScreenInUse(bool use); + private: void updateTerminalSize(); diff --git a/src/SessionController.cpp b/src/SessionController.cpp index fbb853149..f54892556 100644 --- a/src/SessionController.cpp +++ b/src/SessionController.cpp @@ -292,6 +292,17 @@ void SessionController::openUrl( const KUrl& url ) } } +void SessionController::setupPrimaryScreenSpecificActions( bool use) +{ + KActionCollection * collection = actionCollection() ; + QAction * clearAction = collection->action("clear-history"); + QAction * resetAction = collection->action("clear-history-and-reset"); + + // these actions are meaningful only when primary screen is used. + clearAction->setEnabled(use); + resetAction->setEnabled(use); +} + bool SessionController::eventFilter(QObject* watched , QEvent* event) { if ( watched == _view ) diff --git a/src/SessionController.h b/src/SessionController.h index 8ae33cfdb..6cc492f72 100644 --- a/src/SessionController.h +++ b/src/SessionController.h @@ -158,6 +158,11 @@ public slots: */ void openUrl( const KUrl& url ); + /** + * update actions which are meaningful only when rimary screen is in use. + */ + void setupPrimaryScreenSpecificActions( bool use); + private slots: // menu item handlers void openBrowser(); diff --git a/src/ViewManager.cpp b/src/ViewManager.cpp index 26d427031..9e61f193b 100644 --- a/src/ViewManager.cpp +++ b/src/ViewManager.cpp @@ -520,6 +520,8 @@ SessionController* ViewManager::createController(Session* session , TerminalDisp SessionController* controller = new SessionController(session,view,this); connect( controller , SIGNAL(focused(SessionController*)) , this , SLOT(controllerChanged(SessionController*)) ); connect( session , SIGNAL(destroyed()) , controller , SLOT(deleteLater()) ); + connect( session , SIGNAL(primaryScreenInUse(bool)) , + controller , SLOT(setupPrimaryScreenSpecificActions(bool)) ); connect( view , SIGNAL(destroyed()) , controller , SLOT(deleteLater()) ); // if this is the first controller created then set it as the active controller