}
+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;
void suggest(WordLangTuple const &, docstring_list &);
void insert(WordLangTuple const &);
void accept(WordLangTuple const &);
+ bool hasDictionary(Language const * lang) const;
docstring const error();
//@}
}
+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();
void suggest(WordLangTuple const &, docstring_list &);
void insert(WordLangTuple const &);
void accept(WordLangTuple const &);
+ bool hasDictionary(Language const * lang) const;
docstring const error();
///@}
~Private();
+ bool haveDictionary(string const & lang) const;
Hunspell * addSpeller(string const & lang);
Hunspell * speller(string const & lang);
/// ignored words
}
-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));
//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));
// 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());
}
+bool HunspellChecker::hasDictionary(Language const * lang) const
+{
+ if (!lang)
+ return false;
+ return (d->haveDictionary(lang->code()));
+}
+
+
docstring const HunspellChecker::error()
{
return docstring();
void suggest(WordLangTuple const &, docstring_list &);
void insert(WordLangTuple const &);
void accept(WordLangTuple const &);
+ bool hasDictionary(Language const * lang) const;
docstring const error();
///@}
namespace lyx {
class BufferParams;
+class Language;
class WordLangTuple;
class docstring_list;
/// 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;
};
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);
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");
}
}
+ 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;
}
+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;
* 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;
#include "Server.h"
#include "Session.h"
#include "SpellChecker.h"
+#include "Thesaurus.h"
#include "version.h"
#include "support/convert.h"
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);
// 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)"));
// 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);
// 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);