Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix dropping from finder Lp1822424 #2068

Merged
merged 6 commits into from
Apr 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions build/depends.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ def configure(self, build, conf):

def sources(self, build):
return ['soundio/sounddeviceportaudio.cpp']

class OSXFilePathUrlBackport(Dependence):

def configure(self, build, conf):
return

def sources(self, build):
if build.platform_is_osx:
return ['util/filepathurl.mm']
return []


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

class Foundation(Dependence):
def configure(self, build, conf):
if not build.platform_is_osx:
return
build.env.Append(CPPPATH='/System/Library/Frameworks/Foundation.framework/Headers/')
build.env.Append(LINKFLAGS='-framework Foundation')

class IOKit(Dependence):
"""Used for battery measurements and controlling the screensaver on OS X and iOS."""
def configure(self, build, conf):
Expand Down Expand Up @@ -1519,8 +1536,8 @@ def configure(self, build, conf):
def depends(self, build):
return [SoundTouch, ReplayGain, Ebur128Mit, PortAudio, PortMIDI, Qt, TestHeaders,
FidLib, SndFile, FLAC, OggVorbis, OpenGL, TagLib, ProtoBuf,
Chromaprint, RubberBand, SecurityFramework, CoreServices, IOKit,
QtScriptByteArray, Reverb, FpClassify, PortAudioRingBuffer]
Chromaprint, RubberBand, SecurityFramework, CoreServices, Foundation, IOKit,
QtScriptByteArray, Reverb, FpClassify, PortAudioRingBuffer, OSXFilePathUrlBackport]

def post_dependency_check_configure(self, build, conf):
"""Sets up additional things in the Environment that must happen
Expand Down
22 changes: 15 additions & 7 deletions src/util/dnd.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,26 @@
#include "mixer/playermanager.h"
#include "widget/trackdroptarget.h"

#if defined(__APPLE__) && QT_VERSION < QT_VERSION_CHECK(5, 4, 1)
#include "util/filepathurl.h"
#endif



class DragAndDropHelper {
public:
static QList<QFileInfo> supportedTracksFromUrls(const QList<QUrl>& urls,
bool firstOnly,
bool acceptPlaylists) {
QList<QFileInfo> fileLocations;
foreach (const QUrl& url, urls) {
for (QUrl url : urls) {

#if defined(__APPLE__) && QT_VERSION < QT_VERSION_CHECK(5, 4, 1)
// OS X 10.10 sends file references instead of file paths
// e.g. "file:///.file/id=6571367.1629051"
// QT >= 5.4.1 hides this from us
url = ensureFilePathUrl(url);
#endif

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

QList<QFileInfo> files = DragAndDropHelper::supportedTracksFromUrls(
mimeData.urls(), firstOnly, acceptPlaylists);
for (const auto file : files) {
qDebug() << file.canonicalFilePath();
}
return files;
}

Expand Down Expand Up @@ -151,14 +161,12 @@ class DragAndDropHelper {

static void handleTrackDragEnterEvent(QDragEnterEvent* event, const QString& group,
UserSettingsPointer pConfig) {
qDebug() << "handleTrackDragEnterEvent()";
if (allowLoadToPlayer(group, pConfig) &&
dragEnterAccept(*event->mimeData(), group,
true, false)) {
qDebug() << "event->acceptProposedAction()";
event->acceptProposedAction();
} else {
qDebug() << "event->ignore();";
qDebug() << "Ignoring drag enter event, loading not allowed";
event->ignore();
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/util/filepathurl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#pragma once

#include <QUrl>

QUrl ensureFilePathUrl(const QUrl& url);
37 changes: 37 additions & 0 deletions src/util/filepathurl.mm
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#include "util/filepathurl.h"



#import <Foundation/Foundation.h>

// This File uses Apples Foundation Kit to converte a QUrl containing a file
// reference QUrl("file:///.file/id=6571367.1629051") to a normal file path
// QUrl Mixxx can handle.
// Taken from https://github.com/qt/qtbase/blob/5.11/src/platformsupport/clipboard/qmacmime.mm#L622

QString stringFromNSString(const NSString *string) {
if (!string)
return QString();
QString qstring;
qstring.resize([string length]);
[string getCharacters: reinterpret_cast<unichar*>(qstring.data()) range: NSMakeRange(0, [string length])];
return qstring;
}


QUrl urlFromNSURL(const NSURL *url) {
return QUrl(stringFromNSString([url absoluteString]));
}


QUrl ensureFilePathUrl(const QUrl& url) {
const QByteArray &a = url.toEncoded();
NSString *urlString = [[[NSString alloc] initWithBytesNoCopy:(void *)a.data() length:a.size()
encoding:NSUTF8StringEncoding freeWhenDone:NO] autorelease];
NSURL *nsurl = [NSURL URLWithString:urlString];
// OS X 10.10 sends file references instead of file paths
if ([nsurl isFileReferenceURL]) {
return urlFromNSURL([nsurl filePathURL]);
}
return url;
}