diff options
author | Samuel Gaist <samuel.gaist@edeltech.ch> | 2014-01-29 08:38:40 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2014-03-14 22:40:19 +0100 |
commit | bcfc68f9cd00982decd7ceb312966caf6b1ca05e (patch) | |
tree | 9c59c4ddca94df148cf534a4a4a056ec8c9d00df /src/corelib/io/qfilesystemengine_unix.cpp | |
parent | 6b56b2ddb2c3b744047cd35cc88a16531a2d3048 (diff) |
Use Uniform Type Identifiers to detect OS X bundles
Following Apple's documentation, the first step to identify a
bundle is to check if it has a known extension. Currently, it's
done using string comparisons ored in an if statement. The list
is not complete and new types, whether provided by a system update
or other means, can't be detected.
The new approach is to use Uniform Type Identifier which queries
the OS directly to check whether the extension conforms to
kUTTypeBundle. That includes e.g. applications, frameworks etc.
Task-number: QTBUG-31884
Change-Id: Ief73a83904adf27ccb71b0070e67cba081d1fd4a
Reviewed-by: Jake Petroules <jake.petroules@petroules.com>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/io/qfilesystemengine_unix.cpp')
-rw-r--r-- | src/corelib/io/qfilesystemengine_unix.cpp | 48 |
1 files changed, 18 insertions, 30 deletions
diff --git a/src/corelib/io/qfilesystemengine_unix.cpp b/src/corelib/io/qfilesystemengine_unix.cpp index ea3a3ca13d..6c0f31fb55 100644 --- a/src/corelib/io/qfilesystemengine_unix.cpp +++ b/src/corelib/io/qfilesystemengine_unix.cpp @@ -1,7 +1,7 @@ /**************************************************************************** ** -** Copyright (C) 2013 Samuel Gaist <samuel.gaist@edeltech.ch>> ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Copyright (C) 2013 Samuel Gaist <samuel.gaist@edeltech.ch> ** Contact: http://www.qt-project.org/legal ** ** This file is part of the QtCore module of the Qt Toolkit. @@ -89,35 +89,23 @@ static bool isPackage(const QFileSystemMetaData &data, const QFileSystemEntry &e QFileInfo info(entry.filePath()); QString suffix = info.suffix(); - // First step: is the extenstion known ? - if (suffix == QLatin1String("app") - || suffix == QLatin1String("debug") - || suffix == QLatin1String("profile") - || suffix == QLatin1String("bundle") - || suffix == QLatin1String("pkg")) { - return true; - } - - // Second step: check if an application knows the package type - const QByteArray &native = entry.nativeFilePath(); - const char *nativeFilePath = native.constData(); - int nativeFilePathLength = native.size(); - - QCFType<CFStringRef> path = CFStringCreateWithBytes(0, - reinterpret_cast<const UInt8*>(nativeFilePath), - nativeFilePathLength, - kCFStringEncodingUTF8, - false); - - QCFType<CFURLRef> url = CFURLCreateWithFileSystemPath(0, path, kCFURLPOSIXPathStyle, true); - - UInt32 type, creator; - // Well created packages have the PkgInfo file - if (CFBundleGetPackageInfoInDirectory(url, &type, &creator)) - return true; - - // Find if an application other than Finder claims to know how to handle the package if (suffix.length() > 0) { + // First step: is the extension known ? + CFStringRef extensionRef = QCFString::toCFStringRef(suffix); + CFStringRef uniformTypeIdentifier = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, extensionRef, NULL); + if (UTTypeConformsTo(uniformTypeIdentifier, kUTTypeBundle)) + return true; + + // Second step: check if an application knows the package type + CFStringRef path = QCFString::toCFStringRef(entry.filePath()); + QCFType<CFURLRef> url = CFURLCreateWithFileSystemPath(0, path, kCFURLPOSIXPathStyle, true); + + UInt32 type, creator; + // Well created packages have the PkgInfo file + if (CFBundleGetPackageInfoInDirectory(url, &type, &creator)) + return true; + + // Find if an application other than Finder claims to know how to handle the package QCFType<CFURLRef> application; LSGetApplicationForURL(url, kLSRolesEditor|kLSRolesViewer|kLSRolesViewer, @@ -134,7 +122,7 @@ static bool isPackage(const QFileSystemMetaData &data, const QFileSystemEntry &e // Third step: check if the directory has the package bit set FSRef packageRef; - FSPathMakeRef((UInt8 *)nativeFilePath, &packageRef, NULL); + FSPathMakeRef((UInt8 *)entry.nativeFilePath().constData(), &packageRef, NULL); FSCatalogInfo catalogInfo; FSGetCatalogInfo(&packageRef, |