refs #198, updated network settings so they can read/write JSON and be used with persistent settings

This commit is contained in:
Klaus Basan
2014-04-01 12:20:28 +02:00
parent f3148fdd49
commit 4a180fc27f
2 changed files with 102 additions and 22 deletions

View File

@@ -1,4 +1,5 @@
#include "setnetwork.h"
#include "blackcore/dbus_server.h"
#include "blackmisc/blackmiscfreefunctions.h"
#include "blackmisc/statusmessagelist.h"
#include "blackmisc/settingutilities.h"
@@ -12,7 +13,9 @@ namespace BlackMisc
/*
* Constructor
*/
CSettingsNetwork::CSettingsNetwork()
CSettingsNetwork::CSettingsNetwork() :
m_bookingServiceUrl("http://vatbook.euroutepro.com/xml2.php"),
m_dbusServerAddress(BlackCore::CDBusServer::sessionDBusServer())
{
// settings
}
@@ -48,7 +51,6 @@ namespace BlackMisc
bool CSettingsNetwork::isA(int metaTypeId) const
{
if (metaTypeId == qMetaTypeId<CSettingsNetwork>()) { return true; }
return this->CValueObject::isA(metaTypeId);
}
@@ -58,29 +60,23 @@ namespace BlackMisc
int CSettingsNetwork::compareImpl(const CValueObject &otherBase) const
{
const auto &other = static_cast<const CSettingsNetwork &>(otherBase);
int result;
if ((result = compare(this->m_trafficNetworkServerCurrent, other.m_trafficNetworkServerCurrent))) { return result; }
if ((result = compare(this->m_trafficNetworkServers, other.m_trafficNetworkServers))) { return result; }
return 0;
return compare(TupleConverter<CSettingsNetwork>::toTuple(*this), TupleConverter<CSettingsNetwork>::toTuple(other));
}
/*
* Marshall to DBus
* Marshall
*/
void CSettingsNetwork::marshallToDbus(QDBusArgument &argument) const
{
argument << this->m_trafficNetworkServerCurrent;
argument << this->m_trafficNetworkServers;
argument << TupleConverter<CSettingsNetwork>::toTuple(*this);
}
/*
* Unmarshall from DBus
* Unmarshall
*/
void CSettingsNetwork::unmarshallFromDbus(const QDBusArgument &argument)
{
argument >> this->m_trafficNetworkServerCurrent;
argument >> this->m_trafficNetworkServers;
argument >> TupleConverter<CSettingsNetwork>::toTuple(*this);
}
/*
@@ -105,9 +101,45 @@ namespace BlackMisc
*/
uint CSettingsNetwork::getValueHash() const
{
QList<uint> hashs;
hashs << qHash(this->m_trafficNetworkServers);
return BlackMisc::calculateHash(hashs, "CSettingsNetwork");
return qHash(TupleConverter<CSettingsNetwork>::toTuple(*this));
}
/*
* To JSON
*/
QJsonObject CSettingsNetwork::toJson() const
{
return BlackMisc::serializeJson(CSettingsNetwork::jsonMembers(), TupleConverter<CSettingsNetwork>::toTuple(*this));
}
/*
* From JSON
*/
void CSettingsNetwork::fromJson(const QJsonObject &json)
{
BlackMisc::deserializeJson(json, CSettingsNetwork::jsonMembers(), TupleConverter<CSettingsNetwork>::toTuple(*this));
}
/*
* Members
*/
const QStringList &CSettingsNetwork::jsonMembers()
{
return TupleConverter<CSettingsNetwork>::jsonMembers();
}
/*
* Default values
*/
void CSettingsNetwork::initDefaultValues()
{
CServer currentServer(CServer("Testserver", "Client project testserver", "vatsim-germany.org", 6809, CUser("guest", "Guest Client project", "", "guest")));
this->setCurrentNetworkServer(currentServer);
this->addTrafficNetworkServer(this->getCurrentTrafficNetworkServer());
this->addTrafficNetworkServer(CServer("Europe C2", "VATSIM Server", "88.198.19.202", 6809, CUser("vatsimid", "Black Client", "", "vatsimpw")));
this->addTrafficNetworkServer(CServer("Europe CC", "VATSIM Server", "5.9.155.43", 6809, CUser("vatsimid", "Black Client", "", "vatsimpw")));
this->addTrafficNetworkServer(CServer("UK", "VATSIM Server", "109.169.48.148", 6809, CUser("vatsimid", "Black Client", "", "vatsimpw")));
this->addTrafficNetworkServer(CServer("USA-W", "VATSIM Server", "64.151.108.52", 6809, CUser("vatsimid", "Black Client", "", "vatsimpw")));
}
/*
@@ -152,8 +184,24 @@ namespace BlackMisc
msgs.push_back(CStatusMessage::getInfoMessage("set current server", CStatusMessage::TypeSettings));
return msgs;
}
else if (path == CSettingsNetwork::ValueBookingServiceUrl())
{
if (command == CSettingUtilities::CmdUpdate())
{
QString v = value.toString();
if (this->m_bookingServiceUrl == v)
{
msgs.push_back(CSettingUtilities::valueNotChangedMessage("booking URL"));
}
else
{
changedFlag = true;
msgs.push_back(CSettingUtilities::valueChangedMessage("booking URL"));
}
return msgs;
}
}
return CSettingUtilities::wrongPathMessages(path);
}
} // namespace
} // namespace

View File

@@ -3,10 +3,6 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/*!
\file
*/
#ifndef BLACKMISC_SETTINGS_SERVER_H
#define BLACKMISC_SETTINGS_SERVER_H
@@ -14,7 +10,7 @@
#include "valueobject.h"
#include "statusmessagelist.h"
#include "settingutilities.h"
#include <QJsonObject>
namespace BlackMisc
{
@@ -45,6 +41,20 @@ namespace BlackMisc
return value;
}
//! \brief Path
static const QString &ValueBookingServiceUrl()
{
static const QString value("bookingserviceurl");
return value;
}
//! \brief Path
static const QString &ValueDBusServerAddress()
{
static const QString value("dbuserveraddress");
return value;
}
//! \copydoc CValueObject::toQVariant()
virtual QVariant toQVariant() const override
{
@@ -58,6 +68,10 @@ namespace BlackMisc
BlackMisc::Network::CServer getCurrentTrafficNetworkServer() const { return m_trafficNetworkServerCurrent; }
//! \brief URL of booking service
QString getBookingServiceUrl() const { return m_bookingServiceUrl; }
//! \brief Address for DBus Server
QString getDBusServerAddress() const { return m_dbusServerAddress; }
//! \brief Selected traffic network server
bool setCurrentNetworkServer(const BlackMisc::Network::CServer &currentServer);
@@ -77,8 +91,21 @@ namespace BlackMisc
//! \copydoc CValueObject::getValueHash
virtual uint getValueHash() const override;
//! \copydoc CValueObject::toJson
virtual QJsonObject toJson() const override;
//! \copydoc CValueObject::fromJson
virtual void fromJson(const QJsonObject &json) override;
//! \brief init with meaningful default values
void initDefaultValues();
//! \brief Register metadata
static void registerMetadata();
//! \copydoc TupleConverter<>::jsonMembers()
static const QStringList &jsonMembers();
protected:
//! \copydoc CValueObject::convertToQString
virtual QString convertToQString(bool i18n = false) const override;
@@ -99,13 +126,18 @@ namespace BlackMisc
virtual void unmarshallFromDbus(const QDBusArgument &argument) override;
private:
BLACK_ENABLE_TUPLE_CONVERSION(CSettingsNetwork)
BlackMisc::Network::CServerList m_trafficNetworkServers;
BlackMisc::Network::CServer m_trafficNetworkServerCurrent;
QString m_bookingServiceUrl;
QString m_dbusServerAddress;
};
} // namespace
} // namespace
Q_DECLARE_METATYPE(BlackMisc::Settings::CSettingsNetwork)
BLACK_DECLARE_TUPLE_CONVERSION(BlackMisc::Settings::CSettingsNetwork, (o.m_trafficNetworkServers, o.m_trafficNetworkServerCurrent, o.m_bookingServiceUrl, o.m_dbusServerAddress))
#endif // guard