Use EncryptWidget for relevant partition types in CreatePartitionDialog.

This commit is contained in:
Teo Mrnjavac 2016-06-10 14:45:26 +02:00
parent d75d5c76fe
commit a00ebc01e7

View File

@ -35,6 +35,7 @@
#include <kpmcore/core/partition.h> #include <kpmcore/core/partition.h>
#include <kpmcore/fs/filesystem.h> #include <kpmcore/fs/filesystem.h>
#include <kpmcore/fs/filesystemfactory.h> #include <kpmcore/fs/filesystemfactory.h>
#include <kpmcore/fs/luks.h>
// Qt // Qt
#include <QComboBox> #include <QComboBox>
@ -59,6 +60,8 @@ CreatePartitionDialog::CreatePartitionDialog( Device* device, PartitionNode* par
, m_parent( parentPartition ) , m_parent( parentPartition )
{ {
m_ui->setupUi( this ); m_ui->setupUi( this );
m_ui->encryptWidget->setText( tr( "En&crypt" ) );
m_ui->encryptWidget->hide();
QStringList mountPoints = { "/", "/boot", "/home", "/opt", "/usr", "/var" }; QStringList mountPoints = { "/", "/boot", "/home", "/opt", "/usr", "/var" };
if ( QDir( "/sys/firmware/efi/efivars" ).exists() ) if ( QDir( "/sys/firmware/efi/efivars" ).exists() )
@ -178,11 +181,28 @@ CreatePartitionDialog::createPartition()
FileSystem::Type fsType = m_role.has( PartitionRole::Extended ) FileSystem::Type fsType = m_role.has( PartitionRole::Extended )
? FileSystem::Extended ? FileSystem::Extended
: FileSystem::typeForName( m_ui->fsComboBox->currentText() ); : FileSystem::typeForName( m_ui->fsComboBox->currentText() );
Partition* partition = KPMHelpers::createNewPartition(
m_parent, Partition* partition = nullptr;
*m_device, QString luksPassphrase = m_ui->encryptWidget->passphrase();
m_role, if ( m_ui->encryptWidget->isVisible() &&
fsType, first, last, newFlags() ); !luksPassphrase.isEmpty() )
{
partition = KPMHelpers::createNewEncryptedPartition(
m_parent,
*m_device,
m_role,
fsType, first, last, luksPassphrase, newFlags()
);
}
else
{
partition = KPMHelpers::createNewPartition(
m_parent,
*m_device,
m_role,
fsType, first, last, newFlags()
);
}
PartitionInfo::setMountPoint( partition, m_ui->mountPointComboBox->currentText() ); PartitionInfo::setMountPoint( partition, m_ui->mountPointComboBox->currentText() );
PartitionInfo::setFormat( partition, true ); PartitionInfo::setFormat( partition, true );
@ -198,6 +218,17 @@ CreatePartitionDialog::updateMountPointUi()
{ {
FileSystem::Type type = FileSystem::typeForName( m_ui->fsComboBox->currentText() ); FileSystem::Type type = FileSystem::typeForName( m_ui->fsComboBox->currentText() );
enabled = !s_unmountableFS.contains( type ); enabled = !s_unmountableFS.contains( type );
if ( FS::luks::canEncryptType( type ) )
{
m_ui->encryptWidget->show();
m_ui->encryptWidget->reset();
}
else
{
m_ui->encryptWidget->reset();
m_ui->encryptWidget->hide();
}
} }
m_ui->mountPointLabel->setEnabled( enabled ); m_ui->mountPointLabel->setEnabled( enabled );
m_ui->mountPointComboBox->setEnabled( enabled ); m_ui->mountPointComboBox->setEnabled( enabled );