diff options
author | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
---|---|---|
committer | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
commit | ce4a32fe52ef09d8f5ff1dd22c001110902b60a2 (patch) | |
tree | 5ac38a06f3dde268dc7927dc155896926aaf7012 /kspell2/backgroundengine.cpp | |
download | tdelibs-ce4a32fe52ef09d8f5ff1dd22c001110902b60a2.tar.gz tdelibs-ce4a32fe52ef09d8f5ff1dd22c001110902b60a2.zip |
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdelibs@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kspell2/backgroundengine.cpp')
-rw-r--r-- | kspell2/backgroundengine.cpp | 138 |
1 files changed, 138 insertions, 0 deletions
diff --git a/kspell2/backgroundengine.cpp b/kspell2/backgroundengine.cpp new file mode 100644 index 000000000..d5394dbb5 --- /dev/null +++ b/kspell2/backgroundengine.cpp @@ -0,0 +1,138 @@ +/** + * 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> + +#include <qtimer.h> + +using namespace KSpell2; + +BackgroundEngine::BackgroundEngine( QObject *parent ) + : QObject( parent ) +{ + 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() ); +} + +void BackgroundEngine::setText( const QString& text ) +{ + m_filter->setBuffer( text ); +} + +QString BackgroundEngine::text() const +{ + return m_filter->buffer(); +} + +void BackgroundEngine::changeLanguage( const QString& lang ) +{ + delete m_dict; + if ( lang.isEmpty() ) { + m_dict = 0; + } else { + m_dict = m_broker->dictionary( lang ); + } +} + +QString BackgroundEngine::language() const +{ + if ( m_dict ) + return m_dict->language(); + else + return m_defaultDict->language(); +} + +void BackgroundEngine::setFilter( Filter *filter ) +{ + QString oldText = m_filter->buffer(); + m_filter = filter; + m_filter->setBuffer( oldText ); +} + +void BackgroundEngine::start() +{ + QTimer::singleShot( 0, this, SLOT(checkNext()) ); +} + +void BackgroundEngine::stop() +{ +} + +void BackgroundEngine::continueChecking() +{ + QTimer::singleShot( 0, this, SLOT(checkNext()) ); +} + +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(); +} + +bool BackgroundEngine::checkWord( const QString& word ) +{ + Dictionary *dict = ( m_dict ) ? m_dict : static_cast<Dictionary*>( m_defaultDict ); + return dict->check( word ); +} + +bool BackgroundEngine::addWord( const QString& word ) +{ + Dictionary *dict = ( m_dict ) ? m_dict : static_cast<Dictionary*>( m_defaultDict ); + return dict->addToPersonal( word ); +} + +QStringList BackgroundEngine::suggest( const QString& word ) +{ + Dictionary *dict = ( m_dict ) ? m_dict : static_cast<Dictionary*>( m_defaultDict ); + return dict->suggest( word ); +} + +#include "backgroundengine.moc" |