Improve Osprober logic to immediately check if entries are resizable.
This commit is contained in:
parent
9ebc881223
commit
e7995ad540
@ -32,10 +32,9 @@ AlongsidePage::AlongsidePage( QWidget* parent )
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
AlongsidePage::init( PartitionCoreModule* core , const QStringList& osproberLines )
|
AlongsidePage::init( PartitionCoreModule* core , const OsproberEntryList& osproberEntries )
|
||||||
{
|
{
|
||||||
QLabel* placeholder = new QLabel( "Alongside partitioning goes here.\nOsprober:\n" +
|
QLabel* placeholder = new QLabel( "Alongside partitioning goes here." );
|
||||||
osproberLines.join( '\n' ) );
|
|
||||||
layout()->addWidget( placeholder );
|
layout()->addWidget( placeholder );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,6 +21,8 @@
|
|||||||
|
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
|
|
||||||
|
#include "OsproberEntry.h"
|
||||||
|
|
||||||
class PartitionCoreModule;
|
class PartitionCoreModule;
|
||||||
|
|
||||||
class AlongsidePage : public QWidget
|
class AlongsidePage : public QWidget
|
||||||
@ -29,7 +31,7 @@ class AlongsidePage : public QWidget
|
|||||||
public:
|
public:
|
||||||
explicit AlongsidePage( QWidget* parent = nullptr );
|
explicit AlongsidePage( QWidget* parent = nullptr );
|
||||||
|
|
||||||
void init( PartitionCoreModule* core, const QStringList& osproberLines );
|
void init( PartitionCoreModule* core, const OsproberEntryList& osproberEntries );
|
||||||
|
|
||||||
bool isNextEnabled() const;
|
bool isNextEnabled() const;
|
||||||
|
|
||||||
|
@ -21,11 +21,8 @@
|
|||||||
#include "core/PartitionCoreModule.h"
|
#include "core/PartitionCoreModule.h"
|
||||||
#include "core/DeviceModel.h"
|
#include "core/DeviceModel.h"
|
||||||
#include "core/PartitionModel.h"
|
#include "core/PartitionModel.h"
|
||||||
#include "core/partition.h"
|
#include "OsproberEntry.h"
|
||||||
#include "core/device.h"
|
|
||||||
|
|
||||||
#include "JobQueue.h"
|
|
||||||
#include "GlobalStorage.h"
|
|
||||||
#include "PrettyRadioButton.h"
|
#include "PrettyRadioButton.h"
|
||||||
|
|
||||||
#include "utils/CalamaresUtilsGui.h"
|
#include "utils/CalamaresUtilsGui.h"
|
||||||
@ -61,10 +58,9 @@ ChoicePage::~ChoicePage()
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
ChoicePage::init( PartitionCoreModule* core, const QStringList& osproberLines )
|
ChoicePage::init( PartitionCoreModule* core, const OsproberEntryList& osproberEntries )
|
||||||
{
|
{
|
||||||
m_core = core;
|
m_core = core;
|
||||||
m_osproberLines = osproberLines;
|
|
||||||
|
|
||||||
// sample os-prober output:
|
// sample os-prober output:
|
||||||
// /dev/sda2:Windows 7 (loader):Windows:chain
|
// /dev/sda2:Windows 7 (loader):Windows:chain
|
||||||
@ -103,9 +99,7 @@ ChoicePage::init( PartitionCoreModule* core, const QStringList& osproberLines )
|
|||||||
m_itemsLayout->addWidget( eraseButton );
|
m_itemsLayout->addWidget( eraseButton );
|
||||||
m_itemsLayout->setSpacing( CalamaresUtils::defaultFontHeight() / 2 );
|
m_itemsLayout->setSpacing( CalamaresUtils::defaultFontHeight() / 2 );
|
||||||
|
|
||||||
cDebug() << "Osprober lines, clean:\n" << m_osproberLines.join( '\n' );
|
if ( osproberEntries.count() == 0 )
|
||||||
|
|
||||||
if ( m_osproberLines.count() == 0 )
|
|
||||||
{
|
{
|
||||||
m_messageLabel->setText( tr( "This computer currently does not seem to have an operating system on it. "
|
m_messageLabel->setText( tr( "This computer currently does not seem to have an operating system on it. "
|
||||||
"What would you like to do?" ) );
|
"What would you like to do?" ) );
|
||||||
@ -117,17 +111,9 @@ ChoicePage::init( PartitionCoreModule* core, const QStringList& osproberLines )
|
|||||||
|
|
||||||
alongsideButton->hide();
|
alongsideButton->hide();
|
||||||
}
|
}
|
||||||
else if ( m_osproberLines.count() == 1 )
|
else if ( osproberEntries.count() == 1 )
|
||||||
{
|
|
||||||
QStringList osLine = m_osproberLines.first().split( ':' );
|
|
||||||
QString osName;
|
|
||||||
if ( !osLine.value( 1 ).simplified().isEmpty() )
|
|
||||||
osName = osLine.value( 1 ).simplified();
|
|
||||||
else if ( !osLine.value( 2 ).simplified().isEmpty() )
|
|
||||||
osName = osLine.value( 2 ).simplified();
|
|
||||||
|
|
||||||
if ( canBeResized( osLine ) )
|
|
||||||
{
|
{
|
||||||
|
QString osName = osproberEntries.first().prettyName;
|
||||||
|
|
||||||
if ( !osName.isEmpty() )
|
if ( !osName.isEmpty() )
|
||||||
{
|
{
|
||||||
@ -165,8 +151,7 @@ ChoicePage::init( PartitionCoreModule* core, const QStringList& osproberLines )
|
|||||||
"documents, photos, music, and any other files." )
|
"documents, photos, music, and any other files." )
|
||||||
.arg( "$RELEASE" ) );
|
.arg( "$RELEASE" ) );
|
||||||
}
|
}
|
||||||
}
|
if ( !osproberEntries.first().canBeResized )
|
||||||
else
|
|
||||||
alongsideButton->hide();
|
alongsideButton->hide();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -175,18 +160,15 @@ ChoicePage::init( PartitionCoreModule* core, const QStringList& osproberLines )
|
|||||||
|
|
||||||
bool atLeastOneCanBeResized = false;
|
bool atLeastOneCanBeResized = false;
|
||||||
|
|
||||||
foreach ( QString line, m_osproberLines )
|
foreach ( const OsproberEntry& entry, osproberEntries )
|
||||||
{
|
{
|
||||||
QStringList osLine = line.split( ':' );
|
if ( entry.canBeResized )
|
||||||
if ( canBeResized( osLine ) )
|
|
||||||
{
|
{
|
||||||
atLeastOneCanBeResized = true;
|
atLeastOneCanBeResized = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( atLeastOneCanBeResized )
|
|
||||||
{
|
|
||||||
m_messageLabel->setText( tr( "This computer currently has multiple operating systems on it. "
|
m_messageLabel->setText( tr( "This computer currently has multiple operating systems on it. "
|
||||||
"What would you like to do?" ) );
|
"What would you like to do?" ) );
|
||||||
|
|
||||||
@ -200,8 +182,8 @@ ChoicePage::init( PartitionCoreModule* core, const QStringList& osproberLines )
|
|||||||
"<font color=\"red\">Warning: </font>This will delete all of your Windows 7 programs, "
|
"<font color=\"red\">Warning: </font>This will delete all of your Windows 7 programs, "
|
||||||
"documents, photos, music, and any other files." )
|
"documents, photos, music, and any other files." )
|
||||||
.arg( "$RELEASE" ) );
|
.arg( "$RELEASE" ) );
|
||||||
}
|
|
||||||
else
|
if ( !atLeastOneCanBeResized )
|
||||||
alongsideButton->hide();
|
alongsideButton->hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -272,58 +254,3 @@ ChoicePage::setNextEnabled( bool enabled )
|
|||||||
emit nextStatusChanged( enabled );
|
emit nextStatusChanged( enabled );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
|
||||||
ChoicePage::canBeResized( const QStringList& osproberLine )
|
|
||||||
{
|
|
||||||
cDebug() << "checking if" << osproberLine << "can be resized.";
|
|
||||||
QString partitionWithOs = osproberLine.value( 0 ).simplified();
|
|
||||||
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 ) );
|
|
||||||
PartitionModel* pm = m_core->partitionModelForDevice( dev );
|
|
||||||
for ( int j = 0; j < pm->rowCount(); ++j )
|
|
||||||
{
|
|
||||||
QModelIndex index = pm->index( j, 0 );
|
|
||||||
Partition* candidate = pm->partitionForIndex( index );
|
|
||||||
if ( candidate->partitionPath() == partitionWithOs )
|
|
||||||
{
|
|
||||||
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 )
|
|
||||||
{
|
|
||||||
canResize = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ( canResize )
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if ( canResize )
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
cDebug() << "Partition" << osproberLine << "authorized for resize + autopartition install.";
|
|
||||||
return canResize;
|
|
||||||
}
|
|
||||||
|
|
||||||
cDebug() << "Partition" << osproberLine << "CANNOT BE RESIZED FOR AUTOINSTALL.";
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
@ -21,6 +21,8 @@
|
|||||||
|
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
|
|
||||||
|
#include "OsproberEntry.h"
|
||||||
|
|
||||||
class QBoxLayout;
|
class QBoxLayout;
|
||||||
class QLabel;
|
class QLabel;
|
||||||
|
|
||||||
@ -41,7 +43,7 @@ public:
|
|||||||
explicit ChoicePage( QWidget* parent = nullptr );
|
explicit ChoicePage( QWidget* parent = nullptr );
|
||||||
virtual ~ChoicePage();
|
virtual ~ChoicePage();
|
||||||
|
|
||||||
void init( PartitionCoreModule* core, const QStringList& osproberLines );
|
void init( PartitionCoreModule* core, const OsproberEntryList& osproberEntries );
|
||||||
|
|
||||||
bool isNextEnabled();
|
bool isNextEnabled();
|
||||||
|
|
||||||
@ -53,14 +55,11 @@ signals:
|
|||||||
private:
|
private:
|
||||||
void setNextEnabled( bool enabled );
|
void setNextEnabled( bool enabled );
|
||||||
|
|
||||||
bool canBeResized( const QStringList& osproberLine );
|
|
||||||
|
|
||||||
bool m_nextEnabled;
|
bool m_nextEnabled;
|
||||||
PartitionCoreModule* m_core;
|
PartitionCoreModule* m_core;
|
||||||
QBoxLayout* m_itemsLayout;
|
QBoxLayout* m_itemsLayout;
|
||||||
QLabel* m_messageLabel;
|
QLabel* m_messageLabel;
|
||||||
|
|
||||||
QStringList m_osproberLines;
|
|
||||||
Choice m_choice;
|
Choice m_choice;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
34
src/modules/partition/gui/OsproberEntry.h
Normal file
34
src/modules/partition/gui/OsproberEntry.h
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
/* === This file is part of Calamares - <http://github.com/calamares> ===
|
||||||
|
*
|
||||||
|
* Copyright 2014, Teo Mrnjavac <teo@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/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef OSPROBERENTRY_H
|
||||||
|
#define OSPROBERENTRY_H
|
||||||
|
|
||||||
|
#include <QStringList>
|
||||||
|
|
||||||
|
struct OsproberEntry
|
||||||
|
{
|
||||||
|
QString prettyName;
|
||||||
|
QString path;
|
||||||
|
bool canBeResized;
|
||||||
|
QStringList line;
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef QList< OsproberEntry > OsproberEntryList;
|
||||||
|
|
||||||
|
#endif // OSPROBERENTRY_H
|
@ -21,16 +21,21 @@
|
|||||||
#include <core/DeviceModel.h>
|
#include <core/DeviceModel.h>
|
||||||
#include <core/PartitionCoreModule.h>
|
#include <core/PartitionCoreModule.h>
|
||||||
#include <core/PartitionModel.h>
|
#include <core/PartitionModel.h>
|
||||||
|
#include "core/partition.h"
|
||||||
|
#include "core/device.h"
|
||||||
#include <gui/ChoicePage.h>
|
#include <gui/ChoicePage.h>
|
||||||
#include <gui/EraseDiskPage.h>
|
#include <gui/EraseDiskPage.h>
|
||||||
#include <gui/AlongsidePage.h>
|
#include <gui/AlongsidePage.h>
|
||||||
#include <gui/PartitionPage.h>
|
#include <gui/PartitionPage.h>
|
||||||
#include <gui/PartitionPreview.h>
|
#include <gui/PartitionPreview.h>
|
||||||
|
#include "OsproberEntry.h"
|
||||||
|
|
||||||
#include "CalamaresVersion.h"
|
#include "CalamaresVersion.h"
|
||||||
#include "utils/CalamaresUtilsGui.h"
|
#include "utils/CalamaresUtilsGui.h"
|
||||||
#include "utils/Logger.h"
|
#include "utils/Logger.h"
|
||||||
#include "widgets/WaitingWidget.h"
|
#include "widgets/WaitingWidget.h"
|
||||||
|
#include "GlobalStorage.h"
|
||||||
|
#include "JobQueue.h"
|
||||||
|
|
||||||
// Qt
|
// Qt
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
@ -79,16 +84,32 @@ PartitionViewStep::PartitionViewStep( QObject* parent )
|
|||||||
osprober.readAllStandardOutput() ).trimmed() );
|
osprober.readAllStandardOutput() ).trimmed() );
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList osproberLines;
|
QString osProberReport( "Osprober lines, clean:\n" );
|
||||||
|
OsproberEntryList osproberEntries;
|
||||||
foreach ( const QString& line, osproberOutput.split( '\n' ) )
|
foreach ( const QString& line, osproberOutput.split( '\n' ) )
|
||||||
{
|
{
|
||||||
if ( !line.simplified().isEmpty() )
|
if ( !line.simplified().isEmpty() )
|
||||||
osproberLines.append( line );
|
{
|
||||||
}
|
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();
|
||||||
|
|
||||||
m_choicePage->init( m_core, osproberLines );
|
QString path = lineColumns.value( 0 ).simplified();
|
||||||
|
if ( !path.startsWith( "/dev/" ) ) //basic sanity check
|
||||||
|
continue;
|
||||||
|
|
||||||
|
osproberEntries.append( { prettyName, path, canBeResized( path ), lineColumns } );
|
||||||
|
osProberReport.append( line );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cDebug() << osProberReport;
|
||||||
|
|
||||||
|
m_choicePage->init( m_core, osproberEntries );
|
||||||
m_erasePage->init( m_core );
|
m_erasePage->init( m_core );
|
||||||
m_alongsidePage->init( m_core, osproberLines );
|
m_alongsidePage->init( m_core, osproberEntries );
|
||||||
|
|
||||||
m_widget->addWidget( m_choicePage );
|
m_widget->addWidget( m_choicePage );
|
||||||
m_widget->addWidget( m_manualPartitionPage );
|
m_widget->addWidget( m_manualPartitionPage );
|
||||||
@ -239,3 +260,59 @@ PartitionViewStep::jobs() const
|
|||||||
{
|
{
|
||||||
return m_core->jobs();
|
return m_core->jobs();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool
|
||||||
|
PartitionViewStep::canBeResized( const QString& partitionPath )
|
||||||
|
{
|
||||||
|
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 ) );
|
||||||
|
PartitionModel* pm = m_core->partitionModelForDevice( dev );
|
||||||
|
for ( int j = 0; j < pm->rowCount(); ++j )
|
||||||
|
{
|
||||||
|
QModelIndex index = pm->index( j, 0 );
|
||||||
|
Partition* candidate = pm->partitionForIndex( index );
|
||||||
|
if ( candidate->partitionPath() == partitionWithOs )
|
||||||
|
{
|
||||||
|
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 )
|
||||||
|
{
|
||||||
|
canResize = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ( canResize )
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if ( canResize )
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
cDebug() << "Partition" << partitionWithOs << "authorized for resize + autopartition install.";
|
||||||
|
return canResize;
|
||||||
|
}
|
||||||
|
|
||||||
|
cDebug() << "Partition" << partitionWithOs << "CANNOT BE RESIZED FOR AUTOINSTALL.";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
@ -61,6 +61,8 @@ public:
|
|||||||
QList< Calamares::job_ptr > jobs() const override;
|
QList< Calamares::job_ptr > jobs() const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
bool canBeResized( const QString& partitionPath );
|
||||||
|
|
||||||
PartitionCoreModule* m_core;
|
PartitionCoreModule* m_core;
|
||||||
QStackedWidget* m_widget;
|
QStackedWidget* m_widget;
|
||||||
ChoicePage* m_choicePage;
|
ChoicePage* m_choicePage;
|
||||||
|
Loading…
Reference in New Issue
Block a user