diff --git a/src/calibre/gui2/library/models.py b/src/calibre/gui2/library/models.py index abd80aaa8f..99516ce677 100644 --- a/src/calibre/gui2/library/models.py +++ b/src/calibre/gui2/library/models.py @@ -199,7 +199,7 @@ class BooksModel(QAbstractTableModel): # {{{ self.count_changed() self.clear_caches() self.reset() - + return ids def delete_books_by_id(self, ids): for id in ids: @@ -881,6 +881,15 @@ class DeviceBooksModel(BooksModel): # {{{ ans.extend(v) return ans + def clear_ondevice(self, db_ids): + for data in self.db: + if data is None: + continue + app_id = getattr(data, 'application_id', None) + if app_id is not None and app_id in db_ids: + data.in_library = False + self.reset() + def flags(self, index): if self.map[index.row()] in self.indices_to_be_deleted(): return Qt.ItemIsUserCheckable # Can't figure out how to get the disabled flag in python diff --git a/src/calibre/gui2/ui.py b/src/calibre/gui2/ui.py index 7d258608d0..cfbcb794f3 100644 --- a/src/calibre/gui2/ui.py +++ b/src/calibre/gui2/ui.py @@ -1546,7 +1546,11 @@ class Main(MainWindow, Ui_MainWindow, DeviceGUI): row = None if ci.isValid(): row = ci.row() - view.model().delete_books(rows) + ids_deleted = view.model().delete_books(rows) + for v in (self.memory_view, self.card_a_view, self.card_b_view): + if v is None: + continue + v.model().clear_ondevice(ids_deleted) if row is not None: ci = view.model().index(row, 0) if ci.isValid(): @@ -1591,6 +1595,11 @@ class Main(MainWindow, Ui_MainWindow, DeviceGUI): self.booklists()) model.paths_deleted(paths) self.upload_booklists() + # Clear the ondevice info so it will be recomputed + self.book_on_device(None, None, reset=True) + # We want to reset all the ondevice flags in the library. Use a big + # hammer, so we don't need to worry about whether some succeeded or not + self.library_view.model().refresh() ############################################################################