Skip to content

Commit

Permalink
Dissolve the get_file_path method
Browse files Browse the repository at this point in the history
It seems to be causing build errors with OSX. Moved the required LoC
to both itemviews and coverartbox
  • Loading branch information
samj1912 committed Mar 10, 2017
1 parent f9225f2 commit d743329
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 33 deletions.
24 changes: 22 additions & 2 deletions picard/ui/coverartbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,23 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

import os
import sys
from functools import partial
from PyQt4 import QtCore, QtGui, QtNetwork
from picard import config, log
from picard.album import Album
from picard.coverart.image import CoverArtImage, CoverArtImageError
from picard.track import Track
from picard.file import File
from picard.util import encode_filename, imageinfo, get_file_path
from picard.util import encode_filename, imageinfo

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(QtGui.QLabel):
Expand Down Expand Up @@ -225,7 +234,18 @@ def fetch_remote_image(self, url, fallback_data=None):
xml=False,
priority=True, important=True)
elif url.scheme() == 'file':
path = get_file_path(url)
log.debug("Dropped the URL: %r", url.toString(QtCore.QUrl.RemoveUserInfo))
if sys.platform == 'darwin' and unicode(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(unicode(NSURL.URLWithString_(str(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(unicode(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:
Expand Down
25 changes: 21 additions & 4 deletions picard/ui/itemviews.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,19 @@
from picard.cluster import Cluster, ClusterList, UnmatchedFiles
from picard.file import File
from picard.track import Track, NonAlbumTrack
from picard.util import encode_filename, icontheme, get_file_path
from picard.util import encode_filename, icontheme
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"
Expand Down Expand Up @@ -470,9 +478,18 @@ def drop_urls(urls, target):
for url in urls:
log.debug("Dropped the URL: %r", url.toString(QtCore.QUrl.RemoveUserInfo))
if url.scheme() == "file" or not url.scheme():
filename = get_file_path(url)
if not filename:
continue
if sys.platform == 'darwin' and unicode(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(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))
continue
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)
Expand Down
27 changes: 0 additions & 27 deletions picard/util/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,6 @@
from functools import partial
from picard.const import MUSICBRAINZ_SERVERS

if sys.platform == 'darwin':
try:
from Foundation import NSURL
NSURL_IMPORTED = True
except ImportError:
NSURL_IMPORTED = False
from picard import log
log.warning("Unable to import NSURL, file drag'n'drop might not work correctly")


class LockableObject(QtCore.QObject):

Expand Down Expand Up @@ -445,21 +436,3 @@ def union_sorted_lists(list1, list2):
union.extend(list1[i:])

return union


def get_file_path(url):
# Workaround for https://bugreports.qt.io/browse/QTBUG-40449
# OSX Urls follow the NSURL scheme and need to be converted
from picard import log

file_path = ""
if sys.platform == 'darwin' and unicode(url.path()).startswith('/.file/id='):
if NSURL_IMPORTED:
file_path = 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', file_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 filename with a NULL terminator
file_path = os.path.normpath(os.path.realpath(unicode(url.toLocalFile()).rstrip("\0")))
return file_path

0 comments on commit d743329

Please sign in to comment.