#include "PasswordDialog.h"
+
#include <QLineEdit>
#include <QPushButton>
#include <QVBoxLayout>
#include <QtDebug>
#include <QLabel>
-PasswordDialog::PasswordDialog( QWidget *aParent, const QString &aPassword, const QString &aText, const QString &aTitle ) :
+PasswordDialog::PasswordDialog( const QString &aPassword, const QString &aText, const QString &aTitle, QWidget *aParent ) :
QDialog( aParent )
{
setWindowTitle( aTitle.isNull() ? tr( "Enter password" ) : aTitle );
setModal( true );
- // Store the password hash to iPasswordHash
- // ( aPassword should be allready encoded )
-// QCryptographicHash *hash = new QCryptographicHash( QCryptographicHash::Md5 );
-// hash->addData( aPassword.toUtf8() );
-// iPasswordHash = hash->result();
-// delete hash;
iPasswordHash = aPassword.toUtf8();
/* Create the layout:
QVBoxLayout *layout = new QVBoxLayout;
- if ( !aText.isNull() )
- {
- QLabel *text = new QLabel( aText );
- layout->addWidget( text );
- layout->addStretch();
- }
+ iText = new QLabel( aText );
+ layout->addWidget( iText );
+ layout->addStretch();
iPasswordEdit = new QLineEdit;
iPasswordEdit->setEchoMode( QLineEdit::Password );
layout->addSpacing( 5 );
layout->addLayout( buttonLayout );
- // Connect the buttons pressed signals to corresponding slots
- connect( buttonOK, SIGNAL( pressed() ), this, SLOT( okButtonPressed() ) );
- connect( buttonCancel, SIGNAL( pressed() ), this, SLOT( cancelButtonPressed() ) );
+ // Connect the user action signals to corresponding slots
+ connect( buttonOK, SIGNAL( released() ), this, SLOT( okButtonPressed() ) );
+ connect( buttonCancel, SIGNAL( released() ), this, SLOT( cancelButtonPressed() ) );
// Enable the layout
setLayout( layout );
QCryptographicHash *hash = new QCryptographicHash( QCryptographicHash::Md5 );
hash->addData( iPasswordEdit->text().toUtf8() );
QByteArray userpw = hash->result();
- delete hash;
+ delete hash;
+ close();
+
// Compare the password hashes and emit corresponding signal tellin if the password was correct
if ( iPasswordHash == userpw.toHex() )
{
emit passwordEntered( PasswordDialog::Incorrect );
qDebug() << "Incorrect password!";
}
-
- // Close the dialog
- close();
}
void PasswordDialog::cancelButtonPressed()
{
qDebug() << "PasswordDialog::cancelButtonPressed()";
-
- emit passwordEntered( PasswordDialog::Canceled );
-
+
close();
+ emit passwordEntered( PasswordDialog::Canceled );
}
-PasswordDialog * PasswordDialog::query( QWidget *aParent, const QString &aPassword, const QString &aText, const QString &aTitle )
+void PasswordDialog::update( const QString &aText )
{
- // Create a PasswordDialog instance and show it
- PasswordDialog* dlg = new PasswordDialog( aParent, aPassword, aText, aTitle );
- dlg->show();
- return dlg;
+ qDebug() << "PasswordDialog::update()";
+ iText->setText( aText );
}
-