Move Osprober to PCM and add Osprober roles to PartitionModel.

main
Teo Mrnjavac 9 years ago
parent 7b66514bf5
commit 0224811bf6

@ -25,6 +25,7 @@
#include "core/PartitionIterator.h" #include "core/PartitionIterator.h"
#include "core/PartitionModel.h" #include "core/PartitionModel.h"
#include "core/KPMHelpers.h" #include "core/KPMHelpers.h"
#include "core/PartUtils.h"
#include "jobs/ClearMountsJob.h" #include "jobs/ClearMountsJob.h"
#include "jobs/ClearTempMountsJob.h" #include "jobs/ClearTempMountsJob.h"
#include "jobs/CreatePartitionJob.h" #include "jobs/CreatePartitionJob.h"
@ -108,6 +109,8 @@ PartitionCoreModule::init()
CoreBackend* backend = CoreBackendManager::self()->backend(); CoreBackend* backend = CoreBackendManager::self()->backend();
auto devices = backend->scanDevices( true ); auto devices = backend->scanDevices( true );
m_osproberLines = PartUtils::runOsprober( this );
// Remove the device which contains / from the list // Remove the device which contains / from the list
for ( auto it = devices.begin(); it != devices.end(); ) for ( auto it = devices.begin(); it != devices.end(); )
if ( hasRootPartition( *it ) ) if ( hasRootPartition( *it ) )
@ -120,7 +123,7 @@ PartitionCoreModule::init()
auto deviceInfo = new DeviceInfo( device ); auto deviceInfo = new DeviceInfo( device );
m_deviceInfos << deviceInfo; m_deviceInfos << deviceInfo;
deviceInfo->partitionModel->init( device ); deviceInfo->partitionModel->init( device, m_osproberLines );
} }
m_deviceModel->init( devices ); m_deviceModel->init( devices );
@ -353,6 +356,13 @@ PartitionCoreModule::dumpQueue() const
} }
} }
OsproberEntryList
PartitionCoreModule::osproberEntries() const
{
return m_osproberLines;
}
void void
PartitionCoreModule::refreshPartition( Device* device, Partition* partition ) PartitionCoreModule::refreshPartition( Device* device, Partition* partition )
{ {
@ -517,13 +527,13 @@ PartitionCoreModule::createSummaryInfo() const
Device* deviceBefore = backend->scanDevice( deviceInfo->device->deviceNode() ); Device* deviceBefore = backend->scanDevice( deviceInfo->device->deviceNode() );
summaryInfo.partitionModelBefore = new PartitionModel; summaryInfo.partitionModelBefore = new PartitionModel;
summaryInfo.partitionModelBefore->init( deviceBefore ); summaryInfo.partitionModelBefore->init( deviceBefore, m_osproberLines );
// Make deviceBefore a child of partitionModelBefore so that it is not // Make deviceBefore a child of partitionModelBefore so that it is not
// leaked (as long as partitionModelBefore is deleted) // leaked (as long as partitionModelBefore is deleted)
deviceBefore->setParent( summaryInfo.partitionModelBefore ); deviceBefore->setParent( summaryInfo.partitionModelBefore );
summaryInfo.partitionModelAfter = new PartitionModel; summaryInfo.partitionModelAfter = new PartitionModel;
summaryInfo.partitionModelAfter->init( deviceInfo->device.data() ); summaryInfo.partitionModelAfter->init( deviceInfo->device.data(), m_osproberLines );
lst << summaryInfo; lst << summaryInfo;
} }

@ -114,6 +114,8 @@ public:
void dumpQueue() const; void dumpQueue() const;
OsproberEntryList osproberEntries() const;
Q_SIGNALS: Q_SIGNALS:
void hasRootMountPointChanged( bool value ); void hasRootMountPointChanged( bool value );
void isDirtyChanged( bool value ); void isDirtyChanged( bool value );
@ -153,6 +155,8 @@ private:
DeviceInfo* infoForDevice( Device* ) const; DeviceInfo* infoForDevice( Device* ) const;
Partition* findPartitionByMountPoint( const QString& mountPoint ) const; Partition* findPartitionByMountPoint( const QString& mountPoint ) const;
OsproberEntryList m_osproberLines;
}; };
#endif /* PARTITIONCOREMODULE_H */ #endif /* PARTITIONCOREMODULE_H */

