Skip to content

Commit 04bdfe5

Browse files
committed
Add IExtensionList implementation.
1 parent 92d137c commit 04bdfe5

6 files changed

Lines changed: 103 additions & 6 deletions

File tree

src/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ mo2_add_filter(NAME src/profiles GROUPS
200200
mo2_add_filter(NAME src/proxies GROUPS
201201
downloadmanagerproxy
202202
modlistproxy
203+
extensionlistproxy
203204
organizerproxy
204205
pluginlistproxy
205206
proxyutils

src/extensionlistproxy.cpp

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#include "extensionlistproxy.h"
2+
3+
#include <log.h>
4+
5+
using namespace MOBase;
6+
7+
ExtensionListProxy::ExtensionListProxy(OrganizerProxy* oproxy,
8+
const ExtensionManager& manager)
9+
: m_oproxy(oproxy), m_manager(&manager)
10+
{}
11+
12+
ExtensionListProxy ::~ExtensionListProxy() {}
13+
14+
bool ExtensionListProxy::installed(const QString& identifier) const
15+
{
16+
return m_manager->extension(identifier) != nullptr;
17+
}
18+
19+
bool ExtensionListProxy::enabled(const QString& extension) const
20+
{
21+
return m_manager->isEnabled(extension);
22+
}
23+
24+
bool ExtensionListProxy::enabled(const IExtension& extension) const
25+
{
26+
return m_manager->isEnabled(extension);
27+
}
28+
29+
const IExtension& ExtensionListProxy::get(QString const& identifier) const
30+
{
31+
auto* extension = m_manager->extension(identifier);
32+
if (extension) {
33+
return *extension;
34+
}
35+
throw std::out_of_range(
36+
fmt::format("extension '{}' not found", identifier.toStdString()));
37+
}
38+
39+
const IExtension& ExtensionListProxy::at(std::size_t const& index) const
40+
{
41+
return *m_manager->extensions().at(index);
42+
}
43+
44+
const IExtension& ExtensionListProxy::operator[](std::size_t const& index) const
45+
{
46+
return *m_manager->extensions().at(index);
47+
}
48+
49+
std::size_t ExtensionListProxy::size() const
50+
{
51+
return m_manager->extensions().size();
52+
}

src/extensionlistproxy.h

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#ifndef EXTENSIONLISTPROXY_H
2+
#define EXTENSIONLISTPROXY_H
3+
4+
#include <iextensionlist.h>
5+
6+
#include "extensionmanager.h"
7+
8+
class OrganizerProxy;
9+
10+
class ExtensionListProxy : public MOBase::IExtensionList
11+
{
12+
public:
13+
ExtensionListProxy(OrganizerProxy* oproxy, const ExtensionManager& manager);
14+
virtual ~ExtensionListProxy();
15+
16+
bool installed(const QString& identifier) const override;
17+
bool enabled(const QString& extension) const override;
18+
bool enabled(const MOBase::IExtension& extension) const override;
19+
const MOBase::IExtension& get(QString const& identifier) const override;
20+
const MOBase::IExtension& at(std::size_t const& index) const override;
21+
const MOBase::IExtension& operator[](std::size_t const& index) const override;
22+
std::size_t size() const override;
23+
24+
private:
25+
OrganizerProxy* m_oproxy;
26+
const ExtensionManager* m_manager;
27+
};
28+
29+
#endif

src/organizerproxy.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#include "organizerproxy.h"
22

33
#include "downloadmanagerproxy.h"
4+
#include "extensionlistproxy.h"
5+
#include "extensionmanager.h"
46
#include "glob_matching.h"
57
#include "modlistproxy.h"
68
#include "organizercore.h"
@@ -17,11 +19,14 @@
1719
using namespace MOBase;
1820
using namespace MOShared;
1921

20-
OrganizerProxy::OrganizerProxy(OrganizerCore* organizer, PluginManager* pluginManager,
21-
MOBase::IPlugin* plugin)
22+
OrganizerProxy::OrganizerProxy(OrganizerCore* organizer,
23+
const ExtensionManager& extensionManager,
24+
PluginManager* pluginManager, MOBase::IPlugin* plugin)
2225
: m_Proxied(organizer), m_PluginManager(pluginManager), m_Plugin(plugin),
2326
m_DownloadManagerProxy(
2427
std::make_unique<DownloadManagerProxy>(this, organizer->downloadManager())),
28+
m_ExtensionListProxy(
29+
std::make_unique<ExtensionListProxy>(this, extensionManager)),
2530
m_ModListProxy(std::make_unique<ModListProxy>(this, organizer->modList())),
2631
m_PluginListProxy(
2732
std::make_unique<PluginListProxy>(this, organizer->pluginList()))
@@ -130,6 +135,11 @@ void OrganizerProxy::modDataChanged(IModInterface* mod)
130135
m_Proxied->modDataChanged(mod);
131136
}
132137

138+
MOBase::IExtensionList& OrganizerProxy::extensionList() const
139+
{
140+
return *m_ExtensionListProxy;
141+
}
142+
133143
bool OrganizerProxy::isPluginEnabled(QString const& pluginName) const
134144
{
135145
return m_PluginManager->isEnabled(pluginName);

src/organizerproxy.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,16 @@
1111
class PluginManager;
1212
class DownloadManagerProxy;
1313
class ModListProxy;
14+
class ExtensionManager;
1415
class PluginListProxy;
16+
class ExtensionListProxy;
1517

1618
class OrganizerProxy : public MOBase::IOrganizer
1719
{
1820

1921
public:
20-
OrganizerProxy(OrganizerCore* organizer, PluginManager* pluginManager,
21-
MOBase::IPlugin* plugin);
22+
OrganizerProxy(OrganizerCore* organizer, const ExtensionManager& extensionManager,
23+
PluginManager* pluginManager, MOBase::IPlugin* plugin);
2224
~OrganizerProxy();
2325

2426
public:
@@ -87,7 +89,9 @@ class OrganizerProxy : public MOBase::IOrganizer
8789
virtual bool onProfileChanged(
8890
std::function<void(MOBase::IProfile*, MOBase::IProfile*)> const& func) override;
8991

90-
// Plugin related:
92+
// Plugin/extension related:
93+
virtual MOBase::IExtensionList& extensionList() const override;
94+
9195
virtual bool isPluginEnabled(QString const& pluginName) const override;
9296
virtual bool isPluginEnabled(MOBase::IPlugin* plugin) const override;
9397
virtual QVariant pluginSetting(const QString& pluginName,
@@ -145,6 +149,7 @@ class OrganizerProxy : public MOBase::IOrganizer
145149
std::vector<boost::signals2::connection> m_Connections;
146150

147151
std::unique_ptr<DownloadManagerProxy> m_DownloadManagerProxy;
152+
std::unique_ptr<ExtensionListProxy> m_ExtensionListProxy;
148153
std::unique_ptr<ModListProxy> m_ModListProxy;
149154
std::unique_ptr<PluginListProxy> m_PluginListProxy;
150155
};

src/pluginmanager.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ bool PluginManager::initPlugin(PluginExtension const& extension, IPlugin* plugin
308308

309309
OrganizerProxy* proxy = nullptr;
310310
if (m_core) {
311-
proxy = new OrganizerProxy(m_core, this, plugin);
311+
proxy = new OrganizerProxy(m_core, m_extensions, this, plugin);
312312
proxy->setParent(as_qobject(plugin));
313313
}
314314

0 commit comments

Comments
 (0)