-rw-r--r-- | microkde/kdecore/kstandarddirs.cpp | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/microkde/kdecore/kstandarddirs.cpp b/microkde/kdecore/kstandarddirs.cpp index 500426b..7f2a326 100644 --- a/microkde/kdecore/kstandarddirs.cpp +++ b/microkde/kdecore/kstandarddirs.cpp | |||
@@ -986,513 +986,524 @@ QString KStandardDirs::kde_default(const char *type) { | |||
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")) | 993 | if (!strcmp(type, "tmp")) |
994 | return "tmp/"; | 994 | return "tmp/"; |
995 | 995 | ||
996 | qFatal("unknown resource type %s", type); | 996 | qFatal("unknown resource type %s", type); |
997 | return QString::null; | 997 | return QString::null; |
998 | } | 998 | } |
999 | 999 | ||
1000 | QString KStandardDirs::saveLocation(const char *type, | 1000 | QString KStandardDirs::saveLocation(const char *type, |
1001 | const QString& suffix, | 1001 | const QString& suffix, |
1002 | bool create) const | 1002 | bool create) const |
1003 | { | 1003 | { |
1004 | //qDebug("KStandardDirs::saveLocation called %s %s", type,suffix.latin1() ); | 1004 | //qDebug("KStandardDirs::saveLocation called %s %s", type,suffix.latin1() ); |
1005 | //return ""; | 1005 | //return ""; |
1006 | checkConfig(); | 1006 | checkConfig(); |
1007 | 1007 | ||
1008 | QString *pPath = savelocations.find(type); | 1008 | QString *pPath = savelocations.find(type); |
1009 | if (!pPath) | 1009 | if (!pPath) |
1010 | { | 1010 | { |
1011 | QStringList *dirs = relatives.find(type); | 1011 | QStringList *dirs = relatives.find(type); |
1012 | if (!dirs && ( | 1012 | if (!dirs && ( |
1013 | (strcmp(type, "socket") == 0) || | 1013 | (strcmp(type, "socket") == 0) || |
1014 | (strcmp(type, "tmp") == 0) || | 1014 | (strcmp(type, "tmp") == 0) || |
1015 | (strcmp(type, "cache") == 0) )) | 1015 | (strcmp(type, "cache") == 0) )) |
1016 | { | 1016 | { |
1017 | (void) resourceDirs(type); // Generate socket|tmp|cache resource. | 1017 | (void) resourceDirs(type); // Generate socket|tmp|cache resource. |
1018 | dirs = relatives.find(type); // Search again. | 1018 | dirs = relatives.find(type); // Search again. |
1019 | } | 1019 | } |
1020 | if (dirs) | 1020 | if (dirs) |
1021 | { | 1021 | { |
1022 | // Check for existance of typed directory + suffix | 1022 | // Check for existance of typed directory + suffix |
1023 | if (strncmp(type, "xdgdata-", 8) == 0) | 1023 | if (strncmp(type, "xdgdata-", 8) == 0) |
1024 | pPath = new QString(realPath(localxdgdatadir() + dirs->last())); | 1024 | pPath = new QString(realPath(localxdgdatadir() + dirs->last())); |
1025 | else if (strncmp(type, "xdgconf-", 8) == 0) | 1025 | else if (strncmp(type, "xdgconf-", 8) == 0) |
1026 | pPath = new QString(realPath(localxdgconfdir() + dirs->last())); | 1026 | pPath = new QString(realPath(localxdgconfdir() + dirs->last())); |
1027 | else | 1027 | else |
1028 | pPath = new QString(realPath(localkdedir() + dirs->last())); | 1028 | pPath = new QString(realPath(localkdedir() + dirs->last())); |
1029 | } | 1029 | } |
1030 | else { | 1030 | else { |
1031 | dirs = absolutes.find(type); | 1031 | dirs = absolutes.find(type); |
1032 | if (!dirs) | 1032 | if (!dirs) |
1033 | qFatal("KStandardDirs: The resource type %s is not registered", type); | 1033 | qFatal("KStandardDirs: The resource type %s is not registered", type); |
1034 | pPath = new QString(realPath(dirs->last())); | 1034 | pPath = new QString(realPath(dirs->last())); |
1035 | } | 1035 | } |
1036 | 1036 | ||
1037 | savelocations.insert(type, pPath); | 1037 | savelocations.insert(type, pPath); |
1038 | } | 1038 | } |
1039 | 1039 | ||
1040 | QString fullPath = *pPath + suffix; | 1040 | QString fullPath = *pPath + suffix; |
1041 | //US struct stat st; | 1041 | //US struct stat st; |
1042 | //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))) |
1043 | QFileInfo fullPathInfo(QFile::encodeName(fullPath)); | 1043 | QFileInfo fullPathInfo(QFile::encodeName(fullPath)); |
1044 | if (fullPathInfo.isReadable() || !fullPathInfo.isDir()) | 1044 | if (fullPathInfo.isReadable() || !fullPathInfo.isDir()) |
1045 | 1045 | ||
1046 | 1046 | ||
1047 | { | 1047 | { |
1048 | if(!create) { | 1048 | if(!create) { |
1049 | #ifndef NDEBUG | 1049 | #ifndef NDEBUG |
1050 | qDebug("save location %s doesn't exist", fullPath.latin1()); | 1050 | qDebug("save location %s doesn't exist", fullPath.latin1()); |
1051 | #endif | 1051 | #endif |
1052 | return fullPath; | 1052 | return fullPath; |
1053 | } | 1053 | } |
1054 | if(!makeDir(fullPath, 0700)) { | 1054 | if(!makeDir(fullPath, 0700)) { |
1055 | qWarning("failed to create %s", fullPath.latin1()); | 1055 | qWarning("failed to create %s", fullPath.latin1()); |
1056 | return fullPath; | 1056 | return fullPath; |
1057 | } | 1057 | } |
1058 | dircache.remove(type); | 1058 | dircache.remove(type); |
1059 | } | 1059 | } |
1060 | return fullPath; | 1060 | return fullPath; |
1061 | } | 1061 | } |
1062 | 1062 | ||
1063 | QString KStandardDirs::relativeLocation(const char *type, const QString &absPath) | 1063 | QString KStandardDirs::relativeLocation(const char *type, const QString &absPath) |
1064 | { | 1064 | { |
1065 | QString fullPath = absPath; | 1065 | QString fullPath = absPath; |
1066 | int i = absPath.findRev('/'); | 1066 | int i = absPath.findRev('/'); |
1067 | if (i != -1) | 1067 | if (i != -1) |
1068 | { | 1068 | { |
1069 | fullPath = realPath(absPath.left(i+1))+absPath.mid(i+1); // Normalize | 1069 | fullPath = realPath(absPath.left(i+1))+absPath.mid(i+1); // Normalize |
1070 | } | 1070 | } |
1071 | 1071 | ||
1072 | QStringList candidates = resourceDirs(type); | 1072 | QStringList candidates = resourceDirs(type); |
1073 | 1073 | ||
1074 | for (QStringList::ConstIterator it = candidates.begin(); | 1074 | for (QStringList::ConstIterator it = candidates.begin(); |
1075 | it != candidates.end(); it++) | 1075 | it != candidates.end(); it++) |
1076 | if (fullPath.startsWith(*it)) | 1076 | if (fullPath.startsWith(*it)) |
1077 | { | 1077 | { |
1078 | return fullPath.mid((*it).length()); | 1078 | return fullPath.mid((*it).length()); |
1079 | } | 1079 | } |
1080 | 1080 | ||
1081 | return absPath; | 1081 | return absPath; |
1082 | } | 1082 | } |
1083 | 1083 | ||
1084 | 1084 | ||
1085 | bool KStandardDirs::makeDir(const QString& dir2, int mode) | 1085 | bool KStandardDirs::makeDir(const QString& dir2, int mode) |
1086 | { | 1086 | { |
1087 | QString dir = QDir::convertSeparators( dir2 ); | 1087 | QString dir = QDir::convertSeparators( dir2 ); |
1088 | #if 0 | 1088 | #if 0 |
1089 | //LR | 1089 | //LR |
1090 | 1090 | ||
1091 | // we want an absolute path | 1091 | // we want an absolute path |
1092 | if (dir.at(0) != '/') | 1092 | if (dir.at(0) != '/') |
1093 | return false; | 1093 | return false; |
1094 | 1094 | ||
1095 | QString target = dir; | 1095 | QString target = dir; |
1096 | uint len = target.length(); | 1096 | uint len = target.length(); |
1097 | 1097 | ||
1098 | // append trailing slash if missing | 1098 | // append trailing slash if missing |
1099 | if (dir.at(len - 1) != '/') | 1099 | if (dir.at(len - 1) != '/') |
1100 | target += '/'; | 1100 | target += '/'; |
1101 | 1101 | ||
1102 | QString base(""); | 1102 | QString base(""); |
1103 | uint i = 1; | 1103 | uint i = 1; |
1104 | 1104 | ||
1105 | while( i < len ) | 1105 | while( i < len ) |
1106 | { | 1106 | { |
1107 | //US struct stat st; | 1107 | //US struct stat st; |
1108 | int pos = target.find('/', i); | 1108 | int pos = target.find('/', i); |
1109 | base += target.mid(i - 1, pos - i + 1); | 1109 | base += target.mid(i - 1, pos - i + 1); |
1110 | QCString baseEncoded = QFile::encodeName(base); | 1110 | QCString baseEncoded = QFile::encodeName(base); |
1111 | // bail out if we encountered a problem | 1111 | // bail out if we encountered a problem |
1112 | //US if (stat(baseEncoded, &st) != 0) | 1112 | //US if (stat(baseEncoded, &st) != 0) |
1113 | QFileInfo baseEncodedInfo(baseEncoded); | 1113 | QFileInfo baseEncodedInfo(baseEncoded); |
1114 | if (!baseEncodedInfo.exists()) | 1114 | if (!baseEncodedInfo.exists()) |
1115 | { | 1115 | { |
1116 | // Directory does not exist.... | 1116 | // Directory does not exist.... |
1117 | // Or maybe a dangling symlink ? | 1117 | // Or maybe a dangling symlink ? |
1118 | //US if (lstat(baseEncoded, &st) == 0) | 1118 | //US if (lstat(baseEncoded, &st) == 0) |
1119 | if (baseEncodedInfo.isSymLink()) { | 1119 | if (baseEncodedInfo.isSymLink()) { |
1120 | //US (void)unlink(baseEncoded); // try removing | 1120 | //US (void)unlink(baseEncoded); // try removing |
1121 | QFile(baseEncoded).remove(); | 1121 | QFile(baseEncoded).remove(); |
1122 | } | 1122 | } |
1123 | 1123 | ||
1124 | //US if ( mkdir(baseEncoded, (mode_t) mode) != 0) | 1124 | //US if ( mkdir(baseEncoded, (mode_t) mode) != 0) |
1125 | QDir dirObj; | 1125 | QDir dirObj; |
1126 | if ( dirObj.mkdir(baseEncoded) != true ) | 1126 | if ( dirObj.mkdir(baseEncoded) != true ) |
1127 | { | 1127 | { |
1128 | //US perror("trying to create local folder"); | 1128 | //US perror("trying to create local folder"); |
1129 | return false; // Couldn't create it :-( | 1129 | return false; // Couldn't create it :-( |
1130 | } | 1130 | } |
1131 | } | 1131 | } |
1132 | i = pos + 1; | 1132 | i = pos + 1; |
1133 | } | 1133 | } |
1134 | return true; | 1134 | return true; |
1135 | #endif | 1135 | #endif |
1136 | 1136 | ||
1137 | // ******************************************** | 1137 | // ******************************************** |
1138 | // new code for WIN32 | 1138 | // new code for WIN32 |
1139 | QDir dirObj; | 1139 | QDir dirObj; |
1140 | 1140 | ||
1141 | 1141 | ||
1142 | // we want an absolute path | 1142 | // we want an absolute path |
1143 | #ifndef _WIN32_ | 1143 | #ifndef _WIN32_ |
1144 | if (dir.at(0) != '/') | 1144 | if (dir.at(0) != '/') |
1145 | return false; | 1145 | return false; |
1146 | #endif | 1146 | #endif |
1147 | 1147 | ||
1148 | QString target = dir; | 1148 | QString target = dir; |
1149 | uint len = target.length(); | 1149 | uint len = target.length(); |
1150 | #ifndef _WIN32_ | 1150 | #ifndef _WIN32_ |
1151 | // append trailing slash if missing | 1151 | // append trailing slash if missing |
1152 | if (dir.at(len - 1) != '/') | 1152 | if (dir.at(len - 1) != '/') |
1153 | target += '/'; | 1153 | target += '/'; |
1154 | #endif | 1154 | #endif |
1155 | 1155 | ||
1156 | QString base(""); | 1156 | QString base(""); |
1157 | uint i = 1; | 1157 | uint i = 1; |
1158 | 1158 | ||
1159 | while( i < len ) | 1159 | while( i < len ) |
1160 | { | 1160 | { |
1161 | //US struct stat st; | 1161 | //US struct stat st; |
1162 | #ifndef _WIN32_ | 1162 | #ifndef _WIN32_ |
1163 | int pos = target.find('/', i); | 1163 | int pos = target.find('/', i); |
1164 | #else | 1164 | #else |
1165 | int pos = target.find('\\', i); | 1165 | int pos = target.find('\\', i); |
1166 | #endif | 1166 | #endif |
1167 | if ( pos < 0 ) | 1167 | if ( pos < 0 ) |
1168 | return true; | 1168 | return true; |
1169 | base += target.mid(i - 1, pos - i + 1); | 1169 | base += target.mid(i - 1, pos - i + 1); |
1170 | //QMessageBox::information( 0,"cap111", base, 1 ); | 1170 | //QMessageBox::information( 0,"cap111", base, 1 ); |
1171 | /*US | 1171 | /*US |
1172 | QCString baseEncoded = QFile::encodeName(base); | 1172 | QCString baseEncoded = QFile::encodeName(base); |
1173 | // bail out if we encountered a problem | 1173 | // bail out if we encountered a problem |
1174 | if (stat(baseEncoded, &st) != 0) | 1174 | if (stat(baseEncoded, &st) != 0) |
1175 | { | 1175 | { |
1176 | // Directory does not exist.... | 1176 | // Directory does not exist.... |
1177 | // Or maybe a dangling symlink ? | 1177 | // Or maybe a dangling symlink ? |
1178 | if (lstat(baseEncoded, &st) == 0) | 1178 | if (lstat(baseEncoded, &st) == 0) |
1179 | (void)unlink(baseEncoded); // try removing | 1179 | (void)unlink(baseEncoded); // try removing |
1180 | 1180 | ||
1181 | 1181 | ||
1182 | if ( mkdir(baseEncoded, (mode_t) mode) != 0) { | 1182 | if ( mkdir(baseEncoded, (mode_t) mode) != 0) { |
1183 | perror("trying to create local folder"); | 1183 | perror("trying to create local folder"); |
1184 | return false; // Couldn't create it :-( | 1184 | return false; // Couldn't create it :-( |
1185 | } | 1185 | } |
1186 | } | 1186 | } |
1187 | */ | 1187 | */ |
1188 | 1188 | ||
1189 | if (dirObj.exists(base) == false) | 1189 | if (dirObj.exists(base) == false) |
1190 | { | 1190 | { |
1191 | //qDebug("KStandardDirs::makeDir try to create : %s" , base.latin1()); | 1191 | //qDebug("KStandardDirs::makeDir try to create : %s" , base.latin1()); |
1192 | if (dirObj.mkdir(base) != true) | 1192 | if (dirObj.mkdir(base) != true) |
1193 | { | 1193 | { |
1194 | qDebug("KStandardDirs::makeDir could not create: %s" , base.latin1()); | 1194 | qDebug("KStandardDirs::makeDir could not create: %s" , base.latin1()); |
1195 | return false; | 1195 | return false; |
1196 | } | 1196 | } |
1197 | } | 1197 | } |
1198 | 1198 | ||
1199 | i = pos + 1; | 1199 | i = pos + 1; |
1200 | } | 1200 | } |
1201 | return true; | 1201 | return true; |
1202 | 1202 | ||
1203 | } | 1203 | } |
1204 | 1204 | ||
1205 | static QString readEnvPath(const char *env) | 1205 | static QString readEnvPath(const char *env) |
1206 | { | 1206 | { |
1207 | #ifdef _WIN32_ | 1207 | #ifdef _WIN32_ |
1208 | return ""; | 1208 | return ""; |
1209 | #else | 1209 | #else |
1210 | QCString c_path = getenv(env); | 1210 | QCString c_path = getenv(env); |
1211 | if (c_path.isEmpty()) | 1211 | if (c_path.isEmpty()) |
1212 | return QString::null; | 1212 | return QString::null; |
1213 | return QFile::decodeName(c_path); | 1213 | return QFile::decodeName(c_path); |
1214 | #endif | 1214 | #endif |
1215 | } | 1215 | } |
1216 | 1216 | ||
1217 | void KStandardDirs::addKDEDefaults() | 1217 | void KStandardDirs::addKDEDefaults() |
1218 | { | 1218 | { |
1219 | //qDebug("ERROR: KStandardDirs::addKDEDefaults() called "); | 1219 | //qDebug("ERROR: KStandardDirs::addKDEDefaults() called "); |
1220 | //return; | 1220 | //return; |
1221 | QStringList kdedirList; | 1221 | QStringList kdedirList; |
1222 | 1222 | ||
1223 | // begin KDEDIRS | 1223 | // begin KDEDIRS |
1224 | QString kdedirs = readEnvPath("MICROKDEDIRS"); | 1224 | QString kdedirs = readEnvPath("MICROKDEDIRS"); |
1225 | if (!kdedirs.isEmpty()) | 1225 | if (!kdedirs.isEmpty()) |
1226 | { | 1226 | { |
1227 | tokenize(kdedirList, kdedirs, ":"); | 1227 | tokenize(kdedirList, kdedirs, ":"); |
1228 | } | 1228 | } |
1229 | else | 1229 | else |
1230 | { | 1230 | { |
1231 | QString kdedir = readEnvPath("MICROKDEDIR"); | 1231 | QString kdedir = readEnvPath("MICROKDEDIR"); |
1232 | if (!kdedir.isEmpty()) | 1232 | if (!kdedir.isEmpty()) |
1233 | { | 1233 | { |
1234 | kdedir = KShell::tildeExpand(kdedir); | 1234 | kdedir = KShell::tildeExpand(kdedir); |
1235 | kdedirList.append(kdedir); | 1235 | kdedirList.append(kdedir); |
1236 | } | 1236 | } |
1237 | } | 1237 | } |
1238 | //US kdedirList.append(KDEDIR); | 1238 | //US kdedirList.append(KDEDIR); |
1239 | //US for embedded, add qtopia dir as kdedir | 1239 | //US for embedded, add qtopia dir as kdedir |
1240 | 1240 | ||
1241 | #ifndef DESKTOP_VERSION | 1241 | #ifndef DESKTOP_VERSION |
1242 | kdedirList.append(readEnvPath("QPEDIR" )); | 1242 | QString tmp = readEnvPath("QPEDIR"); |
1243 | if (!tmp.isEmpty()) | ||
1244 | kdedirList.append(tmp); | ||
1245 | |||
1246 | tmp = readEnvPath("QTDIR"); | ||
1247 | if (!tmp.isEmpty()) | ||
1248 | kdedirList.append(tmp); | ||
1249 | |||
1250 | tmp = readEnvPath("OPIEDIR"); | ||
1251 | if (!tmp.isEmpty()) | ||
1252 | kdedirList.append(tmp); | ||
1253 | |||
1243 | #endif | 1254 | #endif |
1244 | 1255 | ||
1245 | #ifdef __KDE_EXECPREFIX | 1256 | #ifdef __KDE_EXECPREFIX |
1246 | QString execPrefix(__KDE_EXECPREFIX); | 1257 | QString execPrefix(__KDE_EXECPREFIX); |
1247 | if (execPrefix!="NONE") | 1258 | if (execPrefix!="NONE") |
1248 | kdedirList.append(execPrefix); | 1259 | kdedirList.append(execPrefix); |
1249 | #endif | 1260 | #endif |
1250 | 1261 | ||
1251 | QString localKdeDir; | 1262 | QString localKdeDir; |
1252 | 1263 | ||
1253 | //US if (getuid()) | 1264 | //US if (getuid()) |
1254 | if (true) | 1265 | if (true) |
1255 | { | 1266 | { |
1256 | localKdeDir = readEnvPath("MICROKDEHOME"); | 1267 | localKdeDir = readEnvPath("MICROKDEHOME"); |
1257 | if (!localKdeDir.isEmpty()) | 1268 | if (!localKdeDir.isEmpty()) |
1258 | { | 1269 | { |
1259 | if (localKdeDir.at(localKdeDir.length()-1) != '/') | 1270 | if (localKdeDir.at(localKdeDir.length()-1) != '/') |
1260 | localKdeDir += '/'; | 1271 | localKdeDir += '/'; |
1261 | } | 1272 | } |
1262 | else | 1273 | else |
1263 | { | 1274 | { |
1264 | localKdeDir = QDir::homeDirPath() + "/kdepim/"; | 1275 | localKdeDir = QDir::homeDirPath() + "/kdepim/"; |
1265 | } | 1276 | } |
1266 | } | 1277 | } |
1267 | else | 1278 | else |
1268 | { | 1279 | { |
1269 | // We treat root different to prevent root messing up the | 1280 | // We treat root different to prevent root messing up the |
1270 | // file permissions in the users home directory. | 1281 | // file permissions in the users home directory. |
1271 | localKdeDir = readEnvPath("MICROKDEROOTHOME"); | 1282 | localKdeDir = readEnvPath("MICROKDEROOTHOME"); |
1272 | if (!localKdeDir.isEmpty()) | 1283 | if (!localKdeDir.isEmpty()) |
1273 | { | 1284 | { |
1274 | if (localKdeDir.at(localKdeDir.length()-1) != '/') | 1285 | if (localKdeDir.at(localKdeDir.length()-1) != '/') |
1275 | localKdeDir += '/'; | 1286 | localKdeDir += '/'; |
1276 | } | 1287 | } |
1277 | else | 1288 | else |
1278 | { | 1289 | { |
1279 | //US struct passwd *pw = getpwuid(0); | 1290 | //US struct passwd *pw = getpwuid(0); |
1280 | //US localKdeDir = QFile::decodeName((pw && pw->pw_dir) ? pw->pw_dir : "/root") + "/.microkde/"; | 1291 | //US localKdeDir = QFile::decodeName((pw && pw->pw_dir) ? pw->pw_dir : "/root") + "/.microkde/"; |
1281 | qDebug("KStandardDirs::addKDEDefaults: 1 has to be fixed"); | 1292 | qDebug("KStandardDirs::addKDEDefaults: 1 has to be fixed"); |
1282 | } | 1293 | } |
1283 | 1294 | ||
1284 | } | 1295 | } |
1285 | 1296 | ||
1286 | //US localKdeDir = appDir(); | 1297 | //US localKdeDir = appDir(); |
1287 | 1298 | ||
1288 | //US | 1299 | //US |
1289 | // qDebug("KStandardDirs::addKDEDefaults: localKdeDir=%s", localKdeDir.latin1()); | 1300 | // qDebug("KStandardDirs::addKDEDefaults: localKdeDir=%s", localKdeDir.latin1()); |
1290 | if (localKdeDir != "-/") | 1301 | if (localKdeDir != "-/") |
1291 | { | 1302 | { |
1292 | localKdeDir = KShell::tildeExpand(localKdeDir); | 1303 | localKdeDir = KShell::tildeExpand(localKdeDir); |
1293 | addPrefix(localKdeDir); | 1304 | addPrefix(localKdeDir); |
1294 | } | 1305 | } |
1295 | 1306 | ||
1296 | for (QStringList::ConstIterator it = kdedirList.begin(); | 1307 | for (QStringList::ConstIterator it = kdedirList.begin(); |
1297 | it != kdedirList.end(); it++) | 1308 | it != kdedirList.end(); it++) |
1298 | { | 1309 | { |
1299 | QString dir = KShell::tildeExpand(*it); | 1310 | QString dir = KShell::tildeExpand(*it); |
1300 | addPrefix(dir); | 1311 | addPrefix(dir); |
1301 | } | 1312 | } |
1302 | // end KDEDIRS | 1313 | // end KDEDIRS |
1303 | 1314 | ||
1304 | // begin XDG_CONFIG_XXX | 1315 | // begin XDG_CONFIG_XXX |
1305 | QStringList xdgdirList; | 1316 | QStringList xdgdirList; |
1306 | QString xdgdirs = readEnvPath("XDG_CONFIG_DIRS"); | 1317 | QString xdgdirs = readEnvPath("XDG_CONFIG_DIRS"); |
1307 | if (!xdgdirs.isEmpty()) | 1318 | if (!xdgdirs.isEmpty()) |
1308 | { | 1319 | { |
1309 | tokenize(xdgdirList, xdgdirs, ":"); | 1320 | tokenize(xdgdirList, xdgdirs, ":"); |
1310 | } | 1321 | } |
1311 | else | 1322 | else |
1312 | { | 1323 | { |
1313 | xdgdirList.clear(); | 1324 | xdgdirList.clear(); |
1314 | xdgdirList.append("/etc/xdg"); | 1325 | xdgdirList.append("/etc/xdg"); |
1315 | } | 1326 | } |
1316 | 1327 | ||
1317 | QString localXdgDir = readEnvPath("XDG_CONFIG_HOME"); | 1328 | QString localXdgDir = readEnvPath("XDG_CONFIG_HOME"); |
1318 | if (!localXdgDir.isEmpty()) | 1329 | if (!localXdgDir.isEmpty()) |
1319 | { | 1330 | { |
1320 | if (localXdgDir.at(localXdgDir.length()-1) != '/') | 1331 | if (localXdgDir.at(localXdgDir.length()-1) != '/') |
1321 | localXdgDir += '/'; | 1332 | localXdgDir += '/'; |
1322 | } | 1333 | } |
1323 | else | 1334 | else |
1324 | { | 1335 | { |
1325 | //US if (getuid()) | 1336 | //US if (getuid()) |
1326 | if (true) | 1337 | if (true) |
1327 | { | 1338 | { |
1328 | localXdgDir = QDir::homeDirPath() + "/.config/"; | 1339 | localXdgDir = QDir::homeDirPath() + "/.config/"; |
1329 | } | 1340 | } |
1330 | else | 1341 | else |
1331 | { | 1342 | { |
1332 | //US struct passwd *pw = getpwuid(0); | 1343 | //US struct passwd *pw = getpwuid(0); |
1333 | //US localXdgDir = QFile::decodeName((pw && pw->pw_dir) ? pw->pw_dir : "/root") + "/.config/"; | 1344 | //US localXdgDir = QFile::decodeName((pw && pw->pw_dir) ? pw->pw_dir : "/root") + "/.config/"; |
1334 | qDebug("KStandardDirs::addKDEDefaults: 2 has to be fixed"); | 1345 | qDebug("KStandardDirs::addKDEDefaults: 2 has to be fixed"); |
1335 | } | 1346 | } |
1336 | } | 1347 | } |
1337 | 1348 | ||
1338 | localXdgDir = KShell::tildeExpand(localXdgDir); | 1349 | localXdgDir = KShell::tildeExpand(localXdgDir); |
1339 | addXdgConfigPrefix(localXdgDir); | 1350 | addXdgConfigPrefix(localXdgDir); |
1340 | 1351 | ||
1341 | for (QStringList::ConstIterator it = xdgdirList.begin(); | 1352 | for (QStringList::ConstIterator it = xdgdirList.begin(); |
1342 | it != xdgdirList.end(); it++) | 1353 | it != xdgdirList.end(); it++) |
1343 | { | 1354 | { |
1344 | QString dir = KShell::tildeExpand(*it); | 1355 | QString dir = KShell::tildeExpand(*it); |
1345 | addXdgConfigPrefix(dir); | 1356 | addXdgConfigPrefix(dir); |
1346 | } | 1357 | } |
1347 | // end XDG_CONFIG_XXX | 1358 | // end XDG_CONFIG_XXX |
1348 | 1359 | ||
1349 | // begin XDG_DATA_XXX | 1360 | // begin XDG_DATA_XXX |
1350 | xdgdirs = readEnvPath("XDG_DATA_DIRS"); | 1361 | xdgdirs = readEnvPath("XDG_DATA_DIRS"); |
1351 | if (!xdgdirs.isEmpty()) | 1362 | if (!xdgdirs.isEmpty()) |
1352 | { | 1363 | { |
1353 | tokenize(xdgdirList, xdgdirs, ":"); | 1364 | tokenize(xdgdirList, xdgdirs, ":"); |
1354 | } | 1365 | } |
1355 | else | 1366 | else |
1356 | { | 1367 | { |
1357 | xdgdirList.clear(); | 1368 | xdgdirList.clear(); |
1358 | for (QStringList::ConstIterator it = kdedirList.begin(); | 1369 | for (QStringList::ConstIterator it = kdedirList.begin(); |
1359 | it != kdedirList.end(); it++) | 1370 | it != kdedirList.end(); it++) |
1360 | { | 1371 | { |
1361 | QString dir = *it; | 1372 | QString dir = *it; |
1362 | if (dir.at(dir.length()-1) != '/') | 1373 | if (dir.at(dir.length()-1) != '/') |
1363 | dir += '/'; | 1374 | dir += '/'; |
1364 | xdgdirList.append(dir+"share/"); | 1375 | xdgdirList.append(dir+"share/"); |
1365 | } | 1376 | } |
1366 | 1377 | ||
1367 | xdgdirList.append("/usr/local/share/"); | 1378 | xdgdirList.append("/usr/local/share/"); |
1368 | xdgdirList.append("/usr/share/"); | 1379 | xdgdirList.append("/usr/share/"); |
1369 | } | 1380 | } |
1370 | 1381 | ||
1371 | localXdgDir = readEnvPath("XDG_DATA_HOME"); | 1382 | localXdgDir = readEnvPath("XDG_DATA_HOME"); |
1372 | if (!localXdgDir.isEmpty()) | 1383 | if (!localXdgDir.isEmpty()) |
1373 | { | 1384 | { |
1374 | if (localXdgDir.at(localXdgDir.length()-1) != '/') | 1385 | if (localXdgDir.at(localXdgDir.length()-1) != '/') |
1375 | localXdgDir += '/'; | 1386 | localXdgDir += '/'; |
1376 | } | 1387 | } |
1377 | else | 1388 | else |
1378 | { | 1389 | { |
1379 | //US if (getuid()) | 1390 | //US if (getuid()) |
1380 | if (true) | 1391 | if (true) |
1381 | { | 1392 | { |
1382 | localXdgDir = QDir::homeDirPath() + "/.local/share/"; | 1393 | localXdgDir = QDir::homeDirPath() + "/.local/share/"; |
1383 | } | 1394 | } |
1384 | else | 1395 | else |
1385 | { | 1396 | { |
1386 | //US struct passwd *pw = getpwuid(0); | 1397 | //US struct passwd *pw = getpwuid(0); |
1387 | //US localXdgDir = QFile::decodeName((pw && pw->pw_dir) ? pw->pw_dir : "/root") + "/.local/share/"; | 1398 | //US localXdgDir = QFile::decodeName((pw && pw->pw_dir) ? pw->pw_dir : "/root") + "/.local/share/"; |
1388 | qDebug("KStandardDirs::addKDEDefaults: 3 has to be fixed"); | 1399 | qDebug("KStandardDirs::addKDEDefaults: 3 has to be fixed"); |
1389 | } | 1400 | } |
1390 | } | 1401 | } |
1391 | 1402 | ||
1392 | localXdgDir = KShell::tildeExpand(localXdgDir); | 1403 | localXdgDir = KShell::tildeExpand(localXdgDir); |
1393 | addXdgDataPrefix(localXdgDir); | 1404 | addXdgDataPrefix(localXdgDir); |
1394 | 1405 | ||
1395 | for (QStringList::ConstIterator it = xdgdirList.begin(); | 1406 | for (QStringList::ConstIterator it = xdgdirList.begin(); |
1396 | it != xdgdirList.end(); it++) | 1407 | it != xdgdirList.end(); it++) |
1397 | { | 1408 | { |
1398 | QString dir = KShell::tildeExpand(*it); | 1409 | QString dir = KShell::tildeExpand(*it); |
1399 | 1410 | ||
1400 | addXdgDataPrefix(dir); | 1411 | addXdgDataPrefix(dir); |
1401 | } | 1412 | } |
1402 | // end XDG_DATA_XXX | 1413 | // end XDG_DATA_XXX |
1403 | 1414 | ||
1404 | 1415 | ||
1405 | uint index = 0; | 1416 | uint index = 0; |
1406 | while (types[index] != 0) { | 1417 | while (types[index] != 0) { |
1407 | addResourceType(types[index], kde_default(types[index])); | 1418 | addResourceType(types[index], kde_default(types[index])); |
1408 | index++; | 1419 | index++; |
1409 | } | 1420 | } |
1410 | 1421 | ||
1411 | addResourceDir("home", QDir::homeDirPath()); | 1422 | addResourceDir("home", QDir::homeDirPath()); |
1412 | } | 1423 | } |
1413 | 1424 | ||
1414 | void KStandardDirs::checkConfig() const | 1425 | void KStandardDirs::checkConfig() const |
1415 | { | 1426 | { |
1416 | /*US | 1427 | /*US |
1417 | if (!addedCustoms && KGlobal::_instance && KGlobal::_instance->_config) | 1428 | if (!addedCustoms && KGlobal::_instance && KGlobal::_instance->_config) |
1418 | const_cast<KStandardDirs*>(this)->addCustomized(KGlobal::_instance->_config); | 1429 | const_cast<KStandardDirs*>(this)->addCustomized(KGlobal::_instance->_config); |
1419 | */ | 1430 | */ |
1420 | if (!addedCustoms && KGlobal::config()) | 1431 | if (!addedCustoms && KGlobal::config()) |
1421 | const_cast<KStandardDirs*>(this)->addCustomized(KGlobal::config()); | 1432 | const_cast<KStandardDirs*>(this)->addCustomized(KGlobal::config()); |
1422 | } | 1433 | } |
1423 | 1434 | ||
1424 | bool KStandardDirs::addCustomized(KConfig *config) | 1435 | bool KStandardDirs::addCustomized(KConfig *config) |
1425 | { | 1436 | { |
1426 | if (addedCustoms) // there are already customized entries | 1437 | if (addedCustoms) // there are already customized entries |
1427 | return false; // we just quite and hope they are the right ones | 1438 | return false; // we just quite and hope they are the right ones |
1428 | 1439 | ||
1429 | // save the numbers of config directories. If this changes, | 1440 | // save the numbers of config directories. If this changes, |
1430 | // we will return true to give KConfig a chance to reparse | 1441 | // we will return true to give KConfig a chance to reparse |
1431 | uint configdirs = resourceDirs("config").count(); | 1442 | uint configdirs = resourceDirs("config").count(); |
1432 | 1443 | ||
1433 | // reading the prefixes in | 1444 | // reading the prefixes in |
1434 | QString oldGroup = config->group(); | 1445 | QString oldGroup = config->group(); |
1435 | config->setGroup("Directories"); | 1446 | config->setGroup("Directories"); |
1436 | 1447 | ||
1437 | QStringList list; | 1448 | QStringList list; |
1438 | QStringList::ConstIterator it; | 1449 | QStringList::ConstIterator it; |
1439 | list = config->readListEntry("prefixes"); | 1450 | list = config->readListEntry("prefixes"); |
1440 | for (it = list.begin(); it != list.end(); it++) | 1451 | for (it = list.begin(); it != list.end(); it++) |
1441 | addPrefix(*it); | 1452 | addPrefix(*it); |
1442 | 1453 | ||
1443 | // iterating over all entries in the group Directories | 1454 | // iterating over all entries in the group Directories |
1444 | // to find entries that start with dir_$type | 1455 | // to find entries that start with dir_$type |
1445 | /*US | 1456 | /*US |
1446 | QMap<QString, QString> entries = config->entryMap("Directories"); | 1457 | QMap<QString, QString> entries = config->entryMap("Directories"); |
1447 | 1458 | ||
1448 | QMap<QString, QString>::ConstIterator it2; | 1459 | QMap<QString, QString>::ConstIterator it2; |
1449 | for (it2 = entries.begin(); it2 != entries.end(); it2++) | 1460 | for (it2 = entries.begin(); it2 != entries.end(); it2++) |
1450 | { | 1461 | { |
1451 | QString key = it2.key(); | 1462 | QString key = it2.key(); |
1452 | if (key.left(4) == "dir_") { | 1463 | if (key.left(4) == "dir_") { |
1453 | // generate directory list, there may be more than 1. | 1464 | // generate directory list, there may be more than 1. |
1454 | QStringList dirs = QStringList::split(',', *it2); | 1465 | QStringList dirs = QStringList::split(',', *it2); |
1455 | QStringList::Iterator sIt(dirs.begin()); | 1466 | QStringList::Iterator sIt(dirs.begin()); |
1456 | QString resType = key.mid(4, key.length()); | 1467 | QString resType = key.mid(4, key.length()); |
1457 | for (; sIt != dirs.end(); ++sIt) { | 1468 | for (; sIt != dirs.end(); ++sIt) { |
1458 | addResourceDir(resType.latin1(), *sIt); | 1469 | addResourceDir(resType.latin1(), *sIt); |
1459 | } | 1470 | } |
1460 | } | 1471 | } |
1461 | } | 1472 | } |
1462 | 1473 | ||
1463 | // Process KIOSK restrictions. | 1474 | // Process KIOSK restrictions. |
1464 | config->setGroup("KDE Resource Restrictions"); | 1475 | config->setGroup("KDE Resource Restrictions"); |
1465 | entries = config->entryMap("KDE Resource Restrictions"); | 1476 | entries = config->entryMap("KDE Resource Restrictions"); |
1466 | for (it2 = entries.begin(); it2 != entries.end(); it2++) | 1477 | for (it2 = entries.begin(); it2 != entries.end(); it2++) |
1467 | { | 1478 | { |
1468 | QString key = it2.key(); | 1479 | QString key = it2.key(); |
1469 | if (!config->readBoolEntry(key, true)) | 1480 | if (!config->readBoolEntry(key, true)) |
1470 | { | 1481 | { |
1471 | d->restrictionsActive = true; | 1482 | d->restrictionsActive = true; |
1472 | d->restrictions.insert(key.latin1(), &d->restrictionsActive); // Anything will do | 1483 | d->restrictions.insert(key.latin1(), &d->restrictionsActive); // Anything will do |
1473 | dircache.remove(key.latin1()); | 1484 | dircache.remove(key.latin1()); |
1474 | } | 1485 | } |
1475 | } | 1486 | } |
1476 | */ | 1487 | */ |
1477 | // save it for future calls - that will return | 1488 | // save it for future calls - that will return |
1478 | addedCustoms = true; | 1489 | addedCustoms = true; |
1479 | config->setGroup(oldGroup); | 1490 | config->setGroup(oldGroup); |
1480 | 1491 | ||
1481 | // return true if the number of config dirs changed | 1492 | // return true if the number of config dirs changed |
1482 | return (resourceDirs("config").count() != configdirs); | 1493 | return (resourceDirs("config").count() != configdirs); |
1483 | } | 1494 | } |
1484 | 1495 | ||
1485 | QString KStandardDirs::localkdedir() const | 1496 | QString KStandardDirs::localkdedir() const |
1486 | { | 1497 | { |
1487 | // Return the prefix to use for saving | 1498 | // Return the prefix to use for saving |
1488 | return prefixes.first(); | 1499 | return prefixes.first(); |
1489 | } | 1500 | } |
1490 | 1501 | ||
1491 | QString KStandardDirs::localxdgdatadir() const | 1502 | QString KStandardDirs::localxdgdatadir() const |
1492 | { | 1503 | { |
1493 | // Return the prefix to use for saving | 1504 | // Return the prefix to use for saving |
1494 | return d->xdgdata_prefixes.first(); | 1505 | return d->xdgdata_prefixes.first(); |
1495 | } | 1506 | } |
1496 | 1507 | ||
1497 | QString KStandardDirs::localxdgconfdir() const | 1508 | QString KStandardDirs::localxdgconfdir() const |
1498 | { | 1509 | { |