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) # diff --git a/src/libcalamares/CMakeLists.txt b/src/libcalamares/CMakeLists.txt index 340f8fe3b..f581b4450 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..26480ef14 --- /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, countryName ) : languageName; + m_englishLabel = needsCountryName ? longFormat.arg( englishName, QLocale::countryToString( m_locale.country() ) ) : 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 24b42d4e5..cdc3f2ecb 100644 --- a/src/libcalamaresui/utils/CalamaresUtilsGui.cpp +++ b/src/libcalamaresui/utils/CalamaresUtilsGui.cpp @@ -262,45 +262,4 @@ clearLayout( QLayout* layout ) } } -LocaleLabel::LocaleLabel( const QString& locale, LabelFormat format ) - : m_locale( LocaleLabel::getLocale( locale ) ) - , m_localeId( locale ) -{ - //: language[name] (country[name]) - QString longFormat = QObject::tr( "%1 (%2)" ); - - QString sortKey = QLocale::languageToString( m_locale.language() ); - QString languageName = m_locale.nativeLanguageName(); - QString countryName; - - if ( languageName.isEmpty() ) - languageName = QString( QLatin1Literal( "* %1 (%2)" ) ).arg( locale, sortKey ); - - 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; -} - -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 6a036b218..135a57c43 100644 --- a/src/libcalamaresui/utils/CalamaresUtilsGui.h +++ b/src/libcalamaresui/utils/CalamaresUtilsGui.h @@ -127,76 +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 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 - { - if ( isEnglish() ) - return !other.isEnglish(); - if ( other.isEnglish() ) - return false; - return m_sortKey < other.m_sortKey; - } - - /** @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 Qt locale. */ - QLocale locale() const - { - return m_locale; - } - - /** @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: - 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 -} ; - - } // namespace CalamaresUtils #endif // CALAMARESUTILSGUI_H diff --git a/src/modules/locale/LocalePage.cpp b/src/modules/locale/LocalePage.cpp index c1309a129..c8076866e 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/CMakeLists.txt b/src/modules/welcome/CMakeLists.txt index f627db032..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} ) @@ -27,10 +27,13 @@ calamares_add_plugin( welcome EXPORT_MACRO PLUGINDLLEXPORT_PRO SOURCES ${CHECKER_SOURCES} + LocaleModel.cpp WelcomeViewStep.cpp WelcomePage.cpp UI WelcomePage.ui + RESOURCES + welcome.qrc LINK_PRIVATE_LIBRARIES calamaresui ${CHECKER_LINK_LIBRARIES} diff --git a/src/modules/welcome/LocaleModel.cpp b/src/modules/welcome/LocaleModel.cpp new file mode 100644 index 000000000..0ecf0fd1c --- /dev/null +++ b/src/modules/welcome/LocaleModel.cpp @@ -0,0 +1,109 @@ +/* === 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" + +LocaleModel::LocaleModel( const QStringList& locales, QObject* parent ) + : QAbstractListModel( parent ) +{ + Q_ASSERT( locales.count() > 0 ); + m_locales.reserve( locales.count() ); + + for ( const auto& l : locales ) + m_locales.push_back( CalamaresUtils::LocaleLabel( l ) ); +} + +LocaleModel::~LocaleModel() +{ +} + +int +LocaleModel::rowCount( const QModelIndex& ) const +{ + return m_locales.count(); +} + +QVariant +LocaleModel::data( const QModelIndex& index, int role ) const +{ + if ( ( role != LabelRole ) && ( role != EnglishLabelRole ) ) + return QVariant(); + + if ( !index.isValid() ) + return QVariant(); + + const auto& locale = m_locales.at( index.row() ); + switch ( role ) + { + case LabelRole: + return locale.label(); + case EnglishLabelRole: + return locale.englishLabel(); + default: + 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() ); + } ); +} + +int +LocaleModel::find( const QLocale& locale ) const +{ + return find( [&]( const LocaleLabel& l ) + { + 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 new file mode 100644 index 000000000..b1566d336 --- /dev/null +++ b/src/modules/welcome/LocaleModel.h @@ -0,0 +1,73 @@ +/* === 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 + +#include "utils/LocaleLabel.h" + +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; + + int rowCount( 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; + int find( const QLocale& ) const; + +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 92dab668b..afb63971d 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,31 +21,32 @@ #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/CalamaresUtilsGui.h" +#include "utils/LocaleLabel.h" +#include "utils/Logger.h" +#include "utils/Retranslator.h" #include #include +#include #include #include #include -#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 ); @@ -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() { @@ -156,58 +131,45 @@ 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 ); + ui->languageWidget->setItemDelegate( new LocaleTwoColumnDelegate( ui->languageWidget ) ); // 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(); } ); + cDebug() << "Matching locale" << defaultLocale; + 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(); + cDebug() << Logger::SubEntry << "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; } ); + 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 - if ( isTranslationAvailable ) - QLocale::setDefault( matchedLocale ); + if ( matchedLocaleIndex >= 0 ) + QLocale::setDefault( m_languages->locale( matchedLocaleIndex ).locale() ); } - if ( isTranslationAvailable ) - CalamaresUtils::installTranslator( matchedLocale.name(), - Calamares::Branding::instance()->translationsPathPrefix(), - qApp ); + if ( matchedLocaleIndex >= 0 ) + { + 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; @@ -216,7 +178,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 ); 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 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 000000000..9f4bf2147 Binary files /dev/null and b/src/modules/welcome/language-icon-128px.png differ diff --git a/src/modules/welcome/language-icon-48px.png b/src/modules/welcome/language-icon-48px.png new file mode 100644 index 000000000..4012a4bee Binary files /dev/null and b/src/modules/welcome/language-icon-48px.png differ 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 + +