This commit is contained in:
Kovid Goyal 2008-05-04 04:42:07 -07:00
parent 4ebf4d2e38
commit 5b99ec33c3

View File

@ -1,6 +1,6 @@
__license__ = 'GPL v3' __license__ = 'GPL v3'
__copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>' __copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
import os, textwrap, traceback, time, re, sre_constants, urllib, locale, codecs import os, textwrap, traceback, time, re, sre_constants, locale, codecs
from datetime import timedelta, datetime from datetime import timedelta, datetime
from operator import attrgetter from operator import attrgetter
from math import cos, sin, pi from math import cos, sin, pi
@ -11,7 +11,7 @@ from PyQt4.QtGui import QTableView, QProgressDialog, QAbstractItemView, QColor,
from PyQt4.QtCore import QAbstractTableModel, QVariant, Qt, QString, \ from PyQt4.QtCore import QAbstractTableModel, QVariant, Qt, QString, \
QCoreApplication, SIGNAL, QObject, QSize, QModelIndex QCoreApplication, SIGNAL, QObject, QSize, QModelIndex
from calibre import iswindows, Settings from calibre import Settings
from calibre.ptempfile import PersistentTemporaryFile from calibre.ptempfile import PersistentTemporaryFile
from calibre.library.database import LibraryDatabase, SearchToken from calibre.library.database import LibraryDatabase, SearchToken
from calibre.gui2 import NONE, TableView, qstring_to_unicode from calibre.gui2 import NONE, TableView, qstring_to_unicode
@ -373,7 +373,6 @@ class BooksModel(QAbstractTableModel):
done = True done = True
return done return done
class BooksView(TableView): class BooksView(TableView):
TIME_FMT = '%d %b %Y' TIME_FMT = '%d %b %Y'
wrapper = textwrap.TextWrapper(width=20) wrapper = textwrap.TextWrapper(width=20)
@ -412,25 +411,9 @@ class BooksView(TableView):
Accept a drop event and return a list of paths that can be read from Accept a drop event and return a list of paths that can be read from
and represent files with extensions. and represent files with extensions.
''' '''
def url_to_path(url):
try:
url = urllib.unquote(url)[8 if iswindows else 7:]
except:
return ''
return url.replace('/', os.sep)
if event.mimeData().hasFormat('text/uri-list'): if event.mimeData().hasFormat('text/uri-list'):
urls = str(event.mimeData().data('text/uri-list')).replace('\x00', '').splitlines() urls = [qstring_to_unicode(u.toLocalFile()) for u in event.mimeData().urls()]
urls = [urllib.unquote(f.strip()) for f in urls] return [u for u in urls if os.path.splitext(u)[1] and os.access(u, os.R_OK)]
# Only accept URLs to local files that have extensions
urls = [url_to_path(u) for u in urls if os.path.splitext(u)[1] and \
u.startswith('file://')]
urls = [u for u in urls if os.access(u, os.R_OK)]
return urls
def dragEnterEvent(self, event): def dragEnterEvent(self, event):
if int(event.possibleActions() & Qt.CopyAction) + \ if int(event.possibleActions() & Qt.CopyAction) + \