Skip to content

Commit

Permalink
Merge pull request #7854 from nextcloud/bugfix/native-share-note
Browse files Browse the repository at this point in the history
Fix looks of share note text field
  • Loading branch information
nilsding authored Feb 14, 2025
2 parents c0ada1f + 7e819b3 commit 228be57
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 68 deletions.
2 changes: 1 addition & 1 deletion resources.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<file>src/gui/filedetails/FileDetailsWindow.qml</file>
<file>src/gui/filedetails/FileTag.qml</file>
<file>src/gui/filedetails/NCInputDateField.qml</file>
<file>src/gui/filedetails/NCInputTextEdit.qml</file>
<file>src/gui/filedetails/NCInputTextArea.qml</file>
<file>src/gui/filedetails/NCInputTextField.qml</file>
<file>src/gui/filedetails/NCTabButton.qml</file>
<file>src/gui/filedetails/ShareeDelegate.qml</file>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,20 @@ import QtQuick.Layouts
import com.nextcloud.desktopclient
import Style

TextEdit {
TextArea {
id: root

readonly property color accentColor: palette.highlight
readonly property color secondaryColor: palette.dark
readonly property color secondaryColor: palette.placeholderText
readonly property alias submitButton: submitButton

clip: true
textMargin: Style.smallSpacing
wrapMode: TextEdit.Wrap
// no implicitHeight here -- let the textarea take as much as it needs
// otherwise it will cut off some text vertically on multi-line strings...

selectByMouse: true
height: Math.max(Style.talkReplyTextFieldPreferredHeight, contentHeight)
rightPadding: submitButton.width

Rectangle {
id: textFieldBorder
anchors.fill: parent
radius: Style.trayWindowRadius
border.width: Style.normalBorderWidth
border.color: root.activeFocus ? root.accentColor : root.secondaryColor
color: palette.base
z: -1
}
wrapMode: TextEdit.Wrap

Button {
id: submitButton
Expand All @@ -61,4 +53,3 @@ TextEdit {
onClicked: root.editingFinished()
}
}

2 changes: 1 addition & 1 deletion src/gui/filedetails/NCInputTextField.qml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ TextField {
id: root

readonly property color accentColor: Style.ncBlue
readonly property color secondaryColor: palette.dark
readonly property color secondaryColor: palette.placeholderText
readonly property alias submitButton: submitButton
property bool validInput: true

Expand Down
2 changes: 0 additions & 2 deletions src/gui/filedetails/ShareDelegate.qml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ GridLayout {
signal toggleAllowResharing(bool enable)
signal togglePasswordProtect(bool enable)
signal toggleExpirationDate(bool enable)
signal toggleNoteToRecipient(bool enable)
signal permissionModeChanged(int permissionMode)

signal setLinkShareLabel(string label)
Expand Down Expand Up @@ -252,7 +251,6 @@ GridLayout {
onToggleHideDownload: root.toggleHideDownload(enable)
onTogglePasswordProtect: root.togglePasswordProtect(enable)
onToggleExpirationDate: root.toggleExpirationDate(enable)
onToggleNoteToRecipient: root.toggleNoteToRecipient(enable)
onPermissionModeChanged: root.permissionModeChanged(permissionMode)

onSetLinkShareLabel: root.setLinkShareLabel(label)
Expand Down
41 changes: 20 additions & 21 deletions src/gui/filedetails/ShareDetailsPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ Page {
readonly property bool isFolderItem: shareModelData.sharedItemType === ShareModel.SharedItemTypeFolder
readonly property bool isEncryptedItem: shareModelData.sharedItemType === ShareModel.SharedItemTypeEncryptedFile || shareModelData.sharedItemType === ShareModel.SharedItemTypeEncryptedFolder || shareModelData.sharedItemType === ShareModel.SharedItemTypeEncryptedTopLevelFolder

property bool waitingForNoteEnabledChange: false
property bool waitingForExpireDateEnabledChange: false
property bool waitingForPasswordProtectEnabledChange: false
property bool waitingForExpireDateChange: false
Expand All @@ -101,7 +100,7 @@ Page {
}

function resetNoteField() {
noteTextEdit.text = note;
noteTextArea.text = note;
waitingForNoteChange = false;
}

Expand Down Expand Up @@ -133,7 +132,7 @@ Page {

function resetNoteEnabledField() {
noteEnabledMenuItem.checked = noteEnabled;
waitingForNoteEnabledChange = false;
waitingForNoteChange = false;
}

function resetExpireDateEnabledField() {
Expand Down Expand Up @@ -277,7 +276,7 @@ Page {
horizontalAlignment: Image.AlignHCenter
fillMode: Image.Pad

source: "image://svgimage-custom-color/edit.svg/" + palette.dark
source: "image://svgimage-custom-color/edit.svg/" + palette.windowText
sourceSize.width: scrollContentsColumn.rowIconWidth
sourceSize.height: scrollContentsColumn.rowIconWidth
}
Expand Down Expand Up @@ -501,7 +500,7 @@ Page {
horizontalAlignment: Image.AlignHCenter
fillMode: Image.Pad

source: "image://svgimage-custom-color/lock-https.svg/" + palette.dark
source: "image://svgimage-custom-color/lock-https.svg/" + palette.windowText
sourceSize.width: scrollContentsColumn.rowIconWidth
sourceSize.height: scrollContentsColumn.rowIconWidth
}
Expand Down Expand Up @@ -607,7 +606,7 @@ Page {
horizontalAlignment: Image.AlignHCenter
fillMode: Image.Pad

source: "image://svgimage-custom-color/calendar.svg/" + palette.dark
source: "image://svgimage-custom-color/calendar.svg/" + palette.windowText
sourceSize.width: scrollContentsColumn.rowIconWidth
sourceSize.height: scrollContentsColumn.rowIconWidth
}
Expand Down Expand Up @@ -662,16 +661,18 @@ Page {
checkable: true
checked: root.noteEnabled
text: qsTr("Note to recipient")
enabled: !root.waitingForNoteEnabledChange
enabled: !root.waitingForNoteChange

onClicked: {
root.toggleNoteToRecipient(checked);
root.waitingForNoteEnabledChange = true;
if (!checked && root.note !== "") {
root.setNote("");
root.waitingForNoteChange = true;
}
}

NCBusyIndicator {
anchors.fill: parent
visible: root.waitingForNoteEnabledChange
visible: root.waitingForNoteChange && !noteEnabledMenuItem.checked
running: visible
z: 1
}
Expand All @@ -682,7 +683,7 @@ Page {
height: visible ? implicitHeight : 0
spacing: scrollContentsColumn.indicatorSpacing

visible: root.noteEnabled
visible: noteEnabledMenuItem.checked

Image {
Layout.preferredWidth: scrollContentsColumn.indicatorItemWidth
Expand All @@ -692,32 +693,30 @@ Page {
horizontalAlignment: Image.AlignHCenter
fillMode: Image.Pad

source: "image://svgimage-custom-color/edit.svg/" + palette.dark
source: "image://svgimage-custom-color/edit.svg/" + palette.windowText
sourceSize.width: scrollContentsColumn.rowIconWidth
sourceSize.height: scrollContentsColumn.rowIconWidth
}

NCInputTextEdit {
id: noteTextEdit
NCInputTextArea {
id: noteTextArea

Layout.fillWidth: true
height: visible ? Math.max(Style.talkReplyTextFieldPreferredHeight, contentHeight) : 0
// no height here -- let the textarea figure it out how much it needs
submitButton.height: Math.min(Style.talkReplyTextFieldPreferredHeight, height - 2)

text: root.note
enabled: root.noteEnabled &&
!root.waitingForNoteChange &&
!root.waitingForNoteEnabledChange
placeholderText: qsTr("Enter a note for the recipient")
enabled: noteEnabledMenuItem.checked && !root.waitingForNoteChange

onEditingFinished: if(text !== root.note) {
onEditingFinished: if (text !== "" && text !== root.note) {
root.setNote(text);
root.waitingForNoteChange = true;
}

NCBusyIndicator {
anchors.fill: parent
visible: root.waitingForNoteChange ||
root.waitingForNoteEnabledChange
visible: root.waitingForNoteChange && noteEnabledMenuItem.checked
running: visible
z: 1
}
Expand Down
1 change: 0 additions & 1 deletion src/gui/filedetails/ShareView.qml
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,6 @@ ColumnLayout {
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.changePermissionModeFromQml(model.share, permissionMode)

onSetLinkShareLabel: shareModel.setLinkShareLabelFromQml(model.share, label)
Expand Down
20 changes: 0 additions & 20 deletions src/gui/filedetails/sharemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1088,26 +1088,6 @@ void ShareModel::toggleShareExpirationDateFromQml(const QVariant &share, const b
toggleShareExpirationDate(ptr, enable);
}

void ShareModel::toggleShareNoteToRecipient(const SharePtr &share, const bool enable) const
{
if (share.isNull()) {
return;
}

const QString note = enable ? tr("Enter a note for the recipient") : QString();
if (const auto linkShare = share.objectCast<LinkShare>()) {
linkShare->setNote(note);
} else if (const auto userGroupShare = share.objectCast<UserGroupShare>()) {
userGroupShare->setNote(note);
}
}

void ShareModel::toggleShareNoteToRecipientFromQml(const QVariant &share, const bool enable) const
{
const auto ptr = share.value<SharePtr>();
toggleShareNoteToRecipient(ptr, enable);
}

void ShareModel::changePermissionModeFromQml(const QVariant &share, const OCC::ShareModel::SharePermissionsMode permissionMode)
{
const auto sharePtr = share.value<SharePtr>();
Expand Down
2 changes: 0 additions & 2 deletions src/gui/filedetails/sharemodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,6 @@ public slots:
void toggleSharePasswordProtectFromQml(const QVariant &share, const bool enable);
void toggleShareExpirationDate(const OCC::SharePtr &share, const bool enable) const;
void toggleShareExpirationDateFromQml(const QVariant &share, const bool enable) const;
void toggleShareNoteToRecipient(const OCC::SharePtr &share, const bool enable) const;
void toggleShareNoteToRecipientFromQml(const QVariant &share, const bool enable) const;
void changePermissionModeFromQml(const QVariant &share, const OCC::ShareModel::SharePermissionsMode permissionMode);

void setLinkShareLabel(const QSharedPointer<OCC::LinkShare> &linkShare, const QString &label) const;
Expand Down
2 changes: 1 addition & 1 deletion src/gui/tray/NCBusyIndicator.qml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import Style
BusyIndicator {
id: root

property color color: palette.dark
property color color: palette.windowText
property string imageSource: "image://svgimage-custom-color/change.svg/"

property int imageSourceSizeWidth: 64
Expand Down
6 changes: 3 additions & 3 deletions test/testsharemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -820,7 +820,7 @@ private slots:
helper.resetTestData();

// Test with an existing link share.
// This one has a pre-existing password
// This one has a pre-existing note
helper.appendShareReplyData(_testLinkShareDefinition);
QCOMPARE(helper.shareCount(), 1);

Expand All @@ -844,15 +844,15 @@ private slots:
const auto linkSharePtr = sharePtr.dynamicCast<LinkShare>(); // Need to connect to signal
QSignalSpy noteSet(linkSharePtr.data(), &LinkShare::noteSet);

model.toggleShareNoteToRecipient(sharePtr, false);
model.setShareNote(sharePtr, QStringLiteral(""));
QVERIFY(noteSet.wait(3000));
QCOMPARE(shareIndex.data(ShareModel::NoteEnabledRole).toBool(), false);

const auto note = QStringLiteral("Don't forget to test everything!");
model.setShareNote(sharePtr, note);
QVERIFY(noteSet.wait(3000));
QCOMPARE(shareIndex.data(ShareModel::NoteEnabledRole).toBool(), true);
// The model stores the recently set password.
// The model stores the recently set note.
// We want to present the user with it in the UI while the model is alive
QCOMPARE(shareIndex.data(ShareModel::NoteRole).toString(), note);
}
Expand Down

0 comments on commit 228be57

Please sign in to comment.