質問

I've been working on a Qt-based C++ program called RoboJournal. It uses Hunspell for spell-checking purposes. Right now, it automatically installs its own dictionary files (en_US.dic) into the user's home folder (i.e. ~/.robojournal/en_US.dic). This works fine as-is on OSes like Windows that provide no compatible dictionaries out of the box but there is a design problem I want to fix:

On Linux, there are several instances of en_US.dic (most notably in /usr/share/hunspell/en_US.dic) This copy is obviously meant to be shared between all programs that use Hunspell, which means that my program should use it if possible instead of relying on its own copy. However, the copy in /usr/share/hunspell/ requires superuser rights to modify; while this means that users may read from it they can't add words to it unless the program is running with superuser permissions or unless I chmod the file to allow everyone to write to it. This problem makes the /usr/share/hunspell/en_US.dic copy much less useful.

Is there a way for users to modify the /usr/share/hunspell/en_US.dic file without having superuser permissions or requiring them to chmod the file first? My Debian package maintainer said that my app should use global system resources whenever possible.

役に立ちましたか?

解決

In situations like this, usually you load the system defaults, and then you load the user specific settings file.

So when your program has been running and the user ignores some words, and adds others, etc. you save this to the user's dictionary in their application data directory.

If you really want your program to save additions to the system wide changes to the default dictionary, you should prompt the user, if they want to save dictionary changes to the system defaults, and then open a superuser login, or whatever credentials that you would need to save edits to that file, and then save it.

Or you could even have it where if the program was started initially as a superuser, then it saves it to the system folder, otherwise it saves it to the user's application directory.

The model that I follow for settings and what not, is explained in QSettings.

http://qt-project.org/doc/qt-4.8/qsettings.html#details

http://qt-project.org/doc/qt-4.8/qsettings.html#platform-specific-notes

QSettings handles everything rather elegantly if you set up your application name and organization name. It doesn't do hunspell dictionaries out of the box, but the locations/paths it uses are significant.

Hope that helps.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top