Ticket #46496: fix-qstandardpaths.patch

File fix-qstandardpaths.patch, 3.4 KB (added by RJVB (René Bertin), 10 years ago)

move ${prefix}/share to the start of the list of system-wide search paths

  • qstandardpaths_mac.cpp

    old new  
    4545
    4646#ifndef QT_BOOTSTRAPPED
    4747#include <qcoreapplication.h>
     48#include <qlibraryinfo.h>
    4849#endif
    4950
    5051#include <CoreFoundation/CoreFoundation.h>
     
    126127    if (err)
    127128       return QString();
    128129
    129    QString path = getFullPath(ref);
     130    QString path = getFullPath(ref);
    130131
    131132    if (type == QStandardPaths::DataLocation || type == QStandardPaths::CacheLocation)
    132133        appendOrganizationAndApp(path);
     
    175176    }
    176177}
    177178
     179static 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
     200static 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
     217static 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
    178234QStringList QStandardPaths::standardLocations(StandardLocation type)
    179235{
    180236    QStringList dirs;
    181237
     238    if (type == GenericDataLocation) {
     239        dirs.append(xdgDataDirs());
     240    }
     241
    182242    if (type == GenericDataLocation || type == DataLocation || type == GenericCacheLocation || type == CacheLocation) {
    183243        const QString path = macLocation(type, kOnAppropriateDisk);
    184244        if (!path.isEmpty())
    185245            dirs.append(path);
    186246    }
    187247
     248    if (type == GenericConfigLocation || type == ConfigLocation)
     249        dirs.append(xdgConfigDirs());
     250
    188251    if (type == DataLocation) {
     252        QStringList xdgDirs = xdgDataDirs();
     253        for (int i = 0; i < xdgDirs.count(); ++i) {
     254            appendOrganizationAndApp(xdgDirs[i]);
     255        }
     256        dirs.append(xdgDirs);
     257
    189258        CFBundleRef mainBundle = CFBundleGetMainBundle();
    190259        if (mainBundle) {
    191260            CFURLRef bundleUrl = CFBundleCopyBundleURL(mainBundle);