From f3f9bfc2a3c59db072ea248703084dfcfc8a0ce1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20G=C3=A2teau?= Date: Fri, 4 Jul 2014 17:33:26 +0200 Subject: [PATCH] Introduce PartitionInfo, to store Calamares-specifc info for a partition --- src/modules/partition/CMakeLists.txt | 2 + src/modules/partition/PartitionCoreModule.cpp | 10 ++++- src/modules/partition/PartitionCoreModule.h | 2 + src/modules/partition/PartitionInfo.cpp | 22 ++++++++++ src/modules/partition/PartitionInfo.h | 40 +++++++++++++++++++ src/modules/partition/PartitionModel.cpp | 15 +++---- src/modules/partition/PartitionModel.h | 10 ++++- 7 files changed, 88 insertions(+), 13 deletions(-) create mode 100644 src/modules/partition/PartitionInfo.cpp create mode 100644 src/modules/partition/PartitionInfo.h diff --git a/src/modules/partition/CMakeLists.txt b/src/modules/partition/CMakeLists.txt index 9f81eb20a..81c36b441 100644 --- a/src/modules/partition/CMakeLists.txt +++ b/src/modules/partition/CMakeLists.txt @@ -15,6 +15,7 @@ calamares_add_plugin( partition DeletePartitionJob.cpp DeviceModel.cpp PartitionCoreModule.cpp + PartitionInfo.cpp PartitionModel.cpp PartitionPage.cpp PartitionViewStep.cpp @@ -36,6 +37,7 @@ set( partview_SRCS DeletePartitionJob.cpp DeviceModel.cpp PartitionCoreModule.cpp + PartitionInfo.cpp PartitionModel.cpp PartitionPage.cpp PMUtils.cpp diff --git a/src/modules/partition/PartitionCoreModule.cpp b/src/modules/partition/PartitionCoreModule.cpp index de49cec6d..71d464a62 100644 --- a/src/modules/partition/PartitionCoreModule.cpp +++ b/src/modules/partition/PartitionCoreModule.cpp @@ -38,7 +38,6 @@ PartitionCoreModule::DeviceInfo::DeviceInfo( Device* dev ) : device( dev ) , partitionModel( new PartitionModel ) { - partitionModel->init( dev ); } PartitionCoreModule::DeviceInfo::~DeviceInfo() @@ -62,13 +61,16 @@ PartitionCoreModule::PartitionCoreModule( QObject* parent ) m_deviceModel->init( lst ); for ( auto device : lst ) { - m_devices << new DeviceInfo( device ); + DeviceInfo* info = new DeviceInfo( device ); + info->partitionModel->init( device, &m_infoForPartitionHash ); + m_devices << info; } } PartitionCoreModule::~PartitionCoreModule() { + qDeleteAll( m_infoForPartitionHash ); qDeleteAll( m_devices ); } @@ -96,6 +98,10 @@ PartitionCoreModule::createPartition( CreatePartitionJob* job ) { DeviceInfo* info = deviceInfoForDevice( job->device() ); Q_ASSERT( info ); + Q_ASSERT( !m_infoForPartitionHash.contains( job->partition() ) ); + PartitionInfo* partitionInfo = new PartitionInfo( job->partition() ); + partitionInfo->mountPoint = job->mountPoint(); + m_infoForPartitionHash[ job->partition() ] = partitionInfo; job->updatePreview(); info->partitionModel->reload(); m_jobs << Calamares::job_ptr( job ); diff --git a/src/modules/partition/PartitionCoreModule.h b/src/modules/partition/PartitionCoreModule.h index d4ead93cb..b72fcf56a 100644 --- a/src/modules/partition/PartitionCoreModule.h +++ b/src/modules/partition/PartitionCoreModule.h @@ -19,6 +19,7 @@ #ifndef PARTITIONCOREMODULE_H #define PARTITIONCOREMODULE_H +#include #include // CalaPM @@ -66,6 +67,7 @@ private: PartitionModel* partitionModel; }; QList< DeviceInfo* > m_devices; + InfoForPartitionHash m_infoForPartitionHash; DeviceModel* m_deviceModel; QList< Calamares::job_ptr > m_jobs; diff --git a/src/modules/partition/PartitionInfo.cpp b/src/modules/partition/PartitionInfo.cpp new file mode 100644 index 000000000..41de83468 --- /dev/null +++ b/src/modules/partition/PartitionInfo.cpp @@ -0,0 +1,22 @@ +/* === 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 + +PartitionInfo::PartitionInfo( Partition* p ) +: partition( p ) +{} diff --git a/src/modules/partition/PartitionInfo.h b/src/modules/partition/PartitionInfo.h new file mode 100644 index 000000000..de33f2267 --- /dev/null +++ b/src/modules/partition/PartitionInfo.h @@ -0,0 +1,40 @@ +/* === 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 PARTITIONINFO_H +#define PARTITIONINFO_H + +#include +#include + +class Partition; + +/** + * Stores Calamares-specific info about a partition. + * Does not own anything. + */ +struct PartitionInfo +{ + explicit PartitionInfo( Partition* ); + Partition* partition; + QString mountPoint; + bool format = false; +}; + +typedef QHash< Partition*, PartitionInfo* > InfoForPartitionHash; + +#endif /* PARTITIONINFO_H */ diff --git a/src/modules/partition/PartitionModel.cpp b/src/modules/partition/PartitionModel.cpp index fe6923473..b72d9d14a 100644 --- a/src/modules/partition/PartitionModel.cpp +++ b/src/modules/partition/PartitionModel.cpp @@ -17,6 +17,7 @@ */ #include +#include #include #include @@ -35,9 +36,10 @@ PartitionModel::PartitionModel( QObject* parent ) } void -PartitionModel::init( Device* device ) +PartitionModel::init( Device* device, InfoForPartitionHash* infoForPartitionHash ) { m_device = device; + m_infoForPartitionHash = infoForPartitionHash; reload(); } @@ -104,15 +106,8 @@ PartitionModel::data( const QModelIndex& index, int role ) const } if ( col == MountPointColumn ) { - QString mountPoint = partition->mountPoint(); - if ( mountPoint.isEmpty() || mountPoint == "none" ) - { - return QString(); - } - else - { - return mountPoint; - } + PartitionInfo* info = m_infoForPartitionHash->value( partition ); + return info ? info->mountPoint : QString(); } if ( col == SizeColumn ) { diff --git a/src/modules/partition/PartitionModel.h b/src/modules/partition/PartitionModel.h index 494efe733..50e9646db 100644 --- a/src/modules/partition/PartitionModel.h +++ b/src/modules/partition/PartitionModel.h @@ -18,6 +18,9 @@ #ifndef PARTITIONMODEL_H #define PARTITIONMODEL_H +#include + +// Qt #include class Device; @@ -37,7 +40,11 @@ public: }; PartitionModel( QObject* parent = 0 ); - void init( Device* device ); + /** + * device and infoForPartitions must remain alive for the life of + * PartitionModel + */ + void init( Device* device, InfoForPartitionHash* infoForPartitionHash ); int columnCount( const QModelIndex& parent = QModelIndex() ) const override; int rowCount( const QModelIndex& parent = QModelIndex() ) const override; @@ -57,6 +64,7 @@ public: private: Device* m_device; + InfoForPartitionHash* m_infoForPartitionHash; QList< Partition* > m_partitionList; void fillPartitionList( PartitionNode* parent );