Programm-Einstellungen anlegen

This commit is contained in:
2024-10-30 17:42:25 +01:00
parent d3b99320dd
commit 8369c31c91
4 changed files with 52 additions and 26 deletions

View File

@@ -213,6 +213,10 @@ Item
{ {
id: cancelBtn id: cancelBtn
text: qsTr("Abbrechen") text: qsTr("Abbrechen")
onClicked:
{
Qt.quit()
}
} }
Button Button
@@ -220,7 +224,7 @@ Item
id: submitBtn id: submitBtn
text: qsTr("Weiter") text: qsTr("Weiter")
property var grids: [createUserGrid, dbGrid] property var grids: [createUserGrid, dbGrid]
property var dict: ({}) property var pyqcrm_conf: ({})
onClicked: onClicked:
{ {
if (bar.itemAt(bar.currentIndex) !== dbTab) if (bar.itemAt(bar.currentIndex) !== dbTab)
@@ -232,17 +236,17 @@ Item
else else
{ {
dict = Qmldict.func(submitBtn.grids) pyqcrm_conf = Qmldict.func(submitBtn.grids)
console.log(dict) if (pyqcrm_conf)
if (dict) {
config.setConfig(dict) config.setConfig(pyqcrm_conf)
appLoader.source = "start.qml" appLoader.source = "start.qml"
} }
} }
} }
} }
} }
}
Component.onCompleted: Component.onCompleted:
{ {

View File

@@ -9,8 +9,8 @@ Item
Component.onCompleted: Component.onCompleted:
{ {
appLoader.window.title = "pyqcrm" appLoader.window.title = "pyqcrm"
appLoader.window.height = Screen.height appLoader.window.height = Screen.height * .5
appLoader.window.width = Screen.width appLoader.window.width = Screen.width * .5
} }

View File

@@ -1,31 +1,27 @@
.pragma library .pragma library
var dict = new Object() function func(tabs)
{
let pyqcrm_conf = {};
function func(createUserGrid) for (var j = 0; j < tabs.length; j++)
{ {
for (var j = 0; j < createUserGrid.length; j++) for (var i = 0; i < tabs[j].children.length; i++)
{
for (var i = 0; i < createUserGrid[j].children.length; i++)
{ {
if (createUserGrid[j].children[i].name) if (tabs[j].children[i].name)
{ {
if (!createUserGrid[j].children[i].text.trim()) if (!tabs[j].children[i].text.trim())
return false return false
pyqcrm_conf[tabs[j].children[i].name] = tabs[j].children[i].text
// dict.set(createUserGrid[j].children[i].name , createUserGrid[j].children[i].text)
dict[createUserGrid[j].children[i].name] = createUserGrid[j].children[i].text
} }
} }
} }
return dict
return pyqcrm_conf
} }

View File

@@ -13,13 +13,39 @@ class ConfigLoader(QObject):
self.config_dir = user_config_dir() + '/pyqcrm' #user_config_dir = Funktion platformdirs self.config_dir = user_config_dir() + '/pyqcrm' #user_config_dir = Funktion platformdirs
config_dir = Path(self.config_dir) config_dir = Path(self.config_dir)
config_dir.mkdir(0o750, True, True) if config_dir.exists():
self.__configLoad() self.__configLoad()
else:
config_dir.mkdir(0o750, True, True)
@Slot(str) @Slot(dict)
def setConfig(self, app_config): def setConfig(self, app_config):
pyqcrm = '[pyqcrm]\n'
db = '[database]\n'
for k, v in app_config.items():
if k == 'username':
pyqcrm = pyqcrm + f"PYQCRM_ADMIN = \"{v}\"\n"
elif k == 'password':
pyqcrm = pyqcrm + f"PYQCRM_ADMIN_PASS = \"{v}\"\n"
elif k == 'db-host':
db = db + f"DB_HOST = \"{v}\"\n"
elif k == 'db-name':
db = db + f"DB_PORT = \"{v}\"\n"
elif k == 'db-port':
db = db + f"DB_NAME = \"{v}\"\n"
elif k == 'db-username':
db = db + f"DB_USER = \"{v}\"\n"
elif k == 'db-password':
db = db + f"DB_PASS = \"{v}\"\n"
appconf = pyqcrm + '\n' + db + '\n'
try:
with open (self.config_dir + '/pyqcrm.toml', 'w') as f:
f.write(appconf)
except FileNotFoundError:
print("Konnte die Konfiguration nicht speichern.")
print (type(app_config))
def __configLoad(self): def __configLoad(self):