summaryrefslogtreecommitdiff
authorllornkcor <llornkcor>2004-04-26 06:42:17 (UTC)
committer llornkcor <llornkcor>2004-04-26 06:42:17 (UTC)
commit4f6f06bab5c52c645ac33bdf77d4ed462b7c6a96 (patch) (unidiff)
treec1c6adc8c197ea923b1cb8c784f5968ca5fe906b
parent0e3e74030b2a38cfc754d253ab098a1126f382ef (diff)
downloadopie-4f6f06bab5c52c645ac33bdf77d4ed462b7c6a96.zip
opie-4f6f06bab5c52c645ac33bdf77d4ed462b7c6a96.tar.gz
opie-4f6f06bab5c52c645ac33bdf77d4ed462b7c6a96.tar.bz2
make shutdown app move to more proper position so it doesn't cut off the titlebar
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/launcher/serverapp.cpp2
1 files changed, 2 insertions, 0 deletions
diff --git a/core/launcher/serverapp.cpp b/core/launcher/serverapp.cpp
index cf543ce..807942d 100644
--- a/core/launcher/serverapp.cpp
+++ b/core/launcher/serverapp.cpp
@@ -196,668 +196,670 @@ bool KeyFilter::checkButtonAction(bool db, int keycode, int press, int autoRepe
196 return true; 196 return true;
197 }else { 197 }else {
198 198
199 199
200 // First check to see if DeviceButtonManager knows something about this button: 200 // First check to see if DeviceButtonManager knows something about this button:
201 const ODeviceButton* button = ODevice::inst()->buttonForKeycode(keycode); 201 const ODeviceButton* button = ODevice::inst()->buttonForKeycode(keycode);
202 if (button && !autoRepeat) { 202 if (button && !autoRepeat) {
203 if ( held_tid ) { 203 if ( held_tid ) {
204 killTimer(held_tid); 204 killTimer(held_tid);
205 held_tid = 0; 205 held_tid = 0;
206 } 206 }
207 if ( button->heldAction().isNull() ) { 207 if ( button->heldAction().isNull() ) {
208 if ( press ) 208 if ( press )
209 emit activate(button, FALSE); 209 emit activate(button, FALSE);
210 } else if ( press ) { 210 } else if ( press ) {
211 heldButton = button; 211 heldButton = button;
212 held_tid = startTimer( ODevice::inst ()->buttonHoldTime () ); 212 held_tid = startTimer( ODevice::inst ()->buttonHoldTime () );
213 } else if ( heldButton ) { 213 } else if ( heldButton ) {
214 heldButton = 0; 214 heldButton = 0;
215 emit activate(button, FALSE); 215 emit activate(button, FALSE);
216 } 216 }
217 QWSServer::screenSaverActivate(FALSE); 217 QWSServer::screenSaverActivate(FALSE);
218 return TRUE; 218 return TRUE;
219 } 219 }
220 return false; 220 return false;
221 } 221 }
222 if ( keycode == HardKey_Suspend ) { 222 if ( keycode == HardKey_Suspend ) {
223 if ( press ) emit power(); 223 if ( press ) emit power();
224 return TRUE; 224 return TRUE;
225 } 225 }
226 if ( keycode == HardKey_Backlight ) { 226 if ( keycode == HardKey_Backlight ) {
227 if ( press ) emit backlight(); 227 if ( press ) emit backlight();
228 return TRUE; 228 return TRUE;
229 } 229 }
230 if ( keycode == Key_F32 ) { 230 if ( keycode == Key_F32 ) {
231#ifndef QT_NO_COP 231#ifndef QT_NO_COP
232 if ( press ) QCopEnvelope e( "QPE/Desktop", "startSync()" ); 232 if ( press ) QCopEnvelope e( "QPE/Desktop", "startSync()" );
233#endif 233#endif
234 return TRUE; 234 return TRUE;
235 } 235 }
236 if ( keycode == Key_F31 ) { 236 if ( keycode == Key_F31 ) {
237 if ( press ) emit symbol(); 237 if ( press ) emit symbol();
238 QWSServer::screenSaverActivate(FALSE); 238 QWSServer::screenSaverActivate(FALSE);
239 return TRUE; 239 return TRUE;
240 } 240 }
241 241
242 if ( keycode == Key_NumLock ) 242 if ( keycode == Key_NumLock )
243 if ( press ) emit numLockStateToggle(); 243 if ( press ) emit numLockStateToggle();
244 244
245 if ( keycode == Key_CapsLock ) 245 if ( keycode == Key_CapsLock )
246 if ( press ) emit capsLockStateToggle(); 246 if ( press ) emit capsLockStateToggle();
247 247
248 if ( serverApp ) 248 if ( serverApp )
249 serverApp->keyClick(keycode,press,autoRepeat); 249 serverApp->keyClick(keycode,press,autoRepeat);
250 250
251 return FALSE; 251 return FALSE;
252} 252}
253 253
254enum MemState { MemUnknown, MemVeryLow, MemLow, MemNormal } memstate=MemUnknown; 254enum MemState { MemUnknown, MemVeryLow, MemLow, MemNormal } memstate=MemUnknown;
255 255
256#if defined(QPE_HAVE_MEMALERTER) 256#if defined(QPE_HAVE_MEMALERTER)
257QPE_MEMALERTER_IMPL 257QPE_MEMALERTER_IMPL
258#endif 258#endif
259 259
260 260
261 261
262//--------------------------------------------------------------------------- 262//---------------------------------------------------------------------------
263 263
264bool ServerApplication::doRestart = FALSE; 264bool ServerApplication::doRestart = FALSE;
265bool ServerApplication::allowRestart = TRUE; 265bool ServerApplication::allowRestart = TRUE;
266bool ServerApplication::ms_is_starting = TRUE; 266bool ServerApplication::ms_is_starting = TRUE;
267 267
268void ServerApplication::switchLCD( bool on ) { 268void ServerApplication::switchLCD( bool on ) {
269 if ( !qApp ) 269 if ( !qApp )
270 return; 270 return;
271 271
272 ServerApplication *dapp = ServerApplication::me() ; 272 ServerApplication *dapp = ServerApplication::me() ;
273 273
274 if ( !dapp-> m_screensaver ) 274 if ( !dapp-> m_screensaver )
275 return; 275 return;
276 276
277 if ( on ) { 277 if ( on ) {
278 dapp-> m_screensaver-> setDisplayState ( true ); 278 dapp-> m_screensaver-> setDisplayState ( true );
279 dapp-> m_screensaver-> setBacklight ( -3 ); 279 dapp-> m_screensaver-> setBacklight ( -3 );
280 }else 280 }else
281 dapp-> m_screensaver-> setDisplayState ( false ); 281 dapp-> m_screensaver-> setDisplayState ( false );
282 282
283 283
284} 284}
285 285
286ServerApplication::ServerApplication( int& argc, char **argv, Type t ) 286ServerApplication::ServerApplication( int& argc, char **argv, Type t )
287 : QPEApplication( argc, argv, t ) 287 : QPEApplication( argc, argv, t )
288{ 288{
289 ms_is_starting = true; 289 ms_is_starting = true;
290 290
291 // We know we'll have lots of cached pixmaps due to App/DocLnks 291 // We know we'll have lots of cached pixmaps due to App/DocLnks
292 QPixmapCache::setCacheLimit(512); 292 QPixmapCache::setCacheLimit(512);
293 293
294 m_ps = new PowerStatus; 294 m_ps = new PowerStatus;
295 m_ps_last = new PowerStatus; 295 m_ps_last = new PowerStatus;
296 pa = new DesktopPowerAlerter( 0 ); 296 pa = new DesktopPowerAlerter( 0 );
297 297
298 m_apm_timer = new QTimer( this ); 298 m_apm_timer = new QTimer( this );
299 connect(m_apm_timer, SIGNAL( timeout() ), 299 connect(m_apm_timer, SIGNAL( timeout() ),
300 this, SLOT( apmTimeout() ) ); 300 this, SLOT( apmTimeout() ) );
301 301
302 reloadPowerWarnSettings(); 302 reloadPowerWarnSettings();
303 303
304 QCopChannel *channel = new QCopChannel( "QPE/System", this ); 304 QCopChannel *channel = new QCopChannel( "QPE/System", this );
305 connect(channel, SIGNAL(received(const QCString&,const QByteArray&) ), 305 connect(channel, SIGNAL(received(const QCString&,const QByteArray&) ),
306 this, SLOT(systemMessage(const QCString&,const QByteArray&) ) ); 306 this, SLOT(systemMessage(const QCString&,const QByteArray&) ) );
307 307
308 channel = new QCopChannel("QPE/Launcher", this ); 308 channel = new QCopChannel("QPE/Launcher", this );
309 connect(channel, SIGNAL(received(const QCString&,const QByteArray&) ), 309 connect(channel, SIGNAL(received(const QCString&,const QByteArray&) ),
310 this, SLOT(launcherMessage(const QCString&,const QByteArray&) ) ); 310 this, SLOT(launcherMessage(const QCString&,const QByteArray&) ) );
311 311
312 m_screensaver = new OpieScreenSaver(); 312 m_screensaver = new OpieScreenSaver();
313 m_screensaver->setInterval( -1 ); 313 m_screensaver->setInterval( -1 );
314 QWSServer::setScreenSaver( m_screensaver ); 314 QWSServer::setScreenSaver( m_screensaver );
315 315
316 connect( qApp, SIGNAL( volumeChanged(bool) ), 316 connect( qApp, SIGNAL( volumeChanged(bool) ),
317 this, SLOT( rereadVolumes() ) ); 317 this, SLOT( rereadVolumes() ) );
318 318
319 319
320 /* ### PluginLoader libqtopia SafeMode */ 320 /* ### PluginLoader libqtopia SafeMode */
321#if 0 321#if 0
322 if ( PluginLoader::inSafeMode() ) 322 if ( PluginLoader::inSafeMode() )
323 QTimer::singleShot(500, this, SLOT(showSafeMode()) ); 323 QTimer::singleShot(500, this, SLOT(showSafeMode()) );
324 QTimer::singleShot(20*1000, this, SLOT(clearSafeMode()) ); 324 QTimer::singleShot(20*1000, this, SLOT(clearSafeMode()) );
325#endif 325#endif
326 326
327 kf = new KeyFilter(this); 327 kf = new KeyFilter(this);
328 328
329 connect( kf, SIGNAL(launch()), this, SIGNAL(launch()) ); 329 connect( kf, SIGNAL(launch()), this, SIGNAL(launch()) );
330 connect( kf, SIGNAL(power()), this, SIGNAL(power()) ); 330 connect( kf, SIGNAL(power()), this, SIGNAL(power()) );
331 connect( kf, SIGNAL(backlight()), this, SIGNAL(backlight()) ); 331 connect( kf, SIGNAL(backlight()), this, SIGNAL(backlight()) );
332 connect( kf, SIGNAL(symbol()), this, SIGNAL(symbol())); 332 connect( kf, SIGNAL(symbol()), this, SIGNAL(symbol()));
333 connect( kf, SIGNAL(numLockStateToggle()), this,SIGNAL(numLockStateToggle())); 333 connect( kf, SIGNAL(numLockStateToggle()), this,SIGNAL(numLockStateToggle()));
334 connect( kf, SIGNAL(capsLockStateToggle()), this,SIGNAL(capsLockStateToggle())); 334 connect( kf, SIGNAL(capsLockStateToggle()), this,SIGNAL(capsLockStateToggle()));
335 connect( kf, SIGNAL(activate(const Opie::Core::ODeviceButton*,bool)), 335 connect( kf, SIGNAL(activate(const Opie::Core::ODeviceButton*,bool)),
336 this,SIGNAL(activate(const Opie::Core::ODeviceButton*,bool))); 336 this,SIGNAL(activate(const Opie::Core::ODeviceButton*,bool)));
337 337
338 338
339 connect( kf, SIGNAL(backlight()), this, SLOT(toggleLight()) ); 339 connect( kf, SIGNAL(backlight()), this, SLOT(toggleLight()) );
340 340
341 connect( this, SIGNAL(power() ), 341 connect( this, SIGNAL(power() ),
342 SLOT(togglePower() ) ); 342 SLOT(togglePower() ) );
343 343
344 rereadVolumes(); 344 rereadVolumes();
345 345
346 serverApp = this; 346 serverApp = this;
347 347
348 apmTimeout(); 348 apmTimeout();
349 grabKeyboard(); 349 grabKeyboard();
350 350
351 /* make sure the event filter is installed */ 351 /* make sure the event filter is installed */
352 const ODeviceButton* but = ODevice::inst()->buttonForKeycode( -1 ); 352 const ODeviceButton* but = ODevice::inst()->buttonForKeycode( -1 );
353} 353}
354 354
355 355
356ServerApplication::~ServerApplication() 356ServerApplication::~ServerApplication()
357{ 357{
358 ungrabKeyboard(); 358 ungrabKeyboard();
359 359
360 360
361 delete pa; 361 delete pa;
362 delete m_ps; 362 delete m_ps;
363 delete m_ps_last; 363 delete m_ps_last;
364} 364}
365 365
366void ServerApplication::apmTimeout() { 366void ServerApplication::apmTimeout() {
367 serverApp-> checkMemory( ); // in case no events are generated 367 serverApp-> checkMemory( ); // in case no events are generated
368 *m_ps_last = *m_ps; 368 *m_ps_last = *m_ps;
369 *m_ps = PowerStatusManager::readStatus(); 369 *m_ps = PowerStatusManager::readStatus();
370 370
371 if ( m_ps->acStatus() != m_ps_last-> acStatus() ) 371 if ( m_ps->acStatus() != m_ps_last-> acStatus() )
372 m_screensaver-> powerStatusChanged( *m_ps ); 372 m_screensaver-> powerStatusChanged( *m_ps );
373 373
374 if ( m_ps->acStatus() == PowerStatus::Online ) { 374 if ( m_ps->acStatus() == PowerStatus::Online ) {
375 return; 375 return;
376 } 376 }
377 377
378 int bat = m_ps-> batteryPercentRemaining(); 378 int bat = m_ps-> batteryPercentRemaining();
379 379
380 if ( bat < m_ps_last-> batteryPercentRemaining() ) { 380 if ( bat < m_ps_last-> batteryPercentRemaining() ) {
381 if ( bat <= m_powerCritical ) { 381 if ( bat <= m_powerCritical ) {
382 QMessageBox battlow( 382 QMessageBox battlow(
383 tr("WARNING"), 383 tr("WARNING"),
384 tr("<p>The battery level is critical!" 384 tr("<p>The battery level is critical!"
385 "<p>Keep power off until AC is restored"), 385 "<p>Keep power off until AC is restored"),
386 QMessageBox::Warning, 386 QMessageBox::Warning,
387 QMessageBox::Cancel, QMessageBox::NoButton, QMessageBox::NoButton, 387 QMessageBox::Cancel, QMessageBox::NoButton, QMessageBox::NoButton,
388 0, QString::null, TRUE, WStyle_StaysOnTop); 388 0, QString::null, TRUE, WStyle_StaysOnTop);
389 battlow.setButtonText(QMessageBox::Cancel, tr("Ok")); 389 battlow.setButtonText(QMessageBox::Cancel, tr("Ok"));
390 battlow.exec(); 390 battlow.exec();
391 } else if ( bat <= m_powerVeryLow ) 391 } else if ( bat <= m_powerVeryLow )
392 pa->alert( tr( "The battery is running very low. "), 2 ); 392 pa->alert( tr( "The battery is running very low. "), 2 );
393 } 393 }
394 394
395 if ( m_ps-> backupBatteryStatus() == PowerStatus::VeryLow ) { 395 if ( m_ps-> backupBatteryStatus() == PowerStatus::VeryLow ) {
396 QMessageBox battlow( 396 QMessageBox battlow(
397 tr("WARNING"), 397 tr("WARNING"),
398 tr("<p>The Back-up battery is very low" 398 tr("<p>The Back-up battery is very low"
399 "<p>Please charge the back-up battery"), 399 "<p>Please charge the back-up battery"),
400 QMessageBox::Warning, 400 QMessageBox::Warning,
401 QMessageBox::Cancel, QMessageBox::NoButton, QMessageBox::NoButton, 401 QMessageBox::Cancel, QMessageBox::NoButton, QMessageBox::NoButton,
402 0, QString::null, TRUE, WStyle_StaysOnTop); 402 0, QString::null, TRUE, WStyle_StaysOnTop);
403 battlow.setButtonText(QMessageBox::Cancel, tr("Ok")); 403 battlow.setButtonText(QMessageBox::Cancel, tr("Ok"));
404 battlow.exec(); 404 battlow.exec();
405 } 405 }
406} 406}
407 407
408void ServerApplication::systemMessage( const QCString& msg, 408void ServerApplication::systemMessage( const QCString& msg,
409 const QByteArray& data ) { 409 const QByteArray& data ) {
410 QDataStream stream ( data, IO_ReadOnly ); 410 QDataStream stream ( data, IO_ReadOnly );
411 411
412 if ( msg == "setScreenSaverInterval(int)" ) { 412 if ( msg == "setScreenSaverInterval(int)" ) {
413 int time; 413 int time;
414 stream >> time; 414 stream >> time;
415 m_screensaver-> setInterval( time ); 415 m_screensaver-> setInterval( time );
416 } 416 }
417 else if ( msg == "setScreenSaverIntervals(int,int,int)" ) { 417 else if ( msg == "setScreenSaverIntervals(int,int,int)" ) {
418 int t1, t2, t3; 418 int t1, t2, t3;
419 stream >> t1 >> t2 >> t3; 419 stream >> t1 >> t2 >> t3;
420 m_screensaver-> setIntervals( t1, t2, t3 ); 420 m_screensaver-> setIntervals( t1, t2, t3 );
421 } 421 }
422 else if ( msg == "setBacklight(int)" ) { 422 else if ( msg == "setBacklight(int)" ) {
423 int bright; 423 int bright;
424 stream >> bright; 424 stream >> bright;
425 m_screensaver-> setBacklight( bright ); 425 m_screensaver-> setBacklight( bright );
426 } 426 }
427 else if ( msg == "setScreenSaverMode(int)" ) { 427 else if ( msg == "setScreenSaverMode(int)" ) {
428 int mode; 428 int mode;
429 stream >> mode; 429 stream >> mode;
430 m_screensaver-> setMode ( mode ); 430 m_screensaver-> setMode ( mode );
431 } 431 }
432 else if ( msg == "reloadPowerWarnSettings()" ) { 432 else if ( msg == "reloadPowerWarnSettings()" ) {
433 reloadPowerWarnSettings(); 433 reloadPowerWarnSettings();
434 } 434 }
435 else if ( msg == "setDisplayState(int)" ) { 435 else if ( msg == "setDisplayState(int)" ) {
436 int state; 436 int state;
437 stream >> state; 437 stream >> state;
438 m_screensaver-> setDisplayState ( state != 0 ); 438 m_screensaver-> setDisplayState ( state != 0 );
439 } 439 }
440 else if ( msg == "suspend()" ) { 440 else if ( msg == "suspend()" ) {
441 emit power(); 441 emit power();
442 } 442 }
443 else if ( msg == "sendBusinessCard()" ) { 443 else if ( msg == "sendBusinessCard()" ) {
444 QString card = ::getenv ( "HOME" ); 444 QString card = ::getenv ( "HOME" );
445 card += "/Applications/addressbook/businesscard.vcf"; 445 card += "/Applications/addressbook/businesscard.vcf";
446 446
447 if ( QFile::exists( card ) ) { 447 if ( QFile::exists( card ) ) {
448 QCopEnvelope e ( "QPE/Obex", "send(QString,QString,QString)" ); 448 QCopEnvelope e ( "QPE/Obex", "send(QString,QString,QString)" );
449 QString mimetype = "text/x-vCard"; 449 QString mimetype = "text/x-vCard";
450 e << tr( "business card" ) << card << mimetype; 450 e << tr( "business card" ) << card << mimetype;
451 } 451 }
452 } 452 }
453} 453}
454 454
455void ServerApplication::reloadPowerWarnSettings ( ) 455void ServerApplication::reloadPowerWarnSettings ( )
456{ 456{
457 Config cfg ( "apm" ); 457 Config cfg ( "apm" );
458 cfg. setGroup ( "Warnings" ); 458 cfg. setGroup ( "Warnings" );
459 459
460 int iv = cfg. readNumEntry ( "checkinterval", 10000 ); 460 int iv = cfg. readNumEntry ( "checkinterval", 10000 );
461 461
462 m_apm_timer-> stop ( ); 462 m_apm_timer-> stop ( );
463 if ( iv ) 463 if ( iv )
464 m_apm_timer-> start ( iv ); 464 m_apm_timer-> start ( iv );
465 465
466 m_powerVeryLow = cfg. readNumEntry ( "powerverylow", 10 ); 466 m_powerVeryLow = cfg. readNumEntry ( "powerverylow", 10 );
467 m_powerCritical = cfg. readNumEntry ( "powervcritical", 5 ); 467 m_powerCritical = cfg. readNumEntry ( "powervcritical", 5 );
468} 468}
469 469
470void ServerApplication::launcherMessage( const QCString & msg, const QByteArray & data ) 470void ServerApplication::launcherMessage( const QCString & msg, const QByteArray & data )
471{ 471{
472 QDataStream stream ( data, IO_ReadOnly ); 472 QDataStream stream ( data, IO_ReadOnly );
473 473
474 if ( msg == "deviceButton(int,int,int)" ) { 474 if ( msg == "deviceButton(int,int,int)" ) {
475 int keycode, press, autoRepeat; 475 int keycode, press, autoRepeat;
476 stream >> keycode >> press >> autoRepeat; 476 stream >> keycode >> press >> autoRepeat;
477 477
478 kf->checkButtonAction ( true, keycode, press, autoRepeat ); 478 kf->checkButtonAction ( true, keycode, press, autoRepeat );
479 } 479 }
480 else if ( msg == "keyRegister(int,QCString,QCString)" ) { 480 else if ( msg == "keyRegister(int,QCString,QCString)" ) {
481 int k; 481 int k;
482 QCString c, m; 482 QCString c, m;
483 stream >> k >> c >> m; 483 stream >> k >> c >> m;
484 484
485 kf -> registerKey( QCopKeyRegister(k, c, m) ); 485 kf -> registerKey( QCopKeyRegister(k, c, m) );
486 } 486 }
487} 487}
488 488
489 489
490bool ServerApplication::screenLocked() 490bool ServerApplication::screenLocked()
491{ 491{
492 return loggedin == 0; 492 return loggedin == 0;
493} 493}
494 494
495void ServerApplication::login(bool at_poweron) 495void ServerApplication::login(bool at_poweron)
496{ 496{
497 if ( !loggedin ) { 497 if ( !loggedin ) {
498 Global::terminateBuiltin("calibrate"); // No tr 498 Global::terminateBuiltin("calibrate"); // No tr
499 Password::authenticate(at_poweron); 499 Password::authenticate(at_poweron);
500 loggedin=1; 500 loggedin=1;
501#ifndef QT_NO_COP 501#ifndef QT_NO_COP
502 QCopEnvelope e( "QPE/Desktop", "unlocked()" ); 502 QCopEnvelope e( "QPE/Desktop", "unlocked()" );
503#endif 503#endif
504 } 504 }
505} 505}
506 506
507#if defined(QPE_HAVE_TOGGLELIGHT) 507#if defined(QPE_HAVE_TOGGLELIGHT)
508#include <qtopia/config.h> 508#include <qtopia/config.h>
509 509
510#include <sys/ioctl.h> 510#include <sys/ioctl.h>
511#include <sys/types.h> 511#include <sys/types.h>
512#include <fcntl.h> 512#include <fcntl.h>
513#include <unistd.h> 513#include <unistd.h>
514#include <errno.h> 514#include <errno.h>
515#include <linux/ioctl.h> 515#include <linux/ioctl.h>
516#include <time.h> 516#include <time.h>
517#endif 517#endif
518 518
519#if 0 519#if 0
520static bool blanked=FALSE; 520static bool blanked=FALSE;
521 521
522static void blankScreen() 522static void blankScreen()
523{ 523{
524#ifdef QWS 524#ifdef QWS
525 QWidget w(0, 0, Qt::WStyle_Customize | Qt::WStyle_NoBorder | Qt::WStyle_Tool | Qt::WStyle_StaysOnTop | Qt::WPaintUnclipped); 525 QWidget w(0, 0, Qt::WStyle_Customize | Qt::WStyle_NoBorder | Qt::WStyle_Tool | Qt::WStyle_StaysOnTop | Qt::WPaintUnclipped);
526 w.resize( qt_screen->width(), qt_screen->height() ); 526 w.resize( qt_screen->width(), qt_screen->height() );
527 w.move(0, 0); 527 w.move(0, 0);
528 528
529 QPainter p(&w); 529 QPainter p(&w);
530 p.fillRect(w.rect(), QBrush(QColor(255,255,255)) ); 530 p.fillRect(w.rect(), QBrush(QColor(255,255,255)) );
531 p.end(); 531 p.end();
532 w.repaint(); 532 w.repaint();
533 533
534 blanked = TRUE; 534 blanked = TRUE;
535#endif 535#endif
536} 536}
537 537
538static void darkScreen() 538static void darkScreen()
539{ 539{
540 /* ### Screen blanking ODevice */ 540 /* ### Screen blanking ODevice */
541#if 0 541#if 0
542 qpe_setBacklight(0); // force off 542 qpe_setBacklight(0); // force off
543#endif 543#endif
544} 544}
545#endif 545#endif
546 546
547namespace { 547namespace {
548 void execAutoStart(const QDateTime& suspendTime ) { 548 void execAutoStart(const QDateTime& suspendTime ) {
549 QString appName; 549 QString appName;
550 int delay; 550 int delay;
551 QDateTime now = QDateTime::currentDateTime(); 551 QDateTime now = QDateTime::currentDateTime();
552 552
553 Config cfg( "autostart" ); 553 Config cfg( "autostart" );
554 cfg.setGroup( "AutoStart" ); 554 cfg.setGroup( "AutoStart" );
555 appName = cfg.readEntry( "Apps", "" ); 555 appName = cfg.readEntry( "Apps", "" );
556 delay = cfg.readNumEntry( "Delay", 0 ); 556 delay = cfg.readNumEntry( "Delay", 0 );
557 557
558 // If the time between suspend and resume was longer then the 558 // If the time between suspend and resume was longer then the
559 // value saved as delay, start the app 559 // value saved as delay, start the app
560 if ( suspendTime.secsTo( now ) >= ( delay * 60 ) && !appName.isEmpty() ) { 560 if ( suspendTime.secsTo( now ) >= ( delay * 60 ) && !appName.isEmpty() ) {
561 QCopEnvelope e( "QPE/System", "execute(QString)" ); 561 QCopEnvelope e( "QPE/System", "execute(QString)" );
562 e << QString( appName ); 562 e << QString( appName );
563 } 563 }
564 } 564 }
565} 565}
566 566
567 567
568void ServerApplication::togglePower() 568void ServerApplication::togglePower()
569{ 569{
570 static bool excllock = false; 570 static bool excllock = false;
571 571
572 if ( excllock ) 572 if ( excllock )
573 return ; 573 return ;
574 574
575 excllock = true; 575 excllock = true;
576 576
577 bool wasloggedin = loggedin; 577 bool wasloggedin = loggedin;
578 loggedin = 0; 578 loggedin = 0;
579 m_suspendTime = QDateTime::currentDateTime(); 579 m_suspendTime = QDateTime::currentDateTime();
580 580
581#ifdef QWS 581#ifdef QWS
582 582
583 if ( Password::needToAuthenticate ( true ) && qt_screen ) { 583 if ( Password::needToAuthenticate ( true ) && qt_screen ) {
584 // Should use a big black window instead. 584 // Should use a big black window instead.
585 // But this would not show up fast enough 585 // But this would not show up fast enough
586 QGfx *g = qt_screen-> screenGfx ( ); 586 QGfx *g = qt_screen-> screenGfx ( );
587 g-> fillRect ( 0, 0, qt_screen-> width ( ), qt_screen-> height ( )); 587 g-> fillRect ( 0, 0, qt_screen-> width ( ), qt_screen-> height ( ));
588 delete g; 588 delete g;
589 } 589 }
590#endif 590#endif
591 591
592 ODevice::inst ( )-> suspend ( ); 592 ODevice::inst ( )-> suspend ( );
593 593
594 ServerApplication::switchLCD ( true ); // force LCD on without slow qcop call 594 ServerApplication::switchLCD ( true ); // force LCD on without slow qcop call
595 QWSServer::screenSaverActivate ( false ); 595 QWSServer::screenSaverActivate ( false );
596 596
597 { 597 {
598 QCopEnvelope( "QPE/Card", "mtabChanged()" ); // might have changed while asleep 598 QCopEnvelope( "QPE/Card", "mtabChanged()" ); // might have changed while asleep
599 } 599 }
600 600
601 if ( wasloggedin ) 601 if ( wasloggedin )
602 login ( true ); 602 login ( true );
603 603
604 execAutoStart(m_suspendTime); 604 execAutoStart(m_suspendTime);
605 //qcopBridge->closeOpenConnections(); 605 //qcopBridge->closeOpenConnections();
606 606
607 excllock = false; 607 excllock = false;
608} 608}
609 609
610void ServerApplication::toggleLight() 610void ServerApplication::toggleLight()
611{ 611{
612#ifndef QT_NO_COP 612#ifndef QT_NO_COP
613 QCopEnvelope e("QPE/System", "setBacklight(int)"); 613 QCopEnvelope e("QPE/System", "setBacklight(int)");
614 e << -2; // toggle 614 e << -2; // toggle
615#endif 615#endif
616} 616}
617 617
618 618
619/* 619/*
620 * We still listen to key events but handle them in 620 * We still listen to key events but handle them in
621 * a special class 621 * a special class
622 */ 622 */
623 623
624bool ServerApplication::eventFilter( QObject *o, QEvent *e) { 624bool ServerApplication::eventFilter( QObject *o, QEvent *e) {
625 if ( e->type() != QEvent::KeyPress && 625 if ( e->type() != QEvent::KeyPress &&
626 e->type() != QEvent::KeyRelease ) 626 e->type() != QEvent::KeyRelease )
627 return QPEApplication::eventFilter( o, e ); 627 return QPEApplication::eventFilter( o, e );
628 628
629 QKeyEvent *ke = static_cast<QKeyEvent*>( e ); 629 QKeyEvent *ke = static_cast<QKeyEvent*>( e );
630 if ( kf->checkButtonAction( true, ke->key(), 630 if ( kf->checkButtonAction( true, ke->key(),
631 e->type() == QEvent::KeyPress, 631 e->type() == QEvent::KeyPress,
632 ke-> isAutoRepeat() )) 632 ke-> isAutoRepeat() ))
633 return true; 633 return true;
634 634
635 return QPEApplication::eventFilter( o, e ); 635 return QPEApplication::eventFilter( o, e );
636 636
637} 637}
638 638
639#ifdef Q_WS_QWS 639#ifdef Q_WS_QWS
640bool ServerApplication::qwsEventFilter( QWSEvent *e ) 640bool ServerApplication::qwsEventFilter( QWSEvent *e )
641{ 641{
642 checkMemory(); 642 checkMemory();
643 643
644 if ( e->type == QWSEvent::Mouse ) { 644 if ( e->type == QWSEvent::Mouse ) {
645 QWSMouseEvent *me = (QWSMouseEvent *)e; 645 QWSMouseEvent *me = (QWSMouseEvent *)e;
646 static bool up = TRUE; 646 static bool up = TRUE;
647 if ( me->simpleData.state&LeftButton ) { 647 if ( me->simpleData.state&LeftButton ) {
648 if ( up ) { 648 if ( up ) {
649 up = FALSE; 649 up = FALSE;
650 screenClick(TRUE); 650 screenClick(TRUE);
651 } 651 }
652 } else if ( !up ) { 652 } else if ( !up ) {
653 up = TRUE; 653 up = TRUE;
654 screenClick(FALSE); 654 screenClick(FALSE);
655 } 655 }
656 }else if ( e->type == QWSEvent::Key ) { 656 }else if ( e->type == QWSEvent::Key ) {
657 QWSKeyEvent * ke = static_cast<QWSKeyEvent*>( e ); 657 QWSKeyEvent * ke = static_cast<QWSKeyEvent*>( e );
658 if ( kf->checkButtonAction( false, 658 if ( kf->checkButtonAction( false,
659 ke-> simpleData.keycode, 659 ke-> simpleData.keycode,
660 ke-> simpleData.is_press, 660 ke-> simpleData.is_press,
661 ke-> simpleData.is_auto_repeat ) ) 661 ke-> simpleData.is_auto_repeat ) )
662 return true; 662 return true;
663 } 663 }
664 664
665 return QPEApplication::qwsEventFilter( e ); 665 return QPEApplication::qwsEventFilter( e );
666} 666}
667#endif 667#endif
668 668
669 669
670/* ### FIXME libqtopia Plugin Safe Mode */ 670/* ### FIXME libqtopia Plugin Safe Mode */
671 671
672void ServerApplication::showSafeMode() 672void ServerApplication::showSafeMode()
673{ 673{
674#if 0 674#if 0
675 if ( QMessageBox::warning(0, tr("Safe Mode"), tr("<P>A system startup error occurred, " 675 if ( QMessageBox::warning(0, tr("Safe Mode"), tr("<P>A system startup error occurred, "
676 "and the system is now in Safe Mode. " 676 "and the system is now in Safe Mode. "
677 "Plugins are not loaded in Safe Mode. " 677 "Plugins are not loaded in Safe Mode. "
678 "You can use the Plugin Manager to " 678 "You can use the Plugin Manager to "
679 "disable plugins that cause system error."), tr("OK"), tr("Plugin Manager..."), 0) == 1 ) { 679 "disable plugins that cause system error."), tr("OK"), tr("Plugin Manager..."), 0) == 1 ) {
680 Global::execute( "pluginmanager" ); 680 Global::execute( "pluginmanager" );
681 } 681 }
682#endif 682#endif
683} 683}
684 684
685void ServerApplication::clearSafeMode() 685void ServerApplication::clearSafeMode()
686{ 686{
687#if 0 687#if 0
688 // If we've been running OK for a while then we won't bother going into 688 // If we've been running OK for a while then we won't bother going into
689 // safe mode immediately on the next crash. 689 // safe mode immediately on the next crash.
690 Config cfg( "PluginLoader" ); 690 Config cfg( "PluginLoader" );
691 cfg.setGroup( "Global" ); 691 cfg.setGroup( "Global" );
692 QString mode = cfg.readEntry( "Mode", "Normal" ); 692 QString mode = cfg.readEntry( "Mode", "Normal" );
693 if ( mode == "MaybeSafe" ) { 693 if ( mode == "MaybeSafe" ) {
694 cfg.writeEntry( "Mode", "Normal" ); 694 cfg.writeEntry( "Mode", "Normal" );
695 } 695 }
696#endif 696#endif
697} 697}
698 698
699 699
700void ServerApplication::shutdown() 700void ServerApplication::shutdown()
701{ 701{
702 if ( type() != GuiServer ) 702 if ( type() != GuiServer )
703 return; 703 return;
704 ShutdownImpl *sd = new ShutdownImpl( 0, 0, WDestructiveClose ); 704 ShutdownImpl *sd = new ShutdownImpl( 0, 0, WDestructiveClose );
705 connect( sd, SIGNAL(shutdown(ShutdownImpl::Type)), 705 connect( sd, SIGNAL(shutdown(ShutdownImpl::Type)),
706 this, SLOT(shutdown(ShutdownImpl::Type)) ); 706 this, SLOT(shutdown(ShutdownImpl::Type)) );
707 QPEApplication::showWidget( sd ); 707 QPEApplication::showWidget( sd );
708 sd->move(0,0);
709
708} 710}
709 711
710void ServerApplication::shutdown( ShutdownImpl::Type t ) 712void ServerApplication::shutdown( ShutdownImpl::Type t )
711{ 713{
712 char *opt = 0; 714 char *opt = 0;
713 715
714 switch ( t ) { 716 switch ( t ) {
715 case ShutdownImpl::ShutdownSystem: 717 case ShutdownImpl::ShutdownSystem:
716 opt = "-h"; 718 opt = "-h";
717 // fall through 719 // fall through
718 case ShutdownImpl::RebootSystem: 720 case ShutdownImpl::RebootSystem:
719 if ( opt == 0 ) 721 if ( opt == 0 )
720 opt = "-r"; 722 opt = "-r";
721 723
722 if ( execl( "/sbin/shutdown", "shutdown", opt, "now", ( void* ) 0) < 0 ) 724 if ( execl( "/sbin/shutdown", "shutdown", opt, "now", ( void* ) 0) < 0 )
723 perror("shutdown"); 725 perror("shutdown");
724 // ::syslog ( LOG_ERR, "Erroring execing shutdown\n" ); 726 // ::syslog ( LOG_ERR, "Erroring execing shutdown\n" );
725 727
726 break; 728 break;
727 case ShutdownImpl::RestartDesktop: 729 case ShutdownImpl::RestartDesktop:
728 restart(); 730 restart();
729 break; 731 break;
730 case ShutdownImpl::TerminateDesktop: 732 case ShutdownImpl::TerminateDesktop:
731 prepareForTermination( FALSE ); 733 prepareForTermination( FALSE );
732 734
733 // This is a workaround for a Qt bug 735 // This is a workaround for a Qt bug
734 // clipboard applet has to stop its poll timer, or Qt/E 736 // clipboard applet has to stop its poll timer, or Qt/E
735 // will hang on quit() right before it emits aboutToQuit() 737 // will hang on quit() right before it emits aboutToQuit()
736 emit aboutToQuit ( ); 738 emit aboutToQuit ( );
737 739
738 quit(); 740 quit();
739 break; 741 break;
740 } 742 }
741} 743}
742 744
743void ServerApplication::restart() 745void ServerApplication::restart()
744{ 746{
745 if ( allowRestart ) { 747 if ( allowRestart ) {
746 748
747 /* 749 /*
748 * Applets and restart is a problem. Some applets delete 750 * Applets and restart is a problem. Some applets delete
749 * their widgets even if ownership gets transfered to the 751 * their widgets even if ownership gets transfered to the
750 * parent (Systray ) but deleting the applet may be unsafe 752 * parent (Systray ) but deleting the applet may be unsafe
751 * as well ( double deletion ). Some have topLevel widgets 753 * as well ( double deletion ). Some have topLevel widgets
752 * and when we dlclose and then delete the widget we will 754 * and when we dlclose and then delete the widget we will
753 * crash and an crash during restart is not nice 755 * crash and an crash during restart is not nice
754 */ 756 */
755#ifdef ALL_APPLETS_ON_THIS_WORLD_ARE_FIXED 757#ifdef ALL_APPLETS_ON_THIS_WORLD_ARE_FIXED
756 /* same as above */ 758 /* same as above */
757 emit aboutToQuit(); 759 emit aboutToQuit();
758 prepareForTermination(TRUE); 760 prepareForTermination(TRUE);
759 doRestart = TRUE; 761 doRestart = TRUE;
760 quit(); 762 quit();
761#else 763#else
762 prepareForTermination( true ); 764 prepareForTermination( true );
763 for ( int fd = 3; fd < 100; fd++ ) 765 for ( int fd = 3; fd < 100; fd++ )
764 close( fd ); 766 close( fd );
765 execl( ( qpeDir() + "/bin/qpe" ).latin1(), "qpe", 0 ); 767 execl( ( qpeDir() + "/bin/qpe" ).latin1(), "qpe", 0 );
766 exit( 1 ); 768 exit( 1 );
767#endif 769#endif
768 } 770 }
769} 771}
770 772
771void ServerApplication::rereadVolumes() 773void ServerApplication::rereadVolumes()
772{ 774{
773 Config cfg( "qpe" ); 775 Config cfg( "qpe" );
774 cfg. setGroup ( "Volume" ); 776 cfg. setGroup ( "Volume" );
775 777
776 m_screentap_sound = cfg. readBoolEntry ( "TouchSound" ); 778 m_screentap_sound = cfg. readBoolEntry ( "TouchSound" );
777 m_keyclick_sound = cfg. readBoolEntry ( "KeySound" ); 779 m_keyclick_sound = cfg. readBoolEntry ( "KeySound" );
778 m_alarm_sound = cfg. readBoolEntry ( "AlarmSound" ); 780 m_alarm_sound = cfg. readBoolEntry ( "AlarmSound" );
779} 781}
780 782
781 783
782void ServerApplication::checkMemory() 784void ServerApplication::checkMemory()
783{ 785{
784#if defined(QPE_HAVE_MEMALERTER) 786#if defined(QPE_HAVE_MEMALERTER)
785 static bool ignoreNormal=TRUE; 787 static bool ignoreNormal=TRUE;
786 static bool existingMessage=FALSE; 788 static bool existingMessage=FALSE;
787 789
788 if(existingMessage) 790 if(existingMessage)
789 return; // don't show a second message while still on first 791 return; // don't show a second message while still on first
790 792
791 existingMessage = TRUE; 793 existingMessage = TRUE;
792 switch ( memstate ) { 794 switch ( memstate ) {
793 case MemUnknown: 795 case MemUnknown:
794 break; 796 break;
795 case MemLow: 797 case MemLow:
796 memstate = MemUnknown; 798 memstate = MemUnknown;
797 if ( !recoverMemory() ) { 799 if ( !recoverMemory() ) {
798 QMessageBox::warning( 0 , tr("Memory Status"), 800 QMessageBox::warning( 0 , tr("Memory Status"),
799 tr("Memory Low\nPlease save data.") ); 801 tr("Memory Low\nPlease save data.") );
800 ignoreNormal = FALSE; 802 ignoreNormal = FALSE;
801 } 803 }
802 break; 804 break;
803 case MemNormal: 805 case MemNormal:
804 memstate = MemUnknown; 806 memstate = MemUnknown;
805 if ( !ignoreNormal ) { 807 if ( !ignoreNormal ) {
806 ignoreNormal = TRUE; 808 ignoreNormal = TRUE;
807 QMessageBox::information ( 0 , tr("Memory Status"), 809 QMessageBox::information ( 0 , tr("Memory Status"),
808 "Memory OK" ); 810 "Memory OK" );
809 } 811 }
810 break; 812 break;
811 case MemVeryLow: 813 case MemVeryLow:
812 memstate = MemUnknown; 814 memstate = MemUnknown;
813 QMessageBox::critical( 0 , tr("Memory Status"), 815 QMessageBox::critical( 0 , tr("Memory Status"),
814 tr("Critical Memory Shortage\n" 816 tr("Critical Memory Shortage\n"
815 "Please end this application\n" 817 "Please end this application\n"
816 "immediately.") ); 818 "immediately.") );
817 recoverMemory(); 819 recoverMemory();
818 } 820 }
819 existingMessage = FALSE; 821 existingMessage = FALSE;
820#endif 822#endif
821} 823}
822 824
823bool ServerApplication::recoverMemory() 825bool ServerApplication::recoverMemory()
824{ 826{
825 return FALSE; 827 return FALSE;
826} 828}
827 829
828void ServerApplication::keyClick(int , bool press, bool ) 830void ServerApplication::keyClick(int , bool press, bool )
829{ 831{
830 if ( press && m_keyclick_sound ) 832 if ( press && m_keyclick_sound )
831 ODevice::inst() -> playKeySound(); 833 ODevice::inst() -> playKeySound();
832 834
833} 835}
834 836
835void ServerApplication::screenClick(bool press) 837void ServerApplication::screenClick(bool press)
836{ 838{
837 if ( press && m_screentap_sound ) 839 if ( press && m_screentap_sound )
838 ODevice::inst() -> playTouchSound(); 840 ODevice::inst() -> playTouchSound();
839} 841}
840 842
841void ServerApplication::soundAlarm() { 843void ServerApplication::soundAlarm() {
842 if ( me ()->m_alarm_sound ) 844 if ( me ()->m_alarm_sound )
843 ODevice::inst()->playAlarmSound(); 845 ODevice::inst()->playAlarmSound();
844} 846}
845 847
846ServerApplication *ServerApplication::me ( ) 848ServerApplication *ServerApplication::me ( )
847{ 849{
848 return static_cast<ServerApplication*>( qApp ); 850 return static_cast<ServerApplication*>( qApp );
849} 851}
850 852
851bool ServerApplication::isStarting() 853bool ServerApplication::isStarting()
852{ 854{
853 return ms_is_starting; 855 return ms_is_starting;
854} 856}
855 857
856int ServerApplication::exec() 858int ServerApplication::exec()
857{ 859{
858 ms_is_starting = true; 860 ms_is_starting = true;
859 odebug << "Serverapp - exec" << oendl; 861 odebug << "Serverapp - exec" << oendl;
860 return QPEApplication::exec(); 862 return QPEApplication::exec();
861} 863}
862 864
863#include "serverapp.moc" 865#include "serverapp.moc"