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/>.
|
|
|
|
*/
|
|
|
|
|
2014-08-08 13:25:56 +02:00
|
|
|
#include <gui/CreatePartitionDialog.h>
|
|
|
|
|
|
|
|
#include <core/ColorUtils.h>
|
|
|
|
#include <core/PartitionInfo.h>
|
|
|
|
#include <core/PMUtils.h>
|
|
|
|
#include <gui/PartitionSizeController.h>
|
2014-06-30 18:08:13 +02:00
|
|
|
|
|
|
|
#include <ui_CreatePartitionDialog.h>
|
2014-08-08 13:25:56 +02:00
|
|
|
|
2014-07-16 10:35:09 +02:00
|
|
|
#include <utils/Logger.h>
|
2014-06-30 18:08:13 +02:00
|
|
|
|
|
|
|
// 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-16 10:59:24 +02:00
|
|
|
static QSet< FileSystem::Type > s_unmountableFS(
|
|
|
|
{
|
|
|
|
FileSystem::Unformatted,
|
|
|
|
FileSystem::LinuxSwap
|
|
|
|
} );
|
|
|
|
|
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 )
|
2014-08-09 11:31:00 +02:00
|
|
|
, m_partitionSizeController( new PartitionSizeController( this ) )
|
2014-06-30 18:08:13 +02:00
|
|
|
, 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 );
|
|
|
|
|
2014-07-28 11:45:13 +02:00
|
|
|
if ( device->partitionTable()->type() == PartitionTable::msdos )
|
|
|
|
initMbrPartitionTypeUi();
|
2014-07-04 18:32:35 +02:00
|
|
|
else
|
2014-07-28 11:45:13 +02:00
|
|
|
initGptPartitionTypeUi();
|
2014-07-01 17:33:53 +02:00
|
|
|
|
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-28 11:45:13 +02:00
|
|
|
void
|
|
|
|
CreatePartitionDialog::initMbrPartitionTypeUi()
|
|
|
|
{
|
|
|
|
QString fixedPartitionString;
|
|
|
|
bool parentIsPartitionTable = m_parent->isRoot();
|
|
|
|
if ( !parentIsPartitionTable )
|
|
|
|
{
|
|
|
|
m_role = PartitionRole( PartitionRole::Logical );
|
|
|
|
fixedPartitionString = tr( "Logical" );
|
|
|
|
}
|
|
|
|
else if ( m_device->partitionTable()->hasExtended() )
|
|
|
|
{
|
|
|
|
m_role = PartitionRole( PartitionRole::Primary );
|
|
|
|
fixedPartitionString = tr( "Primary" );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( fixedPartitionString.isEmpty() )
|
|
|
|
m_ui->fixedPartitionLabel->hide();
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_ui->fixedPartitionLabel->setText( fixedPartitionString );
|
|
|
|
m_ui->primaryRadioButton->hide();
|
|
|
|
m_ui->extendedRadioButton->hide();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CreatePartitionDialog::initGptPartitionTypeUi()
|
|
|
|
{
|
|
|
|
m_role = PartitionRole( PartitionRole::Primary );
|
|
|
|
m_ui->fixedPartitionLabel->setText( tr( "GPT" ) );
|
|
|
|
m_ui->primaryRadioButton->hide();
|
|
|
|
m_ui->extendedRadioButton->hide();
|
|
|
|
}
|
|
|
|
|
2014-07-16 16:20:58 +02:00
|
|
|
Partition*
|
|
|
|
CreatePartitionDialog::createPartition()
|
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-08-09 11:31:00 +02:00
|
|
|
qint64 first = m_partitionSizeController->firstSector();
|
|
|
|
qint64 last = m_partitionSizeController->lastSector();
|
2014-06-30 18:08:13 +02:00
|
|
|
|
2014-08-04 18:16:05 +02:00
|
|
|
FileSystem::Type fsType = m_role.has( PartitionRole::Extended )
|
|
|
|
? FileSystem::Extended
|
|
|
|
: FileSystem::typeForName( m_ui->fsComboBox->currentText() );
|
|
|
|
Partition* partition = PMUtils::createNewPartition(
|
2014-08-05 09:54:30 +02:00
|
|
|
m_parent,
|
|
|
|
*m_device,
|
|
|
|
m_role,
|
2014-08-07 13:04:02 +02:00
|
|
|
fsType, first, last );
|
2014-07-04 17:58:32 +02:00
|
|
|
|
2014-07-16 15:50:41 +02:00
|
|
|
PartitionInfo::setMountPoint( partition, m_ui->mountPointComboBox->currentText() );
|
|
|
|
PartitionInfo::setFormat( partition, true );
|
2014-07-16 16:20:58 +02:00
|
|
|
return partition;
|
2014-06-30 18:08:13 +02:00
|
|
|
}
|
2014-07-04 18:32:35 +02:00
|
|
|
|
|
|
|
void
|
|
|
|
CreatePartitionDialog::updateMountPointUi()
|
|
|
|
{
|
|
|
|
bool enabled = m_ui->primaryRadioButton->isChecked();
|
|
|
|
if ( enabled )
|
|
|
|
{
|
|
|
|
FileSystem::Type type = FileSystem::typeForName( m_ui->fsComboBox->currentText() );
|
2014-07-16 10:59:24 +02:00
|
|
|
enabled = !s_unmountableFS.contains( type );
|
2014-07-04 18:32:35 +02:00
|
|
|
}
|
|
|
|
m_ui->mountPointLabel->setEnabled( enabled );
|
|
|
|
m_ui->mountPointComboBox->setEnabled( enabled );
|
|
|
|
}
|
2014-07-15 17:37:04 +02:00
|
|
|
|
2014-08-07 13:04:02 +02:00
|
|
|
void
|
|
|
|
CreatePartitionDialog::initPartResizerWidget( Partition* partition )
|
|
|
|
{
|
2014-08-07 17:26:26 +02:00
|
|
|
QColor color = PMUtils::isPartitionFreeSpace( partition )
|
|
|
|
? ColorUtils::colorForPartitionInFreeSpace( partition )
|
|
|
|
: ColorUtils::colorForPartition( partition );
|
2014-08-09 11:31:00 +02:00
|
|
|
m_partitionSizeController->init( m_device, partition, color );
|
|
|
|
m_partitionSizeController->setPartResizerWidget( m_ui->partResizerWidget );
|
|
|
|
m_partitionSizeController->setSpinBox( m_ui->sizeSpinBox );
|
2014-08-07 13:04:02 +02:00
|
|
|
}
|
|
|
|
|
2014-07-16 10:15:57 +02:00
|
|
|
void
|
|
|
|
CreatePartitionDialog::initFromFreeSpace( Partition* freeSpacePartition )
|
|
|
|
{
|
2014-08-07 13:04:02 +02:00
|
|
|
initPartResizerWidget( freeSpacePartition );
|
2014-07-16 10:15:57 +02:00
|
|
|
}
|
|
|
|
|
2014-07-15 17:37:04 +02:00
|
|
|
void
|
2014-07-16 16:20:58 +02:00
|
|
|
CreatePartitionDialog::initFromPartitionToCreate( Partition* partition )
|
2014-07-15 17:37:04 +02:00
|
|
|
{
|
2014-07-16 16:20:58 +02:00
|
|
|
Q_ASSERT( partition );
|
2014-07-16 10:15:57 +02:00
|
|
|
|
2014-07-16 10:59:24 +02:00
|
|
|
bool isExtended = partition->roles().has( PartitionRole::Extended );
|
|
|
|
Q_ASSERT( !isExtended );
|
|
|
|
if ( isExtended )
|
|
|
|
{
|
|
|
|
cDebug() << "Editing extended partitions is not supported for now";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-08-07 13:04:02 +02:00
|
|
|
initPartResizerWidget( partition );
|
2014-07-15 17:37:04 +02:00
|
|
|
|
2014-07-16 10:59:24 +02:00
|
|
|
// File System
|
|
|
|
FileSystem::Type fsType = partition->fileSystem().type();
|
|
|
|
m_ui->fsComboBox->setCurrentText( FileSystem::nameForType( fsType ) );
|
|
|
|
|
|
|
|
// Mount point
|
2014-07-16 15:50:41 +02:00
|
|
|
m_ui->mountPointComboBox->setCurrentText( PartitionInfo::mountPoint( partition ) );
|
2014-07-16 10:59:24 +02:00
|
|
|
|
|
|
|
updateMountPointUi();
|
2014-07-15 17:37:04 +02:00
|
|
|
}
|