diff --git a/src/modules/partition/core/BootLoaderModel.cpp b/src/modules/partition/core/BootLoaderModel.cpp index f0661d8b0..16c6ce3c8 100644 --- a/src/modules/partition/core/BootLoaderModel.cpp +++ b/src/modules/partition/core/BootLoaderModel.cpp @@ -2,6 +2,7 @@ * * Copyright 2014, Aurélien Gâteau * Copyright 2015, Teo Mrnjavac + * Copyright 2019, Adriaan de Groot * * Calamares is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -46,9 +47,15 @@ BootLoaderModel::~BootLoaderModel() void BootLoaderModel::init( const QList< Device* >& devices ) { + beginResetModel(); + blockSignals( true ); + m_devices = devices; clear(); createMbrItems(); + + blockSignals( false ); + endResetModel(); } void @@ -69,6 +76,16 @@ BootLoaderModel::update() { beginResetModel(); blockSignals( true ); + updateInternal(); + blockSignals( false ); + endResetModel(); +} + + +void +BootLoaderModel::updateInternal() +{ + QMutexLocker lock(&m_lock); clear(); createMbrItems(); @@ -113,14 +130,13 @@ BootLoaderModel::update() createBootLoaderItem( tr( "Do not install a boot loader" ), QString(), false ) ); } - blockSignals( false ); - endResetModel(); } QVariant BootLoaderModel::data( const QModelIndex& index, int role ) const { + QMutexLocker lock(&m_lock); if ( role == Qt::DisplayRole ) { QString displayRole = QStandardItemModel::data( index, Qt::DisplayRole ).toString(); diff --git a/src/modules/partition/core/BootLoaderModel.h b/src/modules/partition/core/BootLoaderModel.h index 27be18687..fbbb9deb2 100644 --- a/src/modules/partition/core/BootLoaderModel.h +++ b/src/modules/partition/core/BootLoaderModel.h @@ -2,6 +2,7 @@ * * Copyright 2014, Aurélien Gâteau * Copyright 2015, Teo Mrnjavac + * Copyright 2019, Adriaan de Groot * * Calamares is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -19,8 +20,9 @@ #ifndef BOOTLOADERMODEL_H #define BOOTLOADERMODEL_H -#include #include +#include +#include class Device; @@ -51,10 +53,14 @@ public: QVariant data( const QModelIndex& index, int role = Qt::DisplayRole ) const override; + using DeviceList = QList< Device* >; + private: - QList< Device* > m_devices; + DeviceList m_devices; + mutable QMutex m_lock; void createMbrItems(); + void updateInternal(); }; #endif /* BOOTLOADERMODEL_H */ diff --git a/src/modules/partition/core/DeviceList.cpp b/src/modules/partition/core/DeviceList.cpp index 2beaa34dc..680d30dd6 100644 --- a/src/modules/partition/core/DeviceList.cpp +++ b/src/modules/partition/core/DeviceList.cpp @@ -1,7 +1,7 @@ /* === This file is part of Calamares - === * * Copyright 2015-2016, Teo Mrnjavac - * Copyright 2018, Adriaan de Groot + * Copyright 2018-2019, Adriaan de Groot * * Calamares is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/modules/partition/core/DeviceModel.cpp b/src/modules/partition/core/DeviceModel.cpp index e1d63f26c..c76c39090 100644 --- a/src/modules/partition/core/DeviceModel.cpp +++ b/src/modules/partition/core/DeviceModel.cpp @@ -2,6 +2,7 @@ * * Copyright 2014, Aurélien Gâteau * Copyright 2014, Teo Mrnjavac + * Copyright 2019, Adriaan de Groot * * Calamares is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -35,6 +36,15 @@ // STL #include +static void +sortDevices( DeviceModel::DeviceList& l ) +{ + std::sort( l.begin(), l.end(), []( const Device* dev1, const Device* dev2 ) + { + return dev1->deviceNode() < dev2->deviceNode(); + } ); +} + DeviceModel::DeviceModel( QObject* parent ) : QAbstractListModel( parent ) { @@ -45,14 +55,11 @@ DeviceModel::~DeviceModel() } void -DeviceModel::init( const QList< Device* >& devices ) +DeviceModel::init( const DeviceList& devices ) { beginResetModel(); m_devices = devices; - std::sort( m_devices.begin(), m_devices.end(), []( const Device* dev1, const Device* dev2 ) - { - return dev1->deviceNode() < dev2->deviceNode(); - } ); + sortDevices( m_devices ); endResetModel(); } @@ -138,13 +145,8 @@ void DeviceModel::addDevice( Device *device ) { beginResetModel(); - m_devices << device; - std::sort( m_devices.begin(), m_devices.end(), []( const Device* dev1, const Device* dev2 ) - { - return dev1->deviceNode() < dev2->deviceNode(); - } ); - + sortDevices( m_devices ); endResetModel(); } @@ -152,12 +154,7 @@ void DeviceModel::removeDevice( Device *device ) { beginResetModel(); - m_devices.removeAll( device ); - std::sort( m_devices.begin(), m_devices.end(), []( const Device* dev1, const Device* dev2 ) - { - return dev1->deviceNode() < dev2->deviceNode(); - } ); - + sortDevices( m_devices ); endResetModel(); } diff --git a/src/modules/partition/core/DeviceModel.h b/src/modules/partition/core/DeviceModel.h index 2e2f99342..f3e158bbf 100644 --- a/src/modules/partition/core/DeviceModel.h +++ b/src/modules/partition/core/DeviceModel.h @@ -1,7 +1,7 @@ /* === This file is part of Calamares - === * * Copyright 2014, Aurélien Gâteau - * Copyright 2017, Adriaan de Groot + * Copyright 2017, 2019, Adriaan de Groot * * Calamares is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -36,11 +36,13 @@ public: DeviceModel( QObject* parent = nullptr ); ~DeviceModel() override; + using DeviceList = QList< Device* >; + /** * Init the model with the list of devices. Does *not* take ownership of the * devices. */ - void init( const QList< Device* >& devices ); + void init( const DeviceList& devices ); int rowCount( const QModelIndex& parent = QModelIndex() ) const override; QVariant data( const QModelIndex& index, int role = Qt::DisplayRole ) const override; @@ -54,7 +56,7 @@ public: void removeDevice( Device* device ); private: - QList< Device* > m_devices; + DeviceList m_devices; }; #endif /* DEVICEMODEL_H */ diff --git a/src/modules/partition/core/KPMHelpers.cpp b/src/modules/partition/core/KPMHelpers.cpp index 3c0a55987..0265a17e5 100644 --- a/src/modules/partition/core/KPMHelpers.cpp +++ b/src/modules/partition/core/KPMHelpers.cpp @@ -2,7 +2,7 @@ * * Copyright 2014, Aurélien Gâteau * Copyright 2015-2016, Teo Mrnjavac - * Copyright 2018, Adriaan de Groot + * Copyright 2018-2019 Adriaan de Groot * * Calamares is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/modules/partition/core/KPMHelpers.h b/src/modules/partition/core/KPMHelpers.h index b1c3832fc..bca69d1f6 100644 --- a/src/modules/partition/core/KPMHelpers.h +++ b/src/modules/partition/core/KPMHelpers.h @@ -2,6 +2,7 @@ * * Copyright 2014, Aurélien Gâteau * Copyright 2015-2016, Teo Mrnjavac + * Copyright 2019, Adriaan de Groot * * Calamares is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/modules/partition/core/PartUtils.cpp b/src/modules/partition/core/PartUtils.cpp index 75b49701d..251fc62db 100644 --- a/src/modules/partition/core/PartUtils.cpp +++ b/src/modules/partition/core/PartUtils.cpp @@ -1,7 +1,7 @@ /* === This file is part of Calamares - === * * Copyright 2015-2016, Teo Mrnjavac - * Copyright 2018, Adriaan de Groot + * Copyright 2018-2019 Adriaan de Groot * Copyright 2019, Collabora Ltd * * Calamares is free software: you can redistribute it and/or modify diff --git a/src/modules/partition/core/PartUtils.h b/src/modules/partition/core/PartUtils.h index e6a5209ed..ce1ef079f 100644 --- a/src/modules/partition/core/PartUtils.h +++ b/src/modules/partition/core/PartUtils.h @@ -1,7 +1,7 @@ /* === This file is part of Calamares - === * * Copyright 2015-2016, Teo Mrnjavac - * Copyright 2018, Adriaan de Groot + * Copyright 2018-2019 Adriaan de Groot * Copyright 2019, Collabora Ltd * * Calamares is free software: you can redistribute it and/or modify diff --git a/src/modules/partition/core/PartitionActions.cpp b/src/modules/partition/core/PartitionActions.cpp index 0bc0d1860..761b8e4e3 100644 --- a/src/modules/partition/core/PartitionActions.cpp +++ b/src/modules/partition/core/PartitionActions.cpp @@ -1,7 +1,7 @@ /* === This file is part of Calamares - === * * Copyright 2014-2017, Teo Mrnjavac - * Copyright 2017-2018, Adriaan de Groot + * Copyright 2017-2019, Adriaan de Groot * Copyright 2019, Collabora Ltd * * Calamares is free software: you can redistribute it and/or modify diff --git a/src/modules/partition/core/PartitionCoreModule.cpp b/src/modules/partition/core/PartitionCoreModule.cpp index f78419259..e042b23e2 100644 --- a/src/modules/partition/core/PartitionCoreModule.cpp +++ b/src/modules/partition/core/PartitionCoreModule.cpp @@ -2,7 +2,7 @@ * * Copyright 2014, Aurélien Gâteau * Copyright 2014-2015, Teo Mrnjavac - * Copyright 2017-2018, Adriaan de Groot + * Copyright 2017-2019, Adriaan de Groot * Copyright 2018, Caio Carvalho * Copyright 2019, Collabora Ltd * diff --git a/src/modules/partition/core/PartitionCoreModule.h b/src/modules/partition/core/PartitionCoreModule.h index dc0c5eff5..aebf9835f 100644 --- a/src/modules/partition/core/PartitionCoreModule.h +++ b/src/modules/partition/core/PartitionCoreModule.h @@ -2,6 +2,7 @@ * * Copyright 2014, Aurélien Gâteau * Copyright 2014-2016, Teo Mrnjavac + * Copyright 2019, Adriaan de Groot * * Calamares is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/modules/partition/core/PartitionModel.cpp b/src/modules/partition/core/PartitionModel.cpp index 0515184b5..8b13ab0a0 100644 --- a/src/modules/partition/core/PartitionModel.cpp +++ b/src/modules/partition/core/PartitionModel.cpp @@ -1,7 +1,7 @@ /* === This file is part of Calamares - === * * Copyright 2014, Aurélien Gâteau - * Copyright 2018, Adriaan de Groot + * Copyright 2018-2019, Adriaan de Groot * * Calamares is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -40,11 +40,16 @@ PartitionModel::ResetHelper::ResetHelper( PartitionModel* model ) : m_model( model ) { + m_model->m_lock.lock(); m_model->beginResetModel(); } PartitionModel::ResetHelper::~ResetHelper() { + // We need to unlock the mutex before emitting the reset signal, + // because the reset will cause clients to start looking at the + // (new) data. + m_model->m_lock.unlock(); m_model->endResetModel(); } @@ -58,6 +63,7 @@ PartitionModel::PartitionModel( QObject* parent ) void PartitionModel::init( Device* device , const OsproberEntryList& osproberEntries ) { + QMutexLocker lock(&m_lock); beginResetModel(); m_device = device; m_osproberEntries = osproberEntries; @@ -271,6 +277,7 @@ PartitionModel::headerData( int section, Qt::Orientation, int role ) const Partition* PartitionModel::partitionForIndex( const QModelIndex& index ) const { + QMutexLocker lock(&m_lock); if ( !index.isValid() ) return nullptr; return reinterpret_cast< Partition* >( index.internalPointer() ); diff --git a/src/modules/partition/core/PartitionModel.h b/src/modules/partition/core/PartitionModel.h index fa63103c9..f5289254b 100644 --- a/src/modules/partition/core/PartitionModel.h +++ b/src/modules/partition/core/PartitionModel.h @@ -1,7 +1,7 @@ /* === This file is part of Calamares - === * * Copyright 2014, Aurélien Gâteau - * Copyright 2017, Adriaan de Groot + * Copyright 2017, 2019, Adriaan de Groot * * Calamares is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -23,6 +23,7 @@ // Qt #include +#include class Device; class Partition; @@ -115,8 +116,11 @@ public: void update(); private: + friend class ResetHelper; + Device* m_device; OsproberEntryList m_osproberEntries; + mutable QMutex m_lock; }; #endif /* PARTITIONMODEL_H */ diff --git a/src/modules/partition/gui/PartitionDialogHelpers.cpp b/src/modules/partition/gui/PartitionDialogHelpers.cpp index 02d91ca4b..112d12cea 100644 --- a/src/modules/partition/gui/PartitionDialogHelpers.cpp +++ b/src/modules/partition/gui/PartitionDialogHelpers.cpp @@ -2,7 +2,7 @@ * * Copyright 2014, Aurélien Gâteau * Copyright 2016, Teo Mrnjavac - * Copyright 2018, Adriaan de Groot + * Copyright 2018-2019 Adriaan de Groot * * Calamares is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/modules/partition/gui/PartitionPage.cpp b/src/modules/partition/gui/PartitionPage.cpp index 22398bddb..3b51f1e62 100644 --- a/src/modules/partition/gui/PartitionPage.cpp +++ b/src/modules/partition/gui/PartitionPage.cpp @@ -2,7 +2,7 @@ * * Copyright 2014, Aurélien Gâteau * Copyright 2015-2016, Teo Mrnjavac - * Copyright 2018, Adriaan de Groot + * Copyright 2018-2019, Adriaan de Groot * Copyright 2018, Andrius Štikonas * Copyright 2018, Caio Jordão Carvalho * Copyright 2019, Collabora Ltd @@ -512,7 +512,8 @@ findBootloader( const QAbstractItemModel* model, const QString& path ) for ( int i = 0; i < model->rowCount(); ++i) { const auto index = model->index( i, 0, QModelIndex() ); - cDebug() << i << model->itemData( index ); + if ( !index.isValid() ) + continue; QVariant var = model->data( index, BootLoaderModel::BootLoaderPathRole ); if ( var.isValid() && var.toString() == path ) return i; diff --git a/src/modules/partition/gui/PartitionPage.h b/src/modules/partition/gui/PartitionPage.h index 9999c334d..e8a96a4cf 100644 --- a/src/modules/partition/gui/PartitionPage.h +++ b/src/modules/partition/gui/PartitionPage.h @@ -1,7 +1,7 @@ /* === This file is part of Calamares - === * * Copyright 2014, Aurélien Gâteau - * Copyright 2018, Adriaan de Groot + * Copyright 2018-2019, Adriaan de Groot * Copyright 2019, Collabora Ltd * * Calamares is free software: you can redistribute it and/or modify diff --git a/src/modules/partition/gui/PartitionViewStep.cpp b/src/modules/partition/gui/PartitionViewStep.cpp index 85e1b63aa..02d289518 100644 --- a/src/modules/partition/gui/PartitionViewStep.cpp +++ b/src/modules/partition/gui/PartitionViewStep.cpp @@ -2,7 +2,7 @@ * * Copyright 2014, Aurélien Gâteau * Copyright 2014-2017, Teo Mrnjavac - * Copyright 2018, Adriaan de Groot + * Copyright 2018-2019, Adriaan de Groot * Copyright 2019, Collabora Ltd * * Calamares is free software: you can redistribute it and/or modify @@ -60,8 +60,6 @@ #include #include -#include // For sleep(3) - PartitionViewStep::PartitionViewStep( QObject* parent ) : Calamares::ViewStep( parent ) , m_core( nullptr ) @@ -92,15 +90,16 @@ void PartitionViewStep::continueLoading() { Q_ASSERT( !m_choicePage ); - Q_ASSERT( !m_manualPartitionPage ); - - m_manualPartitionPage = new PartitionPage( m_core ); m_choicePage = new ChoicePage( m_swapChoices ); - m_choicePage->init( m_core ); - m_widget->addWidget( m_choicePage ); - m_widget->addWidget( m_manualPartitionPage ); + + // Instantiate the manual partitioning page as needed. + // + Q_ASSERT( !m_manualPartitionPage ); + // m_manualPartitionPage = new PartitionPage( m_core ); + // m_widget->addWidget( m_manualPartitionPage ); + m_widget->removeWidget( m_waitingWidget ); m_waitingWidget->deleteLater(); m_waitingWidget = nullptr; @@ -289,6 +288,12 @@ PartitionViewStep::next() { if ( m_choicePage->currentChoice() == ChoicePage::Manual ) { + if ( !m_manualPartitionPage ) + { + m_manualPartitionPage = new PartitionPage( m_core ); + m_widget->addWidget( m_manualPartitionPage ); + } + m_widget->setCurrentWidget( m_manualPartitionPage ); m_manualPartitionPage->selectDeviceByIndex( m_choicePage->lastSelectedDeviceIndex() ); if ( m_core->isDirty() ) @@ -306,6 +311,12 @@ PartitionViewStep::back() { m_widget->setCurrentWidget( m_choicePage ); m_choicePage->setLastSelectedDeviceIndex( m_manualPartitionPage->selectedDeviceIndex() ); + + if ( m_manualPartitionPage ) + { + m_manualPartitionPage->deleteLater(); + m_manualPartitionPage = nullptr; + } } } @@ -313,10 +324,10 @@ PartitionViewStep::back() bool PartitionViewStep::isNextEnabled() const { - if ( m_choicePage && m_choicePage == m_widget->currentWidget() ) + if ( m_choicePage && m_widget->currentWidget() == m_choicePage ) return m_choicePage->isNextEnabled(); - if ( m_manualPartitionPage && m_manualPartitionPage == m_widget->currentWidget() ) + if ( m_manualPartitionPage && m_widget->currentWidget() == m_manualPartitionPage ) return m_core->hasRootMountPoint(); return false; @@ -333,7 +344,7 @@ PartitionViewStep::isBackEnabled() const bool PartitionViewStep::isAtBeginning() const { - if ( m_widget->currentWidget() == m_manualPartitionPage ) + if ( m_widget->currentWidget() != m_choicePage ) return false; return true; } @@ -342,7 +353,7 @@ PartitionViewStep::isAtBeginning() const bool PartitionViewStep::isAtEnd() const { - if ( m_choicePage == m_widget->currentWidget() ) + if ( m_widget->currentWidget() == m_choicePage ) { if ( m_choicePage->currentChoice() == ChoicePage::Erase || m_choicePage->currentChoice() == ChoicePage::Replace || diff --git a/src/modules/partition/gui/ReplaceWidget.cpp b/src/modules/partition/gui/ReplaceWidget.cpp index 9c7a199be..13001468f 100644 --- a/src/modules/partition/gui/ReplaceWidget.cpp +++ b/src/modules/partition/gui/ReplaceWidget.cpp @@ -2,6 +2,7 @@ * * Copyright 2014-2015, Teo Mrnjavac * Copyright 2014, Aurélien Gâteau + * Copyright 2019, Adriaan de Groot * * Calamares is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/modules/partition/gui/ResizeVolumeGroupDialog.cpp b/src/modules/partition/gui/ResizeVolumeGroupDialog.cpp index 35b6bbdf1..1c5eef0ab 100644 --- a/src/modules/partition/gui/ResizeVolumeGroupDialog.cpp +++ b/src/modules/partition/gui/ResizeVolumeGroupDialog.cpp @@ -1,6 +1,7 @@ /* === This file is part of Calamares - === * * Copyright 2018, Caio Jordão Carvalho + * Copyright 2019, Adriaan de Groot * * Calamares is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -29,8 +30,8 @@ #include ResizeVolumeGroupDialog::ResizeVolumeGroupDialog( LvmDevice *device, - QVector< const Partition* > availablePVs, - QVector< const Partition* >& selectedPVs, + const PartitionVector& availablePVs, + PartitionVector& selectedPVs, QWidget* parent ) : VolumeGroupBaseDialog( device->name(), device->physicalVolumes(), parent ) , m_selectedPVs( selectedPVs ) diff --git a/src/modules/partition/gui/ResizeVolumeGroupDialog.h b/src/modules/partition/gui/ResizeVolumeGroupDialog.h index 1d6015329..82231f885 100644 --- a/src/modules/partition/gui/ResizeVolumeGroupDialog.h +++ b/src/modules/partition/gui/ResizeVolumeGroupDialog.h @@ -1,6 +1,7 @@ /* === This file is part of Calamares - === * * Copyright 2018, Caio Jordão Carvalho + * Copyright 2019, Adriaan de Groot * * Calamares is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -26,15 +27,17 @@ class LvmDevice; class ResizeVolumeGroupDialog : public VolumeGroupBaseDialog { public: + using PartitionVector = QVector< const Partition* >; + ResizeVolumeGroupDialog( LvmDevice *device, - QVector< const Partition* > availablePVs, - QVector< const Partition* >& selectedPVs, + const PartitionVector& availablePVs, + PartitionVector& selectedPVs, QWidget* parent ); void accept() override; private: - QVector< const Partition* >& m_selectedPVs; + PartitionVector& m_selectedPVs; }; #endif // RESIZEVOLUMEGROUPDIALOG_H diff --git a/src/modules/partition/jobs/FillGlobalStorageJob.cpp b/src/modules/partition/jobs/FillGlobalStorageJob.cpp index 7a82e9f1a..8b981ce3e 100644 --- a/src/modules/partition/jobs/FillGlobalStorageJob.cpp +++ b/src/modules/partition/jobs/FillGlobalStorageJob.cpp @@ -2,7 +2,7 @@ * * Copyright 2014, Aurélien Gâteau * Copyright 2015-2016, Teo Mrnjavac - * Copyright 2017, Adriaan de Groot + * Copyright 2017, 2019, Adriaan de Groot * * Calamares is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/modules/partition/tests/PartitionJobTests.cpp b/src/modules/partition/tests/PartitionJobTests.cpp index 0314ea9cd..ac867bcb0 100644 --- a/src/modules/partition/tests/PartitionJobTests.cpp +++ b/src/modules/partition/tests/PartitionJobTests.cpp @@ -1,7 +1,7 @@ /* === This file is part of Calamares - === * * Copyright 2014, Aurélien Gâteau - * Copyright 2017, Adriaan de Groot + * Copyright 2017, 2019 Adriaan de Groot * * Calamares is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by