From 4e11faf1c8b19013da6d5686f79b67c1c746653b Mon Sep 17 00:00:00 2001 From: Mikaƫl Capelle Date: Sun, 25 Oct 2020 15:52:53 +0100 Subject: Move IOrganizer::onModInstalled() to IModList. Add IModList::onModRemoved(). --- src/modlist.cpp | 25 +++++++++++++++++++++++-- src/modlist.h | 35 +++++++++++++++++++++++++++-------- src/modlistproxy.cpp | 10 ++++++++++ src/modlistproxy.h | 2 ++ src/organizercore.cpp | 13 +++---------- src/organizercore.h | 4 ---- src/organizerproxy.cpp | 5 ----- src/organizerproxy.h | 1 - 8 files changed, 65 insertions(+), 30 deletions(-) (limited to 'src') diff --git a/src/modlist.cpp b/src/modlist.cpp index 2499bac0..90433963 100644 --- a/src/modlist.cpp +++ b/src/modlist.cpp @@ -77,6 +77,8 @@ ModList::ModList(PluginContainer *pluginContainer, OrganizerCore *organizer) ModList::~ModList() { + m_ModInstalled.disconnect_all_slots(); + m_ModRemoved.disconnect_all_slots(); m_ModStateChanged.disconnect_all_slots(); m_ModMoved.disconnect_all_slots(); } @@ -1001,10 +1003,29 @@ bool ModList::setPriority(const QString &name, int newPriority) } } +bool ModList::onModInstalled(const std::function& func) +{ + return m_ModInstalled.connect(func).connected(); +} + +bool ModList::onModRemoved(const std::function& func) +{ + return m_ModRemoved.connect(func).connected(); +} + bool ModList::onModStateChanged(const std::function&)>& func) { - auto conn = m_ModStateChanged.connect(func); - return conn.connected(); + return m_ModStateChanged.connect(func).connected(); +} + +void ModList::notifyModInstalled(MOBase::IModInterface* mod) const +{ + m_ModInstalled(mod); +} + +void ModList::notifyModRemoved(QString const& modName) const +{ + m_ModRemoved(modName); } void ModList::notifyModStateChanged(QList modIndices) const diff --git a/src/modlist.h b/src/modlist.h index 5312db34..baaeede3 100644 --- a/src/modlist.h +++ b/src/modlist.h @@ -70,8 +70,10 @@ public: COL_LASTCOLUMN = COL_NOTES, }; - typedef boost::signals2::signal&)> SignalModStateChanged; - typedef boost::signals2::signal SignalModMoved; + using SignalModInstalled = boost::signals2::signal; + using SignalModRemoved = boost::signals2::signal; + using SignalModStateChanged = boost::signals2::signal&)>; + using SignalModMoved = boost::signals2::signal; public: @@ -124,6 +126,22 @@ public: void highlightMods(const QItemSelectionModel *selection, const MOShared::DirectoryEntry &directoryEntry); + /** + * @brief Notify the mod list that the given mod has been installed. This is used + * to notify the plugin that registered through onModInstalled(). + * + * @param mod The installed mod. + */ + void notifyModInstalled(MOBase::IModInterface *mod) const; + + /** + * @brief Notify the mod list that a mod has been removed. This is used + * to notify the plugin that registered through onModRemoved(). + * + * @param modName Name of the removed mod. + */ + void notifyModRemoved(QString const& modName) const; + /** * @brief Notify the mod list that the state of the specified mods has changed. This is used * to notify the plugin that registered through onModStateChanged(). @@ -155,11 +173,10 @@ public: /// \copydoc MOBase::IModList::setPriority virtual bool setPriority(const QString &name, int newPriority) override; - /// \copydoc MOBase::IModList::onModStateChanged - virtual bool onModStateChanged(const std::function&)>& func) override; - - /// \copydoc MOBase::IModList::onModMoved - virtual bool onModMoved(const std::function &func) override; + bool onModInstalled(const std::function& func) override; + bool onModRemoved(const std::function& func) override; + bool onModStateChanged(const std::function&)>& func) override; + bool onModMoved(const std::function &func) override; public: // implementation of virtual functions of QAbstractItemModel @@ -362,8 +379,10 @@ private: TModInfoChange m_ChangeInfo; - SignalModStateChanged m_ModStateChanged; + SignalModInstalled m_ModInstalled; SignalModMoved m_ModMoved; + SignalModRemoved m_ModRemoved; + SignalModStateChanged m_ModStateChanged; QElapsedTimer m_LastCheck; diff --git a/src/modlistproxy.cpp b/src/modlistproxy.cpp index 7ec00c49..321f1873 100644 --- a/src/modlistproxy.cpp +++ b/src/modlistproxy.cpp @@ -42,6 +42,16 @@ bool ModListProxy::setPriority(const QString& name, int newPriority) return m_Proxied->setPriority(name, newPriority); } +bool ModListProxy::onModInstalled(const std::function& func) +{ + return m_Proxied->onModInstalled(MOShared::callIfPluginActive(m_OrganizerProxy, func)); +} + +bool ModListProxy::onModRemoved(const std::function& func) +{ + return m_Proxied->onModRemoved(MOShared::callIfPluginActive(m_OrganizerProxy, func)); +} + bool ModListProxy::onModStateChanged(const std::function&)>& func) { return m_Proxied->onModStateChanged(MOShared::callIfPluginActive(m_OrganizerProxy, func)); diff --git a/src/modlistproxy.h b/src/modlistproxy.h index 13399e0a..5b0a7114 100644 --- a/src/modlistproxy.h +++ b/src/modlistproxy.h @@ -20,6 +20,8 @@ public: int setActive(const QStringList& names, bool active) override; int priority(const QString& name) const override; bool setPriority(const QString& name, int newPriority) override; + bool onModInstalled(const std::function& func) override; + bool onModRemoved(const std::function& func) override; bool onModStateChanged(const std::function&)>& func) override; bool onModMoved(const std::function& func) override; diff --git a/src/organizercore.cpp b/src/organizercore.cpp index 2aaeb86c..989fdcc2 100644 --- a/src/organizercore.cpp +++ b/src/organizercore.cpp @@ -301,7 +301,6 @@ void OrganizerCore::disconnectPlugins() { m_AboutToRun.disconnect_all_slots(); m_FinishedRun.disconnect_all_slots(); - m_ModInstalled.disconnect_all_slots(); m_UserInterfaceInitialized.disconnect_all_slots(); m_ProfileChanged.disconnect_all_slots(); m_PluginSettingChanged.disconnect_all_slots(); @@ -674,6 +673,7 @@ bool OrganizerCore::removeMod(MOBase::IModInterface *mod) } else { return ModInfo::removeMod(index); } + m_ModList.notifyModRemoved(mod->name()); } void OrganizerCore::modDataChanged(MOBase::IModInterface *) @@ -760,7 +760,7 @@ MOBase::IModInterface *OrganizerCore::installMod(const QString &fileName, m_UserInterface->displayModInformation( modInfo, modIndex, ModInfoTabIDs::IniFiles); } - m_ModInstalled(modName); + m_ModList.notifyModInstalled(modInfo.get()); m_DownloadManager.markInstalled(fileName); m_InstallationManager.notifyInstallationEnd(result, modInfo); emit modInstalled(modName); @@ -839,7 +839,7 @@ void OrganizerCore::installDownload(int index) modInfo, modIndex, ModInfoTabIDs::IniFiles); } - m_ModInstalled(modName); + m_ModList.notifyModInstalled(modInfo.get()); m_InstallationManager.notifyInstallationEnd(IPluginInstaller::RESULT_SUCCESS, modInfo); } else { reportError(tr("mod not found: %1").arg(qUtf8Printable(modName))); @@ -1132,13 +1132,6 @@ bool OrganizerCore::onFinishedRun( return conn.connected(); } -bool OrganizerCore::onModInstalled( - const std::function &func) -{ - auto conn = m_ModInstalled.connect(func); - return conn.connected(); -} - bool OrganizerCore::onUserInterfaceInitialized(std::function const& func) { return m_UserInterfaceInitialized.connect(func).connected(); diff --git a/src/organizercore.h b/src/organizercore.h index 813bf084..25e68786 100644 --- a/src/organizercore.h +++ b/src/organizercore.h @@ -80,7 +80,6 @@ private: using SignalAboutToRunApplication = boost::signals2::signal; using SignalFinishedRunApplication = boost::signals2::signal; - using SignalModInstalled = boost::signals2::signal; using SignalUserInterfaceInitialized = boost::signals2::signal; using SignalProfileChanged = boost::signals2::signal; using SignalPluginSettingChanged = boost::signals2::signal; @@ -321,8 +320,6 @@ public: void refreshModList(bool saveChanges = true); QStringList modsSortedByProfilePriority() const; - - bool onModInstalled(const std::function& func); bool onAboutToRun(const std::function& func); bool onFinishedRun(const std::function& func); bool onUserInterfaceInitialized(std::function const& func); @@ -440,7 +437,6 @@ private: SignalAboutToRunApplication m_AboutToRun; SignalFinishedRunApplication m_FinishedRun; - SignalModInstalled m_ModInstalled; SignalUserInterfaceInitialized m_UserInterfaceInitialized; SignalProfileChanged m_ProfileChanged; SignalPluginSettingChanged m_PluginSettingChanged; diff --git a/src/organizerproxy.cpp b/src/organizerproxy.cpp index 2932e6bf..6f4b0cc9 100644 --- a/src/organizerproxy.cpp +++ b/src/organizerproxy.cpp @@ -271,11 +271,6 @@ bool OrganizerProxy::onFinishedRun(const std::functiononFinishedRun(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) { // Always call this one to allow plugin to initialize themselves even when not active: diff --git a/src/organizerproxy.h b/src/organizerproxy.h index cc059aa9..907375fe 100644 --- a/src/organizerproxy.h +++ b/src/organizerproxy.h @@ -61,7 +61,6 @@ public: virtual bool onAboutToRun(const std::function &func); virtual bool onFinishedRun(const std::function &func); - virtual bool onModInstalled(const std::function &func); virtual bool onUserInterfaceInitialized(std::function const& func); virtual bool onProfileChanged(std::function const& func); virtual bool onPluginSettingChanged(std::function const& func); -- cgit v1.3.1