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