[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-core-devel
Subject:    [PATCH] Fix add to dictionary func in KSpell2
From:       Mashrab Kuvatov <kmashrab () sat ! physik ! uni-bremen ! de>
Date:       2005-04-16 18:01:16
Message-ID: 200504162001.20963.kmashrab () sat ! physik ! uni-bremen ! de
[Download RAW message or body]

[Attachment #2 (multipart/mixed)]


Hi all,

the attached patch implements "Add to Dictionary" function in KSpell2.
Would be great for comming KOffice release, if it gets fixed. AFAIK, KWord
is using it for spellchecking.

Cheers,
Mashrab.
PS. Please CC me, I'm not in the list.
-- 
Mashrab Kuvatov
Ph.D student
University of Bremen, IUP
Home-page: www.sat.uni-bremen.de/members/mashrab
PGP key: www.uni-bremen.de/~kmashrab/kmashrab.asc

["kspell2-add-to-dict.patch" (text/x-diff)]

Index: backgroundchecker.cpp
===================================================================
RCS file: /home/kde/kdelibs/kspell2/backgroundchecker.cpp,v
retrieving revision 1.2
diff -u -3 -p -r1.2 backgroundchecker.cpp
--- backgroundchecker.cpp	3 May 2004 19:03:00 -0000	1.2
+++ backgroundchecker.cpp	16 Apr 2005 17:04:22 -0000
@@ -113,6 +113,11 @@ bool BackgroundChecker::checkWord( const
     return d->engine->checkWord( word );
 }
 
+bool BackgroundChecker::addWord( const QString& word )
+{
+    return d->engine->addWord( word );
+}
+
 QStringList BackgroundChecker::suggest( const QString& word ) const
 {
     //return d->thread.suggest( word );
Index: backgroundchecker.h
===================================================================
RCS file: /home/kde/kdelibs/kspell2/backgroundchecker.h,v
retrieving revision 1.2
diff -u -3 -p -r1.2 backgroundchecker.h
--- backgroundchecker.h	1 Dec 2004 12:02:33 -0000	1.2
+++ backgroundchecker.h	16 Apr 2005 17:04:22 -0000
@@ -69,6 +69,7 @@ namespace KSpell2
 
         bool checkWord( const QString& word );
         QStringList suggest( const QString& ) const;
+        bool addWord( const QString& word );
     public slots:
         virtual void setFilter( KSpell2::Filter *filter );
         virtual void start();
Index: backgroundengine.cpp
===================================================================
RCS file: /home/kde/kdelibs/kspell2/backgroundengine.cpp,v
retrieving revision 1.2
diff -u -3 -p -r1.2 backgroundengine.cpp
--- backgroundengine.cpp	3 May 2004 20:14:48 -0000	1.2
+++ backgroundengine.cpp	16 Apr 2005 17:04:22 -0000
@@ -123,6 +123,12 @@ bool BackgroundEngine::checkWord( const 
     return dict->check( word );
 }
 
+bool BackgroundEngine::addWord( const QString& word )
+{
+    Dictionary *dict = ( m_dict ) ? m_dict : static_cast<Dictionary*>( m_defaultDict );
+    return dict->addToPersonal( word );
+}
+
 QStringList BackgroundEngine::suggest( const QString& word )
 {
     Dictionary *dict = ( m_dict ) ? m_dict : static_cast<Dictionary*>( m_defaultDict );
Index: backgroundengine.h
===================================================================
RCS file: /home/kde/kdelibs/kspell2/backgroundengine.h,v
retrieving revision 1.1
diff -u -3 -p -r1.1 backgroundengine.h
--- backgroundengine.h	1 May 2004 05:32:17 -0000	1.1
+++ backgroundengine.h	16 Apr 2005 17:04:22 -0000
@@ -56,6 +56,7 @@ namespace KSpell2
 
         bool        checkWord( const QString& word );
         QStringList suggest( const QString& word );
+        bool        addWord( const QString& word );
     signals:
         void misspelling( const QString&, int );
         void done();
Index: plugins/aspell/kspell_aspelldict.cpp
===================================================================
RCS file: /home/kde/kdelibs/kspell2/plugins/aspell/kspell_aspelldict.cpp,v
retrieving revision 1.1
diff -u -3 -p -r1.1 kspell_aspelldict.cpp
--- plugins/aspell/kspell_aspelldict.cpp	1 May 2004 05:32:17 -0000	1.1
+++ plugins/aspell/kspell_aspelldict.cpp	16 Apr 2005 17:04:22 -0000
@@ -89,8 +89,14 @@ bool ASpellDict::storeReplacement( const
 
 bool ASpellDict::addToPersonal( const QString& word )
 {
-    return aspell_speller_add_to_personal( m_speller, word.utf8(),
+    kdDebug() << "ASpellDict::addToPersonal: word = " << word << endl;
+    aspell_speller_add_to_personal( m_speller, word.utf8(),
                                            word.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 )
Index: ui/dialog.cpp
===================================================================
RCS file: /home/kde/kdelibs/kspell2/ui/dialog.cpp,v
retrieving revision 1.12
diff -u -3 -p -r1.12 dialog.cpp
--- ui/dialog.cpp	28 Oct 2004 13:37:37 -0000	1.12
+++ ui/dialog.cpp	16 Apr 2005 17:04:22 -0000
@@ -200,7 +200,8 @@ void Dialog::show()
 
 void Dialog::slotAddWord()
 {
-    //FIXME: implement or hide the button
+   d->checker->addWord( d->currentWord.word ); 
+   d->checker->continueChecking();
 }
 
 void Dialog::slotReplaceWord()

[Attachment #6 (application/pgp-signature)]

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic