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>
|
2016-03-08 12:44:23 +01:00
|
|
|
* Copyright 2016, Teo Mrnjavac <teo@kde.org>
|
2014-06-30 18:08:13 +02:00
|
|
|
*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
2015-07-02 13:49:21 +02:00
|
|
|
#include "gui/CreatePartitionDialog.h"
|
2014-08-08 13:25:56 +02:00
|
|
|
|
2015-07-02 13:49:21 +02:00
|
|
|
#include "core/ColorUtils.h"
|
|
|
|
#include "core/PartitionInfo.h"
|
2015-09-18 15:41:07 +02:00
|
|
|
#include "core/KPMHelpers.h"
|
2015-07-02 13:49:21 +02:00
|
|
|
#include "gui/PartitionSizeController.h"
|
2014-06-30 18:08:13 +02:00
|
|
|
|
2015-07-02 13:49:21 +02:00
|
|
|
#include "ui_CreatePartitionDialog.h"
|
2014-08-08 13:25:56 +02:00
|
|
|
|
2015-07-02 13:49:21 +02:00
|
|
|
#include "utils/Logger.h"
|
2015-03-16 10:50:34 +01:00
|
|
|
#include "GlobalStorage.h"
|
|
|
|
#include "JobQueue.h"
|
2014-06-30 18:08:13 +02:00
|
|
|
|
2015-07-02 13:49:21 +02:00
|
|
|
// KPMcore
|
|
|
|
#include <kpmcore/core/device.h>
|
|
|
|
#include <kpmcore/core/partition.h>
|
|
|
|
#include <kpmcore/fs/filesystem.h>
|
|
|
|
#include <kpmcore/fs/filesystemfactory.h>
|
2016-06-10 14:45:26 +02:00
|
|
|
#include <kpmcore/fs/luks.h>
|
2014-06-30 18:08:13 +02:00
|
|
|
|
2014-07-04 16:14:06 +02:00
|
|
|
// Qt
|
|
|
|
#include <QComboBox>
|
2015-03-16 10:50:34 +01:00
|
|
|
#include <QDir>
|
2014-07-04 18:32:35 +02:00
|
|
|
#include <QSet>
|
2016-03-08 12:44:01 +01:00
|
|
|
#include <QListWidgetItem>
|
2014-07-04 16:14:06 +02:00
|
|
|
|
2014-07-16 10:59:24 +02:00
|
|
|
static QSet< FileSystem::Type > s_unmountableFS(
|
|
|
|
{
|
|
|
|
FileSystem::Unformatted,
|
2015-07-15 13:26:13 +02:00
|
|
|
FileSystem::LinuxSwap,
|
|
|
|
FileSystem::Extended,
|
|
|
|
FileSystem::Unknown,
|
|
|
|
FileSystem::Lvm2_PV
|
2014-07-16 10:59:24 +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 )
|
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 );
|
2016-06-10 14:45:26 +02:00
|
|
|
m_ui->encryptWidget->setText( tr( "En&crypt" ) );
|
|
|
|
m_ui->encryptWidget->hide();
|
2014-06-30 18:08:13 +02:00
|
|
|
|
2015-03-16 19:21:18 +01:00
|
|
|
QStringList mountPoints = { "/", "/boot", "/home", "/opt", "/usr", "/var" };
|
2015-03-16 10:50:34 +01:00
|
|
|
if ( QDir( "/sys/firmware/efi/efivars" ).exists() )
|
|
|
|
mountPoints << Calamares::JobQueue::instance()->globalStorage()->value( "efiSystemPartition" ).toString();
|
|
|
|
mountPoints.removeDuplicates();
|
|
|
|
mountPoints.sort();
|
|
|
|
m_ui->mountPointComboBox->addItems( mountPoints );
|
|
|
|
|
2015-06-07 03:24:00 +02:00
|
|
|
if ( device->partitionTable()->type() == PartitionTable::msdos ||
|
|
|
|
device->partitionTable()->type() == PartitionTable::msdos_sectorbased )
|
2014-07-28 11:45:13 +02:00
|
|
|
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
|
2016-06-10 15:37:11 +02:00
|
|
|
FileSystem::Type defaultFsType = FileSystem::typeForName(
|
|
|
|
Calamares::JobQueue::instance()->
|
|
|
|
globalStorage()->
|
|
|
|
value( "defaultFileSystemType" ).toString() );
|
|
|
|
int defaultFsIndex = -1;
|
|
|
|
int fsCounter = 0;
|
2014-06-30 18:08:13 +02:00
|
|
|
QStringList fsNames;
|
|
|
|
for ( auto fs : FileSystemFactory::map() )
|
|
|
|
{
|
2016-06-10 15:37:11 +02:00
|
|
|
if ( fs->supportCreate() != FileSystem::cmdSupportNone &&
|
|
|
|
fs->type() != FileSystem::Extended )
|
|
|
|
{
|
2014-06-30 18:08:13 +02:00
|
|
|
fsNames << fs->name();
|
2016-06-10 15:37:11 +02:00
|
|
|
if ( fs->type() == defaultFsType )
|
|
|
|
defaultFsIndex = fsCounter;
|
|
|
|
fsCounter++;
|
|
|
|
}
|
2014-06-30 18:08:13 +02:00
|
|
|
}
|
|
|
|
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() ) );
|
2016-03-08 12:44:01 +01:00
|
|
|
|
2016-06-10 15:37:11 +02:00
|
|
|
// Select a default
|
|
|
|
m_ui->fsComboBox->setCurrentIndex( defaultFsIndex );
|
|
|
|
|
2016-03-08 12:44:01 +01:00
|
|
|
setupFlagsList();
|
2014-06-30 18:08:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
CreatePartitionDialog::~CreatePartitionDialog()
|
|
|
|
{}
|
|
|
|
|
2016-03-08 12:44:01 +01:00
|
|
|
|
|
|
|
PartitionTable::Flags
|
|
|
|
CreatePartitionDialog::newFlags() const
|
|
|
|
{
|
|
|
|
PartitionTable::Flags flags;
|
|
|
|
|
|
|
|
for ( int i = 0; i < m_ui->m_listFlags->count(); i++ )
|
|
|
|
if ( m_ui->m_listFlags->item( i )->checkState() == Qt::Checked )
|
|
|
|
flags |= static_cast< PartitionTable::Flag >(
|
|
|
|
m_ui->m_listFlags->item( i )->data( Qt::UserRole ).toInt() );
|
|
|
|
|
|
|
|
return flags;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
CreatePartitionDialog::setupFlagsList()
|
|
|
|
{
|
|
|
|
int f = 1;
|
|
|
|
QString s;
|
|
|
|
while ( !( s = PartitionTable::flagName( static_cast< PartitionTable::Flag >( f ) ) ).isEmpty() )
|
|
|
|
{
|
|
|
|
QListWidgetItem* item = new QListWidgetItem( s );
|
|
|
|
m_ui->m_listFlags->addItem( item );
|
|
|
|
item->setFlags( Qt::ItemIsUserCheckable | Qt::ItemIsEnabled );
|
|
|
|
item->setData( Qt::UserRole, f );
|
|
|
|
item->setCheckState( Qt::Unchecked );
|
|
|
|
|
|
|
|
f <<= 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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() );
|
2016-06-10 14:45:26 +02:00
|
|
|
|
|
|
|
Partition* partition = nullptr;
|
|
|
|
QString luksPassphrase = m_ui->encryptWidget->passphrase();
|
|
|
|
if ( m_ui->encryptWidget->isVisible() &&
|
|
|
|
!luksPassphrase.isEmpty() )
|
|
|
|
{
|
|
|
|
partition = KPMHelpers::createNewEncryptedPartition(
|
|
|
|
m_parent,
|
|
|
|
*m_device,
|
|
|
|
m_role,
|
|
|
|
fsType, first, last, luksPassphrase, newFlags()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
partition = KPMHelpers::createNewPartition(
|
|
|
|
m_parent,
|
|
|
|
*m_device,
|
|
|
|
m_role,
|
|
|
|
fsType, first, last, newFlags()
|
|
|
|
);
|
|
|
|
}
|
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 );
|
2016-03-08 12:44:01 +01:00
|
|
|
|
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 );
|
2016-06-10 14:45:26 +02:00
|
|
|
|
|
|
|
if ( FS::luks::canEncryptType( type ) )
|
|
|
|
{
|
|
|
|
m_ui->encryptWidget->show();
|
|
|
|
m_ui->encryptWidget->reset();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_ui->encryptWidget->reset();
|
|
|
|
m_ui->encryptWidget->hide();
|
|
|
|
}
|
2014-07-04 18:32:35 +02:00
|
|
|
}
|
|
|
|
m_ui->mountPointLabel->setEnabled( enabled );
|
|
|
|
m_ui->mountPointComboBox->setEnabled( enabled );
|
2015-07-02 12:18:26 +02:00
|
|
|
if ( !enabled )
|
|
|
|
m_ui->mountPointComboBox->setCurrentText( QString() );
|
2014-07-04 18:32:35 +02:00
|
|
|
}
|
2014-07-15 17:37:04 +02:00
|
|
|
|
2014-08-07 13:04:02 +02:00
|
|
|
void
|
|
|
|
CreatePartitionDialog::initPartResizerWidget( Partition* partition )
|
|
|
|
{
|
2015-09-18 15:41:07 +02:00
|
|
|
QColor color = KPMHelpers::isPartitionFreeSpace( partition )
|
2014-08-07 17:26:26 +02:00
|
|
|
? 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
|
|
|
}
|