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/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;
}

@ -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 */

@ -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();
}

@ -18,6 +18,8 @@
#ifndef PARTITIONMODEL_H
#define PARTITIONMODEL_H
#include "OsproberEntry.h"
// Qt
#include <QAbstractItemModel>
@ -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 */

@ -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 );

@ -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;

@ -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 );

@ -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;

@ -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 );

Loading…
Cancel
Save