From 725e9dd68f53ce83f58fec387baeb722bc99a649 Mon Sep 17 00:00:00 2001 From: Timothy Legge Date: Tue, 24 Aug 2010 21:58:45 -0300 Subject: [PATCH] Show I'm Reading list as a read-only collection --- src/calibre/devices/kobo/books.py | 2 +- src/calibre/devices/kobo/driver.py | 17 +++++++++++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/calibre/devices/kobo/books.py b/src/calibre/devices/kobo/books.py index a5b2e98d2f..124a10b380 100644 --- a/src/calibre/devices/kobo/books.py +++ b/src/calibre/devices/kobo/books.py @@ -20,7 +20,7 @@ class Book(MetaInformation): 'title_sort', 'comments', 'category', 'publisher', 'series', 'series_index', 'rating', 'isbn', 'language', 'application_id', 'book_producer', 'lccn', 'lcc', 'ddc', 'rights', 'publication_type', - 'uuid', + 'uuid', 'device_collections', ] def __init__(self, prefix, lpath, title, authors, mime, date, ContentType, thumbnail_name, other=None): diff --git a/src/calibre/devices/kobo/driver.py b/src/calibre/devices/kobo/driver.py index bd96ecd3cd..35fceb80f7 100644 --- a/src/calibre/devices/kobo/driver.py +++ b/src/calibre/devices/kobo/driver.py @@ -72,7 +72,7 @@ class KOBO(USBMS): for idx,b in enumerate(bl): bl_cache[b.lpath] = idx - def update_booklist(prefix, path, title, authors, mime, date, ContentType, ImageID): + def update_booklist(prefix, path, title, authors, mime, date, ContentType, ImageID, readstatus): changed = False # if path_to_ext(path) in self.FORMATS: try: @@ -82,6 +82,13 @@ class KOBO(USBMS): lpath = lpath.replace('\\', '/') # print "LPATH: " + lpath + playlist_map = {} + + if readstatus == 1: + if lpath not in playlist_map: + playlist_map[lpath] = [] + playlist_map[lpath].append("I\'m Reading") + path = self.normalize_path(path) # print "Normalized FileName: " + path @@ -97,11 +104,13 @@ class KOBO(USBMS): if self.update_metadata_item(bl[idx]): # print 'update_metadata_item returned true' changed = True + bl[idx].device_collections = playlist_map.get(lpath, []) else: book = Book(prefix, lpath, title, authors, mime, date, ContentType, ImageID) # print 'Update booklist' if bl.add_book(book, replace_metadata=False): changed = True + book.device_collections = playlist_map.get(book.lpath, []) except: # Probably a path encoding error import traceback traceback.print_exc() @@ -117,7 +126,7 @@ class KOBO(USBMS): #cursor.close() query= 'select Title, Attribution, DateCreated, ContentID, MimeType, ContentType, ' \ - 'ImageID from content where BookID is Null' + 'ImageID, ReadStatus from content where BookID is Null' cursor.execute (query) @@ -129,10 +138,10 @@ class KOBO(USBMS): mime = mime_type_ext(path_to_ext(row[3])) if oncard != 'carda' and oncard != 'cardb' and not row[3].startswith("file:///mnt/sd/"): - changed = update_booklist(self._main_prefix, path, row[0], row[1], mime, row[2], row[5], row[6]) + changed = update_booklist(self._main_prefix, path, row[0], row[1], mime, row[2], row[5], row[6], row[7]) # print "shortbook: " + path elif oncard == 'carda' and row[3].startswith("file:///mnt/sd/"): - changed = update_booklist(self._card_a_prefix, path, row[0], row[1], mime, row[2], row[5], row[6]) + changed = update_booklist(self._card_a_prefix, path, row[0], row[1], mime, row[2], row[5], row[6], row[7]) if changed: need_sync = True