Files
thehub/pos/HubConfig.cpp
T
TomZ 32c45610cd Further fixes for cashier / PoS
Also upgrade the cashier app with logging, ctrl-c catching
and debug + version command line arguments.

Last, this checks the server version and exits if the Hub
version is too old.
2019-05-08 09:07:17 +02:00

80 lines
2.0 KiB
C++

/*
* This file is part of the Flowee project
* Copyright (C) 2018 Tom Zander <tomz@freedommail.ch>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "HubConfig.h"
#include <NetworkManager.h>
#include <Logger.h>
#include <qsettings.h>
const char * HubConfig::GROUP_ID = "server";
const char * HubConfig::KEY_SERVER_HOSTNAME = "hostname";
const char * HubConfig::KEY_SERVER_PORT = "port";
static void set(const char *key, const QVariant &value)
{
QSettings settings;
settings.beginGroup(HubConfig::GROUP_ID);
settings.setValue(key, value);
}
HubConfig::HubConfig(QObject *parent) : QObject(parent), m_port(1235)
{
}
QString HubConfig::server() const
{
return m_server;
}
void HubConfig::setServer(const QString &server)
{
if (m_server == server)
return;
m_server = server;
set(KEY_SERVER_HOSTNAME, server);
emit serverChanged();
}
int HubConfig::port() const
{
return m_port;
}
void HubConfig::setPort(int port)
{
if (m_port == port)
return;
m_port = port;
set(KEY_SERVER_PORT, port);
emit portChanged();
}
EndPoint HubConfig::readEndPoint(NetworkManager *manager)
{
Q_ASSERT(manager);
QSettings settings;
settings.beginGroup(GROUP_ID);
EndPoint ep;
ep.announcePort = settings.value(KEY_SERVER_PORT, 1235).toInt();
ep.hostname = settings.value(KEY_SERVER_HOSTNAME, "127.0.0.1").toString().toStdString();
return ep;
}