summaryrefslogtreecommitdiff
path: root/library/password.cpp
Unidiff
Diffstat (limited to 'library/password.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--library/password.cpp15
1 files changed, 8 insertions, 7 deletions
diff --git a/library/password.cpp b/library/password.cpp
index 6d126c4..25fb1b8 100644
--- a/library/password.cpp
+++ b/library/password.cpp
@@ -60,49 +60,49 @@ private:
60 60
61 61
62extern "C" char *crypt(const char *key, const char *salt); 62extern "C" char *crypt(const char *key, const char *salt);
63static QString qcrypt(const QString& k, const char *salt) 63static QString qcrypt(const QString& k, const char *salt)
64{ 64{
65 return QString::fromUtf8(crypt(k.utf8(),salt)); 65 return QString::fromUtf8(crypt(k.utf8(),salt));
66} 66}
67 67
68/* 68/*
69 * Constructs a PasswordDialog which is a child of 'parent', with the 69 * Constructs a PasswordDialog which is a child of 'parent', with the
70 * name 'name' and widget flags set to 'f' 70 * name 'name' and widget flags set to 'f'
71 */ 71 */
72PasswordDialog::PasswordDialog( QWidget* parent, const char* name, WFlags fl ) 72PasswordDialog::PasswordDialog( QWidget* parent, const char* name, WFlags fl )
73 : PasswordBase( parent, name, fl ) 73 : PasswordBase( parent, name, fl )
74{ 74{
75 QRect desk = qApp->desktop()->geometry(); 75 QRect desk = qApp->desktop()->geometry();
76 76
77 if ( desk.width() < 220 ) { 77 if ( desk.width() < 220 ) {
78 QFont f( font() ); 78 QFont f( font() );
79 f.setPointSize( 18 ); 79 f.setPointSize( 18 );
80 setFont( f ); 80 setFont( f );
81 f.setPointSize( 12 ); 81 f.setPointSize( 12 );
82 prompt->setFont( f ); 82 prompt->setFont( f );
83 } 83 }
84 84
85 button_0->installEventFilter( this ); 85 button_0->installEventFilter( this );
86 button_1->installEventFilter( this ); 86 button_1->installEventFilter( this );
87 button_2->installEventFilter( this ); 87 button_2->installEventFilter( this );
88 button_3->installEventFilter( this ); 88 button_3->installEventFilter( this );
89 button_4->installEventFilter( this ); 89 button_4->installEventFilter( this );
90 button_5->installEventFilter( this ); 90 button_5->installEventFilter( this );
91 button_6->installEventFilter( this ); 91 button_6->installEventFilter( this );
92 button_7->installEventFilter( this ); 92 button_7->installEventFilter( this );
93 button_8->installEventFilter( this ); 93 button_8->installEventFilter( this );
94 button_9->installEventFilter( this ); 94 button_9->installEventFilter( this );
95 button_OK->installEventFilter( this ); 95 button_OK->installEventFilter( this );
96 setFocus(); 96 setFocus();
97} 97}
98 98
99/* 99/*
100 * Destroys the object and frees any allocated resources 100 * Destroys the object and frees any allocated resources
101 */ 101 */
102PasswordDialog::~PasswordDialog() 102PasswordDialog::~PasswordDialog()
103{ 103{
104 // no need to delete child widgets, Qt does it all for us 104 // no need to delete child widgets, Qt does it all for us
105} 105}
106 106
107 107
108 108
@@ -195,157 +195,158 @@ public:
195 void execNonModal() 195 void execNonModal()
196 { 196 {
197 if ( !modl ) { 197 if ( !modl ) {
198 reset(); 198 reset();
199 showFullScreen(); 199 showFullScreen();
200 do { 200 do {
201 qApp->enter_loop(); 201 qApp->enter_loop();
202 } while (result()!=1); 202 } while (result()!=1);
203 } 203 }
204 } 204 }
205 205
206 void accept() 206 void accept()
207 { 207 {
208 if ( !modl ) 208 if ( !modl )
209 qApp->exit_loop(); 209 qApp->exit_loop();
210 QDialog::accept(); 210 QDialog::accept();
211 } 211 }
212 212
213 PasswordDialog *passw; 213 PasswordDialog *passw;
214 bool modl; 214 bool modl;
215}; 215};
216 216
217class OwnerDlg : public QDialog 217class OwnerDlg : public QDialog
218{ 218{
219 Q_OBJECT
219public: 220public:
220 221
221 OwnerDlg( QWidget *parent, const char * name, Contact c, 222 OwnerDlg( QWidget *parent, const char * name, Contact c,
222 bool modal, bool fullscreen = FALSE ) 223 bool modal, bool fullscreen = FALSE )
223 : QDialog( parent, name, modal, 224 : QDialog( parent, name, modal,
224 fullscreen ? 225 fullscreen ?
225 WStyle_NoBorder | WStyle_Customize | WStyle_StaysOnTop : 0 ) 226 WStyle_NoBorder | WStyle_Customize | WStyle_StaysOnTop : 0 )
226 { 227 {
227 if ( fullscreen ) { 228 if ( fullscreen ) {
228 QRect desk = qApp->desktop()->geometry(); 229 QRect desk = qApp->desktop()->geometry();
229 setGeometry( 0, 0, desk.width(), desk.height() ); 230 setGeometry( 0, 0, desk.width(), desk.height() );
230 } 231 }
231 232
232 // set up contents. 233 // set up contents.
233 QString text = "<H1>" + tr("Owner Information") + "</H1>"; 234 QString text = "<H1>" + tr("Owner Information") + "</H1>";
234 text += c.toRichText(); 235 text += c.toRichText();
235 tv = new QTextView(this); 236 tv = new QTextView(this);
236 tv->setText(text); 237 tv->setText(text);
237 238
238 tv->viewport()->installEventFilter(this); 239 tv->viewport()->installEventFilter(this);
239 } 240 }
240 241
241 void resizeEvent( QResizeEvent * ) 242 void resizeEvent( QResizeEvent * )
242 { 243 {
243 tv->resize( size() ); 244 tv->resize( size() );
244 } 245 }
245 246
246 bool eventFilter(QObject *o, QEvent *e) 247 bool eventFilter(QObject *o, QEvent *e)
247 { 248 {
248 if (e->type() == QEvent::KeyPress || e->type() == QEvent::MouseButtonPress ) { 249 if (e->type() == QEvent::KeyPress || e->type() == QEvent::MouseButtonPress ) {
249 accept(); 250 accept();
250 return TRUE; 251 return TRUE;
251 } 252 }
252 return QWidget::eventFilter(o, e); 253 return QWidget::eventFilter(o, e);
253 } 254 }
254 255
255 void mousePressEvent( QMouseEvent * ) { accept(); } 256 void mousePressEvent( QMouseEvent * ) { accept(); }
256 257
257private: 258private:
258 QTextView *tv; 259 QTextView *tv;
259}; 260};
260 261
261/*! 262/*!
262 Returns a crypted password entered by the user when prompted with \a prompt 263 Returns a crypted password entered by the user when prompted with \a prompt
263 The returned value is QString::null if the user cancels the operation, 264 The returned value is QString::null if the user cancels the operation,
264 or the empty string if the user enters no password (but confirms the 265 or the empty string if the user enters no password (but confirms the
265 dialog). 266 dialog).
266*/ 267*/
267 268
268QString Password::getPassword( const QString& prompt ) 269QString Password::getPassword( const QString& prompt )
269{ 270{
270 PasswdDlg pd(0,0,TRUE); 271 PasswdDlg pd(0,0,TRUE);
271 pd.passw->setPrompt( prompt ); 272 pd.passw->setPrompt( prompt );
272 273
273 pd.showMaximized(); 274 pd.showMaximized();
274 int r = pd.exec(); 275 int r = pd.exec();
275 276
276 if ( r == QDialog::Accepted ) { 277 if ( r == QDialog::Accepted ) {
277 if (pd.passw->text.isEmpty()) 278 if (pd.passw->text.isEmpty())
278 return ""; 279 return "";
279 else 280 else
280 return qcrypt(pd.passw->text,"a0"); 281 return qcrypt(pd.passw->text,"a0");
281 } else { 282 } else {
282 return QString::null; 283 return QString::null;
283 } 284 }
284} 285}
285 286
286 287
287/*! 288/*!
288 Return if a prompt for the user's passcode is needed. 289 Return if a prompt for the user's passcode is needed.
289 290
290 If \a at_poweron is TRUE, the dialog is only used if the user's 291 If \a at_poweron is TRUE, the dialog is only used if the user's
291 preference request it at poweron 292 preference request it at poweron
292 293
293 Opie extension to speed up suspend/resume. 294 Opie extension to speed up suspend/resume.
294*/ 295*/
295 296
296bool Password::needToAuthenticate(bool at_poweron) 297bool Password::needToAuthenticate(bool at_poweron)
297{ 298{
298 Config cfg("Security"); 299 Config cfg("Security");
299 cfg.setGroup("Passcode"); 300 cfg.setGroup("Passcode");
300 QString passcode = cfg.readEntry("passcode"); 301 QString passcode = cfg.readEntry("passcode");
301 302
302 return ( !passcode.isEmpty() 303 return ( !passcode.isEmpty()
303 && (!at_poweron || cfg.readNumEntry("passcode_poweron",0)) ); 304 && (!at_poweron || cfg.readNumEntry("passcode_poweron",0)) );
304} 305}
305 306
306/*! 307/*!
307 Prompt, fullscreen, for the user's passcode until they get it right. 308 Prompt, fullscreen, for the user's passcode until they get it right.
308 309
309 If \a at_poweron is TRUE, the dialog is only used if the user's 310 If \a at_poweron is TRUE, the dialog is only used if the user's
310 preference request it at poweron; either way, the screen is always repainted 311 preference request it at poweron; either way, the screen is always repainted
311 by this function. (this functionality may move to the caller of this function). 312 by this function. (this functionality may move to the caller of this function).
312*/ 313*/
313 314
314void Password::authenticate(bool at_poweron) 315void Password::authenticate(bool at_poweron)
315{ 316{
316 Config cfg("Security"); 317 Config cfg("Security");
317 cfg.setGroup("Passcode"); 318 cfg.setGroup("Passcode");
318 QString passcode = cfg.readEntry("passcode"); 319 QString passcode = cfg.readEntry("passcode");
319 if ( !passcode.isEmpty() 320 if ( !passcode.isEmpty()
320 && (!at_poweron || cfg.readNumEntry("passcode_poweron",0)) ) 321 && (!at_poweron || cfg.readNumEntry("passcode_poweron",0)) )
321 { 322 {
322 // Do it as a fullscreen modal dialog 323 // Do it as a fullscreen modal dialog
323 PasswdDlg pd(0,0,TRUE,TRUE); 324 PasswdDlg pd(0,0,TRUE,TRUE);
324 325
325 // see if there is contact information. 326 // see if there is contact information.
326 OwnerDlg *oi = 0; 327 OwnerDlg *oi = 0;
327 QString vfilename = Global::applicationFileName("addressbook", 328 QString vfilename = Global::applicationFileName("addressbook",
328 "businesscard.vcf"); 329 "businesscard.vcf");
329 if (QFile::exists(vfilename)) { 330 if (QFile::exists(vfilename)) {
330 Contact c; 331 Contact c;
331 c = Contact::readVCard( vfilename )[0]; 332 c = Contact::readVCard( vfilename )[0];
332 333
333 oi = new OwnerDlg(0, 0, c, TRUE, TRUE); 334 oi = new OwnerDlg(0, 0, c, TRUE, TRUE);
334 } 335 }
335 336
336 pd.reset(); 337 pd.reset();
337 pd.exec(); 338 pd.exec();
338 while (qcrypt(pd.passw->text, "a0") != passcode) { 339 while (qcrypt(pd.passw->text, "a0") != passcode) {
339 if (oi) 340 if (oi)
340 oi->exec(); 341 oi->exec();
341 pd.reset(); 342 pd.reset();
342 pd.exec(); 343 pd.exec();
343 } 344 }
344 } else if ( at_poweron ) { 345 } else if ( at_poweron ) {
345 // refresh screen #### should probably be in caller 346 // refresh screen #### should probably be in caller
346 // Not needed (we took away the screen blacking) TT 347 // Not needed (we took away the screen blacking) TT
347 // Not needed (we have intelligent screen blacking) sandman 348 // Not needed (we have intelligent screen blacking) sandman
348 //if ( qwsServer ) 349 //if ( qwsServer )
349 //qwsServer->refresh(); 350 //qwsServer->refresh();
350 } 351 }
351} 352}