2 #include <score/application/ApplicationContext.hpp>
3 #include <score/application/GUIApplicationContext.hpp>
4 #include <score/plugins/InterfaceList.hpp>
5 #include <score/plugins/PluginInstances.hpp>
6 #include <score/plugins/qt_interfaces/CommandFactory_QtInterface.hpp>
7 #include <score/plugins/qt_interfaces/FactoryFamily_QtInterface.hpp>
8 #include <score/plugins/qt_interfaces/FactoryInterface_QtInterface.hpp>
9 #include <score/plugins/qt_interfaces/GUIApplicationPlugin_QtInterface.hpp>
10 #include <score/plugins/qt_interfaces/PluginRequirements_QtInterface.hpp>
11 #include <score/tools/std/Optional.hpp>
13 #include <core/plugin/PluginDependencyGraph.hpp>
16 #include <QStringList>
18 #include <score_lib_base_export.h>
23 struct ApplicationContext;
24 class GUIApplicationRegistrar;
25 class Plugin_QtInterface;
35 enum class PluginLoadingError
44 QStringList addonsDir();
45 QStringList pluginsDir();
47 SCORE_LIB_BASE_EXPORT
void loadPluginsInAllFolders(
48 std::vector<score::Addon>& availablePlugins, QStringList additional = {});
50 SCORE_LIB_BASE_EXPORT
void
51 loadAddonsInAllFolders(std::vector<score::Addon>& availablePlugins);
53 std::pair<score::Plugin_QtInterface*, PluginLoadingError>
54 loadPlugin(
const QString& fileName,
const std::vector<score::Addon>& availablePlugins);
56 std::optional<score::Addon> makeAddon(
57 const QString& addon_path,
const QJsonObject& json_addon,
58 const std::vector<score::Addon>& availablePlugins);
60 template <
typename Registrar_T>
61 void registerPluginsImpl(
62 const std::vector<score::Addon>& availablePlugins, Registrar_T& registrar,
68 auto commands_plugin =
dynamic_cast<CommandFactory_QtInterface*
>(addon.plugin);
71 auto [key, cmds] = commands_plugin->make_commands();
72 registrar.registerCommands(key, std::move(cmds));
75 auto factories_plugin =
dynamic_cast<FactoryInterface_QtInterface*
>(addon.plugin);
78 for(
auto& factory_family : registrar.components().factories)
82 for(
auto&& new_factory :
83 factories_plugin->factories(base_ctx, factory_family.first))
85 factory_family.second->insert(std::unique_ptr<InterfaceBase>(new_factory));
89 for(
auto&& new_factory :
90 factories_plugin->guiFactories(context, factory_family.first))
92 factory_family.second->insert(std::unique_ptr<InterfaceBase>(new_factory));
99 template <
typename Registrar_T>
100 void registerPlugins(
101 const std::vector<score::Addon>& availablePlugins, Registrar_T& registrar,
106 auto ctrl_plugin =
dynamic_cast<ApplicationPlugin_QtInterface*
>(addon.plugin);
109 if(
auto plug = ctrl_plugin->make_applicationPlugin(context))
110 registrar.registerApplicationPlugin(plug);
111 if(
auto plug = ctrl_plugin->make_guiApplicationPlugin(context))
112 registrar.registerGUIApplicationPlugin(plug);
115 registerPluginsImpl(availablePlugins, registrar, context);
125 template <
typename Registrar_T,
typename Context_T>
126 void loadPlugins(Registrar_T& registrar,
const Context_T& context)
129 std::vector<score::Addon> availablePlugins;
132 for(
auto score_plug : score::staticPlugins())
135 addon.plugin = score_plug;
136 addon.key = score_plug->key();
137 addon.corePlugin =
true;
138 availablePlugins.push_back(std::move(addon));
141 loadPluginsInAllFolders(availablePlugins);
142 loadAddonsInAllFolders(availablePlugins);
145 registrar.registerAddons(availablePlugins);
154 auto facfam_interface =
dynamic_cast<FactoryList_QtInterface*
>(addon.plugin);
158 for(
auto&& elt : facfam_interface->factoryFamilies())
160 registrar.registerFactory(std::move(elt));
167 PluginDependencyGraph graph{availablePlugins};
168 const auto& add = graph.sortedAddons();
171 registerPlugins(add, registrar, context);
Classes and functions used at the plug-in loading step.
Definition: PluginManager.hpp:26
Base toolkit upon which the software is built.
Definition: Application.cpp:90
The Addon struct.
Definition: Addon.hpp:16
Used to access all the application-wide state and structures.
Definition: ApplicationContext.hpp:24
Specializes ApplicationContext with the QMainWindow.
Definition: GUIApplicationContext.hpp:15