From ef703b0859552260d2dcde1063719a6fd07de641 Mon Sep 17 00:00:00 2001 From: Teo Mrnjavac Date: Thu, 4 Sep 2014 19:37:30 +0200 Subject: [PATCH] Add page for erase+install operation. --- src/modules/partition/CMakeLists.txt | 1 + src/modules/partition/gui/ChoicePage.h | 2 +- src/modules/partition/gui/EraseDiskPage.cpp | 100 ++++++++++++++++++ src/modules/partition/gui/EraseDiskPage.h | 49 +++++++++ .../partition/gui/PartitionViewStep.cpp | 26 ++++- src/modules/partition/gui/PartitionViewStep.h | 2 + 6 files changed, 174 insertions(+), 6 deletions(-) create mode 100644 src/modules/partition/gui/EraseDiskPage.cpp create mode 100644 src/modules/partition/gui/EraseDiskPage.h diff --git a/src/modules/partition/CMakeLists.txt b/src/modules/partition/CMakeLists.txt index 83f360992..626fed8e4 100644 --- a/src/modules/partition/CMakeLists.txt +++ b/src/modules/partition/CMakeLists.txt @@ -33,6 +33,7 @@ calamares_add_plugin( partition gui/ChoicePage.cpp gui/CreatePartitionDialog.cpp gui/EditExistingPartitionDialog.cpp + gui/EraseDiskPage.cpp gui/PartitionPage.cpp gui/PartitionPreview.cpp gui/PartitionSizeController.cpp diff --git a/src/modules/partition/gui/ChoicePage.h b/src/modules/partition/gui/ChoicePage.h index 600f0d101..32a0e07e9 100644 --- a/src/modules/partition/gui/ChoicePage.h +++ b/src/modules/partition/gui/ChoicePage.h @@ -48,7 +48,7 @@ public: Choice currentChoice(); signals: - void nextStatusChanged( bool enabled ); + void nextStatusChanged( bool ); private: void setNextEnabled( bool enabled ); diff --git a/src/modules/partition/gui/EraseDiskPage.cpp b/src/modules/partition/gui/EraseDiskPage.cpp new file mode 100644 index 000000000..94ebb50fe --- /dev/null +++ b/src/modules/partition/gui/EraseDiskPage.cpp @@ -0,0 +1,100 @@ +/* === This file is part of Calamares - === + * + * Copyright 2014, Teo Mrnjavac + * + * 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 "EraseDiskPage.h" + +#include "core/DeviceModel.h" +#include "core/PartitionCoreModule.h" + +#include "utils/CalamaresUtilsGui.h" +#include "utils/Logger.h" + +#include +#include +#include + +EraseDiskPage::EraseDiskPage( QWidget* parent ) + : QWidget( parent ) + , m_nextEnabled( false ) + , m_core( nullptr ) +{ + QVBoxLayout* mainLayout = new QVBoxLayout; + setLayout( mainLayout ); + + QLabel* driveLabel = new QLabel( tr( "Select drive:" ) ); + mainLayout->addWidget( driveLabel ); + + m_drivesView = new QListView; + mainLayout->addWidget( m_drivesView ); + m_drivesView->setViewMode( QListView::IconMode ); + m_drivesView->setWrapping( false ); + m_drivesView->setFlow( QListView::LeftToRight ); + m_drivesView->setSelectionRectVisible( false ); + m_drivesView->setWordWrap( true ); + m_drivesView->setUniformItemSizes( true ); + m_drivesView->setSelectionMode( QAbstractItemView::SingleSelection ); + + m_drivesView->setIconSize( CalamaresUtils::defaultIconSize() * 3 ); + m_drivesView->setGridSize( QSize( CalamaresUtils::defaultFontHeight() * 8, + m_drivesView->iconSize().height() + + CalamaresUtils::defaultFontHeight() * 4 ) ); + m_drivesView->setMinimumHeight( m_drivesView->gridSize().height() + 2 ); + + mainLayout->addStretch(); + setNextEnabled( false ); +} + + +void +EraseDiskPage::init( PartitionCoreModule* core ) +{ + if ( m_core ) //this should probably never happen + { + m_core->revert(); + return; + } + + m_core = core; + m_drivesView->setModel( core->deviceModel() ); + + connect( m_drivesView->selectionModel(), &QItemSelectionModel::selectionChanged, + this, [ this ]() + { + setNextEnabled( m_drivesView->selectionModel()->hasSelection() ); + + //TODO: show a before/after view before this model, update it on selection changed + } ); +} + + +bool +EraseDiskPage::isNextEnabled() +{ + return m_nextEnabled; +} + + +void +EraseDiskPage::setNextEnabled( bool enabled ) +{ + if ( enabled == m_nextEnabled ) + return; + + m_nextEnabled = enabled; + emit nextStatusChanged( enabled ); +} diff --git a/src/modules/partition/gui/EraseDiskPage.h b/src/modules/partition/gui/EraseDiskPage.h new file mode 100644 index 000000000..c44974099 --- /dev/null +++ b/src/modules/partition/gui/EraseDiskPage.h @@ -0,0 +1,49 @@ +/* === This file is part of Calamares - === + * + * Copyright 2014, Teo Mrnjavac + * + * 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 ERASEDISKPAGE_H +#define ERASEDISKPAGE_H + +#include + +class PartitionCoreModule; +class QListView; + +class EraseDiskPage : public QWidget +{ + Q_OBJECT +public: + explicit EraseDiskPage( QWidget* parent = nullptr ); + + void init( PartitionCoreModule* core ); + + bool isNextEnabled(); + +signals: + void nextStatusChanged( bool ); + +private: + void setNextEnabled( bool enabled ); + + QListView* m_drivesView; + PartitionCoreModule* m_core; + + bool m_nextEnabled; +}; + +#endif // ERASEDISKPAGE_H diff --git a/src/modules/partition/gui/PartitionViewStep.cpp b/src/modules/partition/gui/PartitionViewStep.cpp index 55cb4adbb..4cf1cc5aa 100644 --- a/src/modules/partition/gui/PartitionViewStep.cpp +++ b/src/modules/partition/gui/PartitionViewStep.cpp @@ -22,6 +22,7 @@ #include #include #include +#include #include #include @@ -43,6 +44,7 @@ PartitionViewStep::PartitionViewStep( QObject* parent ) , m_widget( new QStackedWidget() ) , m_core( new PartitionCoreModule( this ) ) , m_choicePage( new ChoicePage() ) + , m_erasePage( new EraseDiskPage() ) , m_manualPartitionPage( new PartitionPage( m_core ) ) { m_widget->setContentsMargins( 0, 0, 0, 0 ); @@ -78,9 +80,11 @@ PartitionViewStep::PartitionViewStep( QObject* parent ) QStringList osproberLines = osproberOutput.split( '\n' ); m_choicePage->init( m_core, osproberLines ); + m_erasePage->init( m_core ); m_widget->addWidget( m_choicePage ); m_widget->addWidget( m_manualPartitionPage ); + m_widget->addWidget( m_erasePage ); m_widget->removeWidget( waitingWidget ); waitingWidget->deleteLater(); @@ -88,10 +92,12 @@ PartitionViewStep::PartitionViewStep( QObject* parent ) } ); timer->start( 0 ); - connect( m_core, &PartitionCoreModule::hasRootMountPointChanged, - this, &PartitionViewStep::nextStatusChanged ); - connect( m_choicePage, &ChoicePage::nextStatusChanged, - this, &PartitionViewStep::nextStatusChanged ); + connect( m_core, &PartitionCoreModule::hasRootMountPointChanged, + this, &PartitionViewStep::nextStatusChanged ); + connect( m_choicePage, &ChoicePage::nextStatusChanged, + this, &PartitionViewStep::nextStatusChanged ); + connect( m_erasePage, &EraseDiskPage::nextStatusChanged, + this, &PartitionViewStep::nextStatusChanged ); } @@ -151,7 +157,14 @@ PartitionViewStep::next() { if ( m_choicePage == m_widget->currentWidget() ) { - m_widget->setCurrentWidget( m_manualPartitionPage ); + if ( m_choicePage->currentChoice() == ChoicePage::Manual ) + m_widget->setCurrentWidget( m_manualPartitionPage ); + else if ( m_choicePage->currentChoice() == ChoicePage::Erase ) + { + if ( m_core->isDirty() ) + m_core->revert(); + m_widget->setCurrentWidget( m_erasePage ); + } cDebug() << "Choice applied: " << m_choicePage->currentChoice(); } else @@ -173,6 +186,9 @@ PartitionViewStep::isNextEnabled() const if ( m_choicePage && m_choicePage == m_widget->currentWidget() ) return m_choicePage->isNextEnabled(); + if ( m_erasePage && m_erasePage == m_widget->currentWidget() ) + return m_erasePage->isNextEnabled(); //FIXME: also check for mount point + return m_core->hasRootMountPoint(); } diff --git a/src/modules/partition/gui/PartitionViewStep.h b/src/modules/partition/gui/PartitionViewStep.h index 768b98eab..ee12e2121 100644 --- a/src/modules/partition/gui/PartitionViewStep.h +++ b/src/modules/partition/gui/PartitionViewStep.h @@ -25,6 +25,7 @@ #include "PluginDllMacro.h" class ChoicePage; +class EraseDiskPage; class PartitionPage; class PartitionCoreModule; class QStackedWidget; @@ -62,6 +63,7 @@ private: PartitionCoreModule* m_core; QStackedWidget* m_widget; ChoicePage* m_choicePage; + EraseDiskPage* m_erasePage; PartitionPage* m_manualPartitionPage; };