22 #include <tqcheckbox.h>
23 #include <tqcombobox.h>
28 #include <kapplication.h>
32 #include <kfiledialog.h>
34 #include <klineedit.h>
36 #include <kpushbutton.h>
37 #include <kstdguiitem.h>
41 class KSpellConfigPrivate
44 TQStringList replacelist;
49 : TQWidget(0, 0), nodialog(true)
58 d =
new KSpellConfigPrivate;
59 setReplaceAllList( _ksc.replaceAllList() );
61 setRunTogether( _ksc.runTogether() );
62 setDictionary( _ksc.dictionary() );
63 setDictFromList( _ksc.dictFromList() );
65 setIgnoreList( _ksc.ignoreList() );
66 setEncoding( _ksc.encoding() );
67 setClient( _ksc.
client() );
73 : TQWidget (parent, name), nodialog(false)
82 d =
new KSpellConfigPrivate;
94 setDictFromList( _ksc->dictFromList() );
97 setEncoding( _ksc->encoding() );
98 setClient( _ksc->
client() );
102 cb1 =
new TQCheckBox( i18n(
"Create &root/affix combinations"
103 " not in dictionary"),
this,
"NoRootAffix" );
104 connect( cb1, TQT_SIGNAL(toggled(
bool)), TQT_SLOT(sNoAff(
bool)) );
105 glay->addMultiCellWidget( cb1, 0, 0, 0, 2 );
107 cb2 =
new TQCheckBox( i18n(
"Consider run-together &words"
108 " as spelling errors"),
this,
"RunTogether" );
109 connect( cb2, TQT_SIGNAL(toggled(
bool)), TQT_SLOT(sRunTogether(
bool)) );
110 glay->addMultiCellWidget( cb2, 1, 1, 0, 2 );
112 dictcombo =
new TQComboBox(
this,
"DictFromList" );
113 dictcombo->setInsertionPolicy( TQComboBox::NoInsertion );
114 connect( dictcombo, TQT_SIGNAL (activated(
int)),
115 this, TQT_SLOT (sSetDictionary(
int)) );
116 glay->addMultiCellWidget( dictcombo, 2, 2, 1, 2 );
118 dictlist =
new TQLabel( dictcombo, i18n(
"&Dictionary:"),
this );
119 glay->addWidget( dictlist, 2 ,0 );
121 encodingcombo =
new TQComboBox(
this,
"Encoding" );
122 encodingcombo->insertItem(
"US-ASCII" );
123 encodingcombo->insertItem(
"ISO 8859-1" );
124 encodingcombo->insertItem(
"ISO 8859-2" );
125 encodingcombo->insertItem(
"ISO 8859-3" );
126 encodingcombo->insertItem(
"ISO 8859-4" );
127 encodingcombo->insertItem(
"ISO 8859-5" );
128 encodingcombo->insertItem(
"ISO 8859-7" );
129 encodingcombo->insertItem(
"ISO 8859-8" );
130 encodingcombo->insertItem(
"ISO 8859-9" );
131 encodingcombo->insertItem(
"ISO 8859-13" );
132 encodingcombo->insertItem(
"ISO 8859-15" );
133 encodingcombo->insertItem(
"UTF-8" );
134 encodingcombo->insertItem(
"KOI8-R" );
135 encodingcombo->insertItem(
"KOI8-U" );
136 encodingcombo->insertItem(
"CP1251" );
137 encodingcombo->insertItem(
"CP1255" );
139 connect( encodingcombo, TQT_SIGNAL(activated(
int)),
this,
140 TQT_SLOT(sChangeEncoding(
int)) );
141 glay->addMultiCellWidget( encodingcombo, 3, 3, 1, 2 );
143 TQLabel *tmpQLabel =
new TQLabel( encodingcombo, i18n(
"&Encoding:"),
this);
144 glay->addWidget( tmpQLabel, 3, 0 );
147 clientcombo =
new TQComboBox(
this,
"Client" );
148 clientcombo->insertItem( i18n(
"International Ispell") );
149 clientcombo->insertItem( i18n(
"Aspell") );
150 clientcombo->insertItem( i18n(
"Hspell") );
151 clientcombo->insertItem( i18n(
"Zemberek") );
152 connect( clientcombo, TQT_SIGNAL (activated(
int)),
this,
153 TQT_SLOT (sChangeClient(
int)) );
154 glay->addMultiCellWidget( clientcombo, 4, 4, 1, 2 );
156 tmpQLabel =
new TQLabel( clientcombo, i18n(
"&Client:"),
this );
157 glay->addWidget( tmpQLabel, 4, 0 );
161 TQPushButton *pushButton =
new KPushButton( KStdGuiItem::help(),
this );
162 connect( pushButton, TQT_SIGNAL(clicked()),
this, TQT_SLOT(
sHelp()) );
163 glay->addWidget(pushButton, 5, 2);
176 KSpellConfig::dictFromList()
const
182 KSpellConfig::readGlobalSettings()
189 setDictFromList ( kc->
readNumEntry(
"KSpell_DictFromList",
false) );
190 setEncoding ( kc->
readNumEntry (
"KSpell_Encoding", KS_E_UTF8) );
191 setClient ( kc->
readNumEntry (
"KSpell_Client", KS_CLIENT_ISPELL) );
202 kc->
writeEntry (
"KSpell_RunTogether", (
int) runTogether(),
true,
true);
203 kc->
writeEntry (
"KSpell_Dictionary", dictionary(),
true,
true);
204 kc->
writeEntry (
"KSpell_DictFromList",(
int) dictFromList(),
true,
true);
205 kc->
writeEntry (
"KSpell_Encoding", (
int) encoding(),
215 KSpellConfig::sChangeEncoding(
int i )
217 kdDebug(750) <<
"KSpellConfig::sChangeEncoding(" << i <<
")" <<
endl;
219 emit configChanged();
223 KSpellConfig::sChangeClient(
int i )
229 if ( iclient == KS_CLIENT_ISPELL )
230 getAvailDictsIspell();
231 else if ( iclient == KS_CLIENT_HSPELL )
235 dictcombo->insertItem( i18n(
"Hebrew") );
236 sChangeEncoding( KS_E_CP1255 );
237 }
else if ( iclient == KS_CLIENT_ZEMBEREK ) {
240 dictcombo->insertItem( i18n(
"Turkish") );
241 sChangeEncoding( KS_E_UTF8 );
244 getAvailDictsAspell();
246 emit configChanged();
256 kdDebug(750) <<
"KSpellConfig::interpret [" << fname <<
"]" <<
endl;
258 TQString dname( fname );
260 if( dname.endsWith(
"+" ) )
261 dname.remove( dname.length()-1, 1 );
263 if( dname.endsWith(
"sml") || dname.endsWith(
"med") || dname.endsWith(
"lrg") ||
264 dname.endsWith(
"xlg"))
265 dname.remove(dname.length()-3,3);
269 int i = dname.find(
'-');
272 extension = dname.mid(i+1);
278 if ( (dname.length() == 2) || (dname.length() == 3) ) {
282 else if ( (dname.length() == 5) && (dname[2] ==
'_') ) {
283 lname = dname.left(2);
286 if ( extension.isEmpty() )
289 extension = country +
" - " + extension;
292 else if ( dname==
"english" || dname==
"american" ||
293 dname==
"british" || dname==
"canadian" ) {
294 lname=
"en"; hname=i18n(
"English");
296 else if ( dname ==
"espa~nol" || dname ==
"espanol" ) {
297 lname=
"es"; hname=i18n(
"Spanish");
299 else if (dname==
"dansk") {
300 lname=
"da"; hname=i18n(
"Danish");
302 else if (dname==
"deutsch") {
303 lname=
"de"; hname=i18n(
"German");
305 else if (dname==
"german") {
306 lname=
"de"; hname=i18n(
"German (new spelling)");
308 else if (dname==
"portuguesb" || dname==
"br") {
309 lname=
"br"; hname=i18n(
"Brazilian Portuguese");
311 else if (dname==
"portugues") {
312 lname=
"pt"; hname=i18n(
"Portuguese");
314 else if (dname==
"esperanto") {
315 lname=
"eo"; hname=i18n(
"Esperanto");
317 else if (dname==
"norsk") {
318 lname=
"no"; hname=i18n(
"Norwegian");
320 else if (dname==
"polish") {
321 lname=
"pl"; hname=i18n(
"Polish"); sChangeEncoding(KS_E_LATIN2);
323 else if (dname==
"russian") {
324 lname=
"ru"; hname=i18n(
"Russian");
326 else if (dname==
"slovensko") {
327 lname=
"si"; hname=i18n(
"Slovenian"); sChangeEncoding(KS_E_LATIN2);
329 else if (dname==
"slovak"){
330 lname=
"sk"; hname=i18n(
"Slovak"); sChangeEncoding(KS_E_LATIN2);
332 else if (dname==
"czech") {
333 lname=
"cs"; hname=i18n(
"Czech"); sChangeEncoding(KS_E_LATIN2);
335 else if (dname==
"svenska") {
336 lname=
"sv"; hname=i18n(
"Swedish");
338 else if (dname==
"swiss") {
339 lname=
"de"; hname=i18n(
"Swiss German");
341 else if (dname==
"ukrainian") {
342 lname=
"uk"; hname=i18n(
"Ukrainian");
344 else if (dname==
"lietuviu" || dname==
"lithuanian") {
345 lname=
"lt"; hname=i18n(
"Lithuanian");
347 else if (dname==
"francais" || dname==
"french") {
348 lname=
"fr"; hname=i18n(
"French");
350 else if (dname==
"belarusian") {
351 lname=
"be"; hname=i18n(
"Belarusian");
353 else if( dname ==
"magyar" ) {
354 lname=
"hu"; hname=i18n(
"Hungarian");
355 sChangeEncoding(KS_E_LATIN2);
358 lname=
""; hname=i18n(
"Unknown ispell dictionary",
"Unknown");
360 if (!extension.isEmpty())
362 hname = hname +
" (" + extension +
")";
367 lname==TQString::fromLatin1(
"en") ) ||
375 KSpellConfig::fillInDialog ()
380 kdDebug(750) <<
"KSpellConfig::fillinDialog" <<
endl;
383 cb2->setChecked( runTogether() );
384 encodingcombo->setCurrentItem( encoding() );
385 clientcombo->setCurrentItem(
client() );
388 if ( iclient == KS_CLIENT_ISPELL )
389 getAvailDictsIspell();
390 else if ( iclient == KS_CLIENT_HSPELL )
394 langfnames.append(
"");
395 dictcombo->insertItem( i18n(
"Hebrew") );
396 }
else if ( iclient == KS_CLIENT_ZEMBEREK ) {
399 langfnames.append(
"");
400 dictcombo->insertItem( i18n(
"Turkish") );
403 getAvailDictsAspell();
408 if ( dictFromList() )
409 whichelement = langfnames.findIndex(dictionary());
411 dictcombo->setMinimumWidth (dictcombo->sizeHint().width());
413 if (dictionary().isEmpty() || whichelement!=-1)
415 setDictFromList (
true);
416 if (whichelement!=-1)
417 dictcombo->setCurrentItem(whichelement);
421 if ( !langfnames.empty() )
423 setDictFromList(
true );
424 dictcombo->setCurrentItem(0);
427 setDictFromList(
false );
429 sDictionary( dictFromList() );
430 sPathDictionary( !dictFromList() );
435 void KSpellConfig::getAvailDictsIspell () {
439 langfnames.append(
"");
440 dictcombo->insertItem( i18n(
"ISpell Default") );
443 TQFileInfo dir (
"/usr/lib" KDELIBSUFF
"/ispell");
444 if (!dir.exists() || !dir.isDir())
445 dir.setFile (
"/usr/local/lib" KDELIBSUFF
"/ispell");
446 if (!dir.exists() || !dir.isDir())
447 dir.setFile (
"/usr/local/share/ispell");
448 if (!dir.exists() || !dir.isDir())
449 dir.setFile (
"/usr/share/ispell");
450 if (!dir.exists() || !dir.isDir())
451 dir.setFile (
"/usr/pkg/lib");
457 if (!dir.exists() || !dir.isDir())
return;
459 kdDebug(750) <<
"KSpellConfig::getAvailDictsIspell "
460 << dir.filePath() <<
" " << dir.dirPath() <<
endl;
462 const TQDir thedir (dir.filePath(),
"*.hash");
463 const TQStringList entryList = thedir.entryList();
465 kdDebug(750) <<
"KSpellConfig" << thedir.path() <<
"\n" <<
endl;
466 kdDebug(750) <<
"entryList().count()="
467 << entryList.count() <<
endl;
469 TQStringList::const_iterator entryListItr = entryList.constBegin();
470 const TQStringList::const_iterator entryListEnd = entryList.constEnd();
472 for ( ; entryListItr != entryListEnd; ++entryListItr)
474 TQString fname, lname, hname;
475 fname = *entryListItr;
478 if (fname.endsWith(
".hash")) fname.remove (fname.length()-5,5);
480 if (
interpret (fname, lname, hname) && langfnames.first().isEmpty())
484 langfnames.remove ( langfnames.begin() );
485 langfnames.prepend ( fname );
487 hname=i18n(
"default spelling dictionary"
488 ,
"Default - %1 [%2]").arg(hname).arg(fname);
490 dictcombo->changeItem (hname,0);
494 langfnames.append (fname);
495 hname=hname+
" ["+fname+
"]";
497 dictcombo->insertItem (hname);
502 void KSpellConfig::getAvailDictsAspell () {
507 langfnames.append(
"");
508 dictcombo->insertItem (i18n(
"ASpell Default"));
512 TQFileInfo dir ( ASPELL_DATADIR );
513 if (!dir.exists() || !dir.isDir())
514 dir.setFile (
"/usr/lib" KDELIBSUFF
"/aspell-0.60");
515 if (!dir.exists() || !dir.isDir())
516 dir.setFile (
"/usr/local/lib" KDELIBSUFF
"/aspell");
517 if (!dir.exists() || !dir.isDir())
518 dir.setFile (
"/usr/share/aspell");
519 if (!dir.exists() || !dir.isDir())
520 dir.setFile (
"/usr/local/share/aspell");
521 if (!dir.exists() || !dir.isDir())
522 dir.setFile (
"/usr/pkg/lib/aspell");
523 if (!dir.exists() || !dir.isDir())
return;
525 kdDebug(750) <<
"KSpellConfig::getAvailDictsAspell "
526 << dir.filePath() <<
" " << dir.dirPath() <<
endl;
528 const TQDir thedir (dir.filePath(),
"*");
529 const TQStringList entryList = thedir.entryList();
531 kdDebug(750) <<
"KSpellConfig" << thedir.path() <<
"\n" <<
endl;
532 kdDebug(750) <<
"entryList().count()="
533 << entryList.count() <<
endl;
535 TQStringList::const_iterator entryListItr = entryList.constBegin();
536 const TQStringList::const_iterator entryListEnd = entryList.constEnd();
538 for ( ; entryListItr != entryListEnd; ++entryListItr)
540 TQString fname, lname, hname;
541 fname = *entryListItr;
553 if ( !( fname.endsWith(
".rws") || fname.endsWith(
".multi") ) ) {
561 if (fname.endsWith(
".multi")) fname.remove (fname.length()-6,6);
563 if (fname.endsWith(
".rws")) fname.remove (fname.length()-4,4);
565 if (
interpret (fname, lname, hname) && langfnames.first().isEmpty())
569 langfnames.remove ( langfnames.begin() );
570 langfnames.prepend ( fname );
572 hname=i18n(
"default spelling dictionary"
573 ,
"Default - %1").arg(hname);
575 dictcombo->changeItem (hname,0);
579 langfnames.append (fname);
580 dictcombo->insertItem (hname);
591 if ( iclient == KS_CLIENT_ISPELL ) {
593 langfnames.append(
"");
594 box->insertItem( i18n(
"ISpell Default") );
597 TQFileInfo dir (
"/usr/lib/ispell");
598 if (!dir.exists() || !dir.isDir())
599 dir.setFile (
"/usr/local/lib/ispell");
600 if (!dir.exists() || !dir.isDir())
601 dir.setFile (
"/usr/local/share/ispell");
602 if (!dir.exists() || !dir.isDir())
603 dir.setFile (
"/usr/share/ispell");
604 if (!dir.exists() || !dir.isDir())
605 dir.setFile (
"/usr/pkg/lib");
611 if (!dir.exists() || !dir.isDir())
return;
613 kdDebug(750) <<
"KSpellConfig::getAvailDictsIspell "
614 << dir.filePath() <<
" " << dir.dirPath() <<
endl;
616 const TQDir thedir (dir.filePath(),
"*.hash");
617 const TQStringList entryList = thedir.entryList();
619 kdDebug(750) <<
"KSpellConfig" << thedir.path() <<
"\n" <<
endl;
620 kdDebug(750) <<
"entryList().count()="
621 << entryList.count() <<
endl;
623 TQStringList::const_iterator entryListItr = entryList.constBegin();
624 const TQStringList::const_iterator entryListEnd = entryList.constEnd();
626 for ( ; entryListItr != entryListEnd; ++entryListItr)
628 TQString fname, lname, hname;
629 fname = *entryListItr;
632 if (fname.endsWith(
".hash")) fname.remove (fname.length()-5,5);
634 if (
interpret (fname, lname, hname) && langfnames.first().isEmpty())
638 langfnames.remove ( langfnames.begin() );
639 langfnames.prepend ( fname );
641 hname=i18n(
"default spelling dictionary"
642 ,
"Default - %1 [%2]").arg(hname).arg(fname);
644 box->changeItem (hname,0);
648 langfnames.append (fname);
649 hname=hname+
" ["+fname+
"]";
651 box->insertItem (hname);
654 }
else if ( iclient == KS_CLIENT_HSPELL ) {
656 box->insertItem( i18n(
"Hebrew") );
657 langfnames.append(
"");
658 sChangeEncoding( KS_E_CP1255 );
659 }
else if ( iclient == KS_CLIENT_ZEMBEREK ) {
661 box->insertItem( i18n(
"Turkish") );
662 langfnames.append(
"");
663 sChangeEncoding( KS_E_UTF8 );
667 langfnames.append(
"");
668 box->insertItem (i18n(
"ASpell Default"));
672 TQFileInfo dir (
"/usr/lib" KDELIBSUFF
"/aspell");
673 if (!dir.exists() || !dir.isDir())
674 dir.setFile (
"/usr/lib" KDELIBSUFF
"/aspell-0.60");
675 if (!dir.exists() || !dir.isDir())
676 dir.setFile (
"/usr/local/lib" KDELIBSUFF
"/aspell");
677 if (!dir.exists() || !dir.isDir())
678 dir.setFile (
"/usr/share/aspell");
679 if (!dir.exists() || !dir.isDir())
680 dir.setFile (
"/usr/local/share/aspell");
681 if (!dir.exists() || !dir.isDir())
682 dir.setFile (
"/usr/pkg/lib/aspell");
683 if (!dir.exists() || !dir.isDir())
return;
685 kdDebug(750) <<
"KSpellConfig::getAvailDictsAspell "
686 << dir.filePath() <<
" " << dir.dirPath() <<
endl;
688 const TQDir thedir (dir.filePath(),
"*");
689 const TQStringList entryList = thedir.entryList();
691 kdDebug(750) <<
"KSpellConfig" << thedir.path() <<
"\n" <<
endl;
692 kdDebug(750) <<
"entryList().count()="
693 << entryList.count() <<
endl;
695 TQStringList::const_iterator entryListItr = entryList.constBegin();
696 const TQStringList::const_iterator entryListEnd = entryList.constEnd();
698 for ( ; entryListItr != entryListEnd; ++entryListItr)
700 TQString fname, lname, hname;
701 fname = *entryListItr;
713 if ( !( fname.endsWith(
".rws") || fname.endsWith(
".multi") ) ) {
721 if (fname.endsWith(
".multi")) fname.remove (fname.length()-6,6);
723 if (fname.endsWith(
".rws")) fname.remove (fname.length()-4,4);
725 if (
interpret (fname, lname, hname) && langfnames.first().isEmpty())
729 langfnames.remove ( langfnames.begin() );
730 langfnames.prepend ( fname );
732 hname=i18n(
"default spelling dictionary"
733 ,
"Default - %1").arg(hname);
735 box->changeItem (hname,0);
739 langfnames.append (fname);
740 box->insertItem (hname);
745 int whichelement = langfnames.findIndex(qsdict);
746 if ( whichelement >= 0 ) {
747 box->setCurrentItem( whichelement );
750 *dictionaries = langfnames;
759 KSpellConfig::setClient (
int c)
764 clientcombo->setCurrentItem(c);
790 if (qsdict.length()>5)
791 if ((
signed)qsdict.find(
".hash")==(signed)qsdict.length()-5)
792 qsdict.remove (qsdict.length()-5,5);
800 whichelement = langfnames.findIndex(s);
802 if(whichelement >= 0)
804 dictcombo->setCurrentItem(whichelement);
813 KSpellConfig::setDictFromList (
bool dfl)
827 KSpellConfig::setEncoding (
int enctype)
832 encodingcombo->setCurrentItem(enctype);
852 KSpellConfig::runTogether()
const
858 TQString KSpellConfig::dictionary ()
const
871 KSpellConfig::encoding ()
const
877 KSpellConfig::sRunTogether(
bool)
880 emit configChanged();
884 KSpellConfig::sNoAff(
bool)
887 emit configChanged();
916 KSpellConfig::sSetDictionary (
int i)
919 setDictFromList (
true);
920 TQTimer::singleShot( 0,
this, TQT_SIGNAL( configChanged() ) );
924 KSpellConfig::sDictionary(
bool on)
928 dictcombo->setEnabled (
true);
930 setDictFromList (
true);
934 dictcombo->setEnabled (
false);
936 emit configChanged();
940 KSpellConfig::sPathDictionary(
bool on)
950 setDictFromList (
false);
957 emit configChanged();
968 kapp->invokeHelp(
"configuration",
"kspell");
991 setDictFromList (ksc.dictFromList());
993 setEncoding (ksc.encoding());
1003 ignorelist=_ignorelist;
1007 KSpellConfig::ignoreList ()
const
1016 d->replacelist=_replacelist;
1020 KSpellConfig::replaceAllList()
const
1022 return d->replacelist;
1025 #include "ksconfig.moc"