[locale] [welcome] Adjust to moved LocaleLabel

- Adjust #includes
 - In [welcome], use find() on the model rather than querying
   the combo-box.
main
Adriaan de Groot 6 years ago
parent 58aa9f4989
commit 57452b8c38

@ -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 <QBoxLayout>
#include <QComboBox>
#include <QLabel>
#include <QPushButton>
#include <QProcess>
LocalePage::LocalePage( QWidget* parent )
: QWidget( parent )
, m_blockTzWidgetSet( false )

@ -23,7 +23,7 @@
#include <QVector>
#include "utils/CalamaresUtilsGui.h"
#include "utils/LocaleLabel.h"
class LocaleModel : public QAbstractTableModel
{

@ -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 <QApplication>
@ -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<bool(const QLocale&)> 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

Loading…
Cancel
Save