Start implementing editing of newly-created partitions
This is the beginning of #19
This commit is contained in:
parent
174114f09c
commit
48c078acc5
@ -31,19 +31,20 @@
|
|||||||
#include <QComboBox>
|
#include <QComboBox>
|
||||||
#include <QSet>
|
#include <QSet>
|
||||||
|
|
||||||
CreatePartitionDialog::CreatePartitionDialog( Device* device, Partition* freePartition, QWidget* parent )
|
CreatePartitionDialog::CreatePartitionDialog( Device* device, PartitionNode* parentPartition, QWidget* parentWidget )
|
||||||
: QDialog( parent )
|
: QDialog( parentWidget )
|
||||||
, m_ui( new Ui_CreatePartitionDialog )
|
, m_ui( new Ui_CreatePartitionDialog )
|
||||||
, m_device( device )
|
, m_device( device )
|
||||||
, m_freePartition( freePartition )
|
, m_parent( parentPartition )
|
||||||
{
|
{
|
||||||
m_ui->setupUi( this );
|
m_ui->setupUi( this );
|
||||||
|
|
||||||
FileSystemFactory::init();
|
FileSystemFactory::init();
|
||||||
|
|
||||||
|
bool parentIsPartitionTable = parentPartition->isRoot();
|
||||||
// Partition types
|
// Partition types
|
||||||
QString fixedPartitionType;
|
QString fixedPartitionType;
|
||||||
if ( freePartition->roles().has( PartitionRole::Logical ) )
|
if ( !parentIsPartitionTable )
|
||||||
{
|
{
|
||||||
m_role = PartitionRole( PartitionRole::Logical );
|
m_role = PartitionRole( PartitionRole::Logical );
|
||||||
fixedPartitionType = tr( "Logical" );
|
fixedPartitionType = tr( "Logical" );
|
||||||
@ -72,12 +73,6 @@ CreatePartitionDialog::CreatePartitionDialog( Device* device, Partition* freePar
|
|||||||
}
|
}
|
||||||
m_ui->fsComboBox->addItems( fsNames );
|
m_ui->fsComboBox->addItems( fsNames );
|
||||||
|
|
||||||
// Size
|
|
||||||
qint64 maxSize = ( freePartition->lastSector() - freePartition->firstSector() + 1 ) * device->logicalSectorSize();
|
|
||||||
|
|
||||||
m_ui->sizeSpinBox->setMaximum( maxSize / 1024 / 1024 );
|
|
||||||
m_ui->sizeSpinBox->setValue( m_ui->sizeSpinBox->maximum() );
|
|
||||||
|
|
||||||
// Connections
|
// Connections
|
||||||
connect( m_ui->fsComboBox, SIGNAL( activated( int ) ), SLOT( updateMountPointUi() ) );
|
connect( m_ui->fsComboBox, SIGNAL( activated( int ) ), SLOT( updateMountPointUi() ) );
|
||||||
connect( m_ui->extendedRadioButton, SIGNAL( toggled( bool ) ), SLOT( updateMountPointUi() ) );
|
connect( m_ui->extendedRadioButton, SIGNAL( toggled( bool ) ), SLOT( updateMountPointUi() ) );
|
||||||
@ -86,6 +81,19 @@ CreatePartitionDialog::CreatePartitionDialog( Device* device, Partition* freePar
|
|||||||
CreatePartitionDialog::~CreatePartitionDialog()
|
CreatePartitionDialog::~CreatePartitionDialog()
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
void
|
||||||
|
CreatePartitionDialog::setSectorRange( qint64 minSector, qint64 maxSector )
|
||||||
|
{
|
||||||
|
Q_ASSERT( minSector <= maxSector );
|
||||||
|
m_minSector = minSector;
|
||||||
|
m_maxSector = maxSector;
|
||||||
|
|
||||||
|
qint64 maxSize = ( m_maxSector - m_minSector + 1 ) * m_device->logicalSectorSize();
|
||||||
|
|
||||||
|
m_ui->sizeSpinBox->setMaximum( maxSize / 1024 / 1024 );
|
||||||
|
m_ui->sizeSpinBox->setValue( m_ui->sizeSpinBox->maximum() );
|
||||||
|
}
|
||||||
|
|
||||||
PartitionInfo*
|
PartitionInfo*
|
||||||
CreatePartitionDialog::createPartitionInfo()
|
CreatePartitionDialog::createPartitionInfo()
|
||||||
{
|
{
|
||||||
@ -98,21 +106,19 @@ CreatePartitionDialog::createPartitionInfo()
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
qint64 first = m_freePartition->firstSector();
|
|
||||||
// FIXME: Check rounding errors here
|
// FIXME: Check rounding errors here
|
||||||
qint64 last = first + qint64( m_ui->sizeSpinBox->value() ) * 1024 * 1024 / m_device->logicalSectorSize();
|
qint64 last = m_minSector + qint64( m_ui->sizeSpinBox->value() ) * 1024 * 1024 / m_device->logicalSectorSize();
|
||||||
|
|
||||||
FileSystem::Type type = m_role.has( PartitionRole::Extended )
|
FileSystem::Type type = m_role.has( PartitionRole::Extended )
|
||||||
? FileSystem::Extended
|
? FileSystem::Extended
|
||||||
: FileSystem::typeForName( m_ui->fsComboBox->currentText() );
|
: FileSystem::typeForName( m_ui->fsComboBox->currentText() );
|
||||||
FileSystem* fs = FileSystemFactory::create( type, first, last );
|
FileSystem* fs = FileSystemFactory::create( type, m_minSector, last );
|
||||||
|
|
||||||
PartitionNode* parent = m_freePartition->parent();
|
|
||||||
auto partition = new Partition(
|
auto partition = new Partition(
|
||||||
parent,
|
m_parent,
|
||||||
*m_device,
|
*m_device,
|
||||||
m_role,
|
m_role,
|
||||||
fs, first, last,
|
fs, m_minSector, last,
|
||||||
QString() /* path */,
|
QString() /* path */,
|
||||||
PartitionTable::FlagNone /* availableFlags */,
|
PartitionTable::FlagNone /* availableFlags */,
|
||||||
QString() /* mountPoint */,
|
QString() /* mountPoint */,
|
||||||
@ -141,3 +147,13 @@ CreatePartitionDialog::updateMountPointUi()
|
|||||||
m_ui->mountPointLabel->setEnabled( enabled );
|
m_ui->mountPointLabel->setEnabled( enabled );
|
||||||
m_ui->mountPointComboBox->setEnabled( enabled );
|
m_ui->mountPointComboBox->setEnabled( enabled );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
CreatePartitionDialog::initFromPartition( Partition* partition )
|
||||||
|
{
|
||||||
|
Q_ASSERT( partition );
|
||||||
|
qint64 maxSize = ( partition->lastSector() - partition->firstSector() + 1 ) * m_device->logicalSectorSize();
|
||||||
|
m_ui->sizeSpinBox->setValue( maxSize / 1024 / 1024 );
|
||||||
|
|
||||||
|
// FIXME: Update other fields
|
||||||
|
}
|
||||||
|
@ -27,6 +27,7 @@
|
|||||||
|
|
||||||
class Device;
|
class Device;
|
||||||
class Partition;
|
class Partition;
|
||||||
|
class PartitionNode;
|
||||||
class PartitionInfo;
|
class PartitionInfo;
|
||||||
class Ui_CreatePartitionDialog;
|
class Ui_CreatePartitionDialog;
|
||||||
|
|
||||||
@ -34,9 +35,11 @@ class CreatePartitionDialog : public QDialog
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
CreatePartitionDialog( Device* device, Partition* freePartition, QWidget* parent = nullptr );
|
CreatePartitionDialog( Device* device, PartitionNode* parentPartition, QWidget* parentWidget = nullptr );
|
||||||
~CreatePartitionDialog();
|
~CreatePartitionDialog();
|
||||||
|
|
||||||
|
void setSectorRange( qint64 minSector, qint64 maxSector );
|
||||||
|
void initFromPartition( Partition* partition );
|
||||||
PartitionInfo* createPartitionInfo();
|
PartitionInfo* createPartitionInfo();
|
||||||
|
|
||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
@ -45,7 +48,9 @@ private Q_SLOTS:
|
|||||||
private:
|
private:
|
||||||
QScopedPointer< Ui_CreatePartitionDialog > m_ui;
|
QScopedPointer< Ui_CreatePartitionDialog > m_ui;
|
||||||
Device* m_device;
|
Device* m_device;
|
||||||
Partition* m_freePartition;
|
qint64 m_minSector = 0;
|
||||||
|
qint64 m_maxSector = 0;
|
||||||
|
PartitionNode* m_parent;
|
||||||
PartitionRole m_role = PartitionRole( PartitionRole::None );
|
PartitionRole m_role = PartitionRole( PartitionRole::None );
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -29,6 +29,7 @@
|
|||||||
|
|
||||||
// CalaPM
|
// CalaPM
|
||||||
#include <core/device.h>
|
#include <core/device.h>
|
||||||
|
#include <core/partition.h>
|
||||||
|
|
||||||
// Qt
|
// Qt
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
@ -72,6 +73,7 @@ PartitionPage::PartitionPage( PartitionCoreModule* core, QWidget* parent )
|
|||||||
|
|
||||||
connect( m_ui->newPartitionTableButton, &QAbstractButton::clicked, this, &PartitionPage::onNewPartitionTableClicked );
|
connect( m_ui->newPartitionTableButton, &QAbstractButton::clicked, this, &PartitionPage::onNewPartitionTableClicked );
|
||||||
connect( m_ui->createButton, &QAbstractButton::clicked, this, &PartitionPage::onCreateClicked );
|
connect( m_ui->createButton, &QAbstractButton::clicked, this, &PartitionPage::onCreateClicked );
|
||||||
|
connect( m_ui->editButton, &QAbstractButton::clicked, this, &PartitionPage::onEditClicked );
|
||||||
connect( m_ui->deleteButton, &QAbstractButton::clicked, this, &PartitionPage::onDeleteClicked );
|
connect( m_ui->deleteButton, &QAbstractButton::clicked, this, &PartitionPage::onDeleteClicked );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -132,12 +134,29 @@ PartitionPage::onCreateClicked()
|
|||||||
Partition* partition = model->partitionForIndex( index );
|
Partition* partition = model->partitionForIndex( index );
|
||||||
Q_ASSERT( partition );
|
Q_ASSERT( partition );
|
||||||
|
|
||||||
QPointer<CreatePartitionDialog> dlg = new CreatePartitionDialog( model->device(), partition, this );
|
QPointer<CreatePartitionDialog> dlg = new CreatePartitionDialog( model->device(), partition->parent(), this );
|
||||||
|
dlg->setSectorRange( partition->firstSector(), partition->lastSector() );
|
||||||
if ( dlg->exec() == QDialog::Accepted )
|
if ( dlg->exec() == QDialog::Accepted )
|
||||||
m_core->createPartition( model->device(), dlg->createPartitionInfo() );
|
m_core->createPartition( model->device(), dlg->createPartitionInfo() );
|
||||||
delete dlg;
|
delete dlg;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 ( index.data( PartitionModel::IsNewPartitionRole ).toBool() )
|
||||||
|
updatePartitionToCreate( model->device(), partition );
|
||||||
|
else
|
||||||
|
editExistingPartition( partition );
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
PartitionPage::onDeleteClicked()
|
PartitionPage::onDeleteClicked()
|
||||||
{
|
{
|
||||||
@ -150,3 +169,23 @@ PartitionPage::onDeleteClicked()
|
|||||||
|
|
||||||
m_core->deletePartition( model->device(), partition );
|
m_core->deletePartition( model->device(), partition );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
PartitionPage::updatePartitionToCreate( Device* device, Partition* partition )
|
||||||
|
{
|
||||||
|
QPointer<CreatePartitionDialog> dlg = new CreatePartitionDialog( device, partition->parent(), this );
|
||||||
|
qint64 extraSectors = device->partitionTable()->freeSectorsAfter( *partition );
|
||||||
|
dlg->setSectorRange( partition->firstSector(), partition->lastSector() + extraSectors );
|
||||||
|
dlg->initFromPartition( partition );
|
||||||
|
if ( dlg->exec() == QDialog::Accepted )
|
||||||
|
{
|
||||||
|
m_core->deletePartition( device, partition );
|
||||||
|
m_core->createPartition( device, dlg->createPartitionInfo() );
|
||||||
|
}
|
||||||
|
delete dlg;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
PartitionPage::editExistingPartition( Partition* partition )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
@ -25,7 +25,9 @@
|
|||||||
class PartitionCoreModule;
|
class PartitionCoreModule;
|
||||||
class Ui_PartitionPage;
|
class Ui_PartitionPage;
|
||||||
|
|
||||||
|
class Device;
|
||||||
class DeviceModel;
|
class DeviceModel;
|
||||||
|
class Partition;
|
||||||
|
|
||||||
class PartitionPage : public QWidget
|
class PartitionPage : public QWidget
|
||||||
{
|
{
|
||||||
@ -44,7 +46,11 @@ private:
|
|||||||
void updateButtons();
|
void updateButtons();
|
||||||
void onNewPartitionTableClicked();
|
void onNewPartitionTableClicked();
|
||||||
void onCreateClicked();
|
void onCreateClicked();
|
||||||
|
void onEditClicked();
|
||||||
void onDeleteClicked();
|
void onDeleteClicked();
|
||||||
|
|
||||||
|
void updatePartitionToCreate( Device*, Partition* );
|
||||||
|
void editExistingPartition( Partition* );
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // PARTITIONPAGE_H
|
#endif // PARTITIONPAGE_H
|
||||||
|
Loading…
Reference in New Issue
Block a user