Skip to content

Commit

Permalink
clean up objective-c files: only QUrlFix.mm is required
Browse files Browse the repository at this point in the history
  • Loading branch information
devernay committed Jun 23, 2016
1 parent c0c8423 commit f37cc8c
Show file tree
Hide file tree
Showing 8 changed files with 300 additions and 365 deletions.
9 changes: 5 additions & 4 deletions Engine/Engine.pro
Original file line number Diff line number Diff line change
Expand Up @@ -552,9 +552,10 @@ OTHER_FILES += \

# QMAKE_EXTRA_COMPILERS += SHIBOKEN
macx {

SOURCES += \
OSGLContext_mac.cpp

OBJECTIVE_SOURCES += \
$$PWD/../Engine/OSGLContext_mac.mm \
$$PWD/../Global/ProcInfo_mac.mm \
$$PWD/../Engine/QUrlFix.mm \
$$PWD/../Engine/StandardPaths_mac.mm
QUrlFix.mm
}
File renamed without changes.
12 changes: 7 additions & 5 deletions Engine/QUrlFix.mm
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@

#include "Global/QtCompat.h"

#ifdef Q_OS_MAC
#if defined(Q_OS_MAC) && QT_VERSION < 0x050000

// in Qt 4.8 QUrl is broken on mac, it returns /.file/id= for local files
// See https://bugreports.qt.io/browse/QTBUG-40449

#include <Foundation/NSString.h>
#include <Foundation/NSAutoreleasePool.h>
#include <Foundation/NSURL.h>
Expand Down Expand Up @@ -55,9 +59,6 @@ QUrl fromNSURL(const NSURL *url)

QUrl NATRON_NAMESPACE::QtCompat::toLocalFileUrlFixed(const QUrl& url)
{
#if QT_VERSION >= 0x050000
return url;
#endif
QUrl ret = url;
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSURL *nsurl = toNSURL(url);
Expand All @@ -66,4 +67,5 @@ QUrl fromNSURL(const NSURL *url)
[pool release];
return ret;
}
#endif

#endif // #if defined(Q_OS_MAC) && QT_VERSION < 0x050000
140 changes: 126 additions & 14 deletions Engine/StandardPaths.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,8 @@

#include "Global/GlobalDefines.h"

#ifdef __NATRON_WIN32__
#if defined(Q_OS_WIN)
#include <ofxhUtilities.h> // for wideStringToString
#endif
#if defined(__NATRON_WIN32__)
#include <windows.h>
#include <IntShCut.h>
#include <ShlObj.h>
Expand All @@ -48,19 +46,22 @@
#define CSIDL_MYVIDEO 14
#endif
#include <QtCore/QFileInfo>
#elif defined(__NATRON_LINUX__)

#elif defined(Q_OS_LINUX)
#include <cerrno>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <pwd.h>

CLANG_DIAG_OFF(deprecated)
#include <QtCore/QTextStream>
#include <QHash>
#include <QVarLengthArray>
CLANG_DIAG_ON(deprecated)

#elif defined(Q_OS_MAC)
#include <CoreServices/CoreServices.h>

#endif

NATRON_NAMESPACE_ENTER;
Expand Down Expand Up @@ -92,7 +93,7 @@ StandardPaths::appendOrganizationAndApp(QString &path)

NATRON_NAMESPACE_ANONYMOUS_ENTER

#ifdef __NATRON_WIN32__
#if defined(Q_OS_WIN)
static QString
qSystemDirectory()
{
Expand Down Expand Up @@ -183,7 +184,7 @@ convertCharArray(const wchar_t *path)
return QDir::fromNativeSeparators( QString::fromWCharArray(path) );
}

#elif defined(__NATRON_LINUX__)
#elif defined(Q_OS_LINUX)
//static
QString
resolveUserName(uint userId)
Expand Down Expand Up @@ -212,7 +213,101 @@ resolveUserName(uint userId)
return QString();
}

#endif // ifdef __NATRON_OSX__
#endif // defined(Q_OS_LINUX)

#if defined(Q_OS_MAC)
CLANG_DIAG_OFF(deprecated)

