ShareDialog: Make "can edit" partially checked sometimes #5642

Previously the check box was checked if *any* of its sub-permissions
were granted. This can hide the fact that only a limited subset of them
are actually granted.

The new behavior is to display as "partially checked" if only some
of the sub-permissions are available. Clicking the check box itself
still toggles between granting all or none of them.
This commit is contained in:
Christian Kamm 2017-03-22 13:22:22 +01:00 committed by ckamm
parent da45d99b8f
commit a0e88477c1

View file

@ -374,6 +374,13 @@ void ShareWidget::slotEditPermissionsChanged()
{ {
setEnabled(false); setEnabled(false);
// Can never manually be set to "partial".
// This works because the state cycle for clicking is
// unchecked -> partial -> checked -> unchecked.
if (_ui->permissionsEdit->checkState() == Qt::PartiallyChecked) {
_ui->permissionsEdit->setCheckState(Qt::Checked);
}
Share::Permissions permissions = SharePermissionRead; Share::Permissions permissions = SharePermissionRead;
if (_ui->permissionShare->checkState() == Qt::Checked) { if (_ui->permissionShare->checkState() == Qt::Checked) {
@ -461,24 +468,33 @@ QSharedPointer<Share> ShareWidget::share() const
void ShareWidget::displayPermissions() void ShareWidget::displayPermissions()
{ {
_permissionCreate->setChecked(false); auto perm = _share->getPermissions();
_ui->permissionsEdit->setCheckState(Qt::Unchecked);
_permissionDelete->setChecked(false);
_ui->permissionShare->setCheckState(Qt::Unchecked);
_permissionUpdate->setChecked(false);
if (_share->getPermissions() & SharePermissionUpdate) { _permissionUpdate->setChecked(false);
_permissionCreate->setChecked(false);
_permissionDelete->setChecked(false);
if (perm & SharePermissionUpdate) {
_permissionUpdate->setChecked(true); _permissionUpdate->setChecked(true);
_ui->permissionsEdit->setCheckState(Qt::Checked);
} }
if (!_isFile && _share->getPermissions() & SharePermissionCreate) { if (!_isFile && perm & SharePermissionCreate) {
_permissionCreate->setChecked(true); _permissionCreate->setChecked(true);
_ui->permissionsEdit->setCheckState(Qt::Checked);
} }
if (!_isFile && _share->getPermissions() & SharePermissionDelete) { if (!_isFile && perm & SharePermissionDelete) {
_permissionDelete->setChecked(true); _permissionDelete->setChecked(true);
_ui->permissionsEdit->setCheckState(Qt::Checked);
} }
if (perm & SharePermissionUpdate
&& (_isFile
|| (perm & SharePermissionCreate
&& perm & SharePermissionDelete))) {
_ui->permissionsEdit->setCheckState(Qt::Checked);
} else if (perm & (SharePermissionUpdate | SharePermissionCreate | SharePermissionDelete)) {
_ui->permissionsEdit->setCheckState(Qt::PartiallyChecked);
} else {
_ui->permissionsEdit->setCheckState(Qt::Unchecked);
}
_ui->permissionShare->setCheckState(Qt::Unchecked);
if (_share->getPermissions() & SharePermissionShare) { if (_share->getPermissions() & SharePermissionShare) {
_ui->permissionShare->setCheckState(Qt::Checked); _ui->permissionShare->setCheckState(Qt::Checked);
} }