Add theming options control sharing operations
authorRoeland Jago Douma <rullzer@owncloud.com>
Mon, 22 Feb 2016 12:53:45 +0000 (13:53 +0100)
committerRoeland Jago Douma <rullzer@owncloud.com>
Mon, 22 Feb 2016 12:53:45 +0000 (13:53 +0100)
Fixes #4325

src/gui/sharedialog.cpp
src/gui/socketapi.cpp
src/libsync/theme.cpp
src/libsync/theme.h

index e66b90c4473cfd365fe6db2803da8c96bffef2e1..cfef4fa75ed89139ef18fa7f1657ee2cda811666 100644 (file)
@@ -92,10 +92,11 @@ ShareDialog::ShareDialog(AccountPtr account, const QString &sharePath, const QSt
         return;
     }
 
+    auto theme = Theme::instance();
     bool autoShare = true;
 
     // We only do user/group sharing from 8.2.0
-    if (account->serverVersionInt() >= ((8 << 16) + (2 << 8))) {
+    if (theme->userGroupSharing() && account->serverVersionInt() >= ((8 << 16) + (2 << 8))) {
         _userGroupWidget = new ShareUserGroupWidget(account, sharePath, localPath, resharingAllowed, this);
         _ui->shareWidgetsLayout->addWidget(_userGroupWidget);
 
@@ -112,9 +113,11 @@ ShareDialog::ShareDialog(AccountPtr account, const QString &sharePath, const QSt
         autoShare = false;
     }
 
-    _linkWidget = new ShareLinkWidget(account, sharePath, localPath, resharingAllowed, autoShare, this);
-    _linkWidget->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred);
-    _ui->shareWidgetsLayout->addWidget(_linkWidget);
+    if (theme->linkSharing()) {
+        _linkWidget = new ShareLinkWidget(account, sharePath, localPath, resharingAllowed, autoShare, this);
+        _linkWidget->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred);
+        _ui->shareWidgetsLayout->addWidget(_linkWidget);
+    }
 }
 
 ShareDialog::~ShareDialog()
index 41e46c16439d991f782017b79079ce90967db379..066beefad44504121dd33e0e5234b514247f6159 100644 (file)
@@ -364,6 +364,8 @@ void SocketApi::command_SHARE(const QString& localFile, QIODevice* socket)
 
     qDebug() << Q_FUNC_INFO << localFile;
 
+    auto theme = Theme::instance();
+
     Folder *shareFolder = FolderMan::instance()->folderForPath(localFile);
     if (!shareFolder) {
         const QString message = QLatin1String("SHARE:NOP:")+QDir::toNativeSeparators(localFile);
@@ -373,6 +375,11 @@ void SocketApi::command_SHARE(const QString& localFile, QIODevice* socket)
         const QString message = QLatin1String("SHARE:NOTCONNECTED:")+QDir::toNativeSeparators(localFile);
         // if the folder isn't connected, don't open the share dialog
         sendMessage(socket, message);
+    } else if (!theme->linkSharing() && (
+                 !theme->userGroupSharing() ||
+                 shareFolder->accountState()->account()->serverVersionInt() < ((8 << 16) + (2 << 8)))) {
+        const QString message = QLatin1String("SHARE:NOP:")+QDir::toNativeSeparators(localFile);
+        sendMessage(socket, message);
     } else {
         const QString localFileClean = QDir::cleanPath(localFile);
         const QString file = localFileClean.mid(shareFolder->cleanPath().length()+1);
@@ -448,14 +455,28 @@ void SocketApi::command_SHARE_STATUS(const QString &localFile, QIODevice *socket
             const QString message = QLatin1String("SHARE_STATUS:DISABLED:")+QDir::toNativeSeparators(localFile);
             sendMessage(socket, message);
         } else {
-            QString available = "USER,GROUP";
+            auto theme = Theme::instance();
+            QString available;
 
-            if (capabilities.sharePublicLink()) {
-                available += ",LINK";
+            if (theme->userGroupSharing()) {
+                available = "USER,GROUP";
             }
 
-            const QString message = QLatin1String("SHARE_STATUS:") + available + ":" + QDir::toNativeSeparators(localFile);
-            sendMessage(socket, message);
+            if (theme->linkSharing() && capabilities.sharePublicLink()) {
+                if (available.isEmpty()) {
+                    available = "LINK";
+                } else {
+                    available += ",LINK";
+                }
+            }
+
+            if (available.isEmpty()) {
+                const QString message = QLatin1String("SHARE_STATUS:DISABLED") + ":" + QDir::toNativeSeparators(localFile);
+                sendMessage(socket, message);
+            } else {
+                const QString message = QLatin1String("SHARE_STATUS:") + available + ":" + QDir::toNativeSeparators(localFile);
+                sendMessage(socket, message);
+            }
         }
     }
 }
index 6fbe05f0b7df0bc83f9de7b01015c0f3a333904a..1a80f4cacb73f5ed2da26e61f33d9dc128a8a8d1 100644 (file)
@@ -417,5 +417,16 @@ QString Theme::webDavPathNonShib() const
     return QLatin1String("remote.php/nonshib-webdav/");
 }
 
+bool Theme::linkSharing() const
+{
+    return false;
+}
+
+bool Theme::userGroupSharing() const
+{
+    return true;
+}
+
+
 } // end namespace client
 
index 7cd6e7baa26a6509f12010258fb50f4d18cb210c..c86d848e4b318eefff804a2527ebc248e0409276 100644 (file)
@@ -229,6 +229,14 @@ public:
     virtual QString webDavPath() const;
     virtual QString webDavPathNonShib() const;
 
+    /**
+     * @brief Sharing options
+     *
+     * Allow link sharing and or user/group sharing
+     */
+    virtual bool linkSharing() const;
+    virtual bool userGroupSharing() const;
+
 protected:
 #ifndef TOKEN_AUTH_ONLY
     QIcon themeIcon(const QString& name, bool sysTray = false) const;