-rw-r--r-- | library/global.cpp | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/library/global.cpp b/library/global.cpp index 6c0a66a..6182de8 100644 --- a/library/global.cpp +++ b/library/global.cpp | |||
@@ -520,308 +520,313 @@ void Global::setDocument( QWidget* receiver, const QString& document ) | |||
520 | bool Global::terminateBuiltin( const QString& n ) | 520 | bool Global::terminateBuiltin( const QString& n ) |
521 | { | 521 | { |
522 | if (!builtin) | 522 | if (!builtin) |
523 | return FALSE; | 523 | return FALSE; |
524 | for (int i = 0; builtin[i].file; i++) { | 524 | for (int i = 0; builtin[i].file; i++) { |
525 | if ( builtin[i].file == n ) { | 525 | if ( builtin[i].file == n ) { |
526 | delete running[i]; | 526 | delete running[i]; |
527 | return TRUE; | 527 | return TRUE; |
528 | } | 528 | } |
529 | } | 529 | } |
530 | return FALSE; | 530 | return FALSE; |
531 | } | 531 | } |
532 | 532 | ||
533 | /*! | 533 | /*! |
534 | \internal | 534 | \internal |
535 | */ | 535 | */ |
536 | void Global::terminate( const AppLnk* app ) | 536 | void Global::terminate( const AppLnk* app ) |
537 | { | 537 | { |
538 | //if ( terminateBuiltin(app->exec()) ) return; // maybe? haven't tried this | 538 | //if ( terminateBuiltin(app->exec()) ) return; // maybe? haven't tried this |
539 | 539 | ||
540 | #ifndef QT_NO_COP | 540 | #ifndef QT_NO_COP |
541 | QCString channel = "QPE/Application/" + app->exec().utf8(); | 541 | QCString channel = "QPE/Application/" + app->exec().utf8(); |
542 | if ( QCopChannel::isRegistered(channel) ) { | 542 | if ( QCopChannel::isRegistered(channel) ) { |
543 | QCopEnvelope e(channel, "quit()"); | 543 | QCopEnvelope e(channel, "quit()"); |
544 | } | 544 | } |
545 | #endif | 545 | #endif |
546 | } | 546 | } |
547 | 547 | ||
548 | /*! | 548 | /*! |
549 | Low-level function to run command \a c. | 549 | Low-level function to run command \a c. |
550 | 550 | ||
551 | \warning Do not use this function. Use execute instead. | 551 | \warning Do not use this function. Use execute instead. |
552 | 552 | ||
553 | \sa execute() | 553 | \sa execute() |
554 | */ | 554 | */ |
555 | void Global::invoke(const QString &c) | 555 | void Global::invoke(const QString &c) |
556 | { | 556 | { |
557 | // Convert the command line in to a list of arguments | 557 | // Convert the command line in to a list of arguments |
558 | QStringList list = QStringList::split(QRegExp(" *"),c); | 558 | QStringList list = QStringList::split(QRegExp(" *"),c); |
559 | 559 | ||
560 | #if !defined(QT_NO_COP) | 560 | #if !defined(QT_NO_COP) |
561 | QString ap=list[0]; | 561 | QString ap=list[0]; |
562 | // see if the application is already running | 562 | // see if the application is already running |
563 | // XXX should lock file /tmp/qcop-msg-ap | 563 | // XXX should lock file /tmp/qcop-msg-ap |
564 | if ( QCopChannel::isRegistered( ("QPE/Application/" + ap).latin1() ) ) { | 564 | if ( QCopChannel::isRegistered( ("QPE/Application/" + ap).latin1() ) ) { |
565 | // If the channel is already register, the app is already running, so show it. | 565 | // If the channel is already register, the app is already running, so show it. |
566 | { QCopEnvelope env( ("QPE/Application/" + ap).latin1(), "raise()" ); } | 566 | { QCopEnvelope env( ("QPE/Application/" + ap).latin1(), "raise()" ); } |
567 | 567 | ||
568 | //QCopEnvelope e("QPE/System", "notBusy(QString)" ); | 568 | //QCopEnvelope e("QPE/System", "notBusy(QString)" ); |
569 | //e << ap; | 569 | //e << ap; |
570 | return; | 570 | return; |
571 | } | 571 | } |
572 | // XXX should unlock file /tmp/qcop-msg-ap | 572 | // XXX should unlock file /tmp/qcop-msg-ap |
573 | //see if it is being started | 573 | //see if it is being started |
574 | if ( StartingAppList::isStarting( ap ) ) { | 574 | if ( StartingAppList::isStarting( ap ) ) { |
575 | // FIXME take it out for now, since it leads to a much to short showing of wait if | 575 | // FIXME take it out for now, since it leads to a much to short showing of wait if |
576 | // some entry is clicked. | 576 | // some entry is clicked. |
577 | // Real cause is that ::execute is called twice for document tab. But it would need some larger changes | 577 | // Real cause is that ::execute is called twice for document tab. But it would need some larger changes |
578 | // to fix that, and with future syncs with qtopia 1.6 it will change anyway big time since somebody there | 578 | // to fix that, and with future syncs with qtopia 1.6 it will change anyway big time since somebody there |
579 | // had the idea that an apploader belongs to the launcher ... | 579 | // had the idea that an apploader belongs to the launcher ... |
580 | //QCopEnvelope e("QPE/System", "notBusy(QString)" ); | 580 | //QCopEnvelope e("QPE/System", "notBusy(QString)" ); |
581 | //e << ap; | 581 | //e << ap; |
582 | return; | 582 | return; |
583 | } | 583 | } |
584 | 584 | ||
585 | #endif | 585 | #endif |
586 | 586 | ||
587 | #ifdef QT_NO_QWS_MULTIPROCESS | 587 | #ifdef QT_NO_QWS_MULTIPROCESS |
588 | QMessageBox::warning( 0, "Error", "Could not find the application " + c, "Ok", 0, 0, 0, 1 ); | 588 | QMessageBox::warning( 0, "Error", "Could not find the application " + c, "Ok", 0, 0, 0, 1 ); |
589 | #else | 589 | #else |
590 | 590 | ||
591 | QStrList slist; | 591 | QStrList slist; |
592 | unsigned int j; | 592 | unsigned int j; |
593 | for ( j = 0; j < list.count(); j++ ) | 593 | for ( j = 0; j < list.count(); j++ ) |
594 | slist.append( list[j].utf8() ); | 594 | slist.append( list[j].utf8() ); |
595 | 595 | ||
596 | const char **args = new (const char *)[slist.count() + 1]; | 596 | const char **args = new (const char *)[slist.count() + 1]; |
597 | for ( j = 0; j < slist.count(); j++ ) | 597 | for ( j = 0; j < slist.count(); j++ ) |
598 | args[j] = slist.at(j); | 598 | args[j] = slist.at(j); |
599 | args[j] = NULL; | 599 | args[j] = NULL; |
600 | 600 | ||
601 | #if !defined(QT_NO_COP) | 601 | #if !defined(QT_NO_COP) |
602 | // an attempt to show a wait... | 602 | // an attempt to show a wait... |
603 | // more logic should be used, but this will be fine for the moment... | 603 | // more logic should be used, but this will be fine for the moment... |
604 | QCopEnvelope ( "QPE/System", "busy()" ); | 604 | QCopEnvelope ( "QPE/System", "busy()" ); |
605 | #endif | 605 | #endif |
606 | 606 | ||
607 | #ifdef HAVE_QUICKEXEC | 607 | #ifdef HAVE_QUICKEXEC |
608 | #ifdef Q_OS_MACX | 608 | #ifdef Q_OS_MACX |
609 | QString libexe = qpeDir()+"/binlib/lib"+args[0] + ".dylib"; | 609 | QString libexe = qpeDir()+"/binlib/lib"+args[0] + ".dylib"; |
610 | #else | 610 | #else |
611 | QString libexe = qpeDir()+"/binlib/lib"+args[0] + ".so"; | 611 | QString libexe = qpeDir()+"/binlib/lib"+args[0] + ".so"; |
612 | #endif | 612 | #endif |
613 | qDebug("libfile = %s", libexe.latin1() ); | 613 | qDebug("libfile = %s", libexe.latin1() ); |
614 | if ( QFile::exists( libexe ) ) { | 614 | if ( QFile::exists( libexe ) ) { |
615 | qDebug("calling quickexec %s", libexe.latin1() ); | 615 | qDebug("calling quickexec %s", libexe.latin1() ); |
616 | quickexecv( libexe.utf8().data(), (const char **)args ); | 616 | quickexecv( libexe.utf8().data(), (const char **)args ); |
617 | } else | 617 | } else |
618 | #endif | 618 | #endif |
619 | { | 619 | { |
620 | bool success = false; | 620 | bool success = false; |
621 | int pfd [2]; | 621 | int pfd [2]; |
622 | if ( ::pipe ( pfd ) < 0 ) | 622 | if ( ::pipe ( pfd ) < 0 ) |
623 | pfd [0] = pfd [1] = -1; | 623 | pfd [0] = pfd [1] = -1; |
624 | 624 | ||
625 | pid_t pid = ::fork ( ); | 625 | pid_t pid = ::fork ( ); |
626 | 626 | ||
627 | if ( pid == 0 ) { // child | 627 | if ( pid == 0 ) { // child |
628 | for ( int fd = 3; fd < 100; fd++ ) { | 628 | for ( int fd = 3; fd < 100; fd++ ) { |
629 | if ( fd != pfd [1] ) | 629 | if ( fd != pfd [1] ) |
630 | ::close ( fd ); | 630 | ::close ( fd ); |
631 | } | 631 | } |
632 | ::setpgid ( ::getpid ( ), ::getppid ( )); | 632 | ::setpgid ( ::getpid ( ), ::getppid ( )); |
633 | 633 | ||
634 | // Closing of fd[1] indicates that the execvp succeeded! | 634 | // Closing of fd[1] indicates that the execvp succeeded! |
635 | if ( pfd [1] >= 0 ) | 635 | if ( pfd [1] >= 0 ) |
636 | ::fcntl ( pfd [1], F_SETFD, FD_CLOEXEC ); | 636 | ::fcntl ( pfd [1], F_SETFD, FD_CLOEXEC ); |
637 | 637 | ||
638 | // Try bindir first, so that foo/bar works too | 638 | // Try bindir first, so that foo/bar works too |
639 | ::execv ( qpeDir ( ) + "/bin/" + args [0], (char * const *) args ); | 639 | ::execv ( qpeDir ( ) + "/bin/" + args [0], (char * const *) args ); |
640 | ::execvp ( args [0], (char * const *) args ); | 640 | ::execvp ( args [0], (char * const *) args ); |
641 | 641 | ||
642 | char resultByte = 1; | 642 | char resultByte = 1; |
643 | if ( pfd [1] >= 0 ) | 643 | if ( pfd [1] >= 0 ) |
644 | ::write ( pfd [1], &resultByte, 1 ); | 644 | ::write ( pfd [1], &resultByte, 1 ); |
645 | ::_exit ( -1 ); | 645 | ::_exit ( -1 ); |
646 | } | 646 | } |
647 | else if ( pid > 0 ) { | 647 | else if ( pid > 0 ) { |
648 | success = true; | 648 | success = true; |
649 | 649 | ||
650 | if ( pfd [1] >= 0 ) | 650 | if ( pfd [1] >= 0 ) |
651 | ::close ( pfd [1] ); | 651 | ::close ( pfd [1] ); |
652 | if ( pfd [0] >= 0 ) { | 652 | if ( pfd [0] >= 0 ) { |
653 | while ( true ) { | 653 | while ( true ) { |
654 | char resultByte; | 654 | char resultByte; |
655 | int n = ::read ( pfd [0], &resultByte, 1 ); | 655 | int n = ::read ( pfd [0], &resultByte, 1 ); |
656 | if ( n == 1 ) { | 656 | if ( n == 1 ) { |
657 | success = false; | 657 | success = false; |
658 | break; | 658 | break; |
659 | } | 659 | } |
660 | if (( n == -1 ) && (( errno == ECHILD ) || ( errno == EINTR ))) | 660 | if (( n == -1 ) && (( errno == ECHILD ) || ( errno == EINTR ))) |
661 | continue; | 661 | continue; |
662 | 662 | ||
663 | break; // success | 663 | break; // success |
664 | } | 664 | } |
665 | ::close ( pfd [0] ); | 665 | ::close ( pfd [0] ); |
666 | } | 666 | } |
667 | } | 667 | } |
668 | if ( success ) | 668 | if ( success ) |
669 | StartingAppList::add( list[0] ); | 669 | StartingAppList::add( list[0] ); |
670 | else | 670 | else |
671 | QMessageBox::warning( 0, "Error", "Could not start the application " + c, "Ok", 0, 0, 0, 1 ); | 671 | QMessageBox::warning( 0, "Error", "Could not start the application " + c, "Ok", 0, 0, 0, 1 ); |
672 | } | 672 | } |
673 | #endif //QT_NO_QWS_MULTIPROCESS | 673 | #endif //QT_NO_QWS_MULTIPROCESS |
674 | } | 674 | } |
675 | 675 | ||
676 | 676 | ||
677 | /*! | 677 | /*! |
678 | Executes the application identfied by \a c, passing \a | 678 | Executes the application identfied by \a c, passing \a |
679 | document if it isn't null. | 679 | document if it isn't null. |
680 | 680 | ||
681 | Note that a better approach might be to send a QCop message to the | 681 | Note that a better approach might be to send a QCop message to the |
682 | application's QPE/Application/\e{appname} channel. | 682 | application's QPE/Application/\e{appname} channel. |
683 | */ | 683 | */ |
684 | void Global::execute( const QString &c, const QString& document ) | 684 | void Global::execute( const QString &c, const QString& document ) |
685 | { | 685 | { |
686 | // ask the server to do the work | 686 | // ask the server to do the work |
687 | #if !defined(QT_NO_COP) | 687 | #if !defined(QT_NO_COP) |
688 | if ( document.isNull() ) { | 688 | if ( document.isNull() ) { |
689 | QCopEnvelope e( "QPE/System", "execute(QString)" ); | 689 | QCopEnvelope e( "QPE/System", "execute(QString)" ); |
690 | e << c; | 690 | e << c; |
691 | } else { | 691 | } else { |
692 | QCopEnvelope e( "QPE/System", "execute(QString,QString)" ); | 692 | QCopEnvelope e( "QPE/System", "execute(QString,QString)" ); |
693 | e << c << document; | 693 | e << c << document; |
694 | } | 694 | } |
695 | #endif | 695 | #endif |
696 | return; | 696 | return; |
697 | } | 697 | } |
698 | 698 | ||
699 | /*! | 699 | /*! |
700 | Returns the string \a s with the characters '\', '"', and '$' quoted | 700 | Returns the string \a s with the characters '\', '"', and '$' quoted |
701 | by a preceeding '\'. | 701 | by a preceeding '\'. |
702 | 702 | ||
703 | \sa stringQuote() | 703 | \sa stringQuote() |
704 | */ | 704 | */ |
705 | QString Global::shellQuote(const QString& s) | 705 | QString Global::shellQuote(const QString& s) |
706 | { | 706 | { |
707 | QString r="\""; | 707 | QString r="\""; |
708 | for (int i=0; i<(int)s.length(); i++) { | 708 | for (int i=0; i<(int)s.length(); i++) { |
709 | char c = s[i].latin1(); | 709 | char c = s[i].latin1(); |
710 | switch (c) { | 710 | switch (c) { |
711 | case '\\': case '"': case '$': | 711 | case '\\': case '"': case '$': |
712 | r+="\\"; | 712 | r+="\\"; |
713 | } | 713 | } |
714 | r += s[i]; | 714 | r += s[i]; |
715 | } | 715 | } |
716 | r += "\""; | 716 | r += "\""; |
717 | return r; | 717 | return r; |
718 | } | 718 | } |
719 | 719 | ||
720 | /*! | 720 | /*! |
721 | Returns the string \a s with the characters '\' and '"' quoted by a | 721 | Returns the string \a s with the characters '\' and '"' quoted by a |
722 | preceeding '\'. | 722 | preceeding '\'. |
723 | 723 | ||
724 | \sa shellQuote() | 724 | \sa shellQuote() |
725 | */ | 725 | */ |
726 | QString Global::stringQuote(const QString& s) | 726 | QString Global::stringQuote(const QString& s) |
727 | { | 727 | { |
728 | QString r="\""; | 728 | QString r="\""; |
729 | for (int i=0; i<(int)s.length(); i++) { | 729 | for (int i=0; i<(int)s.length(); i++) { |
730 | char c = s[i].latin1(); | 730 | char c = s[i].latin1(); |
731 | switch (c) { | 731 | switch (c) { |
732 | case '\\': case '"': | 732 | case '\\': case '"': |
733 | r+="\\"; | 733 | r+="\\"; |
734 | } | 734 | } |
735 | r += s[i]; | 735 | r += s[i]; |
736 | } | 736 | } |
737 | r += "\""; | 737 | r += "\""; |
738 | return r; | 738 | return r; |
739 | } | 739 | } |
740 | 740 | ||
741 | /*! | 741 | /*! |
742 | Finds all documents on the system's document directories which | 742 | Finds all documents on the system's document directories which |
743 | match the filter \a mimefilter, and appends the resulting DocLnk | 743 | match the filter \a mimefilter, and appends the resulting DocLnk |
744 | objects to \a folder. | 744 | objects to \a folder. |
745 | */ | 745 | */ |
746 | void Global::findDocuments(DocLnkSet* folder, const QString &mimefilter) | 746 | void Global::findDocuments(DocLnkSet* folder, const QString &mimefilter) |
747 | { | 747 | { |
748 | QString homedocs = QString(getenv("HOME")) + "/Documents"; | 748 | QString homedocs = QString(getenv("HOME")) + "/Documents"; |
749 | DocLnkSet d(homedocs,mimefilter); | 749 | DocLnkSet d(homedocs,mimefilter); |
750 | folder->appendFrom(d); | 750 | folder->appendFrom(d); |
751 | /** let's do intellegint way of searching these files | 751 | /** let's do intellegint way of searching these files |
752 | * a) the user don't want to check mediums global | 752 | * a) the user don't want to check mediums global |
753 | * b) the user wants to check but use the global options for it | 753 | * b) the user wants to check but use the global options for it |
754 | * c) the user wants to check it but not this medium | 754 | * c) the user wants to check it but not this medium |
755 | * d) the user wants to check and this medium as well | 755 | * d) the user wants to check and this medium as well |
756 | * | 756 | * |
757 | * In all cases we need to apply a different mimefilter to | 757 | * In all cases we need to apply a different mimefilter to |
758 | * the medium. | 758 | * the medium. |
759 | * a) mimefilter.isEmpty() we need to apply the responding filter | 759 | * a) mimefilter.isEmpty() we need to apply the responding filter |
760 | * either the global or the one on the medium | 760 | * either the global or the one on the medium |
761 | * | 761 | * |
762 | * b) mimefilter is set to an application we need to find out if the | 762 | * b) mimefilter is set to an application we need to find out if the |
763 | * mimetypes are included in the mime mask of the medium | 763 | * mimetypes are included in the mime mask of the medium |
764 | */ | 764 | */ |
765 | StorageInfo storage; | 765 | StorageInfo storage; |
766 | const QList<FileSystem> &fs = storage.fileSystems(); | 766 | const QList<FileSystem> &fs = storage.fileSystems(); |
767 | QListIterator<FileSystem> it ( fs ); | 767 | QListIterator<FileSystem> it ( fs ); |
768 | for ( ; it.current(); ++it ) { | 768 | for ( ; it.current(); ++it ) { |
769 | if ( (*it)->isRemovable() ) { // let's find out if we should search on it | 769 | if ( (*it)->isRemovable() ) { // let's find out if we should search on it |
770 | // this is a candidate look at the cf and see if we should search on it | 770 | // this is a candidate look at the cf and see if we should search on it |
771 | QString path = (*it)->path(); | 771 | QString path = (*it)->path(); |
772 | if( !checkStorage((*it)->path() + "/.opiestorage.cf" ) ) | 772 | if( !checkStorage((*it)->path() + "/.opiestorage.cf" ) ) |
773 | continue; | 773 | continue; |
774 | Config conf((*it)->path() + "/.opiestorage.cf", Config::File ); | 774 | Config conf((*it)->path() + "/.opiestorage.cf", Config::File ); |
775 | conf.setGroup("subdirs"); | 775 | conf.setGroup("subdirs"); |
776 | QStringList subDirs = conf.readListEntry("subdirs",':'); | 776 | if (conf.readBoolEntry("wholemedia",true)) { |
777 | if (subDirs.isEmpty()) { | 777 | DocLnkSet ide( path,mimefilter); |
778 | subDirs.append("Documents"); | 778 | folder->appendFrom(ide); |
779 | } | 779 | } else { |
780 | for (unsigned c = 0; c < subDirs.count();++c) { | 780 | QStringList subDirs = conf.readListEntry("subdirs",':'); |
781 | DocLnkSet ide( path+"/"+subDirs[c], mimefilter ); | 781 | if (subDirs.isEmpty()) { |
782 | folder->appendFrom(ide); | 782 | subDirs.append("Documents"); |
783 | } | ||
784 | for (unsigned c = 0; c < subDirs.count();++c) { | ||
785 | DocLnkSet ide( path+"/"+subDirs[c], mimefilter ); | ||
786 | folder->appendFrom(ide); | ||
787 | } | ||
783 | } | 788 | } |
784 | } else if ( (*it)->disk() == "/dev/mtdblock6" || (*it)->disk() == "tmpfs" ) { | 789 | } else if ( (*it)->disk() == "/dev/mtdblock6" || (*it)->disk() == "tmpfs" ) { |
785 | QString path = (*it)->path() + "/Documents"; | 790 | QString path = (*it)->path() + "/Documents"; |
786 | DocLnkSet ide( path, mimefilter ); | 791 | DocLnkSet ide( path, mimefilter ); |
787 | folder->appendFrom(ide); | 792 | folder->appendFrom(ide); |
788 | } | 793 | } |
789 | } | 794 | } |
790 | } | 795 | } |
791 | 796 | ||
792 | QStringList Global::languageList() | 797 | QStringList Global::languageList() |
793 | { | 798 | { |
794 | QString lang = getenv("LANG"); | 799 | QString lang = getenv("LANG"); |
795 | QStringList langs; | 800 | QStringList langs; |
796 | langs.append(lang); | 801 | langs.append(lang); |
797 | int i = lang.find("."); | 802 | int i = lang.find("."); |
798 | if ( i > 0 ) | 803 | if ( i > 0 ) |
799 | lang = lang.left( i ); | 804 | lang = lang.left( i ); |
800 | i = lang.find( "_" ); | 805 | i = lang.find( "_" ); |
801 | if ( i > 0 ) | 806 | if ( i > 0 ) |
802 | langs.append(lang.left(i)); | 807 | langs.append(lang.left(i)); |
803 | return langs; | 808 | return langs; |
804 | } | 809 | } |
805 | 810 | ||
806 | QStringList Global::helpPath() | 811 | QStringList Global::helpPath() |
807 | { | 812 | { |
808 | QString qpeDir = QPEApplication::qpeDir(); | 813 | QString qpeDir = QPEApplication::qpeDir(); |
809 | QStringList path; | 814 | QStringList path; |
810 | QStringList langs = Global::languageList(); | 815 | QStringList langs = Global::languageList(); |
811 | for (QStringList::ConstIterator it = langs.fromLast(); it!=langs.end(); --it) { | 816 | for (QStringList::ConstIterator it = langs.fromLast(); it!=langs.end(); --it) { |
812 | QString lang = *it; | 817 | QString lang = *it; |
813 | if ( !lang.isEmpty() ) | 818 | if ( !lang.isEmpty() ) |
814 | path += qpeDir + "/help/" + lang + "/html"; | 819 | path += qpeDir + "/help/" + lang + "/html"; |
815 | } | 820 | } |
816 | path += qpeDir + "/pics"; | 821 | path += qpeDir + "/pics"; |
817 | path += qpeDir + "/help/html"; | 822 | path += qpeDir + "/help/html"; |
818 | /* we even put english into the en dir so try it as fallback as well for opie */ | 823 | /* we even put english into the en dir so try it as fallback as well for opie */ |
819 | path += qpeDir + "/help/en/html"; | 824 | path += qpeDir + "/help/en/html"; |
820 | path += qpeDir + "/docs"; | 825 | path += qpeDir + "/docs"; |
821 | 826 | ||
822 | 827 | ||
823 | return path; | 828 | return path; |
824 | } | 829 | } |
825 | 830 | ||
826 | 831 | ||
827 | #include "global.moc" | 832 | #include "global.moc" |