diff options
Diffstat (limited to 'kspell2/plugins/hspell')
-rw-r--r-- | kspell2/plugins/hspell/Makefile.am | 17 | ||||
-rw-r--r-- | kspell2/plugins/hspell/kspell_hspell.desktop | 18 | ||||
-rw-r--r-- | kspell2/plugins/hspell/kspell_hspellclient.cpp | 57 | ||||
-rw-r--r-- | kspell2/plugins/hspell/kspell_hspellclient.h | 60 | ||||
-rw-r--r-- | kspell2/plugins/hspell/kspell_hspelldict.cpp | 107 | ||||
-rw-r--r-- | kspell2/plugins/hspell/kspell_hspelldict.h | 53 |
6 files changed, 312 insertions, 0 deletions
diff --git a/kspell2/plugins/hspell/Makefile.am b/kspell2/plugins/hspell/Makefile.am new file mode 100644 index 000000000..8f9b4e982 --- /dev/null +++ b/kspell2/plugins/hspell/Makefile.am @@ -0,0 +1,17 @@ +METASOURCES = AUTO + +AM_CPPFLAGS = -I$(top_srcdir)/kspell2 -I$(top_srcdir) $(all_includes) + +# For the future: examine if condensing the tons of *_LDFLAGS variables +# into $(all_libraries) isn't better +AM_LDFLAGS = $(LDFLAGS_AS_NEEDED) $(LDFLAGS_NEW_DTAGS) + +kde_module_LTLIBRARIES = kspell_hspell.la + +kspell_hspell_la_SOURCES = kspell_hspellclient.cpp kspell_hspelldict.cpp + +kspell_hspell_la_LDFLAGS = -module -no-undefined $(KDE_PLUGIN) +kspell_hspell_la_LIBADD = ../../ui/libkspell2.la -lhspell -lz + +service_DATA = kspell_hspell.desktop +servicedir = $(kde_servicesdir) diff --git a/kspell2/plugins/hspell/kspell_hspell.desktop b/kspell2/plugins/hspell/kspell_hspell.desktop new file mode 100644 index 000000000..f07cd0096 --- /dev/null +++ b/kspell2/plugins/hspell/kspell_hspell.desktop @@ -0,0 +1,18 @@ +[Desktop Entry] +Type=Service +ServiceTypes=KSpell/Client +X-KDE-Library=kspell_hspell +X-KDE-PluginInfo-Author=Mashrab Kuvatov +X-KDE-PluginInfo-Name=kspell_hspell +X-KDE-PluginInfo-Version=0.0.1 +X-KDE-PluginInfo-Website=http://www.kde.org +X-KDE-PluginInfo-Category=Clients +X-KDE-PluginInfo-Depends= +X-KDE-PluginInfo-License=LGPL +X-KDE-PluginInfo-EnabledByDefault=true +Name=HSpell +Name[bn]=এইচ-স্পেল +Name[ne]=एच स्पेल +Name[sv]=Hspell +Name[te]=హెచ్ స్పెల్ diff --git a/kspell2/plugins/hspell/kspell_hspellclient.cpp b/kspell2/plugins/hspell/kspell_hspellclient.cpp new file mode 100644 index 000000000..ac0876153 --- /dev/null +++ b/kspell2/plugins/hspell/kspell_hspellclient.cpp @@ -0,0 +1,57 @@ +/** + * kspell_hspellclient.cpp + * + * Copyright (C) 2003 Zack Rusin <[email protected]> + * Copyright (C) 2005 Mashrab Kuvatov <[email protected]> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA + */ +#include "kspell_hspellclient.h" + +#include "kspell_hspelldict.h" + +#include <kgenericfactory.h> +#include <kdebug.h> + +typedef KGenericFactory<HSpellClient> HSpellClientFactory; +K_EXPORT_COMPONENT_FACTORY( kspell_hspell, HSpellClientFactory( "kspell_hspell" ) ) + +using namespace KSpell2; + +HSpellClient::HSpellClient( QObject *parent, const char *name, const QStringList& /* args */ ) + : Client( parent, name ) +{ +} + +HSpellClient::~HSpellClient() +{ +} + +Dictionary* HSpellClient::dictionary( const QString& language ) +{ + HSpellDict *ad = new HSpellDict( language ); + return ad; +} + +QStringList HSpellClient::languages() const +{ + QStringList langs; + langs.append( "he" ); + + return langs; +} + +#include "kspell_hspellclient.moc" diff --git a/kspell2/plugins/hspell/kspell_hspellclient.h b/kspell2/plugins/hspell/kspell_hspellclient.h new file mode 100644 index 000000000..6d7a1773b --- /dev/null +++ b/kspell2/plugins/hspell/kspell_hspellclient.h @@ -0,0 +1,60 @@ +/** + * kspell_hspellclient.h + * + * Copyright (C) 2003 Zack Rusin <[email protected]> + * Copyright (C) 2005 Mashrab Kuvatov <[email protected]> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA + */ +#ifndef KSPELL_HSPELLCLIENT_H +#define KSPELL_HSPELLCLIENT_H + +#include "client.h" +#include <qobject.h> + +/* libhspell is a C library and it does not have #ifdef __cplusplus */ +extern "C" { +#include "hspell.h" +} + +namespace KSpell2 { + class Dictionary; +} +using KSpell2::Dictionary; + +class HSpellClient : public KSpell2::Client +{ + Q_OBJECT +public: + HSpellClient( QObject *parent, const char *name, const QStringList & /* args */ ); + ~HSpellClient(); + + virtual int reliability() const { + return 20; + } + + virtual Dictionary* dictionary( const QString& language ); + + virtual QStringList languages() const; + + virtual QString name() const { + return "HSpell"; + } +private: + +}; + +#endif diff --git a/kspell2/plugins/hspell/kspell_hspelldict.cpp b/kspell2/plugins/hspell/kspell_hspelldict.cpp new file mode 100644 index 000000000..e8944dbf7 --- /dev/null +++ b/kspell2/plugins/hspell/kspell_hspelldict.cpp @@ -0,0 +1,107 @@ +/** + * kspell_hspelldict.cpp + * + * Copyright (C) 2003 Zack Rusin <[email protected]> + * Copyright (C) 2005 Mashrab Kuvatov <[email protected]> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA + */ + +#include "kspell_hspelldict.h" +#include <kdebug.h> + +#include <qtextcodec.h> + +using namespace KSpell2; + +HSpellDict::HSpellDict( const QString& lang ) + : Dictionary( lang ) +{ + int int_error = hspell_init( &m_speller, HSPELL_OPT_DEFAULT ); + if ( int_error == -1 ) + kdDebug() << "HSpellDict::HSpellDict: Init failed" << endl; + /* hspell understans only iso8859-8-i */ + codec = QTextCodec::codecForName( "iso8859-8-i" ); +} + +HSpellDict::~HSpellDict() +{ + /* It exists in =< hspell-0.8 */ + hspell_uninit( m_speller ); +} + +bool HSpellDict::check( const QString& word ) +{ + kdDebug() << "HSpellDict::check word = " << word <<endl; + int preflen; + QCString wordISO = codec->fromUnicode( word ); + /* returns 1 if the word is correct, 0 otherwise */ + int correct = hspell_check_word ( m_speller, + wordISO, + &preflen); //this going to be removed + //in next hspell releases + /* I do not really understand what gimatria is */ + if( correct != 1 ){ + if( hspell_is_canonic_gimatria( wordISO ) != 0 ) + correct = 1; + } + return correct == 1; +} + +QStringList HSpellDict::suggest( const QString& word ) +{ + QStringList qsug; + struct corlist cl; + int n_sugg; + corlist_init( &cl ); + hspell_trycorrect( m_speller, codec->fromUnicode( word ), &cl ); + for( n_sugg = 0; n_sugg < corlist_n( &cl ); n_sugg++){ + qsug.append( codec->toUnicode( corlist_str( &cl, n_sugg) ) ); + } + corlist_free( &cl ); + return qsug; +} + +bool HSpellDict::checkAndSuggest( const QString& word, + QStringList& suggestions ) +{ + bool c = check( word ); + if( c ) + suggestions = suggest( word ); + return c; +} + +bool HSpellDict::storeReplacement( const QString& bad, + const QString& good ) +{ + // hspell-0.9 cannot do this + kdDebug() << "HSpellDict::storeReplacement: Sorry, cannot." << endl; + return false; +} + +bool HSpellDict::addToPersonal( const QString& word ) +{ + // hspell-0.9 cannot do this + kdDebug() << "HSpellDict::addToPersonal: Sorry, cannot." << endl; + return false; +} + +bool HSpellDict::addToSession( const QString& word ) +{ + // hspell-0.9 cannot do this + kdDebug() << "HSpellDict::addToSession: Sorry, cannot." << endl; + return false; +} diff --git a/kspell2/plugins/hspell/kspell_hspelldict.h b/kspell2/plugins/hspell/kspell_hspelldict.h new file mode 100644 index 000000000..a3895dc98 --- /dev/null +++ b/kspell2/plugins/hspell/kspell_hspelldict.h @@ -0,0 +1,53 @@ +/** + * kspell_hspelldict.h + * + * Copyright (C) 2003 Zack Rusin <[email protected]> + * Copyright (C) 2005 Mashrab Kuvatov <[email protected]> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA + */ +#ifndef KSPELL_HSPELLDICT_H +#define KSPELL_HSPELLDICT_H + +#include "dictionary.h" +/* libhspell is a C library and it does not have #ifdef __cplusplus */ +extern "C" { +#include "hspell.h" +} + +class HSpellDict : public KSpell2::Dictionary +{ +public: + HSpellDict( const QString& lang ); + ~HSpellDict(); + virtual bool check( const QString& word ); + + virtual QStringList suggest( const QString& word ); + + virtual bool checkAndSuggest( const QString& word, + QStringList& suggestions ) ; + + virtual bool storeReplacement( const QString& bad, + const QString& good ); + + virtual bool addToPersonal( const QString& word ); + virtual bool addToSession( const QString& word ); +private: + struct dict_radix *m_speller; + QTextCodec *codec; +}; + +#endif |