source: calamares/trunk/fuentes/src/modules/partition/core/BootLoaderModel.cpp @ 7538

Last change on this file since 7538 was 7538, checked in by kbut, 13 months ago

sync with github

File size: 3.7 KB
Line 
1/* === This file is part of Calamares - <https://github.com/calamares> ===
2 *
3 *   Copyright 2014, Aurélien Gâteau <agateau@kde.org>
4 *   Copyright 2015, Teo Mrnjavac <teo@kde.org>
5 *
6 *   Calamares is free software: you can redistribute it and/or modify
7 *   it under the terms of the GNU General Public License as published by
8 *   the Free Software Foundation, either version 3 of the License, or
9 *   (at your option) any later version.
10 *
11 *   Calamares is distributed in the hope that it will be useful,
12 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
13 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 *   GNU General Public License for more details.
15 *
16 *   You should have received a copy of the GNU General Public License
17 *   along with Calamares. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#include "core/BootLoaderModel.h"
21
22#include "core/PartitionInfo.h"
23#include "core/KPMHelpers.h"
24
25// KPMcore
26#include <kpmcore/core/device.h>
27
28static QStandardItem*
29createBootLoaderItem( const QString& description, const QString& path, bool isPartition )
30{
31    QStandardItem* item = new QStandardItem( description );
32    item->setData( path, BootLoaderModel::BootLoaderPathRole );
33    item->setData( isPartition, BootLoaderModel::IsPartitionRole );
34    return item;
35}
36
37BootLoaderModel::BootLoaderModel( QObject* parent )
38    : QStandardItemModel( parent )
39{
40}
41
42BootLoaderModel::~BootLoaderModel()
43{
44}
45
46void
47BootLoaderModel::init( const QList< Device* >& devices )
48{
49    m_devices = devices;
50    clear();
51    createMbrItems();
52}
53
54void
55BootLoaderModel::createMbrItems()
56{
57    for ( auto device : m_devices )
58    {
59        QString text = tr( "Master Boot Record of %1" )
60                       .arg( device->name() );
61        appendRow(
62            createBootLoaderItem( text, device->deviceNode(), false )
63        );
64    }
65}
66
67void
68BootLoaderModel::update()
69{
70    clear();
71    createMbrItems();
72
73    QString partitionText;
74    Partition* partition = KPMHelpers::findPartitionByMountPoint( m_devices, "/boot" );
75    if ( partition )
76        partitionText = tr( "Boot Partition" );
77    else
78    {
79        partition = KPMHelpers::findPartitionByMountPoint( m_devices, "/" );
80        if ( partition )
81            partitionText = tr( "System Partition" );
82    }
83
84    Q_ASSERT( rowCount() > 0 );
85    QStandardItem* last = item( rowCount() - 1 );
86    Q_ASSERT( last );
87    bool lastIsPartition = last->data( IsPartitionRole ).toBool();
88
89    if ( !partition )
90    {
91        if ( lastIsPartition )
92            takeRow( rowCount() - 1 );
93    }
94    else
95    {
96        QString mountPoint = PartitionInfo::mountPoint( partition );
97        if ( lastIsPartition )
98        {
99            last->setText( partitionText );
100            last->setData( mountPoint, BootLoaderPathRole );
101        }
102        else
103        {
104            appendRow(
105                createBootLoaderItem( partitionText, PartitionInfo::mountPoint( partition ), true )
106            );
107        }
108
109        // Create "don't install bootloader" item
110        appendRow(
111            createBootLoaderItem( tr( "Do not install a boot loader" ), QString(), false )
112        );
113    }
114}
115
116
117QVariant
118BootLoaderModel::data( const QModelIndex& index, int role ) const
119{
120    if ( role == Qt::DisplayRole )
121    {
122        if ( QStandardItemModel::data( index, BootLoaderModel::BootLoaderPathRole ).toString().isEmpty() )
123            return QStandardItemModel::data( index, Qt::DisplayRole ).toString();
124
125        return tr( "%1 (%2)" )
126                .arg( QStandardItemModel::data( index, Qt::DisplayRole ).toString() )
127                .arg( QStandardItemModel::data( index, BootLoaderModel::BootLoaderPathRole ).toString() );
128    }
129    return QStandardItemModel::data( index, role );
130}
Note: See TracBrowser for help on using the repository browser.