From 62cfdc8023d7acfa83f70249690910fa7a9ee856 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 23 Jun 2011 13:24:54 -0600 Subject: [PATCH] ... --- src/calibre/gui2/library/views.py | 14 +++++++++----- src/calibre/library/database2.py | 14 ++++++++++++++ 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/src/calibre/gui2/library/views.py b/src/calibre/gui2/library/views.py index 9aa926f5c5..d25325be17 100644 --- a/src/calibre/gui2/library/views.py +++ b/src/calibre/gui2/library/views.py @@ -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] diff --git a/src/calibre/library/database2.py b/src/calibre/library/database2.py index c9ed5c250a..a3211b3817 100644 --- a/src/calibre/library/database2.py +++ b/src/calibre/library/database2.py @@ -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`