diff --git a/src/modules/partition/core/PMUtils.cpp b/src/modules/partition/core/PMUtils.cpp index 7f5d2ac78..89d97cefd 100644 --- a/src/modules/partition/core/PMUtils.cpp +++ b/src/modules/partition/core/PMUtils.cpp @@ -1,6 +1,7 @@ /* === This file is part of Calamares - === * * Copyright 2014, Aurélien Gâteau + * Copyright 2015, Teo Mrnjavac * * 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 ) { diff --git a/src/modules/partition/core/PMUtils.h b/src/modules/partition/core/PMUtils.h index 81778ae3b..b5d661880 100644 --- a/src/modules/partition/core/PMUtils.h +++ b/src/modules/partition/core/PMUtils.h @@ -1,6 +1,7 @@ /* === This file is part of Calamares - === * * Copyright 2014, Aurélien Gâteau + * Copyright 2015, Teo Mrnjavac * * 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 +#include + 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.