Skip to content

Commit

Permalink
Resets navigation to home when coming back from a search. Ensures dar…
Browse files Browse the repository at this point in the history
…k theme correctly sets the icon value
  • Loading branch information
dannygb committed Jul 13, 2019
1 parent a2f5026 commit 4741ba0
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 84 deletions.
103 changes: 59 additions & 44 deletions KeePit/qml/ListEntryItems.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -56,10 +83,6 @@ Page {
}
}

// onCompleted: {
// themeAction.iconName = switchTheme()
// }

// Could be the name of the group
header: PageHeader {
id: pageHeader
Expand All @@ -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")
Expand All @@ -94,10 +118,7 @@ Page {
iconName: "home"
text: i18n.tr("Home")
onTriggered: {
database.loadHome()
previousDepth = null
pageStack.clear()
pageStack.push(listEntryItems)
goHome()
}
},
Action {
Expand Down Expand Up @@ -142,7 +163,7 @@ Page {
anchors.fill: parent
onClicked: onSelected(index, model)
}
}
}
}

SortFilterModel {
Expand All @@ -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
}
}
}
79 changes: 43 additions & 36 deletions KeePit/qml/Main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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) {
Expand All @@ -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()
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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")
}
}
15 changes: 13 additions & 2 deletions KeePit/qml/OpenDatabase.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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")
Expand Down
5 changes: 3 additions & 2 deletions KeePit/qml/Selector.qml
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ Page {
pageTitle = i18n.tr("Keys")
folderModel.nameFilters = ["*.*"]
importer.headerText = i18n.tr('Import key from')
actCreateDb.visible = false;
//actCreateDb.visible = false;
}

function setDatabaseMode() {
keyMode = false
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) {
Expand Down Expand Up @@ -243,6 +243,7 @@ Page {
}

Button {
visible: false
Layout.fillWidth: true
id: actCreateDb
iconName: "add"
Expand Down

0 comments on commit 4741ba0

Please sign in to comment.