Fix Explorer pinning: Add fallbacks for Shell commands (fixes #1599)
authorMichael Schuster <michael@schuster.ms>
Tue, 3 Mar 2020 17:45:58 +0000 (18:45 +0100)
committerMichael Schuster <michael@schuster.ms>
Tue, 3 Mar 2020 17:45:58 +0000 (18:45 +0100)
See: #1599

Signed-off-by: Michael Schuster <michael@schuster.ms>
src/gui/socketapi.cpp
src/gui/socketapi.h

index 7967312b88f3269f191ac110ffec95a228d923a6..45ed4498248bdd21e440e899d892077cb0ccfa6d 100644 (file)
@@ -52,6 +52,7 @@
 #include <QInputDialog>
 
 #include <QClipboard>
+#include <QDesktopServices>
 
 #include <QStandardPaths>
 
@@ -291,6 +292,12 @@ void SocketApi::slotReadSocket()
         int indexOfMethod = staticMetaObject.indexOfMethod(functionWithArguments);
 
         QString argument = line.remove(0, command.length() + 1);
+        if (indexOfMethod == -1) {
+            // Fallback: Try upper-case command
+            functionWithArguments = "command_" + command.toUpper() + "(QString,SocketListener*)";
+            indexOfMethod = staticMetaObject.indexOfMethod(functionWithArguments);
+        }
+
         if (indexOfMethod != -1) {
             staticMetaObject.method(indexOfMethod).invoke(this, Q_ARG(QString, argument), Q_ARG(SocketListener *, listener));
         } else {
@@ -621,6 +628,24 @@ void SocketApi::command_COPY_PUBLIC_LINK(const QString &localFile, SocketListene
     job->run();
 }
 
+// Windows Shell / Explorer pinning fallbacks, see issue: https://github.com/nextcloud/desktop/issues/1599
+#ifdef Q_OS_WIN
+void SocketApi::command_COPYASPATH(const QString &localFile, SocketListener *)
+{
+    QApplication::clipboard()->setText(localFile);
+}
+
+void SocketApi::command_OPENNEWWINDOW(const QString &localFile, SocketListener *)
+{
+    QDesktopServices::openUrl(QUrl::fromLocalFile(localFile));
+}
+
+void SocketApi::command_OPEN(const QString &localFile, SocketListener *socketListener)
+{
+    command_OPENNEWWINDOW(localFile, socketListener);
+}
+#endif
+
 // Fetches the private link url asynchronously and then calls the target slot
 void SocketApi::fetchPrivateLinkUrlHelper(const QString &localFile, const std::function<void(const QString &url)> &targetFun)
 {
index 40adb57006abd19d5914012bf6dbb588649f5ec4..b31294c5b1450587cdf75cfb7f3b839f793dc2ea 100644 (file)
@@ -106,6 +106,13 @@ private:
     Q_INVOKABLE void command_EMAIL_PRIVATE_LINK(const QString &localFile, SocketListener *listener);
     Q_INVOKABLE void command_OPEN_PRIVATE_LINK(const QString &localFile, SocketListener *listener);
 
+    // Windows Shell / Explorer pinning fallbacks, see issue: https://github.com/nextcloud/desktop/issues/1599
+#ifdef Q_OS_WIN
+    Q_INVOKABLE void command_COPYASPATH(const QString &localFile, SocketListener *listener);
+    Q_INVOKABLE void command_OPENNEWWINDOW(const QString &localFile, SocketListener *listener);
+    Q_INVOKABLE void command_OPEN(const QString &localFile, SocketListener *listener);
+#endif
+
     // Fetch the private link and call targetFun
     void fetchPrivateLinkUrlHelper(const QString &localFile, const std::function<void(const QString &url)> &targetFun);