summaryrefslogtreecommitdiffstats
path: root/src/gui/kernel/qguiapplication.cpp
diff options
context:
space:
mode:
authorMorten Johan Sorvig <morten.sorvig@nokia.com>2012-08-09 13:07:21 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2012-10-02 13:22:49 +0200
commit98ad8460a86f18c83f27ad0447b8a8f9099ab8f6 (patch)
tree6275640f07554464c7126157ec2971ec9d2033d9 /src/gui/kernel/qguiapplication.cpp
parent903bd6250affd4209dff4e73c4c46cb69965f5fa (diff)
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 <richard.gustavsen@digia.com>
Diffstat (limited to 'src/gui/kernel/qguiapplication.cpp')
-rw-r--r--src/gui/kernel/qguiapplication.cpp14
1 files changed, 13 insertions, 1 deletions
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 <QtGui/QClipboard>
#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<CFURLRef> 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];