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