diff options
| author | Mikaƫl Capelle <capelle.mikael@gmail.com> | 2020-10-21 20:08:01 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-10-21 20:08:01 +0200 |
| commit | 52cfb8e8a7609c8b763652e1575a769dd5fe1b02 (patch) | |
| tree | 6febde8afe518f8f33a1067b734cf2faadb760ca | |
| parent | ef82ddd36ae30e654841257634b26fa563319f9b (diff) | |
| parent | 3c1f206d7d29d3b3d27082aca23dafd87a95a71b (diff) | |
Merge pull request #1260 from Holt59/iplugin-setactive-fix
Fix usage of isActive
| -rw-r--r-- | src/CMakeLists.txt | 10 | ||||
| -rw-r--r-- | src/downloadmanager.cpp | 31 | ||||
| -rw-r--r-- | src/downloadmanager.h | 21 | ||||
| -rw-r--r-- | src/downloadmanagerproxy.cpp | 44 | ||||
| -rw-r--r-- | src/downloadmanagerproxy.h | 31 | ||||
| -rw-r--r-- | src/installationmanager.cpp | 8 | ||||
| -rw-r--r-- | src/mainwindow.cpp | 3 | ||||
| -rw-r--r-- | src/modlistproxy.cpp | 53 | ||||
| -rw-r--r-- | src/modlistproxy.h | 32 | ||||
| -rw-r--r-- | src/organizerproxy.cpp | 83 | ||||
| -rw-r--r-- | src/organizerproxy.h | 18 | ||||
| -rw-r--r-- | src/plugincontainer.cpp | 2 | ||||
| -rw-r--r-- | src/pluginlistproxy.cpp | 73 | ||||
| -rw-r--r-- | src/pluginlistproxy.h | 36 | ||||
| -rw-r--r-- | src/previewgenerator.cpp | 8 | ||||
| -rw-r--r-- | src/proxyutils.h | 26 |
16 files changed, 429 insertions, 50 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index f1f54cbc..e95179b8 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -33,7 +33,6 @@ add_filter(NAME src/core GROUPS nexusinterface nxmaccessmanager organizercore - organizerproxy apiuseraccount processrunner qdirfiletree @@ -147,6 +146,14 @@ add_filter(NAME src/profiles GROUPS profilesdialog ) +add_filter(NAME src/proxies GROUPS + downloadmanagerproxy + modlistproxy + organizerproxy + pluginlistproxy + proxyutils +) + add_filter(NAME src/register GROUPS shared/directoryentry shared/fileentry @@ -188,6 +195,7 @@ add_filter(NAME src/utilities GROUPS shared/windows_error thread_utils json + glob_matching ) add_filter(NAME src/widgets GROUPS diff --git a/src/downloadmanager.cpp b/src/downloadmanager.cpp index 3e6010db..5db0cbdf 100644 --- a/src/downloadmanager.cpp +++ b/src/downloadmanager.cpp @@ -694,6 +694,7 @@ void DownloadManager::removeFile(int index, bool deleteFile) if(!download->m_Hidden) metaSettings.setValue("removed", true); } + m_DownloadRemoved(index); endDisableDirWatcher(); } @@ -1453,13 +1454,19 @@ void DownloadManager::setState(DownloadManager::DownloadInfo *info, DownloadMana } info->m_State = state; switch (state) { - case STATE_PAUSED: + case STATE_PAUSED: { + info->m_Reply->abort(); + info->m_Output.close(); + m_DownloadPaused(row); + } break; case STATE_ERROR: { info->m_Reply->abort(); info->m_Output.close(); + m_DownloadFailed(row); } break; case STATE_CANCELED: { info->m_Reply->abort(); + m_DownloadFailed(row); } break; case STATE_FETCHINGMODINFO: { m_RequestIDs.insert(m_NexusInterface->requestDescription(info->m_FileInfo->gameName, info->m_FileInfo->modID, this, info->m_DownloadID, QString())); @@ -1473,7 +1480,7 @@ void DownloadManager::setState(DownloadManager::DownloadInfo *info, DownloadMana } break; case STATE_READY: { createMetaFile(info); - emit downloadComplete(row); + m_DownloadComplete(row); } break; default: /* NOP */ break; } @@ -1792,6 +1799,26 @@ QString DownloadManager::downloadPath(int id) return getFilePath(id); } +bool DownloadManager::onDownloadComplete(const std::function<void(int)>& callback) +{ + return m_DownloadComplete.connect(callback).connected(); +} + +bool DownloadManager::onDownloadPaused(const std::function<void(int)>& callback) +{ + return m_DownloadPaused.connect(callback).connected(); +} + +bool DownloadManager::onDownloadFailed(const std::function<void(int)>& callback) +{ + return m_DownloadFailed.connect(callback).connected(); +} + +bool DownloadManager::onDownloadRemoved(const std::function<void(int)>& callback) +{ + return m_DownloadRemoved.connect(callback).connected(); +} + int DownloadManager::indexByName(const QString &fileName) const { for (int i = 0; i < m_ActiveDownloads.size(); ++i) { diff --git a/src/downloadmanager.h b/src/downloadmanager.h index 90def927..8a0d8eed 100644 --- a/src/downloadmanager.h +++ b/src/downloadmanager.h @@ -37,6 +37,7 @@ along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>. #include <QStringList> #include <QFileSystemWatcher> #include <QSettings> +#include <boost/signals2.hpp> namespace MOBase { class IPluginGame; } @@ -126,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) {} }; + using SignalDownloadCallback = boost::signals2::signal<void(int)>; + public: /** @@ -367,11 +370,16 @@ public: */ void refreshList(); - virtual int startDownloadURLs(const QStringList &urls); +public: // IDownloadManager interface: - virtual int startDownloadNexusFile(int modID, int fileID); + int startDownloadURLs(const QStringList &urls) override; + int startDownloadNexusFile(int modID, int fileID) override; + QString downloadPath(int id) override; - virtual 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; /** * @brief retrieve a download index from the filename @@ -383,7 +391,7 @@ public: void pauseAll(); -signals: +Q_SIGNALS: void aboutToUpdate(); @@ -556,6 +564,11 @@ private: QFileSystemWatcher m_DirWatcher; + SignalDownloadCallback m_DownloadComplete; + SignalDownloadCallback m_DownloadPaused; + SignalDownloadCallback m_DownloadFailed; + SignalDownloadCallback m_DownloadRemoved; + //The dirWatcher is actually triggering off normal Mo operations such as deleting downloads or editing .meta files //so it needs to be disabled during operations that are known to cause the creation or deletion of files in the Downloads folder. //Notably using QSettings to edit a file creates a temporarily .lock file that causes the Watcher to trigger multiple listRefreshes freezing the ui. diff --git a/src/downloadmanagerproxy.cpp b/src/downloadmanagerproxy.cpp new file mode 100644 index 00000000..4a5c9b6b --- /dev/null +++ b/src/downloadmanagerproxy.cpp @@ -0,0 +1,44 @@ +#include "downloadmanagerproxy.h" + +#include "proxyutils.h" +#include "organizerproxy.h" + +using namespace MOBase; + +DownloadManagerProxy::DownloadManagerProxy(OrganizerProxy* oproxy, IDownloadManager* downloadManager) : + m_OrganizerProxy(oproxy), m_Proxied(downloadManager) { } + +int DownloadManagerProxy::startDownloadURLs(const QStringList& urls) +{ + return m_Proxied->startDownloadURLs(urls); +} + +int DownloadManagerProxy::startDownloadNexusFile(int modID, int fileID) +{ + return m_Proxied->startDownloadNexusFile(modID, fileID); +} + +QString DownloadManagerProxy::downloadPath(int id) +{ + return m_Proxied->downloadPath(id); +} + +bool DownloadManagerProxy::onDownloadComplete(const std::function<void(int)>& callback) +{ + return m_Proxied->onDownloadComplete(MOShared::callIfPluginActive(m_OrganizerProxy, callback)); +} + +bool DownloadManagerProxy::onDownloadPaused(const std::function<void(int)>& callback) +{ + return m_Proxied->onDownloadPaused(MOShared::callIfPluginActive(m_OrganizerProxy, callback)); +} + +bool DownloadManagerProxy::onDownloadFailed(const std::function<void(int)>& callback) +{ + return m_Proxied->onDownloadFailed(MOShared::callIfPluginActive(m_OrganizerProxy, callback)); +} + +bool DownloadManagerProxy::onDownloadRemoved(const std::function<void(int)>& callback) +{ + return m_Proxied->onDownloadRemoved(MOShared::callIfPluginActive(m_OrganizerProxy, callback)); +} diff --git a/src/downloadmanagerproxy.h b/src/downloadmanagerproxy.h new file mode 100644 index 00000000..f41b60c6 --- /dev/null +++ b/src/downloadmanagerproxy.h @@ -0,0 +1,31 @@ +#ifndef DOWNLOADMANAGERPROXY_H +#define DOWNLOADMANAGERPROXY_H + +#include <idownloadmanager.h> + +class OrganizerProxy; + +class DownloadManagerProxy : public MOBase::IDownloadManager +{ + +public: + + DownloadManagerProxy(OrganizerProxy* oproxy, IDownloadManager* downloadManager); + virtual ~DownloadManagerProxy() { } + + int startDownloadURLs(const QStringList& urls) override; + int startDownloadNexusFile(int modID, int fileID) override; + QString downloadPath(int id) override; + + 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; + +private: + + OrganizerProxy* m_OrganizerProxy; + IDownloadManager* m_Proxied; +}; + +#endif // ORGANIZERPROXY_H diff --git a/src/installationmanager.cpp b/src/installationmanager.cpp index e4937ed9..e9773a95 100644 --- a/src/installationmanager.cpp +++ b/src/installationmanager.cpp @@ -860,7 +860,9 @@ QStringList InstallationManager::getSupportedExtensions() const void InstallationManager::notifyInstallationStart(QString const& archive, bool reinstallation, ModInfo::Ptr currentMod) { for (auto* installer : m_Installers) { - installer->onInstallationStart(archive, reinstallation, currentMod.get()); + if (installer->isActive()) { + installer->onInstallationStart(archive, reinstallation, currentMod.get()); + } } } @@ -869,6 +871,8 @@ void InstallationManager::notifyInstallationEnd( ModInfo::Ptr newMod) { for (auto* installer : m_Installers) { - installer->onInstallationEnd(result, newMod.get()); + if (installer->isActive()) { + installer->onInstallationEnd(result, newMod.get()); + } } } diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index fa5a790c..3428d72a 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -5094,6 +5094,9 @@ void MainWindow::on_actionSettings_triggered() instManager->setModsDirectory(settings.paths().mods()); instManager->setDownloadDirectory(settings.paths().downloads()); + // Schedule a problem check since diagnose plugins may have been enabled / disabled. + scheduleCheckForProblems(); + fixCategories(); refreshFilters(); diff --git a/src/modlistproxy.cpp b/src/modlistproxy.cpp new file mode 100644 index 00000000..7ec00c49 --- /dev/null +++ b/src/modlistproxy.cpp @@ -0,0 +1,53 @@ +#include "modlistproxy.h" +#include "organizerproxy.h" +#include "proxyutils.h" + +using namespace MOBase; + +ModListProxy::ModListProxy(OrganizerProxy* oproxy, IModList* modlist) : + m_OrganizerProxy(oproxy), m_Proxied(modlist) { } + +QString ModListProxy::displayName(const QString& internalName) const +{ + return m_Proxied->displayName(internalName); +} + +QStringList ModListProxy::allMods() const +{ + return m_Proxied->allMods(); +} + +IModList::ModStates ModListProxy::state(const QString& name) const +{ + return m_Proxied->state(name); +} + +bool ModListProxy::setActive(const QString& name, bool active) +{ + return m_Proxied->setActive(name, active); +} + +int ModListProxy::setActive(const QStringList& names, bool active) +{ + return m_Proxied->setActive(names, active); +} + +int ModListProxy::priority(const QString& name) const +{ + return m_Proxied->priority(name); +} + +bool ModListProxy::setPriority(const QString& name, int newPriority) +{ + return m_Proxied->setPriority(name, newPriority); +} + +bool ModListProxy::onModStateChanged(const std::function<void(const std::map<QString, ModStates>&)>& func) +{ + return m_Proxied->onModStateChanged(MOShared::callIfPluginActive(m_OrganizerProxy, func)); +} + +bool ModListProxy::onModMoved(const std::function<void(const QString&, int, int)>& func) +{ + return m_Proxied->onModMoved(MOShared::callIfPluginActive(m_OrganizerProxy, func)); +} diff --git a/src/modlistproxy.h b/src/modlistproxy.h new file mode 100644 index 00000000..13399e0a --- /dev/null +++ b/src/modlistproxy.h @@ -0,0 +1,32 @@ +#ifndef MODLISTPROXY_H +#define MODLISTPROXY_H + +#include <imodlist.h> + +class OrganizerProxy; + +class ModListProxy : public MOBase::IModList +{ + +public: + + ModListProxy(OrganizerProxy* oproxy, IModList* modlist); + virtual ~ModListProxy() { } + + QString displayName(const QString& internalName) const override; + QStringList allMods() const override; + ModStates state(const QString& name) const override; + bool setActive(const QString& name, bool active) override; + int setActive(const QStringList& names, bool active) override; + int priority(const QString& name) const override; + bool setPriority(const QString& name, int newPriority) 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; + +private: + + OrganizerProxy* m_OrganizerProxy; + IModList* m_Proxied; +}; + +#endif // ORGANIZERPROXY_H diff --git a/src/organizerproxy.cpp b/src/organizerproxy.cpp index a5047b43..2932e6bf 100644 --- a/src/organizerproxy.cpp +++ b/src/organizerproxy.cpp @@ -5,6 +5,10 @@ #include "plugincontainer.h"
#include "settings.h"
#include "glob_matching.h"
+#include "downloadmanagerproxy.h"
+#include "modlistproxy.h"
+#include "pluginlistproxy.h"
+#include "proxyutils.h"
#include <QObject>
#include <QApplication>
@@ -13,16 +17,19 @@ using namespace MOBase; using namespace MOShared;
-OrganizerProxy::OrganizerProxy(OrganizerCore *organizer, PluginContainer *pluginContainer, const QString &pluginName)
+OrganizerProxy::OrganizerProxy(OrganizerCore* organizer, PluginContainer* pluginContainer, MOBase::IPlugin* plugin)
: m_Proxied(organizer)
, m_PluginContainer(pluginContainer)
- , m_PluginName(pluginName)
+ , m_Plugin(plugin)
+ , m_DownloadManagerProxy(std::make_unique<DownloadManagerProxy>(this, organizer->downloadManager()))
+ , m_ModListProxy(std::make_unique<ModListProxy>(this, organizer->modList()))
+ , m_PluginListProxy(std::make_unique<PluginListProxy>(this, organizer->pluginList()))
{
}
IModRepositoryBridge *OrganizerProxy::createNexusBridge() const
{
- return new NexusBridge(m_PluginContainer, m_PluginName);
+ return new NexusBridge(m_PluginContainer, m_Plugin->name());
}
QString OrganizerProxy::profileName() const
@@ -171,36 +178,6 @@ bool OrganizerProxy::waitForApplication(HANDLE handle, LPDWORD exitCode) const }
}
-bool OrganizerProxy::onAboutToRun(const std::function<bool (const QString &)> &func)
-{
- return m_Proxied->onAboutToRun(func);
-}
-
-bool OrganizerProxy::onFinishedRun(const std::function<void (const QString &, unsigned int)> &func)
-{
- return m_Proxied->onFinishedRun(func);
-}
-
-bool OrganizerProxy::onModInstalled(const std::function<void (const QString &)> &func)
-{
- return m_Proxied->onModInstalled(func);
-}
-
-bool OrganizerProxy::onUserInterfaceInitialized(std::function<void(QMainWindow*)> const& func)
-{
- return m_Proxied->onUserInterfaceInitialized(func);
-}
-
-bool OrganizerProxy::onProfileChanged(std::function<void(MOBase::IProfile*, MOBase::IProfile*)> const& func)
-{
- return m_Proxied->onProfileChanged(func);
-}
-
-bool OrganizerProxy::onPluginSettingChanged(std::function<void(QString const&, const QString& key, const QVariant&, const QVariant&)> const& func)
-{
- return m_Proxied->onPluginSettingChanged(func);
-}
-
void OrganizerProxy::refreshModList(bool saveChanges)
{
m_Proxied->refreshModList(saveChanges);
@@ -254,17 +231,17 @@ QList<MOBase::IOrganizer::FileInfo> OrganizerProxy::findFileInfos(const QString MOBase::IDownloadManager *OrganizerProxy::downloadManager() const
{
- return m_Proxied->downloadManager();
+ return m_DownloadManagerProxy.get();
}
MOBase::IPluginList *OrganizerProxy::pluginList() const
{
- return m_Proxied->pluginList();
+ return m_PluginListProxy.get();
}
MOBase::IModList *OrganizerProxy::modList() const
{
- return m_Proxied->modList();
+ return m_ModListProxy.get();
}
MOBase::IProfile *OrganizerProxy::profile() const
@@ -281,3 +258,37 @@ QStringList OrganizerProxy::modsSortedByProfilePriority() const {
return m_Proxied->modsSortedByProfilePriority();
}
+
+// CALLBACKS
+
+bool OrganizerProxy::onAboutToRun(const std::function<bool(const QString&)>& func)
+{
+ return m_Proxied->onAboutToRun(MOShared::callIfPluginActive(this, func, true));
+}
+
+bool OrganizerProxy::onFinishedRun(const std::function<void(const QString&, unsigned int)>& func)
+{
+ return m_Proxied->onFinishedRun(MOShared::callIfPluginActive(this, func));
+}
+
+bool OrganizerProxy::onModInstalled(const std::function<void(const QString&)>& func)
+{
+ return m_Proxied->onModInstalled(MOShared::callIfPluginActive(this, func));
+}
+
+bool OrganizerProxy::onUserInterfaceInitialized(std::function<void(QMainWindow*)> const& func)
+{
+ // Always call this one to allow plugin to initialize themselves even when not active:
+ return m_Proxied->onUserInterfaceInitialized(func);
+}
+
+bool OrganizerProxy::onProfileChanged(std::function<void(MOBase::IProfile*, MOBase::IProfile*)> const& func)
+{
+ return m_Proxied->onProfileChanged(MOShared::callIfPluginActive(this, func));
+}
+
+bool OrganizerProxy::onPluginSettingChanged(std::function<void(QString const&, const QString& key, const QVariant&, const QVariant&)> const& func)
+{
+ // Always call this one, otherwise plugin cannot detect they are being enabled / disabled:
+ return m_Proxied->onPluginSettingChanged(func);
+}
diff --git a/src/organizerproxy.h b/src/organizerproxy.h index 8950217d..cc059aa9 100644 --- a/src/organizerproxy.h +++ b/src/organizerproxy.h @@ -1,18 +1,28 @@ #ifndef ORGANIZERPROXY_H
#define ORGANIZERPROXY_H
+#include <memory>
+#include <iplugin.h>
#include <imoinfo.h>
class OrganizerCore;
class PluginContainer;
+class DownloadManagerProxy;
+class ModListProxy;
+class PluginListProxy;
class OrganizerProxy : public MOBase::IOrganizer
{
public:
- OrganizerProxy(OrganizerCore *organizer, PluginContainer *pluginContainer, const QString &pluginName);
+ OrganizerProxy(OrganizerCore *organizer, PluginContainer *pluginContainer, MOBase::IPlugin *plugin);
+
+ /**
+ * @return the plugin corresponding to this proxy.
+ */
+ MOBase::IPlugin* plugin() const { return m_Plugin; }
virtual MOBase::IModRepositoryBridge *createNexusBridge() const;
virtual QString profileName() const;
@@ -65,7 +75,11 @@ private: OrganizerCore *m_Proxied;
PluginContainer *m_PluginContainer;
- QString m_PluginName;
+ MOBase::IPlugin *m_Plugin;
+
+ std::unique_ptr<DownloadManagerProxy> m_DownloadManagerProxy;
+ std::unique_ptr<ModListProxy> m_ModListProxy;
+ std::unique_ptr<PluginListProxy> m_PluginListProxy;
};
diff --git a/src/plugincontainer.cpp b/src/plugincontainer.cpp index 60acc63c..4771359d 100644 --- a/src/plugincontainer.cpp +++ b/src/plugincontainer.cpp @@ -173,7 +173,7 @@ bool PluginContainer::verifyPlugin(IPlugin *plugin) {
if (plugin == nullptr) {
return false;
- } else if (!plugin->init(new OrganizerProxy(m_Organizer, this, plugin->name()))) {
+ } else if (!plugin->init(new OrganizerProxy(m_Organizer, this, plugin))) {
log::warn("plugin failed to initialize");
return false;
}
diff --git a/src/pluginlistproxy.cpp b/src/pluginlistproxy.cpp new file mode 100644 index 00000000..1f8dc2b4 --- /dev/null +++ b/src/pluginlistproxy.cpp @@ -0,0 +1,73 @@ +#include "pluginlistproxy.h" +#include "organizerproxy.h" +#include "proxyutils.h" + +using namespace MOBase; + +PluginListProxy::PluginListProxy(OrganizerProxy* oproxy, IPluginList* pluginlist) : + m_OrganizerProxy(oproxy), m_Proxied(pluginlist) { } + +QStringList PluginListProxy::pluginNames() const +{ + return m_Proxied->pluginNames(); +} + +IPluginList::PluginStates PluginListProxy::state(const QString& name) const +{ + return m_Proxied->state(name); +} + +void PluginListProxy::setState(const QString& name, PluginStates state) +{ + return m_Proxied->setState(name, state); +} + +int PluginListProxy::priority(const QString& name) const +{ + return m_Proxied->priority(name); +} + +bool PluginListProxy::setPriority(const QString& name, int newPriority) +{ + return m_Proxied->setPriority(name, newPriority); +} + +int PluginListProxy::loadOrder(const QString& name) const +{ + return m_Proxied->loadOrder(name); +} + +void PluginListProxy::setLoadOrder(const QStringList& pluginList) +{ + return m_Proxied->setLoadOrder(pluginList); +} + +bool PluginListProxy::isMaster(const QString& name) const +{ + return m_Proxied->isMaster(name); +} + +QStringList PluginListProxy::masters(const QString& name) const +{ + return m_Proxied->masters(name); +} + +QString PluginListProxy::origin(const QString& name) const +{ + return m_Proxied->origin(name); +} + +bool PluginListProxy::onRefreshed(const std::function<void()>& callback) +{ + return m_Proxied->onRefreshed(MOShared::callIfPluginActive(m_OrganizerProxy, callback)); +} + +bool PluginListProxy::onPluginMoved(const std::function<void(const QString&, int, int)>& func) +{ + return m_Proxied->onPluginMoved(MOShared::callIfPluginActive(m_OrganizerProxy, func)); +} + +bool PluginListProxy::onPluginStateChanged(const std::function<void(const std::map<QString, PluginStates>&)> &func) +{ + return m_Proxied->onPluginStateChanged(MOShared::callIfPluginActive(m_OrganizerProxy, func)); +} diff --git a/src/pluginlistproxy.h b/src/pluginlistproxy.h new file mode 100644 index 00000000..e08406e3 --- /dev/null +++ b/src/pluginlistproxy.h @@ -0,0 +1,36 @@ +#ifndef PLUGINLISTPROXY_H +#define PLUGINLISTPROXY_H + +#include <ipluginlist.h> + +class OrganizerProxy; + +class PluginListProxy : public MOBase::IPluginList +{ + +public: + + PluginListProxy(OrganizerProxy* oproxy, IPluginList* pluginlist); + virtual ~PluginListProxy() { } + + QStringList pluginNames() const override; + PluginStates state(const QString& name) const override; + void setState(const QString& name, PluginStates state) override; + int priority(const QString& name) const override; + bool setPriority(const QString& name, int newPriority) override; + int loadOrder(const QString& name) const override; + void setLoadOrder(const QStringList& pluginList) override; + bool isMaster(const QString& name) const override; + QStringList masters(const QString& name) const override; + QString origin(const QString& name) const override; + bool onRefreshed(const std::function<void()>& callback) override; + bool onPluginMoved(const std::function<void(const QString&, int, int)>& func) override; + bool onPluginStateChanged(const std::function<void(const std::map<QString, PluginStates>&)>& func) override; + +private: + + OrganizerProxy* m_OrganizerProxy; + IPluginList* m_Proxied; +}; + +#endif // ORGANIZERPROXY_H diff --git a/src/previewgenerator.cpp b/src/previewgenerator.cpp index f317393e..b406b7bc 100644 --- a/src/previewgenerator.cpp +++ b/src/previewgenerator.cpp @@ -38,13 +38,17 @@ void PreviewGenerator::registerPlugin(MOBase::IPluginPreview *plugin) bool PreviewGenerator::previewSupported(const QString &fileExtension) const
{
- return m_PreviewPlugins.find(fileExtension.toLower()) != m_PreviewPlugins.end();
+ auto it = m_PreviewPlugins.find(fileExtension.toLower());
+ if (it == m_PreviewPlugins.end()) {
+ return false;
+ }
+ return it->second->isActive();
}
QWidget *PreviewGenerator::genPreview(const QString &fileName) const
{
auto iter = m_PreviewPlugins.find(QFileInfo(fileName).suffix().toLower());
- if (iter != m_PreviewPlugins.end()) {
+ if (iter != m_PreviewPlugins.end() && iter->second->isActive()) {
return iter->second->genFilePreview(fileName, m_MaxSize);
} else {
return nullptr;
diff --git a/src/proxyutils.h b/src/proxyutils.h new file mode 100644 index 00000000..4c1717d8 --- /dev/null +++ b/src/proxyutils.h @@ -0,0 +1,26 @@ +#ifndef PROXYUTILS_H +#define PROXYUTILS_H + +#include <type_traits> + +#include "organizerproxy.h" + +namespace MOShared { + + template <class Fn, class T = int> + auto callIfPluginActive(OrganizerProxy* proxy, Fn&& callback, T defaultReturn = T{}) { + return [fn = std::forward<Fn>(callback), proxy, defaultReturn](auto&& ...args) { + if (proxy->plugin()->isActive()) { + return fn(std::forward<decltype(args)>(args)...); + } + else { + if constexpr (!std::is_same_v<std::invoke_result_t<std::decay_t<Fn>, decltype(args)... >, void>) { + return defaultReturn; + } + } + }; + } + +} + +#endif |
