summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--microkde/kdecore/kstandarddirs.cpp3
1 files changed, 3 insertions, 0 deletions
diff --git a/microkde/kdecore/kstandarddirs.cpp b/microkde/kdecore/kstandarddirs.cpp
index 75205d6..500426b 100644
--- a/microkde/kdecore/kstandarddirs.cpp
+++ b/microkde/kdecore/kstandarddirs.cpp
@@ -481,1024 +481,1027 @@ static void lookupDirectory(const QString& path, const QString &relPart,
481 continue; // No match 481 continue; // No match
482*/ 482*/
483//US this should do the same: 483//US this should do the same:
484 pos = regexp.match(fn); 484 pos = regexp.match(fn);
485 if (!pos == 0) 485 if (!pos == 0)
486 continue; // No match 486 continue; // No match
487 } 487 }
488 488
489//US if ( S_ISREG( buff.st_mode)) 489//US if ( S_ISREG( buff.st_mode))
490 if ( pathfnInfo.isFile()) 490 if ( pathfnInfo.isFile())
491 { 491 {
492 if (!uniq || !relList.contains(relPart + fn)) 492 if (!uniq || !relList.contains(relPart + fn))
493 { 493 {
494 list.append( pathfn ); 494 list.append( pathfn );
495 relList.append( relPart + fn ); 495 relList.append( relPart + fn );
496 } 496 }
497 } 497 }
498 } 498 }
499//US closedir( dp ); 499//US closedir( dp );
500 } 500 }
501 else 501 else
502 { 502 {
503 // We look for a single file. 503 // We look for a single file.
504 QString fn = pattern; 504 QString fn = pattern;
505 QString pathfn = path + fn; 505 QString pathfn = path + fn;
506//US struct stat buff; 506//US struct stat buff;
507 QFileInfo pathfnInfo(QFile::encodeName(pathfn)); 507 QFileInfo pathfnInfo(QFile::encodeName(pathfn));
508 508
509 509
510//US if ( stat( QFile::encodeName(pathfn), &buff ) != 0 ) 510//US if ( stat( QFile::encodeName(pathfn), &buff ) != 0 )
511 if ( pathfnInfo.isReadable() == false ) 511 if ( pathfnInfo.isReadable() == false )
512 return; // File not found 512 return; // File not found
513 513
514//US if ( S_ISREG( buff.st_mode)) 514//US if ( S_ISREG( buff.st_mode))
515 if ( pathfnInfo.isFile()) 515 if ( pathfnInfo.isFile())
516 { 516 {
517 if (!uniq || !relList.contains(relPart + fn)) 517 if (!uniq || !relList.contains(relPart + fn))
518 { 518 {
519 list.append( pathfn ); 519 list.append( pathfn );
520 relList.append( relPart + fn ); 520 relList.append( relPart + fn );
521 } 521 }
522 } 522 }
523 } 523 }
524} 524}
525 525
526static void lookupPrefix(const QString& prefix, const QString& relpath, 526static void lookupPrefix(const QString& prefix, const QString& relpath,
527 const QString& relPart, 527 const QString& relPart,
528 const QRegExp &regexp, 528 const QRegExp &regexp,
529 QStringList& list, 529 QStringList& list,
530 QStringList& relList, 530 QStringList& relList,
531 bool recursive, bool uniq) 531 bool recursive, bool uniq)
532{ 532{
533 if (relpath.isNull()) { 533 if (relpath.isNull()) {
534 lookupDirectory(prefix, relPart, regexp, list, 534 lookupDirectory(prefix, relPart, regexp, list,
535 relList, recursive, uniq); 535 relList, recursive, uniq);
536 return; 536 return;
537 } 537 }
538 QString path; 538 QString path;
539 QString rest; 539 QString rest;
540 540
541 if (relpath.length()) 541 if (relpath.length())
542 { 542 {
543 int slash = relpath.find('/'); 543 int slash = relpath.find('/');
544 if (slash < 0) 544 if (slash < 0)
545 rest = relpath.left(relpath.length() - 1); 545 rest = relpath.left(relpath.length() - 1);
546 else { 546 else {
547 path = relpath.left(slash); 547 path = relpath.left(slash);
548 rest = relpath.mid(slash + 1); 548 rest = relpath.mid(slash + 1);
549 } 549 }
550 } 550 }
551 assert(prefix.at(prefix.length() - 1) == '/'); 551 assert(prefix.at(prefix.length() - 1) == '/');
552 552
553//US struct stat buff; 553//US struct stat buff;
554 554
555 if (path.contains('*') || path.contains('?')) { 555 if (path.contains('*') || path.contains('?')) {
556 QRegExp pathExp(path, true, true); 556 QRegExp pathExp(path, true, true);
557 //USDIR *dp = opendir( QFile::encodeName(prefix) ); 557 //USDIR *dp = opendir( QFile::encodeName(prefix) );
558 QDir dp(QFile::encodeName(prefix)); 558 QDir dp(QFile::encodeName(prefix));
559 559
560 //USif (!dp) 560 //USif (!dp)
561 if (!dp.exists()) 561 if (!dp.exists())
562 { 562 {
563 return; 563 return;
564 } 564 }
565 565
566 //USstruct dirent *ep; 566 //USstruct dirent *ep;
567 567
568 QString _dot("."); 568 QString _dot(".");
569 QString _dotdot(".."); 569 QString _dotdot("..");
570 570
571 //USwhile( ( ep = readdir( dp ) ) != 0L ) 571 //USwhile( ( ep = readdir( dp ) ) != 0L )
572 QStringList direntries = dp.entryList(); 572 QStringList direntries = dp.entryList();
573 QStringList::Iterator it = direntries.begin(); 573 QStringList::Iterator it = direntries.begin();
574 574
575 while ( it != list.end() ) // for each file... 575 while ( it != list.end() ) // for each file...
576 { 576 {
577//US QString fn( QFile::decodeName(ep->d_name)); 577//US QString fn( QFile::decodeName(ep->d_name));
578 QString fn = (*it); // dp.entryList() already encodes the strings 578 QString fn = (*it); // dp.entryList() already encodes the strings
579 it++; 579 it++;
580 580
581 if (fn == _dot || fn == _dotdot || fn.at(fn.length() - 1) == '~') 581 if (fn == _dot || fn == _dotdot || fn.at(fn.length() - 1) == '~')
582 continue; 582 continue;
583 583
584#ifdef DESKTOP_VERSION 584#ifdef DESKTOP_VERSION
585 585
586 if (pathExp.search(fn) == -1) 586 if (pathExp.search(fn) == -1)
587 continue; // No match 587 continue; // No match
588 588
589#else 589#else
590//US this should do the same: 590//US this should do the same:
591 if (pathExp.find(fn, 0) == -1) 591 if (pathExp.find(fn, 0) == -1)
592 continue; // No match 592 continue; // No match
593#endif 593#endif
594 QString rfn = relPart+fn; 594 QString rfn = relPart+fn;
595 fn = prefix + fn; 595 fn = prefix + fn;
596//US if ( stat( QFile::encodeName(fn), &buff ) != 0 ) 596//US if ( stat( QFile::encodeName(fn), &buff ) != 0 )
597 QFileInfo fnInfo(QFile::encodeName(fn)); 597 QFileInfo fnInfo(QFile::encodeName(fn));
598 if ( fnInfo.isReadable() == false ) 598 if ( fnInfo.isReadable() == false )
599 { 599 {
600//US kdDebug() << "Error statting " << fn << " : " << perror << endl; 600//US kdDebug() << "Error statting " << fn << " : " << perror << endl;
601 continue; // Couldn't stat (e.g. no permissions) 601 continue; // Couldn't stat (e.g. no permissions)
602 } 602 }
603 //US if ( S_ISDIR( buff.st_mode )) 603 //US if ( S_ISDIR( buff.st_mode ))
604 if ( fnInfo.isDir() ) 604 if ( fnInfo.isDir() )
605 605
606 lookupPrefix(fn + '/', rest, rfn + '/', regexp, list, relList, recursive, uniq); 606 lookupPrefix(fn + '/', rest, rfn + '/', regexp, list, relList, recursive, uniq);
607 } 607 }
608 608
609 //USclosedir( dp ); 609 //USclosedir( dp );
610 } else { 610 } else {
611 // Don't stat, if the dir doesn't exist we will find out 611 // Don't stat, if the dir doesn't exist we will find out
612 // when we try to open it. 612 // when we try to open it.
613 lookupPrefix(prefix + path + '/', rest, 613 lookupPrefix(prefix + path + '/', rest,
614 relPart + path + '/', regexp, list, 614 relPart + path + '/', regexp, list,
615 relList, recursive, uniq); 615 relList, recursive, uniq);
616 } 616 }
617} 617}
618 618
619QStringList 619QStringList
620KStandardDirs::findAllResources( const char *type, 620KStandardDirs::findAllResources( const char *type,
621 const QString& filter, 621 const QString& filter,
622 bool recursive, 622 bool recursive,
623 bool uniq, 623 bool uniq,
624 QStringList &relList) const 624 QStringList &relList) const
625{ 625{
626 QStringList list; 626 QStringList list;
627 if (filter.at(0) == '/') // absolute paths we return 627 if (filter.at(0) == '/') // absolute paths we return
628 { 628 {
629 list.append( filter); 629 list.append( filter);
630 return list; 630 return list;
631 } 631 }
632 632
633 QString filterPath; 633 QString filterPath;
634 QString filterFile; 634 QString filterFile;
635 635
636 if (filter.length()) 636 if (filter.length())
637 { 637 {
638 int slash = filter.findRev('/'); 638 int slash = filter.findRev('/');
639 if (slash < 0) 639 if (slash < 0)
640 filterFile = filter; 640 filterFile = filter;
641 else { 641 else {
642 filterPath = filter.left(slash + 1); 642 filterPath = filter.left(slash + 1);
643 filterFile = filter.mid(slash + 1); 643 filterFile = filter.mid(slash + 1);
644 } 644 }
645 } 645 }
646 checkConfig(); 646 checkConfig();
647 647
648 if (d && d->restrictionsActive && (strcmp(type, "data")==0)) 648 if (d && d->restrictionsActive && (strcmp(type, "data")==0))
649 applyDataRestrictions(filter); 649 applyDataRestrictions(filter);
650 QStringList candidates = resourceDirs(type); 650 QStringList candidates = resourceDirs(type);
651 if (filterFile.isEmpty()) 651 if (filterFile.isEmpty())
652 filterFile = "*"; 652 filterFile = "*";
653 653
654 QRegExp regExp(filterFile, true, true); 654 QRegExp regExp(filterFile, true, true);
655 for (QStringList::ConstIterator it = candidates.begin(); 655 for (QStringList::ConstIterator it = candidates.begin();
656 it != candidates.end(); it++) 656 it != candidates.end(); it++)
657 { 657 {
658 lookupPrefix(*it, filterPath, "", regExp, list, 658 lookupPrefix(*it, filterPath, "", regExp, list,
659 relList, recursive, uniq); 659 relList, recursive, uniq);
660 } 660 }
661 return list; 661 return list;
662} 662}
663 663
664QStringList 664QStringList
665KStandardDirs::findAllResources( const char *type, 665KStandardDirs::findAllResources( const char *type,
666 const QString& filter, 666 const QString& filter,
667 bool recursive, 667 bool recursive,
668 bool uniq) const 668 bool uniq) const
669{ 669{
670 QStringList relList; 670 QStringList relList;
671 return findAllResources(type, filter, recursive, uniq, relList); 671 return findAllResources(type, filter, recursive, uniq, relList);
672} 672}
673 673
674QString 674QString
675KStandardDirs::realPath(const QString &dirname) 675KStandardDirs::realPath(const QString &dirname)
676{ 676{
677#ifdef _WIN32_ 677#ifdef _WIN32_
678 return dirname; 678 return dirname;
679#else 679#else
680//US char realpath_buffer[MAXPATHLEN + 1]; 680//US char realpath_buffer[MAXPATHLEN + 1];
681//US memset(realpath_buffer, 0, MAXPATHLEN + 1); 681//US memset(realpath_buffer, 0, MAXPATHLEN + 1);
682 char realpath_buffer[250 + 1]; 682 char realpath_buffer[250 + 1];
683 memset(realpath_buffer, 0, 250 + 1); 683 memset(realpath_buffer, 0, 250 + 1);
684 684
685 /* If the path contains symlinks, get the real name */ 685 /* If the path contains symlinks, get the real name */
686 if (realpath( QFile::encodeName(dirname).data(), realpath_buffer) != 0) { 686 if (realpath( QFile::encodeName(dirname).data(), realpath_buffer) != 0) {
687 // succes, use result from realpath 687 // succes, use result from realpath
688 int len = strlen(realpath_buffer); 688 int len = strlen(realpath_buffer);
689 realpath_buffer[len] = '/'; 689 realpath_buffer[len] = '/';
690 realpath_buffer[len+1] = 0; 690 realpath_buffer[len+1] = 0;
691 return QFile::decodeName(realpath_buffer); 691 return QFile::decodeName(realpath_buffer);
692 } 692 }
693 693
694 return dirname; 694 return dirname;
695#endif 695#endif
696} 696}
697/*US 697/*US
698void KStandardDirs::createSpecialResource(const char *type) 698void KStandardDirs::createSpecialResource(const char *type)
699{ 699{
700 char hostname[256]; 700 char hostname[256];
701 hostname[0] = 0; 701 hostname[0] = 0;
702 gethostname(hostname, 255); 702 gethostname(hostname, 255);
703 QString dir = QString("%1%2-%3").arg(localkdedir()).arg(type).arg(hostname); 703 QString dir = QString("%1%2-%3").arg(localkdedir()).arg(type).arg(hostname);
704 char link[1024]; 704 char link[1024];
705 link[1023] = 0; 705 link[1023] = 0;
706 int result = readlink(QFile::encodeName(dir).data(), link, 1023); 706 int result = readlink(QFile::encodeName(dir).data(), link, 1023);
707 if ((result == -1) && (errno == ENOENT)) 707 if ((result == -1) && (errno == ENOENT))
708 { 708 {
709 QString srv = findExe(QString::fromLatin1("lnusertemp"), KDEDIR+QString::fromLatin1("/bin")); 709 QString srv = findExe(QString::fromLatin1("lnusertemp"), KDEDIR+QString::fromLatin1("/bin"));
710 if (srv.isEmpty()) 710 if (srv.isEmpty())
711 srv = findExe(QString::fromLatin1("lnusertemp")); 711 srv = findExe(QString::fromLatin1("lnusertemp"));
712 if (!srv.isEmpty()) 712 if (!srv.isEmpty())
713 { 713 {
714 system(QFile::encodeName(srv)+" "+type); 714 system(QFile::encodeName(srv)+" "+type);
715 result = readlink(QFile::encodeName(dir).data(), link, 1023); 715 result = readlink(QFile::encodeName(dir).data(), link, 1023);
716 } 716 }
717 } 717 }
718 if (result > 0) 718 if (result > 0)
719 { 719 {
720 link[result] = 0; 720 link[result] = 0;
721 if (link[0] == '/') 721 if (link[0] == '/')
722 dir = QFile::decodeName(link); 722 dir = QFile::decodeName(link);
723 else 723 else
724 dir = QDir::cleanDirPath(dir+QFile::decodeName(link)); 724 dir = QDir::cleanDirPath(dir+QFile::decodeName(link));
725 } 725 }
726 addResourceDir(type, dir+'/'); 726 addResourceDir(type, dir+'/');
727} 727}
728*/ 728*/
729 729
730QStringList KStandardDirs::resourceDirs(const char *type) const 730QStringList KStandardDirs::resourceDirs(const char *type) const
731{ 731{
732 QStringList *candidates = dircache.find(type); 732 QStringList *candidates = dircache.find(type);
733 733
734 if (!candidates) { // filling cache 734 if (!candidates) { // filling cache
735/*US 735/*US
736 if (strcmp(type, "socket") == 0) 736 if (strcmp(type, "socket") == 0)
737 const_cast<KStandardDirs *>(this)->createSpecialResource(type); 737 const_cast<KStandardDirs *>(this)->createSpecialResource(type);
738 else if (strcmp(type, "tmp") == 0) 738 else if (strcmp(type, "tmp") == 0)
739 const_cast<KStandardDirs *>(this)->createSpecialResource(type); 739 const_cast<KStandardDirs *>(this)->createSpecialResource(type);
740 else if (strcmp(type, "cache") == 0) 740 else if (strcmp(type, "cache") == 0)
741 const_cast<KStandardDirs *>(this)->createSpecialResource(type); 741 const_cast<KStandardDirs *>(this)->createSpecialResource(type);
742*/ 742*/
743 QDir testdir; 743 QDir testdir;
744 744
745 candidates = new QStringList(); 745 candidates = new QStringList();
746 QStringList *dirs; 746 QStringList *dirs;
747 747
748 bool restrictionActive = false; 748 bool restrictionActive = false;
749 if (d && d->restrictionsActive) 749 if (d && d->restrictionsActive)
750 { 750 {
751 if (d->dataRestrictionActive) 751 if (d->dataRestrictionActive)
752 restrictionActive = true; 752 restrictionActive = true;
753 else if (d->restrictions["all"]) 753 else if (d->restrictions["all"])
754 restrictionActive = true; 754 restrictionActive = true;
755 else if (d->restrictions[type]) 755 else if (d->restrictions[type])
756 restrictionActive = true; 756 restrictionActive = true;
757 d->dataRestrictionActive = false; // Reset 757 d->dataRestrictionActive = false; // Reset
758 } 758 }
759 759
760 dirs = relatives.find(type); 760 dirs = relatives.find(type);
761 if (dirs) 761 if (dirs)
762 { 762 {
763 bool local = true; 763 bool local = true;
764 const QStringList *prefixList = 0; 764 const QStringList *prefixList = 0;
765 if (strncmp(type, "xdgdata-", 8) == 0) 765 if (strncmp(type, "xdgdata-", 8) == 0)
766 prefixList = &(d->xdgdata_prefixes); 766 prefixList = &(d->xdgdata_prefixes);
767 else if (strncmp(type, "xdgconf-", 8) == 0) 767 else if (strncmp(type, "xdgconf-", 8) == 0)
768 prefixList = &(d->xdgconf_prefixes); 768 prefixList = &(d->xdgconf_prefixes);
769 else 769 else
770 prefixList = &prefixes; 770 prefixList = &prefixes;
771 771
772 for (QStringList::ConstIterator pit = prefixList->begin(); 772 for (QStringList::ConstIterator pit = prefixList->begin();
773 pit != prefixList->end(); 773 pit != prefixList->end();
774 pit++) 774 pit++)
775 { 775 {
776 for (QStringList::ConstIterator it = dirs->begin(); 776 for (QStringList::ConstIterator it = dirs->begin();
777 it != dirs->end(); ++it) { 777 it != dirs->end(); ++it) {
778 QString path = realPath(*pit + *it); 778 QString path = realPath(*pit + *it);
779 testdir.setPath(path); 779 testdir.setPath(path);
780 if (local && restrictionActive) 780 if (local && restrictionActive)
781 continue; 781 continue;
782 if ((local || testdir.exists()) && !candidates->contains(path)) 782 if ((local || testdir.exists()) && !candidates->contains(path))
783 candidates->append(path); 783 candidates->append(path);
784 } 784 }
785 local = false; 785 local = false;
786 } 786 }
787 } 787 }
788 dirs = absolutes.find(type); 788 dirs = absolutes.find(type);
789 if (dirs) 789 if (dirs)
790 for (QStringList::ConstIterator it = dirs->begin(); 790 for (QStringList::ConstIterator it = dirs->begin();
791 it != dirs->end(); ++it) 791 it != dirs->end(); ++it)
792 { 792 {
793 testdir.setPath(*it); 793 testdir.setPath(*it);
794 if (testdir.exists()) 794 if (testdir.exists())
795 { 795 {
796 QString filename = realPath(*it); 796 QString filename = realPath(*it);
797 if (!candidates->contains(filename)) 797 if (!candidates->contains(filename))
798 candidates->append(filename); 798 candidates->append(filename);
799 } 799 }
800 } 800 }
801 dircache.insert(type, candidates); 801 dircache.insert(type, candidates);
802 } 802 }
803 803
804#if 0 804#if 0
805 kdDebug() << "found dirs for resource " << type << ":" << endl; 805 kdDebug() << "found dirs for resource " << type << ":" << endl;
806 for (QStringList::ConstIterator pit = candidates->begin(); 806 for (QStringList::ConstIterator pit = candidates->begin();
807 pit != candidates->end(); 807 pit != candidates->end();
808 pit++) 808 pit++)
809 { 809 {
810 fprintf(stderr, "%s\n", (*pit).latin1()); 810 fprintf(stderr, "%s\n", (*pit).latin1());
811 } 811 }
812#endif 812#endif
813 813
814 814
815 return *candidates; 815 return *candidates;
816} 816}
817 817
818/*US 818/*US
819QString KStandardDirs::findExe( const QString& appname, 819QString KStandardDirs::findExe( const QString& appname,
820 const QString& pstr, bool ignore) 820 const QString& pstr, bool ignore)
821{ 821{
822 QFileInfo info; 822 QFileInfo info;
823 823
824 // absolute path ? 824 // absolute path ?
825 if (appname.startsWith(QString::fromLatin1("/"))) 825 if (appname.startsWith(QString::fromLatin1("/")))
826 { 826 {
827 info.setFile( appname ); 827 info.setFile( appname );
828 if( info.exists() && ( ignore || info.isExecutable() ) 828 if( info.exists() && ( ignore || info.isExecutable() )
829 && info.isFile() ) { 829 && info.isFile() ) {
830 return appname; 830 return appname;
831 } 831 }
832 return QString::null; 832 return QString::null;
833 } 833 }
834 834
835//US QString p = QString("%1/%2").arg(__KDE_BINDIR).arg(appname); 835//US QString p = QString("%1/%2").arg(__KDE_BINDIR).arg(appname);
836 QString p = QString("%1/%2").arg(appname).arg(appname); 836 QString p = QString("%1/%2").arg(appname).arg(appname);
837 qDebug("KStandardDirs::findExe this is probably wrong"); 837 qDebug("KStandardDirs::findExe this is probably wrong");
838 838
839 info.setFile( p ); 839 info.setFile( p );
840 if( info.exists() && ( ignore || info.isExecutable() ) 840 if( info.exists() && ( ignore || info.isExecutable() )
841 && ( info.isFile() || info.isSymLink() ) ) { 841 && ( info.isFile() || info.isSymLink() ) ) {
842 return p; 842 return p;
843 } 843 }
844 844
845 QStringList tokens; 845 QStringList tokens;
846 p = pstr; 846 p = pstr;
847 847
848 if( p.isNull() ) { 848 if( p.isNull() ) {
849 p = getenv( "PATH" ); 849 p = getenv( "PATH" );
850 } 850 }
851 851
852 tokenize( tokens, p, ":\b" ); 852 tokenize( tokens, p, ":\b" );
853 853
854 // split path using : or \b as delimiters 854 // split path using : or \b as delimiters
855 for( unsigned i = 0; i < tokens.count(); i++ ) { 855 for( unsigned i = 0; i < tokens.count(); i++ ) {
856 p = tokens[ i ]; 856 p = tokens[ i ];
857 857
858 if ( p[ 0 ] == '~' ) 858 if ( p[ 0 ] == '~' )
859 { 859 {
860 int len = p.find( '/' ); 860 int len = p.find( '/' );
861 if ( len == -1 ) 861 if ( len == -1 )
862 len = p.length(); 862 len = p.length();
863 if ( len == 1 ) 863 if ( len == 1 )
864 p.replace( 0, 1, QDir::homeDirPath() ); 864 p.replace( 0, 1, QDir::homeDirPath() );
865 else 865 else
866 { 866 {
867 QString user = p.mid( 1, len - 1 ); 867 QString user = p.mid( 1, len - 1 );
868 struct passwd *dir = getpwnam( user.local8Bit().data() ); 868 struct passwd *dir = getpwnam( user.local8Bit().data() );
869 if ( dir && strlen( dir->pw_dir ) ) 869 if ( dir && strlen( dir->pw_dir ) )
870 p.replace( 0, len, QString::fromLocal8Bit( dir->pw_dir ) ); 870 p.replace( 0, len, QString::fromLocal8Bit( dir->pw_dir ) );
871 } 871 }
872 } 872 }
873 873
874 p += "/"; 874 p += "/";
875 p += appname; 875 p += appname;
876 876
877 // Check for executable in this tokenized path 877 // Check for executable in this tokenized path
878 info.setFile( p ); 878 info.setFile( p );
879 879
880 if( info.exists() && ( ignore || info.isExecutable() ) 880 if( info.exists() && ( ignore || info.isExecutable() )
881 && ( info.isFile() || info.isSymLink() ) ) { 881 && ( info.isFile() || info.isSymLink() ) ) {
882 return p; 882 return p;
883 } 883 }
884 } 884 }
885 885
886 // If we reach here, the executable wasn't found. 886 // If we reach here, the executable wasn't found.
887 // So return empty string. 887 // So return empty string.
888 888
889 return QString::null; 889 return QString::null;
890} 890}
891 891
892int KStandardDirs::findAllExe( QStringList& list, const QString& appname, 892int KStandardDirs::findAllExe( QStringList& list, const QString& appname,
893 const QString& pstr, bool ignore ) 893 const QString& pstr, bool ignore )
894{ 894{
895 QString p = pstr; 895 QString p = pstr;
896 QFileInfo info; 896 QFileInfo info;
897 QStringList tokens; 897 QStringList tokens;
898 898
899 if( p.isNull() ) { 899 if( p.isNull() ) {
900 p = getenv( "PATH" ); 900 p = getenv( "PATH" );
901 } 901 }
902 902
903 list.clear(); 903 list.clear();
904 tokenize( tokens, p, ":\b" ); 904 tokenize( tokens, p, ":\b" );
905 905
906 for ( unsigned i = 0; i < tokens.count(); i++ ) { 906 for ( unsigned i = 0; i < tokens.count(); i++ ) {
907 p = tokens[ i ]; 907 p = tokens[ i ];
908 p += "/"; 908 p += "/";
909 p += appname; 909 p += appname;
910 910
911 info.setFile( p ); 911 info.setFile( p );
912 912
913 if( info.exists() && (ignore || info.isExecutable()) 913 if( info.exists() && (ignore || info.isExecutable())
914 && info.isFile() ) { 914 && info.isFile() ) {
915 list.append( p ); 915 list.append( p );
916 } 916 }
917 917
918 } 918 }
919 919
920 return list.count(); 920 return list.count();
921} 921}
922*/ 922*/
923 923
924static int tokenize( QStringList& tokens, const QString& str, 924static int tokenize( QStringList& tokens, const QString& str,
925 const QString& delim ) 925 const QString& delim )
926{ 926{
927 int len = str.length(); 927 int len = str.length();
928 QString token = ""; 928 QString token = "";
929 929
930 for( int index = 0; index < len; index++) 930 for( int index = 0; index < len; index++)
931 { 931 {
932 if ( delim.find( str[ index ] ) >= 0 ) 932 if ( delim.find( str[ index ] ) >= 0 )
933 { 933 {
934 tokens.append( token ); 934 tokens.append( token );
935 token = ""; 935 token = "";
936 } 936 }
937 else 937 else
938 { 938 {
939 token += str[ index ]; 939 token += str[ index ];
940 } 940 }
941 } 941 }
942 if ( token.length() > 0 ) 942 if ( token.length() > 0 )
943 { 943 {
944 tokens.append( token ); 944 tokens.append( token );
945 } 945 }
946 946
947 return tokens.count(); 947 return tokens.count();
948} 948}
949 949
950QString KStandardDirs::kde_default(const char *type) { 950QString KStandardDirs::kde_default(const char *type) {
951 if (!strcmp(type, "data")) 951 if (!strcmp(type, "data"))
952 return "apps/"; 952 return "apps/";
953 if (!strcmp(type, "html")) 953 if (!strcmp(type, "html"))
954 return "share/doc/HTML/"; 954 return "share/doc/HTML/";
955 if (!strcmp(type, "icon")) 955 if (!strcmp(type, "icon"))
956 return "share/icons/"; 956 return "share/icons/";
957 if (!strcmp(type, "config")) 957 if (!strcmp(type, "config"))
958 return "config/"; 958 return "config/";
959 if (!strcmp(type, "pixmap")) 959 if (!strcmp(type, "pixmap"))
960 return "share/pixmaps/"; 960 return "share/pixmaps/";
961 if (!strcmp(type, "apps")) 961 if (!strcmp(type, "apps"))
962 return "share/applnk/"; 962 return "share/applnk/";
963 if (!strcmp(type, "sound")) 963 if (!strcmp(type, "sound"))
964 return "share/sounds/"; 964 return "share/sounds/";
965 if (!strcmp(type, "locale")) 965 if (!strcmp(type, "locale"))
966 return "share/locale/"; 966 return "share/locale/";
967 if (!strcmp(type, "services")) 967 if (!strcmp(type, "services"))
968 return "share/services/"; 968 return "share/services/";
969 if (!strcmp(type, "servicetypes")) 969 if (!strcmp(type, "servicetypes"))
970 return "share/servicetypes/"; 970 return "share/servicetypes/";
971 if (!strcmp(type, "mime")) 971 if (!strcmp(type, "mime"))
972 return "share/mimelnk/"; 972 return "share/mimelnk/";
973 if (!strcmp(type, "cgi")) 973 if (!strcmp(type, "cgi"))
974 return "cgi-bin/"; 974 return "cgi-bin/";
975 if (!strcmp(type, "wallpaper")) 975 if (!strcmp(type, "wallpaper"))
976 return "share/wallpapers/"; 976 return "share/wallpapers/";
977 if (!strcmp(type, "templates")) 977 if (!strcmp(type, "templates"))
978 return "share/templates/"; 978 return "share/templates/";
979 if (!strcmp(type, "exe")) 979 if (!strcmp(type, "exe"))
980 return "bin/"; 980 return "bin/";
981 if (!strcmp(type, "lib")) 981 if (!strcmp(type, "lib"))
982 return "lib/"; 982 return "lib/";
983 if (!strcmp(type, "module")) 983 if (!strcmp(type, "module"))
984 return "lib/kde3/"; 984 return "lib/kde3/";
985 if (!strcmp(type, "qtplugins")) 985 if (!strcmp(type, "qtplugins"))
986 return "lib/kde3/plugins"; 986 return "lib/kde3/plugins";
987 if (!strcmp(type, "xdgdata-apps")) 987 if (!strcmp(type, "xdgdata-apps"))
988 return "applications/"; 988 return "applications/";
989 if (!strcmp(type, "xdgdata-dirs")) 989 if (!strcmp(type, "xdgdata-dirs"))
990 return "desktop-directories/"; 990 return "desktop-directories/";
991 if (!strcmp(type, "xdgconf-menu")) 991 if (!strcmp(type, "xdgconf-menu"))
992 return "menus/"; 992 return "menus/";
993 if (!strcmp(type, "tmp"))
994 return "tmp/";
995
993 qFatal("unknown resource type %s", type); 996 qFatal("unknown resource type %s", type);
994 return QString::null; 997 return QString::null;
995} 998}
996 999
997QString KStandardDirs::saveLocation(const char *type, 1000QString KStandardDirs::saveLocation(const char *type,
998 const QString& suffix, 1001 const QString& suffix,
999 bool create) const 1002 bool create) const
1000{ 1003{
1001 //qDebug("KStandardDirs::saveLocation called %s %s", type,suffix.latin1() ); 1004 //qDebug("KStandardDirs::saveLocation called %s %s", type,suffix.latin1() );
1002 //return ""; 1005 //return "";
1003 checkConfig(); 1006 checkConfig();
1004 1007
1005 QString *pPath = savelocations.find(type); 1008 QString *pPath = savelocations.find(type);
1006 if (!pPath) 1009 if (!pPath)
1007 { 1010 {
1008 QStringList *dirs = relatives.find(type); 1011 QStringList *dirs = relatives.find(type);
1009 if (!dirs && ( 1012 if (!dirs && (
1010 (strcmp(type, "socket") == 0) || 1013 (strcmp(type, "socket") == 0) ||
1011 (strcmp(type, "tmp") == 0) || 1014 (strcmp(type, "tmp") == 0) ||
1012 (strcmp(type, "cache") == 0) )) 1015 (strcmp(type, "cache") == 0) ))
1013 { 1016 {
1014 (void) resourceDirs(type); // Generate socket|tmp|cache resource. 1017 (void) resourceDirs(type); // Generate socket|tmp|cache resource.
1015 dirs = relatives.find(type); // Search again. 1018 dirs = relatives.find(type); // Search again.
1016 } 1019 }
1017 if (dirs) 1020 if (dirs)
1018 { 1021 {
1019 // Check for existance of typed directory + suffix 1022 // Check for existance of typed directory + suffix
1020 if (strncmp(type, "xdgdata-", 8) == 0) 1023 if (strncmp(type, "xdgdata-", 8) == 0)
1021 pPath = new QString(realPath(localxdgdatadir() + dirs->last())); 1024 pPath = new QString(realPath(localxdgdatadir() + dirs->last()));
1022 else if (strncmp(type, "xdgconf-", 8) == 0) 1025 else if (strncmp(type, "xdgconf-", 8) == 0)
1023 pPath = new QString(realPath(localxdgconfdir() + dirs->last())); 1026 pPath = new QString(realPath(localxdgconfdir() + dirs->last()));
1024 else 1027 else
1025 pPath = new QString(realPath(localkdedir() + dirs->last())); 1028 pPath = new QString(realPath(localkdedir() + dirs->last()));
1026 } 1029 }
1027 else { 1030 else {
1028 dirs = absolutes.find(type); 1031 dirs = absolutes.find(type);
1029 if (!dirs) 1032 if (!dirs)
1030 qFatal("KStandardDirs: The resource type %s is not registered", type); 1033 qFatal("KStandardDirs: The resource type %s is not registered", type);
1031 pPath = new QString(realPath(dirs->last())); 1034 pPath = new QString(realPath(dirs->last()));
1032 } 1035 }
1033 1036
1034 savelocations.insert(type, pPath); 1037 savelocations.insert(type, pPath);
1035 } 1038 }
1036 1039
1037 QString fullPath = *pPath + suffix; 1040 QString fullPath = *pPath + suffix;
1038//US struct stat st; 1041//US struct stat st;
1039//US if (stat(QFile::encodeName(fullPath), &st) != 0 || !(S_ISDIR(st.st_mode))) 1042//US if (stat(QFile::encodeName(fullPath), &st) != 0 || !(S_ISDIR(st.st_mode)))
1040 QFileInfo fullPathInfo(QFile::encodeName(fullPath)); 1043 QFileInfo fullPathInfo(QFile::encodeName(fullPath));
1041 if (fullPathInfo.isReadable() || !fullPathInfo.isDir()) 1044 if (fullPathInfo.isReadable() || !fullPathInfo.isDir())
1042 1045
1043 1046
1044 { 1047 {
1045 if(!create) { 1048 if(!create) {
1046#ifndef NDEBUG 1049#ifndef NDEBUG
1047 qDebug("save location %s doesn't exist", fullPath.latin1()); 1050 qDebug("save location %s doesn't exist", fullPath.latin1());
1048#endif 1051#endif
1049 return fullPath; 1052 return fullPath;
1050 } 1053 }
1051 if(!makeDir(fullPath, 0700)) { 1054 if(!makeDir(fullPath, 0700)) {
1052 qWarning("failed to create %s", fullPath.latin1()); 1055 qWarning("failed to create %s", fullPath.latin1());
1053 return fullPath; 1056 return fullPath;
1054 } 1057 }
1055 dircache.remove(type); 1058 dircache.remove(type);
1056 } 1059 }
1057 return fullPath; 1060 return fullPath;
1058} 1061}
1059 1062
1060QString KStandardDirs::relativeLocation(const char *type, const QString &absPath) 1063QString KStandardDirs::relativeLocation(const char *type, const QString &absPath)
1061{ 1064{
1062 QString fullPath = absPath; 1065 QString fullPath = absPath;
1063 int i = absPath.findRev('/'); 1066 int i = absPath.findRev('/');
1064 if (i != -1) 1067 if (i != -1)
1065 { 1068 {
1066 fullPath = realPath(absPath.left(i+1))+absPath.mid(i+1); // Normalize 1069 fullPath = realPath(absPath.left(i+1))+absPath.mid(i+1); // Normalize
1067 } 1070 }
1068 1071
1069 QStringList candidates = resourceDirs(type); 1072 QStringList candidates = resourceDirs(type);
1070 1073
1071 for (QStringList::ConstIterator it = candidates.begin(); 1074 for (QStringList::ConstIterator it = candidates.begin();
1072 it != candidates.end(); it++) 1075 it != candidates.end(); it++)
1073 if (fullPath.startsWith(*it)) 1076 if (fullPath.startsWith(*it))
1074 { 1077 {
1075 return fullPath.mid((*it).length()); 1078 return fullPath.mid((*it).length());
1076 } 1079 }
1077 1080
1078 return absPath; 1081 return absPath;
1079} 1082}
1080 1083
1081 1084
1082bool KStandardDirs::makeDir(const QString& dir2, int mode) 1085bool KStandardDirs::makeDir(const QString& dir2, int mode)
1083{ 1086{
1084 QString dir = QDir::convertSeparators( dir2 ); 1087 QString dir = QDir::convertSeparators( dir2 );
1085#if 0 1088#if 0
1086 //LR 1089 //LR
1087 1090
1088 // we want an absolute path 1091 // we want an absolute path
1089 if (dir.at(0) != '/') 1092 if (dir.at(0) != '/')
1090 return false; 1093 return false;
1091 1094
1092 QString target = dir; 1095 QString target = dir;
1093 uint len = target.length(); 1096 uint len = target.length();
1094 1097
1095 // append trailing slash if missing 1098 // append trailing slash if missing
1096 if (dir.at(len - 1) != '/') 1099 if (dir.at(len - 1) != '/')
1097 target += '/'; 1100 target += '/';
1098 1101
1099 QString base(""); 1102 QString base("");
1100 uint i = 1; 1103 uint i = 1;
1101 1104
1102 while( i < len ) 1105 while( i < len )
1103 { 1106 {
1104//US struct stat st; 1107//US struct stat st;
1105 int pos = target.find('/', i); 1108 int pos = target.find('/', i);
1106 base += target.mid(i - 1, pos - i + 1); 1109 base += target.mid(i - 1, pos - i + 1);
1107 QCString baseEncoded = QFile::encodeName(base); 1110 QCString baseEncoded = QFile::encodeName(base);
1108 // bail out if we encountered a problem 1111 // bail out if we encountered a problem
1109//US if (stat(baseEncoded, &st) != 0) 1112//US if (stat(baseEncoded, &st) != 0)
1110 QFileInfo baseEncodedInfo(baseEncoded); 1113 QFileInfo baseEncodedInfo(baseEncoded);
1111 if (!baseEncodedInfo.exists()) 1114 if (!baseEncodedInfo.exists())
1112 { 1115 {
1113 // Directory does not exist.... 1116 // Directory does not exist....
1114 // Or maybe a dangling symlink ? 1117 // Or maybe a dangling symlink ?
1115//US if (lstat(baseEncoded, &st) == 0) 1118//US if (lstat(baseEncoded, &st) == 0)
1116 if (baseEncodedInfo.isSymLink()) { 1119 if (baseEncodedInfo.isSymLink()) {
1117//US (void)unlink(baseEncoded); // try removing 1120//US (void)unlink(baseEncoded); // try removing
1118 QFile(baseEncoded).remove(); 1121 QFile(baseEncoded).remove();
1119 } 1122 }
1120 1123
1121 //US if ( mkdir(baseEncoded, (mode_t) mode) != 0) 1124 //US if ( mkdir(baseEncoded, (mode_t) mode) != 0)
1122 QDir dirObj; 1125 QDir dirObj;
1123 if ( dirObj.mkdir(baseEncoded) != true ) 1126 if ( dirObj.mkdir(baseEncoded) != true )
1124 { 1127 {
1125 //US perror("trying to create local folder"); 1128 //US perror("trying to create local folder");
1126 return false; // Couldn't create it :-( 1129 return false; // Couldn't create it :-(
1127 } 1130 }
1128 } 1131 }
1129 i = pos + 1; 1132 i = pos + 1;
1130 } 1133 }
1131 return true; 1134 return true;
1132#endif 1135#endif
1133 1136
1134 // ******************************************** 1137 // ********************************************
1135 // new code for WIN32 1138 // new code for WIN32
1136 QDir dirObj; 1139 QDir dirObj;
1137 1140
1138 1141
1139 // we want an absolute path 1142 // we want an absolute path
1140#ifndef _WIN32_ 1143#ifndef _WIN32_
1141 if (dir.at(0) != '/') 1144 if (dir.at(0) != '/')
1142 return false; 1145 return false;
1143#endif 1146#endif
1144 1147
1145 QString target = dir; 1148 QString target = dir;
1146 uint len = target.length(); 1149 uint len = target.length();
1147#ifndef _WIN32_ 1150#ifndef _WIN32_
1148 // append trailing slash if missing 1151 // append trailing slash if missing
1149 if (dir.at(len - 1) != '/') 1152 if (dir.at(len - 1) != '/')
1150 target += '/'; 1153 target += '/';
1151#endif 1154#endif
1152 1155
1153 QString base(""); 1156 QString base("");
1154 uint i = 1; 1157 uint i = 1;
1155 1158
1156 while( i < len ) 1159 while( i < len )
1157 { 1160 {
1158//US struct stat st; 1161//US struct stat st;
1159#ifndef _WIN32_ 1162#ifndef _WIN32_
1160 int pos = target.find('/', i); 1163 int pos = target.find('/', i);
1161#else 1164#else
1162 int pos = target.find('\\', i); 1165 int pos = target.find('\\', i);
1163#endif 1166#endif
1164 if ( pos < 0 ) 1167 if ( pos < 0 )
1165 return true; 1168 return true;
1166 base += target.mid(i - 1, pos - i + 1); 1169 base += target.mid(i - 1, pos - i + 1);
1167 //QMessageBox::information( 0,"cap111", base, 1 ); 1170 //QMessageBox::information( 0,"cap111", base, 1 );
1168/*US 1171/*US
1169 QCString baseEncoded = QFile::encodeName(base); 1172 QCString baseEncoded = QFile::encodeName(base);
1170 // bail out if we encountered a problem 1173 // bail out if we encountered a problem
1171 if (stat(baseEncoded, &st) != 0) 1174 if (stat(baseEncoded, &st) != 0)
1172 { 1175 {
1173 // Directory does not exist.... 1176 // Directory does not exist....
1174 // Or maybe a dangling symlink ? 1177 // Or maybe a dangling symlink ?
1175 if (lstat(baseEncoded, &st) == 0) 1178 if (lstat(baseEncoded, &st) == 0)
1176 (void)unlink(baseEncoded); // try removing 1179 (void)unlink(baseEncoded); // try removing
1177 1180
1178 1181
1179 if ( mkdir(baseEncoded, (mode_t) mode) != 0) { 1182 if ( mkdir(baseEncoded, (mode_t) mode) != 0) {
1180 perror("trying to create local folder"); 1183 perror("trying to create local folder");
1181 return false; // Couldn't create it :-( 1184 return false; // Couldn't create it :-(
1182 } 1185 }
1183 } 1186 }
1184*/ 1187*/
1185 1188
1186 if (dirObj.exists(base) == false) 1189 if (dirObj.exists(base) == false)
1187 { 1190 {
1188 //qDebug("KStandardDirs::makeDir try to create : %s" , base.latin1()); 1191 //qDebug("KStandardDirs::makeDir try to create : %s" , base.latin1());
1189 if (dirObj.mkdir(base) != true) 1192 if (dirObj.mkdir(base) != true)
1190 { 1193 {
1191 qDebug("KStandardDirs::makeDir could not create: %s" , base.latin1()); 1194 qDebug("KStandardDirs::makeDir could not create: %s" , base.latin1());
1192 return false; 1195 return false;
1193 } 1196 }
1194 } 1197 }
1195 1198
1196 i = pos + 1; 1199 i = pos + 1;
1197 } 1200 }
1198 return true; 1201 return true;
1199 1202
1200} 1203}
1201 1204
1202static QString readEnvPath(const char *env) 1205static QString readEnvPath(const char *env)
1203{ 1206{
1204#ifdef _WIN32_ 1207#ifdef _WIN32_
1205 return ""; 1208 return "";
1206#else 1209#else
1207 QCString c_path = getenv(env); 1210 QCString c_path = getenv(env);
1208 if (c_path.isEmpty()) 1211 if (c_path.isEmpty())
1209 return QString::null; 1212 return QString::null;
1210 return QFile::decodeName(c_path); 1213 return QFile::decodeName(c_path);
1211#endif 1214#endif
1212} 1215}
1213 1216
1214void KStandardDirs::addKDEDefaults() 1217void KStandardDirs::addKDEDefaults()
1215{ 1218{
1216 //qDebug("ERROR: KStandardDirs::addKDEDefaults() called "); 1219 //qDebug("ERROR: KStandardDirs::addKDEDefaults() called ");
1217 //return; 1220 //return;
1218 QStringList kdedirList; 1221 QStringList kdedirList;
1219 1222
1220 // begin KDEDIRS 1223 // begin KDEDIRS
1221 QString kdedirs = readEnvPath("MICROKDEDIRS"); 1224 QString kdedirs = readEnvPath("MICROKDEDIRS");
1222 if (!kdedirs.isEmpty()) 1225 if (!kdedirs.isEmpty())
1223 { 1226 {
1224 tokenize(kdedirList, kdedirs, ":"); 1227 tokenize(kdedirList, kdedirs, ":");
1225 } 1228 }
1226 else 1229 else
1227 { 1230 {
1228 QString kdedir = readEnvPath("MICROKDEDIR"); 1231 QString kdedir = readEnvPath("MICROKDEDIR");
1229 if (!kdedir.isEmpty()) 1232 if (!kdedir.isEmpty())
1230 { 1233 {
1231 kdedir = KShell::tildeExpand(kdedir); 1234 kdedir = KShell::tildeExpand(kdedir);
1232 kdedirList.append(kdedir); 1235 kdedirList.append(kdedir);
1233 } 1236 }
1234 } 1237 }
1235//US kdedirList.append(KDEDIR); 1238//US kdedirList.append(KDEDIR);
1236//US for embedded, add qtopia dir as kdedir 1239//US for embedded, add qtopia dir as kdedir
1237 1240
1238#ifndef DESKTOP_VERSION 1241#ifndef DESKTOP_VERSION
1239 kdedirList.append(readEnvPath("QPEDIR" )); 1242 kdedirList.append(readEnvPath("QPEDIR" ));
1240#endif 1243#endif
1241 1244
1242#ifdef __KDE_EXECPREFIX 1245#ifdef __KDE_EXECPREFIX
1243 QString execPrefix(__KDE_EXECPREFIX); 1246 QString execPrefix(__KDE_EXECPREFIX);
1244 if (execPrefix!="NONE") 1247 if (execPrefix!="NONE")
1245 kdedirList.append(execPrefix); 1248 kdedirList.append(execPrefix);
1246#endif 1249#endif
1247 1250
1248 QString localKdeDir; 1251 QString localKdeDir;
1249 1252
1250//US if (getuid()) 1253//US if (getuid())
1251 if (true) 1254 if (true)
1252 { 1255 {
1253 localKdeDir = readEnvPath("MICROKDEHOME"); 1256 localKdeDir = readEnvPath("MICROKDEHOME");
1254 if (!localKdeDir.isEmpty()) 1257 if (!localKdeDir.isEmpty())
1255 { 1258 {
1256 if (localKdeDir.at(localKdeDir.length()-1) != '/') 1259 if (localKdeDir.at(localKdeDir.length()-1) != '/')
1257 localKdeDir += '/'; 1260 localKdeDir += '/';
1258 } 1261 }
1259 else 1262 else
1260 { 1263 {
1261 localKdeDir = QDir::homeDirPath() + "/kdepim/"; 1264 localKdeDir = QDir::homeDirPath() + "/kdepim/";
1262 } 1265 }
1263 } 1266 }
1264 else 1267 else
1265 { 1268 {
1266 // We treat root different to prevent root messing up the 1269 // We treat root different to prevent root messing up the
1267 // file permissions in the users home directory. 1270 // file permissions in the users home directory.
1268 localKdeDir = readEnvPath("MICROKDEROOTHOME"); 1271 localKdeDir = readEnvPath("MICROKDEROOTHOME");
1269 if (!localKdeDir.isEmpty()) 1272 if (!localKdeDir.isEmpty())
1270 { 1273 {
1271 if (localKdeDir.at(localKdeDir.length()-1) != '/') 1274 if (localKdeDir.at(localKdeDir.length()-1) != '/')
1272 localKdeDir += '/'; 1275 localKdeDir += '/';
1273 } 1276 }
1274 else 1277 else
1275 { 1278 {
1276//US struct passwd *pw = getpwuid(0); 1279//US struct passwd *pw = getpwuid(0);
1277//US localKdeDir = QFile::decodeName((pw && pw->pw_dir) ? pw->pw_dir : "/root") + "/.microkde/"; 1280//US localKdeDir = QFile::decodeName((pw && pw->pw_dir) ? pw->pw_dir : "/root") + "/.microkde/";
1278 qDebug("KStandardDirs::addKDEDefaults: 1 has to be fixed"); 1281 qDebug("KStandardDirs::addKDEDefaults: 1 has to be fixed");
1279 } 1282 }
1280 1283
1281 } 1284 }
1282 1285
1283//US localKdeDir = appDir(); 1286//US localKdeDir = appDir();
1284 1287
1285//US 1288//US
1286// qDebug("KStandardDirs::addKDEDefaults: localKdeDir=%s", localKdeDir.latin1()); 1289// qDebug("KStandardDirs::addKDEDefaults: localKdeDir=%s", localKdeDir.latin1());
1287 if (localKdeDir != "-/") 1290 if (localKdeDir != "-/")
1288 { 1291 {
1289 localKdeDir = KShell::tildeExpand(localKdeDir); 1292 localKdeDir = KShell::tildeExpand(localKdeDir);
1290 addPrefix(localKdeDir); 1293 addPrefix(localKdeDir);
1291 } 1294 }
1292 1295
1293 for (QStringList::ConstIterator it = kdedirList.begin(); 1296 for (QStringList::ConstIterator it = kdedirList.begin();
1294 it != kdedirList.end(); it++) 1297 it != kdedirList.end(); it++)
1295 { 1298 {
1296 QString dir = KShell::tildeExpand(*it); 1299 QString dir = KShell::tildeExpand(*it);
1297 addPrefix(dir); 1300 addPrefix(dir);
1298 } 1301 }
1299 // end KDEDIRS 1302 // end KDEDIRS
1300 1303
1301 // begin XDG_CONFIG_XXX 1304 // begin XDG_CONFIG_XXX
1302 QStringList xdgdirList; 1305 QStringList xdgdirList;
1303 QString xdgdirs = readEnvPath("XDG_CONFIG_DIRS"); 1306 QString xdgdirs = readEnvPath("XDG_CONFIG_DIRS");
1304 if (!xdgdirs.isEmpty()) 1307 if (!xdgdirs.isEmpty())
1305 { 1308 {
1306 tokenize(xdgdirList, xdgdirs, ":"); 1309 tokenize(xdgdirList, xdgdirs, ":");
1307 } 1310 }
1308 else 1311 else
1309 { 1312 {
1310 xdgdirList.clear(); 1313 xdgdirList.clear();
1311 xdgdirList.append("/etc/xdg"); 1314 xdgdirList.append("/etc/xdg");
1312 } 1315 }
1313 1316
1314 QString localXdgDir = readEnvPath("XDG_CONFIG_HOME"); 1317 QString localXdgDir = readEnvPath("XDG_CONFIG_HOME");
1315 if (!localXdgDir.isEmpty()) 1318 if (!localXdgDir.isEmpty())
1316 { 1319 {
1317 if (localXdgDir.at(localXdgDir.length()-1) != '/') 1320 if (localXdgDir.at(localXdgDir.length()-1) != '/')
1318 localXdgDir += '/'; 1321 localXdgDir += '/';
1319 } 1322 }
1320 else 1323 else
1321 { 1324 {
1322//US if (getuid()) 1325//US if (getuid())
1323 if (true) 1326 if (true)
1324 { 1327 {
1325 localXdgDir = QDir::homeDirPath() + "/.config/"; 1328 localXdgDir = QDir::homeDirPath() + "/.config/";
1326 } 1329 }
1327 else 1330 else
1328 { 1331 {
1329//US struct passwd *pw = getpwuid(0); 1332//US struct passwd *pw = getpwuid(0);
1330//US localXdgDir = QFile::decodeName((pw && pw->pw_dir) ? pw->pw_dir : "/root") + "/.config/"; 1333//US localXdgDir = QFile::decodeName((pw && pw->pw_dir) ? pw->pw_dir : "/root") + "/.config/";
1331 qDebug("KStandardDirs::addKDEDefaults: 2 has to be fixed"); 1334 qDebug("KStandardDirs::addKDEDefaults: 2 has to be fixed");
1332 } 1335 }
1333 } 1336 }
1334 1337
1335 localXdgDir = KShell::tildeExpand(localXdgDir); 1338 localXdgDir = KShell::tildeExpand(localXdgDir);
1336 addXdgConfigPrefix(localXdgDir); 1339 addXdgConfigPrefix(localXdgDir);
1337 1340
1338 for (QStringList::ConstIterator it = xdgdirList.begin(); 1341 for (QStringList::ConstIterator it = xdgdirList.begin();
1339 it != xdgdirList.end(); it++) 1342 it != xdgdirList.end(); it++)
1340 { 1343 {
1341 QString dir = KShell::tildeExpand(*it); 1344 QString dir = KShell::tildeExpand(*it);
1342 addXdgConfigPrefix(dir); 1345 addXdgConfigPrefix(dir);
1343 } 1346 }
1344 // end XDG_CONFIG_XXX 1347 // end XDG_CONFIG_XXX
1345 1348
1346 // begin XDG_DATA_XXX 1349 // begin XDG_DATA_XXX
1347 xdgdirs = readEnvPath("XDG_DATA_DIRS"); 1350 xdgdirs = readEnvPath("XDG_DATA_DIRS");
1348 if (!xdgdirs.isEmpty()) 1351 if (!xdgdirs.isEmpty())
1349 { 1352 {
1350 tokenize(xdgdirList, xdgdirs, ":"); 1353 tokenize(xdgdirList, xdgdirs, ":");
1351 } 1354 }
1352 else 1355 else
1353 { 1356 {
1354 xdgdirList.clear(); 1357 xdgdirList.clear();
1355 for (QStringList::ConstIterator it = kdedirList.begin(); 1358 for (QStringList::ConstIterator it = kdedirList.begin();
1356 it != kdedirList.end(); it++) 1359 it != kdedirList.end(); it++)
1357 { 1360 {
1358 QString dir = *it; 1361 QString dir = *it;
1359 if (dir.at(dir.length()-1) != '/') 1362 if (dir.at(dir.length()-1) != '/')
1360 dir += '/'; 1363 dir += '/';
1361 xdgdirList.append(dir+"share/"); 1364 xdgdirList.append(dir+"share/");
1362 } 1365 }
1363 1366
1364 xdgdirList.append("/usr/local/share/"); 1367 xdgdirList.append("/usr/local/share/");
1365 xdgdirList.append("/usr/share/"); 1368 xdgdirList.append("/usr/share/");
1366 } 1369 }
1367 1370
1368 localXdgDir = readEnvPath("XDG_DATA_HOME"); 1371 localXdgDir = readEnvPath("XDG_DATA_HOME");
1369 if (!localXdgDir.isEmpty()) 1372 if (!localXdgDir.isEmpty())
1370 { 1373 {
1371 if (localXdgDir.at(localXdgDir.length()-1) != '/') 1374 if (localXdgDir.at(localXdgDir.length()-1) != '/')
1372 localXdgDir += '/'; 1375 localXdgDir += '/';
1373 } 1376 }
1374 else 1377 else
1375 { 1378 {
1376//US if (getuid()) 1379//US if (getuid())
1377 if (true) 1380 if (true)
1378 { 1381 {
1379 localXdgDir = QDir::homeDirPath() + "/.local/share/"; 1382 localXdgDir = QDir::homeDirPath() + "/.local/share/";
1380 } 1383 }
1381 else 1384 else
1382 { 1385 {
1383//US struct passwd *pw = getpwuid(0); 1386//US struct passwd *pw = getpwuid(0);
1384//US localXdgDir = QFile::decodeName((pw && pw->pw_dir) ? pw->pw_dir : "/root") + "/.local/share/"; 1387//US localXdgDir = QFile::decodeName((pw && pw->pw_dir) ? pw->pw_dir : "/root") + "/.local/share/";
1385 qDebug("KStandardDirs::addKDEDefaults: 3 has to be fixed"); 1388 qDebug("KStandardDirs::addKDEDefaults: 3 has to be fixed");
1386 } 1389 }
1387 } 1390 }
1388 1391
1389 localXdgDir = KShell::tildeExpand(localXdgDir); 1392 localXdgDir = KShell::tildeExpand(localXdgDir);
1390 addXdgDataPrefix(localXdgDir); 1393 addXdgDataPrefix(localXdgDir);
1391 1394
1392 for (QStringList::ConstIterator it = xdgdirList.begin(); 1395 for (QStringList::ConstIterator it = xdgdirList.begin();
1393 it != xdgdirList.end(); it++) 1396 it != xdgdirList.end(); it++)
1394 { 1397 {
1395 QString dir = KShell::tildeExpand(*it); 1398 QString dir = KShell::tildeExpand(*it);
1396 1399
1397 addXdgDataPrefix(dir); 1400 addXdgDataPrefix(dir);
1398 } 1401 }
1399 // end XDG_DATA_XXX 1402 // end XDG_DATA_XXX
1400 1403
1401 1404
1402 uint index = 0; 1405 uint index = 0;
1403 while (types[index] != 0) { 1406 while (types[index] != 0) {
1404 addResourceType(types[index], kde_default(types[index])); 1407 addResourceType(types[index], kde_default(types[index]));
1405 index++; 1408 index++;
1406 } 1409 }
1407 1410
1408 addResourceDir("home", QDir::homeDirPath()); 1411 addResourceDir("home", QDir::homeDirPath());
1409} 1412}
1410 1413
1411void KStandardDirs::checkConfig() const 1414void KStandardDirs::checkConfig() const
1412{ 1415{
1413/*US 1416/*US
1414 if (!addedCustoms && KGlobal::_instance && KGlobal::_instance->_config) 1417 if (!addedCustoms && KGlobal::_instance && KGlobal::_instance->_config)
1415 const_cast<KStandardDirs*>(this)->addCustomized(KGlobal::_instance->_config); 1418 const_cast<KStandardDirs*>(this)->addCustomized(KGlobal::_instance->_config);
1416*/ 1419*/
1417 if (!addedCustoms && KGlobal::config()) 1420 if (!addedCustoms && KGlobal::config())
1418 const_cast<KStandardDirs*>(this)->addCustomized(KGlobal::config()); 1421 const_cast<KStandardDirs*>(this)->addCustomized(KGlobal::config());
1419} 1422}
1420 1423
1421bool KStandardDirs::addCustomized(KConfig *config) 1424bool KStandardDirs::addCustomized(KConfig *config)
1422{ 1425{
1423 if (addedCustoms) // there are already customized entries 1426 if (addedCustoms) // there are already customized entries
1424 return false; // we just quite and hope they are the right ones 1427 return false; // we just quite and hope they are the right ones
1425 1428
1426 // save the numbers of config directories. If this changes, 1429 // save the numbers of config directories. If this changes,
1427 // we will return true to give KConfig a chance to reparse 1430 // we will return true to give KConfig a chance to reparse
1428 uint configdirs = resourceDirs("config").count(); 1431 uint configdirs = resourceDirs("config").count();
1429 1432
1430 // reading the prefixes in 1433 // reading the prefixes in
1431 QString oldGroup = config->group(); 1434 QString oldGroup = config->group();
1432 config->setGroup("Directories"); 1435 config->setGroup("Directories");
1433 1436
1434 QStringList list; 1437 QStringList list;
1435 QStringList::ConstIterator it; 1438 QStringList::ConstIterator it;
1436 list = config->readListEntry("prefixes"); 1439 list = config->readListEntry("prefixes");
1437 for (it = list.begin(); it != list.end(); it++) 1440 for (it = list.begin(); it != list.end(); it++)
1438 addPrefix(*it); 1441 addPrefix(*it);
1439 1442
1440 // iterating over all entries in the group Directories 1443 // iterating over all entries in the group Directories
1441 // to find entries that start with dir_$type 1444 // to find entries that start with dir_$type
1442/*US 1445/*US
1443 QMap<QString, QString> entries = config->entryMap("Directories"); 1446 QMap<QString, QString> entries = config->entryMap("Directories");
1444 1447
1445 QMap<QString, QString>::ConstIterator it2; 1448 QMap<QString, QString>::ConstIterator it2;
1446 for (it2 = entries.begin(); it2 != entries.end(); it2++) 1449 for (it2 = entries.begin(); it2 != entries.end(); it2++)
1447 { 1450 {
1448 QString key = it2.key(); 1451 QString key = it2.key();
1449 if (key.left(4) == "dir_") { 1452 if (key.left(4) == "dir_") {
1450 // generate directory list, there may be more than 1. 1453 // generate directory list, there may be more than 1.
1451 QStringList dirs = QStringList::split(',', *it2); 1454 QStringList dirs = QStringList::split(',', *it2);
1452 QStringList::Iterator sIt(dirs.begin()); 1455 QStringList::Iterator sIt(dirs.begin());
1453 QString resType = key.mid(4, key.length()); 1456 QString resType = key.mid(4, key.length());
1454 for (; sIt != dirs.end(); ++sIt) { 1457 for (; sIt != dirs.end(); ++sIt) {
1455 addResourceDir(resType.latin1(), *sIt); 1458 addResourceDir(resType.latin1(), *sIt);
1456 } 1459 }
1457 } 1460 }
1458 } 1461 }
1459 1462
1460 // Process KIOSK restrictions. 1463 // Process KIOSK restrictions.
1461 config->setGroup("KDE Resource Restrictions"); 1464 config->setGroup("KDE Resource Restrictions");
1462 entries = config->entryMap("KDE Resource Restrictions"); 1465 entries = config->entryMap("KDE Resource Restrictions");
1463 for (it2 = entries.begin(); it2 != entries.end(); it2++) 1466 for (it2 = entries.begin(); it2 != entries.end(); it2++)
1464 { 1467 {
1465 QString key = it2.key(); 1468 QString key = it2.key();
1466 if (!config->readBoolEntry(key, true)) 1469 if (!config->readBoolEntry(key, true))
1467 { 1470 {
1468 d->restrictionsActive = true; 1471 d->restrictionsActive = true;
1469 d->restrictions.insert(key.latin1(), &d->restrictionsActive); // Anything will do 1472 d->restrictions.insert(key.latin1(), &d->restrictionsActive); // Anything will do
1470 dircache.remove(key.latin1()); 1473 dircache.remove(key.latin1());
1471 } 1474 }
1472 } 1475 }
1473*/ 1476*/
1474 // save it for future calls - that will return 1477 // save it for future calls - that will return
1475 addedCustoms = true; 1478 addedCustoms = true;
1476 config->setGroup(oldGroup); 1479 config->setGroup(oldGroup);
1477 1480
1478 // return true if the number of config dirs changed 1481 // return true if the number of config dirs changed
1479 return (resourceDirs("config").count() != configdirs); 1482 return (resourceDirs("config").count() != configdirs);
1480} 1483}
1481 1484
1482QString KStandardDirs::localkdedir() const 1485QString KStandardDirs::localkdedir() const
1483{ 1486{
1484 // Return the prefix to use for saving 1487 // Return the prefix to use for saving
1485 return prefixes.first(); 1488 return prefixes.first();
1486} 1489}
1487 1490
1488QString KStandardDirs::localxdgdatadir() const 1491QString KStandardDirs::localxdgdatadir() const
1489{ 1492{
1490 // Return the prefix to use for saving 1493 // Return the prefix to use for saving
1491 return d->xdgdata_prefixes.first(); 1494 return d->xdgdata_prefixes.first();
1492} 1495}
1493 1496
1494QString KStandardDirs::localxdgconfdir() const 1497QString KStandardDirs::localxdgconfdir() const
1495{ 1498{
1496 // Return the prefix to use for saving 1499 // Return the prefix to use for saving
1497 return d->xdgconf_prefixes.first(); 1500 return d->xdgconf_prefixes.first();
1498} 1501}
1499 1502
1500void KStandardDirs::setAppDir( const QString &appDir ) 1503void KStandardDirs::setAppDir( const QString &appDir )
1501{ 1504{
1502 mAppDir = appDir; 1505 mAppDir = appDir;
1503 1506
1504 if ( mAppDir.right( 1 ) != "/" ) 1507 if ( mAppDir.right( 1 ) != "/" )