2020-08-25 16:05:56 +02:00
|
|
|
/* === This file is part of Calamares - <https://calamares.io> ===
|
2018-05-15 11:40:52 +02:00
|
|
|
*
|
2020-08-22 01:19:58 +02:00
|
|
|
* SPDX-FileCopyrightText: 2014 Aurélien Gâteau <agateau@kde.org>
|
|
|
|
* SPDX-FileCopyrightText: 2016 Teo Mrnjavac <teo@kde.org>
|
|
|
|
* SPDX-FileCopyrightText: 2018-2019 Adriaan de Groot <groot@kde.org>
|
|
|
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
2018-05-15 11:40:52 +02:00
|
|
|
*
|
2020-08-25 16:05:56 +02:00
|
|
|
* Calamares is Free Software: see the License-Identifier above.
|
2018-05-15 11:40:52 +02:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2018-05-16 14:34:33 +02:00
|
|
|
#include "PartitionDialogHelpers.h"
|
2018-05-15 11:40:52 +02:00
|
|
|
|
|
|
|
#include "core/PartUtils.h"
|
|
|
|
|
|
|
|
#include "GlobalStorage.h"
|
|
|
|
#include "JobQueue.h"
|
2018-05-15 12:30:18 +02:00
|
|
|
#include "utils/Logger.h"
|
2018-05-15 11:40:52 +02:00
|
|
|
|
|
|
|
#include <QComboBox>
|
2018-05-16 14:41:47 +02:00
|
|
|
#include <QListWidget>
|
2018-05-15 11:40:52 +02:00
|
|
|
|
|
|
|
QStringList
|
|
|
|
standardMountPoints()
|
|
|
|
{
|
2021-06-18 22:20:11 +02:00
|
|
|
QStringList mountPoints { "/", "/home", "/opt", "/srv", "/usr", "/var" };
|
2018-05-15 11:40:52 +02:00
|
|
|
if ( PartUtils::isEfiSystem() )
|
2020-08-22 01:19:58 +02:00
|
|
|
{
|
2018-05-15 11:40:52 +02:00
|
|
|
mountPoints << Calamares::JobQueue::instance()->globalStorage()->value( "efiSystemPartition" ).toString();
|
2020-08-22 01:19:58 +02:00
|
|
|
}
|
2021-06-18 22:20:11 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
mountPoints << QStringLiteral( "/boot" );
|
|
|
|
}
|
2018-05-15 11:40:52 +02:00
|
|
|
mountPoints.removeDuplicates();
|
|
|
|
mountPoints.sort();
|
|
|
|
return mountPoints;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2020-08-22 01:19:58 +02:00
|
|
|
standardMountPoints( QComboBox& combo )
|
2018-05-15 11:40:52 +02:00
|
|
|
{
|
|
|
|
combo.clear();
|
2019-02-14 22:08:55 +01:00
|
|
|
combo.addItem( QObject::tr( "(no mount point)" ) );
|
2018-05-15 11:40:52 +02:00
|
|
|
combo.addItems( standardMountPoints() );
|
|
|
|
}
|
|
|
|
|
2018-05-15 12:13:19 +02:00
|
|
|
void
|
2020-08-22 01:19:58 +02:00
|
|
|
standardMountPoints( QComboBox& combo, const QString& selected )
|
2018-05-15 12:13:19 +02:00
|
|
|
{
|
|
|
|
standardMountPoints( combo );
|
2018-05-16 12:15:33 +02:00
|
|
|
setSelectedMountPoint( combo, selected );
|
2018-05-15 12:13:19 +02:00
|
|
|
}
|
2018-05-15 12:30:18 +02:00
|
|
|
|
|
|
|
QString
|
2020-08-22 01:19:58 +02:00
|
|
|
selectedMountPoint( QComboBox& combo )
|
2018-05-15 12:30:18 +02:00
|
|
|
{
|
|
|
|
if ( combo.currentIndex() == 0 )
|
2020-08-22 01:19:58 +02:00
|
|
|
{
|
2018-05-15 12:30:18 +02:00
|
|
|
return QString();
|
2020-08-22 01:19:58 +02:00
|
|
|
}
|
2018-05-15 12:30:18 +02:00
|
|
|
return combo.currentText();
|
|
|
|
}
|
2018-05-15 14:01:18 +02:00
|
|
|
|
|
|
|
void
|
2020-08-22 01:19:58 +02:00
|
|
|
setSelectedMountPoint( QComboBox& combo, const QString& selected )
|
2018-05-15 14:01:18 +02:00
|
|
|
{
|
|
|
|
if ( selected.isEmpty() )
|
2020-08-22 01:19:58 +02:00
|
|
|
{
|
2018-05-15 14:01:18 +02:00
|
|
|
combo.setCurrentIndex( 0 ); // (no mount point)
|
2020-08-22 01:19:58 +02:00
|
|
|
}
|
2018-05-15 14:01:18 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
for ( int i = 0; i < combo.count(); ++i )
|
2021-06-18 22:20:11 +02:00
|
|
|
{
|
2018-05-15 14:01:18 +02:00
|
|
|
if ( selected == combo.itemText( i ) )
|
|
|
|
{
|
|
|
|
combo.setCurrentIndex( i );
|
|
|
|
return;
|
|
|
|
}
|
2021-06-18 22:20:11 +02:00
|
|
|
}
|
2018-05-15 14:01:18 +02:00
|
|
|
combo.addItem( selected );
|
2020-08-22 01:19:58 +02:00
|
|
|
combo.setCurrentIndex( combo.count() - 1 );
|
2018-05-15 14:01:18 +02:00
|
|
|
}
|
|
|
|
}
|
2018-05-16 14:41:47 +02:00
|
|
|
|
|
|
|
|
|
|
|
PartitionTable::Flags
|
|
|
|
flagsFromList( const QListWidget& list )
|
|
|
|
{
|
|
|
|
PartitionTable::Flags flags;
|
|
|
|
|
|
|
|
for ( int i = 0; i < list.count(); i++ )
|
2021-06-18 22:20:11 +02:00
|
|
|
{
|
2018-05-16 14:41:47 +02:00
|
|
|
if ( list.item( i )->checkState() == Qt::Checked )
|
2020-08-22 01:19:58 +02:00
|
|
|
{
|
|
|
|
flags |= static_cast< PartitionTable::Flag >( list.item( i )->data( Qt::UserRole ).toInt() );
|
|
|
|
}
|
2021-06-18 22:20:11 +02:00
|
|
|
}
|
2018-05-16 14:41:47 +02:00
|
|
|
|
|
|
|
return flags;
|
|
|
|
}
|
|
|
|
|
2018-05-16 15:04:47 +02:00
|
|
|
void
|
|
|
|
setFlagList( QListWidget& list, PartitionTable::Flags available, PartitionTable::Flags checked )
|
|
|
|
{
|
|
|
|
int f = 1;
|
|
|
|
QString s;
|
|
|
|
while ( !( s = PartitionTable::flagName( static_cast< PartitionTable::Flag >( f ) ) ).isEmpty() )
|
|
|
|
{
|
|
|
|
if ( available & f )
|
|
|
|
{
|
|
|
|
QListWidgetItem* item = new QListWidgetItem( s );
|
|
|
|
list.addItem( item );
|
|
|
|
item->setFlags( Qt::ItemIsUserCheckable | Qt::ItemIsEnabled );
|
|
|
|
item->setData( Qt::UserRole, f );
|
2020-08-22 01:19:58 +02:00
|
|
|
item->setCheckState( ( checked & f ) ? Qt::Checked : Qt::Unchecked );
|
2018-05-16 15:04:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
f <<= 1;
|
|
|
|
}
|
|
|
|
}
|