Commit 63d3cdcd authored by Robert Knight's avatar Robert Knight

Live tab titles. These update dynamically to include the current working...

Live tab titles.  These update dynamically to include the current working directory, process name etc.  The format is currently hardcoded, will be a customisable setting soon.

svn path=/branches/work/konsole-split-view/; revision=658406
parent abaa7ef5
......@@ -21,6 +21,7 @@
#include <QDebug>
#include <QFile>
#include <QFileInfo>
#include <QRegExp>
#include <QTextStream>
#include <QStringList>
......@@ -49,6 +50,24 @@ void ProcessInfo::update()
readProcessInfo(_pid,_enableEnvironmentRead);
}
QString ProcessInfo::format(const QString& input) const
{
bool ok = false;
QString output(input);
// search for and replace known markers
output.replace("%u","NOT IMPLEMENTED YET");
output.replace("%n",name(&ok));
output.replace("%D",currentDir(&ok));
output.replace("%d",QFileInfo(currentDir(&ok)).baseName());
// remove any remaining %[LETTER] sequences
output.replace(QRegExp("%\\w"),QString::null);
return output;
}
QVector<QString> ProcessInfo::arguments(bool* ok) const
{
*ok = _fields & ARGUMENTS;
......@@ -446,3 +465,22 @@ QString SSHProcessInfo::command() const
{
return _command;
}
QString SSHProcessInfo::format(const QString& input) const
{
QString output(input);
// search for and replace known markers
output.replace("%u",_user);
output.replace("%h",_host.left(_host.indexOf('.')));
output.replace("%H",_host);
output.replace("%c",_command);
// remove any remaining %[LETTER] character sequences
output.replace(QRegExp("%\\w"),QString::null);
return output;
}
......@@ -153,6 +153,25 @@ public:
*/
QString currentDir(bool* ok) const;
/**
* Parses an input string, looking for markers beginning with a '%'
* character and returns a string with the markers replaced
* with information from this process description.
*
* The markers recognised are:
*
* %u - Name of the user which owns the process.
* %n - Replaced with the name of the process.
* %d - Replaced with the last part of the path name of the
* process' current working directory.
*
* (eg. if the current directory is '/home/bob' then
* 'bob' would be returned)
*
* %D - Replaced with the current working directory of the process.
*/
QString format(const QString& text) const;
protected:
/**
* This is called on construction to read the process state
......@@ -199,6 +218,8 @@ protected:
*/
void addEnvironmentBinding(const QString& name , const QString& value);
private:
// valid bits for _fields variable, ensure that
......@@ -302,6 +323,21 @@ public:
*/
QString command() const;
/**
* Operates in the same way as ProcessInfo::format(), except
* that the set of markers understood is different:
*
* %u - Replaced with user name which the user initially logged
* into on the remote computer.
* %h - Replaced with the first part of the host name which
* is connected to.
* %H - Replaced with the full host name of the computer which
* is connected to.
* %c - Replaced with the command which the user specified
* to execute when starting the SSH process.
*/
QString format(const QString& input) const;
private:
const ProcessInfo& _process;
QString _user;
......
......@@ -87,6 +87,39 @@ SessionController::~SessionController()
void SessionController::snapshot()
{
qDebug() << "session" << _session->title() << "snapshot";
bool ok = false;
ProcessInfo* process = 0;
ProcessInfo* snapshot = ProcessInfo::newInstance(_session->sessionPid());
snapshot->update();
// use foreground process information if available
// fallback to session process otherwise
int pid = snapshot->foregroundPid(&ok);
if ( ok )
{
process = ProcessInfo::newInstance(pid);
process->update();
}
else
process = snapshot;
if ( process->name(&ok) == "ssh" && ok )
{
SSHProcessInfo sshInfo(*process);
_session->setTitle( sshInfo.format("%H / %u") );
}
else
_session->setTitle( process->format("%d / %n") );
if ( snapshot != process )
{
delete snapshot;
delete process;
}
else
delete snapshot;
}
KUrl SessionController::url() const
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment