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 "sharelinkwidget.h"
|
|
|
|
#include "ui_sharelinkwidget.h"
|
|
|
|
#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 {
|
|
|
|
|
2017-04-05 10:38:46 +03:00
|
|
|
const char propertyShareC[] = "oc_share";
|
|
|
|
|
2015-11-05 11:58:16 +03:00
|
|
|
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)
|
|
|
|
, _manager(0)
|
|
|
|
, _passwordRequired(false)
|
|
|
|
, _expiryRequired(false)
|
|
|
|
, _namesSupported(true)
|
2015-11-05 11:58:16 +03:00
|
|
|
{
|
|
|
|
_ui->setupUi(this);
|
|
|
|
|
2017-04-05 10:38:46 +03:00
|
|
|
_ui->linkShares->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch);
|
|
|
|
_ui->linkShares->horizontalHeader()->setSectionResizeMode(1, QHeaderView::ResizeToContents);
|
|
|
|
_ui->linkShares->horizontalHeader()->setSectionResizeMode(2, QHeaderView::ResizeToContents);
|
|
|
|
|
2015-11-05 11:58:16 +03:00
|
|
|
//Is this a file or folder?
|
2017-04-12 12:09:20 +03:00
|
|
|
QFileInfo fi(localPath);
|
|
|
|
_isFile = fi.isFile();
|
|
|
|
_ui->nameLineEdit->setText(tr("%1 link").arg(fi.fileName()));
|
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();
|
2017-04-05 10:38:46 +03:00
|
|
|
_ui->horizontalLayout_create->addWidget(_pi_create);
|
2015-11-05 11:58:16 +03:00
|
|
|
_ui->horizontalLayout_password->addWidget(_pi_password);
|
2017-06-15 16:38:22 +03:00
|
|
|
_ui->layout_editing->addWidget(_pi_editing, 0, 2);
|
2017-04-05 10:38:46 +03:00
|
|
|
_ui->horizontalLayout_expire->insertWidget(_ui->horizontalLayout_expire->count() - 1, _pi_date);
|
2015-11-05 11:58:16 +03:00
|
|
|
|
2017-09-20 11:14:48 +03:00
|
|
|
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->checkBox_editing, &QAbstractButton::clicked, this, &ShareLinkWidget::slotPermissionsCheckboxClicked);
|
|
|
|
connect(_ui->checkBox_fileListing, &QAbstractButton::clicked, this, &ShareLinkWidget::slotPermissionsCheckboxClicked);
|
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()) {
|
|
|
|
displayError(tr("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)) {
|
2017-04-05 10:38:46 +03:00
|
|
|
displayError(tr("The file can not be shared because it was shared without sharing permission."));
|
2017-05-18 12:39:13 +03:00
|
|
|
sharingPossible = false;
|
|
|
|
}
|
|
|
|
if (!sharingPossible) {
|
2017-04-05 10:38:46 +03:00
|
|
|
_ui->nameLineEdit->setEnabled(false);
|
|
|
|
_ui->createShareButton->setEnabled(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
_ui->createShareButton->setText(tr("Create public link share"));
|
2017-04-21 15:08:00 +03:00
|
|
|
_ui->nameLineEdit->hide();
|
|
|
|
_ui->nameLineEdit->clear(); // so we don't send a name
|
2017-04-05 10:38:46 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
_ui->shareProperties->setEnabled(false);
|
2015-11-05 11:58:16 +03:00
|
|
|
|
|
|
|
_ui->pushButton_setPassword->setEnabled(false);
|
2017-04-05 10:38:46 +03:00
|
|
|
_ui->lineEdit_password->setEnabled(false);
|
|
|
|
_ui->pushButton_setPassword->setEnabled(false);
|
|
|
|
_ui->checkBox_password->setText(tr("P&assword protect"));
|
2015-11-05 11:58:16 +03:00
|
|
|
|
2015-11-23 11:42:16 +03:00
|
|
|
_ui->calendar->setMinimumDate(QDate::currentDate().addDays(1));
|
2015-11-05 11:58:16 +03:00
|
|
|
_ui->calendar->setEnabled(false);
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Parse capabilities
|
|
|
|
|
|
|
|
// If password is enforced then don't allow users to disable it
|
|
|
|
if (_account->capabilities().sharePublicLinkEnforcePassword()) {
|
|
|
|
_ui->checkBox_password->setEnabled(false);
|
2015-12-01 14:43:14 +03:00
|
|
|
_passwordRequired = true;
|
2015-11-05 11:58:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// If expiredate is enforced do not allow disable and set max days
|
|
|
|
if (_account->capabilities().sharePublicLinkEnforceExpireDate()) {
|
|
|
|
_ui->checkBox_expire->setEnabled(false);
|
|
|
|
_ui->calendar->setMaximumDate(QDate::currentDate().addDays(
|
2017-05-17 11:55:42 +03:00
|
|
|
_account->capabilities().sharePublicLinkExpireDateDays()));
|
2017-04-05 10:38:46 +03:00
|
|
|
_expiryRequired = true;
|
2015-11-05 11:58:16 +03:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
_ui->widget_editing->setVisible(
|
|
|
|
!_isFile && _account->capabilities().sharePublicLinkAllowUpload());
|
|
|
|
_ui->checkBox_fileListing->setVisible(
|
|
|
|
_account->capabilities().sharePublicLinkSupportsUploadOnly());
|
2015-11-05 11:58:16 +03:00
|
|
|
|
2017-04-05 10:38:46 +03:00
|
|
|
|
|
|
|
// Prepare sharing menu
|
|
|
|
|
|
|
|
_shareLinkMenu = new QMenu(this);
|
2017-09-20 11:14:48 +03:00
|
|
|
connect(_shareLinkMenu, &QMenu::triggered,
|
|
|
|
this, &ShareLinkWidget::slotShareLinkActionTriggered);
|
2017-04-05 10:38:46 +03:00
|
|
|
_openLinkAction = _shareLinkMenu->addAction(tr("Open link in browser"));
|
|
|
|
_copyLinkAction = _shareLinkMenu->addAction(tr("Copy link to clipboard"));
|
2017-05-02 13:58:01 +03:00
|
|
|
_copyDirectLinkAction = _shareLinkMenu->addAction(tr("Copy link to clipboard (direct download)"));
|
2017-04-05 10:38:46 +03:00
|
|
|
_emailLinkAction = _shareLinkMenu->addAction(tr("Send link by email"));
|
2017-05-02 13:58:01 +03:00
|
|
|
_emailDirectLinkAction = _shareLinkMenu->addAction(tr("Send link by email (direct download)"));
|
2017-04-05 10:38:46 +03:00
|
|
|
|
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
|
|
|
|
|
|
|
// Preserve the previous selection
|
|
|
|
QString selectedShareId;
|
|
|
|
if (auto share = selectedShare()) {
|
|
|
|
selectedShareId = share->getId();
|
|
|
|
}
|
|
|
|
// ...except if selection should move to a new share
|
|
|
|
if (!_newShareOverrideSelectionId.isEmpty()) {
|
|
|
|
selectedShareId = _newShareOverrideSelectionId;
|
|
|
|
_newShareOverrideSelectionId.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
auto table = _ui->linkShares;
|
|
|
|
table->clearContents();
|
|
|
|
table->setRowCount(0);
|
|
|
|
|
|
|
|
auto deleteIcon = QIcon::fromTheme(QLatin1String("user-trash"),
|
2017-05-17 11:55:42 +03:00
|
|
|
QIcon(QLatin1String(":/client/resources/delete.png")));
|
2017-04-05 10:38:46 +03:00
|
|
|
|
|
|
|
foreach (auto share, shares) {
|
|
|
|
if (share->getShareType() != Share::TypeLink) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
auto linkShare = qSharedPointerDynamicCast<LinkShare>(share);
|
|
|
|
|
|
|
|
// 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);
|
2017-04-05 10:38:46 +03:00
|
|
|
connect(share.data(), SIGNAL(expireDateSet()), SLOT(slotExpireSet()));
|
2017-06-15 16:38:22 +03:00
|
|
|
connect(share.data(), SIGNAL(publicUploadSet()), SLOT(slotPermissionsSet()));
|
2017-04-05 10:38:46 +03:00
|
|
|
connect(share.data(), SIGNAL(passwordSet()), SLOT(slotPasswordSet()));
|
2017-05-17 11:55:42 +03:00
|
|
|
connect(share.data(), SIGNAL(passwordSetError(int, QString)), SLOT(slotPasswordSetError(int, QString)));
|
2017-09-20 11:14:48 +03:00
|
|
|
connect(share.data(), &Share::permissionsSet, this, &ShareLinkWidget::slotPermissionsSet);
|
2017-04-05 10:38:46 +03:00
|
|
|
|
|
|
|
// Build the table row
|
|
|
|
auto row = table->rowCount();
|
|
|
|
table->insertRow(row);
|
|
|
|
|
2017-04-12 12:09:20 +03:00
|
|
|
auto nameItem = new QTableWidgetItem;
|
2017-04-05 10:38:46 +03:00
|
|
|
QString name = linkShare->getName();
|
|
|
|
if (name.isEmpty()) {
|
2017-04-12 12:09:20 +03:00
|
|
|
if (!_namesSupported) {
|
|
|
|
name = tr("Public link");
|
|
|
|
nameItem->setFlags(nameItem->flags() & ~Qt::ItemIsEditable);
|
|
|
|
} else {
|
|
|
|
name = linkShare->getToken();
|
|
|
|
}
|
2017-04-05 10:38:46 +03:00
|
|
|
}
|
2017-04-12 12:09:20 +03:00
|
|
|
nameItem->setText(name);
|
2017-04-05 10:38:46 +03:00
|
|
|
nameItem->setData(Qt::UserRole, QVariant::fromValue(linkShare));
|
|
|
|
table->setItem(row, 0, nameItem);
|
|
|
|
|
|
|
|
auto shareButton = new QToolButton;
|
2017-04-12 12:09:20 +03:00
|
|
|
shareButton->setText("...");
|
2017-04-05 10:38:46 +03:00
|
|
|
shareButton->setProperty(propertyShareC, QVariant::fromValue(linkShare));
|
2017-09-20 11:14:48 +03:00
|
|
|
connect(shareButton, &QAbstractButton::clicked, this, &ShareLinkWidget::slotShareLinkButtonClicked);
|
2017-04-05 10:38:46 +03:00
|
|
|
table->setCellWidget(row, 1, shareButton);
|
|
|
|
|
|
|
|
auto deleteButton = new QToolButton;
|
|
|
|
deleteButton->setIcon(deleteIcon);
|
|
|
|
deleteButton->setProperty(propertyShareC, QVariant::fromValue(linkShare));
|
2017-09-20 11:14:48 +03:00
|
|
|
connect(deleteButton, &QAbstractButton::clicked, this, &ShareLinkWidget::slotDeleteShareClicked);
|
2017-04-05 10:38:46 +03:00
|
|
|
table->setCellWidget(row, 2, deleteButton);
|
|
|
|
|
|
|
|
// Reestablish the previous selection
|
|
|
|
if (selectedShareId == share->getId()) {
|
|
|
|
table->selectRow(row);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Select the first share by default
|
|
|
|
if (!selectedShare() && table->rowCount() != 0) {
|
|
|
|
table->selectRow(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!_namesSupported) {
|
|
|
|
_ui->createShareButton->setEnabled(table->rowCount() == 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ShareLinkWidget::slotShareSelectionChanged()
|
2015-11-05 11:58:16 +03:00
|
|
|
{
|
2017-04-05 10:38:46 +03:00
|
|
|
// Disable running progress indicators
|
|
|
|
_pi_create->stopAnimation();
|
|
|
|
_pi_editing->stopAnimation();
|
|
|
|
_pi_date->stopAnimation();
|
|
|
|
_pi_password->stopAnimation();
|
|
|
|
|
2016-01-19 16:03:13 +03:00
|
|
|
_ui->errorLabel->hide();
|
2017-04-05 10:38:46 +03:00
|
|
|
|
|
|
|
auto share = selectedShare();
|
|
|
|
if (!share) {
|
|
|
|
_ui->shareProperties->setEnabled(false);
|
|
|
|
_ui->checkBox_editing->setChecked(false);
|
|
|
|
_ui->checkBox_expire->setChecked(false);
|
|
|
|
_ui->checkBox_password->setChecked(false);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
_ui->shareProperties->setEnabled(true);
|
|
|
|
|
|
|
|
_ui->checkBox_password->setEnabled(!_passwordRequired);
|
|
|
|
_ui->checkBox_expire->setEnabled(!_expiryRequired);
|
|
|
|
_ui->checkBox_editing->setEnabled(
|
2017-05-17 11:55:42 +03:00
|
|
|
_account->capabilities().sharePublicLinkAllowUpload());
|
2017-04-05 10:38:46 +03:00
|
|
|
|
|
|
|
// Password state
|
|
|
|
_ui->checkBox_password->setText(tr("P&assword protect"));
|
|
|
|
if (share->isPasswordSet()) {
|
|
|
|
_ui->checkBox_password->setChecked(true);
|
|
|
|
_ui->lineEdit_password->setEnabled(true);
|
|
|
|
_ui->lineEdit_password->setPlaceholderText("********");
|
|
|
|
_ui->lineEdit_password->setText(QString());
|
|
|
|
_ui->lineEdit_password->setEnabled(true);
|
2017-05-22 15:41:06 +03:00
|
|
|
_ui->pushButton_setPassword->setEnabled(false);
|
2017-04-05 10:38:46 +03:00
|
|
|
} else {
|
|
|
|
_ui->checkBox_password->setChecked(false);
|
|
|
|
_ui->lineEdit_password->setPlaceholderText(QString());
|
|
|
|
_ui->lineEdit_password->setEnabled(false);
|
|
|
|
_ui->pushButton_setPassword->setEnabled(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Expiry state
|
|
|
|
_ui->calendar->setMinimumDate(QDate::currentDate().addDays(1));
|
|
|
|
if (share->getExpireDate().isValid()) {
|
|
|
|
_ui->checkBox_expire->setChecked(true);
|
|
|
|
_ui->calendar->setDate(share->getExpireDate());
|
|
|
|
_ui->calendar->setEnabled(true);
|
|
|
|
} else {
|
|
|
|
_ui->checkBox_expire->setChecked(false);
|
|
|
|
_ui->calendar->setEnabled(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Public upload state (box is hidden for files)
|
|
|
|
if (!_isFile) {
|
|
|
|
_ui->checkBox_editing->setChecked(share->getPublicUpload());
|
2017-06-15 16:38:22 +03:00
|
|
|
_ui->checkBox_fileListing->setChecked(share->getShowFileListing());
|
|
|
|
_ui->checkBox_fileListing->setEnabled(share->getPublicUpload());
|
2017-04-05 10:38:46 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ShareLinkWidget::setExpireDate(const QDate &date)
|
|
|
|
{
|
|
|
|
if (auto current = selectedShare()) {
|
|
|
|
_pi_date->startAnimation();
|
|
|
|
_ui->errorLabel->hide();
|
|
|
|
current->setExpireDate(date);
|
|
|
|
}
|
2015-11-05 11:58:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void ShareLinkWidget::slotExpireSet()
|
|
|
|
{
|
2017-04-05 10:38:46 +03:00
|
|
|
if (sender() == selectedShare().data()) {
|
|
|
|
slotShareSelectionChanged();
|
2016-04-19 12:22:32 +03:00
|
|
|
}
|
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
|
|
|
{
|
2015-11-11 15:01:12 +03:00
|
|
|
if (_ui->checkBox_expire->isChecked()) {
|
|
|
|
setExpireDate(date);
|
|
|
|
}
|
2015-11-05 11:58:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void ShareLinkWidget::slotPasswordReturnPressed()
|
|
|
|
{
|
2017-05-18 12:39:13 +03:00
|
|
|
if (!_manager) {
|
|
|
|
return;
|
|
|
|
}
|
2017-04-05 10:38:46 +03:00
|
|
|
if (!selectedShare()) {
|
|
|
|
// 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();
|
|
|
|
_manager->createLinkShare(_sharePath, _ui->nameLineEdit->text(), _ui->lineEdit_password->text());
|
|
|
|
} else {
|
|
|
|
setPassword(_ui->lineEdit_password->text());
|
|
|
|
}
|
2015-11-05 11:58:16 +03:00
|
|
|
_ui->lineEdit_password->clearFocus();
|
|
|
|
}
|
|
|
|
|
2017-05-17 11:55:42 +03:00
|
|
|
void ShareLinkWidget::slotPasswordChanged(const QString &newText)
|
2015-11-05 11:58:16 +03:00
|
|
|
{
|
|
|
|
// disable the set-password button
|
2017-05-17 11:55:42 +03:00
|
|
|
_ui->pushButton_setPassword->setEnabled(newText.length() > 0);
|
2015-11-05 11:58:16 +03:00
|
|
|
}
|
|
|
|
|
2017-05-17 11:55:42 +03:00
|
|
|
void ShareLinkWidget::slotNameEdited(QTableWidgetItem *item)
|
2017-04-12 12:09:20 +03:00
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-05 11:58:16 +03:00
|
|
|
void ShareLinkWidget::setPassword(const QString &password)
|
|
|
|
{
|
2017-04-05 10:38:46 +03:00
|
|
|
if (auto current = selectedShare()) {
|
|
|
|
_pi_password->startAnimation();
|
|
|
|
_ui->errorLabel->hide();
|
2015-11-05 11:58:16 +03:00
|
|
|
|
2017-04-05 10:38:46 +03:00
|
|
|
_ui->checkBox_password->setEnabled(false);
|
|
|
|
_ui->lineEdit_password->setEnabled(false);
|
2015-11-05 11:58:16 +03:00
|
|
|
|
2017-04-05 10:38:46 +03:00
|
|
|
current->setPassword(password);
|
2015-11-05 11:58:16 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ShareLinkWidget::slotPasswordSet()
|
|
|
|
{
|
2017-04-05 10:38:46 +03:00
|
|
|
_pi_password->stopAnimation();
|
2016-01-22 13:56:05 +03:00
|
|
|
_ui->lineEdit_password->setText(QString());
|
|
|
|
_ui->lineEdit_password->setPlaceholderText(tr("Password Protected"));
|
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
getShares();
|
|
|
|
}
|
|
|
|
|
2017-04-05 10:38:46 +03:00
|
|
|
void ShareLinkWidget::slotShareNameEntered()
|
2015-11-05 11:58:16 +03:00
|
|
|
{
|
2017-05-18 12:39:13 +03:00
|
|
|
if (!_manager) {
|
|
|
|
return;
|
|
|
|
}
|
2017-04-12 12:09:20 +03:00
|
|
|
_pi_create->startAnimation();
|
|
|
|
_manager->createLinkShare(_sharePath, _ui->nameLineEdit->text(), QString());
|
2015-11-05 11:58:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void ShareLinkWidget::slotDeleteShareFetched()
|
|
|
|
{
|
2017-04-05 10:38:46 +03:00
|
|
|
getShares();
|
2015-11-05 11:58:16 +03:00
|
|
|
}
|
|
|
|
|
2017-09-20 12:48:13 +03:00
|
|
|
void ShareLinkWidget::slotCreateShareFetched(const QSharedPointer<LinkShare> &share)
|
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();
|
2017-04-05 10:38:46 +03:00
|
|
|
_ui->nameLineEdit->clear();
|
2015-11-05 11:58:16 +03:00
|
|
|
|
2017-04-05 10:38:46 +03:00
|
|
|
_newShareOverrideSelectionId = share->getId();
|
2015-11-05 11:58:16 +03:00
|
|
|
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
|
|
|
// Deselect existing shares
|
|
|
|
_ui->linkShares->clearSelection();
|
|
|
|
|
|
|
|
// Prepare password entry
|
|
|
|
_pi_create->stopAnimation();
|
2016-01-19 16:03:13 +03:00
|
|
|
_pi_password->stopAnimation();
|
2017-04-05 10:38:46 +03:00
|
|
|
_ui->shareProperties->setEnabled(true);
|
2015-11-05 11:58:16 +03:00
|
|
|
_ui->checkBox_password->setChecked(true);
|
|
|
|
_ui->checkBox_password->setEnabled(false);
|
|
|
|
_ui->checkBox_password->setText(tr("Public shå requires a password"));
|
|
|
|
_ui->checkBox_expire->setEnabled(false);
|
|
|
|
_ui->checkBox_editing->setEnabled(false);
|
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;
|
|
|
|
|
2015-11-05 11:58:16 +03:00
|
|
|
slotCheckBoxPasswordClicked();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ShareLinkWidget::slotCheckBoxPasswordClicked()
|
|
|
|
{
|
|
|
|
if (_ui->checkBox_password->checkState() == Qt::Checked) {
|
2016-08-17 16:48:25 +03:00
|
|
|
_ui->lineEdit_password->setEnabled(true);
|
2017-04-05 10:38:46 +03:00
|
|
|
_ui->pushButton_setPassword->setEnabled(true);
|
|
|
|
_ui->lineEdit_password->setPlaceholderText(tr("Please Set Password"));
|
2015-11-05 11:58:16 +03:00
|
|
|
_ui->lineEdit_password->setFocus();
|
|
|
|
} else {
|
|
|
|
setPassword(QString());
|
|
|
|
_ui->lineEdit_password->setPlaceholderText(QString());
|
|
|
|
_pi_password->startAnimation();
|
2017-04-05 10:38:46 +03:00
|
|
|
_ui->lineEdit_password->setEnabled(false);
|
|
|
|
_ui->pushButton_setPassword->setEnabled(false);
|
2015-11-05 11:58:16 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ShareLinkWidget::slotCheckBoxExpireClicked()
|
|
|
|
{
|
2017-05-17 11:55:42 +03:00
|
|
|
if (_ui->checkBox_expire->checkState() == Qt::Checked) {
|
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);
|
|
|
|
_ui->calendar->setEnabled(true);
|
2017-05-17 11:55:42 +03:00
|
|
|
} else {
|
2015-11-05 11:58:16 +03:00
|
|
|
setExpireDate(QDate());
|
|
|
|
_ui->calendar->setEnabled(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-05 10:38:46 +03:00
|
|
|
void ShareLinkWidget::emailShareLink(const QUrl &url)
|
2016-06-20 14:06:57 +03:00
|
|
|
{
|
|
|
|
QString fileName = _sharePath.mid(_sharePath.lastIndexOf('/') + 1);
|
2017-05-10 10:37:10 +03:00
|
|
|
Utility::openEmailComposer(
|
|
|
|
QString("I shared %1 with you").arg(fileName),
|
|
|
|
url.toString(),
|
|
|
|
this);
|
2016-06-20 14:06:57 +03:00
|
|
|
}
|
|
|
|
|
2017-04-05 10:38:46 +03:00
|
|
|
void ShareLinkWidget::openShareLink(const QUrl &url)
|
2015-11-05 11:58:16 +03:00
|
|
|
{
|
2017-05-10 10:37:10 +03:00
|
|
|
Utility::openBrowser(url, this);
|
2015-11-05 11:58:16 +03:00
|
|
|
}
|
|
|
|
|
2017-06-15 17:03:24 +03:00
|
|
|
void ShareLinkWidget::slotShareLinkButtonClicked()
|
|
|
|
{
|
|
|
|
auto share = sender()->property(propertyShareC).value<QSharedPointer<LinkShare>>();
|
|
|
|
bool downloadEnabled = share->getShowFileListing();
|
|
|
|
_copyDirectLinkAction->setVisible(downloadEnabled);
|
|
|
|
_emailDirectLinkAction->setVisible(downloadEnabled);
|
|
|
|
|
|
|
|
_shareLinkMenu->setProperty(propertyShareC, QVariant::fromValue(share));
|
|
|
|
_shareLinkMenu->exec(QCursor::pos());
|
|
|
|
}
|
|
|
|
|
|
|
|
void ShareLinkWidget::slotShareLinkActionTriggered(QAction *action)
|
2015-11-05 11:58:16 +03:00
|
|
|
{
|
2017-04-05 10:38:46 +03:00
|
|
|
auto share = sender()->property(propertyShareC).value<QSharedPointer<LinkShare>>();
|
|
|
|
|
|
|
|
if (action == _copyLinkAction) {
|
2017-05-10 10:37:10 +03:00
|
|
|
QApplication::clipboard()->setText(share->getLink().toString());
|
2017-05-02 13:58:01 +03:00
|
|
|
} else if (action == _copyDirectLinkAction) {
|
2017-05-10 10:37:10 +03:00
|
|
|
QApplication::clipboard()->setText(share->getDirectDownloadLink().toString());
|
2017-04-05 10:38:46 +03:00
|
|
|
} else if (action == _emailLinkAction) {
|
2017-05-02 13:58:01 +03:00
|
|
|
emailShareLink(share->getLink());
|
|
|
|
} else if (action == _emailDirectLinkAction) {
|
|
|
|
emailShareLink(share->getDirectDownloadLink());
|
2017-04-05 10:38:46 +03:00
|
|
|
} else if (action == _openLinkAction) {
|
2017-05-02 13:58:01 +03:00
|
|
|
openShareLink(share->getLink());
|
2017-04-05 10:38:46 +03:00
|
|
|
}
|
2015-11-05 11:58:16 +03:00
|
|
|
}
|
|
|
|
|
2017-04-05 10:38:46 +03:00
|
|
|
void ShareLinkWidget::slotDeleteShareClicked()
|
2015-11-05 11:58:16 +03:00
|
|
|
{
|
2017-04-05 10:38:46 +03:00
|
|
|
auto share = sender()->property(propertyShareC).value<QSharedPointer<LinkShare>>();
|
|
|
|
share->deleteShare();
|
2015-11-05 11:58:16 +03:00
|
|
|
}
|
|
|
|
|
2017-06-15 16:38:22 +03:00
|
|
|
void ShareLinkWidget::slotPermissionsCheckboxClicked()
|
2015-11-05 11:58:16 +03:00
|
|
|
{
|
2017-04-05 10:38:46 +03:00
|
|
|
if (auto current = selectedShare()) {
|
|
|
|
_ui->checkBox_editing->setEnabled(false);
|
2017-06-15 16:38:22 +03:00
|
|
|
_ui->checkBox_fileListing->setEnabled(false);
|
2017-04-05 10:38:46 +03:00
|
|
|
_pi_editing->startAnimation();
|
|
|
|
_ui->errorLabel->hide();
|
2015-11-05 11:58:16 +03:00
|
|
|
|
2017-06-15 16:38:22 +03:00
|
|
|
SharePermissions perm = SharePermissionRead;
|
|
|
|
if (_ui->checkBox_editing->isChecked() && _ui->checkBox_fileListing->isChecked()) {
|
|
|
|
perm = SharePermissionRead | SharePermissionCreate
|
|
|
|
| SharePermissionUpdate | SharePermissionDelete;
|
|
|
|
} else if (_ui->checkBox_editing->isChecked() && !_ui->checkBox_fileListing->isChecked()) {
|
|
|
|
perm = SharePermissionCreate;
|
|
|
|
}
|
|
|
|
current->setPermissions(perm);
|
2017-04-05 10:38:46 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QSharedPointer<LinkShare> ShareLinkWidget::selectedShare() const
|
|
|
|
{
|
|
|
|
const auto items = _ui->linkShares->selectedItems();
|
|
|
|
if (items.isEmpty()) {
|
|
|
|
return QSharedPointer<LinkShare>();
|
2015-11-05 11:58:16 +03:00
|
|
|
}
|
|
|
|
|
2017-04-05 10:38:46 +03:00
|
|
|
return items.first()->data(Qt::UserRole).value<QSharedPointer<LinkShare>>();
|
|
|
|
}
|
|
|
|
|
2017-06-15 16:38:22 +03:00
|
|
|
void ShareLinkWidget::slotPermissionsSet()
|
2017-04-05 10:38:46 +03:00
|
|
|
{
|
|
|
|
if (sender() == selectedShare().data()) {
|
|
|
|
slotShareSelectionChanged();
|
|
|
|
}
|
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);
|
|
|
|
|
2017-04-05 10:38:46 +03:00
|
|
|
_ui->checkBox_password->setEnabled(!_passwordRequired);
|
2016-01-22 13:56:05 +03:00
|
|
|
_ui->lineEdit_password->setEnabled(true);
|
|
|
|
_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();
|
|
|
|
}
|
|
|
|
}
|