| | 179 | static void normaliseDirs(QStringList &dirs) |
| | 180 | { |
| | 181 | // Normalise paths, skip relative paths |
| | 182 | QMutableListIterator<QString> it(dirs); |
| | 183 | while (it.hasNext()) { |
| | 184 | const QString dir = it.next(); |
| | 185 | if (!dir.startsWith(QLatin1Char('/'))) |
| | 186 | it.remove(); |
| | 187 | else |
| | 188 | it.setValue(QDir::cleanPath(dir)); |
| | 189 | } |
| | 190 | |
| | 191 | // Remove duplicates from the list, there's no use for duplicated |
| | 192 | // paths in XDG_CONFIG_DIRS - if it's not found in the given |
| | 193 | // directory the first time, it won't be there the second time. |
| | 194 | // Plus duplicate paths causes problems for example for mimetypes, |
| | 195 | // where duplicate paths here lead to duplicated mime types returned |
| | 196 | // for a file, eg "text/plain,text/plain" instead of "text/plain" |
| | 197 | dirs.removeDuplicates(); |
| | 198 | } |
| | 199 | |
| | 200 | static QStringList xdgConfigDirs() |
| | 201 | { |
| | 202 | QStringList dirs; |
| | 203 | // http://standards.freedesktop.org/basedir-spec/latest/ |
| | 204 | QString xdgConfigDirsEnv = QFile::decodeName(qgetenv("XDG_CONFIG_DIRS")); |
| | 205 | if (xdgConfigDirsEnv.isEmpty()) { |
| | 206 | #ifndef QT_BOOTSTRAPPED |
| | 207 | dirs.append(QLibraryInfo::location(QLibraryInfo::PrefixPath) + QString::fromLatin1("/config")); |
| | 208 | #endif |
| | 209 | } else { |
| | 210 | dirs = xdgConfigDirsEnv.split(QLatin1Char(':'), QString::SkipEmptyParts); |
| | 211 | |
| | 212 | normaliseDirs(dirs); |
| | 213 | } |
| | 214 | return dirs; |
| | 215 | } |
| | 216 | |
| | 217 | static QStringList xdgDataDirs() |
| | 218 | { |
| | 219 | QStringList dirs; |
| | 220 | // http://standards.freedesktop.org/basedir-spec/latest/ |
| | 221 | QString xdgDataDirsEnv = QFile::decodeName(qgetenv("XDG_DATA_DIRS")); |
| | 222 | if (xdgDataDirsEnv.isEmpty()) { |
| | 223 | #ifndef QT_BOOTSTRAPPED |
| | 224 | dirs.append(QLibraryInfo::location(QLibraryInfo::PrefixPath) + QString::fromLatin1("/share")); |
| | 225 | #endif |
| | 226 | } else { |
| | 227 | dirs = xdgDataDirsEnv.split(QLatin1Char(':'), QString::SkipEmptyParts); |
| | 228 | |
| | 229 | normaliseDirs(dirs); |
| | 230 | } |
| | 231 | return dirs; |
| | 232 | } |
| | 233 | |