From 7442abf298e0425c30fe786dff96231fe7acbc00 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 24 Oct 2012 19:27:07 +0530 Subject: [PATCH] Kobo driver: Fix the ondevice status for some books getting lost. Fixes #1069403 (kobo glo syncronize problem) --- src/calibre/devices/kobo/books.py | 8 ++-- src/calibre/devices/kobo/driver.py | 69 +++++++++++++++++------------- 2 files changed, 43 insertions(+), 34 deletions(-) diff --git a/src/calibre/devices/kobo/books.py b/src/calibre/devices/kobo/books.py index 29506ddc3f..ca51d67e1d 100644 --- a/src/calibre/devices/kobo/books.py +++ b/src/calibre/devices/kobo/books.py @@ -20,7 +20,7 @@ class Book(Book_): def __init__(self, prefix, lpath, title=None, authors=None, mime=None, date=None, ContentType=None, thumbnail_name=None, size=0, other=None): # debug_print('Book::__init__ - title=', title) - show_debug = title is not None and title.lower().find("magic kingdom") >= 0 + show_debug = title is not None and title.lower().find("xxxxx") >= 0 if show_debug: debug_print("Book::__init__ - title=", title, 'authors=', authors) debug_print("Book::__init__ - other=", other) @@ -31,8 +31,8 @@ class Book(Book_): if authors is not None and len(authors) > 0: self.authors_from_string(authors) - if self.author_sort is None or self.author_sort == "Unknown": - self.author_sort = author_to_author_sort(self.authors) + if self.author_sort is None or self.author_sort == "Unknown": + self.author_sort = author_to_author_sort(authors) self.mime = mime @@ -58,7 +58,7 @@ class Book(Book_): self.datetime = time.gmtime() self.contentID = None - self.current_collections = [] + self.current_shelves = [] if thumbnail_name is not None: self.thumbnail = ImageWrapper(thumbnail_name) diff --git a/src/calibre/devices/kobo/driver.py b/src/calibre/devices/kobo/driver.py index 757093b7a8..dcab3026ec 100644 --- a/src/calibre/devices/kobo/driver.py +++ b/src/calibre/devices/kobo/driver.py @@ -850,7 +850,7 @@ class KOBO(USBMS): return collections def sync_booklists(self, booklists, end_session=True): -# debug_print('KOBO: started sync_booklists') + debug_print('KOBO: started sync_booklists') paths = self.get_device_paths() blists = {} @@ -872,7 +872,7 @@ class KOBO(USBMS): self.update_device_database_collections(blist, collections, oncard) USBMS.sync_booklists(self, booklists, end_session=end_session) - #debug_print('KOBO: finished sync_booklists') + debug_print('KOBO: finished sync_booklists') def rebuild_collections(self, booklist, oncard): collections_attributes = [] @@ -1199,7 +1199,7 @@ class KOBOTOUCH(KOBO): author = 'David Forrester' description = 'Communicate with the Kobo Touch, Glo and Mini firmware. Based on the existing Kobo driver by %s.' % (KOBO.author) - supported_dbversion = 62 + supported_dbversion = 65 min_supported_dbversion = 53 booklist_class = KTCollectionsBookList @@ -1285,13 +1285,21 @@ class KOBOTOUCH(KOBO): # Image file name endings. Made up of: image size, min_dbversion, max_dbversion, COVER_FILE_ENDINGS = { - ' - N3_LIBRARY_FULL.parsed':[(355,530),0, 99,], -# ' - N3_LIBRARY_FULL.parsed':[(600,800),0, 99,], - ' - N3_LIBRARY_GRID.parsed':[(149,233),0, 99,], - ' - N3_LIBRARY_LIST.parsed':[(60,90),0, 99,], - ' - N3_LIBRARY_SHELF.parsed': [(40,60),0, 52,], - ' - N3_FULL.parsed':[(600,800),0, 52,], + ' - N3_LIBRARY_FULL.parsed':[(355,473),0, 99,], # Used for Details screen + ' - N3_LIBRARY_GRID.parsed':[(149,198),0, 99,], # Used for library lists + ' - N3_LIBRARY_LIST.parsed':[(60,90),0, 53,], +# ' - N3_LIBRARY_SHELF.parsed': [(40,60),0, 52,], + ' - N3_FULL.parsed':[(600,800),0, 99,], # Used for screensaver, home screen } + #Following are the sizes used with pre2.1.4 firmware +# COVER_FILE_ENDINGS = { +# ' - N3_LIBRARY_FULL.parsed':[(355,530),0, 99,], # Used for Details screen +## ' - N3_LIBRARY_FULL.parsed':[(600,800),0, 99,], +# ' - N3_LIBRARY_GRID.parsed':[(149,233),0, 99,], # Used for library lists +# ' - N3_LIBRARY_LIST.parsed':[(60,90),0, 53,], +# ' - N3_LIBRARY_SHELF.parsed': [(40,60),0, 52,], +# ' - N3_FULL.parsed':[(600,800),0, 99,], # Used for screensaver if "Full screen" is checked. +# } def initialize(self): super(KOBOTOUCH, self).initialize() @@ -1422,6 +1430,7 @@ class KOBOTOUCH(KOBO): debug_print('KoboTouch:update_booklist - bookshelves=', bookshelves) debug_print('KoboTouch:update_booklist - series="%s"' % bl[idx].series) debug_print('KoboTouch:update_booklist - the book=', bl[idx]) + debug_print('KoboTouch:update_booklist - the authors=', bl[idx].authors) debug_print('KoboTouch:update_booklist - application_id=', bl[idx].application_id) bl_cache[lpath] = None if bl[idx].title_sort is not None: @@ -1438,20 +1447,15 @@ class KOBOTOUCH(KOBO): else: debug_print(" Strange: The file: ", prefix, lpath, " does not exist!") debug_print("KoboTouch:update_booklist - book size=", bl[idx].size) -# if lpath in playlist_map and \ -# playlist_map[lpath] not in bl[idx].device_collections: -# bl[idx].device_collections = playlist_map.get(lpath,[]) -# changed = True - if show_debug: debug_print("KoboTouch:update_booklist - ContentID='%s'"%ContentID) bl[idx].contentID = ContentID if lpath in playlist_map: - bl[idx].device_collections = playlist_map.get(lpath,[]) - bl[idx].current_collections = bl[idx].device_collections + bl[idx].device_collections = playlist_map.get(lpath,[]) changed = True + bl[idx].current_shelves = bookshelves if show_debug: debug_print('KoboTouch:update_booklist - updated bl[idx].device_collections=', bl[idx].device_collections) @@ -1482,12 +1486,14 @@ class KOBOTOUCH(KOBO): debug_print('KoboTouch:update_booklist - class:', book.__class__) # debug_print(' resolution:', book.__class__.__mro__) debug_print(" contentid:'%s'"%book.contentID) - debug_print(book) + debug_print(" title:'%s'"%book.title) + debug_print(" the book:", book) debug_print(" author_sort:'%s'"%book.author_sort) + debug_print(" bookshelves:", bookshelves) # print 'Update booklist' - book.device_collections = playlist_map.get(lpath,[])# if lpath in playlist_map else [] - book.current_collections = bl[idx].device_collections + book.device_collections = playlist_map.get(lpath,[])# if lpath in playlist_map else [] + book.current_shelves = bookshelves book.contentID = ContentID # debug_print('KoboTouch:update_booklist - title=', title, 'book.device_collections', book.device_collections) @@ -1526,16 +1532,16 @@ class KOBOTOUCH(KOBO): # return bytestrings if the content cannot the decoded as unicode connection.text_factory = lambda x: unicode(x, "utf-8", "ignore") - self.bookshelvelist = self.get_bookshelflist(connection) - cursor = connection.cursor() cursor.execute('select version from dbversion') result = cursor.fetchone() self.dbversion = result[0] - debug_print("Database Version=%d"%self.dbversion) + self.bookshelvelist = self.get_bookshelflist(connection) + debug_print("KoboTouch:books - shelf list:", self.bookshelvelist) + opts = self.settings() if self.dbversion >= 33: query= ('select Title, Attribution, DateCreated, ContentID, MimeType, ContentType, ' \ @@ -1623,14 +1629,15 @@ class KOBOTOUCH(KOBO): #print "count found in cache: %d, count of files in metadata: %d, need_sync: %s" % \ # (len(bl_cache), len(bl), need_sync) + # Bypassing the KOBO sync_booklists as that does things we don't need to do if need_sync: #self.count_found_in_bl != len(bl) or need_sync: debug_print("KoboTouch:books - about to sync_booklists") if oncard == 'cardb': - self.sync_booklists((None, None, bl)) + USBMS.sync_booklists(self, (None, None, bl)) elif oncard == 'carda': - self.sync_booklists((None, bl, None)) + USBMS.sync_booklists(self, (None, bl, None)) else: - self.sync_booklists((bl, None, None)) + USBMS.sync_booklists(self, (bl, None, None)) self.report_progress(1.0, _('Getting list of books on device...')) debug_print("KoboTouch:books - end - oncard='%s'"%oncard) @@ -2088,13 +2095,14 @@ class KOBOTOUCH(KOBO): def remove_book_from_device_bookshelves(self, connection, book): show_debug = self.is_debugging_title(book.title)# or True - - remove_shelf_list = set(book.current_collections) - set(book.device_collections) - set(["Im_Reading", "Read", "Closed"]) + + remove_shelf_list = set(book.current_shelves) - set(book.device_collections)# - set(["Im_Reading", "Read", "Closed"]) if show_debug: debug_print('KoboTouch:remove_book_from_device_bookshelves - book.application_id="%s"'%book.application_id) debug_print('KoboTouch:remove_book_from_device_bookshelves - book.contentID="%s"'%book.contentID) debug_print('KoboTouch:remove_book_from_device_bookshelves - book.device_collections=', book.device_collections) + debug_print('KoboTouch:remove_book_from_device_bookshelves - book.current_shelves=', book.current_shelves) debug_print('KoboTouch:remove_book_from_device_bookshelves - remove_shelf_list=', remove_shelf_list) if len(remove_shelf_list) == 0: @@ -2155,14 +2163,14 @@ class KOBOTOUCH(KOBO): if not self.supports_bookshelves(): return bookshelves - query = 'SELECT Name FROM Shelf' + query = 'SELECT Name FROM Shelf WHERE _IsDeleted = "false"' cursor = connection.cursor() cursor.execute(query) - # count_bookshelves = 0 +# count_bookshelves = 0 for i, row in enumerate(cursor): bookshelves.append(row[0]) - # count_bookshelves = i + 1 +# count_bookshelves = i + 1 cursor.close() # debug_print("KoboTouch:get_bookshelflist - count bookshelves=" + unicode(count_bookshelves)) @@ -2232,6 +2240,7 @@ class KOBOTOUCH(KOBO): connection.commit() cursor.close() + # Update the bookshelf list. self.bookshelvelist = self.get_bookshelflist(connection) # debug_print("KoboTouch:set_bookshelf - end")