From 4d2354fb569df47346b4e0bc2c066fcdf201ddaf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20G=C3=A2teau?= Date: Mon, 30 Jun 2014 13:37:46 +0200 Subject: [PATCH] Introduce PartitionCoreModule Owner of the Qt models and PM devices --- src/modules/partition/CMakeLists.txt | 1 + src/modules/partition/DeviceModel.cpp | 2 - src/modules/partition/DeviceModel.h | 4 +- src/modules/partition/PartitionCoreModule.cpp | 42 ++++++++++++++++++ src/modules/partition/PartitionCoreModule.h | 43 +++++++++++++++++++ src/modules/partition/PartitionPage.cpp | 15 ++----- src/modules/partition/PartitionPage.h | 4 +- 7 files changed, 93 insertions(+), 18 deletions(-) create mode 100644 src/modules/partition/PartitionCoreModule.cpp create mode 100644 src/modules/partition/PartitionCoreModule.h diff --git a/src/modules/partition/CMakeLists.txt b/src/modules/partition/CMakeLists.txt index 2517dc5a3..d57550c04 100644 --- a/src/modules/partition/CMakeLists.txt +++ b/src/modules/partition/CMakeLists.txt @@ -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 diff --git a/src/modules/partition/DeviceModel.cpp b/src/modules/partition/DeviceModel.cpp index 58cc3e98a..eafc722de 100644 --- a/src/modules/partition/DeviceModel.cpp +++ b/src/modules/partition/DeviceModel.cpp @@ -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 diff --git a/src/modules/partition/DeviceModel.h b/src/modules/partition/DeviceModel.h index 938ef3f80..fb4ced9c2 100644 --- a/src/modules/partition/DeviceModel.h +++ b/src/modules/partition/DeviceModel.h @@ -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 ); diff --git a/src/modules/partition/PartitionCoreModule.cpp b/src/modules/partition/PartitionCoreModule.cpp new file mode 100644 index 000000000..b8073e329 --- /dev/null +++ b/src/modules/partition/PartitionCoreModule.cpp @@ -0,0 +1,42 @@ +/* === 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 + +// CalaPM +#include +#include +#include + +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; +} diff --git a/src/modules/partition/PartitionCoreModule.h b/src/modules/partition/PartitionCoreModule.h new file mode 100644 index 000000000..61895a582 --- /dev/null +++ b/src/modules/partition/PartitionCoreModule.h @@ -0,0 +1,43 @@ +/* === 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 PARTITIONCOREMODULE_H +#define PARTITIONCOREMODULE_H + +#include +#include + +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 */ diff --git a/src/modules/partition/PartitionPage.cpp b/src/modules/partition/PartitionPage.cpp index af1150756..1ed4fb9fb 100644 --- a/src/modules/partition/PartitionPage.cpp +++ b/src/modules/partition/PartitionPage.cpp @@ -20,14 +20,10 @@ // Local #include +#include #include #include -// CalaPM -#include -#include -#include - // Qt #include #include @@ -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 ) diff --git a/src/modules/partition/PartitionPage.h b/src/modules/partition/PartitionPage.h index 8b4949e7d..a3d69f8cd 100644 --- a/src/modules/partition/PartitionPage.h +++ b/src/modules/partition/PartitionPage.h @@ -23,7 +23,7 @@ #include -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