diff --git a/src/blackcore/context_settings.h b/src/blackcore/context_settings.h index 95423decb..686faa8e5 100644 --- a/src/blackcore/context_settings.h +++ b/src/blackcore/context_settings.h @@ -11,11 +11,9 @@ #include "blackinput/keyboard.h" #include "blackmisc/hwkeyboardkeylist.h" #include "blackmisc/statusmessagelist.h" -#include "blackmisc/settingutilities.h" -#include "blackmisc/setnetwork.h" -#include "blackmisc/setaudio.h" #include "blackmisc/dbus.h" #include "blackmisc/variant.h" +#include "blackcore/settingsallclasses.h" #include #include @@ -38,7 +36,8 @@ namespace BlackCore { SettingsHotKeys, SettingsNetwork, - SettingsAudio + SettingsAudio, + SettingsSimulator }; protected: @@ -82,6 +81,13 @@ namespace BlackCore return s; } + //! Path for simulator settings + static const QString &PathSimulatorSettings() + { + static QString s("simulator"); + return s; + } + //! Root path static const QString &PathRoot() { @@ -123,6 +129,9 @@ namespace BlackCore //! Audio settings virtual BlackMisc::Settings::CSettingsAudio getAudioSettings() const = 0; + //! Audio settings + virtual BlackSim::Settings::CSettingsSimulator getSimulatorSettings() const = 0; + //! Hotkeys virtual BlackMisc::Hardware::CKeyboardKeyList getHotkeys() const = 0; diff --git a/src/blackcore/context_settings_impl.cpp b/src/blackcore/context_settings_impl.cpp index 742d49e9d..35f161862 100644 --- a/src/blackcore/context_settings_impl.cpp +++ b/src/blackcore/context_settings_impl.cpp @@ -15,6 +15,7 @@ using namespace BlackMisc; using namespace BlackMisc::Settings; using namespace BlackMisc::Network; using namespace BlackMisc::Hardware; +using namespace BlackSim::Settings; namespace BlackCore { @@ -62,7 +63,7 @@ namespace BlackCore if (jsonObject.contains(IContextSettings::PathAudioSettings())) { this->m_settingsAudio.fromJson( - jsonObject.value(IContextSettings::PathNetworkSettings()).toObject() + jsonObject.value(IContextSettings::PathAudioSettings()).toObject() ); } else @@ -70,6 +71,18 @@ namespace BlackCore this->m_settingsAudio.initDefaultValues(); } + // init simulator + if (jsonObject.contains(IContextSettings::PathSimulatorSettings())) + { + this->m_settingsSimulator.fromJson( + jsonObject.value(IContextSettings::PathSimulatorSettings()).toObject() + ); + } + else + { + this->m_settingsSimulator.initDefaultValues(); + } + // init own members if (jsonObject.contains(IContextSettings::PathHotkeys())) { @@ -129,6 +142,7 @@ namespace BlackCore this->m_hotkeys.initAsHotkeyList(true); this->m_settingsNetwork.initDefaultValues(); this->m_settingsAudio.initDefaultValues(); + this->m_settingsSimulator.initDefaultValues(); this->emitCompletelyChanged(); if (write) return this->write(); @@ -152,6 +166,7 @@ namespace BlackCore QJsonObject jsonObject; jsonObject.insert(IContextSettings::PathNetworkSettings(), this->m_settingsNetwork.toJson()); jsonObject.insert(IContextSettings::PathAudioSettings(), this->m_settingsAudio.toJson()); + jsonObject.insert(IContextSettings::PathSimulatorSettings(), this->m_settingsSimulator.toJson()); jsonObject.insert(IContextSettings::PathHotkeys(), this->m_hotkeys.toJson()); QJsonDocument doc(jsonObject); return doc; @@ -165,6 +180,7 @@ namespace BlackCore emit this->changedSettings(IContextSettings::SettingsHotKeys); emit this->changedSettings(IContextSettings::SettingsNetwork); emit this->changedSettings(IContextSettings::SettingsAudio); + emit this->changedSettings(IContextSettings::SettingsSimulator); } /* @@ -191,6 +207,14 @@ namespace BlackCore return this->m_settingsAudio; } + /* + * Simulator settings + */ + CSettingsSimulator CContextSettings::getSimulatorSettings() const + { + return this->m_settingsSimulator; + } + /* * Pass value */ diff --git a/src/blackcore/context_settings_impl.h b/src/blackcore/context_settings_impl.h index d5910281f..406a1b7d5 100644 --- a/src/blackcore/context_settings_impl.h +++ b/src/blackcore/context_settings_impl.h @@ -10,9 +10,7 @@ #include "dbus_server.h" #include "context_runtime.h" -#include "blackmisc/setnetwork.h" -#include "blackmisc/setaudio.h" - +#include "blackcore/settingsallclasses.h" #include "blackmisc/statusmessagelist.h" #include "blackmisc/hwkeyboardkeylist.h" @@ -20,7 +18,7 @@ namespace BlackCore { /*! - * \brief Settings context implementation + * Settings context implementation */ class CContextSettings : public IContextSettings { @@ -30,10 +28,10 @@ namespace BlackCore friend class IContextSettings; protected: - //! \brief Constructor + //! Constructor CContextSettings(CRuntimeConfig::ContextMode mode, CRuntime *runtime = nullptr); - //! \brief Register myself in DBus + //! Register myself in DBus CContextSettings *registerWithDBus(CDBusServer *server) { if (!server || this->m_mode != CRuntimeConfig::LocalInDbusServer) return this; @@ -45,7 +43,7 @@ namespace BlackCore //! Destructor virtual ~CContextSettings() {} - //! \brief settings file + //! settings file const QString &getSettingsDirectory() const { return BlackMisc::Settings::CSettingUtilities::getSettingsDirectory(); } //! \copydoc IContextSettings::value() @@ -58,10 +56,13 @@ namespace BlackCore //! \copydoc IContextSettings::getAudioSettings() virtual BlackMisc::Settings::CSettingsAudio getAudioSettings() const override; + //! \copydoc IContextSettings::getSimulatorSettings() + virtual BlackSim::Settings::CSettingsSimulator getSimulatorSettings() const override; + //! \copydoc IContextSettings::getHotkeys() virtual BlackMisc::Hardware::CKeyboardKeyList getHotkeys() const override; - //! \brief read settings + //! read settings virtual BlackMisc::CStatusMessage read() override; //! \copydoc IContextSettings::write @@ -79,6 +80,7 @@ namespace BlackCore private: BlackMisc::Settings::CSettingsNetwork m_settingsNetwork; BlackMisc::Settings::CSettingsAudio m_settingsAudio; + BlackSim::Settings::CSettingsSimulator m_settingsSimulator; BlackMisc::Hardware::CKeyboardKeyList m_hotkeys; QJsonDocument toJsonDocument() const; void emitCompletelyChanged(); diff --git a/src/blackcore/context_settings_proxy.cpp b/src/blackcore/context_settings_proxy.cpp index 0bbf54471..04f357ad1 100644 --- a/src/blackcore/context_settings_proxy.cpp +++ b/src/blackcore/context_settings_proxy.cpp @@ -15,6 +15,7 @@ using namespace BlackMisc; using namespace BlackMisc::Settings; using namespace BlackMisc::Network; using namespace BlackMisc::Hardware; +using namespace BlackSim::Settings; namespace BlackCore { @@ -57,6 +58,14 @@ namespace BlackCore return this->m_dBusInterface->callDBusRet(QLatin1Literal("getAudioSettings")); } + /* + * Relay to DBus + */ + CSettingsSimulator CContextSettingsProxy::getSimulatorSettings() const + { + return this->m_dBusInterface->callDBusRet(QLatin1Literal("getSimulatorSettings")); + } + /* * Relay to DBus */ diff --git a/src/blackcore/context_settings_proxy.h b/src/blackcore/context_settings_proxy.h index 4380bc336..d75e69de3 100644 --- a/src/blackcore/context_settings_proxy.h +++ b/src/blackcore/context_settings_proxy.h @@ -52,6 +52,9 @@ namespace BlackCore //! \copydoc IContextSettings::getAudioSettings() virtual BlackMisc::Settings::CSettingsAudio getAudioSettings() const override; + //! \copydoc IContextSettings::getSimulatorSettings() + virtual BlackSim::Settings::CSettingsSimulator getSimulatorSettings() const override; + //! \copydoc IContextSettings::getHotkeys() virtual BlackMisc::Hardware::CKeyboardKeyList getHotkeys() const override; diff --git a/src/blackcore/context_simulator.h b/src/blackcore/context_simulator.h index 05abb7b3b..dca6fc733 100644 --- a/src/blackcore/context_simulator.h +++ b/src/blackcore/context_simulator.h @@ -12,10 +12,10 @@ #include "context.h" #include "blackcore/dbus_server.h" #include "blackcore/context_runtime.h" -#include "blackmisc/nwaircraftmodel.h" -#include "blackmisc/avaircraft.h" #include "blacksim/simulatorinfo.h" #include "blacksim/simulatorinfolist.h" +#include "blackmisc/nwaircraftmodel.h" +#include "blackmisc/avaircraft.h" #include "blackmisc/project.h" #include diff --git a/src/blackmisc/settingsallclasses.h b/src/blackcore/settingsallclasses.h similarity index 63% rename from src/blackmisc/settingsallclasses.h rename to src/blackcore/settingsallclasses.h index 9cff2d995..e80ade19b 100644 --- a/src/blackmisc/settingsallclasses.h +++ b/src/blackcore/settingsallclasses.h @@ -3,10 +3,10 @@ * 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/. */ -#ifndef BLACKMISC_SETTINGSALLCLASSES_H -#define BLACKMISC_SETTINGSALLCLASSES_H +#ifndef BLACKCORE_SETTINGSALLCLASSES_H +#define BLACKCORE_SETTINGSALLCLASSES_H -#include "blackmisc/setnetwork.h" -#include "blackmisc/setaudio.h" +#include "blackmisc/settingsblackmiscclasses.h" +#include "blacksim/setsimulator.h" #endif // guard diff --git a/src/blackmisc/blackmiscallvalueclasses.h b/src/blackmisc/blackmiscallvalueclasses.h index 8d1d546d1..5cc75d961 100644 --- a/src/blackmisc/blackmiscallvalueclasses.h +++ b/src/blackmisc/blackmiscallvalueclasses.h @@ -9,7 +9,7 @@ #include "blackmisc/pqallquantities.h" #include "blackmisc/avallclasses.h" #include "blackmisc/geoallclasses.h" -#include "blackmisc/settingsallclasses.h" +#include "blackmisc/settingsblackmiscclasses.h" #include "blackmisc/indexvariantmap.h" #include "blackmisc/networkallclasses.h" #include "blackmisc/statusmessagelist.h" diff --git a/src/blackmisc/blackmiscfreefunctions.cpp b/src/blackmisc/blackmiscfreefunctions.cpp index cc4f38f85..022b50337 100644 --- a/src/blackmisc/blackmiscfreefunctions.cpp +++ b/src/blackmisc/blackmiscfreefunctions.cpp @@ -9,7 +9,7 @@ #include "mathallclasses.h" #include "geoallclasses.h" #include "networkallclasses.h" -#include "settingsallclasses.h" +#include "settingsblackmiscclasses.h" #include "hwallclasses.h" #include "indexvariantmap.h" #include "variant.h" diff --git a/src/blackmisc/setnetwork.cpp b/src/blackmisc/setnetwork.cpp index cdd4c875c..70cadab44 100644 --- a/src/blackmisc/setnetwork.cpp +++ b/src/blackmisc/setnetwork.cpp @@ -191,15 +191,8 @@ namespace BlackMisc 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")); - } + msgs.push_back(CSettingUtilities::valueChangedMessage(v != this->m_bookingServiceUrl, "booking URL")); + this->m_bookingServiceUrl = v; return msgs; } } diff --git a/src/blackmisc/settingsblackmiscclasses.h b/src/blackmisc/settingsblackmiscclasses.h new file mode 100644 index 000000000..00f65a27c --- /dev/null +++ b/src/blackmisc/settingsblackmiscclasses.h @@ -0,0 +1,7 @@ +#ifndef BLACKMISC_SETTINGSBLACKMISCCLASSES_H +#define BLACKMISC_SETTINGSBLACKMISCCLASSES_H + +#include "blackmisc/setaudio.h" +#include "blackmisc/setnetwork.h" + +#endif // guard diff --git a/src/blackmisc/settingutilities.cpp b/src/blackmisc/settingutilities.cpp index 2fcde4c3c..d05956e95 100644 --- a/src/blackmisc/settingutilities.cpp +++ b/src/blackmisc/settingutilities.cpp @@ -37,7 +37,7 @@ namespace BlackMisc CStatusMessage CSettingUtilities::valueNotChangedMessage(const QString &valueName) { return CStatusMessage(CStatusMessage::TypeSettings, CStatusMessage::SeverityWarning, - QString("Value %1 not changed").arg(valueName)); + QString("Value '%1' not changed").arg(valueName)); } /* @@ -46,7 +46,17 @@ namespace BlackMisc CStatusMessage CSettingUtilities::valueChangedMessage(const QString &valueName) { return CStatusMessage(CStatusMessage::TypeSettings, CStatusMessage::SeverityInfo, - QString("Value %1 changed").arg(valueName)); + QString("Value '%1' changed").arg(valueName)); + } + + /* + * Value changed + */ + CStatusMessage CSettingUtilities::valueChangedMessage(bool changed, const QString &valueName) + { + return changed ? + valueChangedMessage(valueName) : + valueNotChangedMessage(valueName); } /* @@ -100,6 +110,5 @@ namespace BlackMisc static QString file(QString(CSettingUtilities::getSettingsDirectory()).append("/settings.json")); return file; } - } } diff --git a/src/blacksim/blacksimfreefunctions.cpp b/src/blacksim/blacksimfreefunctions.cpp index 5e418e426..3732bfc98 100644 --- a/src/blacksim/blacksimfreefunctions.cpp +++ b/src/blacksim/blacksimfreefunctions.cpp @@ -1,8 +1,12 @@ #include "blacksimfreefunctions.h" + +#include "blacksim/simulatorinfo.h" +#include "blacksim/setsimulator.h" + #include "fsx/simconnectutilities.h" #include "fscommon/aircraftcfgentrieslist.h" #include "fscommon/aircraftmappinglist.h" -#include "simulatorinfo.h" + namespace BlackSim { @@ -10,6 +14,7 @@ namespace BlackSim void registerMetadata() { BlackSim::CSimulatorInfo::registerMetadata(); + BlackSim::Settings::CSettingsSimulator::registerMetadata(); BlackSim::FsCommon::CAircraftCfgEntries::registerMetadata(); BlackSim::FsCommon::CAircraftMapping::registerMetadata(); BlackSim::FsCommon::CAircraftCfgEntriesList::registerMetadata(); diff --git a/src/blacksim/setsimulator.cpp b/src/blacksim/setsimulator.cpp new file mode 100644 index 000000000..c5d6a8af1 --- /dev/null +++ b/src/blacksim/setsimulator.cpp @@ -0,0 +1,162 @@ +#include "setsimulator.h" + +using namespace BlackMisc; +using namespace BlackMisc::Settings; + +namespace BlackSim +{ + namespace Settings + { + /* + * Constructor + */ + CSettingsSimulator::CSettingsSimulator() + { + this->initDefaultValues(); + } + + /* + * Convert to string + */ + QString CSettingsSimulator::convertToQString(bool i18n) const + { + Q_UNUSED(i18n); + QString s("Sel.driver:"); + s.append(" ").append(m_selectedDriver.toQString(i18n)); + return s; + } + + /* + * metaTypeId + */ + int CSettingsSimulator::getMetaTypeId() const + { + return qMetaTypeId(); + } + + /* + * is a + */ + bool CSettingsSimulator::isA(int metaTypeId) const + { + if (metaTypeId == qMetaTypeId()) { return true; } + return this->CValueObject::isA(metaTypeId); + } + + /* + * Compare + */ + int CSettingsSimulator::compareImpl(const CValueObject &otherBase) const + { + const auto &other = static_cast(otherBase); + return compare(TupleConverter::toTuple(*this), TupleConverter::toTuple(other)); + } + + /* + * Marshall + */ + void CSettingsSimulator::marshallToDbus(QDBusArgument &argument) const + { + argument << TupleConverter::toTuple(*this); + } + + /* + * Unmarshall + */ + void CSettingsSimulator::unmarshallFromDbus(const QDBusArgument &argument) + { + argument >> TupleConverter::toTuple(*this); + } + + /* + * Equal? + */ + bool CSettingsSimulator::operator ==(const CSettingsSimulator &other) const + { + if (this == &other) return true; + return compare(*this, other) == 0; + } + + /* + * Unequal? + */ + bool CSettingsSimulator::operator !=(const CSettingsSimulator &other) const + { + return !((*this) == other); + } + + /* + * Hash + */ + uint CSettingsSimulator::getValueHash() const + { + return qHash(TupleConverter::toTuple(*this)); + } + + /* + * To JSON + */ + QJsonObject CSettingsSimulator::toJson() const + { + return BlackMisc::serializeJson(CSettingsSimulator::jsonMembers(), TupleConverter::toTuple(*this)); + } + + /* + * From JSON + */ + void CSettingsSimulator::fromJson(const QJsonObject &json) + { + BlackMisc::deserializeJson(json, CSettingsSimulator::jsonMembers(), TupleConverter::toTuple(*this)); + } + + /* + * Members + */ + const QStringList &CSettingsSimulator::jsonMembers() + { + return TupleConverter::jsonMembers(); + } + + /* + * Default values + */ + void CSettingsSimulator::initDefaultValues() + { + this->m_selectedDriver = CSimulatorInfo::FSX(); + } + + /* + * Register metadata + */ + void CSettingsSimulator::registerMetadata() + { + qRegisterMetaType(); + qDBusRegisterMetaType(); + } + + /* + * Value + */ + BlackMisc::CStatusMessageList CSettingsSimulator::value(const QString &path, const QString &command, const CVariant &value, bool &changedFlag) + { + // TODO: This needs to be refactored to a smarter way to delegate commands + changedFlag = false; + CStatusMessageList msgs; + if (path == CSettingsSimulator::ValueSelectedDriver()) + { + if (command == CSettingUtilities::CmdAdd() || command == CSettingUtilities::CmdUpdate()) + { + if (command == CSettingUtilities::CmdUpdate()) + { + CSimulatorInfo v = value.value(); + msgs.push_back(CSettingUtilities::valueChangedMessage(v != this->m_selectedDriver, "selected driver")); + this->m_selectedDriver = v; + return msgs; + } + return msgs; + } + } + return CSettingUtilities::wrongPathMessages(path); + } + } // namespace +} // namespace diff --git a/src/blacksim/setsimulator.h b/src/blacksim/setsimulator.h new file mode 100644 index 000000000..fbe1547a1 --- /dev/null +++ b/src/blacksim/setsimulator.h @@ -0,0 +1,103 @@ +/* Copyright (C) 2013 VATSIM Community / authors + * This Source Code Form is subject to the terms of the Mozilla Public + * 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_SIMULATOR_H +#define BLACKMISC_SETTINGS_SIMULATOR_H + +#include "blackmisc/valueobject.h" +#include "blackmisc/statusmessagelist.h" +#include "blackmisc/settingutilities.h" +#include "simulatorinfo.h" + +namespace BlackSim +{ + namespace Settings + { + //! Value object encapsulating information of simulator related settings. + class CSettingsSimulator : public BlackMisc::CValueObject + { + public: + //! Default constructor. + CSettingsSimulator(); + + //! Destructor. + virtual ~CSettingsSimulator() {} + + //! Path + static const QString &ValueSelectedDriver() + { + static const QString value("selecteddriver"); + return value; + } + + //! \copydoc CValueObject::toQVariant() + virtual QVariant toQVariant() const override { return QVariant::fromValue(*this); } + + //! Selected driver + BlackSim::CSimulatorInfo getSelectedDriver() const { return this->m_selectedDriver; } + + //! Selected driver + bool setSelectedDriver(const BlackSim::CSimulatorInfo &driver) { this->m_selectedDriver = driver; } + + //! Equal operator == + bool operator ==(const CSettingsSimulator &other) const; + + //! Unequal operator != + bool operator !=(const CSettingsSimulator &other) const; + + //! \copydoc BlackCore::IContextSettings + virtual BlackMisc::CStatusMessageList value(const QString &path, const QString &command, const BlackMisc::CVariant &value, bool &changedFlag); + + //! \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; + + //! Init with meaningful default values + void initDefaultValues(); + + //! \copydoc CValueObject::registerMetadata + static void registerMetadata(); + + //! \copydoc TupleConverter<>::jsonMembers() + static const QStringList &jsonMembers(); + + protected: + //! \copydoc CValueObject::convertToQString + virtual QString convertToQString(bool i18n = false) const override; + + //! \copydoc CValueObject::getMetaTypeId + virtual int getMetaTypeId() const override; + + //! \copydoc CValueObject::isA + virtual bool isA(int metaTypeId) const override; + + //! \copydoc CValueObject::compareImpl + virtual int compareImpl(const CValueObject &other) const override; + + //! \copydoc CValueObject::marshallToDbus + virtual void marshallToDbus(QDBusArgument &argument) const override; + + //! \copydoc CValueObject::unmarshallFromDbus + virtual void unmarshallFromDbus(const QDBusArgument &argument) override; + + private: + BLACK_ENABLE_TUPLE_CONVERSION(CSettingsSimulator) + BlackSim::CSimulatorInfo m_selectedDriver; + }; + + } // namespace +} // namespace + +Q_DECLARE_METATYPE(BlackSim::Settings::CSettingsSimulator) +BLACK_DECLARE_TUPLE_CONVERSION(BlackSim::Settings::CSettingsSimulator, (o.m_selectedDriver)) + +#endif // guard