Skip to content

Commit

Permalink
Start updating the settings tab for extension.
Browse files Browse the repository at this point in the history
  • Loading branch information
Holt59 committed Oct 20, 2024
1 parent 890bee5 commit 8006988
Show file tree
Hide file tree
Showing 20 changed files with 361 additions and 108 deletions.
2 changes: 1 addition & 1 deletion CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"value": "x64"
},
"cacheVariables": {
"CMAKE_CXX_FLAGS": "/EHsc /MP /W4",
"CMAKE_CXX_FLAGS": "/EHsc /MP /W3",
"VCPKG_TARGET_TRIPLET": {
"type": "STRING",
"value": "x64-windows-static-md"
Expand Down
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ set_target_properties(organizer PROPERTIES

# disable translations because we want to be able to install somewhere else if
# required
mo2_configure_target(organizer WARNINGS 4 TRANSLATIONS OFF)
mo2_configure_target(organizer WARNINGS 3 TRANSLATIONS OFF)

# we add translations "manually" to handle MO2_INSTALL_IS_BIN
mo2_add_translations(organizer
Expand Down
20 changes: 17 additions & 3 deletions src/extensionmanager.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
#include "extensionmanager.h"

#include <log.h>
#include <uibase/log.h>

#include "organizercore.h"

using namespace MOBase;
namespace fs = std::filesystem;

ExtensionManager::ExtensionManager(OrganizerCore* core) : m_core{core} {}

void ExtensionManager::loadExtensions(fs::path const& directory)
{
for (const auto& entry : fs::directory_iterator{directory}) {
Expand Down Expand Up @@ -60,8 +64,18 @@ const IExtension* ExtensionManager::extension(QString const& identifier) const

bool ExtensionManager::isEnabled(MOBase::IExtension const& extension) const
{
// TODO
return true;
if (!m_core) {
return true;
}

for (auto& requirement : extension.metadata().requirements()) {
// TODO: needs an organizerproxy...
// if (!requirement.check(m_core)) {
// return false;
//}
}

return m_core->settings().extensions().isEnabled(extension, true);
}

bool ExtensionManager::isEnabled(QString const& identifier) const
Expand Down
7 changes: 7 additions & 0 deletions src/extensionmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,15 @@
#include <uibase/extensions/extension.h>

#include "extensionwatcher.h"
#include "organizerproxy.h"

class OrganizerCore;

class ExtensionManager
{
public:
ExtensionManager(OrganizerCore* core);

// retrieve the list of currently loaded extensions
//
const auto& extensions() const { return m_extensions; }
Expand Down Expand Up @@ -58,6 +63,8 @@ class ExtensionManager
void triggerWatchers(const MOBase::IExtension& extension) const;

private:
OrganizerCore* m_core;
std::unique_ptr<OrganizerProxy> m_proxy;
std::vector<std::unique_ptr<const MOBase::IExtension>> m_extensions;

using WatcherMap = boost::fusion::map<
Expand Down
48 changes: 47 additions & 1 deletion src/extensionsettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,55 @@

using namespace MOBase;

static const QString EXTENSIONS_GROUP = "Extensions";
static const QString EXTENSIONS_ENABLED_GROUP = "ExtensionsEnabled";
static const QString PLUGINS_GROUP = "Plugins";
static const QString PLUGINS_PERSISTENT_GROUP = "PluginPersistance";

ExtensionSettings::ExtensionSettings(QSettings& settings) : m_Settings(settings) {}

QString ExtensionSettings::path(const IExtension& extension, const Setting& setting)
{
QString path = extension.metadata().identifier();
if (!setting.group().isEmpty()) {
path += "/" + setting.group();
}
return path + "/" + setting.name();
}

bool ExtensionSettings::isEnabled(const MOBase::IExtension& extension,
bool defaultValue) const
{
return get<bool>(m_Settings, EXTENSIONS_ENABLED_GROUP,
extension.metadata().identifier(), defaultValue);
}

void ExtensionSettings::setEnabled(const MOBase::IExtension& extension,
bool enabled) const
{
set(m_Settings, EXTENSIONS_ENABLED_GROUP, extension.metadata().identifier(), enabled);
}

QVariant ExtensionSettings::setting(const IExtension& extension,
const Setting& setting) const
{
return get<QVariant>(m_Settings, EXTENSIONS_GROUP, path(extension, setting),
setting.defaultValue());
}

void ExtensionSettings::setSetting(const IExtension& extension, const Setting& setting,
const QVariant& value)
{
set(m_Settings, EXTENSIONS_GROUP, path(extension, setting), value);
}

// commits all the settings to the ini
//
void ExtensionSettings::save()
{
m_Settings.sync();
}

PluginSettings::PluginSettings(QSettings& settings) : m_Settings(settings) {}

QString PluginSettings::path(const QString& pluginName, const QString& key)
Expand Down Expand Up @@ -57,7 +103,7 @@ void PluginSettings::fixPluginEnabledSetting(const IPlugin* plugin)
QVariant PluginSettings::setting(const QString& pluginName, const QString& key,
const QVariant& defaultValue) const
{
return get<QVariant>(m_Settings, "Settings", path(pluginName, key), defaultValue);
return get<QVariant>(m_Settings, PLUGINS_GROUP, path(pluginName, key), defaultValue);
}

void PluginSettings::setSetting(const QString& pluginName, const QString& key,
Expand Down
40 changes: 40 additions & 0 deletions src/extensionsettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,48 @@
#include <QObject>
#include <QSettings>

#include <uibase/extensions/extension.h>
#include <uibase/iplugin.h>

// settings about extensions
class ExtensionSettings : public QObject
{
Q_OBJECT

public:
ExtensionSettings(QSettings& settings);

// check if the specified extension is enabled in the settings
//
bool isEnabled(const MOBase::IExtension& extension, bool defaultValue = true) const;

// set the extension as enabled or disabled in the settings
//
void setEnabled(const MOBase::IExtension& extension, bool enabled) const;

// returns the plugin setting for the given key
//
QVariant setting(const MOBase::IExtension& extension,
const MOBase::Setting& setting) const;

// sets the plugin setting for the given key
//
void setSetting(const MOBase::IExtension& extension, const MOBase::Setting& setting,
const QVariant& value);

// commits all the settings to the ini
//
void save();

private:
QSettings& m_Settings;

// retrieve the path to the given setting
//
static QString path(const MOBase::IExtension& extension,
const MOBase::Setting& setting);
};

// settings about plugins
//
class PluginSettings : public QObject
Expand Down
2 changes: 1 addition & 1 deletion src/instancemanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,7 @@ std::unique_ptr<Instance> selectInstance()
// since there is no instance currently active, load plugins with a null
// OrganizerCore; see PluginManager::initPlugin()
NexusInterface ni(nullptr);
ExtensionManager ec;
ExtensionManager ec(nullptr);
ec.loadExtensions(QDir(QCoreApplication::applicationDirPath() + "/extensions")
.filesystemAbsolutePath());

Expand Down
2 changes: 1 addition & 1 deletion src/moapplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ int MOApplication::setup(MOMultiProcess& multiProcess, bool forceSelect)
m_themes = std::make_unique<ThemeManager>(this);
m_translations = std::make_unique<TranslationManager>(this);

m_extensions = std::make_unique<ExtensionManager>();
m_extensions = std::make_unique<ExtensionManager>(m_core.get());
m_extensions->registerWatcher(*m_themes);
m_extensions->registerWatcher(*m_translations);

Expand Down
8 changes: 3 additions & 5 deletions src/nxmaccessmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,11 +162,9 @@ NexusSSOLogin::NexusSSOLogin() : m_keyReceived(false), m_active(false)
onConnected();
});

QObject::connect(&m_socket,
qOverload<QAbstractSocket::SocketError>(&QWebSocket::error),
[&](auto&& e) {
onError(e);
});
QObject::connect(&m_socket, &QWebSocket::errorOccurred, [&](auto&& e) {
onError(e);
});

QObject::connect(&m_socket, &QWebSocket::sslErrors, [&](auto&& errors) {
onSslErrors(errors);
Expand Down
Loading

0 comments on commit 8006988

Please sign in to comment.