From 13ee5037f4bd60ce1cd8cd1a58a42257831ce999 Mon Sep 17 00:00:00 2001 From: Sambhav Kothari Date: Sun, 19 Feb 2017 15:07:13 +0530 Subject: [PATCH 1/4] Add debug info while dropping items --- picard/ui/itemviews.py | 1 + 1 file changed, 1 insertion(+) diff --git a/picard/ui/itemviews.py b/picard/ui/itemviews.py index eebe934ef..9a67455ab 100644 --- a/picard/ui/itemviews.py +++ b/picard/ui/itemviews.py @@ -467,6 +467,7 @@ class BaseTreeView(QtGui.QTreeWidget): files = [] new_files = [] for url in urls: + log.debug("Adding the URL: %r", url) if url.scheme() == "file" or not url.scheme(): # Dropping a file from iTunes gives a filename with a NULL terminator filename = os.path.normpath(os.path.realpath(unicode(url.toLocalFile()).rstrip("\0"))) From a2fdea1a418445b39a99769fa92c821056d213a6 Mon Sep 17 00:00:00 2001 From: Sambhav Kothari Date: Sun, 19 Feb 2017 15:30:03 +0530 Subject: [PATCH 2/4] PICARD-988: Extract file paths from NSURL --- picard/ui/itemviews.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/picard/ui/itemviews.py b/picard/ui/itemviews.py index 9a67455ab..248f9f78e 100644 --- a/picard/ui/itemviews.py +++ b/picard/ui/itemviews.py @@ -19,6 +19,7 @@ import os import re +import sys from functools import partial from PyQt4 import QtCore, QtGui from picard import config, log @@ -467,10 +468,21 @@ class BaseTreeView(QtGui.QTreeWidget): files = [] new_files = [] for url in urls: - log.debug("Adding the URL: %r", url) + log.debug("Dropped the URL: %r", url.toString(QtCore.QUrl.RemoveUserInfo)) if url.scheme() == "file" or not url.scheme(): - # Dropping a file from iTunes gives a filename with a NULL terminator - filename = os.path.normpath(os.path.realpath(unicode(url.toLocalFile()).rstrip("\0"))) + # Workaround for https://bugreports.qt.io/browse/QTBUG-40449 + # OSX Urls follow the NSURL scheme and need to be converted + if sys.platform == 'darwin' and unicode(url.path()).startswith('/.file/id='): + try: + from Foundation import NSURL + except ImportError: + pass + else: + filename = os.path.normpath(os.path.realpath(unicode(NSURL.URLWithString_(str(url.toString())).filePathURL().path()).rstrip("\0"))) + log.debug('OSX NSURL path detected. Dropped File is: %r', filename) + else: + # Dropping a file from iTunes gives a filename with a NULL terminator + filename = os.path.normpath(os.path.realpath(unicode(url.toLocalFile()).rstrip("\0"))) file = BaseTreeView.tagger.files.get(filename) if file: files.append(file) From e89c96b57a4c0c9266c25aefece365e5ea1528d1 Mon Sep 17 00:00:00 2001 From: Sambhav Kothari Date: Sun, 19 Feb 2017 15:33:52 +0530 Subject: [PATCH 3/4] Add debug log in case of import error --- picard/ui/itemviews.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/picard/ui/itemviews.py b/picard/ui/itemviews.py index 248f9f78e..ac6b05f2c 100644 --- a/picard/ui/itemviews.py +++ b/picard/ui/itemviews.py @@ -476,7 +476,7 @@ class BaseTreeView(QtGui.QTreeWidget): try: from Foundation import NSURL except ImportError: - pass + log.debug("Unable to import NSURL") else: filename = os.path.normpath(os.path.realpath(unicode(NSURL.URLWithString_(str(url.toString())).filePathURL().path()).rstrip("\0"))) log.debug('OSX NSURL path detected. Dropped File is: %r', filename) From 427632cc3432d8844336280753da958426787b31 Mon Sep 17 00:00:00 2001 From: Sambhav Kothari Date: Sun, 19 Feb 2017 15:52:07 +0530 Subject: [PATCH 4/4] Move NSURL import to module level --- picard/ui/itemviews.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/picard/ui/itemviews.py b/picard/ui/itemviews.py index ac6b05f2c..77232cfd2 100644 --- a/picard/ui/itemviews.py +++ b/picard/ui/itemviews.py @@ -32,6 +32,14 @@ from picard.plugin import ExtensionPoint from picard.ui.ratingwidget import RatingWidget from picard.ui.collectionmenu import CollectionMenu +if sys.platform == 'darwin': + try: + from Foundation import NSURL + NSURL_IMPORTED = True + except ImportError: + NSURL_IMPORTED = False + log.warning("Unable to import NSURL, file drag'n'drop might not work correctly") + class BaseAction(QtGui.QAction): NAME = "Unknown" @@ -473,13 +481,11 @@ class BaseTreeView(QtGui.QTreeWidget): # Workaround for https://bugreports.qt.io/browse/QTBUG-40449 # OSX Urls follow the NSURL scheme and need to be converted if sys.platform == 'darwin' and unicode(url.path()).startswith('/.file/id='): - try: - from Foundation import NSURL - except ImportError: - log.debug("Unable to import NSURL") - else: + if NSURL_IMPORTED: filename = os.path.normpath(os.path.realpath(unicode(NSURL.URLWithString_(str(url.toString())).filePathURL().path()).rstrip("\0"))) log.debug('OSX NSURL path detected. Dropped File is: %r', filename) + else: + log.error("Unable to get appropriate file path for %r", url.toString(QtCore.QUrl.RemoveUserInfo)) else: # Dropping a file from iTunes gives a filename with a NULL terminator filename = os.path.normpath(os.path.realpath(unicode(url.toLocalFile()).rstrip("\0")))