diff --git a/src/calibre/devices/prs505/driver.py b/src/calibre/devices/prs505/driver.py index fc92f11dc3..c55936be2d 100644 --- a/src/calibre/devices/prs505/driver.py +++ b/src/calibre/devices/prs505/driver.py @@ -157,7 +157,7 @@ class PRS505(USBMS): debug_print('PRS505: finished sync_booklists') def rebuild_collections(self, booklist, oncard): - debug_print('PRS505: started rebuild_collections') + debug_print('PRS505: started rebuild_collections on card', oncard) c = self.initialize_XML_cache() c.rebuild_collections(booklist, {'carda':1, 'cardb':2}.get(oncard, 0)) c.write() diff --git a/src/calibre/devices/prs505/sony_cache.py b/src/calibre/devices/prs505/sony_cache.py index 9d853fbbd6..289147482c 100644 --- a/src/calibre/devices/prs505/sony_cache.py +++ b/src/calibre/devices/prs505/sony_cache.py @@ -351,9 +351,10 @@ class XMLCache(object): return root = self.record_roots[bl_index] self.update_playlists(bl_index, root, booklist, []) + self.fix_ids() def update_playlists(self, bl_index, root, booklist, collections_attributes): - debug_print('Starting update_playlists', collections_attributes) + debug_print('Starting update_playlists', collections_attributes, bl_index) collections = booklist.get_collections(collections_attributes) lpath_map = self.build_lpath_map(root) for category, books in collections.items(): diff --git a/src/calibre/gui2/actions.py b/src/calibre/gui2/actions.py index d2049d3925..f3f6ee604c 100644 --- a/src/calibre/gui2/actions.py +++ b/src/calibre/gui2/actions.py @@ -832,7 +832,7 @@ class EditMetadataAction(object): # {{{ db.set_metadata(dest_id, dest_mi, ignore_errors=False) # }}} - def edit_device_collections(self, view): + def edit_device_collections(self, view, oncard=None): model = view.model() result = model.get_collections_with_ids() compare = (lambda x,y:cmp(x.lower(), y.lower())) @@ -845,7 +845,8 @@ class EditMetadataAction(object): # {{{ model.rename_collection(old_id=to_rename[text], new_name=unicode(text)) for item in to_delete: model.delete_collection_using_id(item) - self.upload_collections(model.db, view=view) + self.upload_collections(model.db, view=view, oncard=oncard) + view.reset() # }}} diff --git a/src/calibre/gui2/device.py b/src/calibre/gui2/device.py index e956eca562..6be50cf293 100644 --- a/src/calibre/gui2/device.py +++ b/src/calibre/gui2/device.py @@ -1239,17 +1239,13 @@ class DeviceMixin(object): # {{{ self.card_a_view.reset() self.card_b_view.reset() - def _upload_collections(self, job, view): + def _upload_collections(self, job): if job.failed: self.device_job_exception(job) - view.reset() - def upload_collections(self, booklist, view): - on_card = 'carda' if self.stack.currentIndex() == 2 else \ - 'cardb' if self.stack.currentIndex() == 3 else \ - None - done = partial(self._upload_collections, view=view) - return self.device_manager.upload_collections(done, booklist, on_card) + def upload_collections(self, booklist, view=None, oncard=None): + return self.device_manager.upload_collections(self._upload_collections, + booklist, oncard) def upload_books(self, files, names, metadata, on_card=None, memory=None): ''' diff --git a/src/calibre/gui2/init.py b/src/calibre/gui2/init.py index 6df1062e68..efbe32a04e 100644 --- a/src/calibre/gui2/init.py +++ b/src/calibre/gui2/init.py @@ -229,15 +229,23 @@ class LibraryViewMixin(object): # {{{ edit_device_collections=None, similar_menu=similar_menu) add_to_library = (_('Add books to library'), self.add_books_from_device) - edit_device_collections = (_('Manage collections'), self.edit_device_collections) + + edit_device_collections = (_('Manage collections'), + partial(self.edit_device_collections, oncard=None)) self.memory_view.set_context_menu(None, None, None, self.action_view, self.action_save, None, None, self.action_del, add_to_library=add_to_library, edit_device_collections=edit_device_collections) + + edit_device_collections = (_('Manage collections'), + partial(self.edit_device_collections, oncard='carda')) self.card_a_view.set_context_menu(None, None, None, self.action_view, self.action_save, None, None, self.action_del, add_to_library=add_to_library, edit_device_collections=edit_device_collections) + + edit_device_collections = (_('Manage collections'), + partial(self.edit_device_collections, oncard='cardb')) self.card_b_view.set_context_menu(None, None, None, self.action_view, self.action_save, None, None, self.action_del, add_to_library=add_to_library, @@ -254,12 +262,14 @@ class LibraryViewMixin(object): # {{{ getattr(view, func)(*args) self.memory_view.connect_dirtied_signal(self.upload_booklists) - self.memory_view.connect_upload_collections_signal(self.upload_collections) + self.memory_view.connect_upload_collections_signal( + func=self.upload_collections, oncard=None) self.card_a_view.connect_dirtied_signal(self.upload_booklists) - self.card_a_view.connect_upload_collections_signal(self.upload_collections) + self.card_a_view.connect_upload_collections_signal( + func=self.upload_collections, oncard='carda') self.card_b_view.connect_dirtied_signal(self.upload_booklists) - self.card_b_view.connect_upload_collections_signal(self.upload_collections) - + self.card_b_view.connect_upload_collections_signal( + func=self.upload_collections, oncard='cardb') self.book_on_device(None, reset=True) db.set_book_on_device_func(self.book_on_device) self.library_view.set_database(db) diff --git a/src/calibre/gui2/library/models.py b/src/calibre/gui2/library/models.py index de3f9bad1f..d8b85fcd0d 100644 --- a/src/calibre/gui2/library/models.py +++ b/src/calibre/gui2/library/models.py @@ -978,8 +978,8 @@ class DeviceBooksModel(BooksModel): # {{{ x, y = int(self.db[x].size), int(self.db[y].size) return cmp(x, y) def tagscmp(x, y): - x = ','.join(getattr(self.db[x], 'device_collections', [])).lower() - y = ','.join(getattr(self.db[y], 'device_collections', [])).lower() + x = ','.join(sorted(getattr(self.db[x], 'device_collections', []))).lower() + y = ','.join(sorted(getattr(self.db[y], 'device_collections', []))).lower() return cmp(x, y) def libcmp(x, y): x, y = self.db[x].in_library, self.db[y].in_library @@ -1027,9 +1027,6 @@ class DeviceBooksModel(BooksModel): # {{{ def set_database(self, db): self.custom_columns = {} self.db = db - for book in db: - if book.device_collections is not None: - book.device_collections.sort(cmp=lambda x,y: cmp(x.lower(), y.lower())) self.map = list(range(0, len(db))) def current_changed(self, current, previous): @@ -1143,6 +1140,7 @@ class DeviceBooksModel(BooksModel): # {{{ elif cname == 'collections': tags = self.db[self.map[row]].device_collections if tags: + tags.sort(cmp=lambda x,y: cmp(x.lower(), y.lower())) return QVariant(', '.join(tags)) elif role == Qt.ToolTipRole and index.isValid(): if self.map[row] in self.indices_to_be_deleted(): @@ -1189,6 +1187,7 @@ class DeviceBooksModel(BooksModel): # {{{ tags = [i.strip() for i in val.split(',')] tags = [t for t in tags if t] self.db[idx].device_collections = tags + self.dataChanged.emit(index, index) self.upload_collections.emit(self.db) return True diff --git a/src/calibre/gui2/library/views.py b/src/calibre/gui2/library/views.py index c0d6792399..463dccbc1f 100644 --- a/src/calibre/gui2/library/views.py +++ b/src/calibre/gui2/library/views.py @@ -509,8 +509,8 @@ class DeviceBooksView(BooksView): # {{{ def connect_dirtied_signal(self, slot): self._model.booklist_dirtied.connect(slot) - def connect_upload_collections_signal(self, func): - self._model.upload_collections.connect(partial(func, view=self)) + def connect_upload_collections_signal(self, func=None, oncard=None): + self._model.upload_collections.connect(partial(func, view=self, oncard=oncard)) def dropEvent(self, *args): error_dialog(self, _('Not allowed'),