KDECore
backgroundchecker.cpp
Go to the documentation of this file.00001
00021 #include "backgroundchecker.h"
00022
00023 #include "loader_p.h"
00024 #include "backgroundengine_p.h"
00025 #include "filter_p.h"
00026
00027 #include <kdebug.h>
00028
00029 using namespace Sonnet;
00030
00031 class BackgroundChecker::Private
00032 {
00033 public:
00034 BackgroundEngine *engine;
00035 QString currentText;
00036 };
00037
00038
00039 BackgroundChecker::BackgroundChecker(QObject *parent)
00040 : QObject(parent),
00041 d(new Private)
00042 {
00043 d->engine = new BackgroundEngine(this);
00044 connect(d->engine, SIGNAL(misspelling(const QString&, int)),
00045 SIGNAL(misspelling(const QString&, int)));
00046 connect(d->engine, SIGNAL(done()),
00047 SLOT(slotEngineDone()));
00048 }
00049
00050 BackgroundChecker::BackgroundChecker(const Speller &speller, QObject *parent)
00051 : QObject(parent),
00052 d(new Private)
00053 {
00054 d->engine = new BackgroundEngine(this);
00055 d->engine->setSpeller(speller);
00056 connect(d->engine, SIGNAL(misspelling(const QString&, int)),
00057 SIGNAL(misspelling(const QString&, int)));
00058 connect(d->engine, SIGNAL(done()),
00059 SLOT(slotEngineDone()));
00060 }
00061
00062 BackgroundChecker::~BackgroundChecker()
00063 {
00064 delete d;
00065 }
00066
00067 void BackgroundChecker::setText(const QString &text)
00068 {
00069 d->currentText = text;
00070 d->engine->setText(text);
00071 d->engine->start();
00072 }
00073
00074 void BackgroundChecker::start()
00075 {
00076 d->currentText = fetchMoreText();
00077
00078
00079 d->engine->setText(d->currentText);
00080 d->engine->start();
00081 }
00082
00083 void BackgroundChecker::stop()
00084 {
00085 d->engine->stop();
00086 }
00087
00088 QString BackgroundChecker::fetchMoreText()
00089 {
00090 return QString();
00091 }
00092
00093 void BackgroundChecker::finishedCurrentFeed()
00094 {
00095 }
00096
00097 void BackgroundChecker::setSpeller(const Speller &speller)
00098 {
00099 d->engine->setSpeller(speller);
00100 }
00101
00102 Speller BackgroundChecker::speller() const
00103 {
00104 return d->engine->speller();
00105 }
00106
00107 bool BackgroundChecker::checkWord(const QString &word)
00108 {
00109 return d->engine->checkWord( word );
00110 }
00111
00112 bool BackgroundChecker::addWordToPersonal(const QString &word)
00113 {
00114 return d->engine->addWord(word);
00115 }
00116
00117 QStringList BackgroundChecker::suggest(const QString &word) const
00118 {
00119 return d->engine->suggest(word);
00120 }
00121
00122 void BackgroundChecker::changeLanguage(const QString &lang)
00123 {
00124 d->engine->changeLanguage(lang);
00125 }
00126
00127 void BackgroundChecker::continueChecking()
00128 {
00129 d->engine->continueChecking();
00130 }
00131
00132 void BackgroundChecker::slotEngineDone()
00133 {
00134 finishedCurrentFeed();
00135 d->currentText = fetchMoreText();
00136
00137 if ( d->currentText.isNull() ) {
00138 emit done();
00139 } else {
00140 d->engine->setText( d->currentText );
00141 d->engine->start();
00142 }
00143 }
00144
00145 QString BackgroundChecker::text() const
00146 {
00147 return d->engine->filter()->buffer();
00148 }
00149
00150
00151 QString BackgroundChecker::currentContext() const
00152 {
00153 return d->engine->filter()->context();
00154 }
00155
00156 void Sonnet::BackgroundChecker::replace(int start, const QString &oldText,
00157 const QString &newText)
00158 {
00159 Word w(oldText, start);
00160 d->engine->filter()->replace(w, newText);
00161 }
00162
00163 #include "backgroundchecker.moc"