-rw-r--r-- | library/global.cpp | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/library/global.cpp b/library/global.cpp index ce39751..189b830 100644 --- a/library/global.cpp +++ b/library/global.cpp | |||
@@ -469,201 +469,206 @@ bool Global::isBuiltinCommand( const QString &name ) | |||
469 | if(!builtin) | 469 | if(!builtin) |
470 | return FALSE; // yes, it can happen | 470 | return FALSE; // yes, it can happen |
471 | for (int i = 0; builtin[i].file; i++) { | 471 | for (int i = 0; builtin[i].file; i++) { |
472 | if ( builtin[i].file == name ) { | 472 | if ( builtin[i].file == name ) { |
473 | return TRUE; | 473 | return TRUE; |
474 | } | 474 | } |
475 | } | 475 | } |
476 | return FALSE; | 476 | return FALSE; |
477 | } | 477 | } |
478 | 478 | ||
479 | Global::Command* Global::builtin=0; | 479 | Global::Command* Global::builtin=0; |
480 | QGuardedPtr<QWidget> *Global::running=0; | 480 | QGuardedPtr<QWidget> *Global::running=0; |
481 | 481 | ||
482 | /*! | 482 | /*! |
483 | \class Global::Command | 483 | \class Global::Command |
484 | \brief The Global::Command class is internal. | 484 | \brief The Global::Command class is internal. |
485 | \internal | 485 | \internal |
486 | */ | 486 | */ |
487 | 487 | ||
488 | /*! | 488 | /*! |
489 | \internal | 489 | \internal |
490 | */ | 490 | */ |
491 | void Global::setBuiltinCommands( Command* list ) | 491 | void Global::setBuiltinCommands( Command* list ) |
492 | { | 492 | { |
493 | if ( running ) | 493 | if ( running ) |
494 | delete [] running; | 494 | delete [] running; |
495 | 495 | ||
496 | builtin = list; | 496 | builtin = list; |
497 | int count = 0; | 497 | int count = 0; |
498 | if (!builtin) | 498 | if (!builtin) |
499 | return; | 499 | return; |
500 | while ( builtin[count].file ) | 500 | while ( builtin[count].file ) |
501 | count++; | 501 | count++; |
502 | 502 | ||
503 | running = new QGuardedPtr<QWidget> [ count ]; | 503 | running = new QGuardedPtr<QWidget> [ count ]; |
504 | } | 504 | } |
505 | 505 | ||
506 | /*! | 506 | /*! |
507 | \internal | 507 | \internal |
508 | */ | 508 | */ |
509 | void Global::setDocument( QWidget* receiver, const QString& document ) | 509 | void Global::setDocument( QWidget* receiver, const QString& document ) |
510 | { | 510 | { |
511 | Emitter emitter(receiver,document); | 511 | Emitter emitter(receiver,document); |
512 | } | 512 | } |
513 | 513 | ||
514 | /*! | 514 | /*! |
515 | \internal | 515 | \internal |
516 | */ | 516 | */ |
517 | bool Global::terminateBuiltin( const QString& n ) | 517 | bool Global::terminateBuiltin( const QString& n ) |
518 | { | 518 | { |
519 | if (!builtin) | 519 | if (!builtin) |
520 | return FALSE; | 520 | return FALSE; |
521 | for (int i = 0; builtin[i].file; i++) { | 521 | for (int i = 0; builtin[i].file; i++) { |
522 | if ( builtin[i].file == n ) { | 522 | if ( builtin[i].file == n ) { |
523 | delete running[i]; | 523 | delete running[i]; |
524 | return TRUE; | 524 | return TRUE; |
525 | } | 525 | } |
526 | } | 526 | } |
527 | return FALSE; | 527 | return FALSE; |
528 | } | 528 | } |
529 | 529 | ||
530 | /*! | 530 | /*! |
531 | \internal | 531 | \internal |
532 | */ | 532 | */ |
533 | void Global::terminate( const AppLnk* app ) | 533 | void Global::terminate( const AppLnk* app ) |
534 | { | 534 | { |
535 | //if ( terminateBuiltin(app->exec()) ) return; // maybe? haven't tried this | 535 | //if ( terminateBuiltin(app->exec()) ) return; // maybe? haven't tried this |
536 | 536 | ||
537 | #ifndef QT_NO_COP | 537 | #ifndef QT_NO_COP |
538 | QCString channel = "QPE/Application/" + app->exec().utf8(); | 538 | QCString channel = "QPE/Application/" + app->exec().utf8(); |
539 | if ( QCopChannel::isRegistered(channel) ) { | 539 | if ( QCopChannel::isRegistered(channel) ) { |
540 | QCopEnvelope e(channel, "quit()"); | 540 | QCopEnvelope e(channel, "quit()"); |
541 | } | 541 | } |
542 | #endif | 542 | #endif |
543 | } | 543 | } |
544 | 544 | ||
545 | /*! | 545 | /*! |
546 | Low-level function to run command \a c. | 546 | Low-level function to run command \a c. |
547 | 547 | ||
548 | \warning Do not use this function. Use execute instead. | 548 | \warning Do not use this function. Use execute instead. |
549 | 549 | ||
550 | \sa execute() | 550 | \sa execute() |
551 | */ | 551 | */ |
552 | void Global::invoke(const QString &c) | 552 | void Global::invoke(const QString &c) |
553 | { | 553 | { |
554 | // Convert the command line in to a list of arguments | 554 | // Convert the command line in to a list of arguments |
555 | QStringList list = QStringList::split(QRegExp(" *"),c); | 555 | QStringList list = QStringList::split(QRegExp(" *"),c); |
556 | 556 | ||
557 | #if !defined(QT_NO_COP) | 557 | #if !defined(QT_NO_COP) |
558 | QString ap=list[0]; | 558 | QString ap=list[0]; |
559 | // see if the application is already running | 559 | // see if the application is already running |
560 | // XXX should lock file /tmp/qcop-msg-ap | 560 | // XXX should lock file /tmp/qcop-msg-ap |
561 | if ( QCopChannel::isRegistered( ("QPE/Application/" + ap).latin1() ) ) { | 561 | if ( QCopChannel::isRegistered( ("QPE/Application/" + ap).latin1() ) ) { |
562 | // If the channel is already register, the app is already running, so show it. | 562 | // If the channel is already register, the app is already running, so show it. |
563 | { QCopEnvelope env( ("QPE/Application/" + ap).latin1(), "raise()" ); } | 563 | { QCopEnvelope env( ("QPE/Application/" + ap).latin1(), "raise()" ); } |
564 | 564 | ||
565 | QCopEnvelope e("QPE/System", "notBusy(QString)" ); | 565 | //QCopEnvelope e("QPE/System", "notBusy(QString)" ); |
566 | e << ap; | 566 | //e << ap; |
567 | return; | 567 | return; |
568 | } | 568 | } |
569 | // XXX should unlock file /tmp/qcop-msg-ap | 569 | // XXX should unlock file /tmp/qcop-msg-ap |
570 | //see if it is being started | 570 | //see if it is being started |
571 | if ( StartingAppList::isStarting( ap ) ) { | 571 | if ( StartingAppList::isStarting( ap ) ) { |
572 | QCopEnvelope e("QPE/System", "notBusy(QString)" ); | 572 | // FIXME take it out for now, since it leads to a much to short showing of wait if |
573 | e << ap; | 573 | // some entry is clicked. |
574 | // Real cause is that ::execute is called twice for document tab. But it would need some larger changes | ||
575 | // to fix that, and with future syncs with qtopia 1.6 it will change anyway big time since somebody there | ||
576 | // had the idea that an apploader belongs to the launcher ... | ||
577 | //QCopEnvelope e("QPE/System", "notBusy(QString)" ); | ||
578 | //e << ap; | ||
574 | return; | 579 | return; |
575 | } | 580 | } |
576 | 581 | ||
577 | #endif | 582 | #endif |
578 | 583 | ||
579 | #ifdef QT_NO_QWS_MULTIPROCESS | 584 | #ifdef QT_NO_QWS_MULTIPROCESS |
580 | QMessageBox::warning( 0, "Error", "Could not find the application " + c, "Ok", 0, 0, 0, 1 ); | 585 | QMessageBox::warning( 0, "Error", "Could not find the application " + c, "Ok", 0, 0, 0, 1 ); |
581 | #else | 586 | #else |
582 | 587 | ||
583 | QStrList slist; | 588 | QStrList slist; |
584 | unsigned int j; | 589 | unsigned int j; |
585 | for ( j = 0; j < list.count(); j++ ) | 590 | for ( j = 0; j < list.count(); j++ ) |
586 | slist.append( list[j].utf8() ); | 591 | slist.append( list[j].utf8() ); |
587 | 592 | ||
588 | const char **args = new (const char *)[slist.count() + 1]; | 593 | const char **args = new (const char *)[slist.count() + 1]; |
589 | for ( j = 0; j < slist.count(); j++ ) | 594 | for ( j = 0; j < slist.count(); j++ ) |
590 | args[j] = slist.at(j); | 595 | args[j] = slist.at(j); |
591 | args[j] = NULL; | 596 | args[j] = NULL; |
592 | 597 | ||
593 | #if !defined(QT_NO_COP) | 598 | #if !defined(QT_NO_COP) |
594 | // an attempt to show a wait... | 599 | // an attempt to show a wait... |
595 | // more logic should be used, but this will be fine for the moment... | 600 | // more logic should be used, but this will be fine for the moment... |
596 | QCopEnvelope ( "QPE/System", "busy()" ); | 601 | QCopEnvelope ( "QPE/System", "busy()" ); |
597 | #endif | 602 | #endif |
598 | 603 | ||
599 | #ifdef HAVE_QUICKEXEC | 604 | #ifdef HAVE_QUICKEXEC |
600 | QString libexe = qpeDir()+"/binlib/lib"+args[0] + ".so"; | 605 | QString libexe = qpeDir()+"/binlib/lib"+args[0] + ".so"; |
601 | qDebug("libfile = %s", libexe.latin1() ); | 606 | qDebug("libfile = %s", libexe.latin1() ); |
602 | if ( QFile::exists( libexe ) ) { | 607 | if ( QFile::exists( libexe ) ) { |
603 | qDebug("calling quickexec %s", libexe.latin1() ); | 608 | qDebug("calling quickexec %s", libexe.latin1() ); |
604 | quickexecv( libexe.utf8().data(), (const char **)args ); | 609 | quickexecv( libexe.utf8().data(), (const char **)args ); |
605 | } else | 610 | } else |
606 | #endif | 611 | #endif |
607 | { | 612 | { |
608 | bool success = false; | 613 | bool success = false; |
609 | int pfd [2]; | 614 | int pfd [2]; |
610 | if ( ::pipe ( pfd ) < 0 ) | 615 | if ( ::pipe ( pfd ) < 0 ) |
611 | pfd [0] = pfd [1] = -1; | 616 | pfd [0] = pfd [1] = -1; |
612 | 617 | ||
613 | pid_t pid = ::fork ( ); | 618 | pid_t pid = ::fork ( ); |
614 | 619 | ||
615 | if ( pid == 0 ) { // child | 620 | if ( pid == 0 ) { // child |
616 | for ( int fd = 3; fd < 100; fd++ ) { | 621 | for ( int fd = 3; fd < 100; fd++ ) { |
617 | if ( fd != pfd [1] ) | 622 | if ( fd != pfd [1] ) |
618 | ::close ( fd ); | 623 | ::close ( fd ); |
619 | } | 624 | } |
620 | ::setpgid ( ::getpid ( ), ::getppid ( )); | 625 | ::setpgid ( ::getpid ( ), ::getppid ( )); |
621 | 626 | ||
622 | // Closing of fd[1] indicates that the execvp succeeded! | 627 | // Closing of fd[1] indicates that the execvp succeeded! |
623 | if ( pfd [1] >= 0 ) | 628 | if ( pfd [1] >= 0 ) |
624 | ::fcntl ( pfd [1], F_SETFD, FD_CLOEXEC ); | 629 | ::fcntl ( pfd [1], F_SETFD, FD_CLOEXEC ); |
625 | 630 | ||
626 | // Try bindir first, so that foo/bar works too | 631 | // Try bindir first, so that foo/bar works too |
627 | ::execv ( qpeDir ( ) + "/bin/" + args [0], (char * const *) args ); | 632 | ::execv ( qpeDir ( ) + "/bin/" + args [0], (char * const *) args ); |
628 | ::execvp ( args [0], (char * const *) args ); | 633 | ::execvp ( args [0], (char * const *) args ); |
629 | 634 | ||
630 | char resultByte = 1; | 635 | char resultByte = 1; |
631 | if ( pfd [1] >= 0 ) | 636 | if ( pfd [1] >= 0 ) |
632 | ::write ( pfd [1], &resultByte, 1 ); | 637 | ::write ( pfd [1], &resultByte, 1 ); |
633 | ::_exit ( -1 ); | 638 | ::_exit ( -1 ); |
634 | } | 639 | } |
635 | else if ( pid > 0 ) { | 640 | else if ( pid > 0 ) { |
636 | success = true; | 641 | success = true; |
637 | 642 | ||
638 | if ( pfd [1] >= 0 ) | 643 | if ( pfd [1] >= 0 ) |
639 | ::close ( pfd [1] ); | 644 | ::close ( pfd [1] ); |
640 | if ( pfd [0] >= 0 ) { | 645 | if ( pfd [0] >= 0 ) { |
641 | while ( true ) { | 646 | while ( true ) { |
642 | char resultByte; | 647 | char resultByte; |
643 | int n = ::read ( pfd [0], &resultByte, 1 ); | 648 | int n = ::read ( pfd [0], &resultByte, 1 ); |
644 | if ( n == 1 ) { | 649 | if ( n == 1 ) { |
645 | success = false; | 650 | success = false; |
646 | break; | 651 | break; |
647 | } | 652 | } |
648 | if (( n == -1 ) && (( errno == ECHILD ) || ( errno == EINTR ))) | 653 | if (( n == -1 ) && (( errno == ECHILD ) || ( errno == EINTR ))) |
649 | continue; | 654 | continue; |
650 | 655 | ||
651 | break; // success | 656 | break; // success |
652 | } | 657 | } |
653 | ::close ( pfd [0] ); | 658 | ::close ( pfd [0] ); |
654 | } | 659 | } |
655 | } | 660 | } |
656 | if ( success ) | 661 | if ( success ) |
657 | StartingAppList::add( list[0] ); | 662 | StartingAppList::add( list[0] ); |
658 | else | 663 | else |
659 | QMessageBox::warning( 0, "Error", "Could not start the application " + c, "Ok", 0, 0, 0, 1 ); | 664 | QMessageBox::warning( 0, "Error", "Could not start the application " + c, "Ok", 0, 0, 0, 1 ); |
660 | } | 665 | } |
661 | #endif //QT_NO_QWS_MULTIPROCESS | 666 | #endif //QT_NO_QWS_MULTIPROCESS |
662 | } | 667 | } |
663 | 668 | ||
664 | 669 | ||
665 | /*! | 670 | /*! |
666 | Executes the application identfied by \a c, passing \a | 671 | Executes the application identfied by \a c, passing \a |
667 | document if it isn't null. | 672 | document if it isn't null. |
668 | 673 | ||
669 | Note that a better approach might be to send a QCop message to the | 674 | Note that a better approach might be to send a QCop message to the |
@@ -737,113 +742,116 @@ void Global::execute( const QString &c, const QString& document ) | |||
737 | */ | 742 | */ |
738 | QString Global::shellQuote(const QString& s) | 743 | QString Global::shellQuote(const QString& s) |
739 | { | 744 | { |
740 | QString r="\""; | 745 | QString r="\""; |
741 | for (int i=0; i<(int)s.length(); i++) { | 746 | for (int i=0; i<(int)s.length(); i++) { |
742 | char c = s[i].latin1(); | 747 | char c = s[i].latin1(); |
743 | switch (c) { | 748 | switch (c) { |
744 | case '\\': case '"': case '$': | 749 | case '\\': case '"': case '$': |
745 | r+="\\"; | 750 | r+="\\"; |
746 | } | 751 | } |
747 | r += s[i]; | 752 | r += s[i]; |
748 | } | 753 | } |
749 | r += "\""; | 754 | r += "\""; |
750 | return r; | 755 | return r; |
751 | } | 756 | } |
752 | 757 | ||
753 | /*! | 758 | /*! |
754 | Returns the string \a s with the characters '\' and '"' quoted by a | 759 | Returns the string \a s with the characters '\' and '"' quoted by a |
755 | preceeding '\'. | 760 | preceeding '\'. |
756 | 761 | ||
757 | \sa shellQuote() | 762 | \sa shellQuote() |
758 | */ | 763 | */ |
759 | QString Global::stringQuote(const QString& s) | 764 | QString Global::stringQuote(const QString& s) |
760 | { | 765 | { |
761 | QString r="\""; | 766 | QString r="\""; |
762 | for (int i=0; i<(int)s.length(); i++) { | 767 | for (int i=0; i<(int)s.length(); i++) { |
763 | char c = s[i].latin1(); | 768 | char c = s[i].latin1(); |
764 | switch (c) { | 769 | switch (c) { |
765 | case '\\': case '"': | 770 | case '\\': case '"': |
766 | r+="\\"; | 771 | r+="\\"; |
767 | } | 772 | } |
768 | r += s[i]; | 773 | r += s[i]; |
769 | } | 774 | } |
770 | r += "\""; | 775 | r += "\""; |
771 | return r; | 776 | return r; |
772 | } | 777 | } |
773 | 778 | ||
774 | /*! | 779 | /*! |
775 | Finds all documents on the system's document directories which | 780 | Finds all documents on the system's document directories which |
776 | match the filter \a mimefilter, and appends the resulting DocLnk | 781 | match the filter \a mimefilter, and appends the resulting DocLnk |
777 | objects to \a folder. | 782 | objects to \a folder. |
778 | */ | 783 | */ |
779 | void Global::findDocuments(DocLnkSet* folder, const QString &mimefilter) | 784 | void Global::findDocuments(DocLnkSet* folder, const QString &mimefilter) |
780 | { | 785 | { |
781 | QString homedocs = QString(getenv("HOME")) + "/Documents"; | 786 | QString homedocs = QString(getenv("HOME")) + "/Documents"; |
782 | DocLnkSet d(homedocs,mimefilter); | 787 | DocLnkSet d(homedocs,mimefilter); |
783 | folder->appendFrom(d); | 788 | folder->appendFrom(d); |
784 | /** let's do intellegint way of searching these files | 789 | /** let's do intellegint way of searching these files |
785 | * a) the user don't want to check mediums global | 790 | * a) the user don't want to check mediums global |
786 | * b) the user wants to check but use the global options for it | 791 | * b) the user wants to check but use the global options for it |
787 | * c) the user wants to check it but not this medium | 792 | * c) the user wants to check it but not this medium |
788 | * d) the user wants to check and this medium as well | 793 | * d) the user wants to check and this medium as well |
789 | * | 794 | * |
790 | * In all cases we need to apply a different mimefilter to | 795 | * In all cases we need to apply a different mimefilter to |
791 | * the medium. | 796 | * the medium. |
792 | * a) mimefilter.isEmpty() we need to apply the responding filter | 797 | * a) mimefilter.isEmpty() we need to apply the responding filter |
793 | * either the global or the one on the medium | 798 | * either the global or the one on the medium |
794 | * | 799 | * |
795 | * b) mimefilter is set to an application we need to find out if the | 800 | * b) mimefilter is set to an application we need to find out if the |
796 | * mimetypes are included in the mime mask of the medium | 801 | * mimetypes are included in the mime mask of the medium |
797 | */ | 802 | */ |
798 | StorageInfo storage; | 803 | StorageInfo storage; |
799 | const QList<FileSystem> &fs = storage.fileSystems(); | 804 | const QList<FileSystem> &fs = storage.fileSystems(); |
800 | QListIterator<FileSystem> it ( fs ); | 805 | QListIterator<FileSystem> it ( fs ); |
801 | for ( ; it.current(); ++it ) { | 806 | for ( ; it.current(); ++it ) { |
802 | if ( (*it)->isRemovable() ) { // let's find out if we should search on it | 807 | if ( (*it)->isRemovable() ) { // let's find out if we should search on it |
803 | // this is a candidate look at the cf and see if we should search on it | 808 | // this is a candidate look at the cf and see if we should search on it |
804 | QString path = (*it)->path(); | 809 | QString path = (*it)->path(); |
805 | if( !checkStorage((*it)->path() + "/.opiestorage.cf" ) ) | 810 | if( !checkStorage((*it)->path() + "/.opiestorage.cf" ) ) |
806 | continue; | 811 | continue; |
807 | DocLnkSet ide( path, mimefilter ); | 812 | DocLnkSet ide( path, mimefilter ); |
808 | folder->appendFrom(ide); | 813 | folder->appendFrom(ide); |
809 | } else if ( (*it)->disk() == "/dev/mtdblock6" || (*it)->disk() == "tmpfs" ) { | 814 | } else if ( (*it)->disk() == "/dev/mtdblock6" || (*it)->disk() == "tmpfs" ) { |
810 | QString path = (*it)->path() + "/Documents"; | 815 | QString path = (*it)->path() + "/Documents"; |
811 | DocLnkSet ide( path, mimefilter ); | 816 | DocLnkSet ide( path, mimefilter ); |
812 | folder->appendFrom(ide); | 817 | folder->appendFrom(ide); |
813 | } | 818 | } |
814 | } | 819 | } |
815 | } | 820 | } |
816 | 821 | ||
817 | QStringList Global::languageList() | 822 | QStringList Global::languageList() |
818 | { | 823 | { |
819 | QString lang = getenv("LANG"); | 824 | QString lang = getenv("LANG"); |
820 | QStringList langs; | 825 | QStringList langs; |
821 | langs.append(lang); | 826 | langs.append(lang); |
822 | int i = lang.find("."); | 827 | int i = lang.find("."); |
823 | if ( i > 0 ) | 828 | if ( i > 0 ) |
824 | lang = lang.left( i ); | 829 | lang = lang.left( i ); |
825 | i = lang.find( "_" ); | 830 | i = lang.find( "_" ); |
826 | if ( i > 0 ) | 831 | if ( i > 0 ) |
827 | langs.append(lang.left(i)); | 832 | langs.append(lang.left(i)); |
828 | return langs; | 833 | return langs; |
829 | } | 834 | } |
830 | 835 | ||
831 | QStringList Global::helpPath() | 836 | QStringList Global::helpPath() |
832 | { | 837 | { |
838 | QString qpeDir = QPEApplication::qpeDir(); | ||
833 | QStringList path; | 839 | QStringList path; |
834 | QStringList langs = Global::languageList(); | 840 | QStringList langs = Global::languageList(); |
835 | for (QStringList::ConstIterator it = langs.fromLast(); it!=langs.end(); --it) { | 841 | for (QStringList::ConstIterator it = langs.fromLast(); it!=langs.end(); --it) { |
836 | QString lang = *it; | 842 | QString lang = *it; |
837 | if ( !lang.isEmpty() ) | 843 | if ( !lang.isEmpty() ) |
838 | path += QPEApplication::qpeDir() + "/help/" + lang + "/html"; | 844 | path += qpeDir + "/help/" + lang + "/html"; |
839 | } | 845 | } |
840 | path += QPEApplication::qpeDir() + "/pics"; | 846 | path += qpeDir + "/pics"; |
841 | path += QPEApplication::qpeDir() + "/help/html"; | 847 | path += qpeDir + "/help/html"; |
842 | path += QPEApplication::qpeDir() + "/docs"; | 848 | /* we even put english into the en dir so try it as fallback as well for opie */ |
849 | path += qpeDir + "/help/en/html"; | ||
850 | path += qpeDir + "/docs"; | ||
843 | 851 | ||
844 | 852 | ||
845 | return path; | 853 | return path; |
846 | } | 854 | } |
847 | 855 | ||
848 | 856 | ||
849 | #include "global.moc" | 857 | #include "global.moc" |