summaryrefslogtreecommitdiffstats
path: root/tdespell2/plugins/aspell
diff options
context:
space:
mode:
Diffstat (limited to 'tdespell2/plugins/aspell')
-rw-r--r--tdespell2/plugins/aspell/CMakeLists.txt44
-rw-r--r--tdespell2/plugins/aspell/Makefile.am17
-rw-r--r--tdespell2/plugins/aspell/tdespell_aspell.desktop21
-rw-r--r--tdespell2/plugins/aspell/tdespell_aspellclient.cpp66
-rw-r--r--tdespell2/plugins/aspell/tdespell_aspellclient.h57
-rw-r--r--tdespell2/plugins/aspell/tdespell_aspelldict.cpp125
-rw-r--r--tdespell2/plugins/aspell/tdespell_aspelldict.h50
7 files changed, 380 insertions, 0 deletions
diff --git a/tdespell2/plugins/aspell/CMakeLists.txt b/tdespell2/plugins/aspell/CMakeLists.txt
new file mode 100644
index 000000000..9ae66d01b
--- /dev/null
+++ b/tdespell2/plugins/aspell/CMakeLists.txt
@@ -0,0 +1,44 @@
+#################################################
+#
+# (C) 2010 Serghei Amelian
+# serghei (DOT) amelian (AT) gmail.com
+#
+# Improvements and feedback are welcome
+#
+# This file is released under GPL >= 2
+#
+#################################################
+
+include_directories(
+ ${TQT_INCLUDE_DIRS}
+ ${CMAKE_CURRENT_BINARY_DIR}
+ ${CMAKE_BINARY_DIR}/tdecore
+ ${CMAKE_SOURCE_DIR}/tdespell2
+ ${CMAKE_SOURCE_DIR}/tdecore
+ ${ASPELL_INCLUDE_DIRS}
+)
+
+link_directories(
+ ${TQT_LIBRARY_DIRS}
+ ${ASPELL_LIBRARY_DIRS}
+)
+
+
+##### other data ################################
+
+install( FILES tdespell_aspell.desktop DESTINATION ${SERVICES_INSTALL_DIR} )
+
+
+#### tdespell_aspell ##############################
+
+set( target tdespell_aspell )
+
+set( ${target}_SRCS
+ tdespell_aspellclient.cpp tdespell_aspelldict.cpp
+)
+
+tde_add_kpart( ${target} SHARED AUTOMOC
+ SOURCES ${${target}_SRCS}
+ LINK tdespell2-shared ${ASPELL_LIBRARIES}
+ DESTINATION ${PLUGIN_INSTALL_DIR}
+)
diff --git a/tdespell2/plugins/aspell/Makefile.am b/tdespell2/plugins/aspell/Makefile.am
new file mode 100644
index 000000000..4d40583f1
--- /dev/null
+++ b/tdespell2/plugins/aspell/Makefile.am
@@ -0,0 +1,17 @@
+METASOURCES = AUTO
+
+AM_CPPFLAGS = -I$(top_srcdir)/tdespell2 -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 = tdespell_aspell.la
+
+tdespell_aspell_la_SOURCES = tdespell_aspellclient.cpp tdespell_aspelldict.cpp
+
+tdespell_aspell_la_LDFLAGS = -module -no-undefined $(KDE_PLUGIN)
+tdespell_aspell_la_LIBADD = ../../ui/libtdespell2.la -laspell $(LIB_QT) $(LIB_TDECORE)
+
+service_DATA = tdespell_aspell.desktop
+servicedir = $(kde_servicesdir)
diff --git a/tdespell2/plugins/aspell/tdespell_aspell.desktop b/tdespell2/plugins/aspell/tdespell_aspell.desktop
new file mode 100644
index 000000000..af78175f0
--- /dev/null
+++ b/tdespell2/plugins/aspell/tdespell_aspell.desktop
@@ -0,0 +1,21 @@
+[Desktop Entry]
+Type=Service
+ServiceTypes=KSpell/Client
+X-TDE-Library=tdespell_aspell
+X-TDE-PluginInfo-Author=Zack Rusin
+X-TDE-PluginInfo-Email=zack@kde.org
+X-TDE-PluginInfo-Name=tdespell_aspell
+X-TDE-PluginInfo-Version=0.0.1
+X-TDE-PluginInfo-Website=http://www.kde.org
+X-TDE-PluginInfo-Category=Clients
+X-TDE-PluginInfo-Depends=
+X-TDE-PluginInfo-License=LGPL
+X-TDE-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/tdespell2/plugins/aspell/tdespell_aspellclient.cpp b/tdespell2/plugins/aspell/tdespell_aspellclient.cpp
new file mode 100644
index 000000000..a9dcf4241
--- /dev/null
+++ b/tdespell2/plugins/aspell/tdespell_aspellclient.cpp
@@ -0,0 +1,66 @@
+/*
+ * tdespell_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 "tdespell_aspellclient.h"
+
+#include "tdespell_aspelldict.h"
+
+#include <kgenericfactory.h>
+#include <kdebug.h>
+
+typedef KGenericFactory<ASpellClient> ASpellClientFactory;
+K_EXPORT_COMPONENT_FACTORY( tdespell_aspell, ASpellClientFactory( "tdespell_aspell" ) )
+
+using namespace KSpell2;
+
+ASpellClient::ASpellClient( TQObject *parent, const char *name, const TQStringList& /* args */ )
+ : Client( parent, name )
+{
+ m_config = new_aspell_config();
+}
+
+ASpellClient::~ASpellClient()
+{
+ delete_aspell_config( m_config );
+}
+
+Dictionary* ASpellClient::dictionary( const TQString& language )
+{
+ ASpellDict *ad = new ASpellDict( language );
+ return ad;
+}
+
+TQStringList ASpellClient::languages() const
+{
+ AspellDictInfoList *l = get_aspell_dict_info_list( m_config );
+ AspellDictInfoEnumeration *el = aspell_dict_info_list_elements( l );
+
+ TQStringList 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 "tdespell_aspellclient.moc"
diff --git a/tdespell2/plugins/aspell/tdespell_aspellclient.h b/tdespell2/plugins/aspell/tdespell_aspellclient.h
new file mode 100644
index 000000000..6da78f000
--- /dev/null
+++ b/tdespell2/plugins/aspell/tdespell_aspellclient.h
@@ -0,0 +1,57 @@
+/*
+ * tdespell_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 <tqobject.h>
+
+#include "aspell.h"
+
+namespace KSpell2 {
+ class Dictionary;
+}
+using KSpell2::Dictionary;
+
+class ASpellClient : public KSpell2::Client
+{
+ Q_OBJECT
+public:
+ ASpellClient( TQObject *parent, const char *name, const TQStringList & /* args */ );
+ ~ASpellClient();
+
+ virtual int reliability() const {
+ return 20;
+ }
+
+ virtual Dictionary* dictionary( const TQString& language );
+
+ virtual TQStringList languages() const;
+
+ virtual TQString name() const {
+ return "ASpell";
+ }
+private:
+ AspellConfig *m_config;
+
+};
+
+#endif
diff --git a/tdespell2/plugins/aspell/tdespell_aspelldict.cpp b/tdespell2/plugins/aspell/tdespell_aspelldict.cpp
new file mode 100644
index 000000000..c88508c6f
--- /dev/null
+++ b/tdespell2/plugins/aspell/tdespell_aspelldict.cpp
@@ -0,0 +1,125 @@
+/**
+ * tdespell_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 "tdespell_aspelldict.h"
+
+#include <kdebug.h>
+
+#include <tqtextcodec.h>
+
+using namespace KSpell2;
+
+ASpellDict::ASpellDict( const TQString& 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 TQString& 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;
+}
+
+TQStringList ASpellDict::suggest( const TQString& word )
+{
+ /* Needed for Unicode conversion */
+ TQTextCodec *codec = TQTextCodec::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 );
+
+ TQStringList 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 TQString& word,
+ TQStringList& suggestions )
+{
+ bool c = check( word );
+ if ( c )
+ suggestions = suggest( word );
+ return c;
+}
+
+bool ASpellDict::storeReplacement( const TQString& bad,
+ const TQString& 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 TQString& 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 TQString& 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/tdespell2/plugins/aspell/tdespell_aspelldict.h b/tdespell2/plugins/aspell/tdespell_aspelldict.h
new file mode 100644
index 000000000..6b6174a1c
--- /dev/null
+++ b/tdespell2/plugins/aspell/tdespell_aspelldict.h
@@ -0,0 +1,50 @@
+/**
+ * tdespell_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 TQString& lang );
+ ~ASpellDict();
+ virtual bool check( const TQString& word );
+
+ virtual TQStringList suggest( const TQString& word );
+
+ virtual bool checkAndSuggest( const TQString& word,
+ TQStringList& suggestions ) ;
+
+ virtual bool storeReplacement( const TQString& bad,
+ const TQString& good );
+
+ virtual bool addToPersonal( const TQString& word );
+ virtual bool addToSession( const TQString& word );
+private:
+ AspellConfig *m_config;
+ AspellSpeller *m_speller;
+};
+
+#endif