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
|
|
|
|
* the Free Software Foundation; version 2 of the License.
|
|
|
|
*
|
|
|
|
* 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"
|
|
|
|
#include "ui_sharewidget.h"
|
2015-11-01 00:21:09 +03:00
|
|
|
#include "account.h"
|
|
|
|
#include "json.h"
|
|
|
|
#include "folderman.h"
|
|
|
|
#include "folder.h"
|
|
|
|
#include "accountmanager.h"
|
|
|
|
#include "theme.h"
|
|
|
|
#include "configfile.h"
|
|
|
|
#include "capabilities.h"
|
|
|
|
|
|
|
|
#include "thumbnailjob.h"
|
|
|
|
#include "share.h"
|
2015-11-02 00:23:22 +03:00
|
|
|
#include "sharee.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-01 00:21:09 +03:00
|
|
|
|
|
|
|
namespace OCC {
|
|
|
|
|
2015-11-05 11:58:16 +03:00
|
|
|
ShareUserGroupWidget::ShareUserGroupWidget(AccountPtr account, const QString &sharePath, const QString &localPath, bool resharingAllowed, QWidget *parent) :
|
|
|
|
QWidget(parent),
|
|
|
|
_ui(new Ui::ShareUserGroupWidget),
|
2015-11-01 00:21:09 +03:00
|
|
|
_account(account),
|
|
|
|
_sharePath(sharePath),
|
|
|
|
_localPath(localPath),
|
|
|
|
_resharingAllowed(resharingAllowed)
|
|
|
|
{
|
|
|
|
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,
|
|
|
|
_isFile ? QLatin1String("file") : QLatin1String("folder"),
|
|
|
|
_completer);
|
|
|
|
connect(_completerModel, SIGNAL(shareesReady()), this, SLOT(slotShareesReady()));
|
|
|
|
|
|
|
|
_completer->setModel(_completerModel);
|
2015-11-05 00:00:35 +03:00
|
|
|
_ui->shareeLineEdit->setCompleter(_completer);
|
|
|
|
|
2015-11-02 00:23:22 +03:00
|
|
|
_ui->searchPushButton->setEnabled(false);
|
|
|
|
|
2015-11-01 00:21:09 +03:00
|
|
|
_manager = new ShareManager(_account, this);
|
|
|
|
connect(_manager, SIGNAL(sharesFetched(QList<QSharedPointer<Share>>)), SLOT(slotSharesFetched(QList<QSharedPointer<Share>>)));
|
2015-11-02 00:23:22 +03:00
|
|
|
connect(_manager, SIGNAL(shareCreated(QSharedPointer<Share>)), SLOT(getShares()));
|
2015-11-09 17:58:50 +03:00
|
|
|
// connect(_ui->shareeLineEdit, SIGNAL(returnPressed()), SLOT(on_searchPushButton_clicked()));
|
2015-11-05 00:00:35 +03:00
|
|
|
connect(_completer, SIGNAL(activated(QModelIndex)), SLOT(slotCompleterActivated(QModelIndex)));
|
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
|
|
|
|
connect(_ui->shareeLineEdit, SIGNAL(textEdited(QString)),
|
|
|
|
this, SLOT(slotLineEditTextEdited(QString)), Qt::QueuedConnection);
|
|
|
|
connect(&_completionTimer, SIGNAL(timeout()), this, SLOT(on_searchPushButton_clicked()));
|
|
|
|
_completionTimer.setSingleShot(true);
|
|
|
|
_completionTimer.setInterval(600);
|
2015-11-16 19:59:24 +03:00
|
|
|
|
|
|
|
setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Expanding);
|
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-05 11:58:16 +03:00
|
|
|
void ShareUserGroupWidget::on_shareeLineEdit_textChanged(const QString &text)
|
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
|
|
|
if (text == "") {
|
|
|
|
_ui->searchPushButton->setEnabled(false);
|
|
|
|
} else {
|
|
|
|
_ui->searchPushButton->setEnabled(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-16 16:18:01 +03:00
|
|
|
void ShareUserGroupWidget::slotLineEditTextEdited(const QString& text)
|
|
|
|
{
|
|
|
|
// 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-11-05 11:58:16 +03:00
|
|
|
void ShareUserGroupWidget::on_searchPushButton_clicked()
|
2015-11-02 00:23:22 +03:00
|
|
|
{
|
2015-11-16 16:18:01 +03:00
|
|
|
_completionTimer.stop();
|
|
|
|
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
|
|
|
|
2015-11-16 19:59:24 +03:00
|
|
|
foreach (auto sw, _ui->scrollArea->findChildren<ShareWidget*>()) {
|
|
|
|
blacklist << sw->share()->getShareWith();
|
2015-11-05 17:01:29 +03:00
|
|
|
}
|
|
|
|
|
2015-11-16 16:18:01 +03:00
|
|
|
_completerModel->fetch(_ui->shareeLineEdit->text(), blacklist);
|
2015-11-05 17:01:29 +03:00
|
|
|
|
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
|
|
|
|
|
|
|
foreach(const auto &share, shares) {
|
2015-11-05 17:01:29 +03:00
|
|
|
// We don't handle link shares
|
2015-11-01 00:21:09 +03:00
|
|
|
if (share->getShareType() == Share::TypeLink) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2015-11-16 19:59:24 +03:00
|
|
|
ShareWidget *s = new ShareWidget(share, _ui->scrollArea);
|
|
|
|
layout->addWidget(s);
|
|
|
|
|
|
|
|
x++;
|
|
|
|
if (x <= 3) {
|
|
|
|
minimumSize = newViewPort->sizeHint();
|
|
|
|
}
|
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->setVisible(!shares.isEmpty());
|
|
|
|
scrollArea->setWidget(newViewPort);
|
2015-11-05 00:00:35 +03:00
|
|
|
}
|
|
|
|
|
2015-11-16 16:18:01 +03:00
|
|
|
void ShareUserGroupWidget::slotShareesReady()
|
|
|
|
{
|
|
|
|
_completer->complete();
|
|
|
|
}
|
|
|
|
|
2015-11-09 19:21:42 +03:00
|
|
|
void ShareUserGroupWidget::slotCompleterActivated(const QModelIndex & index)
|
|
|
|
{
|
|
|
|
// 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
|
|
|
|
2015-11-16 16:18:01 +03:00
|
|
|
_manager->createShare(_sharePath,
|
2015-11-05 00:00:35 +03:00
|
|
|
(Share::ShareType)sharee->type(),
|
|
|
|
sharee->shareWith(),
|
|
|
|
Share::PermissionRead);
|
2015-11-05 15:16:52 +03:00
|
|
|
|
|
|
|
_ui->shareeLineEdit->setText(QString());
|
2015-11-01 00:21:09 +03:00
|
|
|
}
|
|
|
|
|
2015-11-05 11:58:16 +03:00
|
|
|
ShareWidget::ShareWidget(QSharedPointer<Share> share,
|
2015-11-01 00:21:09 +03:00
|
|
|
QWidget *parent) :
|
|
|
|
QWidget(parent),
|
2015-11-05 11:58:16 +03:00
|
|
|
_ui(new Ui::ShareWidget),
|
2015-11-13 12:27:26 +03:00
|
|
|
_share(share),
|
|
|
|
_showDetailedPermissions(false)
|
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());
|
|
|
|
|
2015-11-13 12:27:26 +03:00
|
|
|
// Set the permissions checkboxes
|
|
|
|
displayPermissions();
|
|
|
|
|
|
|
|
// Hide "detailed permissions" by default
|
|
|
|
_ui->permissionDelete->setHidden(true);
|
|
|
|
_ui->permissionUpdate->setHidden(true);
|
|
|
|
_ui->permissionCreate->setHidden(true);
|
2015-11-01 00:21:09 +03:00
|
|
|
|
|
|
|
connect(_ui->permissionUpdate, SIGNAL(clicked(bool)), SLOT(slotPermissionsChanged()));
|
|
|
|
connect(_ui->permissionCreate, SIGNAL(clicked(bool)), SLOT(slotPermissionsChanged()));
|
|
|
|
connect(_ui->permissionDelete, SIGNAL(clicked(bool)), SLOT(slotPermissionsChanged()));
|
|
|
|
connect(_ui->permissionShare, SIGNAL(clicked(bool)), SLOT(slotPermissionsChanged()));
|
2015-11-13 12:27:26 +03:00
|
|
|
connect(_ui->permissionsEdit, SIGNAL(clicked(bool)), SLOT(slotEditPermissionsChanged()));
|
2015-11-01 00:21:09 +03:00
|
|
|
|
|
|
|
connect(share.data(), SIGNAL(permissionsSet()), SLOT(slotPermissionsSet()));
|
|
|
|
connect(share.data(), SIGNAL(shareDeleted()), SLOT(slotShareDeleted()));
|
|
|
|
}
|
|
|
|
|
2015-11-05 11:58:16 +03:00
|
|
|
void ShareWidget::on_deleteShareButton_clicked()
|
2015-11-01 00:21:09 +03:00
|
|
|
{
|
|
|
|
setEnabled(false);
|
|
|
|
_share->deleteShare();
|
|
|
|
}
|
|
|
|
|
2015-11-13 12:27:26 +03:00
|
|
|
void ShareWidget::on_permissionToggleButton_clicked()
|
|
|
|
{
|
|
|
|
_showDetailedPermissions = !_showDetailedPermissions;
|
|
|
|
_ui->permissionDelete->setVisible(_showDetailedPermissions);
|
|
|
|
_ui->permissionUpdate->setVisible(_showDetailedPermissions);
|
|
|
|
_ui->permissionCreate->setVisible(_showDetailedPermissions);
|
|
|
|
|
|
|
|
if (_showDetailedPermissions) {
|
|
|
|
_ui->permissionToggleButton->setText("Hide");
|
|
|
|
} else {
|
|
|
|
_ui->permissionToggleButton->setText("More");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-05 11:58:16 +03:00
|
|
|
ShareWidget::~ShareWidget()
|
2015-11-01 00:21:09 +03:00
|
|
|
{
|
|
|
|
delete _ui;
|
|
|
|
}
|
|
|
|
|
2015-11-13 12:27:26 +03:00
|
|
|
void ShareWidget::slotEditPermissionsChanged()
|
|
|
|
{
|
|
|
|
setEnabled(false);
|
|
|
|
|
|
|
|
Share::Permissions permissions = Share::PermissionRead;
|
|
|
|
|
|
|
|
if (_ui->permissionShare->checkState() == Qt::Checked) {
|
|
|
|
permissions |= Share::PermissionUpdate;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_ui->permissionsEdit->checkState() == Qt::Checked) {
|
|
|
|
permissions |= Share::PermissionCreate;
|
|
|
|
permissions |= Share::PermissionUpdate;
|
|
|
|
permissions |= Share::PermissionDelete;
|
|
|
|
}
|
|
|
|
|
|
|
|
_share->setPermissions(permissions);
|
|
|
|
}
|
|
|
|
|
2015-11-05 11:58:16 +03:00
|
|
|
void ShareWidget::slotPermissionsChanged()
|
2015-11-01 00:21:09 +03:00
|
|
|
{
|
|
|
|
setEnabled(false);
|
|
|
|
|
|
|
|
Share::Permissions permissions = Share::PermissionRead;
|
|
|
|
|
|
|
|
if (_ui->permissionUpdate->checkState() == Qt::Checked) {
|
|
|
|
permissions |= Share::PermissionUpdate;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_ui->permissionCreate->checkState() == Qt::Checked) {
|
|
|
|
permissions |= Share::PermissionCreate;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_ui->permissionDelete->checkState() == Qt::Checked) {
|
|
|
|
permissions |= Share::PermissionDelete;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_ui->permissionShare->checkState() == Qt::Checked) {
|
|
|
|
permissions |= Share::PermissionShare;
|
|
|
|
}
|
|
|
|
|
|
|
|
_share->setPermissions(permissions);
|
|
|
|
}
|
|
|
|
|
2015-11-13 13:03:51 +03:00
|
|
|
void ShareWidget::slotDeleteAnimationFinished()
|
2015-11-01 00:21:09 +03:00
|
|
|
{
|
|
|
|
deleteLater();
|
|
|
|
}
|
|
|
|
|
2015-11-13 13:03:51 +03:00
|
|
|
void ShareWidget::slotShareDeleted()
|
|
|
|
{
|
|
|
|
QPropertyAnimation *animation = new QPropertyAnimation(this, "maximumHeight", this);
|
|
|
|
|
|
|
|
animation->setDuration(500);
|
|
|
|
animation->setStartValue(height());
|
|
|
|
animation->setEndValue(0);
|
|
|
|
|
|
|
|
connect(animation, SIGNAL(finished()), SLOT(slotDeleteAnimationFinished()));
|
|
|
|
|
|
|
|
animation->start();
|
|
|
|
}
|
|
|
|
|
2015-11-05 11:58:16 +03:00
|
|
|
void ShareWidget::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);
|
|
|
|
}
|
|
|
|
|
2015-11-05 17:01:29 +03:00
|
|
|
QSharedPointer<Share> ShareWidget::share() const
|
|
|
|
{
|
|
|
|
return _share;
|
|
|
|
}
|
|
|
|
|
2015-11-13 12:27:26 +03:00
|
|
|
void ShareWidget::displayPermissions()
|
|
|
|
{
|
|
|
|
_ui->permissionCreate->setCheckState(Qt::Unchecked);
|
|
|
|
_ui->permissionsEdit->setCheckState(Qt::Unchecked);
|
|
|
|
_ui->permissionDelete->setCheckState(Qt::Unchecked);
|
|
|
|
_ui->permissionShare->setCheckState(Qt::Unchecked);
|
|
|
|
_ui->permissionUpdate->setCheckState(Qt::Unchecked);
|
|
|
|
|
|
|
|
if (_share->getPermissions() & Share::PermissionUpdate) {
|
|
|
|
_ui->permissionUpdate->setCheckState(Qt::Checked);
|
|
|
|
_ui->permissionsEdit->setCheckState(Qt::Checked);
|
|
|
|
}
|
|
|
|
if (_share->getPermissions() & Share::PermissionCreate) {
|
|
|
|
_ui->permissionCreate->setCheckState(Qt::Checked);
|
|
|
|
_ui->permissionsEdit->setCheckState(Qt::Checked);
|
|
|
|
}
|
|
|
|
if (_share->getPermissions() & Share::PermissionDelete) {
|
|
|
|
_ui->permissionDelete->setCheckState(Qt::Checked);
|
|
|
|
_ui->permissionsEdit->setCheckState(Qt::Checked);
|
|
|
|
}
|
|
|
|
if (_share->getPermissions() & Share::PermissionShare) {
|
|
|
|
_ui->permissionShare->setCheckState(Qt::Checked);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-01 00:21:09 +03:00
|
|
|
}
|