From 59c635f55261563cb42d6ac22abfcce4ea72d89a Mon Sep 17 00:00:00 2001 From: Jekyll Wu Date: Thu, 5 Apr 2012 17:43:31 +0800 Subject: [PATCH] Add formatter %h which expands to local hostname in local session Note: this %h is different from the %h which expands to remote hostname in remote session. REVIEW: 104490 --- src/ProcessInfo.cpp | 7 +++++++ src/ProcessInfo.h | 3 +++ src/TabTitleFormatButton.cpp | 3 ++- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/ProcessInfo.cpp b/src/ProcessInfo.cpp index e675fbdd3..96b64d7bb 100644 --- a/src/ProcessInfo.cpp +++ b/src/ProcessInfo.cpp @@ -33,6 +33,7 @@ #include #include #include +#include // KDE #include @@ -123,6 +124,7 @@ QString ProcessInfo::format(const QString& input) const // search for and replace known marker output.replace("%u", userName()); + output.replace("%h", localHost()); output.replace("%n", name(&ok)); QString dir = validCurrentDir(); @@ -251,6 +253,11 @@ QString ProcessInfo::userHomeDir() const return _userHomeDir; } +QString ProcessInfo::localHost() +{ + return QHostInfo::localHostName(); +} + void ProcessInfo::setPid(int aPid) { _pid = aPid; diff --git a/src/ProcessInfo.h b/src/ProcessInfo.h index c78b1e0e4..d0d02accf 100644 --- a/src/ProcessInfo.h +++ b/src/ProcessInfo.h @@ -131,6 +131,9 @@ public: /** Returns the user's home directory of the process */ QString userHomeDir() const; + /** Returns the local host */ + static QString localHost(); + /** Returns the name of the current process */ QString name(bool* ok) const; diff --git a/src/TabTitleFormatButton.cpp b/src/TabTitleFormatButton.cpp index 6af84b57b..5097ac494 100644 --- a/src/TabTitleFormatButton.cpp +++ b/src/TabTitleFormatButton.cpp @@ -35,7 +35,8 @@ const TabTitleFormatButton::Element TabTitleFormatButton::_localElements[] = { { "%D" , I18N_NOOP("Current Directory (Long): %D") }, { "%w" , I18N_NOOP("Window Title Set by Shell: %w") }, { "%#" , I18N_NOOP("Session Number: %#") }, - { "%u" , I18N_NOOP("User Name: %u") } + { "%u" , I18N_NOOP("User Name: %u") }, + { "%h" , I18N_NOOP("Local Host: %h") } }; const int TabTitleFormatButton::_localElementCount = sizeof(_localElements) / sizeof(TabTitleFormatButton::Element);