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-02 00:23:22 +03:00
|
|
|
#include <QCompleter>
|
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);
|
|
|
|
_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-05 00:00:35 +03:00
|
|
|
connect(_ui->shareeLineEdit, SIGNAL(returnPressed()), SLOT(on_searchPushButton_clicked()));
|
|
|
|
connect(_completer, SIGNAL(activated(QModelIndex)), SLOT(slotCompleterActivated(QModelIndex)));
|
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
|
|
|
{
|
|
|
|
if (text == "") {
|
|
|
|
_ui->searchPushButton->setEnabled(false);
|
|
|
|
} else {
|
|
|
|
_ui->searchPushButton->setEnabled(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-05 11:58:16 +03:00
|
|
|
void ShareUserGroupWidget::on_searchPushButton_clicked()
|
2015-11-02 00:23:22 +03:00
|
|
|
{
|
2015-11-05 00:00:35 +03:00
|
|
|
_completerModel = new ShareeModel(_account,
|
|
|
|
_ui->shareeLineEdit->text(),
|
|
|
|
_isFile ? QLatin1String("file") : QLatin1String("folder"),
|
2015-11-05 14:30:34 +03:00
|
|
|
_sharees,
|
2015-11-05 00:00:35 +03:00
|
|
|
_completer);
|
|
|
|
connect(_completerModel, SIGNAL(shareesReady()), SLOT(slotUpdateCompletion()));
|
|
|
|
_completerModel->fetch();
|
2015-11-02 00:23:22 +03:00
|
|
|
}
|
|
|
|
|
2015-11-05 11:58:16 +03:00
|
|
|
void ShareUserGroupWidget::slotUpdateCompletion() {
|
2015-11-05 00:00:35 +03:00
|
|
|
_completer->setModel(_completerModel);
|
|
|
|
_ui->shareeLineEdit->setCompleter(_completer);
|
|
|
|
_completer->complete();
|
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
|
|
|
{
|
|
|
|
const QString versionString = _account->serverVersion();
|
|
|
|
qDebug() << Q_FUNC_INFO << versionString << "Fetched" << shares.count() << "shares";
|
|
|
|
|
2015-11-05 14:30:34 +03:00
|
|
|
//FIXME
|
2015-11-05 00:00:35 +03:00
|
|
|
QLayoutItem *child;
|
|
|
|
while ((child = _ui->sharesLayout->takeAt(0)) != 0) {
|
2015-11-05 15:10:32 +03:00
|
|
|
delete child->widget();
|
2015-11-05 00:00:35 +03:00
|
|
|
}
|
2015-11-01 00:21:09 +03:00
|
|
|
|
2015-11-05 14:30:34 +03:00
|
|
|
_sharees.clear();
|
|
|
|
|
2015-11-01 00:21:09 +03:00
|
|
|
foreach(const auto &share, shares) {
|
|
|
|
|
|
|
|
if (share->getShareType() == Share::TypeLink) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2015-11-05 11:58:16 +03:00
|
|
|
ShareWidget *s = new ShareWidget(share, this);
|
2015-11-01 00:21:09 +03:00
|
|
|
_ui->sharesLayout->addWidget(s);
|
2015-11-05 14:30:34 +03:00
|
|
|
|
|
|
|
_sharees.append(share->getShareWith());
|
2015-11-01 00:21:09 +03:00
|
|
|
}
|
2015-11-05 14:30:34 +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));
|
|
|
|
_sharees.append(currentUser);
|
|
|
|
|
2015-11-05 00:00:35 +03:00
|
|
|
_ui->sharesLayout->invalidate();
|
|
|
|
}
|
|
|
|
|
2015-11-05 11:58:16 +03:00
|
|
|
void ShareUserGroupWidget::slotCompleterActivated(const QModelIndex & index) {
|
2015-11-05 00:00:35 +03:00
|
|
|
auto sharee = _completerModel->getSharee(index.row());
|
2015-11-01 00:21:09 +03:00
|
|
|
|
2015-11-05 00:00:35 +03:00
|
|
|
if (sharee.isNull()) {
|
|
|
|
return;
|
|
|
|
}
|
2015-11-01 00:21:09 +03:00
|
|
|
|
2015-11-05 00:00:35 +03:00
|
|
|
_manager->createShare(_sharePath,
|
|
|
|
(Share::ShareType)sharee->type(),
|
|
|
|
sharee->shareWith(),
|
|
|
|
Share::PermissionRead);
|
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-01 00:21:09 +03:00
|
|
|
_share(share)
|
|
|
|
{
|
|
|
|
_ui->setupUi(this);
|
|
|
|
|
2015-11-05 00:00:35 +03:00
|
|
|
_ui->sharedWith->setText(share->getShareWith()->format());
|
|
|
|
|
2015-11-01 00:21:09 +03:00
|
|
|
if (share->getPermissions() & Share::PermissionUpdate) {
|
|
|
|
_ui->permissionUpdate->setCheckState(Qt::Checked);
|
|
|
|
}
|
|
|
|
if (share->getPermissions() & Share::PermissionCreate) {
|
|
|
|
_ui->permissionCreate->setCheckState(Qt::Checked);
|
|
|
|
}
|
|
|
|
if (share->getPermissions() & Share::PermissionDelete) {
|
|
|
|
_ui->permissionDelete->setCheckState(Qt::Checked);
|
|
|
|
}
|
|
|
|
if (share->getPermissions() & Share::PermissionShare) {
|
|
|
|
_ui->permissionShare->setCheckState(Qt::Checked);
|
|
|
|
}
|
|
|
|
|
|
|
|
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()));
|
|
|
|
|
|
|
|
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-05 11:58:16 +03:00
|
|
|
ShareWidget::~ShareWidget()
|
2015-11-01 00:21:09 +03:00
|
|
|
{
|
|
|
|
delete _ui;
|
|
|
|
}
|
|
|
|
|
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-05 11:58:16 +03:00
|
|
|
void ShareWidget::slotShareDeleted()
|
2015-11-01 00:21:09 +03:00
|
|
|
{
|
|
|
|
deleteLater();
|
|
|
|
}
|
|
|
|
|
2015-11-05 11:58:16 +03:00
|
|
|
void ShareWidget::slotPermissionsSet()
|
2015-11-01 00:21:09 +03:00
|
|
|
{
|
|
|
|
setEnabled(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|