From 6e92a043208179a22e7a4e47df78e31050e4ef6b Mon Sep 17 00:00:00 2001 From: Teo Mrnjavac Date: Fri, 22 Apr 2016 16:00:19 +0200 Subject: [PATCH] Say hello to EncryptWidget. --- src/modules/partition/CMakeLists.txt | 6 +- src/modules/partition/gui/EncryptWidget.cpp | 150 ++++++++++++++++++++ src/modules/partition/gui/EncryptWidget.h | 57 ++++++++ src/modules/partition/gui/EncryptWidget.ui | 58 ++++++++ 4 files changed, 269 insertions(+), 2 deletions(-) create mode 100644 src/modules/partition/gui/EncryptWidget.cpp create mode 100644 src/modules/partition/gui/EncryptWidget.h create mode 100644 src/modules/partition/gui/EncryptWidget.ui diff --git a/src/modules/partition/CMakeLists.txt b/src/modules/partition/CMakeLists.txt index 1d766c2cf..5b76ef887 100644 --- a/src/modules/partition/CMakeLists.txt +++ b/src/modules/partition/CMakeLists.txt @@ -31,11 +31,12 @@ calamares_add_plugin( partition core/PartitionIterator.cpp core/PartitionModel.cpp core/PartUtils.cpp + gui/BootInfoWidget.cpp gui/ChoicePage.cpp gui/CreatePartitionDialog.cpp - gui/EditExistingPartitionDialog.cpp - gui/BootInfoWidget.cpp gui/DeviceInfoWidget.cpp + gui/EditExistingPartitionDialog.cpp + gui/EncryptWidget.cpp gui/PartitionPage.cpp gui/PartitionBarsView.cpp gui/PartitionLabelsView.cpp @@ -62,6 +63,7 @@ calamares_add_plugin( partition gui/CreatePartitionDialog.ui gui/CreatePartitionTableDialog.ui gui/EditExistingPartitionDialog.ui + gui/EncryptWidget.ui gui/PartitionPage.ui gui/ReplaceWidget.ui LINK_LIBRARIES diff --git a/src/modules/partition/gui/EncryptWidget.cpp b/src/modules/partition/gui/EncryptWidget.cpp new file mode 100644 index 000000000..0ddd60831 --- /dev/null +++ b/src/modules/partition/gui/EncryptWidget.cpp @@ -0,0 +1,150 @@ +/* === This file is part of Calamares - === + * + * Copyright 2016, 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 "EncryptWidget.h" + +#include + +EncryptWidget::EncryptWidget( QWidget* parent ) + : QWidget( parent ) +{ + setupUi( this ); + + m_iconLabel->setFixedWidth( m_iconLabel->height() ); + m_passphraseLineEdit->hide(); + m_confirmLineEdit->hide(); + m_iconLabel->hide(); + + connect( m_encryptCheckBox, &QCheckBox::stateChanged, + this, &EncryptWidget::onCheckBoxStateChanged ); + connect( m_passphraseLineEdit, &QLineEdit::textEdited, + this, &EncryptWidget::onPassphraseEdited ); + connect( m_confirmLineEdit, &QLineEdit::textEdited, + this, &EncryptWidget::onPassphraseEdited ); + + updateState(); +} + + +EncryptWidget::State +EncryptWidget::state() const +{ + return m_state; +} + + +QString +EncryptWidget::passphrase() const +{ + if ( m_state == EncryptionConfirmed ) + return m_passphraseLineEdit->text(); + return QString(); +} + + +void +EncryptWidget::changeEvent( QEvent* e ) +{ + QWidget::changeEvent( e ); + switch ( e->type() ) + { + case QEvent::LanguageChange: + retranslateUi( this ); + break; + default: + break; + } +} + + +void +EncryptWidget::updateState() +{ + State newState; + if ( m_encryptCheckBox->isChecked() ) + { + if ( !m_passphraseLineEdit->text().isEmpty() && + m_passphraseLineEdit->text() == m_confirmLineEdit->text() ) + { + newState = EncryptionConfirmed; + } + else + { + newState = EncryptionUnconfirmed; + } + } + else + { + newState = EncryptionDisabled; + } + + if ( newState != m_state ) + { + m_state = newState; + emit stateChanged( m_state ); + } +} + + +void +EncryptWidget::onPassphraseEdited() +{ + if ( !m_iconLabel->isVisible() ) + m_iconLabel->show(); + + QString p1 = m_passphraseLineEdit->text(); + QString p2 = m_confirmLineEdit->text(); + + m_iconLabel->setToolTip( QString() ); + if ( p1.isEmpty() && p2.isEmpty() ) + { + m_iconLabel->clear(); + } + else if ( p1 == p2 ) + { + m_iconLabel->setFixedWidth( m_iconLabel->height() ); + m_iconLabel->setPixmap( CalamaresUtils::defaultPixmap( CalamaresUtils::Yes, + CalamaresUtils::Original, + m_iconLabel->size() ) ); + } + else + { + m_iconLabel->setFixedWidth( m_iconLabel->height() ); + m_iconLabel->setPixmap( CalamaresUtils::defaultPixmap( CalamaresUtils::No, + CalamaresUtils::Original, + m_iconLabel->size() ) ); + m_iconLabel->setToolTip( "Please enter the same passphrase in both boxes." ); + } + + updateState(); +} + + +void +EncryptWidget::onCheckBoxStateChanged( int state ) +{ + m_passphraseLineEdit->setVisible( state ); + m_confirmLineEdit->setVisible( state ); + m_iconLabel->setVisible( state ); + m_passphraseLineEdit->clear(); + m_confirmLineEdit->clear(); + m_iconLabel->clear(); + + updateState(); +} diff --git a/src/modules/partition/gui/EncryptWidget.h b/src/modules/partition/gui/EncryptWidget.h new file mode 100644 index 000000000..b0686d982 --- /dev/null +++ b/src/modules/partition/gui/EncryptWidget.h @@ -0,0 +1,57 @@ +/* === This file is part of Calamares - === + * + * Copyright 2016, 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 ENCRYPTWIDGET_H +#define ENCRYPTWIDGET_H + +#include "ui_EncryptWidget.h" + +class EncryptWidget : public QWidget, private Ui::EncryptWidget +{ + Q_OBJECT + +public: + enum State : unsigned short + { + EncryptionDisabled = 0, + EncryptionUnconfirmed, + EncryptionConfirmed + }; + + explicit EncryptWidget( QWidget* parent = nullptr ); + + State state() const; + + QString passphrase() const; + +signals: + void stateChanged( State ); + +protected: + void changeEvent( QEvent* e ); + +private: + void updateState(); + void onPassphraseEdited(); + void onCheckBoxStateChanged( int state ); + + State m_state; +}; + +#endif // ENCRYPTWIDGET_H diff --git a/src/modules/partition/gui/EncryptWidget.ui b/src/modules/partition/gui/EncryptWidget.ui new file mode 100644 index 000000000..f6fdf9cbb --- /dev/null +++ b/src/modules/partition/gui/EncryptWidget.ui @@ -0,0 +1,58 @@ + + + EncryptWidget + + + + 0 + 0 + 822 + 59 + + + + Form + + + + + + En&crypt system + + + + + + + QLineEdit::Password + + + Passphrase + + + + + + + QLineEdit::Password + + + Confirm passphrase + + + + + + + + + + Qt::AlignCenter + + + + + + + +