From b1ea96e4639b916938718875ba9e52ece620fb71 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Fri, 2 Nov 2018 11:58:49 -0400 Subject: [PATCH 01/20] [partition] Don't autoremove the tempdir - Dangerout since we're mounting things inside that tempdir, and then doing a "weak" unmount --- src/modules/partition/core/PartUtils.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/modules/partition/core/PartUtils.cpp b/src/modules/partition/core/PartUtils.cpp index 12aa489db..f080d97a4 100644 --- a/src/modules/partition/core/PartUtils.cpp +++ b/src/modules/partition/core/PartUtils.cpp @@ -163,6 +163,7 @@ lookForFstabEntries( const QString& partitionPath ) { FstabEntryList fstabEntries; QTemporaryDir mountsDir; + mountsDir.setAutoRemove( false ); int exit = QProcess::execute( "mount", { partitionPath, mountsDir.path() } ); if ( !exit ) // if all is well From dc06de58d86e50aaeb3c79ddd8e0b01680fedcbe Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Thu, 3 Jan 2019 15:29:04 +0100 Subject: [PATCH 02/20] Changes: document source of fix --- CHANGES | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGES b/CHANGES index d76ca0ea6..2cedfe508 100644 --- a/CHANGES +++ b/CHANGES @@ -6,11 +6,15 @@ website will have to do for older versions. = 3.2.3 (unreleased) = This release contains contributions from (alphabetically by first name): + - aliveafter1000 == Core == == Modules == + * Fixed bug where, during detection of existing systems, the existing + system partitions may be mounted and then destroyed. + = 3.2.2 (2018-09-04) = This release contains contributions from (alphabetically by first name): From e52f0318fe8e71b83c216bdfa78d7231d4d68309 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Mon, 7 Jan 2019 15:16:37 +0100 Subject: [PATCH 03/20] [locale] Call timedatectl only when needed - When testing and running not-as-root, only call the timedatectl when the settings actually change; this reduces the number of times kauth pops up. --- src/modules/locale/LocalePage.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/modules/locale/LocalePage.cpp b/src/modules/locale/LocalePage.cpp index 9aad283c6..f9e2aa515 100644 --- a/src/modules/locale/LocalePage.cpp +++ b/src/modules/locale/LocalePage.cpp @@ -484,19 +484,22 @@ LocalePage::prettyLCLocale( const QString& lcLocale ) const void LocalePage::updateGlobalStorage() { + auto *gs = Calamares::JobQueue::instance()->globalStorage(); + LocaleGlobal::Location location = m_tzWidget->getCurrentLocation(); - Calamares::JobQueue::instance()->globalStorage() - ->insert( "locationRegion", location.region ); - Calamares::JobQueue::instance()->globalStorage() - ->insert( "locationZone", location.zone ); + bool locationChanged = ( location.region != gs->value( "locationRegion" ) ) || + ( location.zone != gs->value( "locationZone" ) ); + + gs->insert( "locationRegion", location.region ); + gs->insert( "locationZone", location.zone ); const QString bcp47 = m_selectedLocaleConfiguration.toBcp47(); - Calamares::JobQueue::instance()->globalStorage()->insert( "locale", bcp47 ); + gs->insert( "locale", bcp47 ); // If we're in chroot mode (normal install mode), then we immediately set the // timezone on the live system. When debugging timezones, don't bother. #ifndef DEBUG_TIMEZONES - if ( Calamares::Settings::instance()->doChroot() ) + if ( locationChanged && Calamares::Settings::instance()->doChroot() ) { QProcess::execute( "timedatectl", // depends on systemd { "set-timezone", From 3ff480eaa9566bba95e6beaa4e9a43d843694574 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Mon, 7 Jan 2019 17:29:54 +0100 Subject: [PATCH 04/20] [locale] Refactor to make updating global locale setting easier. --- src/modules/locale/LocalePage.cpp | 13 +++++++++++-- src/modules/locale/LocalePage.h | 6 ++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/modules/locale/LocalePage.cpp b/src/modules/locale/LocalePage.cpp index f9e2aa515..d5bd8147a 100644 --- a/src/modules/locale/LocalePage.cpp +++ b/src/modules/locale/LocalePage.cpp @@ -481,6 +481,16 @@ LocalePage::prettyLCLocale( const QString& lcLocale ) const .arg( QLocale::countryToString( locale.country() ) ); } + +void +LocalePage::updateGlobalLocale() +{ + auto *gs = Calamares::JobQueue::instance()->globalStorage(); + const QString bcp47 = m_selectedLocaleConfiguration.toBcp47(); + gs->insert( "locale", bcp47 ); +} + + void LocalePage::updateGlobalStorage() { @@ -493,8 +503,7 @@ LocalePage::updateGlobalStorage() gs->insert( "locationRegion", location.region ); gs->insert( "locationZone", location.zone ); - const QString bcp47 = m_selectedLocaleConfiguration.toBcp47(); - gs->insert( "locale", bcp47 ); + updateGlobalLocale(); // If we're in chroot mode (normal install mode), then we immediately set the // timezone on the live system. When debugging timezones, don't bother. diff --git a/src/modules/locale/LocalePage.h b/src/modules/locale/LocalePage.h index c4ca20503..4b93c690e 100644 --- a/src/modules/locale/LocalePage.h +++ b/src/modules/locale/LocalePage.h @@ -57,6 +57,12 @@ private: // the settings for language and numbers. std::pair< QString, QString > prettyLocaleStatus( const LocaleConfiguration& ) const; + /** @brief Update the GS *locale* key with the selected system language. + * + * This uses whatever is set in m_selectedLocaleConfiguration as the language, + * and writes it to GS *locale* key (as a string, in BCP47 format). + */ + void updateGlobalLocale(); void updateGlobalStorage(); void updateLocaleLabels(); From bc398756f51822b75d3fa46f9a9e795600d72565 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Mon, 7 Jan 2019 18:34:25 +0100 Subject: [PATCH 05/20] [locale] Debugging support for Location - code formatting - provide an operator << for debugging TZ widget --- src/modules/locale/timezonewidget/localeglobal.h | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/modules/locale/timezonewidget/localeglobal.h b/src/modules/locale/timezonewidget/localeglobal.h index 5452b0b09..88a8ae125 100644 --- a/src/modules/locale/timezonewidget/localeglobal.h +++ b/src/modules/locale/timezonewidget/localeglobal.h @@ -38,11 +38,13 @@ class LocaleGlobal { public: - struct Locale { + struct Locale + { QString description, locale; }; - struct Location { + struct Location + { QString region, zone, country; double latitude, longitude; static QString pretty( const QString& s ); @@ -59,7 +61,12 @@ private: static void initLocales(); static void initLocations(); - static double getRightGeoLocation(QString str); + static double getRightGeoLocation( QString str ); }; +inline QDebug& operator <<( QDebug& s, const LocaleGlobal::Location& l ) +{ + return s << l.region << '/' << l.zone << '(' << l.country << ") @N" << l.latitude << 'E' << l.longitude; +} + #endif // LOCALEGLOBAL_H From 9d871fb9dbf7e3af3589d28a945c900994203769 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Mon, 7 Jan 2019 18:49:08 +0100 Subject: [PATCH 06/20] [locale] Update global locale setting when it changes - use debugging to be a little more chatty - when changing the system language on the locale page, the global locale setting should change, too. --- src/modules/locale/LocalePage.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/modules/locale/LocalePage.cpp b/src/modules/locale/LocalePage.cpp index d5bd8147a..cfd7eb2fa 100644 --- a/src/modules/locale/LocalePage.cpp +++ b/src/modules/locale/LocalePage.cpp @@ -137,6 +137,7 @@ LocalePage::LocalePage( QWidget* parent ) connect( m_tzWidget, &TimeZoneWidget::locationChanged, [this]( LocaleGlobal::Location location ) { + cDebug() << "Updating location from TZ widget to" << location; m_blockTzWidgetSet = true; // Set region index @@ -173,6 +174,7 @@ LocalePage::LocalePage( QWidget* parent ) { m_selectedLocaleConfiguration.lang = dlg->selectedLCLocale(); m_selectedLocaleConfiguration.explicit_lang = true; + this->updateGlobalLocale(); this->updateLocaleLabels(); } @@ -441,6 +443,7 @@ LocalePage::onActivate() { auto newLocale = guessLocaleConfiguration(); m_selectedLocaleConfiguration.lang = newLocale.lang; + updateGlobalLocale(); updateLocaleLabels(); } } @@ -487,6 +490,7 @@ LocalePage::updateGlobalLocale() { auto *gs = Calamares::JobQueue::instance()->globalStorage(); const QString bcp47 = m_selectedLocaleConfiguration.toBcp47(); + cDebug() << "Updating global locale setting to" << bcp47; gs->insert( "locale", bcp47 ); } From 093240c131148dbb720c3c8a5df2a706ad54179f Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 8 Jan 2019 10:51:53 +0100 Subject: [PATCH 07/20] [libcalamares] Be less chatty in Python scripts - When finding the gettext path, the debug output was very chatty and didn't include an indication that it was looking for translations. --- src/libcalamares/PythonJobApi.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/libcalamares/PythonJobApi.cpp b/src/libcalamares/PythonJobApi.cpp index f540c2683..19670b87f 100644 --- a/src/libcalamares/PythonJobApi.cpp +++ b/src/libcalamares/PythonJobApi.cpp @@ -275,16 +275,21 @@ gettext_path() } _add_localedirs( candidatePaths, QDir().canonicalPath() ); // . - cDebug() << "Standard paths" << candidatePaths; + cDebug() << "Determining gettext path from" << candidatePaths; - for ( auto lang : _gettext_languages() ) + QStringList candidateLanguages = _gettext_languages(); + + for ( const auto& lang : candidateLanguages ) for ( auto localedir : candidatePaths ) { QDir ldir( localedir ); - cDebug() << "Checking" << lang << "in" < Date: Tue, 8 Jan 2019 11:10:16 +0100 Subject: [PATCH 08/20] [locale] Replace weird static-constructor - Replace createDefault() with a constructor that takes a locale name; use it with en_US.UTF-8 in those places where createDefault was previously used. --- src/modules/locale/LocaleConfiguration.cpp | 12 +++++------- src/modules/locale/LocaleConfiguration.h | 4 +++- src/modules/locale/LocalePage.cpp | 6 ++++-- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/modules/locale/LocaleConfiguration.cpp b/src/modules/locale/LocaleConfiguration.cpp index 7c8ad3305..f980b850c 100644 --- a/src/modules/locale/LocaleConfiguration.cpp +++ b/src/modules/locale/LocaleConfiguration.cpp @@ -27,14 +27,12 @@ LocaleConfiguration::LocaleConfiguration() } -LocaleConfiguration -LocaleConfiguration::createDefault() +LocaleConfiguration::LocaleConfiguration( const QString& localeName ) + : LocaleConfiguration() { - LocaleConfiguration lc = LocaleConfiguration(); - lc.lang = lc.lc_numeric = lc.lc_time = lc.lc_monetary = lc.lc_paper = lc.lc_name - = lc.lc_address = lc.lc_telephone = lc.lc_measurement - = lc.lc_identification = "en_US.UTF-8"; - return lc; + lang = lc_numeric = lc_time = lc_monetary = lc_paper = lc_name + = lc_address = lc_telephone = lc_measurement + = lc_identification = localeName; } diff --git a/src/modules/locale/LocaleConfiguration.h b/src/modules/locale/LocaleConfiguration.h index c077ef6f7..a4753e221 100644 --- a/src/modules/locale/LocaleConfiguration.h +++ b/src/modules/locale/LocaleConfiguration.h @@ -26,9 +26,11 @@ class LocaleConfiguration { public: + /// @brief Create an empty locale, with nothing set explicit LocaleConfiguration(); + /// @brief Create a locale with everything set to the given @p localeName + explicit LocaleConfiguration( const QString& localeName /* "en_US.UTF-8" */ ); - static LocaleConfiguration createDefault(); static LocaleConfiguration fromLanguageAndLocation( const QString& language, const QStringList& availableLocales, const QString& countryCode ); diff --git a/src/modules/locale/LocalePage.cpp b/src/modules/locale/LocalePage.cpp index cfd7eb2fa..45397b1ab 100644 --- a/src/modules/locale/LocalePage.cpp +++ b/src/modules/locale/LocalePage.cpp @@ -452,18 +452,20 @@ LocalePage::onActivate() LocaleConfiguration LocalePage::guessLocaleConfiguration() const { + static QString defaultLocale = QStringLiteral( "en_US.UTF-8" ); + QLocale myLocale; // User-selected language // If we cannot say anything about available locales if ( m_localeGenLines.isEmpty() ) { cWarning() << "guessLocaleConfiguration can't guess from an empty list."; - return LocaleConfiguration::createDefault(); + return LocaleConfiguration( defaultLocale ); } QString myLanguageLocale = myLocale.name(); if ( myLanguageLocale.isEmpty() ) - return LocaleConfiguration::createDefault(); + return LocaleConfiguration( defaultLocale ); return LocaleConfiguration::fromLanguageAndLocation( myLanguageLocale, m_localeGenLines, From b1921cced9c392d2c8afc4565005448489a5d16b Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 8 Jan 2019 11:30:49 +0100 Subject: [PATCH 09/20] [locale] Add tests for some of the data classes --- src/modules/locale/CMakeLists.txt | 11 +++++++ src/modules/locale/Tests.cpp | 53 +++++++++++++++++++++++++++++++ src/modules/locale/Tests.h | 39 +++++++++++++++++++++++ 3 files changed, 103 insertions(+) create mode 100644 src/modules/locale/Tests.cpp create mode 100644 src/modules/locale/Tests.h diff --git a/src/modules/locale/CMakeLists.txt b/src/modules/locale/CMakeLists.txt index 24259d797..e6da9db73 100644 --- a/src/modules/locale/CMakeLists.txt +++ b/src/modules/locale/CMakeLists.txt @@ -59,6 +59,17 @@ if( ECM_FOUND AND BUILD_TESTING ) ${YAMLCPP_LIBRARY} ) set_target_properties( geoiptest PROPERTIES AUTOMOC TRUE ) + + ecm_add_test( + Tests.cpp + LocaleConfiguration.cpp + TEST_NAME + localetest + LINK_LIBRARIES + calamares + Qt5::Test + ) + set_target_properties( localetest PROPERTIES AUTOMOC TRUE ) endif() if( BUILD_TESTING ) diff --git a/src/modules/locale/Tests.cpp b/src/modules/locale/Tests.cpp new file mode 100644 index 000000000..32a10e250 --- /dev/null +++ b/src/modules/locale/Tests.cpp @@ -0,0 +1,53 @@ +/* === 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 "Tests.h" +#include "LocaleConfiguration.h" + +#include + +QTEST_GUILESS_MAIN( LocaleTests ) + + +LocaleTests::LocaleTests() +{ +} + +LocaleTests::~LocaleTests() +{ +} + +void LocaleTests::initTestCase() +{ +} + +void LocaleTests::testEmptyLocaleConfiguration() +{ + LocaleConfiguration lc; + + QVERIFY( lc.isEmpty() ); + QCOMPARE( lc.toBcp47(), QString() ); +} + +void LocaleTests::testDefaultLocaleConfiguration() +{ + LocaleConfiguration lc( "en_US.UTF-8" ); + QVERIFY( !lc.isEmpty() ); + QCOMPARE( lc.toBcp47(), "en_US" ); +} diff --git a/src/modules/locale/Tests.h b/src/modules/locale/Tests.h new file mode 100644 index 000000000..acb3ab309 --- /dev/null +++ b/src/modules/locale/Tests.h @@ -0,0 +1,39 @@ +/* === 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 TESTS_H +#define TESTS_H + +#include + +class LocaleTests : public QObject +{ + Q_OBJECT +public: + LocaleTests(); + ~LocaleTests() override; + +private Q_SLOTS: + void initTestCase(); + // Check the sample config file is processed correctly + void testEmptyLocaleConfiguration(); + void testDefaultLocaleConfiguration(); +}; + +#endif From 0a526febae9cfe761cb427c285165fc1a07c8dff Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 8 Jan 2019 11:39:15 +0100 Subject: [PATCH 10/20] [locale] Refactor setting the BCP47 name and update test --- src/modules/locale/LocaleConfiguration.cpp | 17 ++++++++++++----- src/modules/locale/LocaleConfiguration.h | 8 ++++++++ src/modules/locale/Tests.cpp | 2 +- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/modules/locale/LocaleConfiguration.cpp b/src/modules/locale/LocaleConfiguration.cpp index f980b850c..ca0a707ad 100644 --- a/src/modules/locale/LocaleConfiguration.cpp +++ b/src/modules/locale/LocaleConfiguration.cpp @@ -30,9 +30,19 @@ LocaleConfiguration::LocaleConfiguration() LocaleConfiguration::LocaleConfiguration( const QString& localeName ) : LocaleConfiguration() { - lang = 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_identification = localeName; + + (void) setLanguage( localeName ); +} + +QString +LocaleConfiguration::setLanguage(const QString& localeName ) +{ + QString language = localeName.split( '_' ).first(); + myLanguageLocaleBcp47 = QLocale( language ).bcp47Name().toLower(); + return language; } @@ -42,10 +52,7 @@ LocaleConfiguration::fromLanguageAndLocation( const QString& languageLocale, const QString& countryCode ) { LocaleConfiguration lc; - - // Note that the documentation how this works is in packages.conf - QString language = languageLocale.split( '_' ).first(); - lc.myLanguageLocaleBcp47 = QLocale(language).bcp47Name().toLower(); + QString language = lc.setLanguage( languageLocale ); QStringList linesForLanguage; for ( const QString &line : availableLocales ) diff --git a/src/modules/locale/LocaleConfiguration.h b/src/modules/locale/LocaleConfiguration.h index a4753e221..95dadd5c3 100644 --- a/src/modules/locale/LocaleConfiguration.h +++ b/src/modules/locale/LocaleConfiguration.h @@ -51,6 +51,14 @@ public: bool explicit_lang, explicit_lc; private: + /** @brief sets lang and the BCP47 representation + * + * Note that the documentation how this works is in packages.conf + * + * @return The language part of the locale (e.g. before _) + */ + QString setLanguage( const QString& localeName ); + QString myLanguageLocaleBcp47; }; diff --git a/src/modules/locale/Tests.cpp b/src/modules/locale/Tests.cpp index 32a10e250..6cad2ef74 100644 --- a/src/modules/locale/Tests.cpp +++ b/src/modules/locale/Tests.cpp @@ -49,5 +49,5 @@ void LocaleTests::testDefaultLocaleConfiguration() { LocaleConfiguration lc( "en_US.UTF-8" ); QVERIFY( !lc.isEmpty() ); - QCOMPARE( lc.toBcp47(), "en_US" ); + QCOMPARE( lc.toBcp47(), "en" ); } From dbe50fe3db0ca1ba2993500ee7110fd7a8faf8bc Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 8 Jan 2019 13:23:16 +0100 Subject: [PATCH 11/20] [locale] Improve LocaleConfiguration constructors - Allow split-setting of the language and formats - Test new constructors - Since fromLanguageAndLocation can handle empty localeGen lists just fine, skip all the weird checks that return invalid guessed locale configurations. --- src/modules/locale/LocaleConfiguration.cpp | 15 +++++--------- src/modules/locale/LocaleConfiguration.h | 5 ++++- src/modules/locale/LocalePage.cpp | 17 +--------------- src/modules/locale/Tests.cpp | 23 ++++++++++++++++++++++ src/modules/locale/Tests.h | 1 + 5 files changed, 34 insertions(+), 27 deletions(-) diff --git a/src/modules/locale/LocaleConfiguration.cpp b/src/modules/locale/LocaleConfiguration.cpp index ca0a707ad..2e0689090 100644 --- a/src/modules/locale/LocaleConfiguration.cpp +++ b/src/modules/locale/LocaleConfiguration.cpp @@ -27,16 +27,17 @@ LocaleConfiguration::LocaleConfiguration() } -LocaleConfiguration::LocaleConfiguration( const QString& localeName ) +LocaleConfiguration::LocaleConfiguration( const QString& localeName, const QString& formatsName ) : LocaleConfiguration() { lc_numeric = lc_time = lc_monetary = lc_paper = lc_name = lc_address = lc_telephone = lc_measurement - = lc_identification = localeName; + = lc_identification = formatsName; (void) setLanguage( localeName ); } + QString LocaleConfiguration::setLanguage(const QString& localeName ) { @@ -51,8 +52,7 @@ LocaleConfiguration::fromLanguageAndLocation( const QString& languageLocale, const QStringList& availableLocales, const QString& countryCode ) { - LocaleConfiguration lc; - QString language = lc.setLanguage( languageLocale ); + QString language = languageLocale.split( '_' ).first(); QStringList linesForLanguage; for ( const QString &line : availableLocales ) @@ -269,12 +269,7 @@ LocaleConfiguration::fromLanguageAndLocation( const QString& languageLocale, if ( lc_formats.isEmpty() ) lc_formats = lang; - lc.lang = lang; - lc.lc_address = lc.lc_identification = lc.lc_measurement = lc.lc_monetary - = lc.lc_name = lc.lc_numeric = lc.lc_paper = lc.lc_telephone - = lc.lc_time = lc_formats; - - return lc; + return LocaleConfiguration( lang, lc_formats ); } diff --git a/src/modules/locale/LocaleConfiguration.h b/src/modules/locale/LocaleConfiguration.h index 95dadd5c3..0bd310d9d 100644 --- a/src/modules/locale/LocaleConfiguration.h +++ b/src/modules/locale/LocaleConfiguration.h @@ -29,7 +29,10 @@ public: /// @brief Create an empty locale, with nothing set explicit LocaleConfiguration(); /// @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 ) { }; + /// @brief Create a locale with language and formats separate + explicit LocaleConfiguration( const QString& localeName, const QString& formatsName ); static LocaleConfiguration fromLanguageAndLocation( const QString& language, const QStringList& availableLocales, diff --git a/src/modules/locale/LocalePage.cpp b/src/modules/locale/LocalePage.cpp index 45397b1ab..c456ef940 100644 --- a/src/modules/locale/LocalePage.cpp +++ b/src/modules/locale/LocalePage.cpp @@ -452,22 +452,7 @@ LocalePage::onActivate() LocaleConfiguration LocalePage::guessLocaleConfiguration() const { - static QString defaultLocale = QStringLiteral( "en_US.UTF-8" ); - - QLocale myLocale; // User-selected language - - // If we cannot say anything about available locales - if ( m_localeGenLines.isEmpty() ) - { - cWarning() << "guessLocaleConfiguration can't guess from an empty list."; - return LocaleConfiguration( defaultLocale ); - } - - QString myLanguageLocale = myLocale.name(); - if ( myLanguageLocale.isEmpty() ) - return LocaleConfiguration( defaultLocale ); - - return LocaleConfiguration::fromLanguageAndLocation( myLanguageLocale, + return LocaleConfiguration::fromLanguageAndLocation( QLocale().name(), m_localeGenLines, m_tzWidget->getCurrentLocation().country ); } diff --git a/src/modules/locale/Tests.cpp b/src/modules/locale/Tests.cpp index 6cad2ef74..91fea42b8 100644 --- a/src/modules/locale/Tests.cpp +++ b/src/modules/locale/Tests.cpp @@ -50,4 +50,27 @@ void LocaleTests::testDefaultLocaleConfiguration() LocaleConfiguration lc( "en_US.UTF-8" ); QVERIFY( !lc.isEmpty() ); QCOMPARE( lc.toBcp47(), "en" ); + + LocaleConfiguration lc2( "de_DE.UTF-8" ); + QVERIFY( !lc2.isEmpty() ); + QCOMPARE( lc2.toBcp47(), "de" ); +} + +void LocaleTests::testSplitLocaleConfiguration() +{ + LocaleConfiguration lc( "en_US.UTF-8", "de_DE.UTF-8" ); + QVERIFY( !lc.isEmpty() ); + QCOMPARE( lc.toBcp47(), "en" ); + QCOMPARE( lc.lc_numeric, QStringLiteral( "de_DE.UTF-8" ) ); + + LocaleConfiguration lc2( "de_DE.UTF-8", "da_DK.UTF-8" ); + QVERIFY( !lc2.isEmpty() ); + QCOMPARE( lc2.toBcp47(), "de" ); + QCOMPARE( lc2.lc_numeric, "da_DK.UTF-8" ); + + LocaleConfiguration lc3( "da_DK.UTF-8", "de_DE.UTF-8" ); + QVERIFY( !lc3.isEmpty() ); + QCOMPARE( lc3.toBcp47(), "da" ); + QCOMPARE( lc3.lc_numeric, "de_DE.UTF-8" ); + } diff --git a/src/modules/locale/Tests.h b/src/modules/locale/Tests.h index acb3ab309..299eac61d 100644 --- a/src/modules/locale/Tests.h +++ b/src/modules/locale/Tests.h @@ -34,6 +34,7 @@ private Q_SLOTS: // Check the sample config file is processed correctly void testEmptyLocaleConfiguration(); void testDefaultLocaleConfiguration(); + void testSplitLocaleConfiguration(); }; #endif From 2345b933cdb520d0a3659071734c6c4f0d89a57c Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 8 Jan 2019 13:40:20 +0100 Subject: [PATCH 12/20] [locale] Add operator << for LocaleConfiguration, for debugging --- src/modules/locale/LocaleConfiguration.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/modules/locale/LocaleConfiguration.h b/src/modules/locale/LocaleConfiguration.h index 0bd310d9d..7e835084f 100644 --- a/src/modules/locale/LocaleConfiguration.h +++ b/src/modules/locale/LocaleConfiguration.h @@ -20,6 +20,7 @@ #ifndef LOCALECONFIGURATION_H #define LOCALECONFIGURATION_H +#include #include #include @@ -65,4 +66,9 @@ private: QString myLanguageLocaleBcp47; }; +inline QDebug& operator <<( QDebug& s, const LocaleConfiguration& l ) +{ + return s << l.lang << '(' << l.toBcp47() << ") +" << l.lc_numeric; +} + #endif // LOCALECONFIGURATION_H From 8cc0e1f5f9390c6c92bdd5a32168fa2753622883 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 8 Jan 2019 14:39:40 +0100 Subject: [PATCH 13/20] [locale] Expand tests to check lang - This shows that one constructor isn't doing it right. --- src/modules/locale/Tests.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/modules/locale/Tests.cpp b/src/modules/locale/Tests.cpp index 91fea42b8..889519ca8 100644 --- a/src/modules/locale/Tests.cpp +++ b/src/modules/locale/Tests.cpp @@ -49,10 +49,12 @@ void LocaleTests::testDefaultLocaleConfiguration() { LocaleConfiguration lc( "en_US.UTF-8" ); QVERIFY( !lc.isEmpty() ); + QCOMPARE( lc.lang, "en_US.UTF-8" ); QCOMPARE( lc.toBcp47(), "en" ); LocaleConfiguration lc2( "de_DE.UTF-8" ); QVERIFY( !lc2.isEmpty() ); + QCOMPARE( lc2.lang, "de_DE.UTF-8" ); QCOMPARE( lc2.toBcp47(), "de" ); } @@ -60,11 +62,13 @@ void LocaleTests::testSplitLocaleConfiguration() { LocaleConfiguration lc( "en_US.UTF-8", "de_DE.UTF-8" ); QVERIFY( !lc.isEmpty() ); + QCOMPARE( lc.lang, "en_US.UTF-8" ); QCOMPARE( lc.toBcp47(), "en" ); QCOMPARE( lc.lc_numeric, QStringLiteral( "de_DE.UTF-8" ) ); LocaleConfiguration lc2( "de_DE.UTF-8", "da_DK.UTF-8" ); QVERIFY( !lc2.isEmpty() ); + QCOMPARE( lc2.lang, "de_DE.UTF-8" ); QCOMPARE( lc2.toBcp47(), "de" ); QCOMPARE( lc2.lc_numeric, "da_DK.UTF-8" ); From f1cbd5fcbf109ea50b96a7da35beb59e7baa2732 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 8 Jan 2019 18:09:34 +0100 Subject: [PATCH 14/20] [locale] Provide API for setting language - The language and BCP need to be in-sync - Existing code was inconsistent in setting things, which is why you could get through the locale page without setting a locale (at all) or it would keep English in spite of picking Germand on the welcome page. - Patch tests to use that API. --- src/modules/locale/LocaleConfiguration.cpp | 17 +++++--------- src/modules/locale/LocaleConfiguration.h | 27 +++++++++++----------- src/modules/locale/LocalePage.cpp | 12 +++++----- src/modules/locale/Tests.cpp | 8 +++---- 4 files changed, 30 insertions(+), 34 deletions(-) diff --git a/src/modules/locale/LocaleConfiguration.cpp b/src/modules/locale/LocaleConfiguration.cpp index 2e0689090..64d9971a7 100644 --- a/src/modules/locale/LocaleConfiguration.cpp +++ b/src/modules/locale/LocaleConfiguration.cpp @@ -38,12 +38,12 @@ LocaleConfiguration::LocaleConfiguration( const QString& localeName, const QStri } -QString +void LocaleConfiguration::setLanguage(const QString& localeName ) { QString language = localeName.split( '_' ).first(); - myLanguageLocaleBcp47 = QLocale( language ).bcp47Name().toLower(); - return language; + m_languageLocaleBcp47 = QLocale( language ).bcp47Name().toLower(); + m_lang = localeName; } @@ -276,7 +276,7 @@ LocaleConfiguration::fromLanguageAndLocation( const QString& languageLocale, bool LocaleConfiguration::isEmpty() const { - return lang.isEmpty() && + return m_lang.isEmpty() && lc_numeric.isEmpty() && lc_time.isEmpty() && lc_monetary.isEmpty() && @@ -294,8 +294,8 @@ LocaleConfiguration::toMap() const { QMap< QString, QString > map; - if ( !lang.isEmpty() ) - map.insert( "LANG", lang ); + if ( !m_lang.isEmpty() ) + map.insert( "LANG", m_lang ); if ( !lc_numeric.isEmpty() ) map.insert( "LC_NUMERIC", lc_numeric ); @@ -327,8 +327,3 @@ LocaleConfiguration::toMap() const return map; } -QString -LocaleConfiguration::toBcp47() const -{ - return myLanguageLocaleBcp47; -} diff --git a/src/modules/locale/LocaleConfiguration.h b/src/modules/locale/LocaleConfiguration.h index 7e835084f..e408d8ecb 100644 --- a/src/modules/locale/LocaleConfiguration.h +++ b/src/modules/locale/LocaleConfiguration.h @@ -41,13 +41,21 @@ public: bool isEmpty() const; - QMap< QString, QString > toMap() const; + /** @brief sets lang and the BCP47 representation + * + * Note that the documentation how this works is in packages.conf + */ + void setLanguage( const QString& localeName ); + QString language() const { return m_lang; } + // Note that the documentation how this works is in packages.conf - QString toBcp47() const; + QString toBcp47() const { return m_languageLocaleBcp47; } + + QMap< QString, QString > toMap() const; // These become all uppercase in locale.conf, but we keep them lowercase here to // avoid confusion with locale.h. - QString lang, 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_identification; // If the user has explicitly selected language (from the dialog) @@ -55,20 +63,13 @@ public: bool explicit_lang, explicit_lc; private: - /** @brief sets lang and the BCP47 representation - * - * Note that the documentation how this works is in packages.conf - * - * @return The language part of the locale (e.g. before _) - */ - QString setLanguage( const QString& localeName ); - - QString myLanguageLocaleBcp47; + QString m_lang; + QString m_languageLocaleBcp47; }; inline QDebug& operator <<( QDebug& s, const LocaleConfiguration& l ) { - return s << l.lang << '(' << l.toBcp47() << ") +" << l.lc_numeric; + return s << l.language() << '(' << l.toBcp47() << ") +" << l.lc_numeric; } #endif // LOCALECONFIGURATION_H diff --git a/src/modules/locale/LocalePage.cpp b/src/modules/locale/LocalePage.cpp index c456ef940..65d681f37 100644 --- a/src/modules/locale/LocalePage.cpp +++ b/src/modules/locale/LocalePage.cpp @@ -164,15 +164,15 @@ LocalePage::LocalePage( QWidget* parent ) { LCLocaleDialog* dlg = new LCLocaleDialog( m_selectedLocaleConfiguration.isEmpty() ? - guessLocaleConfiguration().lang : - m_selectedLocaleConfiguration.lang, + guessLocaleConfiguration().language() : + m_selectedLocaleConfiguration.language(), m_localeGenLines, this ); dlg->exec(); if ( dlg->result() == QDialog::Accepted && !dlg->selectedLCLocale().isEmpty() ) { - m_selectedLocaleConfiguration.lang = dlg->selectedLCLocale(); + m_selectedLocaleConfiguration.setLanguage( dlg->selectedLCLocale() ); m_selectedLocaleConfiguration.explicit_lang = true; this->updateGlobalLocale(); this->updateLocaleLabels(); @@ -387,7 +387,7 @@ std::pair< QString, QString > LocalePage::prettyLocaleStatus( const LocaleConfig { return std::make_pair< QString, QString >( tr( "The system language will be set to %1." ) - .arg( prettyLCLocale( lc.lang ) ), + .arg( prettyLCLocale( lc.language() ) ), tr( "The numbers and dates locale will be set to %1." ) .arg( prettyLCLocale( lc.lc_numeric ) ) ); @@ -442,7 +442,7 @@ LocalePage::onActivate() !m_selectedLocaleConfiguration.explicit_lang ) { auto newLocale = guessLocaleConfiguration(); - m_selectedLocaleConfiguration.lang = newLocale.lang; + m_selectedLocaleConfiguration.setLanguage( newLocale.language() ); updateGlobalLocale(); updateLocaleLabels(); } @@ -511,7 +511,7 @@ LocalePage::updateGlobalStorage() auto newLocale = guessLocaleConfiguration(); if ( !m_selectedLocaleConfiguration.isEmpty() && m_selectedLocaleConfiguration.explicit_lang ) - newLocale.lang = m_selectedLocaleConfiguration.lang; + newLocale.setLanguage( m_selectedLocaleConfiguration.language() ); if ( !m_selectedLocaleConfiguration.isEmpty() && m_selectedLocaleConfiguration.explicit_lc ) { diff --git a/src/modules/locale/Tests.cpp b/src/modules/locale/Tests.cpp index 889519ca8..0e1a3eb48 100644 --- a/src/modules/locale/Tests.cpp +++ b/src/modules/locale/Tests.cpp @@ -49,12 +49,12 @@ void LocaleTests::testDefaultLocaleConfiguration() { LocaleConfiguration lc( "en_US.UTF-8" ); QVERIFY( !lc.isEmpty() ); - QCOMPARE( lc.lang, "en_US.UTF-8" ); + QCOMPARE( lc.language(), "en_US.UTF-8" ); QCOMPARE( lc.toBcp47(), "en" ); LocaleConfiguration lc2( "de_DE.UTF-8" ); QVERIFY( !lc2.isEmpty() ); - QCOMPARE( lc2.lang, "de_DE.UTF-8" ); + QCOMPARE( lc2.language(), "de_DE.UTF-8" ); QCOMPARE( lc2.toBcp47(), "de" ); } @@ -62,13 +62,13 @@ void LocaleTests::testSplitLocaleConfiguration() { LocaleConfiguration lc( "en_US.UTF-8", "de_DE.UTF-8" ); QVERIFY( !lc.isEmpty() ); - QCOMPARE( lc.lang, "en_US.UTF-8" ); + QCOMPARE( lc.language(), "en_US.UTF-8" ); QCOMPARE( lc.toBcp47(), "en" ); QCOMPARE( lc.lc_numeric, QStringLiteral( "de_DE.UTF-8" ) ); LocaleConfiguration lc2( "de_DE.UTF-8", "da_DK.UTF-8" ); QVERIFY( !lc2.isEmpty() ); - QCOMPARE( lc2.lang, "de_DE.UTF-8" ); + QCOMPARE( lc2.language(), "de_DE.UTF-8" ); QCOMPARE( lc2.toBcp47(), "de" ); QCOMPARE( lc2.lc_numeric, "da_DK.UTF-8" ); From 200f68ae48f450aca1d6c6a81065e14aecd26848 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 8 Jan 2019 22:18:01 +0100 Subject: [PATCH 15/20] [locale] Reduce debug-chattiness --- src/modules/locale/LocalePage.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/modules/locale/LocalePage.cpp b/src/modules/locale/LocalePage.cpp index 65d681f37..e64740574 100644 --- a/src/modules/locale/LocalePage.cpp +++ b/src/modules/locale/LocalePage.cpp @@ -137,7 +137,6 @@ LocalePage::LocalePage( QWidget* parent ) connect( m_tzWidget, &TimeZoneWidget::locationChanged, [this]( LocaleGlobal::Location location ) { - cDebug() << "Updating location from TZ widget to" << location; m_blockTzWidgetSet = true; // Set region index @@ -318,7 +317,7 @@ LocalePage::init( const QString& initialRegion, } else { - cDebug() << "Cannot open file" << localeGenPath + cWarning() << "Cannot open file" << localeGenPath << ". Assuming the supported languages are already built into " "the locale archive."; QProcess localeA; @@ -477,7 +476,6 @@ LocalePage::updateGlobalLocale() { auto *gs = Calamares::JobQueue::instance()->globalStorage(); const QString bcp47 = m_selectedLocaleConfiguration.toBcp47(); - cDebug() << "Updating global locale setting to" << bcp47; gs->insert( "locale", bcp47 ); } From ba82526449dbadc5a658185f1b56ae50ae60b327 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 8 Jan 2019 22:25:25 +0100 Subject: [PATCH 16/20] CMake: drop RC version for release --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f241cedd0..fa550f3c3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -75,7 +75,7 @@ set( CALAMARES_DESCRIPTION_SUMMARY set( CALAMARES_VERSION_MAJOR 3 ) set( CALAMARES_VERSION_MINOR 2 ) set( CALAMARES_VERSION_PATCH 3 ) -set( CALAMARES_VERSION_RC 1 ) +set( CALAMARES_VERSION_RC 0 ) ### Transifex (languages) info # From 527392f0afa550fd16ba51e4897f14d5afe2a492 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 8 Jan 2019 22:29:55 +0100 Subject: [PATCH 17/20] [libcalamares] Update Copyright statement --- src/libcalamares/PythonJobApi.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libcalamares/PythonJobApi.cpp b/src/libcalamares/PythonJobApi.cpp index 19670b87f..b953f821a 100644 --- a/src/libcalamares/PythonJobApi.cpp +++ b/src/libcalamares/PythonJobApi.cpp @@ -1,7 +1,7 @@ /* === This file is part of Calamares - === * * Copyright 2014-2016, Teo Mrnjavac - * 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 From 4b1b71dd3e8bc800bcd1ff22ca6c8adee8d1b195 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 8 Jan 2019 22:30:12 +0100 Subject: [PATCH 18/20] [locale] Update Copyright statements --- src/modules/locale/LocaleConfiguration.cpp | 2 +- src/modules/locale/LocaleConfiguration.h | 2 +- src/modules/locale/LocalePage.cpp | 2 +- src/modules/locale/LocalePage.h | 1 + src/modules/locale/timezonewidget/localeglobal.h | 1 + 5 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/modules/locale/LocaleConfiguration.cpp b/src/modules/locale/LocaleConfiguration.cpp index 64d9971a7..8bc2b2c77 100644 --- a/src/modules/locale/LocaleConfiguration.cpp +++ b/src/modules/locale/LocaleConfiguration.cpp @@ -1,7 +1,7 @@ /* === This file is part of Calamares - === * * Copyright 2016, Teo Mrnjavac - * 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 diff --git a/src/modules/locale/LocaleConfiguration.h b/src/modules/locale/LocaleConfiguration.h index e408d8ecb..abe90ffcb 100644 --- a/src/modules/locale/LocaleConfiguration.h +++ b/src/modules/locale/LocaleConfiguration.h @@ -1,7 +1,7 @@ /* === This file is part of Calamares - === * * Copyright 2016, Teo Mrnjavac - * 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 diff --git a/src/modules/locale/LocalePage.cpp b/src/modules/locale/LocalePage.cpp index e64740574..41ce488e3 100644 --- a/src/modules/locale/LocalePage.cpp +++ b/src/modules/locale/LocalePage.cpp @@ -1,7 +1,7 @@ /* === This file is part of Calamares - === * * Copyright 2014-2016, Teo Mrnjavac - * 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 diff --git a/src/modules/locale/LocalePage.h b/src/modules/locale/LocalePage.h index 4b93c690e..741a5d2e9 100644 --- a/src/modules/locale/LocalePage.h +++ b/src/modules/locale/LocalePage.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 diff --git a/src/modules/locale/timezonewidget/localeglobal.h b/src/modules/locale/timezonewidget/localeglobal.h index 88a8ae125..1a8f796d4 100644 --- a/src/modules/locale/timezonewidget/localeglobal.h +++ b/src/modules/locale/timezonewidget/localeglobal.h @@ -1,6 +1,7 @@ /* === This file is part of Calamares - === * * Copyright 2014-2016, Teo Mrnjavac + * Copyright 2019, Adriaan de Groot * * Originally from the Manjaro Installation Framework * by Roland Singer From 2d2454025de098605c7ee9a4d057899ebf1ab974 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Wed, 9 Jan 2019 12:58:31 +0100 Subject: [PATCH 19/20] Changes: document locale fix FIXES #1064 --- CHANGES | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGES b/CHANGES index 2cedfe508..2b649b772 100644 --- a/CHANGES +++ b/CHANGES @@ -14,6 +14,11 @@ This release contains contributions from (alphabetically by first name): * Fixed bug where, during detection of existing systems, the existing system partitions may be mounted and then destroyed. + * *locale* It was possible to set the installer and system language + (e.g. to German) while the global storage value for *locale* + remained set to English. Then no localization packages are installed + (see feature `${LOCALE}` in `packages.conf`). Reported downstream + in Netrunner. = 3.2.2 (2018-09-04) = From b18ba3d66292e8fd3848f074d3a4d6fe3381d403 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Wed, 9 Jan 2019 13:00:52 +0100 Subject: [PATCH 20/20] Changes: polish the change-notes a bit --- CHANGES | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/CHANGES b/CHANGES index 2b649b772..ae2ca240b 100644 --- a/CHANGES +++ b/CHANGES @@ -3,23 +3,29 @@ contributors are listed. Note that Calamares does not have a historical changelog -- this log starts with version 3.2.0. The release notes on the website will have to do for older versions. -= 3.2.3 (unreleased) = += 3.2.3 (2019-01-09) = This release contains contributions from (alphabetically by first name): - aliveafter1000 == Core == +There are no core changes in this release. + == Modules == - * Fixed bug where, during detection of existing systems, the existing - system partitions may be mounted and then destroyed. + * *partition* Fixed bug where, during detection of existing systems, the + existing system partitions may be mounted and then files deleted. + This is a **limited** version of the patch from aliveafter1000 + that will be in 3.2.4, which tries harder to mount filesystems + read-only and unmodifiable. * *locale* It was possible to set the installer and system language (e.g. to German) while the global storage value for *locale* remained set to English. Then no localization packages are installed (see feature `${LOCALE}` in `packages.conf`). Reported downstream in Netrunner. + = 3.2.2 (2018-09-04) = This release contains contributions from (alphabetically by first name):