@ -55,10 +55,11 @@ PartitionModel::PartitionModel( QObject* parent )
} }
void void
PartitionModel::init( Device* device ) PartitionModel::init( Device* device , const OsproberEntryList& osproberEntries )
{ {
beginResetModel(); beginResetModel();
m_device = device; m_device = device;
m_osproberEntries = osproberEntries;
endResetModel(); endResetModel();
} }
@ -162,6 +163,30 @@ PartitionModel::data( const QModelIndex& index, int role ) const
return ( partition->lastSector() - partition->firstSector() + 1 ) * m_device->logicalSectorSize(); return ( partition->lastSector() - partition->firstSector() + 1 ) * m_device->logicalSectorSize();
case IsFreeSpaceRole: case IsFreeSpaceRole:
return KPMHelpers::isPartitionFreeSpace( partition ); return KPMHelpers::isPartitionFreeSpace( partition );
// Osprober roles:
case OsproberNameRole:
foreach ( const OsproberEntry& osproberEntry, m_osproberEntries )
if ( osproberEntry.path == partition->partitionPath() )
return osproberEntry.prettyName;
return QVariant();
case OsproberPathRole:
foreach ( const OsproberEntry& osproberEntry, m_osproberEntries )
if ( osproberEntry.path == partition->partitionPath() )
return osproberEntry.path;
return QVariant();
case OsproberCanBeResizedRole:
foreach ( const OsproberEntry& osproberEntry, m_osproberEntries )
if ( osproberEntry.path == partition->partitionPath() )
return osproberEntry.canBeResized;
return QVariant();
case OsproberRawLineRole:
foreach ( const OsproberEntry& osproberEntry, m_osproberEntries )
if ( osproberEntry.path == partition->partitionPath() )
return osproberEntry.line;
return QVariant();
// end Osprober roles.
default: default:
return QVariant(); return QVariant();
} }

@ -18,6 +18,8 @@
#ifndef PARTITIONMODEL_H #ifndef PARTITIONMODEL_H
#define PARTITIONMODEL_H #define PARTITIONMODEL_H
#include "OsproberEntry.h"
// Qt // Qt
#include <QAbstractItemModel> #include <QAbstractItemModel>
@ -66,7 +68,11 @@ public:
// The raw size, as a qlonglong. This is different from the DisplayRole of // The raw size, as a qlonglong. This is different from the DisplayRole of
// SizeColumn, which is a human-readable string. // SizeColumn, which is a human-readable string.
SizeRole = Qt::UserRole + 1, SizeRole = Qt::UserRole + 1,
IsFreeSpaceRole IsFreeSpaceRole,
OsproberNameRole,
OsproberPathRole,
OsproberCanBeResizedRole,
OsproberRawLineRole
}; };
enum Column enum Column
@ -82,7 +88,7 @@ public:
/** /**
* device must remain alive for the life of PartitionModel * device must remain alive for the life of PartitionModel
*/ */
void init( Device* device ); void init( Device* device, const OsproberEntryList& osproberEntries );
// QAbstractItemModel API // QAbstractItemModel API
QModelIndex index( int row, int column, const QModelIndex& parent = QModelIndex() ) const override; QModelIndex index( int row, int column, const QModelIndex& parent = QModelIndex() ) const override;
@ -101,6 +107,7 @@ public:
private: private:
Device* m_device; Device* m_device;
OsproberEntryList m_osproberEntries;
}; };
#endif /* PARTITIONMODEL_H */ #endif /* PARTITIONMODEL_H */

