From fecd1109b3247560827c621b7021b42dfda6cdec Mon Sep 17 00:00:00 2001 From: tarek_saidi Date: Thu, 21 Feb 2008 20:35:27 +0000 Subject: [PATCH] fixed mac specific build problem git-svn-id: https://svn.code.sf.net/p/keepassx/code/trunk@158 b624d157-de02-0410-bad0-e51aec6abb33 --- src/main.cpp | 28 +++++++++++++++++++++------- src/src.pro | 1 + 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 1a3d004..cc03d27 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -31,6 +31,9 @@ #include #include #include +#include +#include + /* #include @@ -55,6 +58,9 @@ #ifdef Q_WS_WIN #include #endif +#ifdef Q_WS_MAC +#include +#endif using namespace std; @@ -496,13 +502,21 @@ QString applicationFilePath() return filePath.filePath(); #elif defined(Q_WS_MAC) - QString qAppFileName_str = qAppFileName(); - if(!qAppFileName_str.isEmpty()) { - QFileInfo fi(qAppFileName_str); - return fi.exists() ? fi.canonicalFilePath() : QString(); - } - #endif - #if defined( Q_OS_UNIX ) + + CFURLRef bundleURL(CFBundleCopyExecutableURL(CFBundleGetMainBundle())); + assert(bundleURL); + CFStringRef cfPath(CFURLCopyFileSystemPath(bundleURL, kCFURLPOSIXPathStyle)); + assert(cfPath); + CFIndex length = CFStringGetLength(cfPath); + const UniChar *chars = CFStringGetCharactersPtr(cfPath); + if (chars) + return QString(reinterpret_cast(chars), length); + + QVarLengthArray buffer(length); + CFStringGetCharacters(cfPath, CFRangeMake(0, length), buffer.data()); + return QString(reinterpret_cast(buffer.constData()), length); + + #elif defined( Q_OS_UNIX ) #ifdef Q_OS_LINUX // Try looking for a /proc//exe symlink first which points to // the absolute path of the executable diff --git a/src/src.pro b/src/src.pro index 04e886f..2e7b803 100644 --- a/src/src.pro +++ b/src/src.pro @@ -50,6 +50,7 @@ macx { isEmpty(PREFIX):PREFIX = /Applications target.path = $${PREFIX} data.path = $${PREFIX}/keepassx.app/Contents/share/keepass + LIBS += -framework CoreFoundation } isEqual(QMAKE_WIN32,1) {