2020-08-25 16:05:56 +02:00
|
|
|
/* === This file is part of Calamares - <https://calamares.io> ===
|
2014-07-23 18:14:27 +02:00
|
|
|
*
|
2020-08-22 01:19:58 +02:00
|
|
|
* SPDX-FileCopyrightText: 2014 Aurélien Gâteau <agateau@kde.org>
|
|
|
|
* SPDX-FileCopyrightText: 2015 Teo Mrnjavac <teo@kde.org>
|
|
|
|
* SPDX-FileCopyrightText: 2019 Adriaan de Groot <groot@kde.org>
|
|
|
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
2014-07-23 18:14:27 +02:00
|
|
|
*
|
2020-08-25 16:05:56 +02:00
|
|
|
* Calamares is Free Software: see the License-Identifier above.
|
2014-07-23 18:14:27 +02:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
#ifndef BOOTLOADERMODEL_H
|
|
|
|
#define BOOTLOADERMODEL_H
|
|
|
|
|
|
|
|
#include <QList>
|
2019-04-01 13:36:18 +02:00
|
|
|
#include <QMutex>
|
|
|
|
#include <QStandardItemModel>
|
2014-07-23 18:14:27 +02:00
|
|
|
|
|
|
|
class Device;
|
2019-05-28 17:01:58 +02:00
|
|
|
class QComboBox;
|
2014-07-23 18:14:27 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This model contains one entry for each device MBR plus one entry for the
|
|
|
|
* /boot or / partition
|
|
|
|
*/
|
|
|
|
class BootLoaderModel : public QStandardItemModel
|
|
|
|
{
|
2014-10-29 13:06:06 +01:00
|
|
|
Q_OBJECT
|
2014-07-23 18:14:27 +02:00
|
|
|
public:
|
2021-05-25 12:33:12 +02:00
|
|
|
using DeviceList = QList< Device* >;
|
|
|
|
|
2014-07-23 18:14:27 +02:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
BootLoaderPathRole = Qt::UserRole + 1,
|
|
|
|
IsPartitionRole
|
|
|
|
};
|
|
|
|
|
2017-09-21 10:04:01 +02:00
|
|
|
BootLoaderModel( QObject* parent = nullptr );
|
2017-09-20 14:24:28 +02:00
|
|
|
~BootLoaderModel() override;
|
2014-07-23 18:14:27 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Init the model with the list of devices. Does *not* take ownership of the
|
|
|
|
* devices.
|
|
|
|
*/
|
2021-05-25 12:33:12 +02:00
|
|
|
void init( const DeviceList& devices );
|
2014-07-23 18:14:27 +02:00
|
|
|
|
|
|
|
void update();
|
|
|
|
|
2015-06-06 23:45:34 +02:00
|
|
|
QVariant data( const QModelIndex& index, int role = Qt::DisplayRole ) const override;
|
|
|
|
|
2014-07-23 18:14:27 +02:00
|
|
|
private:
|
2019-04-01 13:36:18 +02:00
|
|
|
DeviceList m_devices;
|
|
|
|
mutable QMutex m_lock;
|
2014-07-23 18:14:27 +02:00
|
|
|
|
|
|
|
void createMbrItems();
|
2019-04-01 13:36:18 +02:00
|
|
|
void updateInternal();
|
2014-07-23 18:14:27 +02:00
|
|
|
};
|
|
|
|
|
2019-05-28 17:01:58 +02:00
|
|
|
namespace Calamares
|
|
|
|
{
|
2020-02-14 11:15:57 +01:00
|
|
|
/** @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 );
|
2019-05-28 17:01:58 +02:00
|
|
|
|
2020-02-14 11:15:57 +01:00
|
|
|
/** @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 Calamares
|
2014-07-23 18:14:27 +02:00
|
|
|
#endif /* BOOTLOADERMODEL_H */
|