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.
* 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:
```

View File

@ -23,9 +23,13 @@
#include "core/PartitionInfo.h"
#include "core/KPMHelpers.h"
#include "utils/Logger.h"
// KPMcore
#include <kpmcore/core/device.h>
#include <QComboBox>
static QStandardItem*
createBootLoaderItem( const QString& description, const QString& path, bool isPartition )
{
@ -47,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();
@ -74,6 +78,7 @@ BootLoaderModel::createMbrItems()
void
BootLoaderModel::update()
{
cDebug() << "BLM::update holds" << m_devices.count() << "devices" << rowCount() << "rows";
beginResetModel();
blockSignals( true );
updateInternal();
@ -148,3 +153,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

View File

@ -25,6 +25,7 @@
#include <QStandardItemModel>
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 */

View File

@ -22,6 +22,8 @@
#include "core/KPMHelpers.h"
#include "core/PartitionIterator.h"
#include "utils/Logger.h"
// KPMcore
#include <kpmcore/core/partition.h>
#include <kpmcore/fs/luks.h>
@ -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 ) )

View File

@ -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
@ -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() );
}

View File

@ -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;

View File

@ -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();
@ -1025,18 +1024,25 @@ ChoicePage::updateActionChoicePreview( ChoicePage::InstallChoice choice )
eraseBootloaderLabel->setText( tr( "Boot loader location:" ) );
m_bootloaderComboBox = createBootloaderComboBox( eraseWidget );
connect( m_core, &PartitionCoreModule::deviceReverted,
this, [ this ]( Device* dev )
{
Q_UNUSED( dev )
if ( !m_bootloaderComboBox.isNull() )
connect( m_core->bootLoaderModel(), &QAbstractItemModel::modelReset,
[ this ]()
{
if ( m_bootloaderComboBox->model() != m_core->bootLoaderModel() )
m_bootloaderComboBox->setModel( m_core->bootLoaderModel() );
m_bootloaderComboBox->setCurrentIndex( m_lastSelectedDeviceIndex );
if ( !m_bootloaderComboBox.isNull() )
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 );

View File

@ -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();
}
@ -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() );
}

View File

@ -619,7 +619,7 @@ PartitionViewStep::setConfigurationMap( const QVariantMap& configurationMap )
}
QList< Calamares::job_ptr >
Calamares::JobList
PartitionViewStep::jobs() const
{
return m_core->jobs();
@ -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;

View File

@ -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;