diff --git a/src/ProcessInfo.h b/src/ProcessInfo.h --- a/src/ProcessInfo.h +++ b/src/ProcessInfo.h @@ -77,10 +77,8 @@ * the current platform which provides information about a given process. * * @param pid The pid of the process to examine - * @param titleFormat The local title format - used to determine if it - * contains %u which requires expensive prodecures to be used. */ - static ProcessInfo *newInstance(int pid, const QString &titleFormat); + static ProcessInfo *newInstance(int pid); virtual ~ProcessInfo() { @@ -305,7 +303,7 @@ * Constructs a new NullProcessInfo instance. * See ProcessInfo::newInstance() */ - explicit NullProcessInfo(int pid, const QString &titleFormat); + explicit NullProcessInfo(int pid); protected: void readProcessInfo(int pid) Q_DECL_OVERRIDE; bool readCurrentDir(int pid) Q_DECL_OVERRIDE; @@ -324,7 +322,7 @@ * Constructs a new instance of UnixProcessInfo. * See ProcessInfo::newInstance() */ - explicit UnixProcessInfo(int pid, const QString &titleFormat); + explicit UnixProcessInfo(int pid); protected: /** diff --git a/src/ProcessInfo.cpp b/src/ProcessInfo.cpp --- a/src/ProcessInfo.cpp +++ b/src/ProcessInfo.cpp @@ -113,7 +113,7 @@ int currentPid = parentPid(&ok); QString dir = currentDir(&ok); while (!ok && currentPid != 0) { - ProcessInfo *current = ProcessInfo::newInstance(currentPid, QString()); + ProcessInfo *current = ProcessInfo::newInstance(currentPid); current->update(); currentPid = current->parentPid(&ok); dir = current->currentDir(&ok); @@ -331,7 +331,7 @@ // implementations of the UnixProcessInfo abstract class. // -NullProcessInfo::NullProcessInfo(int pid, const QString & /*titleFormat*/) : +NullProcessInfo::NullProcessInfo(int pid) : ProcessInfo(pid) { } @@ -350,10 +350,10 @@ } #if !defined(Q_OS_WIN) -UnixProcessInfo::UnixProcessInfo(int pid, const QString &titleFormat) : +UnixProcessInfo::UnixProcessInfo(int pid) : ProcessInfo(pid) { - setUserNameRequired(titleFormat.contains(QLatin1String("%u"))); + setUserNameRequired(true); } void UnixProcessInfo::readProcessInfo(int pid) @@ -419,8 +419,8 @@ class LinuxProcessInfo : public UnixProcessInfo { public: - LinuxProcessInfo(int pid, const QString &titleFormat) : - UnixProcessInfo(pid, titleFormat) + LinuxProcessInfo(int pid) : + UnixProcessInfo(pid) { } @@ -490,6 +490,7 @@ // This will cause constant opening of /etc/passwd if (userNameRequired()) { readUserName(); + setUserNameRequired(false); } } else { setFileError(statusInfo.error()); @@ -595,8 +596,8 @@ class FreeBSDProcessInfo : public UnixProcessInfo { public: - FreeBSDProcessInfo(int pid, const QString &titleFormat) : - UnixProcessInfo(pid, titleFormat) + FreeBSDProcessInfo(int pid) : + UnixProcessInfo(pid) { } @@ -720,8 +721,8 @@ class OpenBSDProcessInfo : public UnixProcessInfo { public: - OpenBSDProcessInfo(int pid, const QString &titleFormat) : - UnixProcessInfo(pid, titleFormat) + OpenBSDProcessInfo(int pid) : + UnixProcessInfo(pid) { } @@ -838,8 +839,8 @@ class MacProcessInfo : public UnixProcessInfo { public: - MacProcessInfo(int pid, const QString &titleFormat) : - UnixProcessInfo(pid, titleFormat) + MacProcessInfo(int pid) : + UnixProcessInfo(pid) { } @@ -939,8 +940,8 @@ class SolarisProcessInfo : public UnixProcessInfo { public: - SolarisProcessInfo(int pid, const QString &titleFormat) : - UnixProcessInfo(pid, titleFormat) + SolarisProcessInfo(int pid) : + UnixProcessInfo(pid) { } @@ -1170,21 +1171,21 @@ return output; } -ProcessInfo *ProcessInfo::newInstance(int pid, const QString &titleFormat) +ProcessInfo *ProcessInfo::newInstance(int pid) { ProcessInfo *info; #if defined(Q_OS_LINUX) - info = new LinuxProcessInfo(pid, titleFormat); + info = new LinuxProcessInfo(pid); #elif defined(Q_OS_SOLARIS) - info = new SolarisProcessInfo(pid, titleFormat); + info = new SolarisProcessInfo(pid); #elif defined(Q_OS_MACOS) - info = new MacProcessInfo(pid, titleFormat); + info = new MacProcessInfo(pid); #elif defined(Q_OS_FREEBSD) - info = new FreeBSDProcessInfo(pid, titleFormat); + info = new FreeBSDProcessInfo(pid); #elif defined(Q_OS_OPENBSD) - info = new OpenBSDProcessInfo(pid, titleFormat); + info = new OpenBSDProcessInfo(pid); #else - info = new NullProcessInfo(pid, titleFormat); + info = new NullProcessInfo(pid); #endif info->readProcessInfo(pid); return info; diff --git a/src/Session.cpp b/src/Session.cpp --- a/src/Session.cpp +++ b/src/Session.cpp @@ -1062,8 +1062,7 @@ if ((_sessionProcessInfo == nullptr) || (processId() != 0 && processId() != _sessionProcessInfo->pid(&ok))) { delete _sessionProcessInfo; - _sessionProcessInfo = ProcessInfo::newInstance(processId(), - tabTitleFormat(Session::LocalTabTitle)); + _sessionProcessInfo = ProcessInfo::newInstance(processId()); _sessionProcessInfo->setUserHomeDir(); } _sessionProcessInfo->update(); @@ -1076,8 +1075,7 @@ const int foregroundPid = _shellProcess->foregroundProcessGroup(); if (foregroundPid != _foregroundPid) { delete _foregroundProcessInfo; - _foregroundProcessInfo = ProcessInfo::newInstance(foregroundPid, - tabTitleFormat(Session::LocalTabTitle)); + _foregroundProcessInfo = ProcessInfo::newInstance(foregroundPid); _foregroundPid = foregroundPid; } @@ -1134,28 +1132,29 @@ title.replace(QLatin1String("%n"), process->name(&ok)); QString dir = _reportedWorkingUrl.toLocalFile(); + ok = true; if (dir.isEmpty()) { // update current directory from process updateWorkingDirectory(); - dir = process->validCurrentDir(); + dir = process->currentDir(&ok); } - - if (title.contains(QLatin1String("%D"))) { - const QString homeDir = process->userHomeDir(); - if (!homeDir.isEmpty()) { - QString tempDir = dir; - // Change User's Home Dir w/ ~ only at the beginning - if (tempDir.startsWith(homeDir)) { - tempDir.remove(0, homeDir.length()); - tempDir.prepend(QLatin1Char('~')); + if(!ok) { + title.replace(QLatin1String("%d"), QStringLiteral("-")); + title.replace(QLatin1String("%D"), QStringLiteral("-")); + } else { + if (title.contains(QLatin1String("%D"))) { + const QString homeDir = process->userHomeDir(); + if (!homeDir.isEmpty()) { + // Change User's Home Dir w/ ~ only at the beginning + if (dir.startsWith(homeDir)) { + dir.remove(0, homeDir.length()); + dir.prepend(QLatin1Char('~')); + } } - title.replace(QLatin1String("%D"), tempDir); - } else { - // Example: 'sudo top' We have to replace %D with something - title.replace(QLatin1String("%D"), QStringLiteral("-")); + title.replace(QLatin1String("%D"), dir); } + title.replace(QLatin1String("%d"), process->formatShortDir(dir)); } - title.replace(QLatin1String("%d"), process->formatShortDir(dir)); return title; }