This commit is contained in:
Kovid Goyal 2011-06-23 13:24:54 -06:00
parent ddfc313efd
commit 62cfdc8023
2 changed files with 23 additions and 5 deletions

View File

@ -591,8 +591,10 @@ class BooksView(QTableView): # {{{
fmt = prefs['output_format']
def url_for_id(i):
ans = db.format(i, fmt, index_is_id=True, as_path=True,
preserve_filename=True)
try:
ans = db.format_path(i, fmt, index_is_id=True)
except:
ans = None
if ans is None:
fmts = db.formats(i, index_is_id=True)
if fmts:
@ -600,13 +602,15 @@ class BooksView(QTableView): # {{{
else:
fmts = []
for f in fmts:
ans = db.format(i, f, index_is_id=True, as_path=True,
preserve_filename=True)
try:
ans = db.format_path(i, f, index_is_id=True)
except:
ans = None
if ans is None:
ans = db.abspath(i, index_is_id=True)
return QUrl.fromLocalFile(ans)
md.setUrls([url_for_id(i) for i in selected[:25]])
md.setUrls([url_for_id(i) for i in selected])
drag = QDrag(self)
col = self.selectionModel().currentIndex().column()
md.column_name = self.column_map[col]

View File

@ -1144,6 +1144,20 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns):
break
return sha.hexdigest()
def format_path(self, index, fmt, index_is_id=False):
'''
This method is intended to be used only in those rare situations, like
Drag'n Drop, when you absolutely need the path to the original file.
Otherwise, use format(..., as_path=True).
Note that a networked backend will always return None.
'''
path = self.format_abspath(index, fmt, index_is_id=index_is_id)
if path is None:
id_ = index if index_is_id else self.id(index)
raise NoSuchFormat('Record %d has no format: %s'%(id_, fmt))
return path
def format_abspath(self, index, format, index_is_id=False):
'''
Return absolute path to the ebook file of format `format`