Display an error message if loading a dictionary fails
Needs ReviewPublic

Authored by ahmadsamir on Jan 17 2019, 1:06 PM.

Details

Reviewers
sandsmark
loh.tar
Summary

Make Loader emit a signal when loading a dictionary fails; this way
Ui parts can receive that signal and display an appropriate message box.
At the moment DictionaryCombobox, listens to that signal, (the combobox
is used in configWidget, which is embedded in configuration dialogs of
apps using Sonnet, e.g. Kate (both in the config dialog and in the
spellcheck bar), Calligrawords).

BUG: 325541
FIXED-IN: 5.55.0

Test Plan
  • Edit ~/.config/KDE/Sonnet.conf (or wherever your distro puts the conf file under the home dir), and set defaultLanguage= to something invalid/unavailable, say en_AB
  • Start e.g. kate and open the settings dialog or spell check a document (via the Tools -> Spelling -> spelling menu), an error message about the unavailable dictionary should be displayed.

Diff Detail

Repository
R246 Sonnet
Branch
invalid-defaultLanguage (branched from master)
Lint
No Linters Available
Unit
No Unit Test Coverage
Build Status
Buildable 7654
Build 7672: arc lint + arc unit
ahmadsamir created this revision.Jan 17 2019, 1:06 PM
Restricted Application added a project: Frameworks. · View Herald TranscriptJan 17 2019, 1:06 PM
ahmadsamir requested review of this revision.Jan 17 2019, 1:06 PM
pino added a subscriber: pino.Jan 17 2019, 10:22 PM

This makes a "core" library grow a dependency on widgets -- not really a good idea, considering there is the sonnetui library for that.

pino added a comment.Jan 17 2019, 10:30 PM
In D18317#395513, @pino wrote:

This makes a "core" library grow a dependency on widgets -- not really a good idea, considering there is the sonnetui library for that.

In addition to the above, there are also really bad consquences: take a console-only application running QCoreApplication as application class and using sonnetcore. Now, in case of the situation described, sonnetcore will try spawn a QMessageBox, which IIRC exits the application, as no GUI is available.

In D18317#395530, @pino wrote:
In D18317#395513, @pino wrote:

This makes a "core" library grow a dependency on widgets -- not really a good idea, considering there is the sonnetui library for that.

In addition to the above, there are also really bad consquences: take a console-only application running QCoreApplication as application class and using sonnetcore. Now, in case of the situation described, sonnetcore will try spawn a QMessageBox, which IIRC exits the application, as no GUI is available.

OK. I didn't know the core/ui differentiation, I'll adjust the patch and see if I can come up with a better solution without having core lib depend on widgets.

Thanks for the pointers.

Just my thoughts:

  • I think there shouldn't be the (default) dictionary changed by some smart logic. Just hint the user that the setting is not applicable.
  • To set the dict to the system locale seems to me the less smartest trick. If everybody want such "auto-fix" should then the bad setting investigated and tried to find some similar setting, e.g. Bad "de_AT_ost" -> "de_AT" -> "de_DE". Why? Someone may have a locale of "de_DE" but a dict setting "en_US" for whatever reason. Besides I guess Loader::createSpeller is not only called when the default dict will loaded. IIRC has Sonnet some functionallity to guess a language and choose a fitting dict (May that help?)
  • The Config-GUI should show some hint in case of trouble, src/ui/configui.ui
  • Don't overwrite permanently some bad setting with a new value. Perhaps has the user just set up a new system and only missed to install some package
  • Perhaps should the error message saved in a QString(List), retrievable later so it can be shown e.g by KTextEditor::Message
  • Perhaps should Loader::createSpeller return some "Error-Helper-Dictionary" instead of a nullptr, so that Sonnet::defaultLanguage may give something like "ERROR-de_AT_ost" instead of e.g "de_AT_ost".
  • Accordingly should Sonnet::preferredDictionaries filled with data like "ERROR-de_AT_ost"/"ERROR-Deutsch (Östereich something)"
  • See also Sonnet::DictionaryComboBox. There should then the error hints are be visible
  • Take a look at D18125, why I think that may helpful. In the new button should then the hint possible to be shown "ERROR-foo".

