From 7b759f96d62f5a9fadeb504ff6ca214b6b7eac7d Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 22 May 2023 13:26:04 +0530 Subject: [PATCH] Fix #2020233 [Enhancement Request: Send-to-Device: Ask first if book already on device](https://bugs.launchpad.net/calibre/+bug/2020233) --- src/calibre/gui2/device.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/calibre/gui2/device.py b/src/calibre/gui2/device.py index e1a6db40c3..f7179be0de 100644 --- a/src/calibre/gui2/device.py +++ b/src/calibre/gui2/device.py @@ -1043,6 +1043,28 @@ class DeviceMixin: # {{{ def _sync_action_triggered(self, *args): m = getattr(self, '_sync_menu', None) if m is not None: + ids = self.library_view.get_selected_ids(as_set=True) + db = self.current_db.new_api + already_on_device = db.all_field_for('ondevice', ids, default_value='') + books_on_device = {book_id for book_id, val in already_on_device.items() if val} + if books_on_device: + if len(books_on_device) == 1: + if not question_dialog(self, _('Book already on device'), _( + 'The book {} is already present on the device. Resending it might cause any' + ' annotations/bookmarks on the device for this book to be lost. Are you sure?').format( + db.field_for('title', tuple(books_on_device)[0])), skip_dialog_name='confirm-resend-existing-books' + ): + return + else: + title_sorts = db.all_field_for('sort', books_on_device) + titles = sorted(db.all_field_for('title', books_on_device).items(), key=lambda x: title_sorts[x[0]]) + details = '\n'.join(title for book_id, title in titles) + if not question_dialog(self, _('Some books already on device'), _( + 'Some of the selected books are already on the device. Resending them might cause any annotations/bookmarks on the' + ' device for these books to be lost. Click "Show details" to see the books already on the device. Are you sure?'), + skip_dialog_name='confirm-resend-existing-books', det_msg=details + ): + return m.trigger_default() def create_device_menu(self):