-rw-r--r-- | library/global.cpp | 16 |
1 files changed, 1 insertions, 15 deletions
diff --git a/library/global.cpp b/library/global.cpp index 2162e02..d6ba84f 100644 --- a/library/global.cpp +++ b/library/global.cpp | |||
@@ -510,216 +510,202 @@ void Global::setDocument( QWidget* receiver, const QString& document ) | |||
510 | Emitter emitter(receiver,document); | 510 | Emitter emitter(receiver,document); |
511 | } | 511 | } |
512 | 512 | ||
513 | /*! | 513 | /*! |
514 | \internal | 514 | \internal |
515 | */ | 515 | */ |
516 | bool Global::terminateBuiltin( const QString& n ) | 516 | bool Global::terminateBuiltin( const QString& n ) |
517 | { | 517 | { |
518 | if (!builtin) | 518 | if (!builtin) |
519 | return FALSE; | 519 | return FALSE; |
520 | for (int i = 0; builtin[i].file; i++) { | 520 | for (int i = 0; builtin[i].file; i++) { |
521 | if ( builtin[i].file == n ) { | 521 | if ( builtin[i].file == n ) { |
522 | delete running[i]; | 522 | delete running[i]; |
523 | return TRUE; | 523 | return TRUE; |
524 | } | 524 | } |
525 | } | 525 | } |
526 | return FALSE; | 526 | return FALSE; |
527 | } | 527 | } |
528 | 528 | ||
529 | /*! | 529 | /*! |
530 | \internal | 530 | \internal |
531 | */ | 531 | */ |
532 | void Global::terminate( const AppLnk* app ) | 532 | void Global::terminate( const AppLnk* app ) |
533 | { | 533 | { |
534 | //if ( terminateBuiltin(app->exec()) ) return; // maybe? haven't tried this | 534 | //if ( terminateBuiltin(app->exec()) ) return; // maybe? haven't tried this |
535 | 535 | ||
536 | #ifndef QT_NO_COP | 536 | #ifndef QT_NO_COP |
537 | QCString channel = "QPE/Application/" + app->exec().utf8(); | 537 | QCString channel = "QPE/Application/" + app->exec().utf8(); |
538 | if ( QCopChannel::isRegistered(channel) ) { | 538 | if ( QCopChannel::isRegistered(channel) ) { |
539 | QCopEnvelope e(channel, "quit()"); | 539 | QCopEnvelope e(channel, "quit()"); |
540 | } | 540 | } |
541 | #endif | 541 | #endif |
542 | } | 542 | } |
543 | 543 | ||
544 | /*! | 544 | /*! |
545 | Low-level function to run command \a c. | 545 | Low-level function to run command \a c. |
546 | 546 | ||
547 | \warning Do not use this function. Use execute instead. | 547 | \warning Do not use this function. Use execute instead. |
548 | 548 | ||
549 | \sa execute() | 549 | \sa execute() |
550 | */ | 550 | */ |
551 | void Global::invoke(const QString &c) | 551 | void Global::invoke(const QString &c) |
552 | { | 552 | { |
553 | // Convert the command line in to a list of arguments | 553 | // Convert the command line in to a list of arguments |
554 | QStringList list = QStringList::split(QRegExp(" *"),c); | 554 | QStringList list = QStringList::split(QRegExp(" *"),c); |
555 | 555 | ||
556 | #if !defined(QT_NO_COP) | 556 | #if !defined(QT_NO_COP) |
557 | QString ap=list[0]; | 557 | QString ap=list[0]; |
558 | // see if the application is already running | 558 | // see if the application is already running |
559 | // XXX should lock file /tmp/qcop-msg-ap | 559 | // XXX should lock file /tmp/qcop-msg-ap |
560 | if ( QCopChannel::isRegistered( ("QPE/Application/" + ap).latin1() ) ) { | 560 | if ( QCopChannel::isRegistered( ("QPE/Application/" + ap).latin1() ) ) { |
561 | // If the channel is already register, the app is already running, so show it. | 561 | // If the channel is already register, the app is already running, so show it. |
562 | { QCopEnvelope env( ("QPE/Application/" + ap).latin1(), "raise()" ); } | 562 | { QCopEnvelope env( ("QPE/Application/" + ap).latin1(), "raise()" ); } |
563 | 563 | ||
564 | QCopEnvelope e("QPE/System", "notBusy(QString)" ); | 564 | QCopEnvelope e("QPE/System", "notBusy(QString)" ); |
565 | e << ap; | 565 | e << ap; |
566 | return; | 566 | return; |
567 | } | 567 | } |
568 | // XXX should unlock file /tmp/qcop-msg-ap | 568 | // XXX should unlock file /tmp/qcop-msg-ap |
569 | //see if it is being started | 569 | //see if it is being started |
570 | if ( StartingAppList::isStarting( ap ) ) { | 570 | if ( StartingAppList::isStarting( ap ) ) { |
571 | QCopEnvelope e("QPE/System", "notBusy(QString)" ); | 571 | QCopEnvelope e("QPE/System", "notBusy(QString)" ); |
572 | e << ap; | 572 | e << ap; |
573 | return; | 573 | return; |
574 | } | 574 | } |
575 | 575 | ||
576 | #endif | 576 | #endif |
577 | 577 | ||
578 | #ifdef QT_NO_QWS_MULTIPROCESS | 578 | #ifdef QT_NO_QWS_MULTIPROCESS |
579 | QMessageBox::warning( 0, "Error", "Could not find the application " + c, "Ok", 0, 0, 0, 1 ); | 579 | QMessageBox::warning( 0, "Error", "Could not find the application " + c, "Ok", 0, 0, 0, 1 ); |
580 | #else | 580 | #else |
581 | 581 | ||
582 | QStrList slist; | 582 | QStrList slist; |
583 | unsigned int j; | 583 | unsigned int j; |
584 | for ( j = 0; j < list.count(); j++ ) | 584 | for ( j = 0; j < list.count(); j++ ) |
585 | slist.append( list[j].utf8() ); | 585 | slist.append( list[j].utf8() ); |
586 | 586 | ||
587 | const char **args = new (const char *)[slist.count() + 1]; | 587 | const char **args = new (const char *)[slist.count() + 1]; |
588 | for ( j = 0; j < slist.count(); j++ ) | 588 | for ( j = 0; j < slist.count(); j++ ) |
589 | args[j] = slist.at(j); | 589 | args[j] = slist.at(j); |
590 | args[j] = NULL; | 590 | args[j] = NULL; |
591 | 591 | ||
592 | #if !defined(QT_NO_COP) | 592 | #if !defined(QT_NO_COP) |
593 | // an attempt to show a wait... | 593 | // an attempt to show a wait... |
594 | // more logic should be used, but this will be fine for the moment... | 594 | // more logic should be used, but this will be fine for the moment... |
595 | QCopEnvelope ( "QPE/System", "busy()" ); | 595 | QCopEnvelope ( "QPE/System", "busy()" ); |
596 | #endif | 596 | #endif |
597 | 597 | ||
598 | #ifdef HAVE_QUICKEXEC | 598 | #ifdef HAVE_QUICKEXEC |
599 | QString libexe = qpeDir()+"/binlib/lib"+args[0] + ".so"; | 599 | QString libexe = qpeDir()+"/binlib/lib"+args[0] + ".so"; |
600 | qDebug("libfile = %s", libexe.latin1() ); | 600 | qDebug("libfile = %s", libexe.latin1() ); |
601 | if ( QFile::exists( libexe ) ) { | 601 | if ( QFile::exists( libexe ) ) { |
602 | qDebug("calling quickexec %s", libexe.latin1() ); | 602 | qDebug("calling quickexec %s", libexe.latin1() ); |
603 | quickexecv( libexe.utf8().data(), (const char **)args ); | 603 | quickexecv( libexe.utf8().data(), (const char **)args ); |
604 | } else | 604 | } else |
605 | #endif | 605 | #endif |
606 | { | 606 | { |
607 | char *oldpre = ::getenv ( "LD_PRELOAD" ); | ||
608 | |||
609 | QString newpre = QPEApplication::qpeDir ( ) + "/lib/libpreload.so"; | ||
610 | if ( QFile::exists ( newpre )) { | ||
611 | if ( oldpre && oldpre [0] ) | ||
612 | newpre = newpre + ":" + oldpre; | ||
613 | ::setenv ( "LD_PRELOAD", newpre. latin1( ), 1 ); | ||
614 | qDebug ( "\nPRELOADING\n" ); | ||
615 | } | ||
616 | |||
617 | if ( !::vfork() ) { | 607 | if ( !::vfork() ) { |
618 | for ( int fd = 3; fd < 100; fd++ ) | 608 | for ( int fd = 3; fd < 100; fd++ ) |
619 | ::close( fd ); | 609 | ::close( fd ); |
620 | ::setpgid( ::getpid(), ::getppid() ); | 610 | ::setpgid( ::getpid(), ::getppid() ); |
621 | // Try bindir first, so that foo/bar works too | 611 | // Try bindir first, so that foo/bar works too |
622 | ::execv( qpeDir()+"/bin/"+args[0], (char * const *)args ); | 612 | ::execv( qpeDir()+"/bin/"+args[0], (char * const *)args ); |
623 | ::execvp( args[0], (char * const *)args ); | 613 | ::execvp( args[0], (char * const *)args ); |
624 | _exit( -1 ); | 614 | _exit( -1 ); |
625 | } | 615 | } |
626 | if ( oldpre ) | ||
627 | ::setenv ( "LD_PRELOAD", oldpre, 1 ); | ||
628 | else | ||
629 | ::unsetenv ( "LD_PRELOAD" ); | ||
630 | } | 616 | } |
631 | StartingAppList::add( list[0] ); | 617 | StartingAppList::add( list[0] ); |
632 | #endif //QT_NO_QWS_MULTIPROCESS | 618 | #endif //QT_NO_QWS_MULTIPROCESS |
633 | } | 619 | } |
634 | 620 | ||
635 | 621 | ||
636 | /*! | 622 | /*! |
637 | Executes the application identfied by \a c, passing \a | 623 | Executes the application identfied by \a c, passing \a |
638 | document if it isn't null. | 624 | document if it isn't null. |
639 | 625 | ||
640 | Note that a better approach might be to send a QCop message to the | 626 | Note that a better approach might be to send a QCop message to the |
641 | application's QPE/Application/\e{appname} channel. | 627 | application's QPE/Application/\e{appname} channel. |
642 | */ | 628 | */ |
643 | void Global::execute( const QString &c, const QString& document ) | 629 | void Global::execute( const QString &c, const QString& document ) |
644 | { | 630 | { |
645 | if ( qApp->type() != QApplication::GuiServer ) { | 631 | if ( qApp->type() != QApplication::GuiServer ) { |
646 | // ask the server to do the work | 632 | // ask the server to do the work |
647 | #if !defined(QT_NO_COP) | 633 | #if !defined(QT_NO_COP) |
648 | if ( document.isNull() ) { | 634 | if ( document.isNull() ) { |
649 | QCopEnvelope e( "QPE/System", "execute(QString)" ); | 635 | QCopEnvelope e( "QPE/System", "execute(QString)" ); |
650 | e << c; | 636 | e << c; |
651 | } else { | 637 | } else { |
652 | QCopEnvelope e( "QPE/System", "execute(QString,QString)" ); | 638 | QCopEnvelope e( "QPE/System", "execute(QString,QString)" ); |
653 | e << c << document; | 639 | e << c << document; |
654 | } | 640 | } |
655 | #endif | 641 | #endif |
656 | return; | 642 | return; |
657 | } | 643 | } |
658 | 644 | ||
659 | // Attempt to execute the app using a builtin class for the app first | 645 | // Attempt to execute the app using a builtin class for the app first |
660 | // else try and find it in the bin directory | 646 | // else try and find it in the bin directory |
661 | if (builtin) { | 647 | if (builtin) { |
662 | for (int i = 0; builtin[i].file; i++) { | 648 | for (int i = 0; builtin[i].file; i++) { |
663 | if ( builtin[i].file == c ) { | 649 | if ( builtin[i].file == c ) { |
664 | if ( running[i] ) { | 650 | if ( running[i] ) { |
665 | if ( !document.isNull() && builtin[i].documentary ) | 651 | if ( !document.isNull() && builtin[i].documentary ) |
666 | setDocument(running[i], document); | 652 | setDocument(running[i], document); |
667 | running[i]->raise(); | 653 | running[i]->raise(); |
668 | running[i]->show(); | 654 | running[i]->show(); |
669 | running[i]->setActiveWindow(); | 655 | running[i]->setActiveWindow(); |
670 | } else { | 656 | } else { |
671 | running[i] = builtin[i].func( builtin[i].maximized ); | 657 | running[i] = builtin[i].func( builtin[i].maximized ); |
672 | } | 658 | } |
673 | #ifndef QT_NO_COP | 659 | #ifndef QT_NO_COP |
674 | QCopEnvelope e("QPE/System", "notBusy(QString)" ); | 660 | QCopEnvelope e("QPE/System", "notBusy(QString)" ); |
675 | e << c; // that was quick ;-) | 661 | e << c; // that was quick ;-) |
676 | #endif | 662 | #endif |
677 | return; | 663 | return; |
678 | } | 664 | } |
679 | } | 665 | } |
680 | } | 666 | } |
681 | 667 | ||
682 | //Global::invoke(c, document); | 668 | //Global::invoke(c, document); |
683 | 669 | ||
684 | // Convert the command line in to a list of arguments | 670 | // Convert the command line in to a list of arguments |
685 | QStringList list = QStringList::split(QRegExp(" *"),c); | 671 | QStringList list = QStringList::split(QRegExp(" *"),c); |
686 | 672 | ||
687 | #if !defined(QT_NO_COP) | 673 | #if !defined(QT_NO_COP) |
688 | QString ap=list[0]; | 674 | QString ap=list[0]; |
689 | 675 | ||
690 | qDebug("executing %s", ap.latin1() ); | 676 | qDebug("executing %s", ap.latin1() ); |
691 | 677 | ||
692 | /* if need be, sending a qcop message will result in an invoke, see | 678 | /* if need be, sending a qcop message will result in an invoke, see |
693 | preceeding function */ | 679 | preceeding function */ |
694 | invoke( ap ); | 680 | invoke( ap ); |
695 | //{ QCopEnvelope env( ("QPE/Application/" + ap).latin1(), "raise()" ); } | 681 | //{ QCopEnvelope env( ("QPE/Application/" + ap).latin1(), "raise()" ); } |
696 | if ( !document.isEmpty() ) { | 682 | if ( !document.isEmpty() ) { |
697 | QCopEnvelope env( ("QPE/Application/" + ap).latin1(), "setDocument(QString)" ); | 683 | QCopEnvelope env( ("QPE/Application/" + ap).latin1(), "setDocument(QString)" ); |
698 | env << document; | 684 | env << document; |
699 | } | 685 | } |
700 | #endif | 686 | #endif |
701 | } | 687 | } |
702 | 688 | ||
703 | /*! | 689 | /*! |
704 | Returns the string \a s with the characters '\', '"', and '$' quoted | 690 | Returns the string \a s with the characters '\', '"', and '$' quoted |
705 | by a preceeding '\'. | 691 | by a preceeding '\'. |
706 | 692 | ||
707 | \sa stringQuote() | 693 | \sa stringQuote() |
708 | */ | 694 | */ |
709 | QString Global::shellQuote(const QString& s) | 695 | QString Global::shellQuote(const QString& s) |
710 | { | 696 | { |
711 | QString r="\""; | 697 | QString r="\""; |
712 | for (int i=0; i<(int)s.length(); i++) { | 698 | for (int i=0; i<(int)s.length(); i++) { |
713 | char c = s[i].latin1(); | 699 | char c = s[i].latin1(); |
714 | switch (c) { | 700 | switch (c) { |
715 | case '\\': case '"': case '$': | 701 | case '\\': case '"': case '$': |
716 | r+="\\"; | 702 | r+="\\"; |
717 | } | 703 | } |
718 | r += s[i]; | 704 | r += s[i]; |
719 | } | 705 | } |
720 | r += "\""; | 706 | r += "\""; |
721 | return r; | 707 | return r; |
722 | } | 708 | } |
723 | 709 | ||
724 | /*! | 710 | /*! |
725 | Returns the string \a s with the characters '\' and '"' quoted by a | 711 | Returns the string \a s with the characters '\' and '"' quoted by a |