#pragma once #include "provider-plugin.h" #include #include #include #include // Registry of package providers. It owns every IPackageManager (built-in and // external) and can load additional providers at runtime from shared-library // plugins dropped in the plugin directories (see PluginManager::scanDirectory). class PluginManager { public: struct ProviderEntry { ProviderInfo info; IPackageManager* manager = nullptr; // owned by the PluginManager QLibrary* library = nullptr; // owned by the PluginManager; null for built-ins }; PluginManager(); ~PluginManager(); // Register a provider compiled into the application (e.g. pacman, flatpak). // Takes ownership of the manager. void registerBuiltin(ProviderInfo info, IPackageManager* manager); // Scan the plugin directories for external provider plugins and load them. void discoverExternal(); // Drop external plugins and rescan their directories; built-in providers // are kept (their instances stay valid). void reload(); // Re-run isAvailable() on every known provider (e.g. after the app // installed a missing tool) so the Providers page reflects reality. void refreshAvailability(); // All known providers, in registration order. const std::vector& providers() const; // Providers that are enabled (in settings) and whose tool is on the system. std::vector availableProviders() const; // Same as availableProviders() but as plain manager pointers, convenient // for running aggregated operations across every provider. std::vector availableManagers() const; // A single available+enabled provider matching id, or nullptr. const ProviderEntry* findAvailable(const std::string& id) const; bool isEnabled(const std::string& id) const; void setEnabled(const std::string& id, bool enabled); // Manager for a known provider id (enabled or not), or nullptr. IPackageManager* managerFor(const std::string& id) const; private: bool loadPluginFile(const QString& filePath); void scanDirectory(const QString& dir); void unloadExternal(); std::vector m_providers; QSettings m_settings; };