When deleting large numbers of books, give the user the option to skip the Recycle Bin, since sending lots of files to the recycle bin can be very slow. Fixes #784987 (When deleting books the processor goes to 100%)

This commit is contained in:
Kovid Goyal 2011-05-19 11:24:00 -06:00
parent b054dd5d9f
commit 697b535f97
3 changed files with 17 additions and 5 deletions

View File

@ -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?'), '<p>'+
_('You are trying to delete %d books. '
'Sending so many files to the Recycle'
' Bin <b>can be slow</b>. Should calibre skip the'
' Recycle Bin? If you click Yes the files'
' will be <b>permanently deleted</b>.')%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

View File

@ -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()

View File

@ -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):