]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Sync terminal with KIOFuse mount when browing remote directories
authorAlexander Saoutkin <a.saoutkin@gmail.com>
Wed, 25 Mar 2020 20:17:13 +0000 (20:17 +0000)
committerAlexander Saoutkin <a.saoutkin@gmail.com>
Tue, 7 Apr 2020 17:29:22 +0000 (18:29 +0100)
Summary:
Adds the capability to sync the terminal with a KIOFuse mount if the URL is remote.
Partly based on the existence of another DBus currenly in review:
https://invent.kde.org/kde/kio-fuse/-/merge_requests/21

Syncing works in both "directions". Changing the URL to a remote URLin the
DolphinView will change the URL in the terminal to the KIOFuse local path equivalent.
Conversely changing the URL in the terminal to one that happens to be in a KIOFuse
mount will change the URL in the DolphinView to the remote URL equivalent.

Test Plan:
Manual testing (see video in comments).
1. Checking that changing directory in DolphinView from remote/local to local doesn't
cause any regressions.
2. Checking that changing directory in terminal from local to local (but not in
KIOFUse mount) doesn't cause any regressions.
3. Checking that changing directory in DolphinView from remote/local to remote
correctly changes URL in terminal to KIOFuse equivalent.
4. Checking that changing directory in terminal from local to KIOFuse path
correctly changes the URL in the DolphinView to the remote equivalent.
5. Checking the KIOFuse not being installed doesn't cause any regressions.
6. Changing directories very quickly does not cause any slowdown.

Reviewers: #dolphin, fvogt, elvisangelaccio

Reviewed By: #dolphin, fvogt, elvisangelaccio

Subscribers: elvisangelaccio, fvogt, kfm-devel, ngraham

Tags: #dolphin

Differential Revision: https://phabricator.kde.org/D28290

src/CMakeLists.txt
src/panels/terminal/org.kde.KIOFuse.VFS.xml [new file with mode: 0644]
src/panels/terminal/terminalpanel.cpp
src/panels/terminal/terminalpanel.h

index 02a43a2094270a53c572b2dc5bddf70862cbe4bf..fc7b33cbd4a78bd4881e213341c5cea4ff92c724 100644 (file)
@@ -272,6 +272,7 @@ qt5_add_resources(dolphinstatic_SRCS dolphin.qrc)
 qt5_generate_dbus_interface(${CMAKE_CURRENT_SOURCE_DIR}/dolphinmainwindow.h org.kde.DolphinMainWindow.xml)
 qt5_add_dbus_adaptor(dolphinstatic_SRCS ${CMAKE_CURRENT_BINARY_DIR}/org.kde.DolphinMainWindow.xml dolphinmainwindow.h DolphinMainWindow)
 qt5_add_dbus_interface(dolphinstatic_SRCS ${CMAKE_CURRENT_BINARY_DIR}/org.kde.DolphinMainWindow.xml dolphinmainwindowinterface)
+qt5_add_dbus_interface(dolphinstatic_SRCS panels/terminal/org.kde.KIOFuse.VFS.xml kiofuse_interface)
 
 add_library(dolphinstatic STATIC ${dolphinstatic_SRCS})
 
diff --git a/src/panels/terminal/org.kde.KIOFuse.VFS.xml b/src/panels/terminal/org.kde.KIOFuse.VFS.xml
new file mode 100644 (file)
index 0000000..56f753e
--- /dev/null
@@ -0,0 +1,13 @@
+<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN" "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
+<node>
+  <interface name="org.kde.KIOFuse.VFS">
+    <method name="mountUrl">
+      <arg name="remoteUrl" type="s" direction="in"/>
+      <arg type="s" direction="out"/>
+    </method>
+    <method name="remoteUrl">
+      <arg name="localUrl" type="s" direction="in"/>
+      <arg type="s" direction="out"/>
+    </method>
+  </interface>
+</node>
index 861afebee0330fa2fd5c9ffc4917630a29809f6b..b0aff9a777a6ad8000e7a76ea7cc269ba167fd6b 100644 (file)
@@ -18,6 +18,7 @@
  ***************************************************************************/
 
 #include "terminalpanel.h"
+#include "kiofuse_interface.h"
 
 #include <KIO/DesktopExecParser>
 #include <KIO/Job>
