From 4741ba0ca0cfdfa0d97dc6fef315bf05d526a73a Mon Sep 17 00:00:00 2001 From: dannygb Date: Sat, 13 Jul 2019 19:31:47 +0100 Subject: [PATCH] Resets navigation to home when coming back from a search. Ensures dark theme correctly sets the icon value --- KeePit/qml/ListEntryItems.qml | 103 +++++++++++++++++++--------------- KeePit/qml/Main.qml | 79 ++++++++++++++------------ KeePit/qml/OpenDatabase.qml | 15 ++++- KeePit/qml/Selector.qml | 5 +- 4 files changed, 118 insertions(+), 84 deletions(-) diff --git a/KeePit/qml/ListEntryItems.qml b/KeePit/qml/ListEntryItems.qml index 0fe5cbd..43faa7d 100644 --- a/KeePit/qml/ListEntryItems.qml +++ b/KeePit/qml/ListEntryItems.qml @@ -25,27 +25,54 @@ import KeePass3 1.0 Page { - /** - * Handles the MouseArea.onClicked event of the entryDelegate - */ - function onSelected(index, model) { - // A variable property on Database (Main.qml) - database.selectedEntry = model; + property alias actTheme: themeAction + property alias pageHeaderTitle: pageHeader.title + + property var searching: false + + function setPageHeader(selectedEntry) { + console.debug("ListEntryItems: " + selectedEntry.title) + pageHeader.title = !selectedEntry.title + ? i18n.tr(appTitle) + : selectedEntry.title + } + function setPreviousEntry(selectedEntry) { // A variable property on MainView (Main.qml) previousEntry = { entryType : database.selectedEntry.entryType, - UUID : database.selectedEntry.uuid + UUID : database.selectedEntry.uuid, + title: database.selectedEntry.title, + searching: searching } + } + + function resetSearchingState() { + searching = false + } + function handlePageStack(selectedEntry) { // See PageStack.onDepthChanged for how the pageStack and entry model are kept in synch - if(database.selectedEntry.entryType === 2) { // is a password entry so push password page + if(selectedEntry.entryType === 2) { // is a password entry so push password page pageStack.push(entry); - } else if(database.selectedEntry.entryType === 1) { // is a further branch push another level + } else if(selectedEntry.entryType === 1) { // is a further branch push another level pageStack.push(listEntryItems); - } + } + } - listView.currentIndex = index; + /** + * Handles the MouseArea.onClicked event of the entryDelegate + */ + function onSelected(index, model) { + // A variable property on Database (Main.qml) + database.selectedEntry = model; + + setPageHeader(database.selectedEntry) + setPreviousEntry(database.selectedEntry) + resetSearchingState() + handlePageStack(database.selectedEntry) + + listView.currentIndex = index; } function getIconName(model) { @@ -56,10 +83,6 @@ Page { } } - // onCompleted: { - // themeAction.iconName = switchTheme() - // } - // Could be the name of the group header: PageHeader { id: pageHeader @@ -79,11 +102,12 @@ Page { Action { id: themeAction iconName: "" - text: i18n.tr("Swap") + text: i18n.tr("Swap") onTriggered: { switchTheme() - //iconName = iconName == "torch-off" ? "torch-on" : "torch-off" - } + themeAction.iconName = getTheme() + saveTheme() + } }, /*Action { text: i18n.tr("Settings") @@ -94,10 +118,7 @@ Page { iconName: "home" text: i18n.tr("Home") onTriggered: { - database.loadHome() - previousDepth = null - pageStack.clear() - pageStack.push(listEntryItems) + goHome() } }, Action { @@ -142,7 +163,7 @@ Page { anchors.fill: parent onClicked: onSelected(index, model) } - } + } } SortFilterModel { @@ -157,31 +178,25 @@ Page { id: search width: parent.width placeholderText: i18n.tr("Enter a search term") - hasClearButton: false + hasClearButton: true onAccepted: { - database.search(search.text) - } - secondaryItem: Row { - Button { - height: parent.height - width: height - iconName: "clear" - onClicked: { - search.text = "" - database.loadHome() - } + if(search.text == "") { + goHome() + } else { + database.search(search.text) + searching = true } - } + } } - UbuntuListView { - id: listView - height: parent.height - width: parent.width - spacing: 5 - model: sortedEntries - delegate: entryDelegate - focus: true + UbuntuListView { + id: listView + height: parent.height + width: parent.width + spacing: 5 + model: sortedEntries + delegate: entryDelegate + focus: true } } } diff --git a/KeePit/qml/Main.qml b/KeePit/qml/Main.qml index 1a1e630..8a03ee6 100644 --- a/KeePit/qml/Main.qml +++ b/KeePit/qml/Main.qml @@ -39,9 +39,6 @@ MainView { when the device is rotated. The default is false. */ automaticOrientation: true - //backgroundColor: "#000" - //headerColor: "#000" - property string appLocation: '/home/phablet/.local/share/keepit.dannygb/Documents' property string appTitle: 'KeePit' width: units.gu(100) @@ -55,6 +52,22 @@ MainView { property date currentDate: new Date() property var locale: Qt.locale() property var selectedDatabaseToDelete: ({}); + property var pageTitleStack: []; + + function goHome() { + database.loadHome() + previousDepth = null + pageTitleStack.length = 0 + listEntryItems.searching = false + pageStack.clear() + pageStack.push(listEntryItems) + } + + Component.onCompleted: { + readTheme() + openDatabase.actTheme.iconName = getTheme() + listEntryItems.actTheme.iconName = getTheme() + } Database { id: database @@ -71,9 +84,8 @@ MainView { PageStack { id: pageStack - Component.onCompleted: { - theme.name = settings.getSetting("theme") - push(databaseListView) + Component.onCompleted: { + push(databaseListView) } onCurrentPageChanged: { if(currentPage != null) { @@ -90,11 +102,21 @@ MainView { if(previousEntry.UUID !== undefined) { if(previousDepth > depth) { // Backwards previousEntry.UUID = database.reloadBranch(previousEntry.UUID, previousEntry.entryType) + pageTitleStack.pop() + if(previousEntry.searching) { + goHome() + } } else if(previousDepth < depth) { // Forwards database.selectBranch(previousEntry.UUID); + pageTitleStack.push(previousEntry.title) } - } + } + + console.debug("Main: " + pageTitleStack[pageTitleStack.length-1]) + listEntryItems.pageHeaderTitle = pageTitleStack.length > 0 + ? pageTitleStack[pageTitleStack.length-1] + : i18n.tr(appTitle) } resetLogoutTimer() @@ -133,30 +155,7 @@ MainView { id: settings } } - - /*Component { - id: settingsDisabledComponent - - Dialog { - id: settingsDisabledDialog - title: i18n.tr("Settings") - - Button { - color: UbuntuColors.orange - text: i18n.tr("Close Database") - onClicked: { - PopupUtils.close(settingsDisabledDialog) - reset() - } - } - - Button { - text: i18n.tr("Cancel") - onClicked: PopupUtils.close(settingsDisabledDialog) - } - } - }*/ - + Component { id: dialog Dialog { @@ -250,15 +249,23 @@ MainView { //resetTimer.restart(); } + function getTheme() { + return (theme.name == "Ubuntu.Components.Themes.SuruDark") + ? "torch-off" + : "torch-on" + } + function switchTheme() { theme.name = (theme.name == "Ubuntu.Components.Themes.SuruDark") ? "Ubuntu.Components.Themes.Ambiance" - : "Ubuntu.Components.Themes.SuruDark" + : "Ubuntu.Components.Themes.SuruDark" + } + function saveTheme() { settings.saveSetting("theme", theme.name); + } - return (theme.name == "Ubuntu.Components.Themes.SuruDark") - ? "torch-off" - : "torch-on" - } + function readTheme() { + theme.name = settings.getSetting("theme") + } } diff --git a/KeePit/qml/OpenDatabase.qml b/KeePit/qml/OpenDatabase.qml index 23744dc..fc0a190 100644 --- a/KeePit/qml/OpenDatabase.qml +++ b/KeePit/qml/OpenDatabase.qml @@ -28,8 +28,9 @@ import Ubuntu.Components.ListItems 1.3 as ListItem import Qt.labs.folderlistmodel 2.1 Page { - property alias pass: password; - property alias cmbKeySelector: combo; + property alias pass: password + property alias cmbKeySelector: combo + property alias actTheme: themeAction header: PageHeader { id: pageHeader @@ -41,6 +42,16 @@ Page { text: i18n.tr("About") onTriggered: PopupUtils.open(about) }, + Action { + id: themeAction + iconName: "" + text: i18n.tr("Swap") + onTriggered: { + switchTheme() + themeAction.iconName = getTheme() + saveTheme() + } + }, Action { iconName: "import" text: i18n.tr("Import key") diff --git a/KeePit/qml/Selector.qml b/KeePit/qml/Selector.qml index 6c4d94d..6e8028c 100644 --- a/KeePit/qml/Selector.qml +++ b/KeePit/qml/Selector.qml @@ -38,7 +38,7 @@ Page { pageTitle = i18n.tr("Keys") folderModel.nameFilters = ["*.*"] importer.headerText = i18n.tr('Import key from') - actCreateDb.visible = false; + //actCreateDb.visible = false; } function setDatabaseMode() { @@ -46,7 +46,7 @@ Page { pageTitle = appTitle + " - " + i18n.tr("Databases") folderModel.nameFilters = ["*.kdbx"] importer.headerText = i18n.tr('Import database from') - actCreateDb.visible = true; + //actCreateDb.visible = true; } function onDatabaseSelected(index, model) { @@ -243,6 +243,7 @@ Page { } Button { + visible: false Layout.fillWidth: true id: actCreateDb iconName: "add"