mirror of
https://github.com/parchlinux/calamares.git
synced 2025-06-28 09:55:37 -04:00
Implement partition removal
This commit is contained in:
parent
f9ca45face
commit
d013e663b8
6 changed files with 93 additions and 4 deletions
|
@ -10,6 +10,7 @@ calamares_add_plugin( partition
|
||||||
SOURCES
|
SOURCES
|
||||||
CreatePartitionDialog.cpp
|
CreatePartitionDialog.cpp
|
||||||
CreatePartitionJob.cpp
|
CreatePartitionJob.cpp
|
||||||
|
DeletePartitionJob.cpp
|
||||||
DeviceModel.cpp
|
DeviceModel.cpp
|
||||||
PartitionCoreModule.cpp
|
PartitionCoreModule.cpp
|
||||||
PartitionModel.cpp
|
PartitionModel.cpp
|
||||||
|
@ -30,6 +31,7 @@ calamares_add_plugin( partition
|
||||||
set( partview_SRCS
|
set( partview_SRCS
|
||||||
CreatePartitionDialog.cpp
|
CreatePartitionDialog.cpp
|
||||||
CreatePartitionJob.cpp
|
CreatePartitionJob.cpp
|
||||||
|
DeletePartitionJob.cpp
|
||||||
DeviceModel.cpp
|
DeviceModel.cpp
|
||||||
PartitionCoreModule.cpp
|
PartitionCoreModule.cpp
|
||||||
PartitionModel.cpp
|
PartitionModel.cpp
|
||||||
|
|
|
@ -27,6 +27,7 @@ class FileSystem;
|
||||||
|
|
||||||
class CreatePartitionJob : public Calamares::Job
|
class CreatePartitionJob : public Calamares::Job
|
||||||
{
|
{
|
||||||
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
CreatePartitionJob( Device* device, Partition* partition );
|
CreatePartitionJob( Device* device, Partition* partition );
|
||||||
QString prettyName() override;
|
QString prettyName() override;
|
||||||
|
@ -38,6 +39,11 @@ public:
|
||||||
return m_device;
|
return m_device;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Partition* partition() const
|
||||||
|
{
|
||||||
|
return m_partition;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Device* m_device;
|
Device* m_device;
|
||||||
Partition* m_partition;
|
Partition* m_partition;
|
||||||
|
|
|
@ -19,13 +19,17 @@
|
||||||
#include <PartitionCoreModule.h>
|
#include <PartitionCoreModule.h>
|
||||||
|
|
||||||
#include <CreatePartitionJob.h>
|
#include <CreatePartitionJob.h>
|
||||||
|
#include <DeletePartitionJob.h>
|
||||||
#include <DeviceModel.h>
|
#include <DeviceModel.h>
|
||||||
#include <JobQueue.h>
|
#include <JobQueue.h>
|
||||||
#include <PartitionModel.h>
|
#include <PartitionModel.h>
|
||||||
#include <Typedefs.h>
|
#include <Typedefs.h>
|
||||||
|
#include <utils/Logger.h>
|
||||||
|
|
||||||
// CalaPM
|
// CalaPM
|
||||||
#include <CalaPM.h>
|
#include <CalaPM.h>
|
||||||
|
#include <core/device.h>
|
||||||
|
#include <core/partition.h>
|
||||||
#include <backend/corebackend.h>
|
#include <backend/corebackend.h>
|
||||||
#include <backend/corebackendmanager.h>
|
#include <backend/corebackendmanager.h>
|
||||||
|
|
||||||
|
@ -95,7 +99,9 @@ PartitionCoreModule::createPartition( CreatePartitionJob* job )
|
||||||
Q_ASSERT( info );
|
Q_ASSERT( info );
|
||||||
job->updatePreview();
|
job->updatePreview();
|
||||||
info->partitionModel->reload();
|
info->partitionModel->reload();
|
||||||
Calamares::JobQueue::instance()->enqueue( Calamares::job_ptr( job ) );
|
m_jobs << Calamares::job_ptr( job );
|
||||||
|
|
||||||
|
dumpQueue();
|
||||||
}
|
}
|
||||||
|
|
||||||
PartitionCoreModule::DeviceInfo*
|
PartitionCoreModule::DeviceInfo*
|
||||||
|
@ -110,3 +116,55 @@ PartitionCoreModule::deviceInfoForDevice( Device* device ) const
|
||||||
}
|
}
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
PartitionCoreModule::deletePartition( Device* device, Partition* partition )
|
||||||
|
{
|
||||||
|
if ( partition->state() == Partition::StateNew )
|
||||||
|
{
|
||||||
|
// Find matching CreatePartitionJob
|
||||||
|
auto it = std::find_if( m_jobs.begin(), m_jobs.end(), [ partition ]( Calamares::job_ptr job )
|
||||||
|
{
|
||||||
|
CreatePartitionJob* createJob = qobject_cast< CreatePartitionJob* >( job.data() );
|
||||||
|
return createJob && createJob->partition() == partition;
|
||||||
|
} );
|
||||||
|
if ( it == m_jobs.end() )
|
||||||
|
{
|
||||||
|
cDebug() << "Failed to find a CreatePartitionJob matching the partition to remove";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Remove it
|
||||||
|
if ( ! partition->parent()->remove( partition ) )
|
||||||
|
{
|
||||||
|
cDebug() << "Failed to remove partition from preview";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
device->partitionTable()->updateUnallocated( *device );
|
||||||
|
m_jobs.erase( it );
|
||||||
|
// The partition is no longer referenced by either a job or the device
|
||||||
|
// partition list, so we have to delete it
|
||||||
|
delete partition;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
DeletePartitionJob* job = new DeletePartitionJob( device, partition );
|
||||||
|
job->updatePreview();
|
||||||
|
Calamares::JobQueue::instance()->enqueue( Calamares::job_ptr( job ) );
|
||||||
|
m_jobs << Calamares::job_ptr( job );
|
||||||
|
}
|
||||||
|
|
||||||
|
DeviceInfo* info = deviceInfoForDevice( device );
|
||||||
|
info->partitionModel->reload();
|
||||||
|
|
||||||
|
dumpQueue();
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
PartitionCoreModule::dumpQueue() const
|
||||||
|
{
|
||||||
|
cDebug() << "Queue:";
|
||||||
|
for ( auto job : m_jobs )
|
||||||
|
{
|
||||||
|
cDebug() << job->prettyName();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -19,12 +19,15 @@
|
||||||
#ifndef PARTITIONCOREMODULE_H
|
#ifndef PARTITIONCOREMODULE_H
|
||||||
#define PARTITIONCOREMODULE_H
|
#define PARTITIONCOREMODULE_H
|
||||||
|
|
||||||
#include <QList>
|
#include <Typedefs.h>
|
||||||
#include <QObject>
|
|
||||||
|
|
||||||
// CalaPM
|
// CalaPM
|
||||||
#include <core/partitiontable.h>
|
#include <core/partitiontable.h>
|
||||||
|
|
||||||
|
// Qt
|
||||||
|
#include <QList>
|
||||||
|
#include <QObject>
|
||||||
|
|
||||||
class CreatePartitionJob;
|
class CreatePartitionJob;
|
||||||
class Device;
|
class Device;
|
||||||
class DeviceModel;
|
class DeviceModel;
|
||||||
|
@ -47,6 +50,8 @@ public:
|
||||||
|
|
||||||
void createPartition( CreatePartitionJob* job );
|
void createPartition( CreatePartitionJob* job );
|
||||||
|
|
||||||
|
void deletePartition( Device* device, Partition* partition );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct DeviceInfo
|
struct DeviceInfo
|
||||||
{
|
{
|
||||||
|
@ -58,9 +63,13 @@ private:
|
||||||
QList< DeviceInfo* > m_devices;
|
QList< DeviceInfo* > m_devices;
|
||||||
DeviceModel* m_deviceModel;
|
DeviceModel* m_deviceModel;
|
||||||
|
|
||||||
|
QList< Calamares::job_ptr > m_jobs;
|
||||||
|
|
||||||
void listDevices();
|
void listDevices();
|
||||||
|
|
||||||
DeviceInfo* deviceInfoForDevice( Device* device ) const;
|
DeviceInfo* deviceInfoForDevice( Device* device ) const;
|
||||||
|
|
||||||
|
void dumpQueue() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* PARTITIONCOREMODULE_H */
|
#endif /* PARTITIONCOREMODULE_H */
|
||||||
|
|
|
@ -58,6 +58,7 @@ PartitionPage::PartitionPage( QWidget* parent )
|
||||||
} );
|
} );
|
||||||
|
|
||||||
connect( m_ui->createButton, &QAbstractButton::clicked, this, &PartitionPage::onCreateClicked );
|
connect( m_ui->createButton, &QAbstractButton::clicked, this, &PartitionPage::onCreateClicked );
|
||||||
|
connect( m_ui->deleteButton, &QAbstractButton::clicked, this, &PartitionPage::onDeleteClicked );
|
||||||
}
|
}
|
||||||
|
|
||||||
PartitionPage::~PartitionPage()
|
PartitionPage::~PartitionPage()
|
||||||
|
@ -92,7 +93,6 @@ PartitionPage::onCreateClicked()
|
||||||
Q_ASSERT( index.isValid() );
|
Q_ASSERT( index.isValid() );
|
||||||
|
|
||||||
const PartitionModel* model = static_cast< const PartitionModel* >( index.model() );
|
const PartitionModel* model = static_cast< const PartitionModel* >( index.model() );
|
||||||
Q_ASSERT( model );
|
|
||||||
Partition* partition = model->partitionForIndex( index );
|
Partition* partition = model->partitionForIndex( index );
|
||||||
Q_ASSERT( partition );
|
Q_ASSERT( partition );
|
||||||
|
|
||||||
|
@ -103,3 +103,16 @@ PartitionPage::onCreateClicked()
|
||||||
}
|
}
|
||||||
delete dlg;
|
delete dlg;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
PartitionPage::onDeleteClicked()
|
||||||
|
{
|
||||||
|
QModelIndex index = m_ui->partitionListView->currentIndex();
|
||||||
|
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 );
|
||||||
|
}
|
||||||
|
|
|
@ -44,6 +44,7 @@ private:
|
||||||
PartitionCoreModule* m_core;
|
PartitionCoreModule* m_core;
|
||||||
void updateButtons();
|
void updateButtons();
|
||||||
void onCreateClicked();
|
void onCreateClicked();
|
||||||
|
void onDeleteClicked();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // PARTITIONPAGE_H
|
#endif // PARTITIONPAGE_H
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue