Changeset View
Changeset View
Standalone View
Standalone View
src/panels/terminal/terminalpanel.cpp
Show First 20 Lines • Show All 48 Lines • ▼ Show 20 Line(s) | 48 | { | |||
---|---|---|---|---|---|
49 | m_layout = new QVBoxLayout(this); | 49 | m_layout = new QVBoxLayout(this); | ||
50 | m_layout->setMargin(0); | 50 | m_layout->setMargin(0); | ||
51 | } | 51 | } | ||
52 | 52 | | |||
53 | TerminalPanel::~TerminalPanel() | 53 | TerminalPanel::~TerminalPanel() | ||
54 | { | 54 | { | ||
55 | } | 55 | } | ||
56 | 56 | | |||
57 | void TerminalPanel::goHome() | ||||
58 | { | ||||
59 | sendCdToTerminal(QDir::homePath(), HistoryPolicy::SkipHistory); | ||||
60 | } | ||||
61 | | ||||
62 | QString TerminalPanel::currentWorkingDirectory() | ||||
63 | { | ||||
64 | if (m_terminal) { | ||||
65 | return m_terminal->currentWorkingDirectory(); | ||||
66 | } | ||||
67 | return QString(); | ||||
elvisangelaccio: Prefer `QString()`. | |||||
68 | } | ||||
69 | | ||||
57 | void TerminalPanel::terminalExited() | 70 | void TerminalPanel::terminalExited() | ||
58 | { | 71 | { | ||
59 | m_terminal = 0; | 72 | m_terminal = 0; | ||
60 | emit hideTerminalPanel(); | 73 | emit hideTerminalPanel(); | ||
61 | } | 74 | } | ||
62 | 75 | | |||
63 | void TerminalPanel::dockVisibilityChanged() | 76 | void TerminalPanel::dockVisibilityChanged() | ||
64 | { | 77 | { | ||
▲ Show 20 Lines • Show All 74 Lines • ▼ Show 20 Line(s) | 151 | } else { | |||
139 | m_mostLocalUrlJob = KIO::mostLocalUrl(url, KIO::HideProgressInfo); | 152 | m_mostLocalUrlJob = KIO::mostLocalUrl(url, KIO::HideProgressInfo); | ||
140 | if (m_mostLocalUrlJob->uiDelegate()) { | 153 | if (m_mostLocalUrlJob->uiDelegate()) { | ||
141 | KJobWidgets::setWindow(m_mostLocalUrlJob, this); | 154 | KJobWidgets::setWindow(m_mostLocalUrlJob, this); | ||
142 | } | 155 | } | ||
143 | connect(m_mostLocalUrlJob, &KIO::StatJob::result, this, &TerminalPanel::slotMostLocalUrlResult); | 156 | connect(m_mostLocalUrlJob, &KIO::StatJob::result, this, &TerminalPanel::slotMostLocalUrlResult); | ||
144 | } | 157 | } | ||
145 | } | 158 | } | ||
146 | 159 | | |||
147 | void TerminalPanel::sendCdToTerminal(const QString& dir) | 160 | void TerminalPanel::sendCdToTerminal(const QString& dir, HistoryPolicy addToHistory) | ||
148 | { | 161 | { | ||
149 | if (dir == m_konsolePartCurrentDirectory) { | 162 | if (dir == m_konsolePartCurrentDirectory) { | ||
150 | m_clearTerminal = false; | 163 | m_clearTerminal = false; | ||
151 | return; | 164 | return; | ||
152 | } | 165 | } | ||
153 | 166 | | |||
154 | if (!m_clearTerminal) { | 167 | if (!m_clearTerminal) { | ||
155 | // The TerminalV2 interface does not provide a way to delete the | 168 | // The TerminalV2 interface does not provide a way to delete the | ||
156 | // current line before sending a new input. This is mandatory, | 169 | // current line before sending a new input. This is mandatory, | ||
157 | // otherwise sending a 'cd x' to a existing 'rm -rf *' might | 170 | // otherwise sending a 'cd x' to a existing 'rm -rf *' might | ||
158 | // result in data loss. As workaround SIGINT is send. | 171 | // result in data loss. As workaround SIGINT is send. | ||
159 | const int processId = m_terminal->terminalProcessId(); | 172 | const int processId = m_terminal->terminalProcessId(); | ||
160 | if (processId > 0) { | 173 | if (processId > 0) { | ||
161 | kill(processId, SIGINT); | 174 | kill(processId, SIGINT); | ||
162 | } | 175 | } | ||
163 | } | 176 | } | ||
164 | 177 | | |||
165 | m_terminal->sendInput(" cd " + KShell::quoteArg(dir) + '\n'); | 178 | m_terminal->sendInput(" cd " + KShell::quoteArg(dir) + '\n'); | ||
166 | 179 | | |||
167 | // We want to ignore the currentDirectoryChanged(QString) signal, which we will receive after | 180 | // We want to ignore the currentDirectoryChanged(QString) signal, which we will receive after | ||
168 | // the directory change, because this directory change is not caused by a "cd" command that the | 181 | // the directory change, because this directory change is not caused by a "cd" command that the | ||
169 | // user entered in the panel. Therefore, we have to remember 'dir'. Note that it could also be | 182 | // user entered in the panel. Therefore, we have to remember 'dir'. Note that it could also be | ||
170 | // a symbolic link -> remember the 'canonical' path. | 183 | // a symbolic link -> remember the 'canonical' path. | ||
184 | if (addToHistory == HistoryPolicy::AddToHistory) | ||||
171 | m_sendCdToTerminalHistory.enqueue(QDir(dir).canonicalPath()); | 185 | m_sendCdToTerminalHistory.enqueue(QDir(dir).canonicalPath()); | ||
172 | 186 | | |||
173 | if (m_clearTerminal) { | 187 | if (m_clearTerminal) { | ||
174 | m_terminal->sendInput(QStringLiteral(" clear\n")); | 188 | m_terminal->sendInput(QStringLiteral(" clear\n")); | ||
175 | m_clearTerminal = false; | 189 | m_clearTerminal = false; | ||
176 | } | 190 | } | ||
177 | } | 191 | } | ||
178 | 192 | | |||
Show All 26 Lines |
Prefer QString().