summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMikaël Capelle <capelle.mikael@gmail.com>2020-08-29 12:48:17 +0200
committerMikaël Capelle <capelle.mikael@gmail.com>2020-08-29 12:48:17 +0200
commit600a4b3b14db8d7610757c852876641c49612864 (patch)
treeaa92bc736b1513081945b5c897a2ead064131502 /src
parentf0e94c26aebae6f86a59ed974e433f96e77faec7 (diff)
Add a bulk-version of ModList::setActive.
Diffstat (limited to 'src')
-rw-r--r--src/modlist.cpp34
-rw-r--r--src/modlist.h3
2 files changed, 37 insertions, 0 deletions
diff --git a/src/modlist.cpp b/src/modlist.cpp
index cb08c6f4..b093fd88 100644
--- a/src/modlist.cpp
+++ b/src/modlist.cpp
@@ -962,6 +962,40 @@ bool ModList::setActive(const QString &name, bool active)
}
}
+int ModList::setActive(const QStringList& names, bool active) {
+
+ // We only add indices for mods that exist (modIndex != UINT_MAX)
+ // and that can be enabled / disabled.
+ QList<unsigned int> indices;
+ for (const auto& name : names) {
+ auto modIndex = ModInfo::getIndex(name);
+ if (modIndex != UINT_MAX) {
+
+ // This check is not done by the bulk Profile::setModsEnabled, so we
+ // do it here.
+ ModInfo::Ptr modInfo = ModInfo::getByIndex(modIndex);
+ if (!modInfo->alwaysEnabled()) {
+ indices.append(modIndex);
+ }
+ }
+ }
+
+ if (active) {
+ m_Profile->setModsEnabled(indices, {});
+ }
+ else {
+ m_Profile->setModsEnabled({}, indices);
+ }
+
+ // Notify callbacks:
+ for (auto modIndex : indices) {
+ IModList::ModStates newState = state(modIndex);
+ m_ModStateChanged(ModInfo::getByIndex(modIndex)->name(), newState);
+ }
+
+ return indices.size();
+}
+
int ModList::priority(const QString &name) const
{
unsigned int modIndex = ModInfo::getIndex(name);
diff --git a/src/modlist.h b/src/modlist.h
index 8c29300d..22eb7962 100644
--- a/src/modlist.h
+++ b/src/modlist.h
@@ -138,6 +138,9 @@ public:
/// \copydoc MOBase::IModList::setActive
virtual bool setActive(const QString &name, bool active) override;
+ /// \copydoc MOBase::IModList::setActive
+ int setActive(const QStringList& names, bool active) override;
+
/// \copydoc MOBase::IModList::priority
virtual int priority(const QString &name) const override;