]> git.lyx.org Git - features.git/commitdiff
* Spellchecker dialog:
authorJürgen Spitzmüller <spitz@lyx.org>
Wed, 10 Feb 2010 08:10:31 +0000 (08:10 +0000)
committerJürgen Spitzmüller <spitz@lyx.org>
Wed, 10 Feb 2010 08:10:31 +0000 (08:10 +0000)
- mark languages that can be spell checked.
* Thesaurus dialog:
- mark languages that have a thesaurus dictionary.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@33405 a592a061-630c-0410-9148-cb99ea01b6c8

13 files changed:
src/AspellChecker.cpp
src/AspellChecker.h
src/EnchantChecker.cpp
src/EnchantChecker.h
src/HunspellChecker.cpp
src/HunspellChecker.h
src/SpellChecker.h
src/Thesaurus.cpp
src/Thesaurus.h
src/frontends/qt4/GuiApplication.cpp
src/frontends/qt4/GuiDocument.cpp
src/frontends/qt4/GuiSpellchecker.cpp
src/frontends/qt4/GuiThesaurus.cpp

index f9fff666c4c97f9b590b47130e2c5e4a9040d971..a0560bf3c2d28dbea04d897762276211886bbed1 100644 (file)
@@ -223,6 +223,42 @@ void AspellChecker::suggest(WordLangTuple const & wl,
 }
 
 
+bool AspellChecker::hasDictionary(Language const * lang) const
+{
+       if (!lang)
+               return false;
+       // code taken from aspell's list-dicts example
+       AspellConfig * config;
+       AspellDictInfoList * dlist;
+       AspellDictInfoEnumeration * dels;
+       const AspellDictInfo * entry;
+
+       config = new_aspell_config();
+
+       /* the returned pointer should _not_ need to be deleted */
+       dlist = get_aspell_dict_info_list(config);
+
+       /* config is no longer needed */
+       delete_aspell_config(config);
+
+       dels = aspell_dict_info_list_elements(dlist);
+
+       bool have = false;
+       while ((entry = aspell_dict_info_enumeration_next(dels)) != 0)
+       {
+               if (entry->code == lang->code()
+                   && (lang->variety().empty() || entry->jargon == lang->variety())) {
+                       have = true;
+                       break;
+               }
+       }
+
+       delete_aspell_dict_info_enumeration(dels);
+
+       return have;
+}
+
+
 docstring const AspellChecker::error()
 {
        char const * err = 0;
index 52641dd39d6e381f21042e4cf5117b8f6cf3f4d4..73a685a4572733b55b115125fafa40d2657a38a6 100644 (file)
@@ -29,6 +29,7 @@ public:
        void suggest(WordLangTuple const &, docstring_list &);
        void insert(WordLangTuple const &);
        void accept(WordLangTuple const &);
+       bool hasDictionary(Language const * lang) const;
        docstring const error();
        //@}
 
index 61becbcec86ef3b8e26378f2df493d75d72fa256..e67f525c3ee643a574371e431b4519b6334aca97 100644 (file)
@@ -159,6 +159,15 @@ void EnchantChecker::suggest(WordLangTuple const & wl,
 }
 
 
+bool EnchantChecker::hasDictionary(Language const * lang) const
+{
+       if (!lang)
+               return false;
+       enchant::Broker * instance = enchant::Broker::instance();
+       return (instance->dict_exists(lang->code()));
+}
+
+
 docstring const EnchantChecker::error()
 {
        return docstring();
index e0954bc9e25b83ee1ece60a1d4716c222a8d8e64..94f7e20b38fb82797b5639f1a17d29dfd2df2c0c 100644 (file)
@@ -35,6 +35,7 @@ public:
        void suggest(WordLangTuple const &, docstring_list &);
        void insert(WordLangTuple const &);
        void accept(WordLangTuple const &);
+       bool hasDictionary(Language const * lang) const;
        docstring const error();
        ///@}
 
index 31d0787d58df945169623ce83f9fb3d7576a4ec3..5d42421c2c6dc8bbb8c032195e3a6e38919fd70c 100644 (file)
@@ -51,6 +51,7 @@ struct HunspellChecker::Private
 
        ~Private();
 
+       bool haveDictionary(string const & lang) const;
        Hunspell * addSpeller(string const & lang);
        Hunspell * speller(string const & lang);
        /// ignored words
@@ -94,7 +95,7 @@ bool haveLanguageFiles(string const & hpath)
 }
 
 
-Hunspell * HunspellChecker::Private::addSpeller(string const & lang)
+bool HunspellChecker::Private::haveDictionary(string const & lang) const
 {
        string hunspell_path = lyxrc.hunspelldir_path;
        LYXERR(Debug::FILES, "hunspell path: " << external_path(hunspell_path));
@@ -111,7 +112,7 @@ Hunspell * HunspellChecker::Private::addSpeller(string const & lang)
                        //frontend::Alert::error(_("Hunspell Path Not Found"), 
                        //              _("You must set the Hunspell dictionary path in Tools>Preferences>Paths."));
                }
-               return 0;
+               return false;
        }
 
        hunspell_path = external_path(addName(hunspell_path, lang));
