2014-09-19 16:27:39 +02:00
|
|
|
/* === This file is part of Calamares - <http://github.com/calamares> ===
|
|
|
|
*
|
2015-04-28 17:42:11 +02:00
|
|
|
* Copyright 2014-2015, Teo Mrnjavac <teo@kde.org>
|
2014-09-19 16:27:39 +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/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "AlongsidePage.h"
|
|
|
|
|
2014-10-06 18:30:23 +02:00
|
|
|
#include "core/ColorUtils.h"
|
|
|
|
#include "core/PartitionCoreModule.h"
|
|
|
|
#include "core/DeviceModel.h"
|
|
|
|
#include "core/PMUtils.h"
|
|
|
|
#include "core/device.h"
|
|
|
|
#include "core/partition.h"
|
|
|
|
#include "core/PartitionInfo.h"
|
|
|
|
#include "core/PartitionIterator.h"
|
|
|
|
#include "gui/PartitionSplitterWidget.h"
|
2015-04-28 17:42:11 +02:00
|
|
|
#include "gui/PartitionPreview.h"
|
2014-10-06 18:30:23 +02:00
|
|
|
|
|
|
|
#include "JobQueue.h"
|
|
|
|
#include "GlobalStorage.h"
|
|
|
|
#include "utils/Logger.h"
|
|
|
|
#include "utils/CalamaresUtilsGui.h"
|
2014-11-11 17:09:33 +01:00
|
|
|
#include "utils/Retranslator.h"
|
2014-10-16 17:00:08 +02:00
|
|
|
#include "Branding.h"
|
2014-10-06 18:30:23 +02:00
|
|
|
|
2014-09-19 16:27:39 +02:00
|
|
|
#include <QBoxLayout>
|
2014-10-06 18:30:23 +02:00
|
|
|
#include <QComboBox>
|
2014-09-19 16:27:39 +02:00
|
|
|
#include <QLabel>
|
2015-05-29 16:45:24 +02:00
|
|
|
#include <QDir>
|
2014-09-19 16:27:39 +02:00
|
|
|
|
2014-10-06 18:30:23 +02:00
|
|
|
|
2014-09-19 16:27:39 +02:00
|
|
|
AlongsidePage::AlongsidePage( QWidget* parent )
|
|
|
|
: QWidget( parent )
|
|
|
|
, m_nextEnabled( false )
|
|
|
|
, m_core( nullptr )
|
|
|
|
{
|
|
|
|
QVBoxLayout* mainLayout = new QVBoxLayout;
|
|
|
|
setLayout( mainLayout );
|
2014-10-06 18:30:23 +02:00
|
|
|
|
|
|
|
QHBoxLayout* partitionsComboLayout = new QHBoxLayout;
|
|
|
|
mainLayout->addLayout( partitionsComboLayout );
|
|
|
|
|
|
|
|
QLabel* partitionsLabel = new QLabel;
|
|
|
|
partitionsComboLayout->addWidget( partitionsLabel );
|
|
|
|
|
|
|
|
m_partitionsComboBox = new QComboBox;
|
|
|
|
partitionsComboLayout->addWidget( m_partitionsComboBox );
|
|
|
|
partitionsLabel->setBuddy( m_partitionsComboBox );
|
|
|
|
|
|
|
|
partitionsComboLayout->addStretch();
|
|
|
|
|
2015-04-28 17:42:11 +02:00
|
|
|
m_previewWidget = new PartitionPreview;
|
|
|
|
m_previewWidget->setLabelsVisible( true );
|
|
|
|
mainLayout->addWidget( m_previewWidget );
|
|
|
|
|
2014-11-11 17:09:33 +01:00
|
|
|
QLabel* allocateSpaceLabel = new QLabel();
|
|
|
|
mainLayout->addWidget( allocateSpaceLabel );
|
|
|
|
|
|
|
|
CALAMARES_RETRANSLATE(
|
|
|
|
partitionsLabel->setText( tr( "Choose partition to shrink:" ) );
|
|
|
|
allocateSpaceLabel->setText( tr( "Allocate drive space by dragging the divider below:" ) );
|
|
|
|
)
|
2014-10-06 18:30:23 +02:00
|
|
|
|
|
|
|
m_splitterWidget = new PartitionSplitterWidget;
|
|
|
|
mainLayout->addWidget( m_splitterWidget );
|
|
|
|
|
|
|
|
m_sizeLabel = new QLabel;
|
|
|
|
m_sizeLabel->setWordWrap( true );
|
|
|
|
mainLayout->addWidget( m_sizeLabel );
|
|
|
|
|
2015-05-29 16:45:24 +02:00
|
|
|
QBoxLayout* efiLayout = new QHBoxLayout;
|
|
|
|
m_efiLabel = new QLabel;
|
|
|
|
m_efiComboBox = new QComboBox;
|
|
|
|
efiLayout->addWidget( m_efiLabel );
|
|
|
|
efiLayout->addWidget( m_efiComboBox );
|
|
|
|
m_efiLabel->setBuddy( m_efiComboBox );
|
|
|
|
efiLayout->addStretch();
|
|
|
|
mainLayout->addLayout( efiLayout );
|
|
|
|
|
|
|
|
m_efiLabel->hide();
|
|
|
|
m_efiComboBox->hide();
|
|
|
|
|
|
|
|
m_isEfi = QDir( "/sys/firmware/efi/efivars" ).exists();
|
|
|
|
|
2014-10-06 18:30:23 +02:00
|
|
|
mainLayout->addStretch();
|
2014-09-19 16:27:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2014-09-23 17:42:11 +02:00
|
|
|
AlongsidePage::init( PartitionCoreModule* core , const OsproberEntryList& osproberEntries )
|
2014-09-19 16:27:39 +02:00
|
|
|
{
|
2014-10-06 18:30:23 +02:00
|
|
|
if ( m_core != core )
|
|
|
|
m_core = core;
|
|
|
|
|
|
|
|
m_partitionsComboBox->clear();
|
|
|
|
|
|
|
|
connect( m_partitionsComboBox,
|
|
|
|
static_cast< void ( QComboBox::* )( int ) >( &QComboBox::currentIndexChanged ),
|
2015-05-29 16:21:55 +02:00
|
|
|
this, &AlongsidePage::onPartitionSelected );
|
2014-10-06 18:30:23 +02:00
|
|
|
|
|
|
|
connect( m_splitterWidget, &PartitionSplitterWidget::partitionResized,
|
|
|
|
this, [ this ]( const QString& path, qint64 size, qint64 sizeNext )
|
|
|
|
{
|
2015-04-10 13:31:49 +02:00
|
|
|
m_sizeLabel->setText( tr( "With this operation, the partition <strong>%1</strong> which contains "
|
2014-10-06 18:30:23 +02:00
|
|
|
"%4 will be shrunk "
|
2014-10-16 17:00:08 +02:00
|
|
|
"to %2MB and a new %3MB partition will be created for %5." )
|
2014-10-06 18:30:23 +02:00
|
|
|
.arg( path )
|
|
|
|
.arg( size / ( 1024 * 1024 ) )
|
|
|
|
.arg( sizeNext / ( 1024 * 1024 ) )
|
2014-10-16 17:00:08 +02:00
|
|
|
.arg( m_partitionsComboBox->currentText() )
|
|
|
|
.arg( Calamares::Branding::instance()->
|
|
|
|
string( Calamares::Branding::ProductName ) ) );
|
2014-10-06 18:30:23 +02:00
|
|
|
} );
|
|
|
|
|
|
|
|
foreach ( const OsproberEntry& e, osproberEntries )
|
|
|
|
{
|
|
|
|
if ( e.canBeResized )
|
|
|
|
m_partitionsComboBox->addItem( e.prettyName + " (" + e.path + ")", e.path );
|
|
|
|
}
|
|
|
|
setNextEnabled( true );
|
2014-09-19 16:27:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-05-29 16:21:55 +02:00
|
|
|
void
|
|
|
|
AlongsidePage::onPartitionSelected( int comboBoxIndex )
|
|
|
|
{
|
|
|
|
QString path = m_partitionsComboBox->itemData( comboBoxIndex ).toString();
|
|
|
|
cDebug() << "Current index changed:" << path;
|
|
|
|
|
|
|
|
DeviceModel* dm = m_core->deviceModel();
|
|
|
|
for ( int i = 0; i < dm->rowCount(); ++i )
|
|
|
|
{
|
|
|
|
Device* dev = dm->deviceForIndex( dm->index( i ) );
|
|
|
|
Partition* candidate = PMUtils::findPartitionByPath( { dev }, path );
|
|
|
|
if ( candidate )
|
|
|
|
{
|
|
|
|
// store candidate->partitionPath() here!
|
|
|
|
|
|
|
|
bool ok = false;
|
|
|
|
double requiredStorageGB = Calamares::JobQueue::instance()
|
|
|
|
->globalStorage()
|
|
|
|
->value( "requiredStorageGB" )
|
|
|
|
.toDouble( &ok );
|
|
|
|
|
|
|
|
qint64 usedStorageB = candidate->sectorsUsed() * dev->logicalSectorSize();
|
|
|
|
qint64 requiredStorageB = ( requiredStorageGB + 0.1 + 2.0 ) * 1024 * 1024 * 1024;
|
|
|
|
|
|
|
|
// set up splitter widget here, then set up the split position
|
|
|
|
QList< PartitionSplitterItem > allPartitionItems;
|
|
|
|
{
|
|
|
|
PartitionSplitterItem* extendedPartitionItem = nullptr;
|
|
|
|
for ( auto it = PartitionIterator::begin( dev );
|
|
|
|
it != PartitionIterator::end( dev ); ++it )
|
|
|
|
{
|
|
|
|
PartitionSplitterItem newItem = {
|
|
|
|
( *it )->partitionPath(),
|
|
|
|
ColorUtils::colorForPartition( *it ),
|
|
|
|
false,
|
|
|
|
( *it )->capacity(),
|
|
|
|
{}
|
|
|
|
};
|
|
|
|
|
|
|
|
if ( ( *it )->roles().has( PartitionRole::Logical ) && extendedPartitionItem )
|
|
|
|
extendedPartitionItem->children.append( newItem );
|
|
|
|
else
|
|
|
|
{
|
|
|
|
allPartitionItems.append( newItem );
|
|
|
|
if ( ( *it )->roles().has( PartitionRole::Extended ) )
|
|
|
|
extendedPartitionItem = &allPartitionItems.last();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Device* deviceBefore = m_core->createImmutableDeviceCopy( dev );
|
|
|
|
|
|
|
|
PartitionModel* partitionModelBefore = new PartitionModel;
|
|
|
|
partitionModelBefore->init( deviceBefore );
|
|
|
|
deviceBefore->setParent( partitionModelBefore );
|
|
|
|
partitionModelBefore->setParent( m_previewWidget );
|
|
|
|
|
|
|
|
m_previewWidget->setModel( partitionModelBefore );
|
|
|
|
m_splitterWidget->init( allPartitionItems );
|
|
|
|
|
|
|
|
m_splitterWidget->setSplitPartition( candidate->partitionPath(),
|
|
|
|
candidate->used() * 1.1,
|
|
|
|
candidate->capacity() - requiredStorageB,
|
|
|
|
candidate->capacity() / 2,
|
|
|
|
Calamares::Branding::instance()->
|
|
|
|
string( Calamares::Branding::ProductName ) );
|
|
|
|
|
|
|
|
m_splitterWidget->setFixedHeight( qMax< int >( CalamaresUtils::defaultFontHeight() * 1.5, 30 ) );
|
|
|
|
|
2015-05-29 16:45:24 +02:00
|
|
|
m_efiComboBox->hide();
|
|
|
|
m_efiLabel->hide();
|
2015-05-29 16:21:55 +02:00
|
|
|
|
2015-05-29 16:45:24 +02:00
|
|
|
if ( m_isEfi )
|
|
|
|
{
|
|
|
|
QList< Partition* > efiSystemPartitions = m_core->efiSystemPartitions();
|
|
|
|
m_efiLabel->show();
|
2015-05-29 16:21:55 +02:00
|
|
|
|
2015-05-29 16:45:24 +02:00
|
|
|
if ( efiSystemPartitions.count() == 0 )
|
|
|
|
{
|
|
|
|
m_efiLabel->setText(
|
|
|
|
tr( "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 ) ) );
|
|
|
|
setNextEnabled( false );
|
|
|
|
}
|
|
|
|
else if ( efiSystemPartitions.count() == 1 )
|
|
|
|
{
|
|
|
|
m_efiLabel->setText(
|
|
|
|
tr( "The EFI system partition at %1 will be used for "
|
|
|
|
"starting %2." )
|
|
|
|
.arg( efiSystemPartitions.first()->partitionPath() )
|
|
|
|
.arg( Calamares::Branding::instance()->
|
|
|
|
string( Calamares::Branding::ShortProductName ) ) );
|
|
|
|
setNextEnabled( true );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_efiComboBox->show();
|
|
|
|
m_efiLabel->setText( tr( "EFI system partition:" ) );
|
|
|
|
for ( int i = 0; i < efiSystemPartitions.count(); ++i )
|
|
|
|
{
|
|
|
|
Partition* efiPartition = efiSystemPartitions.at( i );
|
|
|
|
m_efiComboBox->addItem( efiPartition->partitionPath(), i );
|
|
|
|
if ( efiPartition->devicePath() == candidate->devicePath() &&
|
|
|
|
efiPartition->number() == 1 )
|
|
|
|
m_efiComboBox->setCurrentIndex( i );
|
|
|
|
}
|
|
|
|
setNextEnabled( true );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
setNextEnabled( true );
|
2015-05-29 16:21:55 +02:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-09-19 16:27:39 +02:00
|
|
|
bool
|
|
|
|
AlongsidePage::isNextEnabled() const
|
|
|
|
{
|
|
|
|
return m_nextEnabled;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-10-06 18:30:23 +02:00
|
|
|
void
|
|
|
|
AlongsidePage::applyChanges()
|
|
|
|
{
|
|
|
|
m_core->revert();
|
|
|
|
|
|
|
|
Q_ASSERT( m_splitterWidget->splitPartitionSize() >= 0 );
|
|
|
|
Q_ASSERT( m_splitterWidget->newPartitionSize() >= 0 );
|
|
|
|
|
|
|
|
|
|
|
|
QString path = m_partitionsComboBox->currentData().toString();
|
|
|
|
|
|
|
|
DeviceModel* dm = m_core->deviceModel();
|
|
|
|
for ( int i = 0; i < dm->rowCount(); ++i )
|
|
|
|
{
|
|
|
|
Device* dev = dm->deviceForIndex( dm->index( i ) );
|
|
|
|
Partition* candidate = PMUtils::findPartitionByPath( { dev }, path );
|
|
|
|
if ( candidate )
|
|
|
|
{
|
|
|
|
qint64 firstSector = candidate->firstSector();
|
|
|
|
qint64 oldLastSector = candidate->lastSector();
|
|
|
|
qint64 newLastSector = m_splitterWidget->splitPartitionSize() /
|
|
|
|
dev->logicalSectorSize();
|
|
|
|
|
|
|
|
m_core->resizePartition( dev, candidate, firstSector, newLastSector );
|
|
|
|
Partition* newPartition = PMUtils::createNewPartition(
|
|
|
|
candidate->parent(),
|
|
|
|
*dev,
|
|
|
|
candidate->roles(),
|
|
|
|
FileSystem::Ext4,
|
|
|
|
newLastSector + 1,
|
|
|
|
oldLastSector );
|
|
|
|
PartitionInfo::setMountPoint( newPartition, "/" );
|
|
|
|
PartitionInfo::setFormat( newPartition, true );
|
|
|
|
|
|
|
|
m_core->createPartition( dev, newPartition );
|
|
|
|
m_core->setBootLoaderInstallPath( dev->deviceNode() );
|
|
|
|
|
2015-05-29 16:45:24 +02:00
|
|
|
if ( m_isEfi )
|
|
|
|
{
|
|
|
|
QList< Partition* > efiSystemPartitions = m_core->efiSystemPartitions();
|
|
|
|
if ( efiSystemPartitions.count() == 1 )
|
|
|
|
{
|
|
|
|
PartitionInfo::setMountPoint(
|
|
|
|
efiSystemPartitions.first(),
|
|
|
|
Calamares::JobQueue::instance()->
|
|
|
|
globalStorage()->
|
|
|
|
value( "efiSystemPartition" ).toString() );
|
|
|
|
}
|
|
|
|
else if ( efiSystemPartitions.count() > 1 )
|
|
|
|
{
|
|
|
|
PartitionInfo::setMountPoint(
|
|
|
|
efiSystemPartitions.at( m_efiComboBox->currentIndex() ),
|
|
|
|
Calamares::JobQueue::instance()->
|
|
|
|
globalStorage()->
|
|
|
|
value( "efiSystemPartition" ).toString() );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-06 18:30:23 +02:00
|
|
|
m_core->dumpQueue();
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-09-19 16:27:39 +02:00
|
|
|
void
|
|
|
|
AlongsidePage::setNextEnabled( bool enabled )
|
|
|
|
{
|
|
|
|
if ( enabled == m_nextEnabled )
|
|
|
|
return;
|
|
|
|
|
|
|
|
m_nextEnabled = enabled;
|
|
|
|
emit nextStatusChanged( enabled );
|
|
|
|
}
|
2014-10-06 18:30:23 +02:00
|
|
|
|