summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAl <26797547+Al12rs@users.noreply.github.com>2020-09-01 03:59:22 -0700
committerGitHub <noreply@github.com>2020-09-01 03:59:22 -0700
commitfa6136c6711a0b651e2d8b652b78b055f0343c9b (patch)
treeb03b2d98dfdda0c19de1626d06dbe34c5407600f /src
parentf0e94c26aebae6f86a59ed974e433f96e77faec7 (diff)
parent3729f18af1ee2a84756eb729e2f2b8343c51c24a (diff)
Merge pull request #1220 from Holt59/modlist-setactive-bulk
Add a bulk-version of ModList::setActive.
Diffstat (limited to 'src')
-rw-r--r--src/modlist.cpp57
-rw-r--r--src/modlist.h15
-rw-r--r--src/organizercore.cpp5
3 files changed, 58 insertions, 19 deletions
diff --git a/src/modlist.cpp b/src/modlist.cpp
index cb08c6f4..cbd9f30c 100644
--- a/src/modlist.cpp
+++ b/src/modlist.cpp
@@ -637,18 +637,6 @@ bool ModList::setData(const QModelIndex &index, const QVariant &value, int role)
}
emit postDataChanged();
-
- IModList::ModStates newState = state(modID);
- if (oldState != newState) {
- try {
- m_ModStateChanged(info->name(), newState);
- } catch (const std::exception &e) {
- log::error("failed to invoke state changed notification: {}", e.what());
- } catch (...) {
- log::error("failed to invoke state changed notification: unknown exception");
- }
- }
-
return result;
}
@@ -834,7 +822,7 @@ void ModList::modInfoChanged(ModInfo::Ptr info)
if (info->name() == m_ChangeInfo.name) {
IModList::ModStates newState = state(info->name());
if (m_ChangeInfo.state != newState) {
- m_ModStateChanged(info->name(), newState);
+ m_ModStateChanged({ {info->name(), newState} });
}
int row = ModInfo::getIndex(info->name());
@@ -952,16 +940,41 @@ bool ModList::setActive(const QString &name, bool active)
{
unsigned int modIndex = ModInfo::getIndex(name);
if (modIndex == UINT_MAX) {
+ log::debug("Trying to {} mod {} which does not exist.",
+ active ? "enable" : "disable", name);
return false;
} else {
m_Profile->setModEnabled(modIndex, active);
-
- IModList::ModStates newState = state(modIndex);
- m_ModStateChanged(name, newState);
return true;
}
}
+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) {
+ indices.append(modIndex);
+ }
+ else {
+ log::debug("Trying to {} mod {} which does not exist.",
+ active ? "enable" : "disable", name);
+ }
+ }
+
+ if (active) {
+ m_Profile->setModsEnabled(indices, {});
+ }
+ else {
+ m_Profile->setModsEnabled({}, indices);
+ }
+
+ return indices.size();
+}
+
int ModList::priority(const QString &name) const
{
unsigned int modIndex = ModInfo::getIndex(name);
@@ -988,12 +1001,22 @@ bool ModList::setPriority(const QString &name, int newPriority)
}
}
-bool ModList::onModStateChanged(const std::function<void (const QString &, IModList::ModStates)> &func)
+bool ModList::onModStateChanged(const std::function<void(const std::map<QString, ModStates>&)>& func)
{
auto conn = m_ModStateChanged.connect(func);
return conn.connected();
}
+void ModList::notifyModStateChanged(QList<unsigned int> modIndices) const
+{
+ std::map<QString, ModStates> mods;
+ for (auto modIndex : modIndices) {
+ ModInfo::Ptr modInfo = ModInfo::getByIndex(modIndex);
+ mods.emplace(modInfo->name(), state(modIndex));
+ }
+ m_ModStateChanged(mods);
+}
+
bool ModList::onModMoved(const std::function<void (const QString &, int, int)> &func)
{
auto conn = m_ModMoved.connect(func);
diff --git a/src/modlist.h b/src/modlist.h
index 8c29300d..5312db34 100644
--- a/src/modlist.h
+++ b/src/modlist.h
@@ -70,7 +70,7 @@ public:
COL_LASTCOLUMN = COL_NOTES,
};
- typedef boost::signals2::signal<void (const QString &, ModStates)> SignalModStateChanged;
+ typedef boost::signals2::signal<void (const std::map<QString, ModStates>&)> SignalModStateChanged;
typedef boost::signals2::signal<void (const QString &, int, int)> SignalModMoved;
public:
@@ -124,6 +124,14 @@ public:
void highlightMods(const QItemSelectionModel *selection, const MOShared::DirectoryEntry &directoryEntry);
+ /**
+ * @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().
+ *
+ * @param modIndices Indices of the mods that changed.
+ */
+ void notifyModStateChanged(QList<unsigned int> modIndices) const;
+
public:
/// \copydoc MOBase::IModList::displayName
@@ -138,6 +146,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;
@@ -145,7 +156,7 @@ public:
virtual bool setPriority(const QString &name, int newPriority) override;
/// \copydoc MOBase::IModList::onModStateChanged
- virtual bool onModStateChanged(const std::function<void (const QString &, ModStates)> &func) override;
+ virtual bool onModStateChanged(const std::function<void(const std::map<QString, ModStates>&)>& func) override;
/// \copydoc MOBase::IModList::onModMoved
virtual bool onModMoved(const std::function<void (const QString &, int, int)> &func) override;
diff --git a/src/organizercore.cpp b/src/organizercore.cpp
index 28bb06db..815c80c2 100644
--- a/src/organizercore.cpp
+++ b/src/organizercore.cpp
@@ -1552,6 +1552,9 @@ void OrganizerCore::modStatusChanged(unsigned int index)
m_DirectoryStructure->getFileRegister()->sortOrigins();
refreshLists();
+
+ m_ModList.notifyModStateChanged({ index });
+
} catch (const std::exception &e) {
reportError(tr("failed to update mod list: %1").arg(e.what()));
}
@@ -1601,6 +1604,8 @@ void OrganizerCore::modStatusChanged(QList<unsigned int> index) {
m_DirectoryStructure->getFileRegister()->sortOrigins();
refreshLists();
+
+ m_ModList.notifyModStateChanged(index);
} catch (const std::exception &e) {
reportError(tr("failed to update mod list: %1").arg(e.what()));
}