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-25 13:26:21 +03:00
|
|
|
#include <QMenu>
|
|
|
|
#include <QAction>
|
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),
|
2016-01-12 16:35:35 +03:00
|
|
|
_resharingAllowed(resharingAllowed),
|
|
|
|
_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,
|
|
|
|
_isFile ? QLatin1String("file") : QLatin1String("folder"),
|
|
|
|
_completer);
|
|
|
|
connect(_completerModel, SIGNAL(shareesReady()), this, SLOT(slotShareesReady()));
|
2016-01-12 16:35:35 +03:00
|
|
|
connect(_completerModel, SIGNAL(displayErrorMessage(int,QString)), this, SLOT(displayError(int,QString)));
|
2015-11-16 16:18:01 +03:00
|
|
|
|
|
|
|
_completer->setModel(_completerModel);
|
2015-12-10 16:56:15 +03:00
|
|
|
_completer->setCaseSensitivity(Qt::CaseInsensitive);
|
2015-11-24 11:07:13 +03:00
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(5, 2, 0)
|
|
|
|
_completer->setFilterMode(Qt::MatchContains);
|
|
|
|
#endif
|
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);
|
|
|
|
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()));
|
2016-01-12 15:19:33 +03:00
|
|
|
connect(_manager, SIGNAL(serverError(int,QString)), this, SLOT(displayError(int,QString)));
|
2015-12-10 15:49:47 +03:00
|
|
|
connect(_ui->shareeLineEdit, SIGNAL(returnPressed()), SLOT(slotLineEditReturn()));
|
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)),
|
|
|
|
Qt::QueuedConnection);
|
|
|
|
connect(_completer, SIGNAL(highlighted(QModelIndex)), SLOT(slotCompleterHighlighted(QModelIndex)),
|
|
|
|
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
|
|
|
|
connect(_ui->shareeLineEdit, SIGNAL(textEdited(QString)),
|
|
|
|
this, SLOT(slotLineEditTextEdited(QString)), Qt::QueuedConnection);
|
2015-11-17 12:24:35 +03:00
|
|
|
connect(&_completionTimer, SIGNAL(timeout()), this, SLOT(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();
|
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
|
|
|
}
|
|
|
|
|
2015-11-16 16:18:01 +03:00
|
|
|
void ShareUserGroupWidget::slotLineEditTextEdited(const QString& text)
|
|
|
|
{
|
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
|
|
|
|
|| 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();
|
|
|
|
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
|
|
|
}
|
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-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-25 13:26:21 +03:00
|
|
|
ShareWidget *s = new ShareWidget(share, _isFile, _ui->scrollArea);
|
2015-11-19 14:32:50 +03:00
|
|
|
connect(s, SIGNAL(resizeRequested()), this, SLOT(slotAdjustScrollWidgetSize()));
|
2015-11-16 19:59:24 +03:00
|
|
|
layout->addWidget(s);
|
|
|
|
|
|
|
|
x++;
|
|
|
|
if (x <= 3) {
|
|
|
|
minimumSize = newViewPort->sizeHint();
|
2015-11-19 14:32:50 +03:00
|
|
|
} else {
|
|
|
|
minimumSize.rwidth() = qMax(newViewPort->sizeHint().width(), minimumSize.width());
|
2015-11-16 19:59:24 +03:00
|
|
|
}
|
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);
|
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;
|
|
|
|
if (scrollArea->findChildren<ShareWidget*>().count() <= 3) {
|
|
|
|
auto minimumSize = scrollArea->widget()->sizeHint();
|
|
|
|
auto spacing = scrollArea->widget()->layout()->spacing();
|
|
|
|
minimumSize.rwidth() += spacing;
|
|
|
|
minimumSize.rheight() += spacing;
|
|
|
|
scrollArea->setMinimumSize(minimumSize);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-16 16:18:01 +03:00
|
|
|
void ShareUserGroupWidget::slotShareesReady()
|
|
|
|
{
|
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();
|
|
|
|
}
|
|
|
|
|
2015-11-09 19:21:42 +03:00
|
|
|
void ShareUserGroupWidget::slotCompleterActivated(const QModelIndex & index)
|
|
|
|
{
|
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
|
|
|
|
2015-11-19 12:38:51 +03:00
|
|
|
_manager->createShare(_sharePath, Share::ShareType(sharee->type()),
|
|
|
|
sharee->shareWith(), Share::PermissionDefault);
|
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
|
|
|
}
|
|
|
|
|
2015-12-10 16:56:15 +03:00
|
|
|
void ShareUserGroupWidget::slotCompleterHighlighted(const QModelIndex & index)
|
|
|
|
{
|
|
|
|
// By default the completer would set the text to EditRole,
|
|
|
|
// override that here.
|
|
|
|
_ui->shareeLineEdit->setText(index.data(Qt::DisplayRole).toString());
|
|
|
|
}
|
|
|
|
|
2016-01-12 15:19:33 +03:00
|
|
|
void ShareUserGroupWidget::displayError(int code, const QString& message)
|
|
|
|
{
|
|
|
|
qDebug() << "Error from server" << code << message;
|
|
|
|
_ui->errorLabel->setText(message);
|
|
|
|
_ui->errorLabel->show();
|
|
|
|
}
|
|
|
|
|
2015-11-05 11:58:16 +03:00
|
|
|
ShareWidget::ShareWidget(QSharedPointer<Share> share,
|
2015-11-25 13:26:21 +03:00
|
|
|
bool isFile,
|
|
|
|
QWidget *parent) :
|
2015-11-01 00:21:09 +03:00
|
|
|
QWidget(parent),
|
2015-11-05 11:58:16 +03:00
|
|
|
_ui(new Ui::ShareWidget),
|
2015-11-13 12:27:26 +03:00
|
|
|
_share(share),
|
2015-11-25 13:26:21 +03:00
|
|
|
_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());
|
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);
|
|
|
|
_permissionUpdate = new QAction(tr("change"), this);
|
|
|
|
_permissionUpdate->setCheckable(true);
|
|
|
|
_permissionDelete = new QAction(tr("delete"), this);
|
|
|
|
_permissionDelete->setCheckable(true);
|
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
|
|
|
|
2015-11-13 12:27:26 +03:00
|
|
|
// Set the permissions checkboxes
|
|
|
|
displayPermissions();
|
|
|
|
|
2015-11-25 13:26:21 +03:00
|
|
|
connect(_permissionUpdate, SIGNAL(triggered(bool)), SLOT(slotPermissionsChanged()));
|
|
|
|
connect(_permissionCreate, SIGNAL(triggered(bool)), SLOT(slotPermissionsChanged()));
|
|
|
|
connect(_permissionDelete, SIGNAL(triggered(bool)), SLOT(slotPermissionsChanged()));
|
2015-11-01 00:21:09 +03:00
|
|
|
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-17 12:40:45 +03:00
|
|
|
|
|
|
|
_ui->deleteShareButton->setIcon(QIcon::fromTheme(QLatin1String("user-trash"),
|
|
|
|
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
|
|
|
}
|
|
|
|
|
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-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) {
|
2015-11-25 13:26:21 +03:00
|
|
|
permissions |= Share::PermissionShare;
|
2015-11-13 12:27:26 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (_ui->permissionsEdit->checkState() == Qt::Checked) {
|
|
|
|
permissions |= Share::PermissionUpdate;
|
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) {
|
2015-11-30 17:47:10 +03:00
|
|
|
permissions |= Share::PermissionCreate;
|
2015-11-25 13:26:21 +03:00
|
|
|
permissions |= Share::PermissionDelete;
|
|
|
|
}
|
2015-11-13 12:27:26 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
_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;
|
|
|
|
|
2015-11-25 13:26:21 +03:00
|
|
|
if (_permissionUpdate->isChecked()) {
|
2015-11-01 00:21:09 +03:00
|
|
|
permissions |= Share::PermissionUpdate;
|
|
|
|
}
|
|
|
|
|
2015-11-25 13:26:21 +03:00
|
|
|
if (_permissionCreate->isChecked()) {
|
2015-11-01 00:21:09 +03:00
|
|
|
permissions |= Share::PermissionCreate;
|
|
|
|
}
|
|
|
|
|
2015-11-25 13:26:21 +03:00
|
|
|
if (_permissionDelete->isChecked()) {
|
2015-11-01 00:21:09 +03:00
|
|
|
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
|
|
|
{
|
2015-11-19 14:32:50 +03:00
|
|
|
resizeRequested();
|
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
|
|
|
|
connect(this, SIGNAL(destroyed(QObject*)), parentWidget(), SLOT(repaint()));
|
2015-11-01 00:21:09 +03:00
|
|
|
}
|
|
|
|
|
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()));
|
2015-11-19 14:32:50 +03:00
|
|
|
connect(animation, SIGNAL(valueChanged(QVariant)), this, SIGNAL(resizeRequested()));
|
2015-11-13 13:03:51 +03:00
|
|
|
|
|
|
|
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()
|
|
|
|
{
|
2015-11-25 13:26:21 +03:00
|
|
|
_permissionCreate->setChecked(false);
|
2015-11-13 12:27:26 +03:00
|
|
|
_ui->permissionsEdit->setCheckState(Qt::Unchecked);
|
2015-11-25 13:26:21 +03:00
|
|
|
_permissionDelete->setChecked(false);
|
2015-11-13 12:27:26 +03:00
|
|
|
_ui->permissionShare->setCheckState(Qt::Unchecked);
|
2015-11-25 13:26:21 +03:00
|
|
|
_permissionUpdate->setChecked(false);
|
2015-11-13 12:27:26 +03:00
|
|
|
|
|
|
|
if (_share->getPermissions() & Share::PermissionUpdate) {
|
2015-11-25 13:26:21 +03:00
|
|
|
_permissionUpdate->setChecked(true);
|
2015-11-13 12:27:26 +03:00
|
|
|
_ui->permissionsEdit->setCheckState(Qt::Checked);
|
|
|
|
}
|
2015-11-30 17:47:10 +03:00
|
|
|
if (!_isFile && _share->getPermissions() & Share::PermissionCreate) {
|
2015-11-25 13:26:21 +03:00
|
|
|
_permissionCreate->setChecked(true);
|
2015-11-13 12:27:26 +03:00
|
|
|
_ui->permissionsEdit->setCheckState(Qt::Checked);
|
|
|
|
}
|
2015-11-25 13:26:21 +03:00
|
|
|
if (!_isFile && _share->getPermissions() & Share::PermissionDelete) {
|
|
|
|
_permissionDelete->setChecked(true);
|
2015-11-13 12:27:26 +03:00
|
|
|
_ui->permissionsEdit->setCheckState(Qt::Checked);
|
|
|
|
}
|
|
|
|
if (_share->getPermissions() & Share::PermissionShare) {
|
|
|
|
_ui->permissionShare->setCheckState(Qt::Checked);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-01 00:21:09 +03:00
|
|
|
}
|