Skip to content

Commit

Permalink
Implement missing share settings
Browse files Browse the repository at this point in the history
Signed-off-by: alex-z <blackslayer4@gmail.com>
  • Loading branch information
allexzander committed Apr 26, 2023
1 parent e409779 commit 8817572
Show file tree
Hide file tree
Showing 11 changed files with 426 additions and 61 deletions.
1 change: 1 addition & 0 deletions resources.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,6 @@
<file>src/gui/tray/EnforcedPlainTextLabel.qml</file>
<file>theme/Style/Style.qml</file>
<file>theme/Style/qmldir</file>
<file>src/gui/filedetails/NCRadioButton.qml</file>
</qresource>
</RCC>
41 changes: 41 additions & 0 deletions src/gui/filedetails/NCRadioButton.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright (C) by Oleksandr Zolotov <alex@nextcloud.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; either version 2 of the License, or
* (at your option) any later version.
*
* 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.
*/

import QtQuick 2.15
import QtQuick.Controls 2.15

RadioButton {
id: root
property int indicatorItemWidth: 16
property int indicatorItemHeight: 16
property string color: "#000000"
readonly property int radius: 9
indicator: Rectangle {
implicitWidth: root.indicatorItemWidth
implicitHeight: root.indicatorItemHeight
anchors.verticalCenter: parent.verticalCenter
anchors.left: parent.left
anchors.leftMargin: 5
radius: root.radius
border.color: root.color
border.width: 1
Rectangle {
anchors.fill: parent
visible: root.checked
color: root.color
radius: root.radius
anchors.margins: 4
}
}
}
4 changes: 4 additions & 0 deletions src/gui/filedetails/ShareDelegate.qml
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,13 @@ GridLayout {
signal resetPasswordField
signal showPasswordSetError(string errorMessage);

signal toggleHideDownload(bool enable)
signal toggleAllowEditing(bool enable)
signal toggleAllowResharing(bool enable)
signal togglePasswordProtect(bool enable)
signal toggleExpirationDate(bool enable)
signal toggleNoteToRecipient(bool enable)
signal permissionModeChanged(int permissionMode)

signal setLinkShareLabel(string label)
signal setExpireDate(var milliseconds) // Since QML ints are only 32 bits, use a variant
Expand Down Expand Up @@ -236,9 +238,11 @@ GridLayout {

onToggleAllowEditing: root.toggleAllowEditing(enable)
onToggleAllowResharing: root.toggleAllowResharing(enable)
onToggleHideDownload: root.toggleHideDownload(enable)
onTogglePasswordProtect: root.togglePasswordProtect(enable)
onToggleExpirationDate: root.toggleExpirationDate(enable)
onToggleNoteToRecipient: root.toggleNoteToRecipient(enable)
onPermissionModeChanged: root.permissionModeChanged(permissionMode)

onSetLinkShareLabel: root.setLinkShareLabel(label)
onSetExpireDate: root.setExpireDate(milliseconds) // Since QML ints are only 32 bits, use a variant
Expand Down
156 changes: 124 additions & 32 deletions src/gui/filedetails/ShareDetailsPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@ Page {

signal toggleAllowEditing(bool enable)
signal toggleAllowResharing(bool enable)
signal toggleHideDownload(bool enable)
signal togglePasswordProtect(bool enable)
signal toggleExpirationDate(bool enable)
signal toggleNoteToRecipient(bool enable)
signal permissionModeChanged(int permissionMode)

signal setLinkShareLabel(string label)
signal setExpireDate(var milliseconds) // Since QML ints are only 32 bits, use a variant
Expand Down Expand Up @@ -65,16 +67,21 @@ Page {
readonly property string linkShareLabel: shareModelData.linkShareLabel ?? ""

readonly property bool editingAllowed: shareModelData.editingAllowed
readonly property bool hideDownload: shareModelData.hideDownload
readonly property bool noteEnabled: shareModelData.noteEnabled
readonly property bool expireDateEnabled: shareModelData.expireDateEnabled
readonly property bool expireDateEnforced: shareModelData.expireDateEnforced
readonly property bool passwordProtectEnabled: shareModelData.passwordProtectEnabled
readonly property bool passwordEnforced: shareModelData.passwordEnforced
readonly property bool isSecureFileDropLink: shareModelData.isSecureFileDropLink
readonly property bool isSharePermissionChangeInProgress: shareModelData.isSharePermissionChangeInProgress
readonly property bool isHideDownloadInProgress: shareModelData.isHideDownloadInProgress
readonly property int currentPermissionMode: shareModelData.currentPermissionMode

readonly property bool isLinkShare: shareModelData.shareType === ShareModel.ShareTypeLink

property bool waitingForEditingAllowedChange: false
readonly property bool isFolderItem: shareModelData.sharedItemTypeRole === ShareModel.SharedItemTypeFolder
readonly property bool isEncryptedItem: shareModelData.sharedItemTypeRole === ShareModel.SharedItemTypeEncryptedFile || shareModelData.sharedItemTypeRole === ShareModel.SharedItemTypeEncryptedFolder || shareModelData.sharedItemTypeRole === ShareModel.SharedItemTypeEncryptedTopLevelFolder

property bool waitingForNoteEnabledChange: false
property bool waitingForExpireDateEnabledChange: false
property bool waitingForPasswordProtectEnabledChange: false
Expand Down Expand Up @@ -108,11 +115,6 @@ Page {
waitingForExpireDateChange = false;
}

function resetEditingAllowedField() {
editingAllowedMenuItem.checked = editingAllowed;
waitingForEditingAllowedChange = false;
}

function resetNoteEnabledField() {
noteEnabledMenuItem.checked = noteEnabled;
waitingForNoteEnabledChange = false;
Expand All @@ -135,8 +137,6 @@ Page {
resetPasswordField();
resetLinkShareLabelField();
resetExpireDateField();

resetEditingAllowedField();
resetNoteEnabledField();
resetExpireDateEnabledField();
resetPasswordProtectEnabledField();
Expand All @@ -154,8 +154,6 @@ Page {
onPasswordChanged: resetPasswordField()
onLinkShareLabelChanged: resetLinkShareLabelField()
onExpireDateChanged: resetExpireDateField()

onEditingAllowedChanged: resetEditingAllowedField()
onNoteEnabledChanged: resetNoteEnabledField()
onExpireDateEnabledChanged: resetExpireDateEnabledField()
onPasswordProtectEnabledChanged: resetPasswordProtectEnabledField()
Expand Down Expand Up @@ -313,34 +311,128 @@ Page {
}
}

// On these checkables, the clicked() signal is called after
// the check state changes.
CheckBox {
id: editingAllowedMenuItem
Loader {
Layout.fillWidth: true
active: !root.isFolderItem && !root.isEncryptedItem
visible: active
sourceComponent: CheckBox {
spacing: moreMenu.indicatorSpacing
padding: moreMenu.itemPadding
indicator.width: moreMenu.indicatorItemWidth
indicator.height: moreMenu.indicatorItemWidth

checkable: true
checked: root.editingAllowed
text: qsTr("Allow upload and editing")
enabled: !root.isSharePermissionChangeInProgress

onClicked: {
root.toggleAllowEditing(checked);
}

NCBusyIndicator {
anchors.fill: parent
visible: root.isSharePermissionChangeInProgress
running: visible
z: 1
}
}
}

Loader {
Layout.fillWidth: true
active: root.isFolderItem && !root.isEncryptedItem
visible: active
sourceComponent: ColumnLayout {
id: permissionRadioButtonsLayout
spacing: 0
width: parent.width

spacing: moreMenu.indicatorSpacing
padding: moreMenu.itemPadding
indicator.width: moreMenu.indicatorItemWidth
indicator.height: moreMenu.indicatorItemWidth
ButtonGroup {
id: permissionModeRadioButtonsGroup
}

checkable: true
checked: root.editingAllowed
text: qsTr("Allow editing")
enabled: !root.waitingForEditingAllowedChange
visible: !root.isSecureFileDropLink
NCRadioButton {
property int permissionMode: ShareModel.ModeViewOnly
Layout.fillWidth: true
ButtonGroup.group: permissionModeRadioButtonsGroup
enabled: !root.isSharePermissionChangeInProgress
checked: root.currentPermissionMode === permissionMode
text: qsTr("View only")
indicatorItemWidth: moreMenu.indicatorItemWidth
indicatorItemHeight: moreMenu.indicatorItemWidth
spacing: moreMenu.indicatorSpacing
padding: moreMenu.itemPadding
onClicked: root.permissionModeChanged(permissionMode);
}

onClicked: {
root.toggleAllowEditing(checked);
root.waitingForEditingAllowedChange = true;
NCRadioButton {
property int permissionMode: ShareModel.ModeUploadAndEditing
Layout.fillWidth: true
ButtonGroup.group: permissionModeRadioButtonsGroup
enabled: !root.isSharePermissionChangeInProgress
checked: root.currentPermissionMode === permissionMode
text: qsTr("Allow upload and editing")
indicatorItemWidth: moreMenu.indicatorItemWidth
indicatorItemHeight: moreMenu.indicatorItemWidth
spacing: moreMenu.indicatorSpacing
padding: moreMenu.itemPadding
onClicked: root.permissionModeChanged(permissionMode);

NCBusyIndicator {
anchors.fill: parent
visible: root.isSharePermissionChangeInProgress
running: visible
z: 1
}
}

NCRadioButton {
property int permissionMode: ShareModel.ModeFileDropOnly
Layout.fillWidth: true
ButtonGroup.group: permissionModeRadioButtonsGroup
enabled: !root.isSharePermissionChangeInProgress
checked: root.currentPermissionMode === permissionMode
text: qsTr("File drop (upload only)")
indicatorItemWidth: moreMenu.indicatorItemWidth
indicatorItemHeight: moreMenu.indicatorItemWidth
spacing: moreMenu.indicatorSpacing
padding: moreMenu.itemPadding
onClicked: root.permissionModeChanged(permissionMode);
}
}
}

NCBusyIndicator {
anchors.fill: parent
visible: root.waitingForEditingAllowedChange
running: visible
z: 1
Loader {
Layout.fillWidth: true

active: root.isLinkShare
visible: active
sourceComponent: ColumnLayout {
CheckBox {
id: hideDownloadEnabledMenuItem

anchors.left: parent.left
anchors.right: parent.right

spacing: moreMenu.indicatorSpacing
padding: moreMenu.itemPadding
indicator.width: moreMenu.indicatorItemWidth
indicator.height: moreMenu.indicatorItemWidth
checked: root.hideDownload
text: qsTr("Hide download")
enabled: !root.isHideDownloadInProgress
onClicked: {
root.toggleHideDownload(checked);
}

NCBusyIndicator {
anchors.fill: parent
visible: root.isHideDownloadInProgress
running: visible
z: 1
}
}
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/gui/filedetails/ShareView.qml
Original file line number Diff line number Diff line change
Expand Up @@ -241,9 +241,11 @@ ColumnLayout {

onToggleAllowEditing: shareModel.toggleShareAllowEditingFromQml(model.share, enable)
onToggleAllowResharing: shareModel.toggleShareAllowResharingFromQml(model.share, enable)
onToggleHideDownload: shareModel.toggleHideDownloadFromQml(model.share, enable)
onTogglePasswordProtect: shareModel.toggleSharePasswordProtectFromQml(model.share, enable)
onToggleExpirationDate: shareModel.toggleShareExpirationDateFromQml(model.share, enable)
onToggleNoteToRecipient: shareModel.toggleShareNoteToRecipientFromQml(model.share, enable)
onPermissionModeChanged: shareModel.changePermissionMode(model.share, permissionMode)

onSetLinkShareLabel: shareModel.setLinkShareLabelFromQml(model.share, label)
onSetExpireDate: shareModel.setShareExpireDateFromQml(model.share, milliseconds)
Expand Down
Loading

0 comments on commit 8817572

Please sign in to comment.