passphraseforkeydialog.cpp 3.28 KB
Newer Older
Pawel Polanski's avatar
Pawel Polanski committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** GNU Lesser General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://qt.nokia.com/contact.
**
**************************************************************************/

30
31
#include "passphraseforkeydialog.h"

32
#include <QtGui/QCheckBox>
33
34
35
#include <QtGui/QDialogButtonBox>
#include <QtGui/QLabel>
#include <QtGui/QLineEdit>
36
37
#include <QtGui/QPushButton>
#include <QtGui/QVBoxLayout>
38
39
40

using namespace Qt4ProjectManager;

41
42
43
PassphraseForKeyDialog::PassphraseForKeyDialog(const QString &keyName, QWidget *parent) :
    QDialog(parent),
    m_buttonBox(0),
Pawel Polanski's avatar
Pawel Polanski committed
44
45
    m_saveCheckBox(0),
    m_passphraseEdit(0)
46
{
47
48
    QVBoxLayout *layout = new QVBoxLayout(this);

49
    QHBoxLayout *hPasswordLayout = new QHBoxLayout;
50
51
52

    QLabel *passphraseLabel = new QLabel(this);
    passphraseLabel->setText(tr("Passphrase:"));
53
    hPasswordLayout->addWidget(passphraseLabel);
54

55
56
57
58
    m_passphraseEdit = new QLineEdit(this);
    m_passphraseEdit->setEchoMode(QLineEdit::Password);
    connect(m_passphraseEdit, SIGNAL(textChanged(QString)), this, SLOT(passphraseChanged()));
    hPasswordLayout->addWidget(m_passphraseEdit);
59

60
61
62
    m_saveCheckBox = new QCheckBox(this);
    m_saveCheckBox->setText(tr("Save passphrase"));
    m_saveCheckBox->setToolTip(tr("This is an insecure option. The password will be saved as plain text."));
63

64
65
    m_buttonBox = new QDialogButtonBox(this);
    m_buttonBox->setStandardButtons(QDialogButtonBox::Cancel|QDialogButtonBox::Ok);
66

67
68
    connect(m_buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
    connect(m_buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
69

70
    layout->addLayout(hPasswordLayout);
71
    layout->addWidget(m_saveCheckBox);
72
    layout->addItem(new QSpacerItem(0, 10));
73
    layout->addWidget(m_buttonBox);
74

75
    setWindowTitle(tr("Passphrase for %1").arg(keyName));
76
    setFixedSize(sizeHint());
77

78
    passphraseChanged();
79
80
}

81
void PassphraseForKeyDialog::passphraseChanged()
82
{
83
84
85
    // We tried the empty passphrase when we get here, so disallow it
    Q_ASSERT(m_buttonBox->button(QDialogButtonBox::Ok));
    m_buttonBox->button(QDialogButtonBox::Ok)->setEnabled(!m_passphraseEdit->text().isEmpty());
86
87
88
89
}

QString PassphraseForKeyDialog::passphrase() const
{
90
    return m_passphraseEdit->text();
91
92
93
94
}

bool PassphraseForKeyDialog::savePassphrase() const
{
95
    return m_saveCheckBox->isChecked();
96
}