summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/launcher/desktop.cpp2
-rw-r--r--core/launcher/main.cpp132
2 files changed, 7 insertions, 127 deletions
diff --git a/core/launcher/desktop.cpp b/core/launcher/desktop.cpp
index bf19280..dee5535 100644
--- a/core/launcher/desktop.cpp
+++ b/core/launcher/desktop.cpp
@@ -432,381 +432,383 @@ void Desktop::checkMemory()
432 memstate = Unknown; 432 memstate = Unknown;
433 QMessageBox::critical( 0 , "Memory Status", 433 QMessageBox::critical( 0 , "Memory Status",
434 "The memory is very low. \n" 434 "The memory is very low. \n"
435 "Please end this application \n" 435 "Please end this application \n"
436 "immediately." ); 436 "immediately." );
437 recoverMemory(); 437 recoverMemory();
438 } 438 }
439 existingMessage = FALSE; 439 existingMessage = FALSE;
440#endif 440#endif
441} 441}
442 442
443static bool isVisibleWindow(int wid) 443static bool isVisibleWindow(int wid)
444{ 444{
445 const QList<QWSWindow> &list = qwsServer->clientWindows(); 445 const QList<QWSWindow> &list = qwsServer->clientWindows();
446 QWSWindow* w; 446 QWSWindow* w;
447 for (QListIterator<QWSWindow> it(list); (w=it.current()); ++it) { 447 for (QListIterator<QWSWindow> it(list); (w=it.current()); ++it) {
448 if ( w->winId() == wid ) 448 if ( w->winId() == wid )
449 return !w->isFullyObscured(); 449 return !w->isFullyObscured();
450 } 450 }
451 return FALSE; 451 return FALSE;
452} 452}
453 453
454static bool hasVisibleWindow(const QString& clientname) 454static bool hasVisibleWindow(const QString& clientname)
455{ 455{
456 const QList<QWSWindow> &list = qwsServer->clientWindows(); 456 const QList<QWSWindow> &list = qwsServer->clientWindows();
457 QWSWindow* w; 457 QWSWindow* w;
458 for (QListIterator<QWSWindow> it(list); (w=it.current()); ++it) { 458 for (QListIterator<QWSWindow> it(list); (w=it.current()); ++it) {
459 if ( w->client()->identity() == clientname && !w->isFullyObscured() ) 459 if ( w->client()->identity() == clientname && !w->isFullyObscured() )
460 return TRUE; 460 return TRUE;
461 } 461 }
462 return FALSE; 462 return FALSE;
463} 463}
464 464
465void Desktop::raiseLauncher() 465void Desktop::raiseLauncher()
466{ 466{
467 Config cfg("qpe"); //F12 'Home' 467 Config cfg("qpe"); //F12 'Home'
468 cfg.setGroup("AppsKey"); 468 cfg.setGroup("AppsKey");
469 QString tempItem; 469 QString tempItem;
470 tempItem = cfg.readEntry("Middle","Home"); 470 tempItem = cfg.readEntry("Middle","Home");
471 if(tempItem == "Home" || tempItem.isEmpty()) { 471 if(tempItem == "Home" || tempItem.isEmpty()) {
472 if ( isVisibleWindow(launcher->winId()) ) 472 if ( isVisibleWindow(launcher->winId()) )
473 launcher->nextView(); 473 launcher->nextView();
474 else 474 else
475 launcher->raise(); 475 launcher->raise();
476 } else { 476 } else {
477 QCopEnvelope e("QPE/System","execute(QString)"); 477 QCopEnvelope e("QPE/System","execute(QString)");
478 e << tempItem; 478 e << tempItem;
479 } 479 }
480} 480}
481 481
482void Desktop::executeOrModify(const QString& appLnkFile) 482void Desktop::executeOrModify(const QString& appLnkFile)
483{ 483{
484 AppLnk lnk(MimeType::appsFolderName() + "/" + appLnkFile); 484 AppLnk lnk(MimeType::appsFolderName() + "/" + appLnkFile);
485 if ( lnk.isValid() ) { 485 if ( lnk.isValid() ) {
486 QCString app = lnk.exec().utf8(); 486 QCString app = lnk.exec().utf8();
487 Global::terminateBuiltin("calibrate"); 487 Global::terminateBuiltin("calibrate");
488 if ( QCopChannel::isRegistered("QPE/Application/" + app) ) { 488 if ( QCopChannel::isRegistered("QPE/Application/" + app) ) {
489 MRUList::addTask(&lnk); 489 MRUList::addTask(&lnk);
490 if ( hasVisibleWindow(app) ) 490 if ( hasVisibleWindow(app) )
491 QCopChannel::send("QPE/Application/" + app, "nextView()"); 491 QCopChannel::send("QPE/Application/" + app, "nextView()");
492 else 492 else
493 QCopChannel::send("QPE/Application/" + app, "raise()"); 493 QCopChannel::send("QPE/Application/" + app, "raise()");
494 } else { 494 } else {
495 lnk.execute(); 495 lnk.execute();
496 } 496 }
497 } 497 }
498} 498}
499 499
500void Desktop::raiseDatebook() 500void Desktop::raiseDatebook()
501{ 501{
502 Config cfg( "qpe" ); //F9 'Activity' 502 Config cfg( "qpe" ); //F9 'Activity'
503 cfg.setGroup( "AppsKey" ); 503 cfg.setGroup( "AppsKey" );
504 QString tempItem; 504 QString tempItem;
505 tempItem = cfg.readEntry( "LeftEnd" , "Calendar" ); 505 tempItem = cfg.readEntry( "LeftEnd" , "Calendar" );
506 if ( tempItem == "Calendar" || tempItem.isEmpty() ) { 506 if ( tempItem == "Calendar" || tempItem.isEmpty() ) {
507 tempItem = "datebook"; 507 tempItem = "datebook";
508 } 508 }
509 QCopEnvelope e( "QPE/System", "execute(QString)" ); 509 QCopEnvelope e( "QPE/System", "execute(QString)" );
510 e << tempItem; 510 e << tempItem;
511} 511}
512 512
513void Desktop::raiseContacts() 513void Desktop::raiseContacts()
514{ 514{
515 Config cfg( "qpe" ); //F10, 'Contacts' 515 Config cfg( "qpe" ); //F10, 'Contacts'
516 cfg.setGroup( "AppsKey" ); 516 cfg.setGroup( "AppsKey" );
517 QString tempItem; 517 QString tempItem;
518 tempItem = cfg.readEntry( "Left2nd", "Address Book" ); 518 tempItem = cfg.readEntry( "Left2nd", "Address Book" );
519 if ( tempItem == "Address Book" || tempItem.isEmpty() ) { 519 if ( tempItem == "Address Book" || tempItem.isEmpty() ) {
520 tempItem = "addressbook"; 520 tempItem = "addressbook";
521 } 521 }
522 QCopEnvelope e("QPE/System","execute(QString)"); 522 QCopEnvelope e("QPE/System","execute(QString)");
523 e << tempItem; 523 e << tempItem;
524} 524}
525 525
526void Desktop::raiseMenu() 526void Desktop::raiseMenu()
527{ 527{
528 Config cfg( "qpe" ); //F11, 'Menu 528 Config cfg( "qpe" ); //F11, 'Menu
529 cfg.setGroup( "AppsKey" ); 529 cfg.setGroup( "AppsKey" );
530 QString tempItem; 530 QString tempItem;
531 tempItem = cfg.readEntry( "Right2nd" , "Popup Menu" ); 531 tempItem = cfg.readEntry( "Right2nd" , "Popup Menu" );
532 if ( tempItem == "Popup Menu" || tempItem.isEmpty() ) { 532 if ( tempItem == "Popup Menu" || tempItem.isEmpty() ) {
533 Global::terminateBuiltin( "calibrate" ); 533 Global::terminateBuiltin( "calibrate" );
534 tb->startMenu()->launch(); 534 tb->startMenu()->launch();
535 } else { 535 } else {
536 QCopEnvelope e("QPE/System","execute(QString)"); 536 QCopEnvelope e("QPE/System","execute(QString)");
537 e << tempItem; 537 e << tempItem;
538 } 538 }
539} 539}
540 540
541void Desktop::raiseEmail() 541void Desktop::raiseEmail()
542{ 542{
543 Config cfg( "qpe" ); //F13, 'Mail' // only in zaurus, on ipaq mail key is F11 543 Config cfg( "qpe" ); //F13, 'Mail' // only in zaurus, on ipaq mail key is F11
544 cfg.setGroup( "AppsKey" ); 544 cfg.setGroup( "AppsKey" );
545 QString tempItem; 545 QString tempItem;
546 tempItem = cfg.readEntry( "RightEnd", "Mail" ); 546 tempItem = cfg.readEntry( "RightEnd", "Mail" );
547 if ( tempItem == "Mail" || tempItem == "qtmail" || tempItem.isEmpty() ) { 547 if ( tempItem == "Mail" || tempItem == "qtmail" || tempItem.isEmpty() ) {
548 tempItem = "mail"; 548 tempItem = "mail";
549 } 549 }
550 QCopEnvelope e("QPE/System","execute(QString)"); 550 QCopEnvelope e("QPE/System","execute(QString)");
551 e << tempItem; 551 e << tempItem;
552} 552}
553 553
554// autoStarts apps on resume and start 554// autoStarts apps on resume and start
555void Desktop::execAutoStart() 555void Desktop::execAutoStart()
556{ 556{
557 QString appName; 557 QString appName;
558 int delay; 558 int delay;
559 QDateTime now = QDateTime::currentDateTime(); 559 QDateTime now = QDateTime::currentDateTime();
560 Config cfg( "autostart" ); 560 Config cfg( "autostart" );
561 cfg.setGroup( "AutoStart" ); 561 cfg.setGroup( "AutoStart" );
562 appName = cfg.readEntry( "Apps", "" ); 562 appName = cfg.readEntry( "Apps", "" );
563 delay = ( cfg.readEntry( "Delay", "0" ) ).toInt(); 563 delay = ( cfg.readEntry( "Delay", "0" ) ).toInt();
564 // If the time between suspend and resume was longer then the 564 // If the time between suspend and resume was longer then the
565 // value saved as delay, start the app 565 // value saved as delay, start the app
566 if ( suspendTime.secsTo( now ) >= ( delay * 60 ) && !appName.isEmpty() ) { 566 if ( suspendTime.secsTo( now ) >= ( delay * 60 ) && !appName.isEmpty() ) {
567 QCopEnvelope e( "QPE/System", "execute(QString)" ); 567 QCopEnvelope e( "QPE/System", "execute(QString)" );
568 e << QString( appName ); 568 e << QString( appName );
569 } 569 }
570} 570}
571 571
572#if defined(QPE_HAVE_TOGGLELIGHT) 572#if defined(QPE_HAVE_TOGGLELIGHT)
573#include <qpe/config.h> 573#include <qpe/config.h>
574 574
575#include <sys/ioctl.h> 575#include <sys/ioctl.h>
576#include <sys/types.h> 576#include <sys/types.h>
577#include <fcntl.h> 577#include <fcntl.h>
578#include <unistd.h> 578#include <unistd.h>
579#include <errno.h> 579#include <errno.h>
580#include <linux/ioctl.h> 580#include <linux/ioctl.h>
581#include <time.h> 581#include <time.h>
582#endif 582#endif
583 583
584static bool blanked=FALSE; 584static bool blanked=FALSE;
585 585
586static void blankScreen() 586static void blankScreen()
587{ 587{
588 if ( !qt_screen ) return; 588 if ( !qt_screen ) return;
589 /* Should use a big black window instead. 589 /* Should use a big black window instead.
590 QGfx* g = qt_screen->screenGfx(); 590 QGfx* g = qt_screen->screenGfx();
591 g->fillRect(0,0,qt_screen->width(),qt_screen->height()); 591 g->fillRect(0,0,qt_screen->width(),qt_screen->height());
592 delete g; 592 delete g;
593 */ 593 */
594 blanked = TRUE; 594 blanked = TRUE;
595} 595}
596 596
597static void darkScreen() 597static void darkScreen()
598{ 598{
599 extern void qpe_setBacklight(int); 599 extern void qpe_setBacklight(int);
600 qpe_setBacklight(0); // force off 600 qpe_setBacklight(0); // force off
601} 601}
602 602
603 603
604void Desktop::togglePower() 604void Desktop::togglePower()
605{ 605{
606 extern void qpe_setBacklight ( int ); // We need to toggle the LCD fast - no time to send a QCop 606 extern void qpe_setBacklight ( int ); // We need to toggle the LCD fast - no time to send a QCop
607 607
608 static bool excllock = false; 608 static bool excllock = false;
609 609
610 if ( excllock ) 610 if ( excllock )
611 return; 611 return;
612 612
613 excllock = true; 613 excllock = true;
614 614
615 bool wasloggedin = loggedin; 615 bool wasloggedin = loggedin;
616 loggedin=0; 616 loggedin=0;
617 suspendTime = QDateTime::currentDateTime(); 617 suspendTime = QDateTime::currentDateTime();
618 618
619// qpe_setBacklight ( 0 ); // force LCD off (sandman: why ????) 619// qpe_setBacklight ( 0 ); // force LCD off (sandman: why ????)
620 620
621 if ( wasloggedin ) 621 if ( wasloggedin )
622 blankScreen(); 622 blankScreen();
623 623
624 qDebug ( "OPIE suspending\n" );
625
624 ODevice::inst ( )-> suspend ( ); 626 ODevice::inst ( )-> suspend ( );
625 627
626 QWSServer::screenSaverActivate ( false ); 628 QWSServer::screenSaverActivate ( false );
627 629
628 qpe_setBacklight ( -3 ); // force LCD on 630 qpe_setBacklight ( -3 ); // force LCD on
629 631
630 { 632 {
631 QCopEnvelope("QPE/Card", "mtabChanged()" ); // might have changed while asleep 633 QCopEnvelope("QPE/Card", "mtabChanged()" ); // might have changed while asleep
632 } 634 }
633 635
634 if ( wasloggedin ) 636 if ( wasloggedin )
635 login(TRUE); 637 login(TRUE);
636 638
637 execAutoStart(); 639 execAutoStart();
638 //qcopBridge->closeOpenConnections(); 640 //qcopBridge->closeOpenConnections();
639 641
640 excllock = false; 642 excllock = false;
641} 643}
642 644
643void Desktop::toggleLight() 645void Desktop::toggleLight()
644{ 646{
645 QCopEnvelope e("QPE/System", "setBacklight(int)"); 647 QCopEnvelope e("QPE/System", "setBacklight(int)");
646 e << -2; // toggle 648 e << -2; // toggle
647} 649}
648 650
649void Desktop::toggleSymbolInput() 651void Desktop::toggleSymbolInput()
650{ 652{
651 tb->toggleSymbolInput(); 653 tb->toggleSymbolInput();
652} 654}
653 655
654void Desktop::toggleNumLockState() 656void Desktop::toggleNumLockState()
655{ 657{
656 tb->toggleNumLockState(); 658 tb->toggleNumLockState();
657} 659}
658 660
659void Desktop::toggleCapsLockState() 661void Desktop::toggleCapsLockState()
660{ 662{
661 tb->toggleCapsLockState(); 663 tb->toggleCapsLockState();
662} 664}
663 665
664void Desktop::styleChange( QStyle &s ) 666void Desktop::styleChange( QStyle &s )
665{ 667{
666 QWidget::styleChange( s ); 668 QWidget::styleChange( s );
667 int displayw = qApp->desktop()->width(); 669 int displayw = qApp->desktop()->width();
668 int displayh = qApp->desktop()->height(); 670 int displayh = qApp->desktop()->height();
669 671
670 QSize sz = tb->sizeHint(); 672 QSize sz = tb->sizeHint();
671 673
672 tb->setGeometry( 0, displayh-sz.height(), displayw, sz.height() ); 674 tb->setGeometry( 0, displayh-sz.height(), displayw, sz.height() );
673} 675}
674 676
675void DesktopApplication::shutdown() 677void DesktopApplication::shutdown()
676{ 678{
677 if ( type() != GuiServer ) 679 if ( type() != GuiServer )
678 return; 680 return;
679 ShutdownImpl *sd = new ShutdownImpl( 0, 0, WDestructiveClose ); 681 ShutdownImpl *sd = new ShutdownImpl( 0, 0, WDestructiveClose );
680 connect( sd, SIGNAL(shutdown(ShutdownImpl::Type)), 682 connect( sd, SIGNAL(shutdown(ShutdownImpl::Type)),
681 this, SLOT(shutdown(ShutdownImpl::Type)) ); 683 this, SLOT(shutdown(ShutdownImpl::Type)) );
682 sd->showMaximized(); 684 sd->showMaximized();
683} 685}
684 686
685void DesktopApplication::shutdown( ShutdownImpl::Type t ) 687void DesktopApplication::shutdown( ShutdownImpl::Type t )
686{ 688{
687 switch ( t ) { 689 switch ( t ) {
688 case ShutdownImpl::ShutdownSystem: 690 case ShutdownImpl::ShutdownSystem:
689 execlp("shutdown", "shutdown", "-h", "now", (void*)0); 691 execlp("shutdown", "shutdown", "-h", "now", (void*)0);
690 break; 692 break;
691 case ShutdownImpl::RebootSystem: 693 case ShutdownImpl::RebootSystem:
692 execlp("shutdown", "shutdown", "-r", "now", (void*)0); 694 execlp("shutdown", "shutdown", "-r", "now", (void*)0);
693 break; 695 break;
694 case ShutdownImpl::RestartDesktop: 696 case ShutdownImpl::RestartDesktop:
695 restart(); 697 restart();
696 break; 698 break;
697 case ShutdownImpl::TerminateDesktop: 699 case ShutdownImpl::TerminateDesktop:
698 prepareForTermination(FALSE); 700 prepareForTermination(FALSE);
699 701
700 // This is a workaround for a Qt bug 702 // This is a workaround for a Qt bug
701 // clipboard applet has to stop its poll timer, or Qt/E 703 // clipboard applet has to stop its poll timer, or Qt/E
702 // will hang on quit() right before it emits aboutToQuit() 704 // will hang on quit() right before it emits aboutToQuit()
703 emit aboutToQuit ( ); 705 emit aboutToQuit ( );
704 706
705 quit(); 707 quit();
706 break; 708 break;
707 } 709 }
708} 710}
709 711
710void DesktopApplication::restart() 712void DesktopApplication::restart()
711{ 713{
712 prepareForTermination(TRUE); 714 prepareForTermination(TRUE);
713 715
714#ifdef Q_WS_QWS 716#ifdef Q_WS_QWS
715 for ( int fd = 3; fd < 100; fd++ ) 717 for ( int fd = 3; fd < 100; fd++ )
716 close( fd ); 718 close( fd );
717#if defined(QT_DEMO_SINGLE_FLOPPY) 719#if defined(QT_DEMO_SINGLE_FLOPPY)
718 execl( "/sbin/init", "qpe", 0 ); 720 execl( "/sbin/init", "qpe", 0 );
719#elif defined(QT_QWS_CASSIOPEIA) 721#elif defined(QT_QWS_CASSIOPEIA)
720 execl( "/bin/sh", "sh", 0 ); 722 execl( "/bin/sh", "sh", 0 );
721#else 723#else
722 execl( (qpeDir()+"/bin/qpe").latin1(), "qpe", 0 ); 724 execl( (qpeDir()+"/bin/qpe").latin1(), "qpe", 0 );
723#endif 725#endif
724 exit(1); 726 exit(1);
725#endif 727#endif
726} 728}
727 729
728void Desktop::startTransferServer() 730void Desktop::startTransferServer()
729{ 731{
730 // start qcop bridge server 732 // start qcop bridge server
731 qcopBridge = new QCopBridge( 4243 ); 733 qcopBridge = new QCopBridge( 4243 );
732 if ( !qcopBridge->ok() ) { 734 if ( !qcopBridge->ok() ) {
733 delete qcopBridge; 735 delete qcopBridge;
734 qcopBridge = 0; 736 qcopBridge = 0;
735 } 737 }
736 // start transfer server 738 // start transfer server
737 transferServer = new TransferServer( 4242 ); 739 transferServer = new TransferServer( 4242 );
738 if ( !transferServer->ok() ) { 740 if ( !transferServer->ok() ) {
739 delete transferServer; 741 delete transferServer;
740 transferServer = 0; 742 transferServer = 0;
741 } 743 }
742 if ( !transferServer || !qcopBridge ) 744 if ( !transferServer || !qcopBridge )
743 startTimer( 2000 ); 745 startTimer( 2000 );
744} 746}
745 747
746void Desktop::timerEvent( QTimerEvent *e ) 748void Desktop::timerEvent( QTimerEvent *e )
747{ 749{
748 killTimer( e->timerId() ); 750 killTimer( e->timerId() );
749 startTransferServer(); 751 startTransferServer();
750} 752}
751 753
752void Desktop::terminateServers() 754void Desktop::terminateServers()
753{ 755{
754 delete transferServer; 756 delete transferServer;
755 delete qcopBridge; 757 delete qcopBridge;
756 transferServer = 0; 758 transferServer = 0;
757 qcopBridge = 0; 759 qcopBridge = 0;
758} 760}
759 761
760void Desktop::rereadVolumes() 762void Desktop::rereadVolumes()
761{ 763{
762 Config cfg("qpe"); 764 Config cfg("qpe");
763 cfg.setGroup("Volume"); 765 cfg.setGroup("Volume");
764 touchclick = cfg.readBoolEntry("TouchSound"); 766 touchclick = cfg.readBoolEntry("TouchSound");
765 keyclick = cfg.readBoolEntry("KeySound"); 767 keyclick = cfg.readBoolEntry("KeySound");
766 alarmsound = cfg.readBoolEntry("AlarmSound"); 768 alarmsound = cfg.readBoolEntry("AlarmSound");
767} 769}
768 770
769void Desktop::keyClick() 771void Desktop::keyClick()
770{ 772{
771 if ( keyclick ) 773 if ( keyclick )
772 ODevice::inst ( )-> keySound ( ); 774 ODevice::inst ( )-> keySound ( );
773} 775}
774 776
775void Desktop::screenClick() 777void Desktop::screenClick()
776{ 778{
777 if ( touchclick ) 779 if ( touchclick )
778 ODevice::inst ( )-> touchSound ( ); 780 ODevice::inst ( )-> touchSound ( );
779} 781}
780 782
781void Desktop::soundAlarm() 783void Desktop::soundAlarm()
782{ 784{
783 if ( qpedesktop-> alarmsound ) 785 if ( qpedesktop-> alarmsound )
784 ODevice::inst ( )-> alarmSound ( ); 786 ODevice::inst ( )-> alarmSound ( );
785} 787}
786 788
787bool Desktop::eventFilter( QObject *, QEvent *ev ) 789bool Desktop::eventFilter( QObject *, QEvent *ev )
788{ 790{
789 if ( ev-> type ( ) == QEvent::KeyPress ) { 791 if ( ev-> type ( ) == QEvent::KeyPress ) {
790 QKeyEvent *ke = (QKeyEvent *) ev; 792 QKeyEvent *ke = (QKeyEvent *) ev;
791 if ( ke-> key ( ) == Qt::Key_F11 ) { // menu key 793 if ( ke-> key ( ) == Qt::Key_F11 ) { // menu key
792 QWidget *active = qApp-> activeWindow ( ); 794 QWidget *active = qApp-> activeWindow ( );
793 795
794 if ( active && active-> isPopup ( )) 796 if ( active && active-> isPopup ( ))
795 active->close(); 797 active->close();
796 798
797 /* 799 /*
798 * On iPAQ 38xx that key is not the "menu key" but the mail key 800 * On iPAQ 38xx that key is not the "menu key" but the mail key
799 * To not confuse the users, make it launch the mail app on 38xx 801 * To not confuse the users, make it launch the mail app on 38xx
800 */ 802 */
801 if (ODevice::inst()->model() == OMODEL_iPAQ_H38xx ) { 803 if (ODevice::inst()->model() == OMODEL_iPAQ_H38xx ) {
802 QCopEnvelope e( "QPE/System", "execute(QString)" ); 804 QCopEnvelope e( "QPE/System", "execute(QString)" );
803 e << QString( "mail" ); 805 e << QString( "mail" );
804 return true; 806 return true;
805 } else { 807 } else {
806 raiseMenu ( ); 808 raiseMenu ( );
807 return true; 809 return true;
808 } 810 }
809 } 811 }
810 } 812 }
811 return false; 813 return false;
812} 814}
diff --git a/core/launcher/main.cpp b/core/launcher/main.cpp
index 5cf624b..ca0bbe4 100644
--- a/core/launcher/main.cpp
+++ b/core/launcher/main.cpp
@@ -1,387 +1,265 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20 20
21#include "desktop.h" 21#include "desktop.h"
22#include "taskbar.h" 22#include "taskbar.h"
23#include "stabmon.h" 23#include "stabmon.h"
24 24
25#include <qpe/qpeapplication.h> 25#include <qpe/qpeapplication.h>
26#include <qpe/network.h> 26#include <qpe/network.h>
27#include <qpe/config.h> 27#include <qpe/config.h>
28#if defined( QT_QWS_CUSTOM ) || defined( QT_QWS_IPAQ ) 28#if defined( QT_QWS_CUSTOM ) || defined( QT_QWS_IPAQ )
29#include <qpe/custom.h> 29#include <qpe/custom.h>
30#endif 30#endif
31 31
32#include <opie/odevice.h> 32#include <opie/odevice.h>
33 33
34#include <qfile.h> 34#include <qfile.h>
35#include <qwindowsystem_qws.h> 35#include <qwindowsystem_qws.h>
36#include <qpe/qcopenvelope_qws.h> 36#include <qpe/qcopenvelope_qws.h>
37#include <qpe/alarmserver.h> 37#include <qpe/alarmserver.h>
38 38
39#include <stdlib.h> 39#include <stdlib.h>
40#include <stdio.h> 40#include <stdio.h>
41#include <signal.h> 41#include <signal.h>
42#include <unistd.h> 42#include <unistd.h>
43 43
44#if defined(QT_QWS_CASSIOPEIA) || defined(QT_QWS_IPAQ) || defined(QT_QWS_EBX) 44#if defined(QT_QWS_IPAQ) || defined(QT_QWS_EBX)
45#include "../calibrate/calibrate.h" 45#include "../calibrate/calibrate.h"
46#endif 46#endif
47 47
48#ifdef QT_QWS_CASSIOPEIA
49static void ignoreMessage( QtMsgType, const char * )
50{
51}
52#include <sys/mount.h>
53#include <sys/types.h>
54#include <sys/stat.h>
55#include <sys/time.h>
56#include <fcntl.h>
57#include <qdatetime.h>
58
59void initCassiopeia()
60{
61 // MIPSEL-specific init - make sure /proc exists for shm
62/*
63 if ( mount("/dev/ram0", "/", "ext2", MS_REMOUNT | MS_MGC_VAL, 0 ) ) {
64 perror("Remounting - / read/write");
65 }
66*/
67 if ( mount("none", "/tmp", "ramfs", 0, 0 ) ) {
68 perror("mounting ramfs /tmp");
69 } else {
70 fprintf( stderr, "mounted /tmp\n" );
71 }
72 if ( mount("none", "/home", "ramfs", 0, 0 ) ) {
73 perror("mounting ramfs /home");
74 } else {
75 fprintf( stderr, "mounted /home\n" );
76 }
77 if ( mount("none","/proc","proc",0,0) ) {
78 perror("Mounting - /proc");
79 } else {
80 fprintf( stderr, "mounted /proc\n" );
81 }
82 if ( mount("none","/mnt","shm",0,0) ) {
83 perror("Mounting - shm");
84 }
85 setenv( "QTDIR", "/", 1 );
86 setenv( "OPIEDIR", "/", 1 );
87 setenv( "HOME", "/home", 1 );
88 mkdir( "/home/Documents", 0755 );
89
90 // set a reasonable starting date
91 QDateTime dt( QDate( 2001, 3, 15 ) );
92 QDateTime now = QDateTime::currentDateTime();
93 int change = now.secsTo( dt );
94
95 time_t t = ::time(0);
96 t += change;
97 stime(&t);
98
99 qInstallMsgHandler(ignoreMessage);
100}
101#endif
102
103#ifdef QPE_OWNAPM
104#include <sys/ioctl.h>
105#include <sys/types.h>
106#include <fcntl.h>
107#include <unistd.h>
108#include <errno.h>
109#include <linux/ioctl.h>
110#include <qpe/global.h>
111
112static void disableAPM()
113{
114
115 int fd, cur_val, ret;
116 char *device = "/dev/apm_bios";
117
118 fd = open (device, O_WRONLY);
119
120 if (fd == -1) {
121 perror(device);
122 return;
123 }
124
125 cur_val = ioctl(fd, APM_IOCGEVTSRC, 0);
126 if (cur_val == -1) {
127 perror("ioctl");
128 exit(errno);
129 }
130
131 ret = ioctl(fd, APM_IOCSEVTSRC, cur_val & ~APM_EVT_POWER_BUTTON);
132 if (ret == -1) {
133 perror("ioctl");
134 return;
135 }
136 close(fd);
137}
138
139static void initAPM()
140{
141 // So that we have to do it ourself, but better.
142 disableAPM();
143}
144#endif
145
146#ifdef QT_DEMO_SINGLE_FLOPPY
147#include <sys/mount.h>
148
149void initFloppy()
150{
151 mount("none","/proc","proc",0,0);
152 setenv( "QTDIR", "/", 0 );
153 setenv( "HOME", "/root", 0 );
154 setenv( "QWS_SIZE", "240x320", 0 );
155}
156#endif
157
158 48
159void initEnvironment() 49void initEnvironment()
160{ 50{
161 Config config("locale"); 51 Config config("locale");
162 config.setGroup( "Location" ); 52 config.setGroup( "Location" );
163 QString tz = config.readEntry( "Timezone", getenv("TZ") ); 53 QString tz = config.readEntry( "Timezone", getenv("TZ") );
164 54
165 // if not timezone set, pick New York 55 // if not timezone set, pick New York
166 if (tz.isNull()) 56 if (tz.isNull())
167 tz = "America/New_York"; 57 tz = "America/New_York";
168 58
169 setenv( "TZ", tz, 1 ); 59 setenv( "TZ", tz, 1 );
170 config.writeEntry( "Timezone", tz); 60 config.writeEntry( "Timezone", tz);
171 61
172 config.setGroup( "Language" ); 62 config.setGroup( "Language" );
173 QString lang = config.readEntry( "Language", getenv("LANG") ); 63 QString lang = config.readEntry( "Language", getenv("LANG") );
174 if ( !lang.isNull() ) 64 if ( !lang.isNull() )
175 setenv( "LANG", lang, 1 ); 65 setenv( "LANG", lang, 1 );
176} 66}
177 67
178static void initBacklight() 68static void initBacklight()
179{ 69{
180 QCopEnvelope e("QPE/System", "setBacklight(int)" ); 70 QCopEnvelope e("QPE/System", "setBacklight(int)" );
181 e << -3; // Forced on 71 e << -3; // Forced on
182} 72}
183 73
184 74
185class ModelKeyFilter : public QObject, public QWSServer::KeyboardFilter 75class ModelKeyFilter : public QObject, public QWSServer::KeyboardFilter
186{ 76{
187public: 77public:
188 ModelKeyFilter ( ) : QObject ( 0, "MODEL_KEY_FILTER" ) 78 ModelKeyFilter ( ) : QObject ( 0, "MODEL_KEY_FILTER" )
189 { 79 {
190 bool doinst = false; 80 bool doinst = false;
191 81
192 m_model = ODevice::inst ( )-> model ( ); 82 m_model = ODevice::inst ( )-> model ( );
193 m_power_timer = 0; 83 m_power_timer = 0;
194 84
195 switch ( m_model ) { 85 switch ( m_model ) {
196 case OMODEL_iPAQ_H31xx: 86 case OMODEL_iPAQ_H31xx:
197 case OMODEL_iPAQ_H36xx: 87 case OMODEL_iPAQ_H36xx:
198 case OMODEL_iPAQ_H37xx: 88 case OMODEL_iPAQ_H37xx:
199 case OMODEL_iPAQ_H38xx: doinst = true; 89 case OMODEL_iPAQ_H38xx: doinst = true;
200 break; 90 break;
201 default : break; 91 default : break;
202 } 92 }
203 if ( doinst ) 93 if ( doinst )
204 QWSServer::setKeyboardFilter ( this ); 94 QWSServer::setKeyboardFilter ( this );
205 } 95 }
206 96
207 virtual bool filter ( int /*unicode*/, int keycode, int modifiers, bool isPress, bool autoRepeat ) 97 virtual bool filter ( int /*unicode*/, int keycode, int modifiers, bool isPress, bool autoRepeat )
208 { 98 {
209 bool kill = false; 99 bool kill = false;
210 100
211 // Rotate cursor keys 180° 101 // Rotate cursor keys 180°
212 switch ( m_model ) { 102 switch ( m_model ) {
213 case OMODEL_iPAQ_H31xx: 103 case OMODEL_iPAQ_H31xx:
214 case OMODEL_iPAQ_H38xx: { 104 case OMODEL_iPAQ_H38xx: {
215 int newkeycode = keycode; 105 int newkeycode = keycode;
216 106
217 switch ( keycode ) { 107 switch ( keycode ) {
218 case Key_Left : newkeycode = Key_Right; break; 108 case Key_Left : newkeycode = Key_Right; break;
219 case Key_Right: newkeycode = Key_Left; break; 109 case Key_Right: newkeycode = Key_Left; break;
220 case Key_Up : newkeycode = Key_Down; break; 110 case Key_Up : newkeycode = Key_Down; break;
221 case Key_Down : newkeycode = Key_Up; break; 111 case Key_Down : newkeycode = Key_Up; break;
222 } 112 }
223 if ( newkeycode != keycode ) { 113 if ( newkeycode != keycode ) {
224 QWSServer::sendKeyEvent ( -1, newkeycode, modifiers, isPress, autoRepeat ); 114 QWSServer::sendKeyEvent ( -1, newkeycode, modifiers, isPress, autoRepeat );
225 kill = true; 115 kill = true;
226 } 116 }
227 break; 117 break;
228 } 118 }
229 default: break; 119 default: break;
230 } 120 }
231 121
232 // map Power Button short/long press to F34/F35 122 // map Power Button short/long press to F34/F35
233 switch ( m_model ) { 123 switch ( m_model ) {
234 case OMODEL_iPAQ_H31xx: 124 case OMODEL_iPAQ_H31xx:
235 case OMODEL_iPAQ_H36xx: 125 case OMODEL_iPAQ_H36xx:
236 case OMODEL_iPAQ_H37xx: 126 case OMODEL_iPAQ_H37xx:
237 case OMODEL_iPAQ_H38xx: { 127 case OMODEL_iPAQ_H38xx: {
238 if ( keycode == Key_SysReq ) { 128 if ( keycode == Key_SysReq ) {
239 if ( isPress ) { 129 if ( isPress ) {
240 if ( m_power_timer ) 130 if ( m_power_timer )
241 killTimer ( m_power_timer ); 131 killTimer ( m_power_timer );
242 m_power_timer = startTimer ( 500 ); 132 m_power_timer = startTimer ( 500 );
243 } 133 }
244 else if ( m_power_timer ) { 134 else if ( m_power_timer ) {
245 killTimer ( m_power_timer ); 135 killTimer ( m_power_timer );
246 m_power_timer = 0; 136 m_power_timer = 0;
247 QWSServer::sendKeyEvent ( -1, Key_F34, 0, true, false ); 137 QWSServer::sendKeyEvent ( -1, Key_F34, 0, true, false );
248 QWSServer::sendKeyEvent ( -1, Key_F34, 0, false, false ); 138 QWSServer::sendKeyEvent ( -1, Key_F34, 0, false, false );
249 } 139 }
250 kill = true; 140 kill = true;
251 } 141 }
252 break; 142 break;
253 } 143 }
254 default: break; 144 default: break;
255 } 145 }
256 return kill; 146 return kill;
257 } 147 }
258 148
259 virtual void timerEvent ( QTimerEvent * ) 149 virtual void timerEvent ( QTimerEvent * )
260 { 150 {
261 killTimer ( m_power_timer ); 151 killTimer ( m_power_timer );
262 m_power_timer = 0; 152 m_power_timer = 0;
263 QWSServer::sendKeyEvent ( -1, Key_F35, 0, true, false ); 153 QWSServer::sendKeyEvent ( -1, Key_F35, 0, true, false );
264 QWSServer::sendKeyEvent ( -1, Key_F35, 0, false, false ); 154 QWSServer::sendKeyEvent ( -1, Key_F35, 0, false, false );
265 } 155 }
266 156
267private: 157private:
268 OModel m_model; 158 OModel m_model;
269 int m_power_timer; 159 int m_power_timer;
270}; 160};
271 161
272 162
273 163
274int initApplication( int argc, char ** argv ) 164int initApplication( int argc, char ** argv )
275{ 165{
276#ifdef QT_QWS_CASSIOPEIA 166 ODevice::inst ( )-> setPowerButtonHandler ( ODevice::OPIE );
277 initCassiopeia();
278#endif
279
280#ifdef QPE_OWNAPM
281 initAPM();
282#endif
283
284#ifdef QT_DEMO_SINGLE_FLOPPY
285 initFloppy();
286#endif
287 167
288 initEnvironment(); 168 initEnvironment();
289 169
290#if !defined(QT_QWS_CASSIOPEIA) && !defined(QT_QWS_IPAQ) && !defined(QT_QWS_EBX) 170#if !defined(QT_QWS_CASSIOPEIA) && !defined(QT_QWS_IPAQ) && !defined(QT_QWS_EBX)
291 setenv( "QWS_SIZE", "240x320", 0 ); 171 setenv( "QWS_SIZE", "240x320", 0 );
292#endif 172#endif
293 173
294 //Don't flicker at startup: 174 //Don't flicker at startup:
295 QWSServer::setDesktopBackground( QImage() ); 175 QWSServer::setDesktopBackground( QImage() );
296 DesktopApplication a( argc, argv, QApplication::GuiServer ); 176 DesktopApplication a( argc, argv, QApplication::GuiServer );
297 177
298 (void) new ModelKeyFilter ( ); 178 (void) new ModelKeyFilter ( );
299 179
300 initBacklight(); 180 initBacklight();
301 181
302 AlarmServer::initialize(); 182 AlarmServer::initialize();
303 183
304 Desktop *d = new Desktop(); 184 Desktop *d = new Desktop();
305 185
306 QObject::connect( &a, SIGNAL(datebook()), d, SLOT(raiseDatebook()) ); 186 QObject::connect( &a, SIGNAL(datebook()), d, SLOT(raiseDatebook()) );
307 QObject::connect( &a, SIGNAL(contacts()), d, SLOT(raiseContacts()) ); 187 QObject::connect( &a, SIGNAL(contacts()), d, SLOT(raiseContacts()) );
308 QObject::connect( &a, SIGNAL(launch()), d, SLOT(raiseLauncher()) ); 188 QObject::connect( &a, SIGNAL(launch()), d, SLOT(raiseLauncher()) );
309 QObject::connect( &a, SIGNAL(email()), d, SLOT(raiseEmail()) ); 189 QObject::connect( &a, SIGNAL(email()), d, SLOT(raiseEmail()) );
310 QObject::connect( &a, SIGNAL(power()), d, SLOT(togglePower()) ); 190 QObject::connect( &a, SIGNAL(power()), d, SLOT(togglePower()) );
311 QObject::connect( &a, SIGNAL(backlight()), d, SLOT(toggleLight()) ); 191 QObject::connect( &a, SIGNAL(backlight()), d, SLOT(toggleLight()) );
312 QObject::connect( &a, SIGNAL(symbol()), d, SLOT(toggleSymbolInput()) ); 192 QObject::connect( &a, SIGNAL(symbol()), d, SLOT(toggleSymbolInput()) );
313 QObject::connect( &a, SIGNAL(numLockStateToggle()), d, SLOT(toggleNumLockState()) ); 193 QObject::connect( &a, SIGNAL(numLockStateToggle()), d, SLOT(toggleNumLockState()) );
314 QObject::connect( &a, SIGNAL(capsLockStateToggle()), d, SLOT(toggleCapsLockState()) ); 194 QObject::connect( &a, SIGNAL(capsLockStateToggle()), d, SLOT(toggleCapsLockState()) );
315 QObject::connect( &a, SIGNAL(prepareForRestart()), d, SLOT(terminateServers()) ); 195 QObject::connect( &a, SIGNAL(prepareForRestart()), d, SLOT(terminateServers()) );
316 196
317 (void)new SysFileMonitor(d); 197 (void)new SysFileMonitor(d);
318 Network::createServer(d); 198 Network::createServer(d);
319 199
320#if defined(QT_QWS_CASSIOPEIA) || defined(QT_QWS_IPAQ) || defined(QT_QWS_EBX) 200#if defined(QT_QWS_CASSIOPEIA) || defined(QT_QWS_IPAQ) || defined(QT_QWS_EBX)
321 if ( !QFile::exists( "/etc/pointercal" ) ) { 201 if ( !QFile::exists( "/etc/pointercal" ) ) {
322 // Make sure calibration widget starts on top. 202 // Make sure calibration widget starts on top.
323 Calibrate *cal = new Calibrate; 203 Calibrate *cal = new Calibrate;
324 cal->exec(); 204 cal->exec();
325 delete cal; 205 delete cal;
326 } 206 }
327#endif 207#endif
328 208
329 d->show(); 209 d->show();
330 210
331 int rv = a.exec(); 211 int rv = a.exec();
332 212
333 delete d; 213 delete d;
334 214
215 ODevice::inst ( )-> setPowerButtonHandler ( ODevice::KERNEL );
216
335 return rv; 217 return rv;
336} 218}
337 219
338static const char *pidfile_path = "/var/run/opie.pid"; 220static const char *pidfile_path = "/var/run/opie.pid";
339 221
340void create_pidfile ( ) 222void create_pidfile ( )
341{ 223{
342 FILE *f; 224 FILE *f;
343 225
344 if (( f = ::fopen ( pidfile_path, "w" ))) { 226 if (( f = ::fopen ( pidfile_path, "w" ))) {
345 ::fprintf ( f, "%d", getpid ( )); 227 ::fprintf ( f, "%d", getpid ( ));
346 ::fclose ( f ); 228 ::fclose ( f );
347 } 229 }
348} 230}
349 231
350void remove_pidfile ( ) 232void remove_pidfile ( )
351{ 233{
352 ::unlink ( pidfile_path ); 234 ::unlink ( pidfile_path );
353} 235}
354 236
355void handle_sigterm ( int /* sig */ ) 237void handle_sigterm ( int /* sig */ )
356{ 238{
357 if ( qApp ) 239 if ( qApp )
358 qApp-> quit ( ); 240 qApp-> quit ( );
359} 241}
360 242
361int main( int argc, char ** argv ) 243int main( int argc, char ** argv )
362{ 244{
363#ifndef SINGLE_APP
364 ::signal( SIGCHLD, SIG_IGN ); 245 ::signal( SIGCHLD, SIG_IGN );
365 246
366 ::signal ( SIGTERM, handle_sigterm ); 247 ::signal ( SIGTERM, handle_sigterm );
367 ::signal ( SIGINT, handle_sigterm ); 248 ::signal ( SIGINT, handle_sigterm );
368 249
369 ::setsid ( ); 250 ::setsid ( );
370 ::setpgid ( 0, 0 ); 251 ::setpgid ( 0, 0 );
371 252
372 ::atexit ( remove_pidfile ); 253 ::atexit ( remove_pidfile );
373 create_pidfile ( ); 254 create_pidfile ( );
374#endif
375 255
376 int retVal = initApplication ( argc, argv ); 256 int retVal = initApplication ( argc, argv );
377 257
378#ifndef SINGLE_APP
379 // Kill them. Kill them all. 258 // Kill them. Kill them all.
380 ::kill ( 0, SIGTERM ); 259 ::kill ( 0, SIGTERM );
381 ::sleep( 1 ); 260 ::sleep ( 1 );
382 ::kill ( 0, SIGKILL ); 261 ::kill ( 0, SIGKILL );
383#endif
384 262
385 return retVal; 263 return retVal;
386} 264}
387 265