diff --git a/src/modules/partition/PartitionCoreModule.cpp b/src/modules/partition/PartitionCoreModule.cpp
index 57f4b77b6..0e408cb0e 100644
--- a/src/modules/partition/PartitionCoreModule.cpp
+++ b/src/modules/partition/PartitionCoreModule.cpp
@@ -60,6 +60,20 @@ PartitionCoreModule::DeviceInfo::forgetChanges()
PartitionInfo::reset( *it );
}
+
+bool
+PartitionCoreModule::DeviceInfo::isDirty() const
+{
+ if ( !jobs.isEmpty() )
+ return true;
+
+ for ( auto it = PartitionIterator::begin( device.data() ); it != PartitionIterator::end( device.data() ); ++it )
+ if ( PartitionInfo::isDirty( *it ) )
+ return true;
+
+ return false;
+}
+
//- PartitionCoreModule ------------------------------------
PartitionCoreModule::PartitionCoreModule( QObject* parent )
: QObject( parent )
@@ -70,6 +84,12 @@ PartitionCoreModule::PartitionCoreModule( QObject* parent )
if ( !CalaPM::init() )
qFatal( "Failed to init CalaPM" );
+ init();
+}
+
+void
+PartitionCoreModule::init()
+{
CoreBackend* backend = CoreBackendManager::self()->backend();
auto devices = backend->scanDevices();
for ( auto device : devices )
@@ -248,6 +268,7 @@ PartitionCoreModule::refresh( Device* device )
Q_ASSERT( model );
model->reload();
updateHasRootMountPoint();
+ updateIsDirty();
m_bootLoaderModel->update();
}
@@ -260,6 +281,21 @@ void PartitionCoreModule::updateHasRootMountPoint()
hasRootMountPointChanged( m_hasRootMountPoint );
}
+void
+PartitionCoreModule::updateIsDirty()
+{
+ bool oldValue = m_isDirty;
+ m_isDirty = false;
+ for ( auto info : m_deviceInfos )
+ if ( info->isDirty() )
+ {
+ m_isDirty = true;
+ break;
+ }
+ if ( oldValue != m_isDirty )
+ isDirtyChanged( m_isDirty );
+}
+
PartitionCoreModule::DeviceInfo*
PartitionCoreModule::infoForDevice( Device* device ) const
{
@@ -289,3 +325,12 @@ PartitionCoreModule::setBootLoaderInstallPath( const QString& path )
{
m_bootLoaderInstallPath = path;
}
+
+void
+PartitionCoreModule::revert()
+{
+ qDeleteAll( m_deviceInfos );
+ m_deviceInfos.clear();
+ init();
+ updateIsDirty();
+}
diff --git a/src/modules/partition/PartitionCoreModule.h b/src/modules/partition/PartitionCoreModule.h
index 8915801f1..860ac144e 100644
--- a/src/modules/partition/PartitionCoreModule.h
+++ b/src/modules/partition/PartitionCoreModule.h
@@ -73,8 +73,11 @@ public:
void refresh( Device* device );
+ void revert();
+
Q_SIGNALS:
void hasRootMountPointChanged( bool value );
+ void isDirtyChanged( bool value );
private:
/**
@@ -89,15 +92,19 @@ private:
QList< Calamares::job_ptr > jobs;
void forgetChanges();
+ bool isDirty() const;
};
QList< DeviceInfo* > m_deviceInfos;
DeviceModel* m_deviceModel;
BootLoaderModel* m_bootLoaderModel;
bool m_hasRootMountPoint = false;
+ bool m_isDirty = false;
QString m_bootLoaderInstallPath;
+ void init();
void updateHasRootMountPoint();
+ void updateIsDirty();
void dumpQueue() const;
diff --git a/src/modules/partition/PartitionInfo.cpp b/src/modules/partition/PartitionInfo.cpp
index f38c0457f..ce5ee975b 100644
--- a/src/modules/partition/PartitionInfo.cpp
+++ b/src/modules/partition/PartitionInfo.cpp
@@ -60,4 +60,11 @@ reset( Partition* partition )
partition->setProperty( FORMAT_PROPERTY, QVariant() );
}
+bool
+isDirty( Partition* partition )
+{
+ return !mountPoint( partition ).isEmpty()
+ || format( partition );
+}
+
} // namespace
diff --git a/src/modules/partition/PartitionInfo.h b/src/modules/partition/PartitionInfo.h
index 6b2da192a..843d360cf 100644
--- a/src/modules/partition/PartitionInfo.h
+++ b/src/modules/partition/PartitionInfo.h
@@ -38,6 +38,8 @@ void setFormat( Partition* partition, bool value );
void reset( Partition* partition );
+bool isDirty( Partition* partition );
+
};
#endif /* PARTITIONINFO_H */
diff --git a/src/modules/partition/PartitionPage.cpp b/src/modules/partition/PartitionPage.cpp
index 07a4c4a2d..1e10ac512 100644
--- a/src/modules/partition/PartitionPage.cpp
+++ b/src/modules/partition/PartitionPage.cpp
@@ -65,7 +65,9 @@ PartitionPage::PartitionPage( PartitionCoreModule* core, QWidget* parent )
updateBootLoaderInstallPath();
} );
+ connect( m_core, &PartitionCoreModule::isDirtyChanged, m_ui->revertButton, &QWidget::setEnabled );
+ connect( m_ui->revertButton, &QAbstractButton::clicked, this, &PartitionPage::onRevertClicked );
connect( m_ui->newPartitionTableButton, &QAbstractButton::clicked, this, &PartitionPage::onNewPartitionTableClicked );
connect( m_ui->createButton, &QAbstractButton::clicked, this, &PartitionPage::onCreateClicked );
connect( m_ui->editButton, &QAbstractButton::clicked, this, &PartitionPage::onEditClicked );
@@ -174,6 +176,15 @@ PartitionPage::onDeleteClicked()
m_core->deletePartition( model->device(), partition );
}
+void
+PartitionPage::onRevertClicked()
+{
+ int oldIndex = m_ui->deviceComboBox->currentIndex();
+ m_core->revert();
+ m_ui->deviceComboBox->setCurrentIndex( oldIndex );
+ updateFromCurrentDevice();
+}
+
void
PartitionPage::updatePartitionToCreate( Device* device, Partition* partition )
{
diff --git a/src/modules/partition/PartitionPage.h b/src/modules/partition/PartitionPage.h
index 719a23539..155ac7af4 100644
--- a/src/modules/partition/PartitionPage.h
+++ b/src/modules/partition/PartitionPage.h
@@ -44,6 +44,7 @@ private:
QScopedPointer< Ui_PartitionPage > m_ui;
PartitionCoreModule* m_core;
void updateButtons();
+ void onRevertClicked();
void onNewPartitionTableClicked();
void onCreateClicked();
void onEditClicked();
diff --git a/src/modules/partition/PartitionPage.ui b/src/modules/partition/PartitionPage.ui
index 7d99314d8..e2262b819 100644
--- a/src/modules/partition/PartitionPage.ui
+++ b/src/modules/partition/PartitionPage.ui
@@ -42,6 +42,16 @@
+ -
+
+
+ false
+
+
+ Revert All Changes
+
+
+
-