Ticket #46536: fix-qstandardpaths.patch

File fix-qstandardpaths.patch, 3.1 KB (added by RJVB (René Bertin), 10 years ago)
  • qtbase/src/corelib/io/qstandardpaths_mac.cpp

     
    3737
    3838#ifndef QT_BOOTSTRAPPED
    3939#include <qcoreapplication.h>
     40#include <qlibraryinfo.h>
    4041#endif
    4142
    4243#include <CoreFoundation/CoreFoundation.h>
     
    169169    }
    170170}
    171171
     172static 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
     193static 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
     210static 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
    172227QStringList QStandardPaths::standardLocations(StandardLocation type)
    173228{
    174229    QStringList dirs;
    175230
     231    if (type == GenericDataLocation) {
     232        dirs.append(xdgDataDirs());
     233    }
     234
    176235    if (type == GenericDataLocation || type == AppDataLocation || type == AppLocalDataLocation || type == GenericCacheLocation || type == CacheLocation) {
    177236        const QString path = macLocation(type, kOnAppropriateDisk);
    178237        if (!path.isEmpty())
    179238            dirs.append(path);
    180239    }
    181240
     241    if (type == GenericConfigLocation || type == ConfigLocation)
     242        dirs.append(xdgConfigDirs());
     243
    182244    if (type == AppDataLocation || type == AppLocalDataLocation) {
     245        QStringList xdgDirs = xdgDataDirs();
     246        for (int i = 0; i < xdgDirs.count(); ++i) {
     247            appendOrganizationAndApp(xdgDirs[i]);
     248        }
     249        dirs.append(xdgDirs);
     250
    183251        CFBundleRef mainBundle = CFBundleGetMainBundle();
    184252        if (mainBundle) {
    185253            CFURLRef bundleUrl = CFBundleCopyBundleURL(mainBundle);