From 1b3d32ca7972ddd4bbef8781d1f3d700d6d12d1c Mon Sep 17 00:00:00 2001 From: Camilo Higuita Date: Thu, 12 Dec 2019 10:41:37 -0500 Subject: [PATCH 1/8] make label item from LabelModel qobject based and expose properties --- src/libcalamares/locale/Label.cpp | 11 ++++++++--- src/libcalamares/locale/Label.h | 18 +++++++++++++++--- src/libcalamares/locale/LabelModel.cpp | 17 +++++++++-------- src/libcalamares/locale/LabelModel.h | 4 +++- 4 files changed, 35 insertions(+), 15 deletions(-) diff --git a/src/libcalamares/locale/Label.cpp b/src/libcalamares/locale/Label.cpp index 58c19101d..519e648bd 100644 --- a/src/libcalamares/locale/Label.cpp +++ b/src/libcalamares/locale/Label.cpp @@ -24,17 +24,19 @@ namespace CalamaresUtils namespace Locale { -Label::Label() - : m_locale( QLocale() ) +Label::Label( QObject* parent ) + : QObject( parent ) + , m_locale( QLocale() ) { m_localeId = m_locale.name(); setLabels( QString(), LabelFormat::IfNeededWithCountry ); } -Label::Label( const QString& locale, LabelFormat format ) +Label::Label( const QString& locale, LabelFormat format, QObject* parent ) : m_locale( Label::getLocale( locale ) ) , m_localeId( locale ) + , QObject( parent ) { setLabels( locale, format ); } @@ -42,6 +44,7 @@ Label::Label( const QString& locale, LabelFormat format ) void Label::setLabels( const QString& locale, LabelFormat format ) { + emit localeIdChanged(m_localeId); //: language[name] (country[name]) QString longFormat = QObject::tr( "%1 (%2)" ); @@ -62,8 +65,10 @@ Label::setLabels( const QString& locale, LabelFormat format ) countryName = m_locale.nativeCountryName(); } m_label = needsCountryName ? longFormat.arg( languageName, countryName ) : languageName; + emit labelChanged(m_label); m_englishLabel = needsCountryName ? longFormat.arg( englishName, QLocale::countryToString( m_locale.country() ) ) : englishName; + emit englishLabelChanged(m_englishLabel); } QLocale diff --git a/src/libcalamares/locale/Label.h b/src/libcalamares/locale/Label.h index 95129d38c..840c6f251 100644 --- a/src/libcalamares/locale/Label.h +++ b/src/libcalamares/locale/Label.h @@ -22,6 +22,7 @@ #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 NOTIFY labelChanged CONSTANT FINAL) + Q_PROPERTY(QString englishLabel READ englishLabel NOTIFY englishLabelChanged CONSTANT FINAL) + Q_PROPERTY(QString localeId MEMBER m_localeId NOTIFY localeIdChanged 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,7 @@ 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. * @@ -100,6 +107,11 @@ protected: QString m_localeId; // the locale identifier, e.g. "en_GB" QString m_label; // the native name of the locale QString m_englishLabel; + +signals: + void labelChanged( QString label ); + void englishLabelChanged( QString englishLabel ); + void localeIdChanged( QString localeIdChanged ); }; } // namespace Locale diff --git a/src/libcalamares/locale/LabelModel.cpp b/src/libcalamares/locale/LabelModel.cpp index bcb8af057..faec3edec 100644 --- a/src/libcalamares/locale/LabelModel.cpp +++ b/src/libcalamares/locale/LabelModel.cpp @@ -17,6 +17,7 @@ */ #include "LabelModel.h" +#include #include "Lookup.h" @@ -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,9 +66,9 @@ 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(); } @@ -79,13 +80,13 @@ 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 +94,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..55dd35b8b 100644 --- a/src/libcalamares/locale/LabelModel.h +++ b/src/libcalamares/locale/LabelModel.h @@ -33,6 +33,8 @@ namespace Locale class DLLEXPORT LabelModel : public QAbstractListModel { + Q_OBJECT + public: enum { @@ -69,7 +71,7 @@ public: int find( const QString& countryCode ) const; private: - QVector< Label > m_locales; + QVector< Label* > m_locales; QStringList m_localeIds; }; From 241cb04f0661225f1daaafb27e43ea7463fa71ee Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 11 Feb 2020 15:25:28 +0100 Subject: [PATCH 2/8] [libcalamares] Coding style --- src/libcalamares/locale/Label.cpp | 6 +++--- src/libcalamares/locale/Label.h | 14 ++++++++------ 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/libcalamares/locale/Label.cpp b/src/libcalamares/locale/Label.cpp index 519e648bd..e526b633d 100644 --- a/src/libcalamares/locale/Label.cpp +++ b/src/libcalamares/locale/Label.cpp @@ -44,7 +44,7 @@ Label::Label( const QString& locale, LabelFormat format, QObject* parent ) void Label::setLabels( const QString& locale, LabelFormat format ) { - emit localeIdChanged(m_localeId); + emit localeIdChanged( m_localeId ); //: language[name] (country[name]) QString longFormat = QObject::tr( "%1 (%2)" ); @@ -65,10 +65,10 @@ Label::setLabels( const QString& locale, LabelFormat format ) countryName = m_locale.nativeCountryName(); } m_label = needsCountryName ? longFormat.arg( languageName, countryName ) : languageName; - emit labelChanged(m_label); + emit labelChanged( m_label ); m_englishLabel = needsCountryName ? longFormat.arg( englishName, QLocale::countryToString( m_locale.country() ) ) : englishName; - emit englishLabelChanged(m_englishLabel); + emit englishLabelChanged( m_englishLabel ); } QLocale diff --git a/src/libcalamares/locale/Label.h b/src/libcalamares/locale/Label.h index 840c6f251..ef6ac0aa3 100644 --- a/src/libcalamares/locale/Label.h +++ b/src/libcalamares/locale/Label.h @@ -21,8 +21,8 @@ #define LOCALE_LABEL_H #include -#include #include +#include namespace CalamaresUtils { @@ -40,9 +40,9 @@ class Label : public QObject { Q_OBJECT - Q_PROPERTY(QString label READ label NOTIFY labelChanged CONSTANT FINAL) - Q_PROPERTY(QString englishLabel READ englishLabel NOTIFY englishLabelChanged CONSTANT FINAL) - Q_PROPERTY(QString localeId MEMBER m_localeId NOTIFY localeIdChanged CONSTANT FINAL) + Q_PROPERTY( QString label READ label NOTIFY labelChanged CONSTANT FINAL ) + Q_PROPERTY( QString englishLabel READ englishLabel NOTIFY englishLabelChanged CONSTANT FINAL ) + Q_PROPERTY( QString localeId MEMBER m_localeId NOTIFY localeIdChanged CONSTANT FINAL ) public: /** @brief Formatting option for label -- add (country) to label. */ @@ -53,7 +53,7 @@ public: }; /** @brief Empty locale. This uses the system-default locale. */ - Label(QObject* parent = nullptr); + Label( QObject* parent = nullptr ); /** @brief Construct from a locale name. * @@ -61,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, QObject* parent = nullptr ); + Label( const QString& localeName, + LabelFormat format = LabelFormat::IfNeededWithCountry, + QObject* parent = nullptr ); /** @brief Define a sorting order. * From 27bc64e63fcba4c0a1f52dae1934de7e5533dff7 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 11 Feb 2020 15:36:30 +0100 Subject: [PATCH 3/8] [libcalamares] C++ style, warnings-- --- src/libcalamares/locale/Label.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/libcalamares/locale/Label.cpp b/src/libcalamares/locale/Label.cpp index e526b633d..2f35d6b03 100644 --- a/src/libcalamares/locale/Label.cpp +++ b/src/libcalamares/locale/Label.cpp @@ -34,9 +34,10 @@ Label::Label( QObject* parent ) } Label::Label( const QString& locale, LabelFormat format, QObject* parent ) - : m_locale( Label::getLocale( locale ) ) + : QObject( parent ) + , m_locale( Label::getLocale( locale ) ) , m_localeId( locale ) - , QObject( parent ) + { setLabels( locale, format ); } From df5a0d25bc845b985c720a320e130686df9663b9 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 11 Feb 2020 16:37:49 +0100 Subject: [PATCH 4/8] [libcalamares] Handle empty locale names quickly --- src/libcalamares/locale/Label.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/libcalamares/locale/Label.cpp b/src/libcalamares/locale/Label.cpp index 2f35d6b03..8e817a4ce 100644 --- a/src/libcalamares/locale/Label.cpp +++ b/src/libcalamares/locale/Label.cpp @@ -75,6 +75,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 From b4b1bf5de213311bb11fc18014e7ad35edb3e44f Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 11 Feb 2020 16:39:39 +0100 Subject: [PATCH 5/8] [libcalamares] Call delegated constructor --- src/libcalamares/locale/Label.cpp | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/libcalamares/locale/Label.cpp b/src/libcalamares/locale/Label.cpp index 8e817a4ce..987c66811 100644 --- a/src/libcalamares/locale/Label.cpp +++ b/src/libcalamares/locale/Label.cpp @@ -25,18 +25,14 @@ namespace Locale { Label::Label( QObject* parent ) - : QObject( parent ) - , m_locale( QLocale() ) + : Label( QString(), LabelFormat::IfNeededWithCountry, parent ) { - m_localeId = m_locale.name(); - - setLabels( QString(), LabelFormat::IfNeededWithCountry ); } Label::Label( const QString& locale, LabelFormat format, QObject* parent ) : QObject( parent ) , m_locale( Label::getLocale( locale ) ) - , m_localeId( locale ) + , m_localeId( locale.isEmpty() ? m_locale.name() : locale ) { setLabels( locale, format ); From 684c5f477cf86e737d48c1c3e84ef831176555e4 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 11 Feb 2020 16:40:36 +0100 Subject: [PATCH 6/8] [libcalamares] Moc warnings-- - don't have a NOTIFY CONSTANT property - the data is constant, so drop NOTIFY - remove redundant signals - remove setLabels() now it's only needed from one constructor --- src/libcalamares/locale/Label.cpp | 9 --------- src/libcalamares/locale/Label.h | 13 +++---------- 2 files changed, 3 insertions(+), 19 deletions(-) diff --git a/src/libcalamares/locale/Label.cpp b/src/libcalamares/locale/Label.cpp index 987c66811..816246699 100644 --- a/src/libcalamares/locale/Label.cpp +++ b/src/libcalamares/locale/Label.cpp @@ -35,13 +35,6 @@ Label::Label( const QString& locale, LabelFormat format, QObject* parent ) , m_localeId( locale.isEmpty() ? m_locale.name() : locale ) { - setLabels( locale, format ); -} - -void -Label::setLabels( const QString& locale, LabelFormat format ) -{ - emit localeIdChanged( m_localeId ); //: language[name] (country[name]) QString longFormat = QObject::tr( "%1 (%2)" ); @@ -62,10 +55,8 @@ Label::setLabels( const QString& locale, LabelFormat format ) countryName = m_locale.nativeCountryName(); } m_label = needsCountryName ? longFormat.arg( languageName, countryName ) : languageName; - emit labelChanged( m_label ); m_englishLabel = needsCountryName ? longFormat.arg( englishName, QLocale::countryToString( m_locale.country() ) ) : englishName; - emit englishLabelChanged( m_englishLabel ); } QLocale diff --git a/src/libcalamares/locale/Label.h b/src/libcalamares/locale/Label.h index ef6ac0aa3..d7fa14453 100644 --- a/src/libcalamares/locale/Label.h +++ b/src/libcalamares/locale/Label.h @@ -40,9 +40,9 @@ class Label : public QObject { Q_OBJECT - Q_PROPERTY( QString label READ label NOTIFY labelChanged CONSTANT FINAL ) - Q_PROPERTY( QString englishLabel READ englishLabel NOTIFY englishLabelChanged CONSTANT FINAL ) - Q_PROPERTY( QString localeId MEMBER m_localeId NOTIFY localeIdChanged CONSTANT FINAL ) + 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. */ @@ -103,17 +103,10 @@ 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 QString m_englishLabel; - -signals: - void labelChanged( QString label ); - void englishLabelChanged( QString englishLabel ); - void localeIdChanged( QString localeIdChanged ); }; } // namespace Locale From ca13d1670e0ab958a3aa985e0d95ec5277be9c47 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Wed, 12 Feb 2020 13:40:59 +0100 Subject: [PATCH 7/8] [libcalamares] Merge more from Camilo - Complete the model for locales --- src/libcalamares/locale/LabelModel.cpp | 10 ++++++++-- src/libcalamares/locale/LabelModel.h | 4 +++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/libcalamares/locale/LabelModel.cpp b/src/libcalamares/locale/LabelModel.cpp index faec3edec..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 @@ -17,7 +18,6 @@ */ #include "LabelModel.h" -#include #include "Lookup.h" @@ -74,6 +74,12 @@ LabelModel::data( const QModelIndex& index, int role ) const } } +QHash< int, QByteArray > +LabelModel::roleNames() const +{ + return { { LabelRole, "label" }, { EnglishLabelRole, "englishLabel" } }; +} + const Label& LabelModel::locale( int row ) const { diff --git a/src/libcalamares/locale/LabelModel.h b/src/libcalamares/locale/LabelModel.h index 55dd35b8b..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 @@ -48,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 * From 1f2f1a657e0d3a530247a72ee3a7ddeeaaeb0e55 Mon Sep 17 00:00:00 2001 From: Camilo Higuita Date: Fri, 13 Dec 2019 14:22:15 +0100 Subject: [PATCH 8/8] [libcalamaresui] Expose Branding strings to QML --- src/libcalamaresui/Branding.cpp | 4 +++- src/libcalamaresui/Branding.h | 11 +++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) 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: