Introduce PartitionCoreModule

Owner of the Qt models and PM devices
This commit is contained in:
Aurélien Gâteau 2014-06-30 13:37:46 +02:00
parent dafd542245
commit 4d2354fb56
7 changed files with 93 additions and 18 deletions

View File

@ -24,6 +24,7 @@ calamares_add_plugin( partition
# Temporary, until views are integrated
set( partview_SRCS
DeviceModel.cpp
PartitionCoreModule.cpp
PartitionModel.cpp
PartitionPage.cpp
${calamares_SOURCE_DIR}/viewpages/AbstractPage.cpp

View File

@ -30,7 +30,6 @@ DeviceModel::DeviceInfo::DeviceInfo( Device* dev )
DeviceModel::DeviceInfo::~DeviceInfo()
{
delete device;
delete partitionModel;
}
@ -41,7 +40,6 @@ DeviceModel::DeviceModel( QObject* parent )
DeviceModel::~DeviceModel()
{
qDeleteAll( m_devices );
}
void

View File

@ -32,8 +32,8 @@ public:
~DeviceModel();
/**
* Init the model with the list of devices.
* Takes ownership of the devices.
* Init the model with the list of devices. Does *not* take ownership of the
* devices.
*/
void init( const QList< Device* >& devices );

View File

@ -0,0 +1,42 @@
/* === 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 <PartitionCoreModule.h>
// CalaPM
#include <CalaPM.h>
#include <backend/corebackend.h>
#include <backend/corebackendmanager.h>
PartitionCoreModule::PartitionCoreModule( QObject* parent )
: QObject( parent )
{
// FIXME: Should be done at startup
if ( !CalaPM::init() )
{
qFatal( "Failed to init CalaPM" );
}
CoreBackend* backend = CoreBackendManager::self()->backend();
m_devices = backend->scanDevices();
}
QList< Device* >
PartitionCoreModule::devices() const
{
return m_devices;
}

View File

@ -0,0 +1,43 @@
/* === 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 PARTITIONCOREMODULE_H
#define PARTITIONCOREMODULE_H
#include <QList>
#include <QObject>
class Device;
/**
* Owns the Qt models and the PM devices
*/
class PartitionCoreModule : public QObject
{
public:
PartitionCoreModule( QObject* parent = nullptr );
QList< Device* > devices() const;
private:
QList< Device* > m_devices;
void listDevices();
};
#endif /* PARTITIONCOREMODULE_H */

View File

@ -20,14 +20,10 @@
// Local
#include <DeviceModel.h>
#include <PartitionCoreModule.h>
#include <PartitionModel.h>
#include <ui_PartitionPage.h>
// CalaPM
#include <CalaPM.h>
#include <backend/corebackend.h>
#include <backend/corebackendmanager.h>
// Qt
#include <QDebug>
#include <QItemSelectionModel>
@ -35,18 +31,13 @@
PartitionPage::PartitionPage( QWidget* parent )
: Calamares::AbstractPage( parent )
, m_ui( new Ui_PartitionPage )
, m_core( new PartitionCoreModule( this ) )
, m_deviceModel( new DeviceModel( this ) )
{
// FIXME: Should be done at startup
if ( !CalaPM::init() )
{
qFatal( "Failed to init CalaPM" );
}
m_backend = CoreBackendManager::self()->backend();
m_ui->setupUi( this );
m_ui->deviceListView->setModel( m_deviceModel );
m_deviceModel->init( m_backend->scanDevices() );
m_deviceModel->init( m_core->devices() );
connect( m_ui->deviceListView->selectionModel(), &QItemSelectionModel::currentChanged,
[ this ]( const QModelIndex& index, const QModelIndex& oldIndex )

View File

@ -23,7 +23,7 @@
#include <QScopedPointer>
class CoreBackend;
class PartitionCoreModule;
class Ui_PartitionPage;
class DeviceModel;
@ -41,8 +41,8 @@ public Q_SLOTS:
private:
QScopedPointer< Ui_PartitionPage > m_ui;
PartitionCoreModule* m_core;
DeviceModel* m_deviceModel;
CoreBackend* m_backend;
};
#endif // PARTITIONPAGE_H