From 974910dbf6fce7df9ebd4ea3c5df3662df1d702d Mon Sep 17 00:00:00 2001 From: Martchus Date: Thu, 14 Jun 2018 23:46:18 +0200 Subject: [PATCH] Make QML coding style more consistent --- qml/EntriesPage.qml | 34 +++---- qml/PasswordDialog.qml | 45 +++++---- qml/main.qml | 206 +++++++++++++++++++---------------------- 3 files changed, 134 insertions(+), 151 deletions(-) diff --git a/qml/EntriesPage.qml b/qml/EntriesPage.qml index eac3f3e..af0d7b9 100644 --- a/qml/EntriesPage.qml +++ b/qml/EntriesPage.qml @@ -6,7 +6,6 @@ import org.kde.kirigami 2.5 as Kirigami Kirigami.ScrollablePage { id: page - property var main: undefined property alias entryModel: delegateModel.model property alias rootIndex: delegateModel.rootIndex @@ -30,8 +29,8 @@ Kirigami.ScrollablePage { qsTr("Unable to paste the entries here")) return } - var joinedEntryNames = pastedEntries.join(", ") - showPassiveNotification(qsTr("Pasted ") + joinedEntryNames) + showPassiveNotification( + qsTr("Pasted ") + pastedEntries.join(", ")) } } right: Kirigami.Action { @@ -75,7 +74,6 @@ Kirigami.ScrollablePage { // dialog to rename an entry BasicDialog { id: renameDialog - property string entryDesc: "?" property int entryIndex: -1 property alias newEntryName: entryNameTextField.text @@ -123,9 +121,9 @@ Kirigami.ScrollablePage { // component representing a field Component { id: fieldsListDelegateComponent + RowLayout { id: fieldsListItem - width: fieldsSheet.width Kirigami.ListItemDragHandle { @@ -196,6 +194,7 @@ Kirigami.ScrollablePage { header: Kirigami.Heading { text: qsTr("Edit account ") + nativeInterface.currentAccountName } + ListView { id: fieldsListView implicitWidth: Kirigami.Units.gridUnit * 30 @@ -275,12 +274,21 @@ Kirigami.ScrollablePage { // list view to display one hierarchy level of entry model ListView { id: entriesListView - anchors.fill: parent - + moveDisplaced: Transition { + YAnimator { + duration: Kirigami.Units.longDuration + easing.type: Easing.InOutQuad + } + } model: DelegateModel { id: delegateModel + delegate: Kirigami.DelegateRecycler { + width: parent ? parent.width : implicitWidth + sourceComponent: listDelegateComponent + } + function isNode(rowNumber) { return entryModel.isNode(entryModel.index(rowNumber, 0, rootIndex)) @@ -295,18 +303,6 @@ Kirigami.ScrollablePage { fieldsSheet.open() } } - - delegate: Kirigami.DelegateRecycler { - width: parent ? parent.width : implicitWidth - sourceComponent: listDelegateComponent - } - } - - moveDisplaced: Transition { - YAnimator { - duration: Kirigami.Units.longDuration - easing.type: Easing.InOutQuad - } } } diff --git a/qml/PasswordDialog.qml b/qml/PasswordDialog.qml index 6e6be2c..e84b7c5 100644 --- a/qml/PasswordDialog.qml +++ b/qml/PasswordDialog.qml @@ -15,6 +15,21 @@ BasicDialog { standardButtons: canAccept ? Controls.Dialog.Ok | Controls.Dialog.Cancel : Controls.Dialog.Cancel title: qsTr("Enter password") + onAccepted: { + nativeInterface.password = password + if (newPassword) { + showPassiveNotification( + qsTr("The new password will be used when saving next time.")) + } else { + nativeInterface.load() + } + } + onRejected: { + if (newPassword) { + showPassiveNotification( + qsTr("You aborted. The password has not been altered.")) + } + } ColumnLayout { Controls.Label { @@ -50,40 +65,24 @@ BasicDialog { } } - onAccepted: { - nativeInterface.password = password - if (newPassword) { - showPassiveNotification( - qsTr("The new password will be used when saving next time.")) - } else { - nativeInterface.load() - } - } - - onRejected: { - if (newPassword) { - showPassiveNotification( - qsTr("You aborted. The password has not been altered.")) - } - } - function clear() { passwordTextField.text = "" repeatPasswordTextField.text = "" } - function askForPassword(instruction, newPassword) { - this.newPassword = newPassword + function askForPassword(instruction) { this.instruction = instruction - this.clear() - this.open() + clear() + open() } function askForExistingPassword(instruction) { - this.askForPassword(instruction, false) + newPassword = false + askForPassword(instruction) } function askForNewPassword(instruction) { - this.askForPassword(instruction, true) + newPassword = true + askForPassword(instruction) } } diff --git a/qml/main.qml b/qml/main.qml index 179b0e7..0239808 100644 --- a/qml/main.qml +++ b/qml/main.qml @@ -6,29 +6,96 @@ import org.kde.kirigami 2.4 as Kirigami Kirigami.ApplicationWindow { id: root - property alias showPasswordsOnFocus: showPasswordsOnFocusSwitch.checked + property var entriesComponent: undefined - function clearStack() { - pageStack.pop(root.pageStack.initialPage, Controls.StackView.Immediate) + header: Kirigami.ApplicationHeader { } + globalDrawer: Kirigami.GlobalDrawer { + id: leftMenu + title: qsTr("Password manager") + titleIcon: "passwordmanager" + topContent: ColumnLayout { + Layout.fillWidth: true - function pushStackEntry(entryModel, rootIndex) { - var title = entryModel.data(rootIndex) - var entriesComponent = Qt.createComponent("EntriesPage.qml") + Controls.MenuSeparator { + padding: 0 + topPadding: 8 + bottomPadding: 0 + Layout.fillWidth: true + } + Controls.Label { + padding: 8 + wrapMode: Controls.Label.Wrap + fontSizeMode: Text.HorizontalFit + minimumPixelSize: 10 + font.pixelSize: 20 + Layout.fillWidth: true + text: nativeInterface.fileOpen ? nativeInterface.fileName : qsTr( + "No file opened") + } + } + actions: [ + Kirigami.Action { + text: qsTr("Create new file") + iconName: "document-new" + onTriggered: fileDialog.createNew() + }, + Kirigami.Action { + text: qsTr("Open existing file") + iconName: "document-open" + onTriggered: fileDialog.openExisting() + }, + Kirigami.Action { + text: "Save modifications" + enabled: nativeInterface.fileOpen + iconName: "document-save" + onTriggered: nativeInterface.save() + }, + Kirigami.Action { + text: "Change password" + enabled: nativeInterface.fileOpen + iconName: "dialog-password" + onTriggered: enterPasswordDialog.askForNewPassword( + "Change password for " + nativeInterface.filePath) + }, + Kirigami.Action { + text: "Close file" + enabled: nativeInterface.fileOpen + iconName: "document-close" + onTriggered: nativeInterface.close() + } + ] + Controls.Switch { + id: showPasswordsOnFocusSwitch + text: qsTr("Show passwords on focus") + checked: true + } + + Controls.Label { + wrapMode: Controls.Label.Wrap + Layout.fillWidth: true + text: nativeInterface.fileOpen ? nativeInterface.filePath : qsTr( + "No file opened") + } + } + contextDrawer: Kirigami.ContextDrawer { + id: contextDrawer + } + Component.onCompleted: { + // load the entries component + entriesComponent = Qt.createComponent("EntriesPage.qml") if (entriesComponent.status !== Component.Ready) { var errorMessage = "Unable to load EntriesPage.qml: " + entriesComponent.errorString() showPassiveNotification(errorMessage) console.error(errorMessage) return } - var entriesPage = entriesComponent.createObject(root, { - main: root, - entryModel: entryModel, - rootIndex: rootIndex, - title: title - }) - pageStack.push(entriesPage) + + // load file if one has been specified via CLI argument + if (nativeInterface.filePath.length) { + nativeInterface.load() + } } PasswordDialog { @@ -77,16 +144,16 @@ Kirigami.ApplicationWindow { } onFileOpenChanged: { clearStack() - if (nativeInterface.fileOpen) { - var entryModel = nativeInterface.entryModel - var rootIndex = entryModel.index(0, 0) - pushStackEntry(entryModel, rootIndex) - showPassiveNotification(qsTr("%1 opened").arg( - nativeInterface.fileName)) - } else { + if (!nativeInterface.fileOpen) { showPassiveNotification(qsTr("%1 closed").arg( nativeInterface.fileName)) + return } + var entryModel = nativeInterface.entryModel + var rootIndex = entryModel.index(0, 0) + pushStackEntry(entryModel, rootIndex) + showPassiveNotification(qsTr("%1 opened").arg( + nativeInterface.fileName)) } onFileSaved: { showPassiveNotification(qsTr("%1 saved").arg( @@ -94,96 +161,17 @@ Kirigami.ApplicationWindow { } } - header: Kirigami.ApplicationHeader { - } - globalDrawer: Kirigami.GlobalDrawer { - id: leftMenu - title: qsTr("Password manager") - titleIcon: "passwordmanager" - - topContent: ColumnLayout { - Layout.fillWidth: true - - Controls.MenuSeparator { - padding: 0 - topPadding: 8 - bottomPadding: 0 - Layout.fillWidth: true - } - Controls.Label { - padding: 8 - wrapMode: Controls.Label.Wrap - fontSizeMode: Text.HorizontalFit - minimumPixelSize: 10 - font.pixelSize: 20 - Layout.fillWidth: true - text: { - if (nativeInterface.fileOpen) { - return nativeInterface.fileName - } else { - return qsTr("No file opened") - } - } - } - } - actions: [ - Kirigami.Action { - text: qsTr("Create new file") - iconName: "document-new" - onTriggered: fileDialog.createNew() - }, - Kirigami.Action { - text: qsTr("Open existing file") - iconName: "document-open" - onTriggered: fileDialog.openExisting() - }, - Kirigami.Action { - text: "Save modifications" - enabled: nativeInterface.fileOpen - iconName: "document-save" - onTriggered: nativeInterface.save() - }, - Kirigami.Action { - text: "Change password" - enabled: nativeInterface.fileOpen - iconName: "dialog-password" - onTriggered: enterPasswordDialog.askForNewPassword( - "Change password for " + nativeInterface.filePath) - }, - Kirigami.Action { - text: "Close file" - enabled: nativeInterface.fileOpen - iconName: "document-close" - onTriggered: nativeInterface.close() - } - ] - - Controls.Switch { - id: showPasswordsOnFocusSwitch - text: qsTr("Show passwords on focus") - checked: true - } - - Controls.Label { - wrapMode: Controls.Label.Wrap - Layout.fillWidth: true - text: { - if (nativeInterface.fileOpen) { - return nativeInterface.filePath - } else { - return qsTr("No file opened") - } - } - } - } - contextDrawer: Kirigami.ContextDrawer { - id: contextDrawer + function clearStack() { + pageStack.pop(root.pageStack.initialPage, Controls.StackView.Immediate) } - Component.onCompleted: { - // load file if one has been specified via CLI argument - if (nativeInterface.filePath.length) { - nativeInterface.load() - } + function pushStackEntry(entryModel, rootIndex) { + pageStack.push(entriesComponent.createObject(root, { + main: root, + entryModel: entryModel, + rootIndex: rootIndex, + title: entryModel.data( + rootIndex) + })) } }