[libcalamares] Move partition-finding into libcalamares

- Moved from KPMHelpers to the partition service
 - The is-partition and find-partition methods that make sense
   in general, are moved to libcalamares.
This commit is contained in:
Adriaan de Groot 2019-06-13 14:41:33 +02:00
parent 3930826e93
commit 4b3bb54320
14 changed files with 221 additions and 94 deletions

View File

@ -117,6 +117,7 @@ if ( KPMcore_FOUND )
include_directories( ${KPMCORE_INCLUDE_DIR} ) include_directories( ${KPMCORE_INCLUDE_DIR} )
list( APPEND libSources list( APPEND libSources
partition/PartitionIterator.cpp partition/PartitionIterator.cpp
partition/PartitionQuery.cpp
) )
list( APPEND OPTIONAL_PRIVATE_LIBRARIES kpmcore ) list( APPEND OPTIONAL_PRIVATE_LIBRARIES kpmcore )
endif() endif()

View File

@ -0,0 +1,95 @@
/* === This file is part of Calamares - <https://github.com/calamares> ===
*
* Copyright 2014, Aurélien Gâteau <agateau@kde.org>
* Copyright 2015-2016, Teo Mrnjavac <teo@kde.org>
* Copyright 2018-2019 Adriaan de Groot <groot@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
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Calamares is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Calamares. If not, see <http://www.gnu.org/licenses/>.
*/
#include "PartitionQuery.h"
#include "PartitionIterator.h"
#include <kpmcore/core/device.h>
#include <kpmcore/core/partition.h>
namespace CalamaresUtils
{
namespace Partition
{
// Types from KPMCore
using ::Device;
using ::Partition;
bool
isPartitionFreeSpace( Partition* partition )
{
return partition->roles().has( PartitionRole::Unallocated );
}
bool
isPartitionNew( Partition* partition )
{
#if defined( WITH_KPMCORE4API )
constexpr auto NewState = Partition::State::New;
#else
constexpr auto NewState = Partition::StateNew;
#endif
return partition->state() == NewState;
}
Partition*
findPartitionByCurrentMountPoint( const QList< Device* >& devices, const QString& mountPoint )
{
for ( auto device : devices )
for ( auto it = PartitionIterator::begin( device ); it != PartitionIterator::end( device ); ++it )
if ( (*it)->mountPoint() == mountPoint )
return *it;
return nullptr;
}
Partition*
findPartitionByPath( const QList< Device* >& devices, const QString& path )
{
if ( path.simplified().isEmpty() )
return nullptr;
for ( auto device : devices )
for ( auto it = PartitionIterator::begin( device ); it != PartitionIterator::end( device ); ++it )
if ( ( *it )->partitionPath() == path.simplified() )
return *it;
return nullptr;
}
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;
}
}
} // namespace

View File

@ -0,0 +1,70 @@
/* === This file is part of Calamares - <https://github.com/calamares> ===
*
* Copyright 2014, Aurélien Gâteau <agateau@kde.org>
* Copyright 2015-2016, Teo Mrnjavac <teo@kde.org>
* Copyright 2019, Adriaan de Groot <groot@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
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Calamares is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Calamares. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef PARTITION_PARTITIONQUERY_H
#define PARTITION_PARTITIONQUERY_H
#include <kpmcore/fs/filesystem.h>
#include <QList>
#include <functional>
class Device;
class Partition;
namespace CalamaresUtils
{
namespace Partition
{
/** @brief Is this a free-space area? */
bool isPartitionFreeSpace( ::Partition* );
/** @brief Is this partition newly-to-be-created?
*
* Returns true if the partition is planned to be created by the installer as
* opposed to already existing on the disk.
*/
bool isPartitionNew( ::Partition* );
/**
* Iterates on all devices and return the first partition which is (already)
* mounted on @p mountPoint.
*/
::Partition* findPartitionByCurrentMountPoint( const QList< ::Device* >& devices, const QString& mountPoint );
// TODO: add this distinction
// ::Partition* findPartitionByIntendedMountPoint( const QList< ::Device* >& devices, const QString& mountPoint );
/**
* Iterates on all devices and partitions and returns a pointer to the Partition object
* for the given path, or nullptr if a Partition for the given path cannot be found.
*/
::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 );
}
}
#endif // PARTITION_PARTITIONQUERY_H

