source: calamares/trunk/fuentes/src/modules/partition/gui/PartitionDialogHelpers.cpp @ 7538

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

sync with github

File size: 3.3 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 2016, Teo Mrnjavac <teo@kde.org>
5 *   Copyright 2018, Adriaan de Groot <groot@kde.org>
6 *
7 *   Calamares is free software: you can redistribute it and/or modify
8 *   it under the terms of the GNU General Public License as published by
9 *   the Free Software Foundation, either version 3 of the License, or
10 *   (at your option) any later version.
11 *
12 *   Calamares is distributed in the hope that it will be useful,
13 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
14 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 *   GNU General Public License for more details.
16 *
17 *   You should have received a copy of the GNU General Public License
18 *   along with Calamares. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21#include "PartitionDialogHelpers.h"
22
23#include "core/PartUtils.h"
24
25#include "GlobalStorage.h"
26#include "JobQueue.h"
27#include "utils/Logger.h"
28
29#include <QComboBox>
30#include <QListWidget>
31
32QStringList
33standardMountPoints()
34{
35    QStringList mountPoints{ "/", "/boot", "/home", "/opt", "/srv", "/usr", "/var" };
36    if ( PartUtils::isEfiSystem() )
37        mountPoints << Calamares::JobQueue::instance()->globalStorage()->value( "efiSystemPartition" ).toString();
38    mountPoints.removeDuplicates();
39    mountPoints.sort();
40    return mountPoints;
41}
42
43void
44standardMountPoints(QComboBox& combo)
45{
46    combo.clear();
47    combo.addItem( combo.tr( "(no mount point)" ) );
48    combo.addItems( standardMountPoints() );
49}
50
51void
52standardMountPoints(QComboBox& combo, const QString& selected)
53{
54    standardMountPoints( combo );
55    setSelectedMountPoint( combo, selected );
56}
57
58QString
59selectedMountPoint(QComboBox& combo)
60{
61    if ( combo.currentIndex() == 0 )
62        return QString();
63    return combo.currentText();
64}
65
66void
67setSelectedMountPoint(QComboBox& combo, const QString& selected)
68{
69    if ( selected.isEmpty() )
70        combo.setCurrentIndex( 0 );  // (no mount point)
71    else
72    {
73        for ( int i = 0; i < combo.count(); ++i )
74            if ( selected == combo.itemText( i ) )
75            {
76                combo.setCurrentIndex( i );
77                return;
78            }
79        combo.addItem( selected );
80        combo.setCurrentIndex( combo.count() - 1);
81    }
82}
83
84
85PartitionTable::Flags
86flagsFromList( const QListWidget& list )
87{
88    PartitionTable::Flags flags;
89
90    for ( int i = 0; i < list.count(); i++ )
91        if ( list.item( i )->checkState() == Qt::Checked )
92            flags |= static_cast< PartitionTable::Flag >(
93                         list.item( i )->data( Qt::UserRole ).toInt() );
94
95    return flags;
96}
97
98void
99setFlagList( QListWidget& list, PartitionTable::Flags available, PartitionTable::Flags checked )
100{
101    int f = 1;
102    QString s;
103    while ( !( s = PartitionTable::flagName( static_cast< PartitionTable::Flag >( f ) ) ).isEmpty() )
104    {
105        if ( available & f )
106        {
107            QListWidgetItem* item = new QListWidgetItem( s );
108            list.addItem( item );
109            item->setFlags( Qt::ItemIsUserCheckable | Qt::ItemIsEnabled );
110            item->setData( Qt::UserRole, f );
111            item->setCheckState( ( checked & f ) ?
112                                     Qt::Checked :
113                                     Qt::Unchecked );
114        }
115
116        f <<= 1;
117    }
118}
Note: See TracBrowser for help on using the repository browser.