Skip to content

Commit

Permalink
Fix after rebase.
Browse files Browse the repository at this point in the history
  • Loading branch information
Holt59 committed Aug 5, 2024
1 parent 680eed7 commit c976d47
Show file tree
Hide file tree
Showing 12 changed files with 470 additions and 507 deletions.
2 changes: 1 addition & 1 deletion src/extensionlistproxy.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef EXTENSIONLISTPROXY_H
#define EXTENSIONLISTPROXY_H

#include <iextensionlist.h>
#include <uibase/extensions/iextensionlist.h>

#include "extensionmanager.h"

Expand Down
2 changes: 1 addition & 1 deletion src/extensionmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <boost/fusion/container.hpp>
#include <boost/fusion/include/at_key.hpp>

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

#include "extensionwatcher.h"

Expand Down
2 changes: 1 addition & 1 deletion src/extensionwatcher.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef EXTENSIONWATCHER_H
#define EXTENSIONWATCHER_H

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

// an extension watcher is a class that watches extensions get loaded/unloaded,
// typically to extract information from theme that are needed by MO2
Expand Down
809 changes: 346 additions & 463 deletions src/organizer_en.ts

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/organizercore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1081,7 +1081,7 @@ bool OrganizerCore::previewFileWithAlternatives(QWidget* parent, QString fileNam
libbsarch::memory_blob fileData =
archiveLoader.extract_to_memory(fileName.toStdWString());
QByteArray convertedFileData((char*)(fileData.data), fileData.size);
QWidget* wid = m_PluginContainer->previewGenerator().genArchivePreview(
QWidget* wid = m_PluginManager->previewGenerator().genArchivePreview(
convertedFileData, filePath);
if (wid == nullptr) {
reportError(tr("failed to generate preview for %1").arg(filePath));
Expand Down
20 changes: 10 additions & 10 deletions src/pluginmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@

#include <QObject>

#include <extension.h>
#include <iplugin.h>
#include <iplugindiagnose.h>
#include <ipluginfilemapper.h>
#include <iplugingame.h>
#include <iplugininstaller.h>
#include <ipluginloader.h>
#include <ipluginmodpage.h>
#include <ipluginpreview.h>
#include <iplugintool.h>
#include <uibase/extensions/extension.h>
#include <uibase/extensions/ipluginloader.h>
#include <uibase/iplugin.h>
#include <uibase/iplugindiagnose.h>
#include <uibase/ipluginfilemapper.h>
#include <uibase/iplugingame.h>
#include <uibase/iplugininstaller.h>
#include <uibase/ipluginmodpage.h>
#include <uibase/ipluginpreview.h>
#include <uibase/iplugintool.h>

#include "game_features.h"
#include "previewgenerator.h"
Expand Down
4 changes: 2 additions & 2 deletions src/previewgenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ QWidget* PreviewGenerator::genArchivePreview(const QByteArray& fileData,
const QString& fileName) const
{
const QString ext = QFileInfo(fileName).suffix().toLower();
auto& previews = m_PluginContainer.plugins<IPluginPreview>();
auto& previews = m_PluginManager.plugins<IPluginPreview>();
for (auto* preview : previews) {
if (m_PluginContainer.isEnabled(preview) &&
if (m_PluginManager.isEnabled(preview) &&
preview->supportedExtensions().contains(ext) && preview->supportsArchives()) {
return preview->genDataPreview(fileData, fileName, m_MaxSize);
}
Expand Down
2 changes: 1 addition & 1 deletion src/proxyqt.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#include <map>

#include <ipluginloader.h>
#include <uibase/extensions/ipluginloader.h>

class ProxyQtLoader : public MOBase::IPluginLoader
{
Expand Down
2 changes: 1 addition & 1 deletion src/settingsdialogextensionrow.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#include <QWidget>

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

namespace Ui
{
Expand Down
122 changes: 100 additions & 22 deletions src/thememanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
#include <QDir>
#include <QDirIterator>
#include <QProxyStyle>
#include <QTextStream>

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

#include "shared/appconfig.h"

Expand Down Expand Up @@ -60,15 +61,95 @@ class ProxyStyle : public QProxyStyle
}
};

namespace
{
QString readWholeFile(std::filesystem::path const& path)
{
QFile file(path);
if (!file.open(QFile::ReadOnly | QFile::Text)) {
return {};
}

return QTextStream(&file).readAll();
}

QStringList extractTopStyleSheetComments(QString const& stylesheet)
{
QTextStream stream(stylesheet.toUtf8());
QStringList topComments;

while (true) {
const auto byteLine = stream.readLine();
if (byteLine.isNull()) {
break;
}

const auto line = QString(byteLine).trimmed();

// skip empty lines
if (line.isEmpty()) {
continue;
}

// only handle single line comments
if (!line.startsWith("/*")) {
break;
}

topComments.push_back(line.mid(2, line.size() - 4).trimmed());
}

return topComments;
}

QString extractBaseStyleFromStyleSheet(std::filesystem::path const& path,
QString const& stylesheet,
const QString& defaultStyle)
{
// read the first line of the files that are either empty or comments
//
const auto topLines = extractTopStyleSheetComments(stylesheet);

const auto factoryStyles = QStyleFactory::keys();

QString style = defaultStyle;

for (const auto& line : topLines) {
if (!line.startsWith("mo2-base-style")) {
continue;
}

const auto parts = line.split(":");
if (parts.size() != 2) {
log::warn("found invalid top-comment for mo2 in {}: {}", path, line);
continue;
}

const auto tmpStyle = parts[1].trimmed();
const auto index = factoryStyles.indexOf(tmpStyle, 0, Qt::CaseInsensitive);
if (index == -1) {
log::warn("base style '{}' from style '{}' not found", tmpStyle, path, line);
continue;
}

style = factoryStyles[index];
log::info("found base style '{}' for style '{}'", style, path);
break;
}

return style;
}

} // namespace

ThemeManager::ThemeManager(QApplication* application) : m_app{application}
{
// add built-in themes
addQtThemes();

// find the default theme - this might be a built-in Qt theme, or null, in which case
// we just create a default theme
if (auto it =
m_baseThemesByIdentifier.find(m_app->style()->objectName().toStdString());
if (auto it = m_baseThemesByIdentifier.find("windowsvista");
it != m_baseThemesByIdentifier.end()) {
m_defaultTheme = it->second;
} else {
Expand Down Expand Up @@ -148,12 +229,14 @@ void ThemeManager::loadQtTheme(std::string_view themeIdentifier)

void ThemeManager::loadExtensionTheme(std::shared_ptr<const Theme> const& theme)
{
auto baseTheme = ToQString(m_defaultTheme->identifier());
const auto stylesheet = buildStyleSheet(theme, baseTheme);

// load the default theme
m_app->setStyle(
new ProxyStyle(QStyleFactory::create(ToQString(m_defaultTheme->identifier()))));
m_app->setStyle(new ProxyStyle(QStyleFactory::create(baseTheme)));

// build the stylesheet and set it
m_app->setStyleSheet(buildStyleSheet(theme));
m_app->setStyleSheet(stylesheet);
}

void ThemeManager::unload()
Expand Down Expand Up @@ -198,24 +281,19 @@ void ThemeManager::addQtThemes()
}
}

namespace
QString ThemeManager::buildStyleSheet(std::shared_ptr<const Theme> const& theme,
QString& baseTheme) const
{
QString readWholeFile(std::filesystem::path const& path)
{
QFile file(path);
if (!file.open(QFile::ReadOnly | QFile::Text)) {
return {};
}
// read the file
const auto stylesheetContent = readWholeFile(theme->stylesheet());

return QTextStream(&file).readAll();
}
} // namespace
// check for base theme override
baseTheme =
extractBaseStyleFromStyleSheet(theme->stylesheet(), stylesheetContent, baseTheme);

QString ThemeManager::buildStyleSheet(std::shared_ptr<const Theme> const& theme) const
{
// create the base stylesheet
QString stylesheet = patchStyleSheet(readWholeFile(theme->stylesheet()),
theme->stylesheet().parent_path());
// patch the file
QString stylesheet =
patchStyleSheet(stylesheetContent, theme->stylesheet().parent_path());

for (auto&& themeAddition : m_additions) {
if (themeAddition->isAdditionFor(*theme)) {
Expand Down
8 changes: 5 additions & 3 deletions src/thememanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <QApplication>
#include <QFileSystemWatcher>

#include <theme.h>
#include <uibase/extensions/theme.h>

#include "extensionwatcher.h"

Expand Down Expand Up @@ -70,9 +70,11 @@ class ThemeManager : public ExtensionWatcher<MOBase::ThemeExtension>,
//
void loadExtensionTheme(std::shared_ptr<const MOBase::Theme> const& theme);

// build a stylesheet for a theme
// build a stylesheet for a theme, extracting the base theme if needed (if no base
// theme is found, the baseTheme variable is kept untouched)
//
QString buildStyleSheet(std::shared_ptr<const MOBase::Theme> const& theme) const;
QString buildStyleSheet(std::shared_ptr<const MOBase::Theme> const& theme,
QString& baseTheme) const;

// patch the given stylesheet by replacing url() to be relative to the given folder
//
Expand Down
2 changes: 1 addition & 1 deletion src/translationmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <QApplication>
#include <QTranslator>

#include <translation.h>
#include <uibase/extensions/translation.h>

#include "extensionwatcher.h"

Expand Down

0 comments on commit c976d47

Please sign in to comment.