From 1b3d32ca7972ddd4bbef8781d1f3d700d6d12d1c Mon Sep 17 00:00:00 2001 From: Camilo Higuita Date: Thu, 12 Dec 2019 10:41:37 -0500 Subject: [PATCH 01/21] make label item from LabelModel qobject based and expose properties --- src/libcalamares/locale/Label.cpp | 11 ++++++++--- src/libcalamares/locale/Label.h | 18 +++++++++++++++--- src/libcalamares/locale/LabelModel.cpp | 17 +++++++++-------- src/libcalamares/locale/LabelModel.h | 4 +++- 4 files changed, 35 insertions(+), 15 deletions(-) diff --git a/src/libcalamares/locale/Label.cpp b/src/libcalamares/locale/Label.cpp index 58c19101d..519e648bd 100644 --- a/src/libcalamares/locale/Label.cpp +++ b/src/libcalamares/locale/Label.cpp @@ -24,17 +24,19 @@ namespace CalamaresUtils namespace Locale { -Label::Label() - : m_locale( QLocale() ) +Label::Label( QObject* parent ) + : QObject( parent ) + , m_locale( QLocale() ) { m_localeId = m_locale.name(); setLabels( QString(), LabelFormat::IfNeededWithCountry ); } -Label::Label( const QString& locale, LabelFormat format ) +Label::Label( const QString& locale, LabelFormat format, QObject* parent ) : m_locale( Label::getLocale( locale ) ) , m_localeId( locale ) + , QObject( parent ) { setLabels( locale, format ); } @@ -42,6 +44,7 @@ Label::Label( const QString& locale, LabelFormat format ) void Label::setLabels( const QString& locale, LabelFormat format ) { + emit localeIdChanged(m_localeId); //: language[name] (country[name]) QString longFormat = QObject::tr( "%1 (%2)" ); @@ -62,8 +65,10 @@ Label::setLabels( const QString& locale, LabelFormat format ) countryName = m_locale.nativeCountryName(); } m_label = needsCountryName ? longFormat.arg( languageName, countryName ) : languageName; + emit labelChanged(m_label); m_englishLabel = needsCountryName ? longFormat.arg( englishName, QLocale::countryToString( m_locale.country() ) ) : englishName; + emit englishLabelChanged(m_englishLabel); } QLocale diff --git a/src/libcalamares/locale/Label.h b/src/libcalamares/locale/Label.h index 95129d38c..840c6f251 100644 --- a/src/libcalamares/locale/Label.h +++ b/src/libcalamares/locale/Label.h @@ -22,6 +22,7 @@ #include #include +#include namespace CalamaresUtils { @@ -35,8 +36,14 @@ namespace Locale * translation system) into QLocales, and also into consistent * human-readable text labels. */ -class Label +class Label : public QObject { + Q_OBJECT + + Q_PROPERTY(QString label READ label NOTIFY labelChanged CONSTANT FINAL) + Q_PROPERTY(QString englishLabel READ englishLabel NOTIFY englishLabelChanged CONSTANT FINAL) + Q_PROPERTY(QString localeId MEMBER m_localeId NOTIFY localeIdChanged CONSTANT FINAL) + public: /** @brief Formatting option for label -- add (country) to label. */ enum class LabelFormat @@ -46,7 +53,7 @@ public: }; /** @brief Empty locale. This uses the system-default locale. */ - Label(); + Label(QObject* parent = nullptr); /** @brief Construct from a locale name. * @@ -54,7 +61,7 @@ public: * The @p format determines whether the country name is always present * in the label (human-readable form) or only if needed for disambiguation. */ - Label( const QString& localeName, LabelFormat format = LabelFormat::IfNeededWithCountry ); + Label( const QString& localeName, LabelFormat format = LabelFormat::IfNeededWithCountry, QObject* parent = nullptr ); /** @brief Define a sorting order. * @@ -100,6 +107,11 @@ protected: QString m_localeId; // the locale identifier, e.g. "en_GB" QString m_label; // the native name of the locale QString m_englishLabel; + +signals: + void labelChanged( QString label ); + void englishLabelChanged( QString englishLabel ); + void localeIdChanged( QString localeIdChanged ); }; } // namespace Locale diff --git a/src/libcalamares/locale/LabelModel.cpp b/src/libcalamares/locale/LabelModel.cpp index bcb8af057..faec3edec 100644 --- a/src/libcalamares/locale/LabelModel.cpp +++ b/src/libcalamares/locale/LabelModel.cpp @@ -17,6 +17,7 @@ */ #include "LabelModel.h" +#include #include "Lookup.h" @@ -36,7 +37,7 @@ LabelModel::LabelModel( const QStringList& locales, QObject* parent ) for ( const auto& l : locales ) { - m_locales.push_back( Label( l ) ); + m_locales.push_back( new Label( l, Label::LabelFormat::IfNeededWithCountry, this ) ); } } @@ -65,9 +66,9 @@ LabelModel::data( const QModelIndex& index, int role ) const switch ( role ) { case LabelRole: - return locale.label(); + return locale->label(); case EnglishLabelRole: - return locale.englishLabel(); + return locale->englishLabel(); default: return QVariant(); } @@ -79,13 +80,13 @@ LabelModel::locale( int row ) const if ( ( row < 0 ) || ( row >= m_locales.count() ) ) { for ( const auto& l : m_locales ) - if ( l.isEnglish() ) + if ( l->isEnglish() ) { - return l; + return *l; } - return m_locales[ 0 ]; + return *m_locales[ 0 ]; } - return m_locales[ row ]; + return *m_locales[ row ]; } int @@ -93,7 +94,7 @@ LabelModel::find( std::function< bool( const Label& ) > predicate ) const { for ( int row = 0; row < m_locales.count(); ++row ) { - if ( predicate( m_locales[ row ] ) ) + if ( predicate( *m_locales[ row ] ) ) { return row; } diff --git a/src/libcalamares/locale/LabelModel.h b/src/libcalamares/locale/LabelModel.h index 03daddbf3..55dd35b8b 100644 --- a/src/libcalamares/locale/LabelModel.h +++ b/src/libcalamares/locale/LabelModel.h @@ -33,6 +33,8 @@ namespace Locale class DLLEXPORT LabelModel : public QAbstractListModel { + Q_OBJECT + public: enum { @@ -69,7 +71,7 @@ public: int find( const QString& countryCode ) const; private: - QVector< Label > m_locales; + QVector< Label* > m_locales; QStringList m_localeIds; }; From 241cb04f0661225f1daaafb27e43ea7463fa71ee Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 11 Feb 2020 15:25:28 +0100 Subject: [PATCH 02/21] [libcalamares] Coding style --- src/libcalamares/locale/Label.cpp | 6 +++--- src/libcalamares/locale/Label.h | 14 ++++++++------ 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/libcalamares/locale/Label.cpp b/src/libcalamares/locale/Label.cpp index 519e648bd..e526b633d 100644 --- a/src/libcalamares/locale/Label.cpp +++ b/src/libcalamares/locale/Label.cpp @@ -44,7 +44,7 @@ Label::Label( const QString& locale, LabelFormat format, QObject* parent ) void Label::setLabels( const QString& locale, LabelFormat format ) { - emit localeIdChanged(m_localeId); + emit localeIdChanged( m_localeId ); //: language[name] (country[name]) QString longFormat = QObject::tr( "%1 (%2)" ); @@ -65,10 +65,10 @@ Label::setLabels( const QString& locale, LabelFormat format ) countryName = m_locale.nativeCountryName(); } m_label = needsCountryName ? longFormat.arg( languageName, countryName ) : languageName; - emit labelChanged(m_label); + emit labelChanged( m_label ); m_englishLabel = needsCountryName ? longFormat.arg( englishName, QLocale::countryToString( m_locale.country() ) ) : englishName; - emit englishLabelChanged(m_englishLabel); + emit englishLabelChanged( m_englishLabel ); } QLocale diff --git a/src/libcalamares/locale/Label.h b/src/libcalamares/locale/Label.h index 840c6f251..ef6ac0aa3 100644 --- a/src/libcalamares/locale/Label.h +++ b/src/libcalamares/locale/Label.h @@ -21,8 +21,8 @@ #define LOCALE_LABEL_H #include -#include #include +#include namespace CalamaresUtils { @@ -40,9 +40,9 @@ class Label : public QObject { Q_OBJECT - Q_PROPERTY(QString label READ label NOTIFY labelChanged CONSTANT FINAL) - Q_PROPERTY(QString englishLabel READ englishLabel NOTIFY englishLabelChanged CONSTANT FINAL) - Q_PROPERTY(QString localeId MEMBER m_localeId NOTIFY localeIdChanged CONSTANT FINAL) + Q_PROPERTY( QString label READ label NOTIFY labelChanged CONSTANT FINAL ) + Q_PROPERTY( QString englishLabel READ englishLabel NOTIFY englishLabelChanged CONSTANT FINAL ) + Q_PROPERTY( QString localeId MEMBER m_localeId NOTIFY localeIdChanged CONSTANT FINAL ) public: /** @brief Formatting option for label -- add (country) to label. */ @@ -53,7 +53,7 @@ public: }; /** @brief Empty locale. This uses the system-default locale. */ - Label(QObject* parent = nullptr); + Label( QObject* parent = nullptr ); /** @brief Construct from a locale name. * @@ -61,7 +61,9 @@ public: * The @p format determines whether the country name is always present * in the label (human-readable form) or only if needed for disambiguation. */ - Label( const QString& localeName, LabelFormat format = LabelFormat::IfNeededWithCountry, QObject* parent = nullptr ); + Label( const QString& localeName, + LabelFormat format = LabelFormat::IfNeededWithCountry, + QObject* parent = nullptr ); /** @brief Define a sorting order. * From 27bc64e63fcba4c0a1f52dae1934de7e5533dff7 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 11 Feb 2020 15:36:30 +0100 Subject: [PATCH 03/21] [libcalamares] C++ style, warnings-- --- src/libcalamares/locale/Label.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/libcalamares/locale/Label.cpp b/src/libcalamares/locale/Label.cpp index e526b633d..2f35d6b03 100644 --- a/src/libcalamares/locale/Label.cpp +++ b/src/libcalamares/locale/Label.cpp @@ -34,9 +34,10 @@ Label::Label( QObject* parent ) } Label::Label( const QString& locale, LabelFormat format, QObject* parent ) - : m_locale( Label::getLocale( locale ) ) + : QObject( parent ) + , m_locale( Label::getLocale( locale ) ) , m_localeId( locale ) - , QObject( parent ) + { setLabels( locale, format ); } From df5a0d25bc845b985c720a320e130686df9663b9 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 11 Feb 2020 16:37:49 +0100 Subject: [PATCH 04/21] [libcalamares] Handle empty locale names quickly --- src/libcalamares/locale/Label.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/libcalamares/locale/Label.cpp b/src/libcalamares/locale/Label.cpp index 2f35d6b03..8e817a4ce 100644 --- a/src/libcalamares/locale/Label.cpp +++ b/src/libcalamares/locale/Label.cpp @@ -75,6 +75,10 @@ Label::setLabels( const QString& locale, LabelFormat format ) QLocale Label::getLocale( const QString& localeName ) { + if ( localeName.isEmpty() ) + { + return QLocale(); + } if ( localeName.contains( "@latin" ) ) { QLocale loc( localeName ); // Ignores @latin From b4b1bf5de213311bb11fc18014e7ad35edb3e44f Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 11 Feb 2020 16:39:39 +0100 Subject: [PATCH 05/21] [libcalamares] Call delegated constructor --- src/libcalamares/locale/Label.cpp | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/libcalamares/locale/Label.cpp b/src/libcalamares/locale/Label.cpp index 8e817a4ce..987c66811 100644 --- a/src/libcalamares/locale/Label.cpp +++ b/src/libcalamares/locale/Label.cpp @@ -25,18 +25,14 @@ namespace Locale { Label::Label( QObject* parent ) - : QObject( parent ) - , m_locale( QLocale() ) + : Label( QString(), LabelFormat::IfNeededWithCountry, parent ) { - m_localeId = m_locale.name(); - - setLabels( QString(), LabelFormat::IfNeededWithCountry ); } Label::Label( const QString& locale, LabelFormat format, QObject* parent ) : QObject( parent ) , m_locale( Label::getLocale( locale ) ) - , m_localeId( locale ) + , m_localeId( locale.isEmpty() ? m_locale.name() : locale ) { setLabels( locale, format ); From 684c5f477cf86e737d48c1c3e84ef831176555e4 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 11 Feb 2020 16:40:36 +0100 Subject: [PATCH 06/21] [libcalamares] Moc warnings-- - don't have a NOTIFY CONSTANT property - the data is constant, so drop NOTIFY - remove redundant signals - remove setLabels() now it's only needed from one constructor --- src/libcalamares/locale/Label.cpp | 9 --------- src/libcalamares/locale/Label.h | 13 +++---------- 2 files changed, 3 insertions(+), 19 deletions(-) diff --git a/src/libcalamares/locale/Label.cpp b/src/libcalamares/locale/Label.cpp index 987c66811..816246699 100644 --- a/src/libcalamares/locale/Label.cpp +++ b/src/libcalamares/locale/Label.cpp @@ -35,13 +35,6 @@ Label::Label( const QString& locale, LabelFormat format, QObject* parent ) , m_localeId( locale.isEmpty() ? m_locale.name() : locale ) { - setLabels( locale, format ); -} - -void -Label::setLabels( const QString& locale, LabelFormat format ) -{ - emit localeIdChanged( m_localeId ); //: language[name] (country[name]) QString longFormat = QObject::tr( "%1 (%2)" ); @@ -62,10 +55,8 @@ Label::setLabels( const QString& locale, LabelFormat format ) countryName = m_locale.nativeCountryName(); } m_label = needsCountryName ? longFormat.arg( languageName, countryName ) : languageName; - emit labelChanged( m_label ); m_englishLabel = needsCountryName ? longFormat.arg( englishName, QLocale::countryToString( m_locale.country() ) ) : englishName; - emit englishLabelChanged( m_englishLabel ); } QLocale diff --git a/src/libcalamares/locale/Label.h b/src/libcalamares/locale/Label.h index ef6ac0aa3..d7fa14453 100644 --- a/src/libcalamares/locale/Label.h +++ b/src/libcalamares/locale/Label.h @@ -40,9 +40,9 @@ class Label : public QObject { Q_OBJECT - Q_PROPERTY( QString label READ label NOTIFY labelChanged CONSTANT FINAL ) - Q_PROPERTY( QString englishLabel READ englishLabel NOTIFY englishLabelChanged CONSTANT FINAL ) - Q_PROPERTY( QString localeId MEMBER m_localeId NOTIFY localeIdChanged CONSTANT FINAL ) + Q_PROPERTY( QString label READ label CONSTANT FINAL ) + Q_PROPERTY( QString englishLabel READ englishLabel CONSTANT FINAL ) + Q_PROPERTY( QString localeId MEMBER m_localeId CONSTANT FINAL ) public: /** @brief Formatting option for label -- add (country) to label. */ @@ -103,17 +103,10 @@ public: static QLocale getLocale( const QString& localeName ); protected: - void setLabels( const QString& name, LabelFormat format ); - QLocale m_locale; QString m_localeId; // the locale identifier, e.g. "en_GB" QString m_label; // the native name of the locale QString m_englishLabel; - -signals: - void labelChanged( QString label ); - void englishLabelChanged( QString englishLabel ); - void localeIdChanged( QString localeIdChanged ); }; } // namespace Locale From ca13d1670e0ab958a3aa985e0d95ec5277be9c47 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Wed, 12 Feb 2020 13:40:59 +0100 Subject: [PATCH 07/21] [libcalamares] Merge more from Camilo - Complete the model for locales --- src/libcalamares/locale/LabelModel.cpp | 10 ++++++++-- src/libcalamares/locale/LabelModel.h | 4 +++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/libcalamares/locale/LabelModel.cpp b/src/libcalamares/locale/LabelModel.cpp index faec3edec..da4e1a9f7 100644 --- a/src/libcalamares/locale/LabelModel.cpp +++ b/src/libcalamares/locale/LabelModel.cpp @@ -1,6 +1,7 @@ /* === This file is part of Calamares - === * - * Copyright 2019, Adriaan de Groot + * Copyright 2019-2020 Adriaan de Groot + * Copyright 2019, Camilo Higuita * * Calamares is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -17,7 +18,6 @@ */ #include "LabelModel.h" -#include #include "Lookup.h" @@ -74,6 +74,12 @@ LabelModel::data( const QModelIndex& index, int role ) const } } +QHash< int, QByteArray > +LabelModel::roleNames() const +{ + return { { LabelRole, "label" }, { EnglishLabelRole, "englishLabel" } }; +} + const Label& LabelModel::locale( int row ) const { diff --git a/src/libcalamares/locale/LabelModel.h b/src/libcalamares/locale/LabelModel.h index 55dd35b8b..7bd1fad67 100644 --- a/src/libcalamares/locale/LabelModel.h +++ b/src/libcalamares/locale/LabelModel.h @@ -1,6 +1,7 @@ /* === This file is part of Calamares - === * - * Copyright 2019, Adriaan de Groot + * Copyright 2019-2020, Adriaan de Groot + * Copyright 2019, Camilo Higuita * * Calamares is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -48,6 +49,7 @@ public: int rowCount( const QModelIndex& parent ) const override; QVariant data( const QModelIndex& index, int role ) const override; + QHash< int, QByteArray > roleNames() const override; /** @brief Gets locale information for entry #n * From 1f2f1a657e0d3a530247a72ee3a7ddeeaaeb0e55 Mon Sep 17 00:00:00 2001 From: Camilo Higuita Date: Fri, 13 Dec 2019 14:22:15 +0100 Subject: [PATCH 08/21] [libcalamaresui] Expose Branding strings to QML --- src/libcalamaresui/Branding.cpp | 4 +++- src/libcalamaresui/Branding.h | 11 +++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/libcalamaresui/Branding.cpp b/src/libcalamaresui/Branding.cpp index a5b6e5dce..9bdccfa51 100644 --- a/src/libcalamaresui/Branding.cpp +++ b/src/libcalamaresui/Branding.cpp @@ -3,6 +3,7 @@ * Copyright 2014-2015, Teo Mrnjavac * Copyright 2017-2019, Adriaan de Groot * Copyright 2018, Raul Rodrigo Segura (raurodse) + * Copyright 2019, Camilo Higuita * * Calamares is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -74,7 +75,8 @@ const QStringList Branding::s_imageEntryStrings = { "productLogo", "productIcon", - "productWelcome" + "productWelcome", + "productWallpaper" }; const QStringList Branding::s_styleEntryStrings = diff --git a/src/libcalamaresui/Branding.h b/src/libcalamaresui/Branding.h index 30e8be846..e3952881e 100644 --- a/src/libcalamaresui/Branding.h +++ b/src/libcalamaresui/Branding.h @@ -3,6 +3,7 @@ * Copyright 2014-2015, Teo Mrnjavac * Copyright 2017-2018, Adriaan de Groot * Copyright 2018, Raul Rodrigo Segura (raurodse) + * Copyright 2019, Camilo Higuita * * Calamares is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -48,7 +49,7 @@ public: * e.g. *Branding::ProductName to get the string value for * the product name. */ - enum StringEntry : short + enum StringEntry { ProductName, Version, @@ -62,13 +63,16 @@ public: KnownIssuesUrl, ReleaseNotesUrl }; + Q_ENUM( StringEntry ) enum ImageEntry : short { ProductLogo, ProductIcon, - ProductWelcome + ProductWelcome, + ProductWallpaper }; + Q_ENUM( ImageEntry ) enum StyleEntry : short { @@ -77,6 +81,7 @@ public: SidebarTextSelect, SidebarTextHighlight }; + Q_ENUM( StyleEntry ) /** @brief Setting for how much the main window may expand. */ enum class WindowExpansion @@ -85,6 +90,7 @@ public: Fullscreen, Fixed }; + Q_ENUM( WindowExpansion ) /** @brief Setting for the main window size. * * The units are pixels (Pixies) or something-based-on-fontsize (Fonties), which @@ -96,6 +102,7 @@ public: Pixies, Fonties }; + Q_ENUM( WindowDimensionUnit ) class WindowDimension : public NamedSuffix< WindowDimensionUnit, WindowDimensionUnit::None > { public: From ffeed05a5d79742607f04583f1a6cbeda38dcd45 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Wed, 12 Feb 2020 14:09:09 +0100 Subject: [PATCH 09/21] Changes: credit Camilo Higuita for QML prep-work --- CHANGES | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES b/CHANGES index 1322f0449..439a3c882 100644 --- a/CHANGES +++ b/CHANGES @@ -7,6 +7,7 @@ website will have to do for older versions. This release contains contributions from (alphabetically by first name): - Anke Boersma + - Camilo Higuita ## Core ## - *Assamese* translation has been completed. From c055e1da49dbedbe9d01cbccbd22eae2288d2b45 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Thu, 13 Feb 2020 09:24:12 +0100 Subject: [PATCH 10/21] [partition] Use untranslated name of filesystem - Patch from Gabriel Craciunescu --- CHANGES | 1 + src/modules/partition/jobs/FillGlobalStorageJob.cpp | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGES b/CHANGES index 439a3c882..cb807cdc4 100644 --- a/CHANGES +++ b/CHANGES @@ -8,6 +8,7 @@ website will have to do for older versions. This release contains contributions from (alphabetically by first name): - Anke Boersma - Camilo Higuita + - Gabriel Craciunescu ## Core ## - *Assamese* translation has been completed. diff --git a/src/modules/partition/jobs/FillGlobalStorageJob.cpp b/src/modules/partition/jobs/FillGlobalStorageJob.cpp index 8b981ce3e..77b1e8aaa 100644 --- a/src/modules/partition/jobs/FillGlobalStorageJob.cpp +++ b/src/modules/partition/jobs/FillGlobalStorageJob.cpp @@ -89,7 +89,7 @@ mapForPartition( Partition* partition, const QString& uuid ) map[ "fs" ] = partition->fileSystem().name( { QStringLiteral("C") } ); // Untranslated if ( partition->fileSystem().type() == FileSystem::Luks && dynamic_cast< FS::luks& >( partition->fileSystem() ).innerFS() ) - map[ "fs" ] = dynamic_cast< FS::luks& >( partition->fileSystem() ).innerFS()->name(); + map[ "fs" ] = dynamic_cast< FS::luks& >( partition->fileSystem() ).innerFS()->name( { QStringLiteral("C") } ); map[ "uuid" ] = uuid; // Debugging for inside the loop in createPartitionList(), From f410a4bb68c288821dad06fbc13374f74912fc0e Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Thu, 13 Feb 2020 10:12:02 +0100 Subject: [PATCH 11/21] [libcalamares] Convenience function for FS names Because getting the untranslated name of a FileSystem is something that needs doing consistently, add some functions for that; it makes it easier to spot places where that isn't done. Probably doesn't compile, and needs extra documentation. --- src/libcalamares/partition/FSName.h | 52 +++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 src/libcalamares/partition/FSName.h diff --git a/src/libcalamares/partition/FSName.h b/src/libcalamares/partition/FSName.h new file mode 100644 index 000000000..f7dfcf5b4 --- /dev/null +++ b/src/libcalamares/partition/FSName.h @@ -0,0 +1,52 @@ +/* === This file is part of Calamares - === + * + * Copyright 2020, 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 . + */ + +/** @brief Gets filesystem names from KPMCore + * + * A name (e.g. "ext4") can be for internal, untranslated, use, or for + * user-visible use. In the latter case it should be translated. The + * KPMCore API gives user-visible names by default. + */ +#ifndef PARTITION_FSNAME_H +#define PARTITION_FSNAME_H + +#include + +#include + +namespace CalamaresUtils +{ +namespace Partition +{ + +static inline QString +untranslatedFS( FileSystem& fs ) +{ + return fs.name( { QStringLiteral( "C" ) } ); +} + +static inline QString +untranslatedFS( FileSystem* fs ) +{ + return fs ? untranslatedFS( *fs ) : QString(); +} + +} // namespace Partition +} // namespace CalamaresUtils + +#endif // PARTITION_FSNAME_H From a0449abab9d51211ef4a87e171a430b585734fd9 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Thu, 13 Feb 2020 11:06:53 +0100 Subject: [PATCH 12/21] [partition] Do not translate filesystem names - Move contents of FSName to KPMHelpers - Use the new functions from FillGlobalStorage Needs more use in the rest of the partition module. --- src/libcalamares/partition/FSName.h | 52 ------------------- src/modules/partition/core/KPMHelpers.h | 13 +++++ .../partition/jobs/FillGlobalStorageJob.cpp | 13 +++-- 3 files changed, 21 insertions(+), 57 deletions(-) delete mode 100644 src/libcalamares/partition/FSName.h diff --git a/src/libcalamares/partition/FSName.h b/src/libcalamares/partition/FSName.h deleted file mode 100644 index f7dfcf5b4..000000000 --- a/src/libcalamares/partition/FSName.h +++ /dev/null @@ -1,52 +0,0 @@ -/* === This file is part of Calamares - === - * - * Copyright 2020, 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 . - */ - -/** @brief Gets filesystem names from KPMCore - * - * A name (e.g. "ext4") can be for internal, untranslated, use, or for - * user-visible use. In the latter case it should be translated. The - * KPMCore API gives user-visible names by default. - */ -#ifndef PARTITION_FSNAME_H -#define PARTITION_FSNAME_H - -#include - -#include - -namespace CalamaresUtils -{ -namespace Partition -{ - -static inline QString -untranslatedFS( FileSystem& fs ) -{ - return fs.name( { QStringLiteral( "C" ) } ); -} - -static inline QString -untranslatedFS( FileSystem* fs ) -{ - return fs ? untranslatedFS( *fs ) : QString(); -} - -} // namespace Partition -} // namespace CalamaresUtils - -#endif // PARTITION_FSNAME_H diff --git a/src/modules/partition/core/KPMHelpers.h b/src/modules/partition/core/KPMHelpers.h index bca69d1f6..7ef9718ae 100644 --- a/src/modules/partition/core/KPMHelpers.h +++ b/src/modules/partition/core/KPMHelpers.h @@ -114,6 +114,19 @@ Partition* createNewEncryptedPartition( PartitionNode* parent, Partition* clonePartition( Device* device, Partition* partition ); QString prettyNameForFileSystemType( FileSystem::Type t ); + +static inline QString +untranslatedFS( FileSystem& fs ) +{ + return fs.name( { QStringLiteral( "C" ) } ); +} + +static inline QString +untranslatedFS( FileSystem* fs ) +{ + return fs ? untranslatedFS( *fs ) : QString(); +} + } #endif /* KPMHELPERS_H */ diff --git a/src/modules/partition/jobs/FillGlobalStorageJob.cpp b/src/modules/partition/jobs/FillGlobalStorageJob.cpp index 77b1e8aaa..10554209c 100644 --- a/src/modules/partition/jobs/FillGlobalStorageJob.cpp +++ b/src/modules/partition/jobs/FillGlobalStorageJob.cpp @@ -20,11 +20,12 @@ #include "jobs/FillGlobalStorageJob.h" -#include "GlobalStorage.h" -#include "JobQueue.h" #include "core/PartitionInfo.h" #include "core/PartitionIterator.h" #include "core/KPMHelpers.h" + +#include "GlobalStorage.h" +#include "JobQueue.h" #include "Branding.h" #include "utils/Logger.h" @@ -40,6 +41,8 @@ #include #include +using KPMHelpers::untranslatedFS; + typedef QHash UuidForPartitionHash; static UuidForPartitionHash @@ -85,11 +88,11 @@ mapForPartition( Partition* partition, const QString& uuid ) QVariantMap map; map[ "device" ] = partition->partitionPath(); map[ "mountPoint" ] = PartitionInfo::mountPoint( partition ); - map[ "fsName" ] = partition->fileSystem().name(); - map[ "fs" ] = partition->fileSystem().name( { QStringLiteral("C") } ); // Untranslated + map[ "fsName" ] = partition->fileSystem().name(); // User-visible + map[ "fs" ] = untranslatedFS( partition->fileSystem() ); if ( partition->fileSystem().type() == FileSystem::Luks && dynamic_cast< FS::luks& >( partition->fileSystem() ).innerFS() ) - map[ "fs" ] = dynamic_cast< FS::luks& >( partition->fileSystem() ).innerFS()->name( { QStringLiteral("C") } ); + map[ "fs" ] = untranslatedFS( dynamic_cast< FS::luks& >( partition->fileSystem() ).innerFS() ); map[ "uuid" ] = uuid; // Debugging for inside the loop in createPartitionList(), From dac5516b2c6841c89e97ef5df35ac1170a922764 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Thu, 13 Feb 2020 11:12:22 +0100 Subject: [PATCH 13/21] [partition] Update copyright, coding style --- .../partition/jobs/FillGlobalStorageJob.cpp | 73 +++++++++++-------- 1 file changed, 44 insertions(+), 29 deletions(-) diff --git a/src/modules/partition/jobs/FillGlobalStorageJob.cpp b/src/modules/partition/jobs/FillGlobalStorageJob.cpp index 10554209c..7faa4b50f 100644 --- a/src/modules/partition/jobs/FillGlobalStorageJob.cpp +++ b/src/modules/partition/jobs/FillGlobalStorageJob.cpp @@ -2,7 +2,7 @@ * * Copyright 2014, Aurélien Gâteau * Copyright 2015-2016, Teo Mrnjavac - * Copyright 2017, 2019, Adriaan de Groot + * Copyright 2017, 2019-2020, 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 @@ -20,13 +20,13 @@ #include "jobs/FillGlobalStorageJob.h" +#include "core/KPMHelpers.h" #include "core/PartitionInfo.h" #include "core/PartitionIterator.h" -#include "core/KPMHelpers.h" +#include "Branding.h" #include "GlobalStorage.h" #include "JobQueue.h" -#include "Branding.h" #include "utils/Logger.h" // KPMcore @@ -43,16 +43,15 @@ using KPMHelpers::untranslatedFS; -typedef QHash UuidForPartitionHash; +typedef QHash< QString, QString > UuidForPartitionHash; static UuidForPartitionHash -findPartitionUuids( QList < Device* > devices ) +findPartitionUuids( QList< Device* > devices ) { UuidForPartitionHash hash; foreach ( Device* device, devices ) { - for ( auto it = PartitionIterator::begin( device ); - it != PartitionIterator::end( device ); ++it ) + for ( auto it = PartitionIterator::begin( device ); it != PartitionIterator::end( device ); ++it ) { Partition* p = *it; QString path = p->partitionPath(); @@ -62,7 +61,9 @@ findPartitionUuids( QList < Device* > devices ) } if ( hash.isEmpty() ) + { cDebug() << "No UUIDs found for existing partitions."; + } return hash; } @@ -76,7 +77,9 @@ getLuksUuid( const QString& path ) process.start(); process.waitForFinished(); if ( process.exitStatus() != QProcess::NormalExit || process.exitCode() ) + { return QString(); + } QString uuid = QString::fromLocal8Bit( process.readAllStandardOutput() ).trimmed(); return uuid; } @@ -90,20 +93,20 @@ mapForPartition( Partition* partition, const QString& uuid ) map[ "mountPoint" ] = PartitionInfo::mountPoint( partition ); map[ "fsName" ] = partition->fileSystem().name(); // User-visible map[ "fs" ] = untranslatedFS( partition->fileSystem() ); - if ( partition->fileSystem().type() == FileSystem::Luks && - dynamic_cast< FS::luks& >( partition->fileSystem() ).innerFS() ) + if ( partition->fileSystem().type() == FileSystem::Luks + && dynamic_cast< FS::luks& >( partition->fileSystem() ).innerFS() ) + { map[ "fs" ] = untranslatedFS( dynamic_cast< FS::luks& >( partition->fileSystem() ).innerFS() ); + } map[ "uuid" ] = uuid; // Debugging for inside the loop in createPartitionList(), // so indent a bit Logger::CDebug deb; - using TR = Logger::DebugRow; + using TR = Logger::DebugRow< const char* const, const QString& >; deb << Logger::SubEntry << "mapping for" << partition->partitionPath() << partition->deviceNode() - << TR( "mtpoint:", PartitionInfo::mountPoint( partition ) ) - << TR( "fs:", map[ "fs" ].toString() ) - << TR( "fsname", map[ "fsName" ].toString() ) - << TR( "uuid", uuid ); + << TR( "mtpoint:", PartitionInfo::mountPoint( partition ) ) << TR( "fs:", map[ "fs" ].toString() ) + << TR( "fsname", map[ "fsName" ].toString() ) << TR( "uuid", uuid ); if ( partition->roles().has( PartitionRole::Luks ) ) { @@ -140,7 +143,7 @@ FillGlobalStorageJob::prettyDescription() const QStringList lines; const auto partitionList = createPartitionList().toList(); - for ( const QVariant &partitionItem : partitionList ) + for ( const QVariant& partitionItem : partitionList ) { if ( partitionItem.type() == QVariant::Map ) { @@ -149,32 +152,42 @@ FillGlobalStorageJob::prettyDescription() const QString mountPoint = partitionMap.value( "mountPoint" ).toString(); QString fsType = partitionMap.value( "fs" ).toString(); if ( mountPoint.isEmpty() || fsType.isEmpty() ) + { continue; + } if ( path.isEmpty() ) { if ( mountPoint == "/" ) + { lines.append( tr( "Install %1 on new %2 system partition." ) - .arg( *Calamares::Branding::ShortProductName ) - .arg( fsType ) ); + .arg( *Calamares::Branding::ShortProductName ) + .arg( fsType ) ); + } else + { lines.append( tr( "Set up new %2 partition with mount point " "%1." ) - .arg( mountPoint ) - .arg( fsType ) ); + .arg( mountPoint ) + .arg( fsType ) ); + } } else { if ( mountPoint == "/" ) + { lines.append( tr( "Install %2 on %3 system partition %1." ) - .arg( path ) - .arg( *Calamares::Branding::ShortProductName ) - .arg( fsType ) ); + .arg( path ) + .arg( *Calamares::Branding::ShortProductName ) + .arg( fsType ) ); + } else + { lines.append( tr( "Set up %3 partition %1 with mount point " "%2." ) - .arg( path ) - .arg( mountPoint ) - .arg( fsType ) ); + .arg( path ) + .arg( mountPoint ) + .arg( fsType ) ); + } } } } @@ -182,8 +195,7 @@ FillGlobalStorageJob::prettyDescription() const QVariant bootloaderMap = createBootLoaderMap(); if ( !m_bootLoaderPath.isEmpty() ) { - lines.append( tr( "Install boot loader on %1." ) - .arg( m_bootLoaderPath ) ); + lines.append( tr( "Install boot loader on %1." ).arg( m_bootLoaderPath ) ); } return lines.join( "
" ); } @@ -204,7 +216,9 @@ FillGlobalStorageJob::exec() { QVariant var = createBootLoaderMap(); if ( !var.isValid() ) + { cDebug() << "Failed to find path for boot loader"; + } cDebug() << "FillGlobalStorageJob writing bootLoader path:" << var; storage->insert( "bootLoader", var ); } @@ -225,8 +239,7 @@ FillGlobalStorageJob::createPartitionList() const for ( auto device : m_devices ) { cDebug() << Logger::SubEntry << "partitions on" << device->deviceNode(); - for ( auto it = PartitionIterator::begin( device ); - it != PartitionIterator::end( device ); ++it ) + for ( auto it = PartitionIterator::begin( device ); it != PartitionIterator::end( device ); ++it ) { // Debug-logging is done when creating the map lst << mapForPartition( *it, hash.value( ( *it )->partitionPath() ) ); @@ -244,7 +257,9 @@ FillGlobalStorageJob::createBootLoaderMap() const { Partition* partition = KPMHelpers::findPartitionByMountPoint( m_devices, path ); if ( !partition ) + { return QVariant(); + } path = partition->partitionPath(); } map[ "installPath" ] = path; From 29894cec6ae2f21cafe849b940c2b87a5dff4018 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Thu, 13 Feb 2020 11:22:09 +0100 Subject: [PATCH 14/21] [partition] Convenience userVisibleFS() - Mark uses of filesystem-name where it's intentional that they are user-visible, with a new convenience function. --- src/modules/partition/core/KPMHelpers.h | 12 ++++++++++++ src/modules/partition/jobs/CreatePartitionJob.cpp | 13 +++++++++---- src/modules/partition/jobs/FillGlobalStorageJob.cpp | 5 +++-- 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/src/modules/partition/core/KPMHelpers.h b/src/modules/partition/core/KPMHelpers.h index 7ef9718ae..bb510cafb 100644 --- a/src/modules/partition/core/KPMHelpers.h +++ b/src/modules/partition/core/KPMHelpers.h @@ -127,6 +127,18 @@ untranslatedFS( FileSystem* fs ) return fs ? untranslatedFS( *fs ) : QString(); } +static inline QString +userVisibleFS( FileSystem& fs ) +{ + return fs.name(); +} + +static inline QString +userVisibleFS( FileSystem* fs ) +{ + return fs ? userVisibleFS( *fs ) : QString(); +} + } #endif /* KPMHELPERS_H */ diff --git a/src/modules/partition/jobs/CreatePartitionJob.cpp b/src/modules/partition/jobs/CreatePartitionJob.cpp index 9f8a01004..b59bffcdc 100644 --- a/src/modules/partition/jobs/CreatePartitionJob.cpp +++ b/src/modules/partition/jobs/CreatePartitionJob.cpp @@ -2,7 +2,7 @@ * * Copyright 2014, Aurélien Gâteau * Copyright 2015, Teo Mrnjavac - * Copyright 2017, Adriaan de Groot + * Copyright 2017, 2020, 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 @@ -20,6 +20,8 @@ #include "jobs/CreatePartitionJob.h" +#include "core/KPMHelpers.h" + #include "utils/Logger.h" #include "utils/Units.h" @@ -32,6 +34,9 @@ #include #include +using KPMHelpers::untranslatedFS; +using KPMHelpers::userVisibleFS; + CreatePartitionJob::CreatePartitionJob( Device* device, Partition* partition ) : PartitionJob( partition ) , m_device( device ) @@ -42,7 +47,7 @@ QString CreatePartitionJob::prettyName() const { return tr( "Create new %2MiB partition on %4 (%3) with file system %1." ) - .arg( m_partition->fileSystem().name() ) + .arg( userVisibleFS( m_partition->fileSystem() ) .arg( CalamaresUtils::BytesToMiB( m_partition->capacity() ) ) .arg( m_device->name() ) .arg( m_device->deviceNode() ); @@ -54,7 +59,7 @@ CreatePartitionJob::prettyDescription() const { return tr( "Create new %2MiB partition on %4 " "(%3) with file system %1." ) - .arg( m_partition->fileSystem().name() ) + .arg( userVisibleFS( m_partition->fileSystem() ) ) .arg( CalamaresUtils::BytesToMiB( m_partition->capacity() ) ) .arg( m_device->name() ) .arg( m_device->deviceNode() ); @@ -65,7 +70,7 @@ QString CreatePartitionJob::prettyStatusMessage() const { return tr( "Creating new %1 partition on %2." ) - .arg( m_partition->fileSystem().name() ) + .arg( userVisibleFS( m_partition->fileSystem() ) ) .arg( m_device->deviceNode() ); } diff --git a/src/modules/partition/jobs/FillGlobalStorageJob.cpp b/src/modules/partition/jobs/FillGlobalStorageJob.cpp index 7faa4b50f..12faaf969 100644 --- a/src/modules/partition/jobs/FillGlobalStorageJob.cpp +++ b/src/modules/partition/jobs/FillGlobalStorageJob.cpp @@ -42,6 +42,7 @@ #include using KPMHelpers::untranslatedFS; +using KPMHelpers::userVisibleFS; typedef QHash< QString, QString > UuidForPartitionHash; @@ -91,7 +92,7 @@ mapForPartition( Partition* partition, const QString& uuid ) QVariantMap map; map[ "device" ] = partition->partitionPath(); map[ "mountPoint" ] = PartitionInfo::mountPoint( partition ); - map[ "fsName" ] = partition->fileSystem().name(); // User-visible + map[ "fsName" ] = userVisibleFS( partition->fileSystem() ); map[ "fs" ] = untranslatedFS( partition->fileSystem() ); if ( partition->fileSystem().type() == FileSystem::Luks && dynamic_cast< FS::luks& >( partition->fileSystem() ).innerFS() ) @@ -106,7 +107,7 @@ mapForPartition( Partition* partition, const QString& uuid ) using TR = Logger::DebugRow< const char* const, const QString& >; deb << Logger::SubEntry << "mapping for" << partition->partitionPath() << partition->deviceNode() << TR( "mtpoint:", PartitionInfo::mountPoint( partition ) ) << TR( "fs:", map[ "fs" ].toString() ) - << TR( "fsname", map[ "fsName" ].toString() ) << TR( "uuid", uuid ); + << TR( "fsName", map[ "fsName" ].toString() ) << TR( "uuid", uuid ); if ( partition->roles().has( PartitionRole::Luks ) ) { From bacca0469570f7e40bf820a3bdcdc60cbb0f2c0e Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Thu, 13 Feb 2020 11:29:45 +0100 Subject: [PATCH 15/21] [partition] Be explicit about what's user visible in SetPartitionFlagsJob --- .../partition/jobs/SetPartitionFlagsJob.cpp | 29 ++++++++++++------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/src/modules/partition/jobs/SetPartitionFlagsJob.cpp b/src/modules/partition/jobs/SetPartitionFlagsJob.cpp index d79f70479..09380a24c 100644 --- a/src/modules/partition/jobs/SetPartitionFlagsJob.cpp +++ b/src/modules/partition/jobs/SetPartitionFlagsJob.cpp @@ -21,6 +21,8 @@ #include "SetPartitionFlagsJob.h" +#include "core/KPMHelpers.h" + #include "utils/Logger.h" #include "utils/Units.h" @@ -32,6 +34,8 @@ #include using CalamaresUtils::BytesToMiB; +using KPMHelpers::untranslatedFS; +using KPMHelpers::userVisibleFS; SetPartFlagsJob::SetPartFlagsJob( Device* device, Partition* partition, @@ -48,10 +52,11 @@ SetPartFlagsJob::prettyName() const if ( !partition()->partitionPath().isEmpty() ) return tr( "Set flags on partition %1." ).arg( partition()->partitionPath() ); - if ( !partition()->fileSystem().name().isEmpty() ) + QString fsNameForUser = userVisibleFS( partition()->fileSystem() ); + if ( !fsNameForUser.isEmpty() ) return tr( "Set flags on %1MiB %2 partition." ) .arg( BytesToMiB( partition()->capacity() ) ) - .arg( partition()->fileSystem().name() ); + .arg( fsNameForUser ); return tr( "Set flags on new partition." ); } @@ -67,10 +72,11 @@ SetPartFlagsJob::prettyDescription() const return tr( "Clear flags on partition %1." ) .arg( partition()->partitionPath() ); - if ( !partition()->fileSystem().name().isEmpty() ) + QString fsNameForUser = userVisibleFS( partition()->fileSystem() ); + if ( !fsNameForUser.isEmpty() ) return tr( "Clear flags on %1MiB %2 partition." ) .arg( BytesToMiB( partition()->capacity() ) ) - .arg( partition()->fileSystem().name() ); + .arg( fsNameForUser ); return tr( "Clear flags on new partition." ); } @@ -81,11 +87,12 @@ SetPartFlagsJob::prettyDescription() const .arg( partition()->partitionPath() ) .arg( flagsList.join( ", " ) ); - if ( !partition()->fileSystem().name().isEmpty() ) + QString fsNameForUser = userVisibleFS( partition()->fileSystem() ); + if ( !fsNameForUser.isEmpty() ) return tr( "Flag %1MiB %2 partition as " "%3." ) .arg( BytesToMiB( partition()->capacity() ) ) - .arg( partition()->fileSystem().name() ) + .arg( fsNameForUser ) .arg( flagsList.join( ", " ) ); return tr( "Flag new partition as %1." ) @@ -103,10 +110,11 @@ SetPartFlagsJob::prettyStatusMessage() const return tr( "Clearing flags on partition %1." ) .arg( partition()->partitionPath() ); - if ( !partition()->fileSystem().name().isEmpty() ) + QString fsNameForUser = userVisibleFS( partition()->fileSystem() ); + if ( !fsNameForUser.isEmpty() ) return tr( "Clearing flags on %1MiB %2 partition." ) .arg( BytesToMiB( partition()->capacity() ) ) - .arg( partition()->fileSystem().name() ); + .arg( fsNameForUser ); return tr( "Clearing flags on new partition." ); } @@ -117,11 +125,12 @@ SetPartFlagsJob::prettyStatusMessage() const .arg( partition()->partitionPath() ) .arg( flagsList.join( ", " ) ); - if ( !partition()->fileSystem().name().isEmpty() ) + QString fsNameForUser = userVisibleFS( partition()->fileSystem() ); + if ( !fsNameForUser.isEmpty() ) return tr( "Setting flags %3 on " "%1MiB %2 partition." ) .arg( BytesToMiB( partition()->capacity() ) ) - .arg( partition()->fileSystem().name() ) + .arg( fsNameForUser ) .arg( flagsList.join( ", " ) ); return tr( "Setting flags %1 on new partition." ) From 88cff387c307daf88dfb7ba4b090bf0d08c977a2 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Thu, 13 Feb 2020 11:33:40 +0100 Subject: [PATCH 16/21] [partition] Be explicit about user-visible FS names, FormatPartitionJob --- src/modules/partition/jobs/FormatPartitionJob.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/modules/partition/jobs/FormatPartitionJob.cpp b/src/modules/partition/jobs/FormatPartitionJob.cpp index 0d43dfdb3..c877343c3 100644 --- a/src/modules/partition/jobs/FormatPartitionJob.cpp +++ b/src/modules/partition/jobs/FormatPartitionJob.cpp @@ -19,6 +19,8 @@ #include "jobs/FormatPartitionJob.h" +#include "core/KPMHelpers.h" + #include "utils/Logger.h" // KPMcore @@ -29,6 +31,9 @@ #include #include +using KPMHelpers::untranslatedFS; +using KPMHelpers::userVisibleFS; + FormatPartitionJob::FormatPartitionJob( Device* device, Partition* partition ) : PartitionJob( partition ) , m_device( device ) @@ -40,7 +45,7 @@ FormatPartitionJob::prettyName() const { return tr( "Format partition %1 (file system: %2, size: %3 MiB) on %4." ) .arg( m_partition->partitionPath() ) - .arg( m_partition->fileSystem().name() ) + .arg( userVisibleFS( m_partition->fileSystem() ) ) .arg( m_partition->capacity() / 1024 / 1024 ) .arg( m_device->name() ); } @@ -52,7 +57,7 @@ FormatPartitionJob::prettyDescription() const return tr( "Format %3MiB partition %1 with " "file system %2." ) .arg( m_partition->partitionPath() ) - .arg( m_partition->fileSystem().name() ) + .arg( userVisibleFS( m_partition->fileSystem() ) ) .arg( m_partition->capacity() / 1024 / 1024 ); } @@ -63,7 +68,7 @@ FormatPartitionJob::prettyStatusMessage() const return tr( "Formatting partition %1 with " "file system %2." ) .arg( m_partition->partitionPath() ) - .arg( m_partition->fileSystem().name() ); + .arg( userVisibleFS( m_partition->fileSystem() ) ); } From 05dfc24af675d04692148787f526914f7851f506 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Thu, 13 Feb 2020 11:45:04 +0100 Subject: [PATCH 17/21] [partition] Be explicit about user-visible FS names, CreatePartitionDialog --- src/modules/partition/gui/CreatePartitionDialog.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/modules/partition/gui/CreatePartitionDialog.cpp b/src/modules/partition/gui/CreatePartitionDialog.cpp index 7823d743d..b85d3e7e8 100644 --- a/src/modules/partition/gui/CreatePartitionDialog.cpp +++ b/src/modules/partition/gui/CreatePartitionDialog.cpp @@ -2,7 +2,7 @@ * * Copyright 2014, Aurélien Gâteau * Copyright 2016, Teo Mrnjavac - * Copyright 2018, Adriaan de Groot + * Copyright 2018, 2020, Adriaan de Groot * Copyright 2018, Andrius Štikonas * Copyright 2018, Caio Carvalho * @@ -106,7 +106,7 @@ CreatePartitionDialog::CreatePartitionDialog( Device* device, PartitionNode* par if ( fs->supportCreate() != FileSystem::cmdSupportNone && fs->type() != FileSystem::Extended ) { - fsNames << fs->name(); + fsNames << KPMHelpers::userVisibleFS( fs ); // This is put into the combobox if ( fs->type() == defaultFsType ) defaultFsIndex = fsCounter; fsCounter++; @@ -232,6 +232,7 @@ CreatePartitionDialog::updateMountPointUi() bool enabled = m_ui->primaryRadioButton->isChecked(); if ( enabled ) { + // This maps translated (user-visible) FS names to a type FileSystem::Type type = FileSystem::typeForName( m_ui->fsComboBox->currentText() ); enabled = !s_unmountableFS.contains( type ); From 472ec3261774447cdd5c7977b39384bcaebf08e3 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Thu, 13 Feb 2020 11:49:20 +0100 Subject: [PATCH 18/21] [partition] Be explicit about user-visible FS names, ReplaceWidget --- src/modules/partition/gui/ReplaceWidget.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/modules/partition/gui/ReplaceWidget.cpp b/src/modules/partition/gui/ReplaceWidget.cpp index 2ee360ced..3d0711761 100644 --- a/src/modules/partition/gui/ReplaceWidget.cpp +++ b/src/modules/partition/gui/ReplaceWidget.cpp @@ -22,6 +22,7 @@ #include "ui_ReplaceWidget.h" #include "core/DeviceModel.h" +#include "core/KPMHelpers.h" #include "core/PartitionCoreModule.h" #include "core/PartitionActions.h" #include "core/PartitionInfo.h" @@ -192,8 +193,8 @@ ReplaceWidget::onPartitionSelected() return; } - QString prettyName = tr( "Data partition (%1)" ) - .arg( partition->fileSystem().name() ); + QString fsNameForUser = KPMHelpers::userVisibleFS( partition->fileSystem() ); + QString prettyName = tr( "Data partition (%1)" ).arg( fsNameForUser ); for ( const QString& line : osproberLines ) { QStringList lineColumns = line.split( ':' ); @@ -210,13 +211,13 @@ ReplaceWidget::onPartitionSelected() if ( osName.isEmpty() ) { prettyName = tr( "Unknown system partition (%1)" ) - .arg( partition->fileSystem().name() ); + .arg( fsNameForUser ); } else { prettyName = tr ( "%1 system partition (%2)" ) .arg( osName.replace( 0, 1, osName.at( 0 ).toUpper() ) ) - .arg( partition->fileSystem().name() ); + .arg( fsNameForUser ); } break; } From ca67534cd23ab0490fde778e96ae372ead036c5b Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Thu, 13 Feb 2020 13:15:06 +0100 Subject: [PATCH 19/21] [partition] Improve logging of bad configs --- src/modules/partition/gui/PartitionViewStep.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/partition/gui/PartitionViewStep.cpp b/src/modules/partition/gui/PartitionViewStep.cpp index 17ac339e9..1bb7f64fd 100644 --- a/src/modules/partition/gui/PartitionViewStep.cpp +++ b/src/modules/partition/gui/PartitionViewStep.cpp @@ -600,7 +600,7 @@ PartitionViewStep::setConfigurationMap( const QVariantMap& configurationMap ) else if ( fsType != FileSystem::Unknown ) cWarning() << "Partition-module setting *defaultFileSystemType* changed" << fsRealName; else - cWarning() << "Partition-module setting *defaultFileSystemType* is bad (" << fsRealName << ") using ext4."; + cWarning() << "Partition-module setting *defaultFileSystemType* is bad (" << fsName << ") using" << fsRealName << "instead."; gs->insert( "defaultFileSystemType", fsRealName ); From 57b608083e1ab4b0ae79f8fb27bad6f8848d6ba2 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Thu, 13 Feb 2020 13:24:09 +0100 Subject: [PATCH 20/21] [partition] Fix build - missing ) --- src/modules/partition/jobs/CreatePartitionJob.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/partition/jobs/CreatePartitionJob.cpp b/src/modules/partition/jobs/CreatePartitionJob.cpp index b59bffcdc..0f9590bfd 100644 --- a/src/modules/partition/jobs/CreatePartitionJob.cpp +++ b/src/modules/partition/jobs/CreatePartitionJob.cpp @@ -47,7 +47,7 @@ QString CreatePartitionJob::prettyName() const { return tr( "Create new %2MiB partition on %4 (%3) with file system %1." ) - .arg( userVisibleFS( m_partition->fileSystem() ) + .arg( userVisibleFS( m_partition->fileSystem() ) ) .arg( CalamaresUtils::BytesToMiB( m_partition->capacity() ) ) .arg( m_device->name() ) .arg( m_device->deviceNode() ); From 5a50a3a40ca6a4749b7d4e38da6642b03d6dad19 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Thu, 13 Feb 2020 13:24:53 +0100 Subject: [PATCH 21/21] [partition] Consistent FS name usage - explicit use of user-visible names in EditExistingPartitionDialog - consistent conversion of config-values to FS names (user-visible). The GS value comes from the ViewStep, and should always match something -- it's already converted to the canonical un-translated so the type should be good. --- .../partition/gui/CreatePartitionDialog.cpp | 14 +++++-- .../gui/EditExistingPartitionDialog.cpp | 41 +++++++++++-------- 2 files changed, 35 insertions(+), 20 deletions(-) diff --git a/src/modules/partition/gui/CreatePartitionDialog.cpp b/src/modules/partition/gui/CreatePartitionDialog.cpp index b85d3e7e8..926df03a3 100644 --- a/src/modules/partition/gui/CreatePartitionDialog.cpp +++ b/src/modules/partition/gui/CreatePartitionDialog.cpp @@ -93,11 +93,17 @@ CreatePartitionDialog::CreatePartitionDialog( Device* device, PartitionNode* par else initGptPartitionTypeUi(); - // File system - FileSystem::Type defaultFsType = FileSystem::typeForName( + // File system; the config value is translated (best-effort) to a type + FileSystem::Type defaultFSType; + QString untranslatedFSName = PartUtils::findFS( Calamares::JobQueue::instance()-> globalStorage()-> - value( "defaultFileSystemType" ).toString() ); + value( "defaultFileSystemType" ).toString(), &defaultFSType ); + if ( defaultFSType == FileSystem::Type::Unknown ) + { + defaultFSType = FileSystem::Type::Ext4; + } + int defaultFsIndex = -1; int fsCounter = 0; QStringList fsNames; @@ -107,7 +113,7 @@ CreatePartitionDialog::CreatePartitionDialog( Device* device, PartitionNode* par fs->type() != FileSystem::Extended ) { fsNames << KPMHelpers::userVisibleFS( fs ); // This is put into the combobox - if ( fs->type() == defaultFsType ) + if ( fs->type() == defaultFSType ) defaultFsIndex = fsCounter; fsCounter++; } diff --git a/src/modules/partition/gui/EditExistingPartitionDialog.cpp b/src/modules/partition/gui/EditExistingPartitionDialog.cpp index 3ad5080b4..6268a2a22 100644 --- a/src/modules/partition/gui/EditExistingPartitionDialog.cpp +++ b/src/modules/partition/gui/EditExistingPartitionDialog.cpp @@ -2,7 +2,7 @@ * * Copyright 2014, Aurélien Gâteau * Copyright 2016, Teo Mrnjavac - * Copyright 2018, Adriaan de Groot + * Copyright 2018, 2020, Adriaan de Groot * * Flags handling originally from KDE Partition Manager, * Copyright 2008-2009, Volker Lanz @@ -22,21 +22,21 @@ * along with Calamares. If not, see . */ -#include +#include "EditExistingPartitionDialog.h" -#include -#include -#include +#include "core/ColorUtils.h" +#include "core/PartitionCoreModule.h" +#include "core/PartitionInfo.h" #include "core/PartUtils.h" -#include +#include "core/KPMHelpers.h" #include "gui/PartitionDialogHelpers.h" -#include +#include "gui/PartitionSizeController.h" -#include +#include "ui_EditExistingPartitionDialog.h" -#include #include "GlobalStorage.h" #include "JobQueue.h" +#include "utils/Logger.h" // KPMcore #include @@ -77,7 +77,7 @@ EditExistingPartitionDialog::EditExistingPartitionDialog( Device* device, Partit m_ui->fileSystemComboBox->setEnabled( doFormat ); if ( !doFormat ) - m_ui->fileSystemComboBox->setCurrentText( m_partition->fileSystem().name() ); + m_ui->fileSystemComboBox->setCurrentText( KPMHelpers::userVisibleFS( m_partition->fileSystem() ) ); updateMountPointPicker(); } ); @@ -93,16 +93,25 @@ EditExistingPartitionDialog::EditExistingPartitionDialog( Device* device, Partit for ( auto fs : FileSystemFactory::map() ) { if ( fs->supportCreate() != FileSystem::cmdSupportNone && fs->type() != FileSystem::Extended ) - fsNames << fs->name(); + fsNames << KPMHelpers::userVisibleFS( fs ); // For the combo box } m_ui->fileSystemComboBox->addItems( fsNames ); - if ( fsNames.contains( m_partition->fileSystem().name() ) ) - m_ui->fileSystemComboBox->setCurrentText( m_partition->fileSystem().name() ); + FileSystem::Type defaultFSType; + QString untranslatedFSName = PartUtils::findFS( + Calamares::JobQueue::instance()-> + globalStorage()-> + value( "defaultFileSystemType" ).toString(), &defaultFSType ); + if ( defaultFSType == FileSystem::Type::Unknown ) + { + defaultFSType = FileSystem::Type::Ext4; + } + + QString thisFSNameForUser = KPMHelpers::userVisibleFS( m_partition->fileSystem() ); + if ( fsNames.contains( thisFSNameForUser ) ) + m_ui->fileSystemComboBox->setCurrentText( thisFSNameForUser ); else - m_ui->fileSystemComboBox->setCurrentText( Calamares::JobQueue::instance()-> - globalStorage()-> - value( "defaultFileSystemType" ).toString() ); + m_ui->fileSystemComboBox->setCurrentText( FileSystem::nameForType( defaultFSType ) ); m_ui->fileSystemLabel->setEnabled( m_ui->formatRadioButton->isChecked() ); m_ui->fileSystemComboBox->setEnabled( m_ui->formatRadioButton->isChecked() );