--- qtbase/src/corelib/io/orig.qstandardpaths_mac.cpp	2014-09-11 12:48:06.000000000 +0200
+++ qtbase/src/corelib/io/qstandardpaths_mac.cpp	2015-01-10 22:11:59.000000000 +0100
@@ -45,6 +45,7 @@
 
 #ifndef QT_BOOTSTRAPPED
 #include <qcoreapplication.h>
+#include <qlibraryinfo.h>
 #endif
 
 #include <CoreFoundation/CoreFoundation.h>
@@ -126,7 +127,7 @@
     if (err)
        return QString();
 
-   QString path = getFullPath(ref);
+    QString path = getFullPath(ref);
 
     if (type == QStandardPaths::DataLocation || type == QStandardPaths::CacheLocation)
         appendOrganizationAndApp(path);
@@ -175,17 +176,85 @@
     }
 }
 
+static void normaliseDirs(QStringList &dirs)
+{
+    // Normalise paths, skip relative paths
+    QMutableListIterator<QString> it(dirs);
+    while (it.hasNext()) {
+        const QString dir = it.next();
+        if (!dir.startsWith(QLatin1Char('/')))
+            it.remove();
+        else
+            it.setValue(QDir::cleanPath(dir));
+    }
+
+    // Remove duplicates from the list, there's no use for duplicated
+    // paths in XDG_CONFIG_DIRS - if it's not found in the given
+    // directory the first time, it won't be there the second time.
+    // Plus duplicate paths causes problems for example for mimetypes,
+    // where duplicate paths here lead to duplicated mime types returned
+    // for a file, eg "text/plain,text/plain" instead of "text/plain"
+    dirs.removeDuplicates();
+}
+
+static QStringList xdgConfigDirs()
+{
+    QStringList dirs;
+    // http://standards.freedesktop.org/basedir-spec/latest/
+    QString xdgConfigDirsEnv = QFile::decodeName(qgetenv("XDG_CONFIG_DIRS"));
+    if (xdgConfigDirsEnv.isEmpty()) {
+#ifndef QT_BOOTSTRAPPED
+        dirs.append(QLibraryInfo::location(QLibraryInfo::PrefixPath) + QString::fromLatin1("/config"));
+#endif
+    } else {
+        dirs = xdgConfigDirsEnv.split(QLatin1Char(':'), QString::SkipEmptyParts);
+
+        normaliseDirs(dirs);
+    }
+    return dirs;
+}
+
+static QStringList xdgDataDirs()
+{
+    QStringList dirs;
+    // http://standards.freedesktop.org/basedir-spec/latest/
+    QString xdgDataDirsEnv = QFile::decodeName(qgetenv("XDG_DATA_DIRS"));
+    if (xdgDataDirsEnv.isEmpty()) {
+#ifndef QT_BOOTSTRAPPED
+        dirs.append(QLibraryInfo::location(QLibraryInfo::PrefixPath) + QString::fromLatin1("/share"));
+#endif
+    } else {
+        dirs = xdgDataDirsEnv.split(QLatin1Char(':'), QString::SkipEmptyParts);
+
+        normaliseDirs(dirs);
+    }
+    return dirs;
+}
+
 QStringList QStandardPaths::standardLocations(StandardLocation type)
 {
     QStringList dirs;
 
+    if (type == GenericDataLocation) {
+        dirs.append(xdgDataDirs());
+    }
+
     if (type == GenericDataLocation || type == DataLocation || type == GenericCacheLocation || type == CacheLocation) {
         const QString path = macLocation(type, kOnAppropriateDisk);
         if (!path.isEmpty())
             dirs.append(path);
     }
 
+    if (type == GenericConfigLocation || type == ConfigLocation)
+        dirs.append(xdgConfigDirs());
+
     if (type == DataLocation) {
+        QStringList xdgDirs = xdgDataDirs();
+        for (int i = 0; i < xdgDirs.count(); ++i) {
+            appendOrganizationAndApp(xdgDirs[i]);
+        }
+        dirs.append(xdgDirs);
+
         CFBundleRef mainBundle = CFBundleGetMainBundle();
         if (mainBundle) {
             CFURLRef bundleUrl = CFBundleCopyBundleURL(mainBundle);
