Add SHARE_STATUS socketAPI command
authorRoeland Jago Douma <rullzer@owncloud.com>
Tue, 6 Oct 2015 07:39:24 +0000 (09:39 +0200)
committerRoeland Jago Douma <rullzer@owncloud.com>
Wed, 14 Oct 2015 10:36:32 +0000 (12:36 +0200)
This command allows to retrieve the share status of a file. In other
words if it can be shared.

src/gui/socketapi.cpp
src/gui/socketapi.h

index e145f81295e2b57907b8dca6a1762d7ccccd5510..5305d00fac9a44989f54244457c761ad9d0e8a96 100644 (file)
@@ -28,6 +28,8 @@
 #include "version.h"
 #include "account.h"
 #include "accountstate.h"
+#include "account.h"
+#include "capabilities.h"
 
 #include <QDebug>
 #include <QUrl>
@@ -406,6 +408,39 @@ void SocketApi::command_VERSION(const QString&, QIODevice* socket)
     sendMessage(socket, QLatin1String("VERSION:" MIRALL_VERSION_STRING ":" MIRALL_SOCKET_API_VERSION));
 }
 
+void SocketApi::command_SHARE_STATUS(const QString &localFile, QIODevice *socket)
+{
+    if (!socket) {
+        qDebug() << Q_FUNC_INFO << "No valid socket object.";
+        return;
+    }
+
+    qDebug() << Q_FUNC_INFO << localFile;
+
+    Folder *shareFolder = FolderMan::instance()->folderForPath(localFile);
+
+    if (!shareFolder) {
+        const QString message = QLatin1String("SHARE_STATUS:NOP:")+QDir::toNativeSeparators(localFile);
+        sendMessage(socket, message);
+    } else {
+        const Capabilities capabilities = shareFolder->accountState()->account()->capabilities();
+
+        if (!capabilities.shareAPI()) {
+            const QString message = QLatin1String("SHARE_STATUS:DISABLED:")+QDir::toNativeSeparators(localFile);
+            sendMessage(socket, message);
+        } else {
+            QString available = "USER,GROUP";
+
+            if (capabilities.sharePublicLink()) {
+                available += ",LINK";
+            }
+
+            const QString message = QLatin1String("SHARE_STATUS:") + available + ":" + QDir::toNativeSeparators(localFile);
+            sendMessage(socket, message);
+        }
+    }
+}
+
 void SocketApi::command_SHARE_MENU_TITLE(const QString &, QIODevice* socket)
 {
     sendMessage(socket, QLatin1String("SHARE_MENU_TITLE:") + tr("Share with %1", "parameter is ownCloud").arg(Theme::instance()->appNameGUI()));
index 355e93af81a54e5cf949cdd2bd0e62a3e2e3b882..238c342f929c5b59ab671ad6721ec1dcb5cebe6e 100644 (file)
@@ -77,6 +77,7 @@ private:
 
     Q_INVOKABLE void command_VERSION(const QString& argument, QIODevice* socket);
 
+    Q_INVOKABLE void command_SHARE_STATUS(const QString& localFile, QIODevice *socket);
     Q_INVOKABLE void command_SHARE_MENU_TITLE(const QString& argument, QIODevice* socket);
     QString buildRegisterPathMessage(const QString& path);