mirror of https://github.com/cutefishos/calamares
Introduce CreatePartitionDialog and CreatePartitionJob
parent
bcfbf3eda2
commit
b060f66456
@ -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 );
|
||||
}
|
@ -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 */
|
@ -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>
|
@ -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 );
|
||||
}
|
@ -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 */
|
Loading…
Reference in New Issue