summaryrefslogtreecommitdiff
path: root/library/qpeapplication.cpp
Unidiff
Diffstat (limited to 'library/qpeapplication.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--library/qpeapplication.cpp4
1 files changed, 2 insertions, 2 deletions
diff --git a/library/qpeapplication.cpp b/library/qpeapplication.cpp
index f0a68cf..70ffec1 100644
--- a/library/qpeapplication.cpp
+++ b/library/qpeapplication.cpp
@@ -281,1029 +281,1029 @@ static void setBacklight(int bright)
281 } FLITE_IN; 281 } FLITE_IN;
282# ifndef FLITE_ON 282# ifndef FLITE_ON
283# ifndef _LINUX_IOCTL_H 283# ifndef _LINUX_IOCTL_H
284# include <linux/ioctl.h> 284# include <linux/ioctl.h>
285# endif 285# endif
286# define FLITE_ON _IOW('f', 7, FLITE_IN) 286# define FLITE_ON _IOW('f', 7, FLITE_IN)
287# endif 287# endif
288 int fd; 288 int fd;
289 if ( QFile::exists("/dev/ts") ) 289 if ( QFile::exists("/dev/ts") )
290 fd = open("/dev/ts", O_WRONLY); 290 fd = open("/dev/ts", O_WRONLY);
291 else 291 else
292 fd = open("/dev/h3600_ts", O_WRONLY); 292 fd = open("/dev/h3600_ts", O_WRONLY);
293 if (fd >= 0 ) { 293 if (fd >= 0 ) {
294 FLITE_IN bl; 294 FLITE_IN bl;
295 bl.mode = 1; 295 bl.mode = 1;
296 bl.pwr = bright ? 1 : 0; 296 bl.pwr = bright ? 1 : 0;
297 bl.brightness = bright; 297 bl.brightness = bright;
298 ioctl(fd, FLITE_ON, &bl); 298 ioctl(fd, FLITE_ON, &bl);
299 close(fd); 299 close(fd);
300 } 300 }
301 } 301 }
302#endif 302#endif
303#endif 303#endif
304 curbl = bright; 304 curbl = bright;
305} 305}
306 306
307void qpe_setBacklight(int bright) { setBacklight(bright); } 307void qpe_setBacklight(int bright) { setBacklight(bright); }
308 308
309static bool dim_on = FALSE; 309static bool dim_on = FALSE;
310static bool lightoff_on = FALSE; 310static bool lightoff_on = FALSE;
311static int disable_suspend = 100; 311static int disable_suspend = 100;
312 312
313static bool powerOnline() 313static bool powerOnline()
314{ 314{
315 return PowerStatusManager::readStatus().acStatus() == PowerStatus::Online; 315 return PowerStatusManager::readStatus().acStatus() == PowerStatus::Online;
316} 316}
317 317
318static bool networkOnline() 318static bool networkOnline()
319{ 319{
320 return Network::networkOnline(); 320 return Network::networkOnline();
321} 321}
322 322
323class QPEScreenSaver : public QWSScreenSaver 323class QPEScreenSaver : public QWSScreenSaver
324{ 324{
325 325
326public: 326public:
327 QPEScreenSaver() 327 QPEScreenSaver()
328 { 328 {
329 } 329 }
330 void restore() 330 void restore()
331 { 331 {
332 setBacklight(-1); 332 setBacklight(-1);
333 } 333 }
334 bool save(int level) 334 bool save(int level)
335 { 335 {
336 switch ( level ) { 336 switch ( level ) {
337 case 0: 337 case 0:
338 if ( disable_suspend > 0 && dim_on ) { 338 if ( disable_suspend > 0 && dim_on ) {
339 if (backlight() > 1) 339 if (backlight() > 1)
340 setBacklight(1); // lowest non-off 340 setBacklight(1); // lowest non-off
341 } 341 }
342 return TRUE; 342 return TRUE;
343 break; 343 break;
344 case 1: 344 case 1:
345 if ( disable_suspend > 1 && lightoff_on ) { 345 if ( disable_suspend > 1 && lightoff_on ) {
346 setBacklight(0); // off 346 setBacklight(0); // off
347 } 347 }
348 return TRUE; 348 return TRUE;
349 break; 349 break;
350 case 2: 350 case 2:
351 if ( disable_suspend > 2 && !powerOnline() && !networkOnline() ) { 351 if ( disable_suspend > 2 && !powerOnline() && !networkOnline() ) {
352 QWSServer::sendKeyEvent( 0xffff, Qt::Key_F34, FALSE, TRUE, FALSE ); 352 QWSServer::sendKeyEvent( 0xffff, Qt::Key_F34, FALSE, TRUE, FALSE );
353 return TRUE; 353 return TRUE;
354 } 354 }
355 break; 355 break;
356 } 356 }
357 return FALSE; 357 return FALSE;
358 } 358 }
359}; 359};
360 360
361static int ssi(int interval, Config &config, const QString &enable, const QString& value, int def) 361static int ssi(int interval, Config &config, const QString &enable, const QString& value, int def)
362{ 362{
363 if ( !enable.isEmpty() && config.readNumEntry(enable,0) == 0 ) 363 if ( !enable.isEmpty() && config.readNumEntry(enable,0) == 0 )
364 return 0; 364 return 0;
365 365
366 if ( interval < 0 ) { 366 if ( interval < 0 ) {
367 // Restore screen blanking and power saving state 367 // Restore screen blanking and power saving state
368 interval = config.readNumEntry( value, def ); 368 interval = config.readNumEntry( value, def );
369 } 369 }
370 return interval; 370 return interval;
371} 371}
372 372
373static void setScreenSaverIntervals(int i1, int i2, int i3) 373static void setScreenSaverIntervals(int i1, int i2, int i3)
374{ 374{
375 Config config( "qpe" ); 375 Config config( "qpe" );
376 config.setGroup( "Screensaver" ); 376 config.setGroup( "Screensaver" );
377 377
378 int v[4]; 378 int v[4];
379 i1 = ssi(i1, config, "Dim","Interval_Dim", 30); 379 i1 = ssi(i1, config, "Dim","Interval_Dim", 30);
380 i2 = ssi(i2, config, "LightOff","Interval_LightOff", 20); 380 i2 = ssi(i2, config, "LightOff","Interval_LightOff", 20);
381 i3 = ssi(i3, config, "","Interval", 60); 381 i3 = ssi(i3, config, "","Interval", 60);
382 382
383 //qDebug("screen saver intervals: %d %d %d", i1, i2, i3); 383 //qDebug("screen saver intervals: %d %d %d", i1, i2, i3);
384 384
385 v[0] = QMAX( 1000*i1, 100); 385 v[0] = QMAX( 1000*i1, 100);
386 v[1] = QMAX( 1000*i2, 100); 386 v[1] = QMAX( 1000*i2, 100);
387 v[2] = QMAX( 1000*i3, 100); 387 v[2] = QMAX( 1000*i3, 100);
388 v[3] = 0; 388 v[3] = 0;
389 dim_on = ( (i1 != 0) ? config.readNumEntry("Dim",1) : FALSE ); 389 dim_on = ( (i1 != 0) ? config.readNumEntry("Dim",1) : FALSE );
390 lightoff_on = ( (i2 != 0 ) ? config.readNumEntry("LightOff",1) : FALSE ); 390 lightoff_on = ( (i2 != 0 ) ? config.readNumEntry("LightOff",1) : FALSE );
391 if ( !i1 && !i2 && !i3 ) 391 if ( !i1 && !i2 && !i3 )
392 QWSServer::setScreenSaverInterval(0); 392 QWSServer::setScreenSaverInterval(0);
393 else 393 else
394 QWSServer::setScreenSaverIntervals(v); 394 QWSServer::setScreenSaverIntervals(v);
395} 395}
396 396
397static void setScreenSaverInterval(int interval) 397static void setScreenSaverInterval(int interval)
398{ 398{
399 setScreenSaverIntervals(-1,-1,interval); 399 setScreenSaverIntervals(-1,-1,interval);
400} 400}
401 401
402 402
403/*! 403/*!
404 \class QPEApplication qpeapplication.h 404 \class QPEApplication qpeapplication.h
405 \brief The QPEApplication class implements various system services 405 \brief The QPEApplication class implements various system services
406 that are available to all Qtopia applications. 406 that are available to all Qtopia applications.
407 407
408 Simply by using QPEApplication instead of QApplication, a plain Qt 408 Simply by using QPEApplication instead of QApplication, a plain Qt
409 application becomes a Qtopia application. It automatically follows 409 application becomes a Qtopia application. It automatically follows
410 style changes, quits and raises, and in the 410 style changes, quits and raises, and in the
411 case of \link docwidget.html document-oriented\endlink applications, 411 case of \link docwidget.html document-oriented\endlink applications,
412 changes the current displayed document in response to the environment. 412 changes the current displayed document in response to the environment.
413*/ 413*/
414 414
415/*! 415/*!
416 \fn void QPEApplication::clientMoused() 416 \fn void QPEApplication::clientMoused()
417 417
418 \internal 418 \internal
419*/ 419*/
420 420
421/*! 421/*!
422 \fn void QPEApplication::timeChanged(); 422 \fn void QPEApplication::timeChanged();
423 423
424 This signal is emitted when the time jumps forward or backwards 424 This signal is emitted when the time jumps forward or backwards
425 by more than the normal passage of time. 425 by more than the normal passage of time.
426*/ 426*/
427 427
428/*! 428/*!
429 \fn void QPEApplication::clockChanged( bool ampm ); 429 \fn void QPEApplication::clockChanged( bool ampm );
430 430
431 This signal is emitted when the user changes the style 431 This signal is emitted when the user changes the style
432 of clock. If \a ampm is TRUE, the user wants a 12-hour 432 of clock. If \a ampm is TRUE, the user wants a 12-hour
433 AM/PM close, otherwise, they want a 24-hour clock. 433 AM/PM close, otherwise, they want a 24-hour clock.
434*/ 434*/
435 435
436/*! 436/*!
437 \fn void QPEApplication::appMessage( const QCString& msg, const QByteArray& data ) 437 \fn void QPEApplication::appMessage( const QCString& msg, const QByteArray& data )
438 438
439 This signal is emitted when a message is received on the 439 This signal is emitted when a message is received on the
440 QPE/Application/<i>appname</i> QCop channel for this application. 440 QPE/Application/<i>appname</i> QCop channel for this application.
441 441
442 The slot to which you connect this signal uses \a msg and \a data 442 The slot to which you connect this signal uses \a msg and \a data
443 in the following way: 443 in the following way:
444 444
445\code 445\code
446 void MyWidget::receive( const QCString& msg, const QByteArray& data ) 446 void MyWidget::receive( const QCString& msg, const QByteArray& data )
447 { 447 {
448 QDataStream stream( data, IO_ReadOnly ); 448 QDataStream stream( data, IO_ReadOnly );
449 if ( msg == "someMessage(int,int,int)" ) { 449 if ( msg == "someMessage(int,int,int)" ) {
450 int a,b,c; 450 int a,b,c;
451 stream >> a >> b >> c; 451 stream >> a >> b >> c;
452 ... 452 ...
453 } else if ( msg == "otherMessage(QString)" ) { 453 } else if ( msg == "otherMessage(QString)" ) {
454 ... 454 ...
455 } 455 }
456 } 456 }
457\endcode 457\endcode
458 458
459 \sa qcop.html 459 \sa qcop.html
460*/ 460*/
461 461
462/*! 462/*!
463 Constructs a QPEApplication just as you would construct 463 Constructs a QPEApplication just as you would construct
464 a QApplication, passing \a argc, \a argv, and \a t. 464 a QApplication, passing \a argc, \a argv, and \a t.
465*/ 465*/
466QPEApplication::QPEApplication( int& argc, char **argv, Type t ) 466QPEApplication::QPEApplication( int& argc, char **argv, Type t )
467 : QApplication( hack(argc), argv, t ) 467 : QApplication( hack(argc), argv, t )
468{ 468{
469 int dw = desktop()->width(); 469 int dw = desktop()->width();
470 if ( dw < 200 ) { 470 if ( dw < 200 ) {
471 setFont( QFont( "helvetica", 8 ) ); 471 setFont( QFont( "helvetica", 8 ) );
472 AppLnk::setSmallIconSize(10); 472 AppLnk::setSmallIconSize(10);
473 AppLnk::setBigIconSize(28); 473 AppLnk::setBigIconSize(28);
474 } 474 }
475 475
476 d = new QPEApplicationData; 476 d = new QPEApplicationData;
477 QMimeSourceFactory::setDefaultFactory(new ResourceMimeFactory); 477 QMimeSourceFactory::setDefaultFactory(new ResourceMimeFactory);
478 478
479 connect(this, SIGNAL(lastWindowClosed()), this, SLOT(hideOrQuit())); 479 connect(this, SIGNAL(lastWindowClosed()), this, SLOT(hideOrQuit()));
480#if defined(Q_WS_QWS) && !defined(QT_NO_COP) 480#if defined(Q_WS_QWS) && !defined(QT_NO_COP)
481 481
482 QString qcopfn("/tmp/qcop-msg-"); 482 QString qcopfn("/tmp/qcop-msg-");
483 qcopfn += QString(argv[0]); // append command name 483 qcopfn += QString(argv[0]); // append command name
484 484
485 QFile f(qcopfn); 485 QFile f(qcopfn);
486 if ( f.open(IO_ReadOnly) ) { 486 if ( f.open(IO_ReadOnly) ) {
487 flock(f.handle(), LOCK_EX); 487 flock(f.handle(), LOCK_EX);
488 } 488 }
489 489
490 sysChannel = new QCopChannel( "QPE/System", this ); 490 sysChannel = new QCopChannel( "QPE/System", this );
491 connect( sysChannel, SIGNAL(received(const QCString &, const QByteArray &)), 491 connect( sysChannel, SIGNAL(received(const QCString &, const QByteArray &)),
492 this, SLOT(systemMessage( const QCString &, const QByteArray &)) ); 492 this, SLOT(systemMessage( const QCString &, const QByteArray &)) );
493 493
494 QCString channel = QCString(argv[0]); 494 QCString channel = QCString(argv[0]);
495 channel.replace(QRegExp(".*/"),""); 495 channel.replace(QRegExp(".*/"),"");
496 d->appName = channel; 496 d->appName = channel;
497 channel = "QPE/Application/" + channel; 497 channel = "QPE/Application/" + channel;
498 pidChannel = new QCopChannel( channel, this); 498 pidChannel = new QCopChannel( channel, this);
499 connect( pidChannel, SIGNAL(received(const QCString &, const QByteArray &)), 499 connect( pidChannel, SIGNAL(received(const QCString &, const QByteArray &)),
500 this, SLOT(pidMessage(const QCString &, const QByteArray &))); 500 this, SLOT(pidMessage(const QCString &, const QByteArray &)));
501 501
502 if ( f.isOpen() ) { 502 if ( f.isOpen() ) {
503 d->keep_running = FALSE; 503 d->keep_running = FALSE;
504 QDataStream ds(&f); 504 QDataStream ds(&f);
505 QCString channel, message; 505 QCString channel, message;
506 QByteArray data; 506 QByteArray data;
507 while(!ds.atEnd()) { 507 while(!ds.atEnd()) {
508 ds >> channel >> message >> data; 508 ds >> channel >> message >> data;
509 d->enqueueQCop(channel,message,data); 509 d->enqueueQCop(channel,message,data);
510 } 510 }
511 511
512 flock(f.handle(), LOCK_UN); 512 flock(f.handle(), LOCK_UN);
513 f.close(); 513 f.close();
514 f.remove(); 514 f.remove();
515 } 515 }
516 516
517 for (int a=0; a<argc; a++) { 517 for (int a=0; a<argc; a++) {
518 if ( qstrcmp(argv[a],"-preload")==0 ) { 518 if ( qstrcmp(argv[a],"-preload")==0 ) {
519 argv[a] = argv[a+1]; 519 argv[a] = argv[a+1];
520 a++; 520 a++;
521 d->preloaded = TRUE; 521 d->preloaded = TRUE;
522 argc-=1; 522 argc-=1;
523 } else if ( qstrcmp(argv[a],"-preload-show")==0 ) { 523 } else if ( qstrcmp(argv[a],"-preload-show")==0 ) {
524 argv[a] = argv[a+1]; 524 argv[a] = argv[a+1];
525 a++; 525 a++;
526 d->preloaded = TRUE; 526 d->preloaded = TRUE;
527 d->forceshow = TRUE; 527 d->forceshow = TRUE;
528 argc-=1; 528 argc-=1;
529 } 529 }
530 } 530 }
531 531
532 /* overide stored arguments */ 532 /* overide stored arguments */
533 setArgs(argc, argv); 533 setArgs(argc, argv);
534 534
535#endif 535#endif
536 536
537 qwsSetDecoration( new QPEDecoration() ); 537 qwsSetDecoration( new QPEDecoration() );
538 538
539#ifndef QT_NO_TRANSLATION 539#ifndef QT_NO_TRANSLATION
540 char *l = getenv( "LANG" ); 540 char *l = getenv( "LANG" );
541 QString lang; 541 QString lang;
542 if ( l ) { 542 if ( l ) {
543 lang = l; 543 lang = l;
544 544
545 /* 545 /*
546 Config config("qpe"); 546 Config config("qpe");
547 config.setGroup( "Appearance" ); 547 config.setGroup( "Appearance" );
548 lang = config.readEntry( "Language", lang ); 548 lang = config.readEntry( "Language", lang );
549 */ 549 */
550 550
551 QTranslator * trans = new QTranslator(this); 551 QTranslator * trans = new QTranslator(this);
552 QString tfn = qpeDir()+"/i18n/"+lang+"/"+d->appName+".qm"; 552 QString tfn = qpeDir()+"/i18n/"+lang+"/"+d->appName+".qm";
553 if ( trans->load( tfn )) 553 if ( trans->load( tfn ))
554 installTranslator( trans ); 554 installTranslator( trans );
555 else 555 else
556 delete trans; 556 delete trans;
557 557
558 trans = new QTranslator(this); 558 trans = new QTranslator(this);
559 tfn = qpeDir()+"/i18n/"+lang+"/libqpe.qm"; 559 tfn = qpeDir()+"/i18n/"+lang+"/libqpe.qm";
560 if ( trans->load( tfn )) 560 if ( trans->load( tfn ))
561 installTranslator( trans ); 561 installTranslator( trans );
562 else 562 else
563 delete trans; 563 delete trans;
564 564
565 //###language/font hack; should look it up somewhere 565 //###language/font hack; should look it up somewhere
566 if ( lang == "ja" || lang == "zh_CN" || lang == "zh_TW" || lang == "ko" ) { 566 if ( lang == "ja" || lang == "zh_CN" || lang == "zh_TW" || lang == "ko" ) {
567 QFont fn = FontManager::unicodeFont( FontManager::Proportional ); 567 QFont fn = FontManager::unicodeFont( FontManager::Proportional );
568 setFont( fn ); 568 setFont( fn );
569 } 569 }
570 } 570 }
571#endif 571#endif
572 572
573 applyStyle(); 573 applyStyle();
574 574
575 if ( type() == GuiServer ) { 575 if ( type() == GuiServer ) {
576 setScreenSaverInterval(-1); 576 setScreenSaverInterval(-1);
577 setVolume(); 577 setVolume();
578 QWSServer::setScreenSaver(new QPEScreenSaver); 578 QWSServer::setScreenSaver(new QPEScreenSaver);
579 } 579 }
580 580
581 installEventFilter( this ); 581 installEventFilter( this );
582 582
583 QPEMenuToolFocusManager::initialize(); 583 QPEMenuToolFocusManager::initialize();
584 584
585#ifdef QT_NO_QWS_CURSOR 585#ifdef QT_NO_QWS_CURSOR
586 // if we have no cursor, probably don't want tooltips 586 // if we have no cursor, probably don't want tooltips
587 QToolTip::setEnabled( FALSE ); 587 QToolTip::setEnabled( FALSE );
588#endif 588#endif
589} 589}
590 590
591static QPtrDict<void>* inputMethodDict=0; 591static QPtrDict<void>* inputMethodDict=0;
592static void createInputMethodDict() 592static void createInputMethodDict()
593{ 593{
594 if ( !inputMethodDict ) 594 if ( !inputMethodDict )
595 inputMethodDict = new QPtrDict<void>; 595 inputMethodDict = new QPtrDict<void>;
596} 596}
597 597
598/*! 598/*!
599 Returns the currently set hint to the system as to whether 599 Returns the currently set hint to the system as to whether
600 \a w has any use for text input methods. 600 \a w has any use for text input methods.
601 601
602 \sa setInputMethodHint() 602 \sa setInputMethodHint()
603*/ 603*/
604QPEApplication::InputMethodHint QPEApplication::inputMethodHint( QWidget* w ) 604QPEApplication::InputMethodHint QPEApplication::inputMethodHint( QWidget* w )
605{ 605{
606 if ( inputMethodDict && w ) 606 if ( inputMethodDict && w )
607 return (InputMethodHint)(int)inputMethodDict->find(w); 607 return (InputMethodHint)(int)inputMethodDict->find(w);
608 return Normal; 608 return Normal;
609} 609}
610 610
611/*! 611/*!
612 \enum QPEApplication::InputMethodHint 612 \enum QPEApplication::InputMethodHint
613 613
614 \value Normal the application sometimes needs text input (the default). 614 \value Normal the application sometimes needs text input (the default).
615 \value AlwaysOff the application never needs text input. 615 \value AlwaysOff the application never needs text input.
616 \value AlwaysOn the application always needs text input. 616 \value AlwaysOn the application always needs text input.
617*/ 617*/
618 618
619/*! 619/*!
620 Hints to the system that \a w has use for text input methods 620 Hints to the system that \a w has use for text input methods
621 as specified by \a mode. 621 as specified by \a mode.
622 622
623 \sa inputMethodHint() 623 \sa inputMethodHint()
624*/ 624*/
625void QPEApplication::setInputMethodHint( QWidget* w, InputMethodHint mode ) 625void QPEApplication::setInputMethodHint( QWidget* w, InputMethodHint mode )
626{ 626{
627 createInputMethodDict(); 627 createInputMethodDict();
628 if ( mode == Normal ) { 628 if ( mode == Normal ) {
629 inputMethodDict->remove(w); 629 inputMethodDict->remove(w);
630 } else { 630 } else {
631 inputMethodDict->insert(w,(void*)mode); 631 inputMethodDict->insert(w,(void*)mode);
632 } 632 }
633} 633}
634 634
635class HackDialog : public QDialog 635class HackDialog : public QDialog
636{ 636{
637public: 637public:
638 void acceptIt() { accept(); } 638 void acceptIt() { accept(); }
639 void rejectIt() { reject(); } 639 void rejectIt() { reject(); }
640}; 640};
641 641
642 642
643void QPEApplication::mapToDefaultAction( QWSKeyEvent *ke, int key ) 643void QPEApplication::mapToDefaultAction( QWSKeyEvent *ke, int key )
644{ 644{
645 // specialised actions for certain widgets. May want to 645 // specialised actions for certain widgets. May want to
646 // add more stuff here. 646 // add more stuff here.
647 if ( activePopupWidget() && activePopupWidget()->inherits( "QListBox" ) 647 if ( activePopupWidget() && activePopupWidget()->inherits( "QListBox" )
648 && activePopupWidget()->parentWidget() 648 && activePopupWidget()->parentWidget()
649 && activePopupWidget()->parentWidget()->inherits( "QComboBox" ) ) 649 && activePopupWidget()->parentWidget()->inherits( "QComboBox" ) )
650 key = Qt::Key_Return; 650 key = Qt::Key_Return;
651 651
652 if ( activePopupWidget() && activePopupWidget()->inherits( "QPopupMenu" ) ) 652 if ( activePopupWidget() && activePopupWidget()->inherits( "QPopupMenu" ) )
653 key = Qt::Key_Return; 653 key = Qt::Key_Return;
654 654
655 ke->simpleData.keycode = key; 655 ke->simpleData.keycode = key;
656} 656}
657 657
658class HackWidget : public QWidget 658class HackWidget : public QWidget
659{ 659{
660public: 660public:
661 bool needsOk() 661 bool needsOk()
662 { return (getWState() & WState_Reserved1 ); } 662 { return (getWState() & WState_Reserved1 ); }
663}; 663};
664 664
665/*! 665/*!
666 \internal 666 \internal
667*/ 667*/
668bool QPEApplication::qwsEventFilter( QWSEvent *e ) 668bool QPEApplication::qwsEventFilter( QWSEvent *e )
669{ 669{
670 if ( !d->notbusysent && e->type == QWSEvent::Focus ) { 670 if ( !d->notbusysent && e->type == QWSEvent::Focus ) {
671 if ( qApp->type() != QApplication::GuiServer ) { 671 if ( qApp->type() != QApplication::GuiServer ) {
672 QCopEnvelope e("QPE/System", "notBusy(QString)" ); 672 QCopEnvelope e("QPE/System", "notBusy(QString)" );
673 e << d->appName; 673 e << d->appName;
674 } 674 }
675 d->notbusysent=TRUE; 675 d->notbusysent=TRUE;
676 } 676 }
677 if ( type() == GuiServer ) { 677 if ( type() == GuiServer ) {
678 switch ( e->type ) { 678 switch ( e->type ) {
679 case QWSEvent::Mouse: 679 case QWSEvent::Mouse:
680 if ( e->asMouse()->simpleData.state && !QWidget::find(e->window()) ) 680 if ( e->asMouse()->simpleData.state && !QWidget::find(e->window()) )
681 emit clientMoused(); 681 emit clientMoused();
682 } 682 }
683 } 683 }
684 if ( e->type == QWSEvent::Key ) { 684 if ( e->type == QWSEvent::Key ) {
685 if ( d->kbgrabber == 1 ) 685 if ( d->kbgrabber == 1 )
686 return TRUE; 686 return TRUE;
687 QWSKeyEvent *ke = (QWSKeyEvent *)e; 687 QWSKeyEvent *ke = (QWSKeyEvent *)e;
688 if ( ke->simpleData.keycode == Qt::Key_F33 ) { 688 if ( ke->simpleData.keycode == Qt::Key_F33 ) {
689 // Use special "OK" key to press "OK" on top level widgets 689 // Use special "OK" key to press "OK" on top level widgets
690 QWidget *active = activeWindow(); 690 QWidget *active = activeWindow();
691 QWidget *popup = 0; 691 QWidget *popup = 0;
692 if ( active && active->isPopup() ) { 692 if ( active && active->isPopup() ) {
693 popup = active; 693 popup = active;
694 active = active->parentWidget(); 694 active = active->parentWidget();
695 } 695 }
696 if ( active && (int)active->winId() == ke->simpleData.window && 696 if ( active && (int)active->winId() == ke->simpleData.window &&
697 !active->testWFlags( WStyle_Customize|WType_Popup|WType_Desktop )) { 697 !active->testWFlags( WStyle_Customize|WType_Popup|WType_Desktop )) {
698 if ( ke->simpleData.is_press ) { 698 if ( ke->simpleData.is_press ) {
699 if ( popup ) 699 if ( popup )
700 popup->close(); 700 popup->close();
701 if ( active->inherits( "QDialog" ) ) { 701 if ( active->inherits( "QDialog" ) ) {
702 HackDialog *d = (HackDialog *)active; 702 HackDialog *d = (HackDialog *)active;
703 d->acceptIt(); 703 d->acceptIt();
704 return TRUE; 704 return TRUE;
705 } else if ( ((HackWidget *)active)->needsOk() ) { 705 } else if ( ((HackWidget *)active)->needsOk() ) {
706 QSignal s; 706 QSignal s;
707 s.connect( active, SLOT( accept() ) ); 707 s.connect( active, SLOT( accept() ) );
708 s.activate(); 708 s.activate();
709 } else { 709 } else {
710 // do the same as with the select key: Map to the default action of the widget: 710 // do the same as with the select key: Map to the default action of the widget:
711 mapToDefaultAction( ke, Qt::Key_Return ); 711 mapToDefaultAction( ke, Qt::Key_Return );
712 } 712 }
713 } 713 }
714 } 714 }
715 } else if ( ke->simpleData.keycode == Qt::Key_F30 ) { 715 } else if ( ke->simpleData.keycode == Qt::Key_F30 ) {
716 // Use special "select" key to do whatever default action a widget has 716 // Use special "select" key to do whatever default action a widget has
717 mapToDefaultAction( ke, Qt::Key_Space ); 717 mapToDefaultAction( ke, Qt::Key_Space );
718 } else if ( ke->simpleData.keycode == Qt::Key_Escape && 718 } else if ( ke->simpleData.keycode == Qt::Key_Escape &&
719 ke->simpleData.is_press ) { 719 ke->simpleData.is_press ) {
720 // Escape key closes app if focus on toplevel 720 // Escape key closes app if focus on toplevel
721 QWidget *active = activeWindow(); 721 QWidget *active = activeWindow();
722 if ( active && active->testWFlags( WType_TopLevel ) && 722 if ( active && active->testWFlags( WType_TopLevel ) &&
723 (int)active->winId() == ke->simpleData.window && 723 (int)active->winId() == ke->simpleData.window &&
724 !active->testWFlags( WStyle_Dialog|WStyle_Customize|WType_Popup|WType_Desktop )) { 724 !active->testWFlags( WStyle_Dialog|WStyle_Customize|WType_Popup|WType_Desktop )) {
725 if ( active->inherits( "QDialog" ) ) { 725 if ( active->inherits( "QDialog" ) ) {
726 HackDialog *d = (HackDialog *)active; 726 HackDialog *d = (HackDialog *)active;
727 d->rejectIt(); 727 d->rejectIt();
728 return TRUE; 728 return TRUE;
729 } else if ( strcmp( argv()[0], "embeddedkonsole") != 0 ) { 729 } else if ( strcmp( argv()[0], "embeddedkonsole") != 0 ) {
730 active->close(); 730 active->close();
731 } 731 }
732 } 732 }
733 } 733 }
734 734
735#if QT_VERSION < 231 735#if QT_VERSION < 231
736 // Filter out the F4/Launcher key from apps 736 // Filter out the F4/Launcher key from apps
737 // ### The launcher key may not always be F4 on all devices 737 // ### The launcher key may not always be F4 on all devices
738 if ( ((QWSKeyEvent *)e)->simpleData.keycode == Qt::Key_F4 ) 738 if ( ((QWSKeyEvent *)e)->simpleData.keycode == Qt::Key_F4 )
739 return TRUE; 739 return TRUE;
740#endif 740#endif
741 } 741 }
742 if ( e->type == QWSEvent::Focus ) { 742 if ( e->type == QWSEvent::Focus ) {
743 QWSFocusEvent *fe = (QWSFocusEvent*)e; 743 QWSFocusEvent *fe = (QWSFocusEvent*)e;
744 QWidget* nfw = QWidget::find(e->window()); 744 QWidget* nfw = QWidget::find(e->window());
745 if ( !fe->simpleData.get_focus ) { 745 if ( !fe->simpleData.get_focus ) {
746 QWidget *active = activeWindow(); 746 QWidget *active = activeWindow();
747 while ( active && active->isPopup() ) { 747 while ( active && active->isPopup() ) {
748 active->close(); 748 active->close();
749 active = activeWindow(); 749 active = activeWindow();
750 } 750 }
751 if ( !nfw && d->kbgrabber == 2 ) { 751 if ( !nfw && d->kbgrabber == 2 ) {
752 ungrabKeyboard(); 752 ungrabKeyboard();
753 d->kbregrab = TRUE; // want kb back when we're active 753 d->kbregrab = TRUE; // want kb back when we're active
754 } 754 }
755 } else { 755 } else {
756 // make sure our modal widget is ALWAYS on top 756 // make sure our modal widget is ALWAYS on top
757 QWidget *topm = activeModalWidget(); 757 QWidget *topm = activeModalWidget();
758 if ( topm ) { 758 if ( topm ) {
759 topm->raise(); 759 topm->raise();
760 } 760 }
761 if ( d->kbregrab ) { 761 if ( d->kbregrab ) {
762 grabKeyboard(); 762 grabKeyboard();
763 d->kbregrab = FALSE; 763 d->kbregrab = FALSE;
764 } 764 }
765 } 765 }
766 if ( fe->simpleData.get_focus && inputMethodDict ) { 766 if ( fe->simpleData.get_focus && inputMethodDict ) {
767 InputMethodHint m = inputMethodHint( QWidget::find(e->window()) ); 767 InputMethodHint m = inputMethodHint( QWidget::find(e->window()) );
768 if ( m == AlwaysOff ) 768 if ( m == AlwaysOff )
769 Global::hideInputMethod(); 769 Global::hideInputMethod();
770 if ( m == AlwaysOn ) 770 if ( m == AlwaysOn )
771 Global::showInputMethod(); 771 Global::showInputMethod();
772 } 772 }
773 } 773 }
774 return QApplication::qwsEventFilter( e ); 774 return QApplication::qwsEventFilter( e );
775} 775}
776 776
777/*! 777/*!
778 Destroys the QPEApplication. 778 Destroys the QPEApplication.
779*/ 779*/
780QPEApplication::~QPEApplication() 780QPEApplication::~QPEApplication()
781{ 781{
782 ungrabKeyboard(); 782 ungrabKeyboard();
783#if defined(Q_WS_QWS) && !defined(QT_NO_COP) 783#if defined(Q_WS_QWS) && !defined(QT_NO_COP)
784 // Need to delete QCopChannels early, since the display will 784 // Need to delete QCopChannels early, since the display will
785 // be gone by the time we get to ~QObject(). 785 // be gone by the time we get to ~QObject().
786 delete sysChannel; 786 delete sysChannel;
787 delete pidChannel; 787 delete pidChannel;
788#endif 788#endif
789 delete d; 789 delete d;
790} 790}
791 791
792/*! 792/*!
793 Returns <tt>$QPEDIR/</tt>. 793 Returns <tt>$OPIEDIR/</tt>.
794*/ 794*/
795QString QPEApplication::qpeDir() 795QString QPEApplication::qpeDir()
796{ 796{
797 const char *base = getenv( "QPEDIR" ); 797 const char *base = getenv( "OPIEDIR" );
798 if ( base ) 798 if ( base )
799 return QString( base ) + "/"; 799 return QString( base ) + "/";
800 800
801 return QString( "../" ); 801 return QString( "../" );
802} 802}
803 803
804/*! 804/*!
805 Returns the user's current Document directory. There is a trailing "/". 805 Returns the user's current Document directory. There is a trailing "/".
806*/ 806*/
807QString QPEApplication::documentDir() 807QString QPEApplication::documentDir()
808{ 808{
809 const char *base = getenv( "HOME" ); 809 const char *base = getenv( "HOME" );
810 if ( base ) 810 if ( base )
811 return QString( base ) + "/Documents/"; 811 return QString( base ) + "/Documents/";
812 812
813 return QString( "../Documents/" ); 813 return QString( "../Documents/" );
814} 814}
815 815
816static int deforient=-1; 816static int deforient=-1;
817 817
818/*! 818/*!
819 \internal 819 \internal
820*/ 820*/
821int QPEApplication::defaultRotation() 821int QPEApplication::defaultRotation()
822{ 822{
823 if ( deforient < 0 ) { 823 if ( deforient < 0 ) {
824 QString d = getenv("QWS_DISPLAY"); 824 QString d = getenv("QWS_DISPLAY");
825 if ( d.contains("Rot90") ) { 825 if ( d.contains("Rot90") ) {
826 deforient = 90; 826 deforient = 90;
827 } else if ( d.contains("Rot180") ) { 827 } else if ( d.contains("Rot180") ) {
828 deforient = 180; 828 deforient = 180;
829 } else if ( d.contains("Rot270") ) { 829 } else if ( d.contains("Rot270") ) {
830 deforient = 270; 830 deforient = 270;
831 } else { 831 } else {
832 deforient=0; 832 deforient=0;
833 } 833 }
834 } 834 }
835 return deforient; 835 return deforient;
836} 836}
837 837
838/*! 838/*!
839 \internal 839 \internal
840*/ 840*/
841void QPEApplication::setDefaultRotation(int r) 841void QPEApplication::setDefaultRotation(int r)
842{ 842{
843 if ( qApp->type() == GuiServer ) { 843 if ( qApp->type() == GuiServer ) {
844 deforient = r; 844 deforient = r;
845 setenv("QWS_DISPLAY", QString("Transformed:Rot%1:0").arg(r).latin1(), 1); 845 setenv("QWS_DISPLAY", QString("Transformed:Rot%1:0").arg(r).latin1(), 1);
846 } else { 846 } else {
847 QCopEnvelope("QPE/System", "setDefaultRotation(int)") << r; 847 QCopEnvelope("QPE/System", "setDefaultRotation(int)") << r;
848 } 848 }
849} 849}
850 850
851/*! 851/*!
852 \internal 852 \internal
853*/ 853*/
854void QPEApplication::applyStyle() 854void QPEApplication::applyStyle()
855{ 855{
856 Config config( "qpe" ); 856 Config config( "qpe" );
857 857
858 config.setGroup( "Appearance" ); 858 config.setGroup( "Appearance" );
859 859
860 // Widget style 860 // Widget style
861 QString style = config.readEntry( "Style", "Light" ); 861 QString style = config.readEntry( "Style", "Light" );
862 internalSetStyle( style ); 862 internalSetStyle( style );
863 863
864 // Colors 864 // Colors
865 QColor bgcolor( config.readEntry( "Background", "#E5E1D5" ) ); 865 QColor bgcolor( config.readEntry( "Background", "#E5E1D5" ) );
866 QColor btncolor( config.readEntry( "Button", "#D6CDBB" ) ); 866 QColor btncolor( config.readEntry( "Button", "#D6CDBB" ) );
867 QPalette pal( btncolor, bgcolor ); 867 QPalette pal( btncolor, bgcolor );
868 QString color = config.readEntry( "Highlight", "#800000" ); 868 QString color = config.readEntry( "Highlight", "#800000" );
869 pal.setColor( QColorGroup::Highlight, QColor(color) ); 869 pal.setColor( QColorGroup::Highlight, QColor(color) );
870 color = config.readEntry( "HighlightedText", "#FFFFFF" ); 870 color = config.readEntry( "HighlightedText", "#FFFFFF" );
871 pal.setColor( QColorGroup::HighlightedText, QColor(color) ); 871 pal.setColor( QColorGroup::HighlightedText, QColor(color) );
872 color = config.readEntry( "Text", "#000000" ); 872 color = config.readEntry( "Text", "#000000" );
873 pal.setColor( QColorGroup::Text, QColor(color) ); 873 pal.setColor( QColorGroup::Text, QColor(color) );
874 color = config.readEntry( "ButtonText", "#000000" ); 874 color = config.readEntry( "ButtonText", "#000000" );
875 pal.setColor( QPalette::Active, QColorGroup::ButtonText, QColor(color) ); 875 pal.setColor( QPalette::Active, QColorGroup::ButtonText, QColor(color) );
876 color = config.readEntry( "Base", "#FFFFFF" ); 876 color = config.readEntry( "Base", "#FFFFFF" );
877 pal.setColor( QColorGroup::Base, QColor(color) ); 877 pal.setColor( QColorGroup::Base, QColor(color) );
878 878
879 pal.setColor( QPalette::Disabled, QColorGroup::Text, 879 pal.setColor( QPalette::Disabled, QColorGroup::Text,
880 pal.color(QPalette::Active, QColorGroup::Background).dark() ); 880 pal.color(QPalette::Active, QColorGroup::Background).dark() );
881 881
882 setPalette( pal, TRUE ); 882 setPalette( pal, TRUE );
883} 883}
884 884
885void QPEApplication::systemMessage( const QCString &msg, const QByteArray &data) 885void QPEApplication::systemMessage( const QCString &msg, const QByteArray &data)
886{ 886{
887#ifdef Q_WS_QWS 887#ifdef Q_WS_QWS
888 QDataStream stream( data, IO_ReadOnly ); 888 QDataStream stream( data, IO_ReadOnly );
889 if ( msg == "applyStyle()" ) { 889 if ( msg == "applyStyle()" ) {
890 applyStyle(); 890 applyStyle();
891 } else if ( msg == "setScreenSaverInterval(int)" ) { 891 } else if ( msg == "setScreenSaverInterval(int)" ) {
892 if ( type() == GuiServer ) { 892 if ( type() == GuiServer ) {
893 int time; 893 int time;
894 stream >> time; 894 stream >> time;
895 setScreenSaverInterval(time); 895 setScreenSaverInterval(time);
896 } 896 }
897 } else if ( msg == "setScreenSaverIntervals(int,int,int)" ) { 897 } else if ( msg == "setScreenSaverIntervals(int,int,int)" ) {
898 if ( type() == GuiServer ) { 898 if ( type() == GuiServer ) {
899 int t1,t2,t3; 899 int t1,t2,t3;
900 stream >> t1 >> t2 >> t3; 900 stream >> t1 >> t2 >> t3;
901 setScreenSaverIntervals(t1,t2,t3); 901 setScreenSaverIntervals(t1,t2,t3);
902 } 902 }
903 } else if ( msg == "setBacklight(int)" ) { 903 } else if ( msg == "setBacklight(int)" ) {
904 if ( type() == GuiServer ) { 904 if ( type() == GuiServer ) {
905 int bright; 905 int bright;
906 stream >> bright; 906 stream >> bright;
907 setBacklight(bright); 907 setBacklight(bright);
908 } 908 }
909 } else if ( msg == "setDefaultRotation(int)" ) { 909 } else if ( msg == "setDefaultRotation(int)" ) {
910 if ( type() == GuiServer ) { 910 if ( type() == GuiServer ) {
911 int r; 911 int r;
912 stream >> r; 912 stream >> r;
913 setDefaultRotation(r); 913 setDefaultRotation(r);
914 } 914 }
915 } else if ( msg == "shutdown()" ) { 915 } else if ( msg == "shutdown()" ) {
916 if ( type() == GuiServer ) 916 if ( type() == GuiServer )
917 shutdown(); 917 shutdown();
918 } else if ( msg == "quit()" ) { 918 } else if ( msg == "quit()" ) {
919 if ( type() != GuiServer ) 919 if ( type() != GuiServer )
920 tryQuit(); 920 tryQuit();
921 } else if ( msg == "forceQuit()" ) { 921 } else if ( msg == "forceQuit()" ) {
922 if ( type() != GuiServer ) 922 if ( type() != GuiServer )
923 quit(); 923 quit();
924 } else if ( msg == "restart()" ) { 924 } else if ( msg == "restart()" ) {
925 if ( type() == GuiServer ) 925 if ( type() == GuiServer )
926 restart(); 926 restart();
927 } else if ( msg == "grabKeyboard(QString)" ) { 927 } else if ( msg == "grabKeyboard(QString)" ) {
928 QString who; 928 QString who;
929 stream >> who; 929 stream >> who;
930 if ( who.isEmpty() ) 930 if ( who.isEmpty() )
931 d->kbgrabber = 0; 931 d->kbgrabber = 0;
932 else if ( who != d->appName ) 932 else if ( who != d->appName )
933 d->kbgrabber = 1; 933 d->kbgrabber = 1;
934 else 934 else
935 d->kbgrabber = 2; 935 d->kbgrabber = 2;
936 } else if ( msg == "language(QString)" ) { 936 } else if ( msg == "language(QString)" ) {
937 if ( type() == GuiServer ) { 937 if ( type() == GuiServer ) {
938 QString l; 938 QString l;
939 stream >> l; 939 stream >> l;
940 QString cl = getenv("LANG"); 940 QString cl = getenv("LANG");
941 if ( cl != l ) { 941 if ( cl != l ) {
942 if ( l.isNull() ) 942 if ( l.isNull() )
943 unsetenv( "LANG" ); 943 unsetenv( "LANG" );
944 else 944 else
945 setenv( "LANG", l.latin1(), 1 ); 945 setenv( "LANG", l.latin1(), 1 );
946 restart(); 946 restart();
947 } 947 }
948 } 948 }
949 } else if ( msg == "timeChange(QString)" ) { 949 } else if ( msg == "timeChange(QString)" ) {
950 QString t; 950 QString t;
951 stream >> t; 951 stream >> t;
952 if ( t.isNull() ) 952 if ( t.isNull() )
953 unsetenv( "TZ" ); 953 unsetenv( "TZ" );
954 else 954 else
955 setenv( "TZ", t.latin1(), 1 ); 955 setenv( "TZ", t.latin1(), 1 );
956 // emit the signal so everyone else knows... 956 // emit the signal so everyone else knows...
957 emit timeChanged(); 957 emit timeChanged();
958 } else if ( msg == "execute(QString)" ) { 958 } else if ( msg == "execute(QString)" ) {
959 if ( type() == GuiServer ) { 959 if ( type() == GuiServer ) {
960 QString t; 960 QString t;
961 stream >> t; 961 stream >> t;
962 Global::execute( t ); 962 Global::execute( t );
963 } 963 }
964 } else if ( msg == "execute(QString,QString)" ) { 964 } else if ( msg == "execute(QString,QString)" ) {
965 if ( type() == GuiServer ) { 965 if ( type() == GuiServer ) {
966 QString t,d; 966 QString t,d;
967 stream >> t >> d; 967 stream >> t >> d;
968 Global::execute( t, d ); 968 Global::execute( t, d );
969 } 969 }
970 } else if ( msg == "addAlarm(QDateTime,QCString,QCString,int)" ) { 970 } else if ( msg == "addAlarm(QDateTime,QCString,QCString,int)" ) {
971 if ( type() == GuiServer ) { 971 if ( type() == GuiServer ) {
972 QDateTime when; 972 QDateTime when;
973 QCString channel, message; 973 QCString channel, message;
974 int data; 974 int data;
975 stream >> when >> channel >> message >> data; 975 stream >> when >> channel >> message >> data;
976 AlarmServer::addAlarm( when, channel, message, data ); 976 AlarmServer::addAlarm( when, channel, message, data );
977 } 977 }
978 } else if ( msg == "deleteAlarm(QDateTime,QCString,QCString,int)" ) { 978 } else if ( msg == "deleteAlarm(QDateTime,QCString,QCString,int)" ) {
979 if ( type() == GuiServer ) { 979 if ( type() == GuiServer ) {
980 QDateTime when; 980 QDateTime when;
981 QCString channel, message; 981 QCString channel, message;
982 int data; 982 int data;
983 stream >> when >> channel >> message >> data; 983 stream >> when >> channel >> message >> data;
984 AlarmServer::deleteAlarm( when, channel, message, data ); 984 AlarmServer::deleteAlarm( when, channel, message, data );
985 } 985 }
986 } else if ( msg == "clockChange(bool)" ) { 986 } else if ( msg == "clockChange(bool)" ) {
987 int tmp; 987 int tmp;
988 stream >> tmp; 988 stream >> tmp;
989 emit clockChanged( tmp ); 989 emit clockChanged( tmp );
990 } else if ( msg == "weekChange(bool)" ) { 990 } else if ( msg == "weekChange(bool)" ) {
991 int tmp; 991 int tmp;
992 stream >> tmp; 992 stream >> tmp;
993 emit weekChanged( tmp ); 993 emit weekChanged( tmp );
994 } else if ( msg == "setDateFormat(DateFormat)" ) { 994 } else if ( msg == "setDateFormat(DateFormat)" ) {
995 DateFormat tmp; 995 DateFormat tmp;
996 stream >> tmp; 996 stream >> tmp;
997 emit dateFormatChanged( tmp ); 997 emit dateFormatChanged( tmp );
998 } else if ( msg == "setVolume(int,int)" ) { 998 } else if ( msg == "setVolume(int,int)" ) {
999 int t,v; 999 int t,v;
1000 stream >> t >> v; 1000 stream >> t >> v;
1001 setVolume(t,v); 1001 setVolume(t,v);
1002 emit volumeChanged( muted ); 1002 emit volumeChanged( muted );
1003 } else if ( msg == "volumeChange(bool)" ) { 1003 } else if ( msg == "volumeChange(bool)" ) {
1004 stream >> muted; 1004 stream >> muted;
1005 setVolume(); 1005 setVolume();
1006 emit volumeChanged( muted ); 1006 emit volumeChanged( muted );
1007 } else if ( msg == "setScreenSaverMode(int)" ) { 1007 } else if ( msg == "setScreenSaverMode(int)" ) {
1008 if ( type() == GuiServer ) { 1008 if ( type() == GuiServer ) {
1009 int old = disable_suspend; 1009 int old = disable_suspend;
1010 stream >> disable_suspend; 1010 stream >> disable_suspend;
1011 //qDebug("setScreenSaverMode(%d)", disable_suspend ); 1011 //qDebug("setScreenSaverMode(%d)", disable_suspend );
1012 if ( disable_suspend > old ) 1012 if ( disable_suspend > old )
1013 setScreenSaverInterval( -1 ); 1013 setScreenSaverInterval( -1 );
1014 } 1014 }
1015 } 1015 }
1016#endif 1016#endif
1017} 1017}
1018 1018
1019/*! 1019/*!
1020 \internal 1020 \internal
1021*/ 1021*/
1022bool QPEApplication::raiseAppropriateWindow() 1022bool QPEApplication::raiseAppropriateWindow()
1023{ 1023{
1024 bool r=FALSE; 1024 bool r=FALSE;
1025 // ########## raise()ing main window should raise and set active 1025 // ########## raise()ing main window should raise and set active
1026 // ########## it and then all childen. This belongs in Qt/Embedded 1026 // ########## it and then all childen. This belongs in Qt/Embedded
1027 QWidget *top = d->qpe_main_widget; 1027 QWidget *top = d->qpe_main_widget;
1028 if ( !top ) top =mainWidget(); 1028 if ( !top ) top =mainWidget();
1029 if ( top && d->keep_running ) { 1029 if ( top && d->keep_running ) {
1030 if ( top->isVisible() ) 1030 if ( top->isVisible() )
1031 r = TRUE; 1031 r = TRUE;
1032#ifdef Q_WS_QWS 1032#ifdef Q_WS_QWS
1033 if ( !d->nomaximize ) 1033 if ( !d->nomaximize )
1034 top->showMaximized(); 1034 top->showMaximized();
1035 else 1035 else
1036#endif 1036#endif
1037 top->show(); 1037 top->show();
1038 top->raise(); 1038 top->raise();
1039 top->setActiveWindow(); 1039 top->setActiveWindow();
1040 } 1040 }
1041 QWidget *topm = activeModalWidget(); 1041 QWidget *topm = activeModalWidget();
1042 if ( topm && topm != top ) { 1042 if ( topm && topm != top ) {
1043 topm->show(); 1043 topm->show();
1044 topm->raise(); 1044 topm->raise();
1045 topm->setActiveWindow(); 1045 topm->setActiveWindow();
1046 r = FALSE; 1046 r = FALSE;
1047 } 1047 }
1048 return r; 1048 return r;
1049} 1049}
1050 1050
1051void QPEApplication::pidMessage( const QCString &msg, const QByteArray & data) 1051void QPEApplication::pidMessage( const QCString &msg, const QByteArray & data)
1052{ 1052{
1053#ifdef Q_WS_QWS 1053#ifdef Q_WS_QWS
1054 1054
1055 if ( msg == "quit()" ) { 1055 if ( msg == "quit()" ) {
1056 tryQuit(); 1056 tryQuit();
1057 } else if ( msg == "quitIfInvisible()" ) { 1057 } else if ( msg == "quitIfInvisible()" ) {
1058 if ( d->qpe_main_widget && !d->qpe_main_widget->isVisible() ) 1058 if ( d->qpe_main_widget && !d->qpe_main_widget->isVisible() )
1059 quit(); 1059 quit();
1060 } else if ( msg == "close()" ) { 1060 } else if ( msg == "close()" ) {
1061 hideOrQuit(); 1061 hideOrQuit();
1062 } else if ( msg == "disablePreload()" ) { 1062 } else if ( msg == "disablePreload()" ) {
1063 d->preloaded = FALSE; 1063 d->preloaded = FALSE;
1064 d->keep_running = TRUE; 1064 d->keep_running = TRUE;
1065 /* so that quit will quit */ 1065 /* so that quit will quit */
1066 } else if ( msg == "enablePreload()" ) { 1066 } else if ( msg == "enablePreload()" ) {
1067 d->preloaded = TRUE; 1067 d->preloaded = TRUE;
1068 d->keep_running = TRUE; 1068 d->keep_running = TRUE;
1069 /* so next quit won't quit */ 1069 /* so next quit won't quit */
1070 } else if ( msg == "raise()" ) { 1070 } else if ( msg == "raise()" ) {
1071 d->keep_running = TRUE; 1071 d->keep_running = TRUE;
1072 d->notbusysent = FALSE; 1072 d->notbusysent = FALSE;
1073 raiseAppropriateWindow(); 1073 raiseAppropriateWindow();
1074 } else if ( msg == "flush()" ) { 1074 } else if ( msg == "flush()" ) {
1075 emit flush(); 1075 emit flush();
1076 // we need to tell the desktop 1076 // we need to tell the desktop
1077 QCopEnvelope e( "QPE/Desktop", "flushDone(QString)" ); 1077 QCopEnvelope e( "QPE/Desktop", "flushDone(QString)" );
1078 e << d->appName; 1078 e << d->appName;
1079 } else if ( msg == "reload()" ) { 1079 } else if ( msg == "reload()" ) {
1080 emit reload(); 1080 emit reload();
1081 } else if ( msg == "setDocument(QString)" ) { 1081 } else if ( msg == "setDocument(QString)" ) {
1082 d->keep_running = TRUE; 1082 d->keep_running = TRUE;
1083 QDataStream stream( data, IO_ReadOnly ); 1083 QDataStream stream( data, IO_ReadOnly );
1084 QString doc; 1084 QString doc;
1085 stream >> doc; 1085 stream >> doc;
1086 QWidget *mw = mainWidget(); 1086 QWidget *mw = mainWidget();
1087 if ( !mw ) 1087 if ( !mw )
1088 mw = d->qpe_main_widget; 1088 mw = d->qpe_main_widget;
1089 if ( mw ) 1089 if ( mw )
1090 Global::setDocument( mw, doc ); 1090 Global::setDocument( mw, doc );
1091 } else if ( msg == "nextView()" ) { 1091 } else if ( msg == "nextView()" ) {
1092 if ( raiseAppropriateWindow() ) 1092 if ( raiseAppropriateWindow() )
1093 emit appMessage( msg, data); 1093 emit appMessage( msg, data);
1094 } else { 1094 } else {
1095 emit appMessage( msg, data); 1095 emit appMessage( msg, data);
1096 } 1096 }
1097#endif 1097#endif
1098} 1098}
1099 1099
1100 1100
1101static bool setWidgetCaptionFromAppName( QWidget* /*mw*/, const QString& /*appName*/, const QString& /*appsPath*/ ) 1101static bool setWidgetCaptionFromAppName( QWidget* /*mw*/, const QString& /*appName*/, const QString& /*appsPath*/ )
1102{ 1102{
1103/* 1103/*
1104 // This works but disable it for now until it is safe to apply 1104 // This works but disable it for now until it is safe to apply
1105 // What is does is scan the .desktop files of all the apps for 1105 // What is does is scan the .desktop files of all the apps for
1106 // the applnk that has the corresponding argv[0] as this program 1106 // the applnk that has the corresponding argv[0] as this program
1107 // then it uses the name stored in the .desktop file as the caption 1107 // then it uses the name stored in the .desktop file as the caption
1108 // for the main widget. This saves duplicating translations for 1108 // for the main widget. This saves duplicating translations for
1109 // the app name in the program and in the .desktop files. 1109 // the app name in the program and in the .desktop files.
1110 1110
1111 AppLnkSet apps( appsPath ); 1111 AppLnkSet apps( appsPath );
1112 1112
1113 QList<AppLnk> appsList = apps.children(); 1113 QList<AppLnk> appsList = apps.children();
1114 for ( QListIterator<AppLnk> it(appsList); it.current(); ++it ) { 1114 for ( QListIterator<AppLnk> it(appsList); it.current(); ++it ) {
1115 if ( (*it)->exec() == appName ) { 1115 if ( (*it)->exec() == appName ) {
1116 mw->setCaption( (*it)->name() ); 1116 mw->setCaption( (*it)->name() );
1117 return TRUE; 1117 return TRUE;
1118 } 1118 }
1119 } 1119 }
1120*/ 1120*/
1121 return FALSE; 1121 return FALSE;
1122} 1122}
1123 1123
1124 1124
1125/*! 1125/*!
1126 Sets \a mw as the mainWidget() and shows it. For small windows, 1126 Sets \a mw as the mainWidget() and shows it. For small windows,
1127 consider passing TRUE for \a nomaximize rather than the default FALSE. 1127 consider passing TRUE for \a nomaximize rather than the default FALSE.
1128 1128
1129 \sa showMainDocumentWidget() 1129 \sa showMainDocumentWidget()
1130*/ 1130*/
1131void QPEApplication::showMainWidget( QWidget* mw, bool nomaximize ) 1131void QPEApplication::showMainWidget( QWidget* mw, bool nomaximize )
1132{ 1132{
1133 setWidgetCaptionFromAppName( mw, d->appName, qpeDir() + "apps" ); 1133 setWidgetCaptionFromAppName( mw, d->appName, qpeDir() + "apps" );
1134 1134
1135 d->nomaximize = nomaximize; 1135 d->nomaximize = nomaximize;
1136 d->qpe_main_widget = mw; 1136 d->qpe_main_widget = mw;
1137 d->sendQCopQ(); 1137 d->sendQCopQ();
1138 if ( d->preloaded ) { 1138 if ( d->preloaded ) {
1139 if(d->forceshow) { 1139 if(d->forceshow) {
1140#ifdef Q_WS_QWS 1140#ifdef Q_WS_QWS
1141 if ( !nomaximize ) 1141 if ( !nomaximize )
1142 mw->showMaximized(); 1142 mw->showMaximized();
1143 else 1143 else
1144#endif 1144#endif
1145 mw->show(); 1145 mw->show();
1146 } 1146 }
1147 } else if ( d->keep_running ) { 1147 } else if ( d->keep_running ) {
1148#ifdef Q_WS_QWS 1148#ifdef Q_WS_QWS
1149 if ( !nomaximize ) 1149 if ( !nomaximize )
1150 mw->showMaximized(); 1150 mw->showMaximized();
1151 else 1151 else
1152#endif 1152#endif
1153 mw->show(); 1153 mw->show();
1154 } 1154 }
1155} 1155}
1156 1156
1157/*! 1157/*!
1158 Sets \a mw as the mainWidget() and shows it. For small windows, 1158 Sets \a mw as the mainWidget() and shows it. For small windows,
1159 consider passing TRUE for \a nomaximize rather than the default FALSE. 1159 consider passing TRUE for \a nomaximize rather than the default FALSE.
1160 1160
1161 This calls designates the application as 1161 This calls designates the application as
1162 a \link docwidget.html document-oriented\endlink application. 1162 a \link docwidget.html document-oriented\endlink application.
1163 1163
1164 The \a mw widget must have a slot: setDocument(const QString&). 1164 The \a mw widget must have a slot: setDocument(const QString&).
1165 1165
1166 \sa showMainWidget() 1166 \sa showMainWidget()
1167*/ 1167*/
1168void QPEApplication::showMainDocumentWidget( QWidget* mw, bool nomaximize ) 1168void QPEApplication::showMainDocumentWidget( QWidget* mw, bool nomaximize )
1169{ 1169{
1170 setWidgetCaptionFromAppName( mw, d->appName, qpeDir() + "apps" ); 1170 setWidgetCaptionFromAppName( mw, d->appName, qpeDir() + "apps" );
1171 1171
1172 if ( mw && argc() == 2 ) 1172 if ( mw && argc() == 2 )
1173 Global::setDocument( mw, QString::fromUtf8(argv()[1]) ); 1173 Global::setDocument( mw, QString::fromUtf8(argv()[1]) );
1174 d->nomaximize = nomaximize; 1174 d->nomaximize = nomaximize;
1175 d->qpe_main_widget = mw; 1175 d->qpe_main_widget = mw;
1176 d->sendQCopQ(); 1176 d->sendQCopQ();
1177 if ( d->preloaded ) { 1177 if ( d->preloaded ) {
1178 if(d->forceshow) { 1178 if(d->forceshow) {
1179#ifdef Q_WS_QWS 1179#ifdef Q_WS_QWS
1180 if ( !nomaximize ) 1180 if ( !nomaximize )
1181 mw->showMaximized(); 1181 mw->showMaximized();
1182 else 1182 else
1183#endif 1183#endif
1184 mw->show(); 1184 mw->show();
1185 } 1185 }
1186 } else if ( d->keep_running ) { 1186 } else if ( d->keep_running ) {
1187#ifdef Q_WS_QWS 1187#ifdef Q_WS_QWS
1188 if ( !nomaximize ) 1188 if ( !nomaximize )
1189 mw->showMaximized(); 1189 mw->showMaximized();
1190 else 1190 else
1191#endif 1191#endif
1192 mw->show(); 1192 mw->show();
1193 } 1193 }
1194} 1194}
1195 1195
1196 1196
1197/*! 1197/*!
1198 Sets that the application should continue running after processing 1198 Sets that the application should continue running after processing
1199 qcop messages. Normally if an application is started via a qcop message, 1199 qcop messages. Normally if an application is started via a qcop message,
1200 the application will process the qcop message and then quit. If while 1200 the application will process the qcop message and then quit. If while
1201 processing the qcop message it calls this function, then the application 1201 processing the qcop message it calls this function, then the application
1202 will show and start proper once it has finished processing qcop messages. 1202 will show and start proper once it has finished processing qcop messages.
1203 1203
1204 \sa keepRunning() 1204 \sa keepRunning()
1205*/ 1205*/
1206void QPEApplication::setKeepRunning() 1206void QPEApplication::setKeepRunning()
1207{ 1207{
1208 if ( qApp && qApp->inherits( "QPEApplication" ) ) { 1208 if ( qApp && qApp->inherits( "QPEApplication" ) ) {
1209 QPEApplication *qpeApp = (QPEApplication*)qApp; 1209 QPEApplication *qpeApp = (QPEApplication*)qApp;
1210 qpeApp->d->keep_running = TRUE; 1210 qpeApp->d->keep_running = TRUE;
1211 } 1211 }
1212} 1212}
1213 1213
1214/*! 1214/*!
1215 Returns whether the application will quit after processing the current 1215 Returns whether the application will quit after processing the current
1216 list of qcop messages. 1216 list of qcop messages.
1217 1217
1218 \sa setKeepRunning() 1218 \sa setKeepRunning()
1219*/ 1219*/
1220bool QPEApplication::keepRunning() const 1220bool QPEApplication::keepRunning() const
1221{ 1221{
1222 return d->keep_running; 1222 return d->keep_running;
1223} 1223}
1224 1224
1225/*! 1225/*!
1226 \internal 1226 \internal
1227*/ 1227*/
1228void QPEApplication::internalSetStyle( const QString &style ) 1228void QPEApplication::internalSetStyle( const QString &style )
1229{ 1229{
1230#if QT_VERSION >= 300 1230#if QT_VERSION >= 300
1231 if ( style == "QPE" ) { 1231 if ( style == "QPE" ) {
1232 setStyle( new QPEStyle ); 1232 setStyle( new QPEStyle );
1233 } else { 1233 } else {
1234 QStyle *s = QStyleFactory::create(style); 1234 QStyle *s = QStyleFactory::create(style);
1235 if ( s ) setStyle(s); 1235 if ( s ) setStyle(s);
1236 } 1236 }
1237#else 1237#else
1238 if ( style == "Windows" ) { 1238 if ( style == "Windows" ) {
1239 setStyle( new QWindowsStyle ); 1239 setStyle( new QWindowsStyle );
1240 } else if ( style == "QPE" ) { 1240 } else if ( style == "QPE" ) {
1241 setStyle( new QPEStyle ); 1241 setStyle( new QPEStyle );
1242 } else if ( style == "Light" ) { 1242 } else if ( style == "Light" ) {
1243 setStyle( new LightStyle ); 1243 setStyle( new LightStyle );
1244 } 1244 }
1245#ifndef QT_NO_STYLE_PLATINUM 1245#ifndef QT_NO_STYLE_PLATINUM
1246 else if ( style == "Platinum" ) { 1246 else if ( style == "Platinum" ) {
1247 setStyle( new QPlatinumStyle ); 1247 setStyle( new QPlatinumStyle );
1248 } 1248 }
1249#endif 1249#endif
1250#ifndef QT_NO_STYLE_MOTIF 1250#ifndef QT_NO_STYLE_MOTIF
1251 else if ( style == "Motif" ) { 1251 else if ( style == "Motif" ) {
1252 setStyle( new QMotifStyle ); 1252 setStyle( new QMotifStyle );
1253 } 1253 }
1254#endif 1254#endif
1255#ifndef QT_NO_STYLE_MOTIFPLUS 1255#ifndef QT_NO_STYLE_MOTIFPLUS
1256 else if ( style == "MotifPlus" ) { 1256 else if ( style == "MotifPlus" ) {
1257 setStyle( new QMotifPlusStyle ); 1257 setStyle( new QMotifPlusStyle );
1258 } 1258 }
1259#endif 1259#endif
1260#endif 1260#endif
1261} 1261}
1262 1262
1263/*! 1263/*!
1264 \internal 1264 \internal
1265*/ 1265*/
1266void QPEApplication::prepareForTermination(bool willrestart) 1266void QPEApplication::prepareForTermination(bool willrestart)
1267{ 1267{
1268 if ( willrestart ) { 1268 if ( willrestart ) {
1269 // Draw a big wait icon, the image can be altered in later revisions 1269 // Draw a big wait icon, the image can be altered in later revisions
1270 //QWidget *d = QApplication::desktop(); 1270 //QWidget *d = QApplication::desktop();
1271 QImage img = Resource::loadImage( "wait" ); 1271 QImage img = Resource::loadImage( "wait" );
1272 QPixmap pix; 1272 QPixmap pix;
1273 pix.convertFromImage(img.smoothScale(3*img.width(), 3*img.height())); 1273 pix.convertFromImage(img.smoothScale(3*img.width(), 3*img.height()));
1274 QLabel *lblWait = new QLabel(0, "wait hack!", QWidget::WStyle_Customize | 1274 QLabel *lblWait = new QLabel(0, "wait hack!", QWidget::WStyle_Customize |
1275 QWidget::WStyle_NoBorder | QWidget::WStyle_Tool ); 1275 QWidget::WStyle_NoBorder | QWidget::WStyle_Tool );
1276 lblWait->setPixmap( pix ); 1276 lblWait->setPixmap( pix );
1277 lblWait->setAlignment( QWidget::AlignCenter ); 1277 lblWait->setAlignment( QWidget::AlignCenter );
1278 lblWait->show(); 1278 lblWait->show();
1279 lblWait->showMaximized(); 1279 lblWait->showMaximized();
1280 } 1280 }
1281#ifndef SINGLE_APP 1281#ifndef SINGLE_APP
1282 { QCopEnvelope envelope("QPE/System", "forceQuit()"); } 1282 { QCopEnvelope envelope("QPE/System", "forceQuit()"); }
1283 processEvents(); // ensure the message goes out. 1283 processEvents(); // ensure the message goes out.
1284 sleep(1); // You have 1 second to comply. 1284 sleep(1); // You have 1 second to comply.
1285#endif 1285#endif
1286} 1286}
1287 1287
1288/*! 1288/*!
1289 \internal 1289 \internal
1290*/ 1290*/
1291void QPEApplication::shutdown() 1291void QPEApplication::shutdown()
1292{ 1292{
1293 // Implement in server's QPEApplication subclass 1293 // Implement in server's QPEApplication subclass
1294} 1294}
1295 1295
1296/*! 1296/*!
1297 \internal 1297 \internal
1298*/ 1298*/
1299void QPEApplication::restart() 1299void QPEApplication::restart()
1300{ 1300{
1301 // Implement in server's QPEApplication subclass 1301 // Implement in server's QPEApplication subclass
1302} 1302}
1303 1303
1304static QPtrDict<void>* stylusDict=0; 1304static QPtrDict<void>* stylusDict=0;
1305static void createDict() 1305static void createDict()
1306{ 1306{
1307 if ( !stylusDict ) 1307 if ( !stylusDict )
1308 stylusDict = new QPtrDict<void>; 1308 stylusDict = new QPtrDict<void>;
1309} 1309}