Merge branch 'issue-1141'

FIXES #1141
This commit is contained in:
Adriaan de Groot 2019-05-31 12:21:18 +02:00
commit 1ef902a41f
10 changed files with 122 additions and 75 deletions

View File

@ -60,6 +60,8 @@ some PEP8 guidelines.
* Function and class definitions have their braces on separate lines. * Function and class definitions have their braces on separate lines.
* A function implementation's return type is on its own line. * A function implementation's return type is on its own line.
* `CamelCase.{cpp,h}` style file names. * `CamelCase.{cpp,h}` style file names.
* Lambdas are preferrably indented to a 4-space tab, even when passed as an
argument to functions.
Example: Example:
``` ```

View File

@ -23,9 +23,13 @@
#include "core/PartitionInfo.h" #include "core/PartitionInfo.h"
#include "core/KPMHelpers.h" #include "core/KPMHelpers.h"
#include "utils/Logger.h"
// KPMcore // KPMcore
#include <kpmcore/core/device.h> #include <kpmcore/core/device.h>
#include <QComboBox>
static QStandardItem* static QStandardItem*
createBootLoaderItem( const QString& description, const QString& path, bool isPartition ) createBootLoaderItem( const QString& description, const QString& path, bool isPartition )
{ {
@ -47,12 +51,12 @@ BootLoaderModel::~BootLoaderModel()
void void
BootLoaderModel::init( const QList< Device* >& devices ) BootLoaderModel::init( const QList< Device* >& devices )
{ {
cDebug() << "BLM::init with" << devices.count() << "devices" << rowCount() << "rows";
beginResetModel(); beginResetModel();
blockSignals( true ); blockSignals( true );
m_devices = devices; m_devices = devices;
clear(); updateInternal();
createMbrItems();
blockSignals( false ); blockSignals( false );
endResetModel(); endResetModel();
@ -74,6 +78,7 @@ BootLoaderModel::createMbrItems()
void void
BootLoaderModel::update() BootLoaderModel::update()
{ {
cDebug() << "BLM::update holds" << m_devices.count() << "devices" << rowCount() << "rows";
beginResetModel(); beginResetModel();
blockSignals( true ); blockSignals( true );
updateInternal(); updateInternal();
@ -148,3 +153,48 @@ BootLoaderModel::data( const QModelIndex& index, int role ) const
} }
return QStandardItemModel::data( index, role ); 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

View File

@ -25,6 +25,7 @@
#include <QStandardItemModel> #include <QStandardItemModel>
class Device; class Device;
class QComboBox;
/** /**
* This model contains one entry for each device MBR plus one entry for the * This model contains one entry for each device MBR plus one entry for the
@ -63,4 +64,20 @@ private:
void updateInternal(); 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 */ #endif /* BOOTLOADERMODEL_H */

View File

@ -22,6 +22,8 @@
#include "core/KPMHelpers.h" #include "core/KPMHelpers.h"
#include "core/PartitionIterator.h" #include "core/PartitionIterator.h"
#include "utils/Logger.h"
// KPMcore // KPMcore
#include <kpmcore/core/partition.h> #include <kpmcore/core/partition.h>
#include <kpmcore/fs/luks.h> #include <kpmcore/fs/luks.h>
@ -81,6 +83,12 @@ _findRootForPartition( PartitionNode* partition )
QColor QColor
colorForPartition( Partition* partition ) colorForPartition( Partition* partition )
{ {
if ( !partition )
{
cWarning() << "NULL partition";
return FREE_SPACE_COLOR;
}
if ( KPMHelpers::isPartitionFreeSpace( partition ) ) if ( KPMHelpers::isPartitionFreeSpace( partition ) )
return FREE_SPACE_COLOR; return FREE_SPACE_COLOR;
if ( partition->roles().has( PartitionRole::Extended ) ) if ( partition->roles().has( PartitionRole::Extended ) )

View File

@ -402,7 +402,7 @@ PartitionCoreModule::deletePartition( Device* device, Partition* partition )
deletePartition( device, childPartition ); deletePartition( device, childPartition );
} }
QList< Calamares::job_ptr >& jobs = deviceInfo->jobs; Calamares::JobList& jobs = deviceInfo->jobs;
if ( partition->state() == KPM_PARTITION_STATE(New) ) if ( partition->state() == KPM_PARTITION_STATE(New) )
{ {
// First remove matching SetPartFlagsJobs // First remove matching SetPartFlagsJobs
@ -496,10 +496,10 @@ PartitionCoreModule::setPartitionFlags( Device* device,
PartitionInfo::setFlags( partition, flags ); PartitionInfo::setFlags( partition, flags );
} }
QList< Calamares::job_ptr > Calamares::JobList
PartitionCoreModule::jobs() const PartitionCoreModule::jobs() const
{ {
QList< Calamares::job_ptr > lst; Calamares::JobList lst;
QList< Device* > devices; QList< Device* > devices;
#ifdef DEBUG_PARTITION_UNSAFE #ifdef DEBUG_PARTITION_UNSAFE
@ -947,12 +947,7 @@ PartitionCoreModule::revertDevice( Device* dev, bool individualRevert )
QList< Device* > devices; QList< Device* > devices;
for ( DeviceInfo* const info : m_deviceInfos ) for ( DeviceInfo* const info : m_deviceInfos )
{ {
// device is a QScopedPointer if ( info && !info->device.isNull() && info->device->type() == Device::Type::Disk_Device )
if ( !info || info->device.isNull() )
continue;
if ( info->device->type() != Device::Type::Disk_Device )
continue;
else
devices.append( info->device.data() ); devices.append( info->device.data() );
} }

View File

@ -247,7 +247,7 @@ private:
QScopedPointer< Device > device; QScopedPointer< Device > device;
QScopedPointer< PartitionModel > partitionModel; QScopedPointer< PartitionModel > partitionModel;
const QScopedPointer< Device > immutableDevice; const QScopedPointer< Device > immutableDevice;
QList< Calamares::job_ptr > jobs; Calamares::JobList jobs;
// To check if LVM VGs are deactivated // To check if LVM VGs are deactivated
bool isAvailable; bool isAvailable;

View File

@ -960,10 +960,8 @@ ChoicePage::updateActionChoicePreview( ChoicePage::InstallChoice choice )
QLabel* sizeLabel = new QLabel( m_previewAfterFrame ); QLabel* sizeLabel = new QLabel( m_previewAfterFrame );
layout->addWidget( sizeLabel ); layout->addWidget( sizeLabel );
sizeLabel->setWordWrap( true ); sizeLabel->setWordWrap( true );
connect( m_afterPartitionSplitterWidget, &PartitionSplitterWidget::partitionResized, connect( m_afterPartitionSplitterWidget, &PartitionSplitterWidget::partitionResized, this,
this, [ this, sizeLabel ]( const QString& path, [ this, sizeLabel ]( const QString& path, qint64 size, qint64 sizeNext )
qint64 size,
qint64 sizeNext )
{ {
Q_UNUSED( path ) Q_UNUSED( path )
sizeLabel->setText( tr( "%1 will be shrunk to %2MiB and a new " sizeLabel->setText( tr( "%1 will be shrunk to %2MiB and a new "
@ -972,7 +970,8 @@ ChoicePage::updateActionChoicePreview( ChoicePage::InstallChoice choice )
.arg( CalamaresUtils::BytesToMiB( size ) ) .arg( CalamaresUtils::BytesToMiB( size ) )
.arg( CalamaresUtils::BytesToMiB( sizeNext ) ) .arg( CalamaresUtils::BytesToMiB( sizeNext ) )
.arg( *Calamares::Branding::ShortProductName ) ); .arg( *Calamares::Branding::ShortProductName ) );
} ); }
);
m_previewAfterFrame->show(); m_previewAfterFrame->show();
m_previewAfterLabel->show(); m_previewAfterLabel->show();
@ -1025,8 +1024,15 @@ ChoicePage::updateActionChoicePreview( ChoicePage::InstallChoice choice )
eraseBootloaderLabel->setText( tr( "Boot loader location:" ) ); eraseBootloaderLabel->setText( tr( "Boot loader location:" ) );
m_bootloaderComboBox = createBootloaderComboBox( eraseWidget ); m_bootloaderComboBox = createBootloaderComboBox( eraseWidget );
connect( m_core, &PartitionCoreModule::deviceReverted, connect( m_core->bootLoaderModel(), &QAbstractItemModel::modelReset,
this, [ this ]( Device* dev ) [ this ]()
{
if ( !m_bootloaderComboBox.isNull() )
Calamares::restoreSelectedBootLoader( *m_bootloaderComboBox, m_core->bootLoaderInstallPath() );
}
);
connect( m_core, &PartitionCoreModule::deviceReverted, this,
[ this ]( Device* dev )
{ {
Q_UNUSED( dev ) Q_UNUSED( dev )
if ( !m_bootloaderComboBox.isNull() ) if ( !m_bootloaderComboBox.isNull() )

View File

@ -219,7 +219,7 @@ PartitionPage::onNewPartitionTableClicked()
m_core->createPartitionTable( device, type ); m_core->createPartitionTable( device, type );
} }
delete dlg; 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. // the bootLoader index after the reset.
updateBootLoaderIndex(); updateBootLoaderIndex();
} }
@ -511,45 +511,10 @@ PartitionPage::updateSelectedBootLoaderIndex()
cDebug() << "Selected bootloader index" << m_lastSelectedBootLoaderIndex; 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 void
PartitionPage::restoreSelectedBootLoader() PartitionPage::restoreSelectedBootLoader()
{ {
const auto* model = m_ui->bootLoaderComboBox->model(); Calamares::restoreSelectedBootLoader( *(m_ui->bootLoaderComboBox), m_core->bootLoaderInstallPath() );
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 );
}
} }

View File

@ -619,7 +619,7 @@ PartitionViewStep::setConfigurationMap( const QVariantMap& configurationMap )
} }
QList< Calamares::job_ptr > Calamares::JobList
PartitionViewStep::jobs() const PartitionViewStep::jobs() const
{ {
return m_core->jobs(); return m_core->jobs();
@ -638,7 +638,11 @@ PartitionViewStep::checkRequirements()
[]{ return tr( "has at least one disk device available." ); }, []{ return tr( "has at least one disk device available." ); },
[]{ return tr( "There are no partitons to install on." ); }, []{ return tr( "There are no partitons to install on." ); },
m_core->deviceModel()->rowCount() > 0, // satisfied m_core->deviceModel()->rowCount() > 0, // satisfied
#ifdef DEBUG_PARTITION_UNSAFE
false // optional
#else
true // required true // required
#endif
} ); } );
return l; return l;

View File

@ -69,7 +69,7 @@ public:
void setConfigurationMap( const QVariantMap& configurationMap ) override; void setConfigurationMap( const QVariantMap& configurationMap ) override;
QList< Calamares::job_ptr > jobs() const override; Calamares::JobList jobs() const override;
Calamares::RequirementsList checkRequirements() override; Calamares::RequirementsList checkRequirements() override;