OSDN Git Service

5407d6109cb85ede3ec91c281c054b65a27faca0
[qt-creator-jp/qt-creator-jp.git] / src / plugins / qt4projectmanager / qt-s60 / passphraseforkeydialog.cpp
1 /**************************************************************************
2 **
3 ** This file is part of Qt Creator
4 **
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
6 **
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
8 **
9 ** No Commercial Usage
10 **
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
14 ** this package.
15 **
16 ** GNU Lesser General Public License Usage
17 **
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file.  Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Nokia gives you certain additional
26 ** rights.  These rights are described in the Nokia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
31 **
32 **************************************************************************/
33
34 #include "passphraseforkeydialog.h"
35
36 #include <QtGui/QCheckBox>
37 #include <QtGui/QDialogButtonBox>
38 #include <QtGui/QLabel>
39 #include <QtGui/QLineEdit>
40 #include <QtGui/QPushButton>
41 #include <QtGui/QVBoxLayout>
42
43 using namespace Qt4ProjectManager;
44
45 PassphraseForKeyDialog::PassphraseForKeyDialog(const QString &keyName, QWidget *parent) :
46     QDialog(parent),
47     m_buttonBox(0),
48     m_saveCheckBox(0),
49     m_passphraseEdit(0)
50 {
51     QVBoxLayout *layout = new QVBoxLayout(this);
52
53     QHBoxLayout *hPasswordLayout = new QHBoxLayout;
54
55     QLabel *passphraseLabel = new QLabel(this);
56     passphraseLabel->setText(tr("Passphrase:"));
57     hPasswordLayout->addWidget(passphraseLabel);
58
59     m_passphraseEdit = new QLineEdit(this);
60     m_passphraseEdit->setEchoMode(QLineEdit::Password);
61     connect(m_passphraseEdit, SIGNAL(textChanged(QString)), this, SLOT(passphraseChanged()));
62     hPasswordLayout->addWidget(m_passphraseEdit);
63
64     m_saveCheckBox = new QCheckBox(this);
65     m_saveCheckBox->setText(tr("Save passphrase"));
66     m_saveCheckBox->setToolTip(tr("This is an insecure option. The password will be saved as plain text."));
67
68     m_buttonBox = new QDialogButtonBox(this);
69     m_buttonBox->setStandardButtons(QDialogButtonBox::Cancel|QDialogButtonBox::Ok);
70
71     connect(m_buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
72     connect(m_buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
73
74     layout->addLayout(hPasswordLayout);
75     layout->addWidget(m_saveCheckBox);
76     layout->addItem(new QSpacerItem(0, 10));
77     layout->addWidget(m_buttonBox);
78
79     setWindowTitle(tr("Passphrase for %1").arg(keyName));
80     setFixedSize(sizeHint());
81
82     passphraseChanged();
83 }
84
85 void PassphraseForKeyDialog::passphraseChanged()
86 {
87     // We tried the empty passphrase when we get here, so disallow it
88     Q_ASSERT(m_buttonBox->button(QDialogButtonBox::Ok));
89     m_buttonBox->button(QDialogButtonBox::Ok)->setEnabled(!m_passphraseEdit->text().isEmpty());
90 }
91
92 QString PassphraseForKeyDialog::passphrase() const
93 {
94     return m_passphraseEdit->text();
95 }
96
97 bool PassphraseForKeyDialog::savePassphrase() const
98 {
99     return m_saveCheckBox->isChecked();
100 }