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>
|
|
|
|
*
|
|
|
|
* 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/PartitionViewStep.h>
|
2014-06-27 18:14:39 +02:00
|
|
|
|
2014-08-08 13:25:56 +02:00
|
|
|
#include <core/DeviceModel.h>
|
|
|
|
#include <core/PartitionCoreModule.h>
|
|
|
|
#include <core/PartitionModel.h>
|
2014-09-03 18:09:37 +02:00
|
|
|
#include <gui/ChoicePage.h>
|
2014-09-04 19:37:30 +02:00
|
|
|
#include <gui/EraseDiskPage.h>
|
2014-09-19 16:27:39 +02:00
|
|
|
#include <gui/AlongsidePage.h>
|
2014-08-08 13:25:56 +02:00
|
|
|
#include <gui/PartitionPage.h>
|
|
|
|
#include <gui/PartitionPreview.h>
|
2014-07-30 14:15:29 +02:00
|
|
|
|
2014-09-03 18:09:37 +02:00
|
|
|
#include "CalamaresVersion.h"
|
|
|
|
#include "utils/CalamaresUtilsGui.h"
|
|
|
|
#include "utils/Logger.h"
|
|
|
|
#include "widgets/WaitingWidget.h"
|
|
|
|
|
2014-07-30 14:15:29 +02:00
|
|
|
// Qt
|
2014-09-03 18:09:37 +02:00
|
|
|
#include <QApplication>
|
2014-07-30 14:15:29 +02:00
|
|
|
#include <QFormLayout>
|
|
|
|
#include <QLabel>
|
2014-09-03 18:09:37 +02:00
|
|
|
#include <QProcess>
|
|
|
|
#include <QStackedWidget>
|
|
|
|
#include <QTimer>
|
2014-06-27 17:25:39 +02:00
|
|
|
|
2014-06-30 13:24:59 +02:00
|
|
|
PartitionViewStep::PartitionViewStep( QObject* parent )
|
2014-06-27 18:14:39 +02:00
|
|
|
: Calamares::ViewStep( parent )
|
2014-09-03 18:09:37 +02:00
|
|
|
, m_widget( new QStackedWidget() )
|
2014-07-02 16:06:54 +02:00
|
|
|
, m_core( new PartitionCoreModule( this ) )
|
2014-09-03 18:09:37 +02:00
|
|
|
, m_choicePage( new ChoicePage() )
|
2014-09-04 19:37:30 +02:00
|
|
|
, m_erasePage( new EraseDiskPage() )
|
2014-09-19 16:27:39 +02:00
|
|
|
, m_alongsidePage( new AlongsidePage() )
|
2014-09-03 18:09:37 +02:00
|
|
|
, m_manualPartitionPage( new PartitionPage( m_core ) )
|
|
|
|
{
|
|
|
|
m_widget->setContentsMargins( 0, 0, 0, 0 );
|
|
|
|
|
|
|
|
QWidget* waitingWidget = new WaitingWidget( tr( "Gathering system information..." ) );
|
|
|
|
m_widget->addWidget( waitingWidget );
|
|
|
|
|
|
|
|
QTimer* timer = new QTimer;
|
|
|
|
timer->setSingleShot( true );
|
|
|
|
connect( timer, &QTimer::timeout,
|
|
|
|
[=]()
|
|
|
|
{
|
|
|
|
QString osproberOutput;
|
|
|
|
QProcess osprober;
|
|
|
|
osprober.setProgram( "os-prober" );
|
|
|
|
osprober.setProcessChannelMode( QProcess::SeparateChannels );
|
|
|
|
osprober.start();
|
|
|
|
if ( !osprober.waitForStarted() )
|
|
|
|
{
|
|
|
|
cDebug() << "ERROR: os-prober cannot start.";
|
|
|
|
}
|
|
|
|
else if ( !osprober.waitForFinished( 60000 ) )
|
|
|
|
{
|
|
|
|
cDebug() << "ERROR: os-prober timed out.";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
osproberOutput.append(
|
|
|
|
QString::fromLocal8Bit(
|
|
|
|
osprober.readAllStandardOutput() ).trimmed() );
|
|
|
|
}
|
|
|
|
|
2014-09-19 16:27:39 +02:00
|
|
|
QStringList osproberLines;
|
|
|
|
foreach ( const QString& line, osproberOutput.split( '\n' ) )
|
|
|
|
{
|
|
|
|
if ( !line.simplified().isEmpty() )
|
|
|
|
osproberLines.append( line );
|
|
|
|
}
|
2014-09-03 18:09:37 +02:00
|
|
|
|
|
|
|
m_choicePage->init( m_core, osproberLines );
|
2014-09-04 19:37:30 +02:00
|
|
|
m_erasePage->init( m_core );
|
2014-09-19 16:27:39 +02:00
|
|
|
m_alongsidePage->init( m_core, osproberLines );
|
2014-09-03 18:09:37 +02:00
|
|
|
|
|
|
|
m_widget->addWidget( m_choicePage );
|
|
|
|
m_widget->addWidget( m_manualPartitionPage );
|
2014-09-04 19:37:30 +02:00
|
|
|
m_widget->addWidget( m_erasePage );
|
2014-09-03 18:09:37 +02:00
|
|
|
m_widget->removeWidget( waitingWidget );
|
|
|
|
waitingWidget->deleteLater();
|
|
|
|
|
|
|
|
timer->deleteLater();
|
|
|
|
} );
|
|
|
|
timer->start( 0 );
|
|
|
|
|
2014-09-19 16:27:39 +02:00
|
|
|
connect( m_core, &PartitionCoreModule::hasRootMountPointChanged,
|
|
|
|
this, &PartitionViewStep::nextStatusChanged );
|
|
|
|
connect( m_choicePage, &ChoicePage::nextStatusChanged,
|
|
|
|
this, &PartitionViewStep::nextStatusChanged );
|
|
|
|
connect( m_erasePage, &EraseDiskPage::nextStatusChanged,
|
|
|
|
this, &PartitionViewStep::nextStatusChanged );
|
|
|
|
connect( m_alongsidePage, &AlongsidePage::nextStatusChanged,
|
|
|
|
this, &PartitionViewStep::nextStatusChanged );
|
2014-09-03 18:09:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
PartitionViewStep::~PartitionViewStep()
|
2014-06-27 17:25:39 +02:00
|
|
|
{
|
2014-09-03 18:09:37 +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
|
2014-07-01 11:49:09 +02:00
|
|
|
PartitionViewStep::prettyName() const
|
2014-06-27 17:25:39 +02:00
|
|
|
{
|
2014-06-27 18:14:39 +02:00
|
|
|
return tr( "Partitions" );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QWidget*
|
2014-06-30 13:24:59 +02:00
|
|
|
PartitionViewStep::widget()
|
2014-06-27 18:14:39 +02:00
|
|
|
{
|
2014-09-03 18:09:37 +02:00
|
|
|
return m_widget;
|
2014-06-27 18:14:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-07-30 14:15:29 +02:00
|
|
|
QWidget*
|
|
|
|
PartitionViewStep::createSummaryWidget() const
|
|
|
|
{
|
|
|
|
QWidget* widget = new QWidget;
|
|
|
|
QFormLayout* layout = new QFormLayout( widget );
|
|
|
|
layout->setMargin( 0 );
|
|
|
|
|
|
|
|
QList< PartitionCoreModule::SummaryInfo > list = m_core->createSummaryInfo();
|
|
|
|
for ( const auto& info : list )
|
|
|
|
{
|
|
|
|
PartitionPreview* preview;
|
|
|
|
|
|
|
|
layout->addRow( new QLabel( info.deviceName ) );
|
|
|
|
|
|
|
|
preview = new PartitionPreview;
|
|
|
|
preview->setModel( info.partitionModelBefore );
|
|
|
|
info.partitionModelBefore->setParent( widget );
|
|
|
|
layout->addRow( tr( "Before:" ), preview );
|
|
|
|
|
|
|
|
preview = new PartitionPreview;
|
|
|
|
preview->setModel( info.partitionModelAfter );
|
|
|
|
info.partitionModelAfter->setParent( widget );
|
|
|
|
layout->addRow( tr( "After:" ), preview );
|
|
|
|
}
|
|
|
|
return widget;
|
|
|
|
}
|
|
|
|
|
2014-09-03 18:09:37 +02:00
|
|
|
|
2014-06-27 18:14:39 +02:00
|
|
|
void
|
2014-06-30 13:24:59 +02:00
|
|
|
PartitionViewStep::next()
|
2014-06-27 18:14:39 +02:00
|
|
|
{
|
2014-09-03 18:09:37 +02:00
|
|
|
if ( m_choicePage == m_widget->currentWidget() )
|
|
|
|
{
|
2014-09-04 19:37:30 +02:00
|
|
|
if ( m_choicePage->currentChoice() == ChoicePage::Manual )
|
|
|
|
m_widget->setCurrentWidget( m_manualPartitionPage );
|
|
|
|
else if ( m_choicePage->currentChoice() == ChoicePage::Erase )
|
|
|
|
{
|
|
|
|
if ( m_core->isDirty() )
|
|
|
|
m_core->revert();
|
|
|
|
m_widget->setCurrentWidget( m_erasePage );
|
|
|
|
}
|
2014-09-19 16:27:39 +02:00
|
|
|
else if ( m_choicePage->currentChoice() == ChoicePage::Alongside )
|
|
|
|
{
|
|
|
|
if ( m_core->isDirty() )
|
|
|
|
m_core->revert();
|
|
|
|
m_widget->setCurrentWidget( m_alongsidePage );
|
|
|
|
}
|
2014-09-03 18:09:37 +02:00
|
|
|
cDebug() << "Choice applied: " << m_choicePage->currentChoice();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
emit done();
|
2014-06-27 18:14:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2014-06-30 13:24:59 +02:00
|
|
|
PartitionViewStep::back()
|
2014-09-03 18:09:37 +02:00
|
|
|
{
|
|
|
|
if ( m_widget->currentWidget() != m_choicePage )
|
|
|
|
m_widget->setCurrentWidget( m_choicePage );
|
|
|
|
}
|
2014-06-27 18:14:39 +02:00
|
|
|
|
|
|
|
|
|
|
|
bool
|
2014-07-01 11:49:09 +02:00
|
|
|
PartitionViewStep::isNextEnabled() const
|
2014-06-27 18:14:39 +02:00
|
|
|
{
|
2014-09-03 18:09:37 +02:00
|
|
|
if ( m_choicePage && m_choicePage == m_widget->currentWidget() )
|
|
|
|
return m_choicePage->isNextEnabled();
|
|
|
|
|
2014-09-04 19:37:30 +02:00
|
|
|
if ( m_erasePage && m_erasePage == m_widget->currentWidget() )
|
2014-09-16 18:13:05 +02:00
|
|
|
{
|
|
|
|
return m_erasePage->isNextEnabled() &&
|
|
|
|
m_core->hasRootMountPoint();
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( m_manualPartitionPage && m_manualPartitionPage == m_widget->currentWidget() )
|
|
|
|
return m_core->hasRootMountPoint();
|
2014-09-04 19:37:30 +02:00
|
|
|
|
2014-09-16 18:13:05 +02:00
|
|
|
return false;
|
2014-06-27 18:14:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool
|
2014-07-01 11:49:09 +02:00
|
|
|
PartitionViewStep::isAtBeginning() const
|
2014-06-27 18:14:39 +02:00
|
|
|
{
|
2014-09-08 10:42:26 +02:00
|
|
|
if ( m_widget->currentWidget() == m_manualPartitionPage ||
|
|
|
|
m_widget->currentWidget() == m_erasePage )
|
2014-09-03 18:09:37 +02:00
|
|
|
return false;
|
2014-06-27 18:14:39 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool
|
2014-07-01 11:49:09 +02:00
|
|
|
PartitionViewStep::isAtEnd() const
|
2014-06-27 18:14:39 +02:00
|
|
|
{
|
2014-09-03 18:09:37 +02:00
|
|
|
if ( m_choicePage == m_widget->currentWidget() )
|
|
|
|
return false;
|
2014-06-27 18:14:39 +02:00
|
|
|
return true;
|
2014-06-27 17:25:39 +02:00
|
|
|
}
|
2014-07-08 14:02:21 +02:00
|
|
|
|
|
|
|
|
|
|
|
QList< Calamares::job_ptr >
|
|
|
|
PartitionViewStep::jobs() const
|
|
|
|
{
|
2014-07-08 15:46:48 +02:00
|
|
|
return m_core->jobs();
|
2014-07-08 14:02:21 +02:00
|
|
|
}
|