diff --git a/src/modules/partition/core/PartitionCoreModule.cpp b/src/modules/partition/core/PartitionCoreModule.cpp index 54e96c499..a440e7155 100644 --- a/src/modules/partition/core/PartitionCoreModule.cpp +++ b/src/modules/partition/core/PartitionCoreModule.cpp @@ -25,6 +25,7 @@ #include "core/PartitionIterator.h" #include "core/PartitionModel.h" #include "core/KPMHelpers.h" +#include "core/PartUtils.h" #include "jobs/ClearMountsJob.h" #include "jobs/ClearTempMountsJob.h" #include "jobs/CreatePartitionJob.h" @@ -108,6 +109,8 @@ PartitionCoreModule::init() CoreBackend* backend = CoreBackendManager::self()->backend(); auto devices = backend->scanDevices( true ); + m_osproberLines = PartUtils::runOsprober( this ); + // Remove the device which contains / from the list for ( auto it = devices.begin(); it != devices.end(); ) if ( hasRootPartition( *it ) ) @@ -120,7 +123,7 @@ PartitionCoreModule::init() auto deviceInfo = new DeviceInfo( device ); m_deviceInfos << deviceInfo; - deviceInfo->partitionModel->init( device ); + deviceInfo->partitionModel->init( device, m_osproberLines ); } m_deviceModel->init( devices ); @@ -353,6 +356,13 @@ PartitionCoreModule::dumpQueue() const } } + +OsproberEntryList +PartitionCoreModule::osproberEntries() const +{ + return m_osproberLines; +} + void PartitionCoreModule::refreshPartition( Device* device, Partition* partition ) { @@ -517,13 +527,13 @@ PartitionCoreModule::createSummaryInfo() const Device* deviceBefore = backend->scanDevice( deviceInfo->device->deviceNode() ); 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 // leaked (as long as partitionModelBefore is deleted) deviceBefore->setParent( summaryInfo.partitionModelBefore ); summaryInfo.partitionModelAfter = new PartitionModel; - summaryInfo.partitionModelAfter->init( deviceInfo->device.data() ); + summaryInfo.partitionModelAfter->init( deviceInfo->device.data(), m_osproberLines ); lst << summaryInfo; } diff --git a/src/modules/partition/core/PartitionCoreModule.h b/src/modules/partition/core/PartitionCoreModule.h index cef1ba1f2..44a83499f 100644 --- a/src/modules/partition/core/PartitionCoreModule.h +++ b/src/modules/partition/core/PartitionCoreModule.h @@ -114,6 +114,8 @@ public: void dumpQueue() const; + OsproberEntryList osproberEntries() const; + Q_SIGNALS: void hasRootMountPointChanged( bool value ); void isDirtyChanged( bool value ); @@ -153,6 +155,8 @@ private: DeviceInfo* infoForDevice( Device* ) const; Partition* findPartitionByMountPoint( const QString& mountPoint ) const; + + OsproberEntryList m_osproberLines; }; #endif /* PARTITIONCOREMODULE_H */ diff --git a/src/modules/partition/core/PartitionModel.cpp b/src/modules/partition/core/PartitionModel.cpp index 49d981f6c..43cdc0fba 100644 --- a/src/modules/partition/core/PartitionModel.cpp +++ b/src/modules/partition/core/PartitionModel.cpp @@ -55,10 +55,11 @@ PartitionModel::PartitionModel( QObject* parent ) } void -PartitionModel::init( Device* device ) +PartitionModel::init( Device* device , const OsproberEntryList& osproberEntries ) { beginResetModel(); m_device = device; + m_osproberEntries = osproberEntries; endResetModel(); } @@ -162,6 +163,30 @@ PartitionModel::data( const QModelIndex& index, int role ) const return ( partition->lastSector() - partition->firstSector() + 1 ) * m_device->logicalSectorSize(); case IsFreeSpaceRole: 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: return QVariant(); } diff --git a/src/modules/partition/core/PartitionModel.h b/src/modules/partition/core/PartitionModel.h index 5e0c11515..ad80733ab 100644 --- a/src/modules/partition/core/PartitionModel.h +++ b/src/modules/partition/core/PartitionModel.h @@ -18,6 +18,8 @@ #ifndef PARTITIONMODEL_H #define PARTITIONMODEL_H +#include "OsproberEntry.h" + // Qt #include @@ -66,7 +68,11 @@ public: // The raw size, as a qlonglong. This is different from the DisplayRole of // SizeColumn, which is a human-readable string. SizeRole = Qt::UserRole + 1, - IsFreeSpaceRole + IsFreeSpaceRole, + OsproberNameRole, + OsproberPathRole, + OsproberCanBeResizedRole, + OsproberRawLineRole }; enum Column @@ -82,7 +88,7 @@ public: /** * device must remain alive for the life of PartitionModel */ - void init( Device* device ); + void init( Device* device, const OsproberEntryList& osproberEntries ); // QAbstractItemModel API QModelIndex index( int row, int column, const QModelIndex& parent = QModelIndex() ) const override; @@ -101,6 +107,7 @@ public: private: Device* m_device; + OsproberEntryList m_osproberEntries; }; #endif /* PARTITIONMODEL_H */ diff --git a/src/modules/partition/gui/AlongsidePage.cpp b/src/modules/partition/gui/AlongsidePage.cpp index 986b81dfb..75cddc66f 100644 --- a/src/modules/partition/gui/AlongsidePage.cpp +++ b/src/modules/partition/gui/AlongsidePage.cpp @@ -104,7 +104,7 @@ AlongsidePage::AlongsidePage( QWidget* parent ) void -AlongsidePage::init( PartitionCoreModule* core , const OsproberEntryList& osproberEntries ) +AlongsidePage::init( PartitionCoreModule* core ) { if ( m_core != core ) m_core = core; @@ -129,7 +129,7 @@ AlongsidePage::init( PartitionCoreModule* core , const OsproberEntryList& osprob string( Calamares::Branding::ProductName ) ) ); } ); - foreach ( const OsproberEntry& e, osproberEntries ) + foreach ( const OsproberEntry& e, m_core->osproberEntries() ) { if ( e.canBeResized ) m_partitionsComboBox->addItem( e.prettyName + " (" + e.path + ")", e.path ); @@ -191,7 +191,7 @@ AlongsidePage::onPartitionSelected( int comboBoxIndex ) Device* deviceBefore = m_core->createImmutableDeviceCopy( dev ); PartitionModel* partitionModelBefore = new PartitionModel; - partitionModelBefore->init( deviceBefore ); + partitionModelBefore->init( deviceBefore, m_core->osproberEntries() ); deviceBefore->setParent( partitionModelBefore ); partitionModelBefore->setParent( m_previewWidget ); diff --git a/src/modules/partition/gui/AlongsidePage.h b/src/modules/partition/gui/AlongsidePage.h index f68ca5ff8..cb02af646 100644 --- a/src/modules/partition/gui/AlongsidePage.h +++ b/src/modules/partition/gui/AlongsidePage.h @@ -38,7 +38,7 @@ class AlongsidePage : public QWidget public: explicit AlongsidePage( QWidget* parent = nullptr ); - void init( PartitionCoreModule* core, const OsproberEntryList& osproberEntries ); + void init( PartitionCoreModule* core ); bool isNextEnabled() const; diff --git a/src/modules/partition/gui/ChoicePage.cpp b/src/modules/partition/gui/ChoicePage.cpp index d4426b8d5..74d20966a 100644 --- a/src/modules/partition/gui/ChoicePage.cpp +++ b/src/modules/partition/gui/ChoicePage.cpp @@ -114,11 +114,9 @@ ChoicePage::~ChoicePage() * @param osproberEntries the output of os-prober, cleaned up and structured. */ void -ChoicePage::init( PartitionCoreModule* core, - const OsproberEntryList& osproberEntries ) +ChoicePage::init( PartitionCoreModule* core ) { m_core = core; - m_osproberEntries = osproberEntries; m_isEfi = QDir( "/sys/firmware/efi/efivars" ).exists(); setupChoices(); @@ -489,7 +487,7 @@ ChoicePage::updateDeviceStatePreview( Device* currentDevice ) Device* deviceBefore = m_core->createImmutableDeviceCopy( currentDevice ); PartitionModel* model = new PartitionModel( preview ); - model->init( deviceBefore ); + model->init( deviceBefore, m_core->osproberEntries() ); // The QObject parents tree is meaningful for memory management here, // see qDeleteAll above. @@ -539,7 +537,7 @@ ChoicePage::updateActionChoicePreview( Device* currentDevice, ChoicePage::Choice PartitionLabelsView* previewLabels = new PartitionLabelsView( m_previewAfterFrame ); PartitionModel* model = new PartitionModel( preview ); - model->init( currentDevice ); + model->init( currentDevice, m_core->osproberEntries() ); // The QObject parents tree is meaningful for memory management here, // see qDeleteAll above. @@ -733,7 +731,7 @@ OsproberEntryList ChoicePage::getOsproberEntriesForDevice( Device* device ) const { OsproberEntryList eList; - foreach ( const OsproberEntry& entry, m_osproberEntries ) + foreach ( const OsproberEntry& entry, m_core->osproberEntries() ) { if ( entry.path.startsWith( device->deviceNode() ) ) eList.append( entry ); diff --git a/src/modules/partition/gui/ChoicePage.h b/src/modules/partition/gui/ChoicePage.h index a68364306..e52bf941c 100644 --- a/src/modules/partition/gui/ChoicePage.h +++ b/src/modules/partition/gui/ChoicePage.h @@ -55,8 +55,7 @@ public: explicit ChoicePage( QWidget* parent = nullptr ); virtual ~ChoicePage(); - void init( PartitionCoreModule* core, - const OsproberEntryList& osproberEntries ); + void init( PartitionCoreModule* core ); bool isNextEnabled() const; @@ -83,7 +82,6 @@ private: bool m_nextEnabled; PartitionCoreModule* m_core; - OsproberEntryList m_osproberEntries; QMutex m_previewsMutex; diff --git a/src/modules/partition/gui/PartitionViewStep.cpp b/src/modules/partition/gui/PartitionViewStep.cpp index 2f840b172..9ecf3b66e 100644 --- a/src/modules/partition/gui/PartitionViewStep.cpp +++ b/src/modules/partition/gui/PartitionViewStep.cpp @@ -74,13 +74,11 @@ PartitionViewStep::PartitionViewStep( QObject* parent ) void PartitionViewStep::continueLoading() { - OsproberEntryList osproberEntries = PartUtils::runOsprober( m_core ); - Q_ASSERT( !m_choicePage ); m_choicePage = new ChoicePage(); - m_choicePage->init( m_core, osproberEntries ); - m_alongsidePage->init( m_core, osproberEntries ); + m_choicePage->init( m_core ); + m_alongsidePage->init( m_core ); m_widget->addWidget( m_choicePage ); m_widget->addWidget( m_manualPartitionPage );