From 94765d40cdb7e859f7a9851e7ad4617a28888083 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Thu, 18 Apr 2019 23:17:49 +0200 Subject: [PATCH] [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