• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdeui
 

tdeui

  • tdeui
tdespell.cpp
1 /* This file is part of the KDE libraries
2  Copyright (C) 1997 David Sweet <dsweet@kde.org>
3  Copyright (C) 2000-2001 Wolfram Diestel <wolfram@steloj.de>
4  Copyright (C) 2003 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 Library General Public
8  License version 2 as published by the Free Software Foundation.
9 
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Library General Public License for more details.
14 
15  You should have received a copy of the GNU Library General Public License
16  along with this library; see the file COPYING.LIB. If not, write to
17  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  Boston, MA 02110-1301, USA.
19 */
20 
21 #ifdef HAVE_CONFIG_H
22 #include <config.h>
23 #endif
24 
25 #include <stdio.h>
26 #include <sys/time.h>
27 #include <sys/types.h>
28 #include <unistd.h>
29 #include <ctype.h>
30 #include <stdlib.h> // atoi
31 
32 #ifdef HAVE_STRINGS_H
33 #include <strings.h>
34 #endif
35 
36 #include <tqregexp.h>
37 #include <tqtextcodec.h>
38 #include <tqtimer.h>
39 
40 #include <tdeapplication.h>
41 #include <tdemessagebox.h>
42 #include <kdebug.h>
43 #include <tdelocale.h>
44 #include "tdespell.h"
45 #include "tdespelldlg.h"
46 #include <twin.h>
47 #include <tdeprocio.h>
48 
49 #define MAXLINELENGTH 10000
50 #undef IGNORE //fix possible conflict
51 
52 enum {
53  GOOD= 0,
54  IGNORE= 1,
55  REPLACE= 2,
56  MISTAKE= 3
57 };
58 
59 enum checkMethod { Method1 = 0, Method2 };
60 
61 struct BufferedWord
62 {
63  checkMethod method;
64  TQString word;
65  bool useDialog;
66  bool suggest;
67 };
68 
69 class KSpell::KSpellPrivate
70 {
71 public:
72  bool endOfResponse;
73  bool m_bIgnoreUpperWords;
74  bool m_bIgnoreTitleCase;
75  bool m_bNoMisspellingsEncountered;
76  SpellerType type;
77  KSpell* suggestSpell;
78  bool checking;
79  TQValueList<BufferedWord> unchecked;
80  TQTimer *checkNextTimer;
81  bool aspellV6;
82 };
83 
84 //TODO
85 //Parse stderr output
86 //e.g. -- invalid dictionary name
87 
88 /*
89  Things to put in KSpellConfigDlg:
90  make root/affix combinations that aren't in the dictionary (-m)
91  don't generate any affix/root combinations (-P)
92  Report run-together words with missing blanks as spelling errors. (-B)
93  default dictionary (-d [dictionary])
94  personal dictionary (-p [dictionary])
95  path to ispell -- NO: ispell should be in $PATH
96  */
97 
98 
99 // Connects a slot to TDEProcIO's output signal
100 #define OUTPUT(x) (connect (proc, TQ_SIGNAL (readReady(TDEProcIO *)), this, TQ_SLOT (x(TDEProcIO *))))
101 
102 // Disconnect a slot from...
103 #define NOOUTPUT(x) (disconnect (proc, TQ_SIGNAL (readReady(TDEProcIO *)), this, TQ_SLOT (x(TDEProcIO *))))
104 
105 
106 
107 KSpell::KSpell( TQWidget *_parent, const TQString &_caption,
108  TQObject *obj, const char *slot, KSpellConfig *_ksc,
109  bool _progressbar, bool _modal )
110 {
111  initialize( _parent, _caption, obj, slot, _ksc,
112  _progressbar, _modal, Text );
113 }
114 
115 KSpell::KSpell( TQWidget *_parent, const TQString &_caption,
116  TQObject *obj, const char *slot, KSpellConfig *_ksc,
117  bool _progressbar, bool _modal, SpellerType type )
118 {
119  initialize( _parent, _caption, obj, slot, _ksc,
120  _progressbar, _modal, type );
121 }
122 
123 void KSpell::hide() { ksdlg->hide(); }
124 
125 int KSpell::heightDlg() const { return ksdlg->height(); }
126 int KSpell::widthDlg() const { return ksdlg->width(); }
127 
128 // Check if aspell is at least version 0.6
129 static bool determineASpellV6()
130 {
131  TQString result;
132  FILE *fs = popen("aspell -v", "r");
133  if (fs)
134  {
135  // Close textstream before we close fs
136  {
137  TQTextStream ts(fs, IO_ReadOnly);
138  result = ts.read().stripWhiteSpace();
139  }
140  pclose(fs);
141  }
142 
143  TQRegExp rx("Aspell (\\d.\\d)");
144  if (rx.search(result) != -1)
145  {
146  float version = rx.cap(1).toFloat();
147  return (version >= 0.6);
148  }
149  return false;
150 }
151 
152 
153 void
154 KSpell::startIspell()
155  //trystart = {0,1,2}
156 {
157  if ((trystart == 0) && (ksconfig->client() == KS_CLIENT_ASPELL))
158  d->aspellV6 = determineASpellV6();
159 
160  kdDebug(750) << "Try #" << trystart << endl;
161 
162  if ( trystart > 0 ) {
163  proc->resetAll();
164  }
165 
166  switch ( ksconfig->client() )
167  {
168  case KS_CLIENT_ISPELL:
169  *proc << "ispell";
170  kdDebug(750) << "Using ispell" << endl;
171  break;
172  case KS_CLIENT_ASPELL:
173  *proc << "aspell";
174  kdDebug(750) << "Using aspell" << endl;
175  break;
176  case KS_CLIENT_HSPELL:
177  *proc << "hspell";
178  kdDebug(750) << "Using hspell" << endl;
179  break;
180  case KS_CLIENT_ZEMBEREK:
181  *proc << "zpspell";
182  kdDebug(750) << "Using zemberek(zpspell)" << endl;
183  break;
184  }
185 
186  if ( ksconfig->client() == KS_CLIENT_ISPELL || ksconfig->client() == KS_CLIENT_ASPELL )
187  {
188  *proc << "-a" << "-S";
189 
190  switch ( d->type )
191  {
192  case HTML:
193  //Debian uses an ispell version that has the -h option instead.
194  //Not sure what they did, but the preferred spell checker
195  //on that platform is aspell anyway, so use -H untill I'll come
196  //up with something better.
197  *proc << "-H";
198  break;
199  case TeX:
200  //same for aspell and ispell
201  *proc << "-t";
202  break;
203  case Nroff:
204  //only ispell supports
205  if ( ksconfig->client() == KS_CLIENT_ISPELL )
206  *proc << "-n";
207  break;
208  case Text:
209  default:
210  //nothing
211  break;
212  }
213  if (ksconfig->noRootAffix())
214  {
215  *proc<<"-m";
216  }
217  if (ksconfig->runTogether())
218  {
219  *proc << "-B";
220  }
221  else
222  {
223  *proc << "-C";
224  }
225 
226 
227  if (trystart<2)
228  {
229  if (! ksconfig->dictionary().isEmpty())
230  {
231  kdDebug(750) << "using dictionary [" << ksconfig->dictionary() << "]" << endl;
232  *proc << "-d";
233  *proc << ksconfig->dictionary();
234  }
235  }
236 
237  //Note to potential debuggers: -Tlatin2 _is_ being added on the
238  // _first_ try. But, some versions of ispell will fail with this
239  // option, so tdespell tries again without it. That's why as 'ps -ax'
240  // shows "ispell -a -S ..." withou the "-Tlatin2" option.
241 
242  if ( trystart<1 ) {
243  switch ( ksconfig->encoding() )
244  {
245  case KS_E_LATIN1:
246  *proc << "-Tlatin1";
247  break;
248  case KS_E_LATIN2:
249  *proc << "-Tlatin2";
250  break;
251  case KS_E_LATIN3:
252  *proc << "-Tlatin3";
253  break;
254 
255  // add the other charsets here
256  case KS_E_LATIN4:
257  case KS_E_LATIN5:
258  case KS_E_LATIN7:
259  case KS_E_LATIN8:
260  case KS_E_LATIN9:
261  case KS_E_LATIN13:
262  // will work, if this is the default charset in the dictionary
263  kdError(750) << "charsets ISO-8859-4, -5, -7, -8, -9 and -13 not supported yet" << endl;
264  break;
265  case KS_E_LATIN15: // ISO-8859-15 (Latin 9)
266  if (ksconfig->client() == KS_CLIENT_ISPELL)
267  {
268  /*
269  * As far as I know, there are no ispell dictionary using ISO-8859-15
270  * but users have the tendency to select this encoding instead of ISO-8859-1
271  * So put ispell in ISO-8859-1 (Latin 1) mode.
272  */
273  *proc << "-Tlatin1";
274  }
275  else
276  kdError(750) << "ISO-8859-15 not supported for aspell yet." << endl;
277  break;
278  case KS_E_UTF8:
279  *proc << "-Tutf8";
280  if (ksconfig->client() == KS_CLIENT_ASPELL)
281  *proc << "--encoding=utf-8";
282  break;
283  case KS_E_KOI8U:
284  *proc << "-w'"; // add ' as a word char
285  break;
286  default:
287  break;
288  }
289  }
290 
291  // -a : pipe mode
292  // -S : sort suggestions by probable correctness
293  }
294  else // hspell and Zemberek(zpspell) doesn't need all the rest of the options
295  *proc << "-a";
296 
297  if (trystart == 0) //don't connect these multiple times
298  {
299  connect( proc, TQ_SIGNAL(receivedStderr(TDEProcess *, char *, int)),
300  this, TQ_SLOT(ispellErrors(TDEProcess *, char *, int)) );
301 
302  connect( proc, TQ_SIGNAL(processExited(TDEProcess *)),
303  this, TQ_SLOT(ispellExit (TDEProcess *)) );
304 
305  OUTPUT(KSpell2);
306  }
307 
308  if ( !proc->start() )
309  {
310  m_status = Error;
311  TQTimer::singleShot( 0, this, TQ_SLOT(emitDeath()));
312  }
313 }
314 
315 void
316 KSpell::ispellErrors( TDEProcess *, char *buffer, int buflen )
317 {
318  buffer[buflen-1] = '\0';
319  // kdDebug(750) << "ispellErrors [" << buffer << "]\n" << endl;
320 }
321 
322 void KSpell::KSpell2( TDEProcIO * )
323 
324 {
325  TQString line;
326 
327  kdDebug(750) << "KSpell::KSpell2" << endl;
328 
329  trystart = maxtrystart; //We've officially started ispell and don't want
330  //to try again if it dies.
331 
332  if ( proc->readln( line, true ) == -1 )
333  {
334  TQTimer::singleShot( 0, this, TQ_SLOT(emitDeath()) );
335  return;
336  }
337 
338 
339  if ( line[0] != '@' ) //@ indicates that ispell is working fine
340  {
341  TQTimer::singleShot( 0, this, TQ_SLOT(emitDeath()) );
342  return;
343  }
344 
345  //We want to recognize KDE in any text!
346  if ( !ignore("kde") )
347  {
348  kdDebug(750) << "@KDE was false" << endl;
349  TQTimer::singleShot( 0, this, TQ_SLOT(emitDeath()) );
350  return;
351  }
352 
353  //We want to recognize linux in any text!
354  if ( !ignore("linux") )
355  {
356  kdDebug(750) << "@Linux was false" << endl;
357  TQTimer::singleShot( 0, this, TQ_SLOT(emitDeath()) );
358  return;
359  }
360 
361  NOOUTPUT( KSpell2 );
362 
363  m_status = Running;
364  emit ready( this );
365 }
366 
367 void
368 KSpell::setUpDialog( bool reallyuseprogressbar )
369 {
370  if ( dialogsetup )
371  return;
372 
373  //Set up the dialog box
374  ksdlg = new KSpellDlg( parent, "dialog",
375  progressbar && reallyuseprogressbar, modaldlg );
376  ksdlg->setCaption( caption );
377 
378  connect( ksdlg, TQ_SIGNAL(command(int)),
379  this, TQ_SLOT(slotStopCancel(int)) );
380  connect( this, TQ_SIGNAL(progress(unsigned int)),
381  ksdlg, TQ_SLOT(slotProgress(unsigned int)) );
382 
383 #ifdef TQ_WS_X11 // FIXME(E): Implement for Qt/Embedded
384  KWin::setIcons( ksdlg->winId(), kapp->icon(), kapp->miniIcon() );
385 #endif
386  if ( modaldlg )
387  ksdlg->setFocus();
388  dialogsetup = true;
389 }
390 
391 bool KSpell::addPersonal( const TQString & word )
392 {
393  TQString qs = word.simplifyWhiteSpace();
394 
395  //we'll let ispell do the work here b/c we can
396  if ( qs.find(' ') != -1 || qs.isEmpty() ) // make sure it's a _word_
397  return false;
398 
399  qs.prepend( "*" );
400  personaldict = true;
401 
402  return proc->writeStdin( qs );
403 }
404 
405 bool KSpell::writePersonalDictionary()
406 {
407  return proc->writeStdin(TQString("#"));
408 }
409 
410 bool KSpell::ignore( const TQString & word )
411 {
412  TQString qs = word.simplifyWhiteSpace();
413 
414  //we'll let ispell do the work here b/c we can
415  if ( qs.find (' ') != -1 || qs.isEmpty() ) // make sure it's a _word_
416  return false;
417 
418  qs.prepend( "@" );
419 
420  return proc->writeStdin( qs );
421 }
422 
423 bool
424 KSpell::cleanFputsWord( const TQString & s, bool appendCR )
425 {
426  TQString qs(s);
427  bool empty = true;
428 
429  for( unsigned int i = 0; i < qs.length(); i++ )
430  {
431  //we need some punctuation for ornaments
432  if ( qs[i] != '\'' && qs[i] != '\"' && qs[i] != '-'
433  && qs[i].isPunct() || qs[i].isSpace() )
434  {
435  qs.remove(i,1);
436  i--;
437  } else {
438  if ( qs[i].isLetter() )
439  empty=false;
440  }
441  }
442 
443  // don't check empty words, otherwise synchronization will lost
444  if (empty)
445  return false;
446 
447  return proc->writeStdin( "^"+qs, appendCR );
448 }
449 
450 bool
451 KSpell::cleanFputs( const TQString & s, bool appendCR )
452 {
453  TQString qs(s);
454  unsigned l = qs.length();
455 
456  // some uses of '$' (e.g. "$0") cause ispell to skip all following text
457  for( unsigned int i = 0; i < l; ++i )
458  {
459  if( qs[i] == '$' )
460  qs[i] = ' ';
461  }
462 
463  if ( l<MAXLINELENGTH )
464  {
465  if ( qs.isEmpty() )
466  qs="";
467  return proc->writeStdin( "^"+qs, appendCR );
468  }
469  else
470  return proc->writeStdin( TQString::fromAscii( "^\n" ),appendCR );
471 }
472 
473 bool KSpell::checkWord( const TQString & buffer, bool _usedialog )
474 {
475  if (d->checking) { // don't check multiple words simultaneously
476  BufferedWord bufferedWord;
477  bufferedWord.method = Method1;
478  bufferedWord.word = buffer;
479  bufferedWord.useDialog = _usedialog;
480  d->unchecked.append( bufferedWord );
481  return true;
482  }
483  d->checking = true;
484  TQString qs = buffer.simplifyWhiteSpace();
485 
486  if ( qs.find (' ') != -1 || qs.isEmpty() ) { // make sure it's a _word_
487  d->checkNextTimer->start( 0, true );
488  return false;
489  }
491  dialog3slot = TQ_SLOT(checkWord3());
492 
493  usedialog = _usedialog;
494  setUpDialog( false );
495  if ( _usedialog )
496  {
497  emitProgress();
498  }
499  else
500  ksdlg->hide();
501 
502  TQString blank_line;
503  while (proc->readln( blank_line, true ) != -1); // eat spurious blanks
504 
505  OUTPUT(checkWord2);
506  // connect (this, TQ_SIGNAL (dialog3()), this, TQ_SLOT (checkWord3()));
507 
508  proc->writeStdin(TQString("%")); // turn off terse mode
509  proc->writeStdin( buffer ); // send the word to ispell
510 
511  return true;
512 }
513 
514 bool KSpell::checkWord( const TQString & buffer, bool _usedialog, bool suggest )
515 {
516  if (d->checking) { // don't check multiple words simultaneously
517  BufferedWord bufferedWord;
518  bufferedWord.method = Method2;
519  bufferedWord.word = buffer;
520  bufferedWord.useDialog = _usedialog;
521  bufferedWord.suggest = suggest;
522  d->unchecked.append( bufferedWord );
523  return true;
524  }
525  d->checking = true;
526  TQString qs = buffer.simplifyWhiteSpace();
527 
528  if ( qs.find (' ') != -1 || qs.isEmpty() ) { // make sure it's a _word_
529  d->checkNextTimer->start( 0, true );
530  return false;
531  }
532 
534  if ( !suggest ) {
535  dialog3slot = TQ_SLOT(checkWord3());
536  usedialog = _usedialog;
537  setUpDialog( false );
538  if ( _usedialog )
539  {
540  emitProgress();
541  }
542  else
543  ksdlg->hide();
544  }
545 
546  TQString blank_line;
547  while (proc->readln( blank_line, true ) != -1); // eat spurious blanks
548 
549  OUTPUT(checkWord2);
550  // connect (this, TQ_SIGNAL (dialog3()), this, TQ_SLOT (checkWord3()));
551 
552  proc->writeStdin(TQString("%")); // turn off terse mode
553  proc->writeStdin( buffer ); // send the word to ispell
554 
555  return true;
556 }
557 
558 void KSpell::checkWord2( TDEProcIO* )
559 {
560  TQString word;
561  TQString line;
562  proc->readln( line, true ); //get ispell's response
563 
564 /* ispell man page: "Each sentence of text input is terminated with an
565  additional blank line, indicating that ispell has completed processing
566  the input line."
567  <sanders>
568  But there can be multiple lines returned in the case of an error,
569  in this case we should consume all the output given otherwise spell checking
570  can get out of sync.
571  </sanders>
572 */
573  TQString blank_line;
574  while (proc->readln( blank_line, true ) != -1); // eat the blank line
575  NOOUTPUT(checkWord2);
576 
577  bool mistake = ( parseOneResponse(line, word, sugg) == MISTAKE );
578  if ( mistake && usedialog )
579  {
580  cwword = word;
581  dialog( word, sugg, TQ_SLOT(checkWord3()) );
582  d->checkNextTimer->start( 0, true );
583  return;
584  }
585  else if( mistake )
586  {
587  emit misspelling( word, sugg, lastpos );
588  }
589 
590  //emits a "corrected" signal _even_ if no change was made
591  //so that the calling program knows when the check is complete
592  emit corrected( word, word, 0L );
593  d->checkNextTimer->start( 0, true );
594 }
595 
596 void KSpell::checkNext()
597 {
598 // Queue words to prevent tdespell from turning into a fork bomb
599  d->checking = false;
600  if (!d->unchecked.empty()) {
601  BufferedWord buf = d->unchecked.front();
602  d->unchecked.pop_front();
603 
604  if (buf.method == Method1)
605  checkWord( buf.word, buf.useDialog );
606  else
607  checkWord( buf.word, buf.useDialog, buf.suggest );
608  }
609 }
610 
611 void KSpell::suggestWord( TDEProcIO * )
612 {
613  TQString word;
614  TQString line;
615  proc->readln( line, true ); //get ispell's response
616 
617 /* ispell man page: "Each sentence of text input is terminated with an
618  additional blank line, indicating that ispell has completed processing
619  the input line." */
620  TQString blank_line;
621  proc->readln( blank_line, true ); // eat the blank line
622 
623  NOOUTPUT(checkWord2);
624 
625  bool mistake = ( parseOneResponse(line, word, sugg) == MISTAKE );
626  if ( mistake && usedialog )
627  {
628  cwword=word;
629  dialog( word, sugg, TQ_SLOT(checkWord3()) );
630  return;
631  }
632 }
633 
634 void KSpell::checkWord3()
635 {
636  disconnect( this, TQ_SIGNAL(dialog3()), this, TQ_SLOT(checkWord3()) );
637 
638  emit corrected( cwword, replacement(), 0L );
639 }
640 
641 TQString KSpell::funnyWord( const TQString & word )
642  // composes a guess from ispell to a readable word
643  // e.g. "re+fry-y+ies" -> "refries"
644 {
645  TQString qs;
646  unsigned int i=0;
647 
648  for( i=0; word [i]!='\0';i++ )
649  {
650  if (word [i]=='+')
651  continue;
652  if (word [i]=='-')
653  {
654  TQString shorty;
655  unsigned int j;
656  int k;
657 
658  for( j = i+1; word[j] != '\0' && word[j] != '+' && word[j] != '-'; j++ )
659  shorty += word[j];
660 
661  i = j-1;
662 
663  if ( !( k = qs.findRev(shorty) ) || k != -1 )
664  qs.remove( k, shorty.length() );
665  else
666  {
667  qs += '-';
668  qs += shorty; //it was a hyphen, not a '-' from ispell
669  }
670  }
671  else
672  qs += word[i];
673  }
674 
675  return qs;
676 }
677 
678 
679 int KSpell::parseOneResponse( const TQString &buffer, TQString &word, TQStringList & sugg )
680  // buffer is checked, word and sugg are filled in
681  // returns
682  // GOOD if word is fine
683  // IGNORE if word is in ignorelist
684  // REPLACE if word is in replacelist
685  // MISTAKE if word is misspelled
686 {
687  word = "";
688  posinline=0;
689 
690  sugg.clear();
691 
692  if ( buffer[0] == '*' || buffer[0] == '+' || buffer[0] == '-' )
693  {
694  return GOOD;
695  }
696 
697  if ( buffer[0] == '&' || buffer[0] == '?' || buffer[0] == '#' )
698  {
699  int i,j;
700 
701 
702  word = buffer.mid( 2, buffer.find( ' ', 3 ) -2 );
703  //check() needs this
704  orig=word;
705 
706  if( d->m_bIgnoreTitleCase && word == word.upper() )
707  return IGNORE;
708 
709  if( d->m_bIgnoreUpperWords && word[0] == word[0].upper() )
710  {
711  TQString text = word[0] + word.right( word.length()-1 ).lower();
712  if( text == word )
713  return IGNORE;
714  }
715 
717  //We don't take advantage of ispell's ignore function because
718  //we can't interrupt ispell's output (when checking a large
719  //buffer) to add a word to _it's_ ignore-list.
720  if ( ignorelist.findIndex( word.lower() ) != -1 )
721  return IGNORE;
722 
724  TQString qs2;
725 
726  if ( buffer.find( ':' ) != -1 )
727  qs2 = buffer.left( buffer.find(':') );
728  else
729  qs2 = buffer;
730 
731  posinline = qs2.right( qs2.length()-qs2.findRev(' ') ).toInt()-1;
732 
734  TQStringList::Iterator it = replacelist.begin();
735  for( ;it != replacelist.end(); ++it, ++it ) // Skip two entries at a time.
736  {
737  if ( word == *it ) // Word matches
738  {
739  ++it;
740  word = *it; // Replace it with the next entry
741  return REPLACE;
742  }
743  }
744 
746  if ( buffer[0] != '#' )
747  {
748  TQString qs = buffer.mid( buffer.find(':')+2, buffer.length() );
749  qs += ',';
750  sugg.clear();
751  i = j = 0;
752 
753  while( (unsigned int)i < qs.length() )
754  {
755  TQString temp = qs.mid( i, (j=qs.find (',',i)) - i );
756  sugg.append( funnyWord(temp) );
757 
758  i=j+2;
759  }
760  }
761 
762  if ( (sugg.count()==1) && (sugg.first() == word) )
763  return GOOD;
764 
765  return MISTAKE;
766  }
767 
768  if ( buffer.isEmpty() ) {
769  kdDebug(750) << "Got an empty response: ignoring"<<endl;
770  return GOOD;
771  }
772 
773  kdError(750) << "HERE?: [" << buffer << "]" << endl;
774  kdError(750) << "Please report this to zack@kde.org" << endl;
775  kdError(750) << "Thank you!" << endl;
776 
777  emit done( false );
778  emit done( KSpell::origbuffer );
779  return MISTAKE;
780 }
781 
782 bool KSpell::checkList (TQStringList *_wordlist, bool _usedialog)
783  // prepare check of string list
784 {
785  wordlist=_wordlist;
786  if ((totalpos=wordlist->count())==0)
787  return false;
788  wlIt = wordlist->begin();
789  usedialog=_usedialog;
790 
791  // prepare the dialog
792  setUpDialog();
793 
794  //set the dialog signal handler
795  dialog3slot = TQ_SLOT (checkList4 ());
796 
797  proc->writeStdin (TQString("%")); // turn off terse mode & check one word at a time
798 
799  //lastpos now counts which *word number* we are at in checkListReplaceCurrent()
800  lastpos = -1;
801  checkList2();
802 
803  // when checked, TDEProcIO calls checkList3a
804  OUTPUT(checkList3a);
805 
806  return true;
807 }
808 
809 void KSpell::checkList2 ()
810  // send one word from the list to TDEProcIO
811  // invoked first time by checkList, later by checkListReplaceCurrent and checkList4
812 {
813  // send next word
814  if (wlIt != wordlist->end())
815  {
816  kdDebug(750) << "KS::cklist2 " << lastpos << ": " << *wlIt << endl;
817 
818  d->endOfResponse = false;
819  bool put;
820  lastpos++; offset=0;
821  put = cleanFputsWord (*wlIt);
822  ++wlIt;
823 
824  // when cleanFPutsWord failed (e.g. on empty word)
825  // try next word; may be this is not good for other
826  // problems, because this will make read the list up to the end
827  if (!put) {
828  checkList2();
829  }
830  }
831  else
832  // end of word list
833  {
834  NOOUTPUT(checkList3a);
835  ksdlg->hide();
836  emit done(true);
837  }
838 }
839 
840 void KSpell::checkList3a (TDEProcIO *)
841  // invoked by TDEProcIO, when data from ispell are read
842 {
843  //kdDebug(750) << "start of checkList3a" << endl;
844 
845  // don't read more data, when dialog is waiting
846  // for user interaction
847  if ( dlgon ) {
848  //kdDebug(750) << "dlgon: don't read more data" << endl;
849  return;
850  }
851 
852  int e, tempe;
853 
854  TQString word;
855  TQString line;
856 
857  do
858  {
859  tempe=proc->readln( line, true ); //get ispell's response
860 
861  //kdDebug(750) << "checkList3a: read bytes [" << tempe << "]" << endl;
862 
863 
864  if ( tempe == 0 ) {
865  d->endOfResponse = true;
866  //kdDebug(750) << "checkList3a: end of resp" << endl;
867  } else if ( tempe>0 ) {
868  if ( (e=parseOneResponse( line, word, sugg ) ) == MISTAKE ||
869  e==REPLACE )
870  {
871  dlgresult=-1;
872 
873  if ( e == REPLACE )
874  {
875  TQString old = *(--wlIt); ++wlIt;
876  dlgreplacement = word;
877  checkListReplaceCurrent();
878  // inform application
879  emit corrected( old, *(--wlIt), lastpos ); ++wlIt;
880  }
881  else if( usedialog )
882  {
883  cwword = word;
884  dlgon = true;
885  // show the dialog
886  dialog( word, sugg, TQ_SLOT(checkList4()) );
887  return;
888  }
889  else
890  {
891  d->m_bNoMisspellingsEncountered = false;
892  emit misspelling( word, sugg, lastpos );
893  }
894  }
895 
896  }
897  emitProgress (); //maybe
898 
899  // stop when empty line or no more data
900  } while (tempe > 0);
901 
902  //kdDebug(750) << "checkList3a: exit loop with [" << tempe << "]" << endl;
903 
904  // if we got an empty line, t.e. end of ispell/aspell response
905  // and the dialog isn't waiting for user interaction, send next word
906  if (d->endOfResponse && !dlgon) {
907  //kdDebug(750) << "checkList3a: send next word" << endl;
908  checkList2();
909  }
910 }
911 
912 void KSpell::checkListReplaceCurrent()
913 {
914 
915  // go back to misspelled word
916  wlIt--;
917 
918  TQString s = *wlIt;
919  s.replace(posinline+offset,orig.length(),replacement());
920  offset += replacement().length()-orig.length();
921  wordlist->insert (wlIt, s);
922  wlIt = wordlist->remove (wlIt);
923  // wlIt now points to the word after the repalced one
924 
925 }
926 
927 void KSpell::checkList4 ()
928  // evaluate dialog return, when a button was pressed there
929 {
930  dlgon=false;
931  TQString old;
932 
933  disconnect (this, TQ_SIGNAL (dialog3()), this, TQ_SLOT (checkList4()));
934 
935  //others should have been processed by dialog() already
936  switch (dlgresult)
937  {
938  case KS_REPLACE:
939  case KS_REPLACEALL:
940  kdDebug(750) << "KS: cklist4: lastpos: " << lastpos << endl;
941  old = *(--wlIt);
942  ++wlIt;
943  // replace word
944  checkListReplaceCurrent();
945  emit corrected( old, *(--wlIt), lastpos );
946  ++wlIt;
947  break;
948  case KS_CANCEL:
949  ksdlg->hide();
950  emit done( false );
951  return;
952  case KS_STOP:
953  ksdlg->hide();
954  emit done( true );
955  return;
956  case KS_CONFIG:
957  ksdlg->hide();
958  emit done( false );
959  //check( origbuffer.mid( lastpos ), true );
960  //trystart = 0;
961  //proc->disconnect();
962  //proc->kill();
963  //delete proc;
964  //proc = new TDEProcIO( codec );
965  //startIspell();
966  return;
967  };
968 
969  // read more if there is more, otherwise send next word
970  if (!d->endOfResponse) {
971  //kdDebug(750) << "checkList4: read more from response" << endl;
972  checkList3a(NULL);
973  }
974 }
975 
976 bool KSpell::check( const TQString &_buffer, bool _usedialog )
977 {
978  TQString qs;
979 
980  usedialog = _usedialog;
981  setUpDialog();
982  //set the dialog signal handler
983  dialog3slot = TQ_SLOT(check3());
984 
985  kdDebug(750) << "KS: check" << endl;
986  origbuffer = _buffer;
987  if ( ( totalpos = origbuffer.length() ) == 0 )
988  {
989  emit done( origbuffer );
990  return false;
991  }
992 
993 
994  // Torben: I corrected the \n\n problem directly in the
995  // origbuffer since I got errors otherwise
996  if ( !origbuffer.endsWith("\n\n" ) )
997  {
998  if (origbuffer.at(origbuffer.length()-1)!='\n')
999  {
1000  origbuffer+='\n';
1001  origbuffer+='\n'; //shouldn't these be removed at some point?
1002  }
1003  else
1004  origbuffer+='\n';
1005  }
1006 
1007  newbuffer = origbuffer;
1008 
1009  // TDEProcIO calls check2 when read from ispell
1010  OUTPUT( check2 );
1011  proc->writeStdin(TQString("!"));
1012 
1013  //lastpos is a position in newbuffer (it has offset in it)
1014  offset = lastlastline = lastpos = lastline = 0;
1015 
1016  emitProgress();
1017 
1018  // send first buffer line
1019  int i = origbuffer.find( '\n', 0 ) + 1;
1020  qs = origbuffer.mid( 0, i );
1021  cleanFputs( qs, false );
1022 
1023  lastline=i; //the character position, not a line number
1024 
1025  if ( usedialog )
1026  {
1027  emitProgress();
1028  }
1029  else
1030  ksdlg->hide();
1031 
1032  return true;
1033 }
1034 
1035 
1036 void KSpell::check2( TDEProcIO * )
1037  // invoked by TDEProcIO when read from ispell
1038 {
1039  int e, tempe;
1040  TQString word;
1041  TQString line;
1042  static bool recursive = false;
1043  if (recursive &&
1044  !ksdlg )
1045  {
1046  return;
1047  }
1048  recursive = true;
1049 
1050  do
1051  {
1052  tempe = proc->readln( line, false ); //get ispell's response
1053  //kdDebug(750) << "KSpell::check2 (" << tempe << "b)" << endl;
1054 
1055  if ( tempe>0 )
1056  {
1057  if ( ( e=parseOneResponse (line, word, sugg) )==MISTAKE ||
1058  e==REPLACE)
1059  {
1060  dlgresult=-1;
1061 
1062  // for multibyte encoding posinline needs correction
1063  if ((ksconfig->encoding() == KS_E_UTF8) && !d->aspellV6) {
1064  // kdDebug(750) << "line: " << origbuffer.mid(lastlastline,
1065  // lastline-lastlastline) << endl;
1066  // kdDebug(750) << "posinline uncorr: " << posinline << endl;
1067 
1068  // convert line to UTF-8, cut at pos, convert back to UCS-2
1069  // and get string length
1070  posinline = (TQString::fromUtf8(
1071  origbuffer.mid(lastlastline,lastline-lastlastline).utf8(),
1072  posinline)).length();
1073  // kdDebug(750) << "posinline corr: " << posinline << endl;
1074  }
1075 
1076  lastpos = posinline+lastlastline+offset;
1077 
1078  //orig is set by parseOneResponse()
1079 
1080  if (e==REPLACE)
1081  {
1082  dlgreplacement=word;
1083  emit corrected( orig, replacement(), lastpos );
1084  offset += replacement().length()-orig.length();
1085  newbuffer.replace( lastpos, orig.length(), word );
1086  }
1087  else //MISTAKE
1088  {
1089  cwword = word;
1090  //kdDebug(750) << "(Before dialog) word=[" << word << "] cwword =[" << cwword << "]\n" << endl;
1091  if ( usedialog ) {
1092  // show the word in the dialog
1093  dialog( word, sugg, TQ_SLOT(check3()) );
1094  } else {
1095  // No dialog, just emit misspelling and continue
1096  d->m_bNoMisspellingsEncountered = false;
1097  emit misspelling( word, sugg, lastpos );
1098  dlgresult = KS_IGNORE;
1099  check3();
1100  }
1101  recursive = false;
1102  return;
1103  }
1104  }
1105 
1106  }
1107 
1108  emitProgress(); //maybe
1109 
1110  } while( tempe>0 );
1111 
1112  if ( tempe == -1 ) { //we were called, but no data seems to be ready...
1113  // Make sure we don't get called directly again and make sure we do get
1114  // called when new data arrives.
1115  NOOUTPUT( check2 );
1116  proc->enableReadSignals(true);
1117  OUTPUT( check2 );
1118  recursive = false;
1119  return;
1120  }
1121 
1122  proc->ackRead();
1123 
1124  //If there is more to check, then send another line to ISpell.
1125  if ( (unsigned int)lastline < origbuffer.length() )
1126  {
1127  int i;
1128  TQString qs;
1129 
1130  //kdDebug(750) << "[EOL](" << tempe << ")[" << temp << "]" << endl;
1131 
1132  lastpos = (lastlastline=lastline) + offset; //do we really want this?
1133  i = origbuffer.find('\n', lastline) + 1;
1134  qs = origbuffer.mid( lastline, i-lastline );
1135  cleanFputs( qs, false );
1136  lastline = i;
1137  recursive = false;
1138  return;
1139  }
1140  else
1141  //This is the end of it all
1142  {
1143  ksdlg->hide();
1144  // kdDebug(750) << "check2() done" << endl;
1145  newbuffer.truncate( newbuffer.length()-2 );
1146  emitProgress();
1147  emit done( newbuffer );
1148  }
1149  recursive = false;
1150 }
1151 
1152 void KSpell::check3 ()
1153  // evaluates the return value of the dialog
1154 {
1155  disconnect (this, TQ_SIGNAL (dialog3()), this, TQ_SLOT (check3()));
1156  kdDebug(750) << "check3 [" << cwword << "] [" << replacement() << "] " << dlgresult << endl;
1157 
1158  //others should have been processed by dialog() already
1159  switch (dlgresult)
1160  {
1161  case KS_REPLACE:
1162  case KS_REPLACEALL:
1163  offset+=replacement().length()-cwword.length();
1164  newbuffer.replace (lastpos, cwword.length(),
1165  replacement());
1166  emit corrected (dlgorigword, replacement(), lastpos);
1167  break;
1168  case KS_CANCEL:
1169  // kdDebug(750) << "canceled\n" << endl;
1170  ksdlg->hide();
1171  emit done( origbuffer );
1172  return;
1173  case KS_CONFIG:
1174  ksdlg->hide();
1175  emit done( origbuffer );
1176  KMessageBox::information( 0, i18n("You have to restart the dialog for changes to take effect") );
1177  //check( origbuffer.mid( lastpos ), true );
1178  return;
1179  case KS_STOP:
1180  ksdlg->hide();
1181  //buffer=newbuffer);
1182  emitProgress();
1183  emit done (newbuffer);
1184  return;
1185  };
1186 
1187  proc->ackRead();
1188 }
1189 
1190 void
1191 KSpell::slotStopCancel (int result)
1192 {
1193  if (dialogwillprocess)
1194  return;
1195 
1196  kdDebug(750) << "KSpell::slotStopCancel [" << result << "]" << endl;
1197 
1198  if (result==KS_STOP || result==KS_CANCEL)
1199  if (!dialog3slot.isEmpty())
1200  {
1201  dlgresult=result;
1202  connect (this, TQ_SIGNAL (dialog3()), this, dialog3slot.ascii());
1203  emit dialog3();
1204  }
1205 }
1206 
1207 
1208 void KSpell::dialog( const TQString & word, TQStringList & sugg, const char *_slot )
1209 {
1210  dlgorigword = word;
1211 
1212  dialog3slot = _slot;
1213  dialogwillprocess = true;
1214  connect( ksdlg, TQ_SIGNAL(command(int)), this, TQ_SLOT(dialog2(int)) );
1215  TQString tmpBuf = newbuffer;
1216  kdDebug(750)<<" position = "<<lastpos<<endl;
1217 
1218  // extract a context string, replace all characters which might confuse
1219  // the RichText display and highlight the possibly wrong word
1220  TQString marker( "_MARKER_" );
1221  tmpBuf.replace( lastpos, word.length(), marker );
1222  TQString context = tmpBuf.mid(TQMAX(lastpos-18,0), 2*18+marker.length());
1223  context.replace( '\n',TQString::fromLatin1(" "));
1224  context.replace( '<', TQString::fromLatin1("&lt;") );
1225  context.replace( '>', TQString::fromLatin1("&gt;") );
1226  context.replace( marker, TQString::fromLatin1("<b>%1</b>").arg( word ) );
1227  context = "<qt>" + context + "</qt>";
1228 
1229  ksdlg->init( word, &sugg, context );
1230  d->m_bNoMisspellingsEncountered = false;
1231  emit misspelling( word, sugg, lastpos );
1232 
1233  emitProgress();
1234  ksdlg->show();
1235 }
1236 
1237 void KSpell::dialog2( int result )
1238 {
1239  TQString qs;
1240 
1241  disconnect( ksdlg, TQ_SIGNAL(command(int)), this, TQ_SLOT(dialog2(int)) );
1242  dialogwillprocess = false;
1243  dlgresult = result;
1244  ksdlg->standby();
1245 
1246  dlgreplacement = ksdlg->replacement();
1247 
1248  //process result here
1249  switch ( dlgresult )
1250  {
1251  case KS_IGNORE:
1252  emit ignoreword( dlgorigword );
1253  break;
1254  case KS_IGNOREALL:
1255  // would be better to lower case only words with beginning cap
1256  ignorelist.prepend( dlgorigword.lower() );
1257  emit ignoreall( dlgorigword );
1258  break;
1259  case KS_ADD:
1260  addPersonal( dlgorigword );
1261  personaldict = true;
1262  emit addword( dlgorigword );
1263  // adding to pesonal dict takes effect at the next line, not the current
1264  ignorelist.prepend( dlgorigword.lower() );
1265  break;
1266  case KS_REPLACEALL:
1267  {
1268  replacelist.append( dlgorigword );
1269  TQString _replacement = replacement();
1270  replacelist.append( _replacement );
1271  emit replaceall( dlgorigword , _replacement );
1272  }
1273  break;
1274  case KS_SUGGEST:
1275  checkWord( ksdlg->replacement(), false, true );
1276  return;
1277  break;
1278  }
1279 
1280  connect( this, TQ_SIGNAL(dialog3()), this, dialog3slot.ascii() );
1281  emit dialog3();
1282 }
1283 
1284 
1285 KSpell::~KSpell()
1286 {
1287  delete proc;
1288  delete ksconfig;
1289  delete ksdlg;
1290  delete d->checkNextTimer;
1291  delete d;
1292 }
1293 
1294 
1295 KSpellConfig KSpell::ksConfig() const
1296 {
1297  ksconfig->setIgnoreList(ignorelist);
1298  ksconfig->setReplaceAllList(replacelist);
1299  return *ksconfig;
1300 }
1301 
1302 void KSpell::cleanUp()
1303 {
1304  if ( m_status == Cleaning )
1305  return; // Ignore
1306 
1307  if ( m_status == Running )
1308  {
1309  if ( personaldict )
1310  writePersonalDictionary();
1311  m_status = Cleaning;
1312  }
1313  proc->closeStdin();
1314 }
1315 
1316 void KSpell::ispellExit( TDEProcess* )
1317 {
1318  kdDebug() << "KSpell::ispellExit() " << m_status << endl;
1319 
1320  if ( (m_status == Starting) && (trystart < maxtrystart) )
1321  {
1322  trystart++;
1323  startIspell();
1324  return;
1325  }
1326 
1327  if ( m_status == Starting )
1328  m_status = Error;
1329  else if (m_status == Cleaning)
1330  m_status = d->m_bNoMisspellingsEncountered ? FinishedNoMisspellingsEncountered : Finished;
1331  else if ( m_status == Running )
1332  m_status = Crashed;
1333  else // Error, Finished, Crashed
1334  return; // Dead already
1335 
1336  kdDebug(750) << "Death" << endl;
1337  TQTimer::singleShot( 0, this, TQ_SLOT(emitDeath()) );
1338 }
1339 
1340 // This is always called from the event loop to make
1341 // sure that the receiver can safely delete the
1342 // KSpell object.
1343 void KSpell::emitDeath()
1344 {
1345  bool deleteMe = autoDelete; // Can't access object after next call!
1346  emit death();
1347  if ( deleteMe )
1348  deleteLater();
1349 }
1350 
1351 void KSpell::setProgressResolution (unsigned int res)
1352 {
1353  progres=res;
1354 }
1355 
1356 void KSpell::emitProgress ()
1357 {
1358  uint nextprog = (uint) (100.*lastpos/(double)totalpos);
1359 
1360  if ( nextprog >= curprog )
1361  {
1362  curprog = nextprog;
1363  emit progress( curprog );
1364  }
1365 }
1366 
1367 void KSpell::moveDlg( int x, int y )
1368 {
1369  TQPoint pt( x,y ), pt2;
1370  pt2 = parent->mapToGlobal( pt );
1371  ksdlg->move( pt2.x(),pt2.y() );
1372 }
1373 
1374 void KSpell::setIgnoreUpperWords(bool _ignore)
1375 {
1376  d->m_bIgnoreUpperWords=_ignore;
1377 }
1378 
1379 void KSpell::setIgnoreTitleCase(bool _ignore)
1380 {
1381  d->m_bIgnoreTitleCase=_ignore;
1382 }
1383 // --------------------------------------------------
1384 // Stuff for modal (blocking) spell checking
1385 //
1386 // Written by Torben Weis <weis@kde.org>. So please
1387 // send bug reports regarding the modal stuff to me.
1388 // --------------------------------------------------
1389 
1390 int
1391 KSpell::modalCheck( TQString& text )
1392 {
1393  return modalCheck( text,0 );
1394 }
1395 
1396 int
1397 KSpell::modalCheck( TQString& text, KSpellConfig* _kcs )
1398 {
1399  modalreturn = 0;
1400  modaltext = text;
1401 
1402  KSpell* spell = new KSpell( 0L, i18n("Spell Checker"), 0 ,
1403  0, _kcs, true, true );
1404 
1405  while (spell->status()!=Finished)
1406  kapp->processEvents();
1407 
1408  text = modaltext;
1409 
1410  delete spell;
1411  return modalreturn;
1412 }
1413 
1414 void KSpell::slotSpellCheckerCorrected( const TQString & oldText, const TQString & newText, unsigned int pos )
1415 {
1416  modaltext=modaltext.replace(pos,oldText.length(),newText);
1417 }
1418 
1419 
1420 void KSpell::slotModalReady()
1421 {
1422  //kdDebug() << tqApp->loopLevel() << endl;
1423  //kdDebug(750) << "MODAL READY------------------" << endl;
1424 
1425  Q_ASSERT( m_status == Running );
1426  connect( this, TQ_SIGNAL( done( const TQString & ) ),
1427  this, TQ_SLOT( slotModalDone( const TQString & ) ) );
1428  TQObject::connect( this, TQ_SIGNAL( corrected( const TQString&, const TQString&, unsigned int ) ),
1429  this, TQ_SLOT( slotSpellCheckerCorrected( const TQString&, const TQString &, unsigned int ) ) );
1430  TQObject::connect( this, TQ_SIGNAL( death() ),
1431  this, TQ_SLOT( slotModalSpellCheckerFinished( ) ) );
1432  check( modaltext );
1433 }
1434 
1435 void KSpell::slotModalDone( const TQString &/*_buffer*/ )
1436 {
1437  //kdDebug(750) << "MODAL DONE " << _buffer << endl;
1438  //modaltext = _buffer;
1439  cleanUp();
1440 
1441  //kdDebug() << "ABOUT TO EXIT LOOP" << endl;
1442  //tqApp->exit_loop();
1443 
1444  //modalWidgetHack->close(true);
1445  slotModalSpellCheckerFinished();
1446 }
1447 
1448 void KSpell::slotModalSpellCheckerFinished( )
1449 {
1450  modalreturn=(int)this->status();
1451 }
1452 
1453 void KSpell::initialize( TQWidget *_parent, const TQString &_caption,
1454  TQObject *obj, const char *slot, KSpellConfig *_ksc,
1455  bool _progressbar, bool _modal, SpellerType type )
1456 {
1457  d = new KSpellPrivate;
1458 
1459  d->m_bIgnoreUpperWords =false;
1460  d->m_bIgnoreTitleCase =false;
1461  d->m_bNoMisspellingsEncountered = true;
1462  d->type = type;
1463  d->checking = false;
1464  d->aspellV6 = false;
1465  d->checkNextTimer = new TQTimer( this );
1466  connect( d->checkNextTimer, TQ_SIGNAL( timeout() ),
1467  this, TQ_SLOT( checkNext() ));
1468  autoDelete = false;
1469  modaldlg = _modal;
1470  progressbar = _progressbar;
1471 
1472  proc = 0;
1473  ksconfig = 0;
1474  ksdlg = 0;
1475  lastpos = 0;
1476 
1477  //won't be using the dialog in ksconfig, just the option values
1478  if ( _ksc )
1479  ksconfig = new KSpellConfig( *_ksc );
1480  else
1481  ksconfig = new KSpellConfig;
1482 
1483  codec = 0;
1484  switch ( ksconfig->encoding() )
1485  {
1486  case KS_E_LATIN1:
1487  codec = TQTextCodec::codecForName("ISO 8859-1");
1488  break;
1489  case KS_E_LATIN2:
1490  codec = TQTextCodec::codecForName("ISO 8859-2");
1491  break;
1492  case KS_E_LATIN3:
1493  codec = TQTextCodec::codecForName("ISO 8859-3");
1494  break;
1495  case KS_E_LATIN4:
1496  codec = TQTextCodec::codecForName("ISO 8859-4");
1497  break;
1498  case KS_E_LATIN5:
1499  codec = TQTextCodec::codecForName("ISO 8859-5");
1500  break;
1501  case KS_E_LATIN7:
1502  codec = TQTextCodec::codecForName("ISO 8859-7");
1503  break;
1504  case KS_E_LATIN8:
1505  codec = TQTextCodec::codecForName("ISO 8859-8-i");
1506  break;
1507  case KS_E_LATIN9:
1508  codec = TQTextCodec::codecForName("ISO 8859-9");
1509  break;
1510  case KS_E_LATIN13:
1511  codec = TQTextCodec::codecForName("ISO 8859-13");
1512  break;
1513  case KS_E_LATIN15:
1514  codec = TQTextCodec::codecForName("ISO 8859-15");
1515  break;
1516  case KS_E_UTF8:
1517  codec = TQTextCodec::codecForName("UTF-8");
1518  break;
1519  case KS_E_KOI8R:
1520  codec = TQTextCodec::codecForName("KOI8-R");
1521  break;
1522  case KS_E_KOI8U:
1523  codec = TQTextCodec::codecForName("KOI8-U");
1524  break;
1525  case KS_E_CP1251:
1526  codec = TQTextCodec::codecForName("CP1251");
1527  break;
1528  case KS_E_CP1255:
1529  codec = TQTextCodec::codecForName("CP1255");
1530  break;
1531  default:
1532  break;
1533  }
1534 
1535  kdDebug(750) << __FILE__ << ":" << __LINE__ << " Codec = " << (codec ? codec->name() : "<default>") << endl;
1536 
1537  // copy ignore list from ksconfig
1538  ignorelist += ksconfig->ignoreList();
1539 
1540  replacelist += ksconfig->replaceAllList();
1541  texmode=dlgon=false;
1542  m_status = Starting;
1543  dialogsetup = false;
1544  progres=10;
1545  curprog=0;
1546 
1547  dialogwillprocess = false;
1548  dialog3slot = TQString::null;
1549 
1550  personaldict = false;
1551  dlgresult = -1;
1552 
1553  caption = _caption;
1554 
1555  parent = _parent;
1556 
1557  trystart = 0;
1558  maxtrystart = 2;
1559 
1560  if ( obj && slot )
1561  // caller wants to know when tdespell is ready
1562  connect( this, TQ_SIGNAL(ready(KSpell *)), obj, slot);
1563  else
1564  // Hack for modal spell checking
1565  connect( this, TQ_SIGNAL(ready(KSpell *)), this, TQ_SLOT(slotModalReady()) );
1566 
1567  proc = new TDEProcIO( codec );
1568 
1569  startIspell();
1570 }
1571 
1572 TQString KSpell::modaltext;
1573 int KSpell::modalreturn = 0;
1574 TQWidget* KSpell::modalWidgetHack = 0;
1575 
1576 #include "tdespell.moc"
1577 
KMessageBox::information
static void information(TQWidget *parent, const TQString &text, const TQString &caption=TQString::null, const TQString &dontShowAgainName=TQString::null, int options=Notify)
Display an "Information" dialog.
Definition: tdemessagebox.cpp:883
KSpellConfig
A configuration class/dialog for KSpell.
Definition: ksconfig.h:88
KSpellConfig::setIgnoreList
void setIgnoreList(TQStringList _ignorelist)
@sect Options setting routines.
Definition: ksconfig.cpp:1010
KSpellConfig::setReplaceAllList
void setReplaceAllList(TQStringList _replaceAllList)
The _replaceAllList contains word you like that replace word.
Definition: ksconfig.cpp:1023
KSpellConfig::noRootAffix
bool noRootAffix() const
Options reading routines.
Definition: ksconfig.cpp:855
KSpellConfig::client
int client() const
Spell checker client, see KSpellClients.
Definition: ksconfig.cpp:848
KSpell
KDE Spellchecker
Definition: tdespell.h:47
KSpell::corrected
void corrected(const TQString &originalword, const TQString &newword, unsigned int pos)
Emitted after the "Replace" or "Replace All" buttons of the dialog was pressed, or if the word was co...
KSpell::status
spellStatus status() const
Returns the status of KSpell.
Definition: tdespell.h:130
KSpell::ignore
virtual bool ignore(const TQString &word)
Tells ISpell/ASpell to ignore this word for the life of this KSpell instance.
Definition: tdespell.cpp:410
KSpell::ready
void ready(KSpell *)
Emitted after KSpell has verified that ISpell/ASpell is running and working properly.
KSpell::KSpell
KSpell(TQWidget *parent, const TQString &caption, TQObject *receiver, const char *slot, KSpellConfig *kcs=0, bool progressbar=true, bool modal=false)
Starts the spellchecker.
Definition: tdespell.cpp:107
KSpell::ignoreword
void ignoreword(const TQString &originalword)
Emitted when the user pressed "Ignore" in the dialog.
KSpell::heightDlg
int heightDlg() const
Returns the height of the dialog box.
Definition: tdespell.cpp:125
KSpell::ignoreall
void ignoreall(const TQString &originalword)
Emitted when the user pressed "Ignore All" in the dialog.
KSpell::~KSpell
virtual ~KSpell()
The destructor instructs ISpell/ASpell to write out the personal dictionary and then terminates ISpel...
Definition: tdespell.cpp:1285
KSpell::checkWord
virtual bool checkWord(const TQString &_buffer, bool usedialog=false)
Spellchecks a single word.
Definition: tdespell.cpp:473
KSpell::hide
void hide()
Hides the dialog box.
Definition: tdespell.cpp:123
KSpell::setIgnoreUpperWords
void setIgnoreUpperWords(bool b)
Call setIgnoreUpperWords(true) to tell the spell-checker to ignore words that are completely uppercas...
Definition: tdespell.cpp:1374
KSpell::misspelling
void misspelling(const TQString &originalword, const TQStringList &suggestions, unsigned int pos)
Emitted whenever a misspelled word is found by check() or by checkWord().
KSpell::ksConfig
KSpellConfig ksConfig() const
Definition: tdespell.cpp:1295
KSpell::moveDlg
void moveDlg(int x, int y)
Moves the dialog.
Definition: tdespell.cpp:1367
KSpell::modalCheck
static int modalCheck(TQString &text) TDE_DEPRECATED
Definition: tdespell.cpp:1391
KSpell::setIgnoreTitleCase
void setIgnoreTitleCase(bool b)
Call setIgnoreTitleCase(true) to tell the spell-checker to ignore words with a 'title' case,...
Definition: tdespell.cpp:1379
KSpell::cleanUp
virtual void cleanUp()
Cleans up ISpell.
Definition: tdespell.cpp:1302
KSpell::setProgressResolution
void setProgressResolution(unsigned int res)
Sets the resolution (in percent) of the progress() signals.
Definition: tdespell.cpp:1351
KSpell::widthDlg
int widthDlg() const
Returns the width of the dialog box.
Definition: tdespell.cpp:126
KSpell::SpellerType
SpellerType
These are possible types of documents which the spell checker can check.
Definition: tdespell.h:80
KSpell::check
virtual bool check(const TQString &_buffer, bool usedialog=true)
Spellchecks a buffer of many words in plain text format.
Definition: tdespell.cpp:976
KSpell::replaceall
void replaceall(const TQString &origword, const TQString &replacement)
Emitted when the user pressed "ReplaceAll" in the dialog.
KSpell::addPersonal
virtual bool addPersonal(const TQString &word)
Adds a word to the user's personal dictionary.
Definition: tdespell.cpp:391
KSpell::progress
void progress(unsigned int i)
Emitted during a check().
KSpell::modaldlg
bool modaldlg
Used for modalCheck.
Definition: tdespell.h:541
KSpell::addword
void addword(const TQString &originalword)
Emitted when the user pressed "Add" in the dialog.
KSpell::checkList
virtual bool checkList(TQStringList *_wordlist, bool usedialog=true)
Spellchecks a list of words.
Definition: tdespell.cpp:782
KSpell::done
void done(const TQString &buffer)
Emitted when check() is done.
KSpell::death
void death()
Emitted on terminal errors and after clean up.
KWin::setIcons
static void setIcons(WId win, const TQPixmap &icon, const TQPixmap &miniIcon)
TDEProcIO
TDEProcIO::resetAll
void resetAll()
TDEProcIO::readln
int readln(TQString &line, bool autoAck=true, bool *partial=0)
TDEProcIO::enableReadSignals
void enableReadSignals(bool enable)
TDEProcIO::writeStdin
bool writeStdin(const TQString &line, bool appendnewline=true)
TDEProcIO::start
bool start(RunMode runmode=NotifyOnExit, bool includeStderr=false)
TDEProcIO::ackRead
void ackRead()
TDEProcess
TDEProcess::closeStdin
bool closeStdin()
endl
kndbgstream & endl(kndbgstream &s)
kdError
kdbgstream kdError(int area=0)
kdDebug
kdbgstream kdDebug(int area=0)
KDE::version
unsigned int version()
tdelocale.h

tdeui

Skip menu "tdeui"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

tdeui

Skip menu "tdeui"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeui by doxygen 1.9.1
This website is maintained by Timothy Pearson.