2015-11-01 00:21:09 +03:00
|
|
|
/*
|
|
|
|
* 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
|
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-01 00:21:09 +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.
|
|
|
|
*/
|
|
|
|
|
2015-11-05 11:58:16 +03:00
|
|
|
#include "shareusergroupwidget.h"
|
|
|
|
#include "ui_shareusergroupwidget.h"
|
2017-04-04 16:05:08 +03:00
|
|
|
#include "ui_shareuserline.h"
|
2015-11-01 00:21:09 +03:00
|
|
|
#include "account.h"
|
|
|
|
#include "folderman.h"
|
|
|
|
#include "folder.h"
|
|
|
|
#include "accountmanager.h"
|
|
|
|
#include "theme.h"
|
|
|
|
#include "configfile.h"
|
|
|
|
#include "capabilities.h"
|
2017-05-10 10:37:10 +03:00
|
|
|
#include "guiutility.h"
|
2015-11-01 00:21:09 +03:00
|
|
|
#include "thumbnailjob.h"
|
2015-11-02 00:23:22 +03:00
|
|
|
#include "sharee.h"
|
2016-09-14 16:31:05 +03:00
|
|
|
#include "sharemanager.h"
|
2015-11-01 00:21:09 +03:00
|
|
|
|
|
|
|
#include "QProgressIndicator.h"
|
|
|
|
#include <QBuffer>
|
|
|
|
#include <QFileIconProvider>
|
|
|
|
#include <QClipboard>
|
|
|
|
#include <QFileInfo>
|
2015-11-09 19:21:42 +03:00
|
|
|
#include <QAbstractProxyModel>
|
2015-11-02 00:23:22 +03:00
|
|
|
#include <QCompleter>
|
2015-11-16 19:59:24 +03:00
|
|
|
#include <qscrollarea.h>
|
|
|
|
#include <qlayout.h>
|
2015-11-13 13:03:51 +03:00
|
|
|
#include <QPropertyAnimation>
|
2015-11-25 13:26:21 +03:00
|
|
|
#include <QMenu>
|
|
|
|
#include <QAction>
|
2017-05-10 10:37:10 +03:00
|
|
|
#include <QDesktopServices>
|
|
|
|
#include <QMessageBox>
|
2015-11-01 00:21:09 +03:00
|
|
|
|
|
|
|
namespace OCC {
|
|
|
|
|
2016-03-30 12:33:34 +03:00
|
|
|
ShareUserGroupWidget::ShareUserGroupWidget(AccountPtr account,
|
2017-05-17 11:55:42 +03:00
|
|
|
const QString &sharePath,
|
|
|
|
const QString &localPath,
|
|
|
|
SharePermissions maxSharingPermissions,
|
2017-09-15 15:24:34 +03:00
|
|
|
const QString &privateLinkUrl,
|
2017-05-17 11:55:42 +03:00
|
|
|
QWidget *parent)
|
|
|
|
: QWidget(parent)
|
|
|
|
, _ui(new Ui::ShareUserGroupWidget)
|
|
|
|
, _account(account)
|
|
|
|
, _sharePath(sharePath)
|
|
|
|
, _localPath(localPath)
|
|
|
|
, _maxSharingPermissions(maxSharingPermissions)
|
2017-09-15 15:24:34 +03:00
|
|
|
, _privateLinkUrl(privateLinkUrl)
|
2017-05-17 11:55:42 +03:00
|
|
|
, _disableCompleterActivated(false)
|
2015-11-01 00:21:09 +03:00
|
|
|
{
|
|
|
|
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();
|
|
|
|
|
2015-11-05 00:00:35 +03:00
|
|
|
_completer = new QCompleter(this);
|
2015-11-16 16:18:01 +03:00
|
|
|
_completerModel = new ShareeModel(_account,
|
2017-05-17 11:55:42 +03:00
|
|
|
_isFile ? QLatin1String("file") : QLatin1String("folder"),
|
|
|
|
_completer);
|
2017-09-20 11:14:48 +03:00
|
|
|
connect(_completerModel, &ShareeModel::shareesReady, this, &ShareUserGroupWidget::slotShareesReady);
|
|
|
|
connect(_completerModel, &ShareeModel::displayErrorMessage, this, &ShareUserGroupWidget::displayError);
|
2015-11-16 16:18:01 +03:00
|
|
|
|
|
|
|
_completer->setModel(_completerModel);
|
2015-12-10 16:56:15 +03:00
|
|
|
_completer->setCaseSensitivity(Qt::CaseInsensitive);
|
2016-05-26 01:52:33 +03:00
|
|
|
_completer->setCompletionMode(QCompleter::UnfilteredPopupCompletion);
|
2015-11-05 00:00:35 +03:00
|
|
|
_ui->shareeLineEdit->setCompleter(_completer);
|
|
|
|
|
2015-11-01 00:21:09 +03:00
|
|
|
_manager = new ShareManager(_account, this);
|
2017-09-20 11:14:48 +03:00
|
|
|
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);
|
2015-12-10 16:56:15 +03:00
|
|
|
|
|
|
|
// 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)),
|
2017-05-17 11:55:42 +03:00
|
|
|
Qt::QueuedConnection);
|
2015-12-10 16:56:15 +03:00
|
|
|
connect(_completer, SIGNAL(highlighted(QModelIndex)), SLOT(slotCompleterHighlighted(QModelIndex)),
|
2017-05-17 11:55:42 +03:00
|
|
|
Qt::QueuedConnection);
|
2015-11-13 12:27:26 +03:00
|
|
|
|
2015-11-16 16:18:01 +03:00
|
|
|
// Queued connection so this signal is recieved after textChanged
|
2017-09-20 11:14:48 +03:00
|
|
|
connect(_ui->shareeLineEdit, &QLineEdit::textEdited,
|
|
|
|
this, &ShareUserGroupWidget::slotLineEditTextEdited, Qt::QueuedConnection);
|
|
|
|
connect(&_completionTimer, &QTimer::timeout, this, &ShareUserGroupWidget::searchForSharees);
|
2015-11-16 16:18:01 +03:00
|
|
|
_completionTimer.setSingleShot(true);
|
|
|
|
_completionTimer.setInterval(600);
|
2015-11-16 19:59:24 +03:00
|
|
|
|
|
|
|
setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Expanding);
|
2016-01-12 15:19:33 +03:00
|
|
|
_ui->errorLabel->hide();
|
2016-04-29 15:11:27 +03:00
|
|
|
|
|
|
|
// Setup the sharee search progress indicator
|
|
|
|
_ui->shareeHorizontalLayout->addWidget(&_pi_sharee);
|
2015-11-01 00:21:09 +03:00
|
|
|
}
|
|
|
|
|
2015-11-05 11:58:16 +03:00
|
|
|
ShareUserGroupWidget::~ShareUserGroupWidget()
|
2015-11-01 00:21:09 +03:00
|
|
|
{
|
|
|
|
delete _ui;
|
|
|
|
}
|
|
|
|
|
2015-11-17 12:24:35 +03:00
|
|
|
void ShareUserGroupWidget::on_shareeLineEdit_textChanged(const QString &)
|
2015-11-02 00:23:22 +03:00
|
|
|
{
|
2015-11-16 16:18:01 +03:00
|
|
|
_completionTimer.stop();
|
2015-11-02 00:23:22 +03:00
|
|
|
}
|
|
|
|
|
2017-05-17 11:55:42 +03:00
|
|
|
void ShareUserGroupWidget::slotLineEditTextEdited(const QString &text)
|
2015-11-16 16:18:01 +03:00
|
|
|
{
|
2016-01-12 16:35:35 +03:00
|
|
|
_disableCompleterActivated = false;
|
2015-11-16 16:18:01 +03:00
|
|
|
// 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();
|
|
|
|
}
|
2015-12-10 15:49:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void ShareUserGroupWidget::slotLineEditReturn()
|
|
|
|
{
|
2016-01-12 16:35:35 +03:00
|
|
|
_disableCompleterActivated = false;
|
2015-12-10 15:49:47 +03:00
|
|
|
// 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);
|
2015-12-10 16:56:15 +03:00
|
|
|
if (sharee->format() == text
|
2017-05-17 11:55:42 +03:00
|
|
|
|| sharee->displayName() == text
|
|
|
|
|| sharee->shareWith() == text) {
|
2015-12-10 15:49:47 +03:00
|
|
|
slotCompleterActivated(_completerModel->index(i));
|
2016-01-12 16:35:35 +03:00
|
|
|
// 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;
|
2015-12-10 15:49:47 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// nothing found? try to refresh completion
|
|
|
|
_completionTimer.start();
|
2015-11-16 16:18:01 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-11-17 12:24:35 +03:00
|
|
|
void ShareUserGroupWidget::searchForSharees()
|
2015-11-02 00:23:22 +03:00
|
|
|
{
|
2015-11-16 16:18:01 +03:00
|
|
|
_completionTimer.stop();
|
2016-04-29 15:11:27 +03:00
|
|
|
_pi_sharee.startAnimation();
|
2015-11-16 16:18:01 +03:00
|
|
|
ShareeModel::ShareeSet blacklist;
|
2015-11-05 17:01:29 +03:00
|
|
|
|
|
|
|
// Add the current user to _sharees since we can't share with ourself
|
|
|
|
QSharedPointer<Sharee> currentUser(new Sharee(_account->credentials()->user(), "", Sharee::Type::User));
|
2015-11-16 16:18:01 +03:00
|
|
|
blacklist << currentUser;
|
2015-11-05 17:01:29 +03:00
|
|
|
|
2017-05-17 11:55:42 +03:00
|
|
|
foreach (auto sw, _ui->scrollArea->findChildren<ShareUserLine *>()) {
|
2015-11-16 19:59:24 +03:00
|
|
|
blacklist << sw->share()->getShareWith();
|
2015-11-05 17:01:29 +03:00
|
|
|
}
|
2016-01-12 16:35:35 +03:00
|
|
|
_ui->errorLabel->hide();
|
2015-11-16 16:18:01 +03:00
|
|
|
_completerModel->fetch(_ui->shareeLineEdit->text(), blacklist);
|
2015-11-02 00:23:22 +03:00
|
|
|
}
|
|
|
|
|
2015-11-05 11:58:16 +03:00
|
|
|
void ShareUserGroupWidget::getShares()
|
2015-11-01 00:21:09 +03:00
|
|
|
{
|
|
|
|
_manager->fetchShares(_sharePath);
|
|
|
|
}
|
|
|
|
|
2015-11-05 11:58:16 +03:00
|
|
|
void ShareUserGroupWidget::slotSharesFetched(const QList<QSharedPointer<Share>> &shares)
|
2015-11-01 00:21:09 +03:00
|
|
|
{
|
2015-11-16 19:59:24 +03:00
|
|
|
QScrollArea *scrollArea = _ui->scrollArea;
|
|
|
|
|
|
|
|
auto newViewPort = new QWidget(scrollArea);
|
|
|
|
auto layout = new QVBoxLayout(newViewPort);
|
|
|
|
|
|
|
|
QSize minimumSize = newViewPort->sizeHint();
|
|
|
|
int x = 0;
|
2015-11-01 00:21:09 +03:00
|
|
|
|
2017-04-04 15:41:25 +03:00
|
|
|
if (shares.isEmpty()) {
|
|
|
|
layout->addWidget(new QLabel(tr("The item is not shared with any users or groups")));
|
|
|
|
} else {
|
2017-05-17 11:55:42 +03:00
|
|
|
foreach (const auto &share, shares) {
|
2017-04-04 15:41:25 +03:00
|
|
|
// We don't handle link shares
|
|
|
|
if (share->getShareType() == Share::TypeLink) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2017-04-04 16:05:08 +03:00
|
|
|
ShareUserLine *s = new ShareUserLine(share, _maxSharingPermissions, _isFile, _ui->scrollArea);
|
2017-09-20 11:14:48 +03:00
|
|
|
connect(s, &ShareUserLine::resizeRequested, this, &ShareUserGroupWidget::slotAdjustScrollWidgetSize);
|
|
|
|
connect(s, &ShareUserLine::visualDeletionDone, this, &ShareUserGroupWidget::getShares);
|
2017-04-04 15:41:25 +03:00
|
|
|
layout->addWidget(s);
|
|
|
|
|
|
|
|
x++;
|
|
|
|
if (x <= 3) {
|
|
|
|
minimumSize = newViewPort->sizeHint();
|
|
|
|
} else {
|
|
|
|
minimumSize.rwidth() = qMax(newViewPort->sizeHint().width(), minimumSize.width());
|
|
|
|
}
|
2015-11-16 19:59:24 +03:00
|
|
|
}
|
2017-04-04 15:41:25 +03:00
|
|
|
layout->addStretch(1);
|
2015-11-01 00:21:09 +03:00
|
|
|
}
|
2015-11-16 19:59:24 +03:00
|
|
|
|
|
|
|
minimumSize.rwidth() += layout->spacing();
|
|
|
|
minimumSize.rheight() += layout->spacing();
|
|
|
|
scrollArea->setMinimumSize(minimumSize);
|
|
|
|
scrollArea->setWidget(newViewPort);
|
2016-01-12 16:35:35 +03:00
|
|
|
|
|
|
|
_disableCompleterActivated = false;
|
2016-02-22 17:14:05 +03:00
|
|
|
_ui->shareeLineEdit->setEnabled(true);
|
2015-11-05 00:00:35 +03:00
|
|
|
}
|
|
|
|
|
2015-11-19 14:32:50 +03:00
|
|
|
void ShareUserGroupWidget::slotAdjustScrollWidgetSize()
|
|
|
|
{
|
|
|
|
QScrollArea *scrollArea = _ui->scrollArea;
|
2017-05-17 11:55:42 +03:00
|
|
|
if (scrollArea->findChildren<ShareUserLine *>().count() <= 3) {
|
2015-11-19 14:32:50 +03:00
|
|
|
auto minimumSize = scrollArea->widget()->sizeHint();
|
|
|
|
auto spacing = scrollArea->widget()->layout()->spacing();
|
|
|
|
minimumSize.rwidth() += spacing;
|
|
|
|
minimumSize.rheight() += spacing;
|
|
|
|
scrollArea->setMinimumSize(minimumSize);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-10 10:37:10 +03:00
|
|
|
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());
|
|
|
|
}
|
|
|
|
|
2015-11-16 16:18:01 +03:00
|
|
|
void ShareUserGroupWidget::slotShareesReady()
|
|
|
|
{
|
2016-04-29 15:11:27 +03:00
|
|
|
_pi_sharee.stopAnimation();
|
2016-01-12 16:35:35 +03:00
|
|
|
if (_completerModel->rowCount() == 0) {
|
|
|
|
displayError(0, tr("No results for '%1'").arg(_completerModel->currentSearch()));
|
|
|
|
return;
|
|
|
|
}
|
2015-11-16 16:18:01 +03:00
|
|
|
_completer->complete();
|
|
|
|
}
|
|
|
|
|
2017-05-17 11:55:42 +03:00
|
|
|
void ShareUserGroupWidget::slotCompleterActivated(const QModelIndex &index)
|
2015-11-09 19:21:42 +03:00
|
|
|
{
|
2016-01-12 16:35:35 +03:00
|
|
|
if (_disableCompleterActivated)
|
|
|
|
return;
|
2015-11-09 19:21:42 +03:00
|
|
|
// 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));
|
2015-11-05 00:00:35 +03:00
|
|
|
if (sharee.isNull()) {
|
|
|
|
return;
|
|
|
|
}
|
2015-11-01 00:21:09 +03:00
|
|
|
|
2016-03-08 22:54:14 +03:00
|
|
|
/*
|
|
|
|
* Add spinner to the bottom of the widget list
|
|
|
|
*/
|
|
|
|
auto viewPort = _ui->scrollArea->widget();
|
2017-05-17 11:55:42 +03:00
|
|
|
auto layout = qobject_cast<QVBoxLayout *>(viewPort->layout());
|
2016-03-08 22:54:14 +03:00
|
|
|
auto indicator = new QProgressIndicator(viewPort);
|
|
|
|
indicator->startAnimation();
|
2017-04-04 15:41:25 +03:00
|
|
|
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);
|
2016-03-08 22:54:14 +03:00
|
|
|
|
2016-02-22 13:44:13 +03:00
|
|
|
/*
|
2016-06-27 12:09:51 +03:00
|
|
|
* Don't send the reshare permissions for federated shares for servers <9.1
|
2016-02-22 13:44:13 +03:00
|
|
|
* https://github.com/owncloud/core/issues/22122#issuecomment-185637344
|
2016-06-27 12:09:51 +03:00
|
|
|
* https://github.com/owncloud/client/issues/4996
|
2016-02-22 13:44:13 +03:00
|
|
|
*/
|
2016-06-27 12:09:51 +03:00
|
|
|
if (sharee->type() == Sharee::Federated
|
2017-05-17 11:55:42 +03:00
|
|
|
&& _account->serverVersionInt() < Account::makeServerVersion(9, 1, 0)) {
|
2016-03-30 12:33:34 +03:00
|
|
|
int permissions = SharePermissionRead | SharePermissionUpdate;
|
2016-02-22 13:44:13 +03:00
|
|
|
if (!_isFile) {
|
2016-03-30 12:33:34 +03:00
|
|
|
permissions |= SharePermissionCreate | SharePermissionDelete;
|
2016-02-22 13:44:13 +03:00
|
|
|
}
|
|
|
|
_manager->createShare(_sharePath, Share::ShareType(sharee->type()),
|
2017-05-17 11:55:42 +03:00
|
|
|
sharee->shareWith(), SharePermission(permissions));
|
2016-02-22 13:44:13 +03:00
|
|
|
} else {
|
|
|
|
_manager->createShare(_sharePath, Share::ShareType(sharee->type()),
|
2017-05-17 11:55:42 +03:00
|
|
|
sharee->shareWith(), SharePermissionDefault);
|
2016-02-22 13:44:13 +03:00
|
|
|
}
|
2015-11-05 15:16:52 +03:00
|
|
|
|
2016-02-22 17:14:05 +03:00
|
|
|
_ui->shareeLineEdit->setEnabled(false);
|
2015-11-05 15:16:52 +03:00
|
|
|
_ui->shareeLineEdit->setText(QString());
|
2015-11-01 00:21:09 +03:00
|
|
|
}
|
|
|
|
|
2017-05-17 11:55:42 +03:00
|
|
|
void ShareUserGroupWidget::slotCompleterHighlighted(const QModelIndex &index)
|
2015-12-10 16:56:15 +03:00
|
|
|
{
|
|
|
|
// By default the completer would set the text to EditRole,
|
|
|
|
// override that here.
|
|
|
|
_ui->shareeLineEdit->setText(index.data(Qt::DisplayRole).toString());
|
|
|
|
}
|
|
|
|
|
2017-05-17 11:55:42 +03:00
|
|
|
void ShareUserGroupWidget::displayError(int code, const QString &message)
|
2016-01-12 15:19:33 +03:00
|
|
|
{
|
2016-04-29 15:11:27 +03:00
|
|
|
_pi_sharee.stopAnimation();
|
2017-04-11 16:50:32 +03:00
|
|
|
|
|
|
|
// Also remove the spinner in the widget list, if any
|
2017-05-17 11:55:42 +03:00
|
|
|
foreach (auto pi, _ui->scrollArea->findChildren<QProgressIndicator *>()) {
|
2017-04-11 16:50:32 +03:00
|
|
|
delete pi;
|
|
|
|
}
|
|
|
|
|
2017-03-30 14:46:20 +03:00
|
|
|
qCWarning(lcSharing) << "Sharing error from server" << code << message;
|
2016-01-12 15:19:33 +03:00
|
|
|
_ui->errorLabel->setText(message);
|
|
|
|
_ui->errorLabel->show();
|
2017-04-11 16:50:32 +03:00
|
|
|
_ui->shareeLineEdit->setEnabled(true);
|
2016-01-12 15:19:33 +03:00
|
|
|
}
|
|
|
|
|
2017-05-10 10:37:10 +03:00
|
|
|
void ShareUserGroupWidget::slotPrivateLinkOpenBrowser()
|
|
|
|
{
|
2017-09-15 15:24:34 +03:00
|
|
|
Utility::openBrowser(_privateLinkUrl, this);
|
2017-05-10 10:37:10 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void ShareUserGroupWidget::slotPrivateLinkCopy()
|
|
|
|
{
|
2017-09-15 15:24:34 +03:00
|
|
|
QApplication::clipboard()->setText(_privateLinkUrl);
|
2017-05-10 10:37:10 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void ShareUserGroupWidget::slotPrivateLinkEmail()
|
|
|
|
{
|
|
|
|
Utility::openEmailComposer(
|
|
|
|
tr("I shared something with you"),
|
2017-09-15 15:24:34 +03:00
|
|
|
_privateLinkUrl,
|
2017-05-10 10:37:10 +03:00
|
|
|
this);
|
|
|
|
}
|
|
|
|
|
2017-04-04 16:05:08 +03:00
|
|
|
ShareUserLine::ShareUserLine(QSharedPointer<Share> share,
|
2017-05-17 11:55:42 +03:00
|
|
|
SharePermissions maxSharingPermissions,
|
|
|
|
bool isFile,
|
|
|
|
QWidget *parent)
|
|
|
|
: QWidget(parent)
|
|
|
|
, _ui(new Ui::ShareUserLine)
|
|
|
|
, _share(share)
|
|
|
|
, _isFile(isFile)
|
2015-11-01 00:21:09 +03:00
|
|
|
{
|
|
|
|
_ui->setupUi(this);
|
|
|
|
|
2015-11-05 00:00:35 +03:00
|
|
|
_ui->sharedWith->setText(share->getShareWith()->format());
|
2017-05-17 11:55:42 +03:00
|
|
|
|
2015-11-25 13:26:21 +03:00
|
|
|
// Create detailed permissions menu
|
|
|
|
QMenu *menu = new QMenu(this);
|
|
|
|
_permissionCreate = new QAction(tr("create"), this);
|
|
|
|
_permissionCreate->setCheckable(true);
|
2016-03-30 12:33:34 +03:00
|
|
|
_permissionCreate->setEnabled(maxSharingPermissions & SharePermissionCreate);
|
2015-11-25 13:26:21 +03:00
|
|
|
_permissionUpdate = new QAction(tr("change"), this);
|
|
|
|
_permissionUpdate->setCheckable(true);
|
2016-03-30 12:33:34 +03:00
|
|
|
_permissionUpdate->setEnabled(maxSharingPermissions & SharePermissionUpdate);
|
2015-11-25 13:26:21 +03:00
|
|
|
_permissionDelete = new QAction(tr("delete"), this);
|
|
|
|
_permissionDelete->setCheckable(true);
|
2016-03-30 12:33:34 +03:00
|
|
|
_permissionDelete->setEnabled(maxSharingPermissions & SharePermissionDelete);
|
2015-11-30 17:47:10 +03:00
|
|
|
|
|
|
|
menu->addAction(_permissionUpdate);
|
|
|
|
/*
|
|
|
|
* Files can't have create or delete permissions
|
|
|
|
*/
|
2015-11-25 13:26:21 +03:00
|
|
|
if (!_isFile) {
|
2015-11-30 17:47:10 +03:00
|
|
|
menu->addAction(_permissionCreate);
|
2015-11-25 13:26:21 +03:00
|
|
|
menu->addAction(_permissionDelete);
|
|
|
|
}
|
|
|
|
_ui->permissionToolButton->setMenu(menu);
|
|
|
|
_ui->permissionToolButton->setPopupMode(QToolButton::InstantPopup);
|
2015-11-05 00:00:35 +03:00
|
|
|
|
2015-11-25 16:02:45 +03:00
|
|
|
QIcon icon(QLatin1String(":/client/resources/more.png"));
|
|
|
|
_ui->permissionToolButton->setIcon(icon);
|
2015-11-05 00:00:35 +03:00
|
|
|
|
2017-03-28 12:15:53 +03:00
|
|
|
// If there's only a single entry in the detailed permission menu, hide it
|
|
|
|
if (menu->actions().size() == 1) {
|
|
|
|
_ui->permissionToolButton->hide();
|
|
|
|
}
|
|
|
|
|
2015-11-13 12:27:26 +03:00
|
|
|
// Set the permissions checkboxes
|
|
|
|
displayPermissions();
|
|
|
|
|
2016-03-30 12:33:34 +03:00
|
|
|
_ui->permissionShare->setEnabled(maxSharingPermissions & SharePermissionShare);
|
|
|
|
_ui->permissionsEdit->setEnabled(maxSharingPermissions
|
2017-05-17 11:55:42 +03:00
|
|
|
& (SharePermissionCreate | SharePermissionUpdate | SharePermissionDelete));
|
2016-03-30 12:33:34 +03:00
|
|
|
|
2017-09-20 11:14:48 +03:00
|
|
|
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);
|
2015-11-01 00:21:09 +03:00
|
|
|
|
2016-02-22 13:44:13 +03:00
|
|
|
/*
|
2016-06-27 12:09:51 +03:00
|
|
|
* We don't show permssion share for federated shares with server <9.1
|
2016-02-22 13:44:13 +03:00
|
|
|
* https://github.com/owncloud/core/issues/22122#issuecomment-185637344
|
2016-06-27 12:09:51 +03:00
|
|
|
* https://github.com/owncloud/client/issues/4996
|
2016-02-22 13:44:13 +03:00
|
|
|
*/
|
2016-06-27 12:09:51 +03:00
|
|
|
if (share->getShareType() == Share::TypeRemote
|
2017-05-17 11:55:42 +03:00
|
|
|
&& share->account()->serverVersionInt() < Account::makeServerVersion(9, 1, 0)) {
|
2016-02-22 13:44:13 +03:00
|
|
|
_ui->permissionShare->setVisible(false);
|
|
|
|
_ui->permissionToolButton->setVisible(false);
|
|
|
|
}
|
|
|
|
|
2017-09-20 11:14:48 +03:00
|
|
|
connect(share.data(), &Share::permissionsSet, this, &ShareUserLine::slotPermissionsSet);
|
|
|
|
connect(share.data(), &Share::shareDeleted, this, &ShareUserLine::slotShareDeleted);
|
2015-11-17 12:40:45 +03:00
|
|
|
|
|
|
|
_ui->deleteShareButton->setIcon(QIcon::fromTheme(QLatin1String("user-trash"),
|
2017-05-17 11:55:42 +03:00
|
|
|
QIcon(QLatin1String(":/client/resources/delete.png"))));
|
2015-12-08 14:58:56 +03:00
|
|
|
|
|
|
|
if (!share->account()->capabilities().shareResharing()) {
|
|
|
|
_ui->permissionShare->hide();
|
|
|
|
}
|
2015-11-01 00:21:09 +03:00
|
|
|
}
|
|
|
|
|
2017-04-04 16:05:08 +03:00
|
|
|
void ShareUserLine::on_deleteShareButton_clicked()
|
2015-11-01 00:21:09 +03:00
|
|
|
{
|
|
|
|
setEnabled(false);
|
|
|
|
_share->deleteShare();
|
|
|
|
}
|
|
|
|
|
2017-04-04 16:05:08 +03:00
|
|
|
ShareUserLine::~ShareUserLine()
|
2015-11-01 00:21:09 +03:00
|
|
|
{
|
|
|
|
delete _ui;
|
|
|
|
}
|
|
|
|
|
2017-04-04 16:05:08 +03:00
|
|
|
void ShareUserLine::slotEditPermissionsChanged()
|
2015-11-13 12:27:26 +03:00
|
|
|
{
|
|
|
|
setEnabled(false);
|
|
|
|
|
2017-03-22 15:22:22 +03:00
|
|
|
// 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);
|
|
|
|
}
|
|
|
|
|
2016-03-30 12:33:34 +03:00
|
|
|
Share::Permissions permissions = SharePermissionRead;
|
2015-11-13 12:27:26 +03:00
|
|
|
|
|
|
|
if (_ui->permissionShare->checkState() == Qt::Checked) {
|
2016-03-30 12:33:34 +03:00
|
|
|
permissions |= SharePermissionShare;
|
2015-11-13 12:27:26 +03:00
|
|
|
}
|
2017-03-22 15:22:22 +03:00
|
|
|
|
2015-11-13 12:27:26 +03:00
|
|
|
if (_ui->permissionsEdit->checkState() == Qt::Checked) {
|
2016-03-30 12:33:34 +03:00
|
|
|
if (_permissionUpdate->isEnabled())
|
|
|
|
permissions |= SharePermissionUpdate;
|
2015-11-25 13:26:21 +03:00
|
|
|
|
2015-11-30 17:47:10 +03:00
|
|
|
/*
|
|
|
|
* Files can't have create or delete permisisons
|
|
|
|
*/
|
2015-11-25 13:26:21 +03:00
|
|
|
if (!_isFile) {
|
2016-03-30 12:33:34 +03:00
|
|
|
if (_permissionCreate->isEnabled())
|
|
|
|
permissions |= SharePermissionCreate;
|
|
|
|
if (_permissionDelete->isEnabled())
|
|
|
|
permissions |= SharePermissionDelete;
|
2015-11-25 13:26:21 +03:00
|
|
|
}
|
2015-11-13 12:27:26 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
_share->setPermissions(permissions);
|
|
|
|
}
|
|
|
|
|
2017-04-04 16:05:08 +03:00
|
|
|
void ShareUserLine::slotPermissionsChanged()
|
2015-11-01 00:21:09 +03:00
|
|
|
{
|
|
|
|
setEnabled(false);
|
2017-05-17 11:55:42 +03:00
|
|
|
|
2016-03-30 12:33:34 +03:00
|
|
|
Share::Permissions permissions = SharePermissionRead;
|
2015-11-01 00:21:09 +03:00
|
|
|
|
2015-11-25 13:26:21 +03:00
|
|
|
if (_permissionUpdate->isChecked()) {
|
2016-03-30 12:33:34 +03:00
|
|
|
permissions |= SharePermissionUpdate;
|
2015-11-01 00:21:09 +03:00
|
|
|
}
|
|
|
|
|
2015-11-25 13:26:21 +03:00
|
|
|
if (_permissionCreate->isChecked()) {
|
2016-03-30 12:33:34 +03:00
|
|
|
permissions |= SharePermissionCreate;
|
2015-11-01 00:21:09 +03:00
|
|
|
}
|
|
|
|
|
2015-11-25 13:26:21 +03:00
|
|
|
if (_permissionDelete->isChecked()) {
|
2016-03-30 12:33:34 +03:00
|
|
|
permissions |= SharePermissionDelete;
|
2015-11-01 00:21:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (_ui->permissionShare->checkState() == Qt::Checked) {
|
2016-03-30 12:33:34 +03:00
|
|
|
permissions |= SharePermissionShare;
|
2015-11-01 00:21:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
_share->setPermissions(permissions);
|
|
|
|
}
|
|
|
|
|
2017-04-04 16:05:08 +03:00
|
|
|
void ShareUserLine::slotDeleteAnimationFinished()
|
2015-11-01 00:21:09 +03:00
|
|
|
{
|
2017-04-04 15:41:25 +03:00
|
|
|
emit resizeRequested();
|
|
|
|
emit visualDeletionDone();
|
2015-11-01 00:21:09 +03:00
|
|
|
deleteLater();
|
2015-11-25 12:09:17 +03:00
|
|
|
|
|
|
|
// 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
|
2017-05-17 11:55:42 +03:00
|
|
|
connect(this, SIGNAL(destroyed(QObject *)), parentWidget(), SLOT(repaint()));
|
2015-11-01 00:21:09 +03:00
|
|
|
}
|
|
|
|
|
2017-04-04 16:05:08 +03:00
|
|
|
void ShareUserLine::slotShareDeleted()
|
2015-11-13 13:03:51 +03:00
|
|
|
{
|
|
|
|
QPropertyAnimation *animation = new QPropertyAnimation(this, "maximumHeight", this);
|
|
|
|
|
|
|
|
animation->setDuration(500);
|
|
|
|
animation->setStartValue(height());
|
|
|
|
animation->setEndValue(0);
|
|
|
|
|
2017-09-20 11:14:48 +03:00
|
|
|
connect(animation, &QAbstractAnimation::finished, this, &ShareUserLine::slotDeleteAnimationFinished);
|
|
|
|
connect(animation, &QVariantAnimation::valueChanged, this, &ShareUserLine::resizeRequested);
|
2015-11-13 13:03:51 +03:00
|
|
|
|
|
|
|
animation->start();
|
|
|
|
}
|
|
|
|
|
2017-04-04 16:05:08 +03:00
|
|
|
void ShareUserLine::slotPermissionsSet()
|
2015-11-01 00:21:09 +03:00
|
|
|
{
|
2015-11-13 12:27:26 +03:00
|
|
|
displayPermissions();
|
2015-11-01 00:21:09 +03:00
|
|
|
setEnabled(true);
|
|
|
|
}
|
|
|
|
|
2017-04-04 16:05:08 +03:00
|
|
|
QSharedPointer<Share> ShareUserLine::share() const
|
2015-11-05 17:01:29 +03:00
|
|
|
{
|
|
|
|
return _share;
|
|
|
|
}
|
|
|
|
|
2017-04-04 16:05:08 +03:00
|
|
|
void ShareUserLine::displayPermissions()
|
2015-11-13 12:27:26 +03:00
|
|
|
{
|
2017-03-22 15:22:22 +03:00
|
|
|
auto perm = _share->getPermissions();
|
|
|
|
|
|
|
|
_permissionUpdate->setChecked(false);
|
2015-11-25 13:26:21 +03:00
|
|
|
_permissionCreate->setChecked(false);
|
|
|
|
_permissionDelete->setChecked(false);
|
2017-03-22 15:22:22 +03:00
|
|
|
if (perm & SharePermissionUpdate) {
|
2015-11-25 13:26:21 +03:00
|
|
|
_permissionUpdate->setChecked(true);
|
2015-11-13 12:27:26 +03:00
|
|
|
}
|
2017-03-22 15:22:22 +03:00
|
|
|
if (!_isFile && perm & SharePermissionCreate) {
|
2015-11-25 13:26:21 +03:00
|
|
|
_permissionCreate->setChecked(true);
|
2015-11-13 12:27:26 +03:00
|
|
|
}
|
2017-03-22 15:22:22 +03:00
|
|
|
if (!_isFile && perm & SharePermissionDelete) {
|
2015-11-25 13:26:21 +03:00
|
|
|
_permissionDelete->setChecked(true);
|
2017-03-22 15:22:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (perm & SharePermissionUpdate
|
2017-05-17 11:55:42 +03:00
|
|
|
&& (_isFile
|
|
|
|
|| (perm & SharePermissionCreate
|
|
|
|
&& perm & SharePermissionDelete))) {
|
2015-11-13 12:27:26 +03:00
|
|
|
_ui->permissionsEdit->setCheckState(Qt::Checked);
|
2017-03-22 15:22:22 +03:00
|
|
|
} else if (perm & (SharePermissionUpdate | SharePermissionCreate | SharePermissionDelete)) {
|
|
|
|
_ui->permissionsEdit->setCheckState(Qt::PartiallyChecked);
|
|
|
|
} else {
|
|
|
|
_ui->permissionsEdit->setCheckState(Qt::Unchecked);
|
2015-11-13 12:27:26 +03:00
|
|
|
}
|
2017-03-22 15:22:22 +03:00
|
|
|
|
|
|
|
_ui->permissionShare->setCheckState(Qt::Unchecked);
|
2016-03-30 12:33:34 +03:00
|
|
|
if (_share->getPermissions() & SharePermissionShare) {
|
2015-11-13 12:27:26 +03:00
|
|
|
_ui->permissionShare->setCheckState(Qt::Checked);
|
|
|
|
}
|
|
|
|
}
|
2015-11-01 00:21:09 +03:00
|
|
|
}
|