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