2017-12-20 14:39:09 +01:00
|
|
|
/* === This file is part of Calamares - <https://github.com/calamares> ===
|
2016-04-22 16:00:19 +02:00
|
|
|
*
|
|
|
|
* Copyright 2016, Teo Mrnjavac <teo@kde.org>
|
2020-03-10 03:20:03 +01:00
|
|
|
* Copyright 2020, Adriaan de Groot <groot@kde.org>
|
2016-04-22 16:00:19 +02:00
|
|
|
*
|
|
|
|
* 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 <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include "EncryptWidget.h"
|
|
|
|
|
2020-03-10 03:20:03 +01:00
|
|
|
#include "ui_EncryptWidget.h"
|
|
|
|
|
2020-03-10 02:45:40 +01:00
|
|
|
#include "utils/CalamaresUtilsGui.h"
|
2020-03-10 03:20:03 +01:00
|
|
|
#include "utils/Retranslator.h"
|
2016-04-22 16:00:19 +02:00
|
|
|
|
|
|
|
EncryptWidget::EncryptWidget( QWidget* parent )
|
|
|
|
: QWidget( parent )
|
2020-03-10 03:20:03 +01:00
|
|
|
, m_ui( new Ui::EncryptWidget )
|
|
|
|
, m_state( Encryption::Disabled )
|
2016-04-22 16:00:19 +02:00
|
|
|
{
|
2020-03-10 03:20:03 +01:00
|
|
|
m_ui->setupUi( this );
|
2016-04-22 16:00:19 +02:00
|
|
|
|
2020-03-10 03:20:03 +01:00
|
|
|
m_ui->m_iconLabel->setFixedWidth( m_ui->m_iconLabel->height() );
|
|
|
|
m_ui->m_passphraseLineEdit->hide();
|
|
|
|
m_ui->m_confirmLineEdit->hide();
|
|
|
|
m_ui->m_iconLabel->hide();
|
2016-04-22 16:00:19 +02:00
|
|
|
|
2020-03-10 03:20:03 +01:00
|
|
|
connect( m_ui->m_encryptCheckBox, &QCheckBox::stateChanged, this, &EncryptWidget::onCheckBoxStateChanged );
|
|
|
|
connect( m_ui->m_passphraseLineEdit, &QLineEdit::textEdited, this, &EncryptWidget::onPassphraseEdited );
|
|
|
|
connect( m_ui->m_confirmLineEdit, &QLineEdit::textEdited, this, &EncryptWidget::onPassphraseEdited );
|
2016-04-22 16:00:19 +02:00
|
|
|
|
2020-03-10 03:20:03 +01:00
|
|
|
setFixedHeight( m_ui->m_passphraseLineEdit->height() ); // Avoid jumping up and down
|
2016-04-22 16:00:19 +02:00
|
|
|
updateState();
|
2020-03-10 03:20:03 +01:00
|
|
|
|
|
|
|
CALAMARES_RETRANSLATE_SLOT( &EncryptWidget::retranslate )
|
2016-04-22 16:00:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-06-10 14:40:49 +02:00
|
|
|
void
|
|
|
|
EncryptWidget::reset()
|
|
|
|
{
|
2020-03-10 03:20:03 +01:00
|
|
|
m_ui->m_passphraseLineEdit->clear();
|
|
|
|
m_ui->m_confirmLineEdit->clear();
|
2016-06-10 14:40:49 +02:00
|
|
|
|
2020-03-10 03:20:03 +01:00
|
|
|
m_ui->m_encryptCheckBox->setChecked( false );
|
2016-06-10 14:40:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-03-10 03:20:03 +01:00
|
|
|
EncryptWidget::Encryption
|
2016-04-22 16:00:19 +02:00
|
|
|
EncryptWidget::state() const
|
|
|
|
{
|
|
|
|
return m_state;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-06-10 14:40:49 +02:00
|
|
|
void
|
|
|
|
EncryptWidget::setText( const QString& text )
|
|
|
|
{
|
2020-03-10 03:20:03 +01:00
|
|
|
m_ui->m_encryptCheckBox->setText( text );
|
2016-06-10 14:40:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-04-22 16:00:19 +02:00
|
|
|
QString
|
|
|
|
EncryptWidget::passphrase() const
|
|
|
|
{
|
2020-03-10 03:20:03 +01:00
|
|
|
if ( m_state == Encryption::Confirmed )
|
|
|
|
{
|
|
|
|
return m_ui->m_passphraseLineEdit->text();
|
|
|
|
}
|
2016-04-22 16:00:19 +02:00
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2020-03-10 03:20:03 +01:00
|
|
|
EncryptWidget::retranslate()
|
2016-04-22 16:00:19 +02:00
|
|
|
{
|
2020-03-10 03:20:03 +01:00
|
|
|
m_ui->retranslateUi( this );
|
|
|
|
onPassphraseEdited(); // For the tooltip
|
2016-04-22 16:00:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
EncryptWidget::updateState()
|
|
|
|
{
|
2020-03-10 03:20:03 +01:00
|
|
|
Encryption newState;
|
|
|
|
if ( m_ui->m_encryptCheckBox->isChecked() )
|
2016-04-22 16:00:19 +02:00
|
|
|
{
|
2020-03-10 03:20:03 +01:00
|
|
|
if ( !m_ui->m_passphraseLineEdit->text().isEmpty()
|
|
|
|
&& m_ui->m_passphraseLineEdit->text() == m_ui->m_confirmLineEdit->text() )
|
2016-04-22 16:00:19 +02:00
|
|
|
{
|
2020-03-10 03:20:03 +01:00
|
|
|
newState = Encryption::Confirmed;
|
2016-04-22 16:00:19 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-03-10 03:20:03 +01:00
|
|
|
newState = Encryption::Unconfirmed;
|
2016-04-22 16:00:19 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-03-10 03:20:03 +01:00
|
|
|
newState = Encryption::Disabled;
|
2016-04-22 16:00:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( newState != m_state )
|
|
|
|
{
|
|
|
|
m_state = newState;
|
|
|
|
emit stateChanged( m_state );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-10 03:20:03 +01:00
|
|
|
///@brief Give @p label the @p pixmap from the standard-pixmaps
|
|
|
|
static void
|
|
|
|
applyPixmap( QLabel* label, CalamaresUtils::ImageType pixmap )
|
|
|
|
{
|
|
|
|
label->setFixedWidth( label->height() );
|
|
|
|
label->setPixmap( CalamaresUtils::defaultPixmap( pixmap, CalamaresUtils::Original, label->size() ) );
|
|
|
|
}
|
2016-04-22 16:00:19 +02:00
|
|
|
|
|
|
|
void
|
|
|
|
EncryptWidget::onPassphraseEdited()
|
|
|
|
{
|
2020-03-10 03:20:03 +01:00
|
|
|
if ( !m_ui->m_iconLabel->isVisible() )
|
|
|
|
{
|
|
|
|
m_ui->m_iconLabel->show();
|
|
|
|
}
|
2016-04-22 16:00:19 +02:00
|
|
|
|
2020-03-10 03:20:03 +01:00
|
|
|
QString p1 = m_ui->m_passphraseLineEdit->text();
|
|
|
|
QString p2 = m_ui->m_confirmLineEdit->text();
|
2016-04-22 16:00:19 +02:00
|
|
|
|
2020-03-10 03:20:03 +01:00
|
|
|
m_ui->m_iconLabel->setToolTip( QString() );
|
2016-04-22 16:00:19 +02:00
|
|
|
if ( p1.isEmpty() && p2.isEmpty() )
|
|
|
|
{
|
2020-07-29 13:42:56 +02:00
|
|
|
applyPixmap( m_ui->m_iconLabel, CalamaresUtils::StatusWarning );
|
|
|
|
m_ui->m_iconLabel->setToolTip( tr( "Please enter the same passphrase in both boxes." ) );
|
2016-04-22 16:00:19 +02:00
|
|
|
}
|
|
|
|
else if ( p1 == p2 )
|
|
|
|
{
|
2020-07-29 13:42:56 +02:00
|
|
|
applyPixmap( m_ui->m_iconLabel, CalamaresUtils::StatusOk );
|
2016-04-22 16:00:19 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-07-29 13:42:56 +02:00
|
|
|
applyPixmap( m_ui->m_iconLabel, CalamaresUtils::StatusError );
|
2020-03-10 03:20:03 +01:00
|
|
|
m_ui->m_iconLabel->setToolTip( tr( "Please enter the same passphrase in both boxes." ) );
|
2016-04-22 16:00:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
updateState();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2020-03-10 03:20:03 +01:00
|
|
|
EncryptWidget::onCheckBoxStateChanged( int checked )
|
2016-04-22 16:00:19 +02:00
|
|
|
{
|
2020-03-10 03:20:03 +01:00
|
|
|
// @p checked is a Qt::CheckState, 0 is "unchecked" and 2 is "checked"
|
|
|
|
m_ui->m_passphraseLineEdit->setVisible( checked );
|
|
|
|
m_ui->m_confirmLineEdit->setVisible( checked );
|
|
|
|
m_ui->m_iconLabel->setVisible( checked );
|
|
|
|
m_ui->m_passphraseLineEdit->clear();
|
|
|
|
m_ui->m_confirmLineEdit->clear();
|
|
|
|
m_ui->m_iconLabel->clear();
|
2016-04-22 16:00:19 +02:00
|
|
|
|
|
|
|
updateState();
|
|
|
|
}
|