passwordmanager/qml/main.qml

155 lines
4.8 KiB
QML
Raw Normal View History

import QtQuick 2.7
import QtQuick.Controls 2.1 as Controls
import QtQuick.Layouts 1.2
import QtQuick.Dialogs 1.3
import org.kde.kirigami 2.4 as Kirigami
2015-04-22 19:30:09 +02:00
Kirigami.ApplicationWindow {
2015-04-22 19:30:09 +02:00
id: root
function clearStack() {
pageStack.pop(root.pageStack.initialPage, Controls.StackView.Immediate)
2015-04-22 19:30:09 +02:00
}
function pushStackEntry(entryModel, rootIndex) {
var title = entryModel.data(rootIndex)
var 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
2015-04-22 19:30:09 +02:00
}
var entriesPage = entriesComponent.createObject(root, {
entryModel: entryModel,
rootIndex: rootIndex,
title: title
})
pageStack.push(entriesPage)
2015-04-22 19:30:09 +02:00
}
PasswordDialog {
id: enterPasswordDialog
2015-04-22 19:30:09 +02:00
}
FileDialog {
id: fileDialog
title: selectExisting ? qsTr("Select an existing file") : qsTr(
"Select path for new file")
onAccepted: {
if (fileUrls.length < 1) {
return
2015-04-22 19:30:09 +02:00
}
nativeInterface.filePath = fileUrls[0]
if (selectExisting) {
nativeInterface.load()
} else {
nativeInterface.create()
2015-04-22 19:30:09 +02:00
}
}
onRejected: {
showPassiveNotification("Canceled file selection")
}
function openExisting() {
this.selectExisting = true
this.open()
}
function createNew() {
this.selectExisting = false
this.open()
2015-04-22 19:30:09 +02:00
}
}
Connections {
target: nativeInterface
onFileError: {
showPassiveNotification(errorMessage)
}
onPasswordRequired: {
enterPasswordDialog.askForExistingPassword(
qsTr("Password required to open ") + filePath)
leftMenu.resetMenu()
}
onFileOpenChanged: {
clearStack()
if (!nativeInterface.fileOpen) {
return
2015-04-22 19:30:09 +02:00
}
var entryModel = nativeInterface.entryModel
var rootIndex = entryModel.index(0, 0)
pushStackEntry(entryModel, rootIndex)
2015-04-22 19:30:09 +02:00
}
}
header: Kirigami.ApplicationHeader {
}
globalDrawer: Kirigami.GlobalDrawer {
id: leftMenu
title: qsTr("Password manager")
titleIcon: "passwordmanager"
bannerImageSource: "banner.png"
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()
2015-04-22 19:30:09 +02:00
}
]
}
contextDrawer: Kirigami.ContextDrawer {
id: contextDrawer
}
pageStack.initialPage: mainPageComponent
// main app content
Component {
id: mainPageComponent
RowLayout {
spacing: 5
Controls.Label {
text: {
if (nativeInterface.fileOpen) {
return qsTr("The file %1 has been opened.").arg(
nativeInterface.filePath)
} else {
return qsTr("No file has been opened.")
}
2015-12-05 22:52:00 +01:00
}
2015-04-22 19:30:09 +02:00
}
}
}
Component.onCompleted: {
// load file if one has been specified via CLI argument
if (nativeInterface.filePath.length) {
nativeInterface.load()
2015-04-22 19:30:09 +02:00
}
}
}