From dbbb96fa05fcb9bdbd3fd4824c2ce6314450e391 Mon Sep 17 00:00:00 2001 From: Charles Haley Date: Sun, 20 Nov 2022 11:47:55 +0000 Subject: [PATCH] Add more error checking. --- src/calibre/gui2/preferences/search.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/calibre/gui2/preferences/search.py b/src/calibre/gui2/preferences/search.py index 7795844081..13faccb23f 100644 --- a/src/calibre/gui2/preferences/search.py +++ b/src/calibre/gui2/preferences/search.py @@ -155,8 +155,11 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form): name = icu_lower(str(self.gst_names.currentText())) if not name: return error_dialog(self.gui, _('Grouped search terms'), - _('The search term cannot be blank'), + _('The search term name cannot be blank'), show=True) + if ' ' in name: + return error_dialog(self.gui, _('Invalid grouped search name'), + _('The grouped search term name cannot contain spaces'), show=True) if idx != 0: orig_name = str(self.gst_names.itemData(idx) or '') else: @@ -176,7 +179,6 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form): if not val: return error_dialog(self.gui, _('Grouped search terms'), _('The value box cannot be empty'), show=True) - if orig_name and name != orig_name: del self.gst[orig_name] self.gst_changed = True @@ -234,8 +236,16 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form): 'The option to have un-accented characters match accented characters has no effect' ' if you also turn on case-sensitive searching. So only turn on one of those options'), show=True) raise AbortCommit() + ucs = (m.strip() for m in self.opt_grouped_search_make_user_categories.text().split(',') if m.strip()) + ucs -= (self.gst.keys()) + if ucs: + error_dialog(self, _('Missing grouped search terms'), _( + 'The option "Make user categories from" contains names that ' + "aren't grouped search terms: {}").format(', '.join(sorted(ucs))), show=True) + raise AbortCommit() + restart = ConfigWidgetBase.commit(self) - if self.gst_changed: + if self.gst_changed or self.muc_changed: self.db.new_api.set_pref('grouped_search_terms', self.gst) self.db.field_metadata.add_grouped_search_terms(self.gst) self.db.new_api.set_pref('similar_authors_search_key',