diff --git a/samples/blackgui/mainwindow.h b/samples/blackgui/mainwindow.h index af32e241f..3439355f6 100644 --- a/samples/blackgui/mainwindow.h +++ b/samples/blackgui/mainwindow.h @@ -14,7 +14,7 @@ #include "guimodeenums.h" #include "blackcore/context_audio.h" #include "blackcore/context_network.h" -#include "blackcore/context_settings_interface.h" +#include "blackcore/context_settings.h" #include "blackcore/context_application.h" #include "blackcore/context_simulator.h" #include "blackcore/coreruntime.h" diff --git a/samples/blackgui/mainwindow_init.cpp b/samples/blackgui/mainwindow_init.cpp index 4808b7e9b..afa8fd6a0 100644 --- a/samples/blackgui/mainwindow_init.cpp +++ b/samples/blackgui/mainwindow_init.cpp @@ -7,6 +7,8 @@ #include "blackcore/context_simulator_proxy.h" #include "blackcore/context_application_impl.h" #include "blackcore/context_application_proxy.h" +#include "blackcore/context_settings_impl.h" +#include "blackcore/context_settings_proxy.h" #include "blackcore/context_audio_impl.h" #include "blackcore/context_audio_proxy.h" #include "blackcore/coreruntime.h" @@ -170,8 +172,8 @@ void MainWindow::init(GuiModes::CoreMode coreMode) { this->m_dBusConnection = QDBusConnection::sessionBus(); this->m_contextNetwork = new BlackCore::CContextNetworkProxy(BlackCore::CDBusServer::ServiceName, this->m_dBusConnection, this); - this->m_contextSettings = new BlackCore::IContextSettings(BlackCore::CDBusServer::ServiceName, this->m_dBusConnection, this); this->m_contextAudio = new BlackCore::CContextAudioProxy(BlackCore::CDBusServer::ServiceName, this->m_dBusConnection, this); + this->m_contextSettings = new BlackCore::CContextSettingsProxy(BlackCore::CDBusServer::ServiceName, this->m_dBusConnection, this); this->m_contextApplication = new BlackCore::CContextApplicationProxy(BlackCore::CDBusServer::ServiceName, this->m_dBusConnection, this); this->m_contextSimulator = new BlackCore::CContextSimulatorProxy(BlackCore::CDBusServer::ServiceName, this->m_dBusConnection, this); } diff --git a/src/blackcore/context_settings.h b/src/blackcore/context_settings.h index 69e37a876..6b168d09b 100644 --- a/src/blackcore/context_settings.h +++ b/src/blackcore/context_settings.h @@ -6,60 +6,115 @@ #ifndef BLACKCORE_CONTEXTSETTINGS_H #define BLACKCORE_CONTEXTSETTINGS_H -#include "blackcore/coreruntime.h" -#include "blackcore/dbus_server.h" -#include "blackcore/context_settings_interface.h" #include "blackmisc/statusmessagelist.h" +#include "blackmisc/settingutilities.h" +#include "blackmisc/setnetwork.h" #include "blackmisc/hwkeyboardkeylist.h" -#include -#define BLACKCORE_CONTEXTSETTINGS_INTERFACENAME "blackcore.contextsettings" +#include +#include + +#define BLACKCORE_CONTEXTSETTINGS_INTERFACENAME "net.vatsim.PilotClient.BlackCore.ContextSettings" +#define BLACKCORE_CONTEXTSETTINGS_OBJECTPATH "/Settings" namespace BlackCore { + /*! - * \brief Network context + * \brief Context settings interface */ - class CContextSettings : public IContextSettings + class IContextSettings : public QObject { - // Register by same name, make signals sender independent - // http://dbus.freedesktop.org/doc/dbus-faq.html#idp48032144 - Q_CLASSINFO("D-Bus Interface", BLACKCORE_CONTEXTSETTINGS_INTERFACENAME) Q_OBJECT + Q_CLASSINFO("D-Bus Interface", BLACKCORE_CONTEXTSETTINGS_INTERFACENAME) public: - //! \brief Constructor - CContextSettings(CCoreRuntime *runtime); - - //! Destructor - virtual ~CContextSettings() {} - - //! \brief Register myself in DBus - void registerWithDBus(CDBusServer *server) + /*! + * \brief Service name + */ + static const QString &InterfaceName() { - server->addObject(IContextSettings::ServicePath(), this); + static QString s(BLACKCORE_CONTEXTSETTINGS_INTERFACENAME); + return s; } - //! \brief Runtime - const CCoreRuntime *getRuntime() const + /*! + * \brief Service path + */ + static const QString &ObjectPath() { - return static_cast(this->parent()); + static QString s(BLACKCORE_CONTEXTSETTINGS_OBJECTPATH); + return s; } - //! \copydoc IContextSettings::value() - virtual BlackMisc::CStatusMessageList value(const QString &path, const QString &command, const QVariant &value); + /*! + * \brief Path for network settings + * \remarks no to be confused with DBus paths + */ + static const QString &PathNetworkSettings() + { + static QString s("network"); + return s; + } + + /*! + * \brief Path for network settings + * \remarks no to be confused with DBus paths + */ + static const QString &PathRoot() + { + static QString s("root"); + return s; + } + + /*! + * \brief Path for hotkeys + * \remarks no to be confused with DBus paths + */ + static const QString &PathHotkeys() + { + static QString s("hotkeys"); + return s; + } + + /*! + * \brief DBus version constructor + */ + IContextSettings(QObject *parent = nullptr) : QObject(parent) {} + + /*! + * Destructor + */ + virtual ~IContextSettings() {} + + + /*! + * \brief Handle value + * \param path where value belongs to + * \param command what to do with value + * \param value + * \return messages generated during handling + * \remarks Do not make this a slot, no DBus XML signature shall be created. The QVariant + * will be send a tailored value method using QDBusVariant + * @see value(const QString &, const QString &, QDBusVariant, int) + */ + virtual BlackMisc::CStatusMessageList value(const QString &path, const QString &command, const QVariant &value) = 0; + + signals: + //! \brief Settings have been changed + void changedSettings(); + + //! \brief Network settings have been changed + void changedNetworkSettings(); public slots: - //! \copydoc IContextSettings::getNetworkSettings() - virtual BlackMisc::Settings::CSettingsNetwork getNetworkSettings() const; - //! \copydoc IContextSettings::getHotkeys() - virtual BlackMisc::Hardware::CKeyboardKeyList getHotkeys() const; + //! \brief Network settings + virtual BlackMisc::Settings::CSettingsNetwork getNetworkSettings() const = 0; - private: - BlackMisc::Settings::CSettingsNetwork m_settingsNetwork; - BlackMisc::Hardware::CKeyboardKeyList m_hotkeys; + //! \brief Hotkeys + virtual BlackMisc::Hardware::CKeyboardKeyList getHotkeys() const = 0; }; } diff --git a/src/blackcore/context_settings.cpp b/src/blackcore/context_settings_impl.cpp similarity index 92% rename from src/blackcore/context_settings.cpp rename to src/blackcore/context_settings_impl.cpp index 8a950a8ad..98f8e4fb7 100644 --- a/src/blackcore/context_settings.cpp +++ b/src/blackcore/context_settings_impl.cpp @@ -3,8 +3,9 @@ * 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/. */ -#include "context_settings.h" +#include "context_settings_impl.h" #include "coreruntime.h" + #include "blackmisc/settingutilities.h" using namespace BlackMisc; @@ -18,7 +19,7 @@ namespace BlackCore /* * Init this context */ - CContextSettings::CContextSettings(CCoreRuntime *runtime) : IContextSettings(runtime) + CContextSettings::CContextSettings(QObject *parent) : IContextSettings(parent) { // create some dummy settings // this would actually be reading the settings from disk .. @@ -37,7 +38,7 @@ namespace BlackCore /* * Hotkeys */ - Hardware::CKeyboardKeyList CContextSettings::getHotkeys() const + CKeyboardKeyList CContextSettings::getHotkeys() const { return this->m_hotkeys; } @@ -45,7 +46,7 @@ namespace BlackCore /* * Network settings */ - BlackMisc::Settings::CSettingsNetwork CContextSettings::getNetworkSettings() const + CSettingsNetwork CContextSettings::getNetworkSettings() const { return this->m_settingsNetwork; } diff --git a/src/blackcore/context_settings_impl.h b/src/blackcore/context_settings_impl.h new file mode 100644 index 000000000..63069807a --- /dev/null +++ b/src/blackcore/context_settings_impl.h @@ -0,0 +1,70 @@ +/* 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/. */ + +#ifndef BLACKCORE_CONTEXTSETTINGS_IMPL_H +#define BLACKCORE_CONTEXTSETTINGS_IMPL_H + +#include "context_settings.h" +#include "dbus_server.h" +#include "coreruntime.h" + +#include "blackmisc/setnetwork.h" +#include "blackmisc/statusmessagelist.h" +#include "blackmisc/hwkeyboardkeylist.h" + +namespace BlackCore +{ + + /*! + * \brief Settings context implementation + */ + class CContextSettings : public IContextSettings + { + Q_OBJECT + Q_CLASSINFO("D-Bus Interface", BLACKCORE_CONTEXTSETTINGS_INTERFACENAME) + + public: + + //! \brief Constructor + CContextSettings(QObject *runtime = nullptr); + + //! Destructor + virtual ~CContextSettings() {} + + //! \brief Register myself in DBus + void registerWithDBus(CDBusServer *server) + { + server->addObject(IContextSettings::ObjectPath(), this); + } + + //! \brief Runtime + CCoreRuntime *getRuntime() + { + return static_cast(this->parent()); + } + + //! \brief Runtime + const CCoreRuntime *getRuntime() const + { + return static_cast(this->parent()); + } + + public slots: + //! \copydoc IContextSettings::getNetworkSettings() + virtual BlackMisc::Settings::CSettingsNetwork getNetworkSettings() const override; + + //! \copydoc IContextSettings::getHotkeys() + virtual BlackMisc::Hardware::CKeyboardKeyList getHotkeys() const override; + + //! \copydoc IContextSettings::value() + virtual BlackMisc::CStatusMessageList value(const QString &path, const QString &command, const QVariant &value) override; + + private: + BlackMisc::Settings::CSettingsNetwork m_settingsNetwork; + BlackMisc::Hardware::CKeyboardKeyList m_hotkeys; + }; +} + +#endif // guard diff --git a/src/blackcore/context_settings_interface.h b/src/blackcore/context_settings_interface.h deleted file mode 100644 index 55349f89a..000000000 --- a/src/blackcore/context_settings_interface.h +++ /dev/null @@ -1,150 +0,0 @@ -/* 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/. */ - -#ifndef BLACKCORE_CONTEXTSETTINGS_INTERFACE_H -#define BLACKCORE_CONTEXTSETTINGS_INTERFACE_H - -#include "blackmisc/statusmessagelist.h" -#include "blackmisc/genericdbusinterface.h" -#include "blackmisc/settingutilities.h" -#include "blackmisc/setnetwork.h" -#include "blackmisc/hwkeyboardkeylist.h" -#include -#include -#include - -#define BLACKCORE_CONTEXTSETTINGS_INTERFACENAME "blackcore.contextsettings" -#define BLACKCORE_CONTEXTSETTINGS_SERVICEPATH "/settings" - -// SERVICENAME must contain at least one ".", otherwise generation fails -// as this is interpreted in the way comain.somename - -namespace BlackCore -{ - - /*! - * \brief The interface context settings - */ - class IContextSettings : public QObject - { - Q_OBJECT - Q_CLASSINFO("D-Bus Interface", BLACKCORE_CONTEXTSETTINGS_INTERFACENAME) - - public: - - /*! - * \brief Service name - */ - static const QString &InterfaceName() - { - static QString s(BLACKCORE_CONTEXTSETTINGS_INTERFACENAME); - return s; - } - - /*! - * \brief Service path - */ - static const QString &ServicePath() - { - static QString s(BLACKCORE_CONTEXTSETTINGS_SERVICEPATH); - return s; - } - - /*! - * \brief Path for network settings - * \remarks no to be confused with DBus paths - */ - static const QString &PathNetworkSettings() - { - static QString s("network"); - return s; - } - - /*! - * \brief Path for network settings - * \remarks no to be confused with DBus paths - */ - static const QString &PathRoot() - { - static QString s("root"); - return s; - } - - /*! - * \brief Path for hotkeys - * \remarks no to be confused with DBus paths - */ - static const QString &PathHotkeys() - { - static QString s("hotkeys"); - return s; - } - - /*! - * \brief DBus version constructor - */ - IContextSettings(const QString &serviceName, QDBusConnection &connection, QObject *parent = nullptr); - - /*! - * Destructor - */ - ~IContextSettings() {} - - - /*! - * \brief Handle value - * \param path where value belongs to - * \param command what to do with value - * \param value - * \return messages generated during handling - * \remarks Do not make this a slot, no DBus XML signature shall be created. The QVariant - * will be send a tailored value method using QDBusVariant - * @see value(const QString &, const QString &, QDBusVariant, int) - */ - virtual BlackMisc::CStatusMessageList value(const QString &path, const QString &command, const QVariant &value); - - private: - BlackMisc::CGenericDBusInterface *m_dBusInterface; - - /*! - * Relay connection signals to local signals - * No idea why this has to be wired and is not done automatically - * \param connection - */ - void relaySignals(const QString &serviceName, QDBusConnection &connection); - - protected: - /*! - * \brief IContextSettings - * \param parent - */ - IContextSettings(QObject *parent = nullptr) : QObject(parent), m_dBusInterface(nullptr) {} - - signals: - //! \brief Settings have been changed - void changedSettings(); - - //! \brief Network settings have been changed - void changedNetworkSettings(); - - public slots: - - //! \brief Network settings - virtual BlackMisc::Settings::CSettingsNetwork getNetworkSettings() const; - - //! \brief Hotkeys - virtual BlackMisc::Hardware::CKeyboardKeyList getHotkeys() const; - - /*! - * \brief DBus version of value method. - * \remarks Basically an unwanted signature as this is different from the "local" signature and - * contains explicit DBus types (a: QDbusArgument, b: type for conversion). - * If this can be removed, fine. - */ - virtual BlackMisc::CStatusMessageList value(const QString &path, const QString &command, QDBusVariant value, int unifiedBlackMetaType); - }; -} - -#endif // guard diff --git a/src/blackcore/context_settings_interface.cpp b/src/blackcore/context_settings_proxy.cpp similarity index 56% rename from src/blackcore/context_settings_interface.cpp rename to src/blackcore/context_settings_proxy.cpp index 184523ad3..a9412549a 100644 --- a/src/blackcore/context_settings_interface.cpp +++ b/src/blackcore/context_settings_proxy.cpp @@ -3,22 +3,29 @@ * 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/. */ -#include "blackcore/context_settings_interface.h" +#include "context_settings_proxy.h" + #include "blackmisc/blackmiscfreefunctions.h" + #include #include #include +using namespace BlackMisc; +using namespace BlackMisc::Settings; +using namespace BlackMisc::Network; +using namespace BlackMisc::Hardware; + namespace BlackCore { /* * Constructor for DBus */ - IContextSettings::IContextSettings(const QString &serviceName, QDBusConnection &connection, QObject *parent) : QObject(parent), m_dBusInterface(0) + CContextSettingsProxy::CContextSettingsProxy(const QString &serviceName, QDBusConnection &connection, QObject *parent) : IContextSettings(parent), m_dBusInterface(nullptr) { this->m_dBusInterface = new BlackMisc::CGenericDBusInterface( - serviceName , IContextSettings::ServicePath(), IContextSettings::InterfaceName(), + serviceName , IContextSettings::ObjectPath(), IContextSettings::InterfaceName(), connection, this); this->relaySignals(serviceName, connection); } @@ -26,32 +33,32 @@ namespace BlackCore /* * Workaround for signals */ - void IContextSettings::relaySignals(const QString &serviceName, QDBusConnection &connection) + void CContextSettingsProxy::relaySignals(const QString &serviceName, QDBusConnection &connection) { - connection.connect(serviceName, IContextSettings::ServicePath(), IContextSettings::InterfaceName(), + connection.connect(serviceName, IContextSettings::ObjectPath(), IContextSettings::InterfaceName(), "changedNetworkSettings", this, SIGNAL(changedNetworkSettings())); } /* * Relay to DBus */ - BlackMisc::Settings::CSettingsNetwork IContextSettings::getNetworkSettings() const + CSettingsNetwork CContextSettingsProxy::getNetworkSettings() const { - return this->m_dBusInterface->callDBusRet(QLatin1Literal("getNetworkSettings")); + return this->m_dBusInterface->callDBusRet(QLatin1Literal("getNetworkSettings")); } /* * Relay tp DBus */ - BlackMisc::Hardware::CKeyboardKeyList IContextSettings::getHotkeys() const + CKeyboardKeyList CContextSettingsProxy::getHotkeys() const { - return this->m_dBusInterface->callDBusRet(QLatin1Literal("getHotkeys")); + return this->m_dBusInterface->callDBusRet(QLatin1Literal("getHotkeys")); } /* * Relay to DBus, but make this no slot */ - BlackMisc::CStatusMessageList IContextSettings::value(const QString &path, const QString &command, const QVariant &value) + BlackMisc::CStatusMessageList CContextSettingsProxy::value(const QString &path, const QString &command, const QVariant &value) { int type = value.userType() - BlackMisc::firstBlackMetaType(); return this->m_dBusInterface->callDBusRet(QLatin1Literal("value"), path, command, QDBusVariant(value), type); @@ -60,7 +67,7 @@ namespace BlackCore /* * DBus version of value */ - BlackMisc::CStatusMessageList IContextSettings::value(const QString &path, const QString &command, QDBusVariant value, int unifiedBlackMetaType) + BlackMisc::CStatusMessageList CContextSettingsProxy::value(const QString &path, const QString &command, QDBusVariant value, int unifiedBlackMetaType) { QVariant qv = value.variant(); if (qv.canConvert()) diff --git a/src/blackcore/context_settings_proxy.h b/src/blackcore/context_settings_proxy.h new file mode 100644 index 000000000..7e84a015f --- /dev/null +++ b/src/blackcore/context_settings_proxy.h @@ -0,0 +1,89 @@ +/* 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/. */ + +#ifndef BLACKCORE_CONTEXTSETTINGS_PROXY_H +#define BLACKCORE_CONTEXTSETTINGS_PROXY_H + +#include "context_settings.h" + +#include "blackmisc/statusmessagelist.h" +#include "blackmisc/genericdbusinterface.h" +#include "blackmisc/settingutilities.h" +#include "blackmisc/setnetwork.h" +#include "blackmisc/hwkeyboardkeylist.h" + +#include + +namespace BlackCore +{ + + /*! + * \brief Settings context proxy + */ + class CContextSettingsProxy : public IContextSettings + { + Q_OBJECT + + public: + + /*! + * \brief DBus version constructor + */ + CContextSettingsProxy(const QString &serviceName, QDBusConnection &connection, QObject *parent = nullptr); + + /*! + * Destructor + */ + virtual ~CContextSettingsProxy() {} + + + /*! + * \brief Handle value + * \param path where value belongs to + * \param command what to do with value + * \param value + * \return messages generated during handling + * \remarks Do not make this a slot, no DBus XML signature shall be created. The QVariant + * will be send a tailored value method using QDBusVariant + * @see value(const QString &, const QString &, QDBusVariant, int) + */ + virtual BlackMisc::CStatusMessageList value(const QString &path, const QString &command, const QVariant &value) override; + + private: + BlackMisc::CGenericDBusInterface *m_dBusInterface; + + /*! + * Relay connection signals to local signals + * No idea why this has to be wired and is not done automatically + * \param connection + */ + void relaySignals(const QString &serviceName, QDBusConnection &connection); + + protected: + /*! + * \brief IContextSettings + * \param parent + */ + CContextSettingsProxy(QObject *parent = nullptr) : IContextSettings(parent), m_dBusInterface(nullptr) {} + + public slots: + + //! \copydoc IContextSettings::getNetworkSettings() + virtual BlackMisc::Settings::CSettingsNetwork getNetworkSettings() const override; + + //! \copydoc IContextSettings::getHotkeys() + virtual BlackMisc::Hardware::CKeyboardKeyList getHotkeys() const override; + + /*! + * \brief DBus version of value method. + * \remarks Basically an unwanted signature as this is different from the "local" signature and + * contains explicit DBus types (a: QDbusArgument, b: type for conversion). + * If this can be removed, fine. + */ + BlackMisc::CStatusMessageList value(const QString &path, const QString &command, QDBusVariant value, int unifiedBlackMetaType); + }; +} + +#endif // guard diff --git a/src/blackcore/coreruntime.cpp b/src/blackcore/coreruntime.cpp index 3a7b67fd5..90c746d6d 100644 --- a/src/blackcore/coreruntime.cpp +++ b/src/blackcore/coreruntime.cpp @@ -3,7 +3,7 @@ #include "blackmisc/nwserver.h" #include "blackcore/context_application_impl.h" #include "blackcore/context_network_impl.h" -#include "blackcore/context_settings.h" +#include "blackcore/context_settings_impl.h" #include "blackcore/context_audio_impl.h" #include "blackcore/context_simulator_impl.h"