From 3f0fee00a50142a3ed995dd2b8449d2c39707042 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 4 Jul 2012 10:58:41 +0530 Subject: [PATCH] When copying to library and deleting after copy, do not place deleted files in recycle bin, as this is redundant and slow (they have already been copied into another library) --- src/calibre/gui2/actions/copy_to_library.py | 3 ++- src/calibre/gui2/library/models.py | 11 +++++------ src/calibre/library/database2.py | 6 ++++-- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/calibre/gui2/actions/copy_to_library.py b/src/calibre/gui2/actions/copy_to_library.py index f901d5ce30..a6699b0fcb 100644 --- a/src/calibre/gui2/actions/copy_to_library.py +++ b/src/calibre/gui2/actions/copy_to_library.py @@ -216,7 +216,8 @@ class CopyToLibraryAction(InterfaceAction): if ci.isValid(): row = ci.row() - v.model().delete_books_by_id(self.worker.processed) + v.model().delete_books_by_id(self.worker.processed, + permanent=True) self.gui.iactions['Remove Books'].library_ids_deleted( self.worker.processed, row) diff --git a/src/calibre/gui2/library/models.py b/src/calibre/gui2/library/models.py index e2706c0a54..f0296a32c7 100644 --- a/src/calibre/gui2/library/models.py +++ b/src/calibre/gui2/library/models.py @@ -220,16 +220,15 @@ class BooksModel(QAbstractTableModel): # {{{ self.count_changed() self.reset() - def delete_books(self, indices): + def delete_books(self, indices, permanent=False): ids = map(self.id, indices) - for id in ids: - self.db.delete_book(id, notify=False) - self.books_deleted() + self.delete_books_by_id(ids, permanent=permanent) return ids - def delete_books_by_id(self, ids): + def delete_books_by_id(self, ids, permanent=False): for id in ids: - self.db.delete_book(id) + self.db.delete_book(id, permanent=permanent, do_clean=False) + self.db.clean() self.books_deleted() def books_added(self, num): diff --git a/src/calibre/library/database2.py b/src/calibre/library/database2.py index ccb9bc35b7..e60350b307 100644 --- a/src/calibre/library/database2.py +++ b/src/calibre/library/database2.py @@ -1425,7 +1425,8 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns): opath = self.format_abspath(book_id, nfmt, index_is_id=True) return fmt if opath is None else nfmt - def delete_book(self, id, notify=True, commit=True, permanent=False): + def delete_book(self, id, notify=True, commit=True, permanent=False, + do_clean=True): ''' Removes book from the result cache and the underlying database. If you set commit to False, you must call clean() manually afterwards @@ -1442,7 +1443,8 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns): self.conn.execute('DELETE FROM books WHERE id=?', (id,)) if commit: self.conn.commit() - self.clean() + if do_clean: + self.clean() self.data.books_deleted([id]) if notify: self.notify('delete', [id])