calamares/src/modules/partition/gui/PartitionViewStep.cpp

421 lines
14 KiB
C++
Raw Normal View History

2014-06-27 17:25:39 +02:00
/* === This file is part of Calamares - <http://github.com/calamares> ===
*
* Copyright 2014, Aurélien Gâteau <agateau@kde.org>
2016-02-12 17:19:30 +01:00
* Copyright 2014-2016, Teo Mrnjavac <teo@kde.org>
2014-06-27 17:25: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 "gui/PartitionViewStep.h"
#include "core/DeviceModel.h"
#include "core/PartitionCoreModule.h"
#include "core/PartitionModel.h"
#include "core/KPMHelpers.h"
#include "core/OsproberEntry.h"
#include "core/PartUtils.h"
#include "gui/ChoicePage.h"
#include "gui/PartitionPage.h"
#include "gui/PartitionBarsView.h"
2015-12-03 19:40:06 +01:00
#include "gui/PartitionLabelsView.h"
#include "CalamaresVersion.h"
#include "utils/CalamaresUtilsGui.h"
#include "utils/Logger.h"
#include "utils/Retranslator.h"
#include "widgets/WaitingWidget.h"
#include "GlobalStorage.h"
#include "JobQueue.h"
#include "Job.h"
#include "Branding.h"
#include <kpmcore/core/device.h>
#include <kpmcore/core/partition.h>
// Qt
#include <QApplication>
#include <QFormLayout>
#include <QLabel>
#include <QProcess>
#include <QStackedWidget>
#include <QTimer>
2014-06-27 17:25:39 +02:00
PartitionViewStep::PartitionViewStep( QObject* parent )
: Calamares::ViewStep( parent )
, m_widget( new QStackedWidget() )
, m_core( new PartitionCoreModule( this ) )
, m_choicePage( nullptr )
, m_manualPartitionPage( new PartitionPage( m_core ) )
{
m_widget->setContentsMargins( 0, 0, 0, 0 );
m_waitingWidget = new WaitingWidget( QString() );
m_widget->addWidget( m_waitingWidget );
CALAMARES_RETRANSLATE( qobject_cast< WaitingWidget* >( m_waitingWidget )->setText( tr( "Gathering system information..." ) ); )
// We're not done loading, but we need the configuration map first.
}
void
PartitionViewStep::continueLoading()
{
Q_ASSERT( !m_choicePage );
2015-11-26 15:31:43 +01:00
m_choicePage = new ChoicePage();
m_choicePage->init( m_core );
m_widget->addWidget( m_choicePage );
m_widget->addWidget( m_manualPartitionPage );
m_widget->removeWidget( m_waitingWidget );
m_waitingWidget->deleteLater();
m_waitingWidget = nullptr;
connect( m_core, &PartitionCoreModule::hasRootMountPointChanged,
this, &PartitionViewStep::nextStatusChanged );
connect( m_choicePage, &ChoicePage::nextStatusChanged,
this, &PartitionViewStep::nextStatusChanged );
}
PartitionViewStep::~PartitionViewStep()
2014-06-27 17:25:39 +02:00
{
if ( m_choicePage && m_choicePage->parent() == nullptr )
m_choicePage->deleteLater();
if ( m_manualPartitionPage && m_manualPartitionPage->parent() == nullptr )
m_manualPartitionPage->deleteLater();
2014-06-27 17:25:39 +02:00
}
QString
PartitionViewStep::prettyName() const
2014-06-27 17:25:39 +02:00
{
return tr( "Partitions" );
}
QWidget*
PartitionViewStep::widget()
{
return m_widget;
}
QWidget*
PartitionViewStep::createSummaryWidget() const
{
QWidget* widget = new QWidget;
QVBoxLayout* mainLayout = new QVBoxLayout;
widget->setLayout( mainLayout );
mainLayout->setMargin( 0 );
ChoicePage::Choice choice = m_choicePage->currentChoice();
QFormLayout* formLayout = new QFormLayout( widget );
2015-04-09 17:49:00 +02:00
const int MARGIN = CalamaresUtils::defaultFontHeight() / 2;
formLayout->setContentsMargins( MARGIN, 0, MARGIN, MARGIN );
mainLayout->addLayout( formLayout );
QList< PartitionCoreModule::SummaryInfo > list = m_core->createSummaryInfo();
if ( list.length() > 1 ) // There are changes on more than one disk
{
//NOTE: all of this should only happen when Manual partitioning is active.
// Any other choice should result in a list.length() == 1.
QLabel* modeLabel = new QLabel;
formLayout->addRow( modeLabel );
QString modeText;
switch ( choice )
{
case ChoicePage::Alongside:
modeText = tr( "Install %1 <strong>alongside</strong> another operating system." )
.arg( Calamares::Branding::instance()->
string( Calamares::Branding::ShortVersionedName ) );
break;
case ChoicePage::Erase:
modeText = tr( "<strong>Erase</strong> disk and install %1." )
.arg( Calamares::Branding::instance()->
string( Calamares::Branding::ShortVersionedName ) );
break;
case ChoicePage::Replace:
modeText = tr( "<strong>Replace</strong> a partition with %1." )
.arg( Calamares::Branding::instance()->
string( Calamares::Branding::ShortVersionedName ) );
break;
default:
modeText = tr( "<strong>Manual</strong> partitioning." );
}
modeLabel->setText( modeText );
}
for ( const auto& info : list )
{
QLabel* diskInfoLabel = new QLabel;
if ( list.length() == 1 ) // this is the only disk preview
{
QString modeText;
switch ( choice )
{
case ChoicePage::Alongside:
modeText = tr( "Install %1 <strong>alongside</strong> another operating system on disk <strong>%2</strong> (%3)." )
.arg( Calamares::Branding::instance()->
string( Calamares::Branding::ShortVersionedName ) )
.arg( info.deviceNode )
.arg( info.deviceName );
break;
case ChoicePage::Erase:
modeText = tr( "<strong>Erase</strong> disk <strong>%2</strong> (%3) and install %1." )
.arg( Calamares::Branding::instance()->
string( Calamares::Branding::ShortVersionedName ) )
.arg( info.deviceNode )
.arg( info.deviceName );
break;
case ChoicePage::Replace:
modeText = tr( "<strong>Replace</strong> a partition on disk <strong>%2</strong> (%3) with %1." )
.arg( Calamares::Branding::instance()->
string( Calamares::Branding::ShortVersionedName ) )
.arg( info.deviceNode )
.arg( info.deviceName );
break;
default:
modeText = tr( "<strong>Manual</strong> partitioning on disk <strong>%1</strong> (%2)." )
.arg( info.deviceNode )
.arg( info.deviceName );
}
diskInfoLabel->setText( modeText );
}
else // multiple disk previews!
{
diskInfoLabel->setText( tr( "Disk <strong>%1</strong> (%2)" )
.arg( info.deviceNode )
.arg( info.deviceName ) );
}
2015-04-09 17:49:00 +02:00
formLayout->addRow( diskInfoLabel );
PartitionBarsView* preview;
2015-12-03 19:40:06 +01:00
PartitionLabelsView* previewLabels;
QVBoxLayout* field;
PartitionBarsView::NestedPartitionsMode mode = Calamares::JobQueue::instance()->globalStorage()->
value( "drawNestedPartitions" ).toBool() ?
PartitionBarsView::DrawNestedPartitions :
PartitionBarsView::NoNestedPartitions;
preview = new PartitionBarsView;
preview->setNestedPartitionsMode( mode );
2015-12-03 19:40:06 +01:00
previewLabels = new PartitionLabelsView;
2016-02-11 16:00:49 +01:00
previewLabels->setExtendedPartitionHidden( mode == PartitionBarsView::NoNestedPartitions );
preview->setModel( info.partitionModelBefore );
2015-12-03 19:40:06 +01:00
previewLabels->setModel( info.partitionModelBefore );
2016-01-13 18:09:20 +01:00
preview->setSelectionMode( QAbstractItemView::NoSelection );
previewLabels->setSelectionMode( QAbstractItemView::NoSelection );
info.partitionModelBefore->setParent( widget );
2015-12-03 19:40:06 +01:00
field = new QVBoxLayout;
CalamaresUtils::unmarginLayout( field );
field->setSpacing( 6 );
field->addWidget( preview );
field->addWidget( previewLabels );
2016-01-25 16:58:54 +01:00
formLayout->addRow( tr( "Current:" ), field );
preview = new PartitionBarsView;
preview->setNestedPartitionsMode( mode );
2015-12-03 19:40:06 +01:00
previewLabels = new PartitionLabelsView;
2016-02-11 16:00:49 +01:00
previewLabels->setExtendedPartitionHidden( mode == PartitionBarsView::NoNestedPartitions );
preview->setModel( info.partitionModelAfter );
2015-12-03 19:40:06 +01:00
previewLabels->setModel( info.partitionModelAfter );
2016-01-13 18:09:20 +01:00
preview->setSelectionMode( QAbstractItemView::NoSelection );
previewLabels->setSelectionMode( QAbstractItemView::NoSelection );
info.partitionModelAfter->setParent( widget );
2015-12-03 19:40:06 +01:00
field = new QVBoxLayout;
CalamaresUtils::unmarginLayout( field );
field->setSpacing( 6 );
field->addWidget( preview );
field->addWidget( previewLabels );
2016-01-13 18:09:20 +01:00
formLayout->addRow( tr( "After:" ), field );
}
QStringList jobsLines;
foreach ( const Calamares::job_ptr& job, jobs() )
{
if ( !job->prettyDescription().isEmpty() )
jobsLines.append( job->prettyDescription() );
}
2015-04-10 12:55:08 +02:00
if ( !jobsLines.isEmpty() )
{
QLabel* jobsLabel = new QLabel( widget );
mainLayout->addWidget( jobsLabel );
jobsLabel->setText( jobsLines.join( "<br/>" ) );
int m = CalamaresUtils::defaultFontHeight() / 2;
jobsLabel->setMargin( CalamaresUtils::defaultFontHeight() / 2 );
QPalette pal;
pal.setColor( QPalette::Background, pal.background().color().lighter( 108 ) );
jobsLabel->setAutoFillBackground( true );
jobsLabel->setPalette( pal );
}
return widget;
}
void
PartitionViewStep::next()
{
if ( m_choicePage == m_widget->currentWidget() )
{
2014-09-04 19:37:30 +02:00
if ( m_choicePage->currentChoice() == ChoicePage::Manual )
{
2014-09-04 19:37:30 +02:00
m_widget->setCurrentWidget( m_manualPartitionPage );
if ( m_core->isDirty() )
m_manualPartitionPage->onRevertClicked();
}
2014-09-04 19:37:30 +02:00
else if ( m_choicePage->currentChoice() == ChoicePage::Erase )
{
emit done();
return;
2014-09-04 19:37:30 +02:00
}
else if ( m_choicePage->currentChoice() == ChoicePage::Alongside )
{
2016-01-13 17:50:05 +01:00
emit done();
return;
}
else if ( m_choicePage->currentChoice() == ChoicePage::Replace )
{
emit done();
return;
}
cDebug() << "Choice applied: " << m_choicePage->currentChoice();
return;
}
emit done();
}
void
PartitionViewStep::back()
{
if ( m_widget->currentWidget() != m_choicePage )
m_widget->setCurrentWidget( m_choicePage );
}
bool
PartitionViewStep::isNextEnabled() const
{
if ( m_choicePage && m_choicePage == m_widget->currentWidget() )
return m_choicePage->isNextEnabled();
if ( m_manualPartitionPage && m_manualPartitionPage == m_widget->currentWidget() )
return m_core->hasRootMountPoint();
2014-09-04 19:37:30 +02:00
return false;
}
bool
PartitionViewStep::isBackEnabled() const
{
return true;
}
bool
PartitionViewStep::isAtBeginning() const
{
2016-01-13 17:50:05 +01:00
if ( m_widget->currentWidget() == m_manualPartitionPage )
return false;
return true;
}
bool
PartitionViewStep::isAtEnd() const
{
if ( m_choicePage == m_widget->currentWidget() )
{
2015-12-18 17:46:06 +01:00
if ( m_choicePage->currentChoice() == ChoicePage::Erase ||
2016-01-13 17:50:05 +01:00
m_choicePage->currentChoice() == ChoicePage::Replace ||
m_choicePage->currentChoice() == ChoicePage::Alongside )
return true;
return false;
}
return true;
2014-06-27 17:25:39 +02:00
}
void
PartitionViewStep::onActivate()
{
// if we're coming back to PVS from the next VS
if ( m_widget->currentWidget() == m_choicePage )
{
// m_choicePage->reset();
//FIXME: ReplaceWidget should be reset maybe?
}
}
void
PartitionViewStep::onLeave()
{
if ( m_widget->currentWidget() == m_choicePage )
m_choicePage->onLeave();
}
void
PartitionViewStep::setConfigurationMap( const QVariantMap& configurationMap )
{
// Copy the efiSystemPartition setting to the global storage. It is needed not only in
// the EraseDiskPage, but also in the bootloader configuration modules (grub, bootloader).
Calamares::GlobalStorage* gs = Calamares::JobQueue::instance()->globalStorage();
if ( configurationMap.contains( "efiSystemPartition" ) &&
configurationMap.value( "efiSystemPartition" ).type() == QVariant::String &&
!configurationMap.value( "efiSystemPartition" ).toString().isEmpty() )
{
gs->insert( "efiSystemPartition", configurationMap.value( "efiSystemPartition" ).toString() );
}
else
{
gs->insert( "efiSystemPartition", QStringLiteral( "/boot/efi" ) );
}
if ( configurationMap.contains( "ensureSuspendToDisk" ) &&
configurationMap.value( "ensureSuspendToDisk" ).type() == QVariant::Bool )
{
gs->insert( "ensureSuspendToDisk", configurationMap.value( "ensureSuspendToDisk" ).toBool() );
}
else
{
gs->insert( "ensureSuspendToDisk", true );
}
if ( configurationMap.contains( "drawNestedPartitions" ) &&
configurationMap.value( "drawNestedPartitions" ).type() == QVariant::Bool )
{
2016-02-10 15:41:32 +01:00
gs->insert( "drawNestedPartitions",
configurationMap.value( "drawNestedPartitions", false ).toBool() );
}
else
{
gs->insert( "drawNestedPartitions", false );
}
QTimer::singleShot( 0, this, &PartitionViewStep::continueLoading );
}
QList< Calamares::job_ptr >
PartitionViewStep::jobs() const
{
2014-07-08 15:46:48 +02:00
return m_core->jobs();
}
2015-09-09 18:52:08 +02:00
CALAMARES_PLUGIN_FACTORY_DEFINITION( PartitionViewStepFactory, registerPlugin<PartitionViewStep>(); )