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") );
447 TQFileInfo dir (
"/usr/lib" KDELIBSUFF
"/ispell");
448 if (!dir.exists() || !dir.isDir())
449 dir.setFile (
"/usr/local/lib" KDELIBSUFF
"/ispell");
450 if (!dir.exists() || !dir.isDir())
451 dir.setFile (
"/usr/local/share/ispell");
452 if (!dir.exists() || !dir.isDir())
453 dir.setFile (
"/usr/share/ispell");
454 if (!dir.exists() || !dir.isDir())
455 dir.setFile (
"/usr/pkg/lib");
461 if (!dir.exists() || !dir.isDir())
return;
463 kdDebug(750) <<
"KSpellConfig::getAvailDictsIspell " 464 << dir.filePath() <<
" " << dir.dirPath() <<
endl;
466 const TQDir thedir (dir.filePath(),
"*.hash");
467 const TQStringList entryList = thedir.entryList();
469 kdDebug(750) <<
"KSpellConfig" << thedir.path() <<
"\n" <<
endl;
470 kdDebug(750) <<
"entryList().count()=" 471 << entryList.count() <<
endl;
473 TQStringList::const_iterator entryListItr = entryList.constBegin();
474 const TQStringList::const_iterator entryListEnd = entryList.constEnd();
476 for ( ; entryListItr != entryListEnd; ++entryListItr)
478 TQString fname, lname, hname;
479 fname = *entryListItr;
482 if (fname.endsWith(
".hash")) fname.remove (fname.length()-5,5);
484 if (
interpret (fname, lname, hname) && langfnames.first().isEmpty())
488 langfnames.remove ( langfnames.begin() );
489 langfnames.prepend ( fname );
491 hname=i18n(
"default spelling dictionary" 492 ,
"Default - %1 [%2]").arg(hname).arg(fname);
494 dictcombo->changeItem (hname,0);
498 langfnames.append (fname);
499 hname=hname+
" ["+fname+
"]";
501 dictcombo->insertItem (hname);
506 void KSpellConfig::getAvailDictsAspell () {
511 langfnames.append(
"");
512 dictcombo->insertItem (i18n(
"ASpell Default"));
516 TQFileInfo dir ( ASPELL_DATADIR );
517 if (!dir.exists() || !dir.isDir())
518 dir.setFile (
"/usr/lib" KDELIBSUFF
"/aspell-0.60");
519 if (!dir.exists() || !dir.isDir())
520 dir.setFile (
"/usr/local/lib" KDELIBSUFF
"/aspell");
521 if (!dir.exists() || !dir.isDir())
522 dir.setFile (
"/usr/share/aspell");
523 if (!dir.exists() || !dir.isDir())
524 dir.setFile (
"/usr/local/share/aspell");
525 if (!dir.exists() || !dir.isDir())
526 dir.setFile (
"/usr/pkg/lib/aspell");
527 if (!dir.exists() || !dir.isDir())
return;
529 kdDebug(750) <<
"KSpellConfig::getAvailDictsAspell " 530 << dir.filePath() <<
" " << dir.dirPath() <<
endl;
532 const TQDir thedir (dir.filePath(),
"*");
533 const TQStringList entryList = thedir.entryList();
535 kdDebug(750) <<
"KSpellConfig" << thedir.path() <<
"\n" <<
endl;
536 kdDebug(750) <<
"entryList().count()=" 537 << entryList.count() <<
endl;
539 TQStringList::const_iterator entryListItr = entryList.constBegin();
540 const TQStringList::const_iterator entryListEnd = entryList.constEnd();
542 for ( ; entryListItr != entryListEnd; ++entryListItr)
544 TQString fname, lname, hname;
545 fname = *entryListItr;
557 if ( !( fname.endsWith(
".rws") || fname.endsWith(
".multi") ) ) {
565 if (fname.endsWith(
".multi")) fname.remove (fname.length()-6,6);
567 if (fname.endsWith(
".rws")) fname.remove (fname.length()-4,4);
569 if (
interpret (fname, lname, hname) && langfnames.first().isEmpty())
573 langfnames.remove ( langfnames.begin() );
574 langfnames.prepend ( fname );
576 hname=i18n(
"default spelling dictionary" 577 ,
"Default - %1").arg(hname);
579 dictcombo->changeItem (hname,0);
583 langfnames.append (fname);
584 dictcombo->insertItem (hname);
595 if ( iclient == KS_CLIENT_ISPELL ) {
597 langfnames.append(
"");
598 box->insertItem( i18n(
"ISpell Default") );
601 TQFileInfo dir (
"/usr/lib/ispell");
602 if (!dir.exists() || !dir.isDir())
603 dir.setFile (
"/usr/local/lib/ispell");
604 if (!dir.exists() || !dir.isDir())
605 dir.setFile (
"/usr/local/share/ispell");
606 if (!dir.exists() || !dir.isDir())
607 dir.setFile (
"/usr/share/ispell");
608 if (!dir.exists() || !dir.isDir())
609 dir.setFile (
"/usr/pkg/lib");
615 if (!dir.exists() || !dir.isDir())
return;
617 kdDebug(750) <<
"KSpellConfig::getAvailDictsIspell " 618 << dir.filePath() <<
" " << dir.dirPath() <<
endl;
620 const TQDir thedir (dir.filePath(),
"*.hash");
621 const TQStringList entryList = thedir.entryList();
623 kdDebug(750) <<
"KSpellConfig" << thedir.path() <<
"\n" <<
endl;
624 kdDebug(750) <<
"entryList().count()=" 625 << entryList.count() <<
endl;
627 TQStringList::const_iterator entryListItr = entryList.constBegin();
628 const TQStringList::const_iterator entryListEnd = entryList.constEnd();
630 for ( ; entryListItr != entryListEnd; ++entryListItr)
632 TQString fname, lname, hname;
633 fname = *entryListItr;
636 if (fname.endsWith(
".hash")) fname.remove (fname.length()-5,5);
638 if (
interpret (fname, lname, hname) && langfnames.first().isEmpty())
642 langfnames.remove ( langfnames.begin() );
643 langfnames.prepend ( fname );
645 hname=i18n(
"default spelling dictionary" 646 ,
"Default - %1 [%2]").arg(hname).arg(fname);
648 box->changeItem (hname,0);
652 langfnames.append (fname);
653 hname=hname+
" ["+fname+
"]";
655 box->insertItem (hname);
658 }
else if ( iclient == KS_CLIENT_HSPELL ) {
660 box->insertItem( i18n(
"Hebrew") );
661 langfnames.append(
"");
662 sChangeEncoding( KS_E_CP1255 );
663 }
else if ( iclient == KS_CLIENT_ZEMBEREK ) {
665 box->insertItem( i18n(
"Turkish") );
666 langfnames.append(
"");
667 sChangeEncoding( KS_E_UTF8 );
671 langfnames.append(
"");
672 box->insertItem (i18n(
"ASpell Default"));
676 TQFileInfo dir (
"/usr/lib" KDELIBSUFF
"/aspell");
677 if (!dir.exists() || !dir.isDir())
678 dir.setFile (
"/usr/lib" KDELIBSUFF
"/aspell-0.60");
679 if (!dir.exists() || !dir.isDir())
680 dir.setFile (
"/usr/local/lib" KDELIBSUFF
"/aspell");
681 if (!dir.exists() || !dir.isDir())
682 dir.setFile (
"/usr/share/aspell");
683 if (!dir.exists() || !dir.isDir())
684 dir.setFile (
"/usr/local/share/aspell");
685 if (!dir.exists() || !dir.isDir())
686 dir.setFile (
"/usr/pkg/lib/aspell");
687 if (!dir.exists() || !dir.isDir())
return;
689 kdDebug(750) <<
"KSpellConfig::getAvailDictsAspell " 690 << dir.filePath() <<
" " << dir.dirPath() <<
endl;
692 const TQDir thedir (dir.filePath(),
"*");
693 const TQStringList entryList = thedir.entryList();
695 kdDebug(750) <<
"KSpellConfig" << thedir.path() <<
"\n" <<
endl;
696 kdDebug(750) <<
"entryList().count()=" 697 << entryList.count() <<
endl;
699 TQStringList::const_iterator entryListItr = entryList.constBegin();
700 const TQStringList::const_iterator entryListEnd = entryList.constEnd();
702 for ( ; entryListItr != entryListEnd; ++entryListItr)
704 TQString fname, lname, hname;
705 fname = *entryListItr;
717 if ( !( fname.endsWith(
".rws") || fname.endsWith(
".multi") ) ) {
725 if (fname.endsWith(
".multi")) fname.remove (fname.length()-6,6);
727 if (fname.endsWith(
".rws")) fname.remove (fname.length()-4,4);
729 if (
interpret (fname, lname, hname) && langfnames.first().isEmpty())
733 langfnames.remove ( langfnames.begin() );
734 langfnames.prepend ( fname );
736 hname=i18n(
"default spelling dictionary" 737 ,
"Default - %1").arg(hname);
739 box->changeItem (hname,0);
743 langfnames.append (fname);
744 box->insertItem (hname);
749 int whichelement = langfnames.findIndex(qsdict);
750 if ( whichelement >= 0 ) {
751 box->setCurrentItem( whichelement );
754 *dictionaries = langfnames;
763 KSpellConfig::setClient (
int c)
768 clientcombo->setCurrentItem(c);
794 if (qsdict.length()>5)
795 if ((
signed)qsdict.find(
".hash")==(signed)qsdict.length()-5)
796 qsdict.remove (qsdict.length()-5,5);
804 whichelement = langfnames.findIndex(s);
806 if(whichelement >= 0)
808 dictcombo->setCurrentItem(whichelement);
817 KSpellConfig::setDictFromList (
bool dfl)
831 KSpellConfig::setEncoding (
int enctype)
836 encodingcombo->setCurrentItem(enctype);
856 KSpellConfig::runTogether()
const 862 TQString KSpellConfig::dictionary ()
const 875 KSpellConfig::encoding ()
const 881 KSpellConfig::sRunTogether(
bool)
884 emit configChanged();
888 KSpellConfig::sNoAff(
bool)
891 emit configChanged();
920 KSpellConfig::sSetDictionary (
int i)
923 setDictFromList (
true);
924 TQTimer::singleShot( 0,
this, TQT_SIGNAL( configChanged() ) );
928 KSpellConfig::sDictionary(
bool on)
932 dictcombo->setEnabled (
true);
934 setDictFromList (
true);
938 dictcombo->setEnabled (
false);
940 emit configChanged();
944 KSpellConfig::sPathDictionary(
bool on)
954 setDictFromList (
false);
961 emit configChanged();
972 kapp->invokeHelp(
"configuration",
"tdespell");
995 setDictFromList (ksc.dictFromList());
997 setEncoding (ksc.encoding());
1007 ignorelist=_ignorelist;
1011 KSpellConfig::ignoreList ()
const 1020 d->replacelist=_replacelist;
1024 KSpellConfig::replaceAllList()
const 1026 return d->replacelist;
1029 #include "ksconfig.moc" TQString twoAlphaToCountryName(const TQString &code) const
TQString language() const
void setNoRootAffix(bool)
Set an ISpell option.
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...
kdbgstream kdDebug(int area=0)
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 setReplaceAllList(TQStringList _replaceAllList)
The _replaceAllList contains word you like that replace word.
void sHelp()
Invokes the help documentation for tdespell.
bool writeGlobalSettings()
Call this method before this class is deleted if you want the settings you have (or the user has) cho...
static int spacingHint()
Return the number of pixels you shall use between widgets inside a dialog according to the KDE standa...
void writeEntry(const TQString &pKey, const TQString &pValue, bool bPersistent=true, bool bGlobal=false, bool bNLS=false)
bool noRootAffix() const
Options reading routines.
virtual ~KSpellConfig()
Deconstructor.
void setRunTogether(bool)
Set an ISpell option.
static TDELocale * locale()
A configuration class/dialog for KSpell.
void setIgnoreList(TQStringList _ignorelist)
Options setting routines.
int client() const
Spell checker client, see KSpellClients.
static TDEConfig * config()
kndbgstream & endl(kndbgstream &s)
void activateHelp(void)
Use this function to activate the help information for this widget.
TQString readEntry(const TQString &pKey, const TQString &aDefault=TQString::null) const
int readNumEntry(const TQString &pKey, int nDefault=0) const
TQString twoAlphaToLanguageName(const TQString &code) const