Merge branch 'locale-polish'
This commit is contained in:
commit
0c14bbc50b
3
CHANGES
3
CHANGES
@ -12,6 +12,9 @@ This release contains contributions from (alphabetically by first name):
|
|||||||
|
|
||||||
## Modules ##
|
## Modules ##
|
||||||
|
|
||||||
|
- *locale* module no longer recognized the legacy GeoIP configuration.
|
||||||
|
This has been deprecated since Calamares 3.2.8.
|
||||||
|
|
||||||
|
|
||||||
# 3.2.13 (2019-08-30) #
|
# 3.2.13 (2019-08-30) #
|
||||||
|
|
||||||
|
@ -18,10 +18,15 @@
|
|||||||
|
|
||||||
#include "Manager.h"
|
#include "Manager.h"
|
||||||
|
|
||||||
|
#include "utils/Logger.h"
|
||||||
|
|
||||||
#include <QEventLoop>
|
#include <QEventLoop>
|
||||||
|
#include <QMutex>
|
||||||
|
#include <QMutexLocker>
|
||||||
#include <QNetworkAccessManager>
|
#include <QNetworkAccessManager>
|
||||||
#include <QNetworkReply>
|
#include <QNetworkReply>
|
||||||
#include <QNetworkRequest>
|
#include <QNetworkRequest>
|
||||||
|
#include <QThread>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
|
||||||
namespace CalamaresUtils
|
namespace CalamaresUtils
|
||||||
@ -45,21 +50,91 @@ RequestOptions::applyToRequest( QNetworkRequest* request ) const
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Manager::Private
|
class Manager::Private : public QObject
|
||||||
{
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
private:
|
||||||
std::unique_ptr< QNetworkAccessManager > m_nam;
|
std::unique_ptr< QNetworkAccessManager > m_nam;
|
||||||
|
|
||||||
|
using ThreadNam = QPair< QThread*, QNetworkAccessManager* >;
|
||||||
|
QVector< ThreadNam > m_perThreadNams;
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void cleanupNam();
|
||||||
|
|
||||||
|
public:
|
||||||
QUrl m_hasInternetUrl;
|
QUrl m_hasInternetUrl;
|
||||||
bool m_hasInternet;
|
bool m_hasInternet;
|
||||||
|
|
||||||
Private();
|
Private();
|
||||||
|
|
||||||
|
QNetworkAccessManager* nam();
|
||||||
};
|
};
|
||||||
|
|
||||||
Manager::Private::Private()
|
Manager::Private::Private()
|
||||||
: m_nam( std::make_unique< QNetworkAccessManager >() )
|
: m_nam( std::make_unique< QNetworkAccessManager >() )
|
||||||
, m_hasInternet( false )
|
, m_hasInternet( false )
|
||||||
{
|
{
|
||||||
|
m_perThreadNams.reserve( 20 );
|
||||||
|
m_perThreadNams.append( qMakePair( QThread::currentThread(), m_nam.get() ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static QMutex*
|
||||||
|
namMutex()
|
||||||
|
{
|
||||||
|
static QMutex namMutex;
|
||||||
|
return &namMutex;
|
||||||
|
}
|
||||||
|
|
||||||
|
QNetworkAccessManager*
|
||||||
|
Manager::Private::nam()
|
||||||
|
{
|
||||||
|
QMutexLocker lock( namMutex() );
|
||||||
|
|
||||||
|
auto* thread = QThread::currentThread();
|
||||||
|
int index = 0;
|
||||||
|
for ( const auto& n : m_perThreadNams )
|
||||||
|
{
|
||||||
|
if ( n.first == thread )
|
||||||
|
{
|
||||||
|
return n.second;
|
||||||
|
}
|
||||||
|
++index;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Need a new NAM for this thread
|
||||||
|
QNetworkAccessManager* nam = new QNetworkAccessManager();
|
||||||
|
m_perThreadNams.append( qMakePair( thread, nam ) );
|
||||||
|
QObject::connect( thread, &QThread::finished, this, &Manager::Private::cleanupNam );
|
||||||
|
|
||||||
|
return nam;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
Manager::Private::cleanupNam()
|
||||||
|
{
|
||||||
|
QMutexLocker lock( namMutex() );
|
||||||
|
|
||||||
|
auto* thread = QThread::currentThread();
|
||||||
|
bool cleanupFound = false;
|
||||||
|
int cleanupIndex = 0;
|
||||||
|
for ( const auto& n : m_perThreadNams )
|
||||||
|
{
|
||||||
|
if ( n.first == thread )
|
||||||
|
{
|
||||||
|
cleanupFound = true;
|
||||||
|
delete n.second;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
++cleanupIndex;
|
||||||
|
}
|
||||||
|
if ( cleanupFound )
|
||||||
|
{
|
||||||
|
m_perThreadNams.remove( cleanupIndex );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Manager::Manager()
|
Manager::Manager()
|
||||||
: d( std::make_unique< Private >() )
|
: d( std::make_unique< Private >() )
|
||||||
{
|
{
|
||||||
@ -83,9 +158,9 @@ Manager::hasInternet()
|
|||||||
bool
|
bool
|
||||||
Manager::checkHasInternet()
|
Manager::checkHasInternet()
|
||||||
{
|
{
|
||||||
bool hasInternet = d->m_nam->networkAccessible() == QNetworkAccessManager::Accessible;
|
bool hasInternet = d->nam()->networkAccessible() == QNetworkAccessManager::Accessible;
|
||||||
|
|
||||||
if ( !hasInternet && ( d->m_nam->networkAccessible() == QNetworkAccessManager::UnknownAccessibility ) )
|
if ( !hasInternet && ( d->nam()->networkAccessible() == QNetworkAccessManager::UnknownAccessibility ) )
|
||||||
{
|
{
|
||||||
hasInternet = synchronousPing( d->m_hasInternetUrl );
|
hasInternet = synchronousPing( d->m_hasInternetUrl );
|
||||||
}
|
}
|
||||||
@ -108,9 +183,11 @@ Manager::setCheckHasInternetUrl( const QUrl& url )
|
|||||||
* On failure, returns nullptr (e.g. bad URL, timeout).
|
* On failure, returns nullptr (e.g. bad URL, timeout).
|
||||||
*/
|
*/
|
||||||
static QNetworkReply*
|
static QNetworkReply*
|
||||||
asynchronousRun( const std::unique_ptr< QNetworkAccessManager >& nam, const QUrl& url, const RequestOptions& options )
|
asynchronousRun( QNetworkAccessManager* nam, const QUrl& url, const RequestOptions& options )
|
||||||
{
|
{
|
||||||
QNetworkRequest request = QNetworkRequest( url );
|
QNetworkRequest request = QNetworkRequest( url );
|
||||||
|
options.applyToRequest( &request );
|
||||||
|
|
||||||
QNetworkReply* reply = nam->get( request );
|
QNetworkReply* reply = nam->get( request );
|
||||||
QTimer* timer = nullptr;
|
QTimer* timer = nullptr;
|
||||||
|
|
||||||
@ -121,7 +198,6 @@ asynchronousRun( const std::unique_ptr< QNetworkAccessManager >& nam, const QUrl
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
options.applyToRequest( &request );
|
|
||||||
if ( options.hasTimeout() )
|
if ( options.hasTimeout() )
|
||||||
{
|
{
|
||||||
timer = new QTimer( reply );
|
timer = new QTimer( reply );
|
||||||
@ -142,12 +218,12 @@ asynchronousRun( const std::unique_ptr< QNetworkAccessManager >& nam, const QUrl
|
|||||||
* is marked for later automatic deletion, so don't store the pointer.
|
* is marked for later automatic deletion, so don't store the pointer.
|
||||||
*/
|
*/
|
||||||
static QPair< RequestStatus, QNetworkReply* >
|
static QPair< RequestStatus, QNetworkReply* >
|
||||||
synchronousRun( const std::unique_ptr< QNetworkAccessManager >& nam, const QUrl& url, const RequestOptions& options )
|
synchronousRun( QNetworkAccessManager* nam, const QUrl& url, const RequestOptions& options )
|
||||||
{
|
{
|
||||||
auto* reply = asynchronousRun( nam, url, options );
|
auto* reply = asynchronousRun( nam, url, options );
|
||||||
if ( !reply )
|
if ( !reply )
|
||||||
{
|
{
|
||||||
return qMakePair( RequestStatus( RequestStatus::Failed ), nullptr );
|
return qMakePair( RequestStatus( RequestStatus::Failed ), nullptr );
|
||||||
}
|
}
|
||||||
|
|
||||||
QEventLoop loop;
|
QEventLoop loop;
|
||||||
@ -176,7 +252,7 @@ Manager::synchronousPing( const QUrl& url, const RequestOptions& options )
|
|||||||
return RequestStatus::Failed;
|
return RequestStatus::Failed;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto reply = synchronousRun( d->m_nam, url, options );
|
auto reply = synchronousRun( d->nam(), url, options );
|
||||||
if ( reply.first )
|
if ( reply.first )
|
||||||
{
|
{
|
||||||
return reply.second->bytesAvailable() ? RequestStatus::Ok : RequestStatus::Empty;
|
return reply.second->bytesAvailable() ? RequestStatus::Ok : RequestStatus::Empty;
|
||||||
@ -195,16 +271,18 @@ Manager::synchronousGet( const QUrl& url, const RequestOptions& options )
|
|||||||
return QByteArray();
|
return QByteArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
auto reply = synchronousRun( d->m_nam, url, options );
|
auto reply = synchronousRun( d->nam(), url, options );
|
||||||
return reply.first ? reply.second->readAll() : QByteArray();
|
return reply.first ? reply.second->readAll() : QByteArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
QNetworkReply*
|
QNetworkReply*
|
||||||
Manager::asynchronouseGet( const QUrl& url, const CalamaresUtils::Network::RequestOptions& options )
|
Manager::asynchronouseGet( const QUrl& url, const CalamaresUtils::Network::RequestOptions& options )
|
||||||
{
|
{
|
||||||
return asynchronousRun( d->m_nam, url, options );
|
return asynchronousRun( d->nam(), url, options );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
} // namespace Network
|
} // namespace Network
|
||||||
} // namespace CalamaresUtils
|
} // namespace CalamaresUtils
|
||||||
|
|
||||||
|
#include "Manager.moc"
|
||||||
|
@ -25,9 +25,7 @@
|
|||||||
#include <QListWidget>
|
#include <QListWidget>
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
|
|
||||||
LCLocaleDialog::LCLocaleDialog( const QString& guessedLCLocale,
|
LCLocaleDialog::LCLocaleDialog( const QString& guessedLCLocale, const QStringList& localeGenLines, QWidget* parent )
|
||||||
const QStringList& localeGenLines,
|
|
||||||
QWidget* parent )
|
|
||||||
: QDialog( parent )
|
: QDialog( parent )
|
||||||
{
|
{
|
||||||
setModal( true );
|
setModal( true );
|
||||||
@ -41,7 +39,7 @@ LCLocaleDialog::LCLocaleDialog( const QString& guessedLCLocale,
|
|||||||
upperText->setText( tr( "The system locale setting affects the language and character "
|
upperText->setText( tr( "The system locale setting affects the language and character "
|
||||||
"set for some command line user interface elements.<br/>"
|
"set for some command line user interface elements.<br/>"
|
||||||
"The current setting is <strong>%1</strong>." )
|
"The current setting is <strong>%1</strong>." )
|
||||||
.arg( guessedLCLocale ) );
|
.arg( guessedLCLocale ) );
|
||||||
mainLayout->addWidget( upperText );
|
mainLayout->addWidget( upperText );
|
||||||
setMinimumWidth( upperText->fontMetrics().height() * 24 );
|
setMinimumWidth( upperText->fontMetrics().height() * 24 );
|
||||||
|
|
||||||
@ -60,33 +58,32 @@ LCLocaleDialog::LCLocaleDialog( const QString& guessedLCLocale,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QDialogButtonBox* dbb = new QDialogButtonBox( QDialogButtonBox::Ok | QDialogButtonBox::Cancel,
|
QDialogButtonBox* dbb
|
||||||
Qt::Horizontal,
|
= new QDialogButtonBox( QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, this );
|
||||||
this );
|
|
||||||
dbb->button( QDialogButtonBox::Cancel )->setText( tr( "&Cancel" ) );
|
dbb->button( QDialogButtonBox::Cancel )->setText( tr( "&Cancel" ) );
|
||||||
dbb->button( QDialogButtonBox::Ok )->setText( tr( "&OK" ) );
|
dbb->button( QDialogButtonBox::Ok )->setText( tr( "&OK" ) );
|
||||||
|
|
||||||
mainLayout->addWidget( dbb );
|
mainLayout->addWidget( dbb );
|
||||||
|
|
||||||
connect( dbb->button( QDialogButtonBox::Ok ), &QPushButton::clicked,
|
connect( dbb->button( QDialogButtonBox::Ok ), &QPushButton::clicked, this, &QDialog::accept );
|
||||||
this, &QDialog::accept );
|
connect( dbb->button( QDialogButtonBox::Cancel ), &QPushButton::clicked, this, &QDialog::reject );
|
||||||
connect( dbb->button( QDialogButtonBox::Cancel ), &QPushButton::clicked,
|
|
||||||
this, &QDialog::reject );
|
|
||||||
|
|
||||||
connect( m_localesWidget, &QListWidget::itemDoubleClicked,
|
connect( m_localesWidget, &QListWidget::itemDoubleClicked, this, &QDialog::accept );
|
||||||
this, &QDialog::accept );
|
connect( m_localesWidget, &QListWidget::itemSelectionChanged, [this, dbb]() {
|
||||||
connect( m_localesWidget, &QListWidget::itemSelectionChanged,
|
|
||||||
[this, dbb]()
|
|
||||||
{
|
|
||||||
if ( m_localesWidget->selectedItems().isEmpty() )
|
if ( m_localesWidget->selectedItems().isEmpty() )
|
||||||
|
{
|
||||||
dbb->button( QDialogButtonBox::Ok )->setEnabled( false );
|
dbb->button( QDialogButtonBox::Ok )->setEnabled( false );
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
dbb->button( QDialogButtonBox::Ok )->setEnabled( true );
|
dbb->button( QDialogButtonBox::Ok )->setEnabled( true );
|
||||||
|
}
|
||||||
} );
|
} );
|
||||||
|
|
||||||
if ( selected > -1 )
|
if ( selected > -1 )
|
||||||
|
{
|
||||||
m_localesWidget->setCurrentRow( selected );
|
m_localesWidget->setCurrentRow( selected );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -37,4 +37,4 @@ private:
|
|||||||
QListWidget* m_localesWidget;
|
QListWidget* m_localesWidget;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // LCLOCALEDIALOG_H
|
#endif // LCLOCALEDIALOG_H
|
||||||
|
@ -30,16 +30,15 @@ LocaleConfiguration::LocaleConfiguration()
|
|||||||
LocaleConfiguration::LocaleConfiguration( const QString& localeName, const QString& formatsName )
|
LocaleConfiguration::LocaleConfiguration( const QString& localeName, const QString& formatsName )
|
||||||
: LocaleConfiguration()
|
: LocaleConfiguration()
|
||||||
{
|
{
|
||||||
lc_numeric = lc_time = lc_monetary = lc_paper = lc_name
|
lc_numeric = lc_time = lc_monetary = lc_paper = lc_name = lc_address = lc_telephone = lc_measurement
|
||||||
= lc_address = lc_telephone = lc_measurement
|
= lc_identification = formatsName;
|
||||||
= lc_identification = formatsName;
|
|
||||||
|
|
||||||
(void) setLanguage( localeName );
|
(void)setLanguage( localeName );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
LocaleConfiguration::setLanguage(const QString& localeName )
|
LocaleConfiguration::setLanguage( const QString& localeName )
|
||||||
{
|
{
|
||||||
QString language = localeName.split( '_' ).first();
|
QString language = localeName.split( '_' ).first();
|
||||||
m_languageLocaleBcp47 = QLocale( language ).bcp47Name().toLower();
|
m_languageLocaleBcp47 = QLocale( language ).bcp47Name().toLower();
|
||||||
@ -55,30 +54,39 @@ LocaleConfiguration::fromLanguageAndLocation( const QString& languageLocale,
|
|||||||
QString language = languageLocale.split( '_' ).first();
|
QString language = languageLocale.split( '_' ).first();
|
||||||
|
|
||||||
QStringList linesForLanguage;
|
QStringList linesForLanguage;
|
||||||
for ( const QString &line : availableLocales )
|
for ( const QString& line : availableLocales )
|
||||||
{
|
{
|
||||||
if ( line.startsWith( language ) )
|
if ( line.startsWith( language ) )
|
||||||
|
{
|
||||||
linesForLanguage.append( line );
|
linesForLanguage.append( line );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QString lang;
|
QString lang;
|
||||||
if ( linesForLanguage.length() == 0 || languageLocale.isEmpty() )
|
if ( linesForLanguage.length() == 0 || languageLocale.isEmpty() )
|
||||||
|
{
|
||||||
lang = "en_US.UTF-8";
|
lang = "en_US.UTF-8";
|
||||||
|
}
|
||||||
else if ( linesForLanguage.length() == 1 )
|
else if ( linesForLanguage.length() == 1 )
|
||||||
|
{
|
||||||
lang = linesForLanguage.first();
|
lang = linesForLanguage.first();
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
QStringList linesForLanguageUtf;
|
QStringList linesForLanguageUtf;
|
||||||
// FIXME: this might be useless if we already filter out non-UTF8 locales
|
// FIXME: this might be useless if we already filter out non-UTF8 locales
|
||||||
foreach ( QString line, linesForLanguage )
|
foreach ( QString line, linesForLanguage )
|
||||||
{
|
{
|
||||||
if ( line.contains( "UTF-8", Qt::CaseInsensitive ) ||
|
if ( line.contains( "UTF-8", Qt::CaseInsensitive ) || line.contains( "utf8", Qt::CaseInsensitive ) )
|
||||||
line.contains( "utf8", Qt::CaseInsensitive ) )
|
{
|
||||||
linesForLanguageUtf.append( line );
|
linesForLanguageUtf.append( line );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( linesForLanguageUtf.length() == 1 )
|
if ( linesForLanguageUtf.length() == 1 )
|
||||||
|
{
|
||||||
lang = linesForLanguageUtf.first();
|
lang = linesForLanguageUtf.first();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// lang could still be empty if we found multiple locales that satisfy myLanguage
|
// lang could still be empty if we found multiple locales that satisfy myLanguage
|
||||||
@ -92,8 +100,7 @@ LocaleConfiguration::fromLanguageAndLocation( const QString& languageLocale,
|
|||||||
# locale categories reflect the selected location. */
|
# locale categories reflect the selected location. */
|
||||||
if ( language == "pt" || language == "zh" )
|
if ( language == "pt" || language == "zh" )
|
||||||
{
|
{
|
||||||
QString proposedLocale = QString( "%1_%2" ).arg( language )
|
QString proposedLocale = QString( "%1_%2" ).arg( language ).arg( countryCode );
|
||||||
.arg( countryCode );
|
|
||||||
foreach ( QString line, linesForLanguage )
|
foreach ( QString line, linesForLanguage )
|
||||||
{
|
{
|
||||||
if ( line.contains( proposedLocale ) )
|
if ( line.contains( proposedLocale ) )
|
||||||
@ -108,7 +115,7 @@ LocaleConfiguration::fromLanguageAndLocation( const QString& languageLocale,
|
|||||||
// language locale and pick the first result, if any.
|
// language locale and pick the first result, if any.
|
||||||
if ( lang.isEmpty() )
|
if ( lang.isEmpty() )
|
||||||
{
|
{
|
||||||
for ( const QString &line : availableLocales )
|
for ( const QString& line : availableLocales )
|
||||||
{
|
{
|
||||||
if ( line.startsWith( languageLocale ) )
|
if ( line.startsWith( languageLocale ) )
|
||||||
{
|
{
|
||||||
@ -116,13 +123,14 @@ LocaleConfiguration::fromLanguageAndLocation( const QString& languageLocale,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Else we have an unrecognized or unsupported locale, all we can do is go with
|
// Else we have an unrecognized or unsupported locale, all we can do is go with
|
||||||
// en_US.UTF-8 UTF-8. This completes all default language setting guesswork.
|
// en_US.UTF-8 UTF-8. This completes all default language setting guesswork.
|
||||||
if ( lang.isEmpty() )
|
if ( lang.isEmpty() )
|
||||||
|
{
|
||||||
lang = "en_US.UTF-8";
|
lang = "en_US.UTF-8";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// The following block was inspired by Ubiquity, scripts/localechooser-apply.
|
// The following block was inspired by Ubiquity, scripts/localechooser-apply.
|
||||||
@ -171,10 +179,9 @@ LocaleConfiguration::fromLanguageAndLocation( const QString& languageLocale,
|
|||||||
// We make a proposed locale based on the UI language and the timezone's country. There is no
|
// We make a proposed locale based on the UI language and the timezone's country. There is no
|
||||||
// guarantee that this will be a valid, supported locale (often it won't).
|
// guarantee that this will be a valid, supported locale (often it won't).
|
||||||
QString lc_formats;
|
QString lc_formats;
|
||||||
QString combined = QString( "%1_%2" ).arg( language )
|
QString combined = QString( "%1_%2" ).arg( language ).arg( countryCode );
|
||||||
.arg( countryCode );
|
|
||||||
// We look up if it's a supported locale.
|
// We look up if it's a supported locale.
|
||||||
for ( const QString &line : availableLocales )
|
for ( const QString& line : availableLocales )
|
||||||
{
|
{
|
||||||
if ( line.startsWith( combined ) )
|
if ( line.startsWith( combined ) )
|
||||||
{
|
{
|
||||||
@ -187,7 +194,7 @@ LocaleConfiguration::fromLanguageAndLocation( const QString& languageLocale,
|
|||||||
if ( lc_formats.isEmpty() )
|
if ( lc_formats.isEmpty() )
|
||||||
{
|
{
|
||||||
QStringList available;
|
QStringList available;
|
||||||
for ( const QString &line : availableLocales )
|
for ( const QString& line : availableLocales )
|
||||||
{
|
{
|
||||||
if ( line.contains( QString( "_%1" ).arg( countryCode ) ) )
|
if ( line.contains( QString( "_%1" ).arg( countryCode ) ) )
|
||||||
{
|
{
|
||||||
@ -248,11 +255,10 @@ LocaleConfiguration::fromLanguageAndLocation( const QString& languageLocale,
|
|||||||
};
|
};
|
||||||
if ( countryToDefaultLanguage.contains( countryCode ) )
|
if ( countryToDefaultLanguage.contains( countryCode ) )
|
||||||
{
|
{
|
||||||
QString combinedLocale =
|
QString combinedLocale
|
||||||
QString( "%1_%2" ).arg( countryToDefaultLanguage.value( countryCode ) )
|
= QString( "%1_%2" ).arg( countryToDefaultLanguage.value( countryCode ) ).arg( countryCode );
|
||||||
.arg( countryCode );
|
|
||||||
|
|
||||||
for ( const QString &line : availableLocales )
|
for ( const QString& line : availableLocales )
|
||||||
{
|
{
|
||||||
if ( line.startsWith( combinedLocale ) )
|
if ( line.startsWith( combinedLocale ) )
|
||||||
{
|
{
|
||||||
@ -267,7 +273,9 @@ LocaleConfiguration::fromLanguageAndLocation( const QString& languageLocale,
|
|||||||
// If we cannot make a good choice for a given country we go with the LANG
|
// If we cannot make a good choice for a given country we go with the LANG
|
||||||
// setting, which defaults to en_US.UTF-8 UTF-8 if all else fails.
|
// setting, which defaults to en_US.UTF-8 UTF-8 if all else fails.
|
||||||
if ( lc_formats.isEmpty() )
|
if ( lc_formats.isEmpty() )
|
||||||
|
{
|
||||||
lc_formats = lang;
|
lc_formats = lang;
|
||||||
|
}
|
||||||
|
|
||||||
return LocaleConfiguration( lang, lc_formats );
|
return LocaleConfiguration( lang, lc_formats );
|
||||||
}
|
}
|
||||||
@ -276,54 +284,36 @@ LocaleConfiguration::fromLanguageAndLocation( const QString& languageLocale,
|
|||||||
bool
|
bool
|
||||||
LocaleConfiguration::isEmpty() const
|
LocaleConfiguration::isEmpty() const
|
||||||
{
|
{
|
||||||
return m_lang.isEmpty() &&
|
return m_lang.isEmpty() && lc_numeric.isEmpty() && lc_time.isEmpty() && lc_monetary.isEmpty() && lc_paper.isEmpty()
|
||||||
lc_numeric.isEmpty() &&
|
&& lc_name.isEmpty() && lc_address.isEmpty() && lc_telephone.isEmpty() && lc_measurement.isEmpty()
|
||||||
lc_time.isEmpty() &&
|
&& lc_identification.isEmpty();
|
||||||
lc_monetary.isEmpty() &&
|
|
||||||
lc_paper.isEmpty() &&
|
|
||||||
lc_name.isEmpty() &&
|
|
||||||
lc_address.isEmpty() &&
|
|
||||||
lc_telephone.isEmpty() &&
|
|
||||||
lc_measurement.isEmpty() &&
|
|
||||||
lc_identification.isEmpty();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// @brief Sets @p value on @p key in the @p map if @p value is non-empty
|
||||||
|
static inline void
|
||||||
|
add_lc( QMap< QString, QString >& map, const char* key, const QString& value )
|
||||||
|
{
|
||||||
|
if ( !value.isEmpty() )
|
||||||
|
{
|
||||||
|
map.insert( key, value );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
QMap< QString, QString >
|
QMap< QString, QString >
|
||||||
LocaleConfiguration::toMap() const
|
LocaleConfiguration::toMap() const
|
||||||
{
|
{
|
||||||
QMap< QString, QString > map;
|
QMap< QString, QString > map;
|
||||||
|
|
||||||
if ( !m_lang.isEmpty() )
|
add_lc( map, "LANG", m_lang );
|
||||||
map.insert( "LANG", m_lang );
|
add_lc( map, "LC_NUMERIC", lc_numeric );
|
||||||
|
add_lc( map, "LC_TIME", lc_time );
|
||||||
if ( !lc_numeric.isEmpty() )
|
add_lc( map, "LC_MONETARY", lc_monetary );
|
||||||
map.insert( "LC_NUMERIC", lc_numeric );
|
add_lc( map, "LC_PAPER", lc_paper );
|
||||||
|
add_lc( map, "LC_NAME", lc_name );
|
||||||
if ( !lc_time.isEmpty() )
|
add_lc( map, "LC_ADDRESS", lc_address );
|
||||||
map.insert( "LC_TIME", lc_time );
|
add_lc( map, "LC_TELEPHONE", lc_telephone );
|
||||||
|
add_lc( map, "LC_MEASUREMENT", lc_measurement );
|
||||||
if ( !lc_monetary.isEmpty() )
|
add_lc( map, "LC_IDENTIFICATION", lc_identification );
|
||||||
map.insert( "LC_MONETARY", lc_monetary );
|
|
||||||
|
|
||||||
if ( !lc_paper.isEmpty() )
|
|
||||||
map.insert( "LC_PAPER", lc_paper );
|
|
||||||
|
|
||||||
if ( !lc_name.isEmpty() )
|
|
||||||
map.insert( "LC_NAME", lc_name );
|
|
||||||
|
|
||||||
if ( !lc_address.isEmpty() )
|
|
||||||
map.insert( "LC_ADDRESS", lc_address );
|
|
||||||
|
|
||||||
if ( !lc_telephone.isEmpty() )
|
|
||||||
map.insert( "LC_TELEPHONE", lc_telephone );
|
|
||||||
|
|
||||||
if ( !lc_measurement.isEmpty() )
|
|
||||||
map.insert( "LC_MEASUREMENT", lc_measurement );
|
|
||||||
|
|
||||||
if ( !lc_identification.isEmpty() )
|
|
||||||
map.insert( "LC_IDENTIFICATION", lc_identification );
|
|
||||||
|
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,8 +21,8 @@
|
|||||||
#define LOCALECONFIGURATION_H
|
#define LOCALECONFIGURATION_H
|
||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QString>
|
|
||||||
#include <QMap>
|
#include <QMap>
|
||||||
|
#include <QString>
|
||||||
|
|
||||||
class LocaleConfiguration
|
class LocaleConfiguration
|
||||||
{
|
{
|
||||||
@ -31,13 +31,14 @@ public:
|
|||||||
explicit LocaleConfiguration();
|
explicit LocaleConfiguration();
|
||||||
/// @brief Create a locale with everything set to the given @p localeName
|
/// @brief Create a locale with everything set to the given @p localeName
|
||||||
explicit LocaleConfiguration( const QString& localeName /* "en_US.UTF-8" */ )
|
explicit LocaleConfiguration( const QString& localeName /* "en_US.UTF-8" */ )
|
||||||
: LocaleConfiguration( localeName, localeName ) { }
|
: LocaleConfiguration( localeName, localeName )
|
||||||
|
{
|
||||||
|
}
|
||||||
/// @brief Create a locale with language and formats separate
|
/// @brief Create a locale with language and formats separate
|
||||||
explicit LocaleConfiguration( const QString& localeName, const QString& formatsName );
|
explicit LocaleConfiguration( const QString& localeName, const QString& formatsName );
|
||||||
|
|
||||||
static LocaleConfiguration fromLanguageAndLocation( const QString& language,
|
static LocaleConfiguration
|
||||||
const QStringList& availableLocales,
|
fromLanguageAndLocation( const QString& language, const QStringList& availableLocales, const QString& countryCode );
|
||||||
const QString& countryCode );
|
|
||||||
|
|
||||||
bool isEmpty() const;
|
bool isEmpty() const;
|
||||||
|
|
||||||
@ -55,8 +56,8 @@ public:
|
|||||||
|
|
||||||
// These become all uppercase in locale.conf, but we keep them lowercase here to
|
// These become all uppercase in locale.conf, but we keep them lowercase here to
|
||||||
// avoid confusion with locale.h.
|
// avoid confusion with locale.h.
|
||||||
QString lc_numeric, lc_time, lc_monetary, lc_paper, lc_name, lc_address,
|
QString lc_numeric, lc_time, lc_monetary, lc_paper, lc_name, lc_address, lc_telephone, lc_measurement,
|
||||||
lc_telephone, lc_measurement, lc_identification;
|
lc_identification;
|
||||||
|
|
||||||
// If the user has explicitly selected language (from the dialog)
|
// If the user has explicitly selected language (from the dialog)
|
||||||
// or numbers format, set these to avoid implicit changes to them.
|
// or numbers format, set these to avoid implicit changes to them.
|
||||||
@ -67,9 +68,10 @@ private:
|
|||||||
QString m_languageLocaleBcp47;
|
QString m_languageLocaleBcp47;
|
||||||
};
|
};
|
||||||
|
|
||||||
inline QDebug& operator <<( QDebug& s, const LocaleConfiguration& l )
|
inline QDebug&
|
||||||
|
operator<<( QDebug& s, const LocaleConfiguration& l )
|
||||||
{
|
{
|
||||||
return s << l.language() << '(' << l.toBcp47() << ") +" << l.lc_numeric;
|
return s << l.language() << '(' << l.toBcp47() << ") +" << l.lc_numeric;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // LOCALECONFIGURATION_H
|
#endif // LOCALECONFIGURATION_H
|
||||||
|
@ -35,8 +35,8 @@
|
|||||||
#include <QBoxLayout>
|
#include <QBoxLayout>
|
||||||
#include <QComboBox>
|
#include <QComboBox>
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
#include <QPushButton>
|
|
||||||
#include <QProcess>
|
#include <QProcess>
|
||||||
|
#include <QPushButton>
|
||||||
|
|
||||||
LocalePage::LocalePage( QWidget* parent )
|
LocalePage::LocalePage( QWidget* parent )
|
||||||
: QWidget( parent )
|
: QWidget( parent )
|
||||||
@ -99,154 +99,49 @@ LocalePage::LocalePage( QWidget* parent )
|
|||||||
|
|
||||||
setLayout( mainLayout );
|
setLayout( mainLayout );
|
||||||
|
|
||||||
connect( m_regionCombo,
|
connect( m_regionCombo, QOverload< int >::of( &QComboBox::currentIndexChanged ), this, &LocalePage::regionChanged );
|
||||||
static_cast< void ( QComboBox::* )( int ) >( &QComboBox::currentIndexChanged ),
|
connect( m_zoneCombo, QOverload< int >::of( &QComboBox::currentIndexChanged ), this, &LocalePage::zoneChanged );
|
||||||
[this]( int currentIndex )
|
connect( m_tzWidget, &TimeZoneWidget::locationChanged, this, &LocalePage::locationChanged );
|
||||||
{
|
connect( m_localeChangeButton, &QPushButton::clicked, this, &LocalePage::changeLocale );
|
||||||
Q_UNUSED( currentIndex )
|
connect( m_formatsChangeButton, &QPushButton::clicked, this, &LocalePage::changeFormats );
|
||||||
QHash< QString, QList< LocaleGlobal::Location > > regions = LocaleGlobal::getLocations();
|
|
||||||
if ( !regions.contains( m_regionCombo->currentData().toString() ) )
|
|
||||||
return;
|
|
||||||
|
|
||||||
m_zoneCombo->blockSignals( true );
|
CALAMARES_RETRANSLATE_SLOT( &LocalePage::updateLocaleLabels )
|
||||||
|
|
||||||
m_zoneCombo->clear();
|
|
||||||
|
|
||||||
const QList< LocaleGlobal::Location > zones = regions.value( m_regionCombo->currentData().toString() );
|
|
||||||
for ( const LocaleGlobal::Location& zone : zones )
|
|
||||||
{
|
|
||||||
m_zoneCombo->addItem( LocaleGlobal::Location::pretty( zone.zone ), zone.zone );
|
|
||||||
}
|
|
||||||
|
|
||||||
m_zoneCombo->model()->sort( 0 );
|
|
||||||
|
|
||||||
m_zoneCombo->blockSignals( false );
|
|
||||||
|
|
||||||
m_zoneCombo->currentIndexChanged( m_zoneCombo->currentIndex() );
|
|
||||||
} );
|
|
||||||
|
|
||||||
connect( m_zoneCombo,
|
|
||||||
static_cast< void ( QComboBox::* )( int ) >( &QComboBox::currentIndexChanged ),
|
|
||||||
[this]( int currentIndex )
|
|
||||||
{
|
|
||||||
Q_UNUSED( currentIndex )
|
|
||||||
if ( !m_blockTzWidgetSet )
|
|
||||||
m_tzWidget->setCurrentLocation( m_regionCombo->currentData().toString(),
|
|
||||||
m_zoneCombo->currentData().toString() );
|
|
||||||
|
|
||||||
updateGlobalStorage();
|
|
||||||
} );
|
|
||||||
|
|
||||||
connect( m_tzWidget, &TimeZoneWidget::locationChanged,
|
|
||||||
[this]( LocaleGlobal::Location location )
|
|
||||||
{
|
|
||||||
m_blockTzWidgetSet = true;
|
|
||||||
|
|
||||||
// Set region index
|
|
||||||
int index = m_regionCombo->findData( location.region );
|
|
||||||
if ( index < 0 )
|
|
||||||
return;
|
|
||||||
|
|
||||||
m_regionCombo->setCurrentIndex( index );
|
|
||||||
|
|
||||||
// Set zone index
|
|
||||||
index = m_zoneCombo->findData( location.zone );
|
|
||||||
if ( index < 0 )
|
|
||||||
return;
|
|
||||||
|
|
||||||
m_zoneCombo->setCurrentIndex( index );
|
|
||||||
|
|
||||||
m_blockTzWidgetSet = false;
|
|
||||||
|
|
||||||
updateGlobalStorage();
|
|
||||||
} );
|
|
||||||
|
|
||||||
connect( m_localeChangeButton, &QPushButton::clicked,
|
|
||||||
[this]
|
|
||||||
{
|
|
||||||
LCLocaleDialog* dlg =
|
|
||||||
new LCLocaleDialog( m_selectedLocaleConfiguration.isEmpty() ?
|
|
||||||
guessLocaleConfiguration().language() :
|
|
||||||
m_selectedLocaleConfiguration.language(),
|
|
||||||
m_localeGenLines,
|
|
||||||
this );
|
|
||||||
dlg->exec();
|
|
||||||
if ( dlg->result() == QDialog::Accepted &&
|
|
||||||
!dlg->selectedLCLocale().isEmpty() )
|
|
||||||
{
|
|
||||||
m_selectedLocaleConfiguration.setLanguage( dlg->selectedLCLocale() );
|
|
||||||
m_selectedLocaleConfiguration.explicit_lang = true;
|
|
||||||
this->updateGlobalLocale();
|
|
||||||
this->updateLocaleLabels();
|
|
||||||
}
|
|
||||||
|
|
||||||
dlg->deleteLater();
|
|
||||||
} );
|
|
||||||
|
|
||||||
connect( m_formatsChangeButton, &QPushButton::clicked,
|
|
||||||
[this]
|
|
||||||
{
|
|
||||||
LCLocaleDialog* dlg =
|
|
||||||
new LCLocaleDialog( m_selectedLocaleConfiguration.isEmpty() ?
|
|
||||||
guessLocaleConfiguration().lc_numeric :
|
|
||||||
m_selectedLocaleConfiguration.lc_numeric,
|
|
||||||
m_localeGenLines,
|
|
||||||
this );
|
|
||||||
dlg->exec();
|
|
||||||
if ( dlg->result() == QDialog::Accepted &&
|
|
||||||
!dlg->selectedLCLocale().isEmpty() )
|
|
||||||
{
|
|
||||||
// TODO: improve the granularity of this setting.
|
|
||||||
m_selectedLocaleConfiguration.lc_numeric = dlg->selectedLCLocale();
|
|
||||||
m_selectedLocaleConfiguration.lc_time = dlg->selectedLCLocale();
|
|
||||||
m_selectedLocaleConfiguration.lc_monetary = dlg->selectedLCLocale();
|
|
||||||
m_selectedLocaleConfiguration.lc_paper = dlg->selectedLCLocale();
|
|
||||||
m_selectedLocaleConfiguration.lc_name = dlg->selectedLCLocale();
|
|
||||||
m_selectedLocaleConfiguration.lc_address = dlg->selectedLCLocale();
|
|
||||||
m_selectedLocaleConfiguration.lc_telephone = dlg->selectedLCLocale();
|
|
||||||
m_selectedLocaleConfiguration.lc_measurement = dlg->selectedLCLocale();
|
|
||||||
m_selectedLocaleConfiguration.lc_identification = dlg->selectedLCLocale();
|
|
||||||
m_selectedLocaleConfiguration.explicit_lc = true;
|
|
||||||
|
|
||||||
this->updateLocaleLabels();
|
|
||||||
}
|
|
||||||
|
|
||||||
dlg->deleteLater();
|
|
||||||
|
|
||||||
} );
|
|
||||||
|
|
||||||
CALAMARES_RETRANSLATE(
|
|
||||||
m_regionLabel->setText( tr( "Region:" ) );
|
|
||||||
m_zoneLabel->setText( tr( "Zone:" ) );
|
|
||||||
|
|
||||||
updateLocaleLabels();
|
|
||||||
|
|
||||||
m_localeChangeButton->setText( tr( "&Change..." ) );
|
|
||||||
m_formatsChangeButton->setText( tr( "&Change..." ) );
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
LocalePage::~LocalePage()
|
LocalePage::~LocalePage() {}
|
||||||
{}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
LocalePage::updateLocaleLabels()
|
LocalePage::updateLocaleLabels()
|
||||||
{
|
{
|
||||||
LocaleConfiguration lc = m_selectedLocaleConfiguration.isEmpty() ?
|
m_regionLabel->setText( tr( "Region:" ) );
|
||||||
guessLocaleConfiguration() :
|
m_zoneLabel->setText( tr( "Zone:" ) );
|
||||||
m_selectedLocaleConfiguration;
|
m_localeChangeButton->setText( tr( "&Change..." ) );
|
||||||
|
m_formatsChangeButton->setText( tr( "&Change..." ) );
|
||||||
|
|
||||||
|
LocaleConfiguration lc
|
||||||
|
= m_selectedLocaleConfiguration.isEmpty() ? guessLocaleConfiguration() : m_selectedLocaleConfiguration;
|
||||||
auto labels = prettyLocaleStatus( lc );
|
auto labels = prettyLocaleStatus( lc );
|
||||||
m_localeLabel->setText( labels.first );
|
m_localeLabel->setText( labels.first );
|
||||||
m_formatsLabel->setText( labels.second );
|
m_formatsLabel->setText( labels.second );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline bool
|
||||||
|
containsLocation( const QList< LocaleGlobal::Location >& locations, const QString& zone )
|
||||||
|
{
|
||||||
|
for ( const LocaleGlobal::Location& location : locations )
|
||||||
|
{
|
||||||
|
if ( location.zone == zone )
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
LocalePage::init( const QString& initialRegion,
|
LocalePage::init( const QString& initialRegion, const QString& initialZone, const QString& localeGenPath )
|
||||||
const QString& initialZone,
|
|
||||||
const QString& localeGenPath )
|
|
||||||
{
|
{
|
||||||
m_regionCombo->blockSignals( true );
|
m_regionCombo->blockSignals( true );
|
||||||
m_zoneCombo->blockSignals( true );
|
m_zoneCombo->blockSignals( true );
|
||||||
@ -267,20 +162,7 @@ LocalePage::init( const QString& initialRegion,
|
|||||||
|
|
||||||
m_regionCombo->currentIndexChanged( m_regionCombo->currentIndex() );
|
m_regionCombo->currentIndexChanged( m_regionCombo->currentIndex() );
|
||||||
|
|
||||||
// Default location
|
if ( keys.contains( initialRegion ) && containsLocation( regions.value( initialRegion ), initialZone ) )
|
||||||
auto containsLocation = []( const QList< LocaleGlobal::Location >& locations,
|
|
||||||
const QString& zone ) -> bool
|
|
||||||
{
|
|
||||||
for ( const LocaleGlobal::Location& location : locations )
|
|
||||||
{
|
|
||||||
if ( location.zone == zone )
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
};
|
|
||||||
|
|
||||||
if ( keys.contains( initialRegion ) &&
|
|
||||||
containsLocation( regions.value( initialRegion ), initialZone ) )
|
|
||||||
{
|
{
|
||||||
m_tzWidget->setCurrentLocation( initialRegion, initialZone );
|
m_tzWidget->setCurrentLocation( initialRegion, initialZone );
|
||||||
}
|
}
|
||||||
@ -298,14 +180,13 @@ LocalePage::init( const QString& initialRegion,
|
|||||||
QFile supported( "/usr/share/i18n/SUPPORTED" );
|
QFile supported( "/usr/share/i18n/SUPPORTED" );
|
||||||
QByteArray ba;
|
QByteArray ba;
|
||||||
|
|
||||||
if ( supported.exists() &&
|
if ( supported.exists() && supported.open( QIODevice::ReadOnly | QIODevice::Text ) )
|
||||||
supported.open( QIODevice::ReadOnly | QIODevice::Text ) )
|
|
||||||
{
|
{
|
||||||
ba = supported.readAll();
|
ba = supported.readAll();
|
||||||
supported.close();
|
supported.close();
|
||||||
|
|
||||||
const auto lines = ba.split( '\n' );
|
const auto lines = ba.split( '\n' );
|
||||||
for ( const QByteArray &line : lines )
|
for ( const QByteArray& line : lines )
|
||||||
{
|
{
|
||||||
m_localeGenLines.append( QString::fromLatin1( line.simplified() ) );
|
m_localeGenLines.append( QString::fromLatin1( line.simplified() ) );
|
||||||
}
|
}
|
||||||
@ -321,28 +202,32 @@ LocalePage::init( const QString& initialRegion,
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
cWarning() << "Cannot open file" << localeGenPath
|
cWarning() << "Cannot open file" << localeGenPath
|
||||||
<< ". Assuming the supported languages are already built into "
|
<< ". Assuming the supported languages are already built into "
|
||||||
"the locale archive.";
|
"the locale archive.";
|
||||||
QProcess localeA;
|
QProcess localeA;
|
||||||
localeA.start( "locale", QStringList() << "-a" );
|
localeA.start( "locale", QStringList() << "-a" );
|
||||||
localeA.waitForFinished();
|
localeA.waitForFinished();
|
||||||
ba = localeA.readAllStandardOutput();
|
ba = localeA.readAllStandardOutput();
|
||||||
}
|
}
|
||||||
const auto lines = ba.split( '\n' );
|
const auto lines = ba.split( '\n' );
|
||||||
for ( const QByteArray &line : lines )
|
for ( const QByteArray& line : lines )
|
||||||
{
|
{
|
||||||
if ( line.startsWith( "## " ) ||
|
if ( line.startsWith( "## " ) || line.startsWith( "# " ) || line.simplified() == "#" )
|
||||||
line.startsWith( "# " ) ||
|
{
|
||||||
line.simplified() == "#" )
|
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
QString lineString = QString::fromLatin1( line.simplified() );
|
QString lineString = QString::fromLatin1( line.simplified() );
|
||||||
if ( lineString.startsWith( "#" ) )
|
if ( lineString.startsWith( "#" ) )
|
||||||
|
{
|
||||||
lineString.remove( '#' );
|
lineString.remove( '#' );
|
||||||
|
}
|
||||||
lineString = lineString.simplified();
|
lineString = lineString.simplified();
|
||||||
|
|
||||||
if ( lineString.isEmpty() )
|
if ( lineString.isEmpty() )
|
||||||
|
{
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
m_localeGenLines.append( lineString );
|
m_localeGenLines.append( lineString );
|
||||||
}
|
}
|
||||||
@ -351,41 +236,44 @@ LocalePage::init( const QString& initialRegion,
|
|||||||
if ( m_localeGenLines.isEmpty() )
|
if ( m_localeGenLines.isEmpty() )
|
||||||
{
|
{
|
||||||
cWarning() << "cannot acquire a list of available locales."
|
cWarning() << "cannot acquire a list of available locales."
|
||||||
<< "The locale and localecfg modules will be broken as long as this "
|
<< "The locale and localecfg modules will be broken as long as this "
|
||||||
"system does not provide"
|
"system does not provide"
|
||||||
<< "\n\t "
|
<< "\n\t "
|
||||||
<< "* a well-formed"
|
<< "* a well-formed" << supported.fileName() << "\n\tOR"
|
||||||
<< supported.fileName()
|
<< "* a well-formed"
|
||||||
<< "\n\tOR"
|
<< ( localeGenPath.isEmpty() ? QLatin1Literal( "/etc/locale.gen" ) : localeGenPath ) << "\n\tOR"
|
||||||
<< "* a well-formed"
|
<< "* a complete pre-compiled locale-gen database which allows complete locale -a output.";
|
||||||
<< (localeGenPath.isEmpty() ? QLatin1Literal("/etc/locale.gen") : localeGenPath)
|
return; // something went wrong and there's nothing we can do about it.
|
||||||
<< "\n\tOR"
|
|
||||||
<< "* a complete pre-compiled locale-gen database which allows complete locale -a output.";
|
|
||||||
return; // something went wrong and there's nothing we can do about it.
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Assuming we have a list of supported locales, we usually only want UTF-8 ones
|
// Assuming we have a list of supported locales, we usually only want UTF-8 ones
|
||||||
// because it's not 1995.
|
// because it's not 1995.
|
||||||
for ( auto it = m_localeGenLines.begin(); it != m_localeGenLines.end(); )
|
for ( auto it = m_localeGenLines.begin(); it != m_localeGenLines.end(); )
|
||||||
{
|
{
|
||||||
if ( !it->contains( "UTF-8", Qt::CaseInsensitive ) &&
|
if ( !it->contains( "UTF-8", Qt::CaseInsensitive ) && !it->contains( "utf8", Qt::CaseInsensitive ) )
|
||||||
!it->contains( "utf8", Qt::CaseInsensitive ) )
|
{
|
||||||
it = m_localeGenLines.erase( it );
|
it = m_localeGenLines.erase( it );
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
++it;
|
++it;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// We strip " UTF-8" from "en_US.UTF-8 UTF-8" because it's redundant redundant.
|
// We strip " UTF-8" from "en_US.UTF-8 UTF-8" because it's redundant redundant.
|
||||||
for ( auto it = m_localeGenLines.begin(); it != m_localeGenLines.end(); ++it )
|
for ( auto it = m_localeGenLines.begin(); it != m_localeGenLines.end(); ++it )
|
||||||
{
|
{
|
||||||
if ( it->endsWith( " UTF-8" ) )
|
if ( it->endsWith( " UTF-8" ) )
|
||||||
|
{
|
||||||
it->chop( 6 );
|
it->chop( 6 );
|
||||||
|
}
|
||||||
*it = it->simplified();
|
*it = it->simplified();
|
||||||
}
|
}
|
||||||
updateGlobalStorage();
|
updateGlobalStorage();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::pair< QString, QString > LocalePage::prettyLocaleStatus( const LocaleConfiguration& lc ) const
|
std::pair< QString, QString >
|
||||||
|
LocalePage::prettyLocaleStatus( const LocaleConfiguration& lc ) const
|
||||||
{
|
{
|
||||||
using CalamaresUtils::Locale::Label;
|
using CalamaresUtils::Locale::Label;
|
||||||
|
|
||||||
@ -401,14 +289,11 @@ QString
|
|||||||
LocalePage::prettyStatus() const
|
LocalePage::prettyStatus() const
|
||||||
{
|
{
|
||||||
QString status;
|
QString status;
|
||||||
status += tr( "Set timezone to %1/%2.<br/>" )
|
status += tr( "Set timezone to %1/%2.<br/>" ).arg( m_regionCombo->currentText() ).arg( m_zoneCombo->currentText() );
|
||||||
.arg( m_regionCombo->currentText() )
|
|
||||||
.arg( m_zoneCombo->currentText() );
|
|
||||||
|
|
||||||
LocaleConfiguration lc = m_selectedLocaleConfiguration.isEmpty() ?
|
LocaleConfiguration lc
|
||||||
guessLocaleConfiguration() :
|
= m_selectedLocaleConfiguration.isEmpty() ? guessLocaleConfiguration() : m_selectedLocaleConfiguration;
|
||||||
m_selectedLocaleConfiguration;
|
auto labels = prettyLocaleStatus( lc );
|
||||||
auto labels = prettyLocaleStatus(lc);
|
|
||||||
status += labels.first + "<br/>";
|
status += labels.first + "<br/>";
|
||||||
status += labels.second + "<br/>";
|
status += labels.second + "<br/>";
|
||||||
|
|
||||||
@ -432,9 +317,8 @@ LocalePage::createJobs()
|
|||||||
QMap< QString, QString >
|
QMap< QString, QString >
|
||||||
LocalePage::localesMap()
|
LocalePage::localesMap()
|
||||||
{
|
{
|
||||||
return m_selectedLocaleConfiguration.isEmpty() ?
|
return m_selectedLocaleConfiguration.isEmpty() ? guessLocaleConfiguration().toMap()
|
||||||
guessLocaleConfiguration().toMap() :
|
: m_selectedLocaleConfiguration.toMap();
|
||||||
m_selectedLocaleConfiguration.toMap();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -442,8 +326,7 @@ void
|
|||||||
LocalePage::onActivate()
|
LocalePage::onActivate()
|
||||||
{
|
{
|
||||||
m_regionCombo->setFocus();
|
m_regionCombo->setFocus();
|
||||||
if ( m_selectedLocaleConfiguration.isEmpty() ||
|
if ( m_selectedLocaleConfiguration.isEmpty() || !m_selectedLocaleConfiguration.explicit_lang )
|
||||||
!m_selectedLocaleConfiguration.explicit_lang )
|
|
||||||
{
|
{
|
||||||
auto newLocale = guessLocaleConfiguration();
|
auto newLocale = guessLocaleConfiguration();
|
||||||
m_selectedLocaleConfiguration.setLanguage( newLocale.language() );
|
m_selectedLocaleConfiguration.setLanguage( newLocale.language() );
|
||||||
@ -456,16 +339,15 @@ LocalePage::onActivate()
|
|||||||
LocaleConfiguration
|
LocaleConfiguration
|
||||||
LocalePage::guessLocaleConfiguration() const
|
LocalePage::guessLocaleConfiguration() const
|
||||||
{
|
{
|
||||||
return LocaleConfiguration::fromLanguageAndLocation( QLocale().name(),
|
return LocaleConfiguration::fromLanguageAndLocation(
|
||||||
m_localeGenLines,
|
QLocale().name(), m_localeGenLines, m_tzWidget->getCurrentLocation().country );
|
||||||
m_tzWidget->getCurrentLocation().country );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
LocalePage::updateGlobalLocale()
|
LocalePage::updateGlobalLocale()
|
||||||
{
|
{
|
||||||
auto *gs = Calamares::JobQueue::instance()->globalStorage();
|
auto* gs = Calamares::JobQueue::instance()->globalStorage();
|
||||||
const QString bcp47 = m_selectedLocaleConfiguration.toBcp47();
|
const QString bcp47 = m_selectedLocaleConfiguration.toBcp47();
|
||||||
gs->insert( "locale", bcp47 );
|
gs->insert( "locale", bcp47 );
|
||||||
}
|
}
|
||||||
@ -474,11 +356,11 @@ LocalePage::updateGlobalLocale()
|
|||||||
void
|
void
|
||||||
LocalePage::updateGlobalStorage()
|
LocalePage::updateGlobalStorage()
|
||||||
{
|
{
|
||||||
auto *gs = Calamares::JobQueue::instance()->globalStorage();
|
auto* gs = Calamares::JobQueue::instance()->globalStorage();
|
||||||
|
|
||||||
LocaleGlobal::Location location = m_tzWidget->getCurrentLocation();
|
LocaleGlobal::Location location = m_tzWidget->getCurrentLocation();
|
||||||
bool locationChanged = ( location.region != gs->value( "locationRegion" ) ) ||
|
bool locationChanged
|
||||||
( location.zone != gs->value( "locationZone" ) );
|
= ( location.region != gs->value( "locationRegion" ) ) || ( location.zone != gs->value( "locationZone" ) );
|
||||||
|
|
||||||
gs->insert( "locationRegion", location.region );
|
gs->insert( "locationRegion", location.region );
|
||||||
gs->insert( "locationZone", location.zone );
|
gs->insert( "locationZone", location.zone );
|
||||||
@ -491,18 +373,17 @@ LocalePage::updateGlobalStorage()
|
|||||||
if ( locationChanged && Calamares::Settings::instance()->doChroot() )
|
if ( locationChanged && Calamares::Settings::instance()->doChroot() )
|
||||||
{
|
{
|
||||||
QProcess::execute( "timedatectl", // depends on systemd
|
QProcess::execute( "timedatectl", // depends on systemd
|
||||||
{ "set-timezone",
|
{ "set-timezone", location.region + '/' + location.zone } );
|
||||||
location.region + '/' + location.zone } );
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Preserve those settings that have been made explicit.
|
// Preserve those settings that have been made explicit.
|
||||||
auto newLocale = guessLocaleConfiguration();
|
auto newLocale = guessLocaleConfiguration();
|
||||||
if ( !m_selectedLocaleConfiguration.isEmpty() &&
|
if ( !m_selectedLocaleConfiguration.isEmpty() && m_selectedLocaleConfiguration.explicit_lang )
|
||||||
m_selectedLocaleConfiguration.explicit_lang )
|
{
|
||||||
newLocale.setLanguage( m_selectedLocaleConfiguration.language() );
|
newLocale.setLanguage( m_selectedLocaleConfiguration.language() );
|
||||||
if ( !m_selectedLocaleConfiguration.isEmpty() &&
|
}
|
||||||
m_selectedLocaleConfiguration.explicit_lc )
|
if ( !m_selectedLocaleConfiguration.isEmpty() && m_selectedLocaleConfiguration.explicit_lc )
|
||||||
{
|
{
|
||||||
newLocale.lc_numeric = m_selectedLocaleConfiguration.lc_numeric;
|
newLocale.lc_numeric = m_selectedLocaleConfiguration.lc_numeric;
|
||||||
newLocale.lc_time = m_selectedLocaleConfiguration.lc_time;
|
newLocale.lc_time = m_selectedLocaleConfiguration.lc_time;
|
||||||
@ -520,3 +401,120 @@ LocalePage::updateGlobalStorage()
|
|||||||
m_selectedLocaleConfiguration = newLocale;
|
m_selectedLocaleConfiguration = newLocale;
|
||||||
updateLocaleLabels();
|
updateLocaleLabels();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
LocalePage::regionChanged( int currentIndex )
|
||||||
|
{
|
||||||
|
Q_UNUSED( currentIndex )
|
||||||
|
QHash< QString, QList< LocaleGlobal::Location > > regions = LocaleGlobal::getLocations();
|
||||||
|
if ( !regions.contains( m_regionCombo->currentData().toString() ) )
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_zoneCombo->blockSignals( true );
|
||||||
|
|
||||||
|
m_zoneCombo->clear();
|
||||||
|
|
||||||
|
const QList< LocaleGlobal::Location > zones = regions.value( m_regionCombo->currentData().toString() );
|
||||||
|
for ( const LocaleGlobal::Location& zone : zones )
|
||||||
|
{
|
||||||
|
m_zoneCombo->addItem( LocaleGlobal::Location::pretty( zone.zone ), zone.zone );
|
||||||
|
}
|
||||||
|
|
||||||
|
m_zoneCombo->model()->sort( 0 );
|
||||||
|
|
||||||
|
m_zoneCombo->blockSignals( false );
|
||||||
|
|
||||||
|
m_zoneCombo->currentIndexChanged( m_zoneCombo->currentIndex() );
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
LocalePage::zoneChanged( int currentIndex )
|
||||||
|
{
|
||||||
|
Q_UNUSED( currentIndex )
|
||||||
|
if ( !m_blockTzWidgetSet )
|
||||||
|
m_tzWidget->setCurrentLocation( m_regionCombo->currentData().toString(),
|
||||||
|
m_zoneCombo->currentData().toString() );
|
||||||
|
|
||||||
|
updateGlobalStorage();
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
LocalePage::locationChanged( LocaleGlobal::Location location )
|
||||||
|
{
|
||||||
|
m_blockTzWidgetSet = true;
|
||||||
|
|
||||||
|
// Set region index
|
||||||
|
int index = m_regionCombo->findData( location.region );
|
||||||
|
if ( index < 0 )
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_regionCombo->setCurrentIndex( index );
|
||||||
|
|
||||||
|
// Set zone index
|
||||||
|
index = m_zoneCombo->findData( location.zone );
|
||||||
|
if ( index < 0 )
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_zoneCombo->setCurrentIndex( index );
|
||||||
|
|
||||||
|
m_blockTzWidgetSet = false;
|
||||||
|
|
||||||
|
updateGlobalStorage();
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
LocalePage::changeLocale()
|
||||||
|
{
|
||||||
|
LCLocaleDialog* dlg
|
||||||
|
= new LCLocaleDialog( m_selectedLocaleConfiguration.isEmpty() ? guessLocaleConfiguration().language()
|
||||||
|
: m_selectedLocaleConfiguration.language(),
|
||||||
|
m_localeGenLines,
|
||||||
|
this );
|
||||||
|
dlg->exec();
|
||||||
|
if ( dlg->result() == QDialog::Accepted && !dlg->selectedLCLocale().isEmpty() )
|
||||||
|
{
|
||||||
|
m_selectedLocaleConfiguration.setLanguage( dlg->selectedLCLocale() );
|
||||||
|
m_selectedLocaleConfiguration.explicit_lang = true;
|
||||||
|
this->updateGlobalLocale();
|
||||||
|
this->updateLocaleLabels();
|
||||||
|
}
|
||||||
|
|
||||||
|
dlg->deleteLater();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
LocalePage::changeFormats()
|
||||||
|
{
|
||||||
|
LCLocaleDialog* dlg
|
||||||
|
= new LCLocaleDialog( m_selectedLocaleConfiguration.isEmpty() ? guessLocaleConfiguration().lc_numeric
|
||||||
|
: m_selectedLocaleConfiguration.lc_numeric,
|
||||||
|
m_localeGenLines,
|
||||||
|
this );
|
||||||
|
dlg->exec();
|
||||||
|
if ( dlg->result() == QDialog::Accepted && !dlg->selectedLCLocale().isEmpty() )
|
||||||
|
{
|
||||||
|
// TODO: improve the granularity of this setting.
|
||||||
|
m_selectedLocaleConfiguration.lc_numeric = dlg->selectedLCLocale();
|
||||||
|
m_selectedLocaleConfiguration.lc_time = dlg->selectedLCLocale();
|
||||||
|
m_selectedLocaleConfiguration.lc_monetary = dlg->selectedLCLocale();
|
||||||
|
m_selectedLocaleConfiguration.lc_paper = dlg->selectedLCLocale();
|
||||||
|
m_selectedLocaleConfiguration.lc_name = dlg->selectedLCLocale();
|
||||||
|
m_selectedLocaleConfiguration.lc_address = dlg->selectedLCLocale();
|
||||||
|
m_selectedLocaleConfiguration.lc_telephone = dlg->selectedLCLocale();
|
||||||
|
m_selectedLocaleConfiguration.lc_measurement = dlg->selectedLCLocale();
|
||||||
|
m_selectedLocaleConfiguration.lc_identification = dlg->selectedLCLocale();
|
||||||
|
m_selectedLocaleConfiguration.explicit_lc = true;
|
||||||
|
|
||||||
|
this->updateLocaleLabels();
|
||||||
|
}
|
||||||
|
|
||||||
|
dlg->deleteLater();
|
||||||
|
}
|
||||||
|
@ -21,6 +21,8 @@
|
|||||||
#define LOCALEPAGE_H
|
#define LOCALEPAGE_H
|
||||||
|
|
||||||
#include "LocaleConfiguration.h"
|
#include "LocaleConfiguration.h"
|
||||||
|
#include "timezonewidget/localeglobal.h"
|
||||||
|
|
||||||
#include "Job.h"
|
#include "Job.h"
|
||||||
|
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
@ -37,9 +39,7 @@ public:
|
|||||||
explicit LocalePage( QWidget* parent = nullptr );
|
explicit LocalePage( QWidget* parent = nullptr );
|
||||||
virtual ~LocalePage();
|
virtual ~LocalePage();
|
||||||
|
|
||||||
void init( const QString& initialRegion,
|
void init( const QString& initialRegion, const QString& initialZone, const QString& localeGenPath );
|
||||||
const QString& initialZone,
|
|
||||||
const QString& localeGenPath );
|
|
||||||
|
|
||||||
QString prettyStatus() const;
|
QString prettyStatus() const;
|
||||||
|
|
||||||
@ -65,6 +65,12 @@ private:
|
|||||||
void updateGlobalStorage();
|
void updateGlobalStorage();
|
||||||
void updateLocaleLabels();
|
void updateLocaleLabels();
|
||||||
|
|
||||||
|
void regionChanged( int currentIndex );
|
||||||
|
void zoneChanged( int currentIndex );
|
||||||
|
void locationChanged( LocaleGlobal::Location location );
|
||||||
|
void changeLocale();
|
||||||
|
void changeFormats();
|
||||||
|
|
||||||
TimeZoneWidget* m_tzWidget;
|
TimeZoneWidget* m_tzWidget;
|
||||||
QComboBox* m_regionCombo;
|
QComboBox* m_regionCombo;
|
||||||
QComboBox* m_zoneCombo;
|
QComboBox* m_zoneCombo;
|
||||||
@ -83,4 +89,4 @@ private:
|
|||||||
bool m_blockTzWidgetSet;
|
bool m_blockTzWidgetSet;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // LOCALEPAGE_H
|
#endif // LOCALEPAGE_H
|
||||||
|
@ -27,7 +27,7 @@
|
|||||||
#include "JobQueue.h"
|
#include "JobQueue.h"
|
||||||
|
|
||||||
#include "geoip/Handler.h"
|
#include "geoip/Handler.h"
|
||||||
|
#include "network/Manager.h"
|
||||||
#include "utils/CalamaresUtilsGui.h"
|
#include "utils/CalamaresUtilsGui.h"
|
||||||
#include "utils/Logger.h"
|
#include "utils/Logger.h"
|
||||||
#include "utils/Variant.h"
|
#include "utils/Variant.h"
|
||||||
@ -38,51 +38,19 @@
|
|||||||
#include <QtConcurrent/QtConcurrentRun>
|
#include <QtConcurrent/QtConcurrentRun>
|
||||||
|
|
||||||
|
|
||||||
CALAMARES_PLUGIN_FACTORY_DEFINITION( LocaleViewStepFactory, registerPlugin<LocaleViewStep>(); )
|
CALAMARES_PLUGIN_FACTORY_DEFINITION( LocaleViewStepFactory, registerPlugin< LocaleViewStep >(); )
|
||||||
|
|
||||||
LocaleViewStep::LocaleViewStep( QObject* parent )
|
LocaleViewStep::LocaleViewStep( QObject* parent )
|
||||||
: Calamares::ViewStep( parent )
|
: Calamares::ViewStep( parent )
|
||||||
, m_widget( new QWidget() )
|
, m_widget( new QWidget() )
|
||||||
, m_actualWidget( new LocalePage() )
|
, m_actualWidget( nullptr )
|
||||||
, m_nextEnabled( false )
|
, m_nextEnabled( false )
|
||||||
|
, m_geoip( nullptr )
|
||||||
{
|
{
|
||||||
QBoxLayout* mainLayout = new QHBoxLayout;
|
QBoxLayout* mainLayout = new QHBoxLayout;
|
||||||
m_widget->setLayout( mainLayout );
|
m_widget->setLayout( mainLayout );
|
||||||
CalamaresUtils::unmarginLayout( mainLayout );
|
CalamaresUtils::unmarginLayout( mainLayout );
|
||||||
|
|
||||||
m_waitingWidget = new WaitingWidget( tr( "Loading location data..." ) );
|
|
||||||
mainLayout->addWidget( m_waitingWidget );
|
|
||||||
|
|
||||||
connect( &m_initWatcher, &QFutureWatcher< void >::finished,
|
|
||||||
this, [=]
|
|
||||||
{
|
|
||||||
bool hasInternet = Calamares::JobQueue::instance()->globalStorage()
|
|
||||||
->value( "hasInternet" ).toBool();
|
|
||||||
if ( m_geoipUrl.isEmpty() || !hasInternet )
|
|
||||||
setUpPage();
|
|
||||||
else
|
|
||||||
fetchGeoIpTimezone();
|
|
||||||
});
|
|
||||||
|
|
||||||
QFuture< void > initFuture = QtConcurrent::run( [=]
|
|
||||||
{
|
|
||||||
LocaleGlobal::init();
|
|
||||||
if ( m_geoipUrl.isEmpty() )
|
|
||||||
return;
|
|
||||||
|
|
||||||
Calamares::GlobalStorage* gs = Calamares::JobQueue::instance()->globalStorage();
|
|
||||||
|
|
||||||
// Max 10sec wait for RequirementsChecker to finish, assuming the welcome
|
|
||||||
// module is used.
|
|
||||||
// If welcome is not used, either "hasInternet" should be set by other means,
|
|
||||||
// or the GeoIP feature should be disabled.
|
|
||||||
for ( int i = 0; i < 10; ++i )
|
|
||||||
if ( !gs->contains( "hasInternet" ) )
|
|
||||||
QThread::sleep( 1 );
|
|
||||||
} );
|
|
||||||
|
|
||||||
m_initWatcher.setFuture( initFuture );
|
|
||||||
|
|
||||||
emit nextStatusChanged( m_nextEnabled );
|
emit nextStatusChanged( m_nextEnabled );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -90,19 +58,22 @@ LocaleViewStep::LocaleViewStep( QObject* parent )
|
|||||||
LocaleViewStep::~LocaleViewStep()
|
LocaleViewStep::~LocaleViewStep()
|
||||||
{
|
{
|
||||||
if ( m_widget && m_widget->parent() == nullptr )
|
if ( m_widget && m_widget->parent() == nullptr )
|
||||||
|
{
|
||||||
m_widget->deleteLater();
|
m_widget->deleteLater();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
LocaleViewStep::setUpPage()
|
LocaleViewStep::setUpPage()
|
||||||
{
|
{
|
||||||
m_actualWidget->init( m_startingTimezone.first,
|
if ( !m_actualWidget )
|
||||||
m_startingTimezone.second,
|
{
|
||||||
m_localeGenPath );
|
m_actualWidget = new LocalePage();
|
||||||
m_widget->layout()->removeWidget( m_waitingWidget );
|
}
|
||||||
m_waitingWidget->deleteLater();
|
m_actualWidget->init( m_startingTimezone.first, m_startingTimezone.second, m_localeGenPath );
|
||||||
m_widget->layout()->addWidget( m_actualWidget );
|
m_widget->layout()->addWidget( m_actualWidget );
|
||||||
|
|
||||||
m_nextEnabled = true;
|
m_nextEnabled = true;
|
||||||
emit nextStatusChanged( m_nextEnabled );
|
emit nextStatusChanged( m_nextEnabled );
|
||||||
}
|
}
|
||||||
@ -111,16 +82,14 @@ LocaleViewStep::setUpPage()
|
|||||||
void
|
void
|
||||||
LocaleViewStep::fetchGeoIpTimezone()
|
LocaleViewStep::fetchGeoIpTimezone()
|
||||||
{
|
{
|
||||||
CalamaresUtils::GeoIP::Handler h( m_geoipStyle, m_geoipUrl, m_geoipSelector );
|
if ( m_geoip && m_geoip->isValid() )
|
||||||
if ( h.isValid() )
|
|
||||||
{
|
{
|
||||||
m_startingTimezone = h.get();
|
m_startingTimezone = m_geoip->get();
|
||||||
if ( !m_startingTimezone.isValid() )
|
if ( !m_startingTimezone.isValid() )
|
||||||
cWarning() << "GeoIP lookup at" << m_geoipUrl << "failed.";
|
{
|
||||||
|
cWarning() << "GeoIP lookup at" << m_geoip->url() << "failed.";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
cWarning() << "GeoIP Style" << m_geoipStyle << "is not recognized.";
|
|
||||||
setUpPage();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -183,6 +152,10 @@ LocaleViewStep::jobs() const
|
|||||||
void
|
void
|
||||||
LocaleViewStep::onActivate()
|
LocaleViewStep::onActivate()
|
||||||
{
|
{
|
||||||
|
if ( !m_actualWidget )
|
||||||
|
{
|
||||||
|
setUpPage();
|
||||||
|
}
|
||||||
m_actualWidget->onActivate();
|
m_actualWidget->onActivate();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -191,17 +164,26 @@ void
|
|||||||
LocaleViewStep::onLeave()
|
LocaleViewStep::onLeave()
|
||||||
{
|
{
|
||||||
m_jobs.clear();
|
m_jobs.clear();
|
||||||
m_jobs.append( m_actualWidget->createJobs() );
|
|
||||||
|
|
||||||
m_prettyStatus = m_actualWidget->prettyStatus();
|
if ( m_actualWidget )
|
||||||
|
{
|
||||||
|
m_jobs.append( m_actualWidget->createJobs() );
|
||||||
|
|
||||||
auto map = m_actualWidget->localesMap();
|
m_prettyStatus = m_actualWidget->prettyStatus();
|
||||||
QVariantMap vm;
|
|
||||||
for ( auto it = map.constBegin(); it != map.constEnd(); ++it )
|
|
||||||
vm.insert( it.key(), it.value() );
|
|
||||||
|
|
||||||
Calamares::JobQueue::instance()->globalStorage()
|
auto map = m_actualWidget->localesMap();
|
||||||
->insert( "localeConf", vm );
|
QVariantMap vm;
|
||||||
|
for ( auto it = map.constBegin(); it != map.constEnd(); ++it )
|
||||||
|
{
|
||||||
|
vm.insert( it.key(), it.value() );
|
||||||
|
}
|
||||||
|
|
||||||
|
Calamares::JobQueue::instance()->globalStorage()->insert( "localeConf", vm );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Calamares::JobQueue::instance()->globalStorage()->remove( "localeConf" );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -216,35 +198,51 @@ LocaleViewStep::setConfigurationMap( const QVariantMap& configurationMap )
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
m_startingTimezone = CalamaresUtils::GeoIP::RegionZonePair( QStringLiteral( "America" ), QStringLiteral( "New_York" ) );
|
m_startingTimezone
|
||||||
|
= CalamaresUtils::GeoIP::RegionZonePair( QStringLiteral( "America" ), QStringLiteral( "New_York" ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
m_localeGenPath = CalamaresUtils::getString( configurationMap, "localeGenPath" );
|
m_localeGenPath = CalamaresUtils::getString( configurationMap, "localeGenPath" );
|
||||||
if ( m_localeGenPath.isEmpty() )
|
if ( m_localeGenPath.isEmpty() )
|
||||||
|
{
|
||||||
m_localeGenPath = QStringLiteral( "/etc/locale.gen" );
|
m_localeGenPath = QStringLiteral( "/etc/locale.gen" );
|
||||||
|
}
|
||||||
|
|
||||||
bool ok = false;
|
bool ok = false;
|
||||||
QVariantMap geoip = CalamaresUtils::getSubMap( configurationMap, "geoip", ok );
|
QVariantMap geoip = CalamaresUtils::getSubMap( configurationMap, "geoip", ok );
|
||||||
if ( ok )
|
if ( ok )
|
||||||
{
|
{
|
||||||
m_geoipUrl = CalamaresUtils::getString( geoip, "url" );
|
QString url = CalamaresUtils::getString( geoip, "url" );
|
||||||
m_geoipStyle = CalamaresUtils::getString( geoip, "style" );
|
QString style = CalamaresUtils::getString( geoip, "style" );
|
||||||
m_geoipSelector = CalamaresUtils::getString( geoip, "selector" );
|
QString selector = CalamaresUtils::getString( geoip, "selector" );
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Accommodate deprecated geoip configuration
|
|
||||||
m_geoipUrl = CalamaresUtils::getString( configurationMap, "geoipUrl" );
|
|
||||||
m_geoipStyle = CalamaresUtils::getString( configurationMap, "geoipStyle" );
|
|
||||||
m_geoipSelector = CalamaresUtils::getString( configurationMap, "geoipSelector" );
|
|
||||||
|
|
||||||
if ( !m_geoipUrl.isEmpty() && ( m_geoipStyle.isEmpty() || m_geoipStyle == "legacy" ) )
|
m_geoip = std::make_unique< CalamaresUtils::GeoIP::Handler >( style, url, selector );
|
||||||
|
if ( !m_geoip->isValid() )
|
||||||
{
|
{
|
||||||
m_geoipStyle = "json";
|
cWarning() << "GeoIP Style" << style << "is not recognized.";
|
||||||
m_geoipUrl.append( "/json/" );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !m_geoipUrl.isEmpty() )
|
|
||||||
cWarning() << "Legacy-style GeoIP configuration is deprecated. Use geoip: map.";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Calamares::RequirementsList
|
||||||
|
LocaleViewStep::checkRequirements()
|
||||||
|
{
|
||||||
|
LocaleGlobal::init();
|
||||||
|
if ( m_geoip && m_geoip->isValid() )
|
||||||
|
{
|
||||||
|
auto& network = CalamaresUtils::Network::Manager::instance();
|
||||||
|
if ( network.hasInternet() )
|
||||||
|
{
|
||||||
|
fetchGeoIpTimezone();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if ( network.synchronousPing( m_geoip->url() ) )
|
||||||
|
{
|
||||||
|
fetchGeoIpTimezone();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return Calamares::RequirementsList();
|
||||||
|
}
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
#ifndef LOCALEVIEWSTEP_H
|
#ifndef LOCALEVIEWSTEP_H
|
||||||
#define LOCALEVIEWSTEP_H
|
#define LOCALEVIEWSTEP_H
|
||||||
|
|
||||||
|
#include "geoip/Handler.h"
|
||||||
#include "geoip/Interface.h"
|
#include "geoip/Interface.h"
|
||||||
#include "utils/PluginFactory.h"
|
#include "utils/PluginFactory.h"
|
||||||
#include "viewpages/ViewStep.h"
|
#include "viewpages/ViewStep.h"
|
||||||
@ -29,6 +30,8 @@
|
|||||||
#include <QFutureWatcher>
|
#include <QFutureWatcher>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
class LocalePage;
|
class LocalePage;
|
||||||
class WaitingWidget;
|
class WaitingWidget;
|
||||||
|
|
||||||
@ -58,14 +61,15 @@ public:
|
|||||||
|
|
||||||
void setConfigurationMap( const QVariantMap& configurationMap ) override;
|
void setConfigurationMap( const QVariantMap& configurationMap ) override;
|
||||||
|
|
||||||
|
/// @brief Do setup (returns empty list) asynchronously
|
||||||
|
virtual Calamares::RequirementsList checkRequirements();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void setUpPage();
|
void setUpPage();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void fetchGeoIpTimezone();
|
void fetchGeoIpTimezone();
|
||||||
QWidget* m_widget;
|
QWidget* m_widget;
|
||||||
QFutureWatcher< void > m_initWatcher;
|
|
||||||
WaitingWidget* m_waitingWidget;
|
|
||||||
|
|
||||||
LocalePage* m_actualWidget;
|
LocalePage* m_actualWidget;
|
||||||
bool m_nextEnabled;
|
bool m_nextEnabled;
|
||||||
@ -74,13 +78,10 @@ private:
|
|||||||
CalamaresUtils::GeoIP::RegionZonePair m_startingTimezone;
|
CalamaresUtils::GeoIP::RegionZonePair m_startingTimezone;
|
||||||
QString m_localeGenPath;
|
QString m_localeGenPath;
|
||||||
|
|
||||||
QString m_geoipUrl; // The URL, depening on style might be modified on lookup
|
|
||||||
QString m_geoipStyle; // String selecting which kind of geoip data to expect
|
|
||||||
QString m_geoipSelector; // String selecting data from the geoip lookup
|
|
||||||
|
|
||||||
QList< Calamares::job_ptr > m_jobs;
|
QList< Calamares::job_ptr > m_jobs;
|
||||||
|
std::unique_ptr< CalamaresUtils::GeoIP::Handler > m_geoip;
|
||||||
};
|
};
|
||||||
|
|
||||||
CALAMARES_PLUGIN_FACTORY_DECLARATION( LocaleViewStepFactory )
|
CALAMARES_PLUGIN_FACTORY_DECLARATION( LocaleViewStepFactory )
|
||||||
|
|
||||||
#endif // LOCALEVIEWSTEP_H
|
#endif // LOCALEVIEWSTEP_H
|
||||||
|
@ -19,11 +19,11 @@
|
|||||||
|
|
||||||
#include <SetTimezoneJob.h>
|
#include <SetTimezoneJob.h>
|
||||||
|
|
||||||
#include "JobQueue.h"
|
|
||||||
#include "GlobalStorage.h"
|
#include "GlobalStorage.h"
|
||||||
|
#include "JobQueue.h"
|
||||||
#include "Settings.h"
|
#include "Settings.h"
|
||||||
#include "utils/Logger.h"
|
|
||||||
#include "utils/CalamaresUtilsSystem.h"
|
#include "utils/CalamaresUtilsSystem.h"
|
||||||
|
#include "utils/Logger.h"
|
||||||
|
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
@ -51,13 +51,13 @@ SetTimezoneJob::exec()
|
|||||||
// to a running timedated over D-Bus), and we have code that works
|
// to a running timedated over D-Bus), and we have code that works
|
||||||
if ( !Calamares::Settings::instance()->doChroot() )
|
if ( !Calamares::Settings::instance()->doChroot() )
|
||||||
{
|
{
|
||||||
int ec = CalamaresUtils::System::instance()->
|
int ec = CalamaresUtils::System::instance()->targetEnvCall(
|
||||||
targetEnvCall( { "timedatectl",
|
{ "timedatectl", "set-timezone", m_region + '/' + m_zone } );
|
||||||
"set-timezone",
|
|
||||||
m_region + '/' + m_zone } );
|
|
||||||
|
|
||||||
if ( !ec )
|
if ( !ec )
|
||||||
|
{
|
||||||
return Calamares::JobResult::ok();
|
return Calamares::JobResult::ok();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QString localtimeSlink( "/etc/localtime" );
|
QString localtimeSlink( "/etc/localtime" );
|
||||||
@ -72,31 +72,21 @@ SetTimezoneJob::exec()
|
|||||||
tr( "Bad path: %1" ).arg( zoneFile.absolutePath() ) );
|
tr( "Bad path: %1" ).arg( zoneFile.absolutePath() ) );
|
||||||
|
|
||||||
// Make sure /etc/localtime doesn't exist, otherwise symlinking will fail
|
// Make sure /etc/localtime doesn't exist, otherwise symlinking will fail
|
||||||
CalamaresUtils::System::instance()->
|
CalamaresUtils::System::instance()->targetEnvCall( { "rm", "-f", localtimeSlink } );
|
||||||
targetEnvCall( { "rm",
|
|
||||||
"-f",
|
|
||||||
localtimeSlink } );
|
|
||||||
|
|
||||||
int ec = CalamaresUtils::System::instance()->
|
int ec = CalamaresUtils::System::instance()->targetEnvCall( { "ln", "-s", zoneinfoPath, localtimeSlink } );
|
||||||
targetEnvCall( { "ln",
|
|
||||||
"-s",
|
|
||||||
zoneinfoPath,
|
|
||||||
localtimeSlink } );
|
|
||||||
if ( ec )
|
if ( ec )
|
||||||
return Calamares::JobResult::error( tr( "Cannot set timezone." ),
|
return Calamares::JobResult::error(
|
||||||
tr( "Link creation failed, target: %1; link name: %2" )
|
tr( "Cannot set timezone." ),
|
||||||
.arg( zoneinfoPath )
|
tr( "Link creation failed, target: %1; link name: %2" ).arg( zoneinfoPath ).arg( "/etc/localtime" ) );
|
||||||
.arg( "/etc/localtime" ) );
|
|
||||||
|
|
||||||
QFile timezoneFile( gs->value( "rootMountPoint" ).toString() + "/etc/timezone" );
|
QFile timezoneFile( gs->value( "rootMountPoint" ).toString() + "/etc/timezone" );
|
||||||
|
|
||||||
if ( !timezoneFile.open( QIODevice::WriteOnly |
|
if ( !timezoneFile.open( QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate ) )
|
||||||
QIODevice::Text |
|
return Calamares::JobResult::error( tr( "Cannot set timezone," ),
|
||||||
QIODevice::Truncate ) )
|
tr( "Cannot open /etc/timezone for writing" ) );
|
||||||
return Calamares::JobResult::error( tr( "Cannot set timezone,"),
|
|
||||||
tr( "Cannot open /etc/timezone for writing"));
|
|
||||||
|
|
||||||
QTextStream out(&timezoneFile);
|
QTextStream out( &timezoneFile );
|
||||||
out << m_region << '/' << m_zone << "\n";
|
out << m_region << '/' << m_zone << "\n";
|
||||||
timezoneFile.close();
|
timezoneFile.close();
|
||||||
|
|
||||||
|
@ -26,8 +26,7 @@ class SetTimezoneJob : public Calamares::Job
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
SetTimezoneJob( const QString& region,
|
SetTimezoneJob( const QString& region, const QString& zone );
|
||||||
const QString& zone );
|
|
||||||
|
|
||||||
QString prettyName() const override;
|
QString prettyName() const override;
|
||||||
Calamares::JobResult exec() override;
|
Calamares::JobResult exec() override;
|
||||||
|
@ -25,19 +25,17 @@
|
|||||||
QTEST_GUILESS_MAIN( LocaleTests )
|
QTEST_GUILESS_MAIN( LocaleTests )
|
||||||
|
|
||||||
|
|
||||||
LocaleTests::LocaleTests()
|
LocaleTests::LocaleTests() {}
|
||||||
|
|
||||||
|
LocaleTests::~LocaleTests() {}
|
||||||
|
|
||||||
|
void
|
||||||
|
LocaleTests::initTestCase()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
LocaleTests::~LocaleTests()
|
void
|
||||||
{
|
LocaleTests::testEmptyLocaleConfiguration()
|
||||||
}
|
|
||||||
|
|
||||||
void LocaleTests::initTestCase()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void LocaleTests::testEmptyLocaleConfiguration()
|
|
||||||
{
|
{
|
||||||
LocaleConfiguration lc;
|
LocaleConfiguration lc;
|
||||||
|
|
||||||
@ -45,7 +43,8 @@ void LocaleTests::testEmptyLocaleConfiguration()
|
|||||||
QCOMPARE( lc.toBcp47(), QString() );
|
QCOMPARE( lc.toBcp47(), QString() );
|
||||||
}
|
}
|
||||||
|
|
||||||
void LocaleTests::testDefaultLocaleConfiguration()
|
void
|
||||||
|
LocaleTests::testDefaultLocaleConfiguration()
|
||||||
{
|
{
|
||||||
LocaleConfiguration lc( "en_US.UTF-8" );
|
LocaleConfiguration lc( "en_US.UTF-8" );
|
||||||
QVERIFY( !lc.isEmpty() );
|
QVERIFY( !lc.isEmpty() );
|
||||||
@ -58,7 +57,8 @@ void LocaleTests::testDefaultLocaleConfiguration()
|
|||||||
QCOMPARE( lc2.toBcp47(), "de" );
|
QCOMPARE( lc2.toBcp47(), "de" );
|
||||||
}
|
}
|
||||||
|
|
||||||
void LocaleTests::testSplitLocaleConfiguration()
|
void
|
||||||
|
LocaleTests::testSplitLocaleConfiguration()
|
||||||
{
|
{
|
||||||
LocaleConfiguration lc( "en_US.UTF-8", "de_DE.UTF-8" );
|
LocaleConfiguration lc( "en_US.UTF-8", "de_DE.UTF-8" );
|
||||||
QVERIFY( !lc.isEmpty() );
|
QVERIFY( !lc.isEmpty() );
|
||||||
@ -76,5 +76,4 @@ void LocaleTests::testSplitLocaleConfiguration()
|
|||||||
QVERIFY( !lc3.isEmpty() );
|
QVERIFY( !lc3.isEmpty() );
|
||||||
QCOMPARE( lc3.toBcp47(), "da" );
|
QCOMPARE( lc3.toBcp47(), "da" );
|
||||||
QCOMPARE( lc3.lc_numeric, "de_DE.UTF-8" );
|
QCOMPARE( lc3.lc_numeric, "de_DE.UTF-8" );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user