View File

@ -22,6 +22,7 @@
#include "core/KPMHelpers.h" #include "core/KPMHelpers.h"
#include "partition/PartitionIterator.h" #include "partition/PartitionIterator.h"
#include "partition/PartitionQuery.h"
#include "utils/Logger.h" #include "utils/Logger.h"
// KPMcore // KPMcore
@ -33,6 +34,8 @@
#include <QMap> #include <QMap>
using CalamaresUtils::Partition::PartitionIterator; using CalamaresUtils::Partition::PartitionIterator;
using CalamaresUtils::Partition::isPartitionFreeSpace;
using CalamaresUtils::Partition::isPartitionNew;
static const int NUM_PARTITION_COLORS = 5; static const int NUM_PARTITION_COLORS = 5;
static const int NUM_NEW_PARTITION_COLORS = 4; static const int NUM_NEW_PARTITION_COLORS = 4;
@ -91,7 +94,7 @@ colorForPartition( Partition* partition )
return FREE_SPACE_COLOR; return FREE_SPACE_COLOR;
} }
if ( KPMHelpers::isPartitionFreeSpace( partition ) ) if ( isPartitionFreeSpace( partition ) )
return FREE_SPACE_COLOR; return FREE_SPACE_COLOR;
if ( partition->roles().has( PartitionRole::Extended ) ) if ( partition->roles().has( PartitionRole::Extended ) )
return EXTENDED_COLOR; return EXTENDED_COLOR;
@ -126,16 +129,16 @@ colorForPartition( Partition* partition )
Partition* child = *it; Partition* child = *it;
if ( child == partition ) if ( child == partition )
break; break;
if ( !KPMHelpers::isPartitionFreeSpace( child ) && if ( !isPartitionFreeSpace( child ) &&
!child->hasChildren() ) !child->hasChildren() )
{ {
if ( KPMHelpers::isPartitionNew( child ) ) if ( isPartitionNew( child ) )
++newColorIdx; ++newColorIdx;
++colorIdx; ++colorIdx;
} }
} }
if ( KPMHelpers::isPartitionNew( partition ) ) if ( isPartitionNew( partition ) )
return NEW_PARTITION_COLORS[ newColorIdx % NUM_NEW_PARTITION_COLORS ]; return NEW_PARTITION_COLORS[ newColorIdx % NUM_NEW_PARTITION_COLORS ];
if ( partition->fileSystem().supportGetUUID() != FileSystem::cmdSupportNone && if ( partition->fileSystem().supportGetUUID() != FileSystem::cmdSupportNone &&
@ -172,9 +175,9 @@ colorForPartitionInFreeSpace( Partition* partition )
Partition* child = *it; Partition* child = *it;
if ( child == partition ) if ( child == partition )
break; break;
if ( !KPMHelpers::isPartitionFreeSpace( child ) && if ( !isPartitionFreeSpace( child ) &&
!child->hasChildren() && !child->hasChildren() &&
KPMHelpers::isPartitionNew( child ) ) isPartitionNew( child ) )
++newColorIdx; ++newColorIdx;
} }
return NEW_PARTITION_COLORS[ newColorIdx % NUM_NEW_PARTITION_COLORS ]; return NEW_PARTITION_COLORS[ newColorIdx % NUM_NEW_PARTITION_COLORS ];

View File