@@ -25,6 +26,7 @@
 #include <KJobWidgets>
 #include <KLocalizedString>
 #include <KMessageWidget>
+#include <KMountPoint>
 #include <KParts/ReadOnlyPart>
 #include <KPluginFactory>
 #include <KPluginLoader>
@@ -50,7 +52,10 @@ TerminalPanel::TerminalPanel(QWidget* parent) :
     m_konsolePartMissingMessage(nullptr),
     m_konsolePart(nullptr),
     m_konsolePartCurrentDirectory(),
-    m_sendCdToTerminalHistory()
+    m_sendCdToTerminalHistory(),
+    m_kiofuseInterface(QStringLiteral("org.kde.KIOFuse"),
+                       QStringLiteral("/org/kde/KIOFuse"),
+                       QDBusConnection::sessionBus())
 {
     m_layout = new QVBoxLayout(this);
     m_layout->setContentsMargins(0, 0, 0, 0);
@@ -244,6 +249,19 @@ void TerminalPanel::slotMostLocalUrlResult(KJob* job)
     const QUrl url = statJob->mostLocalUrl();
     if (url.isLocalFile()) {
         sendCdToTerminal(url.toLocalFile());
+    } else {
+        // URL isn't local, only hope for the terminal to be in sync with the
+        // DolphinView is to mount the remote URL in KIOFuse and point to it.
+        // If we can't do that for any reason, silently fail.
+        auto reply = m_kiofuseInterface.mountUrl(url.toString());
+        QDBusPendingCallWatcher * watcher = new QDBusPendingCallWatcher(reply, this);
+        QObject::connect(watcher, &QDBusPendingCallWatcher::finished, this, [=] (QDBusPendingCallWatcher* watcher) {
+            watcher->deleteLater();
+            if (!reply.isError()) {
+                // Successfully mounted, point to the KIOFuse equivalent path.
+                sendCdToTerminal(reply.value());
+            }
+        });
     }
 
     m_mostLocalUrlJob = nullptr;
@@ -261,8 +279,31 @@ void TerminalPanel::slotKonsolePartCurrentDirectoryChanged(const QString& dir)
         }
     }
 
+    // User may potentially be browsing inside a KIOFuse mount.
+    // If so lets try and change the DolphinView to point to the remote URL equivalent.
+    // instead of into the KIOFuse mount itself (which can cause performance issues!)
     const QUrl url(QUrl::fromLocalFile(dir));
-    emit changeUrl(url);
+
+    KMountPoint::Ptr mountPoint = KMountPoint::currentMountPoints().findByPath(m_konsolePartCurrentDirectory);
+    if (mountPoint && mountPoint->mountType() != QStringLiteral("fuse.kio-fuse")) {
+        // Not in KIOFUse mount, so just switch to the corresponding URL.
+        emit changeUrl(url);
+        return;
+    }
+
+    auto reply = m_kiofuseInterface.remoteUrl(m_konsolePartCurrentDirectory);
+    QDBusPendingCallWatcher * watcher = new QDBusPendingCallWatcher(reply, this);
+    QObject::connect(watcher, &QDBusPendingCallWatcher::finished, this, [=] (QDBusPendingCallWatcher* watcher) {
+        watcher->deleteLater();
+        if (reply.isError()) {
+            // KIOFuse errored out... just show the normal URL
+            emit changeUrl(url);
+        } else {
+            // Our location happens to be in a KIOFuse mount and is mounted.
+            // Let's change the DolphinView to point to the remote URL equivalent.
+            emit changeUrl(QUrl::fromUserInput(reply.value()));
+        }
+    });
 }
 
 bool TerminalPanel::terminalHasFocus() const
index 6ab205fe32cb01828dff012bdfb49e6b8d59ad5e..661fee4d486d2374b6e9044819e6095cfa19a9d3 100644 (file)
@@ -21,6 +21,7 @@
 #define TERMINALPANEL_H
 
 #include "panels/panel.h"
+#include "kiofuse_interface.h"
 
 #include <QQueue>
 
@@ -101,6 +102,7 @@ private:
     KParts::ReadOnlyPart* m_konsolePart;
     QString m_konsolePartCurrentDirectory;
     QQueue<QString> m_sendCdToTerminalHistory;
+    org::kde::KIOFuse::VFS m_kiofuseInterface;
 };
 
 #endif // TERMINALPANEL_H