diff --git a/src/calibre/devices/android/driver.py b/src/calibre/devices/android/driver.py index dfd940f777..5642235b31 100644 --- a/src/calibre/devices/android/driver.py +++ b/src/calibre/devices/android/driver.py @@ -51,8 +51,8 @@ class ANDROID(USBMS): 'GT-I5700', 'SAMSUNG', 'DELL', 'LINUX'] WINDOWS_MAIN_MEM = ['ANDROID_PHONE', 'A855', 'A853', 'INC.NEXUS_ONE', '__UMS_COMPOSITE', '_MB200', 'MASS_STORAGE', '_-_CARD', - 'PR OD_GT-I9000', 'FILE-STOR_GADGET'] - WINDOWS_CARD_A_MEM = ['ANDROID_PHONE', 'PR OD_GT-I9000_CARD', + 'GT-I9000', 'FILE-STOR_GADGET'] + WINDOWS_CARD_A_MEM = ['ANDROID_PHONE', 'GT-I9000_CARD', 'FILE-STOR_GADGET'] OSX_MAIN_MEM = 'HTC Android Phone Media' diff --git a/src/calibre/devices/kobo/books.py b/src/calibre/devices/kobo/books.py index 0389b266f2..781562d091 100644 --- a/src/calibre/devices/kobo/books.py +++ b/src/calibre/devices/kobo/books.py @@ -13,7 +13,7 @@ from calibre import isbytestring class Book(MetaInformation): - BOOK_ATTRS = ['lpath', 'size', 'mime', 'device_collections'] + BOOK_ATTRS = ['lpath', 'size', 'mime', 'device_collections', '_new_book'] JSON_ATTRS = [ 'lpath', 'title', 'authors', 'mime', 'size', 'tags', 'author_sort', @@ -27,6 +27,7 @@ class Book(MetaInformation): MetaInformation.__init__(self, '') self.device_collections = [] + self._new_book = False self.path = os.path.join(prefix, lpath) if os.sep == '\\': diff --git a/src/calibre/devices/usbms/books.py b/src/calibre/devices/usbms/books.py index 7108fa3f00..0f5c848c1a 100644 --- a/src/calibre/devices/usbms/books.py +++ b/src/calibre/devices/usbms/books.py @@ -15,7 +15,7 @@ from calibre.utils.config import prefs class Book(MetaInformation): - BOOK_ATTRS = ['lpath', 'size', 'mime', 'device_collections'] + BOOK_ATTRS = ['lpath', 'size', 'mime', 'device_collections', '_new_book'] JSON_ATTRS = [ 'lpath', 'title', 'authors', 'mime', 'size', 'tags', 'author_sort', @@ -30,6 +30,7 @@ class Book(MetaInformation): MetaInformation.__init__(self, '') + self._new_book = False self.device_collections = [] self.path = os.path.join(prefix, lpath) if os.sep == '\\': @@ -133,12 +134,21 @@ class CollectionsBookList(BookList): def get_collections(self, collection_attributes): collections = {} series_categories = set([]) - collection_attributes = list(collection_attributes) - if prefs['preserve_user_collections']: - collection_attributes += ['device_collections'] - for attr in collection_attributes: - attr = attr.strip() - for book in self: + for book in self: + # The default: leave the book in all existing collections. Do not + # add any new ones. + attrs = ['device_collections'] + if getattr(book, '_new_book', False): + if prefs['preserve_user_collections']: + # Ensure that the book is in all the book's existing + # collections plus all metadata collections + attrs += collection_attributes + else: + # The book's existing collections are ignored. Put the book + # in collections defined by its metadata. + attrs = collection_attributes + for attr in attrs: + attr = attr.strip() val = getattr(book, attr, None) if not val: continue if isbytestring(val): diff --git a/src/calibre/devices/usbms/driver.py b/src/calibre/devices/usbms/driver.py index 2fc8b0d814..30629161db 100644 --- a/src/calibre/devices/usbms/driver.py +++ b/src/calibre/devices/usbms/driver.py @@ -233,6 +233,7 @@ class USBMS(CLI, Device): book = self.book_class(prefix, lpath, other=info) if book.size is None: book.size = os.stat(self.normalize_path(path)).st_size + book._new_book = True # Must be before add_book booklists[blist].add_book(book, replace_metadata=True) self.report_progress(1.0, _('Adding books to device metadata listing...')) debug_print('USBMS: finished adding metadata') @@ -273,6 +274,9 @@ class USBMS(CLI, Device): self.report_progress(1.0, _('Removing books from device metadata listing...')) debug_print('USBMS: finished removing metadata for %d books'%(len(paths))) + # If you override this method and you use book._new_book, then you must + # complete the processing before you call this method. The flag is cleared + # at the end just before the return def sync_booklists(self, booklists, end_session=True): debug_print('USBMS: starting sync_booklists') @@ -291,6 +295,12 @@ class USBMS(CLI, Device): write_prefix(self._card_a_prefix, 1) write_prefix(self._card_b_prefix, 2) + # Clear the _new_book indication, as we are supposed to be done with + # adding books at this point + for blist in booklists: + for book in blist: + book._new_book = False + self.report_progress(1.0, _('Sending metadata to device...')) debug_print('USBMS: finished sync_booklists')