From cb453a9ba70106832eec2cb0feecbd91d2e8b7d7 Mon Sep 17 00:00:00 2001 From: Mikaƫl Capelle Date: Wed, 2 Dec 2020 21:08:22 +0100 Subject: Fix callbacks for IOrganizer when plugin are unloaded/loaded. --- src/organizerproxy.cpp | 57 ++++++++++++++++++++++++++++++++++---------------- 1 file changed, 39 insertions(+), 18 deletions(-) (limited to 'src/organizerproxy.cpp') diff --git a/src/organizerproxy.cpp b/src/organizerproxy.cpp index 92f250ea..13b91ff4 100644 --- a/src/organizerproxy.cpp +++ b/src/organizerproxy.cpp @@ -22,10 +22,31 @@ OrganizerProxy::OrganizerProxy(OrganizerCore* organizer, PluginContainer* plugin : m_Proxied(organizer) , m_PluginContainer(pluginContainer) , m_Plugin(plugin) + , m_PluginName(plugin->name()) , m_DownloadManagerProxy(std::make_unique(this, organizer->downloadManager())) , m_ModListProxy(std::make_unique(this, organizer->modList())) , m_PluginListProxy(std::make_unique(this, organizer->pluginList())) { + m_Connections.push_back(m_Proxied->onAboutToRun(callSignalIfPluginActive(this, m_AboutToRun, true))); + m_Connections.push_back(m_Proxied->onFinishedRun(callSignalIfPluginActive(this, m_FinishedRun))); + m_Connections.push_back(m_Proxied->onProfileCreated(callSignalIfPluginActive(this, m_ProfileCreated))); + m_Connections.push_back(m_Proxied->onProfileRenamed(callSignalIfPluginActive(this, m_ProfileRenamed))); + m_Connections.push_back(m_Proxied->onProfileRemoved(callSignalIfPluginActive(this, m_ProfileRemoved))); + m_Connections.push_back(m_Proxied->onProfileChanged(callSignalIfPluginActive(this, m_ProfileChanged))); + + m_Connections.push_back(m_Proxied->onUserInterfaceInitialized(callSignalAlways(m_UserInterfaceInitialized))); + m_Connections.push_back(m_Proxied->onPluginSettingChanged(callSignalAlways(m_PluginSettingChanged))); + m_Connections.push_back(m_Proxied->onPluginEnabled(callSignalAlways(m_PluginEnabled))); + m_Connections.push_back(m_Proxied->onPluginDisabled(callSignalAlways(m_PluginDisabled))); + +} + +OrganizerProxy::~OrganizerProxy() +{ + log::debug("~OrganizerProxy() for {}.", m_PluginName); + for (auto& conn : m_Connections) { + conn.disconnect(); + } } IModRepositoryBridge *OrganizerProxy::createNexusBridge() const @@ -265,68 +286,68 @@ MOBase::IPluginGame const *OrganizerProxy::managedGame() const bool OrganizerProxy::onAboutToRun(const std::function& func) { - return m_Proxied->onAboutToRun(MOShared::callIfPluginActive(this, func, true)); + return m_Proxied->onAboutToRun(MOShared::callIfPluginActive(this, func, true)).connected(); } bool OrganizerProxy::onFinishedRun(const std::function& func) { - return m_Proxied->onFinishedRun(MOShared::callIfPluginActive(this, func)); -} - -bool OrganizerProxy::onUserInterfaceInitialized(std::function const& func) -{ - // Always call this one to allow plugin to initialize themselves even when not active: - return m_Proxied->onUserInterfaceInitialized(func); + return m_Proxied->onFinishedRun(MOShared::callIfPluginActive(this, func)).connected(); } bool OrganizerProxy::onProfileCreated(std::function const& func) { - return m_Proxied->onProfileCreated(MOShared::callIfPluginActive(this, func)); + return m_ProfileCreated.connect(func).connected(); } bool OrganizerProxy::onProfileRenamed(std::function const& func) { - return m_Proxied->onProfileRenamed(MOShared::callIfPluginActive(this, func)); + return m_ProfileRenamed.connect(func).connected(); } bool OrganizerProxy::onProfileRemoved(std::function const& func) { - return m_Proxied->onProfileRemoved(MOShared::callIfPluginActive(this, func)); + return m_ProfileRemoved.connect(func).connected(); } bool OrganizerProxy::onProfileChanged(std::function const& func) { - return m_Proxied->onProfileChanged(MOShared::callIfPluginActive(this, func)); + return m_ProfileChanged.connect(func).connected(); +} + +bool OrganizerProxy::onUserInterfaceInitialized(std::function const& func) +{ + // Always call this one to allow plugin to initialize themselves even when not active: + return m_UserInterfaceInitialized.connect(func).connected(); } // Always call these one, otherwise plugin cannot detect they are being enabled / disabled: bool OrganizerProxy::onPluginSettingChanged(std::function const& func) { - return m_Proxied->onPluginSettingChanged(func); + return m_PluginSettingChanged.connect(func).connected(); } bool OrganizerProxy::onPluginEnabled(std::function const& func) { - return m_Proxied->onPluginEnabled(func); + return m_PluginEnabled.connect(func).connected(); } bool OrganizerProxy::onPluginEnabled(const QString& pluginName, std::function const& func) { - return m_Proxied->onPluginEnabled([=](const IPlugin* plugin) { + return onPluginEnabled([=](const IPlugin* plugin) { if (plugin->name().compare(pluginName, Qt::CaseInsensitive) == 0) { func(); } - }); + }); } bool OrganizerProxy::onPluginDisabled(std::function const& func) { - return m_Proxied->onPluginDisabled(func); + return m_PluginDisabled.connect(func).connected(); } bool OrganizerProxy::onPluginDisabled(const QString& pluginName, std::function const& func) { - return m_Proxied->onPluginDisabled([=](const IPlugin* plugin) { + return onPluginDisabled([=](const IPlugin* plugin) { if (plugin->name().compare(pluginName, Qt::CaseInsensitive) == 0) { func(); } -- cgit v1.3.1