From 74ec078976fbd64433142e6974f30cc113047c00 Mon Sep 17 00:00:00 2001 From: Mikaƫl Capelle Date: Tue, 10 Nov 2020 21:38:58 +0100 Subject: Replace usage of IPlugin::isActive(). --- src/plugincontainer.h | 125 +++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 113 insertions(+), 12 deletions(-) (limited to 'src/plugincontainer.h') diff --git a/src/plugincontainer.h b/src/plugincontainer.h index 2b39726b..1a3173fb 100644 --- a/src/plugincontainer.h +++ b/src/plugincontainer.h @@ -22,6 +22,30 @@ class IUserInterface; #include #endif // Q_MOC_RUN #include +#include + + +class OrganizerProxy; + + +// Small class that allows calling check() for plugin requirements +// without passing the IOrganizer. +class PluginRequirementProxy { +public: + + std::vector problems() const; + QString description(unsigned int id) const; + +private: + + const MOBase::PluginRequirement* m_Requirement; + OrganizerProxy* m_Proxy; + + PluginRequirementProxy(const MOBase::PluginRequirement* requirement, OrganizerProxy* proxy); + + friend class PluginContainer; + +}; class PluginContainer : public QObject, public MOBase::IPluginDiagnose @@ -32,18 +56,24 @@ class PluginContainer : public QObject, public MOBase::IPluginDiagnose private: - typedef boost::fusion::map< - boost::fusion::pair>, - boost::fusion::pair>, - boost::fusion::pair>, - boost::fusion::pair>, - boost::fusion::pair>, - boost::fusion::pair>, - boost::fusion::pair>, - boost::fusion::pair>, - boost::fusion::pair>, - boost::fusion::pair> - > PluginMap; + using PluginMap = boost::fusion::map< + boost::fusion::pair>, + boost::fusion::pair>, + boost::fusion::pair>, + boost::fusion::pair>, + boost::fusion::pair>, + boost::fusion::pair>, + boost::fusion::pair>, + boost::fusion::pair>, + boost::fusion::pair>, + boost::fusion::pair> + >; + + using AccessPluginMap = boost::fusion::map< + boost::fusion::pair>, + boost::fusion::pair>, + boost::fusion::pair> + >; static const unsigned int PROBLEM_PLUGINSNOTLOADED = 1; @@ -112,6 +142,71 @@ public: return temp; } + /** + * @brief Check if a plugin implement a given interface. + * + * @param plugin The plugin to check. + * + * @return true if the plugin implements the interface, false otherwise. + * + * @tparam The interface type. + */ + template + bool implementInterface(MOBase::IPlugin* plugin) const { + // We need a QObject to be able to qobject_cast<> to the plugin types: + QObject* oPlugin = as_qobject(plugin); + + if (!oPlugin) { + return false; + } + + // Find all the names: + bool implement = false; + boost::mp11::mp_for_each([oPlugin, &implement](const auto* p) { + using plugin_type = std::decay_t; + if (qobject_cast(oPlugin)) { + implement = true; + } + }); + + return implement; + } + + /** + * @brief Retrieve a plugin from its name or a corresponding non-IPlugin + * interface. + * + * @param t Name of the plugin to retrieve, or non-IPlugin interface. + * + * @return the corresponding plugin, or a null pointer. + */ + MOBase::IPlugin* plugin(QString const& pluginName) const; + MOBase::IPlugin* plugin(MOBase::IPluginDiagnose* diagnose) const; + MOBase::IPlugin* plugin(MOBase::IPluginFileMapper* mapper) const; + + /** + * @brief Check if the given plugin is enabled. + * + * @param plugin The plugin to check. + * + * @return true if the plugin is enabled, false otherwise. + */ + bool isEnabled(MOBase::IPlugin *plugin) const; + + // These are friendly methods that called isEnabled(plugin(arg)). + bool isEnabled(QString const& pluginName) const; + bool isEnabled(MOBase::IPluginDiagnose* diagnose) const; + bool isEnabled(MOBase::IPluginFileMapper* mapper) const; + + /** + * @brief Retrieve the requirements for the given plugin. + * + * @param plugin The plugin to retrieve the requirements for. + * + * @return the requirements (as proxy) for the given plugin. + */ + std::vector requirements(MOBase::IPlugin* plugin) const; + /** * @brief Retrieved the (localized) names of interfaces implemented by the given * plugin. @@ -179,6 +274,12 @@ private: PluginMap m_Plugins; + // This maps allow access to IPlugin* from name or diagnose/mapper object. + AccessPluginMap m_AccessPlugins; + + std::map m_Proxies; + std::map>> m_Requirements; + std::map m_SupportedGames; std::vector m_DiagnosisConnections; QStringList m_FailedPlugins; -- cgit v1.3.1