diff --git a/src/calibre/gui2/actions/delete.py b/src/calibre/gui2/actions/delete.py index a1fddd84b8..718f0737b3 100644 --- a/src/calibre/gui2/actions/delete.py +++ b/src/calibre/gui2/actions/delete.py @@ -9,11 +9,12 @@ from functools import partial from PyQt4.Qt import QMenu, QObject, QTimer -from calibre.gui2 import error_dialog +from calibre.gui2 import error_dialog, question_dialog from calibre.gui2.dialogs.delete_matching_from_device import DeleteMatchingFromDeviceDialog from calibre.gui2.dialogs.confirm_delete import confirm from calibre.gui2.dialogs.confirm_delete_location import confirm_location from calibre.gui2.actions import InterfaceAction +from calibre.utils.recycle_bin import can_recycle single_shot = partial(QTimer.singleShot, 10) @@ -24,6 +25,15 @@ class MultiDeleter(QObject): QObject.__init__(self, gui) self.model = gui.library_view.model() self.ids = ids + self.permanent = False + if can_recycle and len(ids) > 100: + if question_dialog(gui, _('Are you sure?'), '
'+ + _('You are trying to delete %d books. ' + 'Sending so many files to the Recycle' + ' Bin can be slow. Should calibre skip the' + ' Recycle Bin? If you click Yes the files' + ' will be permanently deleted.')%len(ids)): + self.permanent = True self.gui = gui self.failures = [] self.deleted_ids = [] @@ -44,7 +54,8 @@ class MultiDeleter(QObject): title_ = self.model.db.title(id_, index_is_id=True) if title_: title = title_ - self.model.db.delete_book(id_, notify=False, commit=False) + self.model.db.delete_book(id_, notify=False, commit=False, + permanent=self.permanent) self.deleted_ids.append(id_) except: import traceback diff --git a/src/calibre/library/database2.py b/src/calibre/library/database2.py index 8ac33d4b40..9a740a08b7 100644 --- a/src/calibre/library/database2.py +++ b/src/calibre/library/database2.py @@ -1145,7 +1145,7 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns): self.notify('metadata', [id]) return True - def delete_book(self, id, notify=True, commit=True): + def delete_book(self, id, notify=True, commit=True, permanent=False): ''' Removes book from the result cache and the underlying database. If you set commit to False, you must call clean() manually afterwards @@ -1155,10 +1155,10 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns): except: path = None if path and os.path.exists(path): - self.rmtree(path) + self.rmtree(path, permanent=permanent) parent = os.path.dirname(path) if len(os.listdir(parent)) == 0: - self.rmtree(parent) + self.rmtree(parent, permanent=permanent) self.conn.execute('DELETE FROM books WHERE id=?', (id,)) if commit: self.conn.commit() diff --git a/src/calibre/utils/recycle_bin.py b/src/calibre/utils/recycle_bin.py index df6016d796..7d3d268553 100644 --- a/src/calibre/utils/recycle_bin.py +++ b/src/calibre/utils/recycle_bin.py @@ -24,6 +24,7 @@ elif isosx: path = path.decode(filesystem_encoding) u.send2trash(path) +can_recycle = callable(recycle) def delete_file(path): if callable(recycle):