TDE core libraries
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.

backgroundchecker.cpp 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. /**
  2. * backgroundchecker.cpp
  3. *
  4. * Copyright (C) 2004 Zack Rusin <zack@kde.org>
  5. *
  6. * This library is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * This library is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with this library; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  19. * 02110-1301 USA
  20. */
  21. #include "backgroundchecker.h"
  22. #include "broker.h"
  23. #include "backgroundengine.h"
  24. //#include "backgroundthread.h"
  25. //#include "threadevents.h"
  26. #include <kdebug.h>
  27. using namespace KSpell2;
  28. class BackgroundChecker::Private
  29. {
  30. public:
  31. //BackgroundThread thread;
  32. BackgroundEngine *engine;
  33. TQString currentText;
  34. };
  35. BackgroundChecker::BackgroundChecker( const Broker::Ptr& broker, TQObject* parent,
  36. const char *name )
  37. : TQObject( parent, name )
  38. {
  39. d = new Private;
  40. //d->thread.setReceiver( this );
  41. //d->thread.setBroker( broker );
  42. d->engine = new BackgroundEngine( this );
  43. d->engine->setBroker( broker );
  44. connect( d->engine, TQT_SIGNAL(misspelling( const TQString&, int )),
  45. TQT_SIGNAL(misspelling( const TQString&, int )) );
  46. connect( d->engine, TQT_SIGNAL(done()),
  47. TQT_SLOT(slotEngineDone()) );
  48. }
  49. BackgroundChecker::~BackgroundChecker()
  50. {
  51. delete d;
  52. }
  53. void BackgroundChecker::checkText( const TQString& text )
  54. {
  55. d->currentText = text;
  56. //d->thread.setText( text );
  57. d->engine->setText( text );
  58. d->engine->start();
  59. }
  60. void BackgroundChecker::start()
  61. {
  62. d->currentText = getMoreText();
  63. // ## what if d->currentText.isEmpty()?
  64. //kdDebug()<<"KSpell BackgroundChecker: starting with : \"" << d->currentText << "\""<<endl;
  65. //d->thread.setText( d->currentText );
  66. d->engine->setText( d->currentText );
  67. d->engine->start();
  68. }
  69. void BackgroundChecker::stop()
  70. {
  71. //d->thread.stop();
  72. d->engine->stop();
  73. }
  74. TQString BackgroundChecker::getMoreText()
  75. {
  76. return TQString::null;
  77. }
  78. void BackgroundChecker::finishedCurrentFeed()
  79. {
  80. }
  81. void BackgroundChecker::setFilter( Filter *filter )
  82. {
  83. //d->thread.setFilter( filter );
  84. d->engine->setFilter( filter );
  85. }
  86. Filter *BackgroundChecker::filter() const
  87. {
  88. //return d->thread.filter();
  89. return d->engine->filter();
  90. }
  91. Broker *BackgroundChecker::broker() const
  92. {
  93. //return d->thread.broker();
  94. return d->engine->broker();
  95. }
  96. bool BackgroundChecker::checkWord( const TQString& word )
  97. {
  98. //kdDebug()<<"checking word \""<<word<< "\""<<endl;
  99. return d->engine->checkWord( word );
  100. }
  101. bool BackgroundChecker::addWord( const TQString& word )
  102. {
  103. return d->engine->addWord( word );
  104. }
  105. TQStringList BackgroundChecker::suggest( const TQString& word ) const
  106. {
  107. //return d->thread.suggest( word );
  108. return d->engine->suggest( word );
  109. }
  110. void BackgroundChecker::changeLanguage( const TQString& lang )
  111. {
  112. //d->thread.changeLanguage( lang );
  113. d->engine->changeLanguage( lang );
  114. }
  115. void BackgroundChecker::continueChecking()
  116. {
  117. d->engine->continueChecking();
  118. }
  119. void BackgroundChecker::slotEngineDone()
  120. {
  121. finishedCurrentFeed();
  122. d->currentText = getMoreText();
  123. if ( d->currentText.isNull() ) {
  124. emit done();
  125. } else {
  126. //d->thread.setText( d->currentText );
  127. d->engine->setText( d->currentText );
  128. d->engine->start();
  129. }
  130. }
  131. //////////////////////////////////////////////////////////////////
  132. #if 0
  133. void BackgroundChecker::customEvent( TQCustomEvent *event )
  134. {
  135. if ( (int)event->type() == FoundMisspelling ) {
  136. MisspellingEvent *me = static_cast<MisspellingEvent*>( event );
  137. kdDebug()<<"Found misspelling of \"" << me->word() << "\"" <<endl;
  138. TQString currentWord = d->currentText.mid( me->position(), me->word().length() );
  139. if ( currentWord == me->word() )
  140. emit misspelling( me->word(), me->position() );
  141. else {
  142. kdDebug()<<"Cleaning up misspelling for old text which is \""<<currentWord
  143. <<"\" and should be \""<<me->word()<<"\""<<endl;
  144. }
  145. } else if ( (int)event->type() == FinishedChecking ) {
  146. d->currentText = getMoreText();
  147. if ( d->currentText.isEmpty() )
  148. emit done();
  149. else
  150. d->thread.setText( d->currentText );
  151. } else {
  152. TQObject::customEvent( event );
  153. }
  154. }
  155. #endif
  156. #include "backgroundchecker.moc"