backgroundchecker.cpp00001
00021 #include "backgroundchecker.h"
00022
00023 #include "broker.h"
00024 #include "backgroundengine.h"
00025
00026
00027
00028 #include <kdebug.h>
00029
00030 using namespace KSpell2;
00031
00032 class BackgroundChecker::Private
00033 {
00034 public:
00035
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
00046
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
00064 d->engine->setText( text );
00065 d->engine->start();
00066 }
00067
00068 void BackgroundChecker::start()
00069 {
00070 d->currentText = getMoreText();
00071
00072
00073
00074 d->engine->setText( d->currentText );
00075 d->engine->start();
00076 }
00077
00078 void BackgroundChecker::stop()
00079 {
00080
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
00096 d->engine->setFilter( filter );
00097 }
00098
00099 Filter *BackgroundChecker::filter() const
00100 {
00101
00102 return d->engine->filter();
00103 }
00104
00105 Broker *BackgroundChecker::broker() const
00106 {
00107
00108 return d->engine->broker();
00109 }
00110
00111 bool BackgroundChecker::checkWord( const QString& word )
00112 {
00113
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
00125 return d->engine->suggest( word );
00126 }
00127
00128 void BackgroundChecker::changeLanguage( const QString& lang )
00129 {
00130
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
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"
|