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

kspell2

  • kspell2
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

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.8.1.2
This website is maintained by Timothy Pearson.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. |