[KDE/Mac] QStandardPaths possible solution

Jeremy Whiting jpwhiting at kde.org
Mon Jan 5 22:46:39 UTC 2015


None of those includes were needed apparently. I've attached an updated
patch. I also looked at the 5.3 branch and it has qstandardpaths_mac.cpp
instead of qstandardpaths_mac.mm so a similar patch that changes that file
would be needed for 5.3.

BR,
Jeremy

On Mon, Jan 5, 2015 at 2:46 PM, Jeremy Whiting <jpwhiting at kde.org> wrote:

> No, kf5 doesn't require Qt 5.4 yet, but some of plasma does iirc. On the
> other hand, getting this into qt itself is not going to happen on Qt 5.3
> branch (it's frozen) or 5.4 (it's also frozen), which is why I
> created/updated the patch for the 5.4 branch (I guess I really should have
> used the dev branch instead as that will become 5.5). I'm not sure if the
> patch will apply to 5.3 or not, the patch was changing
> qstandardpaths_mac.cpp which doesn't even exist in the 5.4 branch (it's
> qstandardpaths_mac.mm here) If it was .mm in 5.3 it should apply or would
> be simple to tweak so that it does apply for macports to use I guess.
>
> BR,
> Jeremy
>
> On Mon, Jan 5, 2015 at 2:41 PM, René J.V. <rjvbertin at gmail.com> wrote:
>
>> On Monday January 05 2015 13:51:18 Jeremy Whiting wrote:
>>
>> > I've looked at Marko's patch and had to tweak it a bit to get it to
>> apply
>> > to qt 5.4 branch. I've attached a first try here while it builds at the
>> > same time so I can test it.
>>
>> Could we please make sure the fix applies to Qt 5.3 also? That's what's
>> currently in MacPorts, and unless the maintainer intends to upgrade it to
>> 5.4 soon, that's what I'll be working on to make it co-installable with Qt4
>> ...
>>
>> KF5 doesn't yet require Qt5.4, or does it??
>>
>> R.
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.kde.org/pipermail/kde-mac/attachments/20150105/bb2674f9/attachment.html>
-------------- next part --------------
diff --git a/src/corelib/io/qstandardpaths_mac.mm b/src/corelib/io/qstandardpaths_mac.mm
index 01d1c01..a2d56f3 100644
--- a/src/corelib/io/qstandardpaths_mac.mm
+++ b/src/corelib/io/qstandardpaths_mac.mm
@@ -127,7 +127,7 @@ static QString macLocation(QStandardPaths::StandardLocation type, short domain)
     if (err)
        return QString();
 
-   QString path = getFullPath(ref);
+    QString path = getFullPath(ref);
 
     if (type == QStandardPaths::AppDataLocation || type == QStandardPaths::AppLocalDataLocation || type == QStandardPaths::CacheLocation)
         appendOrganizationAndApp(path);
@@ -177,6 +177,38 @@ QString QStandardPaths::writableLocation(StandardLocation type)
     }
 }
 
+static QStringList xdgDataDirs()
+{
+    QStringList dirs;
+    // http://standards.freedesktop.org/basedir-spec/latest/
+    QString xdgDataDirsEnv = QFile::decodeName(qgetenv("XDG_DATA_DIRS"));
+    if (xdgDataDirsEnv.isEmpty()) {
+        dirs.append(QString::fromLatin1("/opt/local/share"));
+        dirs.append(QString::fromLatin1("/Library/Application Support"));
+    } else {
+        dirs = xdgDataDirsEnv.split(QLatin1Char(':'), QString::SkipEmptyParts);
+
+        // Normalize 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_DATA_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();
+    }
+    return dirs;
+}
+
 QStringList QStandardPaths::standardLocations(StandardLocation type)
 {
     QStringList dirs;
@@ -187,7 +219,15 @@ QStringList QStandardPaths::standardLocations(StandardLocation type)
             dirs.append(path);
     }
 
+    if (type == GenericDataLocation)
+        dirs.append(xdgDataDirs());
+
     if (type == AppDataLocation || type == AppLocalDataLocation) {
+        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);


More information about the kde-mac mailing list