From: Roeland Jago Douma Date: Tue, 6 Oct 2015 07:39:24 +0000 (+0200) Subject: Add SHARE_STATUS socketAPI command X-Git-Tag: archive/raspbian/3.16.7-1_deb13u1+rpi1~1^2~1558^2 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=028dc8d6c33f4b937dcc1ae3707d1ff36efb8375;p=nextcloud-desktop.git Add SHARE_STATUS socketAPI command This command allows to retrieve the share status of a file. In other words if it can be shared. --- diff --git a/src/gui/socketapi.cpp b/src/gui/socketapi.cpp index e145f8129..5305d00fa 100644 --- a/src/gui/socketapi.cpp +++ b/src/gui/socketapi.cpp @@ -28,6 +28,8 @@ #include "version.h" #include "account.h" #include "accountstate.h" +#include "account.h" +#include "capabilities.h" #include #include @@ -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())); diff --git a/src/gui/socketapi.h b/src/gui/socketapi.h index 355e93af8..238c342f9 100644 --- a/src/gui/socketapi.h +++ b/src/gui/socketapi.h @@ -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);