Introduce CreatePartitionDialog and CreatePartitionJob

This commit is contained in:
Aurélien Gâteau 2014-06-30 18:08:13 +02:00
parent bcfbf3eda2
commit b060f66456
10 changed files with 362 additions and 44 deletions

View File

@ -8,12 +8,15 @@ calamares_add_plugin( partition
EXPORT_MACRO PLUGINDLLEXPORT_PRO
CONFIG_FILE module.conf
SOURCES
CreatePartitionDialog.cpp
CreatePartitionJob.cpp
DeviceModel.cpp
PartitionModel.cpp
PartitionPage.cpp
PartitionViewStep.cpp
PMUtils.cpp
UI
CreatePartitionDialog.ui
PartitionPage.ui
LINK_LIBRARIES
calapm
@ -24,6 +27,8 @@ calamares_add_plugin( partition
# Temporary, until views are integrated
set( partview_SRCS
CreatePartitionDialog.cpp
CreatePartitionJob.cpp
DeviceModel.cpp
PartitionCoreModule.cpp
PartitionModel.cpp
@ -32,7 +37,10 @@ set( partview_SRCS
${calamares_SOURCE_DIR}/viewpages/AbstractPage.cpp
main.cpp
)
qt5_wrap_ui( partview_SRCS PartitionPage.ui )
qt5_wrap_ui( partview_SRCS
CreatePartitionDialog.ui
PartitionPage.ui
)
include_directories( ${CMAKE_CURRENT_BINARY_DIR} )

View File

@ -0,0 +1,68 @@
/* === This file is part of Calamares - <http://github.com/calamares> ===
*
* Copyright 2014, Aurélien Gâteau <agateau@kde.org>
*
* Calamares is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Calamares is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Calamares. If not, see <http://www.gnu.org/licenses/>.
*/
#include <CreatePartitionDialog.h>
#include <CreatePartitionJob.h>
#include <ui_CreatePartitionDialog.h>
// CalaPM
#include <core/device.h>
#include <core/partition.h>
#include <fs/filesystem.h>
#include <fs/filesystemfactory.h>
CreatePartitionDialog::CreatePartitionDialog( Device* device, Partition* freePartition, QWidget* parent )
: QDialog( parent )
, m_ui( new Ui_CreatePartitionDialog )
, m_device( device )
, m_freePartition( freePartition )
{
m_ui->setupUi( this );
FileSystemFactory::init();
QStringList fsNames;
for ( auto fs : FileSystemFactory::map() )
{
if ( fs->supportCreate() != FileSystem::cmdSupportNone && fs->type() != FileSystem::Extended )
{
fsNames << fs->name();
}
}
m_ui->fsComboBox->addItems( fsNames );
qint64 maxSize = ( freePartition->lastSector() - freePartition->firstSector() + 1 ) * device->logicalSectorSize();
m_ui->sizeSpinBox->setMaximum( maxSize / 1024 / 1024 );
m_ui->sizeSpinBox->setValue( m_ui->sizeSpinBox->maximum() );
}
CreatePartitionDialog::~CreatePartitionDialog()
{}
CreatePartitionJob*
CreatePartitionDialog::createJob()
{
qint64 first = m_freePartition->firstSector();
// FIXME: Check rounding errors here
qint64 last = first + qint64( m_ui->sizeSpinBox->value() ) * 1024 * 1024 / m_device->logicalSectorSize();
FileSystem::Type type = FileSystem::typeForName( m_ui->fsComboBox->currentText() );
FileSystem* fs = FileSystemFactory::create( type, first, last );
return new CreatePartitionJob( m_device, m_freePartition, fs );
}

View File

@ -0,0 +1,44 @@
/* === This file is part of Calamares - <http://github.com/calamares> ===
*
* Copyright 2014, Aurélien Gâteau <agateau@kde.org>
*
* Calamares is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Calamares is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Calamares. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef CREATEPARTITIONDIALOG_H
#define CREATEPARTITIONDIALOG_H
#include <QDialog>
#include <QScopedPointer>
class CreatePartitionJob;
class Device;
class Partition;
class Ui_CreatePartitionDialog;
class CreatePartitionDialog : public QDialog
{
public:
CreatePartitionDialog( Device* device, Partition* freePartition, QWidget* parent = nullptr );
~CreatePartitionDialog();
CreatePartitionJob* createJob();
private:
QScopedPointer< Ui_CreatePartitionDialog > m_ui;
Device* m_device;
Partition* m_freePartition;
};
#endif /* CREATEPARTITIONDIALOG_H */

View File

@ -0,0 +1,110 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>CreatePartitionDialog</class>
<widget class="QDialog" name="CreatePartitionDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>186</width>
<height>170</height>
</rect>
</property>
<property name="windowTitle">
<string>Create a Partition</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QFormLayout" name="formLayout">
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>File System:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="fsComboBox"/>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Size:</string>
</property>
</widget>
</item>
<item row="3" column="0">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="2" column="1">
<widget class="QSpinBox" name="sizeSpinBox">
<property name="suffix">
<string> MB</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<tabstops>
<tabstop>fsComboBox</tabstop>
<tabstop>sizeSpinBox</tabstop>
<tabstop>buttonBox</tabstop>
</tabstops>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>CreatePartitionDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>181</x>
<y>165</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>CreatePartitionDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>181</x>
<y>165</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View File

@ -0,0 +1,60 @@
/* === This file is part of Calamares - <http://github.com/calamares> ===
*
* Copyright 2014, Aurélien Gâteau <agateau@kde.org>
*
* Calamares is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Calamares is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Calamares. If not, see <http://www.gnu.org/licenses/>.
*/
#include <CreatePartitionJob.h>
// CalaPM
#include <core/device.h>
#include <core/partition.h>
#include <core/partitiontable.h>
#include <fs/filesystem.h>
CreatePartitionJob::CreatePartitionJob( Device* device, Partition* freePartition, FileSystem* fs )
: m_device( device )
, m_freePartition( freePartition )
, m_fs( fs )
{
}
QString
CreatePartitionJob::prettyName()
{
return tr( "Create partition" ); // FIXME
}
void
CreatePartitionJob::exec()
{
}
void
CreatePartitionJob::createPreview()
{
PartitionNode* parent = m_freePartition->parent();
Partition* partition = new Partition(
parent,
*m_device,
PartitionRole( PartitionRole::Primary ), // FIXME: Support extended partitions
m_fs, m_fs->firstSector(), m_fs->lastSector(),
QString() /* path */
);
m_device->partitionTable()->removeUnallocated();
parent->insert( partition );
m_device->partitionTable()->updateUnallocated( *m_device );
}

View File

@ -0,0 +1,47 @@
/* === This file is part of Calamares - <http://github.com/calamares> ===
*
* Copyright 2014, Aurélien Gâteau <agateau@kde.org>
*
* Calamares is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Calamares is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Calamares. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef CREATEPARTITIONJOB_H
#define CREATEPARTITIONJOB_H
#include <Job.h>
class Device;
class Partition;
class FileSystem;
class CreatePartitionJob : public Calamares::Job
{
public:
CreatePartitionJob( Device* device, Partition* freePartition, FileSystem* fs );
QString prettyName() override;
void exec() override;
void createPreview();
Device* device() const
{
return m_device;
}
private:
Device* m_device;
Partition* m_freePartition;
FileSystem* m_fs;
};
#endif /* CREATEPARTITIONJOB_H */

View File

@ -18,16 +18,16 @@
#include <PartitionCoreModule.h>
#include <CreatePartitionJob.h>
#include <DeviceModel.h>
#include <JobQueue.h>
#include <PartitionModel.h>
#include <Typedefs.h>
// CalaPM
#include <CalaPM.h>
#include <backend/corebackend.h>
#include <backend/corebackendmanager.h>
#include <core/device.h>
#include <core/partition.h>
#include <fs/filesystem.h>
//- DeviceInfo --------------------------------------------
@ -89,40 +89,21 @@ PartitionCoreModule::partitionModelForDevice( Device* device ) const
}
void
PartitionCoreModule::createPartition( Partition* freeSpacePartition, FileSystem* fs, const QString& mountPoint, PartitionTable::Flags flags )
PartitionCoreModule::createPartition( CreatePartitionJob* job )
{
DeviceInfo* info = deviceInfoForPath( freeSpacePartition->devicePath() );
DeviceInfo* info = deviceInfoForDevice( job->device() );
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
job->createPreview();
info->partitionModel->reload();
// Create a CreatePartitionJob
// Enqueue job
Calamares::JobQueue::instance()->enqueue( Calamares::job_ptr( job ) );
}
PartitionCoreModule::DeviceInfo*
PartitionCoreModule::deviceInfoForPath( const QString& path ) const
PartitionCoreModule::deviceInfoForDevice( Device* device ) const
{
for ( auto info : m_devices )
{
if ( info->device->deviceNode() == path )
if ( info->device == device )
{
return info;
}

View File

@ -25,6 +25,7 @@
// CalaPM
#include <core/partitiontable.h>
class CreatePartitionJob;
class Device;
class DeviceModel;
class FileSystem;
@ -44,7 +45,7 @@ public:
PartitionModel* partitionModelForDevice( Device* device ) const;
void createPartition( Partition* freeSpacePartition, FileSystem* fs, const QString& mountPoint, PartitionTable::Flags flags );
void createPartition( CreatePartitionJob* job );
private:
struct DeviceInfo
@ -59,7 +60,7 @@ private:
void listDevices();
DeviceInfo* deviceInfoForPath( const QString& path ) const;
DeviceInfo* deviceInfoForDevice( Device* device ) const;
};
#endif /* PARTITIONCOREMODULE_H */

View File

@ -35,6 +35,11 @@ public:
Partition* partitionForIndex( const QModelIndex& index ) const;
Device* device() const
{
return m_device;
}
/**
* Reload model from m_device new content
*/

View File

@ -19,17 +19,13 @@
#include "PartitionPage.h"
// Local
#include <CreatePartitionDialog.h>
#include <DeviceModel.h>
#include <PartitionCoreModule.h>
#include <PartitionModel.h>
#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>
@ -97,12 +93,10 @@ void PartitionPage::onCreateClicked()
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 );
CreatePartitionDialog dlg( model->device(), partition, this );
if ( !dlg.exec() )
{
return;
}
m_core->createPartition( dlg.createJob() );
}