[Sharing] Add user/group sharing dialog

Dialog can now retrive current shares for path, set the permissions on
those shares and delete the share.
This commit is contained in:
Roeland Jago Douma 2015-10-31 22:21:09 +01:00
parent 37098c96f9
commit 309be57a12
9 changed files with 476 additions and 0 deletions

View file

@ -23,6 +23,8 @@ set(client_UI
protocolwidget.ui
settingsdialog.ui
sharedialog.ui
shareusergroupdialog.ui
sharedialogshare.ui
sslerrordialog.ui
owncloudsetuppage.ui
addcertificatedialog.ui
@ -60,6 +62,7 @@ set(client_SRCS
settingsdialog.cpp
share.cpp
sharedialog.cpp
shareusergroupdialog.cpp
socketapi.cpp
sslbutton.cpp
sslerrordialog.cpp

View file

@ -174,6 +174,8 @@ Application::Application(int &argc, char **argv) :
connect(FolderMan::instance()->socketApi(), SIGNAL(shareCommandReceived(QString, QString, bool)),
_gui, SLOT(slotShowShareDialog(QString, QString, bool)));
connect(FolderMan::instance()->socketApi(), SIGNAL(shareUserGroupCommandReceived(QString, QString, bool)),
_gui, SLOT(slotShowShareUserGroupDialog(QString, QString, bool)));
// startup procedure.
connect(&_checkConnectionTimer, SIGNAL(timeout()), this, SLOT(slotCheckConnection()));

View file

@ -20,6 +20,7 @@
#include "progressdispatcher.h"
#include "owncloudsetupwizard.h"
#include "sharedialog.h"
#include "shareusergroupdialog.h"
#if defined(Q_OS_MAC)
# include "settingsdialogmac.h"
# include "macwindow.h" // qtmacgoodies
@ -780,5 +781,26 @@ void ownCloudGui::slotShowShareDialog(const QString &sharePath, const QString &l
raiseDialog(w);
}
void ownCloudGui::slotShowShareUserGroupDialog(const QString &sharePath, const QString &localPath, bool resharingAllowed)
{
const auto folder = FolderMan::instance()->folderForPath(localPath);
if (!folder) {
qDebug() << "Could not open share dialog for" << localPath << "no responsible folder found";
return;
}
// For https://github.com/owncloud/client/issues/3783
_settingsDialog->hide();
const auto accountState = folder->accountState();
qDebug() << Q_FUNC_INFO << "Opening share dialog" << sharePath << localPath;
ShareUserGroupDialog *w = new ShareUserGroupDialog(accountState->account(), sharePath, localPath, resharingAllowed);
w->getShares();
w->setAttribute( Qt::WA_DeleteOnClose, true );
raiseDialog(w);
}
} // end namespace

View file

@ -77,6 +77,7 @@ public slots:
void slotOpenPath(const QString& path);
void slotAccountStateChanged();
void slotShowShareDialog(const QString &sharePath, const QString &localPath, bool resharingAllowed);
void slotShowShareUserGroupDialog(const QString &sharePath, const QString &localPath, bool resharingAllowed);
private slots:
void slotDisplayIdle();

View file

@ -0,0 +1,170 @@
/*
* 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.
*/
#include "shareusergroupdialog.h"
#include "ui_shareusergroupdialog.h"
#include "ui_sharedialogshare.h"
#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"
#include "QProgressIndicator.h"
#include <QBuffer>
#include <QFileIconProvider>
#include <QClipboard>
#include <QFileInfo>
namespace OCC {
ShareUserGroupDialog::ShareUserGroupDialog(AccountPtr account, const QString &sharePath, const QString &localPath, bool resharingAllowed, QWidget *parent) :
QDialog(parent),
_ui(new Ui::ShareUserGroupDialog),
_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();
_manager = new ShareManager(_account, this);
connect(_manager, SIGNAL(sharesFetched(QList<QSharedPointer<Share>>)), SLOT(slotSharesFetched(QList<QSharedPointer<Share>>)));
}
void ShareUserGroupDialog::done( int r ) {
ConfigFile cfg;
cfg.saveGeometry(this);
QDialog::done(r);
}
ShareUserGroupDialog::~ShareUserGroupDialog()
{
delete _ui;
}
void ShareUserGroupDialog::getShares()
{
_manager->fetchShares(_sharePath);
}
void ShareUserGroupDialog::slotSharesFetched(const QList<QSharedPointer<Share>> &shares)
{
const QString versionString = _account->serverVersion();
qDebug() << Q_FUNC_INFO << versionString << "Fetched" << shares.count() << "shares";
// TODO clear old shares
foreach(const auto &share, shares) {
if (share->getShareType() == Share::TypeLink) {
continue;
}
ShareDialogShare *s = new ShareDialogShare(share, this);
_ui->sharesLayout->addWidget(s);
}
// Add all new shares to share list
}
ShareDialogShare::ShareDialogShare(QSharedPointer<Share> share,
QWidget *parent) :
QWidget(parent),
_ui(new Ui::ShareDialogShare),
_share(share)
{
_ui->setupUi(this);
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()));
}
void ShareDialogShare::on_deleteShareButton_clicked()
{
setEnabled(false);
_share->deleteShare();
}
ShareDialogShare::~ShareDialogShare()
{
delete _ui;
}
void ShareDialogShare::slotPermissionsChanged()
{
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);
}
void ShareDialogShare::slotShareDeleted()
{
deleteLater();
}
void ShareDialogShare::slotPermissionsSet()
{
setEnabled(true);
}
}

