Start implementing support for creating partitions

This commit is contained in:
Aurélien Gâteau 2014-06-30 16:17:28 +02:00
parent 3a59cdeda9
commit c9409ba6b2
6 changed files with 96 additions and 2 deletions

View File

@ -25,6 +25,9 @@
#include <CalaPM.h>
#include <backend/corebackend.h>
#include <backend/corebackendmanager.h>
#include <core/device.h>
#include <core/partition.h>
#include <fs/filesystem.h>
//- DeviceInfo --------------------------------------------
@ -84,3 +87,45 @@ PartitionCoreModule::partitionModelForDevice( Device* device ) const
}
return nullptr;
}
void
PartitionCoreModule::createPartition( Partition* freeSpacePartition, FileSystem* fs, const QString& mountPoint, PartitionTable::Flags flags )
{
DeviceInfo* info = deviceInfoForPath( freeSpacePartition->devicePath() );
Q_ASSERT( info );
PartitionNode* parent = freeSpacePartition->parent();
// Create a Partition object
Partition* partition = new Partition(
parent,
*info->device,
PartitionRole( PartitionRole::Primary ), // FIXME: Support extended partitions
fs, fs->firstSector(), fs->lastSector(),
QString() /* path */
);
// Add Partition object
info->device->partitionTable()->removeUnallocated();
parent->insert( partition );
info->device->partitionTable()->updateUnallocated( *info->device );
// Update model
info->partitionModel->reload();
// Create a CreatePartitionJob
// Enqueue job
}
PartitionCoreModule::DeviceInfo*
PartitionCoreModule::deviceInfoForPath( const QString& path ) const
{
for ( auto info : m_devices )
{
if ( info->device->deviceNode() == path )
{
return info;
}
}
return nullptr;
}

View File

@ -22,8 +22,13 @@
#include <QList>
#include <QObject>
// CalaPM
#include <core/partitiontable.h>
class Device;
class DeviceModel;
class FileSystem;
class Partition;
class PartitionModel;
/**
@ -39,6 +44,8 @@ public:
PartitionModel* partitionModelForDevice( Device* device ) const;
void createPartition( Partition* freeSpacePartition, FileSystem* fs, const QString& mountPoint, PartitionTable::Flags flags );
private:
struct DeviceInfo
{
@ -51,6 +58,8 @@ private:
DeviceModel* m_deviceModel;
void listDevices();
DeviceInfo* deviceInfoForPath( const QString& path ) const;
};
#endif /* PARTITIONCOREMODULE_H */

View File

@ -33,10 +33,16 @@ PartitionModel::PartitionModel( QObject* parent )
void
PartitionModel::init( Device* device )
{
beginResetModel();
m_device = device;
reload();
}
void
PartitionModel::reload()
{
beginResetModel();
m_partitionList.clear();
if ( device )
if ( m_device )
{
fillPartitionList( m_device->partitionTable() );
}

View File

@ -35,6 +35,11 @@ public:
Partition* partitionForIndex( const QModelIndex& index ) const;
/**
* Reload model from m_device new content
*/
void reload();
private:
Device* m_device;
QList< Partition* > m_partitionList;

View File

@ -25,6 +25,11 @@
#include <PMUtils.h>
#include <ui_PartitionPage.h>
// CalaPM
#include <core/partition.h>
#include <core/partitiontable.h>
#include <fs/ext4.h>
// Qt
#include <QDebug>
#include <QItemSelectionModel>
@ -52,7 +57,10 @@ PartitionPage::PartitionPage( QWidget* parent )
{
updateButtons();
} );
connect( model, &QAbstractItemModel::modelReset, this, &PartitionPage::updateButtons );
} );
connect( m_ui->createButton, &QAbstractButton::clicked, this, &PartitionPage::onCreateClicked );
}
PartitionPage::~PartitionPage()
@ -78,3 +86,23 @@ void PartitionPage::updateButtons()
m_ui->editButton->setEnabled( edit );
m_ui->deleteButton->setEnabled( del );
}
void PartitionPage::onCreateClicked()
{
QModelIndex index = m_ui->partitionListView->currentIndex();
Q_ASSERT( index.isValid() );
const PartitionModel* model = static_cast< const PartitionModel* >( index.model() );
Q_ASSERT( model );
Partition* partition = model->partitionForIndex( index );
Q_ASSERT( partition );
// FIXME: Ask user partition details here
qint64 start = partition->firstSector();
qint64 end = partition->lastSector();
FileSystem* fs = new FS::ext4( start, end, 0, "Calamares" );
PartitionTable::Flags flags = PartitionTable::FlagNone;
QString mountPoint;
m_core->createPartition( partition, fs, mountPoint, flags );
}

View File

@ -43,6 +43,7 @@ private:
QScopedPointer< Ui_PartitionPage > m_ui;
PartitionCoreModule* m_core;
void updateButtons();
void onCreateClicked();
};
#endif // PARTITIONPAGE_H