2020-07-11 21:03:58 +02:00
|
|
|
/****************************************************************************
|
|
|
|
** ScStw Libraries
|
|
|
|
** Copyright (C) 2020 Itsblue development
|
|
|
|
**
|
|
|
|
** 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/>.
|
|
|
|
****************************************************************************/
|
|
|
|
|
2020-07-10 15:20:13 +02:00
|
|
|
#include "../../headers/client/scstwremotesettings.h"
|
|
|
|
|
|
|
|
ScStwRemoteSettings::ScStwRemoteSettings(ScStwClient * scStwClient, QObject * parent) : ScStwSettings(parent)
|
|
|
|
{
|
|
|
|
this->scStwClient = scStwClient;
|
2020-07-11 11:17:20 +02:00
|
|
|
this->scStwClient->addSignalSubscription(ScStw::SettingChanged);
|
2020-07-10 15:20:13 +02:00
|
|
|
|
|
|
|
connect(this->scStwClient, &ScStwClient::gotSignal, this, &ScStwRemoteSettings::handleBaseStationSignal);
|
|
|
|
}
|
|
|
|
|
|
|
|
ScStwRemoteSettings::SettingsMode ScStwRemoteSettings::getMode() {
|
|
|
|
if(this->scStwClient->getState() == ScStwClient::CONNECTED)
|
|
|
|
return ScStwRemoteSettings::REMOTE;
|
|
|
|
else
|
|
|
|
return ScStwRemoteSettings::LOCAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
QVariant ScStwRemoteSettings::readSetting(QString key, int keyInt, int keyLevel) {
|
2020-07-11 20:30:04 +02:00
|
|
|
if(this->getMode() == LOCAL || keyLevel > ScStwSettings::KeyLevel)
|
2020-07-10 15:20:13 +02:00
|
|
|
return ScStwSettings::readSetting(key, keyInt, keyLevel);
|
|
|
|
|
|
|
|
return this->scStwClient->readRemoteSetting(ScStwSettings::BaseStationSetting(keyInt));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ScStwRemoteSettings::writeSetting(QString key, QVariant value, int keyInt, int keyLevel) {
|
2020-07-11 20:30:04 +02:00
|
|
|
if(this->getMode() == LOCAL || keyLevel > ScStwSettings::KeyLevel)
|
2020-07-10 15:20:13 +02:00
|
|
|
return ScStwSettings::writeSetting(key, value, keyInt, keyLevel);
|
|
|
|
|
2020-07-11 11:17:20 +02:00
|
|
|
ScStw::StatusCode res = this->scStwClient->writeRemoteSetting(ScStwSettings::BaseStationSetting(keyInt), value);
|
2020-07-10 15:20:13 +02:00
|
|
|
|
2020-07-11 11:17:20 +02:00
|
|
|
return res == ScStw::Success;
|
2020-07-10 15:20:13 +02:00
|
|
|
}
|
|
|
|
|
2020-07-11 20:30:04 +02:00
|
|
|
bool ScStwRemoteSettings::setDefaultSetting(QString key, QVariant defaultVariant, int keyInt, int keyLevel) {
|
|
|
|
if(this->getMode() == LOCAL || keyLevel > ScStwSettings::KeyLevel)
|
2020-07-10 15:20:13 +02:00
|
|
|
return ScStwSettings::setDefaultSetting(key, defaultVariant, keyInt, keyLevel);
|
|
|
|
|
2020-07-11 20:30:04 +02:00
|
|
|
return false;
|
2020-07-10 15:20:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void ScStwRemoteSettings::handleClientStateChange() {
|
|
|
|
if(this->scStwClient->getState() == ScStwClient::DISCONNECTED)
|
2020-07-11 14:00:31 +02:00
|
|
|
emit this->settingChanged(-1, 0, QVariant());
|
2020-07-10 15:20:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void ScStwRemoteSettings::handleBaseStationSignal(ScStw::SignalKey key, QVariant data) {
|
|
|
|
switch (key) {
|
|
|
|
case ScStw::SettingChanged:
|
2020-07-11 20:30:04 +02:00
|
|
|
emit this->settingChanged(data.toMap()["key"].toInt(), ScStwSettings::KeyLevel, data.toMap()["value"]);
|
2020-07-10 15:20:13 +02:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|