]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Make "most local url" determination asynchronous so that it doesn't block the GUI...
authorDavid Faure <faure@kde.org>
Fri, 2 Oct 2009 10:55:59 +0000 (10:55 +0000)
committerDavid Faure <faure@kde.org>
Fri, 2 Oct 2009 10:55:59 +0000 (10:55 +0000)
 (e.g. when accessing the non-existing sftp://192.168.1.100/home)
and only run this job if the terminal panel is shown (or at the time when it is made visible).
Sorry kdebase users, you get to update kdelibs again.
BUG: 202176

svn path=/trunk/KDE/kdebase/apps/; revision=1030480

src/panels/terminal/terminalpanel.cpp
src/panels/terminal/terminalpanel.h

index 7dbedd17d07bdbbd6ca4c1af9a69ae15c9b4e3de..3b77cd92e849420ea5a4416c95480fcae648cc26 100644 (file)
@@ -23,7 +23,8 @@
 #include <kde_terminal_interface_v2.h>
 #include <kparts/part.h>
 #include <kshell.h>
 #include <kde_terminal_interface_v2.h>
 #include <kparts/part.h>
 #include <kshell.h>
-#include <kio/netaccess.h>
+#include <kio/job.h>
+#include <KIO/JobUiDelegate>
 
 #include <QBoxLayout>
 #include <QShowEvent>
 
 #include <QBoxLayout>
 #include <QShowEvent>
@@ -58,15 +59,13 @@ void TerminalPanel::setUrl(const KUrl& url)
     }
 
     Panel::setUrl(url);
     }
 
     Panel::setUrl(url);
-    KUrl mostLocalUrl = KIO::NetAccess::mostLocalUrl(url, 0);
+
     const bool sendInput = (m_terminal != 0)
                            && (m_terminal->foregroundProcessId() == -1)
     const bool sendInput = (m_terminal != 0)
                            && (m_terminal->foregroundProcessId() == -1)
-                           && isVisible()
-                           && mostLocalUrl.isLocalFile();
+                           && isVisible();
     if (sendInput) {
     if (sendInput) {
-        m_terminal->sendInput("cd " + KShell::quoteArg(mostLocalUrl.toLocalFile()) + '\n');
+        cdUrl(url);
     }
     }
-
 }
 
 void TerminalPanel::terminalExited()
 }
 
 void TerminalPanel::terminalExited()
@@ -90,16 +89,41 @@ void TerminalPanel::showEvent(QShowEvent* event)
             m_terminalWidget = part->widget();
             m_layout->addWidget(m_terminalWidget);
             m_terminal = qobject_cast<TerminalInterfaceV2 *>(part);
             m_terminalWidget = part->widget();
             m_layout->addWidget(m_terminalWidget);
             m_terminal = qobject_cast<TerminalInterfaceV2 *>(part);
-        }        
+        }
     }
     if (m_terminal != 0) {
     }
     if (m_terminal != 0) {
-        m_terminal->showShellInDir(url().path());
-        m_terminal->sendInput("cd " + KShell::quoteArg(url().path()) + '\n');
-        m_terminal->sendInput("clear\n");
+        m_terminal->showShellInDir(url().toLocalFile());
+        cdUrl(url());
+        m_terminal->sendInput("clear\n"); // TODO do clear after slotMostLocalUrlResult is called, for remote dirs?
         m_terminalWidget->setFocus();
     }
 
     Panel::showEvent(event);
 }
 
         m_terminalWidget->setFocus();
     }
 
     Panel::showEvent(event);
 }
 
+void TerminalPanel::cdUrl(const KUrl& url)
+{
+    if (url.isLocalFile()) {
+        cdDirectory(url.toLocalFile());
+    } else {
+        KIO::StatJob* job = KIO::mostLocalUrl(url, KIO::HideProgressInfo);
+        job->ui()->setWindow(this);
+        connect(job, SIGNAL(result(KJob*)), this, SLOT(slotMostLocalUrlResult(KJob*)));
+    }
+}
+
+void TerminalPanel::cdDirectory(const QString& dir)
+{
+    m_terminal->sendInput("cd " + KShell::quoteArg(dir) + '\n');
+}
+
+void TerminalPanel::slotMostLocalUrlResult(KJob* job)
+{
+    KIO::StatJob* statJob = static_cast<KIO::StatJob *>(job);
+    const KUrl url = statJob->mostLocalUrl();
+    if (url.isLocalFile()) {
+        cdDirectory(url.toLocalFile());
+    }
+}
+
 #include "terminalpanel.moc"
 #include "terminalpanel.moc"
index 4e060bbefba73fad2bc860ca58c6edcfeebae100..7b08483f64f7687024a9884553b1793827a51204 100644 (file)
@@ -53,6 +53,13 @@ protected:
     /** @see QWidget::showEvent() */
     virtual void showEvent(QShowEvent* event);
 
     /** @see QWidget::showEvent() */
     virtual void showEvent(QShowEvent* event);
 
+private slots:
+    void slotMostLocalUrlResult(KJob* job);
+
+private:
+    void cdUrl(const KUrl& url);
+    void cdDirectory(const QString& path);
+
 private:
     QVBoxLayout* m_layout;
     TerminalInterfaceV2* m_terminal;
 private:
     QVBoxLayout* m_layout;
     TerminalInterfaceV2* m_terminal;