Remove unneeded NSURL code

It was fixed with Qt5.4.1.
See https://bugreports.qt.io/browse/QTBUG-24379
This commit is contained in:
Sambhav Kothari
2017-04-08 00:30:42 +05:30
parent d8671f2ea8
commit df364b7ad8
2 changed files with 2 additions and 40 deletions

View File

@@ -30,14 +30,6 @@ from picard.util import imageinfo
from picard.util.lrucache import LRUCache
from picard.const import MAX_COVERS_TO_STACK
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 ActiveLabel(QtWidgets.QLabel):
"""Clickable QLabel."""
@@ -344,18 +336,7 @@ class CoverArtBox(QtWidgets.QGroupBox):
xml=False,
priority=True, important=True)
elif url.scheme() == 'file':
log.debug("Dropped the URL: %r", url.toString(QtCore.QUrl.RemoveUserInfo))
if sys.platform == 'darwin' and url.path().startswith('/.file/id='):
# Workaround for https://bugreports.qt.io/browse/QTBUG-40449
# OSX Urls follow the NSURL scheme and need to be converted
if NSURL_IMPORTED:
path = os.path.normpath(os.path.realpath(NSURL.URLWithString_(string_(url.toString()).filePathURL().path()).rstrip("\0")))
log.debug('OSX NSURL path detected. Dropped File is: %r', path)
else:
log.error("Unable to get appropriate file path for %r", url.toString(QtCore.QUrl.RemoveUserInfo))
else:
# Dropping a file from iTunes gives a path with a NULL terminator
path = os.path.normpath(os.path.realpath(url.toLocalFile().rstrip("\0")))
path = os.path.normpath(os.path.realpath(url.toLocalFile().rstrip("\0")))
if path and os.path.exists(path):
mime = 'image/png' if path.lower().endswith('.png') else 'image/jpeg'
with open(path, 'rb') as f:

View File

@@ -32,14 +32,6 @@ 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(QtWidgets.QAction):
NAME = "Unknown"
@@ -478,18 +470,7 @@ class BaseTreeView(QtWidgets.QTreeWidget):
for url in urls:
log.debug("Dropped the URL: %r", url.toString(QtCore.QUrl.RemoveUserInfo))
if url.scheme() == "file" or not url.scheme():
if sys.platform == 'darwin' and url.path().startswith('/.file/id='):
# Workaround for https://bugreports.qt.io/browse/QTBUG-40449
# OSX Urls follow the NSURL scheme and need to be converted
if NSURL_IMPORTED:
filename = os.path.normpath(os.path.realpath(NSURL.URLWithString_(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))
continue
else:
# Dropping a file from iTunes gives a filename with a NULL terminator
filename = os.path.normpath(os.path.realpath(url.toLocalFile().rstrip("\0")))
filename = os.path.normpath(os.path.realpath(url.toLocalFile().rstrip("\0")))
file = BaseTreeView.tagger.files.get(filename)
if file:
files.append(file)