]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/panels/terminal/terminalpanel.cpp
Don't block unmounting when terminal panel's cwd is the mountpoint
[dolphin.git] / src / panels / terminal / terminalpanel.cpp
index fb7d89d31d7cf47fe0ee26b0c9e451931724ddc2..b7d3605aa57ea147c67a1f772f1bf90825131e29 100644 (file)
@@ -54,6 +54,19 @@ TerminalPanel::~TerminalPanel()
 {
 }
 
+void TerminalPanel::goHome()
+{
+    sendCdToTerminal(QDir::homePath(), HistoryPolicy::SkipHistory);
+}
+
+QString TerminalPanel::currentWorkingDirectory()
+{
+    if (m_terminal) {
+        return m_terminal->currentWorkingDirectory();
+    }
+    return QString();
+}
+
 void TerminalPanel::terminalExited()
 {
     m_terminal = 0;
@@ -71,7 +84,7 @@ void TerminalPanel::dockVisibilityChanged()
                    this, SLOT(slotKonsolePartCurrentDirectoryChanged(QString)));
 
         // Make sure this terminal does not prevent unmounting any removable drives
-        changeDir(QUrl::fromLocalFile("/"));
+        changeDir(QUrl::fromLocalFile(QStringLiteral("/")));
 
         // Because we have disconnected from the part's currentDirectoryChanged()
         // signal, we have to update m_konsolePartCurrentDirectory manually. If this
@@ -105,7 +118,7 @@ void TerminalPanel::showEvent(QShowEvent* event)
     if (!m_terminal) {
         m_clearTerminal = true;
         KPluginFactory* factory = 0;
-        KService::Ptr service = KService::serviceByDesktopName("konsolepart");
+        KService::Ptr service = KService::serviceByDesktopName(QStringLiteral("konsolepart"));
         if (service) {
             factory = KPluginLoader(service->library()).factory();
         }
@@ -137,14 +150,14 @@ void TerminalPanel::changeDir(const QUrl& url)
         sendCdToTerminal(url.toLocalFile());
     } else {
         m_mostLocalUrlJob = KIO::mostLocalUrl(url, KIO::HideProgressInfo);
-        if (m_mostLocalUrlJob->ui()) {
+        if (m_mostLocalUrlJob->uiDelegate()) {
             KJobWidgets::setWindow(m_mostLocalUrlJob, this);
         }
         connect(m_mostLocalUrlJob, &KIO::StatJob::result, this, &TerminalPanel::slotMostLocalUrlResult);
     }
 }
 
-void TerminalPanel::sendCdToTerminal(const QString& dir)
+void TerminalPanel::sendCdToTerminal(const QString& dir, HistoryPolicy addToHistory)
 {
     if (dir == m_konsolePartCurrentDirectory) {
         m_clearTerminal = false;
@@ -168,10 +181,11 @@ void TerminalPanel::sendCdToTerminal(const QString& dir)
     // the directory change, because this directory change is not caused by a "cd" command that the
     // user entered in the panel. Therefore, we have to remember 'dir'. Note that it could also be
     // a symbolic link -> remember the 'canonical' path.
-    m_sendCdToTerminalHistory.enqueue(QDir(dir).canonicalPath());
+    if (addToHistory == HistoryPolicy::AddToHistory)
+        m_sendCdToTerminalHistory.enqueue(QDir(dir).canonicalPath());
 
     if (m_clearTerminal) {
-        m_terminal->sendInput(" clear\n");
+        m_terminal->sendInput(QStringLiteral(" clear\n"));
         m_clearTerminal = false;
     }
 }
@@ -199,5 +213,6 @@ void TerminalPanel::slotKonsolePartCurrentDirectoryChanged(const QString& dir)
         }
     }
 
-    emit changeUrl(dir);
+    const QUrl url(QUrl::fromLocalFile(dir));
+    emit changeUrl(url);
 }