diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/downloadmanager.cpp | 18 | ||||
| -rw-r--r-- | src/downloadmanager.h | 18 | ||||
| -rw-r--r-- | src/downloadmanagerproxy.cpp | 26 | ||||
| -rw-r--r-- | src/downloadmanagerproxy.h | 14 | ||||
| -rw-r--r-- | src/modlist.cpp | 19 | ||||
| -rw-r--r-- | src/modlist.h | 38 | ||||
| -rw-r--r-- | src/modlistproxy.cpp | 27 | ||||
| -rw-r--r-- | src/modlistproxy.h | 14 | ||||
| -rw-r--r-- | src/organizercore.cpp | 8 | ||||
| -rw-r--r-- | src/organizercore.h | 7 | ||||
| -rw-r--r-- | src/pluginlist.cpp | 27 | ||||
| -rw-r--r-- | src/pluginlist.h | 51 | ||||
| -rw-r--r-- | src/pluginlistproxy.cpp | 27 | ||||
| -rw-r--r-- | src/pluginlistproxy.h | 13 |
14 files changed, 198 insertions, 109 deletions
diff --git a/src/downloadmanager.cpp b/src/downloadmanager.cpp index 648cfaa2..ff4e9458 100644 --- a/src/downloadmanager.cpp +++ b/src/downloadmanager.cpp @@ -201,7 +201,7 @@ QString DownloadManager::DownloadInfo::currentURL() DownloadManager::DownloadManager(NexusInterface *nexusInterface, QObject *parent) : - IDownloadManager(parent), m_NexusInterface(nexusInterface), m_DirWatcher(), m_ShowHidden(false), + m_NexusInterface(nexusInterface), m_DirWatcher(), m_ShowHidden(false), m_ParentWidget(nullptr) { m_OrganizerCore = dynamic_cast<OrganizerCore*>(parent); @@ -1787,24 +1787,24 @@ QString DownloadManager::downloadPath(int id) return getFilePath(id); } -bool DownloadManager::onDownloadComplete(const std::function<void(int)>& callback) +boost::signals2::connection DownloadManager::onDownloadComplete(const std::function<void(int)>& callback) { - return m_DownloadComplete.connect(callback).connected(); + return m_DownloadComplete.connect(callback); } -bool DownloadManager::onDownloadPaused(const std::function<void(int)>& callback) +boost::signals2::connection DownloadManager::onDownloadPaused(const std::function<void(int)>& callback) { - return m_DownloadPaused.connect(callback).connected(); + return m_DownloadPaused.connect(callback); } -bool DownloadManager::onDownloadFailed(const std::function<void(int)>& callback) +boost::signals2::connection DownloadManager::onDownloadFailed(const std::function<void(int)>& callback) { - return m_DownloadFailed.connect(callback).connected(); + return m_DownloadFailed.connect(callback); } -bool DownloadManager::onDownloadRemoved(const std::function<void(int)>& callback) +boost::signals2::connection DownloadManager::onDownloadRemoved(const std::function<void(int)>& callback) { - return m_DownloadRemoved.connect(callback).connected(); + return m_DownloadRemoved.connect(callback); } int DownloadManager::indexByName(const QString &fileName) const diff --git a/src/downloadmanager.h b/src/downloadmanager.h index bd8e9799..953ab88b 100644 --- a/src/downloadmanager.h +++ b/src/downloadmanager.h @@ -48,7 +48,7 @@ class OrganizerCore; /*! * \brief manages downloading of files and provides progress information for gui elements **/ -class DownloadManager : public MOBase::IDownloadManager +class DownloadManager : public QObject { Q_OBJECT @@ -127,6 +127,8 @@ private: DownloadInfo() : m_TotalSize(0), m_ReQueried(false), m_Hidden(false), m_SpeedDiff(std::tuple<int,int,int,int,int>(0,0,0,0,0)), m_HasData(false) {} }; + friend class DownloadManagerProxy; + using SignalDownloadCallback = boost::signals2::signal<void(int)>; public: @@ -366,14 +368,14 @@ public: public: // IDownloadManager interface: - int startDownloadURLs(const QStringList &urls) override; - int startDownloadNexusFile(int modID, int fileID) override; - QString downloadPath(int id) override; + int startDownloadURLs(const QStringList &urls); + int startDownloadNexusFile(int modID, int fileID); + QString downloadPath(int id); - bool onDownloadComplete(const std::function<void(int)>& callback) override; - bool onDownloadPaused(const std::function<void(int)>& callback) override; - bool onDownloadFailed(const std::function<void(int)>& callback) override; - bool onDownloadRemoved(const std::function<void(int)>& callback) override; + boost::signals2::connection onDownloadComplete(const std::function<void(int)>& callback); + boost::signals2::connection onDownloadPaused(const std::function<void(int)>& callback); + boost::signals2::connection onDownloadFailed(const std::function<void(int)>& callback); + boost::signals2::connection onDownloadRemoved(const std::function<void(int)>& callback); /** * @brief retrieve a download index from the filename diff --git a/src/downloadmanagerproxy.cpp b/src/downloadmanagerproxy.cpp index 4a5c9b6b..06dad21f 100644 --- a/src/downloadmanagerproxy.cpp +++ b/src/downloadmanagerproxy.cpp @@ -4,9 +4,23 @@ #include "organizerproxy.h" using namespace MOBase; +using namespace MOShared; -DownloadManagerProxy::DownloadManagerProxy(OrganizerProxy* oproxy, IDownloadManager* downloadManager) : - m_OrganizerProxy(oproxy), m_Proxied(downloadManager) { } +DownloadManagerProxy::DownloadManagerProxy(OrganizerProxy* oproxy, DownloadManager* downloadManager) : + m_OrganizerProxy(oproxy), m_Proxied(downloadManager) +{ + m_Connections.push_back(m_Proxied->onDownloadComplete(callSignalIfPluginActive(m_OrganizerProxy, m_DownloadComplete))); + m_Connections.push_back(m_Proxied->onDownloadFailed(callSignalIfPluginActive(m_OrganizerProxy, m_DownloadFailed))); + m_Connections.push_back(m_Proxied->onDownloadRemoved(callSignalIfPluginActive(m_OrganizerProxy, m_DownloadRemoved))); + m_Connections.push_back(m_Proxied->onDownloadPaused(callSignalIfPluginActive(m_OrganizerProxy, m_DownloadPaused))); +} + +DownloadManagerProxy::~DownloadManagerProxy() +{ + for (auto& conn : m_Connections) { + conn.disconnect(); + } +} int DownloadManagerProxy::startDownloadURLs(const QStringList& urls) { @@ -25,20 +39,20 @@ QString DownloadManagerProxy::downloadPath(int id) bool DownloadManagerProxy::onDownloadComplete(const std::function<void(int)>& callback) { - return m_Proxied->onDownloadComplete(MOShared::callIfPluginActive(m_OrganizerProxy, callback)); + return m_DownloadComplete.connect(callback).connected(); } bool DownloadManagerProxy::onDownloadPaused(const std::function<void(int)>& callback) { - return m_Proxied->onDownloadPaused(MOShared::callIfPluginActive(m_OrganizerProxy, callback)); + return m_DownloadPaused.connect(callback).connected(); } bool DownloadManagerProxy::onDownloadFailed(const std::function<void(int)>& callback) { - return m_Proxied->onDownloadFailed(MOShared::callIfPluginActive(m_OrganizerProxy, callback)); + return m_DownloadFailed.connect(callback).connected(); } bool DownloadManagerProxy::onDownloadRemoved(const std::function<void(int)>& callback) { - return m_Proxied->onDownloadRemoved(MOShared::callIfPluginActive(m_OrganizerProxy, callback)); + return m_DownloadRemoved.connect(callback).connected(); } diff --git a/src/downloadmanagerproxy.h b/src/downloadmanagerproxy.h index f41b60c6..23692179 100644 --- a/src/downloadmanagerproxy.h +++ b/src/downloadmanagerproxy.h @@ -2,6 +2,7 @@ #define DOWNLOADMANAGERPROXY_H #include <idownloadmanager.h> +#include "downloadmanager.h" class OrganizerProxy; @@ -10,8 +11,8 @@ class DownloadManagerProxy : public MOBase::IDownloadManager public: - DownloadManagerProxy(OrganizerProxy* oproxy, IDownloadManager* downloadManager); - virtual ~DownloadManagerProxy() { } + DownloadManagerProxy(OrganizerProxy* oproxy, DownloadManager* downloadManager); + virtual ~DownloadManagerProxy(); int startDownloadURLs(const QStringList& urls) override; int startDownloadNexusFile(int modID, int fileID) override; @@ -25,7 +26,14 @@ public: private: OrganizerProxy* m_OrganizerProxy; - IDownloadManager* m_Proxied; + DownloadManager* m_Proxied; + + DownloadManager::SignalDownloadCallback m_DownloadComplete; + DownloadManager::SignalDownloadCallback m_DownloadPaused; + DownloadManager::SignalDownloadCallback m_DownloadFailed; + DownloadManager::SignalDownloadCallback m_DownloadRemoved; + + std::vector<boost::signals2::connection> m_Connections; }; #endif // ORGANIZERPROXY_H diff --git a/src/modlist.cpp b/src/modlist.cpp index d7324e7f..237f65fa 100644 --- a/src/modlist.cpp +++ b/src/modlist.cpp @@ -1020,19 +1020,19 @@ bool ModList::setPriority(const QString &name, int newPriority) } } -bool ModList::onModInstalled(const std::function<void(MOBase::IModInterface*)>& func) +boost::signals2::connection ModList::onModInstalled(const std::function<void(MOBase::IModInterface*)>& func) { - return m_ModInstalled.connect(func).connected(); + return m_ModInstalled.connect(func); } -bool ModList::onModRemoved(const std::function<void(QString const&)>& func) +boost::signals2::connection ModList::onModRemoved(const std::function<void(QString const&)>& func) { - return m_ModRemoved.connect(func).connected(); + return m_ModRemoved.connect(func); } -bool ModList::onModStateChanged(const std::function<void(const std::map<QString, ModStates>&)>& func) +boost::signals2::connection ModList::onModStateChanged(const std::function<void(const std::map<QString, IModList::ModStates>&)>& func) { - return m_ModStateChanged.connect(func).connected(); + return m_ModStateChanged.connect(func); } void ModList::notifyModInstalled(MOBase::IModInterface* mod) const @@ -1047,7 +1047,7 @@ void ModList::notifyModRemoved(QString const& modName) const void ModList::notifyModStateChanged(QList<unsigned int> modIndices) const { - std::map<QString, ModStates> mods; + std::map<QString, IModList::ModStates> mods; for (auto modIndex : modIndices) { ModInfo::Ptr modInfo = ModInfo::getByIndex(modIndex); mods.emplace(modInfo->name(), state(modIndex)); @@ -1055,10 +1055,9 @@ void ModList::notifyModStateChanged(QList<unsigned int> modIndices) const m_ModStateChanged(mods); } -bool ModList::onModMoved(const std::function<void (const QString &, int, int)> &func) +boost::signals2::connection ModList::onModMoved(const std::function<void (const QString &, int, int)> &func) { - auto conn = m_ModMoved.connect(func); - return conn.connected(); + return m_ModMoved.connect(func); } bool ModList::dropURLs(const QMimeData *mimeData, int row, const QModelIndex &parent) diff --git a/src/modlist.h b/src/modlist.h index 385ca04c..fd26bb91 100644 --- a/src/modlist.h +++ b/src/modlist.h @@ -49,7 +49,7 @@ class OrganizerCore; * This is used in a view in the main window of MO. It combines general information about
* the mods from ModInfo with status information from the Profile
**/
-class ModList : public QAbstractItemModel, public MOBase::IModList
+class ModList : public QAbstractItemModel
{
Q_OBJECT
@@ -70,9 +70,11 @@ public: COL_LASTCOLUMN = COL_NOTES,
};
+ friend class ModListProxy;
+
using SignalModInstalled = boost::signals2::signal<void(MOBase::IModInterface*)>;
using SignalModRemoved = boost::signals2::signal<void(QString const&)>;
- using SignalModStateChanged = boost::signals2::signal<void (const std::map<QString, ModStates>&)>;
+ using SignalModStateChanged = boost::signals2::signal<void (const std::map<QString, MOBase::IModList::ModStates>&)>;
using SignalModMoved = boost::signals2::signal<void (const QString &, int, int)>;
public:
@@ -153,37 +155,37 @@ public: public:
/// \copydoc MOBase::IModList::displayName
- virtual QString displayName(const QString &internalName) const override;
+ QString displayName(const QString &internalName) const;
/// \copydoc MOBase::IModList::allMods
- virtual QStringList allMods() const override;
- virtual QStringList allModsByProfilePriority(MOBase::IProfile* profile = nullptr) const override;
+ QStringList allMods() const;
+ QStringList allModsByProfilePriority(MOBase::IProfile* profile = nullptr) const;
// \copydoc MOBase::IModList::getMod
- MOBase::IModInterface* getMod(const QString& name) const override;
+ MOBase::IModInterface* getMod(const QString& name) const;
// \copydoc MOBase::IModList::remove
- bool removeMod(MOBase::IModInterface* mod) override;
+ bool removeMod(MOBase::IModInterface* mod);
/// \copydoc MOBase::IModList::state
- virtual ModStates state(const QString &name) const override;
+ MOBase::IModList::ModStates state(const QString &name) const;
/// \copydoc MOBase::IModList::setActive
- virtual bool setActive(const QString &name, bool active) override;
+ bool setActive(const QString &name, bool active);
/// \copydoc MOBase::IModList::setActive
- int setActive(const QStringList& names, bool active) override;
+ int setActive(const QStringList& names, bool active);
/// \copydoc MOBase::IModList::priority
- virtual int priority(const QString &name) const override;
+ int priority(const QString &name) const;
/// \copydoc MOBase::IModList::setPriority
- virtual bool setPriority(const QString &name, int newPriority) override;
+ bool setPriority(const QString &name, int newPriority);
- bool onModInstalled(const std::function<void(MOBase::IModInterface*)>& func) override;
- bool onModRemoved(const std::function<void(QString const&)>& func) override;
- bool onModStateChanged(const std::function<void(const std::map<QString, ModStates>&)>& func) override;
- bool onModMoved(const std::function<void (const QString &, int, int)> &func) override;
+ boost::signals2::connection onModInstalled(const std::function<void(MOBase::IModInterface*)>& func);
+ boost::signals2::connection onModRemoved(const std::function<void(QString const&)>& func);
+ boost::signals2::connection onModStateChanged(const std::function<void(const std::map<QString, MOBase::IModList::ModStates>&)>& func);
+ boost::signals2::connection onModMoved(const std::function<void (const QString &, int, int)> &func);
public: // implementation of virtual functions of QAbstractItemModel
@@ -335,7 +337,7 @@ private: bool dropMod(const QMimeData *mimeData, int row, const QModelIndex &parent);
- ModStates state(unsigned int modIndex) const;
+ MOBase::IModList::ModStates state(unsigned int modIndex) const;
bool moveSelection(QAbstractItemView *itemView, int direction);
@@ -359,7 +361,7 @@ private: struct TModInfoChange {
QString name;
- QFlags<IModList::ModState> state;
+ QFlags<MOBase::IModList::ModState> state;
};
private:
diff --git a/src/modlistproxy.cpp b/src/modlistproxy.cpp index 8fcbdbdf..991476da 100644 --- a/src/modlistproxy.cpp +++ b/src/modlistproxy.cpp @@ -1,11 +1,26 @@ #include "modlistproxy.h" #include "organizerproxy.h" #include "proxyutils.h" +#include "modlist.h" using namespace MOBase; +using namespace MOShared; -ModListProxy::ModListProxy(OrganizerProxy* oproxy, IModList* modlist) : - m_OrganizerProxy(oproxy), m_Proxied(modlist) { } +ModListProxy::ModListProxy(OrganizerProxy* oproxy, ModList* modlist) : + m_OrganizerProxy(oproxy), m_Proxied(modlist) +{ + m_Connections.push_back(m_Proxied->onModInstalled(callSignalIfPluginActive(m_OrganizerProxy, m_ModInstalled))); + m_Connections.push_back(m_Proxied->onModMoved(callSignalIfPluginActive(m_OrganizerProxy, m_ModMoved))); + m_Connections.push_back(m_Proxied->onModRemoved(callSignalIfPluginActive(m_OrganizerProxy, m_ModRemoved))); + m_Connections.push_back(m_Proxied->onModStateChanged(callSignalIfPluginActive(m_OrganizerProxy, m_ModStateChanged))); +} + +ModListProxy::~ModListProxy() +{ + for (auto& conn : m_Connections) { + conn.disconnect(); + } +} QString ModListProxy::displayName(const QString& internalName) const { @@ -59,20 +74,20 @@ bool ModListProxy::setPriority(const QString& name, int newPriority) bool ModListProxy::onModInstalled(const std::function<void(IModInterface*)>& func) { - return m_Proxied->onModInstalled(MOShared::callIfPluginActive(m_OrganizerProxy, func)); + return m_ModInstalled.connect(func).connected(); } bool ModListProxy::onModRemoved(const std::function<void(QString const&)>& func) { - return m_Proxied->onModRemoved(MOShared::callIfPluginActive(m_OrganizerProxy, func)); + return m_ModRemoved.connect(func).connected(); } bool ModListProxy::onModStateChanged(const std::function<void(const std::map<QString, ModStates>&)>& func) { - return m_Proxied->onModStateChanged(MOShared::callIfPluginActive(m_OrganizerProxy, func)); + return m_ModStateChanged.connect(func).connected(); } bool ModListProxy::onModMoved(const std::function<void(const QString&, int, int)>& func) { - return m_Proxied->onModMoved(MOShared::callIfPluginActive(m_OrganizerProxy, func)); + return m_ModMoved.connect(func).connected(); } diff --git a/src/modlistproxy.h b/src/modlistproxy.h index c805cf4e..12d74e4a 100644 --- a/src/modlistproxy.h +++ b/src/modlistproxy.h @@ -2,6 +2,7 @@ #define MODLISTPROXY_H #include <imodlist.h> +#include "modlist.h" class OrganizerProxy; @@ -10,8 +11,8 @@ class ModListProxy : public MOBase::IModList public: - ModListProxy(OrganizerProxy* oproxy, IModList* modlist); - virtual ~ModListProxy() { } + ModListProxy(OrganizerProxy* oproxy, ModList* modlist); + virtual ~ModListProxy(); QString displayName(const QString& internalName) const override; QStringList allMods() const override; @@ -31,7 +32,14 @@ public: private: OrganizerProxy* m_OrganizerProxy; - IModList* m_Proxied; + ModList* m_Proxied; + + ModList::SignalModInstalled m_ModInstalled; + ModList::SignalModMoved m_ModMoved; + ModList::SignalModRemoved m_ModRemoved; + ModList::SignalModStateChanged m_ModStateChanged; + + std::vector<boost::signals2::connection> m_Connections; }; #endif // ORGANIZERPROXY_H diff --git a/src/organizercore.cpp b/src/organizercore.cpp index 7016f9a1..6a333a22 100644 --- a/src/organizercore.cpp +++ b/src/organizercore.cpp @@ -72,6 +72,7 @@ #include <tuple> #include <utility> +#include "organizerproxy.h" using namespace MOShared; using namespace MOBase; @@ -96,7 +97,7 @@ OrganizerCore::OrganizerCore(Settings &settings) , m_Settings(settings) , m_Updater(&NexusInterface::instance()) , m_ModList(m_PluginContainer, this) - , m_PluginList(this) + , m_PluginList(*this) , m_DirectoryRefresher(new DirectoryRefresher(settings.refreshThreadCount())) , m_DirectoryStructure(new DirectoryEntry(L"data", nullptr, 0)) , m_DownloadManager(&NexusInterface::instance(), this) @@ -1529,6 +1530,11 @@ IPluginGame const *OrganizerCore::managedGame() const return m_GamePlugin; } +IOrganizer const* OrganizerCore::managedGameOrganizer() const +{ + return m_PluginContainer->requirements(m_GamePlugin).m_Organizer; +} + std::vector<QString> OrganizerCore::enabledArchives() { std::vector<QString> result; diff --git a/src/organizercore.h b/src/organizercore.h index 1b77b7f5..cb612eae 100644 --- a/src/organizercore.h +++ b/src/organizercore.h @@ -234,6 +234,13 @@ public: MOBase::IPluginGame const *managedGame() const;
/**
+ * @brief Retrieve the organizer proxy of the currently managed game.
+ *
+ */
+ MOBase::IOrganizer const* managedGameOrganizer() const;
+
+
+ /**
* @return the list of contents for the currently managed game, or an empty vector
* if the game plugin does not implement the ModDataContent feature.
*/
diff --git a/src/pluginlist.cpp b/src/pluginlist.cpp index 8d04b592..504b17c5 100644 --- a/src/pluginlist.cpp +++ b/src/pluginlist.cpp @@ -55,6 +55,7 @@ along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>. #include <algorithm>
#include <stdexcept>
+#include "organizercore.h"
using namespace MOBase;
using namespace MOShared;
@@ -94,8 +95,9 @@ static QString TruncateString(const QString& text) }
-PluginList::PluginList(QObject *parent)
- : QAbstractItemModel(parent)
+PluginList::PluginList(OrganizerCore& organizer)
+ : QAbstractItemModel(&organizer)
+ , m_Organizer(organizer)
, m_FontMetrics(QFont())
{
connect(this, SIGNAL(writePluginsList()), this, SLOT(generatePluginIndexes()));
@@ -267,7 +269,7 @@ void PluginList::refresh(const QString &profileName updateIndices();
if (gamePlugins) {
- gamePlugins->readPluginLists(this);
+ gamePlugins->readPluginLists(m_Organizer.managedGameOrganizer()->pluginList());
}
testMasters();
@@ -546,7 +548,7 @@ void PluginList::saveTo(const QString &lockedOrderFileName {
GamePlugins *gamePlugins = m_GamePlugin->feature<GamePlugins>();
if (gamePlugins) {
- gamePlugins->writePluginLists(this);
+ gamePlugins->writePluginLists(m_Organizer.managedGameOrganizer()->pluginList());
}
writeLockedOrder(lockedOrderFileName);
@@ -875,13 +877,12 @@ QString PluginList::origin(const QString &name) const }
}
-bool PluginList::onPluginStateChanged(const std::function<void(const std::map<QString, PluginStates>&)>& func)
+boost::signals2::connection PluginList::onPluginStateChanged(const std::function<void(const std::map<QString, PluginStates>&)>& func)
{
- auto conn = m_PluginStateChanged.connect(func);
- return conn.connected();
+ return m_PluginStateChanged.connect(func);
}
-void PluginList::pluginStatesChanged(QStringList const& pluginNames, IPluginList::PluginStates state) const {
+void PluginList::pluginStatesChanged(QStringList const& pluginNames, PluginStates state) const {
if (pluginNames.isEmpty()) {
return;
}
@@ -892,17 +893,15 @@ void PluginList::pluginStatesChanged(QStringList const& pluginNames, IPluginList m_PluginStateChanged(infos);
}
-bool PluginList::onRefreshed(const std::function<void ()> &callback)
+boost::signals2::connection PluginList::onRefreshed(const std::function<void ()> &callback)
{
- auto conn = m_Refreshed.connect(callback);
- return conn.connected();
+ return m_Refreshed.connect(callback);
}
-bool PluginList::onPluginMoved(const std::function<void (const QString &, int, int)> &func)
+boost::signals2::connection PluginList::onPluginMoved(const std::function<void (const QString &, int, int)> &func)
{
- auto conn = m_PluginMoved.connect(func);
- return conn.connected();
+ return m_PluginMoved.connect(func);
}
diff --git a/src/pluginlist.h b/src/pluginlist.h index 0b49b86f..5f0cef3d 100644 --- a/src/pluginlist.h +++ b/src/pluginlist.h @@ -43,6 +43,8 @@ namespace MOBase { class IPluginGame; } #include <vector>
#include <map>
+class OrganizerCore;
+
template <class C>
class ChangeBracket {
@@ -79,7 +81,7 @@ private: /**
* @brief model representing the plugins (.esp/.esm) in the current virtual data folder
**/
-class PluginList : public QAbstractItemModel, public MOBase::IPluginList
+class PluginList : public QAbstractItemModel
{
Q_OBJECT
friend class ChangeBracket<PluginList>;
@@ -94,9 +96,13 @@ public: COL_LASTCOLUMN = COL_MODINDEX
};
- typedef boost::signals2::signal<void ()> SignalRefreshed;
- typedef boost::signals2::signal<void (const QString &, int, int)> SignalPluginMoved;
- typedef boost::signals2::signal<void (const std::map<QString, PluginStates>&)> SignalPluginStateChanged;
+ using PluginStates = MOBase::IPluginList::PluginStates;
+
+ friend class PluginListProxy;
+
+ using SignalRefreshed = boost::signals2::signal<void ()>;
+ using SignalPluginMoved = boost::signals2::signal<void (const QString &, int, int)>;
+ using SignalPluginStateChanged = boost::signals2::signal<void (const std::map<QString, PluginStates>&)>;
public:
@@ -105,7 +111,7 @@ public: *
* @param parent parent object
**/
- PluginList(QObject *parent = nullptr);
+ PluginList(OrganizerCore &organizer);
~PluginList();
@@ -221,21 +227,22 @@ public: public:
- virtual QStringList pluginNames() const override;
- virtual PluginStates state(const QString &name) const override;
- virtual void setState(const QString &name, PluginStates state) override;
- virtual int priority(const QString &name) const override;
- virtual int loadOrder(const QString &name) const override;
- virtual bool setPriority(const QString& name, int newPriority) override;
- virtual bool onRefreshed(const std::function<void()> &callback);
- virtual bool isMaster(const QString &name) const override;
- virtual bool isLight(const QString &name) const;
- virtual bool isLightFlagged(const QString &name) const;
- virtual QStringList masters(const QString &name) const override;
- 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 std::map<QString, PluginStates>&)> &func) override;
+ QStringList pluginNames() const;
+ PluginStates state(const QString &name) const;
+ void setState(const QString &name, PluginStates state);
+ int priority(const QString &name) const;
+ int loadOrder(const QString &name) const;
+ bool setPriority(const QString& name, int newPriority);
+ bool isMaster(const QString &name) const;
+ bool isLight(const QString &name) const;
+ bool isLightFlagged(const QString &name) const;
+ QStringList masters(const QString &name) const;
+ QString origin(const QString &name) const;
+ void setLoadOrder(const QStringList& pluginList);
+
+ boost::signals2::connection onRefreshed(const std::function<void()>& callback);
+ boost::signals2::connection onPluginMoved(const std::function<void(const QString&, int, int)>& func);
+ boost::signals2::connection onPluginStateChanged(const std::function<void (const std::map<QString, PluginStates>&)> &func);
public: // implementation of the QAbstractTableModel interface
@@ -368,10 +375,12 @@ private: * @param state New state of the plugin.
*
*/
- void pluginStatesChanged(QStringList const& pluginNames, IPluginList::PluginStates state) const;
+ void pluginStatesChanged(QStringList const& pluginNames, PluginStates state) const;
private:
+ OrganizerCore& m_Organizer;
+
std::vector<ESPInfo> m_ESPs;
mutable std::map<QString, QByteArray> m_LastSaveHash;
diff --git a/src/pluginlistproxy.cpp b/src/pluginlistproxy.cpp index 1f8dc2b4..b51d108b 100644 --- a/src/pluginlistproxy.cpp +++ b/src/pluginlistproxy.cpp @@ -3,11 +3,24 @@ #include "proxyutils.h" using namespace MOBase; +using namespace MOShared; -PluginListProxy::PluginListProxy(OrganizerProxy* oproxy, IPluginList* pluginlist) : - m_OrganizerProxy(oproxy), m_Proxied(pluginlist) { } +PluginListProxy::PluginListProxy(OrganizerProxy* oproxy, PluginList* pluginlist) : + m_OrganizerProxy(oproxy), m_Proxied(pluginlist) +{ + m_Connections.push_back(m_Proxied->onRefreshed(callSignalIfPluginActive(m_OrganizerProxy, m_Refreshed))); + m_Connections.push_back(m_Proxied->onPluginMoved(callSignalIfPluginActive(m_OrganizerProxy, m_PluginMoved))); + m_Connections.push_back(m_Proxied->onPluginStateChanged(callSignalIfPluginActive(m_OrganizerProxy, m_PluginStateChanged))); +} + +PluginListProxy::~PluginListProxy() +{ + for (auto& conn : m_Connections) { + conn.disconnect(); + } +} -QStringList PluginListProxy::pluginNames() const +QStringList PluginListProxy::pluginNames() const { return m_Proxied->pluginNames(); } @@ -57,17 +70,17 @@ QString PluginListProxy::origin(const QString& name) const return m_Proxied->origin(name); } -bool PluginListProxy::onRefreshed(const std::function<void()>& callback) +bool PluginListProxy::onRefreshed(const std::function<void()>& func) { - return m_Proxied->onRefreshed(MOShared::callIfPluginActive(m_OrganizerProxy, callback)); + return m_Refreshed.connect(func).connected(); } bool PluginListProxy::onPluginMoved(const std::function<void(const QString&, int, int)>& func) { - return m_Proxied->onPluginMoved(MOShared::callIfPluginActive(m_OrganizerProxy, func)); + return m_PluginMoved.connect(func).connected(); } bool PluginListProxy::onPluginStateChanged(const std::function<void(const std::map<QString, PluginStates>&)> &func) { - return m_Proxied->onPluginStateChanged(MOShared::callIfPluginActive(m_OrganizerProxy, func)); + return m_PluginStateChanged.connect(func).connected(); } diff --git a/src/pluginlistproxy.h b/src/pluginlistproxy.h index e08406e3..04a6ad55 100644 --- a/src/pluginlistproxy.h +++ b/src/pluginlistproxy.h @@ -2,6 +2,7 @@ #define PLUGINLISTPROXY_H #include <ipluginlist.h> +#include "pluginlist.h" class OrganizerProxy; @@ -10,8 +11,8 @@ class PluginListProxy : public MOBase::IPluginList public: - PluginListProxy(OrganizerProxy* oproxy, IPluginList* pluginlist); - virtual ~PluginListProxy() { } + PluginListProxy(OrganizerProxy* oproxy, PluginList* pluginlist); + virtual ~PluginListProxy(); QStringList pluginNames() const override; PluginStates state(const QString& name) const override; @@ -30,7 +31,13 @@ public: private: OrganizerProxy* m_OrganizerProxy; - IPluginList* m_Proxied; + PluginList* m_Proxied; + + PluginList::SignalRefreshed m_Refreshed; + PluginList::SignalPluginMoved m_PluginMoved; + PluginList::SignalPluginStateChanged m_PluginStateChanged; + + std::vector<boost::signals2::connection> m_Connections; }; #endif // ORGANIZERPROXY_H |
