Start implementing support for creating partitions
This commit is contained in:
parent
3a59cdeda9
commit
c9409ba6b2
@ -25,6 +25,9 @@
|
|||||||
#include <CalaPM.h>
|
#include <CalaPM.h>
|
||||||
#include <backend/corebackend.h>
|
#include <backend/corebackend.h>
|
||||||
#include <backend/corebackendmanager.h>
|
#include <backend/corebackendmanager.h>
|
||||||
|
#include <core/device.h>
|
||||||
|
#include <core/partition.h>
|
||||||
|
#include <fs/filesystem.h>
|
||||||
|
|
||||||
|
|
||||||
//- DeviceInfo --------------------------------------------
|
//- DeviceInfo --------------------------------------------
|
||||||
@ -84,3 +87,45 @@ PartitionCoreModule::partitionModelForDevice( Device* device ) const
|
|||||||
}
|
}
|
||||||
return nullptr;
|
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;
|
||||||
|
}
|
||||||
|
@ -22,8 +22,13 @@
|
|||||||
#include <QList>
|
#include <QList>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
|
||||||
|
// CalaPM
|
||||||
|
#include <core/partitiontable.h>
|
||||||
|
|
||||||
class Device;
|
class Device;
|
||||||
class DeviceModel;
|
class DeviceModel;
|
||||||
|
class FileSystem;
|
||||||
|
class Partition;
|
||||||
class PartitionModel;
|
class PartitionModel;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -39,6 +44,8 @@ public:
|
|||||||
|
|
||||||
PartitionModel* partitionModelForDevice( Device* device ) const;
|
PartitionModel* partitionModelForDevice( Device* device ) const;
|
||||||
|
|
||||||
|
void createPartition( Partition* freeSpacePartition, FileSystem* fs, const QString& mountPoint, PartitionTable::Flags flags );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct DeviceInfo
|
struct DeviceInfo
|
||||||
{
|
{
|
||||||
@ -51,6 +58,8 @@ private:
|
|||||||
DeviceModel* m_deviceModel;
|
DeviceModel* m_deviceModel;
|
||||||
|
|
||||||
void listDevices();
|
void listDevices();
|
||||||
|
|
||||||
|
DeviceInfo* deviceInfoForPath( const QString& path ) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* PARTITIONCOREMODULE_H */
|
#endif /* PARTITIONCOREMODULE_H */
|
||||||
|
@ -33,10 +33,16 @@ PartitionModel::PartitionModel( QObject* parent )
|
|||||||
void
|
void
|
||||||
PartitionModel::init( Device* device )
|
PartitionModel::init( Device* device )
|
||||||
{
|
{
|
||||||
beginResetModel();
|
|
||||||
m_device = device;
|
m_device = device;
|
||||||
|
reload();
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
PartitionModel::reload()
|
||||||
|
{
|
||||||
|
beginResetModel();
|
||||||
m_partitionList.clear();
|
m_partitionList.clear();
|
||||||
if ( device )
|
if ( m_device )
|
||||||
{
|
{
|
||||||
fillPartitionList( m_device->partitionTable() );
|
fillPartitionList( m_device->partitionTable() );
|
||||||
}
|
}
|
||||||
|
@ -35,6 +35,11 @@ public:
|
|||||||
|
|
||||||
Partition* partitionForIndex( const QModelIndex& index ) const;
|
Partition* partitionForIndex( const QModelIndex& index ) const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reload model from m_device new content
|
||||||
|
*/
|
||||||
|
void reload();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Device* m_device;
|
Device* m_device;
|
||||||
QList< Partition* > m_partitionList;
|
QList< Partition* > m_partitionList;
|
||||||
|
@ -25,6 +25,11 @@
|
|||||||
#include <PMUtils.h>
|
#include <PMUtils.h>
|
||||||
#include <ui_PartitionPage.h>
|
#include <ui_PartitionPage.h>
|
||||||
|
|
||||||
|
// CalaPM
|
||||||
|
#include <core/partition.h>
|
||||||
|
#include <core/partitiontable.h>
|
||||||
|
#include <fs/ext4.h>
|
||||||
|
|
||||||
// Qt
|
// Qt
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QItemSelectionModel>
|
#include <QItemSelectionModel>
|
||||||
@ -52,7 +57,10 @@ PartitionPage::PartitionPage( QWidget* parent )
|
|||||||
{
|
{
|
||||||
updateButtons();
|
updateButtons();
|
||||||
} );
|
} );
|
||||||
|
connect( model, &QAbstractItemModel::modelReset, this, &PartitionPage::updateButtons );
|
||||||
} );
|
} );
|
||||||
|
|
||||||
|
connect( m_ui->createButton, &QAbstractButton::clicked, this, &PartitionPage::onCreateClicked );
|
||||||
}
|
}
|
||||||
|
|
||||||
PartitionPage::~PartitionPage()
|
PartitionPage::~PartitionPage()
|
||||||
@ -78,3 +86,23 @@ void PartitionPage::updateButtons()
|
|||||||
m_ui->editButton->setEnabled( edit );
|
m_ui->editButton->setEnabled( edit );
|
||||||
m_ui->deleteButton->setEnabled( del );
|
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 );
|
||||||
|
}
|
||||||
|
@ -43,6 +43,7 @@ private:
|
|||||||
QScopedPointer< Ui_PartitionPage > m_ui;
|
QScopedPointer< Ui_PartitionPage > m_ui;
|
||||||
PartitionCoreModule* m_core;
|
PartitionCoreModule* m_core;
|
||||||
void updateButtons();
|
void updateButtons();
|
||||||
|
void onCreateClicked();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // PARTITIONPAGE_H
|
#endif // PARTITIONPAGE_H
|
||||||
|
Loading…
Reference in New Issue
Block a user