summaryrefslogtreecommitdiff
path: root/library
authorsandman <sandman>2002-10-17 00:39:31 (UTC)
committer sandman <sandman>2002-10-17 00:39:31 (UTC)
commit259d10f40405fd77ba0a8947782f716be94da3a5 (patch) (unidiff)
tree636cb3a899d27a8fe41f377fabc5bd170a74c6dc /library
parent5d28c61d84da1814d356540b557bbfe026da98aa (diff)
downloadopie-259d10f40405fd77ba0a8947782f716be94da3a5.zip
opie-259d10f40405fd77ba0a8947782f716be94da3a5.tar.gz
opie-259d10f40405fd77ba0a8947782f716be94da3a5.tar.bz2
- fix for bug #292 (Improper behaviour of frontlight disabling)
- fix for bug #199 (Desktop visible on resume before password dialog appears)
Diffstat (limited to 'library') (more/less context) (ignore whitespace changes)
-rw-r--r--library/password.cpp24
-rw-r--r--library/password.h1
2 files changed, 23 insertions, 2 deletions
diff --git a/library/password.cpp b/library/password.cpp
index 4b22b65..6d126c4 100644
--- a/library/password.cpp
+++ b/library/password.cpp
@@ -1,333 +1,353 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. 2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of the Qtopia Environment. 4** This file is part of the Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20#include "password.h" 20#include "password.h"
21#include "config.h" 21#include "config.h"
22#include "global.h" 22#include "global.h"
23#include "backend/contact.h" 23#include "backend/contact.h"
24#include <qlabel.h> 24#include <qlabel.h>
25#include <qlineedit.h> 25#include <qlineedit.h>
26#include <qtextview.h> 26#include <qtextview.h>
27#include <qstring.h> 27#include <qstring.h>
28#include <qapplication.h> 28#include <qapplication.h>
29#include <qfile.h> 29#include <qfile.h>
30#include <qwindowsystem_qws.h> 30//#include <qwindowsystem_qws.h>
31 31
32#include <qdialog.h> 32#include <qdialog.h>
33 33
34#include <unistd.h> //for sleep 34#include <unistd.h> //for sleep
35#include "passwordbase_p.h" 35#include "passwordbase_p.h"
36 36
37class PasswordDialog : public PasswordBase 37class PasswordDialog : public PasswordBase
38{ 38{
39 Q_OBJECT 39 Q_OBJECT
40 40
41public: 41public:
42 PasswordDialog( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 ); 42 PasswordDialog( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 );
43 ~PasswordDialog(); 43 ~PasswordDialog();
44 44
45 void clear(); 45 void clear();
46 void setPrompt( const QString& ); 46 void setPrompt( const QString& );
47 47
48signals: 48signals:
49 void passwordEntered( const QString& ); 49 void passwordEntered( const QString& );
50 50
51protected: 51protected:
52 bool eventFilter( QObject*, QEvent* ); 52 bool eventFilter( QObject*, QEvent* );
53 void keyPressEvent( QKeyEvent * ); 53 void keyPressEvent( QKeyEvent * );
54 54
55private: 55private:
56 void input( QString ); 56 void input( QString );
57 friend class Password; 57 friend class Password;
58 QString text; 58 QString text;
59}; 59};
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
109/*! 109/*!
110 \reimp 110 \reimp
111*/ 111*/
112 112
113bool PasswordDialog::eventFilter( QObject*o, QEvent*e ) 113bool PasswordDialog::eventFilter( QObject*o, QEvent*e )
114{ 114{
115 if ( e->type() == QEvent::MouseButtonRelease ) { 115 if ( e->type() == QEvent::MouseButtonRelease ) {
116 if ( o == button_OK ) { 116 if ( o == button_OK ) {
117 emit passwordEntered( text ); 117 emit passwordEntered( text );
118 } else { 118 } else {
119 QLabel *l = (QLabel*)o; 119 QLabel *l = (QLabel*)o;
120 input(l->text()); 120 input(l->text());
121 } 121 }
122 } 122 }
123 return FALSE; 123 return FALSE;
124} 124}
125 125
126 126
127/*! 127/*!
128 \reimp 128 \reimp
129*/ 129*/
130 130
131void PasswordDialog::keyPressEvent( QKeyEvent * ) 131void PasswordDialog::keyPressEvent( QKeyEvent * )
132{ 132{
133#if 0 133#if 0
134 if ( e->key() == Key_Enter || e->key() == Key_Return ) 134 if ( e->key() == Key_Enter || e->key() == Key_Return )
135 emit passwordEntered( text ); 135 emit passwordEntered( text );
136 else 136 else
137 input( e->text() ); 137 input( e->text() );
138#endif 138#endif
139} 139}
140 140
141 141
142/*! 142/*!
143 143
144*/ 144*/
145 145
146void PasswordDialog::input( QString c ) 146void PasswordDialog::input( QString c )
147{ 147{
148 text += c; 148 text += c;
149 display->setText( text ); 149 display->setText( text );
150} 150}
151 151
152/*! 152/*!
153 153
154*/ 154*/
155 155
156void PasswordDialog::setPrompt( const QString& s ) 156void PasswordDialog::setPrompt( const QString& s )
157{ 157{
158 prompt->setText( s ); 158 prompt->setText( s );
159} 159}
160 160
161void PasswordDialog::clear() 161void PasswordDialog::clear()
162{ 162{
163 text = ""; 163 text = "";
164 input(""); 164 input("");
165} 165}
166 166
167class PasswdDlg : public QDialog 167class PasswdDlg : public QDialog
168{ 168{
169public: 169public:
170 PasswdDlg( QWidget *parent, const char * name, bool modal, bool fullscreen = FALSE ) 170 PasswdDlg( QWidget *parent, const char * name, bool modal, bool fullscreen = FALSE )
171 : QDialog( parent, name, modal, fullscreen ? WStyle_NoBorder | WStyle_Customize | WStyle_StaysOnTop : 0 ), 171 : QDialog( parent, name, modal, fullscreen ? WStyle_NoBorder | WStyle_Customize | WStyle_StaysOnTop : 0 ),
172 modl(modal) 172 modl(modal)
173 { 173 {
174 passw = new PasswordDialog( this ); 174 passw = new PasswordDialog( this );
175 175
176 if ( fullscreen ) { 176 if ( fullscreen ) {
177 QRect desk = qApp->desktop()->geometry(); 177 QRect desk = qApp->desktop()->geometry();
178 setGeometry( 0, 0, desk.width(), desk.height() ); 178 setGeometry( 0, 0, desk.width(), desk.height() );
179 } 179 }
180 180
181 connect( passw, SIGNAL(passwordEntered(const QString&)), 181 connect( passw, SIGNAL(passwordEntered(const QString&)),
182 this, SLOT(accept()) ); 182 this, SLOT(accept()) );
183 } 183 }
184 184
185 void resizeEvent( QResizeEvent * ) 185 void resizeEvent( QResizeEvent * )
186 { 186 {
187 passw->resize( size() ); 187 passw->resize( size() );
188 } 188 }
189 189
190 void reset() 190 void reset()
191 { 191 {
192 passw->clear(); 192 passw->clear();
193 } 193 }
194 194
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{
219public: 219public:
220 220
221 OwnerDlg( QWidget *parent, const char * name, Contact c, 221 OwnerDlg( QWidget *parent, const char * name, Contact c,
222 bool modal, bool fullscreen = FALSE ) 222 bool modal, bool fullscreen = FALSE )
223 : QDialog( parent, name, modal, 223 : QDialog( parent, name, modal,
224 fullscreen ? 224 fullscreen ?
225 WStyle_NoBorder | WStyle_Customize | WStyle_StaysOnTop : 0 ) 225 WStyle_NoBorder | WStyle_Customize | WStyle_StaysOnTop : 0 )
226 { 226 {
227 if ( fullscreen ) { 227 if ( fullscreen ) {
228 QRect desk = qApp->desktop()->geometry(); 228 QRect desk = qApp->desktop()->geometry();
229 setGeometry( 0, 0, desk.width(), desk.height() ); 229 setGeometry( 0, 0, desk.width(), desk.height() );
230 } 230 }
231 231
232 // set up contents. 232 // set up contents.
233 QString text = "<H1>" + tr("Owner Information") + "</H1>"; 233 QString text = "<H1>" + tr("Owner Information") + "</H1>";
234 text += c.toRichText(); 234 text += c.toRichText();
235 tv = new QTextView(this); 235 tv = new QTextView(this);
236 tv->setText(text); 236 tv->setText(text);
237 237
238 tv->viewport()->installEventFilter(this); 238 tv->viewport()->installEventFilter(this);
239 } 239 }
240 240
241 void resizeEvent( QResizeEvent * ) 241 void resizeEvent( QResizeEvent * )
242 { 242 {
243 tv->resize( size() ); 243 tv->resize( size() );
244 } 244 }
245 245
246 bool eventFilter(QObject *o, QEvent *e) 246 bool eventFilter(QObject *o, QEvent *e)
247 { 247 {
248 if (e->type() == QEvent::KeyPress || e->type() == QEvent::MouseButtonPress ) { 248 if (e->type() == QEvent::KeyPress || e->type() == QEvent::MouseButtonPress ) {
249 accept(); 249 accept();
250 return TRUE; 250 return TRUE;
251 } 251 }
252 return QWidget::eventFilter(o, e); 252 return QWidget::eventFilter(o, e);
253 } 253 }
254 254
255 void mousePressEvent( QMouseEvent * ) { accept(); } 255 void mousePressEvent( QMouseEvent * ) { accept(); }
256 256
257private: 257private:
258 QTextView *tv; 258 QTextView *tv;
259}; 259};
260 260
261/*! 261/*!
262 Returns a crypted password entered by the user when prompted with \a prompt 262 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, 263 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 264 or the empty string if the user enters no password (but confirms the
265 dialog). 265 dialog).
266*/ 266*/
267 267
268QString Password::getPassword( const QString& prompt ) 268QString Password::getPassword( const QString& prompt )
269{ 269{
270 PasswdDlg pd(0,0,TRUE); 270 PasswdDlg pd(0,0,TRUE);
271 pd.passw->setPrompt( prompt ); 271 pd.passw->setPrompt( prompt );
272 272
273 pd.showMaximized(); 273 pd.showMaximized();
274 int r = pd.exec(); 274 int r = pd.exec();
275 275
276 if ( r == QDialog::Accepted ) { 276 if ( r == QDialog::Accepted ) {
277 if (pd.passw->text.isEmpty()) 277 if (pd.passw->text.isEmpty())
278 return ""; 278 return "";
279 else 279 else
280 return qcrypt(pd.passw->text,"a0"); 280 return qcrypt(pd.passw->text,"a0");
281 } else { 281 } else {
282 return QString::null; 282 return QString::null;
283 } 283 }
284} 284}
285 285
286 286
287/*! 287/*!
288 Return if a prompt for the user's passcode is needed.
289
290 If \a at_poweron is TRUE, the dialog is only used if the user's
291 preference request it at poweron
292
293 Opie extension to speed up suspend/resume.
294*/
295
296bool Password::needToAuthenticate(bool at_poweron)
297{
298 Config cfg("Security");
299 cfg.setGroup("Passcode");
300 QString passcode = cfg.readEntry("passcode");
301
302 return ( !passcode.isEmpty()
303 && (!at_poweron || cfg.readNumEntry("passcode_poweron",0)) );
304}
305
306/*!
288 Prompt, fullscreen, for the user's passcode until they get it right. 307 Prompt, fullscreen, for the user's passcode until they get it right.
289 308
290 If \a at_poweron is TRUE, the dialog is only used if the user's 309 If \a at_poweron is TRUE, the dialog is only used if the user's
291 preference request it at poweron; either way, the screen is always repainted 310 preference request it at poweron; either way, the screen is always repainted
292 by this function. (this functionality may move to the caller of this function). 311 by this function. (this functionality may move to the caller of this function).
293*/ 312*/
294 313
295void Password::authenticate(bool at_poweron) 314void Password::authenticate(bool at_poweron)
296{ 315{
297 Config cfg("Security"); 316 Config cfg("Security");
298 cfg.setGroup("Passcode"); 317 cfg.setGroup("Passcode");
299 QString passcode = cfg.readEntry("passcode"); 318 QString passcode = cfg.readEntry("passcode");
300 if ( !passcode.isEmpty() 319 if ( !passcode.isEmpty()
301 && (!at_poweron || cfg.readNumEntry("passcode_poweron",0)) ) 320 && (!at_poweron || cfg.readNumEntry("passcode_poweron",0)) )
302 { 321 {
303 // Do it as a fullscreen modal dialog 322 // Do it as a fullscreen modal dialog
304 PasswdDlg pd(0,0,TRUE,TRUE); 323 PasswdDlg pd(0,0,TRUE,TRUE);
305 324
306 // see if there is contact information. 325 // see if there is contact information.
307 OwnerDlg *oi = 0; 326 OwnerDlg *oi = 0;
308 QString vfilename = Global::applicationFileName("addressbook", 327 QString vfilename = Global::applicationFileName("addressbook",
309 "businesscard.vcf"); 328 "businesscard.vcf");
310 if (QFile::exists(vfilename)) { 329 if (QFile::exists(vfilename)) {
311 Contact c; 330 Contact c;
312 c = Contact::readVCard( vfilename )[0]; 331 c = Contact::readVCard( vfilename )[0];
313 332
314 oi = new OwnerDlg(0, 0, c, TRUE, TRUE); 333 oi = new OwnerDlg(0, 0, c, TRUE, TRUE);
315 } 334 }
316 335
317 pd.reset(); 336 pd.reset();
318 pd.exec(); 337 pd.exec();
319 while (qcrypt(pd.passw->text, "a0") != passcode) { 338 while (qcrypt(pd.passw->text, "a0") != passcode) {
320 if (oi) 339 if (oi)
321 oi->exec(); 340 oi->exec();
322 pd.reset(); 341 pd.reset();
323 pd.exec(); 342 pd.exec();
324 } 343 }
325 } else if ( at_poweron ) { 344 } else if ( at_poweron ) {
326 // refresh screen #### should probably be in caller 345 // refresh screen #### should probably be in caller
327 // Not needed (we took away the screen blacking) 346 // Not needed (we took away the screen blacking) TT
347 // Not needed (we have intelligent screen blacking) sandman
328 //if ( qwsServer ) 348 //if ( qwsServer )
329 //qwsServer->refresh(); 349 //qwsServer->refresh();
330 } 350 }
331} 351}
332 352
333#include "password.moc" 353#include "password.moc"
diff --git a/library/password.h b/library/password.h
index a3a3e45..a2f2c3c 100644
--- a/library/password.h
+++ b/library/password.h
@@ -1,32 +1,33 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. 2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of the Qtopia Environment. 4** This file is part of the Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20#ifndef PASSWORD_H 20#ifndef PASSWORD_H
21#define PASSWORD_H 21#define PASSWORD_H
22 22
23#include <qstring.h> 23#include <qstring.h>
24 24
25class Password 25class Password
26{ 26{
27public: 27public:
28 static bool needToAuthenticate(bool atpoweron=FALSE); // Opie extension to speed up suspend/resume (sandman)
28 static void authenticate(bool atpoweron=FALSE); 29 static void authenticate(bool atpoweron=FALSE);
29 static QString getPassword( const QString& prompt ); 30 static QString getPassword( const QString& prompt );
30}; 31};
31 32
32#endif // PASSWORD_H 33#endif // PASSWORD_H