2014-06-30 18:08:13 +02:00
|
|
|
/* === 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>
|
|
|
|
|
2014-07-04 17:58:32 +02:00
|
|
|
#include <PartitionInfo.h>
|
2014-06-30 18:08:13 +02:00
|
|
|
#include <ui_CreatePartitionDialog.h>
|
|
|
|
|
|
|
|
// CalaPM
|
|
|
|
#include <core/device.h>
|
|
|
|
#include <core/partition.h>
|
|
|
|
#include <fs/filesystem.h>
|
|
|
|
#include <fs/filesystemfactory.h>
|
|
|
|
|
2014-07-04 16:14:06 +02:00
|
|
|
// Qt
|
|
|
|
#include <QComboBox>
|
2014-07-04 18:32:35 +02:00
|
|
|
#include <QSet>
|
2014-07-04 16:14:06 +02:00
|
|
|
|
2014-07-15 17:37:04 +02:00
|
|
|
CreatePartitionDialog::CreatePartitionDialog( Device* device, PartitionNode* parentPartition, QWidget* parentWidget )
|
|
|
|
: QDialog( parentWidget )
|
2014-06-30 18:08:13 +02:00
|
|
|
, m_ui( new Ui_CreatePartitionDialog )
|
|
|
|
, m_device( device )
|
2014-07-15 17:37:04 +02:00
|
|
|
, m_parent( parentPartition )
|
2014-06-30 18:08:13 +02:00
|
|
|
{
|
|
|
|
m_ui->setupUi( this );
|
|
|
|
|
|
|
|
FileSystemFactory::init();
|
2014-07-01 17:33:53 +02:00
|
|
|
|
2014-07-15 17:37:04 +02:00
|
|
|
bool parentIsPartitionTable = parentPartition->isRoot();
|
2014-07-04 18:32:35 +02:00
|
|
|
// Partition types
|
|
|
|
QString fixedPartitionType;
|
2014-07-15 17:37:04 +02:00
|
|
|
if ( !parentIsPartitionTable )
|
2014-07-01 17:33:53 +02:00
|
|
|
{
|
|
|
|
m_role = PartitionRole( PartitionRole::Logical );
|
2014-07-04 18:32:35 +02:00
|
|
|
fixedPartitionType = tr( "Logical" );
|
2014-07-01 17:33:53 +02:00
|
|
|
}
|
|
|
|
else if ( m_device->partitionTable()->hasExtended() )
|
|
|
|
{
|
|
|
|
m_role = PartitionRole( PartitionRole::Primary );
|
2014-07-04 18:32:35 +02:00
|
|
|
fixedPartitionType = tr( "Primary" );
|
2014-07-01 17:33:53 +02:00
|
|
|
}
|
|
|
|
|
2014-07-04 18:32:35 +02:00
|
|
|
if ( fixedPartitionType.isEmpty() )
|
|
|
|
m_ui->fixedPartitionLabel->hide();
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_ui->fixedPartitionLabel->setText( fixedPartitionType );
|
2014-07-01 17:33:53 +02:00
|
|
|
m_ui->primaryRadioButton->hide();
|
|
|
|
m_ui->extendedRadioButton->hide();
|
|
|
|
}
|
|
|
|
|
2014-07-04 18:32:35 +02:00
|
|
|
// File system
|
2014-06-30 18:08:13 +02:00
|
|
|
QStringList fsNames;
|
|
|
|
for ( auto fs : FileSystemFactory::map() )
|
|
|
|
{
|
|
|
|
if ( fs->supportCreate() != FileSystem::cmdSupportNone && fs->type() != FileSystem::Extended )
|
|
|
|
fsNames << fs->name();
|
|
|
|
}
|
|
|
|
m_ui->fsComboBox->addItems( fsNames );
|
|
|
|
|
2014-07-04 18:32:35 +02:00
|
|
|
// Connections
|
|
|
|
connect( m_ui->fsComboBox, SIGNAL( activated( int ) ), SLOT( updateMountPointUi() ) );
|
|
|
|
connect( m_ui->extendedRadioButton, SIGNAL( toggled( bool ) ), SLOT( updateMountPointUi() ) );
|
2014-06-30 18:08:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
CreatePartitionDialog::~CreatePartitionDialog()
|
|
|
|
{}
|
|
|
|
|
2014-07-04 17:58:32 +02:00
|
|
|
PartitionInfo*
|
|
|
|
CreatePartitionDialog::createPartitionInfo()
|
2014-06-30 18:08:13 +02:00
|
|
|
{
|
2014-07-01 17:33:53 +02:00
|
|
|
if ( m_role.roles() == PartitionRole::None )
|
|
|
|
{
|
|
|
|
m_role = PartitionRole(
|
2014-07-02 14:12:47 +02:00
|
|
|
m_ui->extendedRadioButton->isChecked()
|
|
|
|
? PartitionRole::Extended
|
|
|
|
: PartitionRole::Primary
|
|
|
|
);
|
2014-07-01 17:33:53 +02:00
|
|
|
}
|
|
|
|
|
2014-06-30 18:08:13 +02:00
|
|
|
// FIXME: Check rounding errors here
|
2014-07-15 17:37:04 +02:00
|
|
|
qint64 last = m_minSector + qint64( m_ui->sizeSpinBox->value() ) * 1024 * 1024 / m_device->logicalSectorSize();
|
2014-06-30 18:08:13 +02:00
|
|
|
|
2014-07-01 17:33:53 +02:00
|
|
|
FileSystem::Type type = m_role.has( PartitionRole::Extended )
|
2014-07-02 14:12:47 +02:00
|
|
|
? FileSystem::Extended
|
|
|
|
: FileSystem::typeForName( m_ui->fsComboBox->currentText() );
|
2014-07-15 17:37:04 +02:00
|
|
|
FileSystem* fs = FileSystemFactory::create( type, m_minSector, last );
|
2014-07-01 17:09:39 +02:00
|
|
|
|
2014-07-04 17:58:32 +02:00
|
|
|
auto partition = new Partition(
|
2014-07-15 17:37:04 +02:00
|
|
|
m_parent,
|
2014-07-01 17:09:39 +02:00
|
|
|
*m_device,
|
2014-07-01 17:33:53 +02:00
|
|
|
m_role,
|
2014-07-15 17:37:04 +02:00
|
|
|
fs, m_minSector, last,
|
2014-07-02 15:48:47 +02:00
|
|
|
QString() /* path */,
|
|
|
|
PartitionTable::FlagNone /* availableFlags */,
|
2014-07-04 16:34:30 +02:00
|
|
|
QString() /* mountPoint */,
|
2014-07-02 15:48:47 +02:00
|
|
|
false /* mounted */,
|
|
|
|
PartitionTable::FlagNone /* activeFlags */,
|
|
|
|
Partition::StateNew
|
2014-07-01 17:09:39 +02:00
|
|
|
);
|
2014-07-04 17:58:32 +02:00
|
|
|
|
|
|
|
auto info = new PartitionInfo( partition );
|
|
|
|
info->mountPoint = m_ui->mountPointComboBox->currentText();
|
2014-07-04 18:00:25 +02:00
|
|
|
info->format = true;
|
2014-07-04 17:58:32 +02:00
|
|
|
return info;
|
2014-06-30 18:08:13 +02:00
|
|
|
}
|
2014-07-04 18:32:35 +02:00
|
|
|
|
|
|
|
void
|
|
|
|
CreatePartitionDialog::updateMountPointUi()
|
|
|
|
{
|
|
|
|
static QSet< FileSystem::Type > unmountableFS( { FileSystem::Unformatted, FileSystem::LinuxSwap } );
|
|
|
|
|
|
|
|
bool enabled = m_ui->primaryRadioButton->isChecked();
|
|
|
|
if ( enabled )
|
|
|
|
{
|
|
|
|
FileSystem::Type type = FileSystem::typeForName( m_ui->fsComboBox->currentText() );
|
|
|
|
enabled = !unmountableFS.contains( type );
|
|
|
|
}
|
|
|
|
m_ui->mountPointLabel->setEnabled( enabled );
|
|
|
|
m_ui->mountPointComboBox->setEnabled( enabled );
|
|
|
|
}
|
2014-07-15 17:37:04 +02:00
|
|
|
|
2014-07-16 10:15:57 +02:00
|
|
|
void
|
|
|
|
CreatePartitionDialog::initSectorRange( Partition* partition )
|
|
|
|
{
|
|
|
|
PartitionTable* table = m_device->partitionTable();
|
|
|
|
m_minSector = partition->firstSector() - table->freeSectorsBefore( *partition );
|
|
|
|
m_maxSector = partition->lastSector() + table->freeSectorsAfter( *partition );
|
|
|
|
|
|
|
|
qint64 maxSize = ( m_maxSector - m_minSector + 1 ) * m_device->logicalSectorSize();
|
|
|
|
|
|
|
|
m_ui->sizeSpinBox->setMaximum( maxSize / 1024 / 1024 );
|
|
|
|
m_ui->sizeSpinBox->setValue( m_ui->sizeSpinBox->maximum() );
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CreatePartitionDialog::initFromFreeSpace( Partition* freeSpacePartition )
|
|
|
|
{
|
|
|
|
initSectorRange( freeSpacePartition );
|
|
|
|
}
|
|
|
|
|
2014-07-15 17:37:04 +02:00
|
|
|
void
|
2014-07-16 10:02:41 +02:00
|
|
|
CreatePartitionDialog::initFromPartitionInfo( PartitionInfo* partitionInfo )
|
2014-07-15 17:37:04 +02:00
|
|
|
{
|
2014-07-16 10:02:41 +02:00
|
|
|
Q_ASSERT( partitionInfo );
|
|
|
|
Partition* partition = partitionInfo->partition;
|
2014-07-16 10:15:57 +02:00
|
|
|
|
|
|
|
initSectorRange( partition );
|
|
|
|
|
2014-07-15 17:37:04 +02:00
|
|
|
qint64 maxSize = ( partition->lastSector() - partition->firstSector() + 1 ) * m_device->logicalSectorSize();
|
|
|
|
m_ui->sizeSpinBox->setValue( maxSize / 1024 / 1024 );
|
|
|
|
|
2014-07-16 10:02:41 +02:00
|
|
|
m_ui->mountPointComboBox->setCurrentText( partitionInfo->mountPoint );
|
2014-07-15 17:37:04 +02:00
|
|
|
}
|