-rw-r--r-- | core/launcher/desktop.cpp | 34 | ||||
-rw-r--r-- | library/password.cpp | 24 | ||||
-rw-r--r-- | library/password.h | 1 |
3 files changed, 46 insertions, 13 deletions
diff --git a/core/launcher/desktop.cpp b/core/launcher/desktop.cpp index 0e60839..d74b745 100644 --- a/core/launcher/desktop.cpp +++ b/core/launcher/desktop.cpp | |||
@@ -1,532 +1,534 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of 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 | 20 | ||
21 | #include "desktop.h" | 21 | #include "desktop.h" |
22 | #include "info.h" | 22 | #include "info.h" |
23 | #include "launcher.h" | 23 | #include "launcher.h" |
24 | //#include "mrulist.h" | 24 | //#include "mrulist.h" |
25 | #include "qcopbridge.h" | 25 | #include "qcopbridge.h" |
26 | #include "shutdownimpl.h" | 26 | #include "shutdownimpl.h" |
27 | #include "startmenu.h" | 27 | #include "startmenu.h" |
28 | #include "taskbar.h" | 28 | #include "taskbar.h" |
29 | #include "transferserver.h" | 29 | #include "transferserver.h" |
30 | #include "irserver.h" | 30 | #include "irserver.h" |
31 | #include "packageslave.h" | 31 | #include "packageslave.h" |
32 | 32 | ||
33 | #include <qpe/applnk.h> | 33 | #include <qpe/applnk.h> |
34 | #include <qpe/mimetype.h> | 34 | #include <qpe/mimetype.h> |
35 | #include <qpe/password.h> | 35 | #include <qpe/password.h> |
36 | #include <qpe/config.h> | 36 | #include <qpe/config.h> |
37 | #include <qpe/power.h> | 37 | #include <qpe/power.h> |
38 | #include <qpe/timeconversion.h> | 38 | #include <qpe/timeconversion.h> |
39 | #include <qpe/qcopenvelope_qws.h> | 39 | #include <qpe/qcopenvelope_qws.h> |
40 | #include <qpe/network.h> | 40 | #include <qpe/network.h> |
41 | #include <qpe/global.h> | 41 | #include <qpe/global.h> |
42 | 42 | ||
43 | #if defined( QT_QWS_CUSTOM ) || defined( QT_QWS_IPAQ ) | 43 | #if defined( QT_QWS_CUSTOM ) || defined( QT_QWS_IPAQ ) |
44 | #include <qpe/custom.h> | 44 | #include <qpe/custom.h> |
45 | #endif | 45 | #endif |
46 | 46 | ||
47 | #include <opie/odevice.h> | 47 | #include <opie/odevice.h> |
48 | 48 | ||
49 | #include <qgfx_qws.h> | 49 | #include <qgfx_qws.h> |
50 | #include <qmainwindow.h> | 50 | #include <qmainwindow.h> |
51 | #include <qmessagebox.h> | 51 | #include <qmessagebox.h> |
52 | #include <qtimer.h> | 52 | #include <qtimer.h> |
53 | #include <qwindowsystem_qws.h> | 53 | #include <qwindowsystem_qws.h> |
54 | 54 | ||
55 | #include <qvaluelist.h> | 55 | #include <qvaluelist.h> |
56 | 56 | ||
57 | #include <stdlib.h> | 57 | #include <stdlib.h> |
58 | #include <unistd.h> | 58 | #include <unistd.h> |
59 | #include <fcntl.h> | 59 | #include <fcntl.h> |
60 | 60 | ||
61 | using namespace Opie; | 61 | using namespace Opie; |
62 | 62 | ||
63 | class QCopKeyRegister | 63 | class QCopKeyRegister |
64 | { | 64 | { |
65 | public: | 65 | public: |
66 | QCopKeyRegister() : keyCode( 0 ) | 66 | QCopKeyRegister() : keyCode( 0 ) |
67 | { } | 67 | { } |
68 | QCopKeyRegister( int k, const QString &c, const QString &m ) | 68 | QCopKeyRegister( int k, const QString &c, const QString &m ) |
69 | : keyCode( k ), channel( c ), message( m ) | 69 | : keyCode( k ), channel( c ), message( m ) |
70 | { } | 70 | { } |
71 | 71 | ||
72 | int getKeyCode() const | 72 | int getKeyCode() const |
73 | { | 73 | { |
74 | return keyCode; | 74 | return keyCode; |
75 | } | 75 | } |
76 | QString getChannel() const | 76 | QString getChannel() const |
77 | { | 77 | { |
78 | return channel; | 78 | return channel; |
79 | } | 79 | } |
80 | QString getMessage() const | 80 | QString getMessage() const |
81 | { | 81 | { |
82 | return message; | 82 | return message; |
83 | } | 83 | } |
84 | 84 | ||
85 | private: | 85 | private: |
86 | int keyCode; | 86 | int keyCode; |
87 | QString channel, message; | 87 | QString channel, message; |
88 | }; | 88 | }; |
89 | 89 | ||
90 | typedef QValueList<QCopKeyRegister> KeyRegisterList; | 90 | typedef QValueList<QCopKeyRegister> KeyRegisterList; |
91 | KeyRegisterList keyRegisterList; | 91 | KeyRegisterList keyRegisterList; |
92 | 92 | ||
93 | static Desktop* qpedesktop = 0; | 93 | static Desktop* qpedesktop = 0; |
94 | static int loggedin = 0; | 94 | static int loggedin = 0; |
95 | static void login( bool at_poweron ) | 95 | static void login( bool at_poweron ) |
96 | { | 96 | { |
97 | if ( !loggedin ) { | 97 | if ( !loggedin ) { |
98 | Global::terminateBuiltin( "calibrate" ); | 98 | Global::terminateBuiltin( "calibrate" ); |
99 | Password::authenticate( at_poweron ); | 99 | Password::authenticate( at_poweron ); |
100 | loggedin = 1; | 100 | loggedin = 1; |
101 | QCopEnvelope e( "QPE/Desktop", "unlocked()" ); | 101 | QCopEnvelope e( "QPE/Desktop", "unlocked()" ); |
102 | } | 102 | } |
103 | } | 103 | } |
104 | 104 | ||
105 | bool Desktop::screenLocked() | 105 | bool Desktop::screenLocked() |
106 | { | 106 | { |
107 | return loggedin == 0; | 107 | return loggedin == 0; |
108 | } | 108 | } |
109 | 109 | ||
110 | /* | 110 | /* |
111 | Priority is number of alerts that are needed to pop up | 111 | Priority is number of alerts that are needed to pop up |
112 | alert. | 112 | alert. |
113 | */ | 113 | */ |
114 | class DesktopPowerAlerter : public QMessageBox | 114 | class DesktopPowerAlerter : public QMessageBox |
115 | { | 115 | { |
116 | public: | 116 | public: |
117 | DesktopPowerAlerter( QWidget *parent, const char *name = 0 ) | 117 | DesktopPowerAlerter( QWidget *parent, const char *name = 0 ) |
118 | : QMessageBox( tr( "Battery Status" ), "Low Battery", | 118 | : QMessageBox( tr( "Battery Status" ), "Low Battery", |
119 | QMessageBox::Critical, | 119 | QMessageBox::Critical, |
120 | QMessageBox::Ok | QMessageBox::Default, | 120 | QMessageBox::Ok | QMessageBox::Default, |
121 | QMessageBox::NoButton, QMessageBox::NoButton, | 121 | QMessageBox::NoButton, QMessageBox::NoButton, |
122 | parent, name, FALSE ) | 122 | parent, name, FALSE ) |
123 | { | 123 | { |
124 | currentPriority = INT_MAX; | 124 | currentPriority = INT_MAX; |
125 | alertCount = 0; | 125 | alertCount = 0; |
126 | } | 126 | } |
127 | 127 | ||
128 | void alert( const QString &text, int priority ); | 128 | void alert( const QString &text, int priority ); |
129 | void hideEvent( QHideEvent * ); | 129 | void hideEvent( QHideEvent * ); |
130 | private: | 130 | private: |
131 | int currentPriority; | 131 | int currentPriority; |
132 | int alertCount; | 132 | int alertCount; |
133 | }; | 133 | }; |
134 | 134 | ||
135 | void DesktopPowerAlerter::alert( const QString &text, int priority ) | 135 | void DesktopPowerAlerter::alert( const QString &text, int priority ) |
136 | { | 136 | { |
137 | alertCount++; | 137 | alertCount++; |
138 | if ( alertCount < priority ) | 138 | if ( alertCount < priority ) |
139 | return ; | 139 | return ; |
140 | if ( priority > currentPriority ) | 140 | if ( priority > currentPriority ) |
141 | return ; | 141 | return ; |
142 | currentPriority = priority; | 142 | currentPriority = priority; |
143 | setText( text ); | 143 | setText( text ); |
144 | show(); | 144 | show(); |
145 | } | 145 | } |
146 | 146 | ||
147 | 147 | ||
148 | void DesktopPowerAlerter::hideEvent( QHideEvent *e ) | 148 | void DesktopPowerAlerter::hideEvent( QHideEvent *e ) |
149 | { | 149 | { |
150 | QMessageBox::hideEvent( e ); | 150 | QMessageBox::hideEvent( e ); |
151 | alertCount = 0; | 151 | alertCount = 0; |
152 | currentPriority = INT_MAX; | 152 | currentPriority = INT_MAX; |
153 | } | 153 | } |
154 | 154 | ||
155 | 155 | ||
156 | class QPEScreenSaver : public QWSScreenSaver | 156 | class QPEScreenSaver : public QWSScreenSaver |
157 | { | 157 | { |
158 | private: | 158 | private: |
159 | int LcdOn; | 159 | int LcdOn; |
160 | 160 | ||
161 | public: | 161 | public: |
162 | QPEScreenSaver() | 162 | QPEScreenSaver() |
163 | { | 163 | { |
164 | m_disable_suspend = 100; | 164 | m_disable_suspend = 100; |
165 | m_enable_dim = false; | 165 | m_enable_dim = false; |
166 | m_enable_lightoff = false; | 166 | m_enable_lightoff = false; |
167 | m_enable_onlylcdoff = false; | 167 | m_enable_onlylcdoff = false; |
168 | 168 | ||
169 | m_lcd_status = true; | 169 | m_lcd_status = true; |
170 | 170 | ||
171 | m_backlight_bright = -1; | 171 | m_backlight_bright = -1; |
172 | m_backlight_forcedoff = false; | 172 | m_backlight_forcedoff = false; |
173 | 173 | ||
174 | // Make sure the LCD is in fact on, (if opie was killed while the LCD is off it would still be off) | 174 | // Make sure the LCD is in fact on, (if opie was killed while the LCD is off it would still be off) |
175 | ODevice::inst ( ) -> setDisplayStatus ( true ); | 175 | ODevice::inst ( ) -> setDisplayStatus ( true ); |
176 | } | 176 | } |
177 | void restore() | 177 | void restore() |
178 | { | 178 | { |
179 | if ( !m_lcd_status ) { // We must have turned it off | 179 | if ( !m_lcd_status ) { // We must have turned it off |
180 | ODevice::inst ( ) -> setDisplayStatus ( true ); | 180 | ODevice::inst ( ) -> setDisplayStatus ( true ); |
181 | m_lcd_status = true; | 181 | m_lcd_status = true; |
182 | } | 182 | } |
183 | 183 | ||
184 | setBacklight ( -3 ); | 184 | setBacklight ( -1 ); |
185 | } | 185 | } |
186 | bool save( int level ) | 186 | bool save( int level ) |
187 | { | 187 | { |
188 | switch ( level ) { | 188 | switch ( level ) { |
189 | case 0: | 189 | case 0: |
190 | if ( m_disable_suspend > 0 && m_enable_dim ) { | 190 | if ( m_disable_suspend > 0 && m_enable_dim ) { |
191 | if ( backlight() > 1 ) | 191 | if ( backlight() > 1 ) |
192 | setBacklight( 1 ); // lowest non-off | 192 | setBacklight( 1 ); // lowest non-off |
193 | } | 193 | } |
194 | return true; | 194 | return true; |
195 | break; | 195 | break; |
196 | case 1: | 196 | case 1: |
197 | if ( m_disable_suspend > 1 && m_enable_lightoff ) { | 197 | if ( m_disable_suspend > 1 && m_enable_lightoff ) { |
198 | setBacklight( 0 ); // off | 198 | setBacklight( 0 ); // off |
199 | } | 199 | } |
200 | return true; | 200 | return true; |
201 | break; | 201 | break; |
202 | case 2: | 202 | case 2: |
203 | if ( m_enable_onlylcdoff ) { | 203 | if ( m_enable_onlylcdoff ) { |
204 | ODevice::inst ( ) -> setDisplayStatus ( false ); | 204 | ODevice::inst ( ) -> setDisplayStatus ( false ); |
205 | m_lcd_status = false; | 205 | m_lcd_status = false; |
206 | return true; | 206 | return true; |
207 | } | 207 | } |
208 | else // We're going to suspend the whole machine | 208 | else // We're going to suspend the whole machine |
209 | { | 209 | { |
210 | if ( ( m_disable_suspend > 2 ) && | 210 | if ( ( m_disable_suspend > 2 ) && |
211 | ( PowerStatusManager::readStatus().acStatus() != PowerStatus::Online ) && | 211 | ( PowerStatusManager::readStatus().acStatus() != PowerStatus::Online ) && |
212 | ( !Network::networkOnline ( ) ) ) { | 212 | ( !Network::networkOnline ( ) ) ) { |
213 | QWSServer::sendKeyEvent( 0xffff, Qt::Key_F34, FALSE, TRUE, FALSE ); | 213 | QWSServer::sendKeyEvent( 0xffff, Qt::Key_F34, FALSE, TRUE, FALSE ); |
214 | return true; | 214 | return true; |
215 | } | 215 | } |
216 | } | 216 | } |
217 | break; | 217 | break; |
218 | } | 218 | } |
219 | return false; | 219 | return false; |
220 | } | 220 | } |
221 | 221 | ||
222 | private: | 222 | private: |
223 | static int ssi( int interval, Config & config, const QString & enable, const QString & value, int def ) | 223 | static int ssi( int interval, Config & config, const QString & enable, const QString & value, int def ) |
224 | { | 224 | { |
225 | if ( !enable.isEmpty() && config.readNumEntry( enable, 0 ) == 0 ) | 225 | if ( !enable.isEmpty() && config.readNumEntry( enable, 0 ) == 0 ) |
226 | return 0; | 226 | return 0; |
227 | 227 | ||
228 | if ( interval < 0 ) { | 228 | if ( interval < 0 ) { |
229 | // Restore screen blanking and power saving state | 229 | // Restore screen blanking and power saving state |
230 | interval = config.readNumEntry( value, def ); | 230 | interval = config.readNumEntry( value, def ); |
231 | } | 231 | } |
232 | return interval; | 232 | return interval; |
233 | } | 233 | } |
234 | 234 | ||
235 | public: | 235 | public: |
236 | void setIntervals( int i1, int i2, int i3 ) | 236 | void setIntervals( int i1, int i2, int i3 ) |
237 | { | 237 | { |
238 | Config config( "qpe" ); | 238 | Config config( "qpe" ); |
239 | config.setGroup( "Screensaver" ); | 239 | config.setGroup( "Screensaver" ); |
240 | 240 | ||
241 | int v[ 4 ]; | 241 | int v[ 4 ]; |
242 | i1 = ssi( i1, config, "Dim", "Interval_Dim", 30 ); | 242 | i1 = ssi( i1, config, "Dim", "Interval_Dim", 30 ); |
243 | i2 = ssi( i2, config, "LightOff", "Interval_LightOff", 20 ); | 243 | i2 = ssi( i2, config, "LightOff", "Interval_LightOff", 20 ); |
244 | i3 = ssi( i3, config, "", "Interval", 60 ); | 244 | i3 = ssi( i3, config, "", "Interval", 60 ); |
245 | 245 | ||
246 | //qDebug("screen saver intervals: %d %d %d", i1, i2, i3); | 246 | //qDebug("screen saver intervals: %d %d %d", i1, i2, i3); |
247 | 247 | ||
248 | v [ 0 ] = QMAX( 1000 * i1, 100 ); | 248 | v [ 0 ] = QMAX( 1000 * i1, 100 ); |
249 | v [ 1 ] = QMAX( 1000 * i2, 100 ); | 249 | v [ 1 ] = QMAX( 1000 * i2, 100 ); |
250 | v [ 2 ] = QMAX( 1000 * i3, 100 ); | 250 | v [ 2 ] = QMAX( 1000 * i3, 100 ); |
251 | v [ 3 ] = 0; | 251 | v [ 3 ] = 0; |
252 | m_enable_dim = ( ( i1 != 0 ) ? config. readNumEntry ( "Dim", 1 ) : false ); | 252 | m_enable_dim = ( ( i1 != 0 ) ? config. readNumEntry ( "Dim", 1 ) : false ); |
253 | m_enable_lightoff = ( ( i2 != 0 ) ? config. readNumEntry ( "LightOff", 1 ) : false ); | 253 | m_enable_lightoff = ( ( i2 != 0 ) ? config. readNumEntry ( "LightOff", 1 ) : false ); |
254 | m_enable_onlylcdoff = config. readNumEntry ( "LcdOffOnly", 0 ); | 254 | m_enable_onlylcdoff = config. readNumEntry ( "LcdOffOnly", 0 ); |
255 | 255 | ||
256 | if ( !i1 && !i2 && !i3 ) | 256 | if ( !i1 && !i2 && !i3 ) |
257 | QWSServer::setScreenSaverInterval( 0 ); | 257 | QWSServer::setScreenSaverInterval( 0 ); |
258 | else | 258 | else |
259 | QWSServer::setScreenSaverIntervals( v ); | 259 | QWSServer::setScreenSaverIntervals( v ); |
260 | } | 260 | } |
261 | 261 | ||
262 | void setInterval ( int interval ) | 262 | void setInterval ( int interval ) |
263 | { | 263 | { |
264 | setIntervals ( -1, -1, interval ); | 264 | setIntervals ( -1, -1, interval ); |
265 | } | 265 | } |
266 | 266 | ||
267 | void setMode ( int mode ) | 267 | void setMode ( int mode ) |
268 | { | 268 | { |
269 | if ( mode > m_disable_suspend ) | 269 | if ( mode > m_disable_suspend ) |
270 | setInterval( -1 ); | 270 | setInterval( -1 ); |
271 | m_disable_suspend = mode; | 271 | m_disable_suspend = mode; |
272 | } | 272 | } |
273 | 273 | ||
274 | int backlight ( ) | 274 | int backlight ( ) |
275 | { | 275 | { |
276 | if ( m_backlight_bright == -1 ) { | 276 | if ( m_backlight_bright == -1 ) { |
277 | // Read from config | 277 | // Read from config |
278 | Config config ( "qpe" ); | 278 | Config config ( "qpe" ); |
279 | config. setGroup ( "Screensaver" ); | 279 | config. setGroup ( "Screensaver" ); |
280 | m_backlight_bright = config. readNumEntry ( "Brightness", 255 ); | 280 | m_backlight_bright = config. readNumEntry ( "Brightness", 255 ); |
281 | } | 281 | } |
282 | return m_backlight_bright; | 282 | return m_backlight_bright; |
283 | } | 283 | } |
284 | 284 | ||
285 | void setBacklight ( int bright ) | 285 | void setBacklight ( int bright ) |
286 | { | 286 | { |
287 | if ( bright == -3 ) { | 287 | if ( bright == -3 ) { |
288 | // Forced on | 288 | // Forced on |
289 | m_backlight_forcedoff = false; | 289 | m_backlight_forcedoff = false; |
290 | bright = -1; | 290 | bright = -1; |
291 | } | 291 | } |
292 | if ( m_backlight_forcedoff && bright != -2 ) | 292 | if ( m_backlight_forcedoff && bright != -2 ) |
293 | return ; | 293 | return ; |
294 | if ( bright == -2 ) { | 294 | if ( bright == -2 ) { |
295 | // Toggle between off and on | 295 | // Toggle between off and on |
296 | bright = m_backlight_bright ? 0 : -1; | 296 | bright = m_backlight_bright ? 0 : -1; |
297 | m_backlight_forcedoff = !bright; | 297 | m_backlight_forcedoff = !bright; |
298 | } | 298 | } |
299 | 299 | ||
300 | m_backlight_bright = bright; | 300 | m_backlight_bright = bright; |
301 | 301 | ||
302 | bright = backlight ( ); | 302 | bright = backlight ( ); |
303 | ODevice::inst ( ) -> setDisplayBrightness ( bright ); | 303 | ODevice::inst ( ) -> setDisplayBrightness ( bright ); |
304 | 304 | ||
305 | m_backlight_bright = bright; | 305 | m_backlight_bright = bright; |
306 | } | 306 | } |
307 | 307 | ||
308 | void setDisplayState ( bool on ) | 308 | void setDisplayState ( bool on ) |
309 | { | 309 | { |
310 | if ( m_lcd_status != on ) { | 310 | if ( m_lcd_status != on ) { |
311 | ODevice::inst ( ) -> setDisplayStatus ( on ); | 311 | ODevice::inst ( ) -> setDisplayStatus ( on ); |
312 | m_lcd_status = on; | 312 | m_lcd_status = on; |
313 | } | 313 | } |
314 | } | 314 | } |
315 | 315 | ||
316 | private: | 316 | private: |
317 | int m_disable_suspend; | 317 | int m_disable_suspend; |
318 | bool m_enable_dim; | 318 | bool m_enable_dim; |
319 | bool m_enable_lightoff; | 319 | bool m_enable_lightoff; |
320 | bool m_enable_onlylcdoff; | 320 | bool m_enable_onlylcdoff; |
321 | 321 | ||
322 | bool m_lcd_status; | 322 | bool m_lcd_status; |
323 | 323 | ||
324 | int m_backlight_bright; | 324 | int m_backlight_bright; |
325 | bool m_backlight_forcedoff; | 325 | bool m_backlight_forcedoff; |
326 | }; | 326 | }; |
327 | 327 | ||
328 | 328 | ||
329 | void DesktopApplication::switchLCD ( bool on ) | 329 | void DesktopApplication::switchLCD ( bool on ) |
330 | { | 330 | { |
331 | if ( qApp ) { | 331 | if ( qApp ) { |
332 | DesktopApplication *dapp = (DesktopApplication *) qApp; | 332 | DesktopApplication *dapp = (DesktopApplication *) qApp; |
333 | 333 | ||
334 | if ( dapp-> m_screensaver ) { | 334 | if ( dapp-> m_screensaver ) { |
335 | if ( on ) | 335 | if ( on ) { |
336 | dapp-> m_screensaver-> restore ( ); //setBacklight ( on ? -3 : -1 ); | 336 | dapp-> m_screensaver-> setDisplayState ( true ); |
337 | else | 337 | dapp-> m_screensaver-> setBacklight ( -3 ); |
338 | dapp-> m_screensaver-> save ( 1 ); | 338 | } |
339 | 339 | else { | |
340 | } | 340 | dapp-> m_screensaver-> setDisplayState ( false ); |
341 | } | ||
342 | } | ||
341 | } | 343 | } |
342 | } | 344 | } |
343 | 345 | ||
344 | 346 | ||
345 | DesktopApplication::DesktopApplication( int& argc, char **argv, Type appType ) | 347 | DesktopApplication::DesktopApplication( int& argc, char **argv, Type appType ) |
346 | : QPEApplication( argc, argv, appType ) | 348 | : QPEApplication( argc, argv, appType ) |
347 | { | 349 | { |
348 | 350 | ||
349 | QTimer * t = new QTimer( this ); | 351 | QTimer * t = new QTimer( this ); |
350 | connect( t, SIGNAL( timeout() ), this, SLOT( psTimeout() ) ); | 352 | connect( t, SIGNAL( timeout() ), this, SLOT( psTimeout() ) ); |
351 | t->start( 10000 ); | 353 | t->start( 10000 ); |
352 | ps = new PowerStatus; | 354 | ps = new PowerStatus; |
353 | pa = new DesktopPowerAlerter( 0 ); | 355 | pa = new DesktopPowerAlerter( 0 ); |
354 | 356 | ||
355 | channel = new QCopChannel( "QPE/Desktop", this ); | 357 | channel = new QCopChannel( "QPE/Desktop", this ); |
356 | connect( channel, SIGNAL( received( const QCString&, const QByteArray& ) ), | 358 | connect( channel, SIGNAL( received( const QCString&, const QByteArray& ) ), |
357 | this, SLOT( desktopMessage( const QCString&, const QByteArray& ) ) ); | 359 | this, SLOT( desktopMessage( const QCString&, const QByteArray& ) ) ); |
358 | 360 | ||
359 | channel = new QCopChannel( "QPE/System", this ); | 361 | channel = new QCopChannel( "QPE/System", this ); |
360 | connect( channel, SIGNAL( received( const QCString&, const QByteArray& ) ), | 362 | connect( channel, SIGNAL( received( const QCString&, const QByteArray& ) ), |
361 | this, SLOT( systemMessage( const QCString&, const QByteArray& ) ) ); | 363 | this, SLOT( systemMessage( const QCString&, const QByteArray& ) ) ); |
362 | 364 | ||
363 | m_screensaver = new QPEScreenSaver; | 365 | m_screensaver = new QPEScreenSaver; |
364 | 366 | ||
365 | m_screensaver-> setInterval ( -1 ); | 367 | m_screensaver-> setInterval ( -1 ); |
366 | QWSServer::setScreenSaver( m_screensaver ); | 368 | QWSServer::setScreenSaver( m_screensaver ); |
367 | } | 369 | } |
368 | 370 | ||
369 | 371 | ||
370 | DesktopApplication::~DesktopApplication() | 372 | DesktopApplication::~DesktopApplication() |
371 | { | 373 | { |
372 | delete ps; | 374 | delete ps; |
373 | delete pa; | 375 | delete pa; |
374 | } | 376 | } |
375 | 377 | ||
376 | void DesktopApplication::desktopMessage( const QCString &msg, const QByteArray &data ) | 378 | void DesktopApplication::desktopMessage( const QCString &msg, const QByteArray &data ) |
377 | { | 379 | { |
378 | #ifdef Q_WS_QWS | 380 | #ifdef Q_WS_QWS |
379 | QDataStream stream( data, IO_ReadOnly ); | 381 | QDataStream stream( data, IO_ReadOnly ); |
380 | if ( msg == "keyRegister(int key, QString channel, QString message)" ) { | 382 | if ( msg == "keyRegister(int key, QString channel, QString message)" ) { |
381 | int k; | 383 | int k; |
382 | QString c, m; | 384 | QString c, m; |
383 | stream >> k; | 385 | stream >> k; |
384 | stream >> c; | 386 | stream >> c; |
385 | stream >> m; | 387 | stream >> m; |
386 | 388 | ||
387 | qWarning( "KeyRegisterReceived: %i, %s, %s", k, ( const char* ) c, ( const char * ) m ); | 389 | qWarning( "KeyRegisterReceived: %i, %s, %s", k, ( const char* ) c, ( const char * ) m ); |
388 | keyRegisterList.append( QCopKeyRegister( k, c, m ) ); | 390 | keyRegisterList.append( QCopKeyRegister( k, c, m ) ); |
389 | } | 391 | } |
390 | #endif | 392 | #endif |
391 | } | 393 | } |
392 | 394 | ||
393 | 395 | ||
394 | void DesktopApplication::systemMessage( const QCString & msg, const QByteArray & data ) | 396 | void DesktopApplication::systemMessage( const QCString & msg, const QByteArray & data ) |
395 | { | 397 | { |
396 | #ifdef Q_WS_QWS | 398 | #ifdef Q_WS_QWS |
397 | QDataStream stream ( data, IO_ReadOnly ); | 399 | QDataStream stream ( data, IO_ReadOnly ); |
398 | 400 | ||
399 | if ( msg == "setScreenSaverInterval(int)" ) { | 401 | if ( msg == "setScreenSaverInterval(int)" ) { |
400 | int time; | 402 | int time; |
401 | stream >> time; | 403 | stream >> time; |
402 | m_screensaver-> setInterval( time ); | 404 | m_screensaver-> setInterval( time ); |
403 | } | 405 | } |
404 | else if ( msg == "setScreenSaverIntervals(int,int,int)" ) { | 406 | else if ( msg == "setScreenSaverIntervals(int,int,int)" ) { |
405 | int t1, t2, t3; | 407 | int t1, t2, t3; |
406 | stream >> t1 >> t2 >> t3; | 408 | stream >> t1 >> t2 >> t3; |
407 | m_screensaver-> setIntervals( t1, t2, t3 ); | 409 | m_screensaver-> setIntervals( t1, t2, t3 ); |
408 | } | 410 | } |
409 | else if ( msg == "setBacklight(int)" ) { | 411 | else if ( msg == "setBacklight(int)" ) { |
410 | int bright; | 412 | int bright; |
411 | stream >> bright; | 413 | stream >> bright; |
412 | m_screensaver-> setBacklight( bright ); | 414 | m_screensaver-> setBacklight( bright ); |
413 | } | 415 | } |
414 | else if ( msg == "setScreenSaverMode(int)" ) { | 416 | else if ( msg == "setScreenSaverMode(int)" ) { |
415 | int mode; | 417 | int mode; |
416 | stream >> mode; | 418 | stream >> mode; |
417 | m_screensaver-> setMode ( mode ); | 419 | m_screensaver-> setMode ( mode ); |
418 | } | 420 | } |
419 | else if ( msg == "setDisplayState(int)" ) { | 421 | else if ( msg == "setDisplayState(int)" ) { |
420 | int state; | 422 | int state; |
421 | stream >> state; | 423 | stream >> state; |
422 | m_screensaver-> setDisplayState ( state != 0 ); | 424 | m_screensaver-> setDisplayState ( state != 0 ); |
423 | } | 425 | } |
424 | else if ( msg == "suspend()" ) { | 426 | else if ( msg == "suspend()" ) { |
425 | emit power(); | 427 | emit power(); |
426 | } | 428 | } |
427 | #endif | 429 | #endif |
428 | } | 430 | } |
429 | 431 | ||
430 | enum MemState { Unknown, VeryLow, Low, Normal } memstate = Unknown; | 432 | enum MemState { Unknown, VeryLow, Low, Normal } memstate = Unknown; |
431 | 433 | ||
432 | #ifdef Q_WS_QWS | 434 | #ifdef Q_WS_QWS |
433 | bool DesktopApplication::qwsEventFilter( QWSEvent *e ) | 435 | bool DesktopApplication::qwsEventFilter( QWSEvent *e ) |
434 | { | 436 | { |
435 | qpedesktop->checkMemory(); | 437 | qpedesktop->checkMemory(); |
436 | 438 | ||
437 | if ( e->type == QWSEvent::Key ) { | 439 | if ( e->type == QWSEvent::Key ) { |
438 | QWSKeyEvent * ke = ( QWSKeyEvent * ) e; | 440 | QWSKeyEvent * ke = ( QWSKeyEvent * ) e; |
439 | if ( !loggedin && ke->simpleData.keycode != Key_F34 ) | 441 | if ( !loggedin && ke->simpleData.keycode != Key_F34 ) |
440 | return TRUE; | 442 | return TRUE; |
441 | bool press = ke->simpleData.is_press; | 443 | bool press = ke->simpleData.is_press; |
442 | bool autoRepeat = ke->simpleData.is_auto_repeat; | 444 | bool autoRepeat = ke->simpleData.is_auto_repeat; |
443 | 445 | ||
444 | /* | 446 | /* |
445 | app that registers key/message to be sent back to the app, when it doesn't have focus, | 447 | app that registers key/message to be sent back to the app, when it doesn't have focus, |
446 | when user presses key, unless keyboard has been requested from app. | 448 | when user presses key, unless keyboard has been requested from app. |
447 | will not send multiple repeats if user holds key | 449 | will not send multiple repeats if user holds key |
448 | i.e. one shot | 450 | i.e. one shot |
449 | */ | 451 | */ |
450 | if ( !keyRegisterList.isEmpty() && ke->simpleData.keycode !=0 && press) { | 452 | if ( !keyRegisterList.isEmpty() && ke->simpleData.keycode !=0 && press) { |
451 | // qDebug("<<<<<<<<<<<<<keycode %d", ke->simpleData.keycode); | 453 | // qDebug("<<<<<<<<<<<<<keycode %d", ke->simpleData.keycode); |
452 | KeyRegisterList::Iterator it; | 454 | KeyRegisterList::Iterator it; |
453 | for ( it = keyRegisterList.begin(); it != keyRegisterList.end(); ++it ) { | 455 | for ( it = keyRegisterList.begin(); it != keyRegisterList.end(); ++it ) { |
454 | if ( ( *it ).getKeyCode() == ke->simpleData.keycode && !autoRepeat && !keyboardGrabbed() ) { | 456 | if ( ( *it ).getKeyCode() == ke->simpleData.keycode && !autoRepeat && !keyboardGrabbed() ) { |
455 | if ( press ) | 457 | if ( press ) |
456 | qDebug( "press" ); | 458 | qDebug( "press" ); |
457 | else | 459 | else |
458 | qDebug( "release" ); | 460 | qDebug( "release" ); |
459 | QCopEnvelope( ( *it ).getChannel().utf8(), ( *it ).getMessage().utf8() ); | 461 | QCopEnvelope( ( *it ).getChannel().utf8(), ( *it ).getMessage().utf8() ); |
460 | } | 462 | } |
461 | } | 463 | } |
462 | } | 464 | } |
463 | 465 | ||
464 | if ( !keyboardGrabbed() ) { | 466 | if ( !keyboardGrabbed() ) { |
465 | if ( ke->simpleData.keycode == Key_F9 ) { | 467 | if ( ke->simpleData.keycode == Key_F9 ) { |
466 | if ( press ) | 468 | if ( press ) |
467 | emit datebook(); | 469 | emit datebook(); |
468 | return TRUE; | 470 | return TRUE; |
469 | } | 471 | } |
470 | if ( ke->simpleData.keycode == Key_F10 ) { | 472 | if ( ke->simpleData.keycode == Key_F10 ) { |
471 | if ( !press && cardSendTimer ) { | 473 | if ( !press && cardSendTimer ) { |
472 | emit contacts(); | 474 | emit contacts(); |
473 | delete cardSendTimer; | 475 | delete cardSendTimer; |
474 | } | 476 | } |
475 | else if ( press ) { | 477 | else if ( press ) { |
476 | cardSendTimer = new QTimer(); | 478 | cardSendTimer = new QTimer(); |
477 | cardSendTimer->start( 2000, TRUE ); | 479 | cardSendTimer->start( 2000, TRUE ); |
478 | connect( cardSendTimer, SIGNAL( timeout() ), this, SLOT( sendCard() ) ); | 480 | connect( cardSendTimer, SIGNAL( timeout() ), this, SLOT( sendCard() ) ); |
479 | } | 481 | } |
480 | return TRUE; | 482 | return TRUE; |
481 | } | 483 | } |
482 | /* menu key now opens application menu/toolbar | 484 | /* menu key now opens application menu/toolbar |
483 | if ( ke->simpleData.keycode == Key_F11 ) { | 485 | if ( ke->simpleData.keycode == Key_F11 ) { |
484 | if ( press ) emit menu(); | 486 | if ( press ) emit menu(); |
485 | return TRUE; | 487 | return TRUE; |
486 | } | 488 | } |
487 | */ | 489 | */ |
488 | if ( ke->simpleData.keycode == Key_F12 ) { | 490 | if ( ke->simpleData.keycode == Key_F12 ) { |
489 | while ( activePopupWidget() ) | 491 | while ( activePopupWidget() ) |
490 | activePopupWidget() ->close(); | 492 | activePopupWidget() ->close(); |
491 | if ( press ) | 493 | if ( press ) |
492 | emit launch(); | 494 | emit launch(); |
493 | return TRUE; | 495 | return TRUE; |
494 | } | 496 | } |
495 | if ( ke->simpleData.keycode == Key_F13 ) { | 497 | if ( ke->simpleData.keycode == Key_F13 ) { |
496 | if ( press ) | 498 | if ( press ) |
497 | emit email(); | 499 | emit email(); |
498 | return TRUE; | 500 | return TRUE; |
499 | } | 501 | } |
500 | } | 502 | } |
501 | 503 | ||
502 | if ( ke->simpleData.keycode == Key_F34 ) { | 504 | if ( ke->simpleData.keycode == Key_F34 ) { |
503 | if ( press ) | 505 | if ( press ) |
504 | emit power(); | 506 | emit power(); |
505 | return TRUE; | 507 | return TRUE; |
506 | } | 508 | } |
507 | // This was used for the iPAQ PowerButton | 509 | // This was used for the iPAQ PowerButton |
508 | // See main.cpp for new KeyboardFilter | 510 | // See main.cpp for new KeyboardFilter |
509 | // | 511 | // |
510 | // if ( ke->simpleData.keycode == Key_SysReq ) { | 512 | // if ( ke->simpleData.keycode == Key_SysReq ) { |
511 | // if ( press ) emit power(); | 513 | // if ( press ) emit power(); |
512 | // return TRUE; | 514 | // return TRUE; |
513 | // } | 515 | // } |
514 | if ( ke->simpleData.keycode == Key_F35 ) { | 516 | if ( ke->simpleData.keycode == Key_F35 ) { |
515 | if ( press ) | 517 | if ( press ) |
516 | emit backlight(); | 518 | emit backlight(); |
517 | return TRUE; | 519 | return TRUE; |
518 | } | 520 | } |
519 | if ( ke->simpleData.keycode == Key_F32 ) { | 521 | if ( ke->simpleData.keycode == Key_F32 ) { |
520 | if ( press ) | 522 | if ( press ) |
521 | QCopEnvelope e( "QPE/Desktop", "startSync()" ); | 523 | QCopEnvelope e( "QPE/Desktop", "startSync()" ); |
522 | return TRUE; | 524 | return TRUE; |
523 | } | 525 | } |
524 | if ( ke->simpleData.keycode == Key_F31 && !ke->simpleData.modifiers ) { | 526 | if ( ke->simpleData.keycode == Key_F31 && !ke->simpleData.modifiers ) { |
525 | if ( press ) | 527 | if ( press ) |
526 | emit symbol(); | 528 | emit symbol(); |
527 | return TRUE; | 529 | return TRUE; |
528 | } | 530 | } |
529 | if ( ke->simpleData.keycode == Key_NumLock ) { | 531 | if ( ke->simpleData.keycode == Key_NumLock ) { |
530 | if ( press ) | 532 | if ( press ) |
531 | emit numLockStateToggle(); | 533 | emit numLockStateToggle(); |
532 | } | 534 | } |
@@ -673,367 +675,377 @@ void Desktop::checkMemory() | |||
673 | return ; // don't show a second message while still on first | 675 | return ; // don't show a second message while still on first |
674 | 676 | ||
675 | existingMessage = TRUE; | 677 | existingMessage = TRUE; |
676 | switch ( memstate ) { | 678 | switch ( memstate ) { |
677 | case Unknown: | 679 | case Unknown: |
678 | break; | 680 | break; |
679 | case Low: | 681 | case Low: |
680 | memstate = Unknown; | 682 | memstate = Unknown; |
681 | if ( recoverMemory() ) | 683 | if ( recoverMemory() ) |
682 | ignoreNormal = TRUE; | 684 | ignoreNormal = TRUE; |
683 | else | 685 | else |
684 | QMessageBox::warning( 0 , "Memory Status", | 686 | QMessageBox::warning( 0 , "Memory Status", |
685 | "The memory smacks of shortage. \n" | 687 | "The memory smacks of shortage. \n" |
686 | "Please save data. " ); | 688 | "Please save data. " ); |
687 | break; | 689 | break; |
688 | case Normal: | 690 | case Normal: |
689 | memstate = Unknown; | 691 | memstate = Unknown; |
690 | if ( ignoreNormal ) | 692 | if ( ignoreNormal ) |
691 | ignoreNormal = FALSE; | 693 | ignoreNormal = FALSE; |
692 | // else | 694 | // else |
693 | // QMessageBox::information ( 0 , "Memory Status", | 695 | // QMessageBox::information ( 0 , "Memory Status", |
694 | // "There is enough memory again." ); | 696 | // "There is enough memory again." ); |
695 | break; | 697 | break; |
696 | case VeryLow: | 698 | case VeryLow: |
697 | memstate = Unknown; | 699 | memstate = Unknown; |
698 | QMessageBox::critical( 0 , "Memory Status", | 700 | QMessageBox::critical( 0 , "Memory Status", |
699 | "The memory is very low. \n" | 701 | "The memory is very low. \n" |
700 | "Please end this application \n" | 702 | "Please end this application \n" |
701 | "immediately." ); | 703 | "immediately." ); |
702 | recoverMemory(); | 704 | recoverMemory(); |
703 | } | 705 | } |
704 | existingMessage = FALSE; | 706 | existingMessage = FALSE; |
705 | #endif | 707 | #endif |
706 | } | 708 | } |
707 | 709 | ||
708 | static bool isVisibleWindow( int wid ) | 710 | static bool isVisibleWindow( int wid ) |
709 | { | 711 | { |
710 | const QList<QWSWindow> &list = qwsServer->clientWindows(); | 712 | const QList<QWSWindow> &list = qwsServer->clientWindows(); |
711 | QWSWindow* w; | 713 | QWSWindow* w; |
712 | for ( QListIterator<QWSWindow> it( list ); ( w = it.current() ); ++it ) { | 714 | for ( QListIterator<QWSWindow> it( list ); ( w = it.current() ); ++it ) { |
713 | if ( w->winId() == wid ) | 715 | if ( w->winId() == wid ) |
714 | return !w->isFullyObscured(); | 716 | return !w->isFullyObscured(); |
715 | } | 717 | } |
716 | return FALSE; | 718 | return FALSE; |
717 | } | 719 | } |
718 | 720 | ||
719 | static bool hasVisibleWindow( const QString& clientname ) | 721 | static bool hasVisibleWindow( const QString& clientname ) |
720 | { | 722 | { |
721 | const QList<QWSWindow> &list = qwsServer->clientWindows(); | 723 | const QList<QWSWindow> &list = qwsServer->clientWindows(); |
722 | QWSWindow* w; | 724 | QWSWindow* w; |
723 | for ( QListIterator<QWSWindow> it( list ); ( w = it.current() ); ++it ) { | 725 | for ( QListIterator<QWSWindow> it( list ); ( w = it.current() ); ++it ) { |
724 | if ( w->client() ->identity() == clientname && !w->isFullyObscured() ) | 726 | if ( w->client() ->identity() == clientname && !w->isFullyObscured() ) |
725 | return TRUE; | 727 | return TRUE; |
726 | } | 728 | } |
727 | return FALSE; | 729 | return FALSE; |
728 | } | 730 | } |
729 | 731 | ||
730 | void Desktop::raiseLauncher() | 732 | void Desktop::raiseLauncher() |
731 | { | 733 | { |
732 | Config cfg( "qpe" ); //F12 'Home' | 734 | Config cfg( "qpe" ); //F12 'Home' |
733 | cfg.setGroup( "AppsKey" ); | 735 | cfg.setGroup( "AppsKey" ); |
734 | QString tempItem; | 736 | QString tempItem; |
735 | tempItem = cfg.readEntry( "Middle", "Home" ); | 737 | tempItem = cfg.readEntry( "Middle", "Home" ); |
736 | if ( tempItem == "Home" || tempItem.isEmpty() ) { | 738 | if ( tempItem == "Home" || tempItem.isEmpty() ) { |
737 | home ( ); | 739 | home ( ); |
738 | } | 740 | } |
739 | else { | 741 | else { |
740 | QCopEnvelope e( "QPE/System", "execute(QString)" ); | 742 | QCopEnvelope e( "QPE/System", "execute(QString)" ); |
741 | e << tempItem; | 743 | e << tempItem; |
742 | } | 744 | } |
743 | } | 745 | } |
744 | 746 | ||
745 | void Desktop::home ( ) | 747 | void Desktop::home ( ) |
746 | { | 748 | { |
747 | if ( isVisibleWindow( launcher->winId() ) ) | 749 | if ( isVisibleWindow( launcher->winId() ) ) |
748 | launcher->nextView(); | 750 | launcher->nextView(); |
749 | else | 751 | else |
750 | launcher->raise(); | 752 | launcher->raise(); |
751 | } | 753 | } |
752 | 754 | ||
753 | void Desktop::executeOrModify( const QString& appLnkFile ) | 755 | void Desktop::executeOrModify( const QString& appLnkFile ) |
754 | { | 756 | { |
755 | AppLnk lnk( MimeType::appsFolderName() + "/" + appLnkFile ); | 757 | AppLnk lnk( MimeType::appsFolderName() + "/" + appLnkFile ); |
756 | if ( lnk.isValid() ) { | 758 | if ( lnk.isValid() ) { |
757 | QCString app = lnk.exec().utf8(); | 759 | QCString app = lnk.exec().utf8(); |
758 | Global::terminateBuiltin( "calibrate" ); | 760 | Global::terminateBuiltin( "calibrate" ); |
759 | if ( QCopChannel::isRegistered( "QPE/Application/" + app ) ) { | 761 | if ( QCopChannel::isRegistered( "QPE/Application/" + app ) ) { |
760 | // MRUList::addTask( &lnk ); | 762 | // MRUList::addTask( &lnk ); |
761 | if ( hasVisibleWindow( app ) ) | 763 | if ( hasVisibleWindow( app ) ) |
762 | QCopChannel::send( "QPE/Application/" + app, "nextView()" ); | 764 | QCopChannel::send( "QPE/Application/" + app, "nextView()" ); |
763 | else | 765 | else |
764 | QCopChannel::send( "QPE/Application/" + app, "raise()" ); | 766 | QCopChannel::send( "QPE/Application/" + app, "raise()" ); |
765 | } | 767 | } |
766 | else { | 768 | else { |
767 | lnk.execute(); | 769 | lnk.execute(); |
768 | } | 770 | } |
769 | } | 771 | } |
770 | } | 772 | } |
771 | 773 | ||
772 | void Desktop::raiseDatebook() | 774 | void Desktop::raiseDatebook() |
773 | { | 775 | { |
774 | Config cfg( "qpe" ); //F9 'Activity' | 776 | Config cfg( "qpe" ); //F9 'Activity' |
775 | cfg.setGroup( "AppsKey" ); | 777 | cfg.setGroup( "AppsKey" ); |
776 | QString tempItem; | 778 | QString tempItem; |
777 | tempItem = cfg.readEntry( "LeftEnd" , "Calendar" ); | 779 | tempItem = cfg.readEntry( "LeftEnd" , "Calendar" ); |
778 | if ( tempItem == "Calendar" || tempItem.isEmpty() ) { | 780 | if ( tempItem == "Calendar" || tempItem.isEmpty() ) { |
779 | tempItem = "datebook"; | 781 | tempItem = "datebook"; |
780 | } | 782 | } |
781 | QCopEnvelope e( "QPE/System", "execute(QString)" ); | 783 | QCopEnvelope e( "QPE/System", "execute(QString)" ); |
782 | e << tempItem; | 784 | e << tempItem; |
783 | } | 785 | } |
784 | 786 | ||
785 | void Desktop::raiseContacts() | 787 | void Desktop::raiseContacts() |
786 | { | 788 | { |
787 | Config cfg( "qpe" ); //F10, 'Contacts' | 789 | Config cfg( "qpe" ); //F10, 'Contacts' |
788 | cfg.setGroup( "AppsKey" ); | 790 | cfg.setGroup( "AppsKey" ); |
789 | QString tempItem; | 791 | QString tempItem; |
790 | tempItem = cfg.readEntry( "Left2nd", "Address Book" ); | 792 | tempItem = cfg.readEntry( "Left2nd", "Address Book" ); |
791 | if ( tempItem == "Address Book" || tempItem.isEmpty() ) { | 793 | if ( tempItem == "Address Book" || tempItem.isEmpty() ) { |
792 | tempItem = "addressbook"; | 794 | tempItem = "addressbook"; |
793 | } | 795 | } |
794 | QCopEnvelope e( "QPE/System", "execute(QString)" ); | 796 | QCopEnvelope e( "QPE/System", "execute(QString)" ); |
795 | e << tempItem; | 797 | e << tempItem; |
796 | } | 798 | } |
797 | 799 | ||
798 | void Desktop::raiseMenu() | 800 | void Desktop::raiseMenu() |
799 | { | 801 | { |
800 | Config cfg( "qpe" ); //F11, 'Menu | 802 | Config cfg( "qpe" ); //F11, 'Menu |
801 | cfg.setGroup( "AppsKey" ); | 803 | cfg.setGroup( "AppsKey" ); |
802 | QString tempItem; | 804 | QString tempItem; |
803 | tempItem = cfg.readEntry( "Right2nd" , "Popup Menu" ); | 805 | tempItem = cfg.readEntry( "Right2nd" , "Popup Menu" ); |
804 | if ( tempItem == "Popup Menu" || tempItem.isEmpty() ) { | 806 | if ( tempItem == "Popup Menu" || tempItem.isEmpty() ) { |
805 | Global::terminateBuiltin( "calibrate" ); | 807 | Global::terminateBuiltin( "calibrate" ); |
806 | tb->startMenu() ->launch(); | 808 | tb->startMenu() ->launch(); |
807 | } | 809 | } |
808 | else { | 810 | else { |
809 | QCopEnvelope e( "QPE/System", "execute(QString)" ); | 811 | QCopEnvelope e( "QPE/System", "execute(QString)" ); |
810 | e << tempItem; | 812 | e << tempItem; |
811 | } | 813 | } |
812 | } | 814 | } |
813 | 815 | ||
814 | void Desktop::raiseEmail() | 816 | void Desktop::raiseEmail() |
815 | { | 817 | { |
816 | Config cfg( "qpe" ); //F13, 'Mail' // only in zaurus, on ipaq mail key is F11 | 818 | Config cfg( "qpe" ); //F13, 'Mail' // only in zaurus, on ipaq mail key is F11 |
817 | cfg.setGroup( "AppsKey" ); | 819 | cfg.setGroup( "AppsKey" ); |
818 | QString tempItem; | 820 | QString tempItem; |
819 | tempItem = cfg.readEntry( "RightEnd", "Mail" ); | 821 | tempItem = cfg.readEntry( "RightEnd", "Mail" ); |
820 | if ( tempItem == "Mail" || tempItem == "qtmail" || tempItem.isEmpty() ) { | 822 | if ( tempItem == "Mail" || tempItem == "qtmail" || tempItem.isEmpty() ) { |
821 | tempItem = "mail"; | 823 | tempItem = "mail"; |
822 | } | 824 | } |
823 | QCopEnvelope e( "QPE/System", "execute(QString)" ); | 825 | QCopEnvelope e( "QPE/System", "execute(QString)" ); |
824 | e << tempItem; | 826 | e << tempItem; |
825 | } | 827 | } |
826 | 828 | ||
827 | // autoStarts apps on resume and start | 829 | // autoStarts apps on resume and start |
828 | void Desktop::execAutoStart() | 830 | void Desktop::execAutoStart() |
829 | { | 831 | { |
830 | QString appName; | 832 | QString appName; |
831 | int delay; | 833 | int delay; |
832 | QDateTime now = QDateTime::currentDateTime(); | 834 | QDateTime now = QDateTime::currentDateTime(); |
833 | Config cfg( "autostart" ); | 835 | Config cfg( "autostart" ); |
834 | cfg.setGroup( "AutoStart" ); | 836 | cfg.setGroup( "AutoStart" ); |
835 | appName = cfg.readEntry( "Apps", "" ); | 837 | appName = cfg.readEntry( "Apps", "" ); |
836 | delay = ( cfg.readEntry( "Delay", "0" ) ).toInt(); | 838 | delay = ( cfg.readEntry( "Delay", "0" ) ).toInt(); |
837 | // If the time between suspend and resume was longer then the | 839 | // If the time between suspend and resume was longer then the |
838 | // value saved as delay, start the app | 840 | // value saved as delay, start the app |
839 | if ( suspendTime.secsTo( now ) >= ( delay * 60 ) && !appName.isEmpty() ) { | 841 | if ( suspendTime.secsTo( now ) >= ( delay * 60 ) && !appName.isEmpty() ) { |
840 | QCopEnvelope e( "QPE/System", "execute(QString)" ); | 842 | QCopEnvelope e( "QPE/System", "execute(QString)" ); |
841 | e << QString( appName ); | 843 | e << QString( appName ); |
842 | } | 844 | } |
843 | } | 845 | } |
844 | 846 | ||
845 | #if defined(QPE_HAVE_TOGGLELIGHT) | 847 | #if defined(QPE_HAVE_TOGGLELIGHT) |
846 | #include <qpe/config.h> | 848 | #include <qpe/config.h> |
847 | 849 | ||
848 | #include <sys/ioctl.h> | 850 | #include <sys/ioctl.h> |
849 | #include <sys/types.h> | 851 | #include <sys/types.h> |
850 | #include <fcntl.h> | 852 | #include <fcntl.h> |
851 | #include <unistd.h> | 853 | #include <unistd.h> |
852 | #include <errno.h> | 854 | #include <errno.h> |
853 | #include <linux/ioctl.h> | 855 | #include <linux/ioctl.h> |
854 | #include <time.h> | 856 | #include <time.h> |
855 | #endif | 857 | #endif |
856 | 858 | ||
857 | 859 | ||
858 | void Desktop::togglePower() | 860 | void Desktop::togglePower() |
859 | { | 861 | { |
860 | static bool excllock = false; | 862 | static bool excllock = false; |
861 | 863 | ||
862 | qDebug ( "togglePower (locked == %d)", excllock ? 1 : 0 ); | 864 | qDebug ( "togglePower (locked == %d)", excllock ? 1 : 0 ); |
863 | 865 | ||
864 | if ( excllock ) | 866 | if ( excllock ) |
865 | return ; | 867 | return; |
866 | 868 | ||
867 | excllock = true; | 869 | excllock = true; |
868 | 870 | ||
869 | bool wasloggedin = loggedin; | 871 | bool wasloggedin = loggedin; |
870 | loggedin = 0; | 872 | loggedin = 0; |
871 | suspendTime = QDateTime::currentDateTime(); | 873 | suspendTime = QDateTime::currentDateTime(); |
872 | 874 | ||
873 | ODevice::inst ( ) -> suspend ( ); | 875 | #ifdef QWS |
876 | if ( Password::needToAuthenticate ( true ) && qt_screen ) { | ||
877 | // Should use a big black window instead. | ||
878 | // But this would not show up fast enough | ||
879 | QGfx *g = qt_screen-> screenGfx ( ); | ||
880 | g-> fillRect ( 0, 0, qt_screen-> width ( ), qt_screen-> height ( )); | ||
881 | delete g; | ||
882 | } | ||
883 | #endif | ||
884 | |||
885 | ODevice::inst ( )-> suspend ( ); | ||
874 | 886 | ||
875 | QWSServer::screenSaverActivate ( false ); | ||
876 | DesktopApplication::switchLCD ( true ); // force LCD on without slow qcop call | 887 | DesktopApplication::switchLCD ( true ); // force LCD on without slow qcop call |
888 | QWSServer::screenSaverActivate ( false ); | ||
877 | 889 | ||
878 | { | 890 | { |
879 | QCopEnvelope( "QPE/Card", "mtabChanged()" ); // might have changed while asleep | 891 | QCopEnvelope( "QPE/Card", "mtabChanged()" ); // might have changed while asleep |
880 | } | 892 | } |
881 | 893 | ||
882 | if ( wasloggedin ) | 894 | if ( wasloggedin ) |
883 | login( TRUE ); | 895 | login ( true ); |
884 | 896 | ||
885 | execAutoStart(); | 897 | execAutoStart(); |
886 | //qcopBridge->closeOpenConnections(); | 898 | //qcopBridge->closeOpenConnections(); |
887 | 899 | ||
888 | excllock = false; | 900 | excllock = false; |
889 | } | 901 | } |
890 | 902 | ||
891 | void Desktop::toggleLight() | 903 | void Desktop::toggleLight() |
892 | { | 904 | { |
893 | QCopEnvelope e( "QPE/System", "setBacklight(int)" ); | 905 | QCopEnvelope e( "QPE/System", "setBacklight(int)" ); |
894 | e << -2; // toggle | 906 | e << -2; // toggle |
895 | } | 907 | } |
896 | 908 | ||
897 | void Desktop::toggleSymbolInput() | 909 | void Desktop::toggleSymbolInput() |
898 | { | 910 | { |
899 | tb->toggleSymbolInput(); | 911 | tb->toggleSymbolInput(); |
900 | } | 912 | } |
901 | 913 | ||
902 | void Desktop::toggleNumLockState() | 914 | void Desktop::toggleNumLockState() |
903 | { | 915 | { |
904 | tb->toggleNumLockState(); | 916 | tb->toggleNumLockState(); |
905 | } | 917 | } |
906 | 918 | ||
907 | void Desktop::toggleCapsLockState() | 919 | void Desktop::toggleCapsLockState() |
908 | { | 920 | { |
909 | tb->toggleCapsLockState(); | 921 | tb->toggleCapsLockState(); |
910 | } | 922 | } |
911 | 923 | ||
912 | void Desktop::styleChange( QStyle &s ) | 924 | void Desktop::styleChange( QStyle &s ) |
913 | { | 925 | { |
914 | QWidget::styleChange( s ); | 926 | QWidget::styleChange( s ); |
915 | int displayw = qApp->desktop() ->width(); | 927 | int displayw = qApp->desktop() ->width(); |
916 | int displayh = qApp->desktop() ->height(); | 928 | int displayh = qApp->desktop() ->height(); |
917 | 929 | ||
918 | QSize sz = tb->sizeHint(); | 930 | QSize sz = tb->sizeHint(); |
919 | 931 | ||
920 | tb->setGeometry( 0, displayh - sz.height(), displayw, sz.height() ); | 932 | tb->setGeometry( 0, displayh - sz.height(), displayw, sz.height() ); |
921 | } | 933 | } |
922 | 934 | ||
923 | void DesktopApplication::shutdown() | 935 | void DesktopApplication::shutdown() |
924 | { | 936 | { |
925 | if ( type() != GuiServer ) | 937 | if ( type() != GuiServer ) |
926 | return ; | 938 | return ; |
927 | ShutdownImpl *sd = new ShutdownImpl( 0, 0, WDestructiveClose ); | 939 | ShutdownImpl *sd = new ShutdownImpl( 0, 0, WDestructiveClose ); |
928 | connect( sd, SIGNAL( shutdown( ShutdownImpl::Type ) ), | 940 | connect( sd, SIGNAL( shutdown( ShutdownImpl::Type ) ), |
929 | this, SLOT( shutdown( ShutdownImpl::Type ) ) ); | 941 | this, SLOT( shutdown( ShutdownImpl::Type ) ) ); |
930 | sd->showMaximized(); | 942 | sd->showMaximized(); |
931 | } | 943 | } |
932 | 944 | ||
933 | void DesktopApplication::shutdown( ShutdownImpl::Type t ) | 945 | void DesktopApplication::shutdown( ShutdownImpl::Type t ) |
934 | { | 946 | { |
935 | switch ( t ) { | 947 | switch ( t ) { |
936 | case ShutdownImpl::ShutdownSystem: | 948 | case ShutdownImpl::ShutdownSystem: |
937 | execlp( "shutdown", "shutdown", "-h", "now", ( void* ) 0 ); | 949 | execlp( "shutdown", "shutdown", "-h", "now", ( void* ) 0 ); |
938 | break; | 950 | break; |
939 | case ShutdownImpl::RebootSystem: | 951 | case ShutdownImpl::RebootSystem: |
940 | execlp( "shutdown", "shutdown", "-r", "now", ( void* ) 0 ); | 952 | execlp( "shutdown", "shutdown", "-r", "now", ( void* ) 0 ); |
941 | break; | 953 | break; |
942 | case ShutdownImpl::RestartDesktop: | 954 | case ShutdownImpl::RestartDesktop: |
943 | restart(); | 955 | restart(); |
944 | break; | 956 | break; |
945 | case ShutdownImpl::TerminateDesktop: | 957 | case ShutdownImpl::TerminateDesktop: |
946 | prepareForTermination( FALSE ); | 958 | prepareForTermination( FALSE ); |
947 | 959 | ||
948 | // This is a workaround for a Qt bug | 960 | // This is a workaround for a Qt bug |
949 | // clipboard applet has to stop its poll timer, or Qt/E | 961 | // clipboard applet has to stop its poll timer, or Qt/E |
950 | // will hang on quit() right before it emits aboutToQuit() | 962 | // will hang on quit() right before it emits aboutToQuit() |
951 | emit aboutToQuit ( ); | 963 | emit aboutToQuit ( ); |
952 | 964 | ||
953 | quit(); | 965 | quit(); |
954 | break; | 966 | break; |
955 | } | 967 | } |
956 | } | 968 | } |
957 | 969 | ||
958 | void DesktopApplication::restart() | 970 | void DesktopApplication::restart() |
959 | { | 971 | { |
960 | prepareForTermination( TRUE ); | 972 | prepareForTermination( TRUE ); |
961 | 973 | ||
962 | #ifdef Q_WS_QWS | 974 | #ifdef Q_WS_QWS |
963 | 975 | ||
964 | for ( int fd = 3; fd < 100; fd++ ) | 976 | for ( int fd = 3; fd < 100; fd++ ) |
965 | close( fd ); | 977 | close( fd ); |
966 | #if defined(QT_DEMO_SINGLE_FLOPPY) | 978 | #if defined(QT_DEMO_SINGLE_FLOPPY) |
967 | 979 | ||
968 | execl( "/sbin/init", "qpe", 0 ); | 980 | execl( "/sbin/init", "qpe", 0 ); |
969 | #elif defined(QT_QWS_CASSIOPEIA) | 981 | #elif defined(QT_QWS_CASSIOPEIA) |
970 | 982 | ||
971 | execl( "/bin/sh", "sh", 0 ); | 983 | execl( "/bin/sh", "sh", 0 ); |
972 | #else | 984 | #else |
973 | 985 | ||
974 | execl( ( qpeDir() + "/bin/qpe" ).latin1(), "qpe", 0 ); | 986 | execl( ( qpeDir() + "/bin/qpe" ).latin1(), "qpe", 0 ); |
975 | #endif | 987 | #endif |
976 | 988 | ||
977 | exit( 1 ); | 989 | exit( 1 ); |
978 | #endif | 990 | #endif |
979 | } | 991 | } |
980 | 992 | ||
981 | void Desktop::startTransferServer() | 993 | void Desktop::startTransferServer() |
982 | { | 994 | { |
983 | // start qcop bridge server | 995 | // start qcop bridge server |
984 | qcopBridge = new QCopBridge( 4243 ); | 996 | qcopBridge = new QCopBridge( 4243 ); |
985 | if ( !qcopBridge->ok() ) { | 997 | if ( !qcopBridge->ok() ) { |
986 | delete qcopBridge; | 998 | delete qcopBridge; |
987 | qcopBridge = 0; | 999 | qcopBridge = 0; |
988 | } | 1000 | } |
989 | // start transfer server | 1001 | // start transfer server |
990 | transferServer = new TransferServer( 4242 ); | 1002 | transferServer = new TransferServer( 4242 ); |
991 | if ( !transferServer->ok() ) { | 1003 | if ( !transferServer->ok() ) { |
992 | delete transferServer; | 1004 | delete transferServer; |
993 | transferServer = 0; | 1005 | transferServer = 0; |
994 | } | 1006 | } |
995 | if ( !transferServer || !qcopBridge ) | 1007 | if ( !transferServer || !qcopBridge ) |
996 | startTimer( 2000 ); | 1008 | startTimer( 2000 ); |
997 | } | 1009 | } |
998 | 1010 | ||
999 | void Desktop::timerEvent( QTimerEvent *e ) | 1011 | void Desktop::timerEvent( QTimerEvent *e ) |
1000 | { | 1012 | { |
1001 | killTimer( e->timerId() ); | 1013 | killTimer( e->timerId() ); |
1002 | startTransferServer(); | 1014 | startTransferServer(); |
1003 | } | 1015 | } |
1004 | 1016 | ||
1005 | void Desktop::terminateServers() | 1017 | void Desktop::terminateServers() |
1006 | { | 1018 | { |
1007 | delete transferServer; | 1019 | delete transferServer; |
1008 | delete qcopBridge; | 1020 | delete qcopBridge; |
1009 | transferServer = 0; | 1021 | transferServer = 0; |
1010 | qcopBridge = 0; | 1022 | qcopBridge = 0; |
1011 | } | 1023 | } |
1012 | 1024 | ||
1013 | void Desktop::rereadVolumes() | 1025 | void Desktop::rereadVolumes() |
1014 | { | 1026 | { |
1015 | Config cfg( "qpe" ); | 1027 | Config cfg( "qpe" ); |
1016 | cfg.setGroup( "Volume" ); | 1028 | cfg.setGroup( "Volume" ); |
1017 | touchclick = cfg.readBoolEntry( "TouchSound" ); | 1029 | touchclick = cfg.readBoolEntry( "TouchSound" ); |
1018 | keyclick = cfg.readBoolEntry( "KeySound" ); | 1030 | keyclick = cfg.readBoolEntry( "KeySound" ); |
1019 | alarmsound = cfg.readBoolEntry( "AlarmSound" ); | 1031 | alarmsound = cfg.readBoolEntry( "AlarmSound" ); |
1020 | } | 1032 | } |
1021 | 1033 | ||
1022 | void Desktop::keyClick() | 1034 | void Desktop::keyClick() |
1023 | { | 1035 | { |
1024 | if ( keyclick ) | 1036 | if ( keyclick ) |
1025 | ODevice::inst ( ) -> keySound ( ); | 1037 | ODevice::inst ( ) -> keySound ( ); |
1026 | } | 1038 | } |
1027 | 1039 | ||
1028 | void Desktop::screenClick() | 1040 | void Desktop::screenClick() |
1029 | { | 1041 | { |
1030 | if ( touchclick ) | 1042 | if ( touchclick ) |
1031 | ODevice::inst ( ) -> touchSound ( ); | 1043 | ODevice::inst ( ) -> touchSound ( ); |
1032 | } | 1044 | } |
1033 | 1045 | ||
1034 | void Desktop::soundAlarm() | 1046 | void Desktop::soundAlarm() |
1035 | { | 1047 | { |
1036 | if ( qpedesktop-> alarmsound ) | 1048 | if ( qpedesktop-> alarmsound ) |
1037 | ODevice::inst ( ) -> alarmSound ( ); | 1049 | ODevice::inst ( ) -> alarmSound ( ); |
1038 | } | 1050 | } |
1039 | 1051 | ||
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 | ||
37 | class PasswordDialog : public PasswordBase | 37 | class PasswordDialog : public PasswordBase |
38 | { | 38 | { |
39 | Q_OBJECT | 39 | Q_OBJECT |
40 | 40 | ||
41 | public: | 41 | public: |
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 | ||
48 | signals: | 48 | signals: |
49 | void passwordEntered( const QString& ); | 49 | void passwordEntered( const QString& ); |
50 | 50 | ||
51 | protected: | 51 | protected: |
52 | bool eventFilter( QObject*, QEvent* ); | 52 | bool eventFilter( QObject*, QEvent* ); |
53 | void keyPressEvent( QKeyEvent * ); | 53 | void keyPressEvent( QKeyEvent * ); |
54 | 54 | ||
55 | private: | 55 | private: |
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 | ||
62 | extern "C" char *crypt(const char *key, const char *salt); | 62 | extern "C" char *crypt(const char *key, const char *salt); |
63 | static QString qcrypt(const QString& k, const char *salt) | 63 | static 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 | */ |
72 | PasswordDialog::PasswordDialog( QWidget* parent, const char* name, WFlags fl ) | 72 | PasswordDialog::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 | */ |
102 | PasswordDialog::~PasswordDialog() | 102 | PasswordDialog::~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 | ||
113 | bool PasswordDialog::eventFilter( QObject*o, QEvent*e ) | 113 | bool 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 | ||
131 | void PasswordDialog::keyPressEvent( QKeyEvent * ) | 131 | void 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 | ||
146 | void PasswordDialog::input( QString c ) | 146 | void 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 | ||
156 | void PasswordDialog::setPrompt( const QString& s ) | 156 | void PasswordDialog::setPrompt( const QString& s ) |
157 | { | 157 | { |
158 | prompt->setText( s ); | 158 | prompt->setText( s ); |
159 | } | 159 | } |
160 | 160 | ||
161 | void PasswordDialog::clear() | 161 | void PasswordDialog::clear() |
162 | { | 162 | { |
163 | text = ""; | 163 | text = ""; |
164 | input(""); | 164 | input(""); |
165 | } | 165 | } |
166 | 166 | ||
167 | class PasswdDlg : public QDialog | 167 | class PasswdDlg : public QDialog |
168 | { | 168 | { |
169 | public: | 169 | public: |
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 | ||
217 | class OwnerDlg : public QDialog | 217 | class OwnerDlg : public QDialog |
218 | { | 218 | { |
219 | public: | 219 | public: |
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 | ||
257 | private: | 257 | private: |
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 | ||
268 | QString Password::getPassword( const QString& prompt ) | 268 | QString 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 | |||
296 | bool 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 | ||
295 | void Password::authenticate(bool at_poweron) | 314 | void 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 | ||
25 | class Password | 25 | class Password |
26 | { | 26 | { |
27 | public: | 27 | public: |
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 |