From f1faf8745ad96e8a22b9f78016ee4e0ea03f0cf1 Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Wed, 25 Nov 2015 11:26:21 +0100 Subject: [PATCH] [Sharing] Permissions now in dropdown menu As discusses with jan. * Detailed permissions displayed in qtoolboxmenu * Made share rows slightly smaller Bug fix: * Do not show delete permissions for file shares --- src/gui/shareusergroupwidget.cpp | 78 ++++++++++++++++---------------- src/gui/shareusergroupwidget.h | 11 +++-- src/gui/sharewidget.ui | 46 ++++++------------- 3 files changed, 61 insertions(+), 74 deletions(-) diff --git a/src/gui/shareusergroupwidget.cpp b/src/gui/shareusergroupwidget.cpp index ae8e4fbe5..d7979a659 100644 --- a/src/gui/shareusergroupwidget.cpp +++ b/src/gui/shareusergroupwidget.cpp @@ -37,6 +37,8 @@ #include #include #include +#include +#include namespace OCC { @@ -143,7 +145,7 @@ void ShareUserGroupWidget::slotSharesFetched(const QList> continue; } - ShareWidget *s = new ShareWidget(share, _ui->scrollArea); + ShareWidget *s = new ShareWidget(share, _isFile, _ui->scrollArea); connect(s, SIGNAL(resizeRequested()), this, SLOT(slotAdjustScrollWidgetSize())); layout->addWidget(s); @@ -196,27 +198,39 @@ void ShareUserGroupWidget::slotCompleterActivated(const QModelIndex & index) } ShareWidget::ShareWidget(QSharedPointer share, - QWidget *parent) : + bool isFile, + QWidget *parent) : QWidget(parent), _ui(new Ui::ShareWidget), _share(share), - _showDetailedPermissions(false) + _isFile(isFile) { _ui->setupUi(this); _ui->sharedWith->setText(share->getShareWith()->format()); + + // Create detailed permissions menu + QMenu *menu = new QMenu(this); + _permissionCreate = new QAction(tr("create"), this); + _permissionCreate->setCheckable(true); + menu->addAction(_permissionCreate); + _permissionUpdate = new QAction(tr("change"), this); + _permissionUpdate->setCheckable(true); + menu->addAction(_permissionUpdate); + _permissionDelete = new QAction(tr("delete"), this); + _permissionDelete->setCheckable(true); + if (!_isFile) { + menu->addAction(_permissionDelete); + } + _ui->permissionToolButton->setMenu(menu); + _ui->permissionToolButton->setPopupMode(QToolButton::InstantPopup); // Set the permissions checkboxes displayPermissions(); - // Hide "detailed permissions" by default - _ui->permissionDelete->setHidden(true); - _ui->permissionUpdate->setHidden(true); - _ui->permissionCreate->setHidden(true); - - 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(_permissionUpdate, SIGNAL(triggered(bool)), SLOT(slotPermissionsChanged())); + connect(_permissionCreate, SIGNAL(triggered(bool)), SLOT(slotPermissionsChanged())); + connect(_permissionDelete, SIGNAL(triggered(bool)), SLOT(slotPermissionsChanged())); connect(_ui->permissionShare, SIGNAL(clicked(bool)), SLOT(slotPermissionsChanged())); connect(_ui->permissionsEdit, SIGNAL(clicked(bool)), SLOT(slotEditPermissionsChanged())); @@ -233,21 +247,6 @@ void ShareWidget::on_deleteShareButton_clicked() _share->deleteShare(); } -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"); - } - emit resizeRequested(); -} - ShareWidget::~ShareWidget() { delete _ui; @@ -260,13 +259,16 @@ void ShareWidget::slotEditPermissionsChanged() Share::Permissions permissions = Share::PermissionRead; if (_ui->permissionShare->checkState() == Qt::Checked) { - permissions |= Share::PermissionUpdate; + permissions |= Share::PermissionShare; } if (_ui->permissionsEdit->checkState() == Qt::Checked) { permissions |= Share::PermissionCreate; permissions |= Share::PermissionUpdate; - permissions |= Share::PermissionDelete; + + if (!_isFile) { + permissions |= Share::PermissionDelete; + } } _share->setPermissions(permissions); @@ -278,15 +280,15 @@ void ShareWidget::slotPermissionsChanged() Share::Permissions permissions = Share::PermissionRead; - if (_ui->permissionUpdate->checkState() == Qt::Checked) { + if (_permissionUpdate->isChecked()) { permissions |= Share::PermissionUpdate; } - if (_ui->permissionCreate->checkState() == Qt::Checked) { + if (_permissionCreate->isChecked()) { permissions |= Share::PermissionCreate; } - if (_ui->permissionDelete->checkState() == Qt::Checked) { + if (_permissionDelete->isChecked()) { permissions |= Share::PermissionDelete; } @@ -330,22 +332,22 @@ QSharedPointer ShareWidget::share() const void ShareWidget::displayPermissions() { - _ui->permissionCreate->setCheckState(Qt::Unchecked); + _permissionCreate->setChecked(false); _ui->permissionsEdit->setCheckState(Qt::Unchecked); - _ui->permissionDelete->setCheckState(Qt::Unchecked); + _permissionDelete->setChecked(false); _ui->permissionShare->setCheckState(Qt::Unchecked); - _ui->permissionUpdate->setCheckState(Qt::Unchecked); + _permissionUpdate->setChecked(false); if (_share->getPermissions() & Share::PermissionUpdate) { - _ui->permissionUpdate->setCheckState(Qt::Checked); + _permissionUpdate->setChecked(true); _ui->permissionsEdit->setCheckState(Qt::Checked); } if (_share->getPermissions() & Share::PermissionCreate) { - _ui->permissionCreate->setCheckState(Qt::Checked); + _permissionCreate->setChecked(true); _ui->permissionsEdit->setCheckState(Qt::Checked); } - if (_share->getPermissions() & Share::PermissionDelete) { - _ui->permissionDelete->setCheckState(Qt::Checked); + if (!_isFile && _share->getPermissions() & Share::PermissionDelete) { + _permissionDelete->setChecked(true); _ui->permissionsEdit->setCheckState(Qt::Checked); } if (_share->getPermissions() & Share::PermissionShare) { diff --git a/src/gui/shareusergroupwidget.h b/src/gui/shareusergroupwidget.h index 9591f882f..fcf2458e0 100644 --- a/src/gui/shareusergroupwidget.h +++ b/src/gui/shareusergroupwidget.h @@ -24,6 +24,7 @@ #include #include +class QAction; class QCompleter; class QModelIndex; @@ -47,7 +48,7 @@ class ShareWidget : public QWidget Q_OBJECT public: - explicit ShareWidget(QSharedPointer Share, QWidget *parent = 0); + explicit ShareWidget(QSharedPointer Share, bool isFile, QWidget *parent = 0); ~ShareWidget(); QSharedPointer share() const; @@ -60,18 +61,20 @@ private slots: void on_deleteShareButton_clicked(); void slotPermissionsChanged(); void slotEditPermissionsChanged(); - void on_permissionToggleButton_clicked(); void slotDeleteAnimationFinished(); void slotShareDeleted(); void slotPermissionsSet(); - private: void displayPermissions(); Ui::ShareWidget *_ui; QSharedPointer _share; - bool _showDetailedPermissions; + bool _isFile; + + QAction *_permissionCreate; + QAction *_permissionUpdate; + QAction *_permissionDelete; }; diff --git a/src/gui/sharewidget.ui b/src/gui/sharewidget.ui index 83a5841d0..a6b044590 100644 --- a/src/gui/sharewidget.ui +++ b/src/gui/sharewidget.ui @@ -10,7 +10,7 @@ 0 0 468 - 92 + 64 @@ -46,56 +46,38 @@ 40 - 20 + 15 - - - + + + QFrame::StyledPanel + + + QFrame::Raised - - - - Can Share - - - - Can Edit + can edit - - + + - Create - - - - - - - Change - - - - - - - Delete + can share - + - More + ...