From 5994e9b4cecd1f417127e662d21b9e55483e3a44 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 16 Apr 2019 15:34:09 +0200 Subject: [PATCH 01/18] Changes: document what this branch will do --- CHANGES | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGES b/CHANGES index 431da632c..e6cc6ff79 100644 --- a/CHANGES +++ b/CHANGES @@ -20,6 +20,10 @@ This release contains contributions from (alphabetically by first name): ## Modules ## + * *Welcome* module has improved usability: a standard icon + alongside the *Language* label, for improved recognition, + and improved language-list display and sorting. #1107 + # 3.2.5 (2019-04-15) # From 5e951466dfd09e617a9ddbed1606773e191d1800 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 16 Apr 2019 15:38:06 +0200 Subject: [PATCH 02/18] [libcalamaresui] Sort languages by ISO code - this puts the Englishes together, and is less confusing than sorting with American first. --- src/libcalamaresui/utils/CalamaresUtilsGui.h | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/libcalamaresui/utils/CalamaresUtilsGui.h b/src/libcalamaresui/utils/CalamaresUtilsGui.h index 6a036b218..49f94e6a4 100644 --- a/src/libcalamaresui/utils/CalamaresUtilsGui.h +++ b/src/libcalamaresui/utils/CalamaresUtilsGui.h @@ -154,11 +154,7 @@ public: */ bool operator <( const LocaleLabel& other ) const { - if ( isEnglish() ) - return !other.isEnglish(); - if ( other.isEnglish() ) - return false; - return m_sortKey < other.m_sortKey; + return m_localeId < other.m_localeId; } /** @brief Is this locale English? From 620940c75b90d422d73a98285c816cc4a1e8a52b Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 16 Apr 2019 23:49:27 +0200 Subject: [PATCH 03/18] [libcalamaresui] Drop now-unused sortKey from LocaleLabel - sortKey is unused - add englishLabel for reverse-i18n --- src/libcalamaresui/utils/CalamaresUtilsGui.cpp | 12 +++--------- src/libcalamaresui/utils/CalamaresUtilsGui.h | 8 +++++++- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/libcalamaresui/utils/CalamaresUtilsGui.cpp b/src/libcalamaresui/utils/CalamaresUtilsGui.cpp index 69924f1b8..123d9858c 100644 --- a/src/libcalamaresui/utils/CalamaresUtilsGui.cpp +++ b/src/libcalamaresui/utils/CalamaresUtilsGui.cpp @@ -269,26 +269,20 @@ LocaleLabel::LocaleLabel( const QString& locale, LabelFormat format ) //: language[name] (country[name]) QString longFormat = QObject::tr( "%1 (%2)" ); - QString sortKey = QLocale::languageToString( m_locale.language() ); QString languageName = m_locale.nativeLanguageName(); + QString englishName = m_locale.languageToString( m_locale.language() ); QString countryName; if ( languageName.isEmpty() ) - languageName = QString( QLatin1Literal( "* %1 (%2)" ) ).arg( locale, sortKey ); + languageName = QString( QLatin1Literal( "* %1 (%2)" ) ).arg( locale, englishName ); bool needsCountryName = ( format == LabelFormat::AlwaysWithCountry ) || (locale.contains( '_' ) && QLocale::countriesForLanguage( m_locale.language() ).count() > 1 ); if ( needsCountryName ) - { - sortKey.append( '+' ); - sortKey.append( QLocale::countryToString( m_locale.country() ) ); - countryName = m_locale.nativeCountryName(); - } - - m_sortKey = sortKey; m_label = needsCountryName ? longFormat.arg( languageName ).arg( countryName ) : languageName; + m_englishLabel = englishName; } QLocale LocaleLabel::getLocale( const QString& localeName ) diff --git a/src/libcalamaresui/utils/CalamaresUtilsGui.h b/src/libcalamaresui/utils/CalamaresUtilsGui.h index 49f94e6a4..124594800 100644 --- a/src/libcalamaresui/utils/CalamaresUtilsGui.h +++ b/src/libcalamaresui/utils/CalamaresUtilsGui.h @@ -172,6 +172,12 @@ public: { return m_label; } + /** @brief Get the *English* human-readable name for this locale. */ + QString englishLabel() const + { + return m_englishLabel; + } + /** @brief Get the Qt locale. */ QLocale locale() const { @@ -188,8 +194,8 @@ public: protected: QLocale m_locale; QString m_localeId; // the locale identifier, e.g. "en_GB" - QString m_sortKey; // the English name of the locale QString m_label; // the native name of the locale + QString m_englishLabel; } ; From f04d08454835b2619df5226748b62429d84a1e26 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Thu, 18 Apr 2019 14:27:37 +0200 Subject: [PATCH 04/18] [welcome] Start on a model for the locale choices --- src/modules/welcome/CMakeLists.txt | 1 + src/modules/welcome/LocaleModel.cpp | 52 +++++++++++++++++++++++++++++ src/modules/welcome/LocaleModel.h | 43 ++++++++++++++++++++++++ 3 files changed, 96 insertions(+) create mode 100644 src/modules/welcome/LocaleModel.cpp create mode 100644 src/modules/welcome/LocaleModel.h diff --git a/src/modules/welcome/CMakeLists.txt b/src/modules/welcome/CMakeLists.txt index f627db032..415faa500 100644 --- a/src/modules/welcome/CMakeLists.txt +++ b/src/modules/welcome/CMakeLists.txt @@ -27,6 +27,7 @@ calamares_add_plugin( welcome EXPORT_MACRO PLUGINDLLEXPORT_PRO SOURCES ${CHECKER_SOURCES} + LocaleModel.cpp WelcomeViewStep.cpp WelcomePage.cpp UI diff --git a/src/modules/welcome/LocaleModel.cpp b/src/modules/welcome/LocaleModel.cpp new file mode 100644 index 000000000..5fd032a52 --- /dev/null +++ b/src/modules/welcome/LocaleModel.cpp @@ -0,0 +1,52 @@ +/* === This file is part of Calamares - === + * + * Copyright 2019, Adriaan de Groot + * + * Calamares 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. + * + * Calamares 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 Calamares. If not, see . + */ + +#include "LocaleModel.h" + +int +LocaleModel::columnCount( const QModelIndex& ) const +{ + return 2; +} + +int +LocaleModel::rowCount( const QModelIndex& ) const +{ + return m_locales.size(); +} + +QVariant +LocaleModel::data( const QModelIndex& index, int role ) const +{ + if ( role != Qt::DisplayRole ) + return QVariant(); + + if ( !index.isValid() ) + return QVariant(); + + const auto& locale = m_locales.at( index.row() ); + switch ( index.column() ) + { + case 0: + return locale.label(); + case 1: + return locale.englishLabel(); + default: + return QVariant(); + } +} diff --git a/src/modules/welcome/LocaleModel.h b/src/modules/welcome/LocaleModel.h new file mode 100644 index 000000000..06a6a74c2 --- /dev/null +++ b/src/modules/welcome/LocaleModel.h @@ -0,0 +1,43 @@ +/* === This file is part of Calamares - === + * + * Copyright 2019, Adriaan de Groot + * + * Calamares 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. + * + * Calamares 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 Calamares. If not, see . + */ + +#ifndef WELCOME_LOCALEMODEL_H +#define WELCOME_LOCALEMODEL_H + +#include + +#include + +#include "utils/CalamaresUtilsGui.h" + +class LocaleModel : public QAbstractItemModel +{ +public: + LocaleModel( const QStringList& locales, QObject* parent = nullptr ); + virtual ~LocaleModel(); + + int rowCount( const QModelIndex& parent ) const override; + int columnCount( const QModelIndex& parent ) const override; + + QVariant data( const QModelIndex& index, int role ) const override; + +private: + std::vector< CalamaresUtils::LocaleLabel > m_locales; +} ; + +#endif From 7f8411c3b775bf4281d79dea34b9b13f17b0a689 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Thu, 18 Apr 2019 22:38:12 +0200 Subject: [PATCH 05/18] [welcome] Add standard language-chooser icon - After discussion with Red Hat UI advice, switch to standard icon - Tooltip as well --- src/modules/welcome/CMakeLists.txt | 2 + src/modules/welcome/WelcomePage.ui | 40 +++++++------------- src/modules/welcome/language-icon-128px.png | Bin 0 -> 4634 bytes src/modules/welcome/language-icon-48px.png | Bin 0 -> 2315 bytes src/modules/welcome/welcome.qrc | 6 +++ 5 files changed, 21 insertions(+), 27 deletions(-) create mode 100644 src/modules/welcome/language-icon-128px.png create mode 100644 src/modules/welcome/language-icon-48px.png create mode 100644 src/modules/welcome/welcome.qrc diff --git a/src/modules/welcome/CMakeLists.txt b/src/modules/welcome/CMakeLists.txt index 415faa500..d702321f7 100644 --- a/src/modules/welcome/CMakeLists.txt +++ b/src/modules/welcome/CMakeLists.txt @@ -32,6 +32,8 @@ calamares_add_plugin( welcome WelcomePage.cpp UI WelcomePage.ui + RESOURCES + welcome.qrc LINK_PRIVATE_LIBRARIES calamaresui ${CHECKER_LINK_LIBRARIES} diff --git a/src/modules/welcome/WelcomePage.ui b/src/modules/welcome/WelcomePage.ui index a5197fef5..51fa19c04 100644 --- a/src/modules/welcome/WelcomePage.ui +++ b/src/modules/welcome/WelcomePage.ui @@ -13,6 +13,9 @@ Form + + Select language + @@ -46,7 +49,7 @@ - + @@ -64,21 +67,15 @@ - - - - 1 - 0 - + + + Select language - &Language: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + - - languageWidget + + :/welcome/language-icon-48px.png @@ -92,19 +89,6 @@ - - - - Qt::Horizontal - - - - 40 - 20 - - - - @@ -217,6 +201,8 @@ - + + + diff --git a/src/modules/welcome/language-icon-128px.png b/src/modules/welcome/language-icon-128px.png new file mode 100644 index 0000000000000000000000000000000000000000..9f4bf21477c314cdc5e459fe3beb457abda077a8 GIT binary patch literal 4634 zcma)Ac{r5c`+jE(LLplrOBk|CvJXObld|vY*!MlcC?#vk_7O(5EMv)sVEb zE+zXxaH8_nG7kU%8is!Z@@+Pf1b$=*yl)n$=8v)ubo24%HgfYq0TQ>xCFR6#-%<8W z=>`!u{vix~oC8Db{ZYU@Cm#nCw}zWPD#XX%BY<1Y@UCCOk~9E7+1-rH0?qXGf*676^#4dcvuq;5UCxlytZf{`Gwd1+ z%ekzB>kEaYnr;@n`fgep;Kg6wTsl3wbL*kRYR-sKsIJudhSbb0-3)hYqub|uTMF>| zoMW*IIU}28VPZ;KiOus7Hcl=2EGvO;4hoRLC~KkYH&s7Ol72b7T?s2II_t=DPP?J{ zi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sK zhR>T&i7Y*JP0jGL+ISO*R`xY7^_cyA|H9#2R{4;+GYTG6ZEY$!Ik_j`F)%EhzP1r) z0h#m*Lrj+}DwA!KEv~6^dHB9Sg60S51JD8rXhq_;q@^fG7~~a{%GLJz&QAnZfvcuT zmVJ#nNg*Ebd+3e{yGFj;c}H}&N)+YR4uv8`D~(kV$E>1E>{kT)+GXduPogE+qnHCY z4i~)A&DF#e$|(EnPi_^A7&F!ZWRP9u9LS{l4+a`}mRT3SR;FeQFyvgv#LTR1VPR2s zj&52%P_-kM=tDnAhS;%pV z7%F6sSuSy*=gDT!I?eIGFIj8bl8~6iS!)09@&SK33j z$;Zj&N6le)9x2)`v9ABbEHxL!h$y1&+YoVuL||JzAe7?+-7%R2&LBZvtSdT7P55@+ zpD*N!4L4k1)3T?`bj3R!dgPL${Qn90kg$KF;M4Dn!?$CVEe^|eA6{r|9)@t>Z@2T6 z`DW#-h&Gb%hAa(jG{q3}#ht@b2$L+hC%j1;rBCRr)HXQ}r6yT4Ujq9z!57BwK1K%z znNc@AW*i(1V;m1}V0$25?`?TkMpNo=_G8rv#9qb@$^yOC^!Uz5K@!_(=bK9UdY-=w zGFu9?U&x{e9NCU((Yep*i4SnqKU&L-aZ$iuS2V&A|H79&?^whB0&=PKssQOl5<*Y5yWxT`(Z5ho7 z*<`n3cJ1~NqQ7$BdozNOo@(g6B~56~3R0#}R3J}n23t;se-RY%Hu=I~PQ^}Ig7GE9 zqTSU8f-FRoxs0-Y5(ZHIAxsn=|gniB2_qz$*wIbE71929}4FCWD literal 0 HcmV?d00001 diff --git a/src/modules/welcome/language-icon-48px.png b/src/modules/welcome/language-icon-48px.png new file mode 100644 index 0000000000000000000000000000000000000000..4012a4bee05f8f3e38a6f9efe0ff705361b094a7 GIT binary patch literal 2315 zcma)8XHXN`5>5hGKoA8(HDII$2wg*{N&->^Bs3|ZM2dvuL8N(+qF$sU0V7?J0SN*c z+NC6*NW0V#5CuXJFd&8|oq#X?et+JN-92;8w>$HFyE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wT*R5;BH$j}46b4e9b_Zpw*AL8!yVH6ap-)RTNc#c!m{=F|AN;?o;kl23xCTU~97jgGF> zTR!7SOG_)EQh6U<8xO7ETrVh?xN7Jc_Di)jtdKRgx?b9sve8Wm@-hKjW{HJ{Sjm?7O* z4FGX#$sS_-puZ`MB`zc5Kai*E=;+x0u`n<XUsr~wKG1S7#tN1k)MuB_e#Q--V-P5J@ zpjA~>r~T!)RkeHsRvy?nyb@vD-H4fFHa*4 z28V}*O-)TDCQZPgPv?XZH=^lNtx>n8LK=T_W%B}EjazIVibrBkYa7hOS`UIykL;8l z4YB6A1GJ$Zv3iCPz5SzaV`D>T_R@s>xE#J6iWPV(vUdsV^LI^3=EJz&^`)hy7v<&t zU)FYGfm6K4$>ILUi=Z<+gQ>?L8NTowPn_ZF>4G1aX2RxYupXQbDIo zwlYVoz14^kdxq;)=S^P&T+onBIflsNEMhsXF1N{=Xwm%qtl3}hJE81wB(vs2Pf5_ycTi;$1eNWOiT2VcN$`F4Os z0N^;y$=>MjU=6VDUst2&wHP?g(8q{{jm-KtKQh literal 0 HcmV?d00001 diff --git a/src/modules/welcome/welcome.qrc b/src/modules/welcome/welcome.qrc new file mode 100644 index 000000000..37462e0a6 --- /dev/null +++ b/src/modules/welcome/welcome.qrc @@ -0,0 +1,6 @@ + + + language-icon-128px.png + language-icon-48px.png + + From 589168685eb3a4fbdecd9ccd1a598e83ed81858e Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Thu, 18 Apr 2019 23:16:02 +0200 Subject: [PATCH 06/18] [welcome] Complete LocaleModel implementation - It's a table with two columns (localized name and english name) --- src/modules/welcome/LocaleModel.cpp | 13 +++++++++++++ src/modules/welcome/LocaleModel.h | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/modules/welcome/LocaleModel.cpp b/src/modules/welcome/LocaleModel.cpp index 5fd032a52..67e306a3a 100644 --- a/src/modules/welcome/LocaleModel.cpp +++ b/src/modules/welcome/LocaleModel.cpp @@ -18,6 +18,19 @@ #include "LocaleModel.h" +LocaleModel::LocaleModel(const QStringList& locales, QObject* parent) + : QAbstractTableModel( parent ) +{ + m_locales.reserve( locales.count() ); + + for ( const auto& l : locales ) + m_locales.emplace_back( l ); +} + +LocaleModel::~LocaleModel() +{ +} + int LocaleModel::columnCount( const QModelIndex& ) const { diff --git a/src/modules/welcome/LocaleModel.h b/src/modules/welcome/LocaleModel.h index 06a6a74c2..9e622a43f 100644 --- a/src/modules/welcome/LocaleModel.h +++ b/src/modules/welcome/LocaleModel.h @@ -25,7 +25,7 @@ #include "utils/CalamaresUtilsGui.h" -class LocaleModel : public QAbstractItemModel +class LocaleModel : public QAbstractTableModel { public: LocaleModel( const QStringList& locales, QObject* parent = nullptr ); From 94765d40cdb7e859f7a9851e7ad4617a28888083 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Thu, 18 Apr 2019 23:17:49 +0200 Subject: [PATCH 07/18] [welcome] Switch to using LocaleModel for language combobox - Use the model instead of inserting items - While here, tidy includes and documentation --- src/modules/welcome/WelcomePage.cpp | 35 +++++++++-------------------- src/modules/welcome/WelcomePage.h | 7 ++++++ 2 files changed, 18 insertions(+), 24 deletions(-) diff --git a/src/modules/welcome/WelcomePage.cpp b/src/modules/welcome/WelcomePage.cpp index 92dab668b..b0090bc2c 100644 --- a/src/modules/welcome/WelcomePage.cpp +++ b/src/modules/welcome/WelcomePage.cpp @@ -2,7 +2,7 @@ * * Copyright 2014-2015, Teo Mrnjavac * Copyright 2015, Anke Boersma - * Copyright 2017-2018, Adriaan de Groot + * Copyright 2017-2019, Adriaan de Groot * * Calamares is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -21,15 +21,17 @@ #include "WelcomePage.h" #include "ui_WelcomePage.h" -#include "CalamaresVersion.h" +#include "LocaleModel.h" #include "checker/CheckerContainer.h" -#include "utils/Logger.h" -#include "utils/CalamaresUtilsGui.h" -#include "utils/Retranslator.h" -#include "modulesystem/ModuleManager.h" +#include "Branding.h" +#include "CalamaresVersion.h" #include "Settings.h" #include "ViewManager.h" +#include "modulesystem/ModuleManager.h" +#include "utils/Logger.h" +#include "utils/CalamaresUtilsGui.h" +#include "utils/Retranslator.h" #include #include @@ -39,13 +41,11 @@ #include #include -#include "Branding.h" - - WelcomePage::WelcomePage( QWidget* parent ) : QWidget( parent ) , ui( new Ui::WelcomePage ) , m_checkingWidget( new CheckerContainer( this ) ) + , m_languages( nullptr ) { connect( Calamares::ModuleManager::instance(), &Calamares::ModuleManager::requirementsResult, m_checkingWidget, &CheckerContainer::requirementsChecked ); connect( Calamares::ModuleManager::instance(), &Calamares::ModuleManager::requirementsComplete, m_checkingWidget, &CheckerContainer::requirementsComplete ); @@ -156,21 +156,8 @@ WelcomePage::initLanguages() ui->languageWidget->clear(); ui->languageWidget->setInsertPolicy( QComboBox::InsertAtBottom ); - { - std::list< CalamaresUtils::LocaleLabel > localeList; - const auto locales = QString( CALAMARES_TRANSLATION_LANGUAGES ).split( ';'); - for ( const QString& locale : locales ) - { - localeList.emplace_back( locale ); - } - - localeList.sort(); // According to the sortkey, which is english - - for ( const auto& locale : localeList ) - { - ui->languageWidget->addItem( locale.label(), locale.locale() ); - } - } + m_languages = new LocaleModel( QString( CALAMARES_TRANSLATION_LANGUAGES ).split( ';') ); + ui->languageWidget->setModel( m_languages ); // Find the best initial translation QLocale defaultLocale = QLocale( QLocale::system().name() ); diff --git a/src/modules/welcome/WelcomePage.h b/src/modules/welcome/WelcomePage.h index 65b619c79..ec689735b 100644 --- a/src/modules/welcome/WelcomePage.h +++ b/src/modules/welcome/WelcomePage.h @@ -1,6 +1,7 @@ /* === This file is part of Calamares - === * * Copyright 2014, Teo Mrnjavac + * Copyright 2019, Adriaan de Groot * * Calamares is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -27,6 +28,7 @@ class WelcomePage; } class CheckerContainer; +class LocaleModel; class WelcomePage : public QWidget { @@ -34,19 +36,24 @@ class WelcomePage : public QWidget public: explicit WelcomePage( QWidget* parent = nullptr ); + /// @brief Configure the buttons for URLs from the branding configuration void setUpLinks( bool showSupportUrl, bool showKnownIssuesUrl, bool showReleaseNotesUrl ); + /// @brief Results of requirements checking bool verdict() const; protected: void focusInEvent( QFocusEvent* e ) override; //choose the child widget to focus private: + /// @brief Fill the list of languages with the available translations void initLanguages(); + Ui::WelcomePage* ui; CheckerContainer* m_checkingWidget; + LocaleModel *m_languages; }; #endif // WELCOMEPAGE_H From bd0af4bb77dd6a39ca42ab91b5533cb53789c3e0 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Fri, 19 Apr 2019 09:18:26 +0200 Subject: [PATCH 08/18] [libcalamaresui] Give LocaleLabel a default constructor - Needed for use in containers - While here refactor building the english label --- src/libcalamaresui/utils/CalamaresUtilsGui.cpp | 16 +++++++++++++++- src/libcalamaresui/utils/CalamaresUtilsGui.h | 5 +++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/libcalamaresui/utils/CalamaresUtilsGui.cpp b/src/libcalamaresui/utils/CalamaresUtilsGui.cpp index 123d9858c..9f68cf742 100644 --- a/src/libcalamaresui/utils/CalamaresUtilsGui.cpp +++ b/src/libcalamaresui/utils/CalamaresUtilsGui.cpp @@ -262,9 +262,23 @@ clearLayout( QLayout* layout ) } } +LocaleLabel::LocaleLabel() + : m_locale( QLocale() ) +{ + m_localeId = m_locale.name(); + + setLabels( QString(), LabelFormat::IfNeededWithCountry ); +} + LocaleLabel::LocaleLabel( const QString& locale, LabelFormat format ) : m_locale( LocaleLabel::getLocale( locale ) ) , m_localeId( locale ) +{ + setLabels( locale, format ); +} + +void +LocaleLabel::setLabels( const QString& locale, LabelFormat format ) { //: language[name] (country[name]) QString longFormat = QObject::tr( "%1 (%2)" ); @@ -274,7 +288,7 @@ LocaleLabel::LocaleLabel( const QString& locale, LabelFormat format ) QString countryName; if ( languageName.isEmpty() ) - languageName = QString( QLatin1Literal( "* %1 (%2)" ) ).arg( locale, englishName ); + languageName = QString( "* %1 (%2)" ).arg( locale, englishName ); bool needsCountryName = ( format == LabelFormat::AlwaysWithCountry ) || (locale.contains( '_' ) && QLocale::countriesForLanguage( m_locale.language() ).count() > 1 ); diff --git a/src/libcalamaresui/utils/CalamaresUtilsGui.h b/src/libcalamaresui/utils/CalamaresUtilsGui.h index 124594800..9df4f48c6 100644 --- a/src/libcalamaresui/utils/CalamaresUtilsGui.h +++ b/src/libcalamaresui/utils/CalamaresUtilsGui.h @@ -140,6 +140,9 @@ public: /** @brief Formatting option for label -- add (country) to label. */ enum class LabelFormat { AlwaysWithCountry, IfNeededWithCountry } ; + /** @brief Empty locale. This uses the system-default locale. */ + LocaleLabel(); + /** @brief Construct from a locale name. * * The @p localeName should be one that Qt recognizes, e.g. en_US or ar_EY. @@ -192,6 +195,8 @@ 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 From 314aee8d68534ea9e692fad5766d02e5020bfbf3 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Fri, 19 Apr 2019 09:31:16 +0200 Subject: [PATCH 09/18] [welcome] Switch to QVector - QVector is a better match with passing in QStringList, otherwise you end up dealing with Qt's int indexes vs. std::vector's uint indexes everywhere. - Introduce find() --- src/modules/welcome/LocaleModel.cpp | 35 +++++++++++++++++++++++++++-- src/modules/welcome/LocaleModel.h | 22 +++++++++++++++--- 2 files changed, 52 insertions(+), 5 deletions(-) diff --git a/src/modules/welcome/LocaleModel.cpp b/src/modules/welcome/LocaleModel.cpp index 67e306a3a..d2517a461 100644 --- a/src/modules/welcome/LocaleModel.cpp +++ b/src/modules/welcome/LocaleModel.cpp @@ -21,10 +21,11 @@ LocaleModel::LocaleModel(const QStringList& locales, QObject* parent) : QAbstractTableModel( parent ) { + Q_ASSERT( locales.count() > 0 ); m_locales.reserve( locales.count() ); for ( const auto& l : locales ) - m_locales.emplace_back( l ); + m_locales.push_back( CalamaresUtils::LocaleLabel( l ) ); } LocaleModel::~LocaleModel() @@ -40,7 +41,7 @@ LocaleModel::columnCount( const QModelIndex& ) const int LocaleModel::rowCount( const QModelIndex& ) const { - return m_locales.size(); + return m_locales.count(); } QVariant @@ -63,3 +64,33 @@ LocaleModel::data( const QModelIndex& index, int role ) const return QVariant(); } } + +const CalamaresUtils::LocaleLabel& +LocaleModel::locale(int row) +{ + if ( ( row < 0 ) || ( row >= m_locales.count() ) ) + { + for ( const auto& l : m_locales ) + if ( l.isEnglish() ) + return l; + return m_locales[0]; + } + return m_locales[row]; +} + +int +LocaleModel::find(std::function predicate) const +{ + for ( int row = 0; row < m_locales.count() ; ++row ) + { + if ( predicate( m_locales[row] ) ) + return row; + } + return -1; +} + +int +LocaleModel::find(std::function predicate) const +{ + return find( [&]( const LocaleLabel& l ){ return predicate( l.locale() ); } ); +} diff --git a/src/modules/welcome/LocaleModel.h b/src/modules/welcome/LocaleModel.h index 9e622a43f..68cede172 100644 --- a/src/modules/welcome/LocaleModel.h +++ b/src/modules/welcome/LocaleModel.h @@ -20,24 +20,40 @@ #define WELCOME_LOCALEMODEL_H #include +#include -#include #include "utils/CalamaresUtilsGui.h" class LocaleModel : public QAbstractTableModel { public: + using LocaleLabel = CalamaresUtils::LocaleLabel; + LocaleModel( const QStringList& locales, QObject* parent = nullptr ); - virtual ~LocaleModel(); + virtual ~LocaleModel() override; int rowCount( const QModelIndex& parent ) const override; int columnCount( const QModelIndex& parent ) const override; QVariant data( const QModelIndex& index, int role ) const override; + /** @brief Gets locale information for entry #n + * + * This is the backing data for the model; if @p row is out-of-range, + * returns a reference to en_US. + */ + const LocaleLabel& locale( int row ); + + /** @brief Searches for an item that matches @p predicate + * + * Returns the row number of the first match, or -1 if there isn't one. + */ + int find( std::function predicate) const; + int find( std::function predicate) const; + private: - std::vector< CalamaresUtils::LocaleLabel > m_locales; + QVector< LocaleLabel > m_locales; } ; #endif From 0c868dbd17f913be449763e2673aec9bec404a1e Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Fri, 19 Apr 2019 09:39:19 +0200 Subject: [PATCH 10/18] [welcome] Another find() overload - Also find a specific locale - While here, apply Calamares coding style --- src/modules/welcome/LocaleModel.cpp | 40 +++++++++++++++++++---------- src/modules/welcome/LocaleModel.h | 13 +++++----- 2 files changed, 33 insertions(+), 20 deletions(-) diff --git a/src/modules/welcome/LocaleModel.cpp b/src/modules/welcome/LocaleModel.cpp index d2517a461..43d13ea6c 100644 --- a/src/modules/welcome/LocaleModel.cpp +++ b/src/modules/welcome/LocaleModel.cpp @@ -18,7 +18,7 @@ #include "LocaleModel.h" -LocaleModel::LocaleModel(const QStringList& locales, QObject* parent) +LocaleModel::LocaleModel( const QStringList& locales, QObject* parent ) : QAbstractTableModel( parent ) { Q_ASSERT( locales.count() > 0 ); @@ -56,17 +56,17 @@ LocaleModel::data( const QModelIndex& index, int role ) const const auto& locale = m_locales.at( index.row() ); switch ( index.column() ) { - case 0: - return locale.label(); - case 1: - return locale.englishLabel(); - default: - return QVariant(); + case 0: + return locale.label(); + case 1: + return locale.englishLabel(); + default: + return QVariant(); } } -const CalamaresUtils::LocaleLabel& -LocaleModel::locale(int row) +const CalamaresUtils::LocaleLabel& +LocaleModel::locale( int row ) { if ( ( row < 0 ) || ( row >= m_locales.count() ) ) { @@ -78,8 +78,8 @@ LocaleModel::locale(int row) return m_locales[row]; } -int -LocaleModel::find(std::function predicate) const +int +LocaleModel::find( std::function predicate ) const { for ( int row = 0; row < m_locales.count() ; ++row ) { @@ -89,8 +89,20 @@ LocaleModel::find(std::function predicate) const return -1; } -int -LocaleModel::find(std::function predicate) const +int +LocaleModel::find( std::function predicate ) const { - return find( [&]( const LocaleLabel& l ){ return predicate( l.locale() ); } ); + return find( [&]( const LocaleLabel& l ) + { + return predicate( l.locale() ); + } ); +} + +int +LocaleModel::find( const QLocale& locale ) const +{ + return find( [&]( const LocaleLabel& l ) + { + return locale == l.locale(); + } ); } diff --git a/src/modules/welcome/LocaleModel.h b/src/modules/welcome/LocaleModel.h index 68cede172..4df183048 100644 --- a/src/modules/welcome/LocaleModel.h +++ b/src/modules/welcome/LocaleModel.h @@ -29,7 +29,7 @@ class LocaleModel : public QAbstractTableModel { public: using LocaleLabel = CalamaresUtils::LocaleLabel; - + LocaleModel( const QStringList& locales, QObject* parent = nullptr ); virtual ~LocaleModel() override; @@ -39,18 +39,19 @@ public: QVariant data( const QModelIndex& index, int role ) const override; /** @brief Gets locale information for entry #n - * + * * This is the backing data for the model; if @p row is out-of-range, * returns a reference to en_US. */ const LocaleLabel& locale( int row ); - + /** @brief Searches for an item that matches @p predicate - * + * * Returns the row number of the first match, or -1 if there isn't one. */ - int find( std::function predicate) const; - int find( std::function predicate) const; + int find( std::function predicate ) const; + int find( std::function predicate ) const; + int find( const QLocale& ) const; private: QVector< LocaleLabel > m_locales; From 242d75673175af2930774d201fd61ec3acd683db Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Fri, 19 Apr 2019 09:55:51 +0200 Subject: [PATCH 11/18] [libcalamaresui] Add convenience name() to LocaleLabel --- src/libcalamaresui/utils/CalamaresUtilsGui.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/libcalamaresui/utils/CalamaresUtilsGui.h b/src/libcalamaresui/utils/CalamaresUtilsGui.h index 9df4f48c6..f1a20964f 100644 --- a/src/libcalamaresui/utils/CalamaresUtilsGui.h +++ b/src/libcalamaresui/utils/CalamaresUtilsGui.h @@ -187,6 +187,11 @@ public: return m_locale; } + QString LocaleLabel::name() const + { + return m_locale.name(); + } + /** @brief Get a Qt locale for the given @p localeName * * This special-cases `sr@latin`, which is used as a translation From 58aa9f49899a57d2069a5b5d174cc4ae785d0d93 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Fri, 19 Apr 2019 10:04:49 +0200 Subject: [PATCH 12/18] [libcalamares] Move LocaleLabel from libcalamaresui to libcalamares - This isn't a UI-dependent class - Doesn't make much sense in CalamaresUtilsGui either --- src/libcalamares/CMakeLists.txt | 1 + src/libcalamares/utils/LocaleLabel.cpp | 73 +++++++++++ src/libcalamares/utils/LocaleLabel.h | 113 ++++++++++++++++++ .../utils/CalamaresUtilsGui.cpp | 51 +------- src/libcalamaresui/utils/CalamaresUtilsGui.h | 82 ------------- 5 files changed, 188 insertions(+), 132 deletions(-) create mode 100644 src/libcalamares/utils/LocaleLabel.cpp create mode 100644 src/libcalamares/utils/LocaleLabel.h diff --git a/src/libcalamares/CMakeLists.txt b/src/libcalamares/CMakeLists.txt index a7dd1c0fe..fc1f026ae 100644 --- a/src/libcalamares/CMakeLists.txt +++ b/src/libcalamares/CMakeLists.txt @@ -23,6 +23,7 @@ set( utilsSources utils/CalamaresUtils.cpp utils/CalamaresUtilsSystem.cpp utils/CommandList.cpp + utils/LocaleLabel.cpp utils/Logger.cpp utils/PluginFactory.cpp utils/Retranslator.cpp diff --git a/src/libcalamares/utils/LocaleLabel.cpp b/src/libcalamares/utils/LocaleLabel.cpp new file mode 100644 index 000000000..275ece622 --- /dev/null +++ b/src/libcalamares/utils/LocaleLabel.cpp @@ -0,0 +1,73 @@ +/* === This file is part of Calamares - === + * + * Copyright 2014-2015, Teo Mrnjavac + * Copyright 2017-2018, Adriaan de Groot + * + * Calamares 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. + * + * Calamares 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 Calamares. If not, see . + */ + +#include "LocaleLabel.h" + +namespace CalamaresUtils +{ + +LocaleLabel::LocaleLabel() + : m_locale( QLocale() ) +{ + m_localeId = m_locale.name(); + + setLabels( QString(), LabelFormat::IfNeededWithCountry ); +} + +LocaleLabel::LocaleLabel( const QString& locale, LabelFormat format ) + : m_locale( LocaleLabel::getLocale( locale ) ) + , m_localeId( locale ) +{ + setLabels( locale, format ); +} + +void +LocaleLabel::setLabels( const QString& locale, LabelFormat format ) +{ + //: language[name] (country[name]) + QString longFormat = QObject::tr( "%1 (%2)" ); + + QString languageName = m_locale.nativeLanguageName(); + QString englishName = m_locale.languageToString( m_locale.language() ); + QString countryName; + + if ( languageName.isEmpty() ) + languageName = QString( "* %1 (%2)" ).arg( locale, englishName ); + + bool needsCountryName = ( format == LabelFormat::AlwaysWithCountry ) || + (locale.contains( '_' ) && QLocale::countriesForLanguage( m_locale.language() ).count() > 1 ); + + if ( needsCountryName ) + countryName = m_locale.nativeCountryName(); + m_label = needsCountryName ? longFormat.arg( languageName ).arg( countryName ) : languageName; + m_englishLabel = englishName; +} + +QLocale LocaleLabel::getLocale( const QString& localeName ) +{ + if ( localeName.contains( "@latin" ) ) + { + QLocale loc( localeName ); // Ignores @latin + return QLocale( loc.language(), QLocale::Script::LatinScript, loc.country() ); + } + else + return QLocale( localeName ); +} + +} // namespace diff --git a/src/libcalamares/utils/LocaleLabel.h b/src/libcalamares/utils/LocaleLabel.h new file mode 100644 index 000000000..d3113c869 --- /dev/null +++ b/src/libcalamares/utils/LocaleLabel.h @@ -0,0 +1,113 @@ +/* === This file is part of Calamares - === + * + * Copyright 2014-2015, Teo Mrnjavac + * Copyright 2017-2018, Adriaan de Groot + * + * Calamares 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. + * + * Calamares 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 Calamares. If not, see . + */ + +#ifndef LIBCALAMARES_LOCALELABEL_H +#define LIBCALAMARES_LOCALELABEL_H + +#include +#include + +namespace CalamaresUtils +{ + +/** + * @brief Consistent locale (language + country) naming. + * + * Support class to turn locale names (as used by Calamares's + * translation system) into QLocales, and also into consistent + * human-readable text labels. + */ +class LocaleLabel +{ +public: + /** @brief Formatting option for label -- add (country) to label. */ + enum class LabelFormat { AlwaysWithCountry, IfNeededWithCountry } ; + + /** @brief Empty locale. This uses the system-default locale. */ + LocaleLabel(); + + /** @brief Construct from a locale name. + * + * The @p localeName should be one that Qt recognizes, e.g. en_US or ar_EY. + * The @p format determines whether the country name is always present + * in the label (human-readable form) or only if needed for disambiguation. + */ + LocaleLabel( const QString& localeName, LabelFormat format = LabelFormat::IfNeededWithCountry ); + + /** @brief Define a sorting order. + * + * English (@see isEnglish() -- it means en_US) is sorted at the top. + */ + bool operator <( const LocaleLabel& other ) const + { + return m_localeId < other.m_localeId; + } + + /** @brief Is this locale English? + * + * en_US and en (American English) is defined as English. The Queen's + * English -- proper English -- is relegated to non-English status. + */ + bool isEnglish() const + { + return m_localeId == QLatin1Literal( "en_US" ) || m_localeId == QLatin1Literal( "en" ); + } + + /** @brief Get the human-readable name for this locale. */ + QString label() const + { + return m_label; + } + /** @brief Get the *English* human-readable name for this locale. */ + QString englishLabel() const + { + return m_englishLabel; + } + + /** @brief Get the Qt locale. */ + QLocale locale() const + { + return m_locale; + } + + QString name() const + { + return m_locale.name(); + } + + /** @brief Get a Qt locale for the given @p localeName + * + * This special-cases `sr@latin`, which is used as a translation + * name in Calamares, while Qt recognizes `sr@latn`. + */ + 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; +} ; + + +} // namespace CalamaresUtils + +#endif // LIBCALAMARES_LOCALELABEL_H diff --git a/src/libcalamaresui/utils/CalamaresUtilsGui.cpp b/src/libcalamaresui/utils/CalamaresUtilsGui.cpp index 9f68cf742..ef239b9d8 100644 --- a/src/libcalamaresui/utils/CalamaresUtilsGui.cpp +++ b/src/libcalamaresui/utils/CalamaresUtilsGui.cpp @@ -262,53 +262,4 @@ clearLayout( QLayout* layout ) } } -LocaleLabel::LocaleLabel() - : m_locale( QLocale() ) -{ - m_localeId = m_locale.name(); - - setLabels( QString(), LabelFormat::IfNeededWithCountry ); -} - -LocaleLabel::LocaleLabel( const QString& locale, LabelFormat format ) - : m_locale( LocaleLabel::getLocale( locale ) ) - , m_localeId( locale ) -{ - setLabels( locale, format ); -} - -void -LocaleLabel::setLabels( const QString& locale, LabelFormat format ) -{ - //: language[name] (country[name]) - QString longFormat = QObject::tr( "%1 (%2)" ); - - QString languageName = m_locale.nativeLanguageName(); - QString englishName = m_locale.languageToString( m_locale.language() ); - QString countryName; - - if ( languageName.isEmpty() ) - languageName = QString( "* %1 (%2)" ).arg( locale, englishName ); - - bool needsCountryName = ( format == LabelFormat::AlwaysWithCountry ) || - (locale.contains( '_' ) && QLocale::countriesForLanguage( m_locale.language() ).count() > 1 ); - - if ( needsCountryName ) - countryName = m_locale.nativeCountryName(); - m_label = needsCountryName ? longFormat.arg( languageName ).arg( countryName ) : languageName; - m_englishLabel = englishName; -} - -QLocale LocaleLabel::getLocale( const QString& localeName ) -{ - if ( localeName.contains( "@latin" ) ) - { - QLocale loc( localeName ); // Ignores @latin - return QLocale( loc.language(), QLocale::Script::LatinScript, loc.country() ); - } - else - return QLocale( localeName ); -} - - -} +} // namespace diff --git a/src/libcalamaresui/utils/CalamaresUtilsGui.h b/src/libcalamaresui/utils/CalamaresUtilsGui.h index f1a20964f..135a57c43 100644 --- a/src/libcalamaresui/utils/CalamaresUtilsGui.h +++ b/src/libcalamaresui/utils/CalamaresUtilsGui.h @@ -127,88 +127,6 @@ constexpr int windowMinimumHeight = 520; constexpr int windowPreferredWidth = 1024; constexpr int windowPreferredHeight = 520; -/** - * @brief Consistent locale (language + country) naming. - * - * Support class to turn locale names (as used by Calamares's - * translation system) into QLocales, and also into consistent - * human-readable text labels. - */ -class LocaleLabel -{ -public: - /** @brief Formatting option for label -- add (country) to label. */ - enum class LabelFormat { AlwaysWithCountry, IfNeededWithCountry } ; - - /** @brief Empty locale. This uses the system-default locale. */ - LocaleLabel(); - - /** @brief Construct from a locale name. - * - * The @p localeName should be one that Qt recognizes, e.g. en_US or ar_EY. - * The @p format determines whether the country name is always present - * in the label (human-readable form) or only if needed for disambiguation. - */ - LocaleLabel( const QString& localeName, LabelFormat format = LabelFormat::IfNeededWithCountry ); - - /** @brief Define a sorting order. - * - * English (@see isEnglish() -- it means en_US) is sorted at the top. - */ - bool operator <( const LocaleLabel& other ) const - { - return m_localeId < other.m_localeId; - } - - /** @brief Is this locale English? - * - * en_US and en (American English) is defined as English. The Queen's - * English -- proper English -- is relegated to non-English status. - */ - bool isEnglish() const - { - return m_localeId == QLatin1Literal( "en_US" ) || m_localeId == QLatin1Literal( "en" ); - } - - /** @brief Get the human-readable name for this locale. */ - QString label() const - { - return m_label; - } - /** @brief Get the *English* human-readable name for this locale. */ - QString englishLabel() const - { - return m_englishLabel; - } - - /** @brief Get the Qt locale. */ - QLocale locale() const - { - return m_locale; - } - - QString LocaleLabel::name() const - { - return m_locale.name(); - } - - /** @brief Get a Qt locale for the given @p localeName - * - * This special-cases `sr@latin`, which is used as a translation - * name in Calamares, while Qt recognizes `sr@latn`. - */ - 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; -} ; - - } // namespace CalamaresUtils #endif // CALAMARESUTILSGUI_H From 57452b8c380b1d83745ca97d59db5db82ab9857a Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Fri, 19 Apr 2019 10:10:36 +0200 Subject: [PATCH 13/18] [locale] [welcome] Adjust to moved LocaleLabel - Adjust #includes - In [welcome], use find() on the model rather than querying the combo-box. --- src/modules/locale/LocalePage.cpp | 12 ++++--- src/modules/welcome/LocaleModel.h | 2 +- src/modules/welcome/WelcomePage.cpp | 56 +++++++---------------------- 3 files changed, 21 insertions(+), 49 deletions(-) diff --git a/src/modules/locale/LocalePage.cpp b/src/modules/locale/LocalePage.cpp index 1ddb2cc0a..ba76eb763 100644 --- a/src/modules/locale/LocalePage.cpp +++ b/src/modules/locale/LocalePage.cpp @@ -19,23 +19,25 @@ #include "LocalePage.h" -#include "timezonewidget/timezonewidget.h" #include "SetTimezoneJob.h" -#include "utils/CalamaresUtilsGui.h" -#include "utils/Logger.h" -#include "utils/Retranslator.h" +#include "timezonewidget/timezonewidget.h" + #include "GlobalStorage.h" #include "JobQueue.h" #include "LCLocaleDialog.h" #include "Settings.h" +#include "utils/CalamaresUtilsGui.h" +#include "utils/LocaleLabel.h" +#include "utils/Logger.h" +#include "utils/Retranslator.h" + #include #include #include #include #include - LocalePage::LocalePage( QWidget* parent ) : QWidget( parent ) , m_blockTzWidgetSet( false ) diff --git a/src/modules/welcome/LocaleModel.h b/src/modules/welcome/LocaleModel.h index 4df183048..805a1df65 100644 --- a/src/modules/welcome/LocaleModel.h +++ b/src/modules/welcome/LocaleModel.h @@ -23,7 +23,7 @@ #include -#include "utils/CalamaresUtilsGui.h" +#include "utils/LocaleLabel.h" class LocaleModel : public QAbstractTableModel { diff --git a/src/modules/welcome/WelcomePage.cpp b/src/modules/welcome/WelcomePage.cpp index b0090bc2c..30e828dfc 100644 --- a/src/modules/welcome/WelcomePage.cpp +++ b/src/modules/welcome/WelcomePage.cpp @@ -29,8 +29,9 @@ #include "Settings.h" #include "ViewManager.h" #include "modulesystem/ModuleManager.h" -#include "utils/Logger.h" #include "utils/CalamaresUtilsGui.h" +#include "utils/LocaleLabel.h" +#include "utils/Logger.h" #include "utils/Retranslator.h" #include @@ -123,32 +124,6 @@ WelcomePage::WelcomePage( QWidget* parent ) } -/** @brief Match the combobox of languages with a predicate - * - * Scans the entries in the @p list (actually a ComboBox) and if one - * matches the given @p predicate, returns true and sets @p matchFound - * to the locale that matched. - * - * If none match, returns false and leaves @p matchFound unchanged. - */ -static -bool matchLocale( QComboBox& list, QLocale& matchFound, std::function predicate) -{ - for (int i = 0; i < list.count(); i++) - { - QLocale thisLocale = list.itemData( i, Qt::UserRole ).toLocale(); - if ( predicate(thisLocale) ) - { - list.setCurrentIndex( i ); - cDebug() << Logger::SubEntry << "Matched locale " << thisLocale.name(); - matchFound = thisLocale; - return true; - } - } - - return false; -} - void WelcomePage::initLanguages() { @@ -161,38 +136,33 @@ WelcomePage::initLanguages() // Find the best initial translation QLocale defaultLocale = QLocale( QLocale::system().name() ); - QLocale matchedLocale; cDebug() << "Matching exact locale" << defaultLocale; - bool isTranslationAvailable = - matchLocale( *(ui->languageWidget), matchedLocale, - [&](const QLocale& x){ return x.language() == defaultLocale.language() && x.country() == defaultLocale.country(); } ); + int matchedLocaleIndex = m_languages->find( + [&](const QLocale& x){ return x.language() == defaultLocale.language() && x.country() == defaultLocale.country(); } ); - if ( !isTranslationAvailable ) + if ( matchedLocaleIndex < 0 ) { cDebug() << "Matching approximate locale" << defaultLocale.language(); - isTranslationAvailable = - matchLocale( *(ui->languageWidget), matchedLocale, - [&](const QLocale& x){ return x.language() == defaultLocale.language(); } ) ; + matchedLocaleIndex = m_languages->find( + [&](const QLocale& x){ return x.language() == defaultLocale.language(); } ); } - if ( !isTranslationAvailable ) + if ( matchedLocaleIndex < 0 ) { QLocale en_us( QLocale::English, QLocale::UnitedStates ); cDebug() << "Matching English (US)"; - isTranslationAvailable = - matchLocale( *(ui->languageWidget), matchedLocale, - [&](const QLocale& x){ return x == en_us; } ); + matchedLocaleIndex = m_languages->find( en_us ); // Now, if it matched, because we didn't match the system locale, switch to the one found - if ( isTranslationAvailable ) - QLocale::setDefault( matchedLocale ); + if ( matchedLocaleIndex >= 0 ) + QLocale::setDefault( m_languages->locale( matchedLocaleIndex ).locale() ); } - if ( isTranslationAvailable ) - CalamaresUtils::installTranslator( matchedLocale.name(), + if ( matchedLocaleIndex >= 0 ) + CalamaresUtils::installTranslator( m_languages->locale( matchedLocaleIndex ).name(), Calamares::Branding::instance()->translationsPathPrefix(), qApp ); else From e5d1c0ae274f5f96d018b0c1ddcf08aaa88b5398 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Fri, 19 Apr 2019 10:15:57 +0200 Subject: [PATCH 14/18] [welcome] Fix matched-with-a-locale - Previously the matchLocale() function set the index in the combobox; do it separately now. --- src/modules/welcome/WelcomePage.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/modules/welcome/WelcomePage.cpp b/src/modules/welcome/WelcomePage.cpp index 30e828dfc..8185d7f77 100644 --- a/src/modules/welcome/WelcomePage.cpp +++ b/src/modules/welcome/WelcomePage.cpp @@ -137,13 +137,13 @@ WelcomePage::initLanguages() // Find the best initial translation QLocale defaultLocale = QLocale( QLocale::system().name() ); - cDebug() << "Matching exact locale" << defaultLocale; + cDebug() << "Matching locale" << defaultLocale; int matchedLocaleIndex = m_languages->find( [&](const QLocale& x){ return x.language() == defaultLocale.language() && x.country() == defaultLocale.country(); } ); if ( matchedLocaleIndex < 0 ) { - cDebug() << "Matching approximate locale" << defaultLocale.language(); + cDebug() << Logger::SubEntry << "Matching approximate locale" << defaultLocale.language(); matchedLocaleIndex = m_languages->find( [&](const QLocale& x){ return x.language() == defaultLocale.language(); } ); @@ -153,7 +153,7 @@ WelcomePage::initLanguages() { QLocale en_us( QLocale::English, QLocale::UnitedStates ); - cDebug() << "Matching English (US)"; + cDebug() << Logger::SubEntry << "Matching English (US)"; matchedLocaleIndex = m_languages->find( en_us ); // Now, if it matched, because we didn't match the system locale, switch to the one found @@ -162,9 +162,13 @@ WelcomePage::initLanguages() } if ( matchedLocaleIndex >= 0 ) - CalamaresUtils::installTranslator( m_languages->locale( matchedLocaleIndex ).name(), - Calamares::Branding::instance()->translationsPathPrefix(), - qApp ); + { + QString name = m_languages->locale( matchedLocaleIndex ).name(); + cDebug() << Logger::SubEntry << "Matched with index" << matchedLocaleIndex << name; + + CalamaresUtils::installTranslator( name, Calamares::Branding::instance()->translationsPathPrefix(), qApp ); + ui->languageWidget->setCurrentIndex( matchedLocaleIndex ); + } else cWarning() << "No available translation matched" << defaultLocale; From 53fd1590b87d2d8319fd9fe2d16d3d18bae7c399 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Fri, 19 Apr 2019 10:24:10 +0200 Subject: [PATCH 15/18] [welcome] Don't use combobox itemdata for locale information --- src/modules/welcome/WelcomePage.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/welcome/WelcomePage.cpp b/src/modules/welcome/WelcomePage.cpp index 8185d7f77..2f859cd91 100644 --- a/src/modules/welcome/WelcomePage.cpp +++ b/src/modules/welcome/WelcomePage.cpp @@ -177,7 +177,7 @@ WelcomePage::initLanguages() this, [&]( int newIndex ) { - QLocale selectedLocale = ui->languageWidget->itemData( newIndex, Qt::UserRole ).toLocale(); + const auto& selectedLocale = m_languages->locale( newIndex ).locale(); cDebug() << "Selected locale" << selectedLocale; QLocale::setDefault( selectedLocale ); From 0b833b1e756398b0a9a65ef81123768a5aea80d8 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Fri, 19 Apr 2019 11:38:43 +0200 Subject: [PATCH 16/18] [welcome] Switch model to a list model - There doesn't seem to be a real benefit to providing the name and label as separate columns. --- src/modules/welcome/LocaleModel.cpp | 8 +------- src/modules/welcome/LocaleModel.h | 5 ++--- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/src/modules/welcome/LocaleModel.cpp b/src/modules/welcome/LocaleModel.cpp index 43d13ea6c..b735983c1 100644 --- a/src/modules/welcome/LocaleModel.cpp +++ b/src/modules/welcome/LocaleModel.cpp @@ -19,7 +19,7 @@ #include "LocaleModel.h" LocaleModel::LocaleModel( const QStringList& locales, QObject* parent ) - : QAbstractTableModel( parent ) + : QAbstractListModel( parent ) { Q_ASSERT( locales.count() > 0 ); m_locales.reserve( locales.count() ); @@ -32,12 +32,6 @@ LocaleModel::~LocaleModel() { } -int -LocaleModel::columnCount( const QModelIndex& ) const -{ - return 2; -} - int LocaleModel::rowCount( const QModelIndex& ) const { diff --git a/src/modules/welcome/LocaleModel.h b/src/modules/welcome/LocaleModel.h index 805a1df65..c8125c0d8 100644 --- a/src/modules/welcome/LocaleModel.h +++ b/src/modules/welcome/LocaleModel.h @@ -19,13 +19,13 @@ #ifndef WELCOME_LOCALEMODEL_H #define WELCOME_LOCALEMODEL_H -#include +#include #include #include "utils/LocaleLabel.h" -class LocaleModel : public QAbstractTableModel +class LocaleModel : public QAbstractListModel { public: using LocaleLabel = CalamaresUtils::LocaleLabel; @@ -34,7 +34,6 @@ public: virtual ~LocaleModel() override; int rowCount( const QModelIndex& parent ) const override; - int columnCount( const QModelIndex& parent ) const override; QVariant data( const QModelIndex& index, int role ) const override; From 81acc496dc18ca7822514bbd4a6931501a87226d Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Fri, 19 Apr 2019 13:34:25 +0200 Subject: [PATCH 17/18] [welcome] Introduce a delegate for drawing the languages list - Show the native name left, English name right --- src/modules/welcome/CMakeLists.txt | 2 +- src/modules/welcome/LocaleModel.cpp | 15 +++++++++++---- src/modules/welcome/LocaleModel.h | 16 +++++++++++++++- src/modules/welcome/WelcomePage.cpp | 5 +++-- 4 files changed, 30 insertions(+), 8 deletions(-) diff --git a/src/modules/welcome/CMakeLists.txt b/src/modules/welcome/CMakeLists.txt index d702321f7..e6ddd2bd7 100644 --- a/src/modules/welcome/CMakeLists.txt +++ b/src/modules/welcome/CMakeLists.txt @@ -16,9 +16,9 @@ include_directories( ${PROJECT_BINARY_DIR}/src/libcalamaresui ) set( CHECKER_SOURCES checker/CheckerContainer.cpp + checker/GeneralRequirements.cpp checker/ResultWidget.cpp checker/ResultsListWidget.cpp - checker/GeneralRequirements.cpp ${PARTMAN_SRC} ) diff --git a/src/modules/welcome/LocaleModel.cpp b/src/modules/welcome/LocaleModel.cpp index b735983c1..0ecf0fd1c 100644 --- a/src/modules/welcome/LocaleModel.cpp +++ b/src/modules/welcome/LocaleModel.cpp @@ -41,18 +41,18 @@ LocaleModel::rowCount( const QModelIndex& ) const QVariant LocaleModel::data( const QModelIndex& index, int role ) const { - if ( role != Qt::DisplayRole ) + if ( ( role != LabelRole ) && ( role != EnglishLabelRole ) ) return QVariant(); if ( !index.isValid() ) return QVariant(); const auto& locale = m_locales.at( index.row() ); - switch ( index.column() ) + switch ( role ) { - case 0: + case LabelRole: return locale.label(); - case 1: + case EnglishLabelRole: return locale.englishLabel(); default: return QVariant(); @@ -100,3 +100,10 @@ LocaleModel::find( const QLocale& locale ) const return locale == l.locale(); } ); } + +void +LocaleTwoColumnDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const +{ + QStyledItemDelegate::paint( painter, option, index ); + option.widget->style()->drawItemText( painter, option.rect, Qt::AlignRight | Qt::AlignVCenter, option.palette, false, index.data( LocaleModel::EnglishLabelRole ).toString() ); +} diff --git a/src/modules/welcome/LocaleModel.h b/src/modules/welcome/LocaleModel.h index c8125c0d8..b1566d336 100644 --- a/src/modules/welcome/LocaleModel.h +++ b/src/modules/welcome/LocaleModel.h @@ -20,9 +20,9 @@ #define WELCOME_LOCALEMODEL_H #include +#include #include - #include "utils/LocaleLabel.h" class LocaleModel : public QAbstractListModel @@ -30,6 +30,12 @@ class LocaleModel : public QAbstractListModel public: using LocaleLabel = CalamaresUtils::LocaleLabel; + enum + { + LabelRole = Qt::DisplayRole, + EnglishLabelRole = Qt::UserRole + 1 + }; + LocaleModel( const QStringList& locales, QObject* parent = nullptr ); virtual ~LocaleModel() override; @@ -56,4 +62,12 @@ private: QVector< LocaleLabel > m_locales; } ; +class LocaleTwoColumnDelegate : public QStyledItemDelegate +{ +public: + using QStyledItemDelegate::QStyledItemDelegate; + + void paint( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const override; +} ; + #endif diff --git a/src/modules/welcome/WelcomePage.cpp b/src/modules/welcome/WelcomePage.cpp index 2f859cd91..afb63971d 100644 --- a/src/modules/welcome/WelcomePage.cpp +++ b/src/modules/welcome/WelcomePage.cpp @@ -36,10 +36,10 @@ #include #include +#include #include #include #include -#include #include WelcomePage::WelcomePage( QWidget* parent ) @@ -133,6 +133,7 @@ WelcomePage::initLanguages() m_languages = new LocaleModel( QString( CALAMARES_TRANSLATION_LANGUAGES ).split( ';') ); ui->languageWidget->setModel( m_languages ); + ui->languageWidget->setItemDelegate( new LocaleTwoColumnDelegate( ui->languageWidget ) ); // Find the best initial translation QLocale defaultLocale = QLocale( QLocale::system().name() ); @@ -165,7 +166,7 @@ WelcomePage::initLanguages() { QString name = m_languages->locale( matchedLocaleIndex ).name(); cDebug() << Logger::SubEntry << "Matched with index" << matchedLocaleIndex << name; - + CalamaresUtils::installTranslator( name, Calamares::Branding::instance()->translationsPathPrefix(), qApp ); ui->languageWidget->setCurrentIndex( matchedLocaleIndex ); } From cb5825a521b2be9c078c9eb3544b925126d573db Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Fri, 19 Apr 2019 13:52:19 +0200 Subject: [PATCH 18/18] [libcalamares] English label with country --- src/libcalamares/utils/LocaleLabel.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libcalamares/utils/LocaleLabel.cpp b/src/libcalamares/utils/LocaleLabel.cpp index 275ece622..26480ef14 100644 --- a/src/libcalamares/utils/LocaleLabel.cpp +++ b/src/libcalamares/utils/LocaleLabel.cpp @@ -26,7 +26,7 @@ LocaleLabel::LocaleLabel() : m_locale( QLocale() ) { m_localeId = m_locale.name(); - + setLabels( QString(), LabelFormat::IfNeededWithCountry ); } @@ -55,8 +55,8 @@ LocaleLabel::setLabels( const QString& locale, LabelFormat format ) if ( needsCountryName ) countryName = m_locale.nativeCountryName(); - m_label = needsCountryName ? longFormat.arg( languageName ).arg( countryName ) : languageName; - m_englishLabel = englishName; + m_label = needsCountryName ? longFormat.arg( languageName, countryName ) : languageName; + m_englishLabel = needsCountryName ? longFormat.arg( englishName, QLocale::countryToString( m_locale.country() ) ) : englishName; } QLocale LocaleLabel::getLocale( const QString& localeName )