summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChris Bessent <lost.dragonist@gmail.com>2022-01-23 11:09:56 -0700
committerChris Bessent <lost.dragonist@gmail.com>2022-01-23 11:11:22 -0700
commit0b14cc4753f2a5c359b842f2573124bdabb6d0b3 (patch)
treee78c3227318102f1af22fc221aec9a0de2bd27d9 /src
parentcee8d5ed72299a34f7b2ccd4c31e35f9eff0801d (diff)
Enforce the priority rules on every refresh
Diffstat (limited to 'src')
-rw-r--r--src/pluginlist.cpp77
-rw-r--r--src/pluginlist.h1
2 files changed, 64 insertions, 14 deletions
diff --git a/src/pluginlist.cpp b/src/pluginlist.cpp
index 657ada17..52434e89 100644
--- a/src/pluginlist.cpp
+++ b/src/pluginlist.cpp
@@ -273,6 +273,7 @@ void PluginList::refresh(const QString &profileName
}
fixPrimaryPlugins();
+ fixPluginRelationships();
testMasters();
@@ -318,6 +319,51 @@ void PluginList::fixPrimaryPlugins()
}
}
+void PluginList::fixPluginRelationships()
+{
+ TimeThis timer("PluginList::fixPluginRelationships");
+
+ // Count the types of plugins
+ int masterCount = 0;
+ for (auto plugin : m_ESPs) {
+ if (plugin.isLight || plugin.isMaster) {
+ masterCount++;
+ }
+ }
+
+ // Ensure masters are up top and normal plugins are down below
+ for (int i = 0; i < m_ESPs.size(); i++) {
+ ESPInfo& plugin = m_ESPs[i];
+ if (plugin.isLight || plugin.isMaster) {
+ if (plugin.priority > masterCount) {
+ int newPriority = masterCount + 1;
+ setPluginPriority(i, newPriority);
+ }
+ }
+ else {
+ if (plugin.priority < masterCount) {
+ int newPriority = masterCount + 1;
+ setPluginPriority(i, newPriority);
+ }
+ }
+ }
+
+ // Ensure master/child relationships are observed
+ for (int i = 0; i < m_ESPs.size(); i++) {
+ ESPInfo& plugin = m_ESPs[i];
+ int newPriority = plugin.priority;
+ for (auto master : plugin.masters) {
+ auto iter = m_ESPsByName.find(master);
+ if (iter != m_ESPsByName.end()) {
+ newPriority = std::max(newPriority, m_ESPs[iter->second].priority);
+ }
+ }
+ if (newPriority != plugin.priority) {
+ setPluginPriority(i, newPriority);
+ }
+ }
+}
+
void PluginList::fixPriorities()
{
std::vector<std::pair<int, int>> espPrios;
@@ -1514,23 +1560,26 @@ void PluginList::setPluginPriority(int row, int &newPriority, bool isForced)
}
try {
- if (newPriorityTemp > oldPriority) {
- // priority is higher than the old, so the gap we left is in lower priorities
- for (int i = oldPriority + 1; i <= newPriorityTemp; ++i) {
- --m_ESPs.at(m_ESPsByPriority.at(i)).priority;
+ if (newPriorityTemp != oldPriority) {
+ if (newPriorityTemp > oldPriority) {
+ // priority is higher than the old, so the gap we left is in lower priorities
+ for (int i = oldPriority + 1; i <= newPriorityTemp; ++i) {
+ --m_ESPs.at(m_ESPsByPriority.at(i)).priority;
+ }
+ emit dataChanged(index(oldPriority + 1, 0), index(newPriorityTemp, columnCount()));
}
- emit dataChanged(index(oldPriority + 1, 0), index(newPriorityTemp, columnCount()));
- } else {
- for (int i = newPriorityTemp; i < oldPriority; ++i) {
- ++m_ESPs.at(m_ESPsByPriority.at(i)).priority;
+ else {
+ for (int i = newPriorityTemp; i < oldPriority; ++i) {
+ ++m_ESPs.at(m_ESPsByPriority.at(i)).priority;
+ }
+ emit dataChanged(index(newPriorityTemp, 0), index(oldPriority - 1, columnCount()));
+ ++newPriority;
}
- emit dataChanged(index(newPriorityTemp, 0), index(oldPriority - 1, columnCount()));
- ++newPriority;
- }
- m_ESPs.at(row).priority = newPriorityTemp;
- emit dataChanged(index(row, 0), index(row, columnCount()));
- m_PluginMoved(m_ESPs[row].name, oldPriority, newPriorityTemp);
+ m_ESPs.at(row).priority = newPriorityTemp;
+ emit dataChanged(index(row, 0), index(row, columnCount()));
+ m_PluginMoved(m_ESPs[row].name, oldPriority, newPriorityTemp);
+ }
} catch (const std::out_of_range&) {
reportError(tr("failed to restore load order for %1").arg(m_ESPs[row].name));
}
diff --git a/src/pluginlist.h b/src/pluginlist.h
index a6efa71b..af70396e 100644
--- a/src/pluginlist.h
+++ b/src/pluginlist.h
@@ -360,6 +360,7 @@ private:
void fixPrimaryPlugins();
void fixPriorities();
+ void fixPluginRelationships();
int findPluginByPriority(int priority);