From 0e8e03dc5de2f40e67ffa55a3dac59b012688bbe13de9d7a75d18fb579180ecd Mon Sep 17 00:00:00 2001 From: Daniel Stoppek Date: Wed, 20 Nov 2024 12:39:20 +0100 Subject: [PATCH] Changed DataBase to BusinessModel --- Gui/CustomerTables.qml | 2 +- Gui/main.qml | 42 +++++++++++++++++++++++++-- lib/{DataBase.py => BusinessModel.py} | 2 +- lib/ConfigLoader.py | 15 ++++++---- lib/__init__.py | 1 + main.py | 6 ++-- pyqcrm.pyproject | 2 +- 7 files changed, 55 insertions(+), 15 deletions(-) rename lib/{DataBase.py => BusinessModel.py} (96%) diff --git a/Gui/CustomerTables.qml b/Gui/CustomerTables.qml index 33ec91a..307912b 100644 --- a/Gui/CustomerTables.qml +++ b/Gui/CustomerTables.qml @@ -113,7 +113,7 @@ Item { Layout.fillWidth: true columnSpacing: 1 rowSpacing: 2 - model: dbm + model: bm alternatingRows: true resizableColumns: true // @disable-check M16 selectionBehavior: TableView.SelectRows diff --git a/Gui/main.qml b/Gui/main.qml index 52c39ae..428b352 100644 --- a/Gui/main.qml +++ b/Gui/main.qml @@ -12,6 +12,7 @@ ApplicationWindow height: Screen.height * .7 visible: true title: "PYQCRM" + property string confile: "" TopBar { @@ -71,10 +72,45 @@ ApplicationWindow { id: settingsFiledialog - title: qsTr("pyqcrm Einstellungen") + title: qsTr("PYQCRM Einstellungen") currentFolder: StandardPaths.standardLocations(StandardPaths.DocumentsLocation)[0] modality: "ApplicationModal" - nameFilters: ["pyqcrm Einstellungen (*.toml)"] - onAccepted: config.importConfig(selectedFile) + nameFilters: [qsTr("PYQCRM Einstellungen (*.pyqcrm)")] + onAccepted: + { + encryptPwDialog.open() + confile = selectedFile + } + } + Dialog + { + id: encryptPwDialog + modal: true + title: qsTr("PYQCRM Einstellungen") + anchors.centerIn: parent + standardButtons: Dialog.Ok | Dialog.Cancel + onAccepted: config.importConfig(confile, encryptPassword.text) + ColumnLayout + { + RowLayout + { + Label + { + text: qsTr("Passwort eingeben:") + } + + TextField + { + id: encryptPassword + echoMode: TextInput.Password + implicitWidth: 300 + } + } + + } + + + + } } diff --git a/lib/DataBase.py b/lib/BusinessModel.py similarity index 96% rename from lib/DataBase.py rename to lib/BusinessModel.py index e7769dc..eb4e7bc 100644 --- a/lib/DataBase.py +++ b/lib/BusinessModel.py @@ -4,7 +4,7 @@ from PySide6.QtCore import QAbstractTableModel, QModelIndex, Qt, Slot -class DataBase(QAbstractTableModel): +class BusinessModel(QAbstractTableModel): def __init__(self, con): super().__init__() diff --git a/lib/ConfigLoader.py b/lib/ConfigLoader.py index 3f06e15..990bf62 100644 --- a/lib/ConfigLoader.py +++ b/lib/ConfigLoader.py @@ -5,7 +5,7 @@ from pathlib import Path from PySide6.QtCore import QObject, Slot from .Vermasseln import Vermasseln import shutil - +from urllib.parse import urlparse class ConfigLoader(QObject): __config = None @@ -20,11 +20,14 @@ class ConfigLoader(QObject): else: config_dir.mkdir(0o750, True, True) - @Slot(str) - def importConfig(self, confile): - print(confile) - confile= confile.replace('file:///','') - shutil.copyfile(confile, self.config_dir+ '/pyqcrm.toml') + @Slot(str, str) + def importConfig(self, confile, password): + print(password) + + confile = urlparse(confile) + print(confile.path) + #confile= confile.replace('file://','') + shutil.copyfile(confile.path, self.config_dir+ '/pyqcrm.toml') @Slot(dict) def setConfig(self, app_config): diff --git a/lib/__init__.py b/lib/__init__.py index 7f1fccf..5c3efa1 100644 --- a/lib/__init__.py +++ b/lib/__init__.py @@ -1 +1,2 @@ from .ConfigLoader import ConfigLoader +from .BusinessModel import BusinessModel diff --git a/main.py b/main.py index 07fed73..193f702 100644 --- a/main.py +++ b/main.py @@ -5,7 +5,7 @@ from PySide6.QtGui import QGuiApplication from PySide6.QtQml import QQmlApplicationEngine from PySide6.QtCore import QResource from lib.ConfigLoader import ConfigLoader -from lib.DataBase import DataBase +from lib.BusinessModel import BusinessModel import rc_pyqcrm import rc_qml import sqlite3 @@ -56,13 +56,13 @@ if __name__ == "__main__": config = ConfigLoader() con = testConnection() - dbm = DataBase(con) + bm = BusinessModel(con) if not config.getConfig(): bad_config = True - engine.rootContext().setContextProperty("dbm", dbm) + engine.rootContext().setContextProperty("bm", bm) engine.rootContext().setContextProperty("bad_config", bad_config) # print(f"Fehler: {i}") engine.rootContext().setContextProperty("config", config) engine.load(qml_file) diff --git a/pyqcrm.pyproject b/pyqcrm.pyproject index fbd53dd..d3bd7d2 100644 --- a/pyqcrm.pyproject +++ b/pyqcrm.pyproject @@ -11,7 +11,7 @@ "Gui/CustomerTables.qml", "Gui/SearchBar.qml", "Gui/test.qml", - "lib/DataBase.py", + "lib/BusinessModel.py", "Gui/EmployeTables.qml", "Gui/AddCustomer.qml", "pyqcrm.qrc",