From 3932371cd12ae7ec0812fbb2db3315448e18f1a8 Mon Sep 17 00:00:00 2001 From: Mikaël Capelle Date: Sun, 11 Oct 2020 21:17:34 +0200 Subject: Use proxy for ModList, PluginList and DownloadManager. Do not use registered callbacks when plugin is inactive. --- src/organizerproxy.cpp | 81 ++++++++++++++++++++++++++++---------------------- 1 file changed, 45 insertions(+), 36 deletions(-) (limited to 'src/organizerproxy.cpp') diff --git a/src/organizerproxy.cpp b/src/organizerproxy.cpp index a5047b43..05011e80 100644 --- a/src/organizerproxy.cpp +++ b/src/organizerproxy.cpp @@ -5,6 +5,10 @@ #include "plugincontainer.h" #include "settings.h" #include "glob_matching.h" +#include "downloadmanagerproxy.h" +#include "modlistproxy.h" +#include "pluginlistproxy.h" +#include "proxyutils.h" #include #include @@ -13,16 +17,19 @@ using namespace MOBase; using namespace MOShared; -OrganizerProxy::OrganizerProxy(OrganizerCore *organizer, PluginContainer *pluginContainer, const QString &pluginName) +OrganizerProxy::OrganizerProxy(OrganizerCore* organizer, PluginContainer* pluginContainer, MOBase::IPlugin* plugin) : m_Proxied(organizer) , m_PluginContainer(pluginContainer) - , m_PluginName(pluginName) + , m_Plugin(plugin) + , m_DownloadManagerProxy(std::make_unique(this, organizer->downloadManager())) + , m_ModListProxy(std::make_unique(this, organizer->modList())) + , m_PluginListProxy(std::make_unique(this, organizer->pluginList())) { } IModRepositoryBridge *OrganizerProxy::createNexusBridge() const { - return new NexusBridge(m_PluginContainer, m_PluginName); + return new NexusBridge(m_PluginContainer, m_Plugin->name()); } QString OrganizerProxy::profileName() const @@ -171,36 +178,6 @@ bool OrganizerProxy::waitForApplication(HANDLE handle, LPDWORD exitCode) const } } -bool OrganizerProxy::onAboutToRun(const std::function &func) -{ - return m_Proxied->onAboutToRun(func); -} - -bool OrganizerProxy::onFinishedRun(const std::function &func) -{ - return m_Proxied->onFinishedRun(func); -} - -bool OrganizerProxy::onModInstalled(const std::function &func) -{ - return m_Proxied->onModInstalled(func); -} - -bool OrganizerProxy::onUserInterfaceInitialized(std::function const& func) -{ - return m_Proxied->onUserInterfaceInitialized(func); -} - -bool OrganizerProxy::onProfileChanged(std::function const& func) -{ - return m_Proxied->onProfileChanged(func); -} - -bool OrganizerProxy::onPluginSettingChanged(std::function const& func) -{ - return m_Proxied->onPluginSettingChanged(func); -} - void OrganizerProxy::refreshModList(bool saveChanges) { m_Proxied->refreshModList(saveChanges); @@ -254,17 +231,17 @@ QList OrganizerProxy::findFileInfos(const QString MOBase::IDownloadManager *OrganizerProxy::downloadManager() const { - return m_Proxied->downloadManager(); + return m_DownloadManagerProxy.get(); } MOBase::IPluginList *OrganizerProxy::pluginList() const { - return m_Proxied->pluginList(); + return m_PluginListProxy.get(); } MOBase::IModList *OrganizerProxy::modList() const { - return m_Proxied->modList(); + return m_ModListProxy.get(); } MOBase::IProfile *OrganizerProxy::profile() const @@ -281,3 +258,35 @@ QStringList OrganizerProxy::modsSortedByProfilePriority() const { return m_Proxied->modsSortedByProfilePriority(); } + +// CALLBACKS + +bool OrganizerProxy::onAboutToRun(const std::function& func) +{ + return m_Proxied->onAboutToRun(MOShared::callIfPluginActive(this, func, true)); +} + +bool OrganizerProxy::onFinishedRun(const std::function& func) +{ + return m_Proxied->onFinishedRun(MOShared::callIfPluginActive(this, func)); +} + +bool OrganizerProxy::onModInstalled(const std::function& func) +{ + return m_Proxied->onModInstalled(MOShared::callIfPluginActive(this, func)); +} + +bool OrganizerProxy::onUserInterfaceInitialized(std::function const& func) +{ + return m_Proxied->onUserInterfaceInitialized(MOShared::callIfPluginActive(this, func)); +} + +bool OrganizerProxy::onProfileChanged(std::function const& func) +{ + return m_Proxied->onProfileChanged(MOShared::callIfPluginActive(this, func)); +} + +bool OrganizerProxy::onPluginSettingChanged(std::function const& func) +{ + return m_Proxied->onPluginSettingChanged(MOShared::callIfPluginActive(this, func)); +} -- cgit v1.3.1 From 3c1f206d7d29d3b3d27082aca23dafd87a95a71b Mon Sep 17 00:00:00 2001 From: Mikaël Capelle Date: Sun, 18 Oct 2020 10:13:59 +0200 Subject: Always call onPluginSettingChanged and onUserInterfaceInitialized callbacks. --- src/organizerproxy.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/organizerproxy.cpp') diff --git a/src/organizerproxy.cpp b/src/organizerproxy.cpp index 05011e80..2932e6bf 100644 --- a/src/organizerproxy.cpp +++ b/src/organizerproxy.cpp @@ -278,7 +278,8 @@ bool OrganizerProxy::onModInstalled(const std::function& f bool OrganizerProxy::onUserInterfaceInitialized(std::function const& func) { - return m_Proxied->onUserInterfaceInitialized(MOShared::callIfPluginActive(this, func)); + // Always call this one to allow plugin to initialize themselves even when not active: + return m_Proxied->onUserInterfaceInitialized(func); } bool OrganizerProxy::onProfileChanged(std::function const& func) @@ -288,5 +289,6 @@ bool OrganizerProxy::onProfileChanged(std::function const& func) { - return m_Proxied->onPluginSettingChanged(MOShared::callIfPluginActive(this, func)); + // Always call this one, otherwise plugin cannot detect they are being enabled / disabled: + return m_Proxied->onPluginSettingChanged(func); } -- cgit v1.3.1