Introduce PartitionInfo, to store Calamares-specifc info for a partition

main
Aurélien Gâteau 11 years ago
parent 1247077ccc
commit f3f9bfc2a3

@ -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

@ -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 );

@ -19,6 +19,7 @@
#ifndef PARTITIONCOREMODULE_H
#define PARTITIONCOREMODULE_H
#include <PartitionInfo.h>
#include <Typedefs.h>
// CalaPM
@ -66,6 +67,7 @@ private:
PartitionModel* partitionModel;
};
QList< DeviceInfo* > m_devices;
InfoForPartitionHash m_infoForPartitionHash;
DeviceModel* m_deviceModel;
QList< Calamares::job_ptr > m_jobs;

@ -0,0 +1,22 @@
/* === This file is part of Calamares - <http://github.com/calamares> ===
*
* Copyright 2014, Aurélien Gâteau <agateau@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 <PartitionInfo.h>
PartitionInfo::PartitionInfo( Partition* p )
: partition( p )
{}

@ -0,0 +1,40 @@
/* === This file is part of Calamares - <http://github.com/calamares> ===
*
* Copyright 2014, Aurélien Gâteau <agateau@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 PARTITIONINFO_H
#define PARTITIONINFO_H
#include <QHash>
#include <QString>
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 */

@ -17,6 +17,7 @@
*/
#include <PartitionModel.h>
#include <PartitionInfo.h>
#include <PMUtils.h>
#include <utils/Logger.h>
@ -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 )
{

@ -18,6 +18,9 @@
#ifndef PARTITIONMODEL_H
#define PARTITIONMODEL_H
#include <PartitionInfo.h>
// Qt
#include <QAbstractListModel>
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 );

Loading…
Cancel
Save