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 From cca709baaeb415d4cc600d3274169c2db7c90bd9 Mon Sep 17 00:00:00 2001 From: Mikaël Capelle Date: Sun, 25 Oct 2020 16:18:19 +0100 Subject: Rename IOrganizer::refreshModList -> refresh. --- src/mainwindow.cpp | 20 +++++++++----------- src/organizercore.cpp | 16 +++++++++------- src/organizercore.h | 2 +- src/organizerproxy.cpp | 4 ++-- src/organizerproxy.h | 2 +- 5 files changed, 22 insertions(+), 22 deletions(-) (limited to 'src') diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 3428d72a..851900a0 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -1730,7 +1730,7 @@ void MainWindow::activateSelectedProfile() m_ModListSortProxy->setProfile(m_OrganizerCore.currentProfile()); refreshSaveList(); - m_OrganizerCore.refreshModList(); + m_OrganizerCore.refresh(); updateModCount(); updatePluginCount(); ui->statusBar->updateNormalMessage(m_OrganizerCore); @@ -2683,7 +2683,7 @@ void MainWindow::restoreBackup_clicked() if (!modDir.rename(modInfo->absolutePath(), destinationPath)) { reportError(tr("failed to rename \"%1\" to \"%2\"").arg(modInfo->absolutePath()).arg(destinationPath)); } - m_OrganizerCore.refreshModList(); + m_OrganizerCore.refresh(); } } } @@ -2833,7 +2833,7 @@ void MainWindow::backupMod_clicked() QMessageBox::information(this, tr("Failed"), tr("Failed to create backup.")); } - m_OrganizerCore.refreshModList(); + m_OrganizerCore.refresh(); } void MainWindow::resumeDownload(int downloadIndex) @@ -3618,7 +3618,7 @@ void MainWindow::createEmptyMod_clicked() return; } - m_OrganizerCore.refreshModList(); + m_OrganizerCore.refresh(); if (newPriority >= 0) { m_OrganizerCore.modList()->changeModPriority(ModInfo::getIndex(name), newPriority); @@ -3656,7 +3656,7 @@ void MainWindow::createSeparator_clicked() } if (m_OrganizerCore.createMod(name) == nullptr) { return; } - m_OrganizerCore.refreshModList(); + m_OrganizerCore.refresh(); if (newPriority >= 0) { @@ -3811,7 +3811,7 @@ void MainWindow::doMoveOverwriteContentToMod(const QString &modAbsolutePath) log::error("Move operation failed: {}", formatSystemMessage(e)); } - m_OrganizerCore.refreshModList(); + m_OrganizerCore.refresh(); } void MainWindow::clearOverwrite() @@ -3835,7 +3835,7 @@ void MainWindow::clearOverwrite() delList.push_back(overwriteDir.absoluteFilePath(f)); if (shellDelete(delList, true)) { scheduleCheckForProblems(); - m_OrganizerCore.refreshModList(); + m_OrganizerCore.refresh(); } else { const auto e = GetLastError(); log::error("Delete operation failed: {}", formatSystemMessage(e)); @@ -5133,9 +5133,7 @@ void MainWindow::on_actionSettings_triggered() ui->dataTabShowFromArchives->setCheckState(Qt::Checked); ui->dataTabShowFromArchives->setEnabled(true); } - m_OrganizerCore.refreshModList(); - m_OrganizerCore.refreshDirectoryStructure(); - m_OrganizerCore.refreshLists(); + m_OrganizerCore.refresh(); } if (settings.paths().cache() != oldCacheDirectory) { @@ -6358,7 +6356,7 @@ void MainWindow::on_restoreModsButton_clicked() tr("Failed to restore the backup. Errorcode: %1") .arg(formatSystemMessage(e))); } - m_OrganizerCore.refreshModList(false); + m_OrganizerCore.refresh(false); } } diff --git a/src/organizercore.cpp b/src/organizercore.cpp index 989fdcc2..ac485c91 100644 --- a/src/organizercore.cpp +++ b/src/organizercore.cpp @@ -678,7 +678,7 @@ bool OrganizerCore::removeMod(MOBase::IModInterface *mod) void OrganizerCore::modDataChanged(MOBase::IModInterface *) { - refreshModList(false); + refresh(false); } QVariant OrganizerCore::pluginSetting(const QString &pluginName, @@ -740,7 +740,7 @@ MOBase::IModInterface *OrganizerCore::installMod(const QString &fileName, if (result == IPluginInstaller::RESULT_SUCCESS) { MessageDialog::showMessage(tr("Installation successful"), qApp->activeWindow()); - refreshModList(); + refresh(); int modIndex = ModInfo::getIndex(modName); if (modIndex != UINT_MAX) { @@ -776,7 +776,7 @@ MOBase::IModInterface *OrganizerCore::installMod(const QString &fileName, "If this was prior to a FOMOD setup, this warning may be ignored. " "However, if this was during installation, the mod will likely be missing files."), QMessageBox::Ok); - refreshModList(); + refresh(); } } return nullptr; @@ -822,7 +822,7 @@ void OrganizerCore::installDownload(int index) if (result == IPluginInstaller::RESULT_SUCCESS) { MessageDialog::showMessage(tr("Installation successful"), qApp->activeWindow()); - refreshModList(); + refresh(); int modIndex = ModInfo::getIndex(modName); if (modIndex != UINT_MAX) { @@ -855,7 +855,7 @@ void OrganizerCore::installDownload(int index) "If this was prior to a FOMOD setup, this warning may be ignored. " "However, if this was during installation, the mod will likely be missing files."), QMessageBox::Ok); - refreshModList(); + refresh(); } } } catch (const std::exception &e) { @@ -1147,7 +1147,7 @@ bool OrganizerCore::onPluginSettingChanged(std::function& func); diff --git a/src/organizerproxy.cpp b/src/organizerproxy.cpp index 6f4b0cc9..5e720ea8 100644 --- a/src/organizerproxy.cpp +++ b/src/organizerproxy.cpp @@ -178,9 +178,9 @@ bool OrganizerProxy::waitForApplication(HANDLE handle, LPDWORD exitCode) const } } -void OrganizerProxy::refreshModList(bool saveChanges) +void OrganizerProxy::refresh(bool saveChanges) { - m_Proxied->refreshModList(saveChanges); + m_Proxied->refresh(saveChanges); } IModInterface *OrganizerProxy::installMod(const QString &fileName, const QString &nameSuggestion) diff --git a/src/organizerproxy.h b/src/organizerproxy.h index 907375fe..29210ff2 100644 --- a/src/organizerproxy.h +++ b/src/organizerproxy.h @@ -57,7 +57,7 @@ public: virtual HANDLE startApplication(const QString &executable, const QStringList &args = QStringList(), const QString &cwd = "", const QString &profile = "", const QString &forcedCustomOverwrite = "", bool ignoreCustomOverwrite = false); virtual bool waitForApplication(HANDLE handle, LPDWORD exitCode = nullptr) const; - virtual void refreshModList(bool saveChanges); + virtual void refresh(bool saveChanges); virtual bool onAboutToRun(const std::function &func); virtual bool onFinishedRun(const std::function &func); -- cgit v1.3.1 From d804a5e186b421c75e01338ce9d22601c78bbb38 Mon Sep 17 00:00:00 2001 From: Mikaël Capelle Date: Sun, 25 Oct 2020 16:53:31 +0100 Subject: Move IOrganizer::modsSortedByProfilePriority() to IModList::allModsByProfilePriority(). --- src/mainwindow.cpp | 4 ++-- src/modlist.cpp | 8 ++++++++ src/modlist.h | 1 + src/modlistproxy.cpp | 5 +++++ src/modlistproxy.h | 1 + src/organizercore.cpp | 8 ++++---- src/organizercore.h | 10 +++++++++- src/organizerproxy.cpp | 5 ----- src/organizerproxy.h | 2 -- 9 files changed, 30 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 851900a0..a2afb8a0 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -3775,7 +3775,7 @@ void MainWindow::moveOverwriteContentToExistingMod() QString modAbsolutePath; - for (const auto& mod : m_OrganizerCore.modsSortedByProfilePriority()) { + for (const auto& mod : m_OrganizerCore.modsSortedByProfilePriority(m_OrganizerCore.currentProfile())) { if (result.compare(mod) == 0) { ModInfo::Ptr modInfo = ModInfo::getByIndex(ModInfo::getIndex(mod)); modAbsolutePath = modInfo->absolutePath(); @@ -6549,7 +6549,7 @@ void MainWindow::sendSelectedModsToSeparator_clicked() int newPriority = INT_MAX; bool foundSection = false; - for (auto mod : m_OrganizerCore.modsSortedByProfilePriority()) { + for (auto mod : m_OrganizerCore.modsSortedByProfilePriority(m_OrganizerCore.currentProfile())) { unsigned int modIndex = ModInfo::getIndex(mod); ModInfo::Ptr modInfo = ModInfo::getByIndex(modIndex); if (!foundSection && result.compare(mod) == 0) { diff --git a/src/modlist.cpp b/src/modlist.cpp index 90433963..d72cede9 100644 --- a/src/modlist.cpp +++ b/src/modlist.cpp @@ -931,6 +931,14 @@ QStringList ModList::allMods() const return result; } +QStringList ModList::allModsByProfilePriority(MOBase::IProfile* profile) const +{ + Profile* mo2Profile = profile == nullptr ? + m_Organizer->currentProfile() + : dynamic_cast(profile); + return m_Organizer->modsSortedByProfilePriority(mo2Profile); +} + IModList::ModStates ModList::state(const QString &name) const { unsigned int modIndex = ModInfo::getIndex(name); diff --git a/src/modlist.h b/src/modlist.h index baaeede3..8748cb30 100644 --- a/src/modlist.h +++ b/src/modlist.h @@ -157,6 +157,7 @@ public: /// \copydoc MOBase::IModList::allMods virtual QStringList allMods() const override; + virtual QStringList allModsByProfilePriority(MOBase::IProfile* profile = nullptr) const override; /// \copydoc MOBase::IModList::state virtual ModStates state(const QString &name) const override; diff --git a/src/modlistproxy.cpp b/src/modlistproxy.cpp index 321f1873..51cea1ee 100644 --- a/src/modlistproxy.cpp +++ b/src/modlistproxy.cpp @@ -17,6 +17,11 @@ QStringList ModListProxy::allMods() const return m_Proxied->allMods(); } +QStringList ModListProxy::allModsByProfilePriority(MOBase::IProfile* profile) const +{ + return m_Proxied->allModsByProfilePriority(profile); +} + IModList::ModStates ModListProxy::state(const QString& name) const { return m_Proxied->state(name); diff --git a/src/modlistproxy.h b/src/modlistproxy.h index 5b0a7114..2e653850 100644 --- a/src/modlistproxy.h +++ b/src/modlistproxy.h @@ -15,6 +15,7 @@ public: QString displayName(const QString& internalName) const override; QStringList allMods() const override; + QStringList allModsByProfilePriority(MOBase::IProfile* profile = nullptr) const override; ModStates state(const QString& name) const override; bool setActive(const QString& name, bool active) override; int setActive(const QStringList& names, bool active) override; diff --git a/src/organizercore.cpp b/src/organizercore.cpp index ac485c91..a66a6450 100644 --- a/src/organizercore.cpp +++ b/src/organizercore.cpp @@ -974,13 +974,13 @@ ModList *OrganizerCore::modList() return &m_ModList; } -QStringList OrganizerCore::modsSortedByProfilePriority() const +QStringList OrganizerCore::modsSortedByProfilePriority(Profile *profile) const { QStringList res; - for (int i = currentProfile()->getPriorityMinimum(); - i < currentProfile()->getPriorityMinimum() + (int)currentProfile()->numRegularMods(); + for (int i = profile->getPriorityMinimum(); + i < profile->getPriorityMinimum() + (int)profile->numRegularMods(); ++i) { - int modIndex = currentProfile()->modIndexByPriority(i); + int modIndex = profile->modIndexByPriority(i); auto modInfo = ModInfo::getByIndex(modIndex); if (!modInfo->hasFlag(ModInfo::FLAG_OVERWRITE) && !modInfo->hasFlag(ModInfo::FLAG_BACKUP)) { diff --git a/src/organizercore.h b/src/organizercore.h index 226c5c0a..95c7ef51 100644 --- a/src/organizercore.h +++ b/src/organizercore.h @@ -289,6 +289,15 @@ public: static void setGlobalCrashDumpsType(CrashDumpsType crashDumpsType); static std::wstring crashDumpsPath(); + /** + * @brief Returns the name of all the mods in the priority order of the given profile. + * + * @param profile Profile to use for the mod order. + * + * @return the name of all the mods in the priority order of the given profile. + */ + QStringList modsSortedByProfilePriority(Profile* profile) const; + public: MOBase::IModRepositoryBridge *createNexusBridge() const; QString profileName() const; @@ -318,7 +327,6 @@ public: PluginList *pluginList(); ModList *modList(); void refresh(bool saveChanges = true); - QStringList modsSortedByProfilePriority() const; bool onAboutToRun(const std::function& func); bool onFinishedRun(const std::function& func); diff --git a/src/organizerproxy.cpp b/src/organizerproxy.cpp index 5e720ea8..e369c1a3 100644 --- a/src/organizerproxy.cpp +++ b/src/organizerproxy.cpp @@ -254,11 +254,6 @@ MOBase::IPluginGame const *OrganizerProxy::managedGame() const return m_Proxied->managedGame(); } -QStringList OrganizerProxy::modsSortedByProfilePriority() const -{ - return m_Proxied->modsSortedByProfilePriority(); -} - // CALLBACKS bool OrganizerProxy::onAboutToRun(const std::function& func) diff --git a/src/organizerproxy.h b/src/organizerproxy.h index 29210ff2..a72d01b3 100644 --- a/src/organizerproxy.h +++ b/src/organizerproxy.h @@ -67,8 +67,6 @@ public: virtual MOBase::IPluginGame const *managedGame() const; - virtual QStringList modsSortedByProfilePriority() const; - private: OrganizerCore *m_Proxied; -- cgit v1.3.1 From 4b8c2b4a3b3f262564775a24a3296d740b97d146 Mon Sep 17 00:00:00 2001 From: Mikaël Capelle Date: Sun, 25 Oct 2020 17:16:04 +0100 Subject: Add missing notifyModRemoved(). --- src/modlist.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src') diff --git a/src/modlist.cpp b/src/modlist.cpp index d72cede9..94c8883d 100644 --- a/src/modlist.cpp +++ b/src/modlist.cpp @@ -1205,6 +1205,8 @@ void ModList::removeRowForce(int row, const QModelIndex &parent) m_Profile->refreshModStatus(); // removes the mod from the status list m_Profile->writeModlist(); // this ensures the modified list gets written back before new mods can be installed + notifyModRemoved(modInfo->name()); + if (wasEnabled) { emit removeOrigin(modInfo->name()); } -- cgit v1.3.1 From a216177b879bea6db659c65b0c37bbfe70ce08fd Mon Sep 17 00:00:00 2001 From: Mikaël Capelle Date: Sun, 25 Oct 2020 17:16:17 +0100 Subject: Move IOrganizer::removeMod() to IModList::removeMod(). --- src/modlist.cpp | 12 ++++++++++++ src/modlist.h | 3 +++ src/modlistproxy.cpp | 5 +++++ src/modlistproxy.h | 1 + src/organizercore.cpp | 11 ----------- src/organizercore.h | 1 - src/organizerproxy.cpp | 5 ----- src/organizerproxy.h | 1 - 8 files changed, 21 insertions(+), 18 deletions(-) (limited to 'src') diff --git a/src/modlist.cpp b/src/modlist.cpp index 94c8883d..40a9af5e 100644 --- a/src/modlist.cpp +++ b/src/modlist.cpp @@ -939,6 +939,18 @@ QStringList ModList::allModsByProfilePriority(MOBase::IProfile* profile) const return m_Organizer->modsSortedByProfilePriority(mo2Profile); } +bool ModList::removeMod(MOBase::IModInterface* mod) +{ + unsigned int index = ModInfo::getIndex(mod->name()); + if (index == UINT_MAX) { + return mod->remove(); + } + else { + return ModInfo::removeMod(index); + } + notifyModRemoved(mod->name()); +} + IModList::ModStates ModList::state(const QString &name) const { unsigned int modIndex = ModInfo::getIndex(name); diff --git a/src/modlist.h b/src/modlist.h index 8748cb30..810b0efd 100644 --- a/src/modlist.h +++ b/src/modlist.h @@ -159,6 +159,9 @@ public: virtual QStringList allMods() const override; virtual QStringList allModsByProfilePriority(MOBase::IProfile* profile = nullptr) const override; + // \copydoc MOBase::IModList::remove + bool removeMod(MOBase::IModInterface* mod) override; + /// \copydoc MOBase::IModList::state virtual ModStates state(const QString &name) const override; diff --git a/src/modlistproxy.cpp b/src/modlistproxy.cpp index 51cea1ee..660e4b9d 100644 --- a/src/modlistproxy.cpp +++ b/src/modlistproxy.cpp @@ -22,6 +22,11 @@ QStringList ModListProxy::allModsByProfilePriority(MOBase::IProfile* profile) co return m_Proxied->allModsByProfilePriority(profile); } +bool ModListProxy::removeMod(MOBase::IModInterface* mod) +{ + return m_Proxied->removeMod(mod); +} + IModList::ModStates ModListProxy::state(const QString& name) const { return m_Proxied->state(name); diff --git a/src/modlistproxy.h b/src/modlistproxy.h index 2e653850..486564a4 100644 --- a/src/modlistproxy.h +++ b/src/modlistproxy.h @@ -16,6 +16,7 @@ public: QString displayName(const QString& internalName) const override; QStringList allMods() const override; QStringList allModsByProfilePriority(MOBase::IProfile* profile = nullptr) const override; + bool removeMod(MOBase::IModInterface* mod) override; ModStates state(const QString& name) const override; bool setActive(const QString& name, bool active) override; int setActive(const QStringList& names, bool active) override; diff --git a/src/organizercore.cpp b/src/organizercore.cpp index a66a6450..76d53791 100644 --- a/src/organizercore.cpp +++ b/src/organizercore.cpp @@ -665,17 +665,6 @@ MOBase::IModInterface *OrganizerCore::createMod(GuessedValue &name) .data(); } -bool OrganizerCore::removeMod(MOBase::IModInterface *mod) -{ - unsigned int index = ModInfo::getIndex(mod->name()); - if (index == UINT_MAX) { - return mod->remove(); - } else { - return ModInfo::removeMod(index); - } - m_ModList.notifyModRemoved(mod->name()); -} - void OrganizerCore::modDataChanged(MOBase::IModInterface *) { refresh(false); diff --git a/src/organizercore.h b/src/organizercore.h index 95c7ef51..50d44c49 100644 --- a/src/organizercore.h +++ b/src/organizercore.h @@ -310,7 +310,6 @@ public: MOBase::IModInterface *getMod(const QString &name) const; MOBase::IPluginGame *getGame(const QString &gameName) const; MOBase::IModInterface *createMod(MOBase::GuessedValue &name); - bool removeMod(MOBase::IModInterface *mod); void modDataChanged(MOBase::IModInterface *mod); QVariant pluginSetting(const QString &pluginName, const QString &key) const; void setPluginSetting(const QString &pluginName, const QString &key, const QVariant &value); diff --git a/src/organizerproxy.cpp b/src/organizerproxy.cpp index e369c1a3..cb9e0e1d 100644 --- a/src/organizerproxy.cpp +++ b/src/organizerproxy.cpp @@ -82,11 +82,6 @@ IModInterface *OrganizerProxy::createMod(MOBase::GuessedValue &name) return m_Proxied->createMod(name); } -bool OrganizerProxy::removeMod(IModInterface *mod) -{ - return m_Proxied->removeMod(mod); -} - void OrganizerProxy::modDataChanged(IModInterface *mod) { m_Proxied->modDataChanged(mod); diff --git a/src/organizerproxy.h b/src/organizerproxy.h index a72d01b3..16ae21eb 100644 --- a/src/organizerproxy.h +++ b/src/organizerproxy.h @@ -35,7 +35,6 @@ public: virtual MOBase::IModInterface *getMod(const QString &name) const; virtual MOBase::IPluginGame *getGame(const QString &gameName) const; virtual MOBase::IModInterface *createMod(MOBase::GuessedValue &name); - virtual bool removeMod(MOBase::IModInterface *mod); virtual void modDataChanged(MOBase::IModInterface *mod); virtual QVariant pluginSetting(const QString &pluginName, const QString &key) const; virtual void setPluginSetting(const QString &pluginName, const QString &key, const QVariant &value); -- cgit v1.3.1 From 551e8353e090040ee337e718cf0f1b9fe31a0423 Mon Sep 17 00:00:00 2001 From: Mikaël Capelle Date: Sun, 25 Oct 2020 17:46:29 +0100 Subject: Move IOrganizer::getMod() to IModList::getMod(). --- src/mainwindow.cpp | 8 ++++---- src/modlist.cpp | 6 ++++++ src/modlist.h | 3 +++ src/modlistproxy.cpp | 5 +++++ src/modlistproxy.h | 1 + src/organizercore.cpp | 6 ------ src/organizercore.h | 1 - src/organizerproxy.cpp | 5 ----- src/organizerproxy.h | 1 - 9 files changed, 19 insertions(+), 17 deletions(-) (limited to 'src') diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index a2afb8a0..85aa0df1 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -3603,7 +3603,7 @@ void MainWindow::createEmptyMod_clicked() } } - if (m_OrganizerCore.getMod(name) != nullptr) { + if (m_OrganizerCore.modList()->getMod(name) != nullptr) { reportError(tr("A mod with this name already exists")); return; } @@ -3638,13 +3638,13 @@ void MainWindow::createSeparator_clicked() GUESS_USER); if (!ok) { return; } } - if (m_OrganizerCore.getMod(name) != nullptr) + if (m_OrganizerCore.modList()->getMod(name) != nullptr) { reportError(tr("A separator with this name already exists")); return; } name->append("_separator"); - if (m_OrganizerCore.getMod(name) != nullptr) + if (m_OrganizerCore.modList()->getMod(name) != nullptr) { return; } @@ -3739,7 +3739,7 @@ void MainWindow::createModFromOverwrite() } } - if (m_OrganizerCore.getMod(name) != nullptr) { + if (m_OrganizerCore.modList()->getMod(name) != nullptr) { reportError(tr("A mod with this name already exists")); return; } diff --git a/src/modlist.cpp b/src/modlist.cpp index 40a9af5e..98ee3f3a 100644 --- a/src/modlist.cpp +++ b/src/modlist.cpp @@ -939,6 +939,12 @@ QStringList ModList::allModsByProfilePriority(MOBase::IProfile* profile) const return m_Organizer->modsSortedByProfilePriority(mo2Profile); } +MOBase::IModInterface* ModList::getMod(const QString& name) const +{ + unsigned int index = ModInfo::getIndex(name); + return index == UINT_MAX ? nullptr : ModInfo::getByIndex(index).data(); +} + bool ModList::removeMod(MOBase::IModInterface* mod) { unsigned int index = ModInfo::getIndex(mod->name()); diff --git a/src/modlist.h b/src/modlist.h index 810b0efd..385ca04c 100644 --- a/src/modlist.h +++ b/src/modlist.h @@ -159,6 +159,9 @@ public: virtual QStringList allMods() const override; virtual QStringList allModsByProfilePriority(MOBase::IProfile* profile = nullptr) const override; + // \copydoc MOBase::IModList::getMod + MOBase::IModInterface* getMod(const QString& name) const override; + // \copydoc MOBase::IModList::remove bool removeMod(MOBase::IModInterface* mod) override; diff --git a/src/modlistproxy.cpp b/src/modlistproxy.cpp index 660e4b9d..8fcbdbdf 100644 --- a/src/modlistproxy.cpp +++ b/src/modlistproxy.cpp @@ -22,6 +22,11 @@ QStringList ModListProxy::allModsByProfilePriority(MOBase::IProfile* profile) co return m_Proxied->allModsByProfilePriority(profile); } +IModInterface* ModListProxy::getMod(const QString& name) const +{ + return m_Proxied->getMod(name); +} + bool ModListProxy::removeMod(MOBase::IModInterface* mod) { return m_Proxied->removeMod(mod); diff --git a/src/modlistproxy.h b/src/modlistproxy.h index 486564a4..c805cf4e 100644 --- a/src/modlistproxy.h +++ b/src/modlistproxy.h @@ -16,6 +16,7 @@ public: QString displayName(const QString& internalName) const override; QStringList allMods() const override; QStringList allModsByProfilePriority(MOBase::IProfile* profile = nullptr) const override; + MOBase::IModInterface* getMod(const QString& name) const override; bool removeMod(MOBase::IModInterface* mod) override; ModStates state(const QString& name) const override; bool setActive(const QString& name, bool active) override; diff --git a/src/organizercore.cpp b/src/organizercore.cpp index 76d53791..82305c1a 100644 --- a/src/organizercore.cpp +++ b/src/organizercore.cpp @@ -618,12 +618,6 @@ MOBase::VersionInfo OrganizerCore::appVersion() const return m_Updater.getVersion(); } -MOBase::IModInterface *OrganizerCore::getMod(const QString &name) const -{ - unsigned int index = ModInfo::getIndex(name); - return index == UINT_MAX ? nullptr : ModInfo::getByIndex(index).data(); -} - MOBase::IPluginGame *OrganizerCore::getGame(const QString &name) const { for (IPluginGame *game : m_PluginContainer->plugins()) { diff --git a/src/organizercore.h b/src/organizercore.h index 50d44c49..61caeed0 100644 --- a/src/organizercore.h +++ b/src/organizercore.h @@ -307,7 +307,6 @@ public: QString basePath() const; QString modsPath() const; MOBase::VersionInfo appVersion() const; - MOBase::IModInterface *getMod(const QString &name) const; MOBase::IPluginGame *getGame(const QString &gameName) const; MOBase::IModInterface *createMod(MOBase::GuessedValue &name); void modDataChanged(MOBase::IModInterface *mod); diff --git a/src/organizerproxy.cpp b/src/organizerproxy.cpp index cb9e0e1d..56e40ae5 100644 --- a/src/organizerproxy.cpp +++ b/src/organizerproxy.cpp @@ -67,11 +67,6 @@ VersionInfo OrganizerProxy::appVersion() const return m_Proxied->appVersion(); } -IModInterface *OrganizerProxy::getMod(const QString &name) const -{ - return m_Proxied->getMod(name); -} - IPluginGame *OrganizerProxy::getGame(const QString &gameName) const { return m_Proxied->getGame(gameName); diff --git a/src/organizerproxy.h b/src/organizerproxy.h index 16ae21eb..6cf9de77 100644 --- a/src/organizerproxy.h +++ b/src/organizerproxy.h @@ -32,7 +32,6 @@ public: virtual QString basePath() const; virtual QString modsPath() const; virtual MOBase::VersionInfo appVersion() const; - virtual MOBase::IModInterface *getMod(const QString &name) const; virtual MOBase::IPluginGame *getGame(const QString &gameName) const; virtual MOBase::IModInterface *createMod(MOBase::GuessedValue &name); virtual void modDataChanged(MOBase::IModInterface *mod); -- cgit v1.3.1 From 0ca5d2843e48169e58978439f9f6bc60c579efce Mon Sep 17 00:00:00 2001 From: Mikaël Capelle Date: Sun, 25 Oct 2020 19:29:08 +0100 Subject: Use static_cast instead of dynamic_cast. --- src/modlist.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src') diff --git a/src/modlist.cpp b/src/modlist.cpp index 98ee3f3a..f4c034dc 100644 --- a/src/modlist.cpp +++ b/src/modlist.cpp @@ -934,8 +934,7 @@ QStringList ModList::allMods() const QStringList ModList::allModsByProfilePriority(MOBase::IProfile* profile) const { Profile* mo2Profile = profile == nullptr ? - m_Organizer->currentProfile() - : dynamic_cast(profile); + m_Organizer->currentProfile() : static_cast(profile); return m_Organizer->modsSortedByProfilePriority(mo2Profile); } -- cgit v1.3.1