From 6adf18caebd03ad0f80c3c6ccc10011f677f1bd3 Mon Sep 17 00:00:00 2001 From: Bent Witthold Date: Tue, 3 Feb 2026 11:17:26 +0100 Subject: [PATCH] Server settings are read from QSettings and applied if they are changed. --- genericcore.cpp | 23 ++++++++++++++++++++--- genericcore.h | 2 ++ network/apiroutes.h | 1 - network/servercommunicator.cpp | 10 +++++++++- network/servercommunicator.h | 6 ++++++ 5 files changed, 37 insertions(+), 5 deletions(-) diff --git a/genericcore.cpp b/genericcore.cpp index 44875c5..8a527f2 100644 --- a/genericcore.cpp +++ b/genericcore.cpp @@ -13,6 +13,7 @@ #include "CoreConfig.h" #include "constants.h" #include "data/filehandler.h" +#include "data/settingshandler.h" #include "model/generalsortfiltermodel.h" #include "model/metadata.h" #include "model/tablemodel.h" @@ -134,6 +135,14 @@ bool GenericCore::exportCSVFile(const QString& filePath) { return FileHandler::exportToCSVFile(itemsAsStringLists, filePath); } +void GenericCore::applySettings(QVariantMap settingMap, QString group) { + SettingsHandler::saveSettings(settingMap, group); + + if (group == "Server") { + setupServerConfiguration(); + } +} + bool GenericCore::isSyncServerSetup() const { if (m_serverCommunicator) { return true; @@ -254,7 +263,15 @@ void GenericCore::setupServerConfiguration() { connect(m_serverCommunicator.get(), &ServerCommunicator::deleteRequestFailure, this, &GenericCore::onDeleteRequestFailure); - /// fetching/posting items on startup to test the communication with the server - // m_serverCommunicator->fetchItems(); - // m_serverCommunicator->postItems(); + applyServerConfiguration(); +} + +void GenericCore::applyServerConfiguration() { + const QVariantMap serverSettings = SettingsHandler::getSettings("Server"); + const QString urlValue = serverSettings.value("url").toString(); + if (!urlValue.isEmpty()) { + const QString emailValue = serverSettings.value("email").toString(); + const QString passwordValue = serverSettings.value("password").toString(); + m_serverCommunicator->setServerConfiguration(urlValue, emailValue, passwordValue); + } } diff --git a/genericcore.h b/genericcore.h index f939692..1c39ef0 100644 --- a/genericcore.h +++ b/genericcore.h @@ -33,6 +33,7 @@ class GenericCore : public QObject { void importCSVFile(const QString& filePath); bool exportCSVFile(const QString& filePath); + void applySettings(QVariantMap settingMap, QString group = ""); bool isSyncServerSetup() const; public slots: @@ -65,6 +66,7 @@ class GenericCore : public QObject { /// Network communication std::unique_ptr m_serverCommunicator; void setupServerConfiguration(); + void applyServerConfiguration(); }; #endif // GENERICCORE_H diff --git a/network/apiroutes.h b/network/apiroutes.h index 70ef34e..e89da3a 100644 --- a/network/apiroutes.h +++ b/network/apiroutes.h @@ -5,7 +5,6 @@ // TODO add namespace -static const QString baseUrl = "http://127.0.0.1:4000"; static const QString apiPrefix = "/api/"; static const QString ROUTE_ITEMS = apiPrefix + "items"; diff --git a/network/servercommunicator.cpp b/network/servercommunicator.cpp index cab273e..7545e2e 100644 --- a/network/servercommunicator.cpp +++ b/network/servercommunicator.cpp @@ -13,7 +13,6 @@ ServerCommunicator::ServerCommunicator(QObject* parent) m_netManager.setAutoDeleteReplies(true); m_restManager = std::make_shared(&m_netManager); m_serviceApi = std::make_shared(); - setUrl(baseUrl); } bool ServerCommunicator::sslSupported() { @@ -96,3 +95,12 @@ void ServerCommunicator::deleteItem(const QString& id) { reply->deleteLater(); }); } + +void ServerCommunicator::setServerConfiguration(const QString url, + const QString email, + const QString password) { + setUrl(url); + + m_email = email; + m_password = password; +} diff --git a/network/servercommunicator.h b/network/servercommunicator.h index e364b6d..3107604 100644 --- a/network/servercommunicator.h +++ b/network/servercommunicator.h @@ -16,6 +16,8 @@ class ServerCommunicator : public QObject { QUrl url() const; void setUrl(const QUrl& url); + void setServerConfiguration(const QString url, const QString email, const QString password); + public slots: void fetchItems(); void postItems(const QByteArray& jsonData); @@ -35,6 +37,10 @@ class ServerCommunicator : public QObject { QNetworkAccessManager m_netManager; std::shared_ptr m_restManager; std::shared_ptr m_serviceApi; + + QString m_email; + QString m_password; + // QString m_authToken; }; #endif // SERVERCOMMUNICATOR_H