1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
|
/**
* backgroundengine.cpp
*
* Copyright (C) 2004 Zack Rusin <[email protected]>
*
* 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 <tqtimer.h>
using namespace KSpell2;
BackgroundEngine::BackgroundEngine( TQObject *parent )
: TQObject( 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 TQString& text )
{
m_filter->setBuffer( text );
}
TQString BackgroundEngine::text() const
{
return m_filter->buffer();
}
void BackgroundEngine::changeLanguage( const TQString& lang )
{
delete m_dict;
if ( lang.isEmpty() ) {
m_dict = 0;
} else {
m_dict = m_broker->dictionary( lang );
}
}
TQString BackgroundEngine::language() const
{
if ( m_dict )
return m_dict->language();
else
return m_defaultDict->language();
}
void BackgroundEngine::setFilter( Filter *filter )
{
TQString oldText = m_filter->buffer();
m_filter = filter;
m_filter->setBuffer( oldText );
}
void BackgroundEngine::start()
{
TQTimer::singleShot( 0, this, TQT_SLOT(checkNext()) );
}
void BackgroundEngine::stop()
{
}
void BackgroundEngine::continueChecking()
{
TQTimer::singleShot( 0, this, TQT_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 TQString& word )
{
Dictionary *dict = ( m_dict ) ? m_dict : static_cast<Dictionary*>( m_defaultDict );
return dict->check( word );
}
bool BackgroundEngine::addWord( const TQString& word )
{
Dictionary *dict = ( m_dict ) ? m_dict : static_cast<Dictionary*>( m_defaultDict );
return dict->addToPersonal( word );
}
TQStringList BackgroundEngine::suggest( const TQString& word )
{
Dictionary *dict = ( m_dict ) ? m_dict : static_cast<Dictionary*>( m_defaultDict );
return dict->suggest( word );
}
#include "backgroundengine.moc"
|