summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin T. H. Sandsmark <martin.sandsmark@kde.org>2016-08-13 21:52:52 (GMT)
committerMartin T. H. Sandsmark <martin.sandsmark@kde.org>2016-08-28 15:04:18 (GMT)
commite7770aba9f6af26cba3dbecc1ac085acb214c6cc (patch)
treeeef7253667a6793042d50ab11717220bc3e71f99
parenteea5ecfc5ed93515afaae5b9b938154eeaaf0ba8 (diff)
Avoid polling processes if they report what we need with OCS7
This is apparently what the OCS7 stuff is supposed to solve, so let's use it if we can. REVIEW: 128784 BUG: 325442
-rw-r--r--src/ProcessInfo.cpp27
-rw-r--r--src/ProcessInfo.h29
-rw-r--r--src/Session.cpp50
3 files changed, 49 insertions, 57 deletions
diff --git a/src/ProcessInfo.cpp b/src/ProcessInfo.cpp
index 6a5ac2d..96750b9 100644
--- a/src/ProcessInfo.cpp
+++ b/src/ProcessInfo.cpp
@@ -120,33 +120,6 @@ QString ProcessInfo::validCurrentDir() const
return dir;
}
-QString ProcessInfo::format(const QString& input) const
-{
- bool ok = false;
-
- QString output(input);
-
- // search for and replace known marker
- output.replace(QLatin1String("%u"), userName());
- output.replace(QLatin1String("%h"), localHost());
- output.replace(QLatin1String("%n"), name(&ok));
-
- QString dir = validCurrentDir();
- if (output.contains(QLatin1String("%D"))) {
- QString homeDir = userHomeDir();
- QString tempDir = dir;
- // Change User's Home Dir w/ ~ only at the beginning
- if (tempDir.startsWith(homeDir)) {
- tempDir.remove(0, homeDir.length());
- tempDir.prepend('~');
- }
- output.replace(QLatin1String("%D"), tempDir);
- }
- output.replace(QLatin1String("%d"), formatShortDir(dir));
-
- return output;
-}
-
QSet<QString> ProcessInfo::_commonDirNames;
QSet<QString> ProcessInfo::commonDirNames()
diff --git a/src/ProcessInfo.h b/src/ProcessInfo.h
index 3590651..b28a364 100644
--- a/src/ProcessInfo.h
+++ b/src/ProcessInfo.h
@@ -156,26 +156,6 @@ public:
void setUserHomeDir();
/**
- * 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.
- * <br>
- * The markers recognized are:
- * <ul>
- * <li> %u - Name of the user which owns the process. </li>
- * <li> %n - Replaced with the name of the process. </li>
- * <li> %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)
- * </li>
- * <li> %D - Replaced with the current working directory of the process. </li>
- * </ul>
- */
- QString format(const QString& text) const;
-
- /**
* This enum describes the errors which can occur when trying to read
* a process's information.
*/
@@ -204,6 +184,11 @@ public:
};
Q_DECLARE_FLAGS(Fields, Field)
+ // takes a full directory path and returns a
+ // shortened version suitable for display in
+ // space-constrained UI elements (eg. tabs)
+ QString formatShortDir(const QString& dirPath) const;
+
protected:
/**
* Constructs a new process instance. You should not call the constructor
@@ -278,10 +263,6 @@ protected:
bool userNameRequired() const;
private:
- // takes a full directory path and returns a
- // shortened version suitable for display in
- // space-constrained UI elements (eg. tabs)
- QString formatShortDir(const QString& dirPath) const;
Fields _fields;
diff --git a/src/Session.cpp b/src/Session.cpp
index 14a0fbb..54d1034 100644
--- a/src/Session.cpp
+++ b/src/Session.cpp
@@ -1049,20 +1049,58 @@ bool Session::isRemote()
QString Session::getDynamicTitle()
{
- // update current directory from process
- updateWorkingDirectory();
ProcessInfo* process = getProcessInfo();
// format tab titles using process info
bool ok = false;
- QString title;
if (process->name(&ok) == "ssh" && ok) {
SSHProcessInfo sshInfo(*process);
- title = sshInfo.format(tabTitleFormat(Session::RemoteTabTitle));
- } else {
- title = process->format(tabTitleFormat(Session::LocalTabTitle));
+ return sshInfo.format(tabTitleFormat(Session::RemoteTabTitle));
+ }
+
+ /*
+ * 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.
+ * <br>
+ * The markers recognized are:
+ * <ul>
+ * <li> %u - Name of the user which owns the process. </li>
+ * <li> %n - Replaced with the name of the process. </li>
+ * <li> %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)
+ * </li>
+ * <li> %D - Replaced with the current working directory of the process. </li>
+ * </ul>
+ */
+ QString title = tabTitleFormat(Session::LocalTabTitle);
+ // search for and replace known marker
+ title.replace(QLatin1String("%u"), process->userName());
+ title.replace(QLatin1String("%h"), process->localHost());
+ title.replace(QLatin1String("%n"), process->name(&ok));
+
+ QString dir = _reportedWorkingUrl.toLocalFile();
+ if (dir.isEmpty()) {
+ // update current directory from process
+ updateWorkingDirectory();
+ dir = process->validCurrentDir();
+ }
+
+ if (title.contains(QLatin1String("%D"))) {
+ QString homeDir = process->userHomeDir();
+ QString tempDir = dir;
+ // Change User's Home Dir w/ ~ only at the beginning
+ if (tempDir.startsWith(homeDir)) {
+ tempDir.remove(0, homeDir.length());
+ tempDir.prepend('~');
+ }
+ title.replace(QLatin1String("%D"), tempDir);
}
+ title.replace(QLatin1String("%d"), process->formatShortDir(dir));
return title;
}