@@ -122,9 +123,20 @@ Hunspell * HunspellChecker::Private::addSpeller(string const & lang)
                        // FIXME: We should indicate somehow that this language is not
                        // supported, probably by popping a warning. But we'll need to
                        // remember which warnings we've issued.
-                       return 0;
+                       return false;
                }
        }
+       return true;
+}
+
+
+Hunspell * HunspellChecker::Private::addSpeller(string const & lang)
+{
+       string hunspell_path = lyxrc.hunspelldir_path;
+
+       if (!haveDictionary(lang))
+               return 0;
+
        FileName const affix(hunspell_path + ".aff");
        FileName const dict(hunspell_path + ".dic");
        Hunspell * h = new Hunspell(affix.absFilename().c_str(), dict.absFilename().c_str());
@@ -227,6 +239,14 @@ void HunspellChecker::suggest(WordLangTuple const & wl,
 }
 
 
+bool HunspellChecker::hasDictionary(Language const * lang) const
+{
+       if (!lang)
+               return false;
+       return (d->haveDictionary(lang->code()));
+}
+
+
 docstring const HunspellChecker::error()
 {
        return docstring();
index 6e0ef024a7a12ccd813433a768481a360fa3a3aa..ccb5257be5bea4b1d6dee943b09d320683f2c15b 100644 (file)
@@ -29,6 +29,7 @@ public:
        void suggest(WordLangTuple const &, docstring_list &);
        void insert(WordLangTuple const &);
        void accept(WordLangTuple const &);
+       bool hasDictionary(Language const * lang) const;
        docstring const error();
        ///@}
 
index 6d8c77df00f6c174e6bd5fea2621a792f31fe6a5..bac19d116104f39b12af4fc3c0dc5553ed4d415c 100644 (file)
@@ -19,6 +19,7 @@
 namespace lyx {
 
 class BufferParams;
+class Language;
 class WordLangTuple;
 class docstring_list;
 
@@ -56,6 +57,9 @@ public:
        /// accept the given word temporarily
        virtual void accept(WordLangTuple const &) = 0;
 
+       /// check if dictionary exists
+       virtual bool hasDictionary(Language const *) const = 0;
+
        /// give an error message on messy exit
        virtual docstring const error() = 0;
 };
index a80ef87ad7c09bae4d9b829278cc38a255f66699..f3814baaf7adc4bf246f4ca3c52ea715589063c9 100644 (file)
@@ -79,6 +79,10 @@ struct Thesaurus::Private
                return false;
        }
 
+       ///
+       typedef std::pair<std::string, std::string> ThesFiles;
+       ///
+       ThesFiles getThesaurus(docstring const & lang);
        /// add a thesaurus to the list
        bool addThesaurus(docstring const & lang);
 
@@ -86,15 +90,16 @@ struct Thesaurus::Private
        Thesauri thes_;
 };
 
-bool Thesaurus::Private::addThesaurus(docstring const & lang)
+
+pair<string, string> Thesaurus::Private::getThesaurus(docstring const & lang)
 {
        string const thes_path = external_path(lyxrc.thesaurusdir_path);
        LYXERR(Debug::FILES, "thesaurus path: " << thes_path);
        if (thes_path.empty())
-               return false;
+               return make_pair(string(), string());
 
        if (thesaurusAvailable(lang))
-               return true;
+               return make_pair(string(), string());
 
        FileNameList const idx_files = FileName(thes_path).dirList("idx");
        FileNameList const data_files = FileName(thes_path).dirList("dat");
@@ -121,6 +126,16 @@ bool Thesaurus::Private::addThesaurus(docstring const & lang)
                        }
                }
 
+       return make_pair(idx, data);
+}
+
+
+bool Thesaurus::Private::addThesaurus(docstring const & lang)
+{
+       ThesFiles files = getThesaurus(lang);
+       string const idx = files.first;
+       string const data = files.second;
+
        if (idx.empty() || data.empty())
                return false;
 
@@ -137,6 +152,13 @@ bool Thesaurus::thesaurusAvailable(docstring const & lang) const
 }
 
 
