source: calamares/trunk/fuentes/src/modules/partition/gui/EncryptWidget.cpp @ 7538

Last change on this file since 7538 was 7538, checked in by kbut, 13 months ago

sync with github

File size: 4.2 KB
Line 
1/* === This file is part of Calamares - <https://github.com/calamares> ===
2 *
3 *   Copyright 2016, Teo Mrnjavac <teo@kde.org>
4 *
5 *   Calamares is free software: you can redistribute it and/or modify
6 *   it under the terms of the GNU General Public License as published by
7 *   the Free Software Foundation, either version 3 of the License, or
8 *   (at your option) any later version.
9 *
10 *   Calamares is distributed in the hope that it will be useful,
11 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
12 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 *   GNU General Public License for more details.
14 *
15 *   You should have received a copy of the GNU General Public License
16 *   along with Calamares. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19
20#include "EncryptWidget.h"
21
22#include <utils/CalamaresUtilsGui.h>
23
24EncryptWidget::EncryptWidget( QWidget* parent )
25    : QWidget( parent )
26    , m_state( EncryptionDisabled )
27{
28    setupUi( this );
29
30    m_iconLabel->setFixedWidth( m_iconLabel->height() );
31    m_passphraseLineEdit->hide();
32    m_confirmLineEdit->hide();
33    m_iconLabel->hide();
34
35    connect( m_encryptCheckBox, &QCheckBox::stateChanged,
36             this, &EncryptWidget::onCheckBoxStateChanged );
37    connect( m_passphraseLineEdit, &QLineEdit::textEdited,
38             this, &EncryptWidget::onPassphraseEdited );
39    connect( m_confirmLineEdit, &QLineEdit::textEdited,
40             this, &EncryptWidget::onPassphraseEdited );
41
42    setFixedHeight( m_passphraseLineEdit->height() ); // Avoid jumping up and down
43    updateState();
44}
45
46
47void
48EncryptWidget::reset()
49{
50    m_passphraseLineEdit->clear();
51    m_confirmLineEdit->clear();
52
53    m_encryptCheckBox->setChecked( false );
54}
55
56
57EncryptWidget::State
58EncryptWidget::state() const
59{
60    return m_state;
61}
62
63
64void
65EncryptWidget::setText( const QString& text )
66{
67    m_encryptCheckBox->setText( text );
68}
69
70
71QString
72EncryptWidget::passphrase() const
73{
74    if ( m_state == EncryptionConfirmed )
75        return m_passphraseLineEdit->text();
76    return QString();
77}
78
79
80void
81EncryptWidget::changeEvent( QEvent* e )
82{
83    QWidget::changeEvent( e );
84    switch ( e->type() )
85    {
86    case QEvent::LanguageChange:
87        retranslateUi( this );
88        break;
89    default:
90        break;
91    }
92}
93
94
95void
96EncryptWidget::updateState()
97{
98    State newState;
99    if ( m_encryptCheckBox->isChecked() )
100    {
101        if ( !m_passphraseLineEdit->text().isEmpty() &&
102             m_passphraseLineEdit->text() == m_confirmLineEdit->text() )
103        {
104            newState = EncryptionConfirmed;
105        }
106        else
107        {
108            newState = EncryptionUnconfirmed;
109        }
110    }
111    else
112    {
113        newState = EncryptionDisabled;
114    }
115
116    if ( newState != m_state )
117    {
118        m_state = newState;
119        emit stateChanged( m_state );
120    }
121}
122
123
124void
125EncryptWidget::onPassphraseEdited()
126{
127    if ( !m_iconLabel->isVisible() )
128        m_iconLabel->show();
129
130    QString p1 = m_passphraseLineEdit->text();
131    QString p2 = m_confirmLineEdit->text();
132
133    m_iconLabel->setToolTip( QString() );
134    if ( p1.isEmpty() && p2.isEmpty() )
135    {
136        m_iconLabel->clear();
137    }
138    else if ( p1 == p2 )
139    {
140        m_iconLabel->setFixedWidth( m_iconLabel->height() );
141        m_iconLabel->setPixmap( CalamaresUtils::defaultPixmap( CalamaresUtils::Yes,
142                                                               CalamaresUtils::Original,
143                                                               m_iconLabel->size() ) );
144    }
145    else
146    {
147        m_iconLabel->setFixedWidth( m_iconLabel->height() );
148        m_iconLabel->setPixmap( CalamaresUtils::defaultPixmap( CalamaresUtils::No,
149                                                               CalamaresUtils::Original,
150                                                               m_iconLabel->size() ) );
151        m_iconLabel->setToolTip( tr( "Please enter the same passphrase in both boxes." ) );
152    }
153
154    updateState();
155}
156
157
158void
159EncryptWidget::onCheckBoxStateChanged( int state )
160{
161    m_passphraseLineEdit->setVisible( state );
162    m_confirmLineEdit->setVisible( state );
163    m_iconLabel->setVisible( state );
164    m_passphraseLineEdit->clear();
165    m_confirmLineEdit->clear();
166    m_iconLabel->clear();
167
168    updateState();
169}
Note: See TracBrowser for help on using the repository browser.