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, TQ_SIGNAL(toggled(
bool)), TQ_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, TQ_SIGNAL(toggled(
bool)), TQ_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, TQ_SIGNAL (activated(
int)),
115 this, TQ_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, TQ_SIGNAL(activated(
int)),
this,
140 TQ_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, TQ_SIGNAL (activated(
int)),
this,
153 TQ_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, TQ_SIGNAL(clicked()),
this, TQ_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", DEFAULT_SPELL_CHECKER) );
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") );
446 <<
"/usr/" SYSTEM_LIBDIR
"/ispell"
448 <<
"/usr/local/" SYSTEM_LIBDIR
"/ispell"
449 <<
"/usr/local/lib/ispell"
450 <<
"/usr/local/share/ispell"
451 <<
"/usr/share/ispell"
453 for (TQStringList::ConstIterator it=dirs.begin(); it != dirs.end(); ++it) {
455 if (dir.exists() && dir.isDir()) {
462 if (!dir.exists() || !dir.isDir())
return;
464 kdDebug(750) <<
"KSpellConfig::getAvailDictsIspell "
465 << dir.filePath() <<
" " << dir.dirPath() <<
endl;
467 const TQDir thedir (dir.filePath(),
"*.hash");
468 const TQStringList entryList = thedir.entryList();
470 kdDebug(750) <<
"KSpellConfig" << thedir.path() <<
"\n" <<
endl;
471 kdDebug(750) <<
"entryList().count()="
472 << entryList.count() <<
endl;
474 TQStringList::const_iterator entryListItr = entryList.constBegin();
475 const TQStringList::const_iterator entryListEnd = entryList.constEnd();
477 for ( ; entryListItr != entryListEnd; ++entryListItr)
479 TQString fname, lname, hname;
480 fname = *entryListItr;
483 if (fname.endsWith(
".hash")) fname.remove (fname.length()-5,5);
485 if (
interpret (fname, lname, hname) && langfnames.first().isEmpty())
489 langfnames.remove ( langfnames.begin() );
490 langfnames.prepend ( fname );
492 hname=i18n(
"default spelling dictionary"
493 ,
"Default - %1 [%2]").arg(hname).arg(fname);
495 dictcombo->changeItem (hname,0);
499 langfnames.append (fname);
500 hname=hname+
" ["+fname+
"]";
502 dictcombo->insertItem (hname);
507 void KSpellConfig::getAvailDictsAspell () {
512 langfnames.append(
"");
513 dictcombo->insertItem (i18n(
"ASpell Default"));
517 TQFileInfo dir ( ASPELL_DATADIR );
518 if (!dir.exists() || !dir.isDir())
519 dir.setFile (
"/usr/lib" KDELIBSUFF
"/aspell-0.60");
520 if (!dir.exists() || !dir.isDir())
521 dir.setFile (
"/usr/local/lib" KDELIBSUFF
"/aspell");
522 if (!dir.exists() || !dir.isDir())
523 dir.setFile (
"/usr/share/aspell");
524 if (!dir.exists() || !dir.isDir())
525 dir.setFile (
"/usr/local/share/aspell");
526 if (!dir.exists() || !dir.isDir())
527 dir.setFile (
"/usr/pkg/lib/aspell");
528 if (!dir.exists() || !dir.isDir())
return;
530 kdDebug(750) <<
"KSpellConfig::getAvailDictsAspell "
531 << dir.filePath() <<
" " << dir.dirPath() <<
endl;
533 const TQDir thedir (dir.filePath(),
"*");
534 const TQStringList entryList = thedir.entryList();
536 kdDebug(750) <<
"KSpellConfig" << thedir.path() <<
"\n" <<
endl;
537 kdDebug(750) <<
"entryList().count()="
538 << entryList.count() <<
endl;
540 TQStringList::const_iterator entryListItr = entryList.constBegin();
541 const TQStringList::const_iterator entryListEnd = entryList.constEnd();
543 for ( ; entryListItr != entryListEnd; ++entryListItr)
545 TQString fname, lname, hname;
546 fname = *entryListItr;
558 if ( !( fname.endsWith(
".rws") || fname.endsWith(
".multi") ) ) {
566 if (fname.endsWith(
".multi")) fname.remove (fname.length()-6,6);
568 if (fname.endsWith(
".rws")) fname.remove (fname.length()-4,4);
570 if (
interpret (fname, lname, hname) && langfnames.first().isEmpty())
574 langfnames.remove ( langfnames.begin() );
575 langfnames.prepend ( fname );
577 hname=i18n(
"default spelling dictionary"
578 ,
"Default - %1").arg(hname);
580 dictcombo->changeItem (hname,0);
584 langfnames.append (fname);
585 dictcombo->insertItem (hname);
596 if ( iclient == KS_CLIENT_ISPELL ) {
598 langfnames.append(
"");
599 box->insertItem( i18n(
"ISpell Default") );
603 TQFileInfo dir (ISPELL_LIBDIR);
605 TQFileInfo dir (
"/usr/lib/ispell");
606 if (!dir.exists() || !dir.isDir())
607 dir.setFile (
"/usr/local/lib/ispell");
608 if (!dir.exists() || !dir.isDir())
609 dir.setFile (
"/usr/local/share/ispell");
610 if (!dir.exists() || !dir.isDir())
611 dir.setFile (
"/usr/share/ispell");
612 if (!dir.exists() || !dir.isDir())
613 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, TQ_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"
static int spacingHint()
Return the number of pixels you shall use between widgets inside a dialog according to the KDE standa...
A configuration class/dialog for KSpell.
void setIgnoreList(TQStringList _ignorelist)
@sect Options setting routines.
bool writeGlobalSettings()
Call this method before this class is deleted if you want the settings you have (or the user has) cho...
KSpellConfig(TQWidget *parent=0, const char *name=0, KSpellConfig *spellConfig=0, bool addHelpButton=true)
Constructs a KSpellConfig with default or custom settings.
bool interpret(TQString &fname, TQString &lname, TQString &hname)
This takes a dictionary file name and provides both a language abbreviation appropriate for the $LANG...
void fillDicts(TQComboBox *box, TQStringList *dictionaries=0)
Get the translated dictionary names and, optionally, the corresponding internal dictionary names.
void setDictionary(const TQString qs)
Set the name of the dictionary to use.
void activateHelp(void)
Use this function to activate the help information for this widget.
void setNoRootAffix(bool)
Set an ISpell option.
virtual ~KSpellConfig()
Deconstructor.
void setReplaceAllList(TQStringList _replaceAllList)
The _replaceAllList contains word you like that replace word.
bool noRootAffix() const
Options reading routines.
void setRunTogether(bool)
Set an ISpell option.
int client() const
Spell checker client, see KSpellClients.
void sHelp()
Invokes the help documentation for tdespell.
TQString readEntry(const TQString &pKey, const TQString &aDefault=TQString::null) const
int readNumEntry(const TQString &pKey, int nDefault=0) const
void writeEntry(const TQString &pKey, const TQString &pValue, bool bPersistent=true, bool bGlobal=false, bool bNLS=false)
static TDEConfig * config()
static TDELocale * locale()
TQString twoAlphaToLanguageName(const TQString &code) const
TQString twoAlphaToCountryName(const TQString &code) const
kndbgstream & endl(kndbgstream &s)
kdbgstream kdDebug(int area=0)