From 5f6284a98baded49d31b9723117a98d3bd010cfe Mon Sep 17 00:00:00 2001 From: Samuel Gaist Date: Sun, 23 Nov 2014 01:00:05 +0100 Subject: [PATCH] Implement Download folder path retrieval on OS X The current implementation returns the DocumentLocation folder. Since now only cocoa is supported, we can use NSFileManager to get the correct path. [ChangeLog][QtCore][OS X] Now QStandardPaths returns the correct path for the DownloadLocation. Change-Id: Ic0ea3ebf8585a1e34a7b43c734df78fd3949d4d4 Reviewed-by: Thiago Macieira --- src/corelib/io/io.pri | 5 ++--- src/corelib/io/qstandardpaths.cpp | 2 +- ...{qstandardpaths_mac.cpp => qstandardpaths_mac.mm} | 12 ++++++++++-- src/tools/bootstrap/bootstrap.pro | 7 ++++--- 4 files changed, 17 insertions(+), 9 deletions(-) rename src/corelib/io/{qstandardpaths_mac.cpp => qstandardpaths_mac.mm} (94%) diff --git a/src/corelib/io/io.pri b/src/corelib/io/io.pri index bdc362ef22..77788e3cca 100644 --- a/src/corelib/io/io.pri +++ b/src/corelib/io/io.pri @@ -148,9 +148,8 @@ win32 { HEADERS += io/qfilesystemwatcher_fsevents_p.h } macx { - SOURCES += \ - io/qstorageinfo_mac.cpp \ - io/qstandardpaths_mac.cpp + SOURCES += io/qstorageinfo_mac.cpp + OBJECTIVE_SOURCES += io/qstandardpaths_mac.mm LIBS += -framework DiskArbitration -framework IOKit } else:ios { OBJECTIVE_SOURCES += io/qstandardpaths_ios.mm diff --git a/src/corelib/io/qstandardpaths.cpp b/src/corelib/io/qstandardpaths.cpp index c206e432f6..6950d58fda 100644 --- a/src/corelib/io/qstandardpaths.cpp +++ b/src/corelib/io/qstandardpaths.cpp @@ -195,7 +195,7 @@ QT_BEGIN_NAMESPACE \li "~/Library/Preferences" \li "C:/Users//AppData/Local", "C:/ProgramData" \row \li DownloadLocation - \li "~/Documents" + \li "~/Downloads" \li "C:/Users//Documents" \row \li GenericCacheLocation \li "~/Library/Caches", "/Library/Caches" diff --git a/src/corelib/io/qstandardpaths_mac.cpp b/src/corelib/io/qstandardpaths_mac.mm similarity index 94% rename from src/corelib/io/qstandardpaths_mac.cpp rename to src/corelib/io/qstandardpaths_mac.mm index 673b734d40..01d1c01f78 100644 --- a/src/corelib/io/qstandardpaths_mac.cpp +++ b/src/corelib/io/qstandardpaths_mac.mm @@ -33,6 +33,7 @@ #include "qstandardpaths.h" #include +#include #include #ifndef QT_BOOTSTRAPPED @@ -55,8 +56,6 @@ OSType translateLocation(QStandardPaths::StandardLocation type) return kPreferencesFolderType; case QStandardPaths::DesktopLocation: return kDesktopFolderType; - case QStandardPaths::DownloadLocation: // needs NSSearchPathForDirectoriesInDomains with NSDownloadsDirectory - // which needs an objective-C *.mm file... case QStandardPaths::DocumentsLocation: return kDocumentsFolderType; case QStandardPaths::FontsLocation: @@ -113,6 +112,15 @@ static void appendOrganizationAndApp(QString &path) static QString macLocation(QStandardPaths::StandardLocation type, short domain) { + // https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSFileManager_Class/index.html + if (type == QStandardPaths::DownloadLocation) { + NSFileManager *fileManager = [NSFileManager defaultManager]; + NSURL *url = [fileManager URLForDirectory:NSDownloadsDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:NO error:nil]; + if (!url) + return QString(); + return QString::fromNSString([url path]); + } + // http://developer.apple.com/documentation/Carbon/Reference/Folder_Manager/Reference/reference.html FSRef ref; OSErr err = FSFindFolder(domain, translateLocation(type), false, &ref); diff --git a/src/tools/bootstrap/bootstrap.pro b/src/tools/bootstrap/bootstrap.pro index 2b58bff8f3..527a932c4d 100644 --- a/src/tools/bootstrap/bootstrap.pro +++ b/src/tools/bootstrap/bootstrap.pro @@ -132,12 +132,13 @@ win32:SOURCES += ../../corelib/io/qfilesystemengine_win.cpp \ mac { SOURCES += ../../corelib/kernel/qcoreapplication_mac.cpp \ ../../corelib/kernel/qcore_mac.cpp - LIBS += -framework CoreServices + LIBS += -framework CoreServices -framework Foundation } macx { - SOURCES += \ - ../../corelib/io/qstandardpaths_mac.cpp + OBJECTIVE_SOURCES += \ + ../../corelib/tools/qstring_mac.mm \ + ../../corelib/io/qstandardpaths_mac.mm } else:unix { SOURCES += \ ../../corelib/io/qstandardpaths_unix.cpp