72 lines
1.5 KiB
C++
72 lines
1.5 KiB
C++
#include "settingsservice.h"
|
|
|
|
namespace Defaults {
|
|
|
|
constexpr auto GuestUserId = "2641ffe8cd4311eda27f0242ac120002";
|
|
constexpr auto ServerAddress = "195.133.196.161:8000";
|
|
|
|
}
|
|
|
|
namespace Keys {
|
|
|
|
constexpr auto ServerAddress = "server_address";
|
|
constexpr auto SelectedUser = "selected_user";
|
|
constexpr auto SelectedStore = "selected_store";
|
|
|
|
}
|
|
|
|
QVariant SettingsService::value(const QString &key, const QVariant &defaultValue) const
|
|
{
|
|
return m_settings.value(key, defaultValue);
|
|
}
|
|
|
|
void SettingsService::setValue(const QString &key, const QVariant &value)
|
|
{
|
|
m_settings.setValue(key, value);
|
|
}
|
|
|
|
QString SettingsService::serverAddress() const
|
|
{
|
|
return value(Keys::ServerAddress, Defaults::ServerAddress).toString();
|
|
}
|
|
|
|
void SettingsService::setServerAddress(const QString &address)
|
|
{
|
|
if (serverAddress() == address) {
|
|
return;
|
|
}
|
|
|
|
setValue(Keys::ServerAddress, address);
|
|
emit serverAddressChanged();
|
|
}
|
|
|
|
QString SettingsService::selectedUserId() const
|
|
{
|
|
return value(Keys::SelectedUser, Defaults::GuestUserId).toString();
|
|
}
|
|
|
|
void SettingsService::setSelectedUserId(const QString &userId)
|
|
{
|
|
if (selectedUserId() == userId) {
|
|
return;
|
|
}
|
|
|
|
setValue(Keys::SelectedUser, userId);
|
|
emit selectedUserIdChanged();
|
|
}
|
|
|
|
QString SettingsService::selectedStoreId() const
|
|
{
|
|
return value(Keys::SelectedStore).toString();
|
|
}
|
|
|
|
void SettingsService::setSelectedStoreId(const QString &storeId)
|
|
{
|
|
if (selectedStoreId() == storeId) {
|
|
return;
|
|
}
|
|
|
|
setValue(Keys::SelectedStore, storeId);
|
|
emit selectedStoreIdChanged();
|
|
}
|