mirror of
https://github.com/ModOrganizer2/modorganizer.git
synced 2026-07-27 13:58:24 -07:00
Merge pull request #1226 from Holt59/fix-ipluginlist-callbacks
Change for onPluginStateChanged to take a list of plugins.
This commit is contained in:
+45
-12
@@ -312,10 +312,14 @@ void PluginList::enableESP(const QString &name, bool enable)
|
||||
std::map<QString, int>::iterator iter = m_ESPsByName.find(name.toLower());
|
||||
|
||||
if (iter != m_ESPsByName.end()) {
|
||||
auto enabled = m_ESPs[iter->second].enabled;
|
||||
m_ESPs[iter->second].enabled =
|
||||
enable | m_ESPs[iter->second].forceEnabled;
|
||||
|
||||
emit writePluginsList();
|
||||
if (enabled != m_ESPs[iter->second].enabled) {
|
||||
pluginStatesChanged({ name }, state(name));
|
||||
}
|
||||
} else {
|
||||
reportError(tr("Plugin not found: %1").arg(qUtf8Printable(name)));
|
||||
}
|
||||
@@ -335,30 +339,36 @@ int PluginList::findPluginByPriority(int priority)
|
||||
void PluginList::enableSelected(const QItemSelectionModel *selectionModel)
|
||||
{
|
||||
if (selectionModel->hasSelection()) {
|
||||
bool dirty = false;
|
||||
QStringList dirty;
|
||||
for (auto row : selectionModel->selectedRows(COL_PRIORITY)) {
|
||||
int rowIndex = findPluginByPriority(row.data().toInt());
|
||||
if (!m_ESPs[rowIndex].enabled) {
|
||||
m_ESPs[rowIndex].enabled = true;
|
||||
dirty = true;
|
||||
dirty.append(m_ESPs[rowIndex].name);
|
||||
}
|
||||
}
|
||||
if (dirty) emit writePluginsList();
|
||||
if (!dirty.isEmpty()) {
|
||||
emit writePluginsList();
|
||||
pluginStatesChanged(dirty, IPluginList::PluginState::STATE_ACTIVE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void PluginList::disableSelected(const QItemSelectionModel *selectionModel)
|
||||
{
|
||||
if (selectionModel->hasSelection()) {
|
||||
bool dirty = false;
|
||||
QStringList dirty;
|
||||
for (auto row : selectionModel->selectedRows(COL_PRIORITY)) {
|
||||
int rowIndex = findPluginByPriority(row.data().toInt());
|
||||
if (!m_ESPs[rowIndex].forceEnabled && m_ESPs[rowIndex].enabled) {
|
||||
m_ESPs[rowIndex].enabled = false;
|
||||
dirty = true;
|
||||
dirty.append(m_ESPs[rowIndex].name);
|
||||
}
|
||||
}
|
||||
if (dirty) emit writePluginsList();
|
||||
if (!dirty.isEmpty()) {
|
||||
emit writePluginsList();
|
||||
pluginStatesChanged(dirty, IPluginList::PluginState::STATE_INACTIVE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -367,10 +377,17 @@ void PluginList::enableAll()
|
||||
{
|
||||
if (QMessageBox::question(nullptr, tr("Confirm"), tr("Really enable all plugins?"),
|
||||
QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) {
|
||||
QStringList dirty;
|
||||
for (ESPInfo &info : m_ESPs) {
|
||||
info.enabled = true;
|
||||
if (!info.enabled) {
|
||||
info.enabled = true;
|
||||
dirty.append(info.name);
|
||||
}
|
||||
}
|
||||
if (!dirty.isEmpty()) {
|
||||
emit writePluginsList();
|
||||
pluginStatesChanged(dirty, IPluginList::PluginState::STATE_ACTIVE);
|
||||
}
|
||||
emit writePluginsList();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -379,12 +396,17 @@ void PluginList::disableAll()
|
||||
{
|
||||
if (QMessageBox::question(nullptr, tr("Confirm"), tr("Really disable all plugins?"),
|
||||
QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) {
|
||||
QStringList dirty;
|
||||
for (ESPInfo &info : m_ESPs) {
|
||||
if (!info.forceEnabled) {
|
||||
if (!info.forceEnabled && info.enabled) {
|
||||
info.enabled = false;
|
||||
dirty.append(info.name);
|
||||
}
|
||||
}
|
||||
emit writePluginsList();
|
||||
if (!dirty.isEmpty()) {
|
||||
emit writePluginsList();
|
||||
pluginStatesChanged(dirty, IPluginList::PluginState::STATE_INACTIVE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -853,12 +875,23 @@ QString PluginList::origin(const QString &name) const
|
||||
}
|
||||
}
|
||||
|
||||
bool PluginList::onPluginStateChanged(const std::function<void (const QString &, PluginStates)> &func)
|
||||
bool PluginList::onPluginStateChanged(const std::function<void(const std::map<QString, PluginStates>&)>& func)
|
||||
{
|
||||
auto conn = m_PluginStateChanged.connect(func);
|
||||
return conn.connected();
|
||||
}
|
||||
|
||||
void PluginList::pluginStatesChanged(QStringList const& pluginNames, IPluginList::PluginStates state) const {
|
||||
if (pluginNames.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
std::map<QString, IPluginList::PluginStates> infos;
|
||||
for (auto& name : pluginNames) {
|
||||
infos[name] = state;
|
||||
}
|
||||
m_PluginStateChanged(infos);
|
||||
}
|
||||
|
||||
bool PluginList::onRefreshed(const std::function<void ()> &callback)
|
||||
{
|
||||
auto conn = m_Refreshed.connect(callback);
|
||||
@@ -1324,7 +1357,7 @@ bool PluginList::setData(const QModelIndex &modIndex, const QVariant &value, int
|
||||
IPluginList::PluginStates newState = state(modName);
|
||||
if (oldState != newState) {
|
||||
try {
|
||||
m_PluginStateChanged(modName, newState);
|
||||
pluginStatesChanged({ modName }, newState);
|
||||
testMasters();
|
||||
emit dataChanged(
|
||||
this->index(0, 0),
|
||||
|
||||
+11
-2
@@ -96,7 +96,7 @@ public:
|
||||
|
||||
typedef boost::signals2::signal<void ()> SignalRefreshed;
|
||||
typedef boost::signals2::signal<void (const QString &, int, int)> SignalPluginMoved;
|
||||
typedef boost::signals2::signal<void (const QString &, PluginStates)> SignalPluginStateChanged;
|
||||
typedef boost::signals2::signal<void (const std::map<QString, PluginStates>&)> SignalPluginStateChanged;
|
||||
|
||||
public:
|
||||
|
||||
@@ -235,7 +235,7 @@ public:
|
||||
virtual QString origin(const QString &name) const override;
|
||||
virtual void setLoadOrder(const QStringList &pluginList) override;
|
||||
virtual bool onPluginMoved(const std::function<void (const QString &, int, int)> &func) override;
|
||||
virtual bool onPluginStateChanged(const std::function<void (const QString &, PluginStates)> &func) override;
|
||||
virtual bool onPluginStateChanged(const std::function<void (const std::map<QString, PluginStates>&)> &func) override;
|
||||
|
||||
public: // implementation of the QAbstractTableModel interface
|
||||
|
||||
@@ -361,6 +361,15 @@ private:
|
||||
|
||||
int findPluginByPriority(int priority);
|
||||
|
||||
/**
|
||||
* @brief Notify MO2 plugins that the states of the given plugins have changed to the given state.
|
||||
*
|
||||
* @param pluginNames Names of the plugin.
|
||||
* @param state New state of the plugin.
|
||||
*
|
||||
*/
|
||||
void pluginStatesChanged(QStringList const& pluginNames, IPluginList::PluginStates state) const;
|
||||
|
||||
private:
|
||||
|
||||
std::vector<ESPInfo> m_ESPs;
|
||||
|
||||
Reference in New Issue
Block a user