diff --git a/src/libcalamares/locale/Label.cpp b/src/libcalamares/locale/Label.cpp index 58c19101d..816246699 100644 --- a/src/libcalamares/locale/Label.cpp +++ b/src/libcalamares/locale/Label.cpp @@ -24,23 +24,16 @@ namespace CalamaresUtils namespace Locale { -Label::Label() - : m_locale( QLocale() ) +Label::Label( QObject* parent ) + : Label( QString(), LabelFormat::IfNeededWithCountry, parent ) { - m_localeId = m_locale.name(); - - setLabels( QString(), LabelFormat::IfNeededWithCountry ); } -Label::Label( const QString& locale, LabelFormat format ) - : m_locale( Label::getLocale( locale ) ) - , m_localeId( locale ) -{ - setLabels( locale, format ); -} +Label::Label( const QString& locale, LabelFormat format, QObject* parent ) + : QObject( parent ) + , m_locale( Label::getLocale( locale ) ) + , m_localeId( locale.isEmpty() ? m_locale.name() : locale ) -void -Label::setLabels( const QString& locale, LabelFormat format ) { //: language[name] (country[name]) QString longFormat = QObject::tr( "%1 (%2)" ); @@ -69,6 +62,10 @@ Label::setLabels( const QString& locale, LabelFormat format ) QLocale Label::getLocale( const QString& localeName ) { + if ( localeName.isEmpty() ) + { + return QLocale(); + } if ( localeName.contains( "@latin" ) ) { QLocale loc( localeName ); // Ignores @latin diff --git a/src/libcalamares/locale/Label.h b/src/libcalamares/locale/Label.h index 95129d38c..d7fa14453 100644 --- a/src/libcalamares/locale/Label.h +++ b/src/libcalamares/locale/Label.h @@ -21,6 +21,7 @@ #define LOCALE_LABEL_H #include +#include #include namespace CalamaresUtils @@ -35,8 +36,14 @@ namespace Locale * translation system) into QLocales, and also into consistent * human-readable text labels. */ -class Label +class Label : public QObject { + Q_OBJECT + + Q_PROPERTY( QString label READ label CONSTANT FINAL ) + Q_PROPERTY( QString englishLabel READ englishLabel CONSTANT FINAL ) + Q_PROPERTY( QString localeId MEMBER m_localeId CONSTANT FINAL ) + public: /** @brief Formatting option for label -- add (country) to label. */ enum class LabelFormat @@ -46,7 +53,7 @@ public: }; /** @brief Empty locale. This uses the system-default locale. */ - Label(); + Label( QObject* parent = nullptr ); /** @brief Construct from a locale name. * @@ -54,7 +61,9 @@ public: * The @p format determines whether the country name is always present * in the label (human-readable form) or only if needed for disambiguation. */ - Label( const QString& localeName, LabelFormat format = LabelFormat::IfNeededWithCountry ); + Label( const QString& localeName, + LabelFormat format = LabelFormat::IfNeededWithCountry, + QObject* parent = nullptr ); /** @brief Define a sorting order. * @@ -94,8 +103,6 @@ public: static QLocale getLocale( const QString& localeName ); protected: - void setLabels( const QString& name, LabelFormat format ); - QLocale m_locale; QString m_localeId; // the locale identifier, e.g. "en_GB" QString m_label; // the native name of the locale diff --git a/src/libcalamares/locale/LabelModel.cpp b/src/libcalamares/locale/LabelModel.cpp index bcb8af057..da4e1a9f7 100644 --- a/src/libcalamares/locale/LabelModel.cpp +++ b/src/libcalamares/locale/LabelModel.cpp @@ -1,6 +1,7 @@ /* === This file is part of Calamares - === * - * Copyright 2019, Adriaan de Groot + * Copyright 2019-2020 Adriaan de Groot + * Copyright 2019, Camilo Higuita * * Calamares is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -36,7 +37,7 @@ LabelModel::LabelModel( const QStringList& locales, QObject* parent ) for ( const auto& l : locales ) { - m_locales.push_back( Label( l ) ); + m_locales.push_back( new Label( l, Label::LabelFormat::IfNeededWithCountry, this ) ); } } @@ -65,27 +66,33 @@ LabelModel::data( const QModelIndex& index, int role ) const switch ( role ) { case LabelRole: - return locale.label(); + return locale->label(); case EnglishLabelRole: - return locale.englishLabel(); + return locale->englishLabel(); default: return QVariant(); } } +QHash< int, QByteArray > +LabelModel::roleNames() const +{ + return { { LabelRole, "label" }, { EnglishLabelRole, "englishLabel" } }; +} + const Label& LabelModel::locale( int row ) const { if ( ( row < 0 ) || ( row >= m_locales.count() ) ) { for ( const auto& l : m_locales ) - if ( l.isEnglish() ) + if ( l->isEnglish() ) { - return l; + return *l; } - return m_locales[ 0 ]; + return *m_locales[ 0 ]; } - return m_locales[ row ]; + return *m_locales[ row ]; } int @@ -93,7 +100,7 @@ LabelModel::find( std::function< bool( const Label& ) > predicate ) const { for ( int row = 0; row < m_locales.count(); ++row ) { - if ( predicate( m_locales[ row ] ) ) + if ( predicate( *m_locales[ row ] ) ) { return row; } diff --git a/src/libcalamares/locale/LabelModel.h b/src/libcalamares/locale/LabelModel.h index 03daddbf3..7bd1fad67 100644 --- a/src/libcalamares/locale/LabelModel.h +++ b/src/libcalamares/locale/LabelModel.h @@ -1,6 +1,7 @@ /* === This file is part of Calamares - === * - * Copyright 2019, Adriaan de Groot + * Copyright 2019-2020, Adriaan de Groot + * Copyright 2019, Camilo Higuita * * Calamares is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -33,6 +34,8 @@ namespace Locale class DLLEXPORT LabelModel : public QAbstractListModel { + Q_OBJECT + public: enum { @@ -46,6 +49,7 @@ public: int rowCount( const QModelIndex& parent ) const override; QVariant data( const QModelIndex& index, int role ) const override; + QHash< int, QByteArray > roleNames() const override; /** @brief Gets locale information for entry #n * @@ -69,7 +73,7 @@ public: int find( const QString& countryCode ) const; private: - QVector< Label > m_locales; + QVector< Label* > m_locales; QStringList m_localeIds; }; diff --git a/src/libcalamaresui/Branding.cpp b/src/libcalamaresui/Branding.cpp index a5b6e5dce..9bdccfa51 100644 --- a/src/libcalamaresui/Branding.cpp +++ b/src/libcalamaresui/Branding.cpp @@ -3,6 +3,7 @@ * Copyright 2014-2015, Teo Mrnjavac * Copyright 2017-2019, Adriaan de Groot * Copyright 2018, Raul Rodrigo Segura (raurodse) + * Copyright 2019, Camilo Higuita * * Calamares is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -74,7 +75,8 @@ const QStringList Branding::s_imageEntryStrings = { "productLogo", "productIcon", - "productWelcome" + "productWelcome", + "productWallpaper" }; const QStringList Branding::s_styleEntryStrings = diff --git a/src/libcalamaresui/Branding.h b/src/libcalamaresui/Branding.h index 30e8be846..e3952881e 100644 --- a/src/libcalamaresui/Branding.h +++ b/src/libcalamaresui/Branding.h @@ -3,6 +3,7 @@ * Copyright 2014-2015, Teo Mrnjavac * Copyright 2017-2018, Adriaan de Groot * Copyright 2018, Raul Rodrigo Segura (raurodse) + * Copyright 2019, Camilo Higuita * * Calamares is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -48,7 +49,7 @@ public: * e.g. *Branding::ProductName to get the string value for * the product name. */ - enum StringEntry : short + enum StringEntry { ProductName, Version, @@ -62,13 +63,16 @@ public: KnownIssuesUrl, ReleaseNotesUrl }; + Q_ENUM( StringEntry ) enum ImageEntry : short { ProductLogo, ProductIcon, - ProductWelcome + ProductWelcome, + ProductWallpaper }; + Q_ENUM( ImageEntry ) enum StyleEntry : short { @@ -77,6 +81,7 @@ public: SidebarTextSelect, SidebarTextHighlight }; + Q_ENUM( StyleEntry ) /** @brief Setting for how much the main window may expand. */ enum class WindowExpansion @@ -85,6 +90,7 @@ public: Fullscreen, Fixed }; + Q_ENUM( WindowExpansion ) /** @brief Setting for the main window size. * * The units are pixels (Pixies) or something-based-on-fontsize (Fonties), which @@ -96,6 +102,7 @@ public: Pixies, Fonties }; + Q_ENUM( WindowDimensionUnit ) class WindowDimension : public NamedSuffix< WindowDimensionUnit, WindowDimensionUnit::None > { public: