2015-11-05 11:58:16 +03:00
|
|
|
/*
|
|
|
|
* 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
|
2016-10-25 12:00:07 +03:00
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
2015-11-05 11:58:16 +03:00
|
|
|
*
|
|
|
|
* 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 "ui_sharelinkwidget.h"
|
2018-08-02 22:19:57 +03:00
|
|
|
#include "sharelinkwidget.h"
|
2015-11-05 11:58:16 +03:00
|
|
|
#include "account.h"
|
|
|
|
#include "capabilities.h"
|
|
|
|
|
2016-09-14 16:31:05 +03:00
|
|
|
#include "sharemanager.h"
|
2017-05-10 10:37:10 +03:00
|
|
|
#include "guiutility.h"
|
2015-11-05 11:58:16 +03:00
|
|
|
|
|
|
|
#include "QProgressIndicator.h"
|
|
|
|
#include <QBuffer>
|
|
|
|
#include <QClipboard>
|
|
|
|
#include <QFileInfo>
|
2016-06-20 14:06:57 +03:00
|
|
|
#include <QDesktopServices>
|
2016-09-22 15:16:58 +03:00
|
|
|
#include <QMessageBox>
|
2017-04-05 10:38:46 +03:00
|
|
|
#include <QMenu>
|
|
|
|
#include <QToolButton>
|
2015-11-05 11:58:16 +03:00
|
|
|
|
|
|
|
namespace OCC {
|
|
|
|
|
|
|
|
ShareLinkWidget::ShareLinkWidget(AccountPtr account,
|
2017-05-17 11:55:42 +03:00
|
|
|
const QString &sharePath,
|
|
|
|
const QString &localPath,
|
|
|
|
SharePermissions maxSharingPermissions,
|
|
|
|
QWidget *parent)
|
|
|
|
: QWidget(parent)
|
|
|
|
, _ui(new Ui::ShareLinkWidget)
|
|
|
|
, _account(account)
|
|
|
|
, _sharePath(sharePath)
|
|
|
|
, _localPath(localPath)
|
2018-07-26 15:43:21 +03:00
|
|
|
, _manager(nullptr)
|
|
|
|
, _linkShare(nullptr)
|
2017-05-17 11:55:42 +03:00
|
|
|
, _passwordRequired(false)
|
|
|
|
, _expiryRequired(false)
|
|
|
|
, _namesSupported(true)
|
2018-07-26 15:43:21 +03:00
|
|
|
, _linkContextMenu(nullptr)
|
|
|
|
, _copyLinkAction(nullptr)
|
|
|
|
, _readOnlyLinkAction(nullptr)
|
|
|
|
, _allowEditingLinkAction(nullptr)
|
|
|
|
, _allowUploadEditingLinkAction(nullptr)
|
|
|
|
, _allowUploadLinkAction(nullptr)
|
|
|
|
, _passwordProtectLinkAction(nullptr)
|
|
|
|
, _expirationDateLinkAction(nullptr)
|
|
|
|
, _unshareLinkAction(nullptr)
|
2015-11-05 11:58:16 +03:00
|
|
|
{
|
|
|
|
_ui->setupUi(this);
|
|
|
|
|
|
|
|
//Is this a file or folder?
|
2017-04-12 12:09:20 +03:00
|
|
|
QFileInfo fi(localPath);
|
|
|
|
_isFile = fi.isFile();
|
2018-01-12 11:27:11 +03:00
|
|
|
|
2015-11-05 11:58:16 +03:00
|
|
|
// the following progress indicator widgets are added to layouts which makes them
|
|
|
|
// automatically deleted once the dialog dies.
|
2017-05-17 11:55:42 +03:00
|
|
|
_pi_create = new QProgressIndicator();
|
2015-11-05 11:58:16 +03:00
|
|
|
_pi_password = new QProgressIndicator();
|
2017-05-17 11:55:42 +03:00
|
|
|
_pi_date = new QProgressIndicator();
|
|
|
|
_pi_editing = new QProgressIndicator();
|
2018-08-02 19:15:18 +03:00
|
|
|
|
|
|
|
// TODO: where to loading should show up?
|
|
|
|
// _ui->verticalLayout->addWidget(_pi_create, Qt::AlignCenter);
|
|
|
|
// _ui->verticalLayout->addWidget(_pi_password, Qt::AlignCenter);
|
|
|
|
// _ui->verticalLayout->addWidget(_pi_editing, Qt::AlignCenter);
|
2018-07-26 15:43:21 +03:00
|
|
|
|
|
|
|
connect(_ui->enableShareLink, &QCheckBox::toggled, this, &ShareLinkWidget::slotCreateorDeleteShareLink);
|
|
|
|
connect(_ui->lineEdit_password, &QLineEdit::returnPressed, this, &ShareLinkWidget::slotCreatePassword);
|
|
|
|
connect(_ui->confirmPassword, &QAbstractButton::clicked, this, &ShareLinkWidget::slotCreatePassword);
|
|
|
|
connect(_ui->confirmExpirationDate, &QAbstractButton::clicked, this, &ShareLinkWidget::slotCreatePassword);
|
2017-09-20 11:14:48 +03:00
|
|
|
connect(_ui->calendar, &QDateTimeEdit::dateChanged, this, &ShareLinkWidget::slotExpireDateChanged);
|
2015-11-05 11:58:16 +03:00
|
|
|
|
2017-05-18 12:39:13 +03:00
|
|
|
_ui->errorLabel->hide();
|
|
|
|
|
|
|
|
bool sharingPossible = true;
|
2017-04-05 10:38:46 +03:00
|
|
|
if (!_account->capabilities().sharePublicLink()) {
|
2018-07-26 15:43:21 +03:00
|
|
|
qCWarning(lcSharing) << "Link shares have been disabled";
|
2017-05-18 12:39:13 +03:00
|
|
|
sharingPossible = false;
|
2017-05-17 11:55:42 +03:00
|
|
|
} else if (!(maxSharingPermissions & SharePermissionShare)) {
|
2018-07-26 15:43:21 +03:00
|
|
|
qCWarning(lcSharing) << "The file can not be shared because it was shared without sharing permission.";
|
2017-05-18 12:39:13 +03:00
|
|
|
sharingPossible = false;
|
|
|
|
}
|
2018-07-26 15:43:21 +03:00
|
|
|
|
|
|
|
if (!sharingPossible)
|
|
|
|
_ui->shareLinkWidget->hide();
|
|
|
|
else
|
|
|
|
_ui->shareLinkWidget->show();
|
2017-04-05 10:38:46 +03:00
|
|
|
|
|
|
|
// Older servers don't support multiple public link shares
|
2017-04-21 15:08:00 +03:00
|
|
|
if (!_account->capabilities().sharePublicLinkMultiple()) {
|
2017-04-05 10:38:46 +03:00
|
|
|
_namesSupported = false;
|
|
|
|
}
|
|
|
|
|
2018-07-26 15:43:21 +03:00
|
|
|
_ui->passwordShareProperty->hide();
|
|
|
|
_ui->expirationShareProperty->hide();
|
2015-11-23 11:42:16 +03:00
|
|
|
_ui->calendar->setMinimumDate(QDate::currentDate().addDays(1));
|
2015-11-05 11:58:16 +03:00
|
|
|
|
|
|
|
// check if the file is already inside of a synced folder
|
2017-05-17 11:55:42 +03:00
|
|
|
if (sharePath.isEmpty()) {
|
2015-11-05 11:58:16 +03:00
|
|
|
// 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();
|
2017-03-30 14:46:20 +03:00
|
|
|
qCWarning(lcSharing) << "Unable to share files not in a sync folder.";
|
2015-11-05 11:58:16 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-07-26 15:43:21 +03:00
|
|
|
// TODO File Drop
|
2017-06-15 16:38:22 +03:00
|
|
|
// File can't have public upload set; we also hide it if the capability isn't there
|
2018-03-15 21:43:26 +03:00
|
|
|
// _ui->widget_editing->setVisible(
|
|
|
|
// !_isFile && _account->capabilities().sharePublicLinkAllowUpload());
|
|
|
|
//_ui->radio_uploadOnly->setVisible(
|
|
|
|
//_account->capabilities().sharePublicLinkSupportsUploadOnly());
|
2015-11-05 11:58:16 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Create the share manager and connect it properly
|
|
|
|
*/
|
2017-05-18 12:39:13 +03:00
|
|
|
if (sharingPossible) {
|
|
|
|
_manager = new ShareManager(_account, this);
|
2017-09-20 11:14:48 +03:00
|
|
|
connect(_manager, &ShareManager::sharesFetched, this, &ShareLinkWidget::slotSharesFetched);
|
2017-09-20 12:48:13 +03:00
|
|
|
connect(_manager, &ShareManager::linkShareCreated, this, &ShareLinkWidget::slotCreateShareFetched);
|
2017-09-20 11:14:48 +03:00
|
|
|
connect(_manager, &ShareManager::linkShareRequiresPassword, this, &ShareLinkWidget::slotCreateShareRequiresPassword);
|
|
|
|
connect(_manager, &ShareManager::serverError, this, &ShareLinkWidget::slotServerError);
|
2017-05-18 12:39:13 +03:00
|
|
|
}
|
2015-11-05 11:58:16 +03:00
|
|
|
}
|
|
|
|
|
2017-04-05 10:38:46 +03:00
|
|
|
ShareLinkWidget::~ShareLinkWidget()
|
|
|
|
{
|
|
|
|
delete _ui;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ShareLinkWidget::getShares()
|
|
|
|
{
|
2017-05-18 12:39:13 +03:00
|
|
|
if (_manager) {
|
|
|
|
_manager->fetchShares(_sharePath);
|
|
|
|
}
|
2017-04-05 10:38:46 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void ShareLinkWidget::slotSharesFetched(const QList<QSharedPointer<Share>> &shares)
|
|
|
|
{
|
|
|
|
const QString versionString = _account->serverVersion();
|
2017-03-30 14:46:20 +03:00
|
|
|
qCInfo(lcSharing) << versionString << "Fetched" << shares.count() << "shares";
|
2017-04-05 10:38:46 +03:00
|
|
|
|
|
|
|
foreach (auto share, shares) {
|
|
|
|
if (share->getShareType() != Share::TypeLink) {
|
|
|
|
continue;
|
|
|
|
}
|
2018-07-26 15:43:21 +03:00
|
|
|
_linkShare = qSharedPointerDynamicCast<LinkShare>(share);
|
2017-04-05 10:38:46 +03:00
|
|
|
|
|
|
|
// Connect all shares signals to gui slots
|
2017-09-20 11:14:48 +03:00
|
|
|
connect(share.data(), &Share::serverError, this, &ShareLinkWidget::slotServerError);
|
|
|
|
connect(share.data(), &Share::shareDeleted, this, &ShareLinkWidget::slotDeleteShareFetched);
|
2018-07-26 15:43:21 +03:00
|
|
|
//TODO connect(_linkShare.data(), &LinkShare::expireDateSet, this, &ShareLinkWidget::slotExpireSet);
|
|
|
|
connect(_linkShare.data(), &LinkShare::passwordSet, this, &ShareLinkWidget::slotPasswordSet);
|
|
|
|
connect(_linkShare.data(), &LinkShare::passwordSetError, this, &ShareLinkWidget::slotPasswordSetError);
|
|
|
|
|
|
|
|
// Prepare permissions check and create group action
|
|
|
|
bool checked = false;
|
|
|
|
SharePermissions perm = _linkShare->getPermissions();
|
|
|
|
QActionGroup *permissionsGroup = new QActionGroup(this);
|
|
|
|
|
|
|
|
// radio button style
|
|
|
|
permissionsGroup->setExclusive(true);
|
|
|
|
|
|
|
|
if(_isFile){
|
2018-08-02 16:30:23 +03:00
|
|
|
checked = perm & (SharePermissionRead & SharePermissionUpdate);
|
2018-07-26 15:43:21 +03:00
|
|
|
_allowEditingLinkAction = permissionsGroup->addAction(tr("Allow Editing"));
|
|
|
|
_allowEditingLinkAction->setCheckable(true);
|
|
|
|
_allowEditingLinkAction->setChecked(checked);
|
|
|
|
|
|
|
|
} else {
|
2018-08-02 16:30:23 +03:00
|
|
|
checked = perm & SharePermissionRead;
|
2018-07-26 15:43:21 +03:00
|
|
|
_readOnlyLinkAction = permissionsGroup->addAction(tr("Read only"));
|
|
|
|
_readOnlyLinkAction->setCheckable(true);
|
|
|
|
_readOnlyLinkAction->setChecked(checked);
|
|
|
|
|
2018-08-02 16:30:23 +03:00
|
|
|
checked = perm & (SharePermissionRead &
|
|
|
|
SharePermissionCreate &
|
|
|
|
SharePermissionUpdate &
|
|
|
|
SharePermissionDelete);
|
2018-07-26 15:43:21 +03:00
|
|
|
_allowUploadEditingLinkAction = permissionsGroup->addAction(tr("Allow Upload && Editing"));
|
|
|
|
_allowUploadEditingLinkAction->setCheckable(true);
|
|
|
|
_allowUploadEditingLinkAction->setChecked(checked);
|
|
|
|
|
2018-08-02 16:30:23 +03:00
|
|
|
checked = perm & SharePermissionCreate;
|
2018-07-26 15:43:21 +03:00
|
|
|
_allowUploadLinkAction = permissionsGroup->addAction(tr("File Drop (Upload Only)"));
|
|
|
|
_allowUploadLinkAction->setCheckable(true);
|
|
|
|
_allowUploadLinkAction->setChecked(checked);
|
2017-04-05 10:38:46 +03:00
|
|
|
}
|
|
|
|
|
2018-07-26 15:43:21 +03:00
|
|
|
// Prepare sharing menu
|
|
|
|
_linkContextMenu = new QMenu(this);
|
|
|
|
|
|
|
|
// Add copy action (icon only)
|
|
|
|
_copyLinkAction = _linkContextMenu->addAction(QIcon(":/client/resources/copy.svg"),
|
|
|
|
tr("Copy link"));
|
|
|
|
|
|
|
|
// Adds permissions actions (radio button style)
|
|
|
|
if(_isFile){
|
|
|
|
_linkContextMenu->addAction(_allowEditingLinkAction);
|
2018-05-13 16:46:48 +03:00
|
|
|
} else {
|
2018-07-26 15:43:21 +03:00
|
|
|
_linkContextMenu->addAction(_readOnlyLinkAction);
|
|
|
|
_linkContextMenu->addAction(_allowUploadEditingLinkAction);
|
|
|
|
_linkContextMenu->addAction(_allowUploadLinkAction);
|
2018-05-13 16:46:48 +03:00
|
|
|
}
|
2017-04-05 10:38:46 +03:00
|
|
|
|
|
|
|
|
2018-07-26 15:43:21 +03:00
|
|
|
// Adds action to display password widget (check box)
|
|
|
|
_passwordProtectLinkAction = _linkContextMenu->addAction(tr("Password Protect"));
|
|
|
|
_passwordProtectLinkAction->setCheckable(true);
|
2017-04-05 10:38:46 +03:00
|
|
|
|
2018-07-26 15:43:21 +03:00
|
|
|
if(_linkShare->isPasswordSet()){
|
|
|
|
_passwordProtectLinkAction->setChecked(true);
|
|
|
|
_ui->lineEdit_password->setPlaceholderText("********");
|
|
|
|
_ui->passwordShareProperty->show();
|
|
|
|
}
|
2017-04-05 10:38:46 +03:00
|
|
|
|
2018-07-26 15:43:21 +03:00
|
|
|
// If password is enforced then don't allow users to disable it
|
|
|
|
if (_account->capabilities().sharePublicLinkEnforcePassword()) {
|
|
|
|
_passwordProtectLinkAction->setChecked(true);
|
|
|
|
_passwordProtectLinkAction->setEnabled(false);
|
|
|
|
_passwordRequired = true;
|
|
|
|
}
|
2017-04-05 10:38:46 +03:00
|
|
|
|
2018-07-26 15:43:21 +03:00
|
|
|
// Adds action to display expiration date widget (check box)
|
|
|
|
_expirationDateLinkAction = _linkContextMenu->addAction(tr("Expiration Date"));
|
|
|
|
_expirationDateLinkAction->setCheckable(true);
|
|
|
|
if(_linkShare->getExpireDate().isValid()){
|
|
|
|
_expirationDateLinkAction->setChecked(true);
|
|
|
|
_ui->expirationShareProperty->show();
|
|
|
|
}
|
2017-04-05 10:38:46 +03:00
|
|
|
|
|
|
|
|
2018-07-26 15:43:21 +03:00
|
|
|
// If expiredate is enforced do not allow disable and set max days
|
|
|
|
if (_account->capabilities().sharePublicLinkEnforceExpireDate()) {
|
|
|
|
_ui->calendar->setMaximumDate(QDate::currentDate().addDays(
|
|
|
|
_account->capabilities().sharePublicLinkExpireDateDays()));
|
|
|
|
_expirationDateLinkAction->setChecked(true);
|
|
|
|
_expirationDateLinkAction->setEnabled(false);
|
|
|
|
_expiryRequired = true;
|
2018-05-13 16:46:48 +03:00
|
|
|
}
|
2017-04-05 10:38:46 +03:00
|
|
|
|
2018-07-26 15:43:21 +03:00
|
|
|
// Adds action to unshare widget (check box)
|
|
|
|
_unshareLinkAction = _linkContextMenu->addAction(QIcon(":/client/resources/delete.png"),
|
|
|
|
tr("Unshare"));
|
|
|
|
|
|
|
|
connect(_linkContextMenu, &QMenu::triggered,
|
|
|
|
this, &ShareLinkWidget::slotLinkContextMenuActionTriggered);
|
|
|
|
|
|
|
|
_ui->shareLinkToolButton->setMenu(_linkContextMenu);
|
|
|
|
_ui->shareLinkToolButton->setEnabled(true);
|
|
|
|
_ui->enableShareLink->setEnabled(true);
|
|
|
|
_ui->enableShareLink->setChecked(true);
|
2017-04-05 10:38:46 +03:00
|
|
|
}
|
2018-07-26 15:43:21 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// TODO
|
|
|
|
//void ShareLinkWidget::slotShareSelectionChanged()
|
|
|
|
//{
|
|
|
|
// // Disable running progress indicators
|
|
|
|
// _pi_create->stopAnimation();
|
|
|
|
// _pi_editing->stopAnimation();
|
|
|
|
// _pi_date->stopAnimation();
|
|
|
|
// _pi_password->stopAnimation();
|
2017-04-05 10:38:46 +03:00
|
|
|
|
2018-07-26 15:43:21 +03:00
|
|
|
// _ui->errorLabel->hide();
|
|
|
|
// _ui->passwordShareProperty->show();
|
|
|
|
// _ui->expirationShareProperty->show();
|
|
|
|
|
|
|
|
// if (!_account->capabilities().sharePublicLinkAllowUpload()) {
|
|
|
|
// _allowUploadEditingLinkAction->setEnabled(false);
|
|
|
|
// _allowUploadLinkAction->setEnabled(false);
|
|
|
|
// }
|
|
|
|
|
|
|
|
// // Password state
|
|
|
|
// _ui->lineEdit_password->setEnabled(_linkShare->isPasswordSet());
|
|
|
|
// if(_linkShare->isPasswordSet()) _ui->lineEdit_password->setPlaceholderText("********");
|
|
|
|
// _ui->lineEdit_password->setText(QString());
|
|
|
|
// _ui->lineEdit_password->setEnabled(_linkShare->isPasswordSet());
|
|
|
|
// _ui->confirmPassword->setEnabled(_linkShare->isPasswordSet());
|
|
|
|
|
|
|
|
// // Expiry state
|
|
|
|
// _ui->calendar->setMinimumDate(QDate::currentDate().addDays(1));
|
|
|
|
// if (_linkShare->getExpireDate().isValid()) {
|
|
|
|
// _ui->calendar->setDate(_linkShare->getExpireDate());
|
|
|
|
// _ui->calendar->setEnabled(true);
|
|
|
|
// }
|
|
|
|
// // Public upload state (box is hidden for files)
|
2018-03-15 21:43:26 +03:00
|
|
|
// if (!_isFile) {
|
2018-07-26 15:43:21 +03:00
|
|
|
// if (_linkShare->getPublicUpload()) {
|
|
|
|
// if (_linkShare->getShowFileListing()) {
|
|
|
|
// _allowUploadEditingLinkAction->setChecked(true);
|
2018-03-15 21:43:26 +03:00
|
|
|
// } else {
|
2018-07-26 15:43:21 +03:00
|
|
|
// _allowUploadLinkAction->setChecked(true);
|
2018-03-15 21:43:26 +03:00
|
|
|
// }
|
|
|
|
// } else {
|
2018-07-26 15:43:21 +03:00
|
|
|
// _readOnlyLinkAction->setChecked(true);
|
2018-03-15 21:43:26 +03:00
|
|
|
// }
|
|
|
|
// }
|
2018-07-26 15:43:21 +03:00
|
|
|
//}
|
2017-04-05 10:38:46 +03:00
|
|
|
|
|
|
|
void ShareLinkWidget::setExpireDate(const QDate &date)
|
|
|
|
{
|
2018-07-26 15:43:21 +03:00
|
|
|
if (_linkShare) {
|
2017-04-05 10:38:46 +03:00
|
|
|
_pi_date->startAnimation();
|
|
|
|
_ui->errorLabel->hide();
|
2018-07-26 15:43:21 +03:00
|
|
|
_linkShare->setExpireDate(date);
|
2017-04-05 10:38:46 +03:00
|
|
|
}
|
2015-11-05 11:58:16 +03:00
|
|
|
}
|
|
|
|
|
2018-07-26 15:43:21 +03:00
|
|
|
// TODO
|
|
|
|
//void ShareLinkWidget::slotExpireSet()
|
|
|
|
//{
|
|
|
|
// if (sender() == _linkShare.data()) {
|
|
|
|
// slotShareSelectionChanged();
|
|
|
|
// }
|
|
|
|
//}
|
2015-11-05 11:58:16 +03:00
|
|
|
|
2015-11-11 15:01:12 +03:00
|
|
|
void ShareLinkWidget::slotExpireDateChanged(const QDate &date)
|
2015-11-05 11:58:16 +03:00
|
|
|
{
|
2018-07-26 15:43:21 +03:00
|
|
|
setExpireDate(date);
|
2015-11-05 11:58:16 +03:00
|
|
|
}
|
|
|
|
|
2018-07-26 15:43:21 +03:00
|
|
|
void ShareLinkWidget::slotCreatePassword()
|
2015-11-05 11:58:16 +03:00
|
|
|
{
|
2017-05-18 12:39:13 +03:00
|
|
|
if (!_manager) {
|
|
|
|
return;
|
|
|
|
}
|
2018-07-26 15:43:21 +03:00
|
|
|
if (!_linkShare) {
|
2017-04-05 10:38:46 +03:00
|
|
|
// If share creation requires a password, we'll be in this case
|
|
|
|
if (_ui->lineEdit_password->text().isEmpty()) {
|
|
|
|
_ui->lineEdit_password->setFocus();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
_pi_create->startAnimation();
|
2018-07-26 15:43:21 +03:00
|
|
|
_manager->createLinkShare(_sharePath, QString(), _ui->lineEdit_password->text());
|
2017-04-05 10:38:46 +03:00
|
|
|
} else {
|
|
|
|
setPassword(_ui->lineEdit_password->text());
|
|
|
|
}
|
2015-11-05 11:58:16 +03:00
|
|
|
}
|
|
|
|
|
2018-07-26 15:43:21 +03:00
|
|
|
void ShareLinkWidget::slotCreateorDeleteShareLink(bool checked)
|
2017-04-12 12:09:20 +03:00
|
|
|
{
|
2018-07-26 15:43:21 +03:00
|
|
|
if (!_manager) {
|
|
|
|
qCWarning(lcSharing) << "No share manager set.";
|
2017-04-12 12:09:20 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-07-26 15:43:21 +03:00
|
|
|
_pi_create->startAnimation();
|
|
|
|
if(checked){
|
|
|
|
_manager->createLinkShare(_sharePath, QString(), QString());
|
|
|
|
} else {
|
|
|
|
if (!_linkShare) {
|
|
|
|
qCWarning(lcSharing) << "No public link set.";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
confirmAndDeleteShare();
|
2017-04-12 12:09:20 +03:00
|
|
|
}
|
2018-07-26 15:43:21 +03:00
|
|
|
|
|
|
|
_ui->shareLinkToolButton->setEnabled(checked);
|
2017-04-12 12:09:20 +03:00
|
|
|
}
|
|
|
|
|
2015-11-05 11:58:16 +03:00
|
|
|
void ShareLinkWidget::setPassword(const QString &password)
|
|
|
|
{
|
2018-07-26 15:43:21 +03:00
|
|
|
if (_linkShare) {
|
2017-04-05 10:38:46 +03:00
|
|
|
_pi_password->startAnimation();
|
|
|
|
_ui->errorLabel->hide();
|
2018-07-26 15:43:21 +03:00
|
|
|
_linkShare->setPassword(password);
|
2015-11-05 11:58:16 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ShareLinkWidget::slotPasswordSet()
|
|
|
|
{
|
2018-08-02 21:22:37 +03:00
|
|
|
if (!_linkShare)
|
2018-05-13 16:46:48 +03:00
|
|
|
return;
|
|
|
|
|
2017-04-05 10:38:46 +03:00
|
|
|
_pi_password->stopAnimation();
|
2016-01-22 13:56:05 +03:00
|
|
|
_ui->lineEdit_password->setText(QString());
|
2018-08-02 21:22:37 +03:00
|
|
|
if (_linkShare->isPasswordSet()) {
|
2018-05-13 16:46:48 +03:00
|
|
|
_ui->lineEdit_password->setPlaceholderText("********");
|
|
|
|
_ui->lineEdit_password->setEnabled(true);
|
|
|
|
} else {
|
|
|
|
_ui->lineEdit_password->setPlaceholderText(QString());
|
|
|
|
}
|
2016-01-22 13:56:05 +03:00
|
|
|
|
2015-11-05 11:58:16 +03:00
|
|
|
/*
|
|
|
|
* 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.
|
2018-05-13 16:46:48 +03:00
|
|
|
*
|
|
|
|
* NOTE: I don't see this happening with oC > 10
|
2015-11-05 11:58:16 +03:00
|
|
|
*/
|
|
|
|
getShares();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ShareLinkWidget::slotDeleteShareFetched()
|
|
|
|
{
|
2017-04-05 10:38:46 +03:00
|
|
|
getShares();
|
2015-11-05 11:58:16 +03:00
|
|
|
}
|
|
|
|
|
2018-07-26 15:43:21 +03:00
|
|
|
void ShareLinkWidget::slotCreateShareFetched()
|
2015-11-05 11:58:16 +03:00
|
|
|
{
|
2017-04-05 10:38:46 +03:00
|
|
|
_pi_create->stopAnimation();
|
2015-11-05 11:58:16 +03:00
|
|
|
_pi_password->stopAnimation();
|
|
|
|
getShares();
|
|
|
|
}
|
|
|
|
|
2017-05-17 11:55:42 +03:00
|
|
|
void ShareLinkWidget::slotCreateShareRequiresPassword(const QString &message)
|
2015-11-05 11:58:16 +03:00
|
|
|
{
|
2017-04-05 10:38:46 +03:00
|
|
|
// Prepare password entry
|
|
|
|
_pi_create->stopAnimation();
|
2016-01-19 16:03:13 +03:00
|
|
|
_pi_password->stopAnimation();
|
2018-07-26 15:43:21 +03:00
|
|
|
_ui->passwordShareProperty->show();
|
2016-01-19 16:03:13 +03:00
|
|
|
if (!message.isEmpty()) {
|
|
|
|
_ui->errorLabel->setText(message);
|
|
|
|
_ui->errorLabel->show();
|
|
|
|
}
|
2015-11-05 11:58:16 +03:00
|
|
|
|
2015-12-01 14:43:14 +03:00
|
|
|
_passwordRequired = true;
|
|
|
|
|
2018-07-26 15:43:21 +03:00
|
|
|
togglePasswordOptions(true);
|
2015-11-05 11:58:16 +03:00
|
|
|
}
|
|
|
|
|
2018-07-26 15:43:21 +03:00
|
|
|
void ShareLinkWidget::togglePasswordOptions(bool enable)
|
2015-11-05 11:58:16 +03:00
|
|
|
{
|
2018-07-26 15:43:21 +03:00
|
|
|
_ui->passwordShareProperty->setVisible(enable);
|
|
|
|
if(enable) _ui->lineEdit_password->setFocus();
|
2015-11-05 11:58:16 +03:00
|
|
|
}
|
|
|
|
|
2018-07-26 15:43:21 +03:00
|
|
|
void ShareLinkWidget::toggleExpireDateOptions(bool enable)
|
2015-11-05 11:58:16 +03:00
|
|
|
{
|
2018-07-26 15:43:21 +03:00
|
|
|
_ui->expirationShareProperty->setVisible(enable);
|
|
|
|
if (enable) {
|
2015-11-05 11:58:16 +03:00
|
|
|
const QDate date = QDate::currentDate().addDays(1);
|
|
|
|
setExpireDate(date);
|
|
|
|
_ui->calendar->setDate(date);
|
|
|
|
_ui->calendar->setMinimumDate(date);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-26 15:43:21 +03:00
|
|
|
void ShareLinkWidget::confirmAndDeleteShare()
|
2017-11-15 17:01:48 +03:00
|
|
|
{
|
|
|
|
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>")
|
2018-07-26 15:43:21 +03:00
|
|
|
.arg(shareName()),
|
2017-11-15 17:01:48 +03:00
|
|
|
QMessageBox::NoButton,
|
|
|
|
this);
|
|
|
|
QPushButton *yesButton =
|
|
|
|
messageBox->addButton(tr("Delete"), QMessageBox::YesRole);
|
|
|
|
messageBox->addButton(tr("Cancel"), QMessageBox::NoRole);
|
|
|
|
|
|
|
|
connect(messageBox, &QMessageBox::finished, this,
|
2018-07-26 15:43:21 +03:00
|
|
|
[messageBox, yesButton, this]() {
|
|
|
|
if (messageBox->clickedButton() == yesButton){
|
2018-08-02 19:15:18 +03:00
|
|
|
// TODO: dlete is not hapenning correctly
|
2018-07-26 15:43:21 +03:00
|
|
|
this->_linkShare->deleteShare();
|
|
|
|
this->_ui->enableShareLink->setChecked(false);
|
|
|
|
this->_ui->shareLinkToolButton->setEnabled(false);
|
|
|
|
}
|
2017-11-15 17:01:48 +03:00
|
|
|
});
|
|
|
|
messageBox->open();
|
|
|
|
}
|
|
|
|
|
2018-07-26 15:43:21 +03:00
|
|
|
QString ShareLinkWidget::shareName() const
|
2017-11-15 17:01:48 +03:00
|
|
|
{
|
2018-07-26 15:43:21 +03:00
|
|
|
QString name = _linkShare->getName();
|
2017-11-15 17:01:48 +03:00
|
|
|
if (!name.isEmpty())
|
|
|
|
return name;
|
|
|
|
if (!_namesSupported)
|
|
|
|
return tr("Public link");
|
2018-07-26 15:43:21 +03:00
|
|
|
return _linkShare->getToken();
|
2017-11-15 17:01:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void ShareLinkWidget::slotContextMenuButtonClicked()
|
2017-06-15 17:03:24 +03:00
|
|
|
{
|
2017-11-15 17:01:48 +03:00
|
|
|
_linkContextMenu->exec(QCursor::pos());
|
2017-06-15 17:03:24 +03:00
|
|
|
}
|
|
|
|
|
2017-11-15 17:01:48 +03:00
|
|
|
void ShareLinkWidget::slotLinkContextMenuActionTriggered(QAction *action)
|
2015-11-05 11:58:16 +03:00
|
|
|
{
|
|
|
|
|
2018-07-26 15:43:21 +03:00
|
|
|
bool state = action->isChecked();
|
|
|
|
SharePermissions perm = SharePermissionRead;
|
2015-11-05 11:58:16 +03:00
|
|
|
|
2018-07-26 15:43:21 +03:00
|
|
|
if (action == _copyLinkAction) {
|
|
|
|
QApplication::clipboard()->setText(_linkShare->getLink().toString());
|
2015-11-05 11:58:16 +03:00
|
|
|
|
2018-07-26 15:43:21 +03:00
|
|
|
} else if (action == _readOnlyLinkAction && state) {
|
|
|
|
_linkShare->setPermissions(perm);
|
2017-04-05 10:38:46 +03:00
|
|
|
|
2018-07-26 15:43:21 +03:00
|
|
|
} else if (action == _allowEditingLinkAction && state) {
|
2018-08-02 16:30:23 +03:00
|
|
|
perm |= SharePermissionUpdate;
|
2018-07-26 15:43:21 +03:00
|
|
|
_linkShare->setPermissions(perm);
|
2015-11-05 11:58:16 +03:00
|
|
|
|
2018-07-26 15:43:21 +03:00
|
|
|
} else if (action == _allowUploadEditingLinkAction && state) {
|
|
|
|
perm |= SharePermissionCreate | SharePermissionUpdate | SharePermissionDelete;
|
|
|
|
_linkShare->setPermissions(perm);
|
2017-04-05 10:38:46 +03:00
|
|
|
|
2018-07-26 15:43:21 +03:00
|
|
|
} else if (action == _allowUploadLinkAction && state) {
|
|
|
|
perm = SharePermissionCreate;
|
|
|
|
_linkShare->setPermissions(perm);
|
|
|
|
|
|
|
|
} else if (action == _passwordProtectLinkAction) {
|
|
|
|
togglePasswordOptions(state);
|
|
|
|
|
|
|
|
} else if (action == _expirationDateLinkAction) {
|
|
|
|
toggleExpireDateOptions(state);
|
|
|
|
|
|
|
|
} else if (action == _unshareLinkAction) {
|
|
|
|
confirmAndDeleteShare();
|
2017-04-05 10:38:46 +03:00
|
|
|
}
|
2015-11-05 11:58:16 +03:00
|
|
|
}
|
|
|
|
|
2016-01-22 13:56:05 +03:00
|
|
|
void ShareLinkWidget::slotServerError(int code, const QString &message)
|
2015-11-05 11:58:16 +03:00
|
|
|
{
|
2017-04-05 10:38:46 +03:00
|
|
|
_pi_create->stopAnimation();
|
2016-01-22 13:56:05 +03:00
|
|
|
_pi_date->stopAnimation();
|
|
|
|
_pi_password->stopAnimation();
|
|
|
|
_pi_editing->stopAnimation();
|
|
|
|
|
2017-03-30 14:46:20 +03:00
|
|
|
qCWarning(lcSharing) << "Error from server" << code << message;
|
2016-01-12 15:19:33 +03:00
|
|
|
displayError(message);
|
2015-11-05 11:58:16 +03:00
|
|
|
}
|
|
|
|
|
2016-01-22 13:56:05 +03:00
|
|
|
void ShareLinkWidget::slotPasswordSetError(int code, const QString &message)
|
|
|
|
{
|
|
|
|
slotServerError(code, message);
|
|
|
|
_ui->lineEdit_password->setFocus();
|
|
|
|
}
|
|
|
|
|
2017-05-17 11:55:42 +03:00
|
|
|
void ShareLinkWidget::displayError(const QString &errMsg)
|
2015-11-05 11:58:16 +03:00
|
|
|
{
|
2017-05-17 11:55:42 +03:00
|
|
|
_ui->errorLabel->setText(errMsg);
|
2015-11-05 11:58:16 +03:00
|
|
|
_ui->errorLabel->show();
|
|
|
|
}
|
|
|
|
}
|