From c2cf63c483e78f899b1c1b5643f766b9828a0355 Mon Sep 17 00:00:00 2001 From: Stephan Binner Date: Sun, 23 Sep 2001 15:03:53 +0000 Subject: [PATCH] Implemented "Monitor for Activity" and "Monitor for Silence" (#16377, #20737, #30585) TEmulation only calls Bell in TEWidget if connected but always displays bell in toolbar. Changed credits. svn path=/trunk/kdebase/konsole/; revision=115167 --- konsole/TEmuVt102.cpp | 7 ++++++- konsole/TEmulation.cpp | 8 +++++++- konsole/TEmulation.h | 3 +++ konsole/konsole.cpp | 39 ++++++++++++++++++++++++++++++++++++ konsole/konsole.h | 5 +++++ konsole/main.cpp | 3 +++ konsole/session.cpp | 45 +++++++++++++++++++++++++++++++++++++++++- konsole/session.h | 11 +++++++++++ 8 files changed, 118 insertions(+), 3 deletions(-) diff --git a/konsole/TEmuVt102.cpp b/konsole/TEmuVt102.cpp index 1b22ed27..f920e9f9 100644 --- a/konsole/TEmuVt102.cpp +++ b/konsole/TEmuVt102.cpp @@ -267,6 +267,7 @@ void TEmuVt102::initTokenizer() void TEmuVt102::onRcvChar(int cc) { int i; + emit notifySessionState(NOTIFYACTIVITY); if (cc == 127) return; //VT100: ignore. @@ -367,7 +368,10 @@ void TEmuVt102::tau( int token, int p, int q ) case TY_CTL___('D' ) : /* EOT: ignored */ break; case TY_CTL___('E' ) : reportAnswerBack ( ); break; //VT100 case TY_CTL___('F' ) : /* ACK: ignored */ break; - case TY_CTL___('G' ) : gui->Bell ( ); break; //VT100 + case TY_CTL___('G' ) : if (connected) + gui->Bell ( ); + emit notifySessionState(NOTIFYBELL); + break; //VT100 case TY_CTL___('H' ) : scr->BackSpace ( ); break; //VT100 case TY_CTL___('I' ) : scr->Tabulate ( ); break; //VT100 case TY_CTL___('J' ) : scr->NewLine ( ); break; //VT100 @@ -793,6 +797,7 @@ void TEmuVt102::onScrollLock() void TEmuVt102::onKeyPress( QKeyEvent* ev ) { if (!connected) return; // someone else gets the keys + emit notifySessionState(NOTIFYNORMAL); //printf("State/Key: 0x%04x 0x%04x (%d,%d)\n",ev->state(),ev->key(),ev->text().length(),ev->text().length()?ev->text().ascii()[0]:0); diff --git a/konsole/TEmulation.cpp b/konsole/TEmulation.cpp index e6b4a62a..143e08b0 100644 --- a/konsole/TEmulation.cpp +++ b/konsole/TEmulation.cpp @@ -202,6 +202,8 @@ void TEmulation::onRcvChar(int c) // process application unicode input to terminal // this is a trivial scanner { + emit notifySessionState(NOTIFYACTIVITY); + c &= 0xff; switch (c) { @@ -209,7 +211,10 @@ void TEmulation::onRcvChar(int c) case '\t' : scr->Tabulate(); break; case '\n' : scr->NewLine(); break; case '\r' : scr->Return(); break; - case 0x07 : gui->Bell(); break; + case 0x07 : if (connected) + gui->Bell(); + emit notifySessionState(NOTIFYBELL); + break; default : scr->ShowCharacter(c); break; }; } @@ -226,6 +231,7 @@ void TEmulation::onRcvChar(int c) void TEmulation::onKeyPress( QKeyEvent* ev ) { if (!connected) return; // someone else gets the keys + emit notifySessionState(NOTIFYNORMAL); if (scr->getHistCursor() != scr->getHistLines()); scr->setHistCursor(scr->getHistLines()); if (!ev->text().isEmpty()) diff --git a/konsole/TEmulation.h b/konsole/TEmulation.h index a0d8c37b..75828f40 100644 --- a/konsole/TEmulation.h +++ b/konsole/TEmulation.h @@ -20,6 +20,8 @@ #include #include +enum { NOTIFYNORMAL=0, NOTIFYBELL=1, NOTIFYACTIVITY=2, NOTIFYSILENCE=3 }; + class TEmulation : public QObject { Q_OBJECT @@ -54,6 +56,7 @@ signals: void ImageSizeChanged(int lines, int columns); void changeColumns(int columns); void changeTitle(int arg, const char* str); + void notifySessionState(int state); public: diff --git a/konsole/konsole.cpp b/konsole/konsole.cpp index e7c47601..eebd5651 100644 --- a/konsole/konsole.cpp +++ b/konsole/konsole.cpp @@ -195,6 +195,8 @@ Konsole::Konsole(const char* name, const QString& _program, ,m_toolbarSessionsCommands(0) ,m_signals(0) ,m_help(0) +,monitorActivity(0) +,monitorSilence(0) ,showToolbar(0) ,showMenubar(0) ,showScrollbar(0) @@ -371,6 +373,14 @@ void Konsole::makeGUI() SLOT(slotRenameSession()), this); renameSession->plug(m_sessions); + monitorActivity = new KToggleAction ( i18n( "Monitor for Activity" ), "idea", 0, this, + SLOT( slotToggleMonitor() ), this ); + monitorActivity->plug ( m_sessions ); + + monitorSilence = new KToggleAction ( i18n( "Monitor for Silence" ), "ktip", 0, this, + SLOT( slotToggleMonitor() ), this ); + monitorSilence->plug ( m_sessions ); + m_clearHistory = new KAction(i18n("Clear &History"), "history_clear", 0, this, SLOT(slotClearHistory()), this); m_clearHistory->setEnabled( se->history().isOn() ); @@ -1438,6 +1448,7 @@ void Konsole::activateSession(TESession *s) QObject::disconnect( se->getEmulation(),SIGNAL(activateMenu()), this,SLOT(activateMenu()) ); QObject::disconnect( se->getEmulation(),SIGNAL(moveSessionLeft()), this,SLOT(moveSessionLeft()) ); QObject::disconnect( se->getEmulation(),SIGNAL(moveSessionRight()), this,SLOT(moveSessionRight()) ); + notifySessionState(se,NOTIFYNORMAL); // Delete the session if isn't in the session list any longer. if (sessions.find(se) == -1) delete se; @@ -1463,6 +1474,8 @@ void Konsole::activateSession(TESession *s) updateKeytabMenu(); // act. the keytab for this session m_clearHistory->setEnabled( se->history().isOn() ); m_saveHistory->setEnabled( se->history().isOn() ); + monitorActivity->setChecked( se->isMonitorActivity() ); + monitorSilence->setChecked( se->isMonitorSilence() ); sessions.find(se); uint position=sessions.at(); m_moveSessionLeft->setEnabled(position>0); @@ -1477,6 +1490,7 @@ void Konsole::allowPrevNext() QObject::connect( se->getEmulation(),SIGNAL(activateMenu()), this,SLOT(activateMenu()) ); QObject::connect( se->getEmulation(),SIGNAL(moveSessionLeft()), this,SLOT(moveSessionLeft()) ); QObject::connect( se->getEmulation(),SIGNAL(moveSessionRight()), this,SLOT(moveSessionRight()) ); + notifySessionState(se,NOTIFYNORMAL); } KSimpleConfig *Konsole::defaultSession() @@ -1563,6 +1577,8 @@ TESession *Konsole::newSession(KSimpleConfig *co, QString program, const QStrLis this, SLOT(configureRequest(TEWidget*,int,int,int)) ); connect( s, SIGNAL( updateTitle() ), this, SLOT( updateTitle() ) ); + connect( s, SIGNAL( notifySessionState(TESession*, int) ), + this, SLOT( notifySessionState(TESession*, int)) ); s->setFontNo(QMIN(fno, TOPFONT)); s->setSchemaNo(schmno); @@ -1723,6 +1739,29 @@ void Konsole::moveSessionRight() m_moveSessionRight->setEnabled(position+1setMonitorActivity( monitorActivity->isChecked() ); + se->setMonitorSilence( monitorSilence->isChecked() ); + notifySessionState(se,NOTIFYNORMAL); +} + +void Konsole::notifySessionState(TESession* session, int state) +{ + int button_id=-(sessions.find(session)+3); + KToolBarButton* ktb=toolBar()->getButton(button_id); + switch(state) + { + case NOTIFYNORMAL : ktb->setIcon("openterm"); + break; + case NOTIFYBELL : ktb->setIcon("bell"); + break; + case NOTIFYACTIVITY: ktb->setIcon("idea"); + break; + case NOTIFYSILENCE : ktb->setIcon("ktip"); + } +} + // --| Session support |------------------------------------------------------- void Konsole::clearSessionHistory(TESession & session) diff --git a/konsole/konsole.h b/konsole/konsole.h index 0b30fee0..521f5a04 100644 --- a/konsole/konsole.h +++ b/konsole/konsole.h @@ -99,6 +99,7 @@ private slots: void updateKeytabMenu(); void changeColumns(int); + void notifySessionState(TESession* session,int state); void notifySize(int,int); void updateTitle(); void prevSession(); @@ -114,6 +115,7 @@ private slots: void slotToggleFrame(); void slotRenameSession(); void slotRenameSession(int); + void slotToggleMonitor(); void slotClearAllSessionHistories(); void slotHistoryType(); void slotClearHistory(); @@ -175,10 +177,13 @@ private: KPopupMenu* m_signals; KPopupMenu* m_help; + KToggleAction *monitorActivity; + KToggleAction *monitorSilence; KToggleAction *showToolbar; KToggleAction *showMenubar; KToggleAction *showScrollbar; KToggleAction *showFrame; + KSelectAction *selectSize; KSelectAction *selectFont; KSelectAction *selectScrollbar; diff --git a/konsole/main.cpp b/konsole/main.cpp index ed96ad6f..afea2454 100644 --- a/konsole/main.cpp +++ b/konsole/main.cpp @@ -174,6 +174,9 @@ int main(int argc, char* argv[]) aboutData.addCredit("Stephan Kulow", I18N_NOOP("Solaris support and work on history"), "coolo@kde.org"); + aboutData.addCredit("Stephan Binner", + I18N_NOOP("bug fixing and improvements"), + "stephan.binner@gmx.de"); aboutData.addCredit("",I18N_NOOP("Thanks to many others.\n" "The above list only reflects the contributors\n" "I managed to keep track of.")); diff --git a/konsole/session.cpp b/konsole/session.cpp index 92233e9d..c820d2f4 100644 --- a/konsole/session.cpp +++ b/konsole/session.cpp @@ -8,6 +8,8 @@ #define HERE fprintf(stderr,"%s(%d): here\n",__FILE__,__LINE__) #endif +#define SILENCE_TIMEOUT 10000 // milliseconds + /*! \class TESession Sessions are combinations of TEPTy and Emulations. @@ -19,7 +21,9 @@ */ TESession::TESession(KMainWindow* main, TEWidget* te, const QString &_pgm, QStrList & _args, const QString &_term) - : schema_no(0) + : monitorActivity(false) + , monitorSilence(false) + , schema_no(0) , font_no(3) , pgm(_pgm) , args(_args) @@ -48,6 +52,11 @@ TESession::TESession(KMainWindow* main, TEWidget* te, const QString &_pgm, QStrL connect( em, SIGNAL( changeTitle( int, const QString & ) ), this, SLOT( setUserTitle( int, const QString & ) ) ); + connect( em, SIGNAL( notifySessionState(int) ), + this, SLOT( notifySessionState(int) ) ); + monitorTimer = new QTimer(this); + connect(monitorTimer, SIGNAL(timeout()), this, SLOT(monitorTimerDone())); + connect( sh,SIGNAL(done(int)), this,SLOT(done(int)) ); //kdDebug(1211)<<"TESession ctor() done"<start(SILENCE_TIMEOUT,true); +} + +void TESession::notifySessionState(int state) +{ + if (state==NOTIFYACTIVITY) { + if (monitorSilence) { + monitorTimer->stop(); + monitorTimer->start(SILENCE_TIMEOUT,true); + } + if (!monitorActivity) + return; + } + + emit notifySessionState(this, state); +} void TESession::kill(int signal) { @@ -203,5 +231,20 @@ QString TESession::getPgm() return pgm; } +bool TESession::isMonitorActivity() { return monitorActivity; } +bool TESession::isMonitorSilence() { return monitorSilence; } + +void TESession::setMonitorActivity(bool _monitor) { monitorActivity=_monitor; } +void TESession::setMonitorSilence(bool _monitor) +{ + if (monitorSilence==_monitor) + return; + + monitorSilence=_monitor; + if (monitorSilence) + monitorTimer->start(SILENCE_TIMEOUT,true); + else + monitorTimer->stop(); +} #include "session.moc" diff --git a/konsole/session.h b/konsole/session.h index 4d38b3d2..416664a5 100644 --- a/konsole/session.h +++ b/konsole/session.h @@ -36,6 +36,8 @@ public: void setConnect(bool r); TEmulation* getEmulation(); // to control emulation bool isSecure(); + bool isMonitorActivity(); + bool isMonitorSilence(); int schemaNo(); int fontNo(); const QString& Term(); @@ -50,6 +52,8 @@ public: void setHistory(const HistoryType&); const HistoryType& history(); + void setMonitorActivity(bool); + void setMonitorSilence(bool); void setSchemaNo(int sn); void setKeymapNo(int kn); void setKeymap(const QString& _id); @@ -68,9 +72,12 @@ signals: void done(TESession*, int); void updateTitle(); + void notifySessionState(TESession* session, int state); private slots: void setUserTitle( int, const QString &caption ); + void monitorTimerDone(); + void notifySessionState(int state); private: @@ -78,6 +85,10 @@ private: TEWidget* te; TEmulation* em; + bool monitorActivity; + bool monitorSilence; + QTimer* monitorTimer; + //FIXME: using the indices here // is propably very bad. We should // use a persistent reference instead.