2014-07-17 09:49:15 +02:00
|
|
|
/* === This file is part of Calamares - <http://github.com/calamares> ===
|
|
|
|
*
|
|
|
|
* Copyright 2014, Aurélien Gâteau <agateau@kde.org>
|
2016-03-04 19:13:49 +01:00
|
|
|
* Copyright 2016, Teo Mrnjavac <teo@kde.org>
|
|
|
|
*
|
|
|
|
* Flags handling originally from KDE Partition Manager,
|
|
|
|
* Copyright 2008-2009, Volker Lanz <vl@fidra.de>
|
|
|
|
* Copyright 2016, Andrius Štikonas <andrius@stikonas.eu>
|
2014-07-17 09:49:15 +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/>.
|
|
|
|
*/
|
|
|
|
|
2014-08-08 13:25:56 +02:00
|
|
|
#include <gui/EditExistingPartitionDialog.h>
|
|
|
|
|
|
|
|
#include <core/ColorUtils.h>
|
|
|
|
#include <core/PartitionCoreModule.h>
|
|
|
|
#include <core/PartitionInfo.h>
|
2015-09-18 15:41:07 +02:00
|
|
|
#include <core/KPMHelpers.h>
|
2014-08-08 13:25:56 +02:00
|
|
|
#include <gui/PartitionSizeController.h>
|
2014-07-17 09:49:15 +02:00
|
|
|
|
|
|
|
#include <ui_EditExistingPartitionDialog.h>
|
2014-08-08 13:25:56 +02:00
|
|
|
|
2014-07-17 09:49:15 +02:00
|
|
|
#include <utils/Logger.h>
|
2015-03-16 10:50:34 +01:00
|
|
|
#include "GlobalStorage.h"
|
|
|
|
#include "JobQueue.h"
|
2014-07-17 09:49:15 +02:00
|
|
|
|
2015-07-08 18:21:19 +02:00
|
|
|
// KPMcore
|
|
|
|
#include <kpmcore/core/device.h>
|
|
|
|
#include <kpmcore/core/partition.h>
|
|
|
|
#include <kpmcore/fs/filesystemfactory.h>
|
2014-07-17 09:49:15 +02:00
|
|
|
|
|
|
|
// Qt
|
|
|
|
#include <QComboBox>
|
2015-03-16 10:50:34 +01:00
|
|
|
#include <QDir>
|
2014-07-17 09:49:15 +02:00
|
|
|
|
|
|
|
EditExistingPartitionDialog::EditExistingPartitionDialog( Device* device, Partition* partition, QWidget* parentWidget )
|
|
|
|
: QDialog( parentWidget )
|
|
|
|
, m_ui( new Ui_EditExistingPartitionDialog )
|
|
|
|
, m_device( device )
|
|
|
|
, m_partition( partition )
|
2014-08-06 18:31:46 +02:00
|
|
|
, m_partitionSizeController( new PartitionSizeController( this ) )
|
2014-07-17 09:49:15 +02:00
|
|
|
{
|
|
|
|
m_ui->setupUi( this );
|
2014-08-06 18:31:46 +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 );
|
|
|
|
|
2014-08-07 17:26:26 +02:00
|
|
|
QColor color = ColorUtils::colorForPartition( m_partition );
|
2014-08-09 11:31:00 +02:00
|
|
|
m_partitionSizeController->init( m_device, m_partition, color );
|
2014-08-06 18:31:46 +02:00
|
|
|
m_partitionSizeController->setSpinBox( m_ui->sizeSpinBox );
|
|
|
|
|
2014-07-17 09:49:15 +02:00
|
|
|
m_ui->mountPointComboBox->setCurrentText( PartitionInfo::mountPoint( partition ) );
|
2014-08-06 18:31:46 +02:00
|
|
|
|
|
|
|
replacePartResizerWidget();
|
|
|
|
|
2015-07-15 12:51:35 +02:00
|
|
|
connect( m_ui->formatRadioButton, &QAbstractButton::toggled,
|
|
|
|
[ this ]( bool doFormat )
|
2014-08-06 18:31:46 +02:00
|
|
|
{
|
|
|
|
replacePartResizerWidget();
|
2015-07-15 12:51:35 +02:00
|
|
|
|
|
|
|
m_ui->fileSystemLabel->setEnabled( doFormat );
|
|
|
|
m_ui->fileSystemComboBox->setEnabled( doFormat );
|
2015-07-15 13:25:52 +02:00
|
|
|
|
2015-07-15 13:35:07 +02:00
|
|
|
if ( !doFormat )
|
|
|
|
m_ui->fileSystemComboBox->setCurrentText( m_partition->fileSystem().name() );
|
|
|
|
|
2015-07-15 13:25:52 +02:00
|
|
|
updateMountPointPicker();
|
|
|
|
} );
|
|
|
|
|
|
|
|
connect( m_ui->fileSystemComboBox, &QComboBox::currentTextChanged,
|
|
|
|
[ this ]( QString )
|
|
|
|
{
|
|
|
|
updateMountPointPicker();
|
2014-08-06 18:31:46 +02:00
|
|
|
} );
|
2015-07-15 12:51:35 +02:00
|
|
|
|
|
|
|
// File system
|
|
|
|
QStringList fsNames;
|
|
|
|
for ( auto fs : FileSystemFactory::map() )
|
|
|
|
{
|
|
|
|
if ( fs->supportCreate() != FileSystem::cmdSupportNone && fs->type() != FileSystem::Extended )
|
|
|
|
fsNames << fs->name();
|
|
|
|
}
|
|
|
|
m_ui->fileSystemComboBox->addItems( fsNames );
|
|
|
|
|
|
|
|
if ( fsNames.contains( m_partition->fileSystem().name() ) )
|
|
|
|
m_ui->fileSystemComboBox->setCurrentText( m_partition->fileSystem().name() );
|
|
|
|
else
|
2016-06-10 15:41:53 +02:00
|
|
|
m_ui->fileSystemComboBox->setCurrentText( Calamares::JobQueue::instance()->
|
|
|
|
globalStorage()->
|
|
|
|
value( "defaultFileSystemType" ).toString() );
|
2015-07-15 12:51:35 +02:00
|
|
|
|
|
|
|
m_ui->fileSystemLabel->setEnabled( m_ui->formatRadioButton->isChecked() );
|
|
|
|
m_ui->fileSystemComboBox->setEnabled( m_ui->formatRadioButton->isChecked() );
|
2016-03-04 19:13:49 +01:00
|
|
|
|
|
|
|
setupFlagsList();
|
2014-07-17 09:49:15 +02:00
|
|
|
}
|
|
|
|
|
2016-03-04 19:13:49 +01:00
|
|
|
|
2014-07-17 09:49:15 +02:00
|
|
|
EditExistingPartitionDialog::~EditExistingPartitionDialog()
|
|
|
|
{}
|
|
|
|
|
2016-03-04 19:13:49 +01:00
|
|
|
|
|
|
|
PartitionTable::Flags
|
|
|
|
EditExistingPartitionDialog::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
|
|
|
|
EditExistingPartitionDialog::setupFlagsList()
|
|
|
|
{
|
|
|
|
int f = 1;
|
|
|
|
QString s;
|
|
|
|
while ( !( s = PartitionTable::flagName( static_cast< PartitionTable::Flag >( f ) ) ).isEmpty() )
|
|
|
|
{
|
|
|
|
if ( m_partition->availableFlags() & f )
|
|
|
|
{
|
|
|
|
QListWidgetItem* item = new QListWidgetItem( s );
|
|
|
|
m_ui->m_listFlags->addItem( item );
|
|
|
|
item->setFlags( Qt::ItemIsUserCheckable | Qt::ItemIsEnabled );
|
|
|
|
item->setData( Qt::UserRole, f );
|
|
|
|
item->setCheckState( ( m_partition->activeFlags() & f ) ?
|
|
|
|
Qt::Checked :
|
|
|
|
Qt::Unchecked );
|
|
|
|
}
|
|
|
|
|
|
|
|
f <<= 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-07-17 09:49:15 +02:00
|
|
|
void
|
2014-07-17 14:59:59 +02:00
|
|
|
EditExistingPartitionDialog::applyChanges( PartitionCoreModule* core )
|
2014-07-17 09:49:15 +02:00
|
|
|
{
|
|
|
|
PartitionInfo::setMountPoint( m_partition, m_ui->mountPointComboBox->currentText() );
|
2014-08-04 18:16:05 +02:00
|
|
|
|
2014-08-09 11:31:00 +02:00
|
|
|
qint64 newFirstSector = m_partitionSizeController->firstSector();
|
2016-03-04 19:13:49 +01:00
|
|
|
qint64 newLastSector = m_partitionSizeController->lastSector();
|
|
|
|
bool partResizedMoved = newFirstSector != m_partition->firstSector() ||
|
|
|
|
newLastSector != m_partition->lastSector();
|
2014-08-06 18:31:46 +02:00
|
|
|
|
2015-07-15 12:51:35 +02:00
|
|
|
FileSystem::Type fsType = FileSystem::Unknown;
|
|
|
|
if ( m_ui->formatRadioButton->isChecked() )
|
|
|
|
{
|
|
|
|
fsType = m_partition->roles().has( PartitionRole::Extended )
|
|
|
|
? FileSystem::Extended
|
|
|
|
: FileSystem::typeForName( m_ui->fileSystemComboBox->currentText() );
|
|
|
|
}
|
|
|
|
|
2016-03-04 19:13:49 +01:00
|
|
|
if ( partResizedMoved )
|
2014-08-04 18:16:05 +02:00
|
|
|
{
|
|
|
|
if ( m_ui->formatRadioButton->isChecked() )
|
|
|
|
{
|
2015-09-18 15:41:07 +02:00
|
|
|
Partition* newPartition = KPMHelpers::createNewPartition(
|
2014-08-05 09:54:30 +02:00
|
|
|
m_partition->parent(),
|
|
|
|
*m_device,
|
|
|
|
m_partition->roles(),
|
2015-07-15 12:51:35 +02:00
|
|
|
fsType,
|
2014-08-06 18:31:46 +02:00
|
|
|
newFirstSector,
|
2016-03-04 19:13:49 +01:00
|
|
|
newLastSector,
|
|
|
|
newFlags() );
|
2014-08-04 18:16:05 +02:00
|
|
|
PartitionInfo::setMountPoint( newPartition, PartitionInfo::mountPoint( m_partition ) );
|
|
|
|
PartitionInfo::setFormat( newPartition, true );
|
|
|
|
|
|
|
|
core->deletePartition( m_device, m_partition );
|
|
|
|
core->createPartition( m_device, newPartition );
|
2016-03-04 19:13:49 +01:00
|
|
|
core->setPartitionFlags( m_device, newPartition, newFlags() );
|
2014-08-04 18:16:05 +02:00
|
|
|
}
|
|
|
|
else
|
2015-07-15 12:51:35 +02:00
|
|
|
{
|
|
|
|
core->resizePartition( m_device,
|
|
|
|
m_partition,
|
|
|
|
newFirstSector,
|
|
|
|
newLastSector );
|
2016-03-04 19:13:49 +01:00
|
|
|
if ( m_partition->activeFlags() != newFlags() )
|
|
|
|
core->setPartitionFlags( m_device, m_partition, newFlags() );
|
2015-07-15 12:51:35 +02:00
|
|
|
}
|
2014-08-04 18:16:05 +02:00
|
|
|
}
|
2014-08-04 19:26:16 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
// No size changes
|
|
|
|
if ( m_ui->formatRadioButton->isChecked() )
|
2015-07-15 12:51:35 +02:00
|
|
|
{
|
|
|
|
// if the FS type is unchanged, we just format
|
|
|
|
if ( m_partition->fileSystem().type() == fsType )
|
|
|
|
{
|
|
|
|
core->formatPartition( m_device, m_partition );
|
2016-03-04 19:13:49 +01:00
|
|
|
if ( m_partition->activeFlags() != newFlags() )
|
|
|
|
core->setPartitionFlags( m_device, m_partition, newFlags() );
|
2015-07-15 12:51:35 +02:00
|
|
|
}
|
|
|
|
else // otherwise, we delete and recreate the partition with new fs type
|
|
|
|
{
|
2015-09-18 15:41:07 +02:00
|
|
|
Partition* newPartition = KPMHelpers::createNewPartition(
|
2015-07-15 12:51:35 +02:00
|
|
|
m_partition->parent(),
|
|
|
|
*m_device,
|
|
|
|
m_partition->roles(),
|
|
|
|
fsType,
|
|
|
|
m_partition->firstSector(),
|
2016-03-04 19:13:49 +01:00
|
|
|
m_partition->lastSector(),
|
|
|
|
newFlags() );
|
2015-07-15 12:51:35 +02:00
|
|
|
PartitionInfo::setMountPoint( newPartition, PartitionInfo::mountPoint( m_partition ) );
|
|
|
|
PartitionInfo::setFormat( newPartition, true );
|
|
|
|
|
|
|
|
core->deletePartition( m_device, m_partition );
|
|
|
|
core->createPartition( m_device, newPartition );
|
2016-03-04 19:13:49 +01:00
|
|
|
core->setPartitionFlags( m_device, newPartition, newFlags() );
|
2015-07-15 12:51:35 +02:00
|
|
|
}
|
|
|
|
}
|
2014-08-04 19:26:16 +02:00
|
|
|
else
|
2015-07-15 12:51:35 +02:00
|
|
|
{
|
2014-08-04 19:26:16 +02:00
|
|
|
core->refreshPartition( m_device, m_partition );
|
2016-03-04 19:13:49 +01:00
|
|
|
if ( m_partition->activeFlags() != newFlags() )
|
|
|
|
core->setPartitionFlags( m_device, m_partition, newFlags() );
|
2015-07-15 12:51:35 +02:00
|
|
|
}
|
2014-08-04 19:26:16 +02:00
|
|
|
}
|
2014-07-17 09:49:15 +02:00
|
|
|
}
|
2014-08-06 18:31:46 +02:00
|
|
|
|
2016-03-04 19:13:49 +01:00
|
|
|
|
2014-08-06 18:31:46 +02:00
|
|
|
void
|
|
|
|
EditExistingPartitionDialog::replacePartResizerWidget()
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* There is no way to reliably update the partition used by
|
|
|
|
* PartResizerWidget, which is necessary when we switch between "format" and
|
|
|
|
* "keep". This is a hack which replaces the existing PartResizerWidget
|
|
|
|
* with a new one.
|
|
|
|
*/
|
|
|
|
PartResizerWidget* widget = new PartResizerWidget( this );
|
|
|
|
|
|
|
|
layout()->replaceWidget( m_ui->partResizerWidget, widget );
|
|
|
|
delete m_ui->partResizerWidget;
|
|
|
|
m_ui->partResizerWidget = widget;
|
|
|
|
|
2014-08-09 11:31:00 +02:00
|
|
|
m_partitionSizeController->setPartResizerWidget( widget, m_ui->formatRadioButton->isChecked() );
|
2014-08-06 18:31:46 +02:00
|
|
|
}
|
2015-07-15 13:25:52 +02:00
|
|
|
|
2016-03-04 19:13:49 +01:00
|
|
|
|
2015-07-15 13:25:52 +02:00
|
|
|
void
|
|
|
|
EditExistingPartitionDialog::updateMountPointPicker()
|
|
|
|
{
|
|
|
|
bool doFormat = m_ui->formatRadioButton->isChecked();
|
|
|
|
FileSystem::Type fsType = FileSystem::Unknown;
|
|
|
|
if ( doFormat )
|
|
|
|
{
|
|
|
|
fsType = FileSystem::typeForName( m_ui->fileSystemComboBox->currentText() );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fsType = m_partition->fileSystem().type();
|
|
|
|
}
|
|
|
|
bool canMount = true;
|
|
|
|
if ( fsType == FileSystem::Extended ||
|
|
|
|
fsType == FileSystem::LinuxSwap ||
|
|
|
|
fsType == FileSystem::Unformatted ||
|
|
|
|
fsType == FileSystem::Unknown ||
|
|
|
|
fsType == FileSystem::Lvm2_PV )
|
|
|
|
{
|
|
|
|
canMount = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_ui->mountPointLabel->setEnabled( canMount );
|
|
|
|
m_ui->mountPointComboBox->setEnabled( canMount );
|
|
|
|
if ( !canMount )
|
|
|
|
m_ui->mountPointComboBox->setCurrentText( QString() );
|
|
|
|
}
|