Add generic search function to iterate over partitions for convenience.
This commit is contained in:
parent
04f977d28f
commit
94e9c659d1
@ -1,6 +1,7 @@
|
||||
/* === This file is part of Calamares - <http://github.com/calamares> ===
|
||||
*
|
||||
* Copyright 2014, Aurélien Gâteau <agateau@kde.org>
|
||||
* Copyright 2015, Teo Mrnjavac <teo@kde.org>
|
||||
*
|
||||
* Calamares is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@ -29,13 +30,15 @@ namespace PMUtils
|
||||
{
|
||||
|
||||
|
||||
bool isPartitionFreeSpace( Partition* partition )
|
||||
bool
|
||||
isPartitionFreeSpace( Partition* partition )
|
||||
{
|
||||
return partition->roles().has( PartitionRole::Unallocated );
|
||||
}
|
||||
|
||||
|
||||
bool isPartitionNew( Partition* partition )
|
||||
bool
|
||||
isPartitionNew( Partition* partition )
|
||||
{
|
||||
return partition->state() == Partition::StateNew;
|
||||
}
|
||||
@ -63,6 +66,19 @@ findPartitionByPath( const QList< Device* >& devices, const QString& path )
|
||||
}
|
||||
|
||||
|
||||
QList< Partition* >
|
||||
findPartitions( const QList< Device* >& devices,
|
||||
std::function< bool ( Partition* ) > criterionFunction )
|
||||
{
|
||||
QList< Partition* > results;
|
||||
for ( auto device : devices )
|
||||
for ( auto it = PartitionIterator::begin( device ); it != PartitionIterator::end( device ); ++it )
|
||||
if ( criterionFunction( *it ) )
|
||||
results.append( *it );
|
||||
return results;
|
||||
}
|
||||
|
||||
|
||||
Partition*
|
||||
createNewPartition( PartitionNode* parent, const Device& device, const PartitionRole& role, FileSystem::Type fsType, qint64 firstSector, qint64 lastSector )
|
||||
{
|
||||
|
@ -1,6 +1,7 @@
|
||||
/* === This file is part of Calamares - <http://github.com/calamares> ===
|
||||
*
|
||||
* Copyright 2014, Aurélien Gâteau <agateau@kde.org>
|
||||
* Copyright 2015, Teo Mrnjavac <teo@kde.org>
|
||||
*
|
||||
* Calamares is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@ -24,6 +25,8 @@
|
||||
// Qt
|
||||
#include <QList>
|
||||
|
||||
#include <functional>
|
||||
|
||||
class Device;
|
||||
class Partition;
|
||||
class PartitionNode;
|
||||
@ -55,6 +58,13 @@ Partition* findPartitionByMountPoint( const QList< Device* >& devices, const QSt
|
||||
*/
|
||||
Partition* findPartitionByPath( const QList< Device* >& devices, const QString& path );
|
||||
|
||||
/**
|
||||
* Iterates on all devices and partitions and returns a list of pointers to the Partition
|
||||
* objects that satisfy the conditions defined in the criterion function.
|
||||
*/
|
||||
QList< Partition* > findPartitions( const QList< Device* >& devices,
|
||||
std::function< bool ( Partition* ) > criterionFunction );
|
||||
|
||||
/**
|
||||
* Helper function to create a new Partition object (does not create anything
|
||||
* on the disk) associated with a FileSystem.
|
||||
|
Loading…
Reference in New Issue
Block a user