mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
D'nd for remove books
This commit is contained in:
parent
6e03557e02
commit
56d1694b47
@ -88,6 +88,32 @@ class DeleteAction(InterfaceAction):
|
|||||||
action_add_menu = True
|
action_add_menu = True
|
||||||
action_menu_clone_qaction = _('Remove selected books')
|
action_menu_clone_qaction = _('Remove selected books')
|
||||||
|
|
||||||
|
accepts_drops = True
|
||||||
|
|
||||||
|
def accept_enter_event(self, event, mime_data):
|
||||||
|
if mime_data.hasFormat("application/calibre+from_library"):
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
def accept_drag_move_event(self, event, mime_data):
|
||||||
|
if mime_data.hasFormat("application/calibre+from_library"):
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
def drop_event(self, event, mime_data):
|
||||||
|
mime = 'application/calibre+from_library'
|
||||||
|
if mime_data.hasFormat(mime):
|
||||||
|
self.dropped_ids = tuple(map(int, str(mime_data.data(mime)).split()))
|
||||||
|
QTimer.singleShot(1, self.do_drop)
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
def do_drop(self):
|
||||||
|
book_ids = self.dropped_ids
|
||||||
|
del self.dropped_ids
|
||||||
|
if book_ids:
|
||||||
|
self.do_library_delete(book_ids)
|
||||||
|
|
||||||
def genesis(self):
|
def genesis(self):
|
||||||
self.qaction.triggered.connect(self.delete_books)
|
self.qaction.triggered.connect(self.delete_books)
|
||||||
self.delete_menu = self.qaction.menu()
|
self.delete_menu = self.qaction.menu()
|
||||||
@ -296,6 +322,44 @@ class DeleteAction(InterfaceAction):
|
|||||||
current_row = rmap.get(next_id, None)
|
current_row = rmap.get(next_id, None)
|
||||||
self.library_ids_deleted(ids_deleted, current_row=current_row)
|
self.library_ids_deleted(ids_deleted, current_row=current_row)
|
||||||
|
|
||||||
|
def do_library_delete(self, to_delete_ids):
|
||||||
|
view = self.gui.current_view()
|
||||||
|
# Ask the user if they want to delete the book from the library or device if it is in both.
|
||||||
|
if self.gui.device_manager.is_device_connected:
|
||||||
|
on_device = False
|
||||||
|
on_device_ids = self._get_selected_ids()
|
||||||
|
for id in on_device_ids:
|
||||||
|
res = self.gui.book_on_device(id)
|
||||||
|
if res[0] or res[1] or res[2]:
|
||||||
|
on_device = True
|
||||||
|
if on_device:
|
||||||
|
break
|
||||||
|
if on_device:
|
||||||
|
loc = confirm_location('<p>' + _('Some of the selected books are on the attached device. '
|
||||||
|
'<b>Where</b> do you want the selected files deleted from?'),
|
||||||
|
self.gui)
|
||||||
|
if not loc:
|
||||||
|
return
|
||||||
|
elif loc == 'dev':
|
||||||
|
self.remove_matching_books_from_device()
|
||||||
|
return
|
||||||
|
elif loc == 'both':
|
||||||
|
self.remove_matching_books_from_device()
|
||||||
|
# The following will run if the selected books are not on a connected device.
|
||||||
|
# The user has selected to delete from the library or the device and library.
|
||||||
|
if not confirm('<p>'+_('The selected books will be '
|
||||||
|
'<b>permanently deleted</b> and the files '
|
||||||
|
'removed from your calibre library. Are you sure?')
|
||||||
|
+'</p>', 'library_delete_books', self.gui):
|
||||||
|
return
|
||||||
|
next_id = view.next_id
|
||||||
|
if len(to_delete_ids) < 5:
|
||||||
|
view.model().delete_books_by_id(to_delete_ids)
|
||||||
|
self.library_ids_deleted2(to_delete_ids, next_id=next_id)
|
||||||
|
else:
|
||||||
|
self.__md = MultiDeleter(self.gui, to_delete_ids,
|
||||||
|
partial(self.library_ids_deleted2, next_id=next_id))
|
||||||
|
|
||||||
def delete_books(self, *args):
|
def delete_books(self, *args):
|
||||||
'''
|
'''
|
||||||
Delete selected books from device or library.
|
Delete selected books from device or library.
|
||||||
@ -307,41 +371,7 @@ class DeleteAction(InterfaceAction):
|
|||||||
# Library view is visible.
|
# Library view is visible.
|
||||||
if self.gui.stack.currentIndex() == 0:
|
if self.gui.stack.currentIndex() == 0:
|
||||||
to_delete_ids = [view.model().id(r) for r in rows]
|
to_delete_ids = [view.model().id(r) for r in rows]
|
||||||
# Ask the user if they want to delete the book from the library or device if it is in both.
|
self.do_library_delete(to_delete_ids)
|
||||||
if self.gui.device_manager.is_device_connected:
|
|
||||||
on_device = False
|
|
||||||
on_device_ids = self._get_selected_ids()
|
|
||||||
for id in on_device_ids:
|
|
||||||
res = self.gui.book_on_device(id)
|
|
||||||
if res[0] or res[1] or res[2]:
|
|
||||||
on_device = True
|
|
||||||
if on_device:
|
|
||||||
break
|
|
||||||
if on_device:
|
|
||||||
loc = confirm_location('<p>' + _('Some of the selected books are on the attached device. '
|
|
||||||
'<b>Where</b> do you want the selected files deleted from?'),
|
|
||||||
self.gui)
|
|
||||||
if not loc:
|
|
||||||
return
|
|
||||||
elif loc == 'dev':
|
|
||||||
self.remove_matching_books_from_device()
|
|
||||||
return
|
|
||||||
elif loc == 'both':
|
|
||||||
self.remove_matching_books_from_device()
|
|
||||||
# The following will run if the selected books are not on a connected device.
|
|
||||||
# The user has selected to delete from the library or the device and library.
|
|
||||||
if not confirm('<p>'+_('The selected books will be '
|
|
||||||
'<b>permanently deleted</b> and the files '
|
|
||||||
'removed from your calibre library. Are you sure?')
|
|
||||||
+'</p>', 'library_delete_books', self.gui):
|
|
||||||
return
|
|
||||||
next_id = view.next_id
|
|
||||||
if len(rows) < 5:
|
|
||||||
view.model().delete_books_by_id(to_delete_ids)
|
|
||||||
self.library_ids_deleted2(to_delete_ids, next_id=next_id)
|
|
||||||
else:
|
|
||||||
self.__md = MultiDeleter(self.gui, to_delete_ids,
|
|
||||||
partial(self.library_ids_deleted2, next_id=next_id))
|
|
||||||
# Device view is visible.
|
# Device view is visible.
|
||||||
else:
|
else:
|
||||||
if self.gui.stack.currentIndex() == 1:
|
if self.gui.stack.currentIndex() == 1:
|
||||||
|
@ -50,9 +50,10 @@ class EditMetadataAction(InterfaceAction):
|
|||||||
def do_drop(self):
|
def do_drop(self):
|
||||||
book_ids = self.dropped_ids
|
book_ids = self.dropped_ids
|
||||||
del self.dropped_ids
|
del self.dropped_ids
|
||||||
db = self.gui.library_view.model().db
|
if book_ids:
|
||||||
rows = [db.row(i) for i in book_ids]
|
db = self.gui.library_view.model().db
|
||||||
self.edit_metadata_for(rows, book_ids)
|
rows = [db.row(i) for i in book_ids]
|
||||||
|
self.edit_metadata_for(rows, book_ids)
|
||||||
|
|
||||||
def genesis(self):
|
def genesis(self):
|
||||||
md = self.qaction.menu()
|
md = self.qaction.menu()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user