2014-12-16 16:24:05 +01:00
|
|
|
/* === This file is part of Calamares - <http://github.com/calamares> ===
|
|
|
|
*
|
2015-05-22 18:16:03 +02:00
|
|
|
* Copyright 2014-2015, Teo Mrnjavac <teo@kde.org>
|
2014-12-16 16:24:05 +01:00
|
|
|
* 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 "ReplacePage.h"
|
|
|
|
#include "ui_ReplacePage.h"
|
|
|
|
|
|
|
|
#include <core/PartitionCoreModule.h>
|
2015-05-25 19:22:47 +02:00
|
|
|
#include <core/device.h>
|
2014-12-16 16:24:05 +01:00
|
|
|
#include <core/DeviceModel.h>
|
|
|
|
#include <core/partition.h>
|
|
|
|
#include <fs/filesystem.h>
|
|
|
|
#include <core/PMUtils.h>
|
|
|
|
#include <core/PartitionInfo.h>
|
|
|
|
|
|
|
|
#include <JobQueue.h>
|
|
|
|
#include <GlobalStorage.h>
|
|
|
|
#include <utils/Retranslator.h>
|
|
|
|
#include <utils/CalamaresUtilsGui.h>
|
|
|
|
#include <utils/Logger.h>
|
|
|
|
#include <Branding.h>
|
|
|
|
|
2015-05-22 18:16:03 +02:00
|
|
|
#include <QDir>
|
|
|
|
#include <QProcess>
|
|
|
|
|
2014-12-16 16:24:05 +01:00
|
|
|
|
|
|
|
ReplacePage::ReplacePage( PartitionCoreModule* core, QWidget* parent )
|
|
|
|
: QWidget( parent )
|
|
|
|
, m_ui( new Ui_ReplacePage )
|
|
|
|
, m_core( core )
|
2015-05-22 18:16:03 +02:00
|
|
|
, m_isEfi( false )
|
2014-12-16 16:24:05 +01:00
|
|
|
{
|
|
|
|
m_ui->setupUi( this );
|
|
|
|
m_ui->deviceComboBox->setModel( m_core->deviceModel() );
|
2015-04-22 11:17:22 +02:00
|
|
|
m_ui->partitionPreview->setLabelsVisible( true );
|
2014-12-16 16:24:05 +01:00
|
|
|
|
2015-05-28 19:09:32 +02:00
|
|
|
m_ui->bootComboBox->hide();
|
|
|
|
m_ui->bootComboBox->clear();
|
|
|
|
m_ui->bootStatusLabel->hide();
|
|
|
|
m_ui->bootStatusLabel->clear();
|
2015-05-22 18:16:03 +02:00
|
|
|
|
2014-12-16 16:24:05 +01:00
|
|
|
// updateButtons();
|
|
|
|
|
|
|
|
updateFromCurrentDevice();
|
|
|
|
|
|
|
|
connect( m_ui->deviceComboBox, &QComboBox::currentTextChanged,
|
|
|
|
[ this ]( const QString& /* text */ )
|
|
|
|
{
|
|
|
|
updateFromCurrentDevice();
|
|
|
|
} );
|
|
|
|
|
|
|
|
CALAMARES_RETRANSLATE(
|
|
|
|
m_ui->retranslateUi( this );
|
|
|
|
onPartitionSelected();
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ReplacePage::~ReplacePage()
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
ReplacePage::isNextEnabled() const
|
|
|
|
{
|
|
|
|
return m_nextEnabled;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-04-29 18:15:46 +02:00
|
|
|
void
|
|
|
|
ReplacePage::reset()
|
|
|
|
{
|
|
|
|
int oldDeviceIndex = m_ui->deviceComboBox->currentIndex();
|
|
|
|
m_core->revert();
|
2015-05-28 19:09:32 +02:00
|
|
|
|
|
|
|
m_ui->bootComboBox->hide();
|
|
|
|
m_ui->bootComboBox->clear();
|
|
|
|
m_ui->bootStatusLabel->hide();
|
|
|
|
m_ui->bootStatusLabel->clear();
|
|
|
|
|
2015-04-29 18:15:46 +02:00
|
|
|
m_ui->deviceComboBox->setCurrentIndex( oldDeviceIndex );
|
|
|
|
updateFromCurrentDevice();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-12-16 16:24:05 +01:00
|
|
|
void
|
|
|
|
ReplacePage::applyChanges()
|
|
|
|
{
|
|
|
|
PartitionModel* model = qobject_cast< PartitionModel* >( m_ui->partitionTreeView->model() );
|
|
|
|
if ( model )
|
|
|
|
{
|
|
|
|
Partition* partition = model->partitionForIndex( m_ui->partitionTreeView->currentIndex() );
|
|
|
|
if ( partition )
|
|
|
|
{
|
|
|
|
Device* dev = model->device();
|
|
|
|
Partition* newPartition = PMUtils::createNewPartition(
|
|
|
|
partition->parent(),
|
|
|
|
*dev,
|
|
|
|
partition->roles(),
|
|
|
|
FileSystem::Ext4,
|
|
|
|
partition->firstSector(),
|
|
|
|
partition->lastSector() );
|
|
|
|
PartitionInfo::setMountPoint( newPartition, "/" );
|
|
|
|
PartitionInfo::setFormat( newPartition, true );
|
|
|
|
|
|
|
|
m_core->deletePartition( dev, partition );
|
|
|
|
m_core->createPartition( dev, newPartition );
|
|
|
|
|
2015-05-22 18:16:03 +02:00
|
|
|
if ( m_isEfi )
|
|
|
|
{
|
2015-05-28 19:09:32 +02:00
|
|
|
QList< Partition* > efiSystemPartitions = m_core->efiSystemPartitions();
|
|
|
|
if ( efiSystemPartitions.count() == 1 )
|
2015-05-22 18:16:03 +02:00
|
|
|
{
|
|
|
|
PartitionInfo::setMountPoint(
|
2015-05-28 19:09:32 +02:00
|
|
|
efiSystemPartitions.first(),
|
2015-05-22 18:16:03 +02:00
|
|
|
Calamares::JobQueue::instance()->
|
|
|
|
globalStorage()->
|
|
|
|
value( "efiSystemPartition" ).toString() );
|
|
|
|
}
|
2015-05-28 19:09:32 +02:00
|
|
|
else if ( efiSystemPartitions.count() > 1 )
|
2015-05-22 18:16:03 +02:00
|
|
|
{
|
|
|
|
PartitionInfo::setMountPoint(
|
2015-05-28 19:09:32 +02:00
|
|
|
efiSystemPartitions.at( m_ui->bootComboBox->currentIndex() ),
|
2015-05-22 18:16:03 +02:00
|
|
|
Calamares::JobQueue::instance()->
|
|
|
|
globalStorage()->
|
|
|
|
value( "efiSystemPartition" ).toString() );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-16 16:24:05 +01:00
|
|
|
m_core->dumpQueue();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
ReplacePage::onPartitionSelected()
|
|
|
|
{
|
2015-05-26 19:22:44 +02:00
|
|
|
if ( Calamares::JobQueue::instance()->globalStorage()->value( "firmwareType" ) == "efi" )
|
|
|
|
m_isEfi = true;
|
|
|
|
|
2014-12-16 16:24:05 +01:00
|
|
|
if ( m_ui->partitionTreeView->currentIndex() == QModelIndex() )
|
|
|
|
{
|
2015-04-03 12:19:27 +02:00
|
|
|
updateStatus( CalamaresUtils::PartitionPartition,
|
2014-12-16 16:24:05 +01:00
|
|
|
tr( "Select where to install %1.<br/>"
|
2014-12-19 14:10:40 +01:00
|
|
|
"<font color=\"red\">Warning: </font>this will delete all files "
|
2014-12-16 16:24:05 +01:00
|
|
|
"on the selected partition." )
|
|
|
|
.arg( Calamares::Branding::instance()->
|
|
|
|
string( Calamares::Branding::VersionedName ) ) );
|
|
|
|
setNextEnabled( false );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ok = false;
|
|
|
|
double requiredSpaceB = Calamares::JobQueue::instance()
|
|
|
|
->globalStorage()
|
|
|
|
->value( "requiredStorageGB" )
|
|
|
|
.toDouble( &ok ) * 1024 * 1024 * 1024;
|
|
|
|
|
|
|
|
PartitionModel* model = qobject_cast< PartitionModel* >( m_ui->partitionTreeView->model() );
|
|
|
|
if ( model && ok )
|
|
|
|
{
|
2014-12-19 15:25:31 +01:00
|
|
|
QStringList osproberLines = Calamares::JobQueue::instance()
|
|
|
|
->globalStorage()
|
|
|
|
->value( "osproberLines" ).toStringList();
|
|
|
|
|
2014-12-16 16:24:05 +01:00
|
|
|
Partition* partition = model->partitionForIndex( m_ui->partitionTreeView->currentIndex() );
|
|
|
|
if ( !partition ||
|
|
|
|
partition->state() != Partition::StateNone )
|
|
|
|
{
|
|
|
|
updateStatus( CalamaresUtils::Fail,
|
|
|
|
tr( "The selected item does not appear to be a valid partition." ) );
|
|
|
|
setNextEnabled( false );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( partition->roles().has( PartitionRole::Unallocated ) )
|
|
|
|
{
|
|
|
|
updateStatus( CalamaresUtils::Fail,
|
|
|
|
tr( "%1 cannot be installed on empty space. Please select an "
|
|
|
|
"existing partition." )
|
|
|
|
.arg( Calamares::Branding::instance()->
|
|
|
|
string( Calamares::Branding::VersionedName ) ) );
|
|
|
|
setNextEnabled( false );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( partition->roles().has( PartitionRole::Extended ) )
|
|
|
|
{
|
|
|
|
updateStatus( CalamaresUtils::Fail,
|
|
|
|
tr( "%1 cannot be installed on an extended partition. Please select an "
|
|
|
|
"existing primary or logical partition." )
|
|
|
|
.arg( Calamares::Branding::instance()->
|
|
|
|
string( Calamares::Branding::VersionedName ) ) );
|
|
|
|
setNextEnabled( false );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( partition->partitionPath().isEmpty() )
|
|
|
|
{
|
|
|
|
updateStatus( CalamaresUtils::Fail,
|
|
|
|
tr( "%1 cannot be installed on this partition." )
|
|
|
|
.arg( Calamares::Branding::instance()->
|
|
|
|
string( Calamares::Branding::VersionedName ) ) );
|
|
|
|
setNextEnabled( false );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-12-19 15:25:31 +01:00
|
|
|
QString prettyName = tr( "Data partition (%1)" )
|
|
|
|
.arg( partition->fileSystem().name() );
|
|
|
|
foreach ( const QString& line, osproberLines )
|
|
|
|
{
|
|
|
|
QStringList lineColumns = line.split( ':' );
|
|
|
|
|
|
|
|
QString path = lineColumns.value( 0 ).simplified();
|
|
|
|
if ( path == partition->partitionPath() )
|
|
|
|
{
|
|
|
|
QString osName;
|
|
|
|
if ( !lineColumns.value( 1 ).simplified().isEmpty() )
|
|
|
|
osName = lineColumns.value( 1 ).simplified();
|
|
|
|
else if ( !lineColumns.value( 2 ).simplified().isEmpty() )
|
|
|
|
osName = lineColumns.value( 2 ).simplified();
|
|
|
|
|
|
|
|
if ( osName.isEmpty() )
|
|
|
|
{
|
|
|
|
prettyName = tr( "Unknown system partition (%1)" )
|
|
|
|
.arg( partition->fileSystem().name() );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
prettyName = tr ( "%1 system partition (%2)" )
|
|
|
|
.arg( osName.replace( 0, 1, osName.at( 0 ).toUpper() ) )
|
|
|
|
.arg( partition->fileSystem().name() );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-16 16:24:05 +01:00
|
|
|
if ( partition->capacity() < requiredSpaceB )
|
|
|
|
{
|
|
|
|
updateStatus( CalamaresUtils::Fail,
|
2015-04-10 13:31:49 +02:00
|
|
|
tr( "<strong>%4</strong><br/><br/>"
|
2014-12-19 15:25:31 +01:00
|
|
|
"The partition %1 is too small for %2. Please select a partition "
|
2014-12-16 17:33:19 +01:00
|
|
|
"with capacity at least %3 GiB." )
|
2014-12-16 16:24:05 +01:00
|
|
|
.arg( partition->partitionPath() )
|
|
|
|
.arg( Calamares::Branding::instance()->
|
|
|
|
string( Calamares::Branding::VersionedName ) )
|
|
|
|
.arg( requiredSpaceB / ( 1024. * 1024. * 1024. ),
|
2014-12-19 15:25:31 +01:00
|
|
|
0, 'f', 1 )
|
|
|
|
.arg( prettyName ) );
|
2014-12-16 16:24:05 +01:00
|
|
|
setNextEnabled( false );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-05-22 18:16:03 +02:00
|
|
|
m_ui->bootComboBox->hide();
|
|
|
|
m_ui->bootComboBox->clear();
|
|
|
|
m_ui->bootStatusLabel->hide();
|
|
|
|
m_ui->bootStatusLabel->clear();
|
|
|
|
|
|
|
|
if ( m_isEfi )
|
|
|
|
{
|
2015-05-28 19:09:32 +02:00
|
|
|
QList< Partition* > efiSystemPartitions = m_core->efiSystemPartitions();
|
|
|
|
if ( efiSystemPartitions.count() == 0 )
|
2015-05-22 18:16:03 +02:00
|
|
|
{
|
|
|
|
updateStatus( CalamaresUtils::Fail,
|
|
|
|
tr( "<strong>%2</strong><br/><br/>"
|
|
|
|
"An EFI system partition cannot be found anywhere "
|
|
|
|
"on this system. Please go back and use manual "
|
|
|
|
"partitioning to set up %1." )
|
|
|
|
.arg( Calamares::Branding::instance()->
|
|
|
|
string( Calamares::Branding::ShortProductName ) )
|
|
|
|
.arg( prettyName ) );
|
|
|
|
setNextEnabled( false );
|
|
|
|
}
|
2015-05-28 19:09:32 +02:00
|
|
|
else if ( efiSystemPartitions.count() == 1 )
|
2015-05-22 18:16:03 +02:00
|
|
|
{
|
|
|
|
updateStatus( CalamaresUtils::PartitionPartition,
|
|
|
|
tr( "<strong>%3</strong><br/><br/>"
|
|
|
|
"%1 will be installed on %2.<br/>"
|
|
|
|
"<font color=\"red\">Warning: </font>all data on partition "
|
|
|
|
"%2 will be lost.")
|
|
|
|
.arg( Calamares::Branding::instance()->
|
|
|
|
string( Calamares::Branding::VersionedName ) )
|
|
|
|
.arg( partition->partitionPath() )
|
|
|
|
.arg( prettyName ) );
|
|
|
|
m_ui->bootStatusLabel->show();
|
|
|
|
m_ui->bootStatusLabel->setText(
|
|
|
|
tr( "The EFI system partition at %1 will be used for starting %2." )
|
2015-05-28 19:09:32 +02:00
|
|
|
.arg( efiSystemPartitions.first()->partitionPath() )
|
2014-12-16 16:24:05 +01:00
|
|
|
.arg( Calamares::Branding::instance()->
|
2015-05-22 18:16:03 +02:00
|
|
|
string( Calamares::Branding::ShortProductName ) ) );
|
|
|
|
setNextEnabled( true );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
updateStatus( CalamaresUtils::PartitionPartition,
|
|
|
|
tr( "<strong>%3</strong><br/><br/>"
|
|
|
|
"%1 will be installed on %2.<br/>"
|
|
|
|
"<font color=\"red\">Warning: </font>all data on partition "
|
|
|
|
"%2 will be lost.")
|
|
|
|
.arg( Calamares::Branding::instance()->
|
|
|
|
string( Calamares::Branding::VersionedName ) )
|
|
|
|
.arg( partition->partitionPath() )
|
|
|
|
.arg( prettyName ) );
|
|
|
|
m_ui->bootStatusLabel->show();
|
|
|
|
m_ui->bootStatusLabel->setText( tr( "EFI system partition:" ) );
|
|
|
|
m_ui->bootComboBox->show();
|
2015-05-28 19:09:32 +02:00
|
|
|
for ( int i = 0; i < efiSystemPartitions.count(); ++i )
|
2015-05-22 18:16:03 +02:00
|
|
|
{
|
2015-05-28 19:09:32 +02:00
|
|
|
Partition* efiPartition = efiSystemPartitions.at( i );
|
2015-05-22 18:16:03 +02:00
|
|
|
m_ui->bootComboBox->addItem( efiPartition->partitionPath(), i );
|
|
|
|
if ( efiPartition->devicePath() == partition->devicePath() &&
|
|
|
|
efiPartition->number() == 1 )
|
|
|
|
m_ui->bootComboBox->setCurrentIndex( i );
|
|
|
|
}
|
|
|
|
setNextEnabled( true );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
updateStatus( CalamaresUtils::PartitionPartition,
|
|
|
|
tr( "<strong>%3</strong><br/><br/>"
|
|
|
|
"%1 will be installed on %2.<br/>"
|
|
|
|
"<font color=\"red\">Warning: </font>all data on partition "
|
|
|
|
"%2 will be lost.")
|
|
|
|
.arg( Calamares::Branding::instance()->
|
|
|
|
string( Calamares::Branding::VersionedName ) )
|
|
|
|
.arg( partition->partitionPath() )
|
|
|
|
.arg( prettyName ) );
|
|
|
|
setNextEnabled( true );
|
|
|
|
}
|
2014-12-16 16:24:05 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
ReplacePage::setNextEnabled( bool enabled )
|
|
|
|
{
|
|
|
|
if ( enabled == m_nextEnabled )
|
|
|
|
return;
|
|
|
|
|
|
|
|
m_nextEnabled = enabled;
|
|
|
|
emit nextStatusChanged( enabled );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
ReplacePage::updateStatus( CalamaresUtils::ImageType imageType, const QString& text )
|
|
|
|
{
|
|
|
|
int iconSize = CalamaresUtils::defaultFontHeight() * 8;
|
|
|
|
m_ui->selectedIconLabel->setPixmap( CalamaresUtils::defaultPixmap( imageType,
|
|
|
|
CalamaresUtils::Original,
|
|
|
|
QSize( iconSize, iconSize ) ) );
|
|
|
|
m_ui->selectedIconLabel->setFixedHeight( iconSize );
|
|
|
|
m_ui->selectedStatusLabel->setText( text );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
ReplacePage::updateFromCurrentDevice()
|
|
|
|
{
|
|
|
|
QModelIndex index = m_core->deviceModel()->index( m_ui->deviceComboBox->currentIndex(), 0 );
|
|
|
|
if ( !index.isValid() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
Device* device = m_core->deviceModel()->deviceForIndex( index );
|
|
|
|
|
|
|
|
QAbstractItemModel* oldModel = m_ui->partitionTreeView->model();
|
|
|
|
if ( oldModel )
|
|
|
|
disconnect( oldModel, 0, this, 0 );
|
|
|
|
|
|
|
|
PartitionModel* model = m_core->partitionModelForDevice( device );
|
|
|
|
m_ui->partitionPreview->setModel( model );
|
|
|
|
m_ui->partitionTreeView->setModel( model );
|
|
|
|
m_ui->partitionTreeView->expandAll();
|
|
|
|
|
|
|
|
// Must be done here because we need to have a model set to define
|
|
|
|
// individual column resize mode
|
|
|
|
QHeaderView* header = m_ui->partitionTreeView->header();
|
|
|
|
header->setSectionResizeMode( QHeaderView::ResizeToContents );
|
|
|
|
header->setSectionResizeMode( 0, QHeaderView::Stretch );
|
|
|
|
|
|
|
|
//updateButtons();
|
|
|
|
// Establish connection here because selection model is destroyed when
|
|
|
|
// model changes
|
2014-12-19 15:27:46 +01:00
|
|
|
connect( m_ui->partitionTreeView->selectionModel(), &QItemSelectionModel::currentRowChanged,
|
|
|
|
this, &ReplacePage::onPartitionViewActivated );
|
|
|
|
|
2014-12-16 16:24:05 +01:00
|
|
|
connect( model, &QAbstractItemModel::modelReset, this, &ReplacePage::onPartitionModelReset );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
ReplacePage::onPartitionViewActivated()
|
|
|
|
{
|
|
|
|
QModelIndex index = m_ui->partitionTreeView->currentIndex();
|
|
|
|
if ( !index.isValid() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
const PartitionModel* model = static_cast< const PartitionModel* >( index.model() );
|
|
|
|
Q_ASSERT( model );
|
|
|
|
Partition* partition = model->partitionForIndex( index );
|
|
|
|
Q_ASSERT( partition );
|
|
|
|
|
|
|
|
onPartitionSelected();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
ReplacePage::onPartitionModelReset()
|
|
|
|
{
|
|
|
|
m_ui->partitionTreeView->expandAll();
|
|
|
|
onPartitionSelected();
|
|
|
|
}
|