From 7ee008e150bc5bcf76082d726f719ee0fdfda982 Mon Sep 17 00:00:00 2001 From: SulfurNitride Date: Wed, 11 Feb 2026 02:37:39 -0600 Subject: Fluorine Manager: full Linux port of Mod Organizer 2 Complete native Linux port with FUSE-based virtual filesystem, Proton/umu-run integration, and Flatpak packaging. Key features: - FUSE VFS replacing Windows USVFS (in-process + standalone helper for Flatpak) - Proton/GE-Proton/umu-run launcher with env var forwarding - Flatpak support (sandbox-aware VFS, NXM handler, umu-run) - Wine prefix management UI - Case-insensitive path resolution for Linux filesystems - QSettings-safe INI handling (avoids Bethesda INI corruption) - Portable instance support with auto-generated launcher scripts Co-Authored-By: Claude Opus 4.6 --- libs/preview_base/src/previewbase.cpp | 185 ++++++++++++++++++++++++++++++++++ 1 file changed, 185 insertions(+) create mode 100644 libs/preview_base/src/previewbase.cpp (limited to 'libs/preview_base/src/previewbase.cpp') diff --git a/libs/preview_base/src/previewbase.cpp b/libs/preview_base/src/previewbase.cpp new file mode 100644 index 0000000..cd393d8 --- /dev/null +++ b/libs/preview_base/src/previewbase.cpp @@ -0,0 +1,185 @@ +/* +Copyright (C) 2014 Sebastian Herbord. All rights reserved. + +This file is part of Base Preview plugin for MO + +Base Preview plugin is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +Base Preview plugin is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with Base Preview plugin. If not, see . +*/ + +#include "previewbase.h" + +#include +#include +#include +#include +#include +#include +#include + +#include + +using namespace MOBase; + +PreviewBase::PreviewBase() : m_MOInfo(nullptr) {} + +bool PreviewBase::init(IOrganizer* moInfo) +{ + m_MOInfo = moInfo; + + const QStringList& blacklist = + m_MOInfo->pluginSetting(name(), "blacklisted_extensions") + .toString() + .toLower() + .split(','); + + // set up image reader to be used for all image types qt (the current installation) + // supports + auto imageReader = + std::bind(&PreviewBase::genImagePreview, this, std::placeholders::_1, + std::placeholders::_2, std::placeholders::_3); + + foreach (const QByteArray& fileType, QImageReader::supportedImageFormats()) { + auto strFileType = QString(fileType).toLower(); + + // skip dds as that one is handled by the dds preview plugin. + if (strFileType == "dds" || blacklist.contains(strFileType)) + continue; + + m_PreviewGenerators[strFileType] = imageReader; + } + + const QStringList supportedTextFormats = {"txt", "ini", "json", "log", "cfg", "psc"}; + + auto textReader = std::bind(&PreviewBase::genTxtPreview, this, std::placeholders::_1, + std::placeholders::_2, std::placeholders::_3); + + foreach (const QString fileType, supportedTextFormats) { + + // skip blacklisted ones + if (blacklist.contains(fileType)) + continue; + + m_PreviewGenerators[fileType] = textReader; + } + + return true; +} + +QString PreviewBase::name() const +{ + return "Preview Base"; +} + +QString PreviewBase::localizedName() const +{ + return tr("Preview Base"); +} + +QString PreviewBase::author() const +{ + return "Tannin"; +} + +QString PreviewBase::description() const +{ + return tr("Supports previewing various types of data files"); +} + +MOBase::VersionInfo PreviewBase::version() const +{ + return VersionInfo(1, 1, 0, VersionInfo::RELEASE_FINAL); +} + +QList PreviewBase::settings() const +{ + QList result; + result.push_back(PluginSetting( + "enabled", + tr("Enable previewing of basic file types, such as images and text files."), + QVariant(true))); + result.push_back( + PluginSetting("blacklisted_extensions", + tr("Specify a list of comma separated extensions (without \".\") " + "that should not be previewed by this plugin."), + QVariant(""))); + return result; +} + +std::set PreviewBase::supportedExtensions() const +{ + std::set extensions; + for (const auto& generator : m_PreviewGenerators) { + extensions.insert(generator.first); + } + + return extensions; +} + +QWidget* PreviewBase::genFilePreview(const QString& fileName, + const QSize& maxSize) const +{ + return genDataPreview(nullptr, fileName, maxSize); +} + +QWidget* PreviewBase::genDataPreview(const QByteArray& fileData, + const QString& fileName, + const QSize& maxSize) const +{ + auto iter = m_PreviewGenerators.find(QFileInfo(fileName).suffix().toLower()); + if (iter != m_PreviewGenerators.end()) { + return iter->second(fileName, maxSize, fileData); + } else { + return nullptr; + } +} + +QWidget* PreviewBase::genImagePreview(const QString& fileName, const QSize&, + const QByteArray& fileData) const +{ + QLabel* label = new QLabel(); + QPixmap pic; + if (fileData == nullptr) { + pic = QPixmap(fileName); + } else { + pic.loadFromData(fileData); + } + QSize screenSize = QApplication::primaryScreen()->geometry().size(); + // ensure the output image is no more than 80% of the screen height. + // If the aspect ratio is higher than that of the screen this would still allow the + // image to extend beyond the screen but it ensures you can drag the window and close + // it + int maxHeight = static_cast(screenSize.height() * 0.8f); + if (pic.size().height() > maxHeight) { + pic = pic.scaledToHeight(maxHeight, Qt::SmoothTransformation); + } + label->setPixmap(pic); + return label; +} + +QWidget* PreviewBase::genTxtPreview(const QString& fileName, const QSize&, + const QByteArray& fileData) const +{ + QTextEdit* edit = new QTextEdit(); + if (fileData == nullptr) { + edit->setText(MOBase::readFileText(fileName)); + } else { + edit->setText(MOBase::decodeTextData(fileData)); + } + edit->setReadOnly(true); + return edit; +} + +#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) +Q_EXPORT_PLUGIN2(previewBase, PreviewBase) +#endif -- cgit v1.3.1