diff --git a/src/core/loader.cpp b/src/core/loader.cpp --- a/src/core/loader.cpp +++ b/src/core/loader.cpp @@ -89,13 +89,18 @@ if (plang.isEmpty()) { plang = d->settings->defaultLanguage(); } - const QVector lClients = d->languageClients[plang]; - if (lClients.isEmpty()) { + // make sure plang is one of languages(), otherwise calling + // d->languageClients[plang] will create a default-constructed value + // for it and it doesn't have any dictionaries to begin with + if (!languages().contains(plang)) { qCWarning(SONNET_LOG_CORE) << "No language dictionaries for the language:" << plang; + emit loadingDictionaryFailed(plang); return nullptr; } + const QVector lClients = d->languageClients[plang]; + if (backend.isEmpty()) { backend = d->settings->defaultClient(); if (!backend.isEmpty()) { diff --git a/src/core/loader_p.h b/src/core/loader_p.h --- a/src/core/loader_p.h +++ b/src/core/loader_p.h @@ -127,6 +127,14 @@ */ void configurationChanged(); + /** + * Emitted when loading a dictionary fails, so that Ui parts can + * display an appropriate error message informing the user about + * the issue. + * @since 5.55 + */ + void loadingDictionaryFailed(const QString &lang) const; + protected: friend class Settings; void changed(); diff --git a/src/ui/dictionarycombobox.h b/src/ui/dictionarycombobox.h --- a/src/ui/dictionarycombobox.h +++ b/src/ui/dictionarycombobox.h @@ -109,6 +109,8 @@ private: DictionaryComboBoxPrivate *const d; Q_PRIVATE_SLOT(d, void slotDictionaryChanged(int)) + + void slotLoadingDictionaryFailed(const QString &lang); }; } diff --git a/src/ui/dictionarycombobox.cpp b/src/ui/dictionarycombobox.cpp --- a/src/ui/dictionarycombobox.cpp +++ b/src/ui/dictionarycombobox.cpp @@ -19,6 +19,9 @@ */ #include "dictionarycombobox.h" +#include "loader_p.h" + +#include #include #include "ui_debug.h" @@ -34,6 +37,7 @@ DictionaryComboBox *q; void slotDictionaryChanged(int idx); + bool dictionaryErrorShown = false; }; void DictionaryComboBoxPrivate::slotDictionaryChanged(int idx) @@ -48,6 +52,8 @@ : QComboBox(parent) , d(new DictionaryComboBoxPrivate(this)) { + connect(Loader::openLoader(), &Loader::loadingDictionaryFailed, + this, &DictionaryComboBox::slotLoadingDictionaryFailed); reloadCombo(); connect(this, SIGNAL(activated(int)), SLOT(slotDictionaryChanged(int))); @@ -140,6 +146,17 @@ } } +void DictionaryComboBox::slotLoadingDictionaryFailed(const QString &lang) +{ + if (!d->dictionaryErrorShown) { + QMessageBox::warning(nullptr, + tr("Spell Checker"), + tr("No dictionaries for language: \"%1\" could be loaded.\n" + "Please check the spell checker configuration.\n").arg(lang)); + d->dictionaryErrorShown = true; + } +} + } // namespace Sonnet #include "moc_dictionarycombobox.cpp"