Not investigated if all of these is needed or possible.

PS: Typo in SUMMARY "..of the the dictionary.." 2x the

@loh.tar: I'll think that over, thanks for the pointers :)

Just my thoughts:

  • I think there shouldn't be the (default) dictionary changed by some smart logic. Just hint the user that the setting is not applicable.

The user will open the sonnet config dialog and see that the dictionary he wants is already selected (e.g. the dictionary files have just been renamed, but it's the same dictionary); that is confusing, as can be gleaned from the linked bug report.

  • To set the dict to the system locale seems to me the less smartest trick. If everybody want such "auto-fix" should then the bad setting investigated and tried to find some similar setting, e.g. Bad "de_AT_ost" -> "de_AT" -> "de_DE". Why? Someone may have a locale of "de_DE" but a dict setting "en_US" for whatever reason. Besides I guess Loader::createSpeller is not only called when the default dict will loaded. IIRC has Sonnet some functionallity to guess a language and choose a fitting dict (May that help?)

It's what sonnet settings default to initially:
https://cgit.kde.org/sonnet.git/tree/src/core/settings.cpp#n291:

d->defaultLanguage = settings.value(QStringLiteral("defaultLanguage"),
                                        QLocale::system().name()).toString();

Language auto detection seems to cause some havoc: https://bugs.kde.org/show_bug.cgi?id=386611

  • The Config-GUI should show some hint in case of trouble, src/ui/configui.ui

[..]

  • Don't overwrite permanently some bad setting with a new value. Perhaps has the user just set up a new system and only missed to install some package

Same problem as above, the user opens the config dialog and the dictionary he wants is already selected....

[...]

Well, I'm not a Sonnet Guru, more a normal user. Sorry if it sounds so. I can't give a detailed point how to solve some particular issue.

My comment is more about what I would expect or what I would try to achieve.

I didn't investigate from where is Loader::createSpeller called and what happens after a nullptr is returned. Perhaps can there add some error handling to hint the user.

Well, I'm not a Sonnet Guru, more a normal user.

Me too; your views are appreciated all the same.

ahmadsamir updated this revision to Diff 50486.Jan 29 2019, 4:18 PM
ahmadsamir retitled this revision from Don't fail if defaultLanguage dictionary can't be loaded to Display an error message if loading a dictionary fails.
ahmadsamir edited the summary of this revision. (Show Details)
ahmadsamir edited the test plan for this revision. (Show Details)
ahmadsamir removed a reviewer: loh.tar.
ahmadsamir removed a subscriber: pino.

Rework the patch:

  • so as not to change the config file without the user's intervention
  • core libs shouldn't depend on Gui bits
ahmadsamir added a subscriber: pino.
loh.tar added a comment.EditedJan 30 2019, 3:20 PM

My observations:

  • There is no hint when you activate auto spell check (yes, it's out of this scope)
  • Before showing the combobox by "Change Dictionary" the popup appears
  • The combobox shows then some other setting, here it was the first entry
  • When open the config dialog the new popup block the processing. So the expected dialog is only shown after user action

My suggestion:

  • For me are extra popups annoying. I would suggest to avoid them
  • Add some hint embedded to the Sonnet config dialog. IIRC I have seen in some config dialog a similar hint like these KTextEditor::Message, but I may wrong
  • Perhaps should the combobox shown an empty entry or an error hint instead of some (not expected) value
  • How about to emit the full message, not only the missed language? This way is no need to formulate everywhere an own error text

Todo:

  • A patch to KTextEditor to show the hint as KTextEditor::Message when some spell check is requested

Addendum:
Even when the dict is changed (and working) by the combobox there still appears the error hint (?)

No language dictionaries for the language: "en_AB"

I've split the changes to the Loader in https://phabricator.kde.org/D18907.

And will hopefully try to handle the Ui part in this current diff.