From 98ad8460a86f18c83f27ad0447b8a8f9099ab8f6 Mon Sep 17 00:00:00 2001 From: Morten Johan Sorvig Date: Thu, 9 Aug 2012 13:07:21 +0200 Subject: Set CWD when launched from Finder. Like Qt 4. Use the presence of the "-psn_" command- line argument to detect Finder launches. Link QtGui against the Cocoa framework due to CFBundle usage. Change-Id: I947ae53462072fbdb23afcc0a13ce6b26d02c191 Reviewed-by: Richard Moe Gustavsen --- src/gui/gui.pro | 4 ++++ src/gui/kernel/qguiapplication.cpp | 14 +++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/gui/gui.pro b/src/gui/gui.pro index cab44f8047..d9d2aaec2d 100644 --- a/src/gui/gui.pro +++ b/src/gui/gui.pro @@ -16,6 +16,10 @@ testcocoon { load(testcocoon) } +mac { + LIBS_PRIVATE += -framework Cocoa +} + CONFIG += simd QMAKE_DOCS = $$PWD/doc/qtgui.qdocconf diff --git a/src/gui/kernel/qguiapplication.cpp b/src/gui/kernel/qguiapplication.cpp index 419403d938..46e7334e37 100644 --- a/src/gui/kernel/qguiapplication.cpp +++ b/src/gui/kernel/qguiapplication.cpp @@ -90,6 +90,10 @@ #include #endif +#ifdef Q_OS_MAC +# include "private/qcore_mac_p.h" +#endif + QT_BEGIN_NAMESPACE Q_GUI_EXPORT bool qt_is_gui_used = true; @@ -868,7 +872,15 @@ void QGuiApplicationPrivate::init() QGuiApplication::setLayoutDirection(Qt::RightToLeft); #ifdef Q_OS_MAC } else if (arg.startsWith("-psn_")) { - // eat "-psn_xxxx" on Mac + // eat "-psn_xxxx" on Mac, which is passed when starting an app from Finder. + // special hack to change working directory (for an app bundle) when running from finder + if (QDir::currentPath() == QLatin1String("/")) { + QCFType bundleURL(CFBundleCopyBundleURL(CFBundleGetMainBundle())); + QString qbundlePath = QCFString(CFURLCopyFileSystemPath(bundleURL, + kCFURLPOSIXPathStyle)); + if (qbundlePath.endsWith(QLatin1String(".app"))) + QDir::setCurrent(qbundlePath.section(QLatin1Char('/'), 0, -2)); + } #endif } else { argv[j++] = argv[i]; -- cgit v1.2.3