summaryrefslogtreecommitdiffabout
path: root/microkde
authorulf69 <ulf69>2004-08-05 21:44:59 (UTC)
committer ulf69 <ulf69>2004-08-05 21:44:59 (UTC)
commitbb1dd236b41cbd5cc4aed3b320801aa07974122d (patch) (unidiff)
tree4d07c4fc759d2926c8a48e49af59448d46a35a7b /microkde
parent6ee7d4f5119837f89ec534c8c5c73845d521e135 (diff)
downloadkdepimpi-bb1dd236b41cbd5cc4aed3b320801aa07974122d.zip
kdepimpi-bb1dd236b41cbd5cc4aed3b320801aa07974122d.tar.gz
kdepimpi-bb1dd236b41cbd5cc4aed3b320801aa07974122d.tar.bz2
additional change for the tmp resourcetype
Diffstat (limited to 'microkde') (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
@@ -865,256 +865,259 @@ QString KStandardDirs::findExe( const QString& appname,
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