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.
139 lines
3.3 KiB
139 lines
3.3 KiB
15 years ago
|
/**
|
||
|
* backgroundengine.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 "backgroundengine.h"
|
||
|
|
||
|
#include "defaultdictionary.h"
|
||
|
#include "dictionary.h"
|
||
|
#include "filter.h"
|
||
|
|
||
|
#include <kdebug.h>
|
||
|
|
||
14 years ago
|
#include <tqtimer.h>
|
||
15 years ago
|
|
||
|
using namespace KSpell2;
|
||
|
|
||
14 years ago
|
BackgroundEngine::BackgroundEngine( TQObject *parent )
|
||
|
: TQObject( parent )
|
||
15 years ago
|
{
|
||
|
m_filter = Filter::defaultFilter();
|
||
|
m_dict = 0;
|
||
|
}
|
||
|
|
||
|
BackgroundEngine::~BackgroundEngine()
|
||
|
{
|
||
|
delete m_dict; m_dict = 0;
|
||
|
}
|
||
|
|
||
|
void BackgroundEngine::setBroker( const Broker::Ptr& broker )
|
||
|
{
|
||
|
m_broker = broker;
|
||
|
delete m_dict;
|
||
|
m_defaultDict = m_broker->defaultDictionary();
|
||
|
m_filter->setSettings( m_broker->settings() );
|
||
|
}
|
||
|
|
||
14 years ago
|
void BackgroundEngine::setText( const TQString& text )
|
||
15 years ago
|
{
|
||
|
m_filter->setBuffer( text );
|
||
|
}
|
||
|
|
||
14 years ago
|
TQString BackgroundEngine::text() const
|
||
15 years ago
|
{
|
||
|
return m_filter->buffer();
|
||
|
}
|
||
|
|
||
14 years ago
|
void BackgroundEngine::changeLanguage( const TQString& lang )
|
||
15 years ago
|
{
|
||
|
delete m_dict;
|
||
|
if ( lang.isEmpty() ) {
|
||
|
m_dict = 0;
|
||
|
} else {
|
||
|
m_dict = m_broker->dictionary( lang );
|
||
|
}
|
||
|
}
|
||
|
|
||
14 years ago
|
TQString BackgroundEngine::language() const
|
||
15 years ago
|
{
|
||
|
if ( m_dict )
|
||
|
return m_dict->language();
|
||
|
else
|
||
|
return m_defaultDict->language();
|
||
|
}
|
||
|
|
||
|
void BackgroundEngine::setFilter( Filter *filter )
|
||
|
{
|
||
14 years ago
|
TQString oldText = m_filter->buffer();
|
||
15 years ago
|
m_filter = filter;
|
||
|
m_filter->setBuffer( oldText );
|
||
|
}
|
||
|
|
||
|
void BackgroundEngine::start()
|
||
|
{
|
||
14 years ago
|
TQTimer::singleShot( 0, this, TQT_SLOT(checkNext()) );
|
||
15 years ago
|
}
|
||
|
|
||
|
void BackgroundEngine::stop()
|
||
|
{
|
||
|
}
|
||
|
|
||
|
void BackgroundEngine::continueChecking()
|
||
|
{
|
||
14 years ago
|
TQTimer::singleShot( 0, this, TQT_SLOT(checkNext()) );
|
||
15 years ago
|
}
|
||
|
|
||
|
void BackgroundEngine::checkNext()
|
||
|
{
|
||
|
Word w = m_filter->nextWord();
|
||
|
if ( w.end ) {
|
||
|
emit done();
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
Dictionary *dict = ( m_dict ) ? m_dict : static_cast<Dictionary*>( m_defaultDict );
|
||
|
|
||
|
if ( !dict->check( w.word ) ) {
|
||
|
//kdDebug()<<"found misspelling "<< w.word <<endl;
|
||
|
emit misspelling( w.word, w.start );
|
||
|
//wait for the handler. the parent will decide itself when to continue
|
||
|
} else
|
||
|
continueChecking();
|
||
|
}
|
||
|
|
||
14 years ago
|
bool BackgroundEngine::checkWord( const TQString& word )
|
||
15 years ago
|
{
|
||
|
Dictionary *dict = ( m_dict ) ? m_dict : static_cast<Dictionary*>( m_defaultDict );
|
||
|
return dict->check( word );
|
||
|
}
|
||
|
|
||
14 years ago
|
bool BackgroundEngine::addWord( const TQString& word )
|
||
15 years ago
|
{
|
||
|
Dictionary *dict = ( m_dict ) ? m_dict : static_cast<Dictionary*>( m_defaultDict );
|
||
|
return dict->addToPersonal( word );
|
||
|
}
|
||
|
|
||
14 years ago
|
TQStringList BackgroundEngine::suggest( const TQString& word )
|
||
15 years ago
|
{
|
||
|
Dictionary *dict = ( m_dict ) ? m_dict : static_cast<Dictionary*>( m_defaultDict );
|
||
|
return dict->suggest( word );
|
||
|
}
|
||
|
|
||
|
#include "backgroundengine.moc"
|