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 @@ | |||
16 | ** | 16 | ** |
17 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 17 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
18 | ** | 18 | ** |
19 | ** Contact info@trolltech.com if any conditions of this licensing are | 19 | ** Contact info@trolltech.com if any conditions of this licensing are |
20 | ** not clear to you. | 20 | ** not clear to you. |
21 | ** | 21 | ** |
22 | **********************************************************************/ | 22 | **********************************************************************/ |
23 | 23 | ||
24 | #include "pin.h" | 24 | #include "pin.h" |
25 | #include "pinDialogBase.h" | 25 | #include "pinDialogBase.h" |
26 | /* OPIE */ | 26 | /* OPIE */ |
27 | #include <opie2/odebug.h> | 27 | #include <opie2/odebug.h> |
28 | #include <opie2/oapplication.h> | 28 | #include <opie2/oapplication.h> |
29 | /* QT */ | 29 | /* QT */ |
30 | #include <qpe/config.h> | 30 | #include <qpe/config.h> |
31 | #include <qlabel.h> | 31 | #include <qlabel.h> |
32 | #include <qlineedit.h> | 32 | #include <qlineedit.h> |
33 | #include <qtextview.h> | 33 | #include <qtextview.h> |
34 | #include <qstring.h> | 34 | #include <qstring.h> |
35 | #include <qdialog.h> | 35 | #include <qdialog.h> |
36 | /* UNIX */ | 36 | /* UNIX */ |
37 | #include <unistd.h> | 37 | #include <unistd.h> |
38 | #include <stdlib.h> | 38 | #include <stdlib.h> |
39 | #include <time.h> | 39 | #include <time.h> |
40 | 40 | ||
41 | extern "C" char *crypt(const char *key, const char *salt); | 41 | extern "C" char *crypt(const char *key, const char *salt); |
42 | 42 | ||
43 | using Opie::Security::MultiauthConfigWidget; | 43 | using Opie::Security::MultiauthConfigWidget; |
44 | using Opie::Security::MultiauthPluginObject; | 44 | using Opie::Security::MultiauthPluginObject; |
45 | 45 | ||
46 | /// set to TRUE when we press the 'Skip' button | 46 | /// set to TRUE when we press the 'Skip' button |
47 | static bool isSkip = FALSE; | 47 | static bool isSkip = FALSE; |
48 | 48 | ||
49 | /// PIN input graphical widget. | 49 | /// PIN input graphical widget. |
50 | /** | 50 | /** |
51 | * Inherits the PinDialogBase class defined originally in pinDialogBase.ui interface file. | 51 | * Inherits the PinDialogBase class defined originally in pinDialogBase.ui interface file. |
52 | * \sa PinDlg and PinDialog (the class generated from the .ui file) | 52 | * \sa PinDlg and PinDialog (the class generated from the .ui file) |
53 | * It comes from the original PIN locking code in Opie : | 53 | * It comes from the original PIN locking code in Opie : |
54 | * \sa http://dudu.dyn.2-h.org/opiedoxydoc/library_2password_8cpp-source.html | 54 | * \sa http://dudu.dyn.2-h.org/opiedoxydoc/library_2password_8cpp-source.html |
55 | */ | 55 | */ |
56 | class PinDialog : public PinDialogBase | 56 | class PinDialog : public PinDialogBase |
57 | { | 57 | { |
58 | Q_OBJECT | 58 | Q_OBJECT |
59 | 59 | ||
60 | public: | 60 | public: |
61 | PinDialog( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 ); | 61 | PinDialog( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 ); |
62 | ~PinDialog(); | 62 | ~PinDialog(); |
63 | 63 | ||
64 | void clear(); | 64 | void clear(); |
65 | void setPrompt( const QString& ); | 65 | void setPrompt( const QString& ); |
66 | 66 | ||
67 | signals: | 67 | signals: |
68 | /// emitted when we press the Enter button | 68 | /// emitted when we press the Enter button |
69 | void passwordEntered( const QString& ); | 69 | void passwordEntered( const QString& ); |
70 | /// emitted when we press the Skip button | 70 | /// emitted when we press the Skip button |
71 | void skip(); | 71 | void skip(); |
72 | 72 | ||
73 | protected: | 73 | protected: |
74 | bool eventFilter( QObject*, QEvent* ); | 74 | bool eventFilter( QObject*, QEvent* ); |
75 | 75 | ||
76 | private: | 76 | private: |
77 | void input( QString ); | 77 | void input( QString ); |
78 | friend class PinPlugin; | 78 | friend class PinPlugin; |
79 | QString text; | 79 | QString text; |
80 | |||
81 | private slots: | ||
82 | void slotInput(); | ||
83 | void slotSkip(); | ||
84 | void slotOK(); | ||
85 | void slotBackspace(); | ||
80 | }; | 86 | }; |
81 | 87 | ||
82 | 88 | ||
83 | /// Constructs a PinDialog widget, and initializes things | 89 | /// Constructs a PinDialog widget, and initializes things |
84 | PinDialog::PinDialog( QWidget* parent, const char* name, WFlags fl ) | 90 | PinDialog::PinDialog( QWidget* parent, const char* name, WFlags fl ) |
85 | : PinDialogBase( parent, name, fl ) | 91 | : PinDialogBase( parent, name, fl ) |
86 | { | 92 | { |
87 | QRect desk = oApp->desktop()->geometry(); | 93 | QRect desk = oApp->desktop()->geometry(); |
88 | 94 | ||
89 | if ( desk.width() < 220 ) { | 95 | if ( desk.width() < 220 ) { |
90 | QFont f( font() ); | 96 | QFont f( font() ); |
91 | f.setPointSize( 18 ); | 97 | f.setPointSize( 18 ); |
92 | setFont( f ); | 98 | setFont( f ); |
93 | f.setPointSize( 12 ); | 99 | f.setPointSize( 12 ); |
94 | prompt->setFont( f ); | 100 | prompt->setFont( f ); |
95 | } | 101 | } |
96 | 102 | ||
103 | connect ( button_0, SIGNAL( clicked()), SLOT( slotInput())); | ||
104 | connect ( button_1, SIGNAL( clicked()), SLOT( slotInput())); | ||
105 | connect ( button_2, SIGNAL( clicked()), SLOT( slotInput())); | ||
106 | connect ( button_3, SIGNAL( clicked()), SLOT( slotInput())); | ||
107 | connect ( button_4, SIGNAL( clicked()), SLOT( slotInput())); | ||
108 | connect ( button_5, SIGNAL( clicked()), SLOT( slotInput())); | ||
109 | connect ( button_6, SIGNAL( clicked()), SLOT( slotInput())); | ||
110 | connect ( button_7, SIGNAL( clicked()), SLOT( slotInput())); | ||
111 | connect ( button_8, SIGNAL( clicked()), SLOT( slotInput())); | ||
112 | connect ( button_9, SIGNAL( clicked()), SLOT( slotInput())); | ||
113 | connect ( button_Skip, SIGNAL( clicked()), SLOT( slotSkip())); | ||
114 | connect ( button_OK, SIGNAL( clicked()), SLOT( slotOK())); | ||
115 | |||
97 | button_0->installEventFilter( this ); | 116 | button_0->installEventFilter( this ); |
98 | button_1->installEventFilter( this ); | 117 | button_1->installEventFilter( this ); |
99 | button_2->installEventFilter( this ); | 118 | button_2->installEventFilter( this ); |
100 | button_3->installEventFilter( this ); | 119 | button_3->installEventFilter( this ); |
101 | button_4->installEventFilter( this ); | 120 | button_4->installEventFilter( this ); |
102 | button_5->installEventFilter( this ); | 121 | button_5->installEventFilter( this ); |
103 | button_6->installEventFilter( this ); | 122 | button_6->installEventFilter( this ); |
104 | button_7->installEventFilter( this ); | 123 | button_7->installEventFilter( this ); |
105 | button_8->installEventFilter( this ); | 124 | button_8->installEventFilter( this ); |
106 | button_9->installEventFilter( this ); | 125 | button_9->installEventFilter( this ); |
107 | button_Skip->installEventFilter( this ); | 126 | button_Skip->installEventFilter( this ); |
108 | button_OK->installEventFilter( this ); | 127 | button_OK->installEventFilter( this ); |
109 | setFocus(); | 128 | button_OK->setFocus(); |
110 | } | 129 | } |
111 | 130 | ||
112 | /// nothing to do | 131 | /// nothing to do |
113 | PinDialog::~PinDialog() | 132 | PinDialog::~PinDialog() |
114 | { | 133 | { |
115 | // no need to delete child widgets, Qt does it all for us | 134 | // no need to delete child widgets, Qt does it all for us |
116 | } | 135 | } |
117 | 136 | ||
118 | /// Record the pressed numbers, and the Skip and Enter commands | 137 | /// Handle keyboard events |
119 | bool PinDialog::eventFilter( QObject*o, QEvent*e ) | 138 | bool PinDialog::eventFilter( QObject*o, QEvent*e ) |
120 | { | 139 | { |
121 | if ( e->type() == QEvent::MouseButtonRelease ) { | 140 | if(e->type() == QEvent::KeyPress) { |
122 | if ( o == button_OK ) { | 141 | switch(((QKeyEvent *)e)->key()) { |
123 | emit passwordEntered( text ); | 142 | case Key_0...Key_9: |
124 | } | 143 | input(((QKeyEvent *)e)->text()); |
125 | else if ( o == button_Skip ) { | 144 | return TRUE; |
126 | isSkip = TRUE; | 145 | case Key_Backspace: |
127 | emit skip(); | 146 | slotBackspace(); |
128 | } | 147 | return TRUE; |
129 | else { | ||
130 | QLabel *l = (QLabel*)o; | ||
131 | input(l->text()); | ||
132 | } | 148 | } |
133 | } | 149 | } |
134 | return FALSE; | 150 | return FALSE; |
135 | } | 151 | } |
136 | 152 | ||
153 | void PinDialog::slotInput() | ||
154 | { | ||
155 | QPushButton *l = (QPushButton*)sender(); | ||
156 | input(l->text().stripWhiteSpace()); | ||
157 | } | ||
158 | |||
159 | void PinDialog::slotSkip() | ||
160 | { | ||
161 | isSkip = TRUE; | ||
162 | emit skip(); | ||
163 | } | ||
164 | |||
165 | void PinDialog::slotOK() | ||
166 | { | ||
167 | emit passwordEntered( text ); | ||
168 | } | ||
169 | |||
170 | void PinDialog::slotBackspace() | ||
171 | { | ||
172 | if(text.length() > 0) { | ||
173 | text.truncate( text.length() - 1 ); | ||
174 | display->setText( text ); | ||
175 | } | ||
176 | } | ||
177 | |||
137 | void PinDialog::input( QString c ) | 178 | void PinDialog::input( QString c ) |
138 | { | 179 | { |
139 | text += c; | 180 | text += c; |
140 | display->setText( text ); | 181 | display->setText( text ); |
141 | } | 182 | } |
142 | 183 | ||
143 | void PinDialog::setPrompt( const QString& s ) | 184 | void PinDialog::setPrompt( const QString& s ) |
144 | { | 185 | { |
145 | prompt->setText( s ); | 186 | prompt->setText( s ); |
146 | } | 187 | } |
147 | 188 | ||
148 | void PinDialog::clear() | 189 | void PinDialog::clear() |
149 | { | 190 | { |
150 | text = ""; | 191 | text = ""; |
151 | input(""); | 192 | input(""); |
152 | } | 193 | } |
153 | 194 | ||
154 | /// PIN dialog | 195 | /// PIN dialog |
155 | /** | 196 | /** |
156 | * Dialog containing the PinDialog widget (which asks for a PIN) and interfacing with its I/O. | 197 | * Dialog containing the PinDialog widget (which asks for a PIN) and interfacing with its I/O. |
157 | * \sa PinDialog | 198 | * \sa PinDialog |
158 | */ | 199 | */ |
159 | class PinDlg : public QDialog | 200 | class PinDlg : public QDialog |
160 | { | 201 | { |
161 | public: | 202 | public: |
162 | PinDlg( QWidget *parent, const char * name, bool modal, bool fullscreen = FALSE ) | 203 | PinDlg( QWidget *parent, const char * name, bool modal, bool fullscreen = FALSE ) |
163 | : QDialog( parent, name, modal, fullscreen ? WStyle_NoBorder | WStyle_Customize | WStyle_StaysOnTop : 0 ), | 204 | : QDialog( parent, name, modal, fullscreen ? WStyle_NoBorder | WStyle_Customize | WStyle_StaysOnTop : 0 ), |
164 | modl(modal) | 205 | modl(modal) |
165 | { | 206 | { |
166 | pinD = new PinDialog( this ); | 207 | pinD = new PinDialog( this ); |
167 | 208 | ||
168 | if ( fullscreen ) { | 209 | if ( fullscreen ) { |
169 | QRect desk = oApp->desktop()->geometry(); | 210 | QRect desk = oApp->desktop()->geometry(); |
170 | setGeometry( 0, 0, desk.width(), desk.height() ); | 211 | setGeometry( 0, 0, desk.width(), desk.height() ); |
171 | } | 212 | } |
172 | 213 | ||
173 | connect( pinD, SIGNAL(passwordEntered(const QString&)), | 214 | connect( pinD, SIGNAL(passwordEntered(const QString&)), |
174 | this, SLOT(accept()) ); | 215 | this, SLOT(accept()) ); |
175 | connect( pinD, SIGNAL(skip()), this, SLOT(accept()) ); | 216 | connect( pinD, SIGNAL(skip()), this, SLOT(accept()) ); |
176 | } | 217 | } |
177 | 218 | ||
178 | void resizeEvent( QResizeEvent * ) | 219 | void resizeEvent( QResizeEvent * ) |
179 | { | 220 | { |
180 | pinD->resize( size() ); | 221 | pinD->resize( size() ); |
181 | } | 222 | } |
182 | 223 | ||
183 | void reset() | 224 | void reset() |
184 | { | 225 | { |
185 | pinD->clear(); | 226 | pinD->clear(); |
186 | } | 227 | } |
187 | 228 | ||
188 | /// Slot receiving the Skip or Enter commands, and closing the QDialog | 229 | /// Slot receiving the Skip or Enter commands, and closing the QDialog |
189 | void accept() | 230 | void accept() |
190 | { | 231 | { |
191 | if ( !modl ) | 232 | if ( !modl ) |
192 | oApp->exit_loop(); | 233 | oApp->exit_loop(); |
193 | QDialog::accept(); | 234 | QDialog::accept(); |
194 | } | 235 | } |
195 | 236 | ||
196 | PinDialog *pinD; | 237 | PinDialog *pinD; |
197 | bool modl; | 238 | bool modl; |
198 | }; | 239 | }; |
199 | 240 | ||
200 | /// generate a fairly random salt and return the PIN hashed by crypt() | 241 | /// generate a fairly random salt and return the PIN hashed by crypt() |