Show a summary of the partition changes on the summary page

This commit is contained in:
Aurélien Gâteau 2014-07-30 14:15:29 +02:00
parent e7e57689d8
commit 03c5a38b90
8 changed files with 141 additions and 22 deletions

View File

@ -36,6 +36,11 @@ ViewStep::prettyStatus() const
return QString(); return QString();
} }
QWidget*
ViewStep::createSummaryWidget() const
{
return nullptr;
}
void void
ViewStep::onActivate() ViewStep::onActivate()

View File

@ -37,6 +37,12 @@ public:
virtual QString prettyName() const = 0; virtual QString prettyName() const = 0;
virtual QString prettyStatus() const; virtual QString prettyStatus() const;
/**
* Optional. Should return a widget which will be inserted in the summary
* page. The caller takes ownership of the widget.
*/
virtual QWidget* createSummaryWidget() const;
//TODO: we might want to make this a QSharedPointer //TODO: we might want to make this a QSharedPointer
virtual QWidget* widget() = 0; virtual QWidget* widget() = 0;

View File

@ -349,3 +349,30 @@ PartitionCoreModule::revert()
init(); init();
updateIsDirty(); updateIsDirty();
} }
QList< PartitionCoreModule::SummaryInfo >
PartitionCoreModule::createSummaryInfo() const
{
QList< SummaryInfo > lst;
CoreBackend* backend = CoreBackendManager::self()->backend();
for ( auto deviceInfo : m_deviceInfos )
{
if ( !deviceInfo->isDirty() )
continue;
SummaryInfo summaryInfo;
summaryInfo.deviceName = deviceInfo->device->name();
Device* deviceBefore = backend->scanDevice( deviceInfo->device->deviceNode() );
summaryInfo.partitionModelBefore = new PartitionModel;
summaryInfo.partitionModelBefore->init( deviceBefore );
// Make deviceBefore a child of partitionModelBefore so that it is not
// leaked (as long as partitionModelBefore is deleted)
deviceBefore->setParent( summaryInfo.partitionModelBefore );
summaryInfo.partitionModelAfter = new PartitionModel;
summaryInfo.partitionModelAfter->init( deviceInfo->device.data() );
lst << summaryInfo;
}
return lst;
}

View File

@ -45,6 +45,13 @@ class PartitionCoreModule : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
struct SummaryInfo
{
QString deviceName;
PartitionModel* partitionModelBefore;
PartitionModel* partitionModelAfter;
};
PartitionCoreModule( QObject* parent = nullptr ); PartitionCoreModule( QObject* parent = nullptr );
~PartitionCoreModule(); ~PartitionCoreModule();
@ -80,6 +87,12 @@ public:
*/ */
void refreshPartition( Device* device, Partition* partition ); void refreshPartition( Device* device, Partition* partition );
/**
* Returns a list of SummaryInfo for devices which have pending changes.
* Caller is responsible for deleting the partition models
*/
QList< SummaryInfo > createSummaryInfo() const;
Q_SIGNALS: Q_SIGNALS:
void hasRootMountPointChanged( bool value ); void hasRootMountPointChanged( bool value );
void isDirtyChanged( bool value ); void isDirtyChanged( bool value );

View File

