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

tdespell2

  • tdespell2
backgroundthread.cpp
1 
21 #include "backgroundthread.h"
22 
23 #include "threadevents.h"
24 #include "broker.h"
25 #include "filter.h"
26 #include "dictionary.h"
27 
28 #include <kdebug.h>
29 #include <tqapplication.h>
30 
31 using namespace KSpell2;
32 
33 BackgroundThread::BackgroundThread()
34  : TQThread(), m_broker( 0 ), m_dict( 0 )
35 {
36  m_recv = 0;
37  m_filter = Filter::defaultFilter();
38  m_done = false;
39 }
40 
41 void BackgroundThread::setReceiver( TQObject *recv )
42 {
43  m_recv = recv;
44 }
45 
46 void BackgroundThread::setBroker( const Broker::Ptr& broker )
47 {
48  stop();
49  m_broker = broker;
50  delete m_dict;
51  m_dict = m_broker->dictionary();
52  m_filter->restart();
53 }
54 
55 TQStringList BackgroundThread::suggest( const TQString& word ) const
56 {
57  return m_dict->suggest( word );
58 }
59 
60 void BackgroundThread::run()
61 {
62  m_mutex.lock();
63  m_done = false;
64  for ( Word w = m_filter->nextWord(); !m_done && !w.end;
65  w = m_filter->nextWord() ) {
66  if ( !m_dict->check( w.word ) && !m_done ) {
67  MisspellingEvent *event = new MisspellingEvent( w.word, w.start );
68  TQApplication::postEvent( m_recv, event );
69  }
70  }
71  m_mutex.unlock();
72  FinishedCheckingEvent *event = new FinishedCheckingEvent();
73  TQApplication::postEvent( m_recv, event );
74 }
75 
76 void BackgroundThread::setText( const TQString& buff )
77 {
78  stop();
79  m_mutex.lock();
80  m_filter->setBuffer( buff );
81  m_mutex.unlock();
82  start();
83 }
84 
85 void BackgroundThread::setFilter( Filter *filter )
86 {
87  stop();
88  m_mutex.lock();
89  Filter *oldFilter = m_filter;
90  m_filter = filter;
91  if ( oldFilter ) {
92  m_filter->setBuffer( oldFilter->buffer() );
93  oldFilter->setBuffer( TQString::null );
94  }
95  m_mutex.unlock();
96  start();
97 }
98 
99 void BackgroundThread::changeLanguage( const TQString& lang )
100 {
101  stop();
102  m_mutex.lock();
103  delete m_dict;
104  m_dict = m_broker->dictionary( lang );
105  m_filter->restart();
106  m_mutex.unlock();
107  start();
108 }
109 
110 void BackgroundThread::stop()
111 {
112  //### maybe terminate() would be better than using m_done
113  m_done = true;
114  wait();
115 }
KSpell2::Filter
Filter is used to split text into words which will be spell checked.
Definition: filter.h:64
KSpell2
tdespell_hspellclient.h
Definition: backgroundchecker.h:28
KSpell2::Word
Structure abstracts the word and its position in the parent text.
Definition: filter.h:39

tdespell2

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

tdespell2

Skip menu "tdespell2"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  •     tdecore
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  • tdeioslave
  •   http
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdespell2 by doxygen 1.8.8
This website is maintained by Timothy Pearson.