[Konsole-devel] Bug #183963: Renamed tab is being reset

Andrea Solis andrea at imageworks.com
Mon May 17 23:22:19 UTC 2010


Hi All,

It turns out that bug #183963 is extremely important to my organization so I 
have investigated fixing it.

The problem -- If a konsole tab name is set using this command:

qdbus org.kde.konsole $KONSOLE_DBUS_SESSION org.kde.konsole.Session.setTitle 1 "foo"

The tab name changes but then almost immedately reverts back to it's previous name.

I checked out and examined the code, as far as I can tell this is what occurs:

1.  The qdbus command is processed by Session::setTitle which sets the new value 
in Session::_displayTitle:

         Session::_displayTitle = "foo"

2.  SessionController::snapshot is called, it obtains the current title by 
calling Session::getDynamicTitle

3.  Session::getDynamicTitle formats the title by calling ProcessInfo::format 
and passing either _localTabTitleFormat or _remoteTabTitleFormat.  It does *not* 
use _displayTitle!

4.  ProcessInfo::format replaces the formatting characters in 
_localTabTitleFormat (or _remoteTabTitleFormat).  Since _displayTitle is not 
used, and _localTabTitleFormat is not changed by Session::setTitle, the previous 
title is returned.

Therefore, the previous title is displayed in the tab by SessionController::snapshot


I was able to come up with two possiblie solutions, and would like an opinion on 
which to persue.  If none of them seem the best, I'd appreciate any advice or 
suggestions on how to best fix the bug.

1.  Modify Session::setTitle so that it sets tabTitleFormat as well as displayTitle:
--------------------------- start code snippet ---------------------
void Session::setTitle(TitleRole role , const QString& newTitle)
{
     if ( title(role) != newTitle )
     {
         if ( role == NameRole )
             _nameTitle = newTitle;
         else if ( role == DisplayedTitleRole )
         {
             _displayTitle = newTitle;
             setTabTitleFormat(LocalTabTitle, newTitle);
             // Check if process=="ssh" before changing RemoteTabTitle?
             setTabTitleFormat(RemoteTabTitle, newTitle);
         }

         emit titleChanged();
     }
}
--------------------------- end code snippet ---------------------

This would be the easiest to implement, and would almost mimic the behavior of 
SessionController::renameSession.  However, I really don't prefer this solution, 
as it changes more than just the title.  Also, it changes the Local format as 
well as the Remote format, is that a good idea?

2.  Add a new binding to the Session class so the tab title format can be 
controlled via qdbus:

     Q_SCRIPTABLE void Session::setTabTitleFormat(int context,
const QString& format)

This seems more reasonable, as it is very clear as to what is being set.  Script 
writers can use qdbus to set exactly what they want to set, nothing more, 
nothing less.


I also thought of this:  Add a "pre-formatting" method to 
Session::getDynamicTitle.  Introduce two new formatting characters, one would be 
replaced by _nameTitle and another by _displayTitle:

--------------------------- start code snippet ---------------------

QString Session::formatDynamicTitle(const QString &input)
{
     QString output(input);
     // Make sure "%S" and "%T" are unique (or come up with somethig else)
     output.replace("%S", title(NameRole));
     output.replace("%T", title(DisplayedTitleRole));

     return output;
}
QString Session::getDynamicTitle()
{
     // update current directory from process
     ProcessInfo* process = updateWorkingDirectory();

     // format tab titles using process info
     bool ok = false;
     QString title;
     QString format;

     if ( process->name(&ok) == "ssh" && ok )
     {
         format = formatDynamicTitle(tabTitleFormat(Session::RemoteTabTitle));
         SSHProcessInfo sshInfo(*process);
         title = sshInfo.format(format);
     }
     else
     {
         format = formatDynamicTitle(tabTitleFormat(Session::LocalTabTitle));
         title = process->format(format);
     }

     return title;
}
--------------------------- end code snippet ---------------------

That would give the most control, but would have to be implemented along with 
solution #2 so that the format string could be changed via qdbus.

Any feedback would be greatly appreciated, Thanks!

-- 
Andrea





More information about the konsole-devel mailing list