Rework boot loader combo box
List MBR of all devices Does not loose its selection when updated
This commit is contained in:
parent
c9c1917997
commit
ab4604258c
104
src/modules/partition/BootLoaderModel.cpp
Normal file
104
src/modules/partition/BootLoaderModel.cpp
Normal file
@ -0,0 +1,104 @@
|
|||||||
|
/* === 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/>.
|
||||||
|
*/
|
||||||
|
#include <BootLoaderModel.h>
|
||||||
|
|
||||||
|
#include <PartitionInfo.h>
|
||||||
|
#include <PMUtils.h>
|
||||||
|
|
||||||
|
// CalaPM
|
||||||
|
#include <core/device.h>
|
||||||
|
|
||||||
|
static QStandardItem*
|
||||||
|
createBootLoaderItem( const QString& description, const QString& path, bool isPartition )
|
||||||
|
{
|
||||||
|
QStandardItem* item = new QStandardItem( description );
|
||||||
|
item->setData( path, BootLoaderModel::BootLoaderPathRole );
|
||||||
|
item->setData( isPartition, BootLoaderModel::IsPartitionRole );
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
|
||||||
|
BootLoaderModel::BootLoaderModel( QObject* parent )
|
||||||
|
: QStandardItemModel( parent )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
BootLoaderModel::~BootLoaderModel()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
BootLoaderModel::init( const QList< Device* >& devices )
|
||||||
|
{
|
||||||
|
m_devices = devices;
|
||||||
|
clear();
|
||||||
|
createMbrItems();
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
BootLoaderModel::createMbrItems()
|
||||||
|
{
|
||||||
|
for( auto device : m_devices )
|
||||||
|
{
|
||||||
|
QString text = tr( "Master Boot Record of %1" )
|
||||||
|
.arg( device->name() );
|
||||||
|
appendRow(
|
||||||
|
createBootLoaderItem( text, device->deviceNode(), false )
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
BootLoaderModel::update()
|
||||||
|
{
|
||||||
|
QString partitionText;
|
||||||
|
Partition* partition = PMUtils::findPartitionByMountPoint( m_devices, "/boot" );
|
||||||
|
if ( partition )
|
||||||
|
partitionText = tr( "Boot Partition" );
|
||||||
|
else
|
||||||
|
{
|
||||||
|
partition = PMUtils::findPartitionByMountPoint( m_devices, "/" );
|
||||||
|
if ( partition )
|
||||||
|
partitionText = tr( "System Partition" );
|
||||||
|
}
|
||||||
|
|
||||||
|
Q_ASSERT( rowCount() > 0 );
|
||||||
|
QStandardItem* last = item( rowCount() - 1 );
|
||||||
|
Q_ASSERT( last );
|
||||||
|
bool lastIsPartition = last->data( IsPartitionRole ).toBool();
|
||||||
|
|
||||||
|
if ( !partition )
|
||||||
|
{
|
||||||
|
if ( lastIsPartition )
|
||||||
|
takeRow( rowCount() - 1 );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString mountPoint = PartitionInfo::mountPoint( partition );
|
||||||
|
if ( lastIsPartition )
|
||||||
|
{
|
||||||
|
last->setText( partitionText );
|
||||||
|
last->setData( mountPoint, BootLoaderPathRole );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
appendRow(
|
||||||
|
createBootLoaderItem( partitionText, PartitionInfo::mountPoint( partition ), true )
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
56
src/modules/partition/BootLoaderModel.h
Normal file
56
src/modules/partition/BootLoaderModel.h
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
/* === 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/>.
|
||||||
|
*/
|
||||||
|
#ifndef BOOTLOADERMODEL_H
|
||||||
|
#define BOOTLOADERMODEL_H
|
||||||
|
|
||||||
|
#include <QStandardItemModel>
|
||||||
|
#include <QList>
|
||||||
|
|
||||||
|
class Device;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This model contains one entry for each device MBR plus one entry for the
|
||||||
|
* /boot or / partition
|
||||||
|
*/
|
||||||
|
class BootLoaderModel : public QStandardItemModel
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
enum
|
||||||
|
{
|
||||||
|
BootLoaderPathRole = Qt::UserRole + 1,
|
||||||
|
IsPartitionRole
|
||||||
|
};
|
||||||
|
|
||||||
|
BootLoaderModel( QObject* parent = 0 );
|
||||||
|
~BootLoaderModel();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Init the model with the list of devices. Does *not* take ownership of the
|
||||||
|
* devices.
|
||||||
|
*/
|
||||||
|
void init( const QList< Device* >& devices );
|
||||||
|
|
||||||
|
void update();
|
||||||
|
|
||||||
|
private:
|
||||||
|
QList< Device* > m_devices;
|
||||||
|
|
||||||
|
void createMbrItems();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* BOOTLOADERMODEL_H */
|
@ -22,6 +22,7 @@ calamares_add_plugin( partition
|
|||||||
EXPORT_MACRO PLUGINDLLEXPORT_PRO
|
EXPORT_MACRO PLUGINDLLEXPORT_PRO
|
||||||
CONFIG_FILE module.conf
|
CONFIG_FILE module.conf
|
||||||
SOURCES
|
SOURCES
|
||||||
|
BootLoaderModel.cpp
|
||||||
CreatePartitionDialog.cpp
|
CreatePartitionDialog.cpp
|
||||||
CreatePartitionJob.cpp
|
CreatePartitionJob.cpp
|
||||||
CreatePartitionTableJob.cpp
|
CreatePartitionTableJob.cpp
|
||||||
|
@ -18,6 +18,9 @@
|
|||||||
|
|
||||||
#include <PMUtils.h>
|
#include <PMUtils.h>
|
||||||
|
|
||||||
|
#include <PartitionInfo.h>
|
||||||
|
#include <PartitionIterator.h>
|
||||||
|
|
||||||
// CalaPM
|
// CalaPM
|
||||||
#include <core/partition.h>
|
#include <core/partition.h>
|
||||||
#include <fs/filesystem.h>
|
#include <fs/filesystem.h>
|
||||||
@ -35,4 +38,14 @@ bool isPartitionNew( Partition* partition )
|
|||||||
return partition->state() == Partition::StateNew;
|
return partition->state() == Partition::StateNew;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Partition*
|
||||||
|
findPartitionByMountPoint( const QList< Device* >& devices, const QString& mountPoint )
|
||||||
|
{
|
||||||
|
for ( auto device : devices )
|
||||||
|
for ( auto it = PartitionIterator::begin( device ); it != PartitionIterator::end( device ); ++it )
|
||||||
|
if ( PartitionInfo::mountPoint( *it ) == mountPoint )
|
||||||
|
return *it;
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
@ -18,6 +18,10 @@
|
|||||||
#ifndef PMUTILS_H
|
#ifndef PMUTILS_H
|
||||||
#define PMUTILS_H
|
#define PMUTILS_H
|
||||||
|
|
||||||
|
// Qt
|
||||||
|
#include <QList>
|
||||||
|
|
||||||
|
class Device;
|
||||||
class Partition;
|
class Partition;
|
||||||
|
|
||||||
namespace PMUtils
|
namespace PMUtils
|
||||||
@ -27,6 +31,8 @@ bool isPartitionFreeSpace( Partition* );
|
|||||||
|
|
||||||
bool isPartitionNew( Partition* );
|
bool isPartitionNew( Partition* );
|
||||||
|
|
||||||
|
Partition* findPartitionByMountPoint( const QList< Device* >& devices, const QString& mountPoint );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* PMUTILS_H */
|
#endif /* PMUTILS_H */
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
|
|
||||||
#include <PartitionCoreModule.h>
|
#include <PartitionCoreModule.h>
|
||||||
|
|
||||||
|
#include <BootLoaderModel.h>
|
||||||
#include <CreatePartitionJob.h>
|
#include <CreatePartitionJob.h>
|
||||||
#include <CreatePartitionTableJob.h>
|
#include <CreatePartitionTableJob.h>
|
||||||
#include <DeletePartitionJob.h>
|
#include <DeletePartitionJob.h>
|
||||||
@ -63,7 +64,7 @@ PartitionCoreModule::DeviceInfo::forgetChanges()
|
|||||||
PartitionCoreModule::PartitionCoreModule( QObject* parent )
|
PartitionCoreModule::PartitionCoreModule( QObject* parent )
|
||||||
: QObject( parent )
|
: QObject( parent )
|
||||||
, m_deviceModel( new DeviceModel( this ) )
|
, m_deviceModel( new DeviceModel( this ) )
|
||||||
, m_bootLoaderModel( new QStandardItemModel( this ) )
|
, m_bootLoaderModel( new BootLoaderModel( this ) )
|
||||||
{
|
{
|
||||||
// FIXME: Should be done at startup
|
// FIXME: Should be done at startup
|
||||||
if ( !CalaPM::init() )
|
if ( !CalaPM::init() )
|
||||||
@ -80,6 +81,7 @@ PartitionCoreModule::PartitionCoreModule( QObject* parent )
|
|||||||
}
|
}
|
||||||
m_deviceModel->init( devices );
|
m_deviceModel->init( devices );
|
||||||
|
|
||||||
|
m_bootLoaderModel->init( devices );
|
||||||
}
|
}
|
||||||
|
|
||||||
PartitionCoreModule::~PartitionCoreModule()
|
PartitionCoreModule::~PartitionCoreModule()
|
||||||
@ -246,7 +248,7 @@ PartitionCoreModule::refresh( Device* device )
|
|||||||
Q_ASSERT( model );
|
Q_ASSERT( model );
|
||||||
model->reload();
|
model->reload();
|
||||||
updateHasRootMountPoint();
|
updateHasRootMountPoint();
|
||||||
updateBootLoaderModel();
|
m_bootLoaderModel->update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PartitionCoreModule::updateHasRootMountPoint()
|
void PartitionCoreModule::updateHasRootMountPoint()
|
||||||
@ -269,44 +271,6 @@ PartitionCoreModule::infoForDevice( Device* device ) const
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
static QStandardItem*
|
|
||||||
createBootLoaderItem( const QString& description, const QString& path )
|
|
||||||
{
|
|
||||||
QString text = PartitionCoreModule::tr( "%1 (%2)" )
|
|
||||||
.arg( description )
|
|
||||||
.arg( path );
|
|
||||||
QStandardItem* item = new QStandardItem( text );
|
|
||||||
item->setData( path, PartitionCoreModule::BootLoaderPathRole );
|
|
||||||
return item;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
PartitionCoreModule::updateBootLoaderModel()
|
|
||||||
{
|
|
||||||
m_bootLoaderModel->clear();
|
|
||||||
// Can contain up to 2 entries:
|
|
||||||
// - MBR of disk which contains /boot or /
|
|
||||||
// - /boot or / partition
|
|
||||||
QString partitionText;
|
|
||||||
Partition* partition = findPartitionByMountPoint( "/boot" );
|
|
||||||
if ( partition )
|
|
||||||
partitionText = tr( "Boot Partition" );
|
|
||||||
else
|
|
||||||
{
|
|
||||||
partition = findPartitionByMountPoint( "/" );
|
|
||||||
if ( partition )
|
|
||||||
partitionText = tr( "System Partition" );
|
|
||||||
else
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
m_bootLoaderModel->appendRow(
|
|
||||||
createBootLoaderItem( tr( "Master Boot Record" ), partition->devicePath() )
|
|
||||||
);
|
|
||||||
m_bootLoaderModel->appendRow(
|
|
||||||
createBootLoaderItem( partitionText, partition->partitionPath() )
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Partition*
|
Partition*
|
||||||
PartitionCoreModule::findPartitionByMountPoint( const QString& mountPoint ) const
|
PartitionCoreModule::findPartitionByMountPoint( const QString& mountPoint ) const
|
||||||
{
|
{
|
||||||
|
@ -29,6 +29,7 @@
|
|||||||
#include <QList>
|
#include <QList>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
|
||||||
|
class BootLoaderModel;
|
||||||
class CreatePartitionJob;
|
class CreatePartitionJob;
|
||||||
class Device;
|
class Device;
|
||||||
class DeviceModel;
|
class DeviceModel;
|
||||||
@ -44,11 +45,6 @@ class PartitionCoreModule : public QObject
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
enum
|
|
||||||
{
|
|
||||||
BootLoaderPathRole = Qt::UserRole + 1
|
|
||||||
};
|
|
||||||
|
|
||||||
PartitionCoreModule( QObject* parent = nullptr );
|
PartitionCoreModule( QObject* parent = nullptr );
|
||||||
~PartitionCoreModule();
|
~PartitionCoreModule();
|
||||||
|
|
||||||
@ -95,7 +91,7 @@ private:
|
|||||||
QList< DeviceInfo* > m_deviceInfos;
|
QList< DeviceInfo* > m_deviceInfos;
|
||||||
|
|
||||||
DeviceModel* m_deviceModel;
|
DeviceModel* m_deviceModel;
|
||||||
QStandardItemModel* m_bootLoaderModel;
|
BootLoaderModel* m_bootLoaderModel;
|
||||||
bool m_hasRootMountPoint = false;
|
bool m_hasRootMountPoint = false;
|
||||||
|
|
||||||
void listDevices();
|
void listDevices();
|
||||||
|
@ -5,6 +5,8 @@ set( jobtests_SRCS
|
|||||||
${PartitionModule_SOURCE_DIR}/CreatePartitionJob.cpp
|
${PartitionModule_SOURCE_DIR}/CreatePartitionJob.cpp
|
||||||
${PartitionModule_SOURCE_DIR}/CreatePartitionTableJob.cpp
|
${PartitionModule_SOURCE_DIR}/CreatePartitionTableJob.cpp
|
||||||
${PartitionModule_SOURCE_DIR}/DeletePartitionJob.cpp
|
${PartitionModule_SOURCE_DIR}/DeletePartitionJob.cpp
|
||||||
|
${PartitionModule_SOURCE_DIR}/PartitionInfo.cpp
|
||||||
|
${PartitionModule_SOURCE_DIR}/PartitionIterator.cpp
|
||||||
${PartitionModule_SOURCE_DIR}/PartitionJob.cpp
|
${PartitionModule_SOURCE_DIR}/PartitionJob.cpp
|
||||||
${PartitionModule_SOURCE_DIR}/PMUtils.cpp
|
${PartitionModule_SOURCE_DIR}/PMUtils.cpp
|
||||||
JobTests.cpp
|
JobTests.cpp
|
||||||
|
Loading…
Reference in New Issue
Block a user