You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
180 lines
4.7 KiB
180 lines
4.7 KiB
15 years ago
|
/**
|
||
|
* backgroundchecker.cpp
|
||
|
*
|
||
|
* Copyright (C) 2004 Zack Rusin <zack@kde.org>
|
||
|
*
|
||
|
* This library is free software; you can redistribute it and/or
|
||
|
* modify it under the terms of the GNU Lesser General Public
|
||
|
* License as published by the Free Software Foundation; either
|
||
|
* version 2.1 of the License, or (at your option) any later version.
|
||
|
*
|
||
|
* This library is distributed in the hope that it will be useful,
|
||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||
|
* Lesser General Public License for more details.
|
||
|
*
|
||
|
* You should have received a copy of the GNU Lesser General Public
|
||
|
* License along with this library; if not, write to the Free Software
|
||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||
|
* 02110-1301 USA
|
||
|
*/
|
||
|
#include "backgroundchecker.h"
|
||
|
|
||
|
#include "broker.h"
|
||
|
#include "backgroundengine.h"
|
||
|
//#include "backgroundthread.h"
|
||
|
//#include "threadevents.h"
|
||
|
|
||
|
#include <kdebug.h>
|
||
|
|
||
|
using namespace KSpell2;
|
||
|
|
||
|
class BackgroundChecker::Private
|
||
|
{
|
||
|
public:
|
||
|
//BackgroundThread thread;
|
||
|
BackgroundEngine *engine;
|
||
15 years ago
|
TQString currentText;
|
||
15 years ago
|
};
|
||
|
|
||
15 years ago
|
BackgroundChecker::BackgroundChecker( const Broker::Ptr& broker, TQObject* parent,
|
||
15 years ago
|
const char *name )
|
||
15 years ago
|
: TQObject( parent, name )
|
||
15 years ago
|
{
|
||
|
d = new Private;
|
||
|
//d->thread.setReceiver( this );
|
||
|
//d->thread.setBroker( broker );
|
||
|
d->engine = new BackgroundEngine( this );
|
||
|
d->engine->setBroker( broker );
|
||
15 years ago
|
connect( d->engine, TQT_SIGNAL(misspelling( const TQString&, int )),
|
||
|
TQT_SIGNAL(misspelling( const TQString&, int )) );
|
||
|
connect( d->engine, TQT_SIGNAL(done()),
|
||
|
TQT_SLOT(slotEngineDone()) );
|
||
15 years ago
|
}
|
||
|
|
||
|
BackgroundChecker::~BackgroundChecker()
|
||
|
{
|
||
|
delete d;
|
||
|
}
|
||
|
|
||
15 years ago
|
void BackgroundChecker::checkText( const TQString& text )
|
||
15 years ago
|
{
|
||
|
d->currentText = text;
|
||
|
//d->thread.setText( text );
|
||
|
d->engine->setText( text );
|
||
|
d->engine->start();
|
||
|
}
|
||
|
|
||
|
void BackgroundChecker::start()
|
||
|
{
|
||
|
d->currentText = getMoreText();
|
||
|
// ## what if d->currentText.isEmpty()?
|
||
|
//kdDebug()<<"KSpell BackgroundChecker: starting with : \"" << d->currentText << "\""<<endl;
|
||
|
//d->thread.setText( d->currentText );
|
||
|
d->engine->setText( d->currentText );
|
||
|
d->engine->start();
|
||
|
}
|
||
|
|
||
|
void BackgroundChecker::stop()
|
||
|
{
|
||
|
//d->thread.stop();
|
||
|
d->engine->stop();
|
||
|
}
|
||
|
|
||
15 years ago
|
TQString BackgroundChecker::getMoreText()
|
||
15 years ago
|
{
|
||
15 years ago
|
return TQString::null;
|
||
15 years ago
|
}
|
||
|
|
||
|
void BackgroundChecker::finishedCurrentFeed()
|
||
|
{
|
||
|
}
|
||
|
|
||
|
void BackgroundChecker::setFilter( Filter *filter )
|
||
|
{
|
||
|
//d->thread.setFilter( filter );
|
||
|
d->engine->setFilter( filter );
|
||
|
}
|
||
|
|
||
|
Filter *BackgroundChecker::filter() const
|
||
|
{
|
||
|
//return d->thread.filter();
|
||
|
return d->engine->filter();
|
||
|
}
|
||
|
|
||
|
Broker *BackgroundChecker::broker() const
|
||
|
{
|
||
|
//return d->thread.broker();
|
||
|
return d->engine->broker();
|
||
|
}
|
||
|
|
||
15 years ago
|
bool BackgroundChecker::checkWord( const TQString& word )
|
||
15 years ago
|
{
|
||
|
//kdDebug()<<"checking word \""<<word<< "\""<<endl;
|
||
|
return d->engine->checkWord( word );
|
||
|
}
|
||
|
|
||
15 years ago
|
bool BackgroundChecker::addWord( const TQString& word )
|
||
15 years ago
|
{
|
||
|
return d->engine->addWord( word );
|
||
|
}
|
||
|
|
||
15 years ago
|
TQStringList BackgroundChecker::suggest( const TQString& word ) const
|
||
15 years ago
|
{
|
||
|
//return d->thread.suggest( word );
|
||
|
return d->engine->suggest( word );
|
||
|
}
|
||
|
|
||
15 years ago
|
void BackgroundChecker::changeLanguage( const TQString& lang )
|
||
15 years ago
|
{
|
||
|
//d->thread.changeLanguage( lang );
|
||
|
d->engine->changeLanguage( lang );
|
||
|
}
|
||
|
|
||
|
void BackgroundChecker::continueChecking()
|
||
|
{
|
||
|
d->engine->continueChecking();
|
||
|
}
|
||
|
|
||
|
void BackgroundChecker::slotEngineDone()
|
||
|
{
|
||
|
finishedCurrentFeed();
|
||
|
d->currentText = getMoreText();
|
||
|
|
||
|
if ( d->currentText.isNull() ) {
|
||
|
emit done();
|
||
|
} else {
|
||
|
//d->thread.setText( d->currentText );
|
||
|
d->engine->setText( d->currentText );
|
||
|
d->engine->start();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
//////////////////////////////////////////////////////////////////
|
||
|
#if 0
|
||
15 years ago
|
void BackgroundChecker::customEvent( TQCustomEvent *event )
|
||
15 years ago
|
{
|
||
|
if ( (int)event->type() == FoundMisspelling ) {
|
||
|
MisspellingEvent *me = static_cast<MisspellingEvent*>( event );
|
||
|
kdDebug()<<"Found misspelling of \"" << me->word() << "\"" <<endl;
|
||
15 years ago
|
TQString currentWord = d->currentText.mid( me->position(), me->word().length() );
|
||
15 years ago
|
if ( currentWord == me->word() )
|
||
|
emit misspelling( me->word(), me->position() );
|
||
|
else {
|
||
|
kdDebug()<<"Cleaning up misspelling for old text which is \""<<currentWord
|
||
|
<<"\" and should be \""<<me->word()<<"\""<<endl;
|
||
|
}
|
||
|
} else if ( (int)event->type() == FinishedChecking ) {
|
||
|
d->currentText = getMoreText();
|
||
|
if ( d->currentText.isEmpty() )
|
||
|
emit done();
|
||
|
else
|
||
|
d->thread.setText( d->currentText );
|
||
|
} else {
|
||
15 years ago
|
TQObject::customEvent( event );
|
||
15 years ago
|
}
|
||
|
}
|
||
|
#endif
|
||
|
|
||
|
#include "backgroundchecker.moc"
|