aboutsummaryrefslogtreecommitdiff
path: root/libs/installer_bsplugins/src/MOPlugin
diff options
context:
space:
mode:
authorSulfurNitride <SulfurNitride@users.noreply.github.com>2026-04-12 21:04:15 -0500
committerSulfurNitride <SulfurNitride@users.noreply.github.com>2026-04-12 21:04:15 -0500
commit3949dcfce95af4bd305f258ff5b170d7d50435f6 (patch)
tree4c768be256c40f31794c3311f0a2c22933a6705a /libs/installer_bsplugins/src/MOPlugin
parent892070f3dec1dc690983fd862880e37e711c2516 (diff)
VFS perf fixes, icon/stylesheet compat, download filename fix
VFS: - Open backing fd at mo2_open time for read-only handles so mo2_read can splice without re-opening the file on every read call. - Bump RLIMIT_NOFILE at mount time to fit the resulting fd pressure when the game keeps hundreds of BSAs open. - Dedicated node_cache_mutex so resolveByInode / mo2_lookup stop racing unordered_map writes while multiple tree_mutex readers are active. - max_read=1MB + matching conn->max_read and raised max_readahead/max_write so the kernel merges Wine's small sequential reads into bigger FUSE requests. - Per-op wall-clock counters in mo2_init() logs so we can distinguish VFS latency from game-side work. Proton launch: - Write dxvk.conf to the prefix and set DXVK_CONFIG_FILE to force dxvk.enableGraphicsPipelineLibrary=False, avoiding long GPL compile stalls on first run. UI / plugin compat: - Clamp IconDelegate's per-icon width to [8, 16] so narrow content columns don't trigger QIcon::pixmap(0,0) returning null and logging "failed to load icon" every repaint. - Pre-create lowercase symlinks in the stylesheet directory so QSS files authored on Windows resolve url(foo.svg) when on-disk files are Foo.svg. - Flip content icons empty-chessboard.png and facegen.png to 8-bit RGBA so Qt's built-in PNG reader loads them uniformly. - Add mobase.Version.canonicalString shim for legacy Python plugins that still call the old VersionInfo method on appVersion()'s return. - BSPluginList: compare normalized plugin name lists instead of byte hashes so the post-run case-fix refresh stops spuriously firing the "load order changed" dialog. - BSPluginList disabled by default. Download manager: - Parse CDN URL with QUrl + QUrlQuery and read the filename from the response-content-disposition query param (RFC 6266 quoted / unquoted / ext-value forms), not QFileInfo on the raw URL. - When the API or URL gives us a CDN object key (no archive extension), prefer the actual Content-Disposition header from the live response in metaDataChanged and downloadFinished. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'libs/installer_bsplugins/src/MOPlugin')
-rw-r--r--libs/installer_bsplugins/src/MOPlugin/BSPlugins.cpp79
-rw-r--r--libs/installer_bsplugins/src/MOPlugin/BSPlugins.h39
-rw-r--r--libs/installer_bsplugins/src/MOPlugin/IPanelInterface.h30
-rw-r--r--libs/installer_bsplugins/src/MOPlugin/IPluginPanel.cpp99
-rw-r--r--libs/installer_bsplugins/src/MOPlugin/IPluginPanel.h47
-rw-r--r--libs/installer_bsplugins/src/MOPlugin/MOPanelInterface.cpp144
-rw-r--r--libs/installer_bsplugins/src/MOPlugin/MOPanelInterface.h60
-rw-r--r--libs/installer_bsplugins/src/MOPlugin/Settings.cpp254
-rw-r--r--libs/installer_bsplugins/src/MOPlugin/Settings.h88
9 files changed, 840 insertions, 0 deletions
diff --git a/libs/installer_bsplugins/src/MOPlugin/BSPlugins.cpp b/libs/installer_bsplugins/src/MOPlugin/BSPlugins.cpp
new file mode 100644
index 0000000..442fbcf
--- /dev/null
+++ b/libs/installer_bsplugins/src/MOPlugin/BSPlugins.cpp
@@ -0,0 +1,79 @@
+#include "BSPlugins.h"
+
+#include "BSPluginList/PluginsWidget.h"
+#include "Settings.h"
+
+using namespace Qt::Literals::StringLiterals;
+
+bool BSPlugins::initPlugin(MOBase::IOrganizer* organizer)
+{
+ m_Organizer = organizer;
+ Settings::init(organizer);
+ return true;
+}
+
+QString BSPlugins::name() const
+{
+ return NAME;
+}
+
+std::vector<std::shared_ptr<const MOBase::IPluginRequirement>>
+BSPlugins::requirements() const
+{
+ return {Requirements::gameDependency(
+ {u"Oblivion"_s, u"Fallout 3"_s, u"New Vegas"_s, u"Skyrim"_s, u"Enderal"_s,
+ u"Fallout 4"_s, u"Skyrim Special Edition"_s, u"Enderal Special Edition"_s,
+ u"Skyrim VR"_s, u"Fallout 4 VR"_s, u"Starfield"_s, u"Oblivion Remastered"_s})};
+}
+
+QString BSPlugins::author() const
+{
+ return u"Parapets"_s;
+}
+
+QString BSPlugins::description() const
+{
+ return tr("Manages plugin load order for BGS game engines");
+}
+
+MOBase::VersionInfo BSPlugins::version() const
+{
+ return MOBase::VersionInfo(0, 1, 5, 0, MOBase::VersionInfo::RELEASE_BETA);
+}
+
+QList<MOBase::PluginSetting> BSPlugins::settings() const
+{
+ return {
+ {u"enable_sort_button"_s, u"Enable the Sort button in the Plugins panel"_s, false},
+ {u"external_change_warning"_s,
+ u"Warn if load order changes while running an executable"_s, true},
+ {u"loot_show_dirty"_s,
+ u"LOOT: Show information about plugins that can be cleaned"_s, true},
+ {u"loot_show_messages"_s,
+ u"LOOT: Show general information and warning messages"_s, true},
+ {u"loot_show_problems"_s,
+ u"LOOT: Show information about incompatibilities and missing masters"_s, true},
+ };
+}
+
+bool BSPlugins::enabledByDefault() const
+{
+ return false;
+}
+
+QWidget* BSPlugins::createWidget(IPanelInterface* panelInterface, QWidget* parent)
+{
+ const auto widget =
+ new BSPluginList::PluginsWidget(m_Organizer, panelInterface, parent);
+ return widget;
+}
+
+QString BSPlugins::label() const
+{
+ return tr("Plugins");
+}
+
+IPluginPanel::Position BSPlugins::position() const
+{
+ return Position::inPlaceOf(u"espTab"_s);
+}
diff --git a/libs/installer_bsplugins/src/MOPlugin/BSPlugins.h b/libs/installer_bsplugins/src/MOPlugin/BSPlugins.h
new file mode 100644
index 0000000..81248d7
--- /dev/null
+++ b/libs/installer_bsplugins/src/MOPlugin/BSPlugins.h
@@ -0,0 +1,39 @@
+#ifndef BSPLUGINS_H
+#define BSPLUGINS_H
+
+#include "IPluginPanel.h"
+
+class BSPlugins final : public IPluginPanel
+{
+ Q_OBJECT
+ Q_INTERFACES(MOBase::IPlugin IPluginPanel)
+ Q_PLUGIN_METADATA(IID "org.tannin.BSPlugins" FILE "bsplugins.json")
+
+public:
+ inline static const QString NAME = QStringLiteral("Bethesda Plugin Manager");
+
+ BSPlugins() = default;
+
+ // IPlugin
+
+ QString name() const override;
+ std::vector<std::shared_ptr<const MOBase::IPluginRequirement>>
+ requirements() const override;
+ QString author() const override;
+ QString description() const override;
+ MOBase::VersionInfo version() const override;
+ QList<MOBase::PluginSetting> settings() const override;
+ bool enabledByDefault() const override;
+
+ // IPluginPanel
+
+ bool initPlugin(MOBase::IOrganizer* organizer);
+ QWidget* createWidget(IPanelInterface* panelInterface, QWidget* parent) override;
+ QString label() const override;
+ Position position() const override;
+
+private:
+ MOBase::IOrganizer* m_Organizer;
+};
+
+#endif // BSPLUGINS_H
diff --git a/libs/installer_bsplugins/src/MOPlugin/IPanelInterface.h b/libs/installer_bsplugins/src/MOPlugin/IPanelInterface.h
new file mode 100644
index 0000000..2904e8e
--- /dev/null
+++ b/libs/installer_bsplugins/src/MOPlugin/IPanelInterface.h
@@ -0,0 +1,30 @@
+#ifndef IPANELINTERFACE_H
+#define IPANELINTERFACE_H
+
+#include <QList>
+#include <QString>
+#include <functional>
+
+class IPanelInterface
+{
+public:
+ // user selected files in the panel whose origins should be highlighted
+ //
+ virtual void setSelectedFiles(const QList<QString>& selectedFiles) = 0;
+
+ // request mod info dialog for origin of file
+ //
+ virtual void displayOriginInformation(const QString& file) = 0;
+
+ virtual bool onPanelActivated(const std::function<void()>& func) = 0;
+
+ virtual bool
+ onSelectedOriginsChanged(const std::function<void(const QList<QString>&)>& func) = 0;
+
+ // HACK: this shouldn't be here, but the MOBase::IPluginList::setState function does
+ // not cause the list to notify its onPluginStateChanged listeners, so this will work
+ // around that
+ virtual void setPluginState(const QString& name, bool enable) = 0;
+};
+
+#endif // IPANELINTERFACE_H
diff --git a/libs/installer_bsplugins/src/MOPlugin/IPluginPanel.cpp b/libs/installer_bsplugins/src/MOPlugin/IPluginPanel.cpp
new file mode 100644
index 0000000..904f049
--- /dev/null
+++ b/libs/installer_bsplugins/src/MOPlugin/IPluginPanel.cpp
@@ -0,0 +1,99 @@
+#include "IPluginPanel.h"
+#include "MOPanelInterface.h"
+
+#include <QTabWidget>
+
+using namespace Qt::Literals::StringLiterals;
+
+IPluginPanel::Position IPluginPanel::Position::before(const QString& panelName)
+{
+ return {Order::Before, panelName};
+}
+
+IPluginPanel::Position IPluginPanel::Position::after(const QString& panelName)
+{
+ return {Order::After, panelName};
+}
+
+IPluginPanel::Position IPluginPanel::Position::inPlaceOf(const QString& panelName)
+{
+ return {Order::InPlaceOf, panelName};
+}
+
+IPluginPanel::Position IPluginPanel::Position::atStart()
+{
+ return {Order::AtStart, {}};
+}
+
+IPluginPanel::Position IPluginPanel::Position::atEnd()
+{
+ return {Order::AtEnd, {}};
+}
+
+bool IPluginPanel::init(MOBase::IOrganizer* organizer)
+{
+ if (organizer == nullptr) {
+ return false;
+ }
+
+ organizer->onUserInterfaceInitialized([this, organizer](QMainWindow* mainWindow) {
+ const auto tabWidget = mainWindow->findChild<QTabWidget*>(u"tabWidget"_s);
+
+ if (tabWidget == nullptr) {
+ return;
+ }
+
+ const auto intfc = new MOPanelInterface(organizer, mainWindow);
+ const auto widget = this->createWidget(intfc, tabWidget);
+ const auto label = this->label();
+ const auto position = this->position();
+
+ switch (position.order_) {
+ case Order::Before: {
+ const auto refTab = !position.reference_.isNull()
+ ? tabWidget->findChild<QWidget*>(position.reference_)
+ : nullptr;
+ if (refTab != nullptr) {
+ if (const int index = tabWidget->indexOf(refTab); index != -1) {
+ const int currentIndex = tabWidget->currentIndex();
+ tabWidget->insertTab(index, widget, label);
+ if (index <= currentIndex) {
+ tabWidget->setCurrentIndex(currentIndex);
+ }
+ }
+ break;
+ }
+ }
+ [[fallthrough]];
+ case Order::AtStart: {
+ const int currentIndex = tabWidget->currentIndex();
+ tabWidget->insertTab(0, widget, label);
+ tabWidget->setCurrentIndex(currentIndex);
+ } break;
+ case Order::InPlaceOf:
+ case Order::After: {
+ const auto refTab = !position.reference_.isNull()
+ ? tabWidget->findChild<QWidget*>(position.reference_)
+ : nullptr;
+
+ if (refTab != nullptr) {
+ if (const int index = tabWidget->indexOf(refTab); index != -1) {
+ tabWidget->insertTab(index + 1, widget, label);
+ if (position.order_ == Order::InPlaceOf) {
+ tabWidget->removeTab(index);
+ }
+ }
+ break;
+ }
+ }
+ [[fallthrough]];
+ case Order::AtEnd: {
+ tabWidget->addTab(widget, label);
+ } break;
+ }
+
+ intfc->assignWidget(tabWidget, widget);
+ });
+
+ return this->initPlugin(organizer);
+}
diff --git a/libs/installer_bsplugins/src/MOPlugin/IPluginPanel.h b/libs/installer_bsplugins/src/MOPlugin/IPluginPanel.h
new file mode 100644
index 0000000..0c73a9c
--- /dev/null
+++ b/libs/installer_bsplugins/src/MOPlugin/IPluginPanel.h
@@ -0,0 +1,47 @@
+#ifndef IPLUGINPANEL_H
+#define IPLUGINPANEL_H
+
+#include "IPanelInterface.h"
+
+#include <iplugin.h>
+
+class IPluginPanel : public QObject, public MOBase::IPlugin
+{
+ Q_INTERFACES(MOBase::IPlugin)
+
+public:
+ enum class Order
+ {
+ Before,
+ AtStart,
+ InPlaceOf,
+ After,
+ AtEnd,
+ };
+
+ struct Position
+ {
+ Order order_;
+ QString reference_;
+
+ static Position before(const QString& panelName);
+ static Position after(const QString& panelName);
+ static Position inPlaceOf(const QString& panelName);
+ static Position atStart();
+ static Position atEnd();
+ };
+
+ bool init(MOBase::IOrganizer* organizer) final;
+
+ virtual bool initPlugin(MOBase::IOrganizer* organizer) = 0;
+
+ virtual QWidget* createWidget(IPanelInterface* callbacks, QWidget* parent) = 0;
+
+ virtual QString label() const = 0;
+
+ virtual Position position() const = 0;
+};
+
+Q_DECLARE_INTERFACE(IPluginPanel, "org.tannin.IPluginPanel/1.0")
+
+#endif // IPLUGINPANEL_H
diff --git a/libs/installer_bsplugins/src/MOPlugin/MOPanelInterface.cpp b/libs/installer_bsplugins/src/MOPlugin/MOPanelInterface.cpp
new file mode 100644
index 0000000..c8bb242
--- /dev/null
+++ b/libs/installer_bsplugins/src/MOPlugin/MOPanelInterface.cpp
@@ -0,0 +1,144 @@
+#include "MOPanelInterface.h"
+
+#include <log.h>
+
+#include <algorithm>
+#include <functional>
+#include <iterator>
+
+using namespace Qt::Literals::StringLiterals;
+
+MOPanelInterface::MOPanelInterface(MOBase::IOrganizer* organizer,
+ QMainWindow* mainWindow)
+ : m_ModList{organizer->modList()}, m_PluginList{organizer->pluginList()},
+ m_ModListView{mainWindow->findChild<QTreeView*>(u"modList"_s)},
+ m_PluginListView{mainWindow->findChild<QTreeView*>(u"espList"_s)}
+{
+ if (m_ModListView) {
+ QObject::connect(m_ModListView, &QTreeView::collapsed, this,
+ &MOPanelInterface::onModSeparatorCollapsed);
+ QObject::connect(m_ModListView, &QTreeView::expanded, this,
+ &MOPanelInterface::onModSeparatorExpanded);
+ QObject::connect(m_ModListView->selectionModel(),
+ &QItemSelectionModel::selectionChanged, this,
+ &MOPanelInterface::onModSelectionChanged);
+ }
+}
+
+MOPanelInterface::~MOPanelInterface() noexcept
+{
+ m_SelectedOriginsChanged.disconnect_all_slots();
+}
+
+void MOPanelInterface::assignWidget(QTabWidget* tabWidget, QWidget* panel)
+{
+ QObject::connect(tabWidget, &QTabWidget::currentChanged,
+ [this, tabWidget, panel](int index) {
+ QWidget* const currentWidget = tabWidget->widget(index);
+ if (currentWidget == panel) {
+ m_PanelActivated();
+ }
+ });
+}
+
+void MOPanelInterface::setSelectedFiles(const QList<QString>& selectedFiles)
+{
+ if (!m_PluginListView) {
+ return;
+ }
+
+ QItemSelection selection;
+ const auto model = m_PluginListView->model();
+ for (int row = 0, count = model->rowCount(); row < count; ++row) {
+ const auto index = model->index(row, 0);
+ if (selectedFiles.contains(index.data(Qt::DisplayRole))) {
+ const auto end = model->index(row, model->columnCount() - 1);
+ selection.select(index, end);
+ }
+ }
+
+ m_PluginListView->selectionModel()->select(selection,
+ QItemSelectionModel::ClearAndSelect);
+}
+
+// FIXME: only works for files in the plugins panel
+void MOPanelInterface::displayOriginInformation(const QString& file)
+{
+ const auto model = m_PluginListView->model();
+ for (int row = 0, count = model->rowCount(); row < count; ++row) {
+ const auto index = model->index(row, 0);
+ const auto other = index.data(Qt::DisplayRole).toString();
+ if (file.compare(other, Qt::CaseInsensitive) == 0) {
+ m_PluginListView->selectionModel()->select(
+ QItemSelection(index, model->index(row, model->columnCount() - 1)),
+ QItemSelectionModel::ClearAndSelect);
+ m_PluginListView->selectionModel()->setCurrentIndex(index,
+ QItemSelectionModel::Current);
+ m_PluginListView->doubleClicked(index);
+ return;
+ }
+ }
+
+ MOBase::log::warn("failed to open origin info for \"{}\"", file);
+}
+
+bool MOPanelInterface::onPanelActivated(const std::function<void()>& func)
+{
+ auto connection = m_PanelActivated.connect(func);
+ return connection.connected();
+}
+
+bool MOPanelInterface::onSelectedOriginsChanged(
+ const std::function<void(const QList<QString>&)>& func)
+{
+ auto connection = m_SelectedOriginsChanged.connect(func);
+ return connection.connected();
+}
+
+void MOPanelInterface::setPluginState(const QString& name, bool enable)
+{
+ const auto model = m_PluginListView->model();
+ for (int i = 0, count = model->rowCount(); i < count; ++i) {
+ const auto index = model->index(i, 0);
+ if (index.data().toString().compare(name, Qt::CaseInsensitive) == 0) {
+ model->setData(index, enable ? Qt::Checked : Qt::Unchecked, Qt::CheckStateRole);
+ }
+ }
+}
+
+void MOPanelInterface::onModSeparatorCollapsed(const QModelIndex& index)
+{
+ if (m_ModListView->selectionModel()->isSelected(index)) {
+ onModSelectionChanged();
+ }
+}
+
+void MOPanelInterface::onModSeparatorExpanded(const QModelIndex& index)
+{
+ if (m_ModListView->selectionModel()->isSelected(index)) {
+ onModSelectionChanged();
+ }
+}
+
+void MOPanelInterface::onModSelectionChanged()
+{
+ QList<QString> origins;
+ std::function<void(const QModelIndex&)> addOrigins;
+ addOrigins = [&](const QModelIndex& index) {
+ if (index.model()->hasChildren(index)) {
+ if (m_ModListView->isExpanded(index)) {
+ return;
+ }
+
+ for (int i = 0, count = index.model()->rowCount(index); i < count; ++i) {
+ addOrigins(index.model()->index(i, 0, index));
+ }
+ } else {
+ origins.append(index.data(Qt::DisplayRole).toString());
+ }
+ };
+
+ const auto indexes = m_ModListView->selectionModel()->selectedRows();
+ std::ranges::for_each(indexes, addOrigins);
+ m_SelectedOriginsChanged(origins);
+}
diff --git a/libs/installer_bsplugins/src/MOPlugin/MOPanelInterface.h b/libs/installer_bsplugins/src/MOPlugin/MOPanelInterface.h
new file mode 100644
index 0000000..184d087
--- /dev/null
+++ b/libs/installer_bsplugins/src/MOPlugin/MOPanelInterface.h
@@ -0,0 +1,60 @@
+#ifndef MOPANELINTERFACE_H
+#define MOPANELINTERFACE_H
+
+#include "IPanelInterface.h"
+
+#include <imoinfo.h>
+
+#include <boost/signals2.hpp>
+
+#include <QMainWindow>
+#include <QTreeView>
+
+class MOPanelInterface final : public QObject, public IPanelInterface
+{
+ Q_OBJECT
+
+public:
+ using SignalPanelActivated = boost::signals2::signal<void()>;
+ using SignalSelectedOriginsChanged =
+ boost::signals2::signal<void(const QList<QString>&)>;
+
+ MOPanelInterface(MOBase::IOrganizer* organizer, QMainWindow* mainWindow);
+
+ MOPanelInterface(const MOPanelInterface&) = delete;
+ MOPanelInterface(MOPanelInterface&&) = delete;
+
+ ~MOPanelInterface() noexcept;
+
+ MOPanelInterface& operator=(const MOPanelInterface&) = delete;
+ MOPanelInterface& operator=(MOPanelInterface&&) = delete;
+
+ void assignWidget(QTabWidget* tabWidget, QWidget* panel);
+
+ void setSelectedFiles(const QList<QString>& selectedFiles) override;
+
+ void displayOriginInformation(const QString& file) override;
+
+ bool onPanelActivated(const std::function<void()>& func) override;
+
+ bool onSelectedOriginsChanged(
+ const std::function<void(const QList<QString>&)>& func) override;
+
+ void setPluginState(const QString& name, bool enable) override;
+
+private slots:
+ void onModSeparatorCollapsed(const QModelIndex& index);
+ void onModSeparatorExpanded(const QModelIndex& index);
+ void onModSelectionChanged();
+
+private:
+ MOBase::IModList* m_ModList;
+ MOBase::IPluginList* m_PluginList;
+ QTreeView* m_ModListView;
+ QTreeView* m_PluginListView;
+
+ SignalPanelActivated m_PanelActivated;
+ SignalSelectedOriginsChanged m_SelectedOriginsChanged;
+};
+
+#endif // MOPANELINTERFACE_H
diff --git a/libs/installer_bsplugins/src/MOPlugin/Settings.cpp b/libs/installer_bsplugins/src/MOPlugin/Settings.cpp
new file mode 100644
index 0000000..8ca77ec
--- /dev/null
+++ b/libs/installer_bsplugins/src/MOPlugin/Settings.cpp
@@ -0,0 +1,254 @@
+#include "Settings.h"
+#include "BSPlugins.h"
+
+#include <QDir>
+#include <QStandardPaths>
+#include <QTreeView>
+
+Settings* Instance = nullptr;
+
+static QString findIniPath(MOBase::IOrganizer* organizer)
+{
+ // FIXME: we can't find non-portable instance paths
+ return QDir(organizer->basePath()).filePath("ModOrganizer.ini");
+}
+
+Settings::Settings(MOBase::IOrganizer* organizer)
+ : Organizer{organizer}, MOSettings{findIniPath(organizer), QSettings::IniFormat}
+{
+ organizer->onPluginSettingChanged(
+ std::bind_front(&Settings::onPluginSettingChanged, this));
+}
+
+void Settings::init(MOBase::IOrganizer* organizer)
+{
+ Instance = new Settings(organizer);
+}
+
+Settings* Settings::instance()
+{
+ return Instance;
+}
+
+void Settings::set(const QString& setting, const QVariant& value)
+{
+ Organizer->setPersistent(BSPlugins::NAME, setting, value);
+}
+
+[[nodiscard]] QVariant Settings::get(const QString& setting, const QVariant& def) const
+{
+ return Organizer->persistent(BSPlugins::NAME, setting, def);
+}
+
+bool Settings::onSettingChanged(
+ const std::function<void(const QString&, const QVariant&, const QVariant&)>& func)
+{
+ auto connection = SettingChanged.connect(func);
+ return connection.connected();
+}
+
+QColor Settings::overwrittenLooseFilesColor() const
+{
+ return MOSettings.value("Settings/overwrittenLooseFilesColor", QColor(0, 255, 0, 64))
+ .value<QColor>();
+}
+
+QColor Settings::overwritingLooseFilesColor() const
+{
+ return MOSettings.value("Settings/overwritingLooseFilesColor", QColor(255, 0, 0, 64))
+ .value<QColor>();
+}
+
+QColor Settings::overwrittenArchiveFilesColor() const
+{
+ return MOSettings
+ .value("Settings/overwrittenArchiveFilesColor", QColor(0, 255, 255, 64))
+ .value<QColor>();
+}
+
+QColor Settings::overwritingArchiveFilesColor() const
+{
+ return MOSettings
+ .value("Settings/overwritingArchiveFilesColor", QColor(255, 0, 255, 64))
+ .value<QColor>();
+}
+
+QColor Settings::containedColor() const
+{
+ return MOSettings.value("Settings/containedColor", QColor(0, 0, 255, 64))
+ .value<QColor>();
+}
+
+bool Settings::offlineMode() const
+{
+ return MOSettings.value("Settings/offline_mode", false).value<bool>();
+}
+
+lootcli::LogLevels Settings::lootLogLevel() const
+{
+ // LOOT integration removed for Fluorine port — return default.
+ return lootcli::LogLevels::Info;
+}
+
+bool Settings::externalChangeWarning() const
+{
+ return Organizer->pluginSetting(BSPlugins::NAME, "external_change_warning")
+ .value<bool>();
+}
+
+bool Settings::enableSortButton() const
+{
+ return Organizer->pluginSetting(BSPlugins::NAME, "enable_sort_button").value<bool>();
+}
+
+bool Settings::lootShowDirty() const
+{
+ return Organizer->pluginSetting(BSPlugins::NAME, "loot_show_dirty").value<bool>();
+}
+
+bool Settings::lootShowMessages() const
+{
+ return Organizer->pluginSetting(BSPlugins::NAME, "loot_show_messages").value<bool>();
+}
+
+bool Settings::lootShowProblems() const
+{
+ return Organizer->pluginSetting(BSPlugins::NAME, "loot_show_problems").value<bool>();
+}
+
+static QString stateSettingName(const QHeaderView* header)
+{
+ return header->parent()->objectName() + "_header";
+}
+
+static void visitRows(const QAbstractItemModel* model,
+ std::function<void(const QModelIndex&)> visit,
+ const QModelIndex& root = QModelIndex())
+{
+ if (root.isValid()) {
+ visit(root);
+ }
+
+ for (int i = 0, count = model->rowCount(root); i < count; ++i) {
+ const auto idx = model->index(i, 0, root);
+ visitRows(model, visit, idx);
+ }
+}
+
+void Settings::saveTreeExpandState(const QTreeView* view)
+{
+ QVariantList expanded;
+ visitRows(view->model(), [&expanded, view](const QModelIndex& index) {
+ if (view->isExpanded(index)) {
+ expanded.append(index.data());
+ }
+ });
+
+ Organizer->setPersistent(BSPlugins::NAME, view->objectName() + "_expanded", expanded);
+}
+
+void Settings::restoreTreeExpandState(QTreeView* view) const
+{
+ // empty is serialized as invalid
+ const QVariant state = Organizer->persistent(
+ BSPlugins::NAME, view->objectName() + "_expanded", QVariantList());
+
+ if (!state.isValid()) {
+ view->collapseAll();
+ } else {
+ const auto expanded = state.toList();
+ if (!expanded.isEmpty()) {
+ view->collapseAll();
+ visitRows(view->model(), [&expanded, view](const QModelIndex& index) {
+ if (expanded.contains(index.data())) {
+ view->expand(index);
+ }
+ });
+ }
+ }
+}
+
+void Settings::saveState(const QHeaderView* header)
+{
+ Organizer->setPersistent(BSPlugins::NAME, stateSettingName(header),
+ header->saveState());
+}
+
+void Settings::restoreState(QHeaderView* header) const
+{
+ const auto state =
+ Organizer->persistent(BSPlugins::NAME, stateSettingName(header)).toByteArray();
+ if (!state.isEmpty()) {
+ header->restoreState(state);
+ }
+}
+
+static QString stateSettingName(const QSplitter* splitter)
+{
+ return splitter->parentWidget()->objectName() + "_splitter";
+}
+
+void Settings::saveState(const QSplitter* splitter)
+{
+ Organizer->setPersistent(BSPlugins::NAME, stateSettingName(splitter),
+ splitter->saveState());
+}
+
+void Settings::restoreState(QSplitter* splitter) const
+{
+ const auto state =
+ Organizer->persistent(BSPlugins::NAME, stateSettingName(splitter)).toByteArray();
+ if (!state.isEmpty()) {
+ splitter->restoreState(state);
+ }
+}
+
+static QString stateSettingName(const MOBase::ExpanderWidget* expander)
+{
+ return expander->button()->objectName() + "_state";
+}
+
+void Settings::saveState(const MOBase::ExpanderWidget* expander)
+{
+ Organizer->setPersistent(BSPlugins::NAME, stateSettingName(expander),
+ expander->saveState());
+}
+
+void Settings::restoreState(MOBase::ExpanderWidget* expander) const
+{
+ const auto state =
+ Organizer->persistent(BSPlugins::NAME, stateSettingName(expander)).toByteArray();
+ if (!state.isEmpty()) {
+ expander->restoreState(state);
+ }
+}
+
+static QString geometrySettingName(const QDialog* dialog)
+{
+ return dialog->objectName() + "_geometry";
+}
+
+void Settings::saveGeometry(const QDialog* dialog)
+{
+ Organizer->setPersistent(BSPlugins::NAME, geometrySettingName(dialog),
+ dialog->saveGeometry());
+}
+
+void Settings::restoreGeometry(QDialog* dialog) const
+{
+ const auto geometry =
+ Organizer->persistent(BSPlugins::NAME, geometrySettingName(dialog)).toByteArray();
+ if (!geometry.isEmpty()) {
+ dialog->restoreGeometry(geometry);
+ }
+}
+
+void Settings::onPluginSettingChanged(const QString& pluginName, const QString& key,
+ const QVariant& oldValue,
+ const QVariant& newValue)
+{
+ if (pluginName != BSPlugins::NAME)
+ return;
+
+ SettingChanged(key, oldValue, newValue);
+}
diff --git a/libs/installer_bsplugins/src/MOPlugin/Settings.h b/libs/installer_bsplugins/src/MOPlugin/Settings.h
new file mode 100644
index 0000000..cf93a29
--- /dev/null
+++ b/libs/installer_bsplugins/src/MOPlugin/Settings.h
@@ -0,0 +1,88 @@
+#ifndef SETTINGS_H
+#define SETTINGS_H
+
+#include "GUI/IGeometrySettings.h"
+#include "GUI/IStateSettings.h"
+
+#include <expanderwidget.h>
+#include <imoinfo.h>
+#include <lootcli/lootcli.h>
+
+#include <boost/signals2.hpp>
+
+#include <QColor>
+#include <QDialog>
+#include <QHeaderView>
+#include <QSettings>
+#include <QSplitter>
+#include <QTreeView>
+
+class Settings final : public GUI::IGeometrySettings<QDialog>,
+ public GUI::IStateSettings<QHeaderView>,
+ public GUI::IStateSettings<QSplitter>,
+ public GUI::IStateSettings<MOBase::ExpanderWidget>
+{
+public:
+ using SignalSettingChanged =
+ boost::signals2::signal<void(const QString&, const QVariant&, const QVariant&)>;
+
+ static void init(MOBase::IOrganizer* organizer);
+
+ [[nodiscard]] static Settings* instance();
+
+ void set(const QString& setting, const QVariant& value);
+
+ [[nodiscard]] QVariant get(const QString& setting, const QVariant& def) const;
+
+ template <typename T>
+ [[nodiscard]] T get(const QString& setting, const QVariant& def) const
+ {
+ return get(setting, def).value<T>();
+ }
+
+ bool onSettingChanged(const std::function<void(const QString&, const QVariant&,
+ const QVariant&)>& func);
+
+ [[nodiscard]] QColor overwrittenLooseFilesColor() const;
+ [[nodiscard]] QColor overwritingLooseFilesColor() const;
+ [[nodiscard]] QColor overwrittenArchiveFilesColor() const;
+ [[nodiscard]] QColor overwritingArchiveFilesColor() const;
+ [[nodiscard]] QColor containedColor() const;
+ [[nodiscard]] bool offlineMode() const;
+ [[nodiscard]] lootcli::LogLevels lootLogLevel() const;
+
+ [[nodiscard]] bool externalChangeWarning() const;
+ [[nodiscard]] bool enableSortButton() const;
+ [[nodiscard]] bool lootShowDirty() const;
+ [[nodiscard]] bool lootShowMessages() const;
+ [[nodiscard]] bool lootShowProblems() const;
+
+ void saveTreeExpandState(const QTreeView* view);
+ void restoreTreeExpandState(QTreeView* view) const;
+
+ void saveState(const QHeaderView* header) override;
+ void restoreState(QHeaderView* header) const override;
+
+ void saveState(const QSplitter* splitter) override;
+ void restoreState(QSplitter* splitter) const override;
+
+ void saveState(const MOBase::ExpanderWidget* expander) override;
+ void restoreState(MOBase::ExpanderWidget* expander) const override;
+
+ // IGeometrySettings<QDialog>
+
+ void saveGeometry(const QDialog* dialog) override;
+ void restoreGeometry(QDialog* dialog) const override;
+
+private:
+ void onPluginSettingChanged(const QString& pluginName, const QString& key,
+ const QVariant& oldValue, const QVariant& newValue);
+
+ explicit Settings(MOBase::IOrganizer* organizer);
+
+ MOBase::IOrganizer* Organizer;
+ QSettings MOSettings;
+ SignalSettingChanged SettingChanged;
+};
+
+#endif // SETTINGS_H