• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • kspell2
 

kspell2

backgroundthread.cpp
00001 
00021 #include "backgroundthread.h"
00022 
00023 #include "threadevents.h"
00024 #include "broker.h"
00025 #include "filter.h"
00026 #include "dictionary.h"
00027 
00028 #include <kdebug.h>
00029 #include <tqapplication.h>
00030 
00031 using namespace KSpell2;
00032 
00033 BackgroundThread::BackgroundThread()
00034     : TQThread(), m_broker( 0 ), m_dict( 0 )
00035 {
00036     m_recv   = 0;
00037     m_filter = Filter::defaultFilter();
00038     m_done   = false;
00039 }
00040 
00041 void BackgroundThread::setReceiver( TQObject *recv )
00042 {
00043     m_recv = recv;
00044 }
00045 
00046 void BackgroundThread::setBroker( const Broker::Ptr& broker )
00047 {
00048     stop();
00049     m_broker = broker;
00050     delete m_dict;
00051     m_dict   = m_broker->dictionary();
00052     m_filter->restart();
00053 }
00054 
00055 TQStringList BackgroundThread::suggest( const TQString& word ) const
00056 {
00057     return m_dict->suggest( word );
00058 }
00059 
00060 void BackgroundThread::run()
00061 {
00062     m_mutex.lock();
00063     m_done = false;
00064     for ( Word w = m_filter->nextWord(); !m_done && !w.end;
00065           w = m_filter->nextWord() ) {
00066         if ( !m_dict->check( w.word ) && !m_done ) {
00067             MisspellingEvent *event = new MisspellingEvent( w.word, w.start );
00068             TQApplication::postEvent( m_recv, event );
00069         }
00070     }
00071     m_mutex.unlock();
00072     FinishedCheckingEvent *event = new FinishedCheckingEvent();
00073     TQApplication::postEvent( m_recv, event );
00074 }
00075 
00076 void BackgroundThread::setText( const TQString& buff )
00077 {
00078     stop();
00079     m_mutex.lock();
00080     m_filter->setBuffer( buff );
00081     m_mutex.unlock();
00082     start();
00083 }
00084 
00085 void BackgroundThread::setFilter( Filter *filter )
00086 {
00087     stop();
00088     m_mutex.lock();
00089     Filter *oldFilter = m_filter;
00090     m_filter = filter;
00091     if ( oldFilter ) {
00092         m_filter->setBuffer( oldFilter->buffer() );
00093         oldFilter->setBuffer( TQString::null );
00094     }
00095     m_mutex.unlock();
00096     start();
00097 }
00098 
00099 void BackgroundThread::changeLanguage( const TQString& lang )
00100 {
00101     stop();
00102     m_mutex.lock();
00103     delete m_dict;
00104     m_dict = m_broker->dictionary( lang );
00105     m_filter->restart();
00106     m_mutex.unlock();
00107     start();
00108 }
00109 
00110 void BackgroundThread::stop()
00111 {
00112     //### maybe terminate() would be better than using m_done
00113     m_done = true;
00114     wait();
00115 }

kspell2

Skip menu "kspell2"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members

kspell2

Skip menu "kspell2"
  • arts
  • dcop
  • dnssd
  • interfaces
  •     interface
  •     library
  •   kspeech
  •   ktexteditor
  • kabc
  • kate
  • kcmshell
  • kdecore
  • kded
  • kdefx
  • kdeprint
  • kdesu
  • kdeui
  • kdoctools
  • khtml
  • kimgio
  • kinit
  • kio
  •   bookmarks
  •   httpfilter
  •   kfile
  •   kio
  •   kioexec
  •   kpasswdserver
  •   kssl
  • kioslave
  •   http
  • kjs
  • kmdi
  •   kmdi
  • knewstuff
  • kparts
  • krandr
  • kresources
  • kspell2
  • kunittest
  • kutils
  • kwallet
  • libkmid
  • libkscreensaver
Generated for kspell2 by doxygen 1.7.6.1
This website is maintained by Timothy Pearson.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. |