Files
pyqcrm/Gui/Firststart.qml
2025-02-27 08:52:33 +01:00

197 lines
4.7 KiB
QML

import QtQuick
import QtQuick.Layouts
import QtQuick.Controls
import QtQuick.Dialogs
import QtCore
import "../js/qmldict.js" as Qmldict
Item
{
property string recpass: ""
property bool adminAvailable: true
property alias recoverEnc: recoveryPaswordDialog
id: firstStartItem
anchors.fill: parent
StackView
{
id: firstStart
anchors.fill: parent
initialItem: "DbConfiguration.qml"
}
RowLayout
{
anchors.bottom: parent.bottom
anchors.margins: 9
width: parent.width
Item
{
Layout.fillWidth: true
}
Button
{
id: cancelBtn
text: qsTr("Abbrechen")
onClicked:
{
Qt.quit()
}
}
Button
{
id: submitBtn
text: qsTr("Speichern")
property var grids: firstStart.currentItem
property var pyqcrm_conf: ({})
property var admin: Boolean
onClicked:
{
if (firstStart.currentItem.name === "database")
{
pyqcrm_conf = Qmldict.firstConf(submitBtn.grids)
if (pyqcrm_conf)
{
config.setConfig(pyqcrm_conf)
}
}
else
{
pyqcrm_conf = Qmldict.firstConf(submitBtn.grids)
if (pyqcrm_conf) config.addAdminUser(pyqcrm_conf)
}
}
}
}
MessageDialog
{
id: recoveryDialog
text: qsTr("Diesen Wiederherstellungscode musst du sicher aufbewahren!\nMöchtest du das jetzt machen?")
title: qsTr("Wiederherstellen")
buttons: MessageDialog.Yes | MessageDialog.No
onAccepted: recoveryPaswordDialog.open()
onRejected: gotoLogin()
}
MessageDialog
{
id: conErrDialog
text: qsTr("Datenbankverbindung fehlgeschlagen")
title: qsTr("Datenbank Verbindung")
}
Dialog
{
id: recoveryPaswordDialog
modal: true
title: qsTr("Wiederherstellung")
anchors.centerIn: parent
standardButtons: Dialog.Ok | Dialog.Cancel
onAccepted:
{
recpass = recoveryPaswordInput.text
saveRecoveryDialog.open()
}
ColumnLayout
{
RowLayout
{
Label
{
text: qsTr("Wiederherstellungspasswort eingeben: ")
}
TextField
{
id: recoveryPaswordInput
text: ""
echoMode: TextInput.Password
implicitWidth: 300
placeholderText: qsTr("Hier Wiederherstellungspasswort eingeben")
}
Label
{
text: qsTr("Wiederherstellungspasswort eingeben: ")
}
TextField
{
id: repeatRecoveryPaswordInput
text: ""
echoMode: TextInput.Password
implicitWidth: 300
placeholderText: qsTr("Hier Wiederherstellungspasswort eingeben")
}
}
}
}
FileDialog
{
id: saveRecoveryDialog
title: qsTr("Wiederherstellungsdatei")
fileMode: adminAvailable? FileDialog.OpenFile: FileDialog.SaveFile
nameFilters: ["PYQCRM Recovery files (*.pyqrec)"]
currentFolder: StandardPaths.standardLocations(StandardPaths.DocumentsLocation)[0]
onAccepted:
{
if (!adminAvailable) config.saveRecoveryKey(saveRecoveryDialog.currentFile, recpass)
else config.getRecoveryKey(saveRecoveryDialog.currentFile, recpass)
gotoLogin()
}
onRejected:
{
if (adminAvailable) quit()
}
}
Component.onCompleted:
{
config.dbConnectionError.connect(onDbConnectionError)
config.adminUserError.connect(onAdminUserError)
config.backupEncryptionKey.connect(onBackupEncryptionKey)
}
function gotoLogin()
{
appLoader.source= "LoginScreen.qml"
topBar.visible = true
}
function onBackupEncryptionKey()
{
recoveryDialog.open()
}
function onDbConnectionError(msg, success)
{
if (!success)
conErrDialog.open()
}
function onAdminUserError(msg, success)
{
if (success)
{
recoveryPaswordDialog.open()
}
else
{
adminAvailable = false
firstStart.push("AdminUserConfig.qml")
}
}
}