static
OSType
translateLocation(NATRON_NAMESPACE::StandardPaths::StandardLocationEnum type)
{
switch (type) {
case NATRON_NAMESPACE::StandardPaths::eStandardLocationConfig:

return kPreferencesFolderType;
case NATRON_NAMESPACE::StandardPaths::eStandardLocationDesktop:

return kDesktopFolderType;
case NATRON_NAMESPACE::StandardPaths::eStandardLocationDownload: // needs NSSearchPathForDirectoriesInDomains with NSDownloadsDirectory
// which needs an objective-C *.mm file...
case NATRON_NAMESPACE::StandardPaths::eStandardLocationDocuments:

return kDocumentsFolderType;
case NATRON_NAMESPACE::StandardPaths::eStandardLocationFonts:
// There are at least two different font directories on the mac: /Library/Fonts and ~/Library/Fonts.

// To select a specific one we have to specify a different first parameter when calling FSFindFolder.
return kFontsFolderType;
case NATRON_NAMESPACE::StandardPaths::eStandardLocationApplications:

return kApplicationsFolderType;
case NATRON_NAMESPACE::StandardPaths::eStandardLocationMusic:

return kMusicDocumentsFolderType;
case NATRON_NAMESPACE::StandardPaths::eStandardLocationMovies:

return kMovieDocumentsFolderType;
case NATRON_NAMESPACE::StandardPaths::eStandardLocationPictures:

return kPictureDocumentsFolderType;
case NATRON_NAMESPACE::StandardPaths::eStandardLocationTemp:

return kTemporaryFolderType;
case NATRON_NAMESPACE::StandardPaths::eStandardLocationGenericData:
case NATRON_NAMESPACE::StandardPaths::eStandardLocationRuntime:
case NATRON_NAMESPACE::StandardPaths::eStandardLocationData:

return kApplicationSupportFolderType;
case NATRON_NAMESPACE::StandardPaths::eStandardLocationGenericCache:
case NATRON_NAMESPACE::StandardPaths::eStandardLocationCache:

return kCachedDataFolderType;
default:

return kDesktopFolderType;
}
}


/*
Constructs a full unicode path from a FSRef.
*/
static QString
getFullPath(const FSRef &ref)
{
QByteArray ba(2048, 0);

if (FSRefMakePath( &ref, reinterpret_cast<UInt8 *>( ba.data() ), ba.size() ) == noErr) {
return QString::fromUtf8( ba.constData() ).normalized(QString::NormalizationForm_C);
}

return QString();
}


static QString
macLocation(NATRON_NAMESPACE::StandardPaths::StandardLocationEnum type, short domain)
{
// http://developer.apple.com/documentation/Carbon/Reference/Folder_Manager/Reference/reference.html
FSRef ref;
OSErr err = FSFindFolder(domain, translateLocation(type), false, &ref);

if (err) {
return QString();
}

QString path = getFullPath(ref);

if ( (type == NATRON_NAMESPACE::StandardPaths::eStandardLocationData) || (type == NATRON_NAMESPACE::StandardPaths::eStandardLocationCache) ) {
NATRON_NAMESPACE::StandardPaths::appendOrganizationAndApp(path);
}

return path;
}

CLANG_DIAG_ON(deprecated)
#endif // defined(Q_OS_MAC)

NATRON_NAMESPACE_ANONYMOUS_EXIT

Expand All @@ -221,9 +316,26 @@ QString
StandardPaths::writableLocation(StandardLocationEnum type)
{
#if QT_VERSION < 0x050000
#ifdef __NATRON_OSX__
return writableLocation_mac_qt4(type);
#elif defined(__NATRON_LINUX__)
#if defined(Q_OS_MAC)
switch (type) {
case eStandardLocationHome:

return QDir::homePath();
case eStandardLocationTemp:

return QDir::tempPath();
case eStandardLocationGenericData:
case eStandardLocationData:
case eStandardLocationGenericCache:
case eStandardLocationCache:
case eStandardLocationRuntime:

return macLocation(type, kUserDomain);
default:

return macLocation(type, kOnAppropriateDisk);
}
#elif defined(Q_OS_LINUX)
switch (type) {
case eStandardLocationHome:

Expand Down Expand Up @@ -405,7 +517,7 @@ StandardPaths::writableLocation(StandardLocationEnum type)
}

return path;
#elif defined(__NATRON_WIN32__)
#elif defined(Q_OS_WIN)
QString result;
static GetSpecialFolderPath SHGetSpecialFolderPath = resolveGetSpecialFolderPath();
if (!SHGetSpecialFolderPath) {
Expand Down Expand Up @@ -503,9 +615,9 @@ StandardPaths::writableLocation(StandardLocationEnum type)
} // switch

return result;
#else // ifdef __NATRON_OSX__
#else
#error "Unsupported operating system"
#endif // ifdef __NATRON_OSX__
#endif

#else // QT_VERSION >= 0x050000
QStandardPaths::StandardLocation path;
Expand Down
Loading

0 comments on commit f37cc8c

Please sign in to comment.