Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/owncloud/client.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOlivier Goffart <ogoffart@woboq.com>2019-10-30 15:56:31 +0300
committerOlivier Goffart <ogoffart@woboq.com>2019-10-30 16:01:14 +0300
commit35e758ab870eb73f7d4c0a04c7c70878c2242626 (patch)
treebabd8733ed1de956293bbbcb45746c0023d671ff
parent318b6b00d8f3755639e2c199cc05524a91ae5258 (diff)
Share dialog: Remove and open the browser insteadsharedialog
The Share Dialog tries to look like the page on the server, but by simply opening the server page, we get rid of a big class of bug since it is really hard to keep that dialog in sync with the server. (As the server do changes from version to versions) That way we can concentrate on doing the work on the sync engine, and do not have to worry about the share dialog.
-rw-r--r--src/gui/CMakeLists.txt7
-rw-r--r--src/gui/application.cpp4
-rw-r--r--src/gui/owncloudgui.cpp70
-rw-r--r--src/gui/owncloudgui.h19
-rw-r--r--src/gui/sharedialog.cpp255
-rw-r--r--src/gui/sharedialog.h77
-rw-r--r--src/gui/sharedialog.ui90
-rw-r--r--src/gui/sharelinkwidget.cpp711
-rw-r--r--src/gui/sharelinkwidget.h153
-rw-r--r--src/gui/sharelinkwidget.ui386
-rw-r--r--src/gui/shareusergroupwidget.cpp627
-rw-r--r--src/gui/shareusergroupwidget.h150
-rw-r--r--src/gui/shareusergroupwidget.ui120
-rw-r--r--src/gui/shareuserline.ui93
-rw-r--r--src/gui/socketapi.cpp58
-rw-r--r--src/gui/socketapi.h10
16 files changed, 22 insertions, 2808 deletions
diff --git a/src/gui/CMakeLists.txt b/src/gui/CMakeLists.txt
index cd4e82d8f..92b3db06a 100644
--- a/src/gui/CMakeLists.txt
+++ b/src/gui/CMakeLists.txt
@@ -27,10 +27,6 @@ set(client_UI_SRCS
activitywidget.ui
synclogdialog.ui
settingsdialog.ui
- sharedialog.ui
- sharelinkwidget.ui
- shareusergroupwidget.ui
- shareuserline.ui
sslerrordialog.ui
addcertificatedialog.ui
proxyauthdialog.ui
@@ -75,10 +71,7 @@ set(client_SRCS
activityitemdelegate.cpp
selectivesyncdialog.cpp
settingsdialog.cpp
- sharedialog.cpp
- sharelinkwidget.cpp
sharemanager.cpp
- shareusergroupwidget.cpp
sharee.cpp
socketapi.cpp
sslbutton.cpp
diff --git a/src/gui/application.cpp b/src/gui/application.cpp
index 213780c88..adff370b4 100644
--- a/src/gui/application.cpp
+++ b/src/gui/application.cpp
@@ -33,7 +33,6 @@
#include "sslerrordialog.h"
#include "theme.h"
#include "clientproxy.h"
-#include "sharedialog.h"
#include "accountmanager.h"
#include "creds/abstractcredentials.h"
#include "updater/ocupdater.h"
@@ -326,9 +325,6 @@ Application::Application(int &argc, char **argv)
slotAccountStateAdded(ai.data());
}
- connect(FolderMan::instance()->socketApi(), &SocketApi::shareCommandReceived,
- _gui.data(), &ownCloudGui::slotShowShareDialog);
-
// startup procedure.
connect(&_checkConnectionTimer, &QTimer::timeout, this, &Application::slotCheckConnection);
_checkConnectionTimer.setInterval(ConnectionValidator::DefaultCallingIntervalMsec); // check for connection every 32 seconds.
diff --git a/src/gui/owncloudgui.cpp b/src/gui/owncloudgui.cpp
index 05f0cb879..1298bc55c 100644
--- a/src/gui/owncloudgui.cpp
+++ b/src/gui/owncloudgui.cpp
@@ -19,7 +19,6 @@
#include "configfile.h"
#include "progressdispatcher.h"
#include "owncloudsetupwizard.h"
-#include "sharedialog.h"
#include "settingsdialog.h"
#include "logger.h"
#include "logbrowser.h"
@@ -127,12 +126,6 @@ void ownCloudGui::slotTrayClicked(QSystemTrayIcon::ActivationReason reason)
if (reason == QSystemTrayIcon::Trigger) {
if (OwncloudSetupWizard::bringWizardToFrontIfVisible()) {
// brought wizard to front
- } else if (_shareDialogs.size() > 0) {
- // Share dialog(s) be hidden by other apps, bring them back
- Q_FOREACH (const QPointer<ShareDialog> &shareDialog, _shareDialogs) {
- Q_ASSERT(shareDialog.data());
- raiseDialog(shareDialog);
- }
} else {
#ifdef Q_OS_MAC
// on macOS, a left click always opens menu.
@@ -1090,69 +1083,6 @@ void ownCloudGui::raiseDialog(QWidget *raiseWidget)
#endif
}
}
-
-
-void ownCloudGui::slotShowShareDialog(const QString &sharePath, const QString &localPath, ShareDialogStartPage startPage)
-{
- QString file;
- const auto folder = FolderMan::instance()->folderForPath(localPath, &file);
- if (!folder) {
- qCWarning(lcApplication) << "Could not open share dialog for" << localPath << "no responsible folder found";
- return;
- }
-
- const auto accountState = folder->accountState();
-
- SyncJournalFileRecord fileRecord;
-
- bool resharingAllowed = true; // lets assume the good
- if (folder->journalDb()->getFileRecord(file, &fileRecord) && fileRecord.isValid()) {
- // check the permission: Is resharing allowed?
- if (!fileRecord._remotePerm.isNull() && !fileRecord._remotePerm.hasPermission(RemotePermissions::CanReshare)) {
- resharingAllowed = false;
- }
- }
-
- // As a first approximation, set the set of permissions that can be granted
- // either to everything (resharing allowed) or nothing (no resharing).
- //
- // The correct value will be found with a propfind from ShareDialog.
- // (we want to show the dialog directly, not wait for the propfind first)
- SharePermissions maxSharingPermissions =
- SharePermissionRead
- | SharePermissionUpdate | SharePermissionCreate | SharePermissionDelete
- | SharePermissionShare;
- if (!resharingAllowed) {
- maxSharingPermissions = SharePermission(0);
- }
-
-
- ShareDialog *w = nullptr;
- if (_shareDialogs.contains(localPath) && _shareDialogs[localPath]) {
- qCInfo(lcApplication) << "Raising share dialog" << sharePath << localPath;
- w = _shareDialogs[localPath];
- } else {
- qCInfo(lcApplication) << "Opening share dialog" << sharePath << localPath << maxSharingPermissions;
- w = new ShareDialog(accountState, sharePath, localPath, maxSharingPermissions, fileRecord.legacyDeriveNumericFileId(), startPage);
- w->setAttribute(Qt::WA_DeleteOnClose, true);
-
- _shareDialogs[localPath] = w;
- connect(w, &QObject::destroyed, this, &ownCloudGui::slotRemoveDestroyedShareDialogs);
- }
- raiseDialog(w);
-}
-
-void ownCloudGui::slotRemoveDestroyedShareDialogs()
-{
- QMutableMapIterator<QString, QPointer<ShareDialog>> it(_shareDialogs);
- while (it.hasNext()) {
- it.next();
- if (!it.value() || it.value() == sender()) {
- it.remove();
- }
- }
-}
-
void ownCloudGui::slotAbout()
{
QString title = tr("About %1").arg(Theme::instance()->appNameGUI());
diff --git a/src/gui/owncloudgui.h b/src/gui/owncloudgui.h
index 8cbb0d892..cee4c7508 100644
--- a/src/gui/owncloudgui.h
+++ b/src/gui/owncloudgui.h
@@ -31,16 +31,11 @@ namespace OCC {
class Folder;
class SettingsDialog;
-class ShareDialog;
+
class Application;
class LogBrowser;
class AccountState;
-enum class ShareDialogStartPage {
- UsersAndGroups,
- PublicLinks,
-};
-
/**
* @brief The ownCloudGui class
* @ingroup gui
@@ -93,17 +88,6 @@ public slots:
void slotAccountStateChanged();
void slotTrayMessageIfServerUnsupported(Account *account);
- /**
- * Open a share dialog for a file or folder.
- *
- * sharePath is the full remote path to the item,
- * localPath is the absolute local path to it (so not relative
- * to the folder).
- */
- void slotShowShareDialog(const QString &sharePath, const QString &localPath, ShareDialogStartPage startPage);
-
- void slotRemoveDestroyedShareDialogs();
-
private slots:
void slotLogin();
void slotLogout();
@@ -135,7 +119,6 @@ private:
bool _workaroundFakeDoubleClick = false;
bool _workaroundManualVisibility = false;
QTimer _delayedTrayUpdateTimer;
- QMap<QString, QPointer<ShareDialog>> _shareDialogs;
QAction *_actionLogin;
QAction *_actionLogout;
diff --git a/src/gui/sharedialog.cpp b/src/gui/sharedialog.cpp
deleted file mode 100644
index 7bad3743d..000000000
--- a/src/gui/sharedialog.cpp
+++ /dev/null
@@ -1,255 +0,0 @@
-/*
- * Copyright (C) by Roeland Jago Douma <roeland@famdouma.nl>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * for more details.
- */
-
-#include "sharedialog.h"
-#include "sharee.h"
-#include "sharelinkwidget.h"
-#include "shareusergroupwidget.h"
-#include "ui_sharedialog.h"
-
-#include "account.h"
-#include "accountstate.h"
-#include "configfile.h"
-#include "theme.h"
-#include "thumbnailjob.h"
-
-#include <QFileInfo>
-#include <QFileIconProvider>
-#include <QPointer>
-#include <QPushButton>
-#include <QFrame>
-
-namespace OCC {
-
-static const int thumbnailSize = 40;
-
-ShareDialog::ShareDialog(QPointer<AccountState> accountState,
- const QString &sharePath,
- const QString &localPath,
- SharePermissions maxSharingPermissions,
- const QByteArray &numericFileId,
- ShareDialogStartPage startPage,
- QWidget *parent)
- : QDialog(parent)
- , _ui(new Ui::ShareDialog)
- , _accountState(accountState)
- , _sharePath(sharePath)
- , _localPath(localPath)
- , _maxSharingPermissions(maxSharingPermissions)
- , _privateLinkUrl(accountState->account()->deprecatedPrivateLinkUrl(numericFileId).toString(QUrl::FullyEncoded))
- , _startPage(startPage)
- , _linkWidget(NULL)
- , _userGroupWidget(NULL)
- , _progressIndicator(NULL)
-{
- setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
- setAttribute(Qt::WA_DeleteOnClose);
- setObjectName("SharingDialog"); // required as group for saveGeometry call
-
- _ui->setupUi(this);
-
- QPushButton *closeButton = _ui->buttonBox->button(QDialogButtonBox::Close);
- connect(closeButton, &QAbstractButton::clicked, this, &QWidget::close);
-
- // We want to act on account state changes
- connect(_accountState.data(), &AccountState::stateChanged, this, &ShareDialog::slotAccountStateChanged);
-
- // Because people press enter in the dialog and we don't want to close for that
- closeButton->setDefault(false);
- closeButton->setAutoDefault(false);
-
- // Set icon
- QFileInfo f_info(_localPath);
- QFileIconProvider icon_provider;
- QIcon icon = icon_provider.icon(f_info);
- auto pixmap = icon.pixmap(thumbnailSize, thumbnailSize);
- if (pixmap.width() > 0) {
- _ui->label_icon->setPixmap(pixmap);
- } else {
- _ui->label_icon->hide();
- }
-
- // Set filename
- QString fileName = QFileInfo(_sharePath).fileName();
- _ui->label_name->setText(tr("%1").arg(fileName));
- QFont f(_ui->label_name->font());
- f.setPointSize(f.pointSize() * 1.4);
- _ui->label_name->setFont(f);
-
- _ui->label_sharePath->setWordWrap(true);
- QString ocDir(_sharePath);
- ocDir.truncate(ocDir.length() - fileName.length());
-
- ocDir.replace(QRegExp("^/*"), "");
- ocDir.replace(QRegExp("/*$"), "");
-
- // Laying this out is complex because sharePath
- // may be in use or not.
- _ui->gridLayout->removeWidget(_ui->label_sharePath);
- _ui->gridLayout->removeWidget(_ui->label_name);
- if (ocDir.isEmpty()) {
- _ui->gridLayout->addWidget(_ui->label_name, 0, 1, 2, 1);
- _ui->label_sharePath->setText(QString());
- } else {
- _ui->gridLayout->addWidget(_ui->label_name, 0, 1, 1, 1);
- _ui->gridLayout->addWidget(_ui->label_sharePath, 1, 1, 1, 1);
- _ui->label_sharePath->setText(tr("Folder: %2").arg(ocDir));
- }
-
- this->setWindowTitle(tr("%1 Sharing").arg(Theme::instance()->appNameGUI()));
-
- if (!accountState->account()->capabilities().shareAPI()) {
- auto label = new QLabel(tr("The server does not allow sharing"));
- label->setWordWrap(true);
- label->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
- layout()->replaceWidget(_ui->shareWidgets, label);
- _ui->shareWidgets->hide();
- return;
- }
-
- if (QFileInfo(_localPath).isFile()) {
- ThumbnailJob *job = new ThumbnailJob(_sharePath, _accountState->account(), this);
- connect(job, &ThumbnailJob::jobFinished, this, &ShareDialog::slotThumbnailFetched);
- job->start();
- }
-
- _progressIndicator = new QProgressIndicator(this);
- _progressIndicator->startAnimation();
- _progressIndicator->setToolTip(tr("Retrieving maximum possible sharing permissions from server..."));
- _ui->buttonBoxLayout->insertWidget(0, _progressIndicator);
-
- // Server versions >= 9.1 support the "share-permissions" property
- // older versions will just return share-permissions: ""
- auto job = new PropfindJob(accountState->account(), _sharePath);
- job->setProperties(
- QList<QByteArray>()
- << "http://open-collaboration-services.org/ns:share-permissions"
- << "http://owncloud.org/ns:fileid" // numeric file id for fallback private link generation
- << "http://owncloud.org/ns:privatelink");
- job->setTimeout(10 * 1000);
- connect(job, &PropfindJob::result, this, &ShareDialog::slotPropfindReceived);
- connect(job, &PropfindJob::finishedWithError, this, &ShareDialog::slotPropfindError);
- job->start();
-}
-
-ShareDialog::~ShareDialog()
-{
- delete _ui;
-}
-
-void ShareDialog::done(int r)
-{
- ConfigFile cfg;
- cfg.saveGeometry(this);
- QDialog::done(r);
-}
-
-void ShareDialog::slotPropfindReceived(const QVariantMap &result)
-{
- const QVariant receivedPermissions = result["share-permissions"];
- if (!receivedPermissions.toString().isEmpty()) {
- _maxSharingPermissions = static_cast<SharePermissions>(receivedPermissions.toInt());
- qCInfo(lcSharing) << "Received sharing permissions for" << _sharePath << _maxSharingPermissions;
- }
- auto privateLinkUrl = result["privatelink"].toString();
- auto numericFileId = result["fileid"].toByteArray();
- if (!privateLinkUrl.isEmpty()) {
- qCInfo(lcSharing) << "Received private link url for" << _sharePath << privateLinkUrl;
- _privateLinkUrl = privateLinkUrl;
- } else if (!numericFileId.isEmpty()) {
- qCInfo(lcSharing) << "Received numeric file id for" << _sharePath << numericFileId;
- _privateLinkUrl = _accountState->account()->deprecatedPrivateLinkUrl(numericFileId).toString(QUrl::FullyEncoded);
- }
-
- showSharingUi();
-}
-
-void ShareDialog::slotPropfindError()
-{
- // On error show the share ui anyway. The user can still see shares,
- // delete them and so on, even though adding new shares or granting
- // some of the permissions might fail.
-
- showSharingUi();
-}
-
-void ShareDialog::showSharingUi()
-{
- _progressIndicator->stopAnimation();
-
- auto theme = Theme::instance();
-
- // There's no difference between being unable to reshare and
- // being unable to reshare with reshare permission.
- bool canReshare = _maxSharingPermissions & SharePermissionShare;
-
- if (!canReshare) {
- auto label = new QLabel(this);
- label->setText(tr("The file can not be shared because it was shared without sharing permission."));
- label->setWordWrap(true);
- label->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
- layout()->replaceWidget(_ui->shareWidgets, label);
- return;
- }
-
- // We only do user/group sharing from 8.2.0
- bool userGroupSharing =
- theme->userGroupSharing()
- && _accountState->account()->serverVersionInt() >= Account::makeServerVersion(8, 2, 0);
-
- if (userGroupSharing) {
- _userGroupWidget = new ShareUserGroupWidget(_accountState->account(), _sharePath, _localPath, _maxSharingPermissions, _privateLinkUrl, this);
- _ui->shareWidgets->addTab(_userGroupWidget, tr("Users and Groups"));
- _userGroupWidget->getShares();
- }
-
- if (theme->linkSharing()) {
- _linkWidget = new ShareLinkWidget(_accountState->account(), _sharePath, _localPath, _maxSharingPermissions, this);
- _linkWidget->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred);
- _ui->shareWidgets->addTab(_linkWidget, tr("Public Links"));
- _linkWidget->getShares();
-
- if (_startPage == ShareDialogStartPage::PublicLinks)
- _ui->shareWidgets->setCurrentWidget(_linkWidget);
- }
-}
-
-void ShareDialog::slotThumbnailFetched(const int &statusCode, const QByteArray &reply)
-{
- if (statusCode != 200) {
- qCWarning(lcSharing) << "Thumbnail status code: " << statusCode;
- return;
- }
-
- QPixmap p;
- p.loadFromData(reply, "PNG");
- p = p.scaledToHeight(thumbnailSize, Qt::SmoothTransformation);
- _ui->label_icon->setPixmap(p);
- _ui->label_icon->show();
-}
-
-void ShareDialog::slotAccountStateChanged(int state)
-{
- bool enabled = (state == AccountState::State::Connected);
- qCDebug(lcSharing) << "Account connected?" << enabled;
-
- if (_userGroupWidget != NULL) {
- _userGroupWidget->setEnabled(enabled);
- }
-
- if (_linkWidget != NULL) {
- _linkWidget->setEnabled(enabled);
- }
-}
-}
diff --git a/src/gui/sharedialog.h b/src/gui/sharedialog.h
deleted file mode 100644
index 7aa93cfde..000000000
--- a/src/gui/sharedialog.h
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * Copyright (C) by Roeland Jago Douma <roeland@famdouma.nl>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * for more details.
- */
-
-#ifndef SHAREDIALOG_H
-#define SHAREDIALOG_H
-
-#include "accountstate.h"
-#include "sharepermissions.h"
-#include "owncloudgui.h"
-
-#include <QPointer>
-#include <QString>
-#include <QDialog>
-#include <QWidget>
-
-class QProgressIndicator;
-
-namespace OCC {
-
-namespace Ui {
- class ShareDialog;
-}
-
-class ShareLinkWidget;
-class ShareUserGroupWidget;
-
-class ShareDialog : public QDialog
-{
- Q_OBJECT
-
-public:
- explicit ShareDialog(QPointer<AccountState> accountState,
- const QString &sharePath,
- const QString &localPath,
- SharePermissions maxSharingPermissions,
- const QByteArray &numericFileId,
- ShareDialogStartPage startPage,
- QWidget *parent = 0);
- ~ShareDialog();
-
-private slots:
- void done(int r);
- void slotPropfindReceived(const QVariantMap &result);
- void slotPropfindError();
- void slotThumbnailFetched(const int &statusCode, const QByteArray &reply);
- void slotAccountStateChanged(int state);
-
-private:
- void showSharingUi();
-
- Ui::ShareDialog *_ui;
- QPointer<AccountState> _accountState;
- QString _sharePath;
- QString _localPath;
- SharePermissions _maxSharingPermissions;
- QByteArray _numericFileId;
- QString _privateLinkUrl;
- ShareDialogStartPage _startPage;
-
- ShareLinkWidget *_linkWidget;
- ShareUserGroupWidget *_userGroupWidget;
- QProgressIndicator *_progressIndicator;
-};
-}
-
-#endif // SHAREDIALOG_H
diff --git a/src/gui/sharedialog.ui b/src/gui/sharedialog.ui
deleted file mode 100644
index 203dc9ea7..000000000
--- a/src/gui/sharedialog.ui
+++ /dev/null
@@ -1,90 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<ui version="4.0">
- <class>OCC::ShareDialog</class>
- <widget class="QDialog" name="OCC::ShareDialog">
- <property name="geometry">
- <rect>
- <x>0</x>
- <y>0</y>
- <width>408</width>
- <height>281</height>
- </rect>
- </property>
- <property name="windowTitle">
- <string>Dialog</string>
- </property>
- <layout class="QVBoxLayout" name="verticalLayout_2">
- <item>
- <layout class="QGridLayout" name="gridLayout">
- <item row="0" column="1">
- <widget class="QLabel" name="label_name">
- <property name="sizePolicy">
- <sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
- <horstretch>0</horstretch>
- <verstretch>0</verstretch>
- </sizepolicy>
- </property>
- <property name="text">
- <string>share label</string>
- </property>
- <property name="textFormat">
- <enum>Qt::PlainText</enum>
- </property>
- </widget>
- </item>
- <item row="1" column="1">
- <widget class="QLabel" name="label_sharePath">
- <property name="sizePolicy">
- <sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
- <horstretch>0</horstretch>
- <verstretch>0</verstretch>
- </sizepolicy>
- </property>
- <property name="font">
- <font>
- <weight>50</weight>
- <bold>false</bold>
- </font>
- </property>
- <property name="text">
- <string>ownCloud Path:</string>
- </property>
- <property name="textFormat">
- <enum>Qt::PlainText</enum>
- </property>
- </widget>
- </item>
- <item row="0" column="0" rowspan="2">
- <widget class="QLabel" name="label_icon">
- <property name="text">
- <string>TextLabel</string>
- </property>
- </widget>
- </item>
- </layout>
- </item>
- <item>
- <widget class="QTabWidget" name="shareWidgets"/>
- </item>
- <item>
- <layout class="QHBoxLayout" name="buttonBoxLayout">
- <item>
- <widget class="QDialogButtonBox" name="buttonBox">
- <property name="sizePolicy">
- <sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
- <horstretch>0</horstretch>
- <verstretch>0</verstretch>
- </sizepolicy>
- </property>
- <property name="standardButtons">
- <set>QDialogButtonBox::Close</set>
- </property>
- </widget>
- </item>
- </layout>
- </item>
- </layout>
- </widget>
- <resources/>
- <connections/>
-</ui>
diff --git a/src/gui/sharelinkwidget.cpp b/src/gui/sharelinkwidget.cpp
deleted file mode 100644
index b2fc30bfe..000000000
--- a/src/gui/sharelinkwidget.cpp
+++ /dev/null
@@ -1,711 +0,0 @@
-/*
- * Copyright (C) by Roeland Jago Douma <roeland@famdouma.nl>
- * Copyright (C) 2015 by Klaas Freitag <freitag@owncloud.com>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * for more details.
- */
-
-#include "sharelinkwidget.h"
-#include "ui_sharelinkwidget.h"
-#include "account.h"
-#include "capabilities.h"
-
-#include "sharemanager.h"
-#include "guiutility.h"
-
-#include "QProgressIndicator.h"
-#include <QBuffer>
-#include <QClipboard>
-#include <QFileInfo>
-#include <QDesktopServices>
-#include <QMessageBox>
-#include <QMenu>
-#include <QToolButton>
-
-namespace OCC {
-
-const char propertyShareC[] = "oc_share";
-
-ShareLinkWidget::ShareLinkWidget(AccountPtr account,
- const QString &sharePath,
- const QString &localPath,
- SharePermissions maxSharingPermissions,
- QWidget *parent)
- : QWidget(parent)
- , _ui(new Ui::ShareLinkWidget)
- , _account(account)
- , _sharePath(sharePath)
- , _localPath(localPath)
- , _manager(nullptr)
- , _passwordRequired(false)
- , _expiryRequired(false)
- , _namesSupported(true)
-{
- _ui->setupUi(this);
-
- _ui->linkShares->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch);
- _ui->linkShares->horizontalHeader()->setSectionResizeMode(1, QHeaderView::ResizeToContents);
- _ui->linkShares->horizontalHeader()->setSectionResizeMode(2, QHeaderView::ResizeToContents);
-
- //Is this a file or folder?
- QFileInfo fi(localPath);
- _isFile = fi.isFile();
-
- // Note: the share name cannot be longer than 64 characters
- _ui->nameLineEdit->setText(tr("Public link"));
-
- // the following progress indicator widgets are added to layouts which makes them
- // automatically deleted once the dialog dies.
- _pi_create = new QProgressIndicator();
- _pi_password = new QProgressIndicator();
- _pi_date = new QProgressIndicator();
- _pi_editing = new QProgressIndicator();
- _ui->horizontalLayout_create->insertWidget(2, _pi_create);
- _ui->horizontalLayout_password->addWidget(_pi_password);
- _ui->layout_editing->addWidget(_pi_editing, 0, 2);
- _ui->horizontalLayout_expire->insertWidget(_ui->horizontalLayout_expire->count() - 1, _pi_date);
-
- connect(_ui->nameLineEdit, &QLineEdit::returnPressed, this, &ShareLinkWidget::slotShareNameEntered);
- connect(_ui->createShareButton, &QAbstractButton::clicked, this, &ShareLinkWidget::slotShareNameEntered);
- connect(_ui->linkShares, &QTableWidget::itemSelectionChanged, this, &ShareLinkWidget::slotShareSelectionChanged);
- connect(_ui->linkShares, &QTableWidget::itemChanged, this, &ShareLinkWidget::slotNameEdited);
- connect(_ui->checkBox_password, &QAbstractButton::clicked, this, &ShareLinkWidget::slotCheckBoxPasswordClicked);
- connect(_ui->lineEdit_password, &QLineEdit::returnPressed, this, &ShareLinkWidget::slotPasswordReturnPressed);
- connect(_ui->lineEdit_password, &QLineEdit::textChanged, this, &ShareLinkWidget::slotPasswordChanged);
- connect(_ui->pushButton_setPassword, &QAbstractButton::clicked, this, &ShareLinkWidget::slotPasswordReturnPressed);
- connect(_ui->checkBox_expire, &QAbstractButton::clicked, this, &ShareLinkWidget::slotCheckBoxExpireClicked);
- connect(_ui->calendar, &QDateTimeEdit::dateChanged, this, &ShareLinkWidget::slotExpireDateChanged);
- connect(_ui->radio_readOnly, &QAbstractButton::clicked, this, &ShareLinkWidget::slotPermissionsClicked);
- connect(_ui->radio_readWrite, &QAbstractButton::clicked, this, &ShareLinkWidget::slotPermissionsClicked);
- connect(_ui->radio_uploadOnly, &QAbstractButton::clicked, this, &ShareLinkWidget::slotPermissionsClicked);
-
- _ui->errorLabel->hide();
-
- bool sharingPossible = true;
- if (!_account->capabilities().sharePublicLink()) {
- displayError(tr("Link shares have been disabled"));
- sharingPossible = false;
- } else if (!(maxSharingPermissions & SharePermissionShare)) {
- displayError(tr("The file can not be shared because it was shared without sharing permission."));
- sharingPossible = false;
- }
- if (!sharingPossible) {
- _ui->nameLineEdit->setEnabled(false);
- _ui->createShareButton->setEnabled(false);
- }
-
- // Older servers don't support multiple public link shares
- if (!_account->capabilities().sharePublicLinkMultiple()) {
- _namesSupported = false;
- _ui->createShareButton->setText(tr("Create public link share"));
- _ui->nameLineEdit->hide();
- _ui->nameLineEdit->clear(); // so we don't send a name
- _ui->nameLabel->hide();
- }
-
- _ui->shareProperties->setEnabled(false);
-
- _ui->pushButton_setPassword->setEnabled(false);
- _ui->lineEdit_password->setEnabled(false);
- _ui->pushButton_setPassword->setEnabled(false);
- _ui->checkBox_password->setText(tr("P&assword protect"));
-
- _ui->calendar->setMinimumDate(QDate::currentDate().addDays(1));
- _ui->calendar->setEnabled(false);
-
- // check if the file is already inside of a synced folder
- if (sharePath.isEmpty()) {
- // The file is not yet in an ownCloud synced folder. We could automatically
- // copy it over, but that is skipped as not all questions can be answered that
- // are involved in that, see https://github.com/owncloud/client/issues/2732
- //
- // _ui->checkBox_shareLink->setEnabled(false);
- // uploadExternalFile();
- qCWarning(lcSharing) << "Unable to share files not in a sync folder.";
- return;
- }
-
-
- // Parse capabilities
-
- // If password is enforced then don't allow users to disable it
- if (_account->capabilities().sharePublicLinkEnforcePassword()) {
- _ui->checkBox_password->setEnabled(false);
- _passwordRequired = true;
- }
-
- // If expiredate is enforced do not allow disable and set max days
- if (_account->capabilities().sharePublicLinkEnforceExpireDate()) {
- _ui->checkBox_expire->setEnabled(false);
- _ui->calendar->setMaximumDate(capabilityDefaultExpireDate());
- _expiryRequired = true;
- }
-
- // Hide permissions that are unavailable for files or disabled by capability.
- bool rwVisible = !_isFile && _account->capabilities().sharePublicLinkAllowUpload();
- bool uploadOnlyVisible = rwVisible && _account->capabilities().sharePublicLinkSupportsUploadOnly();
- _ui->radio_readWrite->setVisible(rwVisible);
- _ui->label_readWrite->setVisible(rwVisible);
- _ui->radio_uploadOnly->setVisible(uploadOnlyVisible);
- _ui->label_uploadOnly->setVisible(uploadOnlyVisible);
-
- // Prepare sharing menu
-
- _linkContextMenu = new QMenu(this);
- connect(_linkContextMenu, &QMenu::triggered,
- this, &ShareLinkWidget::slotLinkContextMenuActionTriggered);
- _openLinkAction = _linkContextMenu->addAction(tr("Open link in browser"));
- _copyLinkAction = _linkContextMenu->addAction(tr("Copy link to clipboard"));
- _copyDirectLinkAction = _linkContextMenu->addAction(tr("Copy link to clipboard (direct download)"));
- _emailLinkAction = _linkContextMenu->addAction(tr("Send link by email"));
- _emailDirectLinkAction = _linkContextMenu->addAction(tr("Send link by email (direct download)"));
- _deleteLinkAction = _linkContextMenu->addAction(tr("Delete"));
-
- /*
- * Create the share manager and connect it properly
- */
- if (sharingPossible) {
- _manager = new ShareManager(_account, this);
- connect(_manager, &ShareManager::sharesFetched, this, &ShareLinkWidget::slotSharesFetched);
- connect(_manager, &ShareManager::linkShareCreated, this, &ShareLinkWidget::slotCreateShareFetched);
- connect(_manager, &ShareManager::linkShareCreationForbidden, this, &ShareLinkWidget::slotCreateShareForbidden);
- connect(_manager, &ShareManager::serverError, this, &ShareLinkWidget::slotServerError);
- }
-
- auto retainSizeWhenHidden = [](QWidget *w) {
- auto sp = w->sizePolicy();
- sp.setRetainSizeWhenHidden(true);
- w->setSizePolicy(sp);
- };
- retainSizeWhenHidden(_ui->pushButton_setPassword);
- retainSizeWhenHidden(_ui->create);
-
- // If this starts out empty the first call to slotShareSelectionChanged()
- // will not properly initialize the ui state if "Create new..." is the
- // only option. So pre-fill with an invalid share id.
- _selectedShareId = QStringLiteral("!&no-share-selected");
-}
-
-ShareLinkWidget::~ShareLinkWidget()
-{
- delete _ui;
-}
-
-void ShareLinkWidget::getShares()
-{
- if (_manager) {
- _manager->fetchShares(_sharePath);
- }
-}
-
-void ShareLinkWidget::slotSharesFetched(const QList<QSharedPointer<Share>> &shares)
-{
- const QString versionString = _account->serverVersion();
- qCInfo(lcSharing) << versionString << "Fetched" << shares.count() << "shares";
-
- // Select the share that was previously selected,
- // except if an explicit override was asked for
- QString reselectShareId = _selectedShareId;
- if (!_newShareOverrideSelectionId.isEmpty()) {
- reselectShareId = _newShareOverrideSelectionId;
- _newShareOverrideSelectionId.clear();
- }
-
- auto table = _ui->linkShares;
-
- // Wipe the table without updating the ui elements, we
- // might want their state untouched if the same share ends
- // up being selected
- disconnect(table, &QTableWidget::itemSelectionChanged, this, &ShareLinkWidget::slotShareSelectionChanged);
- table->clearContents();
- table->setRowCount(0);
- connect(table, &QTableWidget::itemSelectionChanged, this, &ShareLinkWidget::slotShareSelectionChanged);
-
- auto deleteIcon = QIcon::fromTheme(QLatin1String("user-trash"),
- QIcon(QLatin1String(":/client/resources/delete.png")));
-
- foreach (auto share, shares) {
- if (share->getShareType() != Share::TypeLink) {
- continue;
- }
- auto linkShare = qSharedPointerDynamicCast<LinkShare>(share);
-
- // Connect all shares signals to gui slots
- connect(share.data(), &Share::serverError, this, &ShareLinkWidget::slotServerError);
- connect(share.data(), &Share::shareDeleted, this, &ShareLinkWidget::slotDeleteShareFetched);
- connect(share.data(), &Share::permissionsSet, this, &ShareLinkWidget::slotPermissionsSet);
- connect(linkShare.data(), &LinkShare::expireDateSet, this, &ShareLinkWidget::slotExpireSet);
- connect(linkShare.data(), &LinkShare::passwordSet, this, &ShareLinkWidget::slotPasswordSet);
- connect(linkShare.data(), &LinkShare::passwordSetError, this, &ShareLinkWidget::slotPasswordSetError);
-
- // Build the table row
- auto row = table->rowCount();
- table->insertRow(row);
-
- auto nameItem = new QTableWidgetItem;
- auto name = shareName(*linkShare);
- if (!_namesSupported) {
- nameItem->setFlags(nameItem->flags() & ~Qt::ItemIsEditable);
- }
- nameItem->setText(name);
- nameItem->setData(Qt::UserRole, QVariant::fromValue(linkShare));
- table->setItem(row, 0, nameItem);
-
- auto dotdotdotButton = new QToolButton;
- dotdotdotButton->setText("...");
- dotdotdotButton->setProperty(propertyShareC, QVariant::fromValue(linkShare));
- connect(dotdotdotButton, &QAbstractButton::clicked, this, &ShareLinkWidget::slotContextMenuButtonClicked);
- table->setCellWidget(row, 1, dotdotdotButton);
-
- auto deleteButton = new QToolButton;
- deleteButton->setIcon(deleteIcon);
- deleteButton->setProperty(propertyShareC, QVariant::fromValue(linkShare));
- deleteButton->setToolTip(tr("Delete link share"));
- connect(deleteButton, &QAbstractButton::clicked, this, &ShareLinkWidget::slotDeleteShareClicked);
- table->setCellWidget(row, 2, deleteButton);
-
- // Reestablish the previous selection
- if (reselectShareId == share->getId()) {
- table->selectRow(row);
- }
- }
-
- // Add create-new entry
- if (_namesSupported || table->rowCount() == 0) {
- auto row = table->rowCount();
- table->insertRow(row);
- auto createItem = new QTableWidgetItem;
- createItem->setFlags(createItem->flags() & ~Qt::ItemIsEditable);
- createItem->setText(tr("Create new..."));
- auto font = createItem->font();
- font.setItalic(true);
- createItem->setFont(font);
- table->setItem(row, 0, createItem);
- auto dummyItem = new QTableWidgetItem;
- dummyItem->setFlags(dummyItem->flags() & ~Qt::ItemIsEditable);
- table->setItem(row, 1, dummyItem->clone());
- table->setItem(row, 2, dummyItem);
- }
-
- if (!selectedShare()) {
- if (table->rowCount() != 0) {
- // Select the first share by default
- table->selectRow(0);
- } else {
- // explicitly note the deselection,
- // since this was not triggered on table clear above
- slotShareSelectionChanged();
- }
- }
-}
-
-void ShareLinkWidget::slotShareSelectionChanged()
-{
- // Disable running progress indicators
- _pi_create->stopAnimation();
- _pi_editing->stopAnimation();
- _pi_date->stopAnimation();
- _pi_password->stopAnimation();
-
- _ui->errorLabel->hide();
-
- auto share = selectedShare();
- bool selectionUnchanged = false;
- bool createNew = !share;
- if (share) {
- selectionUnchanged = _selectedShareId == share->getId();
- _selectedShareId = share->getId();
- } else {
- selectionUnchanged = _selectedShareId.isEmpty();
- _selectedShareId.clear();
- }
-
- _ui->shareProperties->setEnabled(true);
-
- _ui->checkBox_password->setEnabled(!_passwordRequired);
- _ui->checkBox_expire->setEnabled(!_expiryRequired);
- _ui->widget_editing->setEnabled(true);
- if (!_account->capabilities().sharePublicLinkAllowUpload()) {
- _ui->radio_readWrite->setEnabled(false);
- _ui->radio_uploadOnly->setEnabled(false);
- }
-
- // Password state
- _ui->pushButton_setPassword->setVisible(!createNew);
- _ui->checkBox_password->setText(tr("P&assword protect"));
- if (!selectionUnchanged) {
- if (share && share->isPasswordSet()) {
- _ui->checkBox_password->setChecked(true);
- _ui->lineEdit_password->setPlaceholderText("********");
- _ui->lineEdit_password->setEnabled(true);
- } else if (createNew && _passwordRequired) {
- _ui->checkBox_password->setChecked(true);
- _ui->lineEdit_password->setPlaceholderText(tr("Please Set Password"));
- _ui->lineEdit_password->setEnabled(true);
- } else {
- _ui->checkBox_password->setChecked(false);
- _ui->lineEdit_password->setPlaceholderText(QString());
- _ui->lineEdit_password->setEnabled(false);
- }
- _ui->lineEdit_password->setText(QString());
- _ui->pushButton_setPassword->setEnabled(false);
- }
-
- // Expiry state
- _ui->calendar->setMinimumDate(QDate::currentDate().addDays(1));
- if (share && share->getExpireDate().isValid()) {
- _ui->checkBox_expire->setChecked(true);
- _ui->calendar->setDate(share->getExpireDate());
- _ui->calendar->setEnabled(true);
- } else if (createNew) {
- const QDate defaultExpire = capabilityDefaultExpireDate();
- if (defaultExpire.isValid())
- _ui->calendar->setDate(defaultExpire);
- const bool enabled = _expiryRequired || defaultExpire.isValid();
- _ui->checkBox_expire->setChecked(enabled);
- _ui->calendar->setEnabled(enabled);
- } else {
- _ui->checkBox_expire->setChecked(false);
- _ui->calendar->setEnabled(false);
- }
-
- // Public upload state
- if (share && share->getPublicUpload()) {
- if (share->getShowFileListing()) {
- _ui->radio_readWrite->setChecked(true);
- } else {
- _ui->radio_uploadOnly->setChecked(true);
- }
- } else {
- _ui->radio_readOnly->setChecked(true);
- }
-
- // Name and create button
- _ui->create->setVisible(createNew);
-}
-
-void ShareLinkWidget::setExpireDate(const QDate &date)
-{
- if (auto current = selectedShare()) {
- _pi_date->startAnimation();
- _ui->errorLabel->hide();
- current->setExpireDate(date);
- }
-}
-
-void ShareLinkWidget::slotExpireSet()
-{
- if (sender() == selectedShare().data()) {
- slotShareSelectionChanged();
- }
-}
-
-void ShareLinkWidget::slotExpireDateChanged(const QDate &date)
-{
- if (_ui->checkBox_expire->isChecked()) {
- setExpireDate(date);
- }
-}
-
-void ShareLinkWidget::slotPasswordReturnPressed()
-{
- if (selectedShare()) {
- setPassword(_ui->lineEdit_password->text());
- _ui->lineEdit_password->clearFocus();
- }
-}
-
-void ShareLinkWidget::slotPasswordChanged(const QString &newText)
-{
- // disable the set-password button
- _ui->pushButton_setPassword->setEnabled(newText.length() > 0);
-}
-
-void ShareLinkWidget::slotNameEdited(QTableWidgetItem *item)
-{
- if (!_namesSupported) {
- return;
- }
-
- QString newName = item->text();
- auto share = item->data(Qt::UserRole).value<QSharedPointer<LinkShare>>();
- if (share && newName != share->getName() && newName != share->getToken()) {
- share->setName(newName);
- }
-}
-
-void ShareLinkWidget::setPassword(const QString &password)
-{
- if (auto current = selectedShare()) {
- _pi_password->startAnimation();
- _ui->errorLabel->hide();
-
- _ui->checkBox_password->setEnabled(false);
- _ui->lineEdit_password->setEnabled(false);
-
- current->setPassword(password);
- }
-}
-
-void ShareLinkWidget::slotPasswordSet()
-{
- auto share = selectedShare();
- if (sender() != share.data())
- return;
-
- _pi_password->stopAnimation();
- _ui->checkBox_password->setEnabled(true);
- _ui->lineEdit_password->setText(QString());
- if (share->isPasswordSet()) {
- _ui->lineEdit_password->setPlaceholderText("********");
- _ui->lineEdit_password->setEnabled(true);
- } else {
- _ui->lineEdit_password->setPlaceholderText(QString());
- _ui->lineEdit_password->setEnabled(false);
- }
-
- /*
- * When setting/deleting a password from a share the old share is
- * deleted and a new one is created. So we need to refetch the shares
- * at this point.
- *
- * NOTE: I don't see this happening with oC > 10
- */
- getShares();
-}
-
-void ShareLinkWidget::slotShareNameEntered()
-{
- if (!_manager) {
- return;
- }
- _pi_create->startAnimation();
- _manager->createLinkShare(
- _sharePath,
- _ui->nameLineEdit->text(),
- _ui->checkBox_password->isChecked() ? _ui->lineEdit_password->text() : QString(),
- _ui->checkBox_expire->isChecked() ? _ui->calendar->date() : QDate(),
- uiPermissionState());
-}
-
-void ShareLinkWidget::slotDeleteShareFetched()
-{
- getShares();
-}
-
-void ShareLinkWidget::slotCreateShareFetched(const QSharedPointer<LinkShare> &share)
-{
- _pi_create->stopAnimation();
- _pi_password->stopAnimation();
- _ui->nameLineEdit->clear();
-
- _newShareOverrideSelectionId = share->getId();
- getShares();
-}
-
-void ShareLinkWidget::slotCreateShareForbidden(const QString &message)
-{
- // Show the message, so users can adjust and try again
- _pi_create->stopAnimation();
- if (!message.isEmpty()) {
- _ui->errorLabel->setText(message);
- _ui->errorLabel->show();
- }
-}
-
-void ShareLinkWidget::slotCheckBoxPasswordClicked()
-{
- if (_ui->checkBox_password->checkState() == Qt::Checked) {
- _ui->lineEdit_password->setEnabled(true);
- _ui->pushButton_setPassword->setEnabled(true);
- _ui->lineEdit_password->setPlaceholderText(tr("Please Set Password"));
- _ui->lineEdit_password->setFocus();
- } else {
- setPassword(QString());
- _ui->lineEdit_password->setPlaceholderText(QString());
- _pi_password->startAnimation();
- _ui->lineEdit_password->setEnabled(false);
- _ui->pushButton_setPassword->setEnabled(false);
- }
-}
-
-void ShareLinkWidget::slotCheckBoxExpireClicked()
-{
- if (_ui->checkBox_expire->checkState() == Qt::Checked) {
- const QDate tomorrow = QDate::currentDate().addDays(1);
- QDate defaultDate = capabilityDefaultExpireDate();
- if (!defaultDate.isValid())
- defaultDate = tomorrow;
- setExpireDate(defaultDate);
- _ui->calendar->setDate(defaultDate);
- _ui->calendar->setMinimumDate(tomorrow);
- _ui->calendar->setEnabled(true);
- } else {
- setExpireDate(QDate());
- _ui->calendar->setEnabled(false);
- }
-}
-
-void ShareLinkWidget::emailShareLink(const QUrl &url)
-{
- QString fileName = _sharePath.mid(_sharePath.lastIndexOf('/') + 1);
- Utility::openEmailComposer(
- tr("I shared %1 with you").arg(fileName),
- url.toString(),
- this);
-}
-
-void ShareLinkWidget::openShareLink(const QUrl &url)
-{
- Utility::openBrowser(url, this);
-}
-
-void ShareLinkWidget::confirmAndDeleteShare(const QSharedPointer<LinkShare> &share)
-{
- auto messageBox = new QMessageBox(
- QMessageBox::Question,
- tr("Confirm Link Share Deletion"),
- tr("<p>Do you really want to delete the public link share <i>%1</i>?</p>"
- "<p>Note: This action cannot be undone.</p>")
- .arg(shareName(*share)),
- QMessageBox::NoButton,
- this);
- QPushButton *yesButton =
- messageBox->addButton(tr("Delete"), QMessageBox::YesRole);
- messageBox->addButton(tr("Cancel"), QMessageBox::NoRole);
-
- connect(messageBox, &QMessageBox::finished, this,
- [messageBox, yesButton, share]() {
- if (messageBox->clickedButton() == yesButton)
- share->deleteShare();
- });
- messageBox->open();
-}
-
-QString ShareLinkWidget::shareName(const LinkShare &share) const
-{
- QString name = share.getName();
- if (!name.isEmpty())
- return name;
- if (!_namesSupported)
- return tr("Public link");
- return share.getToken();
-}
-
-void ShareLinkWidget::slotContextMenuButtonClicked()
-{
- auto share = sender()->property(propertyShareC).value<QSharedPointer<LinkShare>>();
- bool downloadEnabled = share->getShowFileListing();
- _copyDirectLinkAction->setVisible(downloadEnabled);
- _emailDirectLinkAction->setVisible(downloadEnabled);
-
- _linkContextMenu->setProperty(propertyShareC, QVariant::fromValue(share));
- _linkContextMenu->exec(QCursor::pos());
-}
-
-void ShareLinkWidget::slotLinkContextMenuActionTriggered(QAction *action)
-{
- auto share = sender()->property(propertyShareC).value<QSharedPointer<LinkShare>>();
-
- if (action == _deleteLinkAction) {
- confirmAndDeleteShare(share);
- } else if (action == _copyLinkAction) {
- QApplication::clipboard()->setText(share->getLink().toString());
- } else if (action == _copyDirectLinkAction) {
- QApplication::clipboard()->setText(share->getDirectDownloadLink().toString());
- } else if (action == _emailLinkAction) {
- emailShareLink(share->getLink());
- } else if (action == _emailDirectLinkAction) {
- emailShareLink(share->getDirectDownloadLink());
- } else if (action == _openLinkAction) {
- openShareLink(share->getLink());
- }
-}
-
-void ShareLinkWidget::slotDeleteShareClicked()
-{
- auto share = sender()->property(propertyShareC).value<QSharedPointer<LinkShare>>();
- confirmAndDeleteShare(share);
-}
-
-SharePermissions ShareLinkWidget::uiPermissionState() const
-{
- if (_ui->radio_readWrite->isChecked()) {
- return SharePermissionRead | SharePermissionCreate
- | SharePermissionUpdate | SharePermissionDelete;
- } else if (_ui->radio_uploadOnly->isChecked()) {
- return SharePermissionCreate;
- }
- return SharePermissionRead;
-}
-
-void ShareLinkWidget::slotPermissionsClicked()
-{
- if (auto current = selectedShare()) {
- _ui->widget_editing->setEnabled(false);
- _pi_editing->startAnimation();
- _ui->errorLabel->hide();
-
- current->setPermissions(uiPermissionState());
- }
-}
-
-QSharedPointer<LinkShare> ShareLinkWidget::selectedShare() const
-{
- const auto items = _ui->linkShares->selectedItems();
- if (items.isEmpty()) {
- return QSharedPointer<LinkShare>();
- }
-
- return items.first()->data(Qt::UserRole).value<QSharedPointer<LinkShare>>();
-}
-
-QDate ShareLinkWidget::capabilityDefaultExpireDate() const
-{
- if (!_account->capabilities().sharePublicLinkDefaultExpire())
- return QDate();
- return QDate::currentDate().addDays(
- _account->capabilities().sharePublicLinkDefaultExpireDateDays());
-}
-
-void ShareLinkWidget::slotPermissionsSet()
-{
- if (sender() == selectedShare().data()) {
- slotShareSelectionChanged();
- }
-}
-
-void ShareLinkWidget::slotServerError(int code, const QString &message)
-{
- _pi_create->stopAnimation();
- _pi_date->stopAnimation();
- _pi_password->stopAnimation();
- _pi_editing->stopAnimation();
-
- qCWarning(lcSharing) << "Error from server" << code << message;
- displayError(message);
-}
-
-void ShareLinkWidget::slotPasswordSetError(int code, const QString &message)
-{
- slotServerError(code, message);
-
- _ui->checkBox_password->setEnabled(!_passwordRequired);
- _ui->lineEdit_password->setEnabled(true);
- _ui->lineEdit_password->setFocus();
-}
-
-void ShareLinkWidget::displayError(const QString &errMsg)
-{
- _ui->errorLabel->setText(errMsg);
- _ui->errorLabel->show();
-}
-}
diff --git a/src/gui/sharelinkwidget.h b/src/gui/sharelinkwidget.h
deleted file mode 100644
index e2cec5ed4..000000000
--- a/src/gui/sharelinkwidget.h
+++ /dev/null
@@ -1,153 +0,0 @@
-/*
- * Copyright (C) by Roeland Jago Douma <roeland@famdouma.nl>
- * Copyright (C) 2015 by Klaas Freitag <freitag@owncloud.com>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * for more details.
- */
-
-#ifndef SHARELINKWIDGET_H
-#define SHARELINKWIDGET_H
-
-#include "accountfwd.h"
-#include "sharepermissions.h"
-#include "QProgressIndicator.h"
-#include "sharepermissions.h"
-#include <QDialog>
-#include <QSharedPointer>
-#include <QList>
-
-class QMenu;
-class QTableWidgetItem;
-
-namespace OCC {
-
-namespace Ui {
- class ShareLinkWidget;
-}
-
-class AbstractCredentials;
-class QuotaInfo;
-class SyncResult;
-class LinkShare;
-class Share;
-class ShareManager;
-
-/**
- * @brief The ShareDialog class
- * @ingroup gui
- */
-class ShareLinkWidget : public QWidget
-{
- Q_OBJECT
-
-public:
- explicit ShareLinkWidget(AccountPtr account,
- const QString &sharePath,
- const QString &localPath,
- SharePermissions maxSharingPermissions,
- QWidget *parent = 0);
- ~ShareLinkWidget();
- void getShares();
-
-private slots:
- void slotSharesFetched(const QList<QSharedPointer<Share>> &shares);
- void slotShareSelectionChanged();
-
- void slotShareNameEntered();
- void slotDeleteShareClicked();
- void slotCheckBoxPasswordClicked();
- void slotCheckBoxExpireClicked();
- void slotPasswordReturnPressed();
- void slotPermissionsClicked();
- void slotExpireDateChanged(const QDate &date);
- void slotPasswordChanged(const QString &newText);
- void slotNameEdited(QTableWidgetItem *item);
-
- void slotContextMenuButtonClicked();
- void slotLinkContextMenuActionTriggered(QAction *action);
-
- void slotDeleteShareFetched();
- void slotCreateShareFetched(const QSharedPointer<LinkShare> &share);
- void slotCreateShareForbidden(const QString &message);
- void slotPasswordSet();
- void slotExpireSet();
- void slotPermissionsSet();
-
- void slotServerError(int code, const QString &message);
- void slotPasswordSetError(int code, const QString &message);
-
-private:
- void displayError(const QString &errMsg);
-
- void setPassword(const QString &password);
- void setExpireDate(const QDate &date);
-
- void copyShareLink(const QUrl &url);
- void emailShareLink(const QUrl &url);
- void openShareLink(const QUrl &url);
-
- /** Confirm with the user and then delete the share */
- void confirmAndDeleteShare(const QSharedPointer<LinkShare> &share);
-
- /** Retrieve a share's name, accounting for _namesSupported */
- QString shareName(const LinkShare &share) const;
-
- /** Permission implied by current ui state */
- SharePermissions uiPermissionState() const;
-
- /**
- * Retrieve the selected share, returning 0 if none.
- *
- * Returning 0 means that the "Create new..." item is selected.
- */
- QSharedPointer<LinkShare> selectedShare() const;
-
- /** Returns the default expire date as requested by the server, invalid otherwise */
- QDate capabilityDefaultExpireDate() const;
-
- Ui::ShareLinkWidget *_ui;
- AccountPtr _account;
- QString _sharePath;
- QString _localPath;
- QString _shareUrl;
-
- QProgressIndicator *_pi_create;
- QProgressIndicator *_pi_password;
- QProgressIndicator *_pi_date;
- QProgressIndicator *_pi_editing;
-
- ShareManager *_manager;
-
- bool _isFile;
- bool _passwordRequired;
- bool _expiryRequired;
- bool _namesSupported;
-
- // For maintaining the selection and temporary ui state
- // when getShares() finishes, but the selection didn't
- // change.
- QString _selectedShareId;
-
- // When a new share is created, we want to select it
- // the next time getShares() finishes. This stores its id.
- QString _newShareOverrideSelectionId;
-
- QMenu *_linkContextMenu = nullptr;
- QAction *_deleteLinkAction = nullptr;
- QAction *_openLinkAction = nullptr;
- QAction *_copyLinkAction = nullptr;
- QAction *_copyDirectLinkAction = nullptr;
- QAction *_emailLinkAction = nullptr;
- QAction *_emailDirectLinkAction = nullptr;
-};
-}
-
-#endif // SHARELINKWIDGET_H
diff --git a/src/gui/sharelinkwidget.ui b/src/gui/sharelinkwidget.ui
deleted file mode 100644
index 7482811ee..000000000
--- a/src/gui/sharelinkwidget.ui
+++ /dev/null
@@ -1,386 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<ui version="4.0">
- <class>OCC::ShareLinkWidget</class>
- <widget class="QWidget" name="OCC::ShareLinkWidget">
- <property name="geometry">
- <rect>
- <x>0</x>
- <y>0</y>
- <width>441</width>
- <height>568</height>
- </rect>
- </property>
- <property name="windowTitle">
- <string>Share NewDocument.odt</string>
- </property>
- <layout class="QVBoxLayout" name="verticalLayout">
- <item>
- <widget class="QLabel" name="publicLinkWarningLabel">
- <property name="text">
- <string>Anyone with the link has access to the file/folder</string>
- </property>
- <property name="textFormat">
- <enum>Qt::PlainText</enum>
- </property>
- <property name="wordWrap">
- <bool>true</bool>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QTableWidget" name="linkShares">
- <property name="sizePolicy">
- <sizepolicy hsizetype="MinimumExpanding" vsizetype="Expanding">
- <horstretch>0</horstretch>
- <verstretch>0</verstretch>
- </sizepolicy>
- </property>
- <property name="horizontalScrollBarPolicy">
- <enum>Qt::ScrollBarAlwaysOff</enum>
- </property>
- <property name="selectionMode">
- <enum>QAbstractItemView::SingleSelection</enum>
- </property>
- <property name="selectionBehavior">
- <enum>QAbstractItemView::SelectRows</enum>
- </property>
- <property name="showGrid">
- <bool>false</bool>
- </property>
- <property name="columnCount">
- <number>3</number>
- </property>
- <attribute name="horizontalHeaderVisible">
- <bool>false</bool>
- </attribute>
- <attribute name="verticalHeaderVisible">
- <bool>false</bool>
- </attribute>
- <column/>
- <column/>
- <column/>
- </widget>
- </item>
- <item>
- <widget class="QWidget" name="shareProperties" native="true">
- <layout class="QGridLayout" name="gridLayout_2">
- <property name="leftMargin">
- <number>0</number>
- </property>
- <property name="topMargin">
- <number>0</number>
- </property>
- <property name="rightMargin">
- <number>0</number>
- </property>
- <property name="bottomMargin">
- <number>0</number>
- </property>
- <item row="6" column="0">
- <layout class="QHBoxLayout" name="horizontalLayout_expire">
- <property name="leftMargin">
- <number>0</number>
- </property>
- <item>
- <widget class="QCheckBox" name="checkBox_expire">
- <property name="text">
- <string>Set &amp;expiration date</string>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QDateEdit" name="calendar">
- <property name="calendarPopup">
- <bool>true</bool>
- </property>
- </widget>
- </item>
- </layout>
- </item>
- <item row="4" column="0">
- <layout class="QHBoxLayout" name="horizontalLayout">
- <property name="leftMargin">
- <number>20</number>
- </property>
- <item>
- <widget class="QLineEdit" name="lineEdit_password">
- <property name="echoMode">
- <enum>QLineEdit::Password</enum>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QPushButton" name="pushButton_setPassword">
- <property name="sizePolicy">
- <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
- <horstretch>0</horstretch>
- <verstretch>0</verstretch>
- </sizepolicy>
- </property>
- <property name="text">
- <string>Set &amp;password </string>
- </property>
- </widget>
- </item>
- </layout>
- </item>
- <item row="3" column="0">
- <layout class="QHBoxLayout" name="horizontalLayout_password">
- <item>
- <widget class="QCheckBox" name="checkBox_password">
- <property name="sizePolicy">
- <sizepolicy hsizetype="Maximum" vsizetype="Maximum">
- <horstretch>0</horstretch>
- <verstretch>0</verstretch>
- </sizepolicy>
- </property>
- <property name="text">
- <string>Set password</string>
- </property>
- </widget>
- </item>
- <item>
- <spacer name="horizontalSpacer_3">
- <property name="orientation">
- <enum>Qt::Horizontal</enum>
- </property>
- <property name="sizeHint" stdset="0">
- <size>
- <width>40</width>
- <height>20</height>
- </size>
- </property>
- </spacer>
- </item>
- </layout>
- </item>
- <item row="2" column="0">
- <widget class="QWidget" name="widget_editing" native="true">
- <layout class="QGridLayout" name="layout_editing">
- <property name="leftMargin">
- <number>0</number>
- </property>
- <property name="topMargin">
- <number>0</number>
- </property>
- <property name="rightMargin">
- <number>0</number>
- </property>
- <property name="verticalSpacing">
- <number>0</number>
- </property>
- <item row="1" column="0">
- <widget class="QLabel" name="label_readOnly">
- <property name="sizePolicy">
- <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
- <horstretch>0</horstretch>
- <verstretch>0</verstretch>
- </sizepolicy>
- </property>
- <property name="text">
- <string>Recipients can view or download contents.</string>
- </property>
- <property name="wordWrap">
- <bool>true</bool>
- </property>
- </widget>
- </item>
- <item row="2" column="0">
- <spacer name="verticalSpacer">
- <property name="orientation">
- <enum>Qt::Vertical</enum>
- </property>
- <property name="sizeType">
- <enum>QSizePolicy::Fixed</enum>
- </property>
- <property name="sizeHint" stdset="0">
- <size>
- <width>20</width>
- <height>6</height>
- </size>
- </property>
- </spacer>
- </item>
- <item row="6" column="0">
- <widget class="QRadioButton" name="radio_uploadOnly">
- <property name="text">
- <string>Upload only (File Drop)</string>
- </property>
- </widget>
- </item>
- <item row="7" column="0">
- <widget class="QLabel" name="label_uploadOnly">
- <property name="sizePolicy">
- <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
- <horstretch>0</horstretch>
- <verstretch>0</verstretch>
- </sizepolicy>
- </property>
- <property name="text">
- <string>Receive files from others without revealing the contents of the folder.</string>
- </property>
- <property name="wordWrap">
- <bool>true</bool>
- </property>
- </widget>
- </item>
- <item row="0" column="0">
- <widget class="QRadioButton" name="radio_readOnly">
- <property name="text">
- <string>Download / View</string>
- </property>
- </widget>
- </item>
- <item row="3" column="0">
- <widget class="QRadioButton" name="radio_readWrite">
- <property name="text">
- <string>Download / View / Upload</string>
- </property>
- </widget>
- </item>
- <item row="4" column="0">
- <widget class="QLabel" name="label_readWrite">
- <property name="sizePolicy">
- <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
- <horstretch>0</horstretch>
- <verstretch>0</verstretch>
- </sizepolicy>
- </property>
- <property name="text">
- <string>Recipients can view, download, edit, delete and upload contents.</string>
- </property>
- <property name="wordWrap">
- <bool>true</bool>
- </property>
- </widget>
- </item>
- <item row="5" column="0">
- <spacer name="verticalSpacer_2">
- <property name="orientation">
- <enum>Qt::Vertical</enum>
- </property>
- <property name="sizeType">
- <enum>QSizePolicy::Fixed</enum>
- </property>
- <property name="sizeHint" stdset="0">
- <size>
- <width>20</width>
- <height>6</height>
- </size>
- </property>
- </spacer>
- </item>
- </layout>
- </widget>
- </item>
- </layout>
- </widget>
- </item>
- <item>
- <widget class="QWidget" name="create" native="true">
- <layout class="QHBoxLayout" name="horizontalLayout_create">
- <property name="leftMargin">
- <number>0</number>
- </property>
- <property name="topMargin">
- <number>0</number>
- </property>
- <property name="rightMargin">
- <number>0</number>
- </property>
- <property name="bottomMargin">
- <number>0</number>
- </property>
- <item>
- <widget class="QLabel" name="nameLabel">
- <property name="text">
- <string>Name:</string>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QLineEdit" name="nameLineEdit">
- <property name="placeholderText">
- <string>Enter name of new share...</string>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QPushButton" name="createShareButton">
- <property name="text">
- <string>&amp;Create</string>
- </property>
- </widget>
- </item>
- </layout>
- </widget>
- </item>
- <item>
- <widget class="QLabel" name="errorLabel">
- <property name="sizePolicy">
- <sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
- <horstretch>0</horstretch>
- <verstretch>0</verstretch>
- </sizepolicy>
- </property>
- <property name="palette">
- <palette>
- <active>
- <colorrole role="WindowText">
- <brush brushstyle="SolidPattern">
- <color alpha="255">
- <red>255</red>
- <green>0</green>
- <blue>0</blue>
- </color>
- </brush>
- </colorrole>
- </active>
- <inactive>
- <colorrole role="WindowText">
- <brush brushstyle="SolidPattern">
- <color alpha="255">
- <red>255</red>
- <green>0</green>
- <blue>0</blue>
- </color>
- </brush>
- </colorrole>
- </inactive>
- <disabled>
- <colorrole role="WindowText">
- <brush brushstyle="SolidPattern">
- <color alpha="255">
- <red>123</red>
- <green>121</green>
- <blue>134</blue>
- </color>
- </brush>
- </colorrole>
- </disabled>
- </palette>
- </property>
- <property name="text">
- <string>TextLabel</string>
- </property>
- <property name="textFormat">
- <enum>Qt::PlainText</enum>
- </property>
- </widget>
- </item>
- </layout>
- </widget>
- <layoutdefault spacing="6" margin="11"/>
- <tabstops>
- <tabstop>nameLineEdit</tabstop>
- <tabstop>createShareButton</tabstop>
- <tabstop>linkShares</tabstop>
- <tabstop>checkBox_password</tabstop>
- <tabstop>lineEdit_password</tabstop>
- <tabstop>pushButton_setPassword</tabstop>
- <tabstop>checkBox_expire</tabstop>
- <tabstop>calendar</tabstop>
- </tabstops>
- <resources/>
- <connections/>
-</ui>
diff --git a/src/gui/shareusergroupwidget.cpp b/src/gui/shareusergroupwidget.cpp
deleted file mode 100644
index ba695d4b4..000000000
--- a/src/gui/shareusergroupwidget.cpp
+++ /dev/null
@@ -1,627 +0,0 @@
-/*
- * Copyright (C) by Roeland Jago Douma <roeland@owncloud.com>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * for more details.
- */
-
-#include "shareusergroupwidget.h"
-#include "ui_shareusergroupwidget.h"
-#include "ui_shareuserline.h"
-#include "account.h"
-#include "folderman.h"
-#include "folder.h"
-#include "accountmanager.h"
-#include "theme.h"
-#include "configfile.h"
-#include "capabilities.h"
-#include "guiutility.h"
-#include "thumbnailjob.h"
-#include "sharee.h"
-#include "sharemanager.h"
-
-#include "QProgressIndicator.h"
-#include <QBuffer>
-#include <QFileIconProvider>
-#include <QClipboard>
-#include <QFileInfo>
-#include <QAbstractProxyModel>
-#include <QCompleter>
-#include <qscrollarea.h>
-#include <qlayout.h>
-#include <QPropertyAnimation>
-#include <QMenu>
-#include <QAction>
-#include <QDesktopServices>
-#include <QMessageBox>
-#include <QCryptographicHash>
-#include <QColor>
-#include <QPainter>
-
-namespace OCC {
-
-ShareUserGroupWidget::ShareUserGroupWidget(AccountPtr account,
- const QString &sharePath,
- const QString &localPath,
- SharePermissions maxSharingPermissions,
- const QString &privateLinkUrl,
- QWidget *parent)
- : QWidget(parent)
- , _ui(new Ui::ShareUserGroupWidget)
- , _account(account)
- , _sharePath(sharePath)
- , _localPath(localPath)
- , _maxSharingPermissions(maxSharingPermissions)
- , _privateLinkUrl(privateLinkUrl)
- , _disableCompleterActivated(false)
-{
- setAttribute(Qt::WA_DeleteOnClose);
- setObjectName("SharingDialogUG"); // required as group for saveGeometry call
-
- _ui->setupUi(this);
-
- //Is this a file or folder?
- _isFile = QFileInfo(localPath).isFile();
-
- _completer = new QCompleter(this);
- _completerModel = new ShareeModel(_account,
- _isFile ? QLatin1String("file") : QLatin1String("folder"),
- _completer);
- connect(_completerModel, &ShareeModel::shareesReady, this, &ShareUserGroupWidget::slotShareesReady);
- connect(_completerModel, &ShareeModel::displayErrorMessage, this, &ShareUserGroupWidget::displayError);
-
- _completer->setModel(_completerModel);
- _completer->setCaseSensitivity(Qt::CaseInsensitive);
- _completer->setCompletionMode(QCompleter::UnfilteredPopupCompletion);
- _ui->shareeLineEdit->setCompleter(_completer);
-
- _manager = new ShareManager(_account, this);
- connect(_manager, &ShareManager::sharesFetched, this, &ShareUserGroupWidget::slotSharesFetched);
- connect(_manager, &ShareManager::shareCreated, this, &ShareUserGroupWidget::getShares);
- connect(_manager, &ShareManager::serverError, this, &ShareUserGroupWidget::displayError);
- connect(_ui->shareeLineEdit, &QLineEdit::returnPressed, this, &ShareUserGroupWidget::slotLineEditReturn);
- connect(_ui->privateLinkText, &QLabel::linkActivated, this, &ShareUserGroupWidget::slotPrivateLinkShare);
-
- // By making the next two QueuedConnections we can override
- // the strings the completer sets on the line edit.
- connect(_completer, SIGNAL(activated(QModelIndex)), SLOT(slotCompleterActivated(QModelIndex)),
- Qt::QueuedConnection);
- connect(_completer, SIGNAL(highlighted(QModelIndex)), SLOT(slotCompleterHighlighted(QModelIndex)),
- Qt::QueuedConnection);
-
- // Queued connection so this signal is recieved after textChanged
- connect(_ui->shareeLineEdit, &QLineEdit::textEdited,
- this, &ShareUserGroupWidget::slotLineEditTextEdited, Qt::QueuedConnection);
- connect(&_completionTimer, &QTimer::timeout, this, &ShareUserGroupWidget::searchForSharees);
- _completionTimer.setSingleShot(true);
- _completionTimer.setInterval(600);
-
- setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Expanding);
- _ui->errorLabel->hide();
-
- // Setup the sharee search progress indicator
- _ui->shareeHorizontalLayout->addWidget(&_pi_sharee);
-}
-
-ShareUserGroupWidget::~ShareUserGroupWidget()
-{
- delete _ui;
-}
-
-void ShareUserGroupWidget::on_shareeLineEdit_textChanged(const QString &)
-{
- _completionTimer.stop();
-}
-
-void ShareUserGroupWidget::slotLineEditTextEdited(const QString &text)
-{
- _disableCompleterActivated = false;
- // First textChanged is called first and we stopped the timer when the text is changed, programatically or not
- // Then we restart the timer here if the user touched a key
- if (!text.isEmpty()) {
- _completionTimer.start();
- }
-}
-
-void ShareUserGroupWidget::slotLineEditReturn()
-{
- _disableCompleterActivated = false;
- // did the user type in one of the options?
- const auto text = _ui->shareeLineEdit->text();
- for (int i = 0; i < _completerModel->rowCount(); ++i) {
- const auto sharee = _completerModel->getSharee(i);
- if (sharee->format() == text
- || sharee->displayName() == text
- || sharee->shareWith() == text) {
- slotCompleterActivated(_completerModel->index(i));
- // make sure we do not send the same item twice (because return is called when we press
- // return to activate an item inthe completer)
- _disableCompleterActivated = true;
- return;
- }
- }
-
- // nothing found? try to refresh completion
- _completionTimer.start();
-}
-
-
-void ShareUserGroupWidget::searchForSharees()
-{
- _completionTimer.stop();
- _pi_sharee.startAnimation();
- ShareeModel::ShareeSet blacklist;
-
- // Add the current user to _sharees since we can't share with ourself
- QSharedPointer<Sharee> currentUser(new Sharee(_account->credentials()->user(), "", Sharee::Type::User));
- blacklist << currentUser;
-
- foreach (auto sw, _ui->scrollArea->findChildren<ShareUserLine *>()) {
- blacklist << sw->share()->getShareWith();
- }
- _ui->errorLabel->hide();
- _completerModel->fetch(_ui->shareeLineEdit->text(), blacklist);
-}
-
-void ShareUserGroupWidget::getShares()
-{
- _manager->fetchShares(_sharePath);
-}
-
-void ShareUserGroupWidget::slotSharesFetched(const QList<QSharedPointer<Share>> &shares)
-{
- QScrollArea *scrollArea = _ui->scrollArea;
-
- auto newViewPort = new QWidget(scrollArea);
- auto layout = new QVBoxLayout(newViewPort);
- layout->setMargin(0);
- layout->setSpacing(0);
-
- QSize minimumSize = newViewPort->sizeHint();
- int x = 0;
-
- foreach (const auto &share, shares) {
- // We don't handle link shares
- if (share->getShareType() == Share::TypeLink) {
- continue;
- }
-
- ShareUserLine *s = new ShareUserLine(share, _maxSharingPermissions, _isFile, _ui->scrollArea);
- connect(s, &ShareUserLine::resizeRequested, this, &ShareUserGroupWidget::slotAdjustScrollWidgetSize);
- connect(s, &ShareUserLine::visualDeletionDone, this, &ShareUserGroupWidget::getShares);
- s->setBackgroundRole(layout->count() % 2 == 0 ? QPalette::Base : QPalette::AlternateBase);
- layout->addWidget(s);
-
- x++;
- if (x <= 3) {
- minimumSize = newViewPort->sizeHint();
- } else {
- minimumSize.rwidth() = qMax(newViewPort->sizeHint().width(), minimumSize.width());
- }
- }
- if (layout->isEmpty()) {
- layout->addWidget(new QLabel(tr("The item is not shared with any users or groups")));
- } else {
- layout->addStretch(1);
- }
-
- minimumSize.rwidth() += layout->spacing();
- minimumSize.rheight() += layout->spacing();
- scrollArea->setMinimumSize(minimumSize);
- scrollArea->setWidget(newViewPort);
-
- _disableCompleterActivated = false;
- _ui->shareeLineEdit->setEnabled(true);
-}
-
-void ShareUserGroupWidget::slotAdjustScrollWidgetSize()
-{
- QScrollArea *scrollArea = _ui->scrollArea;
- if (scrollArea->findChildren<ShareUserLine *>().count() <= 3) {
- auto minimumSize = scrollArea->widget()->sizeHint();
- auto spacing = scrollArea->widget()->layout()->spacing();
- minimumSize.rwidth() += spacing;
- minimumSize.rheight() += spacing;
- scrollArea->setMinimumSize(minimumSize);
- }
-}
-
-void ShareUserGroupWidget::slotPrivateLinkShare()
-{
- auto menu = new QMenu(this);
- menu->setAttribute(Qt::WA_DeleteOnClose);
-
- menu->addAction(tr("Open link in browser"),
- this, SLOT(slotPrivateLinkOpenBrowser()));
- menu->addAction(tr("Copy link to clipboard"),
- this, SLOT(slotPrivateLinkCopy()));
- menu->addAction(tr("Send link by email"),
- this, SLOT(slotPrivateLinkEmail()));
-
- menu->exec(QCursor::pos());
-}
-
-void ShareUserGroupWidget::slotShareesReady()
-{
- _pi_sharee.stopAnimation();
- if (_completerModel->rowCount() == 0) {
- displayError(0, tr("No results for '%1'").arg(_completerModel->currentSearch()));
- return;
- }
- _completer->complete();
-}
-
-void ShareUserGroupWidget::slotCompleterActivated(const QModelIndex &index)
-{
- if (_disableCompleterActivated)
- return;
- // The index is an index from the QCompletion model which is itelf a proxy
- // model proxying the _completerModel
- auto sharee = qvariant_cast<QSharedPointer<Sharee>>(index.data(Qt::UserRole));
- if (sharee.isNull()) {
- return;
- }
-
- /*
- * Add spinner to the bottom of the widget list
- */
- auto viewPort = _ui->scrollArea->widget();
- auto layout = qobject_cast<QVBoxLayout *>(viewPort->layout());
- auto indicator = new QProgressIndicator(viewPort);
- indicator->startAnimation();
- if (layout->count() == 1) {
- // No shares yet! Remove the label, add some stretch.
- delete layout->itemAt(0)->widget();
- layout->addStretch(1);
- }
- layout->insertWidget(layout->count() - 1, indicator);
-
- /*
- * Don't send the reshare permissions for federated shares for servers <9.1
- * https://github.com/owncloud/core/issues/22122#issuecomment-185637344
- * https://github.com/owncloud/client/issues/4996
- */
- if (sharee->type() == Sharee::Federated
- && _account->serverVersionInt() < Account::makeServerVersion(9, 1, 0)) {
- int permissions = SharePermissionRead | SharePermissionUpdate;
- if (!_isFile) {
- permissions |= SharePermissionCreate | SharePermissionDelete;
- }
- _manager->createShare(_sharePath, Share::ShareType(sharee->type()),
- sharee->shareWith(), SharePermission(permissions));
- } else {
- _manager->createShare(_sharePath, Share::ShareType(sharee->type()),
- sharee->shareWith(), _maxSharingPermissions);
- }
-
- _ui->shareeLineEdit->setEnabled(false);
- _ui->shareeLineEdit->setText(QString());
-}
-
-void ShareUserGroupWidget::slotCompleterHighlighted(const QModelIndex &index)
-{
- // By default the completer would set the text to EditRole,
- // override that here.
- _ui->shareeLineEdit->setText(index.data(Qt::DisplayRole).toString());
-}
-
-void ShareUserGroupWidget::displayError(int code, const QString &message)
-{
- _pi_sharee.stopAnimation();
-
- // Also remove the spinner in the widget list, if any
- foreach (auto pi, _ui->scrollArea->findChildren<QProgressIndicator *>()) {
- delete pi;
- }
-
- qCWarning(lcSharing) << "Sharing error from server" << code << message;
- _ui->errorLabel->setText(message);
- _ui->errorLabel->show();
- _ui->shareeLineEdit->setEnabled(true);
-}
-
-void ShareUserGroupWidget::slotPrivateLinkOpenBrowser()
-{
- Utility::openBrowser(_privateLinkUrl, this);
-}
-
-void ShareUserGroupWidget::slotPrivateLinkCopy()
-{
- QApplication::clipboard()->setText(_privateLinkUrl);
-}
-
-void ShareUserGroupWidget::slotPrivateLinkEmail()
-{
- Utility::openEmailComposer(
- tr("I shared something with you"),
- _privateLinkUrl,
- this);
-}
-
-ShareUserLine::ShareUserLine(QSharedPointer<Share> share,
- SharePermissions maxSharingPermissions,
- bool isFile,
- QWidget *parent)
- : QWidget(parent)
- , _ui(new Ui::ShareUserLine)
- , _share(share)
- , _isFile(isFile)
-{
- _ui->setupUi(this);
-
- _ui->sharedWith->setText(share->getShareWith()->format());
-
- // Create detailed permissions menu
- QMenu *menu = new QMenu(this);
- _permissionCreate = new QAction(tr("create"), this);
- _permissionCreate->setCheckable(true);
- _permissionCreate->setEnabled(maxSharingPermissions & SharePermissionCreate);
- _permissionUpdate = new QAction(tr("change"), this);
- _permissionUpdate->setCheckable(true);
- _permissionUpdate->setEnabled(maxSharingPermissions & SharePermissionUpdate);
- _permissionDelete = new QAction(tr("delete"), this);
- _permissionDelete->setCheckable(true);
- _permissionDelete->setEnabled(maxSharingPermissions & SharePermissionDelete);
-
- menu->addAction(_permissionUpdate);
- /*
- * Files can't have create or delete permissions
- */
- if (!_isFile) {
- menu->addAction(_permissionCreate);
- menu->addAction(_permissionDelete);
- }
- _ui->permissionToolButton->setMenu(menu);
- _ui->permissionToolButton->setPopupMode(QToolButton::InstantPopup);
-
- QIcon icon(QLatin1String(":/client/resources/more.svg"));
- _ui->permissionToolButton->setIcon(icon);
-
- // If there's only a single entry in the detailed permission menu, hide it
- if (menu->actions().size() == 1) {
- _ui->permissionToolButton->hide();
- }
-
- // Set the permissions checkboxes
- displayPermissions();
-
- _ui->permissionShare->setEnabled(maxSharingPermissions & SharePermissionShare);
- _ui->permissionsEdit->setEnabled(maxSharingPermissions
- & (SharePermissionCreate | SharePermissionUpdate | SharePermissionDelete));
-
- connect(_permissionUpdate, &QAction::triggered, this, &ShareUserLine::slotPermissionsChanged);
- connect(_permissionCreate, &QAction::triggered, this, &ShareUserLine::slotPermissionsChanged);
- connect(_permissionDelete, &QAction::triggered, this, &ShareUserLine::slotPermissionsChanged);
- connect(_ui->permissionShare, &QAbstractButton::clicked, this, &ShareUserLine::slotPermissionsChanged);
- connect(_ui->permissionsEdit, &QAbstractButton::clicked, this, &ShareUserLine::slotEditPermissionsChanged);
-
- /*
- * We don't show permssion share for federated shares with server <9.1
- * https://github.com/owncloud/core/issues/22122#issuecomment-185637344
- * https://github.com/owncloud/client/issues/4996
- */
- if (share->getShareType() == Share::TypeRemote
- && share->account()->serverVersionInt() < Account::makeServerVersion(9, 1, 0)) {
- _ui->permissionShare->setVisible(false);
- _ui->permissionToolButton->setVisible(false);
- }
-
- connect(share.data(), &Share::permissionsSet, this, &ShareUserLine::slotPermissionsSet);
- connect(share.data(), &Share::shareDeleted, this, &ShareUserLine::slotShareDeleted);
-
- _ui->deleteShareButton->setIcon(QIcon::fromTheme(QLatin1String("user-trash"),
- QIcon(QLatin1String(":/client/resources/delete.png"))));
-
- if (!share->account()->capabilities().shareResharing()) {
- _ui->permissionShare->hide();
- }
-
- loadAvatar();
-}
-
-void ShareUserLine::loadAvatar()
-{
- const int avatarSize = 36;
-
- // Set size of the placeholder
- _ui->avatar->setMinimumHeight(avatarSize);
- _ui->avatar->setMinimumWidth(avatarSize);
- _ui->avatar->setMaximumHeight(avatarSize);
- _ui->avatar->setMaximumWidth(avatarSize);
- _ui->avatar->setAlignment(Qt::AlignCenter);
-
- /* Create the fallback avatar.
- *
- * This will be shown until the avatar image data arrives.
- */
- const QByteArray hash = QCryptographicHash::hash(_ui->sharedWith->text().toUtf8(), QCryptographicHash::Md5);
- double hue = static_cast<quint8>(hash[0]) / 255.;
-
- // See core/js/placeholder.js for details on colors and styling
- const QColor bg = QColor::fromHslF(hue, 0.7, 0.68);
- const QString style = QString(R"(* {
- color: #fff;
- background-color: %1;
- border-radius: %2px;
- text-align: center;
- line-height: %2px;
- font-size: %2px;
- })").arg(bg.name(), QString::number(avatarSize / 2));
- _ui->avatar->setStyleSheet(style);
-
- // The avatar label is the first character of the user name.
- const QString text = _share->getShareWith()->displayName();
- _ui->avatar->setText(text.at(0).toUpper());
-
- /* Start the network job to fetch the avatar data.
- *
- * Currently only regular users can have avatars.
- */
- if (_share->getShareWith()->type() == Sharee::User) {
- AvatarJob *job = new AvatarJob(_share->account(), _share->getShareWith()->shareWith(), avatarSize, this);
- connect(job, &AvatarJob::avatarPixmap, this, &ShareUserLine::slotAvatarLoaded);
- job->start();
- }
-}
-
-void ShareUserLine::slotAvatarLoaded(QImage avatar)
-{
- if (avatar.isNull())
- return;
-
- avatar = AvatarJob::makeCircularAvatar(avatar);
- _ui->avatar->setPixmap(QPixmap::fromImage(avatar));
-
- // Remove the stylesheet for the fallback avatar
- _ui->avatar->setStyleSheet("");
-}
-
-void ShareUserLine::on_deleteShareButton_clicked()
-{
- setEnabled(false);
- _share->deleteShare();
-}
-
-ShareUserLine::~ShareUserLine()
-{
- delete _ui;
-}
-
-void ShareUserLine::slotEditPermissionsChanged()
-{
- setEnabled(false);
-
- // Can never manually be set to "partial".
- // This works because the state cycle for clicking is
- // unchecked -> partial -> checked -> unchecked.
- if (_ui->permissionsEdit->checkState() == Qt::PartiallyChecked) {
- _ui->permissionsEdit->setCheckState(Qt::Checked);
- }
-
- Share::Permissions permissions = SharePermissionRead;
-
- if (_ui->permissionShare->checkState() == Qt::Checked) {
- permissions |= SharePermissionShare;
- }
-
- if (_ui->permissionsEdit->checkState() == Qt::Checked) {
- if (_permissionUpdate->isEnabled())
- permissions |= SharePermissionUpdate;
-
- /*
- * Files can't have create or delete permisisons
- */
- if (!_isFile) {
- if (_permissionCreate->isEnabled())
- permissions |= SharePermissionCreate;
- if (_permissionDelete->isEnabled())
- permissions |= SharePermissionDelete;
- }
- }
-
- _share->setPermissions(permissions);
-}
-
-void ShareUserLine::slotPermissionsChanged()
-{
- setEnabled(false);
-
- Share::Permissions permissions = SharePermissionRead;
-
- if (_permissionUpdate->isChecked()) {
- permissions |= SharePermissionUpdate;
- }
-
- if (_permissionCreate->isChecked()) {
- permissions |= SharePermissionCreate;
- }
-
- if (_permissionDelete->isChecked()) {
- permissions |= SharePermissionDelete;
- }
-
- if (_ui->permissionShare->checkState() == Qt::Checked) {
- permissions |= SharePermissionShare;
- }
-
- _share->setPermissions(permissions);
-}
-
-void ShareUserLine::slotDeleteAnimationFinished()
-{
- emit resizeRequested();
- emit visualDeletionDone();
- deleteLater();
-
- // There is a painting bug where a small line of this widget isn't
- // properly cleared. This explicit repaint() call makes sure any trace of
- // the share widget is removed once it's destroyed. #4189
- connect(this, SIGNAL(destroyed(QObject *)), parentWidget(), SLOT(repaint()));
-}
-
-void ShareUserLine::slotShareDeleted()
-{
- QPropertyAnimation *animation = new QPropertyAnimation(this, "maximumHeight", this);
-
- animation->setDuration(500);
- animation->setStartValue(height());
- animation->setEndValue(0);
-
- connect(animation, &QAbstractAnimation::finished, this, &ShareUserLine::slotDeleteAnimationFinished);
- connect(animation, &QVariantAnimation::valueChanged, this, &ShareUserLine::resizeRequested);
-
- animation->start();
-}
-
-void ShareUserLine::slotPermissionsSet()
-{
- displayPermissions();
- setEnabled(true);
-}
-
-QSharedPointer<Share> ShareUserLine::share() const
-{
- return _share;
-}
-
-void ShareUserLine::displayPermissions()
-{
- auto perm = _share->getPermissions();
-
- _permissionUpdate->setChecked(false);
- _permissionCreate->setChecked(false);
- _permissionDelete->setChecked(false);
- if (perm & SharePermissionUpdate) {
- _permissionUpdate->setChecked(true);
- }
- if (!_isFile && perm & SharePermissionCreate) {
- _permissionCreate->setChecked(true);
- }
- if (!_isFile && perm & SharePermissionDelete) {
- _permissionDelete->setChecked(true);
- }
-
- if (perm & SharePermissionUpdate
- && (_isFile
- || (perm & SharePermissionCreate
- && perm & SharePermissionDelete))) {
- _ui->permissionsEdit->setCheckState(Qt::Checked);
- } else if (perm & (SharePermissionUpdate | SharePermissionCreate | SharePermissionDelete)) {
- _ui->permissionsEdit->setCheckState(Qt::PartiallyChecked);
- } else {
- _ui->permissionsEdit->setCheckState(Qt::Unchecked);
- }
-
- _ui->permissionShare->setCheckState(Qt::Unchecked);
- if (_share->getPermissions() & SharePermissionShare) {
- _ui->permissionShare->setCheckState(Qt::Checked);
- }
-}
-}
diff --git a/src/gui/shareusergroupwidget.h b/src/gui/shareusergroupwidget.h
deleted file mode 100644
index e891359b9..000000000
--- a/src/gui/shareusergroupwidget.h
+++ /dev/null
@@ -1,150 +0,0 @@
-/*
- * Copyright (C) by Roeland Jago Douma <roeland@owncloud.com>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * for more details.
- */
-
-#ifndef SHAREUSERGROUPWIDGET_H
-#define SHAREUSERGROUPWIDGET_H
-
-#include "accountfwd.h"
-#include "sharepermissions.h"
-#include "QProgressIndicator.h"
-#include <QDialog>
-#include <QWidget>
-#include <QSharedPointer>
-#include <QList>
-#include <QVector>
-#include <QTimer>
-
-class QAction;
-class QCompleter;
-class QModelIndex;
-
-namespace OCC {
-
-namespace Ui {
- class ShareUserGroupWidget;
- class ShareUserLine;
-}
-
-class AbstractCredentials;
-class QuotaInfo;
-class SyncResult;
-class Share;
-class Sharee;
-class ShareManager;
-class ShareeModel;
-
-/**
- * @brief The ShareDialog (user/group) class
- * @ingroup gui
- */
-class ShareUserGroupWidget : public QWidget
-{
- Q_OBJECT
-
-public:
- explicit ShareUserGroupWidget(AccountPtr account,
- const QString &sharePath,
- const QString &localPath,
- SharePermissions maxSharingPermissions,
- const QString &privateLinkUrl,
- QWidget *parent = 0);
- ~ShareUserGroupWidget();
-
-public slots:
- void getShares();
-
-private slots:
- void slotSharesFetched(const QList<QSharedPointer<Share>> &shares);
-
- void on_shareeLineEdit_textChanged(const QString &text);
- void searchForSharees();
- void slotLineEditTextEdited(const QString &text);
-
- void slotLineEditReturn();
- void slotCompleterActivated(const QModelIndex &index);
- void slotCompleterHighlighted(const QModelIndex &index);
- void slotShareesReady();
- void slotAdjustScrollWidgetSize();
- void slotPrivateLinkShare();
- void displayError(int code, const QString &message);
-
- void slotPrivateLinkOpenBrowser();
- void slotPrivateLinkCopy();
- void slotPrivateLinkEmail();
-
-private:
- Ui::ShareUserGroupWidget *_ui;
- AccountPtr _account;
- QString _sharePath;
- QString _localPath;
- SharePermissions _maxSharingPermissions;
- QString _privateLinkUrl;
-
- QCompleter *_completer;
- ShareeModel *_completerModel;
- QTimer _completionTimer;
-
- bool _isFile;
- bool _disableCompleterActivated; // in order to avoid that we share the contents twice
- ShareManager *_manager;
-
- QProgressIndicator _pi_sharee;
-};
-
-/**
- * The widget displayed for each user/group share
- */
-class ShareUserLine : public QWidget
-{
- Q_OBJECT
-
-public:
- explicit ShareUserLine(QSharedPointer<Share> Share,
- SharePermissions maxSharingPermissions,
- bool isFile,
- QWidget *parent = 0);
- ~ShareUserLine();
-
- QSharedPointer<Share> share() const;
-
-signals:
- void visualDeletionDone();
- void resizeRequested();
-
-private slots:
- void on_deleteShareButton_clicked();
- void slotPermissionsChanged();
- void slotEditPermissionsChanged();
- void slotDeleteAnimationFinished();
-
- void slotShareDeleted();
- void slotPermissionsSet();
-
- void slotAvatarLoaded(QImage avatar);
-
-private:
- void displayPermissions();
- void loadAvatar();
-
- Ui::ShareUserLine *_ui;
- QSharedPointer<Share> _share;
- bool _isFile;
-
- QAction *_permissionCreate;
- QAction *_permissionUpdate;
- QAction *_permissionDelete;
-};
-}
-
-#endif // SHAREUSERGROUPWIDGET_H
diff --git a/src/gui/shareusergroupwidget.ui b/src/gui/shareusergroupwidget.ui
deleted file mode 100644
index 028d897ce..000000000
--- a/src/gui/shareusergroupwidget.ui
+++ /dev/null
@@ -1,120 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<ui version="4.0">
- <class>OCC::ShareUserGroupWidget</class>
- <widget class="QWidget" name="OCC::ShareUserGroupWidget">
- <property name="geometry">
- <rect>
- <x>0</x>
- <y>0</y>
- <width>397</width>
- <height>273</height>
- </rect>
- </property>
- <property name="windowTitle">
- <string>Share NewDocument.odt</string>
- </property>
- <layout class="QVBoxLayout" name="verticalLayout">
- <item>
- <layout class="QHBoxLayout" name="shareeHorizontalLayout">
- <item>
- <widget class="QLineEdit" name="shareeLineEdit">
- <property name="placeholderText">
- <string>Share with users or groups ...</string>
- </property>
- </widget>
- </item>
- </layout>
- </item>
- <item>
- <widget class="QLabel" name="errorLabel">
- <property name="palette">
- <palette>
- <active>
- <colorrole role="WindowText">
- <brush brushstyle="SolidPattern">
- <color alpha="255">
- <red>255</red>
- <green>0</green>
- <blue>0</blue>
- </color>
- </brush>
- </colorrole>
- </active>
- <inactive>
- <colorrole role="WindowText">
- <brush brushstyle="SolidPattern">
- <color alpha="255">
- <red>255</red>
- <green>0</green>
- <blue>0</blue>
- </color>
- </brush>
- </colorrole>
- </inactive>
- <disabled>
- <colorrole role="WindowText">
- <brush brushstyle="SolidPattern">
- <color alpha="255">
- <red>123</red>
- <green>121</green>
- <blue>134</blue>
- </color>
- </brush>
- </colorrole>
- </disabled>
- </palette>
- </property>
- <property name="text">
- <string notr="true">Placeholder for Error text</string>
- </property>
- <property name="textFormat">
- <enum>Qt::PlainText</enum>
- </property>
- <property name="wordWrap">
- <bool>true</bool>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QScrollArea" name="scrollArea">
- <property name="sizePolicy">
- <sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
- <horstretch>0</horstretch>
- <verstretch>0</verstretch>
- </sizepolicy>
- </property>
- <property name="horizontalScrollBarPolicy">
- <enum>Qt::ScrollBarAlwaysOff</enum>
- </property>
- <property name="widgetResizable">
- <bool>true</bool>
- </property>
- <widget class="QWidget" name="scrollAreaWidgetContents">
- <property name="geometry">
- <rect>
- <x>0</x>
- <y>0</y>
- <width>377</width>
- <height>169</height>
- </rect>
- </property>
- <layout class="QVBoxLayout" name="verticalLayout_3"/>
- </widget>
- </widget>
- </item>
- <item>
- <widget class="QLabel" name="privateLinkText">
- <property name="text">
- <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;You can direct people to this shared file or folder &lt;a href=&quot;private link menu&quot;&gt;&lt;span style=&quot; text-decoration: underline; color:#0000ff;&quot;&gt;by giving them a private link&lt;/span&gt;&lt;/a&gt;.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
- </property>
- <property name="wordWrap">
- <bool>true</bool>
- </property>
- </widget>
- </item>
- </layout>
- </widget>
- <layoutdefault spacing="6" margin="11"/>
- <resources/>
- <connections/>
-</ui>
diff --git a/src/gui/shareuserline.ui b/src/gui/shareuserline.ui
deleted file mode 100644
index 62288a89d..000000000
--- a/src/gui/shareuserline.ui
+++ /dev/null
@@ -1,93 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<ui version="4.0">
- <class>OCC::ShareUserLine</class>
- <widget class="QWidget" name="OCC::ShareUserLine">
- <property name="enabled">
- <bool>true</bool>
- </property>
- <property name="geometry">
- <rect>
- <x>0</x>
- <y>0</y>
- <width>468</width>
- <height>46</height>
- </rect>
- </property>
- <property name="windowTitle">
- <string>Form</string>
- </property>
- <property name="autoFillBackground">
- <bool>true</bool>
- </property>
- <layout class="QVBoxLayout" name="verticalLayout">
- <item>
- <layout class="QHBoxLayout" name="horizontalLayout_2">
- <item>
- <widget class="QLabel" name="avatar">
- <property name="text">
- <string>TextLabel</string>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QLabel" name="sharedWith">
- <property name="text">
- <string>TextLabel</string>
- </property>
- <property name="textFormat">
- <enum>Qt::PlainText</enum>
- </property>
- </widget>
- </item>
- <item>
- <spacer name="horizontalSpacer">
- <property name="orientation">
- <enum>Qt::Horizontal</enum>
- </property>
- <property name="sizeHint" stdset="0">
- <size>
- <width>40</width>
- <height>15</height>
- </size>
- </property>
- </spacer>
- </item>
- <item>
- <widget class="QCheckBox" name="permissionShare">
- <property name="text">
- <string>can share</string>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QCheckBox" name="permissionsEdit">
- <property name="text">
- <string>can edit</string>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QToolButton" name="permissionToolButton">
- <property name="text">
- <string>...</string>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QToolButton" name="deleteShareButton">
- <property name="text">
- <string/>
- </property>
- <property name="icon">
- <iconset theme="user-trash">
- <normaloff>.</normaloff>.</iconset>
- </property>
- </widget>
- </item>
- </layout>
- </item>
- </layout>
- </widget>
- <resources/>
- <connections/>
-</ui>
diff --git a/src/gui/socketapi.cpp b/src/gui/socketapi.cpp
index 5fb27aac4..fa3f66f10 100644
--- a/src/gui/socketapi.cpp
+++ b/src/gui/socketapi.cpp
@@ -452,45 +452,16 @@ void SocketApi::broadcastMessage(const QString &msg, bool doWait)
}
}
-void SocketApi::processShareRequest(const QString &localFile, SocketListener *listener, ShareDialogStartPage startPage)
+void SocketApi::processShareRequest(const QString &localFile, ShareDialogStartPage startPage)
{
- auto theme = Theme::instance();
-
- auto fileData = FileData::get(localFile);
- auto shareFolder = fileData.folder;
- if (!shareFolder) {
- const QString message = QLatin1String("SHARE:NOP:") + QDir::toNativeSeparators(localFile);
- // files that are not within a sync folder are not synced.
- listener->sendMessage(message);
- } else if (!shareFolder->accountState()->isConnected()) {
- const QString message = QLatin1String("SHARE:NOTCONNECTED:") + QDir::toNativeSeparators(localFile);
- // if the folder isn't connected, don't open the share dialog
- listener->sendMessage(message);
- } else if (!theme->linkSharing() && (!theme->userGroupSharing() || shareFolder->accountState()->account()->serverVersionInt() < Account::makeServerVersion(8, 2, 0))) {
- const QString message = QLatin1String("SHARE:NOP:") + QDir::toNativeSeparators(localFile);
- listener->sendMessage(message);
- } else {
- // If the file doesn't have a journal record, it might not be uploaded yet
- if (!fileData.journalRecord().isValid()) {
- const QString message = QLatin1String("SHARE:NOTSYNCED:") + QDir::toNativeSeparators(localFile);
- listener->sendMessage(message);
- return;
- }
-
- auto &remotePath = fileData.serverRelativePath;
-
- // Can't share root folder
- if (remotePath == "/") {
- const QString message = QLatin1String("SHARE:CANNOTSHAREROOT:") + QDir::toNativeSeparators(localFile);
- listener->sendMessage(message);
- return;
- }
-
- const QString message = QLatin1String("SHARE:OK:") + QDir::toNativeSeparators(localFile);
- listener->sendMessage(message);
-
- emit shareCommandReceived(remotePath, fileData.localPath, startPage);
- }
+ fetchPrivateLinkUrlHelper(localFile, [startPage](const QString &link) {
+ QUrl url(link);
+ QUrlQuery query(url);
+ query.addQueryItem(QStringLiteral("details"), QStringLiteral("shareTabView"));
+ Q_UNUSED(startPage); //FIXME
+ url.setQuery(query);
+ Utility::openBrowser(url, nullptr);
+ });
}
void SocketApi::broadcastStatusPushMessage(const QString &systemPath, SyncFileStatus fileStatus)
@@ -533,12 +504,15 @@ void SocketApi::command_RETRIEVE_FILE_STATUS(const QString &argument, SocketList
void SocketApi::command_SHARE(const QString &localFile, SocketListener *listener)
{
- processShareRequest(localFile, listener, ShareDialogStartPage::UsersAndGroups);
+ processShareRequest(localFile, ShareDialogStartPage::UsersAndGroups);
+ const QString message = QLatin1String("SHARE:OK:") + QDir::toNativeSeparators(localFile);
+ listener->sendMessage(message);
+
}
-void SocketApi::command_MANAGE_PUBLIC_LINKS(const QString &localFile, SocketListener *listener)
+void SocketApi::command_MANAGE_PUBLIC_LINKS(const QString &localFile, SocketListener *)
{
- processShareRequest(localFile, listener, ShareDialogStartPage::PublicLinks);
+ processShareRequest(localFile, ShareDialogStartPage::PublicLinks);
}
void SocketApi::command_VERSION(const QString &, SocketListener *listener)
@@ -679,7 +653,7 @@ void SocketApi::command_COPY_PUBLIC_LINK(const QString &localFile, SocketListene
connect(job, &GetOrCreatePublicLinkShare::done, this,
[](const QString &url) { copyUrlToClipboard(url); });
connect(job, &GetOrCreatePublicLinkShare::error, this,
- [=]() { emit shareCommandReceived(fileData.serverRelativePath, fileData.localPath, ShareDialogStartPage::PublicLinks); });
+ [=]() { processShareRequest(localFile, ShareDialogStartPage::PublicLinks); });
job->run();
}
diff --git a/src/gui/socketapi.h b/src/gui/socketapi.h
index bc076ad83..343e8da38 100644
--- a/src/gui/socketapi.h
+++ b/src/gui/socketapi.h
@@ -17,7 +17,6 @@
#include "syncfileitem.h"
#include "common/syncfilestatus.h"
-#include "sharedialog.h" // for the ShareDialogStartPage
#include "common/syncjournalfilerecord.h"
#include "config.h"
@@ -60,9 +59,6 @@ public slots:
void slotRegisterPath(const QString &alias);
void broadcastStatusPushMessage(const QString &systemPath, SyncFileStatus fileStatus);
-signals:
- void shareCommandReceived(const QString &sharePath, const QString &localPath, ShareDialogStartPage startPage);
-
private slots:
void slotNewConnection();
void onLostConnection();
@@ -98,8 +94,12 @@ private:
void broadcastMessage(const QString &msg, bool doWait = false);
+ enum class ShareDialogStartPage {
+ UsersAndGroups,
+ PublicLinks,
+ };
// opens share dialog, sends reply
- void processShareRequest(const QString &localFile, SocketListener *listener, ShareDialogStartPage startPage);
+ void processShareRequest(const QString &localFile, ShareDialogStartPage startPage);
Q_INVOKABLE void command_RETRIEVE_FOLDER_STATUS(const QString &argument, SocketListener *listener);
Q_INVOKABLE void command_RETRIEVE_FILE_STATUS(const QString &argument, SocketListener *listener);