From 3719dfb4d8a607566b2ac4f069671ec878b4a44a Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 12 Jul 2013 17:42:16 +0530 Subject: [PATCH] book_on_device API --- src/calibre/db/legacy.py | 23 +++++++++++++++++++++++ src/calibre/db/tests/legacy.py | 1 + 2 files changed, 24 insertions(+) diff --git a/src/calibre/db/legacy.py b/src/calibre/db/legacy.py index ff0c742e9d..97be03fb19 100644 --- a/src/calibre/db/legacy.py +++ b/src/calibre/db/legacy.py @@ -108,6 +108,7 @@ class LibraryDatabase(object): self.metadata_for_field = self.field_metadata.get self.last_update_check = self.last_modified() + self.book_on_device_func = None def close(self): self.backend.close() @@ -329,6 +330,28 @@ class LibraryDatabase(object): adata = self.new_api._author_data(authors) return [(aid, adata[aid]['name'], adata[aid]['sort'], adata[aid]['link']) for aid in authors] + def book_on_device(self, book_id): + if callable(self.book_on_device_func): + return self.book_on_device_func(book_id) + return None + + def book_on_device_string(self, book_id): + loc = [] + count = 0 + on = self.book_on_device(book_id) + if on is not None: + m, a, b, count = on[:4] + if m is not None: + loc.append(_('Main')) + if a is not None: + loc.append(_('Card A')) + if b is not None: + loc.append(_('Card B')) + return ', '.join(loc) + ((_(' (%s books)')%count) if count > 1 else '') + + def set_book_on_device_func(self, func): + self.book_on_device_func = func + # Private interface {{{ def __iter__(self): diff --git a/src/calibre/db/tests/legacy.py b/src/calibre/db/tests/legacy.py index daa53b7ddd..e5a8a8e7b5 100644 --- a/src/calibre/db/tests/legacy.py +++ b/src/calibre/db/tests/legacy.py @@ -175,6 +175,7 @@ class LegacyTest(BaseTest): 'authors_sort_strings':[(0,), (1,), (2,)], 'author_sort_from_book':[(0,), (1,), (2,)], 'authors_with_sort_strings':[(0,), (1,), (2,)], + 'book_on_device_string':[(1,), (2,), (3,)], }.iteritems(): for a in args: fmt = lambda x: x