From 0199dd15ba0d753d211f411cfd3b2306e9e66152 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 28 Apr 2022 10:18:46 +0530 Subject: [PATCH] Rescan all files when indexing is enabled --- src/calibre/db/cache.py | 4 +++- src/calibre/gui2/fts/scan.py | 28 +++++++++++++++++++--------- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/src/calibre/db/cache.py b/src/calibre/db/cache.py index 7b55aeb993..907f62c44e 100644 --- a/src/calibre/db/cache.py +++ b/src/calibre/db/cache.py @@ -438,10 +438,12 @@ class Cache: return self.backend.fts_enabled @write_api - def enable_fts(self, enabled=True, start_pool=True): + def enable_fts(self, enabled=True, start_pool=True, mark_all_dirty=False): fts = self.backend.enable_fts(weakref.ref(self) if enabled else None) if fts and start_pool: # used in the tests from threading import Thread + if mark_all_dirty: + fts.dirty_existing() self.fts_queue_thread = Thread(name='FTSQueue', target=Cache.dispatch_fts_jobs, args=(self.fts_job_queue, weakref.ref(self)), daemon=True) self.fts_queue_thread.start() fts.pool.initialize() diff --git a/src/calibre/gui2/fts/scan.py b/src/calibre/gui2/fts/scan.py index f5b77f7b0c..c7d1fb241f 100644 --- a/src/calibre/gui2/fts/scan.py +++ b/src/calibre/gui2/fts/scan.py @@ -3,7 +3,7 @@ # License: GPL v3 Copyright: 2022, Kovid Goyal import os -from qt.core import QCheckBox, QVBoxLayout, QWidget +from qt.core import QCheckBox, QLabel, QVBoxLayout, QWidget from calibre.gui2.dialogs.confirm_delete import confirm from calibre.gui2.fts.utils import get_db @@ -14,26 +14,36 @@ class ScanStatus(QWidget): def __init__(self, parent=None): super().__init__(parent) self.l = l = QVBoxLayout(self) + l.setContentsMargins(0, 0, 0, 0) self.enable_fts = b = QCheckBox(self) - b.setText(_('Index books in this library to allow searching their full text')) + b.setText(_('&Index books in this library to allow searching their full text')) l.addWidget(b) + self.enable_msg = la = QLabel('

' + _( + 'In order to search the full text of books, the text must first be indexed. Once enabled, indexing is done' + ' automatically, in the background, whenever new books are added to this calibre library.')) + la.setWordWrap(True) + l.addWidget(la) + + l.addStretch(10) self.apply_fts_state() - b.toggled.connect(self.change_fts_state) + self.enable_fts.toggled.connect(self.change_fts_state) def change_fts_state(self): - if not self.enable_fts.isChecked(): - if not confirm(_('Disabling indexing will mean that all books will have to be re-scanned when re-enabling indexing.' - ' Are you sure?'), 'disable-fts-indexing', self): - return - self.db.enable_fts(enabled=self.enable_fts.isChecked()) + if not self.enable_fts.isChecked() and not confirm(_( + 'Disabling indexing will mean that all books will have to be re-checked when re-enabling indexing. Are you sure?' + ), 'disable-fts-indexing', self): + return + self.db.enable_fts(enabled=self.enable_fts.isChecked(), mark_all_dirty=True) self.apply_fts_state() def apply_fts_state(self): b = self.enable_fts f = b.font() - f.setBold(not b.isChecked()) + indexing_enabled = b.isChecked() + f.setBold(not indexing_enabled) b.setFont(f) + self.enable_msg.setVisible(not indexing_enabled) @property def db(self):