View file

@ -0,0 +1,98 @@
/*
* 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.
*/
#ifndef SHAREDIALOG_UG_H
#define SHAREDIALOG_UG_H
#include "accountfwd.h"
#include "QProgressIndicator.h"
#include <QDialog>
#include <QWidget>
#include <QVariantMap>
#include <QSharedPointer>
#include <QList>
namespace OCC {
namespace Ui {
class ShareUserGroupDialog;
class ShareDialogShare;
}
class AbstractCredentials;
class QuotaInfo;
class SyncResult;
class Share;
class ShareManager;
class ShareDialogShare : public QWidget
{
Q_OBJECT
public:
explicit ShareDialogShare(QSharedPointer<Share> Share, QWidget *parent = 0);
~ShareDialogShare();
signals:
void shareDeleted(ShareDialogShare *share);
private slots:
void on_deleteShareButton_clicked();
void slotPermissionsChanged();
void slotShareDeleted();
void slotPermissionsSet();
private:
Ui::ShareDialogShare *_ui;
QSharedPointer<Share> _share;
};
/**
* @brief The ShareDialog (user/group) class
* @ingroup gui
*/
class ShareUserGroupDialog : public QDialog
{
Q_OBJECT
public:
explicit ShareUserGroupDialog(AccountPtr account,
const QString &sharePath,
const QString &localPath,
bool resharingAllowed,
QWidget *parent = 0);
~ShareUserGroupDialog();
void getShares();
private slots:
void slotSharesFetched(const QList<QSharedPointer<Share>> &shares);
void done( int r );
private:
Ui::ShareUserGroupDialog *_ui;
AccountPtr _account;
QString _sharePath;
QString _localPath;
bool _resharingAllowed;
bool _isFile;
ShareManager *_manager;
QList<ShareDialogShare*> _shares;
};
}
#endif // SHAREDIALOG_UG_H

View file

