From 819a57e45883da1341cf2565d5596cf046fd57cd Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Fri, 11 Jan 2019 17:35:06 +0100 Subject: [PATCH] [libcalamaresui] Store resize configuration - Use the named enums code for simplicity. --- src/libcalamaresui/Branding.cpp | 27 +++++++++++++++++++++++---- src/libcalamaresui/Branding.h | 13 ++++++++++++- 2 files changed, 35 insertions(+), 5 deletions(-) diff --git a/src/libcalamaresui/Branding.cpp b/src/libcalamaresui/Branding.cpp index 086e20b7d..7f8e8c343 100644 --- a/src/libcalamaresui/Branding.cpp +++ b/src/libcalamaresui/Branding.cpp @@ -21,9 +21,10 @@ #include "GlobalStorage.h" #include "utils/CalamaresUtils.h" +#include "utils/ImageRegistry.h" #include "utils/Logger.h" +#include "utils/NamedEnum.h" #include "utils/YamlUtils.h" -#include "utils/ImageRegistry.h" #include #include @@ -107,12 +108,11 @@ Branding::Branding( const QString& brandingFilePath, bail( "The branding component name should match the name of the " "component directory." ); + initSimpleSettings( doc ); + if ( !doc[ "strings" ].IsMap() ) bail( "Syntax error in strings map." ); - m_welcomeStyleCalamares = doc[ "welcomeStyleCalamares" ].as< bool >( false ); - m_welcomeExpandingLogo = doc[ "welcomeExpandingLogo" ].as< bool >( true ); - QVariantMap strings = CalamaresUtils::yamlMapToVariant( doc[ "strings" ] ).toMap(); m_strings.clear(); @@ -288,6 +288,25 @@ Branding::setGlobals( GlobalStorage* globalStorage ) const } +void +Branding::initSimpleSettings( const YAML::Node& doc ) +{ + static const NamedEnumTable< WindowExpansion > weNames{ + { QStringLiteral( "normal" ), WindowExpansion::Normal }, + { QStringLiteral( "fullscreen" ), WindowExpansion::Fullscreen }, + { QStringLiteral( "noexpand" ), WindowExpansion::Fixed } + }; + + bool ok = false; + + m_welcomeStyleCalamares = doc[ "welcomeStyleCalamares" ].as< bool >( false ); + m_welcomeExpandingLogo = doc[ "welcomeExpandingLogo" ].as< bool >( true ); + m_windowExpansion = weNames.find( QString::fromStdString( doc[ "windowExpanding" ].as< std::string >() ), ok ); + if ( !ok ) + cWarning() << "Branding module-setting *windowExpanding* interpreted as" << weNames.find( m_windowExpansion, ok ); +} + + void Branding::bail( const QString& message ) { diff --git a/src/libcalamaresui/Branding.h b/src/libcalamaresui/Branding.h index fe9a83979..94136791c 100644 --- a/src/libcalamaresui/Branding.h +++ b/src/libcalamaresui/Branding.h @@ -27,6 +27,10 @@ #include #include +namespace YAML +{ + class Node; +} namespace Calamares { @@ -63,7 +67,7 @@ public: ProductIcon, ProductWelcome }; - + enum StyleEntry : short { SidebarBackground, @@ -72,6 +76,9 @@ public: SidebarTextHighlight }; + /** @brief Setting for how much the main window may expand. */ + enum class WindowExpansion { Normal, Fullscreen, Fixed } ; + static Branding* instance(); explicit Branding( const QString& brandingFilePath, @@ -115,8 +122,12 @@ private: QString m_slideshowPath; QString m_translationsPathPrefix; + /** @brief Initialize the simple settings below */ + void initSimpleSettings( const YAML::Node& doc ); + bool m_welcomeStyleCalamares; bool m_welcomeExpandingLogo; + WindowExpansion m_windowExpansion; }; template inline QString operator*(U e) { return Branding::instance()->string( e ); }