mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
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:
parent
b054dd5d9f
commit
697b535f97
@ -9,11 +9,12 @@ from functools import partial
|
|||||||
|
|
||||||
from PyQt4.Qt import QMenu, QObject, QTimer
|
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.delete_matching_from_device import DeleteMatchingFromDeviceDialog
|
||||||
from calibre.gui2.dialogs.confirm_delete import confirm
|
from calibre.gui2.dialogs.confirm_delete import confirm
|
||||||
from calibre.gui2.dialogs.confirm_delete_location import confirm_location
|
from calibre.gui2.dialogs.confirm_delete_location import confirm_location
|
||||||
from calibre.gui2.actions import InterfaceAction
|
from calibre.gui2.actions import InterfaceAction
|
||||||
|
from calibre.utils.recycle_bin import can_recycle
|
||||||
|
|
||||||
single_shot = partial(QTimer.singleShot, 10)
|
single_shot = partial(QTimer.singleShot, 10)
|
||||||
|
|
||||||
@ -24,6 +25,15 @@ class MultiDeleter(QObject):
|
|||||||
QObject.__init__(self, gui)
|
QObject.__init__(self, gui)
|
||||||
self.model = gui.library_view.model()
|
self.model = gui.library_view.model()
|
||||||
self.ids = ids
|
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.gui = gui
|
||||||
self.failures = []
|
self.failures = []
|
||||||
self.deleted_ids = []
|
self.deleted_ids = []
|
||||||
@ -44,7 +54,8 @@ class MultiDeleter(QObject):
|
|||||||
title_ = self.model.db.title(id_, index_is_id=True)
|
title_ = self.model.db.title(id_, index_is_id=True)
|
||||||
if title_:
|
if title_:
|
||||||
title = 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_)
|
self.deleted_ids.append(id_)
|
||||||
except:
|
except:
|
||||||
import traceback
|
import traceback
|
||||||
|
@ -1145,7 +1145,7 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns):
|
|||||||
self.notify('metadata', [id])
|
self.notify('metadata', [id])
|
||||||
return True
|
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.
|
Removes book from the result cache and the underlying database.
|
||||||
If you set commit to False, you must call clean() manually afterwards
|
If you set commit to False, you must call clean() manually afterwards
|
||||||
@ -1155,10 +1155,10 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns):
|
|||||||
except:
|
except:
|
||||||
path = None
|
path = None
|
||||||
if path and os.path.exists(path):
|
if path and os.path.exists(path):
|
||||||
self.rmtree(path)
|
self.rmtree(path, permanent=permanent)
|
||||||
parent = os.path.dirname(path)
|
parent = os.path.dirname(path)
|
||||||
if len(os.listdir(parent)) == 0:
|
if len(os.listdir(parent)) == 0:
|
||||||
self.rmtree(parent)
|
self.rmtree(parent, permanent=permanent)
|
||||||
self.conn.execute('DELETE FROM books WHERE id=?', (id,))
|
self.conn.execute('DELETE FROM books WHERE id=?', (id,))
|
||||||
if commit:
|
if commit:
|
||||||
self.conn.commit()
|
self.conn.commit()
|
||||||
|
@ -24,6 +24,7 @@ elif isosx:
|
|||||||
path = path.decode(filesystem_encoding)
|
path = path.decode(filesystem_encoding)
|
||||||
u.send2trash(path)
|
u.send2trash(path)
|
||||||
|
|
||||||
|
can_recycle = callable(recycle)
|
||||||
|
|
||||||
def delete_file(path):
|
def delete_file(path):
|
||||||
if callable(recycle):
|
if callable(recycle):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user