22 #include <tqcheckbox.h>
23 #include <tqcombobox.h>
28 #include <tdeapplication.h>
29 #include <tdeconfig.h>
32 #include <tdefiledialog.h>
33 #include <tdeglobal.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 #if defined(__OpenBSD__) || defined(__FreeBSD__)
192 setClient ( kc->
readNumEntry (
"KSpell_Client", KS_CLIENT_ASPELL) );
194 setClient ( kc->
readNumEntry (
"KSpell_Client", KS_CLIENT_ISPELL) );
206 kc->
writeEntry (
"KSpell_RunTogether", (
int) runTogether(),
true,
true);
207 kc->
writeEntry (
"KSpell_Dictionary", dictionary(),
true,
true);
208 kc->
writeEntry (
"KSpell_DictFromList",(
int) dictFromList(),
true,
true);
209 kc->
writeEntry (
"KSpell_Encoding", (
int) encoding(),
219 KSpellConfig::sChangeEncoding(
int i )
221 kdDebug(750) <<
"KSpellConfig::sChangeEncoding(" << i <<
")" <<
endl;
223 emit configChanged();
227 KSpellConfig::sChangeClient(
int i )
233 if ( iclient == KS_CLIENT_ISPELL )
234 getAvailDictsIspell();
235 else if ( iclient == KS_CLIENT_HSPELL )
239 dictcombo->insertItem( i18n(
"Hebrew") );
240 sChangeEncoding( KS_E_CP1255 );
241 }
else if ( iclient == KS_CLIENT_ZEMBEREK ) {
244 dictcombo->insertItem( i18n(
"Turkish") );
245 sChangeEncoding( KS_E_UTF8 );
248 getAvailDictsAspell();
250 emit configChanged();
260 kdDebug(750) <<
"KSpellConfig::interpret [" << fname <<
"]" <<
endl;
262 TQString dname( fname );
264 if( dname.endsWith(
"+" ) )
265 dname.remove( dname.length()-1, 1 );
267 if( dname.endsWith(
"sml") || dname.endsWith(
"med") || dname.endsWith(
"lrg") ||
268 dname.endsWith(
"xlg"))
269 dname.remove(dname.length()-3,3);
273 int i = dname.find(
'-');
276 extension = dname.mid(i+1);
282 if ( (dname.length() == 2) || (dname.length() == 3) ) {
286 else if ( (dname.length() == 5) && (dname[2] ==
'_') ) {
287 lname = dname.left(2);
290 if ( extension.isEmpty() )
293 extension = country +
" - " + extension;
296 else if ( dname==
"english" || dname==
"american" ||
297 dname==
"british" || dname==
"canadian" ) {
298 lname=
"en"; hname=i18n(
"English");
300 else if ( dname ==
"espa~nol" || dname ==
"espanol" ) {
301 lname=
"es"; hname=i18n(
"Spanish");
303 else if (dname==
"dansk") {
304 lname=
"da"; hname=i18n(
"Danish");
306 else if (dname==
"deutsch") {
307 lname=
"de"; hname=i18n(
"German");
309 else if (dname==
"german") {
310 lname=
"de"; hname=i18n(
"German (new spelling)");
312 else if (dname==
"portuguesb" || dname==
"br") {
313 lname=
"br"; hname=i18n(
"Brazilian Portuguese");
315 else if (dname==
"portugues") {
316 lname=
"pt"; hname=i18n(
"Portuguese");
318 else if (dname==
"esperanto") {
319 lname=
"eo"; hname=i18n(
"Esperanto");
321 else if (dname==
"norsk") {
322 lname=
"no"; hname=i18n(
"Norwegian");
324 else if (dname==
"polish") {
325 lname=
"pl"; hname=i18n(
"Polish"); sChangeEncoding(KS_E_LATIN2);
327 else if (dname==
"russian") {
328 lname=
"ru"; hname=i18n(
"Russian");
330 else if (dname==
"slovensko") {
331 lname=
"si"; hname=i18n(
"Slovenian"); sChangeEncoding(KS_E_LATIN2);
333 else if (dname==
"slovak"){
334 lname=
"sk"; hname=i18n(
"Slovak"); sChangeEncoding(KS_E_LATIN2);
336 else if (dname==
"czech") {
337 lname=
"cs"; hname=i18n(
"Czech"); sChangeEncoding(KS_E_LATIN2);
339 else if (dname==
"svenska") {
340 lname=
"sv"; hname=i18n(
"Swedish");
342 else if (dname==
"swiss") {
343 lname=
"de"; hname=i18n(
"Swiss German");
345 else if (dname==
"ukrainian") {
346 lname=
"uk"; hname=i18n(
"Ukrainian");
348 else if (dname==
"lietuviu" || dname==
"lithuanian") {
349 lname=
"lt"; hname=i18n(
"Lithuanian");
351 else if (dname==
"francais" || dname==
"french") {
352 lname=
"fr"; hname=i18n(
"French");
354 else if (dname==
"belarusian") {
355 lname=
"be"; hname=i18n(
"Belarusian");
357 else if( dname ==
"magyar" ) {
358 lname=
"hu"; hname=i18n(
"Hungarian");
359 sChangeEncoding(KS_E_LATIN2);
362 lname=
""; hname=i18n(
"Unknown ispell dictionary",
"Unknown");
364 if (!extension.isEmpty())
366 hname = hname +
" (" + extension +
")";
371 lname==TQString::fromLatin1(
"en") ) ||
379 KSpellConfig::fillInDialog ()
384 kdDebug(750) <<
"KSpellConfig::fillinDialog" <<
endl;
387 cb2->setChecked( runTogether() );
388 encodingcombo->setCurrentItem( encoding() );
389 clientcombo->setCurrentItem(
client() );
392 if ( iclient == KS_CLIENT_ISPELL )
393 getAvailDictsIspell();
394 else if ( iclient == KS_CLIENT_HSPELL )
398 langfnames.append(
"");
399 dictcombo->insertItem( i18n(
"Hebrew") );
400 }
else if ( iclient == KS_CLIENT_ZEMBEREK ) {
403 langfnames.append(
"");
404 dictcombo->insertItem( i18n(
"Turkish") );
407 getAvailDictsAspell();
412 if ( dictFromList() )
413 whichelement = langfnames.findIndex(dictionary());
415 dictcombo->setMinimumWidth (dictcombo->sizeHint().width());
417 if (dictionary().isEmpty() || whichelement!=-1)
419 setDictFromList (
true);
420 if (whichelement!=-1)
421 dictcombo->setCurrentItem(whichelement);
425 if ( !langfnames.empty() )
427 setDictFromList(
true );
428 dictcombo->setCurrentItem(0);
431 setDictFromList(
false );
433 sDictionary( dictFromList() );
434 sPathDictionary( !dictFromList() );
439 void KSpellConfig::getAvailDictsIspell () {
443 langfnames.append(
"");
444 dictcombo->insertItem( i18n(
"ISpell Default") );
450 <<
"/usr/" SYSTEM_LIBDIR
"/ispell"
452 <<
"/usr/local/" SYSTEM_LIBDIR
"/ispell"
453 <<
"/usr/local/lib/ispell"
454 <<
"/usr/local/share/ispell"
455 <<
"/usr/share/ispell"
457 for (TQStringList::ConstIterator it=dirs.begin(); it != dirs.end(); ++it) {
459 if (dir.exists() && dir.isDir()) {
466 if (!dir.exists() || !dir.isDir())
return;
468 kdDebug(750) <<
"KSpellConfig::getAvailDictsIspell "
469 << dir.filePath() <<
" " << dir.dirPath() <<
endl;
471 const TQDir thedir (dir.filePath(),
"*.hash");
472 const TQStringList entryList = thedir.entryList();
474 kdDebug(750) <<
"KSpellConfig" << thedir.path() <<
"\n" <<
endl;
475 kdDebug(750) <<
"entryList().count()="
476 << entryList.count() <<
endl;
478 TQStringList::const_iterator entryListItr = entryList.constBegin();
479 const TQStringList::const_iterator entryListEnd = entryList.constEnd();
481 for ( ; entryListItr != entryListEnd; ++entryListItr)
483 TQString fname, lname, hname;
484 fname = *entryListItr;
487 if (fname.endsWith(
".hash")) fname.remove (fname.length()-5,5);
489 if (
interpret (fname, lname, hname) && langfnames.first().isEmpty())
493 langfnames.remove ( langfnames.begin() );
494 langfnames.prepend ( fname );
496 hname=i18n(
"default spelling dictionary"
497 ,
"Default - %1 [%2]").arg(hname).arg(fname);
499 dictcombo->changeItem (hname,0);
503 langfnames.append (fname);
504 hname=hname+
" ["+fname+
"]";
506 dictcombo->insertItem (hname);
511 void KSpellConfig::getAvailDictsAspell () {
516 langfnames.append(
"");
517 dictcombo->insertItem (i18n(
"ASpell Default"));
521 TQFileInfo dir ( ASPELL_DATADIR );
522 if (!dir.exists() || !dir.isDir())
523 dir.setFile (
"/usr/lib" KDELIBSUFF
"/aspell-0.60");
524 if (!dir.exists() || !dir.isDir())
525 dir.setFile (
"/usr/local/lib" KDELIBSUFF
"/aspell");
526 if (!dir.exists() || !dir.isDir())
527 dir.setFile (
"/usr/share/aspell");
528 if (!dir.exists() || !dir.isDir())
529 dir.setFile (
"/usr/local/share/aspell");
530 if (!dir.exists() || !dir.isDir())
531 dir.setFile (
"/usr/pkg/lib/aspell");
532 if (!dir.exists() || !dir.isDir())
return;
534 kdDebug(750) <<
"KSpellConfig::getAvailDictsAspell "
535 << dir.filePath() <<
" " << dir.dirPath() <<
endl;
537 const TQDir thedir (dir.filePath(),
"*");
538 const TQStringList entryList = thedir.entryList();
540 kdDebug(750) <<
"KSpellConfig" << thedir.path() <<
"\n" <<
endl;
541 kdDebug(750) <<
"entryList().count()="
542 << entryList.count() <<
endl;
544 TQStringList::const_iterator entryListItr = entryList.constBegin();
545 const TQStringList::const_iterator entryListEnd = entryList.constEnd();
547 for ( ; entryListItr != entryListEnd; ++entryListItr)
549 TQString fname, lname, hname;
550 fname = *entryListItr;
562 if ( !( fname.endsWith(
".rws") || fname.endsWith(
".multi") ) ) {
570 if (fname.endsWith(
".multi")) fname.remove (fname.length()-6,6);
572 if (fname.endsWith(
".rws")) fname.remove (fname.length()-4,4);
574 if (
interpret (fname, lname, hname) && langfnames.first().isEmpty())
578 langfnames.remove ( langfnames.begin() );
579 langfnames.prepend ( fname );
581 hname=i18n(
"default spelling dictionary"
582 ,
"Default - %1").arg(hname);
584 dictcombo->changeItem (hname,0);
588 langfnames.append (fname);
589 dictcombo->insertItem (hname);
600 if ( iclient == KS_CLIENT_ISPELL ) {
602 langfnames.append(
"");
603 box->insertItem( i18n(
"ISpell Default") );
606 TQFileInfo dir (
"/usr/lib/ispell");
607 if (!dir.exists() || !dir.isDir())
608 dir.setFile (
"/usr/local/lib/ispell");
609 if (!dir.exists() || !dir.isDir())
610 dir.setFile (
"/usr/local/share/ispell");
611 if (!dir.exists() || !dir.isDir())
612 dir.setFile (
"/usr/share/ispell");
613 if (!dir.exists() || !dir.isDir())
614 dir.setFile (
"/usr/pkg/lib");
620 if (!dir.exists() || !dir.isDir())
return;
622 kdDebug(750) <<
"KSpellConfig::getAvailDictsIspell "
623 << dir.filePath() <<
" " << dir.dirPath() <<
endl;
625 const TQDir thedir (dir.filePath(),
"*.hash");
626 const TQStringList entryList = thedir.entryList();
628 kdDebug(750) <<
"KSpellConfig" << thedir.path() <<
"\n" <<
endl;
629 kdDebug(750) <<
"entryList().count()="
630 << entryList.count() <<
endl;
632 TQStringList::const_iterator entryListItr = entryList.constBegin();
633 const TQStringList::const_iterator entryListEnd = entryList.constEnd();
635 for ( ; entryListItr != entryListEnd; ++entryListItr)
637 TQString fname, lname, hname;
638 fname = *entryListItr;
641 if (fname.endsWith(
".hash")) fname.remove (fname.length()-5,5);
643 if (
interpret (fname, lname, hname) && langfnames.first().isEmpty())
647 langfnames.remove ( langfnames.begin() );
648 langfnames.prepend ( fname );
650 hname=i18n(
"default spelling dictionary"
651 ,
"Default - %1 [%2]").arg(hname).arg(fname);
653 box->changeItem (hname,0);
657 langfnames.append (fname);
658 hname=hname+
" ["+fname+
"]";
660 box->insertItem (hname);
663 }
else if ( iclient == KS_CLIENT_HSPELL ) {
665 box->insertItem( i18n(
"Hebrew") );
666 langfnames.append(
"");
667 sChangeEncoding( KS_E_CP1255 );
668 }
else if ( iclient == KS_CLIENT_ZEMBEREK ) {
670 box->insertItem( i18n(
"Turkish") );
671 langfnames.append(
"");
672 sChangeEncoding( KS_E_UTF8 );
676 langfnames.append(
"");
677 box->insertItem (i18n(
"ASpell Default"));
681 TQFileInfo dir (
"/usr/lib" KDELIBSUFF
"/aspell");
682 if (!dir.exists() || !dir.isDir())
683 dir.setFile (
"/usr/lib" KDELIBSUFF
"/aspell-0.60");
684 if (!dir.exists() || !dir.isDir())
685 dir.setFile (
"/usr/local/lib" KDELIBSUFF
"/aspell");
686 if (!dir.exists() || !dir.isDir())
687 dir.setFile (
"/usr/share/aspell");
688 if (!dir.exists() || !dir.isDir())
689 dir.setFile (
"/usr/local/share/aspell");
690 if (!dir.exists() || !dir.isDir())
691 dir.setFile (
"/usr/pkg/lib/aspell");
692 if (!dir.exists() || !dir.isDir())
return;
694 kdDebug(750) <<
"KSpellConfig::getAvailDictsAspell "
695 << dir.filePath() <<
" " << dir.dirPath() <<
endl;
697 const TQDir thedir (dir.filePath(),
"*");
698 const TQStringList entryList = thedir.entryList();
700 kdDebug(750) <<
"KSpellConfig" << thedir.path() <<
"\n" <<
endl;
701 kdDebug(750) <<
"entryList().count()="
702 << entryList.count() <<
endl;
704 TQStringList::const_iterator entryListItr = entryList.constBegin();
705 const TQStringList::const_iterator entryListEnd = entryList.constEnd();
707 for ( ; entryListItr != entryListEnd; ++entryListItr)
709 TQString fname, lname, hname;
710 fname = *entryListItr;
722 if ( !( fname.endsWith(
".rws") || fname.endsWith(
".multi") ) ) {
730 if (fname.endsWith(
".multi")) fname.remove (fname.length()-6,6);
732 if (fname.endsWith(
".rws")) fname.remove (fname.length()-4,4);
734 if (
interpret (fname, lname, hname) && langfnames.first().isEmpty())
738 langfnames.remove ( langfnames.begin() );
739 langfnames.prepend ( fname );
741 hname=i18n(
"default spelling dictionary"
742 ,
"Default - %1").arg(hname);
744 box->changeItem (hname,0);
748 langfnames.append (fname);
749 box->insertItem (hname);
754 int whichelement = langfnames.findIndex(qsdict);
755 if ( whichelement >= 0 ) {
756 box->setCurrentItem( whichelement );
759 *dictionaries = langfnames;
768 KSpellConfig::setClient (
int c)
773 clientcombo->setCurrentItem(c);
799 if (qsdict.length()>5)
800 if ((
signed)qsdict.find(
".hash")==(signed)qsdict.length()-5)
801 qsdict.remove (qsdict.length()-5,5);
809 whichelement = langfnames.findIndex(s);
811 if(whichelement >= 0)
813 dictcombo->setCurrentItem(whichelement);
822 KSpellConfig::setDictFromList (
bool dfl)
836 KSpellConfig::setEncoding (
int enctype)
841 encodingcombo->setCurrentItem(enctype);
861 KSpellConfig::runTogether()
const
867 TQString KSpellConfig::dictionary ()
const
880 KSpellConfig::encoding ()
const
886 KSpellConfig::sRunTogether(
bool)
889 emit configChanged();
893 KSpellConfig::sNoAff(
bool)
896 emit configChanged();
925 KSpellConfig::sSetDictionary (
int i)
928 setDictFromList (
true);
929 TQTimer::singleShot( 0,
this, TQT_SIGNAL( configChanged() ) );
933 KSpellConfig::sDictionary(
bool on)
937 dictcombo->setEnabled (
true);
939 setDictFromList (
true);
943 dictcombo->setEnabled (
false);
945 emit configChanged();
949 KSpellConfig::sPathDictionary(
bool on)
959 setDictFromList (
false);
966 emit configChanged();
977 kapp->invokeHelp(
"configuration",
"tdespell");
1000 setDictFromList (ksc.dictFromList());
1002 setEncoding (ksc.encoding());
1003 setClient (ksc.
client());
1012 ignorelist=_ignorelist;
1016 KSpellConfig::ignoreList ()
const
1025 d->replacelist=_replacelist;
1029 KSpellConfig::replaceAllList()
const
1031 return d->replacelist;
1034 #include "ksconfig.moc"