From 983271c55c9c4f920ba97638baeb02cc2e05be12 Mon Sep 17 00:00:00 2001 From: Robert Knight Date: Fri, 18 May 2007 04:20:57 +0000 Subject: [PATCH] Fix tab title syncing between multiple views of the same session. svn path=/trunk/KDE/kdebase/apps/konsole/; revision=665823 --- src/Session.cpp | 41 ++++++++++++++++++++++++--------------- src/Session.h | 28 +++++++++++++++++++------- src/SessionController.cpp | 21 +++++++++++--------- src/SessionManager.cpp | 4 ++-- 4 files changed, 60 insertions(+), 34 deletions(-) diff --git a/src/Session.cpp b/src/Session.cpp index c12e66bf9..597f91fe0 100644 --- a/src/Session.cpp +++ b/src/Session.cpp @@ -295,10 +295,10 @@ void Session::run() void Session::setUserTitle( int what, const QString &caption ) { - //set to true if anything is actually changed (eg. old _title != new _title ) + //set to true if anything is actually changed (eg. old _nameTitle != new _nameTitle ) bool modified = false; - // (btw: what=0 changes _title and icon, what=1 only icon, what=2 only _title + // (btw: what=0 changes _nameTitle and icon, what=1 only icon, what=2 only _nameTitle if ((what == 0) || (what == 2)) { if ( _userTitle != caption ) { _userTitle = caption; @@ -334,8 +334,8 @@ void Session::setUserTitle( int what, const QString &caption ) } if (what == 30) { - if ( _title != caption ) { - setTitle(caption); + if ( _nameTitle != caption ) { + setTitle(Session::NameRole,caption); return; } } @@ -387,7 +387,7 @@ void Session::monitorTimerDone() //This breaks with the addition of multiple views of a session. The popup should disappear //when any of the views of the session becomes active if (_monitorSilence) { - KNotification::event("Silence", i18n("Silence in session '%1'", _title), QPixmap(), + KNotification::event("Silence", i18n("Silence in session '%1'", _nameTitle), QPixmap(), QApplication::activeWindow(), KNotification::CloseWhenWidgetActivated); emit stateChanged(NOTIFYSILENCE); @@ -404,7 +404,7 @@ void Session::activityStateSet(int state) { if (state==NOTIFYBELL) { - emit bellRequest( i18n("Bell in session '%1'",_title) ); + emit bellRequest( i18n("Bell in session '%1'",_nameTitle) ); } else if (state==NOTIFYACTIVITY) { @@ -415,7 +415,7 @@ void Session::activityStateSet(int state) //FIXME: See comments in Session::monitorTimerDone() if (!_notifiedActivity) { - KNotification::event("Activity", i18n("Activity in session '%1'", _title), QPixmap(), + KNotification::event("Activity", i18n("Activity in session '%1'", _nameTitle), QPixmap(), QApplication::activeWindow(), KNotification::CloseWhenWidgetActivated); _notifiedActivity=true; @@ -507,16 +507,16 @@ void Session::done(int exitStatus) QString message; if (_shellProcess->normalExit()) - message = i18n("Session '%1' exited with status %2.", _title, exitStatus); + message = i18n("Session '%1' exited with status %2.", _nameTitle, exitStatus); else if (_shellProcess->signalled()) { if (_shellProcess->coreDumped()) - message = i18n("Session '%1' exited with signal %2 and dumped core.", _title, _shellProcess->exitSignal()); + message = i18n("Session '%1' exited with signal %2 and dumped core.", _nameTitle, _shellProcess->exitSignal()); else - message = i18n("Session '%1' exited with signal %2.", _title, _shellProcess->exitSignal()); + message = i18n("Session '%1' exited with signal %2.", _nameTitle, _shellProcess->exitSignal()); } else - message = i18n("Session '%1' exited unexpectedly.", _title); + message = i18n("Session '%1' exited unexpectedly.", _nameTitle); //FIXME: See comments in Session::monitorTimerDone() KNotification::event("Finished", message , QPixmap(), @@ -556,18 +556,27 @@ void Session::setKeyBindings(const QString &id) _emulation->setKeyBindings(id); } -void Session::setTitle(const QString& title) +void Session::setTitle(TitleRole role , const QString& newTitle) { - if ( title != _title ) + if ( title(role) != newTitle ) { - _title = title; + if ( role == NameRole ) + _nameTitle = newTitle; + else if ( role == DisplayedTitleRole ) + _displayTitle = newTitle; + emit titleChanged(); } } -QString Session::title() const +QString Session::title(TitleRole role) const { - return _title; + if ( role == NameRole ) + return _nameTitle; + else if ( role == DisplayedTitleRole ) + return _displayTitle; + else + return QString(); } void Session::setIconName(const QString& iconName) diff --git a/src/Session.h b/src/Session.h index 7d8c811f4..fa2ca52bc 100644 --- a/src/Session.h +++ b/src/Session.h @@ -62,7 +62,7 @@ class Session : public QObject Q_OBJECT public: - Q_PROPERTY(QString sessionName READ title) + Q_PROPERTY(QString name READ nameTitle) Q_PROPERTY(int processId READ processId) Q_PROPERTY(QString keytab READ keyBindings WRITE setKeyBindings) Q_PROPERTY(QSize size READ size WRITE setSize) @@ -265,11 +265,24 @@ public: void setKeyBindings(const QString& id); /** Returns the name of the key bindings used by this session. */ QString keyBindings() const; - - /** Sets the session's title to @p title. */ - void setTitle(const QString& title); - /** Returns the session's title. */ - QString title() const; + + /** + * This enum describes the available title roles. + */ + enum TitleRole + { + /** The name of the session. */ + NameRole, + /** The title of the session which is displayed in tabs etc. */ + DisplayedTitleRole + }; + + /** Sets the session's title for the specified @p role to @p title. */ + void setTitle(TitleRole role , const QString& title); + /** Returns the session's title for the specified @p role. */ + QString title(TitleRole role) const; + /** Convenience method used to read the name property. Returns title(Session::NameRole). */ + QString nameTitle() const { return title(Session::NameRole); } /** Sets the name of the icon associated with this session. */ void setIconName(const QString& iconName); @@ -443,7 +456,8 @@ private: int _silenceSeconds; - QString _title; + QString _nameTitle; + QString _displayTitle; QString _userTitle; QString _localTabTitleFormat; diff --git a/src/SessionController.cpp b/src/SessionController.cpp index 0c62c9d85..eb07f40a7 100644 --- a/src/SessionController.cpp +++ b/src/SessionController.cpp @@ -119,7 +119,7 @@ void SessionController::requireUrlFilterUpdate() } void SessionController::snapshot() { - qDebug() << "session" << _session->title() << "snapshot"; + qDebug() << "session" << _session->title(Session::NameRole) << "snapshot"; ProcessInfo* process = 0; @@ -163,9 +163,9 @@ void SessionController::snapshot() // apply new title if ( !title.simplified().isEmpty() ) - setTitle(title); + _session->setTitle(Session::DisplayedTitleRole,title); else - setTitle(_session->title()); + _session->setTitle(Session::DisplayedTitleRole,_session->title(Session::NameRole)); } KUrl SessionController::url() const @@ -492,7 +492,7 @@ void SessionController::debugProcess() if ( ok ) { - _session->setTitle(name); + _session->setTitle(Session::DisplayedTitleRole,name); sessionTitleChanged(); } @@ -779,9 +779,12 @@ void SessionController::sessionTitleChanged() _sessionIcon = KIcon( _sessionIconName ); setIcon( _sessionIcon ); } - - //TODO - use _session->displayTitle() here. - setTitle( _session->title() ); + + QString title = _session->title(Session::DisplayedTitleRole); + if ( title.isEmpty() ) + title = _session->title(Session::NameRole); + + setTitle( title ); } void SessionController::showDisplayContextMenu(TerminalDisplay* /*display*/ , int /*state*/, int x, int y) @@ -797,7 +800,7 @@ void SessionController::showDisplayContextMenu(TerminalDisplay* /*display*/ , in else { qWarning() << "Unable to display popup menu for session" - << _session->title() + << _session->title(Session::NameRole) << ", no GUI factory available to build the popup."; } } @@ -899,7 +902,7 @@ void SaveHistoryTask::execute() { SessionPtr session = iter.next(); - dialog->setCaption( i18n("Save Output from %1",session->title()) ); + dialog->setCaption( i18n("Save Output from %1",session->title(Session::NameRole)) ); int result = dialog->exec(); diff --git a/src/SessionManager.cpp b/src/SessionManager.cpp index d622aab69..58a70accd 100644 --- a/src/SessionManager.cpp +++ b/src/SessionManager.cpp @@ -205,7 +205,7 @@ void SessionManager::sessionTerminated(QObject* sessionObject) { Session* session = qobject_cast(sessionObject); - qDebug() << "Session finished: " << session->title(); + qDebug() << "Session finished: " << session->title(Session::NameRole); Q_ASSERT( session ); @@ -317,7 +317,7 @@ void SessionManager::applyProfile(Session* session, const Profile* info , bool m // Basic session settings if ( !modifiedPropertiesOnly || info->isPropertySet(Profile::Name) ) - session->setTitle(info->name()); + session->setTitle(Session::NameRole,info->name()); if ( !modifiedPropertiesOnly || info->isPropertySet(Profile::Command) ) session->setProgram(info->command());