Skip to content

Commit 220affb

Browse files
committed
Fix #11399; fix up Mac OS X 10.10+ dropped file URLs
1 parent 7068772 commit 220affb

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

src/app/qgisapp.cpp

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1102,6 +1102,51 @@ void QgisApp::dropEvent( QDropEvent *event )
11021102
for ( i = urls.begin(); i != urls.end(); ++i )
11031103
{
11041104
QString fileName = i->toLocalFile();
1105+
#ifdef Q_OS_MAC
1106+
// Mac OS X 10.10, under Qt4.8 ,changes dropped URL format
1107+
// https://bugreports.qt.io/browse/QTBUG-40449
1108+
// [pzion 20150805] Work around
1109+
if ( fileName.startsWith( "/.file/id=" ) )
1110+
{
1111+
QgsDebugMsg( "Mac dropped URL with /.file/id= (converting)" );
1112+
CFStringRef relCFStringRef =
1113+
CFStringCreateWithCString(
1114+
kCFAllocatorDefault,
1115+
fileName.toUtf8().constData(),
1116+
kCFStringEncodingUTF8
1117+
);
1118+
CFURLRef relCFURL =
1119+
CFURLCreateWithFileSystemPath(
1120+
kCFAllocatorDefault,
1121+
relCFStringRef,
1122+
kCFURLPOSIXPathStyle,
1123+
false // isDirectory
1124+
);
1125+
CFErrorRef error = 0;
1126+
CFURLRef absCFURL =
1127+
CFURLCreateFilePathURL(
1128+
kCFAllocatorDefault,
1129+
relCFURL,
1130+
&error
1131+
);
1132+
if ( !error )
1133+
{
1134+
static const CFIndex maxAbsPathCStrBufLen = 4096;
1135+
char absPathCStr[maxAbsPathCStrBufLen];
1136+
if ( CFURLGetFileSystemRepresentation(
1137+
absCFURL,
1138+
true, // resolveAgainstBase
1139+
reinterpret_cast<UInt8 *>( &absPathCStr[0] ),
1140+
maxAbsPathCStrBufLen ) )
1141+
{
1142+
fileName = QString( absPathCStr );
1143+
}
1144+
}
1145+
CFRelease( absCFURL );
1146+
CFRelease( relCFURL );
1147+
CFRelease( relCFStringRef );
1148+
}
1149+
#endif
11051150
// seems that some drag and drop operations include an empty url
11061151
// so we test for length to make sure we have something
11071152
if ( !fileName.isEmpty() )

0 commit comments

Comments
 (0)