calamares/src/modules/partition/gui/PartitionPage.cpp

678 lines
23 KiB
C++
Raw Normal View History

/* === This file is part of Calamares - <https://calamares.io> ===
2014-06-27 17:25:39 +02:00
*
2020-08-22 01:19:58 +02:00
* SPDX-FileCopyrightText: 2014 Aurélien Gâteau <agateau@kde.org>
* SPDX-FileCopyrightText: 2015-2016 Teo Mrnjavac <teo@kde.org>
* SPDX-FileCopyrightText: 2018-2019 Adriaan de Groot <groot@kde.org>
* SPDX-FileCopyrightText: 2018 Andrius Štikonas <andrius@stikonas.eu>
* SPDX-FileCopyrightText: 2018 Caio Jordão Carvalho <caiojcarvalho@gmail.com>
* SPDX-FileCopyrightText: 2019 Collabora Ltd
* SPDX-License-Identifier: GPL-3.0-or-later
2014-06-27 17:25:39 +02:00
*
* Calamares is Free Software: see the License-Identifier above.
2014-06-27 17:25:39 +02:00
*
*/
#include "PartitionPage.h"
// Local
#include "core/BootLoaderModel.h"
#include "core/DeviceModel.h"
2020-08-22 01:19:58 +02:00
#include "core/KPMHelpers.h"
#include "core/PartUtils.h"
#include "core/PartitionCoreModule.h"
#include "core/PartitionInfo.h"
#include "core/PartitionModel.h"
#include "gui/CreatePartitionDialog.h"
#include "gui/CreateVolumeGroupDialog.h"
#include "gui/EditExistingPartitionDialog.h"
#include "gui/ResizeVolumeGroupDialog.h"
#include "gui/ScanningDialog.h"
#include "ui_CreatePartitionTableDialog.h"
2020-08-22 01:19:58 +02:00
#include "ui_PartitionPage.h"
#include "GlobalStorage.h"
#include "JobQueue.h"
#include "partition/PartitionQuery.h"
#include "utils/Logger.h"
#include "utils/Retranslator.h"
2015-12-31 13:56:19 +01:00
#include "Branding.h"
// KPMcore
#include <kpmcore/core/device.h>
#include <kpmcore/core/partition.h>
#ifdef WITH_KPMCORE4API
#include <kpmcore/core/softwareraid.h>
#endif
#include <kpmcore/ops/deactivatevolumegroupoperation.h>
#include <kpmcore/ops/removevolumegroupoperation.h>
2014-06-27 17:25:39 +02:00
// Qt
2020-08-22 01:19:58 +02:00
#include <QDir>
#include <QFutureWatcher>
#include <QHeaderView>
#include <QItemSelectionModel>
#include <QMessageBox>
2014-07-01 16:46:33 +02:00
#include <QPointer>
#include <QtConcurrent/QtConcurrent>
2014-06-27 17:25:39 +02:00
PartitionPage::PartitionPage( PartitionCoreModule* core, QWidget* parent )
: QWidget( parent )
2014-06-27 17:25:39 +02:00
, m_ui( new Ui_PartitionPage )
, m_core( core )
2020-08-22 01:19:58 +02:00
, m_lastSelectedBootLoaderIndex( -1 )
, m_isEfi( false )
2014-06-27 17:25:39 +02:00
{
m_isEfi = PartUtils::isEfiSystem();
2014-06-27 17:25:39 +02:00
m_ui->setupUi( this );
2016-06-23 10:01:13 +02:00
m_ui->partitionLabelsView->setVisible(
2020-08-22 01:19:58 +02:00
Calamares::JobQueue::instance()->globalStorage()->value( "alwaysShowPartitionLabels" ).toBool() );
m_ui->deviceComboBox->setModel( m_core->deviceModel() );
m_ui->bootLoaderComboBox->setModel( m_core->bootLoaderModel() );
2020-08-22 01:19:58 +02:00
connect(
m_core->bootLoaderModel(), &QAbstractItemModel::modelReset, this, &PartitionPage::restoreSelectedBootLoader );
PartitionBarsView::NestedPartitionsMode mode
= Calamares::JobQueue::instance()->globalStorage()->value( "drawNestedPartitions" ).toBool()
? PartitionBarsView::DrawNestedPartitions
: PartitionBarsView::NoNestedPartitions;
m_ui->partitionBarsView->setNestedPartitionsMode( mode );
2014-06-30 15:04:10 +02:00
updateButtons();
updateBootLoaderInstallPath();
2014-06-27 17:25:39 +02:00
updateFromCurrentDevice();
connect( m_ui->deviceComboBox, &QComboBox::currentTextChanged, this, &PartitionPage::updateFromCurrentDevice );
2020-08-22 01:19:58 +02:00
connect( m_ui->bootLoaderComboBox,
QOverload< int >::of( &QComboBox::activated ),
this,
&PartitionPage::updateSelectedBootLoaderIndex );
connect(
m_ui->bootLoaderComboBox, &QComboBox::currentTextChanged, this, &PartitionPage::updateBootLoaderInstallPath );
2014-07-24 19:28:53 +02:00
connect( m_core, &PartitionCoreModule::isDirtyChanged, m_ui->revertButton, &QWidget::setEnabled );
2020-08-22 01:19:58 +02:00
connect(
m_ui->partitionTreeView, &QAbstractItemView::doubleClicked, this, &PartitionPage::onPartitionViewActivated );
2014-07-24 19:28:53 +02:00
connect( m_ui->revertButton, &QAbstractButton::clicked, this, &PartitionPage::onRevertClicked );
connect( m_ui->newVolumeGroupButton, &QAbstractButton::clicked, this, &PartitionPage::onNewVolumeGroupClicked );
2020-08-22 01:19:58 +02:00
connect(
m_ui->resizeVolumeGroupButton, &QAbstractButton::clicked, this, &PartitionPage::onResizeVolumeGroupClicked );
connect( m_ui->deactivateVolumeGroupButton,
&QAbstractButton::clicked,
this,
&PartitionPage::onDeactivateVolumeGroupClicked );
connect(
m_ui->removeVolumeGroupButton, &QAbstractButton::clicked, this, &PartitionPage::onRemoveVolumeGroupClicked );
connect(
m_ui->newPartitionTableButton, &QAbstractButton::clicked, this, &PartitionPage::onNewPartitionTableClicked );
connect( m_ui->createButton, &QAbstractButton::clicked, this, &PartitionPage::onCreateClicked );
connect( m_ui->editButton, &QAbstractButton::clicked, this, &PartitionPage::onEditClicked );
2014-07-02 15:49:35 +02:00
connect( m_ui->deleteButton, &QAbstractButton::clicked, this, &PartitionPage::onDeleteClicked );
2020-08-22 01:19:58 +02:00
if ( m_isEfi )
{
2016-03-09 12:54:16 +01:00
m_ui->bootLoaderComboBox->hide();
m_ui->label_3->hide();
}
2021-03-16 16:11:02 +01:00
CALAMARES_RETRANSLATE( m_ui->retranslateUi( this ); );
2014-06-27 17:25:39 +02:00
}
2020-08-22 01:19:58 +02:00
PartitionPage::~PartitionPage() {}
2014-06-30 15:04:10 +02:00
2014-07-02 14:12:47 +02:00
void
PartitionPage::updateButtons()
2014-06-30 15:04:10 +02:00
{
2020-08-22 01:19:58 +02:00
bool create = false, createTable = false, edit = false, del = false, currentDeviceIsVG = false,
isDeactivable = false;
bool isRemovable = false, isVGdeactivated = false;
2014-06-30 15:04:10 +02:00
QModelIndex index = m_ui->partitionTreeView->currentIndex();
2014-06-30 15:04:10 +02:00
if ( index.isValid() )
{
const PartitionModel* model = static_cast< const PartitionModel* >( index.model() );
Q_ASSERT( model );
Partition* partition = model->partitionForIndex( index );
Q_ASSERT( partition );
bool isFree = CalamaresUtils::Partition::isPartitionFreeSpace( partition );
bool isExtended = partition->roles().has( PartitionRole::Extended );
bool hasChildren = isExtended
&& ( partition->children().length() > 1
|| ( partition->children().length() == 1
&& !CalamaresUtils::Partition::isPartitionFreeSpace( partition->children().at( 0 ) ) ) );
bool isInVG = m_core->isInVG( partition );
2014-06-30 15:04:10 +02:00
create = isFree;
// Keep it simple for now: do not support editing extended partitions as
// it does not work with our current edit implementation which is
// actually remove + add. This would not work with extended partitions
// because they need to be created *before* creating logical partitions
// inside them, so an edit must be applied without altering the job
// order.
// TODO: See if LVM PVs can be edited in Calamares
edit = !isFree && !isExtended;
del = !isFree && !isInVG && !hasChildren;
2014-06-30 15:04:10 +02:00
}
if ( m_ui->deviceComboBox->currentIndex() >= 0 )
{
Device* device = nullptr;
QModelIndex deviceIndex = m_core->deviceModel()->index( m_ui->deviceComboBox->currentIndex(), 0 );
if ( deviceIndex.isValid() )
2020-08-22 01:19:58 +02:00
{
device = m_core->deviceModel()->deviceForIndex( deviceIndex );
2020-08-22 01:19:58 +02:00
}
if ( !device )
2020-08-22 01:19:58 +02:00
{
cWarning() << "Device for updateButtons is nullptr";
2020-08-22 01:19:58 +02:00
}
else if ( device->type() != Device::Type::LVM_Device )
{
createTable = true;
#ifdef WITH_KPMCORE4API
2020-08-22 01:19:58 +02:00
if ( device->type() == Device::Type::SoftwareRAID_Device
&& static_cast< SoftwareRAID* >( device )->status() == SoftwareRAID::Status::Inactive )
{
createTable = false;
create = false;
}
#endif
}
else
{
currentDeviceIsVG = true;
2020-08-22 01:19:58 +02:00
LvmDevice* lvmDevice = dynamic_cast< LvmDevice* >( m_core->deviceModel()->deviceForIndex( deviceIndex ) );
isDeactivable = DeactivateVolumeGroupOperation::isDeactivatable( lvmDevice );
isRemovable = RemoveVolumeGroupOperation::isRemovable( lvmDevice );
isVGdeactivated = m_core->isVGdeactivated( lvmDevice );
if ( isVGdeactivated )
2020-08-22 01:19:58 +02:00
{
m_ui->revertButton->setEnabled( true );
2020-08-22 01:19:58 +02:00
}
}
}
2014-06-30 15:04:10 +02:00
m_ui->createButton->setEnabled( create );
m_ui->editButton->setEnabled( edit );
m_ui->deleteButton->setEnabled( del );
m_ui->newPartitionTableButton->setEnabled( createTable );
m_ui->resizeVolumeGroupButton->setEnabled( currentDeviceIsVG && !isVGdeactivated );
m_ui->deactivateVolumeGroupButton->setEnabled( currentDeviceIsVG && isDeactivable && !isVGdeactivated );
m_ui->removeVolumeGroupButton->setEnabled( currentDeviceIsVG && isRemovable );
}
void
PartitionPage::onNewPartitionTableClicked()
{
QModelIndex index = m_core->deviceModel()->index( m_ui->deviceComboBox->currentIndex(), 0 );
Q_ASSERT( index.isValid() );
Device* device = m_core->deviceModel()->deviceForIndex( index );
2020-08-22 01:19:58 +02:00
QPointer< QDialog > dlg = new QDialog( this );
Ui_CreatePartitionTableDialog ui;
ui.setupUi( dlg.data() );
QString areYouSure = tr( "Are you sure you want to create a new partition table on %1?" ).arg( device->name() );
if ( PartUtils::isEfiSystem() )
2020-08-22 01:19:58 +02:00
{
ui.gptRadioButton->setChecked( true );
2020-08-22 01:19:58 +02:00
}
else
2020-08-22 01:19:58 +02:00
{
ui.mbrRadioButton->setChecked( true );
2020-08-22 01:19:58 +02:00
}
ui.areYouSureLabel->setText( areYouSure );
if ( dlg->exec() == QDialog::Accepted )
{
PartitionTable::TableType type = ui.mbrRadioButton->isChecked() ? PartitionTable::msdos : PartitionTable::gpt;
m_core->createPartitionTable( device, type );
}
delete dlg;
2019-05-28 16:47:09 +02:00
// PartionModelReset isn't emitted after createPartitionTable, so we have to manually update
// the bootLoader index after the reset.
updateBootLoaderIndex();
2014-06-30 15:04:10 +02:00
}
bool
PartitionPage::checkCanCreate( Device* device )
{
auto table = device->partitionTable();
2020-08-22 01:19:58 +02:00
if ( table->type() == PartitionTable::msdos || table->type() == PartitionTable::msdos_sectorbased )
{
cDebug() << "Checking MSDOS partition" << table->numPrimaries() << "primaries, max" << table->maxPrimaries();
if ( ( table->numPrimaries() >= table->maxPrimaries() ) && !table->hasExtended() )
{
2020-08-22 01:19:58 +02:00
QMessageBox::warning(
this,
tr( "Can not create new partition" ),
tr( "The partition table on %1 already has %2 primary partitions, and no more can be added. "
2020-08-22 01:19:58 +02:00
"Please remove one primary partition and add an extended partition, instead." )
.arg( device->name() )
.arg( table->numPrimaries() ) );
return false;
}
return true;
}
else
2020-08-22 01:19:58 +02:00
{
return true; // GPT is fine
2020-08-22 01:19:58 +02:00
}
}
void
PartitionPage::onNewVolumeGroupClicked()
{
QString vgName;
QVector< const Partition* > selectedPVs;
qint64 peSize = 4;
QVector< const Partition* > availablePVs;
for ( const Partition* p : m_core->lvmPVs() )
if ( !m_core->isInVG( p ) )
2020-08-22 01:19:58 +02:00
{
availablePVs << p;
2020-08-22 01:19:58 +02:00
}
2020-08-22 01:19:58 +02:00
QPointer< CreateVolumeGroupDialog > dlg
= new CreateVolumeGroupDialog( vgName, selectedPVs, availablePVs, peSize, this );
if ( dlg->exec() == QDialog::Accepted )
{
QModelIndex partitionIndex = m_ui->partitionTreeView->currentIndex();
if ( partitionIndex.isValid() )
{
const PartitionModel* model = static_cast< const PartitionModel* >( partitionIndex.model() );
Q_ASSERT( model );
Partition* partition = model->partitionForIndex( partitionIndex );
Q_ASSERT( partition );
// Disable delete button if current partition was selected to be in VG
// TODO: Should Calamares edit LVM PVs which are in VGs?
if ( selectedPVs.contains( partition ) )
2020-08-22 01:19:58 +02:00
{
m_ui->deleteButton->setEnabled( false );
2020-08-22 01:19:58 +02:00
}
}
QModelIndex deviceIndex = m_core->deviceModel()->index( m_ui->deviceComboBox->currentIndex(), 0 );
Q_ASSERT( deviceIndex.isValid() );
QVariant previousIndexDeviceData = m_core->deviceModel()->data( deviceIndex, Qt::ToolTipRole );
// Creating new VG
m_core->createVolumeGroup( vgName, selectedPVs, peSize );
// As createVolumeGroup method call resets deviceModel,
// is needed to set the current index in deviceComboBox as the previous one
int previousIndex = m_ui->deviceComboBox->findData( previousIndexDeviceData, Qt::ToolTipRole );
2020-08-22 01:19:58 +02:00
m_ui->deviceComboBox->setCurrentIndex( ( previousIndex < 0 ) ? 0 : previousIndex );
updateFromCurrentDevice();
}
delete dlg;
}
void
PartitionPage::onResizeVolumeGroupClicked()
{
QModelIndex deviceIndex = m_core->deviceModel()->index( m_ui->deviceComboBox->currentIndex(), 0 );
LvmDevice* device = dynamic_cast< LvmDevice* >( m_core->deviceModel()->deviceForIndex( deviceIndex ) );
Q_ASSERT( device && device->type() == Device::Type::LVM_Device );
QVector< const Partition* > availablePVs;
QVector< const Partition* > selectedPVs;
for ( const Partition* p : m_core->lvmPVs() )
if ( !m_core->isInVG( p ) )
2020-08-22 01:19:58 +02:00
{
availablePVs << p;
2020-08-22 01:19:58 +02:00
}
2020-08-22 01:19:58 +02:00
QPointer< ResizeVolumeGroupDialog > dlg = new ResizeVolumeGroupDialog( device, availablePVs, selectedPVs, this );
if ( dlg->exec() == QDialog::Accepted )
2020-08-22 01:19:58 +02:00
{
m_core->resizeVolumeGroup( device, selectedPVs );
2020-08-22 01:19:58 +02:00
}
delete dlg;
}
void
PartitionPage::onDeactivateVolumeGroupClicked()
{
QModelIndex deviceIndex = m_core->deviceModel()->index( m_ui->deviceComboBox->currentIndex(), 0 );
LvmDevice* device = dynamic_cast< LvmDevice* >( m_core->deviceModel()->deviceForIndex( deviceIndex ) );
Q_ASSERT( device && device->type() == Device::Type::LVM_Device );
m_core->deactivateVolumeGroup( device );
updateFromCurrentDevice();
PartitionModel* model = m_core->partitionModelForDevice( device );
model->update();
}
void
PartitionPage::onRemoveVolumeGroupClicked()
{
QModelIndex deviceIndex = m_core->deviceModel()->index( m_ui->deviceComboBox->currentIndex(), 0 );
LvmDevice* device = dynamic_cast< LvmDevice* >( m_core->deviceModel()->deviceForIndex( deviceIndex ) );
Q_ASSERT( device && device->type() == Device::Type::LVM_Device );
m_core->removeVolumeGroup( device );
}
2014-07-02 14:12:47 +02:00
void
PartitionPage::onCreateClicked()
{
QModelIndex index = m_ui->partitionTreeView->currentIndex();
Q_ASSERT( index.isValid() );
const PartitionModel* model = static_cast< const PartitionModel* >( index.model() );
Partition* partition = model->partitionForIndex( index );
Q_ASSERT( partition );
if ( !checkCanCreate( model->device() ) )
2020-08-22 01:19:58 +02:00
{
return;
2020-08-22 01:19:58 +02:00
}
2021-06-22 00:21:01 +02:00
QPointer< CreatePartitionDialog > dlg = new CreatePartitionDialog(
model->device(), CreatePartitionDialog::FreeSpace { partition }, getCurrentUsedMountpoints(), this );
if ( dlg->exec() == QDialog::Accepted )
2016-03-08 12:44:49 +01:00
{
Partition* newPart = dlg->getNewlyCreatedPartition();
m_core->createPartition( model->device(), newPart, dlg->newFlags() );
2016-03-08 12:44:49 +01:00
}
delete dlg;
}
2014-07-02 15:49:35 +02:00
void
PartitionPage::onEditClicked()
{
QModelIndex index = m_ui->partitionTreeView->currentIndex();
Q_ASSERT( index.isValid() );
const PartitionModel* model = static_cast< const PartitionModel* >( index.model() );
Partition* partition = model->partitionForIndex( index );
Q_ASSERT( partition );
if ( CalamaresUtils::Partition::isPartitionNew( partition ) )
2020-08-22 01:19:58 +02:00
{
updatePartitionToCreate( model->device(), partition );
2020-08-22 01:19:58 +02:00
}
else
2020-08-22 01:19:58 +02:00
{
editExistingPartition( model->device(), partition );
2020-08-22 01:19:58 +02:00
}
}
2014-07-02 15:49:35 +02:00
void
PartitionPage::onDeleteClicked()
{
QModelIndex index = m_ui->partitionTreeView->currentIndex();
2014-07-02 15:49:35 +02:00
Q_ASSERT( index.isValid() );
const PartitionModel* model = static_cast< const PartitionModel* >( index.model() );
Partition* partition = model->partitionForIndex( index );
Q_ASSERT( partition );
m_core->deletePartition( model->device(), partition );
}
2014-07-24 19:28:53 +02:00
void
PartitionPage::onRevertClicked()
{
2015-12-31 13:56:19 +01:00
ScanningDialog::run(
2020-10-12 14:27:01 +02:00
QtConcurrent::run( [this] {
2015-12-31 13:56:19 +01:00
QMutexLocker locker( &m_revertMutex );
int oldIndex = m_ui->deviceComboBox->currentIndex();
m_core->revertAllDevices();
2020-08-22 01:19:58 +02:00
m_ui->deviceComboBox->setCurrentIndex( ( oldIndex < 0 ) ? 0 : oldIndex );
2015-12-31 13:56:19 +01:00
updateFromCurrentDevice();
} ),
2020-10-12 14:27:01 +02:00
[this] {
m_lastSelectedBootLoaderIndex = -1;
2020-08-22 01:19:58 +02:00
if ( m_ui->bootLoaderComboBox->currentIndex() < 0 )
{
m_ui->bootLoaderComboBox->setCurrentIndex( 0 );
}
},
2015-12-31 13:56:19 +01:00
this );
2014-07-24 19:28:53 +02:00
}
void
PartitionPage::onPartitionViewActivated()
{
QModelIndex index = m_ui->partitionTreeView->currentIndex();
if ( !index.isValid() )
2020-08-22 01:19:58 +02:00
{
return;
2020-08-22 01:19:58 +02:00
}
const PartitionModel* model = static_cast< const PartitionModel* >( index.model() );
Q_ASSERT( model );
Partition* partition = model->partitionForIndex( index );
Q_ASSERT( partition );
// Use the buttons to trigger the actions so that they do nothing if they
// are disabled. Alternatively, the code could use QAction to centralize,
// but I don't expect there will be other occurences of triggering the same
// action from multiple UI elements in this page, so it does not feel worth
// the price.
if ( CalamaresUtils::Partition::isPartitionFreeSpace( partition ) )
2020-08-22 01:19:58 +02:00
{
m_ui->createButton->click();
2020-08-22 01:19:58 +02:00
}
else
2020-08-22 01:19:58 +02:00
{
m_ui->editButton->click();
2020-08-22 01:19:58 +02:00
}
}
void
PartitionPage::updatePartitionToCreate( Device* device, Partition* partition )
{
QStringList mountPoints = getCurrentUsedMountpoints();
mountPoints.removeOne( PartitionInfo::mountPoint( partition ) );
2020-08-22 01:19:58 +02:00
QPointer< CreatePartitionDialog > dlg
2021-06-22 00:21:01 +02:00
= new CreatePartitionDialog( device, CreatePartitionDialog::FreshPartition { partition }, mountPoints, this );
if ( dlg->exec() == QDialog::Accepted )
{
Partition* newPartition = dlg->getNewlyCreatedPartition();
m_core->deletePartition( device, partition );
2016-03-08 16:26:20 +01:00
m_core->createPartition( device, newPartition, dlg->newFlags() );
}
delete dlg;
}
void
PartitionPage::editExistingPartition( Device* device, Partition* partition )
{
QStringList mountPoints = getCurrentUsedMountpoints();
mountPoints.removeOne( PartitionInfo::mountPoint( partition ) );
2020-08-22 01:19:58 +02:00
QPointer< EditExistingPartitionDialog > dlg
= new EditExistingPartitionDialog( device, partition, mountPoints, this );
if ( dlg->exec() == QDialog::Accepted )
2020-08-22 01:19:58 +02:00
{
dlg->applyChanges( m_core );
2020-08-22 01:19:58 +02:00
}
delete dlg;
}
void
PartitionPage::updateBootLoaderInstallPath()
{
if ( m_isEfi || !m_ui->bootLoaderComboBox->isVisible() )
2020-08-22 01:19:58 +02:00
{
return;
2020-08-22 01:19:58 +02:00
}
QVariant var = m_ui->bootLoaderComboBox->currentData( BootLoaderModel::BootLoaderPathRole );
if ( !var.isValid() )
2020-08-22 01:19:58 +02:00
{
return;
2020-08-22 01:19:58 +02:00
}
cDebug() << "PartitionPage::updateBootLoaderInstallPath" << var.toString();
m_core->setBootLoaderInstallPath( var.toString() );
}
void
PartitionPage::updateSelectedBootLoaderIndex()
{
m_lastSelectedBootLoaderIndex = m_ui->bootLoaderComboBox->currentIndex();
cDebug() << "Selected bootloader index" << m_lastSelectedBootLoaderIndex;
}
void
PartitionPage::restoreSelectedBootLoader()
{
2020-08-22 01:19:58 +02:00
Calamares::restoreSelectedBootLoader( *( m_ui->bootLoaderComboBox ), m_core->bootLoaderInstallPath() );
}
void
PartitionPage::updateFromCurrentDevice()
{
QModelIndex index = m_core->deviceModel()->index( m_ui->deviceComboBox->currentIndex(), 0 );
if ( !index.isValid() )
2020-08-22 01:19:58 +02:00
{
return;
2020-08-22 01:19:58 +02:00
}
Device* device = m_core->deviceModel()->deviceForIndex( index );
QAbstractItemModel* oldModel = m_ui->partitionTreeView->model();
if ( oldModel )
2020-08-22 01:19:58 +02:00
{
disconnect( oldModel, nullptr, this, nullptr );
2020-08-22 01:19:58 +02:00
}
PartitionModel* model = m_core->partitionModelForDevice( device );
m_ui->partitionBarsView->setModel( model );
2016-06-23 10:01:13 +02:00
m_ui->partitionLabelsView->setModel( model );
m_ui->partitionTreeView->setModel( model );
m_ui->partitionTreeView->expandAll();
2016-06-23 10:01:13 +02:00
// Make all views use the same selection model.
2020-08-22 01:19:58 +02:00
if ( m_ui->partitionBarsView->selectionModel() != m_ui->partitionTreeView->selectionModel()
|| m_ui->partitionBarsView->selectionModel() != m_ui->partitionLabelsView->selectionModel() )
{
2016-06-23 10:01:13 +02:00
// Tree view
QItemSelectionModel* selectionModel = m_ui->partitionTreeView->selectionModel();
m_ui->partitionTreeView->setSelectionModel( m_ui->partitionBarsView->selectionModel() );
selectionModel->deleteLater();
2016-06-23 10:01:13 +02:00
// Labels view
selectionModel = m_ui->partitionLabelsView->selectionModel();
m_ui->partitionLabelsView->setSelectionModel( m_ui->partitionBarsView->selectionModel() );
selectionModel->deleteLater();
}
// This is necessary because even with the same selection model it might happen that
// a !=0 column is selected in the tree view, which for some reason doesn't trigger a
// timely repaint in the bars view.
2020-08-22 01:19:58 +02:00
connect(
m_ui->partitionBarsView->selectionModel(),
&QItemSelectionModel::currentChanged,
this,
2020-10-12 14:27:01 +02:00
[=] {
2020-08-22 01:19:58 +02:00
QModelIndex selectedIndex = m_ui->partitionBarsView->selectionModel()->currentIndex();
selectedIndex = selectedIndex.sibling( selectedIndex.row(), 0 );
m_ui->partitionBarsView->setCurrentIndex( selectedIndex );
m_ui->partitionLabelsView->setCurrentIndex( selectedIndex );
},
Qt::UniqueConnection );
// Must be done here because we need to have a model set to define
// individual column resize mode
QHeaderView* header = m_ui->partitionTreeView->header();
header->setSectionResizeMode( QHeaderView::ResizeToContents );
header->setSectionResizeMode( 0, QHeaderView::Stretch );
updateButtons();
// Establish connection here because selection model is destroyed when
// model changes
2020-08-22 01:19:58 +02:00
connect( m_ui->partitionTreeView->selectionModel(),
&QItemSelectionModel::currentChanged,
2020-10-12 14:27:01 +02:00
[this]( const QModelIndex&, const QModelIndex& ) { updateButtons(); } );
connect( model, &QAbstractItemModel::modelReset, this, &PartitionPage::onPartitionModelReset );
}
void
PartitionPage::onPartitionModelReset()
{
m_ui->partitionTreeView->expandAll();
updateButtons();
updateBootLoaderIndex();
}
void
PartitionPage::updateBootLoaderIndex()
{
// set bootloader back to user selected index
2020-08-22 01:19:58 +02:00
if ( m_lastSelectedBootLoaderIndex >= 0 && m_ui->bootLoaderComboBox->count() )
{
m_ui->bootLoaderComboBox->setCurrentIndex( m_lastSelectedBootLoaderIndex );
}
}
QStringList
PartitionPage::getCurrentUsedMountpoints()
{
2020-08-22 01:19:58 +02:00
QModelIndex index = m_core->deviceModel()->index( m_ui->deviceComboBox->currentIndex(), 0 );
if ( !index.isValid() )
2020-08-22 01:19:58 +02:00
{
return QStringList();
2020-08-22 01:19:58 +02:00
}
Device* device = m_core->deviceModel()->deviceForIndex( index );
QStringList mountPoints;
2017-01-04 15:18:26 +01:00
for ( Partition* partition : device->partitionTable()->children() )
{
const QString& mountPoint = PartitionInfo::mountPoint( partition );
2017-01-04 15:18:26 +01:00
if ( !mountPoint.isEmpty() )
2020-08-22 01:19:58 +02:00
{
mountPoints << mountPoint;
2020-08-22 01:19:58 +02:00
}
}
return mountPoints;
}
int
PartitionPage::selectedDeviceIndex()
{
return m_ui->deviceComboBox->currentIndex();
}
void
2020-08-22 01:19:58 +02:00
PartitionPage::selectDeviceByIndex( int index )
{
2020-08-22 01:19:58 +02:00
m_ui->deviceComboBox->setCurrentIndex( index );
}