Trash bin: Allow setting removed books to be permanently deleted on on library close. Fixes #2023604 [Enhancement Request: Menu option to clear Calibre trash](https://bugs.launchpad.net/calibre/+bug/2023604)

This commit is contained in:
Kovid Goyal 2023-06-18 12:40:49 +05:30
parent 9ae6fdac9d
commit c349d94af4
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 9 additions and 3 deletions

View File

@ -1261,6 +1261,8 @@ class DB:
def close(self, force=False, unload_formatter_functions=True):
if getattr(self, '_conn', None) is not None:
if self.prefs['expire_old_trash_after'] == 0:
self.expire_old_trash(0)
if unload_formatter_functions:
try:
unload_user_template_functions(self.library_id)
@ -2021,7 +2023,7 @@ class DB:
mtime = st.st_mtime
except OSError:
mtime = 0
if mtime + expire_age_in_seconds <= now:
if mtime + expire_age_in_seconds <= now or expire_age_in_seconds <= 0:
removals.append(x.path)
for x in removals:
rmtree_with_retry(x)

View File

@ -134,11 +134,15 @@ class TrashView(Dialog):
la = QLabel(_('&Permanently delete after:'))
self.auto_delete = ad = QSpinBox(self)
ad.setMinimum(1)
ad.setMinimum(0)
ad.setMaximum(365)
ad.setSpecialValueText(_('on close'))
ad.setValue(int(self.db.pref('expire_old_trash_after', DEFAULT_TRASH_EXPIRY_TIME_SECONDS) / 86400))
ad.setSuffix(_(' days'))
ad.setToolTip(_('Deleted items are permanently deleted automatically after the specified number of days'))
ad.setToolTip(_(
'Deleted items are permanently deleted automatically after the specified number of days. If set to "on close" they are'
' deleted whenever the library is closed, that is when switching to another library or exiting calibre.'
))
ad.valueChanged.connect(self.trash_expiry_time_changed)
h = QHBoxLayout()
h.addWidget(la), h.addWidget(ad), h.addStretch(10)