@ -0,0 +1,133 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>OCC::ShareUserGroupDialog</class>
<widget class="QDialog" name="OCC::ShareUserGroupDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>372</width>
<height>505</height>
</rect>
</property>
<property name="windowTitle">
<string>Share NewDocument.odt</string>
</property>
<layout class="QGridLayout" name="gridLayout_3">
<item row="0" column="0" colspan="2">
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0" rowspan="2">
<widget class="QLabel" name="label_icon">
<property name="text">
<string>TextLabel</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLabel" name="label_name">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>share label</string>
</property>
</widget>
</item>
<item row="0" column="2" rowspan="2">
<widget class="QProgressIndicator" name="pi_share" native="true"/>
</item>
<item row="1" column="1">
<widget class="QLabel" name="label_sharePath">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="font">
<font>
<weight>50</weight>
<bold>false</bold>
</font>
</property>
<property name="text">
<string>ownCloud Path:</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="3" column="0">
<widget class="QLabel" name="errorLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>TextLabel</string>
</property>
</widget>
</item>
<item row="4" column="0" colspan="2">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Close</set>
</property>
</widget>
</item>
<item row="1" column="0">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLineEdit" name="newShareLineEdit"/>
</item>
<item>
<widget class="QPushButton" name="newSharePushButton">
<property name="text">
<string>Share</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="2" column="0">
<layout class="QVBoxLayout" name="sharesLayout">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Shares</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<layoutdefault spacing="6" margin="11"/>
<customwidgets>
<customwidget>
<class>QProgressIndicator</class>
<extends>QWidget</extends>
<header>QProgressIndicator.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>

View file

@ -404,6 +404,51 @@ void SocketApi::command_SHARE(const QString& localFile, QIODevice* socket)
}
}
void SocketApi::command_SHARE_USER_GROUP(const QString& localFile, QIODevice* socket)
{
if (!socket) {
qDebug() << Q_FUNC_INFO << "No valid socket object.";
return;
}
qDebug() << Q_FUNC_INFO << localFile;
Folder *shareFolder = FolderMan::instance()->folderForPath(localFile);
if (!shareFolder) {
const QString message = QLatin1String("SHARE:NOP:")+QDir::toNativeSeparators(localFile);
// files that are not within a sync folder are not synced.
sendMessage(socket, message);
} else if (!shareFolder->accountState()->isConnected()) {
const QString message = QLatin1String("SHARE:NOTCONNECTED:")+QDir::toNativeSeparators(localFile);
// if the folder isn't connected, don't open the share dialog
sendMessage(socket, message);
} else {
const QString folderForPath = shareFolder->path();
const QString remotePath = shareFolder->remotePath() + localFile.right(localFile.count()-folderForPath.count()+1);
// Can't share root folder
if (QDir::cleanPath(remotePath) == "/") {
const QString message = QLatin1String("SHARE:CANNOTSHAREROOT:")+QDir::toNativeSeparators(localFile);
sendMessage(socket, message);
return;
}
SyncJournalFileRecord rec = dbFileRecord_capi(shareFolder, localFile);
bool allowReshare = true; // lets assume the good
if( rec.isValid() ) {
// check the permission: Is resharing allowed?
if( !rec._remotePerm.contains('R') ) {
allowReshare = false;
}
}
const QString message = QLatin1String("SHARE:OK:")+QDir::toNativeSeparators(localFile);
sendMessage(socket, message);
emit shareUserGroupCommandReceived(remotePath, localFile, allowReshare);
}
}
void SocketApi::command_VERSION(const QString&, QIODevice* socket)
{
sendMessage(socket, QLatin1String("VERSION:" MIRALL_VERSION_STRING ":" MIRALL_SOCKET_API_VERSION));

View file

@ -55,6 +55,7 @@ public slots:
signals:
void shareCommandReceived(const QString &sharePath, const QString &localPath, bool resharingAllowed);
void shareUserGroupCommandReceived(const QString &sharePath, const QString &localPath, bool resharingAllowed);
private slots:
void slotNewConnection();
@ -74,6 +75,7 @@ private:
Q_INVOKABLE void command_RETRIEVE_FOLDER_STATUS(const QString& argument, QIODevice* socket);
Q_INVOKABLE void command_RETRIEVE_FILE_STATUS(const QString& argument, QIODevice* socket);
Q_INVOKABLE void command_SHARE(const QString& localFile, QIODevice* socket);
Q_INVOKABLE void command_SHARE_USER_GROUP(const QString& localFile, QIODevice* socket);
Q_INVOKABLE void command_VERSION(const QString& argument, QIODevice* socket);