summaryrefslogtreecommitdiff
path: root/library/global.cpp
authorerik <erik>2007-01-24 19:46:19 (UTC)
committer erik <erik>2007-01-24 19:46:19 (UTC)
commita017bf21dd89159052f2f7a3fbc043a24956c08c (patch) (unidiff)
tree008be2b62ee5487dc55b8a7c7f043c94268f8362 /library/global.cpp
parenta4a7bd22feb060a80e20c81cded43cc24f5cd423 (diff)
downloadopie-a017bf21dd89159052f2f7a3fbc043a24956c08c.zip
opie-a017bf21dd89159052f2f7a3fbc043a24956c08c.tar.gz
opie-a017bf21dd89159052f2f7a3fbc043a24956c08c.tar.bz2
Every file in this commit has a memory leak of some kind or another. I think
all of them are minor and should not effect properly running code. But if I were you I would give libstocks and the stockticker plugin in Today a wide berth. That library is atrocious.
Diffstat (limited to 'library/global.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--library/global.cpp30
1 files changed, 17 insertions, 13 deletions
diff --git a/library/global.cpp b/library/global.cpp
index 7bdd0b1..1895006 100644
--- a/library/global.cpp
+++ b/library/global.cpp
@@ -350,492 +350,496 @@ QString Global::applicationFileName(const QString& appname, const QString& filen
350 return r; 350 return r;
351} 351}
352 352
353/*! 353/*!
354 \internal 354 \internal
355*/ 355*/
356void Global::createDocDir() 356void Global::createDocDir()
357{ 357{
358 if ( !docDirCreated ) { 358 if ( !docDirCreated ) {
359 docDirCreated = TRUE; 359 docDirCreated = TRUE;
360 mkdir( QPEApplication::documentDir().latin1(), 0755 ); 360 mkdir( QPEApplication::documentDir().latin1(), 0755 );
361 } 361 }
362} 362}
363 363
364 364
365/*! 365/*!
366 Displays a status \a message to the user. This usually appears 366 Displays a status \a message to the user. This usually appears
367 in the taskbar for a short amount of time, then disappears. 367 in the taskbar for a short amount of time, then disappears.
368*/ 368*/
369void Global::statusMessage(const QString& message) 369void Global::statusMessage(const QString& message)
370{ 370{
371#if !defined(QT_NO_COP) 371#if !defined(QT_NO_COP)
372 QCopEnvelope e( "QPE/TaskBar", "message(QString)" ); 372 QCopEnvelope e( "QPE/TaskBar", "message(QString)" );
373 e << message; 373 e << message;
374#endif 374#endif
375} 375}
376 376
377/*! 377/*!
378 \internal 378 \internal
379*/ 379*/
380void Global::applyStyle() 380void Global::applyStyle()
381{ 381{
382#if !defined(QT_NO_COP) 382#if !defined(QT_NO_COP)
383 QCopChannel::send( "QPE/System", "applyStyle()" ); 383 QCopChannel::send( "QPE/System", "applyStyle()" );
384#else 384#else
385 ((QPEApplication *)qApp)->applyStyle(); // apply without needing QCop for floppy version 385 ((QPEApplication *)qApp)->applyStyle(); // apply without needing QCop for floppy version
386#endif 386#endif
387} 387}
388 388
389/*! 389/*!
390 \internal 390 \internal
391*/ 391*/
392QWidget *Global::shutdown( bool ) 392QWidget *Global::shutdown( bool )
393{ 393{
394#if !defined(QT_NO_COP) 394#if !defined(QT_NO_COP)
395 QCopChannel::send( "QPE/System", "shutdown()" ); 395 QCopChannel::send( "QPE/System", "shutdown()" );
396#endif 396#endif
397 return 0; 397 return 0;
398} 398}
399 399
400/*! 400/*!
401 \internal 401 \internal
402*/ 402*/
403QWidget *Global::restart( bool ) 403QWidget *Global::restart( bool )
404{ 404{
405#if !defined(QT_NO_COP) 405#if !defined(QT_NO_COP)
406 QCopChannel::send( "QPE/System", "restart()" ); 406 QCopChannel::send( "QPE/System", "restart()" );
407#endif 407#endif
408 return 0; 408 return 0;
409} 409}
410 410
411/*! 411/*!
412 Explicitly show the current input method. 412 Explicitly show the current input method.
413 413
414 Input methods are indicated in the taskbar by a small icon. If the 414 Input methods are indicated in the taskbar by a small icon. If the
415 input method is activated (shown) then it takes up some proportion 415 input method is activated (shown) then it takes up some proportion
416 of the bottom of the screen, to allow the user to interact (input 416 of the bottom of the screen, to allow the user to interact (input
417 characters) with it. 417 characters) with it.
418 418
419 \sa hideInputMethod() 419 \sa hideInputMethod()
420*/ 420*/
421void Global::showInputMethod() 421void Global::showInputMethod()
422{ 422{
423#if !defined(QT_NO_COP) 423#if !defined(QT_NO_COP)
424 QCopChannel::send( "QPE/TaskBar", "showInputMethod()" ); 424 QCopChannel::send( "QPE/TaskBar", "showInputMethod()" );
425#endif 425#endif
426} 426}
427 427
428/*! 428/*!
429 Explicitly hide the current input method. 429 Explicitly hide the current input method.
430 430
431 The current input method is still indicated in the taskbar, but no 431 The current input method is still indicated in the taskbar, but no
432 longer takes up screen space, and can no longer be interacted with. 432 longer takes up screen space, and can no longer be interacted with.
433 433
434 \sa showInputMethod() 434 \sa showInputMethod()
435*/ 435*/
436void Global::hideInputMethod() 436void Global::hideInputMethod()
437{ 437{
438#if !defined(QT_NO_COP) 438#if !defined(QT_NO_COP)
439 QCopChannel::send( "QPE/TaskBar", "hideInputMethod()" ); 439 QCopChannel::send( "QPE/TaskBar", "hideInputMethod()" );
440#endif 440#endif
441} 441}
442 442
443 443
444/*! 444/*!
445 \internal 445 \internal
446*/ 446*/
447bool Global::isBuiltinCommand( const QString &name ) 447bool Global::isBuiltinCommand( const QString &name )
448{ 448{
449 if(!builtin) 449 if(!builtin)
450 return FALSE; // yes, it can happen 450 return FALSE; // yes, it can happen
451 for (int i = 0; builtin[i].file; i++) { 451 for (int i = 0; builtin[i].file; i++) {
452 if ( builtin[i].file == name ) { 452 if ( builtin[i].file == name ) {
453 return TRUE; 453 return TRUE;
454 } 454 }
455 } 455 }
456 return FALSE; 456 return FALSE;
457} 457}
458 458
459Global::Command* Global::builtin=0; 459Global::Command* Global::builtin=0;
460QGuardedPtr<QWidget> *Global::running=0; 460QGuardedPtr<QWidget> *Global::running=0;
461 461
462/*! 462/*!
463 \class Global::Command 463 \class Global::Command
464 \brief The Global::Command class is internal. 464 \brief The Global::Command class is internal.
465 \internal 465 \internal
466*/ 466*/
467 467
468/*! 468/*!
469 \internal 469 \internal
470*/ 470*/
471void Global::setBuiltinCommands( Command* list ) 471void Global::setBuiltinCommands( Command* list )
472{ 472{
473 if ( running ) 473 if ( running )
474 delete [] running; 474 delete [] running;
475 475
476 builtin = list; 476 builtin = list;
477 int count = 0; 477 int count = 0;
478 if (!builtin) 478 if (!builtin)
479 return; 479 return;
480 while ( builtin[count].file ) 480 while ( builtin[count].file )
481 count++; 481 count++;
482 482
483 running = new QGuardedPtr<QWidget> [ count ]; 483 running = new QGuardedPtr<QWidget> [ count ];
484} 484}
485 485
486/*! 486/*!
487 \internal 487 \internal
488*/ 488*/
489void Global::setDocument( QWidget* receiver, const QString& document ) 489void Global::setDocument( QWidget* receiver, const QString& document )
490{ 490{
491 Emitter emitter(receiver,document); 491 Emitter emitter(receiver,document);
492} 492}
493 493
494/*! 494/*!
495 \internal 495 \internal
496*/ 496*/
497bool Global::terminateBuiltin( const QString& n ) 497bool Global::terminateBuiltin( const QString& n )
498{ 498{
499 if (!builtin) 499 if (!builtin)
500 return FALSE; 500 return FALSE;
501 for (int i = 0; builtin[i].file; i++) { 501 for (int i = 0; builtin[i].file; i++) {
502 if ( builtin[i].file == n ) { 502 if ( builtin[i].file == n ) {
503 delete running[i]; 503 delete running[i];
504 return TRUE; 504 return TRUE;
505 } 505 }
506 } 506 }
507 return FALSE; 507 return FALSE;
508} 508}
509 509
510/*! 510/*!
511 \internal 511 \internal
512*/ 512*/
513void Global::terminate( const AppLnk* app ) 513void Global::terminate( const AppLnk* app )
514{ 514{
515 //if ( terminateBuiltin(app->exec()) ) return; // maybe? haven't tried this 515 //if ( terminateBuiltin(app->exec()) ) return; // maybe? haven't tried this
516 516
517#ifndef QT_NO_COP 517#ifndef QT_NO_COP
518 QCString channel = "QPE/Application/" + app->exec().utf8(); 518 QCString channel = "QPE/Application/" + app->exec().utf8();
519 if ( QCopChannel::isRegistered(channel) ) { 519 if ( QCopChannel::isRegistered(channel) ) {
520 QCopEnvelope e(channel, "quit()"); 520 QCopEnvelope e(channel, "quit()");
521 } 521 }
522#endif 522#endif
523} 523}
524 524
525/*! 525/*!
526 Low-level function to run command \a c. 526 Low-level function to run command \a c.
527 527
528 \warning Do not use this function. Use execute instead. 528 \warning Do not use this function. Use execute instead.
529 529
530 \sa execute() 530 \sa execute()
531*/ 531*/
532void Global::invoke(const QString &c) 532void Global::invoke(const QString &c)
533{ 533{
534 // Convert the command line in to a list of arguments 534 // Convert the command line in to a list of arguments
535 QStringList list = QStringList::split(QRegExp(" *"),c); 535 QStringList list = QStringList::split(QRegExp(" *"),c);
536 536
537#if !defined(QT_NO_COP) 537#if !defined(QT_NO_COP)
538 QString ap=list[0]; 538 QString ap=list[0];
539 // see if the application is already running 539 // see if the application is already running
540 // XXX should lock file /tmp/qcop-msg-ap 540 // XXX should lock file /tmp/qcop-msg-ap
541 if ( QCopChannel::isRegistered( ("QPE/Application/" + ap).latin1() ) ) { 541 if ( QCopChannel::isRegistered( ("QPE/Application/" + ap).latin1() ) ) {
542 // If the channel is already register, the app is already running, so show it. 542 // If the channel is already register, the app is already running, so show it.
543 { QCopEnvelope env( ("QPE/Application/" + ap).latin1(), "raise()" ); } 543 {
544 544 QCopEnvelope env( ("QPE/Application/" + ap).latin1(), "raise()" );
545 //QCopEnvelope e("QPE/System", "notBusy(QString)" ); 545 }
546 //e << ap; 546
547 return; 547 //QCopEnvelope e("QPE/System", "notBusy(QString)" );
548 //e << ap;
549 return;
548 } 550 }
549 // XXX should unlock file /tmp/qcop-msg-ap 551 // XXX should unlock file /tmp/qcop-msg-ap
550 //see if it is being started 552 //see if it is being started
551 if ( StartingAppList::isStarting( ap ) ) { 553 if ( StartingAppList::isStarting( ap ) ) {
552 // FIXME take it out for now, since it leads to a much to short showing of wait if 554 // FIXME take it out for now, since it leads to a much to short showing of wait if
553 // some entry is clicked. 555 // some entry is clicked.
554 // Real cause is that ::execute is called twice for document tab. But it would need some larger changes 556 // Real cause is that ::execute is called twice for document tab. But it would need some larger changes
555 // to fix that, and with future syncs with qtopia 1.6 it will change anyway big time since somebody there 557 // to fix that, and with future syncs with qtopia 1.6 it will change anyway big time since somebody there
556 // had the idea that an apploader belongs to the launcher ... 558 // had the idea that an apploader belongs to the launcher ...
557 //QCopEnvelope e("QPE/System", "notBusy(QString)" ); 559 //QCopEnvelope e("QPE/System", "notBusy(QString)" );
558 //e << ap; 560 //e << ap;
559 return; 561 return;
560 } 562 }
561 563
562#endif 564#endif
563 565
564#ifdef QT_NO_QWS_MULTIPROCESS 566#ifdef QT_NO_QWS_MULTIPROCESS
565 QMessageBox::warning( 0, "Error", "Could not find the application " + c, "Ok", 0, 0, 0, 1 ); 567 QMessageBox::warning( 0, "Error", "Could not find the application " + c, "Ok", 0, 0, 0, 1 );
566#else 568#else
567 569
568 QStrList slist; 570 QStrList slist;
569 unsigned int j; 571 unsigned int j;
570 for ( j = 0; j < list.count(); j++ ) 572 for ( j = 0; j < list.count(); j++ )
571 slist.append( list[j].utf8() ); 573 slist.append( list[j].utf8() );
572 574
573 const char **args = new const char *[slist.count() + 1]; 575 const char **args = new const char *[slist.count() + 1];
574 for ( j = 0; j < slist.count(); j++ ) 576 for ( j = 0; j < slist.count(); j++ )
575 args[j] = slist.at(j); 577 args[j] = slist.at(j);
578
576 args[j] = NULL; 579 args[j] = NULL;
577 580
578#if !defined(QT_NO_COP) 581#if !defined(QT_NO_COP)
579 // an attempt to show a wait... 582 // an attempt to show a wait...
580 // more logic should be used, but this will be fine for the moment... 583 // more logic should be used, but this will be fine for the moment...
581 QCopEnvelope ( "QPE/System", "busy()" ); 584 QCopEnvelope ( "QPE/System", "busy()" );
582#endif 585#endif
583 586
584#ifdef HAVE_QUICKEXEC 587#ifdef HAVE_QUICKEXEC
585#ifdef Q_OS_MACX 588#ifdef Q_OS_MACX
586 QString libexe = qpeDir()+"/binlib/lib"+args[0] + ".dylib"; 589 QString libexe = qpeDir()+"/binlib/lib"+args[0] + ".dylib";
587#else 590#else
588 QString libexe = qpeDir()+"/binlib/lib"+args[0] + ".so"; 591 QString libexe = qpeDir()+"/binlib/lib"+args[0] + ".so";
589#endif 592#endif
590 qDebug("libfile = %s", libexe.latin1() ); 593 qDebug("libfile = %s", libexe.latin1() );
591 if ( QFile::exists( libexe ) ) { 594 if ( QFile::exists( libexe ) ) {
592 qDebug("calling quickexec %s", libexe.latin1() ); 595 qDebug("calling quickexec %s", libexe.latin1() );
593 quickexecv( libexe.utf8().data(), (const char **)args ); 596 quickexecv( libexe.utf8().data(), (const char **)args );
594 } else 597 } else
595#endif 598#endif
596 { 599 {
597 bool success = false; 600 bool success = false;
598 int pfd [2]; 601 int pfd [2];
599 if ( ::pipe ( pfd ) < 0 ) 602 if ( ::pipe ( pfd ) < 0 )
600 pfd [0] = pfd [1] = -1; 603 pfd [0] = pfd [1] = -1;
601 604
602 pid_t pid = ::fork ( ); 605 pid_t pid = ::fork ( );
603 606
604 if ( pid == 0 ) { // child 607 if ( pid == 0 ) { // child
605 for ( int fd = 3; fd < 100; fd++ ) { 608 for ( int fd = 3; fd < 100; fd++ ) {
606 if ( fd != pfd [1] ) 609 if ( fd != pfd [1] )
607 ::close ( fd ); 610 ::close ( fd );
608 } 611 }
609 ::setpgid ( ::getpid ( ), ::getppid ( )); 612 ::setpgid ( ::getpid ( ), ::getppid ( ));
610 613
611 // Closing of fd[1] indicates that the execvp succeeded! 614 // Closing of fd[1] indicates that the execvp succeeded!
612 if ( pfd [1] >= 0 ) 615 if ( pfd [1] >= 0 )
613 ::fcntl ( pfd [1], F_SETFD, FD_CLOEXEC ); 616 ::fcntl ( pfd [1], F_SETFD, FD_CLOEXEC );
614 617
615 // Try bindir first, so that foo/bar works too 618 // Try bindir first, so that foo/bar works too
616 ::execv ( qpeDir ( ) + "/bin/" + args [0], (char * const *) args ); 619 ::execv ( qpeDir ( ) + "/bin/" + args [0], (char * const *) args );
617 ::execvp ( args [0], (char * const *) args ); 620 ::execvp ( args [0], (char * const *) args );
618 621
619 char resultByte = 1; 622 char resultByte = 1;
620 if ( pfd [1] >= 0 ) 623 if ( pfd [1] >= 0 )
621 ::write ( pfd [1], &resultByte, 1 ); 624 ::write ( pfd [1], &resultByte, 1 );
622 ::_exit ( -1 ); 625 ::_exit ( -1 );
623 } 626 }
624 else if ( pid > 0 ) { 627 else if ( pid > 0 ) {
625 success = true; 628 success = true;
626 629
627 if ( pfd [1] >= 0 ) 630 if ( pfd [1] >= 0 )
628 ::close ( pfd [1] ); 631 ::close ( pfd [1] );
629 if ( pfd [0] >= 0 ) { 632 if ( pfd [0] >= 0 ) {
630 while ( true ) { 633 while ( true ) {
631 char resultByte; 634 char resultByte;
632 int n = ::read ( pfd [0], &resultByte, 1 ); 635 int n = ::read ( pfd [0], &resultByte, 1 );
633 if ( n == 1 ) { 636 if ( n == 1 ) {
634 success = false; 637 success = false;
635 break; 638 break;
636 } 639 }
637 if (( n == -1 ) && (( errno == ECHILD ) || ( errno == EINTR ))) 640 if (( n == -1 ) && (( errno == ECHILD ) || ( errno == EINTR )))
638 continue; 641 continue;
639 642
640 break; // success 643 break; // success
641 } 644 }
642 ::close ( pfd [0] ); 645 ::close ( pfd [0] );
643 } 646 }
644 } 647 }
645 if ( success ) 648 if ( success )
646 StartingAppList::add( list[0] ); 649 StartingAppList::add( list[0] );
647 else 650 else
648 QMessageBox::warning( 0, "Error", "Could not start the application " + c, "Ok", 0, 0, 0, 1 ); 651 QMessageBox::warning( 0, "Error", "Could not start the application " + c, "Ok", 0, 0, 0, 1 );
649 } 652 }
653 delete [] args;
650#endif //QT_NO_QWS_MULTIPROCESS 654#endif //QT_NO_QWS_MULTIPROCESS
651} 655}
652 656
653 657
654/*! 658/*!
655 Executes the application identfied by \a c, passing \a 659 Executes the application identfied by \a c, passing \a
656 document if it isn't null. 660 document if it isn't null.
657 661
658 Note that a better approach might be to send a QCop message to the 662 Note that a better approach might be to send a QCop message to the
659 application's QPE/Application/\e{appname} channel. 663 application's QPE/Application/\e{appname} channel.
660*/ 664*/
661void Global::execute( const QString &c, const QString& document ) 665void Global::execute( const QString &c, const QString& document )
662{ 666{
663 // ask the server to do the work 667 // ask the server to do the work
664#if !defined(QT_NO_COP) 668#if !defined(QT_NO_COP)
665 if ( document.isNull() ) { 669 if ( document.isNull() ) {
666 QCopEnvelope e( "QPE/System", "execute(QString)" ); 670 QCopEnvelope e( "QPE/System", "execute(QString)" );
667 e << c; 671 e << c;
668 } else { 672 } else {
669 QCopEnvelope e( "QPE/System", "execute(QString,QString)" ); 673 QCopEnvelope e( "QPE/System", "execute(QString,QString)" );
670 e << c << document; 674 e << c << document;
671 } 675 }
672#endif 676#endif
673 return; 677 return;
674} 678}
675 679
676/*! 680/*!
677 Returns the string \a s with the characters '\', '"', and '$' quoted 681 Returns the string \a s with the characters '\', '"', and '$' quoted
678 by a preceeding '\'. 682 by a preceeding '\'.
679 683
680 \sa stringQuote() 684 \sa stringQuote()
681*/ 685*/
682QString Global::shellQuote(const QString& s) 686QString Global::shellQuote(const QString& s)
683{ 687{
684 QString r="\""; 688 QString r="\"";
685 for (int i=0; i<(int)s.length(); i++) { 689 for (int i=0; i<(int)s.length(); i++) {
686 char c = s[i].latin1(); 690 char c = s[i].latin1();
687 switch (c) { 691 switch (c) {
688 case '\\': case '"': case '$': 692 case '\\': case '"': case '$':
689 r+="\\"; 693 r+="\\";
690 } 694 }
691 r += s[i]; 695 r += s[i];
692 } 696 }
693 r += "\""; 697 r += "\"";
694 return r; 698 return r;
695} 699}
696 700
697/*! 701/*!
698 Returns the string \a s with the characters '\' and '"' quoted by a 702 Returns the string \a s with the characters '\' and '"' quoted by a
699 preceeding '\'. 703 preceeding '\'.
700 704
701 \sa shellQuote() 705 \sa shellQuote()
702*/ 706*/
703QString Global::stringQuote(const QString& s) 707QString Global::stringQuote(const QString& s)
704{ 708{
705 QString r="\""; 709 QString r="\"";
706 for (int i=0; i<(int)s.length(); i++) { 710 for (int i=0; i<(int)s.length(); i++) {
707 char c = s[i].latin1(); 711 char c = s[i].latin1();
708 switch (c) { 712 switch (c) {
709 case '\\': case '"': 713 case '\\': case '"':
710 r+="\\"; 714 r+="\\";
711 } 715 }
712 r += s[i]; 716 r += s[i];
713 } 717 }
714 r += "\""; 718 r += "\"";
715 return r; 719 return r;
716} 720}
717 721
718/*! 722/*!
719 Finds all documents on the system's document directories which 723 Finds all documents on the system's document directories which
720 match the filter \a mimefilter, and appends the resulting DocLnk 724 match the filter \a mimefilter, and appends the resulting DocLnk
721 objects to \a folder. 725 objects to \a folder.
722*/ 726*/
723void Global::findDocuments(DocLnkSet* folder, const QString &mimefilter) 727void Global::findDocuments(DocLnkSet* folder, const QString &mimefilter)
724{ 728{
725 QString homedocs = QString(getenv("HOME")) + "/Documents"; 729 QString homedocs = QString(getenv("HOME")) + "/Documents";
726 DocLnkSet d(homedocs,mimefilter); 730 DocLnkSet d(homedocs,mimefilter);
727 folder->appendFrom(d); 731 folder->appendFrom(d);
728 /** let's do intellegint way of searching these files 732 /** let's do intellegint way of searching these files
729 * a) the user don't want to check mediums global 733 * a) the user don't want to check mediums global
730 * b) the user wants to check but use the global options for it 734 * b) the user wants to check but use the global options for it
731 * c) the user wants to check it but not this medium 735 * c) the user wants to check it but not this medium
732 * d) the user wants to check and this medium as well 736 * d) the user wants to check and this medium as well
733 * 737 *
734 * In all cases we need to apply a different mimefilter to 738 * In all cases we need to apply a different mimefilter to
735 * the medium. 739 * the medium.
736 * a) mimefilter.isEmpty() we need to apply the responding filter 740 * a) mimefilter.isEmpty() we need to apply the responding filter
737 * either the global or the one on the medium 741 * either the global or the one on the medium
738 * 742 *
739 * b) mimefilter is set to an application we need to find out if the 743 * b) mimefilter is set to an application we need to find out if the
740 * mimetypes are included in the mime mask of the medium 744 * mimetypes are included in the mime mask of the medium
741 */ 745 */
742 StorageInfo storage; 746 StorageInfo storage;
743 const QList<FileSystem> &fs = storage.fileSystems(); 747 const QList<FileSystem> &fs = storage.fileSystems();
744 QListIterator<FileSystem> it ( fs ); 748 QListIterator<FileSystem> it ( fs );
745 for ( ; it.current(); ++it ) { 749 for ( ; it.current(); ++it ) {
746 if ( (*it)->isRemovable() ) { // let's find out if we should search on it 750 if ( (*it)->isRemovable() ) { // let's find out if we should search on it
747 // this is a candidate look at the cf and see if we should search on it 751 // this is a candidate look at the cf and see if we should search on it
748 QString path = (*it)->path(); 752 QString path = (*it)->path();
749 Config conf((*it)->path() + "/.opiestorage.cf", Config::File ); 753 Config conf((*it)->path() + "/.opiestorage.cf", Config::File );
750 conf.setGroup("main"); 754 conf.setGroup("main");
751 if (!conf.readBoolEntry("check",true)) { 755 if (!conf.readBoolEntry("check",true)) {
752 continue; 756 continue;
753 } 757 }
754 conf.setGroup("subdirs"); 758 conf.setGroup("subdirs");
755 if (conf.readBoolEntry("wholemedia",true)) { 759 if (conf.readBoolEntry("wholemedia",true)) {
756 DocLnkSet ide( path,mimefilter); 760 DocLnkSet ide( path,mimefilter);
757 folder->appendFrom(ide); 761 folder->appendFrom(ide);
758 } else { 762 } else {
759 QStringList subDirs = conf.readListEntry("subdirs",':'); 763 QStringList subDirs = conf.readListEntry("subdirs",':');
760 if (subDirs.isEmpty()) { 764 if (subDirs.isEmpty()) {
761 subDirs.append("Documents"); 765 subDirs.append("Documents");
762 } 766 }
763 for (unsigned c = 0; c < subDirs.count();++c) { 767 for (unsigned c = 0; c < subDirs.count();++c) {
764 DocLnkSet ide( path+"/"+subDirs[c], mimefilter ); 768 DocLnkSet ide( path+"/"+subDirs[c], mimefilter );
765 folder->appendFrom(ide); 769 folder->appendFrom(ide);
766 } 770 }
767 } 771 }
768 } else if ( (*it)->disk() == "/dev/mtdblock6" || (*it)->disk() == "tmpfs" ) { 772 } else if ( (*it)->disk() == "/dev/mtdblock6" || (*it)->disk() == "tmpfs" ) {
769 QString path = (*it)->path() + "/Documents"; 773 QString path = (*it)->path() + "/Documents";
770 DocLnkSet ide( path, mimefilter ); 774 DocLnkSet ide( path, mimefilter );
771 folder->appendFrom(ide); 775 folder->appendFrom(ide);
772 } 776 }
773 } 777 }
774} 778}
775 779
776QStringList Global::languageList() 780QStringList Global::languageList()
777{ 781{
778 QString lang = getenv("LANG"); 782 QString lang = getenv("LANG");
779 QStringList langs; 783 QStringList langs;
780 langs.append(lang); 784 langs.append(lang);
781 int i = lang.find("."); 785 int i = lang.find(".");
782 if ( i > 0 ) 786 if ( i > 0 )
783 lang = lang.left( i ); 787 lang = lang.left( i );
784 i = lang.find( "_" ); 788 i = lang.find( "_" );
785 if ( i > 0 ) 789 if ( i > 0 )
786 langs.append(lang.left(i)); 790 langs.append(lang.left(i));
787 return langs; 791 return langs;
788} 792}
789 793
790QStringList Global::helpPath() 794QStringList Global::helpPath()
791{ 795{
792 QString qpeDir = QPEApplication::qpeDir(); 796 QString qpeDir = QPEApplication::qpeDir();
793 QStringList path; 797 QStringList path;
794 QStringList langs = Global::languageList(); 798 QStringList langs = Global::languageList();
795 for (QStringList::ConstIterator it = langs.fromLast(); it!=langs.end(); --it) { 799 for (QStringList::ConstIterator it = langs.fromLast(); it!=langs.end(); --it) {
796 QString lang = *it; 800 QString lang = *it;
797 if ( !lang.isEmpty() ) 801 if ( !lang.isEmpty() )
798 path += qpeDir + "/help/" + lang + "/html"; 802 path += qpeDir + "/help/" + lang + "/html";
799 } 803 }
800 path += qpeDir + "/pics"; 804 path += qpeDir + "/pics";
801 path += qpeDir + "/help/html"; 805 path += qpeDir + "/help/html";
802 /* we even put english into the en dir so try it as fallback as well for opie */ 806 /* we even put english into the en dir so try it as fallback as well for opie */
803 path += qpeDir + "/help/en/html"; 807 path += qpeDir + "/help/en/html";
804 path += qpeDir + "/docs"; 808 path += qpeDir + "/docs";
805 809
806 810
807 return path; 811 return path;
808} 812}
809 813
810/*! 814/*!
811 \internal 815 \internal
812 Truncate file to size specified 816 Truncate file to size specified
813 \a f must be an open file 817 \a f must be an open file
814 \a size must be a positive value 818 \a size must be a positive value
815 */ 819 */
816bool Global::truncateFile(QFile &f, int size){ 820bool Global::truncateFile(QFile &f, int size){
817 if (!f.isOpen()) 821 if (!f.isOpen())
818 return FALSE; 822 return FALSE;
819 823
820 return ::ftruncate(f.handle(), size) != -1; 824 return ::ftruncate(f.handle(), size) != -1;
821} 825}
822 826
823 827
824 828
825 829
826// #if defined(Q_OS_UNIX) && defined(Q_WS_QWS) 830// #if defined(Q_OS_UNIX) && defined(Q_WS_QWS)
827// extern int qws_display_id; 831// extern int qws_display_id;
828// #endif 832// #endif
829 833
830/*! 834/*!
831 /internal 835 /internal
832 Returns the default system path for storing temporary files. 836 Returns the default system path for storing temporary files.
833 Note: This does not it ensure that the provided directory exists 837 Note: This does not it ensure that the provided directory exists
834*/ 838*/
835QString Global::tempDir() 839QString Global::tempDir()
836{ 840{
837 QString result; 841 QString result;
838#ifdef Q_OS_UNIX 842#ifdef Q_OS_UNIX
839#ifdef Q_WS_QWS 843#ifdef Q_WS_QWS
840 result = QString("/tmp/qtopia-%1/").arg(QString::number(qws_display_id)); 844 result = QString("/tmp/qtopia-%1/").arg(QString::number(qws_display_id));
841#else 845#else