@ -104,7 +104,7 @@ AlongsidePage::AlongsidePage( QWidget* parent )
void void
AlongsidePage::init( PartitionCoreModule* core , const OsproberEntryList& osproberEntries ) AlongsidePage::init( PartitionCoreModule* core )
{ {
if ( m_core != core ) if ( m_core != core )
m_core = core; m_core = core;
@ -129,7 +129,7 @@ AlongsidePage::init( PartitionCoreModule* core , const OsproberEntryList& osprob
string( Calamares::Branding::ProductName ) ) ); string( Calamares::Branding::ProductName ) ) );
} ); } );
foreach ( const OsproberEntry& e, osproberEntries ) foreach ( const OsproberEntry& e, m_core->osproberEntries() )
{ {
if ( e.canBeResized ) if ( e.canBeResized )
m_partitionsComboBox->addItem( e.prettyName + " (" + e.path + ")", e.path ); m_partitionsComboBox->addItem( e.prettyName + " (" + e.path + ")", e.path );
@ -191,7 +191,7 @@ AlongsidePage::onPartitionSelected( int comboBoxIndex )
Device* deviceBefore = m_core->createImmutableDeviceCopy( dev ); Device* deviceBefore = m_core->createImmutableDeviceCopy( dev );
PartitionModel* partitionModelBefore = new PartitionModel; PartitionModel* partitionModelBefore = new PartitionModel;
partitionModelBefore->init( deviceBefore ); partitionModelBefore->init( deviceBefore, m_core->osproberEntries() );
deviceBefore->setParent( partitionModelBefore ); deviceBefore->setParent( partitionModelBefore );
partitionModelBefore->setParent( m_previewWidget ); partitionModelBefore->setParent( m_previewWidget );

@ -38,7 +38,7 @@ class AlongsidePage : public QWidget
public: public:
explicit AlongsidePage( QWidget* parent = nullptr ); explicit AlongsidePage( QWidget* parent = nullptr );
void init( PartitionCoreModule* core, const OsproberEntryList& osproberEntries ); void init( PartitionCoreModule* core );
bool isNextEnabled() const; bool isNextEnabled() const;

@ -114,11 +114,9 @@ ChoicePage::~ChoicePage()
* @param osproberEntries the output of os-prober, cleaned up and structured. * @param osproberEntries the output of os-prober, cleaned up and structured.
*/ */
void void
ChoicePage::init( PartitionCoreModule* core, ChoicePage::init( PartitionCoreModule* core )
const OsproberEntryList& osproberEntries )
{ {
m_core = core; m_core = core;
m_osproberEntries = osproberEntries;
m_isEfi = QDir( "/sys/firmware/efi/efivars" ).exists(); m_isEfi = QDir( "/sys/firmware/efi/efivars" ).exists();
setupChoices(); setupChoices();
@ -489,7 +487,7 @@ ChoicePage::updateDeviceStatePreview( Device* currentDevice )
Device* deviceBefore = m_core->createImmutableDeviceCopy( currentDevice ); Device* deviceBefore = m_core->createImmutableDeviceCopy( currentDevice );
PartitionModel* model = new PartitionModel( preview ); PartitionModel* model = new PartitionModel( preview );
model->init( deviceBefore ); model->init( deviceBefore, m_core->osproberEntries() );
// The QObject parents tree is meaningful for memory management here, // The QObject parents tree is meaningful for memory management here,
// see qDeleteAll above. // see qDeleteAll above.
@ -539,7 +537,7 @@ ChoicePage::updateActionChoicePreview( Device* currentDevice, ChoicePage::Choice
PartitionLabelsView* previewLabels = new PartitionLabelsView( m_previewAfterFrame ); PartitionLabelsView* previewLabels = new PartitionLabelsView( m_previewAfterFrame );
PartitionModel* model = new PartitionModel( preview ); PartitionModel* model = new PartitionModel( preview );
model->init( currentDevice ); model->init( currentDevice, m_core->osproberEntries() );
// The QObject parents tree is meaningful for memory management here, // The QObject parents tree is meaningful for memory management here,
// see qDeleteAll above. // see qDeleteAll above.
@ -733,7 +731,7 @@ OsproberEntryList
ChoicePage::getOsproberEntriesForDevice( Device* device ) const ChoicePage::getOsproberEntriesForDevice( Device* device ) const
{ {
OsproberEntryList eList; OsproberEntryList eList;
foreach ( const OsproberEntry& entry, m_osproberEntries ) foreach ( const OsproberEntry& entry, m_core->osproberEntries() )
{ {
if ( entry.path.startsWith( device->deviceNode() ) ) if ( entry.path.startsWith( device->deviceNode() ) )
eList.append( entry ); eList.append( entry );

@ -55,8 +55,7 @@ public:
explicit ChoicePage( QWidget* parent = nullptr ); explicit ChoicePage( QWidget* parent = nullptr );
virtual ~ChoicePage(); virtual ~ChoicePage();
void init( PartitionCoreModule* core, void init( PartitionCoreModule* core );
const OsproberEntryList& osproberEntries );
bool isNextEnabled() const; bool isNextEnabled() const;
@ -83,7 +82,6 @@ private:
bool m_nextEnabled; bool m_nextEnabled;
PartitionCoreModule* m_core; PartitionCoreModule* m_core;
OsproberEntryList m_osproberEntries;
QMutex m_previewsMutex; QMutex m_previewsMutex;

@ -74,13 +74,11 @@ PartitionViewStep::PartitionViewStep( QObject* parent )
void void
PartitionViewStep::continueLoading() PartitionViewStep::continueLoading()
{ {
OsproberEntryList osproberEntries = PartUtils::runOsprober( m_core );
Q_ASSERT( !m_choicePage ); Q_ASSERT( !m_choicePage );
m_choicePage = new ChoicePage(); m_choicePage = new ChoicePage();
m_choicePage->init( m_core, osproberEntries ); m_choicePage->init( m_core );
m_alongsidePage->init( m_core, osproberEntries ); m_alongsidePage->init( m_core );
m_widget->addWidget( m_choicePage ); m_widget->addWidget( m_choicePage );
m_widget->addWidget( m_manualPartitionPage ); m_widget->addWidget( m_manualPartitionPage );

Loading…
Cancel
Save