Server settings are read from QSettings and applied if they are changed.

This commit is contained in:
2026-02-03 11:17:26 +01:00
parent d4ff1ffb61
commit 6adf18caeb
5 changed files with 37 additions and 5 deletions

View File

@ -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);
}
}

View File

@ -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<ServerCommunicator> m_serverCommunicator;
void setupServerConfiguration();
void applyServerConfiguration();
};
#endif // GENERICCORE_H

View File

@ -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";

View File

@ -13,7 +13,6 @@ ServerCommunicator::ServerCommunicator(QObject* parent)
m_netManager.setAutoDeleteReplies(true);
m_restManager = std::make_shared<QRestAccessManager>(&m_netManager);
m_serviceApi = std::make_shared<QNetworkRequestFactory>();
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;
}

View File

@ -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<QRestAccessManager> m_restManager;
std::shared_ptr<QNetworkRequestFactory> m_serviceApi;
QString m_email;
QString m_password;
// QString m_authToken;
};
#endif // SERVERCOMMUNICATOR_H