kspelldlg.cpp
00001 /* This file is part of the KDE libraries 00002 Copyright (C) 1997 David Sweet <dsweet@kde.org> 00003 Copyright (C) 2000 Rik Hemsley <rik@kde.org> 00004 Copyright (C) 2000-2001 Wolfram Diestel <wolfram@steloj.de> 00005 Copyright (C) 2003 Zack Rusin <zack@kde.org> 00006 00007 This library is free software; you can redistribute it and/or 00008 modify it under the terms of the GNU Library General Public 00009 License version 2 as published by the Free Software Foundation. 00010 00011 This library is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 Library General Public License for more details. 00015 00016 You should have received a copy of the GNU Library General Public License 00017 along with this library; see the file COPYING.LIB. If not, write to 00018 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00019 Boston, MA 02110-1301, USA. 00020 */ 00021 00022 #include <tqstringlist.h> 00023 #include <tqpushbutton.h> 00024 #include <tqlabel.h> 00025 #include <tqlayout.h> 00026 00027 #include <kapplication.h> 00028 #include <klocale.h> 00029 #include <klistbox.h> 00030 #include <kcombobox.h> 00031 #include <klistview.h> 00032 #include <klineedit.h> 00033 #include <kpushbutton.h> 00034 #include <kprogress.h> 00035 #include <kbuttonbox.h> 00036 #include <kdebug.h> 00037 00038 #include "ksconfig.h" 00039 #include "kspelldlg.h" 00040 #include "kspellui.h" 00041 00042 //to initially disable sorting in the suggestions listview 00043 #define NONSORTINGCOLUMN 2 00044 00045 class KSpellDlg::KSpellDlgPrivate { 00046 public: 00047 KSpellUI* ui; 00048 KSpellConfig* spellConfig; 00049 }; 00050 00051 KSpellDlg::KSpellDlg( TQWidget * parent, const char * name, bool _progressbar, bool _modal ) 00052 : KDialogBase( 00053 parent, name, _modal, i18n("Check Spelling"), Help|Cancel|User1, 00054 Cancel, true, i18n("&Finished") 00055 ), 00056 progressbar( false ) 00057 { 00058 Q_UNUSED( _progressbar ); 00059 d = new KSpellDlgPrivate; 00060 d->ui = new KSpellUI( this ); 00061 setMainWidget( d->ui ); 00062 00063 connect( d->ui->m_replaceBtn, TQT_SIGNAL(clicked()), 00064 this, TQT_SLOT(replace())); 00065 connect( this, TQT_SIGNAL(ready(bool)), 00066 d->ui->m_replaceBtn, TQT_SLOT(setEnabled(bool)) ); 00067 00068 connect( d->ui->m_replaceAllBtn, TQT_SIGNAL(clicked()), this, TQT_SLOT(replaceAll())); 00069 connect(this, TQT_SIGNAL(ready(bool)), d->ui->m_replaceAllBtn, TQT_SLOT(setEnabled(bool))); 00070 00071 connect( d->ui->m_skipBtn, TQT_SIGNAL(clicked()), this, TQT_SLOT(ignore())); 00072 connect( this, TQT_SIGNAL(ready(bool)), d->ui->m_skipBtn, TQT_SLOT(setEnabled(bool))); 00073 00074 connect( d->ui->m_skipAllBtn, TQT_SIGNAL(clicked()), this, TQT_SLOT(ignoreAll())); 00075 connect( this, TQT_SIGNAL(ready(bool)), d->ui->m_skipAllBtn, TQT_SLOT(setEnabled(bool))); 00076 00077 connect( d->ui->m_addBtn, TQT_SIGNAL(clicked()), this, TQT_SLOT(add())); 00078 connect( this, TQT_SIGNAL(ready(bool)), d->ui->m_addBtn, TQT_SLOT(setEnabled(bool))); 00079 00080 connect( d->ui->m_suggestBtn, TQT_SIGNAL(clicked()), this, TQT_SLOT(suggest())); 00081 connect( this, TQT_SIGNAL(ready(bool)), d->ui->m_suggestBtn, TQT_SLOT(setEnabled(bool)) ); 00082 d->ui->m_suggestBtn->hide(); 00083 00084 connect(this, TQT_SIGNAL(user1Clicked()), this, TQT_SLOT(stop())); 00085 00086 connect( d->ui->m_replacement, TQT_SIGNAL(textChanged(const TQString &)), 00087 TQT_SLOT(textChanged(const TQString &)) ); 00088 00089 connect( d->ui->m_replacement, TQT_SIGNAL(returnPressed()), TQT_SLOT(replace()) ); 00090 connect( d->ui->m_suggestions, TQT_SIGNAL(selectionChanged(TQListViewItem*)), 00091 TQT_SLOT(slotSelectionChanged(TQListViewItem*)) ); 00092 00093 connect( d->ui->m_suggestions, TQT_SIGNAL( doubleClicked ( TQListViewItem *, const TQPoint &, int ) ), 00094 TQT_SLOT( replace() ) ); 00095 d->spellConfig = new KSpellConfig( 0, 0 ,0, false ); 00096 d->spellConfig->fillDicts( d->ui->m_language ); 00097 connect( d->ui->m_language, TQT_SIGNAL(activated(int)), 00098 d->spellConfig, TQT_SLOT(sSetDictionary(int)) ); 00099 connect( d->spellConfig, TQT_SIGNAL(configChanged()), 00100 TQT_SLOT(slotConfigChanged()) ); 00101 00102 setHelp( "spelldlg", "kspell" ); 00103 setMinimumSize( sizeHint() ); 00104 emit ready( false ); 00105 } 00106 00107 KSpellDlg::~KSpellDlg() 00108 { 00109 delete d->spellConfig; 00110 delete d; 00111 } 00112 00113 void 00114 KSpellDlg::init( const TQString & _word, TQStringList * _sugg ) 00115 { 00116 sugg = _sugg; 00117 word = _word; 00118 00119 d->ui->m_suggestions->clear(); 00120 d->ui->m_suggestions->setSorting( NONSORTINGCOLUMN ); 00121 for ( TQStringList::Iterator it = _sugg->begin(); it != _sugg->end(); ++it ) { 00122 TQListViewItem *item = new TQListViewItem( d->ui->m_suggestions, 00123 d->ui->m_suggestions->lastItem() ); 00124 item->setText( 0, *it ); 00125 } 00126 kdDebug(750) << "KSpellDlg::init [" << word << "]" << endl; 00127 00128 emit ready( true ); 00129 00130 d->ui->m_unknownWord->setText( _word ); 00131 00132 if ( sugg->count() == 0 ) { 00133 d->ui->m_replacement->setText( _word ); 00134 d->ui->m_replaceBtn->setEnabled( false ); 00135 d->ui->m_replaceAllBtn->setEnabled( false ); 00136 d->ui->m_suggestBtn->setEnabled( false ); 00137 } else { 00138 d->ui->m_replacement->setText( (*sugg)[0] ); 00139 d->ui->m_replaceBtn->setEnabled( true ); 00140 d->ui->m_replaceAllBtn->setEnabled( true ); 00141 d->ui->m_suggestBtn->setEnabled( false ); 00142 d->ui->m_suggestions->setSelected( d->ui->m_suggestions->firstChild(), true ); 00143 } 00144 } 00145 00146 void 00147 KSpellDlg::init( const TQString& _word, TQStringList* _sugg, 00148 const TQString& context ) 00149 { 00150 sugg = _sugg; 00151 word = _word; 00152 00153 d->ui->m_suggestions->clear(); 00154 d->ui->m_suggestions->setSorting( NONSORTINGCOLUMN ); 00155 for ( TQStringList::Iterator it = _sugg->begin(); it != _sugg->end(); ++it ) { 00156 TQListViewItem *item = new TQListViewItem( d->ui->m_suggestions, 00157 d->ui->m_suggestions->lastItem() ); 00158 item->setText( 0, *it ); 00159 } 00160 00161 kdDebug(750) << "KSpellDlg::init [" << word << "]" << endl; 00162 00163 emit ready( true ); 00164 00165 d->ui->m_unknownWord->setText( _word ); 00166 d->ui->m_contextLabel->setText( context ); 00167 00168 if ( sugg->count() == 0 ) { 00169 d->ui->m_replacement->setText( _word ); 00170 d->ui->m_replaceBtn->setEnabled( false ); 00171 d->ui->m_replaceAllBtn->setEnabled( false ); 00172 d->ui->m_suggestBtn->setEnabled( false ); 00173 } else { 00174 d->ui->m_replacement->setText( (*sugg)[0] ); 00175 d->ui->m_replaceBtn->setEnabled( true ); 00176 d->ui->m_replaceAllBtn->setEnabled( true ); 00177 d->ui->m_suggestBtn->setEnabled( false ); 00178 d->ui->m_suggestions->setSelected( d->ui->m_suggestions->firstChild(), true ); 00179 } 00180 } 00181 00182 void 00183 KSpellDlg::slotProgress( unsigned int p ) 00184 { 00185 if (!progressbar) 00186 return; 00187 00188 progbar->setValue( (int) p ); 00189 } 00190 00191 void 00192 KSpellDlg::textChanged( const TQString & ) 00193 { 00194 d->ui->m_replaceBtn->setEnabled( true ); 00195 d->ui->m_replaceAllBtn->setEnabled( true ); 00196 d->ui->m_suggestBtn->setEnabled( true ); 00197 } 00198 00199 void 00200 KSpellDlg::slotSelectionChanged( TQListViewItem* item ) 00201 { 00202 if ( item ) 00203 d->ui->m_replacement->setText( item->text( 0 ) ); 00204 } 00205 00206 /* 00207 exit functions 00208 */ 00209 00210 void 00211 KSpellDlg::closeEvent( TQCloseEvent * ) 00212 { 00213 cancel(); 00214 } 00215 00216 void 00217 KSpellDlg::done( int result ) 00218 { 00219 emit command( result ); 00220 } 00221 void 00222 KSpellDlg::ignore() 00223 { 00224 newword = word; 00225 done( KS_IGNORE ); 00226 } 00227 00228 void 00229 KSpellDlg::ignoreAll() 00230 { 00231 newword = word; 00232 done( KS_IGNOREALL ); 00233 } 00234 00235 void 00236 KSpellDlg::add() 00237 { 00238 newword = word; 00239 done( KS_ADD ); 00240 } 00241 00242 00243 void 00244 KSpellDlg::cancel() 00245 { 00246 newword = word; 00247 done( KS_CANCEL ); 00248 } 00249 00250 void 00251 KSpellDlg::replace() 00252 { 00253 newword = d->ui->m_replacement->text(); 00254 done( KS_REPLACE ); 00255 } 00256 00257 void 00258 KSpellDlg::stop() 00259 { 00260 newword = word; 00261 done( KS_STOP ); 00262 } 00263 00264 void 00265 KSpellDlg::replaceAll() 00266 { 00267 newword = d->ui->m_replacement->text(); 00268 done( KS_REPLACEALL ); 00269 } 00270 00271 void 00272 KSpellDlg::suggest() 00273 { 00274 newword = d->ui->m_replacement->text(); 00275 done( KS_SUGGEST ); 00276 } 00277 00278 void 00279 KSpellDlg::slotConfigChanged() 00280 { 00281 d->spellConfig->writeGlobalSettings(); 00282 done( KS_CONFIG ); 00283 } 00284 00285 #include "kspelldlg.moc"