OSDN Git Service

Symbian: Fix up passphrase dialog
authorTobias Hunger <tobias.hunger@nokia.com>
Wed, 24 Nov 2010 14:53:25 +0000 (15:53 +0100)
committerTobias Hunger <tobias.hunger@nokia.com>
Wed, 24 Nov 2010 16:22:17 +0000 (17:22 +0100)
Clean up passphrase dialog to get rid of warnings at runtime.
While at it: Make sure we do not get an empty passphrase.

Reviewed-by: Pawel Polanski
src/plugins/qt4projectmanager/qt-s60/passphraseforkeydialog.cpp
src/plugins/qt4projectmanager/qt-s60/passphraseforkeydialog.h

index c636e93..3e2e7ad 100644 (file)
 
 #include "passphraseforkeydialog.h"
 
+#include <QtGui/QCheckBox>
 #include <QtGui/QDialogButtonBox>
 #include <QtGui/QLabel>
-#include <QtGui/QVBoxLayout>
 #include <QtGui/QLineEdit>
-#include <QtGui/QCheckBox>
+#include <QtGui/QPushButton>
+#include <QtGui/QVBoxLayout>
 
 using namespace Qt4ProjectManager;
 
-PassphraseForKeyDialog::PassphraseForKeyDialog(const QString &keyName, QWidget *parent)
-    : QDialog(parent)
+PassphraseForKeyDialog::PassphraseForKeyDialog(const QString &keyName, QWidget *parent) :
+    QDialog(parent),
+    m_buttonBox(0),
+    m_passphraseEdit(0),
+    m_saveCheckBox(0)
 {
     QVBoxLayout *layout = new QVBoxLayout(this);
-    setLayout(layout);
 
-    QHBoxLayout *hPasswordLayout = new QHBoxLayout(this);
+    QHBoxLayout *hPasswordLayout = new QHBoxLayout;
 
     QLabel *passphraseLabel = new QLabel(this);
     passphraseLabel->setText(tr("Passphrase:"));
-    passphraseLabel->setObjectName(QString::fromUtf8("passphraseLabel"));
-
     hPasswordLayout->addWidget(passphraseLabel);
 
-    QLineEdit *passphraseLineEdit = new QLineEdit(this);
-    passphraseLineEdit->setObjectName(QString::fromUtf8("passphraseLineEdit"));
-    passphraseLineEdit->setEchoMode(QLineEdit::Password);
-
-    connect(passphraseLineEdit, SIGNAL(textChanged(QString)), this, SLOT(setPassphrase(QString)));
+    m_passphraseEdit = new QLineEdit(this);
+    m_passphraseEdit->setEchoMode(QLineEdit::Password);
+    connect(m_passphraseEdit, SIGNAL(textChanged(QString)), this, SLOT(passphraseChanged()));
+    hPasswordLayout->addWidget(m_passphraseEdit);
 
-    hPasswordLayout->addWidget(passphraseLineEdit);
+    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."));
 
-    m_checkBox = new QCheckBox(this);
-    m_checkBox->setText(tr("Save passphrase"));
-    m_checkBox->setObjectName(QString::fromUtf8("checkBox"));
-    m_checkBox->setToolTip(tr("This is an insecure option. The password will be saved as a plain text."));
+    m_buttonBox = new QDialogButtonBox(this);
+    m_buttonBox->setStandardButtons(QDialogButtonBox::Cancel|QDialogButtonBox::Ok);
 
-    QDialogButtonBox *buttonBox = new QDialogButtonBox(this);
-    buttonBox->setObjectName(QString::fromUtf8("buttonBox"));
-    buttonBox->setStandardButtons(QDialogButtonBox::Cancel|QDialogButtonBox::Ok);
-
-    connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
-    connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
+    connect(m_buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
+    connect(m_buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
 
     layout->addLayout(hPasswordLayout);
-    layout->addWidget(m_checkBox);
+    layout->addWidget(m_saveCheckBox);
     layout->addItem(new QSpacerItem(0, 10));
-    layout->addWidget(buttonBox);
+    layout->addWidget(m_buttonBox);
 
     setWindowTitle(tr("Passphrase for %1").arg(keyName));
-    setFixedSize( sizeHint() );
-}
-
-void PassphraseForKeyDialog::accept()
-{
-    done(1);
-}
+    setFixedSize(sizeHint());
 
-void PassphraseForKeyDialog::reject()
-{
-    done(0);
+    passphraseChanged();
 }
 
-void PassphraseForKeyDialog::setPassphrase(const QString &passphrase)
+void PassphraseForKeyDialog::passphraseChanged()
 {
-    m_passphrase = passphrase;
+    // 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());
 }
 
 QString PassphraseForKeyDialog::passphrase() const
 {
-    return m_passphrase;
+    return m_passphraseEdit->text();
 }
 
 bool PassphraseForKeyDialog::savePassphrase() const
 {
-    return m_checkBox->isChecked();
+    return m_saveCheckBox->isChecked();
 }
index 326e7f8..4fe4c00 100644 (file)
@@ -33,6 +33,8 @@
 #include <QtGui/QDialog>
 
 QT_FORWARD_DECLARE_CLASS(QCheckBox);
+QT_FORWARD_DECLARE_CLASS(QDialogButtonBox);
+QT_FORWARD_DECLARE_CLASS(QLineEdit);
 
 namespace Qt4ProjectManager {
 
@@ -46,14 +48,12 @@ public:
     bool savePassphrase() const;
 
 protected slots:
-    void accept();
-    void reject();
-    void setPassphrase(const QString &passphrase);
+    void passphraseChanged();
 
 private:
-    QCheckBox *m_checkBox;
-
-    QString m_passphrase;
+    QDialogButtonBox *m_buttonBox;
+    QCheckBox *m_saveCheckBox;
+    QLineEdit *m_passphraseEdit;
 };
 
 } // namespace Qt4ProjectManager