+bool Thesaurus::thesaurusInstalled(docstring const & lang) const
+{
+       pair<string, string> files = d->getThesaurus(lang);
+       return (!files.first.empty() && !files.second.empty());
+}
+
+
 Thesaurus::Meanings Thesaurus::lookup(docstring const & t, docstring const & lang)
 {
        Meanings meanings;
index 65cd0de6553c4e846a1169cbfa074f6ab5017dfb..9c0bdc61de99e0855ab3a073e44ca0766dded1e9 100644 (file)
@@ -39,8 +39,12 @@ public:
         * look up some text in the thesaurus
         */
        Meanings lookup(docstring const & text, docstring const & lang);
-       /// check if a thesaurus for a given language \p lang is available
+       /** check if a thesaurus for a given language \p lang is available
+        *  (installed and loaded)
+        */
        bool thesaurusAvailable(docstring const & lang) const;
+       /// check if a thesaurus for a given language \p lang is installed
+       bool thesaurusInstalled(docstring const & lang) const;
 
 private:
        struct Private;
index bdb427b646edce9d6122f8bc9eee88e024e4ad5e..8a794da3d395c717ce68f0f879334915dd512e76 100644 (file)
@@ -50,6 +50,7 @@
 #include "Server.h"
 #include "Session.h"
 #include "SpellChecker.h"
+#include "Thesaurus.h"
 #include "version.h"
 
 #include "support/convert.h"
@@ -1973,16 +1974,28 @@ QAbstractItemModel * GuiApplication::languageModel()
                return d->language_model_;
 
        QStandardItemModel * lang_model = new QStandardItemModel(this);
-       lang_model->insertColumns(0, 1);
+       lang_model->insertColumns(0, 3);
        int current_row;
+       QIcon speller(getPixmap("images/", "dialog-show_spellchecker", "png"));
+       QIcon saurus(getPixmap("images/", "thesaurus-entry", "png"));
        Languages::const_iterator it = lyx::languages.begin();
        Languages::const_iterator end = lyx::languages.end();
        for (; it != end; ++it) {
                current_row = lang_model->rowCount();
                lang_model->insertRows(current_row, 1);
-               QModelIndex item = lang_model->index(current_row, 0);
-               lang_model->setData(item, qt_(it->second.display()), Qt::DisplayRole);
-               lang_model->setData(item, toqstr(it->second.lang()), Qt::UserRole);
+               QModelIndex pl_item = lang_model->index(current_row, 0);
+               QModelIndex sp_item = lang_model->index(current_row, 1);
+               QModelIndex th_item = lang_model->index(current_row, 2);
+               lang_model->setData(pl_item, qt_(it->second.display()), Qt::DisplayRole);
+               lang_model->setData(pl_item, toqstr(it->second.lang()), Qt::UserRole);
+               lang_model->setData(sp_item, qt_(it->second.display()), Qt::DisplayRole);
+               lang_model->setData(sp_item, toqstr(it->second.lang()), Qt::UserRole);
+               if (theSpellChecker()->hasDictionary(&it->second))
+                       lang_model->setData(sp_item, speller, Qt::DecorationRole);
+               lang_model->setData(th_item, qt_(it->second.display()), Qt::DisplayRole);
+               lang_model->setData(th_item, toqstr(it->second.lang()), Qt::UserRole);
+               if (thesaurus.thesaurusInstalled(from_ascii(it->second.code())))
+                       lang_model->setData(th_item, saurus, Qt::DecorationRole);
        }
        d->language_model_ = new QSortFilterProxyModel(this);
        d->language_model_->setSourceModel(lang_model);
index f0460dd279b8f8ed4cdbad147406466eb691bd2a..318c1a297b97b41db12994f0b0ca7e7b5cf88ee5 100644 (file)
@@ -852,6 +852,7 @@ GuiDocument::GuiDocument(GuiView & lv)
        // FIXME: it would be nice if sorting was enabled/disabled via a checkbox.
        language_model->sort(0);
        langModule->languageCO->setModel(language_model);
+       langModule->languageCO->setModelColumn(0);
 
        // Always put the default encoding in the first position.
        langModule->encodingCO->addItem(qt_("Language Default (no inputenc)"));
index f4350981f0b63f81e54ed4772e548860a017185d..29254216d72b12db305a5b0380231356c264d64c 100644 (file)
@@ -83,6 +83,7 @@ GuiSpellchecker::GuiSpellchecker(GuiView & lv)
        // FIXME: it would be nice if sorting was enabled/disabled via a checkbox.
        language_model->sort(0);
        d->ui.languageCO->setModel(language_model);
+       d->ui.languageCO->setModelColumn(1);
 
        d->ui.wordED->setReadOnly(true);
 
index 6d6269e6f5e34093c865b47d6f87086e9a81cb11..e92946b8c330bb547a367f914025e84557a6ca78 100644 (file)
@@ -77,6 +77,7 @@ GuiThesaurus::GuiThesaurus(GuiView & lv)
        // FIXME: it would be nice if sorting was enabled/disabled via a checkbox.
        language_model->sort(0);
        languageCO->setModel(language_model);
+       languageCO->setModelColumn(2);
 
        bc().setCancel(closePB);
        bc().setApply(replacePB);