mirror of
https://github.com/parchlinux/calamares.git
synced 2025-06-29 02:15:36 -04:00
New UI and logic for Alongside autopartitioning+install.
This commit is contained in:
parent
08a2ab94e7
commit
961eadada4
7 changed files with 719 additions and 4 deletions
|
@ -18,9 +18,26 @@
|
|||
|
||||
#include "AlongsidePage.h"
|
||||
|
||||
#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"
|
||||
|
||||
#include "JobQueue.h"
|
||||
#include "GlobalStorage.h"
|
||||
#include "utils/Logger.h"
|
||||
#include "utils/CalamaresUtilsGui.h"
|
||||
|
||||
#include <QBoxLayout>
|
||||
#include <QComboBox>
|
||||
#include <QLabel>
|
||||
|
||||
|
||||
AlongsidePage::AlongsidePage( QWidget* parent )
|
||||
: QWidget( parent )
|
||||
, m_nextEnabled( false )
|
||||
|
@ -28,14 +45,133 @@ AlongsidePage::AlongsidePage( QWidget* parent )
|
|||
{
|
||||
QVBoxLayout* mainLayout = new QVBoxLayout;
|
||||
setLayout( mainLayout );
|
||||
|
||||
QHBoxLayout* partitionsComboLayout = new QHBoxLayout;
|
||||
mainLayout->addLayout( partitionsComboLayout );
|
||||
|
||||
QLabel* partitionsLabel = new QLabel;
|
||||
partitionsLabel->setText( tr( "Choose partition to shrink:" ) );
|
||||
partitionsComboLayout->addWidget( partitionsLabel );
|
||||
|
||||
m_partitionsComboBox = new QComboBox;
|
||||
partitionsComboLayout->addWidget( m_partitionsComboBox );
|
||||
partitionsLabel->setBuddy( m_partitionsComboBox );
|
||||
|
||||
partitionsComboLayout->addStretch();
|
||||
|
||||
mainLayout->addWidget( new QLabel( tr( "Allocate drive space by dragging the divider below:" ) ) );
|
||||
|
||||
m_splitterWidget = new PartitionSplitterWidget;
|
||||
mainLayout->addWidget( m_splitterWidget );
|
||||
|
||||
m_sizeLabel = new QLabel;
|
||||
m_sizeLabel->setWordWrap( true );
|
||||
mainLayout->addWidget( m_sizeLabel );
|
||||
|
||||
mainLayout->addStretch();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
AlongsidePage::init( PartitionCoreModule* core , const OsproberEntryList& osproberEntries )
|
||||
{
|
||||
QLabel* placeholder = new QLabel( "Alongside partitioning goes here." );
|
||||
layout()->addWidget( placeholder );
|
||||
if ( m_core != core )
|
||||
m_core = core;
|
||||
|
||||
m_partitionsComboBox->clear();
|
||||
|
||||
connect( m_partitionsComboBox,
|
||||
static_cast< void ( QComboBox::* )( int ) >( &QComboBox::currentIndexChanged ),
|
||||
this, [ this ]( int index )
|
||||
{
|
||||
QString path = m_partitionsComboBox->itemData( index ).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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
m_splitterWidget->init( allPartitionItems );
|
||||
|
||||
m_splitterWidget->setSplitPartition( candidate->partitionPath(),
|
||||
candidate->used() * 1.1,
|
||||
candidate->capacity() - requiredStorageB,
|
||||
candidate->capacity() / 2,
|
||||
tr( "$RELEASE" ) );
|
||||
|
||||
m_splitterWidget->setFixedHeight( qMax< int >( CalamaresUtils::defaultFontHeight() * 1.5, 30 ) );
|
||||
if ( ok )
|
||||
{
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
setNextEnabled( true );
|
||||
return;
|
||||
}
|
||||
}
|
||||
} );
|
||||
|
||||
connect( m_splitterWidget, &PartitionSplitterWidget::partitionResized,
|
||||
this, [ this ]( const QString& path, qint64 size, qint64 sizeNext )
|
||||
{
|
||||
m_sizeLabel->setText( tr( "With this operation, the partition <b>%1</b> which contains "
|
||||
"%4 will be shrunk "
|
||||
"to %2MB and a new %3MB partition will be created for "
|
||||
"$RELEASE." )
|
||||
.arg( path )
|
||||
.arg( size / ( 1024 * 1024 ) )
|
||||
.arg( sizeNext / ( 1024 * 1024 ) )
|
||||
.arg( m_partitionsComboBox->currentText() ) );
|
||||
} );
|
||||
|
||||
foreach ( const OsproberEntry& e, osproberEntries )
|
||||
{
|
||||
if ( e.canBeResized )
|
||||
m_partitionsComboBox->addItem( e.prettyName + " (" + e.path + ")", e.path );
|
||||
}
|
||||
setNextEnabled( true );
|
||||
}
|
||||
|
||||
|
||||
|
@ -46,6 +182,51 @@ AlongsidePage::isNextEnabled() const
|
|||
}
|
||||
|
||||
|
||||
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() );
|
||||
|
||||
m_core->dumpQueue();
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
AlongsidePage::setNextEnabled( bool enabled )
|
||||
{
|
||||
|
@ -55,3 +236,4 @@ AlongsidePage::setNextEnabled( bool enabled )
|
|||
m_nextEnabled = enabled;
|
||||
emit nextStatusChanged( enabled );
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue