prioritize urls over text; fixes linux fm drop (#945)

This commit is contained in:
Damien Elmes 2013-09-20 14:41:56 +09:00
parent cc7ddca7d7
commit 2fff30db2f

View File

@ -813,15 +813,18 @@ to a cloze type first, via Edit>Change Note Type."""))
s = s.lower() s = s.lower()
return (s.startswith("http://") return (s.startswith("http://")
or s.startswith("https://") or s.startswith("https://")
or s.startswith("ftp://")) or s.startswith("ftp://")
or s.startswith("file://"))
def _retrieveURL(self, url): def _retrieveURL(self, url):
"Download file into media folder and return local filename or None." "Download file into media folder and return local filename or None."
# urllib is picky with local file links # urllib doesn't understand percent-escaped utf8, but requires things like
# '#' to be escaped. we don't try to unquote the incoming URL, because
# we should only be receiving file:// urls from url mime, which is unquoted
if url.lower().startswith("file://"): if url.lower().startswith("file://"):
url = url.replace("%", "%25") url = url.replace("%", "%25")
url = url.replace("#", "%23") url = url.replace("#", "%23")
# fetch it into a temporary folder # fetch it into a temporary folder
self.mw.progress.start( self.mw.progress.start(
immediate=True, parent=self.parentWindow) immediate=True, parent=self.parentWindow)
try: try:
@ -1088,16 +1091,20 @@ class EditorWebView(AnkiWebView):
# print "text", mime.text() # print "text", mime.text()
if mime.hasHtml(): if mime.hasHtml():
return self._processHtml(mime) return self._processHtml(mime)
elif mime.hasText():
return self._processText(mime)
elif mime.hasUrls(): elif mime.hasUrls():
return self._processUrls(mime) return self._processUrls(mime)
elif mime.hasText():
return self._processText(mime)
elif mime.hasImage(): elif mime.hasImage():
return self._processImage(mime) return self._processImage(mime)
else: else:
# nothing # nothing
return QMimeData() return QMimeData()
# when user is dragging a file from a file manager on any platform, the
# url type should be set, and it is not URL-encoded. on a mac no text type
# is returned, and on windows the text type is not returned in cases like
# "foo's bar.jpg"
def _processUrls(self, mime): def _processUrls(self, mime):
url = mime.urls()[0].toString() url = mime.urls()[0].toString()
# chrome likes to give us the URL twice with a \n # chrome likes to give us the URL twice with a \n
@ -1108,6 +1115,10 @@ class EditorWebView(AnkiWebView):
mime.setHtml(link) mime.setHtml(link)
return mime return mime
# if the user has used 'copy link location' in the browser, the clipboard
# will contain the URL as text, and no URLs or HTML. the URL will already
# be URL-encoded, and shouldn't be a file:// url unless they're browsing
# locally, which we don't support
def _processText(self, mime): def _processText(self, mime):
txt = unicode(mime.text()) txt = unicode(mime.text())
html = None html = None