mirror of
https://github.com/parchlinux/calamares.git
synced 2025-03-01 05:15:44 -05:00
[libcalamares] Move PartitionIterator to partition service.
- Starting to centralize utility code for partitioning into libcalamares instead of scattered and weirdly shared between modules. - This particular commit breaks compiling the modules, though.
This commit is contained in:
parent
f1822c2adb
commit
d8dc512f45
6 changed files with 74 additions and 17 deletions
|
@ -97,6 +97,30 @@ if( Qt5Xml_FOUND )
|
|||
list( APPEND OPTIONAL_PUBLIC_LIBRARIES Qt5::Network Qt5::Xml )
|
||||
endif()
|
||||
|
||||
### OPTIONAL KPMcore support
|
||||
#
|
||||
#
|
||||
find_package( KPMcore 3.3 )
|
||||
set_package_properties(
|
||||
KPMcore PROPERTIES
|
||||
PURPOSE "For partitioning service"
|
||||
)
|
||||
|
||||
if ( KPMcore_FOUND )
|
||||
find_package( Qt5 REQUIRED DBus ) # Needed for KPMCore
|
||||
find_package( KF5 REQUIRED I18n WidgetsAddons ) # Needed for KPMCore
|
||||
|
||||
if( KPMcore_VERSION VERSION_GREATER "3.3.70" AND KPMcore_VERSION VERSION_LESS "4.0" )
|
||||
message( FATAL_ERROR "KPMCore beta versions are not supported" )
|
||||
endif()
|
||||
|
||||
include_directories( ${KPMCORE_INCLUDE_DIR} )
|
||||
list( APPEND libSources
|
||||
partition/PartitionIterator.cpp
|
||||
)
|
||||
list( APPEND OPTIONAL_PRIVATE_LIBRARIES kpmcore )
|
||||
endif()
|
||||
|
||||
### LIBRARY
|
||||
#
|
||||
#
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
*
|
||||
* Copyright 2014, Aurélien Gâteau <agateau@kde.org>
|
||||
* Copyright 2015, Teo Mrnjavac <teo@kde.org>
|
||||
* Copyright 2017, Adriaan de Groot <groot@kde.org>
|
||||
* Copyright 2017, 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
|
||||
|
@ -25,21 +25,27 @@
|
|||
#include <kpmcore/core/partition.h>
|
||||
#include <kpmcore/core/partitiontable.h>
|
||||
|
||||
namespace CalamaresUtils
|
||||
{
|
||||
namespace Partition
|
||||
{
|
||||
|
||||
using Partition = ::Partition;
|
||||
|
||||
PartitionIterator::PartitionIterator( PartitionTable* table )
|
||||
: m_table( table )
|
||||
{}
|
||||
|
||||
Partition*
|
||||
PartitionIterator::operator*() const
|
||||
{
|
||||
return m_current;
|
||||
}
|
||||
|
||||
Partition* PartitionIterator::operator*() const { return m_current; }
|
||||
|
||||
void
|
||||
PartitionIterator::operator++()
|
||||
{
|
||||
if ( !m_current )
|
||||
{
|
||||
return;
|
||||
}
|
||||
if ( m_current->hasChildren() )
|
||||
{
|
||||
// Go to the first child
|
||||
|
@ -78,18 +84,21 @@ PartitionIterator::operator==( const PartitionIterator& other ) const
|
|||
bool
|
||||
PartitionIterator::operator!=( const PartitionIterator& other ) const
|
||||
{
|
||||
return ! ( *this == other );
|
||||
return !( *this == other );
|
||||
}
|
||||
|
||||
PartitionIterator
|
||||
PartitionIterator::begin( Device* device )
|
||||
{
|
||||
if ( !device )
|
||||
{
|
||||
return PartitionIterator( nullptr );
|
||||
Q_ASSERT(device);
|
||||
}
|
||||
PartitionTable* table = device->partitionTable();
|
||||
if ( !table )
|
||||
{
|
||||
return PartitionIterator( nullptr );
|
||||
}
|
||||
return PartitionIterator::begin( table );
|
||||
}
|
||||
|
||||
|
@ -101,7 +110,9 @@ PartitionIterator::begin( PartitionTable* table )
|
|||
// Does not usually happen, but it did happen on a tiny (10MiB) disk with an MBR
|
||||
// partition table.
|
||||
if ( children.isEmpty() )
|
||||
{
|
||||
return it;
|
||||
}
|
||||
it.m_current = children.first();
|
||||
return it;
|
||||
}
|
||||
|
@ -110,10 +121,14 @@ PartitionIterator
|
|||
PartitionIterator::end( Device* device )
|
||||
{
|
||||
if ( !device )
|
||||
{
|
||||
return PartitionIterator( nullptr );
|
||||
}
|
||||
PartitionTable* table = device->partitionTable();
|
||||
if ( !table )
|
||||
{
|
||||
return PartitionIterator( nullptr );
|
||||
}
|
||||
|
||||
return PartitionIterator::end( table );
|
||||
}
|
||||
|
@ -123,3 +138,6 @@ PartitionIterator::end( PartitionTable* table )
|
|||
{
|
||||
return PartitionIterator( table );
|
||||
}
|
||||
|
||||
} // namespace Partition
|
||||
} // namespace CalamaresUtils
|
|
@ -2,6 +2,7 @@
|
|||
*
|
||||
* Copyright 2014, Aurélien Gâteau <agateau@kde.org>
|
||||
* Copyright 2015, 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
|
||||
|
@ -17,20 +18,34 @@
|
|||
* along with Calamares. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef PARTITIONITERATOR_H
|
||||
#define PARTITIONITERATOR_H
|
||||
#ifndef PARTITION_PARTITIONITERATOR_H
|
||||
#define PARTITION_PARTITIONITERATOR_H
|
||||
|
||||
class Device;
|
||||
class Partition;
|
||||
class PartitionTable;
|
||||
|
||||
/**
|
||||
namespace CalamaresUtils
|
||||
{
|
||||
namespace Partition
|
||||
{
|
||||
|
||||
/** @brief Iterator over KPMCore partitions
|
||||
*
|
||||
* A forward-only iterator to go through the partitions of a device,
|
||||
* independently of whether they are primary, logical or extended.
|
||||
*
|
||||
* An iterator can be created from a device (then it refers to the
|
||||
* partition table of that device) or a partition table. The
|
||||
* partition table must remain valid throughout iteration.
|
||||
*
|
||||
* A nullptr is valid, for an empty iterator.
|
||||
*/
|
||||
class PartitionIterator
|
||||
{
|
||||
public:
|
||||
using Partition = ::Partition;
|
||||
|
||||
Partition* operator*() const;
|
||||
|
||||
void operator++();
|
||||
|
@ -50,4 +65,7 @@ private:
|
|||
Partition* m_current = nullptr;
|
||||
};
|
||||
|
||||
#endif /* PARTITIONITERATOR_H */
|
||||
} // namespace Partition
|
||||
} // namespace CalamaresUtils
|
||||
|
||||
#endif // PARTITION_PARTITIONITERATOR_H
|
|
@ -21,7 +21,6 @@ if ( KPMcore_FOUND )
|
|||
EXPORT_MACRO PLUGINDLLEXPORT_PRO
|
||||
SOURCES
|
||||
ResizeFSJob.cpp
|
||||
${PROJECT_SOURCE_DIR}/src/modules/partition/core/PartitionIterator.cpp
|
||||
LINK_PRIVATE_LIBRARIES
|
||||
kpmcore
|
||||
calamares
|
||||
|
|
|
@ -48,7 +48,6 @@ if ( KPMcore_FOUND )
|
|||
core/PartitionActions.cpp
|
||||
core/PartitionCoreModule.cpp
|
||||
core/PartitionInfo.cpp
|
||||
core/PartitionIterator.cpp
|
||||
core/PartitionLayout.cpp
|
||||
core/PartitionModel.cpp
|
||||
core/PartUtils.cpp
|
||||
|
|
|
@ -5,7 +5,6 @@ set( PartitionModule_SOURCE_DIR .. )
|
|||
set( partitionjobtests_SRCS
|
||||
${PartitionModule_SOURCE_DIR}/core/KPMHelpers.cpp
|
||||
${PartitionModule_SOURCE_DIR}/core/PartitionInfo.cpp
|
||||
${PartitionModule_SOURCE_DIR}/core/PartitionIterator.cpp
|
||||
${PartitionModule_SOURCE_DIR}/jobs/CreatePartitionJob.cpp
|
||||
${PartitionModule_SOURCE_DIR}/jobs/CreatePartitionTableJob.cpp
|
||||
${PartitionModule_SOURCE_DIR}/jobs/DeletePartitionJob.cpp
|
||||
|
|
Loading…
Add table
Reference in a new issue