summaryrefslogtreecommitdiff
path: root/core
authorllornkcor <llornkcor>2002-10-20 04:30:34 (UTC)
committer llornkcor <llornkcor>2002-10-20 04:30:34 (UTC)
commite2694c5aedb3697a373e363cebe72cddb3114a8f (patch) (unidiff)
tree5ba5910a40cfc151e01a956c609f1bdd0243668e /core
parentf6a0af65b96edf63135d2b88c17b8510eebbbd51 (diff)
downloadopie-e2694c5aedb3697a373e363cebe72cddb3114a8f.zip
opie-e2694c5aedb3697a373e363cebe72cddb3114a8f.tar.gz
opie-e2694c5aedb3697a373e363cebe72cddb3114a8f.tar.bz2
fix menu button on zaurus F11 raising opie menu
Diffstat (limited to 'core') (more/less context) (ignore whitespace changes)
-rw-r--r--core/launcher/desktop.cpp10
-rw-r--r--core/launcher/desktop.h131
-rw-r--r--core/launcher/main.cpp1
3 files changed, 72 insertions, 70 deletions
diff --git a/core/launcher/desktop.cpp b/core/launcher/desktop.cpp
index 3546e28..9863187 100644
--- a/core/launcher/desktop.cpp
+++ b/core/launcher/desktop.cpp
@@ -33,835 +33,835 @@
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
61using namespace Opie; 61using namespace Opie;
62 62
63class QCopKeyRegister 63class QCopKeyRegister
64{ 64{
65public: 65public:
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
85private: 85private:
86 int keyCode; 86 int keyCode;
87 QString channel, message; 87 QString channel, message;
88}; 88};
89 89
90typedef QValueList<QCopKeyRegister> KeyRegisterList; 90typedef QValueList<QCopKeyRegister> KeyRegisterList;
91KeyRegisterList keyRegisterList; 91KeyRegisterList keyRegisterList;
92 92
93static Desktop* qpedesktop = 0; 93static Desktop* qpedesktop = 0;
94static int loggedin = 0; 94static int loggedin = 0;
95static void login( bool at_poweron ) 95static 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
105bool Desktop::screenLocked() 105bool 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 */
114class DesktopPowerAlerter : public QMessageBox 114class DesktopPowerAlerter : public QMessageBox
115{ 115{
116public: 116public:
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 * );
130private: 130private:
131 int currentPriority; 131 int currentPriority;
132 int alertCount; 132 int alertCount;
133}; 133};
134 134
135void DesktopPowerAlerter::alert( const QString &text, int priority ) 135void 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
148void DesktopPowerAlerter::hideEvent( QHideEvent *e ) 148void 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
155class QPEScreenSaver : public QWSScreenSaver 155class QPEScreenSaver : public QWSScreenSaver
156{ 156{
157private: 157private:
158 int LcdOn; 158 int LcdOn;
159 159
160public: 160public:
161 QPEScreenSaver() 161 QPEScreenSaver()
162 { 162 {
163 m_disable_suspend = 100; 163 m_disable_suspend = 100;
164 m_enable_dim = false; 164 m_enable_dim = false;
165 m_enable_lightoff = false; 165 m_enable_lightoff = false;
166 m_enable_onlylcdoff = false; 166 m_enable_onlylcdoff = false;
167 167
168 m_lcd_status = true; 168 m_lcd_status = true;
169 169
170 m_backlight_bright = -1; 170 m_backlight_bright = -1;
171 m_backlight_forcedoff = false; 171 m_backlight_forcedoff = false;
172 172
173 // Make sure the LCD is in fact on, (if opie was killed while the LCD is off it would still be off) 173 // Make sure the LCD is in fact on, (if opie was killed while the LCD is off it would still be off)
174 ODevice::inst ( ) -> setDisplayStatus ( true ); 174 ODevice::inst ( ) -> setDisplayStatus ( true );
175 } 175 }
176 void restore() 176 void restore()
177 { 177 {
178 if ( !m_lcd_status ) { // We must have turned it off 178 if ( !m_lcd_status ) { // We must have turned it off
179 ODevice::inst ( ) -> setDisplayStatus ( true ); 179 ODevice::inst ( ) -> setDisplayStatus ( true );
180 m_lcd_status = true; 180 m_lcd_status = true;
181 } 181 }
182 182
183 setBacklight ( -1 ); 183 setBacklight ( -1 );
184 } 184 }
185 bool save( int level ) 185 bool save( int level )
186 { 186 {
187 switch ( level ) { 187 switch ( level ) {
188 case 0: 188 case 0:
189 if ( m_disable_suspend > 0 && m_enable_dim ) { 189 if ( m_disable_suspend > 0 && m_enable_dim ) {
190 if ( backlight() > 1 ) 190 if ( backlight() > 1 )
191 setBacklight( 1 ); // lowest non-off 191 setBacklight( 1 ); // lowest non-off
192 } 192 }
193 return true; 193 return true;
194 break; 194 break;
195 case 1: 195 case 1:
196 if ( m_disable_suspend > 1 && m_enable_lightoff ) { 196 if ( m_disable_suspend > 1 && m_enable_lightoff ) {
197 setBacklight( 0 ); // off 197 setBacklight( 0 ); // off
198 } 198 }
199 return true; 199 return true;
200 break; 200 break;
201 case 2: 201 case 2:
202 if ( m_enable_onlylcdoff ) { 202 if ( m_enable_onlylcdoff ) {
203 ODevice::inst ( ) -> setDisplayStatus ( false ); 203 ODevice::inst ( ) -> setDisplayStatus ( false );
204 m_lcd_status = false; 204 m_lcd_status = false;
205 return true; 205 return true;
206 } 206 }
207 else // We're going to suspend the whole machine 207 else // We're going to suspend the whole machine
208 { 208 {
209 if ( ( m_disable_suspend > 2 ) && 209 if ( ( m_disable_suspend > 2 ) &&
210 ( PowerStatusManager::readStatus().acStatus() != PowerStatus::Online ) && 210 ( PowerStatusManager::readStatus().acStatus() != PowerStatus::Online ) &&
211 ( !Network::networkOnline ( ) ) ) { 211 ( !Network::networkOnline ( ) ) ) {
212 QWSServer::sendKeyEvent( 0xffff, Qt::Key_F34, FALSE, TRUE, FALSE ); 212 QWSServer::sendKeyEvent( 0xffff, Qt::Key_F34, FALSE, TRUE, FALSE );
213 return true; 213 return true;
214 } 214 }
215 } 215 }
216 break; 216 break;
217 } 217 }
218 return false; 218 return false;
219 } 219 }
220 220
221private: 221private:
222 static int ssi( int interval, Config & config, const QString & enable, const QString & value, int def ) 222 static int ssi( int interval, Config & config, const QString & enable, const QString & value, int def )
223 { 223 {
224 if ( !enable.isEmpty() && config.readNumEntry( enable, 0 ) == 0 ) 224 if ( !enable.isEmpty() && config.readNumEntry( enable, 0 ) == 0 )
225 return 0; 225 return 0;
226 226
227 if ( interval < 0 ) { 227 if ( interval < 0 ) {
228 // Restore screen blanking and power saving state 228 // Restore screen blanking and power saving state
229 interval = config.readNumEntry( value, def ); 229 interval = config.readNumEntry( value, def );
230 } 230 }
231 return interval; 231 return interval;
232 } 232 }
233 233
234public: 234public:
235 void setIntervals( int i1, int i2, int i3 ) 235 void setIntervals( int i1, int i2, int i3 )
236 { 236 {
237 Config config( "qpe" ); 237 Config config( "qpe" );
238 config.setGroup( "Screensaver" ); 238 config.setGroup( "Screensaver" );
239 239
240 int v[ 4 ]; 240 int v[ 4 ];
241 i1 = ssi( i1, config, "Dim", "Interval_Dim", 30 ); 241 i1 = ssi( i1, config, "Dim", "Interval_Dim", 30 );
242 i2 = ssi( i2, config, "LightOff", "Interval_LightOff", 20 ); 242 i2 = ssi( i2, config, "LightOff", "Interval_LightOff", 20 );
243 i3 = ssi( i3, config, "", "Interval", 60 ); 243 i3 = ssi( i3, config, "", "Interval", 60 );
244 244
245 //qDebug("screen saver intervals: %d %d %d", i1, i2, i3); 245 //qDebug("screen saver intervals: %d %d %d", i1, i2, i3);
246 246
247 v [ 0 ] = QMAX( 1000 * i1, 100 ); 247 v [ 0 ] = QMAX( 1000 * i1, 100 );
248 v [ 1 ] = QMAX( 1000 * i2, 100 ); 248 v [ 1 ] = QMAX( 1000 * i2, 100 );
249 v [ 2 ] = QMAX( 1000 * i3, 100 ); 249 v [ 2 ] = QMAX( 1000 * i3, 100 );
250 v [ 3 ] = 0; 250 v [ 3 ] = 0;
251 m_enable_dim = ( ( i1 != 0 ) ? config. readNumEntry ( "Dim", 1 ) : false ); 251 m_enable_dim = ( ( i1 != 0 ) ? config. readNumEntry ( "Dim", 1 ) : false );
252 m_enable_lightoff = ( ( i2 != 0 ) ? config. readNumEntry ( "LightOff", 1 ) : false ); 252 m_enable_lightoff = ( ( i2 != 0 ) ? config. readNumEntry ( "LightOff", 1 ) : false );
253 m_enable_onlylcdoff = config. readNumEntry ( "LcdOffOnly", 0 ); 253 m_enable_onlylcdoff = config. readNumEntry ( "LcdOffOnly", 0 );
254 254
255 if ( !i1 && !i2 && !i3 ) 255 if ( !i1 && !i2 && !i3 )
256 QWSServer::setScreenSaverInterval( 0 ); 256 QWSServer::setScreenSaverInterval( 0 );
257 else 257 else
258 QWSServer::setScreenSaverIntervals( v ); 258 QWSServer::setScreenSaverIntervals( v );
259 } 259 }
260 260
261 void setInterval ( int interval ) 261 void setInterval ( int interval )
262 { 262 {
263 setIntervals ( -1, -1, interval ); 263 setIntervals ( -1, -1, interval );
264 } 264 }
265 265
266 void setMode ( int mode ) 266 void setMode ( int mode )
267 { 267 {
268 if ( mode > m_disable_suspend ) 268 if ( mode > m_disable_suspend )
269 setInterval( -1 ); 269 setInterval( -1 );
270 m_disable_suspend = mode; 270 m_disable_suspend = mode;
271 } 271 }
272 272
273 int backlight ( ) 273 int backlight ( )
274 { 274 {
275 if ( m_backlight_bright == -1 ) { 275 if ( m_backlight_bright == -1 ) {
276 // Read from config 276 // Read from config
277 Config config ( "qpe" ); 277 Config config ( "qpe" );
278 config. setGroup ( "Screensaver" ); 278 config. setGroup ( "Screensaver" );
279 m_backlight_bright = config. readNumEntry ( "Brightness", 255 ); 279 m_backlight_bright = config. readNumEntry ( "Brightness", 255 );
280 } 280 }
281 return m_backlight_bright; 281 return m_backlight_bright;
282 } 282 }
283 283
284 void setBacklight ( int bright ) 284 void setBacklight ( int bright )
285 { 285 {
286 if ( bright == -3 ) { 286 if ( bright == -3 ) {
287 // Forced on 287 // Forced on
288 m_backlight_forcedoff = false; 288 m_backlight_forcedoff = false;
289 bright = -1; 289 bright = -1;
290 } 290 }
291 if ( m_backlight_forcedoff && bright != -2 ) 291 if ( m_backlight_forcedoff && bright != -2 )
292 return ; 292 return ;
293 if ( bright == -2 ) { 293 if ( bright == -2 ) {
294 // Toggle between off and on 294 // Toggle between off and on
295 bright = m_backlight_bright ? 0 : -1; 295 bright = m_backlight_bright ? 0 : -1;
296 m_backlight_forcedoff = !bright; 296 m_backlight_forcedoff = !bright;
297 } 297 }
298 298
299 m_backlight_bright = bright; 299 m_backlight_bright = bright;
300 300
301 bright = backlight ( ); 301 bright = backlight ( );
302 ODevice::inst ( ) -> setDisplayBrightness ( bright ); 302 ODevice::inst ( ) -> setDisplayBrightness ( bright );
303 303
304 m_backlight_bright = bright; 304 m_backlight_bright = bright;
305 } 305 }
306 306
307 void setDisplayState ( bool on ) 307 void setDisplayState ( bool on )
308 { 308 {
309 if ( m_lcd_status != on ) { 309 if ( m_lcd_status != on ) {
310 ODevice::inst ( ) -> setDisplayStatus ( on ); 310 ODevice::inst ( ) -> setDisplayStatus ( on );
311 m_lcd_status = on; 311 m_lcd_status = on;
312 } 312 }
313 } 313 }
314 314
315private: 315private:
316 int m_disable_suspend; 316 int m_disable_suspend;
317 bool m_enable_dim; 317 bool m_enable_dim;
318 bool m_enable_lightoff; 318 bool m_enable_lightoff;
319 bool m_enable_onlylcdoff; 319 bool m_enable_onlylcdoff;
320 320
321 bool m_lcd_status; 321 bool m_lcd_status;
322 322
323 int m_backlight_bright; 323 int m_backlight_bright;
324 bool m_backlight_forcedoff; 324 bool m_backlight_forcedoff;
325}; 325};
326 326
327void DesktopApplication::switchLCD ( bool on ) 327void DesktopApplication::switchLCD ( bool on )
328{ 328{
329 if ( qApp ) { 329 if ( qApp ) {
330 DesktopApplication *dapp = (DesktopApplication *) qApp; 330 DesktopApplication *dapp = (DesktopApplication *) qApp;
331 331
332 if ( dapp-> m_screensaver ) { 332 if ( dapp-> m_screensaver ) {
333 if ( on ) { 333 if ( on ) {
334 dapp-> m_screensaver-> setDisplayState ( true ); 334 dapp-> m_screensaver-> setDisplayState ( true );
335 dapp-> m_screensaver-> setBacklight ( -3 ); 335 dapp-> m_screensaver-> setBacklight ( -3 );
336 } 336 }
337 else { 337 else {
338 dapp-> m_screensaver-> setDisplayState ( false ); 338 dapp-> m_screensaver-> setDisplayState ( false );
339 } 339 }
340 } 340 }
341 } 341 }
342} 342}
343 343
344 344
345DesktopApplication::DesktopApplication( int& argc, char **argv, Type appType ) 345DesktopApplication::DesktopApplication( int& argc, char **argv, Type appType )
346 : QPEApplication( argc, argv, appType ) 346 : QPEApplication( argc, argv, appType )
347{ 347{
348 348
349 QTimer * t = new QTimer( this ); 349 QTimer * t = new QTimer( this );
350 connect( t, SIGNAL( timeout() ), this, SLOT( psTimeout() ) ); 350 connect( t, SIGNAL( timeout() ), this, SLOT( psTimeout() ) );
351 t->start( 10000 ); 351 t->start( 10000 );
352 ps = new PowerStatus; 352 ps = new PowerStatus;
353 pa = new DesktopPowerAlerter( 0 ); 353 pa = new DesktopPowerAlerter( 0 );
354 354
355 channel = new QCopChannel( "QPE/Desktop", this ); 355 channel = new QCopChannel( "QPE/Desktop", this );
356 connect( channel, SIGNAL( received( const QCString&, const QByteArray& ) ), 356 connect( channel, SIGNAL( received( const QCString&, const QByteArray& ) ),
357 this, SLOT( desktopMessage( const QCString&, const QByteArray& ) ) ); 357 this, SLOT( desktopMessage( const QCString&, const QByteArray& ) ) );
358 358
359 channel = new QCopChannel( "QPE/System", this ); 359 channel = new QCopChannel( "QPE/System", this );
360 connect( channel, SIGNAL( received( const QCString&, const QByteArray& ) ), 360 connect( channel, SIGNAL( received( const QCString&, const QByteArray& ) ),
361 this, SLOT( systemMessage( const QCString&, const QByteArray& ) ) ); 361 this, SLOT( systemMessage( const QCString&, const QByteArray& ) ) );
362 362
363 m_screensaver = new QPEScreenSaver; 363 m_screensaver = new QPEScreenSaver;
364 364
365 m_screensaver-> setInterval ( -1 ); 365 m_screensaver-> setInterval ( -1 );
366 QWSServer::setScreenSaver( m_screensaver ); 366 QWSServer::setScreenSaver( m_screensaver );
367} 367}
368 368
369 369
370DesktopApplication::~DesktopApplication() 370DesktopApplication::~DesktopApplication()
371{ 371{
372 delete ps; 372 delete ps;
373 delete pa; 373 delete pa;
374} 374}
375 375
376void DesktopApplication::desktopMessage( const QCString &msg, const QByteArray &data ) 376void DesktopApplication::desktopMessage( const QCString &msg, const QByteArray &data )
377{ 377{
378 QDataStream stream( data, IO_ReadOnly ); 378 QDataStream stream( data, IO_ReadOnly );
379 if ( msg == "keyRegister(int key, QString channel, QString message)" ) { 379 if ( msg == "keyRegister(int key, QString channel, QString message)" ) {
380 int k; 380 int k;
381 QString c, m; 381 QString c, m;
382 stream >> k; 382 stream >> k;
383 stream >> c; 383 stream >> c;
384 stream >> m; 384 stream >> m;
385 385
386 qWarning( "KeyRegisterReceived: %i, %s, %s", k, ( const char* ) c, ( const char * ) m ); 386 qWarning( "KeyRegisterReceived: %i, %s, %s", k, ( const char* ) c, ( const char * ) m );
387 keyRegisterList.append( QCopKeyRegister( k, c, m ) ); 387 keyRegisterList.append( QCopKeyRegister( k, c, m ) );
388 } 388 }
389} 389}
390 390
391 391
392void DesktopApplication::systemMessage( const QCString & msg, const QByteArray & data ) 392void DesktopApplication::systemMessage( const QCString & msg, const QByteArray & data )
393{ 393{
394 QDataStream stream ( data, IO_ReadOnly ); 394 QDataStream stream ( data, IO_ReadOnly );
395 395
396 if ( msg == "setScreenSaverInterval(int)" ) { 396 if ( msg == "setScreenSaverInterval(int)" ) {
397 int time; 397 int time;
398 stream >> time; 398 stream >> time;
399 m_screensaver-> setInterval( time ); 399 m_screensaver-> setInterval( time );
400 } 400 }
401 else if ( msg == "setScreenSaverIntervals(int,int,int)" ) { 401 else if ( msg == "setScreenSaverIntervals(int,int,int)" ) {
402 int t1, t2, t3; 402 int t1, t2, t3;
403 stream >> t1 >> t2 >> t3; 403 stream >> t1 >> t2 >> t3;
404 m_screensaver-> setIntervals( t1, t2, t3 ); 404 m_screensaver-> setIntervals( t1, t2, t3 );
405 } 405 }
406 else if ( msg == "setBacklight(int)" ) { 406 else if ( msg == "setBacklight(int)" ) {
407 int bright; 407 int bright;
408 stream >> bright; 408 stream >> bright;
409 m_screensaver-> setBacklight( bright ); 409 m_screensaver-> setBacklight( bright );
410 } 410 }
411 else if ( msg == "setScreenSaverMode(int)" ) { 411 else if ( msg == "setScreenSaverMode(int)" ) {
412 int mode; 412 int mode;
413 stream >> mode; 413 stream >> mode;
414 m_screensaver-> setMode ( mode ); 414 m_screensaver-> setMode ( mode );
415 } 415 }
416 else if ( msg == "setDisplayState(int)" ) { 416 else if ( msg == "setDisplayState(int)" ) {
417 int state; 417 int state;
418 stream >> state; 418 stream >> state;
419 m_screensaver-> setDisplayState ( state != 0 ); 419 m_screensaver-> setDisplayState ( state != 0 );
420 } 420 }
421 else if ( msg == "suspend()" ) { 421 else if ( msg == "suspend()" ) {
422 emit power(); 422 emit power();
423 } 423 }
424} 424}
425 425
426enum MemState { Unknown, VeryLow, Low, Normal } memstate = Unknown; 426enum MemState { Unknown, VeryLow, Low, Normal } memstate = Unknown;
427 427
428#ifdef Q_WS_QWS 428#ifdef Q_WS_QWS
429bool DesktopApplication::qwsEventFilter( QWSEvent *e ) 429bool DesktopApplication::qwsEventFilter( QWSEvent *e )
430{ 430{
431 qpedesktop->checkMemory(); 431 qpedesktop->checkMemory();
432 432
433 if ( e->type == QWSEvent::Key ) { 433 if ( e->type == QWSEvent::Key ) {
434 QWSKeyEvent * ke = ( QWSKeyEvent * ) e; 434 QWSKeyEvent * ke = ( QWSKeyEvent * ) e;
435 if ( !loggedin && ke->simpleData.keycode != Key_F34 ) 435 if ( !loggedin && ke->simpleData.keycode != Key_F34 )
436 return TRUE; 436 return TRUE;
437 bool press = ke->simpleData.is_press; 437 bool press = ke->simpleData.is_press;
438 bool autoRepeat = ke->simpleData.is_auto_repeat; 438 bool autoRepeat = ke->simpleData.is_auto_repeat;
439 439
440 /* 440 /*
441 app that registers key/message to be sent back to the app, when it doesn't have focus, 441 app that registers key/message to be sent back to the app, when it doesn't have focus,
442 when user presses key, unless keyboard has been requested from app. 442 when user presses key, unless keyboard has been requested from app.
443 will not send multiple repeats if user holds key 443 will not send multiple repeats if user holds key
444 i.e. one shot 444 i.e. one shot
445 */ 445 */
446 if ( !keyRegisterList.isEmpty() && ke->simpleData.keycode !=0 && press) { 446 if ( !keyRegisterList.isEmpty() && ke->simpleData.keycode !=0 && press) {
447// qDebug("<<<<<<<<<<<<<keycode %d", ke->simpleData.keycode); 447// qDebug("<<<<<<<<<<<<<keycode %d", ke->simpleData.keycode);
448 KeyRegisterList::Iterator it; 448 KeyRegisterList::Iterator it;
449 for ( it = keyRegisterList.begin(); it != keyRegisterList.end(); ++it ) { 449 for ( it = keyRegisterList.begin(); it != keyRegisterList.end(); ++it ) {
450 if ( ( *it ).getKeyCode() == ke->simpleData.keycode && !autoRepeat && !keyboardGrabbed() ) { 450 if ( ( *it ).getKeyCode() == ke->simpleData.keycode && !autoRepeat && !keyboardGrabbed() ) {
451 if ( press ) 451 if ( press )
452 qDebug( "press" ); 452 qDebug( "press" );
453 else 453 else
454 qDebug( "release" ); 454 qDebug( "release" );
455 QCopEnvelope( ( *it ).getChannel().utf8(), ( *it ).getMessage().utf8() ); 455 QCopEnvelope( ( *it ).getChannel().utf8(), ( *it ).getMessage().utf8() );
456 } 456 }
457 } 457 }
458 } 458 }
459 459
460 if ( !keyboardGrabbed() ) { 460 if ( !keyboardGrabbed() ) {
461 if ( ke->simpleData.keycode == Key_F9 ) { 461 if ( ke->simpleData.keycode == Key_F9 ) {
462 if ( press ) 462 if ( press )
463 emit datebook(); 463 emit datebook();
464 return TRUE; 464 return TRUE;
465 } 465 }
466 if ( ke->simpleData.keycode == Key_F10 ) { 466 if ( ke->simpleData.keycode == Key_F10 ) {
467 if ( !press && cardSendTimer ) { 467 if ( !press && cardSendTimer ) {
468 emit contacts(); 468 emit contacts();
469 delete cardSendTimer; 469 delete cardSendTimer;
470 } 470 }
471 else if ( press ) { 471 else if ( press ) {
472 cardSendTimer = new QTimer(); 472 cardSendTimer = new QTimer();
473 cardSendTimer->start( 2000, TRUE ); 473 cardSendTimer->start( 2000, TRUE );
474 connect( cardSendTimer, SIGNAL( timeout() ), this, SLOT( sendCard() ) ); 474 connect( cardSendTimer, SIGNAL( timeout() ), this, SLOT( sendCard() ) );
475 } 475 }
476 return TRUE; 476 return TRUE;
477 } 477 }
478 /* menu key now opens application menu/toolbar 478// menu key now opens application menu/toolbar
479 if ( ke->simpleData.keycode == Key_F11 ) { 479 if ( ke->simpleData.keycode == Key_F11 ) {
480 if ( press ) emit menu(); 480 if ( press ) emit menu();
481 return TRUE; 481 return TRUE;
482 } 482 }
483 */ 483
484 if ( ke->simpleData.keycode == Key_F12 ) { 484 if ( ke->simpleData.keycode == Key_F12 ) {
485 while ( activePopupWidget() ) 485 while ( activePopupWidget() )
486 activePopupWidget() ->close(); 486 activePopupWidget() ->close();
487 if ( press ) 487 if ( press )
488 emit launch(); 488 emit launch();
489 return TRUE; 489 return TRUE;
490 } 490 }
491 if ( ke->simpleData.keycode == Key_F13 ) { 491 if ( ke->simpleData.keycode == Key_F13 ) {
492 if ( press ) 492 if ( press )
493 emit email(); 493 emit email();
494 return TRUE; 494 return TRUE;
495 } 495 }
496 } 496 }
497 497
498 if ( ke->simpleData.keycode == Key_F34 ) { 498 if ( ke->simpleData.keycode == Key_F34 ) {
499 if ( press ) 499 if ( press )
500 emit power(); 500 emit power();
501 return TRUE; 501 return TRUE;
502 } 502 }
503 // This was used for the iPAQ PowerButton 503 // This was used for the iPAQ PowerButton
504 // See main.cpp for new KeyboardFilter 504 // See main.cpp for new KeyboardFilter
505 // 505 //
506 // if ( ke->simpleData.keycode == Key_SysReq ) { 506 // if ( ke->simpleData.keycode == Key_SysReq ) {
507 // if ( press ) emit power(); 507 // if ( press ) emit power();
508 // return TRUE; 508 // return TRUE;
509 // } 509 // }
510 if ( ke->simpleData.keycode == Key_F35 ) { 510 if ( ke->simpleData.keycode == Key_F35 ) {
511 if ( press ) 511 if ( press )
512 emit backlight(); 512 emit backlight();
513 return TRUE; 513 return TRUE;
514 } 514 }
515 if ( ke->simpleData.keycode == Key_F32 ) { 515 if ( ke->simpleData.keycode == Key_F32 ) {
516 if ( press ) 516 if ( press )
517 QCopEnvelope e( "QPE/Desktop", "startSync()" ); 517 QCopEnvelope e( "QPE/Desktop", "startSync()" );
518 return TRUE; 518 return TRUE;
519 } 519 }
520 if ( ke->simpleData.keycode == Key_F31 && !ke->simpleData.modifiers ) { 520 if ( ke->simpleData.keycode == Key_F31 && !ke->simpleData.modifiers ) {
521 if ( press ) 521 if ( press )
522 emit symbol(); 522 emit symbol();
523 return TRUE; 523 return TRUE;
524 } 524 }
525 if ( ke->simpleData.keycode == Key_NumLock ) { 525 if ( ke->simpleData.keycode == Key_NumLock ) {
526 if ( press ) 526 if ( press )
527 emit numLockStateToggle(); 527 emit numLockStateToggle();
528 } 528 }
529 if ( ke->simpleData.keycode == Key_CapsLock ) { 529 if ( ke->simpleData.keycode == Key_CapsLock ) {
530 if ( press ) 530 if ( press )
531 emit capsLockStateToggle(); 531 emit capsLockStateToggle();
532 } 532 }
533 if ( ( press && !autoRepeat ) || ( !press && autoRepeat ) ) 533 if ( ( press && !autoRepeat ) || ( !press && autoRepeat ) )
534 qpedesktop->keyClick(); 534 qpedesktop->keyClick();
535 } 535 }
536 else { 536 else {
537 if ( e->type == QWSEvent::Mouse ) { 537 if ( e->type == QWSEvent::Mouse ) {
538 QWSMouseEvent * me = ( QWSMouseEvent * ) e; 538 QWSMouseEvent * me = ( QWSMouseEvent * ) e;
539 static bool up = TRUE; 539 static bool up = TRUE;
540 if ( me->simpleData.state & LeftButton ) { 540 if ( me->simpleData.state & LeftButton ) {
541 if ( up ) { 541 if ( up ) {
542 up = FALSE; 542 up = FALSE;
543 qpedesktop->screenClick(); 543 qpedesktop->screenClick();
544 } 544 }
545 } 545 }
546 else { 546 else {
547 up = TRUE; 547 up = TRUE;
548 } 548 }
549 } 549 }
550 } 550 }
551 551
552 return QPEApplication::qwsEventFilter( e ); 552 return QPEApplication::qwsEventFilter( e );
553} 553}
554#endif 554#endif
555 555
556void DesktopApplication::psTimeout() 556void DesktopApplication::psTimeout()
557{ 557{
558 qpedesktop->checkMemory(); // in case no events are being generated 558 qpedesktop->checkMemory(); // in case no events are being generated
559 559
560 *ps = PowerStatusManager::readStatus(); 560 *ps = PowerStatusManager::readStatus();
561 561
562 if ( ( ps->batteryStatus() == PowerStatus::VeryLow ) ) { 562 if ( ( ps->batteryStatus() == PowerStatus::VeryLow ) ) {
563 pa->alert( tr( "Battery is running very low." ), 6 ); 563 pa->alert( tr( "Battery is running very low." ), 6 );
564 } 564 }
565 565
566 if ( ps->batteryStatus() == PowerStatus::Critical ) { 566 if ( ps->batteryStatus() == PowerStatus::Critical ) {
567 pa->alert( tr( "Battery level is critical!\n" 567 pa->alert( tr( "Battery level is critical!\n"
568 "Keep power off until power restored!" ), 1 ); 568 "Keep power off until power restored!" ), 1 );
569 } 569 }
570 570
571 if ( ps->backupBatteryStatus() == PowerStatus::VeryLow ) { 571 if ( ps->backupBatteryStatus() == PowerStatus::VeryLow ) {
572 pa->alert( tr( "The Back-up battery is very low.\nPlease charge the back-up battery." ), 3 ); 572 pa->alert( tr( "The Back-up battery is very low.\nPlease charge the back-up battery." ), 3 );
573 } 573 }
574} 574}
575 575
576 576
577void DesktopApplication::sendCard() 577void DesktopApplication::sendCard()
578{ 578{
579 delete cardSendTimer; 579 delete cardSendTimer;
580 cardSendTimer = 0; 580 cardSendTimer = 0;
581 QString card = getenv( "HOME" ); 581 QString card = getenv( "HOME" );
582 card += "/Applications/addressbook/businesscard.vcf"; 582 card += "/Applications/addressbook/businesscard.vcf";
583 583
584 if ( QFile::exists( card ) ) { 584 if ( QFile::exists( card ) ) {
585 QCopEnvelope e( "QPE/Obex", "send(QString,QString,QString)" ); 585 QCopEnvelope e( "QPE/Obex", "send(QString,QString,QString)" );
586 QString mimetype = "text/x-vCard"; 586 QString mimetype = "text/x-vCard";
587 e << tr( "business card" ) << card << mimetype; 587 e << tr( "business card" ) << card << mimetype;
588 } 588 }
589} 589}
590 590
591#if defined(QPE_HAVE_MEMALERTER) 591#if defined(QPE_HAVE_MEMALERTER)
592QPE_MEMALERTER_IMPL 592QPE_MEMALERTER_IMPL
593#endif 593#endif
594 594
595//=========================================================================== 595//===========================================================================
596 596
597Desktop::Desktop() : 597Desktop::Desktop() :
598 QWidget( 0, 0, WStyle_Tool | WStyle_Customize ), 598 QWidget( 0, 0, WStyle_Tool | WStyle_Customize ),
599 qcopBridge( 0 ), 599 qcopBridge( 0 ),
600 transferServer( 0 ), 600 transferServer( 0 ),
601 packageSlave( 0 ) 601 packageSlave( 0 )
602{ 602{
603 qpedesktop = this; 603 qpedesktop = this;
604 604
605 // bg = new Info( this ); 605 // bg = new Info( this );
606 tb = new TaskBar; 606 tb = new TaskBar;
607 607
608 launcher = new Launcher( 0, 0, WStyle_Customize | QWidget::WGroupLeader ); 608 launcher = new Launcher( 0, 0, WStyle_Customize | QWidget::WGroupLeader );
609 609
610 connect( launcher, SIGNAL( busy() ), tb, SLOT( startWait() ) ); 610 connect( launcher, SIGNAL( busy() ), tb, SLOT( startWait() ) );
611 connect( launcher, SIGNAL( notBusy( const QString& ) ), tb, SLOT( stopWait( const QString& ) ) ); 611 connect( launcher, SIGNAL( notBusy( const QString& ) ), tb, SLOT( stopWait( const QString& ) ) );
612 612
613 int displayw = qApp->desktop() ->width(); 613 int displayw = qApp->desktop() ->width();
614 int displayh = qApp->desktop() ->height(); 614 int displayh = qApp->desktop() ->height();
615 615
616 616
617 QSize sz = tb->sizeHint(); 617 QSize sz = tb->sizeHint();
618 618
619 setGeometry( 0, displayh - sz.height(), displayw, sz.height() ); 619 setGeometry( 0, displayh - sz.height(), displayw, sz.height() );
620 tb->setGeometry( 0, displayh - sz.height(), displayw, sz.height() ); 620 tb->setGeometry( 0, displayh - sz.height(), displayw, sz.height() );
621 621
622 tb->show(); 622 tb->show();
623 launcher->showMaximized(); 623 launcher->showMaximized();
624 launcher->show(); 624 launcher->show();
625 launcher->raise(); 625 launcher->raise();
626#if defined(QPE_HAVE_MEMALERTER) 626#if defined(QPE_HAVE_MEMALERTER)
627 627
628 initMemalerter(); 628 initMemalerter();
629#endif 629#endif
630 // start services 630 // start services
631 startTransferServer(); 631 startTransferServer();
632 ( void ) new IrServer( this ); 632 ( void ) new IrServer( this );
633 rereadVolumes(); 633 rereadVolumes();
634 634
635 packageSlave = new PackageSlave( this ); 635 packageSlave = new PackageSlave( this );
636 connect( qApp, SIGNAL( volumeChanged( bool ) ), this, SLOT( rereadVolumes() ) ); 636 connect( qApp, SIGNAL( volumeChanged( bool ) ), this, SLOT( rereadVolumes() ) );
637 637
638 qApp->installEventFilter( this ); 638 qApp->installEventFilter( this );
639 639
640 qApp-> setMainWidget ( launcher ); 640 qApp-> setMainWidget ( launcher );
641} 641}
642 642
643void Desktop::show() 643void Desktop::show()
644{ 644{
645 login( TRUE ); 645 login( TRUE );
646 QWidget::show(); 646 QWidget::show();
647} 647}
648 648
649Desktop::~Desktop() 649Desktop::~Desktop()
650{ 650{
651 delete launcher; 651 delete launcher;
652 delete tb; 652 delete tb;
653 delete qcopBridge; 653 delete qcopBridge;
654 delete transferServer; 654 delete transferServer;
655} 655}
656 656
657bool Desktop::recoverMemory() 657bool Desktop::recoverMemory()
658{ 658{
659 return tb->recoverMemory(); 659 return tb->recoverMemory();
660} 660}
661 661
662void Desktop::checkMemory() 662void Desktop::checkMemory()
663{ 663{
664#if defined(QPE_HAVE_MEMALERTER) 664#if defined(QPE_HAVE_MEMALERTER)
665 static bool ignoreNormal = FALSE; 665 static bool ignoreNormal = FALSE;
666 static bool existingMessage = FALSE; 666 static bool existingMessage = FALSE;
667 667
668 if ( existingMessage ) 668 if ( existingMessage )
669 return ; // don't show a second message while still on first 669 return ; // don't show a second message while still on first
670 670
671 existingMessage = TRUE; 671 existingMessage = TRUE;
672 switch ( memstate ) { 672 switch ( memstate ) {
673 case Unknown: 673 case Unknown:
674 break; 674 break;
675 case Low: 675 case Low:
676 memstate = Unknown; 676 memstate = Unknown;
677 if ( recoverMemory() ) 677 if ( recoverMemory() )
678 ignoreNormal = TRUE; 678 ignoreNormal = TRUE;
679 else 679 else
680 QMessageBox::warning( 0 , "Memory Status", 680 QMessageBox::warning( 0 , "Memory Status",
681 "The memory smacks of shortage. \n" 681 "The memory smacks of shortage. \n"
682 "Please save data. " ); 682 "Please save data. " );
683 break; 683 break;
684 case Normal: 684 case Normal:
685 memstate = Unknown; 685 memstate = Unknown;
686 if ( ignoreNormal ) 686 if ( ignoreNormal )
687 ignoreNormal = FALSE; 687 ignoreNormal = FALSE;
688// else 688// else
689// QMessageBox::information ( 0 , "Memory Status", 689// QMessageBox::information ( 0 , "Memory Status",
690// "There is enough memory again." ); 690// "There is enough memory again." );
691 break; 691 break;
692 case VeryLow: 692 case VeryLow:
693 memstate = Unknown; 693 memstate = Unknown;
694 QMessageBox::critical( 0 , "Memory Status", 694 QMessageBox::critical( 0 , "Memory Status",
695 "The memory is very low. \n" 695 "The memory is very low. \n"
696 "Please end this application \n" 696 "Please end this application \n"
697 "immediately." ); 697 "immediately." );
698 recoverMemory(); 698 recoverMemory();
699 } 699 }
700 existingMessage = FALSE; 700 existingMessage = FALSE;
701#endif 701#endif
702} 702}
703 703
704static bool isVisibleWindow( int wid ) 704static bool isVisibleWindow( int wid )
705{ 705{
706#ifdef QWS 706#ifdef QWS
707 const QList<QWSWindow> &list = qwsServer->clientWindows(); 707 const QList<QWSWindow> &list = qwsServer->clientWindows();
708 QWSWindow* w; 708 QWSWindow* w;
709 for ( QListIterator<QWSWindow> it( list ); ( w = it.current() ); ++it ) { 709 for ( QListIterator<QWSWindow> it( list ); ( w = it.current() ); ++it ) {
710 if ( w->winId() == wid ) 710 if ( w->winId() == wid )
711 return !w->isFullyObscured(); 711 return !w->isFullyObscured();
712 } 712 }
713#endif 713#endif
714 return FALSE; 714 return FALSE;
715} 715}
716 716
717static bool hasVisibleWindow( const QString& clientname ) 717static bool hasVisibleWindow( const QString& clientname )
718{ 718{
719#ifdef QWS 719#ifdef QWS
720 const QList<QWSWindow> &list = qwsServer->clientWindows(); 720 const QList<QWSWindow> &list = qwsServer->clientWindows();
721 QWSWindow* w; 721 QWSWindow* w;
722 for ( QListIterator<QWSWindow> it( list ); ( w = it.current() ); ++it ) { 722 for ( QListIterator<QWSWindow> it( list ); ( w = it.current() ); ++it ) {
723 if ( w->client() ->identity() == clientname && !w->isFullyObscured() ) 723 if ( w->client() ->identity() == clientname && !w->isFullyObscured() )
724 return TRUE; 724 return TRUE;
725 } 725 }
726#endif 726#endif
727 return FALSE; 727 return FALSE;
728} 728}
729 729
730void Desktop::raiseLauncher() 730void Desktop::raiseLauncher()
731{ 731{
732 Config cfg( "qpe" ); //F12 'Home' 732 Config cfg( "qpe" ); //F12 'Home'
733 cfg.setGroup( "AppsKey" ); 733 cfg.setGroup( "AppsKey" );
734 QString tempItem; 734 QString tempItem;
735 tempItem = cfg.readEntry( "Middle", "Home" ); 735 tempItem = cfg.readEntry( "Middle", "Home" );
736 if ( tempItem == "Home" || tempItem.isEmpty() ) { 736 if ( tempItem == "Home" || tempItem.isEmpty() ) {
737 home ( ); 737 home ( );
738 } 738 }
739 else { 739 else {
740 QCopEnvelope e( "QPE/System", "execute(QString)" ); 740 QCopEnvelope e( "QPE/System", "execute(QString)" );
741 e << tempItem; 741 e << tempItem;
742 } 742 }
743} 743}
744 744
745void Desktop::home ( ) 745void Desktop::home ( )
746{ 746{
747 if ( isVisibleWindow( launcher->winId() ) ) 747 if ( isVisibleWindow( launcher->winId() ) )
748 launcher->nextView(); 748 launcher->nextView();
749 else 749 else
750 launcher->raise(); 750 launcher->raise();
751} 751}
752 752
753void Desktop::executeOrModify( const QString& appLnkFile ) 753void Desktop::executeOrModify( const QString& appLnkFile )
754{ 754{
755 AppLnk lnk( MimeType::appsFolderName() + "/" + appLnkFile ); 755 AppLnk lnk( MimeType::appsFolderName() + "/" + appLnkFile );
756 if ( lnk.isValid() ) { 756 if ( lnk.isValid() ) {
757 QCString app = lnk.exec().utf8(); 757 QCString app = lnk.exec().utf8();
758 Global::terminateBuiltin( "calibrate" ); 758 Global::terminateBuiltin( "calibrate" );
759 if ( QCopChannel::isRegistered( "QPE/Application/" + app ) ) { 759 if ( QCopChannel::isRegistered( "QPE/Application/" + app ) ) {
760 // MRUList::addTask( &lnk ); 760 // MRUList::addTask( &lnk );
761 if ( hasVisibleWindow( app ) ) 761 if ( hasVisibleWindow( app ) )
762 QCopChannel::send( "QPE/Application/" + app, "nextView()" ); 762 QCopChannel::send( "QPE/Application/" + app, "nextView()" );
763 else 763 else
764 QCopChannel::send( "QPE/Application/" + app, "raise()" ); 764 QCopChannel::send( "QPE/Application/" + app, "raise()" );
765 } 765 }
766 else { 766 else {
767 lnk.execute(); 767 lnk.execute();
768 } 768 }
769 } 769 }
770} 770}
771 771
772void Desktop::raiseDatebook() 772void Desktop::raiseDatebook()
773{ 773{
774 Config cfg( "qpe" ); //F9 'Activity' 774 Config cfg( "qpe" ); //F9 'Activity'
775 cfg.setGroup( "AppsKey" ); 775 cfg.setGroup( "AppsKey" );
776 QString tempItem; 776 QString tempItem;
777 tempItem = cfg.readEntry( "LeftEnd" , "Calendar" ); 777 tempItem = cfg.readEntry( "LeftEnd" , "Calendar" );
778 if ( tempItem == "Calendar" || tempItem.isEmpty() ) { 778 if ( tempItem == "Calendar" || tempItem.isEmpty() ) {
779 tempItem = "datebook"; 779 tempItem = "datebook";
780 } 780 }
781 QCopEnvelope e( "QPE/System", "execute(QString)" ); 781 QCopEnvelope e( "QPE/System", "execute(QString)" );
782 e << tempItem; 782 e << tempItem;
783} 783}
784 784
785void Desktop::raiseContacts() 785void Desktop::raiseContacts()
786{ 786{
787 Config cfg( "qpe" ); //F10, 'Contacts' 787 Config cfg( "qpe" ); //F10, 'Contacts'
788 cfg.setGroup( "AppsKey" ); 788 cfg.setGroup( "AppsKey" );
789 QString tempItem; 789 QString tempItem;
790 tempItem = cfg.readEntry( "Left2nd", "Address Book" ); 790 tempItem = cfg.readEntry( "Left2nd", "Address Book" );
791 if ( tempItem == "Address Book" || tempItem.isEmpty() ) { 791 if ( tempItem == "Address Book" || tempItem.isEmpty() ) {
792 tempItem = "addressbook"; 792 tempItem = "addressbook";
793 } 793 }
794 QCopEnvelope e( "QPE/System", "execute(QString)" ); 794 QCopEnvelope e( "QPE/System", "execute(QString)" );
795 e << tempItem; 795 e << tempItem;
796} 796}
797 797
798void Desktop::raiseMenu() 798void Desktop::raiseMenu()
799{ 799{
800 Config cfg( "qpe" ); //F11, 'Menu 800 Config cfg( "qpe" ); //F11, 'Menu
801 cfg.setGroup( "AppsKey" ); 801 cfg.setGroup( "AppsKey" );
802 QString tempItem; 802 QString tempItem;
803 tempItem = cfg.readEntry( "Right2nd" , "Popup Menu" ); 803 tempItem = cfg.readEntry( "Right2nd" , "Popup Menu" );
804 if ( tempItem == "Popup Menu" || tempItem.isEmpty() ) { 804 if ( tempItem == "Popup Menu" || tempItem.isEmpty() ) {
805 Global::terminateBuiltin( "calibrate" ); 805 Global::terminateBuiltin( "calibrate" );
806 tb->startMenu() ->launch(); 806 tb->startMenu() ->launch();
807 } 807 }
808 else { 808 else {
809 QCopEnvelope e( "QPE/System", "execute(QString)" ); 809 QCopEnvelope e( "QPE/System", "execute(QString)" );
810 e << tempItem; 810 e << tempItem;
811 } 811 }
812} 812}
813 813
814void Desktop::raiseEmail() 814void Desktop::raiseEmail()
815{ 815{
816 Config cfg( "qpe" ); //F13, 'Mail' // only in zaurus, on ipaq mail key is F11 816 Config cfg( "qpe" ); //F13, 'Mail' // only in zaurus, on ipaq mail key is F11
817 cfg.setGroup( "AppsKey" ); 817 cfg.setGroup( "AppsKey" );
818 QString tempItem; 818 QString tempItem;
819 tempItem = cfg.readEntry( "RightEnd", "Mail" ); 819 tempItem = cfg.readEntry( "RightEnd", "Mail" );
820 if ( tempItem == "Mail" || tempItem == "qtmail" || tempItem.isEmpty() ) { 820 if ( tempItem == "Mail" || tempItem == "qtmail" || tempItem.isEmpty() ) {
821 tempItem = "mail"; 821 tempItem = "mail";
822 } 822 }
823 QCopEnvelope e( "QPE/System", "execute(QString)" ); 823 QCopEnvelope e( "QPE/System", "execute(QString)" );
824 e << tempItem; 824 e << tempItem;
825} 825}
826 826
827// autoStarts apps on resume and start 827// autoStarts apps on resume and start
828void Desktop::execAutoStart() 828void Desktop::execAutoStart()
829{ 829{
830 QString appName; 830 QString appName;
831 int delay; 831 int delay;
832 QDateTime now = QDateTime::currentDateTime(); 832 QDateTime now = QDateTime::currentDateTime();
833 Config cfg( "autostart" ); 833 Config cfg( "autostart" );
834 cfg.setGroup( "AutoStart" ); 834 cfg.setGroup( "AutoStart" );
835 appName = cfg.readEntry( "Apps", "" ); 835 appName = cfg.readEntry( "Apps", "" );
836 delay = ( cfg.readEntry( "Delay", "0" ) ).toInt(); 836 delay = ( cfg.readEntry( "Delay", "0" ) ).toInt();
837 // If the time between suspend and resume was longer then the 837 // If the time between suspend and resume was longer then the
838 // value saved as delay, start the app 838 // value saved as delay, start the app
839 if ( suspendTime.secsTo( now ) >= ( delay * 60 ) && !appName.isEmpty() ) { 839 if ( suspendTime.secsTo( now ) >= ( delay * 60 ) && !appName.isEmpty() ) {
840 QCopEnvelope e( "QPE/System", "execute(QString)" ); 840 QCopEnvelope e( "QPE/System", "execute(QString)" );
841 e << QString( appName ); 841 e << QString( appName );
842 } 842 }
843} 843}
844 844
845#if defined(QPE_HAVE_TOGGLELIGHT) 845#if defined(QPE_HAVE_TOGGLELIGHT)
846#include <qpe/config.h> 846#include <qpe/config.h>
847 847
848#include <sys/ioctl.h> 848#include <sys/ioctl.h>
849#include <sys/types.h> 849#include <sys/types.h>
850#include <fcntl.h> 850#include <fcntl.h>
851#include <unistd.h> 851#include <unistd.h>
852#include <errno.h> 852#include <errno.h>
853#include <linux/ioctl.h> 853#include <linux/ioctl.h>
854#include <time.h> 854#include <time.h>
855#endif 855#endif
856 856
857 857
858void Desktop::togglePower() 858void Desktop::togglePower()
859{ 859{
860 static bool excllock = false; 860 static bool excllock = false;
861 861
862 qDebug ( "togglePower (locked == %d)", excllock ? 1 : 0 ); 862 qDebug ( "togglePower (locked == %d)", excllock ? 1 : 0 );
863 863
864 if ( excllock ) 864 if ( excllock )
865 return; 865 return;
866 866
867 excllock = true; 867 excllock = true;
diff --git a/core/launcher/desktop.h b/core/launcher/desktop.h
index 09ffe1c..5de85f4 100644
--- a/core/launcher/desktop.h
+++ b/core/launcher/desktop.h
@@ -1,146 +1,147 @@
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#ifndef __DESKTOP_H__ 21#ifndef __DESKTOP_H__
22#define __DESKTOP_H__ 22#define __DESKTOP_H__
23 23
24 24
25#include "shutdownimpl.h" 25#include "shutdownimpl.h"
26 26
27#include <qpe/qpeapplication.h> 27#include <qpe/qpeapplication.h>
28 28
29#include <qwidget.h> 29#include <qwidget.h>
30#include <qdatetime.h> 30#include <qdatetime.h>
31 31
32class Background; 32class Background;
33class Launcher; 33class Launcher;
34class TaskBar; 34class TaskBar;
35class PowerStatus; 35class PowerStatus;
36class QCopBridge; 36class QCopBridge;
37class TransferServer; 37class TransferServer;
38class DesktopPowerAlerter; 38class DesktopPowerAlerter;
39class PackageSlave; 39class PackageSlave;
40class QPEScreenSaver; 40class QPEScreenSaver;
41 41
42class DesktopApplication : public QPEApplication 42class DesktopApplication : public QPEApplication
43{ 43{
44 Q_OBJECT 44 Q_OBJECT
45public: 45public:
46 DesktopApplication( int& argc, char **argv, Type t ); 46 DesktopApplication( int& argc, char **argv, Type t );
47 ~DesktopApplication(); 47 ~DesktopApplication();
48 48
49 static void switchLCD ( bool on ); // only for togglePower in Desktop 49 static void switchLCD ( bool on ); // only for togglePower in Desktop
50 50
51signals: 51signals:
52 void home(); 52 void menu();
53 void datebook(); 53 void home();
54 void contacts(); 54 void datebook();
55 void launch(); 55 void contacts();
56 void email(); 56 void launch();
57 void backlight(); 57 void email();
58 void power(); 58 void backlight();
59 void symbol(); 59 void power();
60 void numLockStateToggle(); 60 void symbol();
61 void capsLockStateToggle(); 61 void numLockStateToggle();
62 void prepareForRestart(); 62 void capsLockStateToggle();
63 void prepareForRestart();
63 64
64protected: 65protected:
65#ifdef Q_WS_QWS 66#ifdef Q_WS_QWS
66 67
67 bool qwsEventFilter( QWSEvent * ); 68 bool qwsEventFilter( QWSEvent * );
68#endif 69#endif
69 70
70 void shutdown(); 71 void shutdown();
71 void restart(); 72 void restart();
72 73
73public slots: 74public slots:
74 virtual void desktopMessage ( const QCString &msg, const QByteArray &data ); 75 virtual void desktopMessage ( const QCString &msg, const QByteArray &data );
75 virtual void systemMessage ( const QCString &msg, const QByteArray &data ); 76 virtual void systemMessage ( const QCString &msg, const QByteArray &data );
76 77
77protected slots: 78protected slots:
78 void shutdown( ShutdownImpl::Type ); 79 void shutdown( ShutdownImpl::Type );
79 void psTimeout(); 80 void psTimeout();
80 void sendCard(); 81 void sendCard();
81private: 82private:
82 DesktopPowerAlerter *pa; 83 DesktopPowerAlerter *pa;
83 PowerStatus *ps; 84 PowerStatus *ps;
84 QTimer *cardSendTimer; 85 QTimer *cardSendTimer;
85 QCopChannel *channel; 86 QCopChannel *channel;
86 QPEScreenSaver *m_screensaver; 87 QPEScreenSaver *m_screensaver;
87}; 88};
88 89
89 90
90class Desktop : public QWidget 91class Desktop : public QWidget
91{ 92{
92 Q_OBJECT 93 Q_OBJECT
93public: 94public:
94 Desktop(); 95 Desktop();
95 ~Desktop(); 96 ~Desktop();
96 97
97 static bool screenLocked(); 98 static bool screenLocked();
98 99
99 void show(); 100 void show();
100 void checkMemory(); 101 void checkMemory();
101 102
102 void keyClick(); 103 void keyClick();
103 void screenClick(); 104 void screenClick();
104 static void soundAlarm(); 105 static void soundAlarm();
105 106
106public slots: 107public slots:
107 void raiseDatebook(); 108 void raiseDatebook();
108 void raiseContacts(); 109 void raiseContacts();
109 void raiseMenu(); 110 void raiseMenu();
110 void raiseLauncher(); 111 void raiseLauncher();
111 void raiseEmail(); 112 void raiseEmail();
112 void execAutoStart(); 113 void execAutoStart();
113 void togglePower(); 114 void togglePower();
114 void toggleLight(); 115 void toggleLight();
115 void toggleNumLockState(); 116 void toggleNumLockState();
116 void toggleCapsLockState(); 117 void toggleCapsLockState();
117 void toggleSymbolInput(); 118 void toggleSymbolInput();
118 void terminateServers(); 119 void terminateServers();
119 void rereadVolumes(); 120 void rereadVolumes();
120 121
121 void home ( ); 122 void home ( );
122 123
123protected: 124protected:
124 void executeOrModify( const QString& appLnkFile ); 125 void executeOrModify( const QString& appLnkFile );
125 void styleChange( QStyle & ); 126 void styleChange( QStyle & );
126 void timerEvent( QTimerEvent *e ); 127 void timerEvent( QTimerEvent *e );
127 128
128 QWidget *bg; 129 QWidget *bg;
129 Launcher *launcher; 130 Launcher *launcher;
130 TaskBar *tb; 131 TaskBar *tb;
131 132
132private: 133private:
133 void startTransferServer(); 134 void startTransferServer();
134 bool recoverMemory(); 135 bool recoverMemory();
135 136
136 QCopBridge *qcopBridge; 137 QCopBridge *qcopBridge;
137 TransferServer *transferServer; 138 TransferServer *transferServer;
138 PackageSlave *packageSlave; 139 PackageSlave *packageSlave;
139 140
140 QDateTime suspendTime; 141 QDateTime suspendTime;
141 bool keyclick, touchclick, alarmsound; 142 bool keyclick, touchclick, alarmsound;
142}; 143};
143 144
144 145
145#endif // __DESKTOP_H__ 146#endif // __DESKTOP_H__
146 147
diff --git a/core/launcher/main.cpp b/core/launcher/main.cpp
index 762a596..8974ced 100644
--- a/core/launcher/main.cpp
+++ b/core/launcher/main.cpp
@@ -1,173 +1,174 @@
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 "taskbar.h" 22#include "taskbar.h"
23#include "stabmon.h" 23#include "stabmon.h"
24 24
25#include <qpe/qpeapplication.h> 25#include <qpe/qpeapplication.h>
26#include <qpe/network.h> 26#include <qpe/network.h>
27#include <qpe/config.h> 27#include <qpe/config.h>
28#if defined( QT_QWS_CUSTOM ) || defined( QT_QWS_IPAQ ) 28#if defined( QT_QWS_CUSTOM ) || defined( QT_QWS_IPAQ )
29#include <qpe/custom.h> 29#include <qpe/custom.h>
30#endif 30#endif
31 31
32#include <opie/odevice.h> 32#include <opie/odevice.h>
33 33
34#include <qfile.h> 34#include <qfile.h>
35#include <qimage.h> 35#include <qimage.h>
36#include <qwindowsystem_qws.h> 36#include <qwindowsystem_qws.h>
37#include <qpe/qcopenvelope_qws.h> 37#include <qpe/qcopenvelope_qws.h>
38#include <qpe/alarmserver.h> 38#include <qpe/alarmserver.h>
39 39
40#include <stdlib.h> 40#include <stdlib.h>
41#include <stdio.h> 41#include <stdio.h>
42#include <signal.h> 42#include <signal.h>
43#include <unistd.h> 43#include <unistd.h>
44 44
45#if defined(QT_QWS_IPAQ) || defined(QT_QWS_EBX) 45#if defined(QT_QWS_IPAQ) || defined(QT_QWS_EBX)
46#include "../calibrate/calibrate.h" 46#include "../calibrate/calibrate.h"
47#endif 47#endif
48 48
49using namespace Opie; 49using namespace Opie;
50 50
51void initEnvironment() 51void initEnvironment()
52{ 52{
53 Config config("locale"); 53 Config config("locale");
54 config.setGroup( "Location" ); 54 config.setGroup( "Location" );
55 QString tz = config.readEntry( "Timezone", getenv("TZ") ); 55 QString tz = config.readEntry( "Timezone", getenv("TZ") );
56 56
57 // if not timezone set, pick New York 57 // if not timezone set, pick New York
58 if (tz.isNull()) 58 if (tz.isNull())
59 tz = "America/New_York"; 59 tz = "America/New_York";
60 60
61 setenv( "TZ", tz, 1 ); 61 setenv( "TZ", tz, 1 );
62 config.writeEntry( "Timezone", tz); 62 config.writeEntry( "Timezone", tz);
63 63
64 config.setGroup( "Language" ); 64 config.setGroup( "Language" );
65 QString lang = config.readEntry( "Language", getenv("LANG") ); 65 QString lang = config.readEntry( "Language", getenv("LANG") );
66 if ( !lang.isNull() ) 66 if ( !lang.isNull() )
67 setenv( "LANG", lang, 1 ); 67 setenv( "LANG", lang, 1 );
68} 68}
69 69
70 70
71int initApplication( int argc, char ** argv ) 71int initApplication( int argc, char ** argv )
72{ 72{
73 initEnvironment(); 73 initEnvironment();
74 74
75#if !defined(QT_QWS_CASSIOPEIA) && !defined(QT_QWS_IPAQ) && !defined(QT_QWS_EBX) 75#if !defined(QT_QWS_CASSIOPEIA) && !defined(QT_QWS_IPAQ) && !defined(QT_QWS_EBX)
76 setenv( "QWS_SIZE", "240x320", 0 ); 76 setenv( "QWS_SIZE", "240x320", 0 );
77#endif 77#endif
78 78
79 //Don't flicker at startup: 79 //Don't flicker at startup:
80 QWSServer::setDesktopBackground( QImage() ); 80 QWSServer::setDesktopBackground( QImage() );
81 DesktopApplication a( argc, argv, QApplication::GuiServer ); 81 DesktopApplication a( argc, argv, QApplication::GuiServer );
82 82
83 ODevice::inst ( )-> setSoftSuspend ( true ); 83 ODevice::inst ( )-> setSoftSuspend ( true );
84 84
85 { // init backlight 85 { // init backlight
86 QCopEnvelope e("QPE/System", "setBacklight(int)" ); 86 QCopEnvelope e("QPE/System", "setBacklight(int)" );
87 e << -3; // Forced on 87 e << -3; // Forced on
88 } 88 }
89 89
90 AlarmServer::initialize(); 90 AlarmServer::initialize();
91 91
92 Desktop *d = new Desktop(); 92 Desktop *d = new Desktop();
93 93
94 QObject::connect( &a, SIGNAL(menu()), d, SLOT(raiseMenu()) );
94 QObject::connect( &a, SIGNAL(datebook()), d, SLOT(raiseDatebook()) ); 95 QObject::connect( &a, SIGNAL(datebook()), d, SLOT(raiseDatebook()) );
95 QObject::connect( &a, SIGNAL(contacts()), d, SLOT(raiseContacts()) ); 96 QObject::connect( &a, SIGNAL(contacts()), d, SLOT(raiseContacts()) );
96 QObject::connect( &a, SIGNAL(launch()), d, SLOT(raiseLauncher()) ); 97 QObject::connect( &a, SIGNAL(launch()), d, SLOT(raiseLauncher()) );
97 QObject::connect( &a, SIGNAL(email()), d, SLOT(raiseEmail()) ); 98 QObject::connect( &a, SIGNAL(email()), d, SLOT(raiseEmail()) );
98 QObject::connect( &a, SIGNAL(power()), d, SLOT(togglePower()) ); 99 QObject::connect( &a, SIGNAL(power()), d, SLOT(togglePower()) );
99 QObject::connect( &a, SIGNAL(backlight()), d, SLOT(toggleLight()) ); 100 QObject::connect( &a, SIGNAL(backlight()), d, SLOT(toggleLight()) );
100 QObject::connect( &a, SIGNAL(symbol()), d, SLOT(toggleSymbolInput()) ); 101 QObject::connect( &a, SIGNAL(symbol()), d, SLOT(toggleSymbolInput()) );
101 QObject::connect( &a, SIGNAL(numLockStateToggle()), d, SLOT(toggleNumLockState()) ); 102 QObject::connect( &a, SIGNAL(numLockStateToggle()), d, SLOT(toggleNumLockState()) );
102 QObject::connect( &a, SIGNAL(capsLockStateToggle()), d, SLOT(toggleCapsLockState()) ); 103 QObject::connect( &a, SIGNAL(capsLockStateToggle()), d, SLOT(toggleCapsLockState()) );
103 QObject::connect( &a, SIGNAL(prepareForRestart()), d, SLOT(terminateServers()) ); 104 QObject::connect( &a, SIGNAL(prepareForRestart()), d, SLOT(terminateServers()) );
104 105
105 (void)new SysFileMonitor(d); 106 (void)new SysFileMonitor(d);
106 Network::createServer(d); 107 Network::createServer(d);
107 108
108#if defined(QT_QWS_CASSIOPEIA) || defined(QT_QWS_IPAQ) || defined(QT_QWS_EBX) 109#if defined(QT_QWS_CASSIOPEIA) || defined(QT_QWS_IPAQ) || defined(QT_QWS_EBX)
109 if ( !QFile::exists( "/etc/pointercal" ) ) { 110 if ( !QFile::exists( "/etc/pointercal" ) ) {
110 // Make sure calibration widget starts on top. 111 // Make sure calibration widget starts on top.
111 Calibrate *cal = new Calibrate; 112 Calibrate *cal = new Calibrate;
112 cal->exec(); 113 cal->exec();
113 delete cal; 114 delete cal;
114 } 115 }
115#endif 116#endif
116 117
117 d->show(); 118 d->show();
118 119
119 int rv = a.exec(); 120 int rv = a.exec();
120 121
121 delete d; 122 delete d;
122 123
123 ODevice::inst ( )-> setSoftSuspend ( false ); 124 ODevice::inst ( )-> setSoftSuspend ( false );
124 125
125 return rv; 126 return rv;
126} 127}
127 128
128static const char *pidfile_path = "/var/run/opie.pid"; 129static const char *pidfile_path = "/var/run/opie.pid";
129 130
130void create_pidfile ( ) 131void create_pidfile ( )
131{ 132{
132 FILE *f; 133 FILE *f;
133 134
134 if (( f = ::fopen ( pidfile_path, "w" ))) { 135 if (( f = ::fopen ( pidfile_path, "w" ))) {
135 ::fprintf ( f, "%d", getpid ( )); 136 ::fprintf ( f, "%d", getpid ( ));
136 ::fclose ( f ); 137 ::fclose ( f );
137 } 138 }
138} 139}
139 140
140void remove_pidfile ( ) 141void remove_pidfile ( )
141{ 142{
142 ::unlink ( pidfile_path ); 143 ::unlink ( pidfile_path );
143} 144}
144 145
145void handle_sigterm ( int /* sig */ ) 146void handle_sigterm ( int /* sig */ )
146{ 147{
147 if ( qApp ) 148 if ( qApp )
148 qApp-> quit ( ); 149 qApp-> quit ( );
149} 150}
150 151
151int main( int argc, char ** argv ) 152int main( int argc, char ** argv )
152{ 153{
153 ::signal ( SIGCHLD, SIG_IGN ); 154 ::signal ( SIGCHLD, SIG_IGN );
154 155
155 ::signal ( SIGTERM, handle_sigterm ); 156 ::signal ( SIGTERM, handle_sigterm );
156 ::signal ( SIGINT, handle_sigterm ); 157 ::signal ( SIGINT, handle_sigterm );
157 158
158 ::setsid ( ); 159 ::setsid ( );
159 ::setpgid ( 0, 0 ); 160 ::setpgid ( 0, 0 );
160 161
161 ::atexit ( remove_pidfile ); 162 ::atexit ( remove_pidfile );
162 create_pidfile ( ); 163 create_pidfile ( );
163 164
164 int retVal = initApplication ( argc, argv ); 165 int retVal = initApplication ( argc, argv );
165 166
166 // Kill them. Kill them all. 167 // Kill them. Kill them all.
167 ::kill ( 0, SIGTERM ); 168 ::kill ( 0, SIGTERM );
168 ::sleep ( 1 ); 169 ::sleep ( 1 );
169 ::kill ( 0, SIGKILL ); 170 ::kill ( 0, SIGKILL );
170 171
171 return retVal; 172 return retVal;
172} 173}
173 174