• Skip to content
  • Skip to link menu
KDE 3.5 API Reference
  • KDE API Reference
  • @topname@
  • Sitemap
  • Contact Us
 

kspell2

backgroundchecker.cpp

00001 
00021 #include "backgroundchecker.h"
00022 
00023 #include "broker.h"
00024 #include "backgroundengine.h"
00025 //#include "backgroundthread.h"
00026 //#include "threadevents.h"
00027 
00028 #include <kdebug.h>
00029 
00030 using namespace KSpell2;
00031 
00032 class BackgroundChecker::Private
00033 {
00034 public:
00035     //BackgroundThread thread;
00036     BackgroundEngine *engine;
00037     QString currentText;
00038 };
00039 
00040 BackgroundChecker::BackgroundChecker( const Broker::Ptr& broker, QObject* parent,
00041                                       const char *name )
00042     : QObject( parent, name )
00043 {
00044     d = new Private;
00045     //d->thread.setReceiver( this );
00046     //d->thread.setBroker( broker );
00047     d->engine = new BackgroundEngine( this );
00048     d->engine->setBroker( broker );
00049     connect( d->engine, SIGNAL(misspelling( const QString&, int )),
00050              SIGNAL(misspelling( const QString&, int )) );
00051     connect( d->engine, SIGNAL(done()),
00052              SLOT(slotEngineDone()) );
00053 }
00054 
00055 BackgroundChecker::~BackgroundChecker()
00056 {
00057     delete d;
00058 }
00059 
00060 void BackgroundChecker::checkText( const QString& text )
00061 {
00062     d->currentText = text;
00063     //d->thread.setText( text );
00064     d->engine->setText( text );
00065     d->engine->start();
00066 }
00067 
00068 void BackgroundChecker::start()
00069 {
00070     d->currentText = getMoreText();
00071     // ## what if d->currentText.isEmpty()?
00072     //kdDebug()<<"KSpell BackgroundChecker: starting with : \"" << d->currentText << "\""<<endl;
00073     //d->thread.setText( d->currentText );
00074     d->engine->setText( d->currentText );
00075     d->engine->start();
00076 }
00077 
00078 void BackgroundChecker::stop()
00079 {
00080     //d->thread.stop();
00081     d->engine->stop();
00082 }
00083 
00084 QString BackgroundChecker::getMoreText()
00085 {
00086     return QString::null;
00087 }
00088 
00089 void BackgroundChecker::finishedCurrentFeed()
00090 {
00091 }
00092 
00093 void BackgroundChecker::setFilter( Filter *filter )
00094 {
00095     //d->thread.setFilter( filter );
00096     d->engine->setFilter( filter );
00097 }
00098 
00099 Filter *BackgroundChecker::filter() const
00100 {
00101     //return d->thread.filter();
00102     return d->engine->filter();
00103 }
00104 
00105 Broker *BackgroundChecker::broker() const
00106 {
00107     //return d->thread.broker();
00108     return d->engine->broker();
00109 }
00110 
00111 bool BackgroundChecker::checkWord( const QString& word )
00112 {
00113     //kdDebug()<<"checking word \""<<word<< "\""<<endl;
00114     return d->engine->checkWord( word );
00115 }
00116 
00117 bool BackgroundChecker::addWord( const QString& word )
00118 {
00119     return d->engine->addWord( word );
00120 }
00121 
00122 QStringList BackgroundChecker::suggest( const QString& word ) const
00123 {
00124     //return d->thread.suggest( word );
00125     return d->engine->suggest( word );
00126 }
00127 
00128 void BackgroundChecker::changeLanguage( const QString& lang )
00129 {
00130     //d->thread.changeLanguage( lang );
00131     d->engine->changeLanguage( lang );
00132 }
00133 
00134 void BackgroundChecker::continueChecking()
00135 {
00136     d->engine->continueChecking();
00137 }
00138 
00139 void BackgroundChecker::slotEngineDone()
00140 {
00141     finishedCurrentFeed();
00142     d->currentText = getMoreText();
00143 
00144     if ( d->currentText.isNull() ) {
00145         emit done();
00146     } else {
00147         //d->thread.setText( d->currentText );
00148         d->engine->setText( d->currentText );
00149         d->engine->start();
00150     }
00151 }
00152 
00154 #if 0
00155 void BackgroundChecker::customEvent( QCustomEvent *event )
00156 {
00157     if ( (int)event->type() == FoundMisspelling ) {
00158         MisspellingEvent *me = static_cast<MisspellingEvent*>( event );
00159         kdDebug()<<"Found misspelling of \"" << me->word() << "\"" <<endl;
00160         QString currentWord = d->currentText.mid( me->position(), me->word().length() );
00161         if ( currentWord == me->word() )
00162             emit misspelling( me->word(), me->position() );
00163         else {
00164             kdDebug()<<"Cleaning up misspelling for old text which is \""<<currentWord
00165                      <<"\" and should be \""<<me->word()<<"\""<<endl;
00166         }
00167     } else if ( (int)event->type() == FinishedChecking ) {
00168         d->currentText = getMoreText();
00169         if ( d->currentText.isEmpty() )
00170             emit done();
00171         else
00172             d->thread.setText( d->currentText );
00173     } else {
00174         QObject::customEvent( event );
00175     }
00176 }
00177 #endif
00178 
00179 #include "backgroundchecker.moc"

kspell2

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

@topname@

Skip menu "@topname@"
  •     kdnssd-avahi
  • 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
  • kresources
  • kspell2
  • kunittest
  • kutils
  • kwallet
  • libkmid
  • libkscreensaver
Generated for @topname@ by doxygen 1.5.5
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal