From 6cd1bf6b3d2c7a0df63bd204f8034dceac1b77a1 Mon Sep 17 00:00:00 2001
From: Teo Mrnjavac <teo@kde.org>
Date: Fri, 27 May 2016 16:29:03 +0200
Subject: [PATCH] Initial work on having the Replace feature obey the
 encryption setting.

---
 src/modules/partition/gui/ChoicePage.cpp | 31 ++++++++++++++++++++++--
 1 file changed, 29 insertions(+), 2 deletions(-)

diff --git a/src/modules/partition/gui/ChoicePage.cpp b/src/modules/partition/gui/ChoicePage.cpp
index 20a548c8c0..4884057a2a 100644
--- a/src/modules/partition/gui/ChoicePage.cpp
+++ b/src/modules/partition/gui/ChoicePage.cpp
@@ -484,6 +484,19 @@ ChoicePage::onEncryptWidgetStateChanged()
              state == EncryptWidget::EncryptionDisabled )
             applyActionChoice( m_choice );
     }
+    else if ( m_choice == Replace )
+    {
+        if ( m_beforePartitionBarsView &&
+             m_beforePartitionBarsView->selectionModel()->currentIndex().isValid() &&
+             ( state == EncryptWidget::EncryptionConfirmed ||
+               state == EncryptWidget::EncryptionDisabled ) )
+        {
+            doReplaceSelectedPartition( m_beforePartitionBarsView->
+                                            selectionModel()->
+                                                currentIndex(),
+                                        QModelIndex() );
+        }
+    }
     updateNextEnabled();
 }
 
@@ -610,13 +623,28 @@ ChoicePage::doReplaceSelectedPartition( const QModelIndex& current,
                 }
             }
 
-            Partition* newPartition = KPMHelpers::createNewPartition(
+            Partition* newPartition = nullptr;
+            if ( m_encryptWidget->state() == EncryptWidget::EncryptionConfirmed )
+            {
+                newPartition = KPMHelpers::createNewEncryptedPartition(
+                    newParent,
+                    *selectedDevice(),
+                    newRoles,
+                    FileSystem::Ext4,
+                    selectedPartition->firstSector(),
+                    selectedPartition->lastSector(),
+                    m_encryptWidget->passphrase() );
+            }
+            else
+            {
+                newPartition = KPMHelpers::createNewPartition(
                     newParent,
                     *selectedDevice(),
                     newRoles,
                     FileSystem::Ext4,
                     selectedPartition->firstSector(),
                     selectedPartition->lastSector() );
+            }
 
             PartitionInfo::setMountPoint( newPartition, "/" );
             PartitionInfo::setFormat( newPartition, true );
@@ -850,7 +878,6 @@ ChoicePage::updateActionChoicePreview( ChoicePage::Choice choice )
                 m_selectLabel->hide();
             else
             {
-                m_encryptWidget->hide();
                 SelectionFilter filter = [ this ]( const QModelIndex& index )
                 {
                     return PartUtils::canBeReplaced( (Partition*)( index.data( PartitionModel::PartitionPtrRole ).value< void* >() ) );
-- 
GitLab