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

tdespell2

  • tdespell2
  • ui
dialog.cpp
1 /*
2  * dialog.cpp
3  *
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 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 "dialog.h"
22 #include "tdespell2ui.h"
23 
24 #include "backgroundchecker.h"
25 #include "broker.h"
26 #include "filter.h"
27 #include "dictionary.h"
28 #include "settings.h"
29 
30 #include <tdeconfig.h>
31 #include <tdelocale.h>
32 #include <kdebug.h>
33 
34 #include <tqlistview.h>
35 #include <tqpushbutton.h>
36 #include <tqcombobox.h>
37 #include <tqlineedit.h>
38 #include <tqlabel.h>
39 #include <tqtimer.h>
40 #include <tqdict.h>
41 
42 namespace KSpell2
43 {
44 
45 //to initially disable sorting in the suggestions listview
46 #define NONSORTINGCOLUMN 2
47 
48 class Dialog::Private
49 {
50 public:
51  KSpell2UI *ui;
52  TQString originalBuffer;
53  BackgroundChecker *checker;
54 
55  Word currentWord;
56  TQMap<TQString, TQString> replaceAllMap;
57 };
58 
59 Dialog::Dialog( BackgroundChecker *checker,
60  TQWidget *parent, const char *name )
61  : KDialogBase( parent, name, true,
62  i18n( "Check Spelling" ),
63  Help|Cancel|User1, Cancel, true,
64  i18n( "&Finished" ) )
65 {
66  d = new Private;
67 
68  d->checker = checker;
69 
70  initGui();
71  initConnections();
72  setMainWidget( static_cast<TQWidget*>(d->ui) );
73 }
74 
75 Dialog::~Dialog()
76 {
77  delete d;
78 }
79 
80 void Dialog::initConnections()
81 {
82  connect( d->ui->m_addBtn, TQ_SIGNAL(clicked()),
83  TQ_SLOT(slotAddWord()) );
84  connect( d->ui->m_replaceBtn, TQ_SIGNAL(clicked()),
85  TQ_SLOT(slotReplaceWord()) );
86  connect( d->ui->m_replaceAllBtn, TQ_SIGNAL(clicked()),
87  TQ_SLOT(slotReplaceAll()) );
88  connect( d->ui->m_skipBtn, TQ_SIGNAL(clicked()),
89  TQ_SLOT(slotSkip()) );
90  connect( d->ui->m_skipAllBtn, TQ_SIGNAL(clicked()),
91  TQ_SLOT(slotSkipAll()) );
92  connect( d->ui->m_suggestBtn, TQ_SIGNAL(clicked()),
93  TQ_SLOT(slotSuggest()) );
94  connect( d->ui->m_language, TQ_SIGNAL(activated(const TQString&)),
95  TQ_SLOT(slotChangeLanguage(const TQString&)) );
96  connect( d->ui->m_suggestions, TQ_SIGNAL(selectionChanged(TQListViewItem*)),
97  TQ_SLOT(slotSelectionChanged(TQListViewItem*)) );
98  connect( d->checker, TQ_SIGNAL(misspelling(const TQString&, int)),
99  TQ_SIGNAL(misspelling(const TQString&, int)) );
100  connect( d->checker, TQ_SIGNAL(misspelling(const TQString&, int)),
101  TQ_SLOT(slotMisspelling(const TQString&, int)) );
102  connect( d->checker, TQ_SIGNAL(done()),
103  TQ_SLOT(slotDone()) );
104  connect( d->ui->m_suggestions, TQ_SIGNAL(doubleClicked(TQListViewItem*, const TQPoint&, int)),
105  TQ_SLOT( slotReplaceWord() ) );
106  connect( this, TQ_SIGNAL(user1Clicked()), this, TQ_SLOT(slotFinished()) );
107  connect( this, TQ_SIGNAL(cancelClicked()),this, TQ_SLOT(slotCancel()) );
108  connect( d->ui->m_replacement, TQ_SIGNAL(returnPressed()), this, TQ_SLOT(slotReplaceWord()) );
109  connect( d->ui->m_autoCorrect, TQ_SIGNAL(clicked()),
110  TQ_SLOT(slotAutocorrect()) );
111  // button use by kword/kpresenter
112  // hide by default
113  d->ui->m_autoCorrect->hide();
114 }
115 
116 void Dialog::initGui()
117 {
118  d->ui = new KSpell2UI( this );
119  d->ui->m_suggestions->setSorting( NONSORTINGCOLUMN );
120  d->ui->m_language->clear();
121  d->ui->m_language->insertStringList( d->checker->broker()->languages() );
122  for ( int i = 0; !d->ui->m_language->text( i ).isNull(); ++i ) {
123  TQString ct = d->ui->m_language->text( i );
124  if ( ct == d->checker->broker()->settings()->defaultLanguage() ) {
125  d->ui->m_language->setCurrentItem( i );
126  break;
127  }
128  }
129 }
130 
131 void Dialog::activeAutoCorrect( bool _active )
132 {
133  if ( _active )
134  d->ui->m_autoCorrect->show();
135  else
136  d->ui->m_autoCorrect->hide();
137 }
138 
139 void Dialog::slotAutocorrect()
140 {
141  kdDebug()<<"void Dialog::slotAutocorrect()\n";
142  emit autoCorrect(d->currentWord.word, d->ui->m_replacement->text() );
143  slotReplaceWord();
144 }
145 
146 void Dialog::slotFinished()
147 {
148  kdDebug()<<"void Dialog::slotFinished() \n";
149  emit stop();
150  //FIXME: should we emit done here?
151  emit done( d->checker->filter()->buffer() );
152  accept();
153 }
154 
155 void Dialog::slotCancel()
156 {
157  kdDebug()<<"void Dialog::slotCancel() \n";
158  emit cancel();
159  reject();
160 }
161 
162 TQString Dialog::originalBuffer() const
163 {
164  return d->originalBuffer;
165 }
166 
167 TQString Dialog::buffer() const
168 {
169  return d->checker->filter()->buffer();
170 }
171 
172 void Dialog::setBuffer( const TQString& buf )
173 {
174  d->originalBuffer = buf;
175 }
176 
177 void Dialog::setFilter( Filter *filter )
178 {
179  filter->setBuffer( d->checker->filter()->buffer() );
180  d->checker->setFilter( filter );
181 }
182 
183 void Dialog::updateDialog( const TQString& word )
184 {
185  d->ui->m_unknownWord->setText( word );
186  d->ui->m_contextLabel->setText( d->checker->filter()->context() );
187  TQStringList suggs = d->checker->suggest( word );
188  d->ui->m_replacement->setText( suggs.first() );
189  fillSuggestions( suggs );
190 }
191 
192 void Dialog::show()
193 {
194  kdDebug()<<"Showing dialog"<<endl;
195  if ( d->originalBuffer.isEmpty() )
196  d->checker->start();
197  else
198  d->checker->checkText( d->originalBuffer );
199 }
200 
201 void Dialog::slotAddWord()
202 {
203  d->checker->addWord( d->currentWord.word );
204  d->checker->continueChecking();
205 }
206 
207 void Dialog::slotReplaceWord()
208 {
209  emit replace( d->currentWord.word, d->currentWord.start,
210  d->ui->m_replacement->text() );
211  d->checker->filter()->replace( d->currentWord, d->ui->m_replacement->text() );
212  d->checker->continueChecking();
213 }
214 
215 void Dialog::slotReplaceAll()
216 {
217  d->replaceAllMap.insert( d->currentWord.word,
218  d->ui->m_replacement->text() );
219  slotReplaceWord();
220 }
221 
222 void Dialog::slotSkip()
223 {
224  d->checker->continueChecking();
225 }
226 
227 void Dialog::slotSkipAll()
228 {
229  //### do we want that or should we have a d->ignoreAll list?
230  d->checker->broker()->settings()->addWordToIgnore( d->ui->m_replacement->text() );
231  d->checker->continueChecking();
232 }
233 
234 void Dialog::slotSuggest()
235 {
236  TQStringList suggs = d->checker->suggest( d->ui->m_replacement->text() );
237  fillSuggestions( suggs );
238 }
239 
240 void Dialog::slotChangeLanguage( const TQString& lang )
241 {
242  d->checker->changeLanguage( lang );
243  slotSuggest();
244 }
245 
246 void Dialog::slotSelectionChanged( TQListViewItem *item )
247 {
248  d->ui->m_replacement->setText( item->text( 0 ) );
249 }
250 
251 void Dialog::fillSuggestions( const TQStringList& suggs )
252 {
253  d->ui->m_suggestions->clear();
254  for ( TQStringList::ConstIterator it = suggs.begin(); it != suggs.end(); ++it ) {
255  new TQListViewItem( d->ui->m_suggestions, d->ui->m_suggestions->firstChild(),
256  *it );
257  }
258 }
259 
260 void Dialog::slotMisspelling(const TQString& word, int start )
261 {
262  kdDebug()<<"Dialog misspelling!!"<<endl;
263  d->currentWord = Word( word, start );
264  if ( d->replaceAllMap.contains( word ) ) {
265  d->ui->m_replacement->setText( d->replaceAllMap[ word ] );
266  slotReplaceWord();
267  } else {
268  updateDialog( word );
269  }
270  KDialogBase::show();
271 }
272 
273 void Dialog::slotDone()
274 {
275  kdDebug()<<"Dialog done!"<<endl;
276  emit done( d->checker->filter()->buffer() );
277  accept();
278 }
279 
280 }
281 
282 #include "dialog.moc"
KSpell2
tdespell_hspellclient.h
Definition: backgroundchecker.h:29

tdespell2

Skip menu "tdespell2"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members

tdespell2

Skip menu "tdespell2"
  • 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 tdespell2 by doxygen 1.9.1
This website is maintained by Timothy Pearson.