From e2b71e669e54ef42293c6778801550a720dededa Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 28 May 2019 16:29:45 +0200 Subject: [PATCH 01/19] [partition] When running UNSAFE, no-install-partition is a warning --- src/modules/partition/gui/PartitionViewStep.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/modules/partition/gui/PartitionViewStep.cpp b/src/modules/partition/gui/PartitionViewStep.cpp index 2e186b3a8..8d82f65c9 100644 --- a/src/modules/partition/gui/PartitionViewStep.cpp +++ b/src/modules/partition/gui/PartitionViewStep.cpp @@ -638,7 +638,11 @@ PartitionViewStep::checkRequirements() []{ return tr( "has at least one disk device available." ); }, []{ return tr( "There are no partitons to install on." ); }, m_core->deviceModel()->rowCount() > 0, // satisfied - true // required +#ifdef DEBUG_PARTITION_UNSAFE + false // optional +#else + true // required +#endif } ); return l; From 8d451622db340250d6d96cd95feca5e12632a5ec Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 28 May 2019 16:39:00 +0200 Subject: [PATCH 02/19] [partition] Idiomatic use of Calamares::JobList --- src/modules/partition/core/PartitionCoreModule.cpp | 6 +++--- src/modules/partition/core/PartitionCoreModule.h | 2 +- src/modules/partition/gui/PartitionViewStep.cpp | 2 +- src/modules/partition/gui/PartitionViewStep.h | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/modules/partition/core/PartitionCoreModule.cpp b/src/modules/partition/core/PartitionCoreModule.cpp index 6dd2b6faf..b098c6ea0 100644 --- a/src/modules/partition/core/PartitionCoreModule.cpp +++ b/src/modules/partition/core/PartitionCoreModule.cpp @@ -402,7 +402,7 @@ PartitionCoreModule::deletePartition( Device* device, Partition* partition ) deletePartition( device, childPartition ); } - QList< Calamares::job_ptr >& jobs = deviceInfo->jobs; + Calamares::JobList& jobs = deviceInfo->jobs; if ( partition->state() == KPM_PARTITION_STATE(New) ) { // First remove matching SetPartFlagsJobs @@ -496,10 +496,10 @@ PartitionCoreModule::setPartitionFlags( Device* device, PartitionInfo::setFlags( partition, flags ); } -QList< Calamares::job_ptr > +Calamares::JobList PartitionCoreModule::jobs() const { - QList< Calamares::job_ptr > lst; + Calamares::JobList lst; QList< Device* > devices; #ifdef DEBUG_PARTITION_UNSAFE diff --git a/src/modules/partition/core/PartitionCoreModule.h b/src/modules/partition/core/PartitionCoreModule.h index 906119a74..7faf67863 100644 --- a/src/modules/partition/core/PartitionCoreModule.h +++ b/src/modules/partition/core/PartitionCoreModule.h @@ -247,7 +247,7 @@ private: QScopedPointer< Device > device; QScopedPointer< PartitionModel > partitionModel; const QScopedPointer< Device > immutableDevice; - QList< Calamares::job_ptr > jobs; + Calamares::JobList jobs; // To check if LVM VGs are deactivated bool isAvailable; diff --git a/src/modules/partition/gui/PartitionViewStep.cpp b/src/modules/partition/gui/PartitionViewStep.cpp index 8d82f65c9..58fa17674 100644 --- a/src/modules/partition/gui/PartitionViewStep.cpp +++ b/src/modules/partition/gui/PartitionViewStep.cpp @@ -619,7 +619,7 @@ PartitionViewStep::setConfigurationMap( const QVariantMap& configurationMap ) } -QList< Calamares::job_ptr > +Calamares::JobList PartitionViewStep::jobs() const { return m_core->jobs(); diff --git a/src/modules/partition/gui/PartitionViewStep.h b/src/modules/partition/gui/PartitionViewStep.h index 47f8fa127..e3d058e67 100644 --- a/src/modules/partition/gui/PartitionViewStep.h +++ b/src/modules/partition/gui/PartitionViewStep.h @@ -69,7 +69,7 @@ public: void setConfigurationMap( const QVariantMap& configurationMap ) override; - QList< Calamares::job_ptr > jobs() const override; + Calamares::JobList jobs() const override; Calamares::RequirementsList checkRequirements() override; From b9686a8a8440084ffa20bdc5441a8af05558817d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philip=20M=C3=BCller?= Date: Thu, 30 May 2019 13:40:42 +0200 Subject: [PATCH 03/19] [Authors] Philip only needs to be listed once I don't need to be listed more then one time ;) --- AUTHORS | 2 -- 1 file changed, 2 deletions(-) diff --git a/AUTHORS b/AUTHORS index e9ae34dcf..9bedcede6 100644 --- a/AUTHORS +++ b/AUTHORS @@ -36,8 +36,6 @@ and moral support from (alphabetically by first name or nickname): - Kyle Robertze - Lisa Vitolo - n3rdopolis - - Phil Mueller - - Philip Mueller - Philip Müller - Ramon Buldó - Raul Rodrigo Segura From a2e54fcf65175006da5fc39fae5fdb7207fd7325 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 28 May 2019 17:16:00 +0200 Subject: [PATCH 04/19] Changes: prep for release --- CHANGES | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGES b/CHANGES index 6de55bff7..e18d3f7e4 100644 --- a/CHANGES +++ b/CHANGES @@ -10,6 +10,9 @@ This release contains contributions from (alphabetically by first name): ## Core ## +No user- or deployer-visible changes. Bugfixing as usual, see the +milestone for details. + ## Modules ## - *branding* now supports os-release variables in the *strings* section, @@ -20,6 +23,7 @@ This release contains contributions from (alphabetically by first name): the file is used, and otherwise the icon is looked up in the current theme. + # 3.2.8 (2019-05-10) # This is a **source-incompatible** release of Calamares. Include files From 0ebabfafd4fe37efbc5ae76eebc548f838e1a433 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 28 May 2019 17:01:58 +0200 Subject: [PATCH 05/19] [partition] Move BootLoaderModel convenience functions - These were hidden inside PartitionPage, but are useful elsewhere. --- .../partition/core/BootLoaderModel.cpp | 49 +++++++++++++++++++ src/modules/partition/core/BootLoaderModel.h | 17 +++++++ src/modules/partition/gui/PartitionPage.cpp | 37 +------------- 3 files changed, 67 insertions(+), 36 deletions(-) diff --git a/src/modules/partition/core/BootLoaderModel.cpp b/src/modules/partition/core/BootLoaderModel.cpp index 16c6ce3c8..eeec12b78 100644 --- a/src/modules/partition/core/BootLoaderModel.cpp +++ b/src/modules/partition/core/BootLoaderModel.cpp @@ -23,9 +23,13 @@ #include "core/PartitionInfo.h" #include "core/KPMHelpers.h" +#include "utils/Logger.h" + // KPMcore #include +#include + static QStandardItem* createBootLoaderItem( const QString& description, const QString& path, bool isPartition ) { @@ -148,3 +152,48 @@ BootLoaderModel::data( const QModelIndex& index, int role ) const } return QStandardItemModel::data( index, role ); } + +namespace Calamares +{ +int +findBootloader( const QAbstractItemModel* model, const QString& path ) +{ + for ( int i = 0; i < model->rowCount(); ++i) + { + const auto index = model->index( i, 0, QModelIndex() ); + if ( !index.isValid() ) + continue; + QVariant var = model->data( index, BootLoaderModel::BootLoaderPathRole ); + if ( var.isValid() && var.toString() == path ) + return i; + } + + return -1; +} + +void +restoreSelectedBootLoader( QComboBox& combo, const QString& path ) +{ + const auto* model = combo.model(); + if ( model->rowCount() < 1 ) + { + cDebug() << "No items in BootLoaderModel"; + return; + } + + int r = -1; + if ( path.isEmpty() ) + { + combo.setCurrentIndex( 0 ); + } + else if ( (r = findBootloader( model, path )) >= 0 ) + { + combo.setCurrentIndex( r ); + } + else + { + combo.setCurrentIndex( 0 ); + } +} + +} // namespace diff --git a/src/modules/partition/core/BootLoaderModel.h b/src/modules/partition/core/BootLoaderModel.h index fbbb9deb2..a2befad00 100644 --- a/src/modules/partition/core/BootLoaderModel.h +++ b/src/modules/partition/core/BootLoaderModel.h @@ -25,6 +25,7 @@ #include class Device; +class QComboBox; /** * This model contains one entry for each device MBR plus one entry for the @@ -63,4 +64,20 @@ private: void updateInternal(); }; +namespace Calamares +{ + /** @brief Returns the row number of boot-loader @p path (e.g. /dev/sda) + * + * Assuming the @p model is a BootLoaderModel, will return a row number + * in the model. Returns -1 otherwise. + */ + int findBootloader( const QAbstractItemModel* model, const QString& path ); + + /** @brief Tries to set @p path as selected item in @p combo + * + * Matches a boot-loader install path (e.g. /dev/sda) with a model + * row and sets that as the current row. + */ + void restoreSelectedBootLoader( QComboBox& combo, const QString& path ); +} // namespace #endif /* BOOTLOADERMODEL_H */ diff --git a/src/modules/partition/gui/PartitionPage.cpp b/src/modules/partition/gui/PartitionPage.cpp index 647a69d5d..3c2ffbdd0 100644 --- a/src/modules/partition/gui/PartitionPage.cpp +++ b/src/modules/partition/gui/PartitionPage.cpp @@ -511,45 +511,10 @@ PartitionPage::updateSelectedBootLoaderIndex() cDebug() << "Selected bootloader index" << m_lastSelectedBootLoaderIndex; } -int -findBootloader( const QAbstractItemModel* model, const QString& path ) -{ - for ( int i = 0; i < model->rowCount(); ++i) - { - const auto index = model->index( i, 0, QModelIndex() ); - if ( !index.isValid() ) - continue; - QVariant var = model->data( index, BootLoaderModel::BootLoaderPathRole ); - if ( var.isValid() && var.toString() == path ) - return i; - } - - return -1; -} - void PartitionPage::restoreSelectedBootLoader() { - const auto* model = m_ui->bootLoaderComboBox->model(); - if ( model->rowCount() < 1 ) - { - cDebug() << "No items in BootLoaderModel"; - return; - } - - int r = -1; - if ( m_core->bootLoaderInstallPath().isEmpty() ) - { - m_ui->bootLoaderComboBox->setCurrentIndex( 0 ); - } - else if ( (r = findBootloader( model, m_core->bootLoaderInstallPath() )) >= 0 ) - { - m_ui->bootLoaderComboBox->setCurrentIndex( r ); - } - else - { - m_ui->bootLoaderComboBox->setCurrentIndex( 0 ); - } + Calamares::restoreSelectedBootLoader( *(m_ui->bootLoaderComboBox), m_core->bootLoaderInstallPath() ); } From f1f5b6c1bb414bc993a7747dcd40d036ee16d102 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 28 May 2019 17:09:59 +0200 Subject: [PATCH 06/19] [partition] Restore BootLoader path in Choice Page - after model resets, restore what was previously selected. - This avoids having an **empty** combobox, SEE #1141 but does not actually set it back to the value the user had previously picked (e.g. changing swap settings **still** breaks the selection). --- src/modules/partition/gui/ChoicePage.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/modules/partition/gui/ChoicePage.cpp b/src/modules/partition/gui/ChoicePage.cpp index 04eec56ed..d9fb89b3f 100644 --- a/src/modules/partition/gui/ChoicePage.cpp +++ b/src/modules/partition/gui/ChoicePage.cpp @@ -1025,6 +1025,12 @@ ChoicePage::updateActionChoicePreview( ChoicePage::InstallChoice choice ) eraseBootloaderLabel->setText( tr( "Boot loader location:" ) ); m_bootloaderComboBox = createBootloaderComboBox( eraseWidget ); + connect( m_core->bootLoaderModel(), &QAbstractItemModel::modelReset, + [ this ]() + { + Calamares::restoreSelectedBootLoader( *m_bootloaderComboBox, m_core->bootLoaderInstallPath() ); + } + ); connect( m_core, &PartitionCoreModule::deviceReverted, this, [ this ]( Device* dev ) { From 2bc95d11d38d5f04cf0ff61497536b22c5da0e8f Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 28 May 2019 16:47:09 +0200 Subject: [PATCH 07/19] [partition] Unrelated typo in comment --- src/modules/partition/gui/PartitionPage.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/partition/gui/PartitionPage.cpp b/src/modules/partition/gui/PartitionPage.cpp index 3c2ffbdd0..915f899b2 100644 --- a/src/modules/partition/gui/PartitionPage.cpp +++ b/src/modules/partition/gui/PartitionPage.cpp @@ -219,7 +219,7 @@ PartitionPage::onNewPartitionTableClicked() m_core->createPartitionTable( device, type ); } delete dlg; - // PartionModelReset isn't emmited after createPartitionTable, so we have to manually update + // PartionModelReset isn't emitted after createPartitionTable, so we have to manually update // the bootLoader index after the reset. updateBootLoaderIndex(); } From 353e713f8146b25b9553d0aece2b85de957ddea8 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Fri, 31 May 2019 10:41:50 +0200 Subject: [PATCH 08/19] [partition] Complain loudly on dangling Partition pointers - Don't crash if a bad pointer gets into colorutils. --- src/modules/partition/core/ColorUtils.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/modules/partition/core/ColorUtils.cpp b/src/modules/partition/core/ColorUtils.cpp index 40f65d2ba..ffe45d443 100644 --- a/src/modules/partition/core/ColorUtils.cpp +++ b/src/modules/partition/core/ColorUtils.cpp @@ -22,6 +22,8 @@ #include "core/KPMHelpers.h" #include "core/PartitionIterator.h" +#include "utils/Logger.h" + // KPMcore #include #include @@ -81,6 +83,12 @@ _findRootForPartition( PartitionNode* partition ) QColor colorForPartition( Partition* partition ) { + if ( !partition ) + { + cWarning() << "NULL partition"; + return FREE_SPACE_COLOR; + } + if ( KPMHelpers::isPartitionFreeSpace( partition ) ) return FREE_SPACE_COLOR; if ( partition->roles().has( PartitionRole::Extended ) ) From 2ce2b080274e0f73a48ab361cc3ab27ff6fb2af8 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Fri, 31 May 2019 10:48:57 +0200 Subject: [PATCH 09/19] [partition] Indent lambdas to tab-stop. - Lambdas are all over the place in this codebase, formulate a standard and start adjusting code to it in passing. --- ci/HACKING.md | 2 + src/modules/partition/gui/ChoicePage.cpp | 55 ++++++++++++------------ 2 files changed, 29 insertions(+), 28 deletions(-) diff --git a/ci/HACKING.md b/ci/HACKING.md index ca3901f07..f2e6308d1 100644 --- a/ci/HACKING.md +++ b/ci/HACKING.md @@ -60,6 +60,8 @@ some PEP8 guidelines. * Function and class definitions have their braces on separate lines. * A function implementation's return type is on its own line. * `CamelCase.{cpp,h}` style file names. +* Lambdas are preferrably indented to a 4-space tab, even when passed as an + argument to functions. Example: ``` diff --git a/src/modules/partition/gui/ChoicePage.cpp b/src/modules/partition/gui/ChoicePage.cpp index d9fb89b3f..3a2b0c4bc 100644 --- a/src/modules/partition/gui/ChoicePage.cpp +++ b/src/modules/partition/gui/ChoicePage.cpp @@ -960,19 +960,18 @@ ChoicePage::updateActionChoicePreview( ChoicePage::InstallChoice choice ) QLabel* sizeLabel = new QLabel( m_previewAfterFrame ); layout->addWidget( sizeLabel ); sizeLabel->setWordWrap( true ); - connect( m_afterPartitionSplitterWidget, &PartitionSplitterWidget::partitionResized, - this, [ this, sizeLabel ]( const QString& path, - qint64 size, - qint64 sizeNext ) - { - Q_UNUSED( path ) - sizeLabel->setText( tr( "%1 will be shrunk to %2MiB and a new " - "%3MiB partition will be created for %4." ) - .arg( m_beforePartitionBarsView->selectionModel()->currentIndex().data().toString() ) - .arg( CalamaresUtils::BytesToMiB( size ) ) - .arg( CalamaresUtils::BytesToMiB( sizeNext ) ) - .arg( *Calamares::Branding::ShortProductName ) ); - } ); + connect( m_afterPartitionSplitterWidget, &PartitionSplitterWidget::partitionResized, this, + [ this, sizeLabel ]( const QString& path, qint64 size, qint64 sizeNext ) + { + Q_UNUSED( path ) + sizeLabel->setText( tr( "%1 will be shrunk to %2MiB and a new " + "%3MiB partition will be created for %4." ) + .arg( m_beforePartitionBarsView->selectionModel()->currentIndex().data().toString() ) + .arg( CalamaresUtils::BytesToMiB( size ) ) + .arg( CalamaresUtils::BytesToMiB( sizeNext ) ) + .arg( *Calamares::Branding::ShortProductName ) ); + } + ); m_previewAfterFrame->show(); m_previewAfterLabel->show(); @@ -1026,23 +1025,23 @@ ChoicePage::updateActionChoicePreview( ChoicePage::InstallChoice choice ) m_bootloaderComboBox = createBootloaderComboBox( eraseWidget ); connect( m_core->bootLoaderModel(), &QAbstractItemModel::modelReset, - [ this ]() - { - Calamares::restoreSelectedBootLoader( *m_bootloaderComboBox, m_core->bootLoaderInstallPath() ); - } - ); - connect( m_core, &PartitionCoreModule::deviceReverted, - this, [ this ]( Device* dev ) - { - Q_UNUSED( dev ) - if ( !m_bootloaderComboBox.isNull() ) + [ this ]() { - if ( m_bootloaderComboBox->model() != m_core->bootLoaderModel() ) - m_bootloaderComboBox->setModel( m_core->bootLoaderModel() ); - - m_bootloaderComboBox->setCurrentIndex( m_lastSelectedDeviceIndex ); + Calamares::restoreSelectedBootLoader( *m_bootloaderComboBox, m_core->bootLoaderInstallPath() ); } - }, Qt::QueuedConnection ); + ); + connect( m_core, &PartitionCoreModule::deviceReverted, this, + [ this ]( Device* dev ) + { + Q_UNUSED( dev ) + if ( !m_bootloaderComboBox.isNull() ) + { + if ( m_bootloaderComboBox->model() != m_core->bootLoaderModel() ) + m_bootloaderComboBox->setModel( m_core->bootLoaderModel() ); + + m_bootloaderComboBox->setCurrentIndex( m_lastSelectedDeviceIndex ); + } + }, Qt::QueuedConnection ); // ^ Must be Queued so it's sure to run when the widget is already visible. eraseLayout->addWidget( m_bootloaderComboBox ); From 3bdbfe6bff5996ed3ffa93a646582c3077f0f689 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Fri, 31 May 2019 10:56:01 +0200 Subject: [PATCH 10/19] [partition] Avoid crash if combobox is gone and model resets - Since the lambda is connected to the model only, it should check that the target combo exists as well. --- src/modules/partition/gui/ChoicePage.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/modules/partition/gui/ChoicePage.cpp b/src/modules/partition/gui/ChoicePage.cpp index 3a2b0c4bc..5e8260dec 100644 --- a/src/modules/partition/gui/ChoicePage.cpp +++ b/src/modules/partition/gui/ChoicePage.cpp @@ -1027,7 +1027,8 @@ ChoicePage::updateActionChoicePreview( ChoicePage::InstallChoice choice ) connect( m_core->bootLoaderModel(), &QAbstractItemModel::modelReset, [ this ]() { - Calamares::restoreSelectedBootLoader( *m_bootloaderComboBox, m_core->bootLoaderInstallPath() ); + if ( !m_bootloaderComboBox.isNull() ) + Calamares::restoreSelectedBootLoader( *m_bootloaderComboBox, m_core->bootLoaderInstallPath() ); } ); connect( m_core, &PartitionCoreModule::deviceReverted, this, From d5f0bdd28c5d906b2452dd04f5b963a7d9e3dfde Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Fri, 31 May 2019 11:37:14 +0200 Subject: [PATCH 11/19] [partition] Simplify negative logic - Instead of multiple continue statements to avoid negative cases, state the one positive case instead. --- src/modules/partition/core/PartitionCoreModule.cpp | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/modules/partition/core/PartitionCoreModule.cpp b/src/modules/partition/core/PartitionCoreModule.cpp index b098c6ea0..4b23c86e4 100644 --- a/src/modules/partition/core/PartitionCoreModule.cpp +++ b/src/modules/partition/core/PartitionCoreModule.cpp @@ -947,12 +947,7 @@ PartitionCoreModule::revertDevice( Device* dev, bool individualRevert ) QList< Device* > devices; for ( DeviceInfo* const info : m_deviceInfos ) { - // device is a QScopedPointer - if ( !info || info->device.isNull() ) - continue; - if ( info->device->type() != Device::Type::Disk_Device ) - continue; - else + if ( info && !info->device.isNull() && info->device->type() == Device::Type::Disk_Device ) devices.append( info->device.data() ); } From 4a6b9f35281159e9afc9c89682d4d30f94d77d5d Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Fri, 31 May 2019 11:47:32 +0200 Subject: [PATCH 12/19] [partition] Call update from init() in BootLoaderModel - update() (might) add some extra rows for boot and root, which otherwise vanish temporarily when calling init. --- src/modules/partition/core/BootLoaderModel.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/modules/partition/core/BootLoaderModel.cpp b/src/modules/partition/core/BootLoaderModel.cpp index eeec12b78..e785050d2 100644 --- a/src/modules/partition/core/BootLoaderModel.cpp +++ b/src/modules/partition/core/BootLoaderModel.cpp @@ -51,12 +51,12 @@ BootLoaderModel::~BootLoaderModel() void BootLoaderModel::init( const QList< Device* >& devices ) { + cDebug() << "BLM::init with" << devices.count() << "devices" << rowCount() << "rows"; beginResetModel(); blockSignals( true ); m_devices = devices; - clear(); - createMbrItems(); + updateInternal(); blockSignals( false ); endResetModel(); @@ -78,6 +78,7 @@ BootLoaderModel::createMbrItems() void BootLoaderModel::update() { + cDebug() << "BLM::update holds" << m_devices.count() << "devices" << rowCount() << "rows"; beginResetModel(); blockSignals( true ); updateInternal(); From a263381996aa5cce60034797b64fd64a9c5b956d Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Fri, 31 May 2019 12:27:32 +0200 Subject: [PATCH 13/19] [partition] Avoid an assert when running Calamares as user. --- src/modules/partition/core/BootLoaderModel.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/modules/partition/core/BootLoaderModel.cpp b/src/modules/partition/core/BootLoaderModel.cpp index e785050d2..7f5a0427a 100644 --- a/src/modules/partition/core/BootLoaderModel.cpp +++ b/src/modules/partition/core/BootLoaderModel.cpp @@ -94,6 +94,10 @@ BootLoaderModel::updateInternal() clear(); createMbrItems(); + // An empty model is possible if you don't havee permissions: don't crash though. + if ( rowCount() < 1 ) + return; + QString partitionText; Partition* partition = KPMHelpers::findPartitionByMountPoint( m_devices, "/boot" ); if ( partition ) From 69dabcae32b952d2d5092f038257854a232e54a4 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Fri, 31 May 2019 12:38:34 +0200 Subject: [PATCH 14/19] [libcalamares] Avoid static destructor - The static destructor issues a warning on exit: QBasicTimer::start: QBasicTimer can only be used with threads started with QThread so instead, heap-allocate the model. This leaks memory, but it's a singleton *and* we're exiting anyway. --- src/libcalamares/locale/LabelModel.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libcalamares/locale/LabelModel.cpp b/src/libcalamares/locale/LabelModel.cpp index ef8ff8ea1..79ff5d67b 100644 --- a/src/libcalamares/locale/LabelModel.cpp +++ b/src/libcalamares/locale/LabelModel.cpp @@ -125,8 +125,8 @@ LabelModel::find( const QString& countryCode ) const LabelModel* availableTranslations() { - static LabelModel model( QString( CALAMARES_TRANSLATION_LANGUAGES ).split( ';') ); - return &model; + static LabelModel* model = new LabelModel( QString( CALAMARES_TRANSLATION_LANGUAGES ).split( ';') ); + return model; } } From 1438729b727d9fd5b805dfc86e695b01b418e30e Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Fri, 31 May 2019 17:06:35 +0200 Subject: [PATCH 15/19] [libcalamaresui] Do filename checks more sanely - check directory exists before trying to open file from it - re-use the componentDir already found for later tests. --- src/libcalamaresui/Branding.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/libcalamaresui/Branding.cpp b/src/libcalamaresui/Branding.cpp index 4dc07ff19..4e573e091 100644 --- a/src/libcalamaresui/Branding.cpp +++ b/src/libcalamaresui/Branding.cpp @@ -129,16 +129,16 @@ Branding::Branding( const QString& brandingFilePath, , m_welcomeExpandingLogo( true ) { cDebug() << "Using Calamares branding file at" << brandingFilePath; + + QDir componentDir( componentDirectory() ); + if ( !componentDir.exists() ) + bail( "Bad component directory path." ); + QFile file( brandingFilePath ); if ( file.exists() && file.open( QFile::ReadOnly | QFile::Text ) ) { QByteArray ba = file.readAll(); - QFileInfo fi ( m_descriptorPath ); - QDir componentDir = fi.absoluteDir(); - if ( !componentDir.exists() ) - bail( "Bad component directory path." ); - try { YAML::Node doc = YAML::Load( ba.constData() ); @@ -146,7 +146,7 @@ Branding::Branding( const QString& brandingFilePath, m_componentName = QString::fromStdString( doc[ "componentName" ] .as< std::string >() ); - if ( m_componentName != QFileInfo( m_descriptorPath ).absoluteDir().dirName() ) + if ( m_componentName != componentDir.dirName() ) bail( "The branding component name should match the name of the " "component directory." ); From 75ce391e7e158eae620fef64738d68e35723dfb6 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Fri, 31 May 2019 17:22:03 +0200 Subject: [PATCH 16/19] [libcalamaresui] Add branding-aware function for loading image by name --- src/libcalamaresui/Branding.cpp | 17 +++++++++++++++++ src/libcalamaresui/Branding.h | 10 ++++++++++ 2 files changed, 27 insertions(+) diff --git a/src/libcalamaresui/Branding.cpp b/src/libcalamaresui/Branding.cpp index 4e573e091..48917f1ba 100644 --- a/src/libcalamaresui/Branding.cpp +++ b/src/libcalamaresui/Branding.cpp @@ -186,6 +186,7 @@ Branding::Branding( const QString& brandingFilePath, loadStrings( m_images, doc, "images", [&]( const QString& s ) -> QString { + // See also image() const QString imageName( expand( s ) ); QFileInfo imageFi( componentDir.absoluteFilePath( imageName ) ); if ( !imageFi.exists() ) @@ -314,6 +315,22 @@ Branding::image( Branding::ImageEntry imageEntry, const QSize& size ) const } } +QPixmap +Branding::image(const QString& imageName, const QSize& size) const +{ + QDir componentDir( componentDirectory() ); + QFileInfo imageFi( componentDir.absoluteFilePath( imageName ) ); + if ( !imageFi.exists() ) + { + const auto icon = QIcon::fromTheme( imageName ); + // Not found, bail out with the filename used + if ( icon.isNull() ) + return QPixmap(); + return icon.pixmap( size ); + } + return ImageRegistry::instance()->pixmap( imageFi.absoluteFilePath(), size ); +} + QString Branding::stylesheet() const { diff --git a/src/libcalamaresui/Branding.h b/src/libcalamaresui/Branding.h index 00174f604..23a7a7a49 100644 --- a/src/libcalamaresui/Branding.h +++ b/src/libcalamaresui/Branding.h @@ -123,6 +123,16 @@ public: QString styleString( Branding::StyleEntry styleEntry ) const; QString imagePath( Branding::ImageEntry imageEntry ) const; QPixmap image( Branding::ImageEntry imageEntry, const QSize& size ) const; + + /** @brief Look up an image in the branding directory or as an icon + * + * The @p name is checked in the branding directory: if it is an image + * file, return the pixmap from that file, at the requested size. + * If it isn't a file, look it up as an icon name in the current theme. + * May return a null pixmap if nothing is found. + */ + QPixmap image( const QString& name, const QSize& size ) const; + /** @brief Stylesheet to apply for this branding. May be empty. * * The file is loaded every time this function is called, so From 07c638ed48b8b3e99333eb59f9a02ac3faf09386 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Fri, 31 May 2019 16:59:38 +0200 Subject: [PATCH 17/19] [welcome] Allow theming the international language-select icon --- src/modules/welcome/WelcomePage.cpp | 6 ++++++ src/modules/welcome/WelcomePage.h | 2 ++ src/modules/welcome/WelcomePage.ui | 2 +- src/modules/welcome/WelcomeViewStep.cpp | 9 +++++++++ src/modules/welcome/welcome.conf | 13 +++++++++++++ 5 files changed, 31 insertions(+), 1 deletion(-) diff --git a/src/modules/welcome/WelcomePage.cpp b/src/modules/welcome/WelcomePage.cpp index ae78aa8ff..66429ec07 100644 --- a/src/modules/welcome/WelcomePage.cpp +++ b/src/modules/welcome/WelcomePage.cpp @@ -270,6 +270,12 @@ WelcomePage::externallySelectedLanguage( int row ) ui->languageWidget->setCurrentIndex( row ); } +void +WelcomePage::setLanguageIcon( QIcon i ) +{ + ui->languageIcon->setPixmap( i.pixmap(48) ); +} + void LocaleTwoColumnDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const diff --git a/src/modules/welcome/WelcomePage.h b/src/modules/welcome/WelcomePage.h index f05426d38..ec9044a68 100644 --- a/src/modules/welcome/WelcomePage.h +++ b/src/modules/welcome/WelcomePage.h @@ -42,6 +42,8 @@ public: void setUpLinks( bool showSupportUrl, bool showKnownIssuesUrl, bool showReleaseNotesUrl ); + /// @brief Set international language-selector icon + void setLanguageIcon( QIcon ); /// @brief Results of requirements checking bool verdict() const; diff --git a/src/modules/welcome/WelcomePage.ui b/src/modules/welcome/WelcomePage.ui index 51fa19c04..548bd5d27 100644 --- a/src/modules/welcome/WelcomePage.ui +++ b/src/modules/welcome/WelcomePage.ui @@ -67,7 +67,7 @@ - + Select language diff --git a/src/modules/welcome/WelcomeViewStep.cpp b/src/modules/welcome/WelcomeViewStep.cpp index e115565b7..0f18cfa2d 100644 --- a/src/modules/welcome/WelcomeViewStep.cpp +++ b/src/modules/welcome/WelcomeViewStep.cpp @@ -137,6 +137,15 @@ WelcomeViewStep::setConfigurationMap( const QVariantMap& configurationMap ) } ); future->setFuture( handler->queryRaw() ); } + + + QString language = CalamaresUtils::getString( configurationMap, "languageIcon" ); + if ( !language.isEmpty() ) + { + auto icon = QIcon::fromTheme( language ); + if ( !icon.isNull() ) + m_widget->setLanguageIcon( icon ); + } } Calamares::RequirementsList diff --git a/src/modules/welcome/welcome.conf b/src/modules/welcome/welcome.conf index 32b026085..a89b63854 100644 --- a/src/modules/welcome/welcome.conf +++ b/src/modules/welcome/welcome.conf @@ -64,3 +64,16 @@ geoip: style: "none" url: "https://geoip.kde.org/v1/ubiquity" # extended XML format selector: "CountryCode" # blank uses default, which is wrong + +# User interface +# +# The "select language" icon is an international standard, but it +# might not theme very well with your desktop environment. +# Fill in an icon name (following FreeDesktop standards) to +# use that named icon instead of the usual one. +# +# Leave blank or unset to use the international standard. +# +# Known icons in this space are "set-language" and "config-language". +# +# languageIcon: set-language From f54b7dee9f4a88856fc8f0ec584e4d6c25774edb Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Fri, 31 May 2019 17:26:30 +0200 Subject: [PATCH 18/19] [welcome] Use convenience image loader from Branding --- src/modules/welcome/WelcomePage.cpp | 4 ++-- src/modules/welcome/WelcomePage.h | 2 +- src/modules/welcome/WelcomeViewStep.cpp | 6 ++++-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/modules/welcome/WelcomePage.cpp b/src/modules/welcome/WelcomePage.cpp index 66429ec07..b29b2e23e 100644 --- a/src/modules/welcome/WelcomePage.cpp +++ b/src/modules/welcome/WelcomePage.cpp @@ -271,9 +271,9 @@ WelcomePage::externallySelectedLanguage( int row ) } void -WelcomePage::setLanguageIcon( QIcon i ) +WelcomePage::setLanguageIcon( QPixmap i ) { - ui->languageIcon->setPixmap( i.pixmap(48) ); + ui->languageIcon->setPixmap( i ); } diff --git a/src/modules/welcome/WelcomePage.h b/src/modules/welcome/WelcomePage.h index ec9044a68..6c244bf0c 100644 --- a/src/modules/welcome/WelcomePage.h +++ b/src/modules/welcome/WelcomePage.h @@ -43,7 +43,7 @@ public: bool showKnownIssuesUrl, bool showReleaseNotesUrl ); /// @brief Set international language-selector icon - void setLanguageIcon( QIcon ); + void setLanguageIcon( QPixmap ); /// @brief Results of requirements checking bool verdict() const; diff --git a/src/modules/welcome/WelcomeViewStep.cpp b/src/modules/welcome/WelcomeViewStep.cpp index 0f18cfa2d..a27cc4cf0 100644 --- a/src/modules/welcome/WelcomeViewStep.cpp +++ b/src/modules/welcome/WelcomeViewStep.cpp @@ -24,10 +24,12 @@ #include "geoip/Handler.h" #include "locale/Lookup.h" -#include "modulesystem/ModuleManager.h" #include "utils/Logger.h" #include "utils/Variant.h" +#include "Branding.h" +#include "modulesystem/ModuleManager.h" + #include #include @@ -142,7 +144,7 @@ WelcomeViewStep::setConfigurationMap( const QVariantMap& configurationMap ) QString language = CalamaresUtils::getString( configurationMap, "languageIcon" ); if ( !language.isEmpty() ) { - auto icon = QIcon::fromTheme( language ); + auto icon = Calamares::Branding::instance()->image( language, QSize( 48, 48 ) ); if ( !icon.isNull() ) m_widget->setLanguageIcon( icon ); } From 8506949ecdfd50005ed32dc7c9873f870ecea671 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Fri, 31 May 2019 17:28:33 +0200 Subject: [PATCH 19/19] Changes: Document new welcome-theming --- CHANGES | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGES b/CHANGES index e18d3f7e4..b5707cd45 100644 --- a/CHANGES +++ b/CHANGES @@ -22,6 +22,8 @@ milestone for details. *productLogo* and *productIcon* keys. If a file is named there, then the file is used, and otherwise the icon is looked up in the current theme. + - *welcome* allows a custom image path or icon name to be set for the + language-selection drop-down (instead of the international standard one). # 3.2.8 (2019-05-10) #