2015-02-25 20:32:25 +03:00
|
|
|
/*
|
|
|
|
* 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
|
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-02-25 20:32:25 +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.
|
|
|
|
*/
|
|
|
|
|
2018-08-02 22:19:57 +03:00
|
|
|
#include "ui_sharedialog.h"
|
2014-09-03 18:12:21 +04:00
|
|
|
#include "sharedialog.h"
|
2017-05-09 15:24:11 +03:00
|
|
|
#include "sharee.h"
|
2015-11-05 11:58:16 +03:00
|
|
|
#include "sharelinkwidget.h"
|
|
|
|
#include "shareusergroupwidget.h"
|
|
|
|
|
2019-04-06 21:15:24 +03:00
|
|
|
#include "sharemanager.h"
|
|
|
|
|
2014-09-03 18:12:21 +04:00
|
|
|
#include "account.h"
|
2016-02-22 12:38:10 +03:00
|
|
|
#include "accountstate.h"
|
2015-03-26 20:08:06 +03:00
|
|
|
#include "configfile.h"
|
2015-11-05 11:58:16 +03:00
|
|
|
#include "theme.h"
|
2015-09-07 14:50:01 +03:00
|
|
|
#include "thumbnailjob.h"
|
2020-10-06 15:01:53 +03:00
|
|
|
#include "wordlist.h"
|
2015-09-07 14:50:01 +03:00
|
|
|
|
2015-08-20 14:40:10 +03:00
|
|
|
#include <QFileInfo>
|
2015-11-05 11:58:16 +03:00
|
|
|
#include <QFileIconProvider>
|
2020-01-09 17:10:01 +03:00
|
|
|
#include <QInputDialog>
|
2016-02-22 12:38:10 +03:00
|
|
|
#include <QPointer>
|
2015-11-05 11:58:16 +03:00
|
|
|
#include <QPushButton>
|
|
|
|
#include <QFrame>
|
2014-09-03 18:12:21 +04:00
|
|
|
|
2020-10-06 15:01:53 +03:00
|
|
|
namespace {
|
|
|
|
QString createRandomPassword()
|
|
|
|
{
|
|
|
|
const auto words = OCC::WordList::getRandomWords(10);
|
|
|
|
|
|
|
|
const auto addFirstLetter = [](const QString ¤t, const QString &next) {
|
|
|
|
return current + next.at(0);
|
|
|
|
};
|
|
|
|
|
|
|
|
return std::accumulate(std::cbegin(words), std::cend(words), QString(), addFirstLetter);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-12-19 18:56:17 +03:00
|
|
|
namespace OCC {
|
2014-09-03 18:12:21 +04:00
|
|
|
|
2017-03-28 12:04:57 +03:00
|
|
|
static const int thumbnailSize = 40;
|
|
|
|
|
2016-03-30 12:33:34 +03:00
|
|
|
ShareDialog::ShareDialog(QPointer<AccountState> accountState,
|
|
|
|
const QString &sharePath,
|
|
|
|
const QString &localPath,
|
|
|
|
SharePermissions maxSharingPermissions,
|
2017-05-10 10:37:10 +03:00
|
|
|
const QByteArray &numericFileId,
|
2018-04-06 18:13:29 +03:00
|
|
|
ShareDialogStartPage startPage,
|
2016-03-30 12:33:34 +03:00
|
|
|
QWidget *parent)
|
2015-11-05 11:58:16 +03:00
|
|
|
: QDialog(parent)
|
2015-01-14 12:35:09 +03:00
|
|
|
, _ui(new Ui::ShareDialog)
|
2016-02-22 12:38:10 +03:00
|
|
|
, _accountState(accountState)
|
2015-01-16 16:48:56 +03:00
|
|
|
, _sharePath(sharePath)
|
2015-02-06 18:24:08 +03:00
|
|
|
, _localPath(localPath)
|
2016-03-30 12:33:34 +03:00
|
|
|
, _maxSharingPermissions(maxSharingPermissions)
|
2017-09-15 15:24:34 +03:00
|
|
|
, _privateLinkUrl(accountState->account()->deprecatedPrivateLinkUrl(numericFileId).toString(QUrl::FullyEncoded))
|
2018-04-06 18:13:29 +03:00
|
|
|
, _startPage(startPage)
|
2014-09-03 18:12:21 +04:00
|
|
|
{
|
2016-09-28 14:00:52 +03:00
|
|
|
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
|
2014-09-03 18:12:21 +04:00
|
|
|
setAttribute(Qt::WA_DeleteOnClose);
|
2015-03-26 20:08:06 +03:00
|
|
|
setObjectName("SharingDialog"); // required as group for saveGeometry call
|
|
|
|
|
2014-09-03 18:12:21 +04:00
|
|
|
_ui->setupUi(this);
|
2015-08-20 14:40:10 +03:00
|
|
|
|
2016-02-22 12:38:10 +03:00
|
|
|
// We want to act on account state changes
|
2017-09-20 11:14:48 +03:00
|
|
|
connect(_accountState.data(), &AccountState::stateChanged, this, &ShareDialog::slotAccountStateChanged);
|
2016-02-22 12:38:10 +03:00
|
|
|
|
2015-11-05 11:58:16 +03:00
|
|
|
// Set icon
|
2015-01-16 16:48:56 +03:00
|
|
|
QFileInfo f_info(_localPath);
|
|
|
|
QFileIconProvider icon_provider;
|
|
|
|
QIcon icon = icon_provider.icon(f_info);
|
2017-05-22 15:15:53 +03:00
|
|
|
auto pixmap = icon.pixmap(thumbnailSize, thumbnailSize);
|
|
|
|
if (pixmap.width() > 0) {
|
|
|
|
_ui->label_icon->setPixmap(pixmap);
|
|
|
|
}
|
2015-01-21 17:03:01 +03:00
|
|
|
|
2015-11-05 11:58:16 +03:00
|
|
|
// Set filename
|
2018-05-28 18:14:57 +03:00
|
|
|
QString fileName = QFileInfo(_sharePath).fileName();
|
2015-03-26 18:51:31 +03:00
|
|
|
_ui->label_name->setText(tr("%1").arg(fileName));
|
|
|
|
QFont f(_ui->label_name->font());
|
2020-08-18 22:46:30 +03:00
|
|
|
f.setPointSize(qRound(f.pointSize() * 1.4));
|
2015-03-26 18:51:31 +03:00
|
|
|
_ui->label_name->setFont(f);
|
2015-02-25 15:44:12 +03:00
|
|
|
|
2015-03-26 18:51:31 +03:00
|
|
|
QString ocDir(_sharePath);
|
|
|
|
ocDir.truncate(ocDir.length() - fileName.length());
|
|
|
|
|
2015-09-04 16:15:26 +03:00
|
|
|
ocDir.replace(QRegExp("^/*"), "");
|
|
|
|
ocDir.replace(QRegExp("/*$"), "");
|
2015-11-24 14:30:53 +03:00
|
|
|
|
|
|
|
// 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);
|
2015-09-04 16:15:26 +03:00
|
|
|
if (ocDir.isEmpty()) {
|
2015-11-24 14:30:53 +03:00
|
|
|
_ui->gridLayout->addWidget(_ui->label_name, 0, 1, 2, 1);
|
2015-03-26 20:08:06 +03:00
|
|
|
_ui->label_sharePath->setText(QString());
|
|
|
|
} else {
|
2015-11-24 14:30:53 +03:00
|
|
|
_ui->gridLayout->addWidget(_ui->label_name, 0, 1, 1, 1);
|
|
|
|
_ui->gridLayout->addWidget(_ui->label_sharePath, 1, 1, 1, 1);
|
2015-03-26 20:08:06 +03:00
|
|
|
_ui->label_sharePath->setText(tr("Folder: %2").arg(ocDir));
|
2015-01-21 17:03:01 +03:00
|
|
|
}
|
2015-02-25 15:44:12 +03:00
|
|
|
|
2015-01-21 17:03:01 +03:00
|
|
|
this->setWindowTitle(tr("%1 Sharing").arg(Theme::instance()->appNameGUI()));
|
|
|
|
|
2016-02-22 12:38:10 +03:00
|
|
|
if (!accountState->account()->capabilities().shareAPI()) {
|
2015-11-19 14:00:53 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-03-30 12:33:34 +03:00
|
|
|
if (QFileInfo(_localPath).isFile()) {
|
2020-05-18 21:54:23 +03:00
|
|
|
auto *job = new ThumbnailJob(_sharePath, _accountState->account(), this);
|
2017-09-20 11:14:48 +03:00
|
|
|
connect(job, &ThumbnailJob::jobFinished, this, &ShareDialog::slotThumbnailFetched);
|
2016-03-30 12:33:34 +03:00
|
|
|
job->start();
|
2015-07-10 16:46:17 +03:00
|
|
|
}
|
|
|
|
|
2016-03-30 12:33:34 +03:00
|
|
|
auto job = new PropfindJob(accountState->account(), _sharePath);
|
2017-09-15 15:24:34 +03:00
|
|
|
job->setProperties(
|
|
|
|
QList<QByteArray>()
|
|
|
|
<< "http://open-collaboration-services.org/ns:share-permissions"
|
2017-11-10 11:22:41 +03:00
|
|
|
<< "http://owncloud.org/ns:fileid" // numeric file id for fallback private link generation
|
2017-09-15 15:24:34 +03:00
|
|
|
<< "http://owncloud.org/ns:privatelink");
|
2016-03-30 12:33:34 +03:00
|
|
|
job->setTimeout(10 * 1000);
|
2017-09-20 11:14:48 +03:00
|
|
|
connect(job, &PropfindJob::result, this, &ShareDialog::slotPropfindReceived);
|
|
|
|
connect(job, &PropfindJob::finishedWithError, this, &ShareDialog::slotPropfindError);
|
2016-03-30 12:33:34 +03:00
|
|
|
job->start();
|
2019-04-06 21:15:24 +03:00
|
|
|
|
|
|
|
bool sharingPossible = true;
|
|
|
|
if (!accountState->account()->capabilities().sharePublicLink()) {
|
|
|
|
qCWarning(lcSharing) << "Link shares have been disabled";
|
|
|
|
sharingPossible = false;
|
|
|
|
} else if (!(maxSharingPermissions & SharePermissionShare)) {
|
|
|
|
qCWarning(lcSharing) << "The file can not be shared because it was shared without sharing permission.";
|
|
|
|
sharingPossible = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sharingPossible) {
|
|
|
|
_manager = new ShareManager(accountState->account(), this);
|
|
|
|
connect(_manager, &ShareManager::sharesFetched, this, &ShareDialog::slotSharesFetched);
|
|
|
|
connect(_manager, &ShareManager::linkShareCreated, this, &ShareDialog::slotAddLinkShareWidget);
|
2020-01-09 17:10:01 +03:00
|
|
|
connect(_manager, &ShareManager::linkShareRequiresPassword, this, &ShareDialog::slotLinkShareRequiresPassword);
|
2019-04-06 21:15:24 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ShareDialog::addLinkShareWidget(const QSharedPointer<LinkShare> &linkShare){
|
|
|
|
_linkWidgetList.append(new ShareLinkWidget(_accountState->account(), _sharePath, _localPath, _maxSharingPermissions, this));
|
|
|
|
int index = _linkWidgetList.size()-1;
|
|
|
|
_linkWidgetList.at(index)->setLinkShare(linkShare);
|
|
|
|
|
|
|
|
connect(linkShare.data(), &Share::serverError, _linkWidgetList.at(index), &ShareLinkWidget::slotServerError);
|
|
|
|
connect(linkShare.data(), &Share::shareDeleted, _linkWidgetList.at(index), &ShareLinkWidget::slotDeleteShareFetched);
|
2020-05-29 21:57:52 +03:00
|
|
|
|
|
|
|
if(_manager) {
|
2020-05-29 19:28:52 +03:00
|
|
|
connect(_manager, &ShareManager::linkShareRequiresPassword, _linkWidgetList.at(index), &ShareLinkWidget::slotCreateShareRequiresPassword);
|
|
|
|
connect(_manager, &ShareManager::serverError, _linkWidgetList.at(index), &ShareLinkWidget::slotServerError);
|
|
|
|
}
|
2019-04-06 21:15:24 +03:00
|
|
|
|
|
|
|
// Connect all shares signals to gui slots
|
|
|
|
connect(this, &ShareDialog::toggleAnimation, _linkWidgetList.at(index), &ShareLinkWidget::slotToggleAnimation);
|
|
|
|
connect(_linkWidgetList.at(index), &ShareLinkWidget::createLinkShare, this, &ShareDialog::slotCreateLinkShare);
|
|
|
|
connect(_linkWidgetList.at(index), &ShareLinkWidget::deleteLinkShare, this, &ShareDialog::slotDeleteShare);
|
|
|
|
//connect(_linkWidgetList.at(index), &ShareLinkWidget::resizeRequested, this, &ShareDialog::slotAdjustScrollWidgetSize);
|
|
|
|
|
2019-12-09 22:59:10 +03:00
|
|
|
// Connect styleChanged events to our widget, so it can adapt (Dark-/Light-Mode switching)
|
|
|
|
connect(this, &ShareDialog::styleChanged, _linkWidgetList.at(index), &ShareLinkWidget::slotStyleChanged);
|
|
|
|
|
2019-04-06 21:15:24 +03:00
|
|
|
_ui->verticalLayout->insertWidget(_linkWidgetList.size()+1, _linkWidgetList.at(index));
|
|
|
|
_linkWidgetList.at(index)->setupUiOptions();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ShareDialog::initLinkShareWidget(){
|
|
|
|
if(_linkWidgetList.size() == 0){
|
|
|
|
_emptyShareLinkWidget = new ShareLinkWidget(_accountState->account(), _sharePath, _localPath, _maxSharingPermissions, this);
|
|
|
|
_linkWidgetList.append(_emptyShareLinkWidget);
|
|
|
|
|
2020-10-14 19:37:34 +03:00
|
|
|
if (_manager) {
|
|
|
|
connect(_manager, &ShareManager::linkShareRequiresPassword, _emptyShareLinkWidget, &ShareLinkWidget::slotCreateShareRequiresPassword);
|
|
|
|
}
|
|
|
|
|
2019-09-18 14:37:49 +03:00
|
|
|
connect(_emptyShareLinkWidget, &ShareLinkWidget::resizeRequested, this, &ShareDialog::slotAdjustScrollWidgetSize);
|
2019-04-06 21:15:24 +03:00
|
|
|
// connect(this, &ShareDialog::toggleAnimation, _emptyShareLinkWidget, &ShareLinkWidget::slotToggleAnimation);
|
|
|
|
connect(_emptyShareLinkWidget, &ShareLinkWidget::createLinkShare, this, &ShareDialog::slotCreateLinkShare);
|
|
|
|
|
|
|
|
_ui->verticalLayout->insertWidget(_linkWidgetList.size()+1, _emptyShareLinkWidget);
|
|
|
|
_emptyShareLinkWidget->show();
|
|
|
|
|
|
|
|
} else if(_emptyShareLinkWidget) {
|
|
|
|
_emptyShareLinkWidget->hide();
|
|
|
|
_ui->verticalLayout->removeWidget(_emptyShareLinkWidget);
|
|
|
|
_linkWidgetList.removeAll(_emptyShareLinkWidget);
|
|
|
|
_emptyShareLinkWidget = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ShareDialog::slotAddLinkShareWidget(const QSharedPointer<LinkShare> &linkShare){
|
|
|
|
emit toggleAnimation(true);
|
|
|
|
addLinkShareWidget(linkShare);
|
|
|
|
initLinkShareWidget();
|
|
|
|
emit toggleAnimation(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ShareDialog::slotSharesFetched(const QList<QSharedPointer<Share>> &shares)
|
|
|
|
{
|
|
|
|
emit toggleAnimation(true);
|
|
|
|
|
|
|
|
const QString versionString = _accountState->account()->serverVersion();
|
|
|
|
qCInfo(lcSharing) << versionString << "Fetched" << shares.count() << "shares";
|
|
|
|
foreach (auto share, shares) {
|
2019-06-21 19:36:45 +03:00
|
|
|
if (share->getShareType() != Share::TypeLink || share->getUidOwner() != share->account()->davUser()) {
|
2019-04-06 21:15:24 +03:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
QSharedPointer<LinkShare> linkShare = qSharedPointerDynamicCast<LinkShare>(share);
|
|
|
|
addLinkShareWidget(linkShare);
|
|
|
|
}
|
|
|
|
|
|
|
|
initLinkShareWidget();
|
|
|
|
emit toggleAnimation(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ShareDialog::slotAdjustScrollWidgetSize()
|
|
|
|
{
|
|
|
|
int count = this->findChildren<ShareLinkWidget *>().count();
|
|
|
|
_ui->scrollArea->setVisible(count > 0);
|
|
|
|
if (count > 0 && count <= 3) {
|
|
|
|
_ui->scrollArea->setFixedHeight(_ui->scrollArea->widget()->sizeHint().height());
|
|
|
|
}
|
|
|
|
_ui->scrollArea->setFrameShape(count > 3 ? QFrame::StyledPanel : QFrame::NoFrame);
|
2014-09-09 03:50:31 +04:00
|
|
|
}
|
|
|
|
|
2014-09-03 18:12:21 +04:00
|
|
|
ShareDialog::~ShareDialog()
|
|
|
|
{
|
2019-04-12 12:52:02 +03:00
|
|
|
_linkWidgetList.clear();
|
2014-09-03 18:12:21 +04:00
|
|
|
delete _ui;
|
|
|
|
}
|
|
|
|
|
2015-11-05 11:58:16 +03:00
|
|
|
void ShareDialog::done(int r)
|
|
|
|
{
|
|
|
|
ConfigFile cfg;
|
|
|
|
cfg.saveGeometry(this);
|
|
|
|
QDialog::done(r);
|
2014-09-09 03:50:31 +04:00
|
|
|
}
|
|
|
|
|
2017-09-15 15:24:34 +03:00
|
|
|
void ShareDialog::slotPropfindReceived(const QVariantMap &result)
|
2014-09-03 18:12:21 +04:00
|
|
|
{
|
2016-03-30 12:33:34 +03:00
|
|
|
const QVariant receivedPermissions = result["share-permissions"];
|
|
|
|
if (!receivedPermissions.toString().isEmpty()) {
|
|
|
|
_maxSharingPermissions = static_cast<SharePermissions>(receivedPermissions.toInt());
|
2017-03-30 14:46:20 +03:00
|
|
|
qCInfo(lcSharing) << "Received sharing permissions for" << _sharePath << _maxSharingPermissions;
|
2015-03-26 19:23:29 +03:00
|
|
|
}
|
2017-09-15 15:24:34 +03:00
|
|
|
auto privateLinkUrl = result["privatelink"].toString();
|
2017-11-10 11:22:41 +03:00
|
|
|
auto numericFileId = result["fileid"].toByteArray();
|
2017-09-15 15:24:34 +03:00
|
|
|
if (!privateLinkUrl.isEmpty()) {
|
|
|
|
qCInfo(lcSharing) << "Received private link url for" << _sharePath << privateLinkUrl;
|
|
|
|
_privateLinkUrl = privateLinkUrl;
|
2017-11-10 11:22:41 +03:00
|
|
|
} else if (!numericFileId.isEmpty()) {
|
|
|
|
qCInfo(lcSharing) << "Received numeric file id for" << _sharePath << numericFileId;
|
|
|
|
_privateLinkUrl = _accountState->account()->deprecatedPrivateLinkUrl(numericFileId).toString(QUrl::FullyEncoded);
|
2017-09-15 15:24:34 +03:00
|
|
|
}
|
2015-03-26 19:23:29 +03:00
|
|
|
|
2016-03-30 12:33:34 +03:00
|
|
|
showSharingUi();
|
|
|
|
}
|
|
|
|
|
2017-09-15 15:24:34 +03:00
|
|
|
void ShareDialog::slotPropfindError()
|
2016-03-30 12:33:34 +03:00
|
|
|
{
|
|
|
|
// 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()
|
|
|
|
{
|
|
|
|
auto theme = Theme::instance();
|
|
|
|
|
2016-04-14 11:03:15 +03:00
|
|
|
// 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."));
|
2017-05-08 21:57:18 +03:00
|
|
|
label->setWordWrap(true);
|
2019-05-10 17:58:54 +03:00
|
|
|
_ui->verticalLayout->insertWidget(1, label);
|
2016-04-14 11:03:15 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-03-30 12:33:34 +03:00
|
|
|
// We only do user/group sharing from 8.2.0
|
|
|
|
bool userGroupSharing =
|
|
|
|
theme->userGroupSharing()
|
2017-03-14 17:57:57 +03:00
|
|
|
&& _accountState->account()->serverVersionInt() >= Account::makeServerVersion(8, 2, 0);
|
2016-03-30 12:33:34 +03:00
|
|
|
|
|
|
|
if (userGroupSharing) {
|
2017-09-15 15:24:34 +03:00
|
|
|
_userGroupWidget = new ShareUserGroupWidget(_accountState->account(), _sharePath, _localPath, _maxSharingPermissions, _privateLinkUrl, this);
|
2019-12-09 22:59:10 +03:00
|
|
|
|
|
|
|
// Connect styleChanged events to our widget, so it can adapt (Dark-/Light-Mode switching)
|
|
|
|
connect(this, &ShareDialog::styleChanged, _userGroupWidget, &ShareUserGroupWidget::slotStyleChanged);
|
|
|
|
|
2018-03-15 21:43:26 +03:00
|
|
|
_ui->verticalLayout->insertWidget(1, _userGroupWidget);
|
2015-11-05 11:58:16 +03:00
|
|
|
_userGroupWidget->getShares();
|
2015-03-09 16:33:02 +03:00
|
|
|
}
|
2016-03-30 12:33:34 +03:00
|
|
|
|
|
|
|
if (theme->linkSharing()) {
|
2020-05-29 21:57:52 +03:00
|
|
|
if(_manager) {
|
2020-05-29 19:12:36 +03:00
|
|
|
_manager->fetchShares(_sharePath);
|
|
|
|
}
|
2016-03-30 12:33:34 +03:00
|
|
|
}
|
2015-03-11 16:09:31 +03:00
|
|
|
}
|
|
|
|
|
2019-04-06 21:15:24 +03:00
|
|
|
void ShareDialog::slotCreateLinkShare()
|
|
|
|
{
|
2020-05-29 21:57:52 +03:00
|
|
|
if(_manager) {
|
2020-10-06 15:01:53 +03:00
|
|
|
const auto askOptionalPassword = _accountState->account()->capabilities().sharePublicLinkAskOptionalPassword();
|
|
|
|
const auto password = askOptionalPassword ? createRandomPassword() : QString();
|
|
|
|
_manager->createLinkShare(_sharePath, QString(), password);
|
2020-05-29 19:28:52 +03:00
|
|
|
}
|
2019-04-06 21:15:24 +03:00
|
|
|
}
|
|
|
|
|
2020-01-09 17:10:01 +03:00
|
|
|
void ShareDialog::slotLinkShareRequiresPassword()
|
|
|
|
{
|
2020-05-29 16:07:05 +03:00
|
|
|
bool ok = false;
|
2020-01-09 17:10:01 +03:00
|
|
|
QString password = QInputDialog::getText(this,
|
|
|
|
tr("Password for share required"),
|
|
|
|
tr("Please enter a password for your link share:"),
|
|
|
|
QLineEdit::Normal,
|
|
|
|
QString(),
|
|
|
|
&ok);
|
|
|
|
|
|
|
|
if (!ok) {
|
|
|
|
// The dialog was canceled so no need to do anything
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-05-29 21:57:52 +03:00
|
|
|
if(_manager) {
|
2020-05-29 19:28:52 +03:00
|
|
|
// Try to create the link share again with the newly entered password
|
|
|
|
_manager->createLinkShare(_sharePath, QString(), password);
|
|
|
|
}
|
2020-01-09 17:10:01 +03:00
|
|
|
}
|
2019-04-06 21:15:24 +03:00
|
|
|
|
|
|
|
void ShareDialog::slotDeleteShare()
|
|
|
|
{
|
|
|
|
auto sharelinkWidget = dynamic_cast<ShareLinkWidget*>(sender());
|
|
|
|
sharelinkWidget->hide();
|
|
|
|
_ui->verticalLayout->removeWidget(sharelinkWidget);
|
|
|
|
_linkWidgetList.removeAll(sharelinkWidget);
|
|
|
|
initLinkShareWidget();
|
|
|
|
}
|
|
|
|
|
2015-01-21 15:51:16 +03:00
|
|
|
void ShareDialog::slotThumbnailFetched(const int &statusCode, const QByteArray &reply)
|
|
|
|
{
|
|
|
|
if (statusCode != 200) {
|
2017-03-30 14:46:20 +03:00
|
|
|
qCWarning(lcSharing) << "Thumbnail status code: " << statusCode;
|
2015-01-21 15:51:16 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QPixmap p;
|
|
|
|
p.loadFromData(reply, "PNG");
|
2017-03-28 12:04:57 +03:00
|
|
|
p = p.scaledToHeight(thumbnailSize, Qt::SmoothTransformation);
|
2015-01-21 15:51:16 +03:00
|
|
|
_ui->label_icon->setPixmap(p);
|
2017-05-19 10:48:47 +03:00
|
|
|
_ui->label_icon->show();
|
2015-01-21 15:51:16 +03:00
|
|
|
}
|
|
|
|
|
2016-02-22 12:38:10 +03:00
|
|
|
void ShareDialog::slotAccountStateChanged(int state)
|
|
|
|
{
|
|
|
|
bool enabled = (state == AccountState::State::Connected);
|
2017-05-09 15:24:11 +03:00
|
|
|
qCDebug(lcSharing) << "Account connected?" << enabled;
|
2016-02-22 12:38:10 +03:00
|
|
|
|
2020-05-29 21:57:52 +03:00
|
|
|
if (_userGroupWidget) {
|
2016-02-22 12:38:10 +03:00
|
|
|
_userGroupWidget->setEnabled(enabled);
|
|
|
|
}
|
|
|
|
|
2019-04-12 12:52:02 +03:00
|
|
|
if(_linkWidgetList.size() > 0){
|
|
|
|
foreach(ShareLinkWidget *widget, _linkWidgetList){
|
|
|
|
widget->setEnabled(state);
|
|
|
|
}
|
|
|
|
}
|
2016-02-22 12:38:10 +03:00
|
|
|
}
|
2019-12-09 22:59:10 +03:00
|
|
|
|
|
|
|
void ShareDialog::changeEvent(QEvent *e)
|
|
|
|
{
|
|
|
|
switch (e->type()) {
|
|
|
|
case QEvent::StyleChange:
|
|
|
|
case QEvent::PaletteChange:
|
|
|
|
case QEvent::ThemeChange:
|
|
|
|
// Notify the other widgets (Dark-/Light-Mode switching)
|
|
|
|
emit styleChanged();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
QDialog::changeEvent(e);
|
|
|
|
}
|
|
|
|
|
2020-05-29 19:12:36 +03:00
|
|
|
} // namespace OCC
|