Changeset View
Changeset View
Standalone View
Standalone View
src/Session.cpp
Show First 20 Lines • Show All 1056 Lines • ▼ Show 20 Line(s) | 1055 | { | |||
---|---|---|---|---|---|
1057 | 1057 | | |||
1058 | bool ok; | 1058 | bool ok; | ||
1059 | // The checking for pid changing looks stupid, but it is needed | 1059 | // The checking for pid changing looks stupid, but it is needed | ||
1060 | // at the moment to workaround the problem that processId() might | 1060 | // at the moment to workaround the problem that processId() might | ||
1061 | // return 0 | 1061 | // return 0 | ||
1062 | if ((_sessionProcessInfo == nullptr) || | 1062 | if ((_sessionProcessInfo == nullptr) || | ||
1063 | (processId() != 0 && processId() != _sessionProcessInfo->pid(&ok))) { | 1063 | (processId() != 0 && processId() != _sessionProcessInfo->pid(&ok))) { | ||
1064 | delete _sessionProcessInfo; | 1064 | delete _sessionProcessInfo; | ||
1065 | _sessionProcessInfo = ProcessInfo::newInstance(processId(), | 1065 | _sessionProcessInfo = ProcessInfo::newInstance(processId()); | ||
1066 | tabTitleFormat(Session::LocalTabTitle)); | | |||
1067 | _sessionProcessInfo->setUserHomeDir(); | 1066 | _sessionProcessInfo->setUserHomeDir(); | ||
1068 | } | 1067 | } | ||
1069 | _sessionProcessInfo->update(); | 1068 | _sessionProcessInfo->update(); | ||
1070 | } | 1069 | } | ||
1071 | 1070 | | |||
1072 | bool Session::updateForegroundProcessInfo() | 1071 | bool Session::updateForegroundProcessInfo() | ||
1073 | { | 1072 | { | ||
1074 | Q_ASSERT(_shellProcess); | 1073 | Q_ASSERT(_shellProcess); | ||
1075 | 1074 | | |||
1076 | const int foregroundPid = _shellProcess->foregroundProcessGroup(); | 1075 | const int foregroundPid = _shellProcess->foregroundProcessGroup(); | ||
1077 | if (foregroundPid != _foregroundPid) { | 1076 | if (foregroundPid != _foregroundPid) { | ||
1078 | delete _foregroundProcessInfo; | 1077 | delete _foregroundProcessInfo; | ||
1079 | _foregroundProcessInfo = ProcessInfo::newInstance(foregroundPid, | 1078 | _foregroundProcessInfo = ProcessInfo::newInstance(foregroundPid); | ||
1080 | tabTitleFormat(Session::LocalTabTitle)); | | |||
1081 | _foregroundPid = foregroundPid; | 1079 | _foregroundPid = foregroundPid; | ||
1082 | } | 1080 | } | ||
1083 | 1081 | | |||
1084 | if (_foregroundProcessInfo != nullptr) { | 1082 | if (_foregroundProcessInfo != nullptr) { | ||
1085 | _foregroundProcessInfo->update(); | 1083 | _foregroundProcessInfo->update(); | ||
1086 | return _foregroundProcessInfo->isValid(); | 1084 | return _foregroundProcessInfo->isValid(); | ||
1087 | } else { | 1085 | } else { | ||
1088 | return false; | 1086 | return false; | ||
Show All 40 Lines | 1099 | { | |||
1129 | */ | 1127 | */ | ||
1130 | QString title = tabTitleFormat(Session::LocalTabTitle); | 1128 | QString title = tabTitleFormat(Session::LocalTabTitle); | ||
1131 | // search for and replace known marker | 1129 | // search for and replace known marker | ||
1132 | title.replace(QLatin1String("%u"), process->userName()); | 1130 | title.replace(QLatin1String("%u"), process->userName()); | ||
1133 | title.replace(QLatin1String("%h"), Konsole::ProcessInfo::localHost()); | 1131 | title.replace(QLatin1String("%h"), Konsole::ProcessInfo::localHost()); | ||
1134 | title.replace(QLatin1String("%n"), process->name(&ok)); | 1132 | title.replace(QLatin1String("%n"), process->name(&ok)); | ||
1135 | 1133 | | |||
1136 | QString dir = _reportedWorkingUrl.toLocalFile(); | 1134 | QString dir = _reportedWorkingUrl.toLocalFile(); | ||
1135 | ok = true; | ||||
1137 | if (dir.isEmpty()) { | 1136 | if (dir.isEmpty()) { | ||
1138 | // update current directory from process | 1137 | // update current directory from process | ||
1139 | updateWorkingDirectory(); | 1138 | updateWorkingDirectory(); | ||
1140 | dir = process->validCurrentDir(); | 1139 | dir = process->currentDir(&ok); | ||
1141 | } | 1140 | } | ||
1142 | 1141 | if(!ok) { | |||
1142 | title.replace(QLatin1String("%d"), QStringLiteral("-")); | ||||
1143 | title.replace(QLatin1String("%D"), QStringLiteral("-")); | ||||
1144 | } else { | ||||
1143 | if (title.contains(QLatin1String("%D"))) { | 1145 | if (title.contains(QLatin1String("%D"))) { | ||
1144 | const QString homeDir = process->userHomeDir(); | 1146 | const QString homeDir = process->userHomeDir(); | ||
1145 | if (!homeDir.isEmpty()) { | 1147 | if (!homeDir.isEmpty()) { | ||
1146 | QString tempDir = dir; | | |||
1147 | // Change User's Home Dir w/ ~ only at the beginning | 1148 | // Change User's Home Dir w/ ~ only at the beginning | ||
1148 | if (tempDir.startsWith(homeDir)) { | 1149 | if (dir.startsWith(homeDir)) { | ||
1149 | tempDir.remove(0, homeDir.length()); | 1150 | dir.remove(0, homeDir.length()); | ||
1150 | tempDir.prepend(QLatin1Char('~')); | 1151 | dir.prepend(QLatin1Char('~')); | ||
1151 | } | 1152 | } | ||
1152 | title.replace(QLatin1String("%D"), tempDir); | | |||
1153 | } else { | | |||
1154 | // Example: 'sudo top' We have to replace %D with something | | |||
1155 | title.replace(QLatin1String("%D"), QStringLiteral("-")); | | |||
1156 | } | 1153 | } | ||
1154 | title.replace(QLatin1String("%D"), dir); | ||||
1157 | } | 1155 | } | ||
1158 | title.replace(QLatin1String("%d"), process->formatShortDir(dir)); | 1156 | title.replace(QLatin1String("%d"), process->formatShortDir(dir)); | ||
1157 | } | ||||
1159 | 1158 | | |||
1160 | return title; | 1159 | return title; | ||
1161 | } | 1160 | } | ||
1162 | 1161 | | |||
1163 | QUrl Session::getUrl() | 1162 | QUrl Session::getUrl() | ||
1164 | { | 1163 | { | ||
1165 | if (_reportedWorkingUrl.isValid()) { | 1164 | if (_reportedWorkingUrl.isValid()) { | ||
1166 | return _reportedWorkingUrl; | 1165 | return _reportedWorkingUrl; | ||
▲ Show 20 Lines • Show All 608 Lines • Show Last 20 Lines |