Diffstat (limited to 'noncore/securityplugins/pin/pin.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/securityplugins/pin/pin.cpp | 67 |
1 files changed, 54 insertions, 13 deletions
diff --git a/noncore/securityplugins/pin/pin.cpp b/noncore/securityplugins/pin/pin.cpp index 2accb9c..f1c52c5 100644 --- a/noncore/securityplugins/pin/pin.cpp +++ b/noncore/securityplugins/pin/pin.cpp @@ -16,185 +16,226 @@ ** ** See http://www.trolltech.com/gpl/ for GPL licensing information. ** ** Contact info@trolltech.com if any conditions of this licensing are ** not clear to you. ** **********************************************************************/ #include "pin.h" #include "pinDialogBase.h" /* OPIE */ #include <opie2/odebug.h> #include <opie2/oapplication.h> /* QT */ #include <qpe/config.h> #include <qlabel.h> #include <qlineedit.h> #include <qtextview.h> #include <qstring.h> #include <qdialog.h> /* UNIX */ #include <unistd.h> #include <stdlib.h> #include <time.h> extern "C" char *crypt(const char *key, const char *salt); using Opie::Security::MultiauthConfigWidget; using Opie::Security::MultiauthPluginObject; /// set to TRUE when we press the 'Skip' button static bool isSkip = FALSE; /// PIN input graphical widget. /** * Inherits the PinDialogBase class defined originally in pinDialogBase.ui interface file. * \sa PinDlg and PinDialog (the class generated from the .ui file) * It comes from the original PIN locking code in Opie : * \sa http://dudu.dyn.2-h.org/opiedoxydoc/library_2password_8cpp-source.html */ class PinDialog : public PinDialogBase { Q_OBJECT public: PinDialog( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 ); ~PinDialog(); void clear(); void setPrompt( const QString& ); signals: /// emitted when we press the Enter button void passwordEntered( const QString& ); /// emitted when we press the Skip button void skip(); protected: bool eventFilter( QObject*, QEvent* ); private: void input( QString ); friend class PinPlugin; QString text; + + private slots: + void slotInput(); + void slotSkip(); + void slotOK(); + void slotBackspace(); }; /// Constructs a PinDialog widget, and initializes things PinDialog::PinDialog( QWidget* parent, const char* name, WFlags fl ) : PinDialogBase( parent, name, fl ) { QRect desk = oApp->desktop()->geometry(); if ( desk.width() < 220 ) { QFont f( font() ); f.setPointSize( 18 ); setFont( f ); f.setPointSize( 12 ); prompt->setFont( f ); } + connect ( button_0, SIGNAL( clicked()), SLOT( slotInput())); + connect ( button_1, SIGNAL( clicked()), SLOT( slotInput())); + connect ( button_2, SIGNAL( clicked()), SLOT( slotInput())); + connect ( button_3, SIGNAL( clicked()), SLOT( slotInput())); + connect ( button_4, SIGNAL( clicked()), SLOT( slotInput())); + connect ( button_5, SIGNAL( clicked()), SLOT( slotInput())); + connect ( button_6, SIGNAL( clicked()), SLOT( slotInput())); + connect ( button_7, SIGNAL( clicked()), SLOT( slotInput())); + connect ( button_8, SIGNAL( clicked()), SLOT( slotInput())); + connect ( button_9, SIGNAL( clicked()), SLOT( slotInput())); + connect ( button_Skip, SIGNAL( clicked()), SLOT( slotSkip())); + connect ( button_OK, SIGNAL( clicked()), SLOT( slotOK())); + button_0->installEventFilter( this ); button_1->installEventFilter( this ); button_2->installEventFilter( this ); button_3->installEventFilter( this ); button_4->installEventFilter( this ); button_5->installEventFilter( this ); button_6->installEventFilter( this ); button_7->installEventFilter( this ); button_8->installEventFilter( this ); button_9->installEventFilter( this ); button_Skip->installEventFilter( this ); button_OK->installEventFilter( this ); - setFocus(); + button_OK->setFocus(); } /// nothing to do PinDialog::~PinDialog() { // no need to delete child widgets, Qt does it all for us } -/// Record the pressed numbers, and the Skip and Enter commands +/// Handle keyboard events bool PinDialog::eventFilter( QObject*o, QEvent*e ) { - if ( e->type() == QEvent::MouseButtonRelease ) { - if ( o == button_OK ) { - emit passwordEntered( text ); - } - else if ( o == button_Skip ) { - isSkip = TRUE; - emit skip(); - } - else { - QLabel *l = (QLabel*)o; - input(l->text()); + if(e->type() == QEvent::KeyPress) { + switch(((QKeyEvent *)e)->key()) { + case Key_0...Key_9: + input(((QKeyEvent *)e)->text()); + return TRUE; + case Key_Backspace: + slotBackspace(); + return TRUE; } } return FALSE; } +void PinDialog::slotInput() +{ + QPushButton *l = (QPushButton*)sender(); + input(l->text().stripWhiteSpace()); +} + +void PinDialog::slotSkip() +{ + isSkip = TRUE; + emit skip(); +} + +void PinDialog::slotOK() +{ + emit passwordEntered( text ); +} + +void PinDialog::slotBackspace() +{ + if(text.length() > 0) { + text.truncate( text.length() - 1 ); + display->setText( text ); + } +} + void PinDialog::input( QString c ) { text += c; display->setText( text ); } void PinDialog::setPrompt( const QString& s ) { prompt->setText( s ); } void PinDialog::clear() { text = ""; input(""); } /// PIN dialog /** * Dialog containing the PinDialog widget (which asks for a PIN) and interfacing with its I/O. * \sa PinDialog */ class PinDlg : public QDialog { public: PinDlg( QWidget *parent, const char * name, bool modal, bool fullscreen = FALSE ) : QDialog( parent, name, modal, fullscreen ? WStyle_NoBorder | WStyle_Customize | WStyle_StaysOnTop : 0 ), modl(modal) { pinD = new PinDialog( this ); if ( fullscreen ) { QRect desk = oApp->desktop()->geometry(); setGeometry( 0, 0, desk.width(), desk.height() ); } connect( pinD, SIGNAL(passwordEntered(const QString&)), this, SLOT(accept()) ); connect( pinD, SIGNAL(skip()), this, SLOT(accept()) ); } void resizeEvent( QResizeEvent * ) { pinD->resize( size() ); } void reset() { pinD->clear(); } /// Slot receiving the Skip or Enter commands, and closing the QDialog void accept() { if ( !modl ) oApp->exit_loop(); QDialog::accept(); } PinDialog *pinD; bool modl; }; /// generate a fairly random salt and return the PIN hashed by crypt() |