2017-12-20 14:39:09 +01:00
|
|
|
/* === This file is part of Calamares - <https://github.com/calamares> ===
|
2014-07-23 18:14:27 +02:00
|
|
|
*
|
|
|
|
* Copyright 2014, Aurélien Gâteau <agateau@kde.org>
|
2015-06-06 23:45:34 +02:00
|
|
|
* Copyright 2015, Teo Mrnjavac <teo@kde.org>
|
2019-04-01 13:55:14 +02:00
|
|
|
* Copyright 2019, Adriaan de Groot <groot@kde.org>
|
2014-07-23 18:14:27 +02:00
|
|
|
*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
2015-07-02 13:49:21 +02:00
|
|
|
#include "core/BootLoaderModel.h"
|
2014-07-23 18:14:27 +02:00
|
|
|
|
2015-07-02 13:49:21 +02:00
|
|
|
#include "core/PartitionInfo.h"
|
2015-09-18 15:41:07 +02:00
|
|
|
#include "core/KPMHelpers.h"
|
2015-07-02 13:49:21 +02:00
|
|
|
|
2019-05-28 17:01:58 +02:00
|
|
|
#include "utils/Logger.h"
|
|
|
|
|
2015-07-02 13:49:21 +02:00
|
|
|
// KPMcore
|
|
|
|
#include <kpmcore/core/device.h>
|
2014-07-23 18:14:27 +02:00
|
|
|
|
2019-05-28 17:01:58 +02:00
|
|
|
#include <QComboBox>
|
|
|
|
|
2014-07-23 18:14:27 +02:00
|
|
|
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 )
|
|
|
|
{
|
2019-04-02 10:55:12 +02:00
|
|
|
beginResetModel();
|
|
|
|
blockSignals( true );
|
|
|
|
|
2014-07-23 18:14:27 +02:00
|
|
|
m_devices = devices;
|
|
|
|
clear();
|
|
|
|
createMbrItems();
|
2019-04-02 10:55:12 +02:00
|
|
|
|
|
|
|
blockSignals( false );
|
|
|
|
endResetModel();
|
2014-07-23 18:14:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
BootLoaderModel::createMbrItems()
|
|
|
|
{
|
2014-07-28 15:00:17 +02:00
|
|
|
for ( auto device : m_devices )
|
2014-07-23 18:14:27 +02:00
|
|
|
{
|
|
|
|
QString text = tr( "Master Boot Record of %1" )
|
2014-07-28 15:00:17 +02:00
|
|
|
.arg( device->name() );
|
2014-07-23 18:14:27 +02:00
|
|
|
appendRow(
|
|
|
|
createBootLoaderItem( text, device->deviceNode(), false )
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
BootLoaderModel::update()
|
|
|
|
{
|
2019-03-29 16:37:26 +01:00
|
|
|
beginResetModel();
|
|
|
|
blockSignals( true );
|
2019-04-01 13:36:18 +02:00
|
|
|
updateInternal();
|
|
|
|
blockSignals( false );
|
|
|
|
endResetModel();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
BootLoaderModel::updateInternal()
|
|
|
|
{
|
|
|
|
QMutexLocker lock(&m_lock);
|
2015-07-07 19:16:22 +02:00
|
|
|
clear();
|
|
|
|
createMbrItems();
|
|
|
|
|
2014-07-23 18:14:27 +02:00
|
|
|
QString partitionText;
|
2015-09-18 15:41:07 +02:00
|
|
|
Partition* partition = KPMHelpers::findPartitionByMountPoint( m_devices, "/boot" );
|
2014-07-23 18:14:27 +02:00
|
|
|
if ( partition )
|
|
|
|
partitionText = tr( "Boot Partition" );
|
|
|
|
else
|
|
|
|
{
|
2015-09-18 15:41:07 +02:00
|
|
|
partition = KPMHelpers::findPartitionByMountPoint( m_devices, "/" );
|
2014-07-23 18:14:27 +02:00
|
|
|
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 );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-07-07 19:16:22 +02:00
|
|
|
QString mountPoint = PartitionInfo::mountPoint( partition );
|
|
|
|
if ( lastIsPartition )
|
|
|
|
{
|
|
|
|
last->setText( partitionText );
|
|
|
|
last->setData( mountPoint, BootLoaderPathRole );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
appendRow(
|
|
|
|
createBootLoaderItem( partitionText, PartitionInfo::mountPoint( partition ), true )
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create "don't install bootloader" item
|
2014-07-23 18:14:27 +02:00
|
|
|
appendRow(
|
2015-07-07 19:16:22 +02:00
|
|
|
createBootLoaderItem( tr( "Do not install a boot loader" ), QString(), false )
|
2014-07-23 18:14:27 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-06 23:45:34 +02:00
|
|
|
|
|
|
|
QVariant
|
|
|
|
BootLoaderModel::data( const QModelIndex& index, int role ) const
|
|
|
|
{
|
2019-04-01 13:36:18 +02:00
|
|
|
QMutexLocker lock(&m_lock);
|
2015-06-06 23:45:34 +02:00
|
|
|
if ( role == Qt::DisplayRole )
|
2015-07-07 19:16:22 +02:00
|
|
|
{
|
2019-03-29 15:54:04 +01:00
|
|
|
QString displayRole = QStandardItemModel::data( index, Qt::DisplayRole ).toString();
|
|
|
|
QString pathRole = QStandardItemModel::data( index, BootLoaderModel::BootLoaderPathRole ).toString();
|
|
|
|
if ( pathRole.isEmpty() )
|
|
|
|
return displayRole;
|
2015-07-07 19:16:22 +02:00
|
|
|
|
2019-03-29 15:54:04 +01:00
|
|
|
return tr( "%1 (%2)" ).arg( displayRole, pathRole );
|
2015-07-07 19:16:22 +02:00
|
|
|
}
|
2015-06-06 23:45:34 +02:00
|
|
|
return QStandardItemModel::data( index, role );
|
|
|
|
}
|
2019-05-28 17:01:58 +02:00
|
|
|
|
|
|
|
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
|