Handle switching libraries with the fts window open

This commit is contained in:
Kovid Goyal 2022-06-14 10:45:53 +05:30
parent eb3a378006
commit 209b40d601
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
3 changed files with 24 additions and 7 deletions

View File

@ -28,6 +28,6 @@ class FullTextSearchAction(InterfaceAction):
self.dialog.show() self.dialog.show()
self.dialog.raise_() self.dialog.raise_()
def library_about_to_change(self, olddb, db): def library_changed(self, db):
if self._dialog is not None: if self._dialog is not None:
self._dialog.library_changed() self._dialog.library_changed()

View File

@ -37,12 +37,16 @@ class FTSDialog(Dialog):
self.results_panel = rp = ResultsPanel(self) self.results_panel = rp = ResultsPanel(self)
rp.switch_to_scan_panel.connect(self.show_scan_status) rp.switch_to_scan_panel.connect(self.show_scan_status)
s.addWidget(ss), s.addWidget(rp) s.addWidget(ss), s.addWidget(rp)
if ss.indexing_progress.almost_complete: self.show_appropriate_panel()
self.update_indexing_label()
self.scan_status.indexing_progress_changed.connect(self.update_indexing_label)
def show_appropriate_panel(self):
ss = self.scan_status
if ss.indexing_enabled and ss.indexing_progress.almost_complete:
self.show_results_panel() self.show_results_panel()
else: else:
self.show_scan_status() self.show_scan_status()
self.update_indexing_label()
self.scan_status.indexing_progress_changed.connect(self.update_indexing_label)
def update_indexing_label(self): def update_indexing_label(self):
ip = self.scan_status.indexing_progress ip = self.scan_status.indexing_progress
@ -52,12 +56,11 @@ class FTSDialog(Dialog):
self.indexing_label.setVisible(True) self.indexing_label.setVisible(True)
try: try:
p = (ip.total - ip.left) / ip.total p = (ip.total - ip.left) / ip.total
p = int(100 * p)
except Exception: except Exception:
self.indexing_label.setVisible(False) self.indexing_label.setVisible(False)
else: else:
if p < 100: if p < 100:
t = _('Indexing is only {0}% done').format(p) t = _('Indexing is only {0:.0%} done').format(p)
ss = '' ss = ''
if p < 90: if p < 90:
ss = 'QLabel { color: red }' ss = 'QLabel { color: red }'
@ -79,6 +82,8 @@ class FTSDialog(Dialog):
def library_changed(self): def library_changed(self):
self.results_panel.clear_results() self.results_panel.clear_results()
self.scan_status.reset_indexing_state_for_current_db()
self.show_appropriate_panel()
def sizeHint(self): def sizeHint(self):
return QSize(1000, 680) return QSize(1000, 680)

View File

@ -101,7 +101,7 @@ class ScanProgress(QWidget):
self.switch_anyway.setText(_('Start &searching')) self.switch_anyway.setText(_('Start &searching'))
else: else:
done = total - left done = total - left
t = _('{0} of {1} book files ({2:.0%}) have been indexed').format( t = _('{0} of {1} book files, {2:.0%} have been indexed').format(
done, total, done / (total or 1)) done, total, done / (total or 1))
self.warn_label.setVisible(True) self.warn_label.setVisible(True)
self.switch_anyway.setIcon(QIcon.ic('dialog_warning.png')) self.switch_anyway.setIcon(QIcon.ic('dialog_warning.png'))
@ -187,9 +187,21 @@ class ScanStatus(QWidget):
with BusyCursor(): with BusyCursor():
self.db.reindex_fts() self.db.reindex_fts()
@property
def indexing_enabled(self):
return self.enable_fts.isChecked()
def reset_indexing_state_for_current_db(self):
self.enable_fts.blockSignals(True)
self.enable_fts.setChecked(self.db.is_fts_enabled())
self.enable_fts.blockSignals(False)
self.update_stats()
self.apply_fts_state()
def shutdown(self): def shutdown(self):
self.indexing_status_timer.stop() self.indexing_status_timer.stop()
self.scan_progress.slow_button.setChecked(True) self.scan_progress.slow_button.setChecked(True)
self.reset_indexing_state_for_current_db()
if __name__ == '__main__': if __name__ == '__main__':