summaryrefslogtreecommitdiffstats
path: root/kspell2/plugins/aspell
diff options
context:
space:
mode:
Diffstat (limited to 'kspell2/plugins/aspell')
-rw-r--r--kspell2/plugins/aspell/Makefile.am17
-rw-r--r--kspell2/plugins/aspell/kspell_aspell.desktop21
-rw-r--r--kspell2/plugins/aspell/kspell_aspellclient.cpp66
-rw-r--r--kspell2/plugins/aspell/kspell_aspellclient.h57
-rw-r--r--kspell2/plugins/aspell/kspell_aspelldict.cpp125
-rw-r--r--kspell2/plugins/aspell/kspell_aspelldict.h50
6 files changed, 336 insertions, 0 deletions
diff --git a/kspell2/plugins/aspell/Makefile.am b/kspell2/plugins/aspell/Makefile.am
new file mode 100644
index 000000000..69f560ec1
--- /dev/null
+++ b/kspell2/plugins/aspell/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_aspell.la
+
+kspell_aspell_la_SOURCES = kspell_aspellclient.cpp kspell_aspelldict.cpp
+
+kspell_aspell_la_LDFLAGS = -module -no-undefined $(KDE_PLUGIN)
+kspell_aspell_la_LIBADD = ../../ui/libkspell2.la -laspell
+
+service_DATA = kspell_aspell.desktop
+servicedir = $(kde_servicesdir)
diff --git a/kspell2/plugins/aspell/kspell_aspell.desktop b/kspell2/plugins/aspell/kspell_aspell.desktop
new file mode 100644
index 000000000..89189eae1
--- /dev/null
+++ b/kspell2/plugins/aspell/kspell_aspell.desktop
@@ -0,0 +1,21 @@
+[Desktop Entry]
+Type=Service
+ServiceTypes=KSpell/Client
+X-KDE-Library=kspell_aspell
+X-KDE-PluginInfo-Author=Zack Rusin
+X-KDE-PluginInfo-Email=zack@kde.org
+X-KDE-PluginInfo-Name=kspell_aspell
+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=ASpell
+Name[bn]=এ-স্পেল
+Name[hi]=आ-स्पैल
+Name[it]=Aspell
+Name[ne]=ए स्पेल
+Name[sv]=Aspell
+Name[ta]=psதேர்ந்தெடு
+Name[te]=ఏస్పెల్
diff --git a/kspell2/plugins/aspell/kspell_aspellclient.cpp b/kspell2/plugins/aspell/kspell_aspellclient.cpp
new file mode 100644
index 000000000..94156c523
--- /dev/null
+++ b/kspell2/plugins/aspell/kspell_aspellclient.cpp
@@ -0,0 +1,66 @@
+/*
+ * kspell_aspellclient.cpp
+ *
+ * Copyright (C) 2003 Zack Rusin <zack@kde.org>
+ *
+ * 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_aspellclient.h"
+
+#include "kspell_aspelldict.h"
+
+#include <kgenericfactory.h>
+#include <kdebug.h>
+
+typedef KGenericFactory<ASpellClient> ASpellClientFactory;
+K_EXPORT_COMPONENT_FACTORY( kspell_aspell, ASpellClientFactory( "kspell_aspell" ) )
+
+using namespace KSpell2;
+
+ASpellClient::ASpellClient( QObject *parent, const char *name, const QStringList& /* args */ )
+ : Client( parent, name )
+{
+ m_config = new_aspell_config();
+}
+
+ASpellClient::~ASpellClient()
+{
+ delete_aspell_config( m_config );
+}
+
+Dictionary* ASpellClient::dictionary( const QString& language )
+{
+ ASpellDict *ad = new ASpellDict( language );
+ return ad;
+}
+
+QStringList ASpellClient::languages() const
+{
+ AspellDictInfoList *l = get_aspell_dict_info_list( m_config );
+ AspellDictInfoEnumeration *el = aspell_dict_info_list_elements( l );
+
+ QStringList langs;
+ const AspellDictInfo *di = 0;
+ while ( ( di = aspell_dict_info_enumeration_next( el ) ) ) {
+ langs.append( di->name );
+ }
+
+ delete_aspell_dict_info_enumeration( el );
+
+ return langs;
+}
+
+#include "kspell_aspellclient.moc"
diff --git a/kspell2/plugins/aspell/kspell_aspellclient.h b/kspell2/plugins/aspell/kspell_aspellclient.h
new file mode 100644
index 000000000..7073e80ec
--- /dev/null
+++ b/kspell2/plugins/aspell/kspell_aspellclient.h
@@ -0,0 +1,57 @@
+/*
+ * kspell_aspellclient.h
+ *
+ * Copyright (C) 2003 Zack Rusin <zack@kde.org>
+ *
+ * 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_ASPELLCLIENT_H
+#define KSPELL_ASPELLCLIENT_H
+
+#include "client.h"
+#include <qobject.h>
+
+#include "aspell.h"
+
+namespace KSpell2 {
+ class Dictionary;
+}
+using KSpell2::Dictionary;
+
+class ASpellClient : public KSpell2::Client
+{
+ Q_OBJECT
+public:
+ ASpellClient( QObject *parent, const char *name, const QStringList & /* args */ );
+ ~ASpellClient();
+
+ virtual int reliability() const {
+ return 20;
+ }
+
+ virtual Dictionary* dictionary( const QString& language );
+
+ virtual QStringList languages() const;
+
+ virtual QString name() const {
+ return "ASpell";
+ }
+private:
+ AspellConfig *m_config;
+
+};
+
+#endif
diff --git a/kspell2/plugins/aspell/kspell_aspelldict.cpp b/kspell2/plugins/aspell/kspell_aspelldict.cpp
new file mode 100644
index 000000000..4674c138a
--- /dev/null
+++ b/kspell2/plugins/aspell/kspell_aspelldict.cpp
@@ -0,0 +1,125 @@
+/**
+ * kspell_aspelldict.cpp
+ *
+ * Copyright (C) 2003 Zack Rusin <zack@kde.org>
+ *
+ * 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_aspelldict.h"
+
+#include <kdebug.h>
+
+#include <qtextcodec.h>
+
+using namespace KSpell2;
+
+ASpellDict::ASpellDict( const QString& lang )
+ : Dictionary( lang )
+{
+ m_config = new_aspell_config();
+ aspell_config_replace( m_config, "lang", lang.latin1() );
+ /* All communication with Aspell is done in UTF-8 */
+ /* For reference, please look at BR#87250 */
+ aspell_config_replace( m_config, "encoding", "utf-8" );
+
+ AspellCanHaveError * possible_err = new_aspell_speller( m_config );
+
+ if ( aspell_error_number( possible_err ) != 0 )
+ kdDebug()<< "Error : "<< aspell_error_message( possible_err ) <<endl;
+ else
+ m_speller = to_aspell_speller( possible_err );
+
+}
+
+ASpellDict::~ASpellDict()
+{
+ delete_aspell_speller( m_speller );
+ delete_aspell_config( m_config );
+}
+
+bool ASpellDict::check( const QString& word )
+{
+ /* ASpell is expecting length of a string in char representation */
+ /* word.length() != word.utf8().length() for nonlatin strings */
+ int correct = aspell_speller_check( m_speller, word.utf8(), word.utf8().length() );
+ return correct;
+}
+
+QStringList ASpellDict::suggest( const QString& word )
+{
+ /* Needed for Unicode conversion */
+ QTextCodec *codec = QTextCodec::codecForName("utf8");
+
+ /* ASpell is expecting length of a string in char representation */
+ /* word.length() != word.utf8().length() for nonlatin strings */
+ const AspellWordList * suggestions = aspell_speller_suggest( m_speller,
+ word.utf8(),
+ word.utf8().length() );
+
+ AspellStringEnumeration * elements = aspell_word_list_elements( suggestions );
+
+ QStringList qsug;
+ const char * cword;
+
+ while ( (cword = aspell_string_enumeration_next( elements )) ) {
+ /* Since while creating the class ASpellDict the encoding is set */
+ /* to utf-8, one has to convert output from Aspell to Unicode */
+ qsug.append( codec->toUnicode( cword ) );
+ }
+
+ delete_aspell_string_enumeration( elements );
+ return qsug;
+}
+
+bool ASpellDict::checkAndSuggest( const QString& word,
+ QStringList& suggestions )
+{
+ bool c = check( word );
+ if ( c )
+ suggestions = suggest( word );
+ return c;
+}
+
+bool ASpellDict::storeReplacement( const QString& bad,
+ const QString& good )
+{
+ /* ASpell is expecting length of a string in char representation */
+ /* word.length() != word.utf8().length() for nonlatin strings */
+ return aspell_speller_store_replacement( m_speller,
+ bad.utf8(), bad.utf8().length(),
+ good.utf8(), good.utf8().length() );
+}
+
+bool ASpellDict::addToPersonal( const QString& word )
+{
+ kdDebug() << "ASpellDict::addToPersonal: word = " << word << endl;
+ /* ASpell is expecting length of a string in char representation */
+ /* word.length() != word.utf8().length() for nonlatin strings */
+ aspell_speller_add_to_personal( m_speller, word.utf8(),
+ word.utf8().length() );
+ /* Add is not enough, one has to save it. This is not documented */
+ /* in ASpell's API manual. I found it in */
+ /* aspell-0.60.2/example/example-c.c */
+ return aspell_speller_save_all_word_lists( m_speller );
+}
+
+bool ASpellDict::addToSession( const QString& word )
+{
+ /* ASpell is expecting length of a string in char representation */
+ /* word.length() != word.utf8().length() for nonlatin strings */
+ return aspell_speller_add_to_session( m_speller, word.utf8(),
+ word.utf8().length() );
+}
diff --git a/kspell2/plugins/aspell/kspell_aspelldict.h b/kspell2/plugins/aspell/kspell_aspelldict.h
new file mode 100644
index 000000000..0a4f520d3
--- /dev/null
+++ b/kspell2/plugins/aspell/kspell_aspelldict.h
@@ -0,0 +1,50 @@
+/**
+ * kspell_aspelldict.h
+ *
+ * Copyright (C) 2003 Zack Rusin <zack@kde.org>
+ *
+ * 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_ASPELLDICT_H
+#define KSPELL_ASPELLDICT_H
+
+#include "dictionary.h"
+
+#include "aspell.h"
+
+class ASpellDict : public KSpell2::Dictionary
+{
+public:
+ ASpellDict( const QString& lang );
+ ~ASpellDict();
+ 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:
+ AspellConfig *m_config;
+ AspellSpeller *m_speller;
+};
+
+#endif