Skip to content

Commit 21c79a4

Browse files
authored
Merge pull request #2068 from daschuer/lp1822424
Fix dropping from finder Lp1822424
2 parents 0e192ac + 7b8ac07 commit 21c79a4

File tree

4 files changed

+76
-9
lines changed

4 files changed

+76
-9
lines changed

build/depends.py

+19-2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,16 @@ def configure(self, build, conf):
2323

2424
def sources(self, build):
2525
return ['soundio/sounddeviceportaudio.cpp']
26+
27+
class OSXFilePathUrlBackport(Dependence):
28+
29+
def configure(self, build, conf):
30+
return
31+
32+
def sources(self, build):
33+
if build.platform_is_osx:
34+
return ['util/filepathurl.mm']
35+
return []
2636

2737

2838
class PortMIDI(Dependence):
@@ -94,6 +104,13 @@ def configure(self, build, conf):
94104
build.env.Append(CPPPATH='/System/Library/Frameworks/CoreServices.framework/Headers/')
95105
build.env.Append(LINKFLAGS='-framework CoreServices')
96106

107+
class Foundation(Dependence):
108+
def configure(self, build, conf):
109+
if not build.platform_is_osx:
110+
return
111+
build.env.Append(CPPPATH='/System/Library/Frameworks/Foundation.framework/Headers/')
112+
build.env.Append(LINKFLAGS='-framework Foundation')
113+
97114
class IOKit(Dependence):
98115
"""Used for battery measurements and controlling the screensaver on OS X and iOS."""
99116
def configure(self, build, conf):
@@ -1519,8 +1536,8 @@ def configure(self, build, conf):
15191536
def depends(self, build):
15201537
return [SoundTouch, ReplayGain, Ebur128Mit, PortAudio, PortMIDI, Qt, TestHeaders,
15211538
FidLib, SndFile, FLAC, OggVorbis, OpenGL, TagLib, ProtoBuf,
1522-
Chromaprint, RubberBand, SecurityFramework, CoreServices, IOKit,
1523-
QtScriptByteArray, Reverb, FpClassify, PortAudioRingBuffer]
1539+
Chromaprint, RubberBand, SecurityFramework, CoreServices, Foundation, IOKit,
1540+
QtScriptByteArray, Reverb, FpClassify, PortAudioRingBuffer, OSXFilePathUrlBackport]
15241541

15251542
def post_dependency_check_configure(self, build, conf):
15261543
"""Sets up additional things in the Environment that must happen

src/util/dnd.h

+15-7
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,26 @@
2222
#include "mixer/playermanager.h"
2323
#include "widget/trackdroptarget.h"
2424

25+
#if defined(__APPLE__) && QT_VERSION < QT_VERSION_CHECK(5, 4, 1)
26+
#include "util/filepathurl.h"
27+
#endif
28+
29+
30+
2531
class DragAndDropHelper {
2632
public:
2733
static QList<QFileInfo> supportedTracksFromUrls(const QList<QUrl>& urls,
2834
bool firstOnly,
2935
bool acceptPlaylists) {
3036
QList<QFileInfo> fileLocations;
31-
foreach (const QUrl& url, urls) {
37+
for (QUrl url : urls) {
38+
39+
#if defined(__APPLE__) && QT_VERSION < QT_VERSION_CHECK(5, 4, 1)
40+
// OS X 10.10 sends file references instead of file paths
41+
// e.g. "file:///.file/id=6571367.1629051"
42+
// QT >= 5.4.1 hides this from us
43+
url = ensureFilePathUrl(url);
44+
#endif
3245

3346
// XXX: Possible WTF alert - Previously we thought we needed
3447
// toString() here but what you actually want in any case when
@@ -121,9 +134,6 @@ class DragAndDropHelper {
121134

122135
QList<QFileInfo> files = DragAndDropHelper::supportedTracksFromUrls(
123136
mimeData.urls(), firstOnly, acceptPlaylists);
124-
for (const auto file : files) {
125-
qDebug() << file.canonicalFilePath();
126-
}
127137
return files;
128138
}
129139

@@ -151,14 +161,12 @@ class DragAndDropHelper {
151161

152162
static void handleTrackDragEnterEvent(QDragEnterEvent* event, const QString& group,
153163
UserSettingsPointer pConfig) {
154-
qDebug() << "handleTrackDragEnterEvent()";
155164
if (allowLoadToPlayer(group, pConfig) &&
156165
dragEnterAccept(*event->mimeData(), group,
157166
true, false)) {
158-
qDebug() << "event->acceptProposedAction()";
159167
event->acceptProposedAction();
160168
} else {
161-
qDebug() << "event->ignore();";
169+
qDebug() << "Ignoring drag enter event, loading not allowed";
162170
event->ignore();
163171
}
164172
}

src/util/filepathurl.h

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#pragma once
2+
3+
#include <QUrl>
4+
5+
QUrl ensureFilePathUrl(const QUrl& url);

src/util/filepathurl.mm

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#include "util/filepathurl.h"
2+
3+
4+
5+
#import <Foundation/Foundation.h>
6+
7+
// This File uses Apples Foundation Kit to converte a QUrl containing a file
8+
// reference QUrl("file:///.file/id=6571367.1629051") to a normal file path
9+
// QUrl Mixxx can handle.
10+
// Taken from https://github.com/qt/qtbase/blob/5.11/src/platformsupport/clipboard/qmacmime.mm#L622
11+
12+
QString stringFromNSString(const NSString *string) {
13+
if (!string)
14+
return QString();
15+
QString qstring;
16+
qstring.resize([string length]);
17+
[string getCharacters: reinterpret_cast<unichar*>(qstring.data()) range: NSMakeRange(0, [string length])];
18+
return qstring;
19+
}
20+
21+
22+
QUrl urlFromNSURL(const NSURL *url) {
23+
return QUrl(stringFromNSString([url absoluteString]));
24+
}
25+
26+
27+
QUrl ensureFilePathUrl(const QUrl& url) {
28+
const QByteArray &a = url.toEncoded();
29+
NSString *urlString = [[[NSString alloc] initWithBytesNoCopy:(void *)a.data() length:a.size()
30+
encoding:NSUTF8StringEncoding freeWhenDone:NO] autorelease];
31+
NSURL *nsurl = [NSURL URLWithString:urlString];
32+
// OS X 10.10 sends file references instead of file paths
33+
if ([nsurl isFileReferenceURL]) {
34+
return urlFromNSURL([nsurl filePathURL]);
35+
}
36+
return url;
37+
}

0 commit comments

Comments
 (0)