[partition] Move BootLoaderModel convenience functions
- These were hidden inside PartitionPage, but are useful elsewhere.
This commit is contained in:
parent
8d451622db
commit
0ebabfafd4
@ -23,9 +23,13 @@
|
|||||||
#include "core/PartitionInfo.h"
|
#include "core/PartitionInfo.h"
|
||||||
#include "core/KPMHelpers.h"
|
#include "core/KPMHelpers.h"
|
||||||
|
|
||||||
|
#include "utils/Logger.h"
|
||||||
|
|
||||||
// KPMcore
|
// KPMcore
|
||||||
#include <kpmcore/core/device.h>
|
#include <kpmcore/core/device.h>
|
||||||
|
|
||||||
|
#include <QComboBox>
|
||||||
|
|
||||||
static QStandardItem*
|
static QStandardItem*
|
||||||
createBootLoaderItem( const QString& description, const QString& path, bool isPartition )
|
createBootLoaderItem( const QString& description, const QString& path, bool isPartition )
|
||||||
{
|
{
|
||||||
@ -148,3 +152,48 @@ BootLoaderModel::data( const QModelIndex& index, int role ) const
|
|||||||
}
|
}
|
||||||
return QStandardItemModel::data( index, role );
|
return QStandardItemModel::data( index, role );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace Calamares
|
||||||
|
{
|
||||||
|
int
|
||||||
|
findBootloader( const QAbstractItemModel* model, const QString& path )
|
||||||
|
{
|
||||||
|
for ( int i = 0; i < model->rowCount(); ++i)
|
||||||
|
{
|
||||||
|
const auto index = model->index( i, 0, QModelIndex() );
|
||||||
|
if ( !index.isValid() )
|
||||||
|
continue;
|
||||||
|
QVariant var = model->data( index, BootLoaderModel::BootLoaderPathRole );
|
||||||
|
if ( var.isValid() && var.toString() == path )
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
restoreSelectedBootLoader( QComboBox& combo, const QString& path )
|
||||||
|
{
|
||||||
|
const auto* model = combo.model();
|
||||||
|
if ( model->rowCount() < 1 )
|
||||||
|
{
|
||||||
|
cDebug() << "No items in BootLoaderModel";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int r = -1;
|
||||||
|
if ( path.isEmpty() )
|
||||||
|
{
|
||||||
|
combo.setCurrentIndex( 0 );
|
||||||
|
}
|
||||||
|
else if ( (r = findBootloader( model, path )) >= 0 )
|
||||||
|
{
|
||||||
|
combo.setCurrentIndex( r );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
combo.setCurrentIndex( 0 );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
#include <QStandardItemModel>
|
#include <QStandardItemModel>
|
||||||
|
|
||||||
class Device;
|
class Device;
|
||||||
|
class QComboBox;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This model contains one entry for each device MBR plus one entry for the
|
* This model contains one entry for each device MBR plus one entry for the
|
||||||
@ -63,4 +64,20 @@ private:
|
|||||||
void updateInternal();
|
void updateInternal();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
namespace Calamares
|
||||||
|
{
|
||||||
|
/** @brief Returns the row number of boot-loader @p path (e.g. /dev/sda)
|
||||||
|
*
|
||||||
|
* Assuming the @p model is a BootLoaderModel, will return a row number
|
||||||
|
* in the model. Returns -1 otherwise.
|
||||||
|
*/
|
||||||
|
int findBootloader( const QAbstractItemModel* model, const QString& path );
|
||||||
|
|
||||||
|
/** @brief Tries to set @p path as selected item in @p combo
|
||||||
|
*
|
||||||
|
* Matches a boot-loader install path (e.g. /dev/sda) with a model
|
||||||
|
* row and sets that as the current row.
|
||||||
|
*/
|
||||||
|
void restoreSelectedBootLoader( QComboBox& combo, const QString& path );
|
||||||
|
} // namespace
|
||||||
#endif /* BOOTLOADERMODEL_H */
|
#endif /* BOOTLOADERMODEL_H */
|
||||||
|
@ -511,45 +511,10 @@ PartitionPage::updateSelectedBootLoaderIndex()
|
|||||||
cDebug() << "Selected bootloader index" << m_lastSelectedBootLoaderIndex;
|
cDebug() << "Selected bootloader index" << m_lastSelectedBootLoaderIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
|
||||||
findBootloader( const QAbstractItemModel* model, const QString& path )
|
|
||||||
{
|
|
||||||
for ( int i = 0; i < model->rowCount(); ++i)
|
|
||||||
{
|
|
||||||
const auto index = model->index( i, 0, QModelIndex() );
|
|
||||||
if ( !index.isValid() )
|
|
||||||
continue;
|
|
||||||
QVariant var = model->data( index, BootLoaderModel::BootLoaderPathRole );
|
|
||||||
if ( var.isValid() && var.toString() == path )
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
PartitionPage::restoreSelectedBootLoader()
|
PartitionPage::restoreSelectedBootLoader()
|
||||||
{
|
{
|
||||||
const auto* model = m_ui->bootLoaderComboBox->model();
|
Calamares::restoreSelectedBootLoader( *(m_ui->bootLoaderComboBox), m_core->bootLoaderInstallPath() );
|
||||||
if ( model->rowCount() < 1 )
|
|
||||||
{
|
|
||||||
cDebug() << "No items in BootLoaderModel";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
int r = -1;
|
|
||||||
if ( m_core->bootLoaderInstallPath().isEmpty() )
|
|
||||||
{
|
|
||||||
m_ui->bootLoaderComboBox->setCurrentIndex( 0 );
|
|
||||||
}
|
|
||||||
else if ( (r = findBootloader( model, m_core->bootLoaderInstallPath() )) >= 0 )
|
|
||||||
{
|
|
||||||
m_ui->bootLoaderComboBox->setCurrentIndex( r );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
m_ui->bootLoaderComboBox->setCurrentIndex( 0 );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user