From c8129898fce9333901f8e45d7c09f668a51c74de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20G=C3=A2teau?= Date: Tue, 22 Jul 2014 17:32:26 +0200 Subject: [PATCH] Introduce FillGlobalStorageJob --- src/modules/partition/CMakeLists.txt | 1 + .../partition/FillGlobalStorageJob.cpp | 65 +++++++++++++++++++ src/modules/partition/FillGlobalStorageJob.h | 47 ++++++++++++++ src/modules/partition/PartitionCoreModule.cpp | 6 ++ 4 files changed, 119 insertions(+) create mode 100644 src/modules/partition/FillGlobalStorageJob.cpp create mode 100644 src/modules/partition/FillGlobalStorageJob.h diff --git a/src/modules/partition/CMakeLists.txt b/src/modules/partition/CMakeLists.txt index 47574fb16..6ebe64cc8 100644 --- a/src/modules/partition/CMakeLists.txt +++ b/src/modules/partition/CMakeLists.txt @@ -28,6 +28,7 @@ calamares_add_plugin( partition DeletePartitionJob.cpp DeviceModel.cpp EditExistingPartitionDialog.cpp + FillGlobalStorageJob.cpp FormatPartitionJob.cpp PartitionCoreModule.cpp PartitionInfo.cpp diff --git a/src/modules/partition/FillGlobalStorageJob.cpp b/src/modules/partition/FillGlobalStorageJob.cpp new file mode 100644 index 000000000..d16b33338 --- /dev/null +++ b/src/modules/partition/FillGlobalStorageJob.cpp @@ -0,0 +1,65 @@ +/* === This file is part of Calamares - === + * + * Copyright 2014, Aurélien Gâteau + * + * 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 . + */ + +#include + +#include +#include +#include +#include + +// CalaPM +#include +#include +#include + +FillGlobalStorageJob::FillGlobalStorageJob( QList< Device* > devices ) + : m_devices( devices ) +{ +} + +QString +FillGlobalStorageJob::prettyName() const +{ + return tr( "Set partition information" ); +} + +Calamares::JobResult +FillGlobalStorageJob::exec() +{ + QVariantList lst; + for( auto device : m_devices ) + for( auto it = PartitionIterator::begin( device ); it != PartitionIterator::end( device ); ++it) + { + QVariant var = mapForPartition( *it ); + if ( var.isValid() ) + lst << var; + } + Calamares::JobQueue::instance()->globalStorage()->insert( "partitions", lst ); + return Calamares::JobResult::ok(); +} + +QVariant +FillGlobalStorageJob::mapForPartition( Partition* partition ) +{ + QVariantMap map; + map[ "device" ] = partition->partitionPath(); + map[ "mountPoint" ] = PartitionInfo::mountPoint( partition ); + map[ "fs" ] = partition->fileSystem().name(); + return map; +} diff --git a/src/modules/partition/FillGlobalStorageJob.h b/src/modules/partition/FillGlobalStorageJob.h new file mode 100644 index 000000000..3eb1a8703 --- /dev/null +++ b/src/modules/partition/FillGlobalStorageJob.h @@ -0,0 +1,47 @@ +/* === This file is part of Calamares - === + * + * Copyright 2014, Aurélien Gâteau + * + * 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 . + */ + +#ifndef FILLGLOBALSTORAGEJOB_H +#define FILLGLOBALSTORAGEJOB_H + +#include + +// Qt +#include + +class Device; +class Partition; + +/** + * Fills the "partitions" key of GlobalStorage. Doing it after partitioning + * makes it possible to access information such as the partition UUID. + */ +class FillGlobalStorageJob : public Calamares::Job +{ + Q_OBJECT +public: + FillGlobalStorageJob( QList< Device* > devices ); + QString prettyName() const override; + Calamares::JobResult exec() override; +private: + QList< Device* > m_devices; + + QVariant mapForPartition( Partition* ); +}; + +#endif /* FILLGLOBALSTORAGEJOB_H */ diff --git a/src/modules/partition/PartitionCoreModule.cpp b/src/modules/partition/PartitionCoreModule.cpp index 4e7d34b62..bcd20e5b2 100644 --- a/src/modules/partition/PartitionCoreModule.cpp +++ b/src/modules/partition/PartitionCoreModule.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -218,8 +219,13 @@ PartitionCoreModule::jobs() const dumpQueue(); QList< Calamares::job_ptr > lst; + QList< Device* > devices; for ( auto info : m_deviceInfos ) + { lst << info->jobs; + devices << info->device.data(); + } + lst << Calamares::job_ptr( new FillGlobalStorageJob( devices ) ); return lst; }