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-25 16:51:57 +02:00
|
|
|
#include <core/PMUtils.h>
|
2014-09-23 17:42:11 +02:00
|
|
|
#include "core/partition.h"
|
|
|
|
#include "core/device.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-09-23 17:42:11 +02:00
|
|
|
#include "OsproberEntry.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-09-23 17:42:11 +02:00
|
|
|
#include "GlobalStorage.h"
|
|
|
|
#include "JobQueue.h"
|
2014-09-03 18:09:37 +02:00
|
|
|
|
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-23 17:42:11 +02:00
|
|
|
QString osProberReport( "Osprober lines, clean:\n" );
|
|
|
|
OsproberEntryList osproberEntries;
|
2014-09-19 16:27:39 +02:00
|
|
|
foreach ( const QString& line, osproberOutput.split( '\n' ) )
|
|
|
|
{
|
|
|
|
if ( !line.simplified().isEmpty() )
|
2014-09-23 17:42:11 +02:00
|
|
|
{
|
|
|
|
QStringList lineColumns = line.split( ':' );
|
|
|
|
QString prettyName;
|
|
|
|
if ( !lineColumns.value( 1 ).simplified().isEmpty() )
|
|
|
|
prettyName = lineColumns.value( 1 ).simplified();
|
|
|
|
else if ( !lineColumns.value( 2 ).simplified().isEmpty() )
|
|
|
|
prettyName = lineColumns.value( 2 ).simplified();
|
|
|
|
|
|
|
|
QString path = lineColumns.value( 0 ).simplified();
|
|
|
|
if ( !path.startsWith( "/dev/" ) ) //basic sanity check
|
|
|
|
continue;
|
|
|
|
|
|
|
|
osproberEntries.append( { prettyName, path, canBeResized( path ), lineColumns } );
|
|
|
|
osProberReport.append( line );
|
|
|
|
}
|
2014-09-19 16:27:39 +02:00
|
|
|
}
|
2014-09-23 17:42:11 +02:00
|
|
|
cDebug() << osProberReport;
|
2014-09-03 18:09:37 +02:00
|
|
|
|
2014-09-23 17:42:11 +02:00
|
|
|
m_choicePage->init( m_core, osproberEntries );
|
2014-09-04 19:37:30 +02:00
|
|
|
m_erasePage->init( m_core );
|
2014-09-23 17:42:11 +02:00
|
|
|
m_alongsidePage->init( m_core, osproberEntries );
|
2014-09-03 18:09:37 +02:00
|
|
|
|
|
|
|
m_widget->addWidget( m_choicePage );
|
|
|
|
m_widget->addWidget( m_manualPartitionPage );
|
2014-09-25 16:51:57 +02:00
|
|
|
m_widget->addWidget( m_alongsidePage );
|
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();
|
2014-10-06 18:30:23 +02:00
|
|
|
return;
|
2014-09-03 18:09:37 +02:00
|
|
|
}
|
2014-10-06 18:30:23 +02:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2014-10-06 18:30:23 +02:00
|
|
|
if ( m_alongsidePage && m_alongsidePage == m_widget->currentWidget() )
|
|
|
|
return m_alongsidePage->isNextEnabled();
|
|
|
|
|
2014-09-16 18:13:05 +02:00
|
|
|
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 ||
|
2014-09-25 16:51:57 +02:00
|
|
|
m_widget->currentWidget() == m_erasePage ||
|
|
|
|
m_widget->currentWidget() == m_alongsidePage )
|
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
|
|
|
|
|
|
|
|
2014-10-06 18:30:23 +02:00
|
|
|
void
|
|
|
|
PartitionViewStep::onLeave()
|
|
|
|
{
|
|
|
|
if ( m_widget->currentWidget() == m_alongsidePage )
|
|
|
|
{
|
|
|
|
m_alongsidePage->applyChanges();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
}
|
2014-09-23 17:42:11 +02:00
|
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
PartitionViewStep::canBeResized( const QString& partitionPath )
|
|
|
|
{
|
2014-10-06 18:30:23 +02:00
|
|
|
//FIXME: check for max partitions count on DOS MBR
|
2014-09-23 17:42:11 +02:00
|
|
|
cDebug() << "checking if" << partitionPath << "can be resized.";
|
|
|
|
QString partitionWithOs = partitionPath;
|
|
|
|
if ( partitionWithOs.startsWith( "/dev/" ) )
|
|
|
|
{
|
|
|
|
cDebug() << partitionWithOs << "seems like a good path";
|
|
|
|
bool canResize = false;
|
|
|
|
DeviceModel* dm = m_core->deviceModel();
|
|
|
|
for ( int i = 0; i < dm->rowCount(); ++i )
|
|
|
|
{
|
|
|
|
Device* dev = dm->deviceForIndex( dm->index( i ) );
|
2014-09-25 16:51:57 +02:00
|
|
|
Partition* candidate = PMUtils::findPartitionByPath( { dev }, partitionWithOs );
|
|
|
|
if ( candidate )
|
2014-09-23 17:42:11 +02:00
|
|
|
{
|
2014-09-25 16:51:57 +02:00
|
|
|
cDebug() << "found Partition* for" << partitionWithOs;
|
|
|
|
bool ok = false;
|
|
|
|
double requiredStorageGB = Calamares::JobQueue::instance()
|
|
|
|
->globalStorage()
|
|
|
|
->value( "requiredStorageGB" )
|
|
|
|
.toDouble( &ok );
|
|
|
|
|
|
|
|
qint64 availableStorageB = candidate->available() * dev->logicalSectorSize();
|
|
|
|
|
|
|
|
// We require a little more for partitioning overhead and swap file
|
|
|
|
// TODO: maybe make this configurable?
|
|
|
|
qint64 requiredStorageB = ( requiredStorageGB + 0.1 + 2.0 ) * 1024 * 1024 * 1024;
|
|
|
|
cDebug() << "Required storage B:" << requiredStorageB;
|
|
|
|
cDebug() << "Available storage B:" << availableStorageB;
|
|
|
|
if ( ok &&
|
|
|
|
availableStorageB > requiredStorageB )
|
2014-09-23 17:42:11 +02:00
|
|
|
{
|
2014-09-25 16:51:57 +02:00
|
|
|
cDebug() << "Partition" << partitionWithOs << "authorized for resize + autopartition install.";
|
|
|
|
|
|
|
|
return true;
|
2014-09-23 17:42:11 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
cDebug() << "Partition" << partitionWithOs << "CANNOT BE RESIZED FOR AUTOINSTALL.";
|
|
|
|
return false;
|
|
|
|
}
|