-rw-r--r-- | library/global.cpp | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/library/global.cpp b/library/global.cpp index 9b3c51e..42c2729 100644 --- a/library/global.cpp +++ b/library/global.cpp | |||
@@ -351,456 +351,472 @@ void Global::addWords(const QString& dictname, const QStringList& wordlist) | |||
351 | given \a filename. Returns QString::null if there was a problem creating | 351 | given \a filename. Returns QString::null if there was a problem creating |
352 | the directory tree for \a appname. | 352 | the directory tree for \a appname. |
353 | If \a filename contains "/", it is the caller's responsibility to | 353 | If \a filename contains "/", it is the caller's responsibility to |
354 | ensure that those directories exist. | 354 | ensure that those directories exist. |
355 | */ | 355 | */ |
356 | QString Global::applicationFileName(const QString& appname, const QString& filename) | 356 | QString Global::applicationFileName(const QString& appname, const QString& filename) |
357 | { | 357 | { |
358 | QDir d; | 358 | QDir d; |
359 | QString r = getenv("HOME"); | 359 | QString r = getenv("HOME"); |
360 | r += "/Applications/"; | 360 | r += "/Applications/"; |
361 | if ( !QFile::exists( r ) ) | 361 | if ( !QFile::exists( r ) ) |
362 | if ( d.mkdir(r) == false ) | 362 | if ( d.mkdir(r) == false ) |
363 | return QString::null; | 363 | return QString::null; |
364 | r += appname; | 364 | r += appname; |
365 | if ( !QFile::exists( r ) ) | 365 | if ( !QFile::exists( r ) ) |
366 | if ( d.mkdir(r) == false ) | 366 | if ( d.mkdir(r) == false ) |
367 | return QString::null; | 367 | return QString::null; |
368 | r += "/"; r += filename; | 368 | r += "/"; r += filename; |
369 | return r; | 369 | return r; |
370 | } | 370 | } |
371 | 371 | ||
372 | /*! | 372 | /*! |
373 | \internal | 373 | \internal |
374 | */ | 374 | */ |
375 | void Global::createDocDir() | 375 | void Global::createDocDir() |
376 | { | 376 | { |
377 | if ( !docDirCreated ) { | 377 | if ( !docDirCreated ) { |
378 | docDirCreated = TRUE; | 378 | docDirCreated = TRUE; |
379 | mkdir( QPEApplication::documentDir().latin1(), 0755 ); | 379 | mkdir( QPEApplication::documentDir().latin1(), 0755 ); |
380 | } | 380 | } |
381 | } | 381 | } |
382 | 382 | ||
383 | 383 | ||
384 | /*! | 384 | /*! |
385 | Displays a status \a message to the user. This usually appears | 385 | Displays a status \a message to the user. This usually appears |
386 | in the taskbar for a short amount of time, then disappears. | 386 | in the taskbar for a short amount of time, then disappears. |
387 | */ | 387 | */ |
388 | void Global::statusMessage(const QString& message) | 388 | void Global::statusMessage(const QString& message) |
389 | { | 389 | { |
390 | #if!defined(QT_NO_COP) | 390 | #if!defined(QT_NO_COP) |
391 | QCopEnvelope e( "QPE/TaskBar", "message(QString)" ); | 391 | QCopEnvelope e( "QPE/TaskBar", "message(QString)" ); |
392 | e << message; | 392 | e << message; |
393 | #endif | 393 | #endif |
394 | } | 394 | } |
395 | 395 | ||
396 | /*! | 396 | /*! |
397 | \internal | 397 | \internal |
398 | */ | 398 | */ |
399 | void Global::applyStyle() | 399 | void Global::applyStyle() |
400 | { | 400 | { |
401 | #if !defined(QT_NO_COP) | 401 | #if !defined(QT_NO_COP) |
402 | QCopChannel::send( "QPE/System", "applyStyle()" ); | 402 | QCopChannel::send( "QPE/System", "applyStyle()" ); |
403 | #else | 403 | #else |
404 | ((QPEApplication *)qApp)->applyStyle(); // apply without needing QCop for floppy version | 404 | ((QPEApplication *)qApp)->applyStyle(); // apply without needing QCop for floppy version |
405 | #endif | 405 | #endif |
406 | } | 406 | } |
407 | 407 | ||
408 | /*! | 408 | /*! |
409 | \internal | 409 | \internal |
410 | */ | 410 | */ |
411 | QWidget *Global::shutdown( bool ) | 411 | QWidget *Global::shutdown( bool ) |
412 | { | 412 | { |
413 | #if !defined(QT_NO_COP) | 413 | #if !defined(QT_NO_COP) |
414 | QCopChannel::send( "QPE/System", "shutdown()" ); | 414 | QCopChannel::send( "QPE/System", "shutdown()" ); |
415 | #endif | 415 | #endif |
416 | return 0; | 416 | return 0; |
417 | } | 417 | } |
418 | 418 | ||
419 | /*! | 419 | /*! |
420 | \internal | 420 | \internal |
421 | */ | 421 | */ |
422 | QWidget *Global::restart( bool ) | 422 | QWidget *Global::restart( bool ) |
423 | { | 423 | { |
424 | #if !defined(QT_NO_COP) | 424 | #if !defined(QT_NO_COP) |
425 | QCopChannel::send( "QPE/System", "restart()" ); | 425 | QCopChannel::send( "QPE/System", "restart()" ); |
426 | #endif | 426 | #endif |
427 | return 0; | 427 | return 0; |
428 | } | 428 | } |
429 | 429 | ||
430 | /*! | 430 | /*! |
431 | Explicitly show the current input method. | 431 | Explicitly show the current input method. |
432 | 432 | ||
433 | Input methods are indicated in the taskbar by a small icon. If the | 433 | Input methods are indicated in the taskbar by a small icon. If the |
434 | input method is activated (shown) then it takes up some proportion | 434 | input method is activated (shown) then it takes up some proportion |
435 | of the bottom of the screen, to allow the user to interact (input | 435 | of the bottom of the screen, to allow the user to interact (input |
436 | characters) with it. | 436 | characters) with it. |
437 | 437 | ||
438 | \sa hideInputMethod() | 438 | \sa hideInputMethod() |
439 | */ | 439 | */ |
440 | void Global::showInputMethod() | 440 | void Global::showInputMethod() |
441 | { | 441 | { |
442 | #if !defined(QT_NO_COP) | 442 | #if !defined(QT_NO_COP) |
443 | QCopChannel::send( "QPE/TaskBar", "showInputMethod()" ); | 443 | QCopChannel::send( "QPE/TaskBar", "showInputMethod()" ); |
444 | #endif | 444 | #endif |
445 | } | 445 | } |
446 | 446 | ||
447 | /*! | 447 | /*! |
448 | Explicitly hide the current input method. | 448 | Explicitly hide the current input method. |
449 | 449 | ||
450 | The current input method is still indicated in the taskbar, but no | 450 | The current input method is still indicated in the taskbar, but no |
451 | longer takes up screen space, and can no longer be interacted with. | 451 | longer takes up screen space, and can no longer be interacted with. |
452 | 452 | ||
453 | \sa showInputMethod() | 453 | \sa showInputMethod() |
454 | */ | 454 | */ |
455 | void Global::hideInputMethod() | 455 | void Global::hideInputMethod() |
456 | { | 456 | { |
457 | #if !defined(QT_NO_COP) | 457 | #if !defined(QT_NO_COP) |
458 | QCopChannel::send( "QPE/TaskBar", "hideInputMethod()" ); | 458 | QCopChannel::send( "QPE/TaskBar", "hideInputMethod()" ); |
459 | #endif | 459 | #endif |
460 | } | 460 | } |
461 | 461 | ||
462 | 462 | ||
463 | /*! | 463 | /*! |
464 | \internal | 464 | \internal |
465 | */ | 465 | */ |
466 | bool Global::isBuiltinCommand( const QString &name ) | 466 | bool Global::isBuiltinCommand( const QString &name ) |
467 | { | 467 | { |
468 | if(!builtin) | 468 | if(!builtin) |
469 | return FALSE; // yes, it can happen | 469 | return FALSE; // yes, it can happen |
470 | for (int i = 0; builtin[i].file; i++) { | 470 | for (int i = 0; builtin[i].file; i++) { |
471 | if ( builtin[i].file == name ) { | 471 | if ( builtin[i].file == name ) { |
472 | return TRUE; | 472 | return TRUE; |
473 | } | 473 | } |
474 | } | 474 | } |
475 | return FALSE; | 475 | return FALSE; |
476 | } | 476 | } |
477 | 477 | ||
478 | Global::Command* Global::builtin=0; | 478 | Global::Command* Global::builtin=0; |
479 | QGuardedPtr<QWidget> *Global::running=0; | 479 | QGuardedPtr<QWidget> *Global::running=0; |
480 | 480 | ||
481 | /*! | 481 | /*! |
482 | \class Global::Command | 482 | \class Global::Command |
483 | \brief The Global::Command class is internal. | 483 | \brief The Global::Command class is internal. |
484 | \internal | 484 | \internal |
485 | */ | 485 | */ |
486 | 486 | ||
487 | /*! | 487 | /*! |
488 | \internal | 488 | \internal |
489 | */ | 489 | */ |
490 | void Global::setBuiltinCommands( Command* list ) | 490 | void Global::setBuiltinCommands( Command* list ) |
491 | { | 491 | { |
492 | if ( running ) | 492 | if ( running ) |
493 | delete [] running; | 493 | delete [] running; |
494 | 494 | ||
495 | builtin = list; | 495 | builtin = list; |
496 | int count = 0; | 496 | int count = 0; |
497 | if (!builtin) | 497 | if (!builtin) |
498 | return; | 498 | return; |
499 | while ( builtin[count].file ) | 499 | while ( builtin[count].file ) |
500 | count++; | 500 | count++; |
501 | 501 | ||
502 | running = new QGuardedPtr<QWidget> [ count ]; | 502 | running = new QGuardedPtr<QWidget> [ count ]; |
503 | } | 503 | } |
504 | 504 | ||
505 | /*! | 505 | /*! |
506 | \internal | 506 | \internal |
507 | */ | 507 | */ |
508 | void Global::setDocument( QWidget* receiver, const QString& document ) | 508 | void Global::setDocument( QWidget* receiver, const QString& document ) |
509 | { | 509 | { |
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 | extern bool opie_block_style; | ||
610 | |||
611 | QString newpre = QPEApplication::qpeDir ( ) + "/lib/libpreload.so"; | ||
612 | if ( opie_block_style && QFile::exists ( newpre )) { | ||
613 | if ( oldpre && oldpre [0] ) | ||
614 | newpre = newpre + ":" + oldpre; | ||
615 | ::setenv ( "LD_PRELOAD", newpre. latin1( ), 1 ); | ||
616 | qDebug ( "\nPRELOADING\n" ); | ||
617 | } | ||
618 | |||
607 | if ( !::vfork() ) { | 619 | if ( !::vfork() ) { |
608 | for ( int fd = 3; fd < 100; fd++ ) | 620 | for ( int fd = 3; fd < 100; fd++ ) |
609 | ::close( fd ); | 621 | ::close( fd ); |
610 | ::setpgid( ::getpid(), ::getppid() ); | 622 | ::setpgid( ::getpid(), ::getppid() ); |
611 | // Try bindir first, so that foo/bar works too | 623 | // Try bindir first, so that foo/bar works too |
612 | ::execv( qpeDir()+"/bin/"+args[0], (char * const *)args ); | 624 | ::execv( qpeDir()+"/bin/"+args[0], (char * const *)args ); |
613 | ::execvp( args[0], (char * const *)args ); | 625 | ::execvp( args[0], (char * const *)args ); |
614 | _exit( -1 ); | 626 | _exit( -1 ); |
615 | } | 627 | } |
628 | if ( oldpre ) | ||
629 | ::setenv ( "LD_PRELOAD", oldpre, 1 ); | ||
630 | else | ||
631 | ::unsetenv ( "LD_PRELOAD" ); | ||
616 | } | 632 | } |
617 | StartingAppList::add( list[0] ); | 633 | StartingAppList::add( list[0] ); |
618 | #endif //QT_NO_QWS_MULTIPROCESS | 634 | #endif //QT_NO_QWS_MULTIPROCESS |
619 | } | 635 | } |
620 | 636 | ||
621 | 637 | ||
622 | /*! | 638 | /*! |
623 | Executes the application identfied by \a c, passing \a | 639 | Executes the application identfied by \a c, passing \a |
624 | document if it isn't null. | 640 | document if it isn't null. |
625 | 641 | ||
626 | Note that a better approach might be to send a QCop message to the | 642 | Note that a better approach might be to send a QCop message to the |
627 | application's QPE/Application/\e{appname} channel. | 643 | application's QPE/Application/\e{appname} channel. |
628 | */ | 644 | */ |
629 | void Global::execute( const QString &c, const QString& document ) | 645 | void Global::execute( const QString &c, const QString& document ) |
630 | { | 646 | { |
631 | if ( qApp->type() != QApplication::GuiServer ) { | 647 | if ( qApp->type() != QApplication::GuiServer ) { |
632 | // ask the server to do the work | 648 | // ask the server to do the work |
633 | #if !defined(QT_NO_COP) | 649 | #if !defined(QT_NO_COP) |
634 | if ( document.isNull() ) { | 650 | if ( document.isNull() ) { |
635 | QCopEnvelope e( "QPE/System", "execute(QString)" ); | 651 | QCopEnvelope e( "QPE/System", "execute(QString)" ); |
636 | e << c; | 652 | e << c; |
637 | } else { | 653 | } else { |
638 | QCopEnvelope e( "QPE/System", "execute(QString,QString)" ); | 654 | QCopEnvelope e( "QPE/System", "execute(QString,QString)" ); |
639 | e << c << document; | 655 | e << c << document; |
640 | } | 656 | } |
641 | #endif | 657 | #endif |
642 | return; | 658 | return; |
643 | } | 659 | } |
644 | 660 | ||
645 | // Attempt to execute the app using a builtin class for the app first | 661 | // Attempt to execute the app using a builtin class for the app first |
646 | // else try and find it in the bin directory | 662 | // else try and find it in the bin directory |
647 | if (builtin) { | 663 | if (builtin) { |
648 | for (int i = 0; builtin[i].file; i++) { | 664 | for (int i = 0; builtin[i].file; i++) { |
649 | if ( builtin[i].file == c ) { | 665 | if ( builtin[i].file == c ) { |
650 | if ( running[i] ) { | 666 | if ( running[i] ) { |
651 | if ( !document.isNull() && builtin[i].documentary ) | 667 | if ( !document.isNull() && builtin[i].documentary ) |
652 | setDocument(running[i], document); | 668 | setDocument(running[i], document); |
653 | running[i]->raise(); | 669 | running[i]->raise(); |
654 | running[i]->show(); | 670 | running[i]->show(); |
655 | running[i]->setActiveWindow(); | 671 | running[i]->setActiveWindow(); |
656 | } else { | 672 | } else { |
657 | running[i] = builtin[i].func( builtin[i].maximized ); | 673 | running[i] = builtin[i].func( builtin[i].maximized ); |
658 | } | 674 | } |
659 | #ifndef QT_NO_COP | 675 | #ifndef QT_NO_COP |
660 | QCopEnvelope e("QPE/System", "notBusy(QString)" ); | 676 | QCopEnvelope e("QPE/System", "notBusy(QString)" ); |
661 | e << c; // that was quick ;-) | 677 | e << c; // that was quick ;-) |
662 | #endif | 678 | #endif |
663 | return; | 679 | return; |
664 | } | 680 | } |
665 | } | 681 | } |
666 | } | 682 | } |
667 | 683 | ||
668 | //Global::invoke(c, document); | 684 | //Global::invoke(c, document); |
669 | 685 | ||
670 | // Convert the command line in to a list of arguments | 686 | // Convert the command line in to a list of arguments |
671 | QStringList list = QStringList::split(QRegExp(" *"),c); | 687 | QStringList list = QStringList::split(QRegExp(" *"),c); |
672 | 688 | ||
673 | #if !defined(QT_NO_COP) | 689 | #if !defined(QT_NO_COP) |
674 | QString ap=list[0]; | 690 | QString ap=list[0]; |
675 | 691 | ||
676 | qDebug("executing %s", ap.latin1() ); | 692 | qDebug("executing %s", ap.latin1() ); |
677 | 693 | ||
678 | /* if need be, sending a qcop message will result in an invoke, see | 694 | /* if need be, sending a qcop message will result in an invoke, see |
679 | preceeding function */ | 695 | preceeding function */ |
680 | invoke( ap ); | 696 | invoke( ap ); |
681 | //{ QCopEnvelope env( ("QPE/Application/" + ap).latin1(), "raise()" ); } | 697 | //{ QCopEnvelope env( ("QPE/Application/" + ap).latin1(), "raise()" ); } |
682 | if ( !document.isEmpty() ) { | 698 | if ( !document.isEmpty() ) { |
683 | QCopEnvelope env( ("QPE/Application/" + ap).latin1(), "setDocument(QString)" ); | 699 | QCopEnvelope env( ("QPE/Application/" + ap).latin1(), "setDocument(QString)" ); |
684 | env << document; | 700 | env << document; |
685 | } | 701 | } |
686 | #endif | 702 | #endif |
687 | } | 703 | } |
688 | 704 | ||
689 | /*! | 705 | /*! |
690 | Returns the string \a s with the characters '\', '"', and '$' quoted | 706 | Returns the string \a s with the characters '\', '"', and '$' quoted |
691 | by a preceeding '\'. | 707 | by a preceeding '\'. |
692 | 708 | ||
693 | \sa stringQuote() | 709 | \sa stringQuote() |
694 | */ | 710 | */ |
695 | QString Global::shellQuote(const QString& s) | 711 | QString Global::shellQuote(const QString& s) |
696 | { | 712 | { |
697 | QString r="\""; | 713 | QString r="\""; |
698 | for (int i=0; i<(int)s.length(); i++) { | 714 | for (int i=0; i<(int)s.length(); i++) { |
699 | char c = s[i].latin1(); | 715 | char c = s[i].latin1(); |
700 | switch (c) { | 716 | switch (c) { |
701 | case '\\': case '"': case '$': | 717 | case '\\': case '"': case '$': |
702 | r+="\\"; | 718 | r+="\\"; |
703 | } | 719 | } |
704 | r += s[i]; | 720 | r += s[i]; |
705 | } | 721 | } |
706 | r += "\""; | 722 | r += "\""; |
707 | return r; | 723 | return r; |
708 | } | 724 | } |
709 | 725 | ||
710 | /*! | 726 | /*! |
711 | Returns the string \a s with the characters '\' and '"' quoted by a | 727 | Returns the string \a s with the characters '\' and '"' quoted by a |
712 | preceeding '\'. | 728 | preceeding '\'. |
713 | 729 | ||
714 | \sa shellQuote() | 730 | \sa shellQuote() |
715 | */ | 731 | */ |
716 | QString Global::stringQuote(const QString& s) | 732 | QString Global::stringQuote(const QString& s) |
717 | { | 733 | { |
718 | QString r="\""; | 734 | QString r="\""; |
719 | for (int i=0; i<(int)s.length(); i++) { | 735 | for (int i=0; i<(int)s.length(); i++) { |
720 | char c = s[i].latin1(); | 736 | char c = s[i].latin1(); |
721 | switch (c) { | 737 | switch (c) { |
722 | case '\\': case '"': | 738 | case '\\': case '"': |
723 | r+="\\"; | 739 | r+="\\"; |
724 | } | 740 | } |
725 | r += s[i]; | 741 | r += s[i]; |
726 | } | 742 | } |
727 | r += "\""; | 743 | r += "\""; |
728 | return r; | 744 | return r; |
729 | } | 745 | } |
730 | 746 | ||
731 | /*! | 747 | /*! |
732 | Finds all documents on the system's document directories which | 748 | Finds all documents on the system's document directories which |
733 | match the filter \a mimefilter, and appends the resulting DocLnk | 749 | match the filter \a mimefilter, and appends the resulting DocLnk |
734 | objects to \a folder. | 750 | objects to \a folder. |
735 | */ | 751 | */ |
736 | void Global::findDocuments(DocLnkSet* folder, const QString &mimefilter) | 752 | void Global::findDocuments(DocLnkSet* folder, const QString &mimefilter) |
737 | { | 753 | { |
738 | QString homedocs = QString(getenv("HOME")) + "/Documents"; | 754 | QString homedocs = QString(getenv("HOME")) + "/Documents"; |
739 | DocLnkSet d(homedocs,mimefilter); | 755 | DocLnkSet d(homedocs,mimefilter); |
740 | folder->appendFrom(d); | 756 | folder->appendFrom(d); |
741 | /** let's do intellegint way of searching these files | 757 | /** let's do intellegint way of searching these files |
742 | * a) the user don't want to check mediums global | 758 | * a) the user don't want to check mediums global |
743 | * b) the user wants to check but use the global options for it | 759 | * b) the user wants to check but use the global options for it |
744 | * c) the user wants to check it but not this medium | 760 | * c) the user wants to check it but not this medium |
745 | * d) the user wants to check and this medium as well | 761 | * d) the user wants to check and this medium as well |
746 | * | 762 | * |
747 | * In all cases we need to apply a different mimefilter to | 763 | * In all cases we need to apply a different mimefilter to |
748 | * the medium. | 764 | * the medium. |
749 | * a) mimefilter.isEmpty() we need to apply the responding filter | 765 | * a) mimefilter.isEmpty() we need to apply the responding filter |
750 | * either the global or the one on the medium | 766 | * either the global or the one on the medium |
751 | * | 767 | * |
752 | * b) mimefilter is set to an application we need to find out if the | 768 | * b) mimefilter is set to an application we need to find out if the |
753 | * mimetypes are included in the mime mask of the medium | 769 | * mimetypes are included in the mime mask of the medium |
754 | */ | 770 | */ |
755 | StorageInfo storage; | 771 | StorageInfo storage; |
756 | const QList<FileSystem> &fs = storage.fileSystems(); | 772 | const QList<FileSystem> &fs = storage.fileSystems(); |
757 | QListIterator<FileSystem> it ( fs ); | 773 | QListIterator<FileSystem> it ( fs ); |
758 | for ( ; it.current(); ++it ) { | 774 | for ( ; it.current(); ++it ) { |
759 | if ( (*it)->isRemovable() ) { // let's find out if we should search on it | 775 | if ( (*it)->isRemovable() ) { // let's find out if we should search on it |
760 | // this is a candidate look at the cf and see if we should search on it | 776 | // this is a candidate look at the cf and see if we should search on it |
761 | QString path = (*it)->path(); | 777 | QString path = (*it)->path(); |
762 | if( !checkStorage((*it)->path() + "/.opiestorage.cf" ) ) | 778 | if( !checkStorage((*it)->path() + "/.opiestorage.cf" ) ) |
763 | continue; | 779 | continue; |
764 | DocLnkSet ide( path, mimefilter ); | 780 | DocLnkSet ide( path, mimefilter ); |
765 | folder->appendFrom(ide); | 781 | folder->appendFrom(ide); |
766 | } else if ( (*it)->disk() == "/dev/mtdblock6" || (*it)->disk() == "tmpfs" ) { | 782 | } else if ( (*it)->disk() == "/dev/mtdblock6" || (*it)->disk() == "tmpfs" ) { |
767 | QString path = (*it)->path() + "/Documents"; | 783 | QString path = (*it)->path() + "/Documents"; |
768 | DocLnkSet ide( path, mimefilter ); | 784 | DocLnkSet ide( path, mimefilter ); |
769 | folder->appendFrom(ide); | 785 | folder->appendFrom(ide); |
770 | } | 786 | } |
771 | } | 787 | } |
772 | } | 788 | } |
773 | 789 | ||
774 | QStringList Global::languageList() | 790 | QStringList Global::languageList() |
775 | { | 791 | { |
776 | QString lang = getenv("LANG"); | 792 | QString lang = getenv("LANG"); |
777 | QStringList langs; | 793 | QStringList langs; |
778 | langs.append(lang); | 794 | langs.append(lang); |
779 | int i = lang.find("."); | 795 | int i = lang.find("."); |
780 | if ( i > 0 ) | 796 | if ( i > 0 ) |
781 | lang = lang.left( i ); | 797 | lang = lang.left( i ); |
782 | i = lang.find( "_" ); | 798 | i = lang.find( "_" ); |
783 | if ( i > 0 ) | 799 | if ( i > 0 ) |
784 | langs.append(lang.left(i)); | 800 | langs.append(lang.left(i)); |
785 | return langs; | 801 | return langs; |
786 | } | 802 | } |
787 | 803 | ||
788 | QStringList Global::helpPath() | 804 | QStringList Global::helpPath() |
789 | { | 805 | { |
790 | QStringList path; | 806 | QStringList path; |
791 | QStringList langs = Global::languageList(); | 807 | QStringList langs = Global::languageList(); |
792 | for (QStringList::ConstIterator it = langs.fromLast(); it!=langs.end(); --it) { | 808 | for (QStringList::ConstIterator it = langs.fromLast(); it!=langs.end(); --it) { |
793 | QString lang = *it; | 809 | QString lang = *it; |
794 | if ( !lang.isEmpty() ) | 810 | if ( !lang.isEmpty() ) |
795 | path += QPEApplication::qpeDir() + "/help/" + lang + "/html"; | 811 | path += QPEApplication::qpeDir() + "/help/" + lang + "/html"; |
796 | } | 812 | } |
797 | path += QPEApplication::qpeDir() + "/pics"; | 813 | path += QPEApplication::qpeDir() + "/pics"; |
798 | path += QPEApplication::qpeDir() + "/help/html"; | 814 | path += QPEApplication::qpeDir() + "/help/html"; |
799 | path += QPEApplication::qpeDir() + "/docs"; | 815 | path += QPEApplication::qpeDir() + "/docs"; |
800 | 816 | ||
801 | 817 | ||
802 | return path; | 818 | return path; |
803 | } | 819 | } |
804 | 820 | ||
805 | 821 | ||
806 | #include "global.moc" | 822 | #include "global.moc" |