@ -18,8 +18,15 @@
#include <PartitionViewStep.h> #include <PartitionViewStep.h>
#include <PartitionPage.h> #include <DeviceModel.h>
#include <PartitionCoreModule.h> #include <PartitionCoreModule.h>
#include <PartitionModel.h>
#include <PartitionPage.h>
#include <PartitionPreview.h>
// Qt
#include <QFormLayout>
#include <QLabel>
PartitionViewStep::PartitionViewStep( QObject* parent ) PartitionViewStep::PartitionViewStep( QObject* parent )
: Calamares::ViewStep( parent ) : Calamares::ViewStep( parent )
@ -45,6 +52,33 @@ PartitionViewStep::widget()
} }
QWidget*
PartitionViewStep::createSummaryWidget() const
{
QWidget* widget = new QWidget;
QFormLayout* layout = new QFormLayout( widget );
layout->setMargin( 0 );
QList< PartitionCoreModule::SummaryInfo > list = m_core->createSummaryInfo();
for ( const auto& info : list )
{
PartitionPreview* preview;
layout->addRow( new QLabel( info.deviceName ) );
preview = new PartitionPreview;
preview->setModel( info.partitionModelBefore );
info.partitionModelBefore->setParent( widget );
layout->addRow( tr( "Before:" ), preview );
preview = new PartitionPreview;
preview->setModel( info.partitionModelAfter );
info.partitionModelAfter->setParent( widget );
layout->addRow( tr( "After:" ), preview );
}
return widget;
}
void void
PartitionViewStep::next() PartitionViewStep::next()
{ {

View File

@ -37,6 +37,7 @@ public:
explicit PartitionViewStep( QObject* parent = 0 ); explicit PartitionViewStep( QObject* parent = 0 );
QString prettyName() const override; QString prettyName() const override;
QWidget* createSummaryWidget() const override;
QWidget* widget() override; QWidget* widget() override;

View File

@ -24,40 +24,67 @@
#include <QBoxLayout> #include <QBoxLayout>
#include <QLabel> #include <QLabel>
static const int SECTION_SPACING = 12;
SummaryPage::SummaryPage( QWidget* parent ) SummaryPage::SummaryPage( QWidget* parent )
: QWidget() : QWidget()
{ {
QBoxLayout *mainLayout = new QVBoxLayout; QVBoxLayout* layout = new QVBoxLayout( this );
setLayout( mainLayout ); layout->setContentsMargins( 0, 0, 0, 0 );
mainLayout->addStretch();
m_label = new QLabel( this );
mainLayout->addWidget( m_label );
m_label->setWordWrap( true );
mainLayout->addStretch();
} }
void void
SummaryPage::onActivate() SummaryPage::onActivate()
{ {
createContentWidget();
QString text; QString text;
bool first = true;
foreach ( Calamares::ViewStep* step, foreach ( Calamares::ViewStep* step,
Calamares::ViewManager::instance()->prepareSteps() ) Calamares::ViewManager::instance()->prepareSteps() )
{ {
//TODO: make it nice! QString text = step->prettyStatus();
if ( !step->prettyStatus().isEmpty() ) QWidget* widget = step->createSummaryWidget();
{
if ( !text.isEmpty() )
text += "<br/><br/>";
text += "<h3>" + step->prettyName() + if ( text.isEmpty() && !widget )
"</h3><br/>" + step->prettyStatus(); continue;
}
if ( first )
first = false;
else
m_layout->addSpacing( SECTION_SPACING );
m_layout->addWidget( createTitleLabel( step->prettyName() ) );
if ( !text.isEmpty() )
m_layout->addWidget( createBodyLabel( text ) );
if ( widget )
m_layout->addWidget( widget );
} }
m_layout->addStretch();
m_label->setText( text ); }
void
SummaryPage::createContentWidget()
{
delete m_contentWidget;
m_contentWidget = new QWidget;
m_layout = new QVBoxLayout( m_contentWidget );
layout()->addWidget( m_contentWidget );
}
QLabel*
SummaryPage::createTitleLabel( const QString& text ) const
{
QLabel* label = new QLabel( text );
QFont fnt = font();
fnt.setBold( true );
label->setFont( fnt );
return label;
}
QLabel*
SummaryPage::createBodyLabel( const QString& text ) const
{
return new QLabel( text );
} }

View File

@ -22,6 +22,7 @@
#include <QWidget> #include <QWidget>
class QLabel; class QLabel;
class QVBoxLayout;
class SummaryPage : public QWidget class SummaryPage : public QWidget
{ {
@ -32,7 +33,12 @@ public:
void onActivate(); void onActivate();
private: private:
QLabel* m_label; QVBoxLayout* m_layout = nullptr;
QWidget* m_contentWidget = nullptr;
void createContentWidget();
QLabel* createTitleLabel( const QString& text ) const;
QLabel* createBodyLabel( const QString& text ) const;
}; };
#endif // SUMMARYPAGE_H #endif // SUMMARYPAGE_H