@ -56,20 +56,6 @@ initKPMcore()
} }
bool
isPartitionFreeSpace( Partition* partition )
{
return partition->roles().has( PartitionRole::Unallocated );
}
bool
isPartitionNew( Partition* partition )
{
return partition->state() == KPM_PARTITION_STATE(New);
}
Partition* Partition*
findPartitionByMountPoint( const QList< Device* >& devices, const QString& mountPoint ) findPartitionByMountPoint( const QList< Device* >& devices, const QString& mountPoint )
{ {
@ -81,33 +67,6 @@ findPartitionByMountPoint( const QList< Device* >& devices, const QString& mount
} }
Partition*
findPartitionByPath( const QList< Device* >& devices, const QString& path )
{
if ( path.simplified().isEmpty() )
return nullptr;
for ( auto device : devices )
for ( auto it = PartitionIterator::begin( device ); it != PartitionIterator::end( device ); ++it )
if ( ( *it )->partitionPath() == path.simplified() )
return *it;
return nullptr;
}
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* Partition*
createNewPartition( PartitionNode* parent, createNewPartition( PartitionNode* parent,
const Device& device, const Device& device,

View File

@ -63,33 +63,12 @@ namespace KPMHelpers
*/ */
bool initKPMcore(); bool initKPMcore();
bool isPartitionFreeSpace( Partition* );
/**
* Returns true if the partition is planned to be created by the installer as
* opposed to already existing on the disk.
*/
bool isPartitionNew( Partition* );
/** /**
* Iterates on all devices and return the first partition which is associated * Iterates on all devices and return the first partition which is associated
* with mountPoint. This uses PartitionInfo::mountPoint(), not Partition::mountPoint() * with mountPoint. This uses PartitionInfo::mountPoint(), not Partition::mountPoint()
*/ */
Partition* findPartitionByMountPoint( const QList< Device* >& devices, const QString& mountPoint ); Partition* findPartitionByMountPoint( const QList< Device* >& devices, const QString& mountPoint );
/**
* Iterates on all devices and partitions and returns a pointer to the Partition object
* for the given path, or nullptr if a Partition for the given path cannot be found.
*/
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 * Helper function to create a new Partition object (does not create anything
* on the disk) associated with a FileSystem. * on the disk) associated with a FileSystem.

View File

@ -29,6 +29,7 @@
#include "GlobalStorage.h" #include "GlobalStorage.h"
#include "JobQueue.h" #include "JobQueue.h"
#include "partition/PartitionIterator.h" #include "partition/PartitionIterator.h"
#include "partition/PartitionQuery.h"
#include "utils/CalamaresUtilsSystem.h" #include "utils/CalamaresUtilsSystem.h"
#include "utils/Logger.h" #include "utils/Logger.h"
@ -37,10 +38,12 @@
#include <kpmcore/core/device.h> #include <kpmcore/core/device.h>
#include <kpmcore/core/partition.h> #include <kpmcore/core/partition.h>
#include <QProcess> #include <QProcess>
#include <QTemporaryDir> #include <QTemporaryDir>
using CalamaresUtils::Partition::isPartitionFreeSpace;
using CalamaresUtils::Partition::isPartitionNew;
namespace PartUtils namespace PartUtils
{ {
@ -133,7 +136,7 @@ canBeResized( Partition* candidate )
return false; return false;
} }
if ( KPMHelpers::isPartitionFreeSpace( candidate ) ) if ( isPartitionFreeSpace( candidate ) )
{ {
cDebug() << Logger::SubEntry << "NO, partition is free space"; cDebug() << Logger::SubEntry << "NO, partition is free space";
return false; return false;
@ -206,7 +209,7 @@ canBeResized( PartitionCoreModule* core, const QString& partitionPath )
for ( int i = 0; i < dm->rowCount(); ++i ) for ( int i = 0; i < dm->rowCount(); ++i )
{ {
Device* dev = dm->deviceForIndex( dm->index( i ) ); Device* dev = dm->deviceForIndex( dm->index( i ) );
Partition* candidate = KPMHelpers::findPartitionByPath( { dev }, partitionWithOs ); Partition* candidate = CalamaresUtils::Partition::findPartitionByPath( { dev }, partitionWithOs );
if ( candidate ) if ( candidate )
{ {
return canBeResized( candidate ); return canBeResized( candidate );

View File

@ -48,6 +48,7 @@
#include "JobExample.h" #include "JobExample.h"
#endif #endif
#include "partition/PartitionIterator.h" #include "partition/PartitionIterator.h"
#include "partition/PartitionQuery.h"
#include "utils/Logger.h" #include "utils/Logger.h"
#include "utils/Variant.h" #include "utils/Variant.h"
@ -70,6 +71,8 @@
#include <QtConcurrent/QtConcurrent> #include <QtConcurrent/QtConcurrent>
using CalamaresUtils::Partition::PartitionIterator; using CalamaresUtils::Partition::PartitionIterator;
using CalamaresUtils::Partition::isPartitionFreeSpace;
using CalamaresUtils::Partition::isPartitionNew;
PartitionCoreModule::RefreshHelper::RefreshHelper(PartitionCoreModule* module) PartitionCoreModule::RefreshHelper::RefreshHelper(PartitionCoreModule* module)
: m_module( module ) : m_module( module )
@ -395,7 +398,7 @@ PartitionCoreModule::deletePartition( Device* device, Partition* partition )
// deleting them, so let's play it safe and keep our own list. // deleting them, so let's play it safe and keep our own list.
QList< Partition* > lst; QList< Partition* > lst;
for ( auto childPartition : partition->children() ) for ( auto childPartition : partition->children() )
if ( !KPMHelpers::isPartitionFreeSpace( childPartition ) ) if ( !isPartitionFreeSpace( childPartition ) )
lst << childPartition; lst << childPartition;
for ( auto childPartition : lst ) for ( auto childPartition : lst )
@ -653,7 +656,7 @@ PartitionCoreModule::scanForEfiSystemPartitions()
} }
QList< Partition* > efiSystemPartitions = QList< Partition* > efiSystemPartitions =
KPMHelpers::findPartitions( devices, PartUtils::isEfiBootable ); CalamaresUtils::Partition::findPartitions( devices, PartUtils::isEfiBootable );
if ( efiSystemPartitions.isEmpty() ) if ( efiSystemPartitions.isEmpty() )
cWarning() << "system is EFI but no EFI system partitions found."; cWarning() << "system is EFI but no EFI system partitions found.";

View File

@ -22,6 +22,8 @@
#include "core/ColorUtils.h" #include "core/ColorUtils.h"
#include "core/PartitionInfo.h" #include "core/PartitionInfo.h"
#include "core/KPMHelpers.h" #include "core/KPMHelpers.h"
#include "partition/PartitionQuery.h"
#include "utils/Logger.h" #include "utils/Logger.h"
// CalaPM // CalaPM
@ -36,6 +38,9 @@
// Qt // Qt
#include <QColor> #include <QColor>
using CalamaresUtils::Partition::isPartitionFreeSpace;
using CalamaresUtils::Partition::isPartitionNew;
//- ResetHelper -------------------------------------------- //- ResetHelper --------------------------------------------
PartitionModel::ResetHelper::ResetHelper( PartitionModel* model ) PartitionModel::ResetHelper::ResetHelper( PartitionModel* model )
: m_model( model ) : m_model( model )
@ -140,11 +145,11 @@ PartitionModel::data( const QModelIndex& index, int role ) const
int col = index.column(); int col = index.column();
if ( col == NameColumn ) if ( col == NameColumn )
{ {
if ( KPMHelpers::isPartitionFreeSpace( partition ) ) if ( isPartitionFreeSpace( partition ) )
return tr( "Free Space" ); return tr( "Free Space" );
else else
{ {
return KPMHelpers::isPartitionNew( partition ) return isPartitionNew( partition )
? tr( "New partition" ) ? tr( "New partition" )
: partition->partitionPath(); : partition->partitionPath();
} }
@ -172,11 +177,11 @@ PartitionModel::data( const QModelIndex& index, int role ) const
QString name; QString name;
if ( col == NameColumn ) if ( col == NameColumn )
{ {
if ( KPMHelpers::isPartitionFreeSpace( partition ) ) if ( isPartitionFreeSpace( partition ) )
name = tr( "Free Space" ); name = tr( "Free Space" );
else else
{ {
name = KPMHelpers::isPartitionNew( partition ) name = isPartitionNew( partition )
? tr( "New partition" ) ? tr( "New partition" )
: partition->partitionPath(); : partition->partitionPath();
} }
@ -189,10 +194,10 @@ PartitionModel::data( const QModelIndex& index, int role ) const
case SizeRole: case SizeRole:
return ( partition->lastSector() - partition->firstSector() + 1 ) * m_device->logicalSize(); return ( partition->lastSector() - partition->firstSector() + 1 ) * m_device->logicalSize();
case IsFreeSpaceRole: case IsFreeSpaceRole:
return KPMHelpers::isPartitionFreeSpace( partition ); return isPartitionFreeSpace( partition );
case IsPartitionNewRole: case IsPartitionNewRole:
return KPMHelpers::isPartitionNew( partition ); return isPartitionNew( partition );
case FileSystemLabelRole: case FileSystemLabelRole:
if ( partition->fileSystem().supportGetLabel() != FileSystem::cmdSupportNone && if ( partition->fileSystem().supportGetLabel() != FileSystem::cmdSupportNone &&

View File

@ -42,6 +42,7 @@
#include "GlobalStorage.h" #include "GlobalStorage.h"
#include "JobQueue.h" #include "JobQueue.h"
#include "partition/PartitionIterator.h" #include "partition/PartitionIterator.h"
#include "partition/PartitionQuery.h"
#include "utils/Logger.h" #include "utils/Logger.h"
#include "utils/Retranslator.h" #include "utils/Retranslator.h"
#include "utils/Units.h" #include "utils/Units.h"
@ -66,6 +67,8 @@
using PartitionActions::Choices::SwapChoice; using PartitionActions::Choices::SwapChoice;
using CalamaresUtils::Partition::PartitionIterator; using CalamaresUtils::Partition::PartitionIterator;
using CalamaresUtils::Partition::isPartitionFreeSpace;
using CalamaresUtils::Partition::findPartitionByPath;
/** @brief Given a set of swap choices, return a sensible value from it. /** @brief Given a set of swap choices, return a sensible value from it.
* *
@ -692,7 +695,7 @@ ChoicePage::doAlongsideApply()
for ( int i = 0; i < dm->rowCount(); ++i ) for ( int i = 0; i < dm->rowCount(); ++i )
{ {
Device* dev = dm->deviceForIndex( dm->index( i ) ); Device* dev = dm->deviceForIndex( dm->index( i ) );
Partition* candidate = KPMHelpers::findPartitionByPath( { dev }, path ); Partition* candidate = findPartitionByPath( { dev }, path );
if ( candidate ) if ( candidate )
{ {
qint64 firstSector = candidate->firstSector(); qint64 firstSector = candidate->firstSector();
@ -755,7 +758,7 @@ ChoicePage::doReplaceSelectedPartition( const QModelIndex& current )
Partition* selectedPartition = Partition* selectedPartition =
static_cast< Partition* >( current.data( PartitionModel::PartitionPtrRole ) static_cast< Partition* >( current.data( PartitionModel::PartitionPtrRole )
.value< void* >() ); .value< void* >() );
if ( KPMHelpers::isPartitionFreeSpace( selectedPartition ) ) if ( isPartitionFreeSpace( selectedPartition ) )
{ {
//NOTE: if the selected partition is free space, we don't deal with //NOTE: if the selected partition is free space, we don't deal with
// a separate /home partition at all because there's no existing // a separate /home partition at all because there's no existing
@ -769,7 +772,7 @@ ChoicePage::doReplaceSelectedPartition( const QModelIndex& current )
if ( parent && parent->roles().has( PartitionRole::Extended ) ) if ( parent && parent->roles().has( PartitionRole::Extended ) )
{ {
newRoles = PartitionRole( PartitionRole::Logical ); newRoles = PartitionRole( PartitionRole::Logical );
newParent = KPMHelpers::findPartitionByPath( { selectedDevice() }, parent->partitionPath() ); newParent = findPartitionByPath( { selectedDevice() }, parent->partitionPath() );
} }
} }
@ -783,7 +786,7 @@ ChoicePage::doReplaceSelectedPartition( const QModelIndex& current )
// We can't use the PartitionPtrRole because we need to make changes to the // We can't use the PartitionPtrRole because we need to make changes to the
// main DeviceModel, not the immutable copy. // main DeviceModel, not the immutable copy.
QString partPath = current.data( PartitionModel::PartitionPathRole ).toString(); QString partPath = current.data( PartitionModel::PartitionPathRole ).toString();
selectedPartition = KPMHelpers::findPartitionByPath( { selectedDevice() }, selectedPartition = findPartitionByPath( { selectedDevice() },
partPath ); partPath );
if ( selectedPartition ) if ( selectedPartition )
{ {
@ -806,7 +809,7 @@ ChoicePage::doReplaceSelectedPartition( const QModelIndex& current )
gs->value( "defaultFileSystemType" ).toString(), gs->value( "defaultFileSystemType" ).toString(),
m_encryptWidget->passphrase() m_encryptWidget->passphrase()
} ); } );
Partition* homePartition = KPMHelpers::findPartitionByPath( { selectedDevice() }, Partition* homePartition = findPartitionByPath( { selectedDevice() },
*homePartitionPath ); *homePartitionPath );
if ( homePartition && doReuseHomePartition ) if ( homePartition && doReuseHomePartition )

View File

@ -31,9 +31,10 @@
#include "ui_CreatePartitionDialog.h" #include "ui_CreatePartitionDialog.h"
#include "utils/Logger.h"
#include "GlobalStorage.h" #include "GlobalStorage.h"
#include "JobQueue.h" #include "JobQueue.h"
#include "partition/PartitionQuery.h"
#include "utils/Logger.h"
// KPMcore // KPMcore
#include <kpmcore/core/device.h> #include <kpmcore/core/device.h>
@ -272,7 +273,7 @@ CreatePartitionDialog::checkMountPointSelection()
void void
CreatePartitionDialog::initPartResizerWidget( Partition* partition ) CreatePartitionDialog::initPartResizerWidget( Partition* partition )
{ {
QColor color = KPMHelpers::isPartitionFreeSpace( partition ) QColor color = CalamaresUtils::Partition::isPartitionFreeSpace( partition )
? ColorUtils::colorForPartitionInFreeSpace( partition ) ? ColorUtils::colorForPartitionInFreeSpace( partition )
: ColorUtils::colorForPartition( partition ); : ColorUtils::colorForPartition( partition );
m_partitionSizeController->init( m_device, partition, color ); m_partitionSizeController->init( m_device, partition, color );

View File

@ -40,11 +40,13 @@
#include "ui_PartitionPage.h" #include "ui_PartitionPage.h"
#include "ui_CreatePartitionTableDialog.h" #include "ui_CreatePartitionTableDialog.h"
#include "GlobalStorage.h"
#include "JobQueue.h"
#include "partition/PartitionQuery.h"
#include "utils/Logger.h" #include "utils/Logger.h"
#include "utils/Retranslator.h" #include "utils/Retranslator.h"
#include "Branding.h" #include "Branding.h"
#include "JobQueue.h"
#include "GlobalStorage.h"
// KPMcore // KPMcore
#include <kpmcore/core/device.h> #include <kpmcore/core/device.h>
@ -132,7 +134,7 @@ PartitionPage::updateButtons()
Q_ASSERT( model ); Q_ASSERT( model );
Partition* partition = model->partitionForIndex( index ); Partition* partition = model->partitionForIndex( index );
Q_ASSERT( partition ); Q_ASSERT( partition );
bool isFree = KPMHelpers::isPartitionFreeSpace( partition ); bool isFree = CalamaresUtils::Partition::isPartitionFreeSpace( partition );
bool isExtended = partition->roles().has( PartitionRole::Extended ); bool isExtended = partition->roles().has( PartitionRole::Extended );
bool isInVG = m_core->isInVG( partition ); bool isInVG = m_core->isInVG( partition );
@ -392,7 +394,7 @@ PartitionPage::onEditClicked()
Partition* partition = model->partitionForIndex( index ); Partition* partition = model->partitionForIndex( index );
Q_ASSERT( partition ); Q_ASSERT( partition );
if ( KPMHelpers::isPartitionNew( partition ) ) if ( CalamaresUtils::Partition::isPartitionNew( partition ) )
updatePartitionToCreate( model->device(), partition ); updatePartitionToCreate( model->device(), partition );
else else
editExistingPartition( model->device(), partition ); editExistingPartition( model->device(), partition );
@ -452,7 +454,7 @@ PartitionPage::onPartitionViewActivated()
// but I don't expect there will be other occurences of triggering the same // but I don't expect there will be other occurences of triggering the same
// action from multiple UI elements in this page, so it does not feel worth // action from multiple UI elements in this page, so it does not feel worth
// the price. // the price.
if ( KPMHelpers::isPartitionFreeSpace( partition ) ) if ( CalamaresUtils::Partition::isPartitionFreeSpace( partition ) )
m_ui->createButton->click(); m_ui->createButton->click();
else else
m_ui->editButton->click(); m_ui->editButton->click();

View File

@ -21,8 +21,9 @@
#include "core/ColorUtils.h" #include "core/ColorUtils.h"
#include "core/KPMHelpers.h" #include "core/KPMHelpers.h"
#include "utils/Logger.h"
#include "partition/PartitionIterator.h" #include "partition/PartitionIterator.h"
#include "partition/PartitionQuery.h"
#include "utils/Logger.h"
#include "utils/CalamaresUtilsGui.h" #include "utils/CalamaresUtilsGui.h"
@ -69,7 +70,7 @@ PartitionSplitterWidget::init( Device* dev, bool drawNestedPartitions )
PartitionSplitterItem newItem = { PartitionSplitterItem newItem = {
( *it )->partitionPath(), ( *it )->partitionPath(),
ColorUtils::colorForPartition( *it ), ColorUtils::colorForPartition( *it ),
KPMHelpers::isPartitionFreeSpace( *it ), CalamaresUtils::Partition::isPartitionFreeSpace( *it ),
( *it )->capacity(), ( *it )->capacity(),
PartitionSplitterItem::Normal, PartitionSplitterItem::Normal,
{} {}

View File

@ -19,6 +19,7 @@
#include <PartitionJobTests.h> #include <PartitionJobTests.h>
#include "partition/PartitionQuery.h"
#include "utils/Units.h" #include "utils/Units.h"
#include <jobs/CreatePartitionJob.h> #include <jobs/CreatePartitionJob.h>
@ -40,6 +41,7 @@ QTEST_GUILESS_MAIN( PartitionJobTests )
using namespace Calamares; using namespace Calamares;
using CalamaresUtils::operator""_MiB; using CalamaresUtils::operator""_MiB;
using CalamaresUtils::Partition::isPartitionFreeSpace;
class PartitionMounter class PartitionMounter
{ {
@ -115,7 +117,7 @@ static Partition*
firstFreePartition( PartitionNode* parent ) firstFreePartition( PartitionNode* parent )
{ {
for( auto child : parent->children() ) for( auto child : parent->children() )
if ( KPMHelpers::isPartitionFreeSpace( child ) ) if ( isPartitionFreeSpace( child ) )
return child; return child;
return nullptr; return nullptr;
} }