00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
#include <qcheckbox.h>
00022
#include <qcombobox.h>
00023
#include <qlabel.h>
00024
#include <qlayout.h>
00025
#include <kpushbutton.h>
00026
#include <qwhatsthis.h>
00027
#include <kapplication.h>
00028
#include <kconfig.h>
00029
#include <kdebug.h>
00030
#include <kdialog.h>
00031
#include <kfiledialog.h>
00032
#include <kglobal.h>
00033
#include <klineedit.h>
00034
#include <klocale.h>
00035
#include <kstdguiitem.h>
00036
00037
#include "koSconfig.h"
00038
00039
class KOSpellConfigPrivate
00040 {
00041
public:
00042 KOSpellConfigPrivate() : shown( false ) {}
00043
QStringList replacelist;
00044
bool shown;
00045 };
00046
00047
00048
KOSpellConfig::KOSpellConfig (
const KOSpellConfig &_ksc)
00049 :
QWidget(0, 0), nodialog(true)
00050 , kc(0)
00051 , cb1(0)
00052 , cb2(0)
00053 , dictlist(0)
00054 , dictcombo(0)
00055 , encodingcombo(0)
00056 ,clientcombo(0)
00057 ,cbIgnoreCase(0)
00058 ,cbIgnoreAccent(0)
00059 ,cbSpellWordWithNumber(0)
00060 ,cbDontCheckUpperWord(0)
00061 ,cbDontCheckTitleCase(0)
00062
00063 {
00064 m_bIgnoreCase =
false;
00065 m_bIgnoreAccent =
false;
00066 d=
new KOSpellConfigPrivate;
00067 setReplaceAllList( _ksc.
replaceAllList ());
00068 setNoRootAffix (_ksc.
noRootAffix());
00069 setRunTogether (_ksc.
runTogether());
00070 setDictionary (_ksc.
dictionary());
00071 setDictFromList (_ksc.
dictFromList());
00072 setIgnoreCase ( _ksc.
ignoreCase ());
00073 setIgnoreAccent( _ksc.
ignoreAccent());
00074 setIgnoreList (_ksc.
ignoreList());
00075 setEncoding (_ksc.
encoding());
00076 setSpellWordWithNumber( _ksc.
spellWordWithNumber());
00077 setDontCheckTitleCase( _ksc.
dontCheckTitleCase());
00078 setDontCheckUpperWord( _ksc.
dontCheckUpperWord());
00079 setClient (_ksc.
client());
00080 }
00081
00082
00083 KOSpellConfig::KOSpellConfig(
QWidget *parent,
const char *name,
00084
KOSpellConfig *_ksc,
bool addHelpButton )
00085 :
QWidget (parent, name), nodialog(false)
00086 , kc(0)
00087 , cb1(0)
00088 , cb2(0)
00089 , dictlist(0)
00090 , dictcombo(0)
00091 , encodingcombo(0)
00092 ,clientcombo(0)
00093 ,cbIgnoreCase(0)
00094 ,cbIgnoreAccent(0)
00095 ,cbSpellWordWithNumber(0)
00096 ,cbDontCheckUpperWord(0)
00097 ,cbDontCheckTitleCase(0)
00098 {
00099 m_bIgnoreCase =
false;
00100 m_bIgnoreAccent =
false;
00101 m_bSpellWordWithNumber =
false;
00102 d=
new KOSpellConfigPrivate;
00103 kc = KGlobal::config();
00104
if( _ksc == 0 )
00105 {
00106 readGlobalSettings();
00107 }
00108
else
00109 {
00110
setReplaceAllList( _ksc->
replaceAllList ());
00111
setNoRootAffix (_ksc->
noRootAffix());
00112
setRunTogether (_ksc->
runTogether());
00113
setDictionary (_ksc->
dictionary());
00114 setDictFromList (_ksc->
dictFromList());
00115
setIgnoreList (_ksc->
ignoreList());
00116 setEncoding (_ksc->
encoding());
00117 setIgnoreCase ( _ksc->
ignoreCase ());
00118 setIgnoreAccent( _ksc->
ignoreAccent());
00119 setSpellWordWithNumber( _ksc->
spellWordWithNumber());
00120 setDontCheckTitleCase( _ksc->
dontCheckTitleCase());
00121 setDontCheckUpperWord( _ksc->
dontCheckUpperWord());
00122 setClient (_ksc->
client());
00123 }
00124
00125
QGridLayout *glay =
new QGridLayout (
this, 8, 3, 0, KDialog::spacingHint() );
00126 cb1 =
new QCheckBox(i18n(
"Create root/affix combinations"
00127
" not in dictionary"),
this );
00128 connect( cb1, SIGNAL(toggled(
bool)), SLOT(sNoAff(
bool)) );
00129 glay->addMultiCellWidget( cb1, 0, 0, 0, 2 );
00130
00131 cb2 =
new QCheckBox( i18n(
"Consider run-together words"
00132
" as spelling errors"),
this );
00133 connect( cb2, SIGNAL(toggled(
bool)), SLOT(sRunTogether(
bool)) );
00134 glay->addMultiCellWidget( cb2, 1, 1, 0, 2 );
00135
00136 dictcombo =
new QComboBox(
this );
00137 dictcombo->setInsertionPolicy (QComboBox::NoInsertion);
00138 connect (dictcombo, SIGNAL (activated (
int)),
00139
this, SLOT (sSetDictionary (
int)));
00140 glay->addMultiCellWidget( dictcombo, 2, 2, 1, 2 );
00141
00142 dictlist =
new QLabel (dictcombo, i18n(
"Dictionary:"),
this);
00143 glay->addWidget( dictlist, 2 ,0 );
00144
00145 encodingcombo =
new QComboBox(
this );
00146 encodingcombo->insertItem (
"US-ASCII");
00147 encodingcombo->insertItem (
"ISO 8859-1");
00148 encodingcombo->insertItem (
"ISO 8859-2");
00149 encodingcombo->insertItem (
"ISO 8859-3");
00150 encodingcombo->insertItem (
"ISO 8859-4");
00151 encodingcombo->insertItem (
"ISO 8859-5");
00152 encodingcombo->insertItem (
"ISO 8859-7");
00153 encodingcombo->insertItem (
"ISO 8859-8");
00154 encodingcombo->insertItem (
"ISO 8859-9");
00155 encodingcombo->insertItem (
"ISO 8859-13");
00156 encodingcombo->insertItem (
"ISO 8859-15");
00157 encodingcombo->insertItem (
"UTF-8");
00158 encodingcombo->insertItem (
"KOI8-R");
00159 encodingcombo->insertItem (
"KOI8-U");
00160 encodingcombo->insertItem (
"CP1251");
00161
00162 connect (encodingcombo, SIGNAL (activated(
int)),
this,
00163 SLOT (sChangeEncoding(
int)));
00164 glay->addMultiCellWidget (encodingcombo, 3, 3, 1, 2);
00165
00166 QLabel *tmpQLabel =
new QLabel( encodingcombo, i18n(
"Encoding:"),
this);
00167 glay->addWidget( tmpQLabel, 3, 0 );
00168
00169 clientcombo =
new QComboBox(
this );
00170 clientcombo->insertItem (i18n(
"International Ispell"));
00171 clientcombo->insertItem (i18n(
"Aspell"));
00172 clientcombo->insertItem (i18n(
"Hspell"));
00173 connect (clientcombo, SIGNAL (activated(
int)),
this,
00174 SLOT (sChangeClient(
int)));
00175 glay->addMultiCellWidget( clientcombo, 4, 4, 1, 2 );
00176
00177 tmpQLabel =
new QLabel( clientcombo, i18n(
"Client:"),
this );
00178 glay->addWidget( tmpQLabel, 4, 0 );
00179
00180
if( addHelpButton ==
true )
00181 {
00182
QPushButton *pushButton =
new KPushButton( KStdGuiItem::help(),
this );
00183 connect( pushButton, SIGNAL(clicked()),
this, SLOT(sHelp()) );
00184 glay->addWidget(pushButton, 10, 2);
00185 }
00186
00187 cbIgnoreCase =
new QCheckBox(i18n(
"Ignore case when checking words"),
this );
00188 connect( cbIgnoreCase , SIGNAL(toggled(
bool)),
this, SLOT(slotIgnoreCase(
bool)) );
00189
00190 cbIgnoreAccent =
new QCheckBox(i18n(
"Ignore accents when checking words"),
this );
00191 connect( cbIgnoreAccent , SIGNAL(toggled(
bool)),
this, SLOT(slotIgnoreAccent(
bool)) );
00192
00193 cbSpellWordWithNumber =
new QCheckBox(i18n(
"Check words with numbers"),
this );
00194 connect( cbSpellWordWithNumber , SIGNAL(toggled(
bool)),
this, SLOT(slotSpellWordWithNumber(
bool)) );
00195
00196 cbDontCheckUpperWord=
new QCheckBox(i18n(
"Ignore uppercase words"),
this);
00197 connect( cbDontCheckUpperWord , SIGNAL(toggled(
bool)),
this, SLOT(slotDontSpellCheckUpperWord(
bool)) );
00198
00199 QWhatsThis::add( cbDontCheckUpperWord, i18n(
"This option tells the spell-checker to accept words that are written in uppercase, such as KDE.") );
00200
00201 cbDontCheckTitleCase=
new QCheckBox(i18n(
"Ignore title case words"),
this);
00202 connect( cbDontCheckTitleCase , SIGNAL(toggled(
bool)),
this, SLOT(slotDontCheckTitleCase(
bool)) );
00203
00204 QWhatsThis::add( cbDontCheckTitleCase, i18n(
"This option tells the spell-checker to accept words starting with an uppercase letter, such as United States."));
00205
00206
00207
00208 glay->addMultiCellWidget( cbIgnoreCase, 5,5,0 ,2 );
00209 glay->addMultiCellWidget( cbIgnoreAccent, 6,6,0 ,2 );
00210 glay->addMultiCellWidget( cbSpellWordWithNumber, 7,7,0 ,2 );
00211 glay->addMultiCellWidget( cbDontCheckUpperWord, 8,8,0 ,2 );
00212 glay->addMultiCellWidget( cbDontCheckTitleCase, 9,9,0 ,2 );
00213
00214
00215
00216
00217 }
00218
00219 KOSpellConfig::~KOSpellConfig ()
00220 {
00221
delete d;
00222 }
00223
00224
bool KOSpellConfig::dictFromList ()
const
00225
{
00226
return dictfromlist;
00227 }
00228
00229
bool KOSpellConfig::ignoreCase ()
const
00230
{
00231
return m_bIgnoreCase;
00232 }
00233
00234
bool KOSpellConfig::ignoreAccent()
const
00235
{
00236
return m_bIgnoreAccent;
00237 }
00238
00239
bool KOSpellConfig::readGlobalSettings ()
00240 {
00241 KConfigGroupSaver cs(kc,
"KSpell");
00242
00243
setNoRootAffix (kc->readNumEntry (
"KSpell_NoRootAffix", 0));
00244
setRunTogether (kc->readNumEntry (
"KSpell_RunTogether", 0));
00245
setDictionary (kc->readEntry (
"KSpell_Dictionary",
""));
00246 setDictFromList (kc->readNumEntry (
"KSpell_DictFromList", FALSE));
00247 setEncoding (kc->readNumEntry (
"KSpell_Encoding", KOS_E_ASCII));
00248 setIgnoreCase( kc->readNumEntry(
"KSpell_IgnoreCase", 0));
00249 setIgnoreAccent( kc->readNumEntry(
"KSpell_IgnoreAccent", 0));
00250 setSpellWordWithNumber( kc->readNumEntry(
"KSpell_SpellWordWithNumber",
false));
00251
00252 setDontCheckTitleCase( kc->readNumEntry(
"KSpell_dont_check_title_case",
false));
00253 setDontCheckUpperWord( kc->readNumEntry(
"KSpell_dont_check_upper_word",
false));
00254
00255 setClient (kc->readNumEntry (
"KSpell_Client", KOS_CLIENT_ASPELL));
00256
return TRUE;
00257 }
00258
00259 bool KOSpellConfig::writeGlobalSettings ()
00260 {
00261 KConfigGroupSaver cs(kc,
"KSpell");
00262 kc->writeEntry (
"KSpell_NoRootAffix",(
int)
noRootAffix (), TRUE, TRUE);
00263 kc->writeEntry (
"KSpell_RunTogether", (
int) runTogether (), TRUE, TRUE);
00264 kc->writeEntry (
"KSpell_Dictionary", dictionary (), TRUE, TRUE);
00265 kc->writeEntry (
"KSpell_DictFromList",(
int) dictFromList(), TRUE, TRUE);
00266 kc->writeEntry (
"KSpell_Encoding", (
int) encoding(),
00267 TRUE, TRUE);
00268 kc->writeEntry (
"KSpell_IgnoreCase",(
int) ignoreCase(), TRUE, TRUE);
00269 kc->writeEntry(
"KSpell_IgnoreAccent", (
int)ignoreAccent(), TRUE, TRUE);
00270 kc->writeEntry(
"KSpell_SpellWordWithNumber", (
int)spellWordWithNumber(), TRUE, TRUE);
00271
00272 kc->writeEntry(
"KSpell_dont_check_title_case", (
int)dontCheckTitleCase(),TRUE,TRUE);
00273 kc->writeEntry(
"KSpell_dont_check_upper_word", (
int)dontCheckUpperWord(),TRUE,TRUE);
00274
00275
00276 kc->writeEntry (
"KSpell_Client", client(),
00277 TRUE, TRUE);
00278 kc->sync();
00279
return TRUE;
00280 }
00281
00282
void KOSpellConfig::slotSpellWordWithNumber(
bool b)
00283 {
00284 setSpellWordWithNumber ( b );
00285 emit configChanged();
00286 }
00287
00288
void KOSpellConfig::slotDontSpellCheckUpperWord(
bool b)
00289 {
00290 setDontCheckUpperWord(b);
00291 emit configChanged();
00292 }
00293
00294
void KOSpellConfig::slotDontCheckTitleCase(
bool b)
00295 {
00296 setDontCheckTitleCase(b);
00297 emit configChanged();
00298 }
00299
00300
void KOSpellConfig::slotIgnoreCase(
bool b)
00301 {
00302 setIgnoreCase ( b );
00303 emit configChanged();
00304 }
00305
00306
void KOSpellConfig::slotIgnoreAccent(
bool b)
00307 {
00308 setIgnoreAccent ( b );
00309 emit configChanged();
00310 }
00311
00312
void KOSpellConfig::sChangeClient (
int i)
00313 {
00314 setClient (i);
00315
00316
00317
if (dictcombo) {
00318
if (iclient == KOS_CLIENT_ISPELL)
00319 getAvailDictsIspell();
00320
else if( iclient == KOS_CLIENT_ASPELL)
00321 getAvailDictsAspell();
00322
else if (iclient == KOS_CLIENT_HSPELL)
00323 {
00324 langfnames.clear();
00325 dictcombo->clear();
00326 dictcombo->insertItem(i18n(
"Hebrew"));
00327 sChangeEncoding(KOS_E_LATIN8);
00328 }
00329
#if 0 //for the futur :)
00330
else if( iclient == KOS_CLIENT_MYSPELL)
00331 getAvailDictsMyspell();
00332
#endif
00333
}
00334 emit configChanged();
00335 }
00336
00337
00338
00339
00340
void KOSpellConfig::sChangeEncoding(
int i)
00341 {
00342 kdDebug(30006) <<
"KOSpellConfig::sChangeEncoding(" << i <<
")" << endl;
00343 setEncoding (i);
00344 emit configChanged();
00345 }
00346
00347 bool KOSpellConfig::interpret (
QString &fname,
QString &lname,
00348
QString &hname)
00349 {
00350
00351 kdDebug(30006) <<
"KOSpellConfig::interpret [" << fname <<
"]" << endl;
00352
00353
QString dname(fname);
00354
00355
if(dname.right(1)==
"+")
00356 dname.remove(dname.length()-1, 1);
00357
00358
if(dname.right(3)==
"sml" || dname.right(3)==
"med" || dname.right(3)==
"lrg" || dname.right(3)==
"xlg")
00359 dname.remove(dname.length()-3,3);
00360
00361
QString extension;
00362
00363
int i = dname.find(
'-');
00364
if (i != -1)
00365 {
00366 extension = dname.mid(i+1);
00367 dname.truncate(i);
00368 }
00369
00370
00371
if (dname.length() == 2) {
00372 lname = dname;
00373 hname = KGlobal::locale()->twoAlphaToLanguageName(lname);
00374 }
00375
else if ((dname.length() == 5) && (dname[2] ==
'_')) {
00376 lname = dname.left(2);
00377 hname = KGlobal::locale()->twoAlphaToLanguageName(lname);
00378
QString country = KGlobal::locale()->twoAlphaToCountryName(dname.right(2));
00379
if (extension.isEmpty())
00380 extension = country;
00381
else
00382 extension = country +
" - " + extension;
00383 }
00384
00385
else if (dname==
"english" || dname==
"american" ||
00386 dname==
"british" || dname==
"canadian") {
00387 lname=
"en"; hname=i18n(
"English");
00388 }
00389
else if (dname==
"espa~nol" || dname==
"espanol") {
00390 lname=
"es"; hname=i18n(
"Spanish");
00391 }
00392
else if (dname==
"dansk") {
00393 lname=
"da"; hname=i18n(
"Danish");
00394 }
00395
else if (dname==
"deutsch") {
00396 lname=
"de"; hname=i18n(
"German");
00397 }
00398
else if (dname==
"german") {
00399 lname=
"de"; hname=i18n(
"German (new spelling)");
00400 }
00401
else if (dname==
"portuguesb" || dname==
"br") {
00402 lname=
"br"; hname=i18n(
"Brazilian Portuguese");
00403 }
00404
else if (dname==
"portugues") {
00405 lname=
"pt"; hname=i18n(
"Portuguese");
00406 }
00407
else if (dname==
"esperanto") {
00408 lname=
"eo"; hname=i18n(
"Esperanto");
00409 }
00410
else if (dname==
"norsk") {
00411 lname=
"no"; hname=i18n(
"Norwegian");
00412 }
00413
else if (dname==
"polish") {
00414 lname=
"pl"; hname=i18n(
"Polish");
00415 }
00416
else if (dname==
"russian") {
00417 lname=
"ru"; hname=i18n(
"Russian");
00418 }
00419
else if (dname==
"slovensko") {
00420 lname=
"si"; hname=i18n(
"Slovenian");
00421 }
00422
else if (dname==
"slovak"){
00423 lname=
"sk"; hname=i18n(
"Slovak");
00424 }
else if (dname==
"czech") {
00425 lname=
"cs"; hname=i18n(
"Czech");
00426 }
00427
else if (dname==
"svenska") {
00428 lname=
"sv"; hname=i18n(
"Swedish");
00429 }
00430
else if (dname==
"swiss") {
00431 lname=
"de"; hname=i18n(
"Swiss German");
00432 }
00433
else if (dname==
"ukrainian") {
00434 lname=
"uk"; hname=i18n(
"Ukrainian");
00435 }
00436
else if (dname==
"lietuviu" || dname==
"lithuanian") {
00437 lname=
"lt"; hname=i18n(
"Lithuanian");
00438 }
00439
else if (dname==
"francais" || dname==
"french") {
00440 lname=
"fr"; hname=i18n(
"French");
00441 }
00442
else if (dname==
"belarusian") {
00443 lname=
"be"; hname=i18n(
"Belarusian");
00444 }
00445
else if( dname ==
"magyar" ) {
00446 lname=
"hu"; hname=i18n(
"Hungarian");
00447
00448 }
00449
else {
00450 lname=
""; hname=i18n(
"Unknown ispell dictionary",
"Unknown");
00451 }
00452
if (!extension.isEmpty())
00453 {
00454 hname = hname +
" (" + extension +
")";
00455 }
00456
00457
00458
if ( (KGlobal::locale()->language()==QString::fromLatin1(
"C") &&
00459 lname==QString::fromLatin1(
"en")) ||
00460 KGlobal::locale()->language()==lname)
00461
return TRUE;
00462
00463
return FALSE;
00464 }
00465
00466
void KOSpellConfig::fillInDialog ()
00467 {
00468
if (nodialog)
00469
return;
00470
00471 kdDebug(30006) <<
"KOSpellConfig::fillinDialog" << endl;
00472
00473 cb1->setChecked (
noRootAffix());
00474 cb2->setChecked (runTogether());
00475 cbIgnoreCase->setChecked(ignoreCase());
00476 cbIgnoreAccent->setChecked(ignoreAccent());
00477 cbSpellWordWithNumber->setChecked(spellWordWithNumber());
00478 cbDontCheckUpperWord->setChecked(dontCheckUpperWord());
00479 cbDontCheckTitleCase->setChecked(dontCheckTitleCase());
00480
00481 encodingcombo->setCurrentItem (encoding());
00482 clientcombo->setCurrentItem( client() );
00483
00484
00485
00486
if (iclient == KOS_CLIENT_ISPELL)
00487 getAvailDictsIspell();
00488
else
00489 getAvailDictsAspell();
00490
00491
00492
int whichelement=-1;
00493
00494
if (dictFromList())
00495 {
00496
QString dict = dictionary();
00497
if (iclient == KOS_CLIENT_ISPELL)
00498 {
00499 whichelement = langfnames.findIndex( dict );
00500 }
00501
else if(iclient == KOS_CLIENT_ASPELL)
00502 {
00503 whichelement = listOfLanguageFileName().findIndex( dict );
00504 }
00505
else if (iclient == KOS_CLIENT_HSPELL)
00506 {
00507 langfnames.clear();
00508 dictcombo->clear();
00509 dictcombo->insertItem(i18n(
"Hebrew"));
00510 }
00511
00512 }
00513 dictcombo->setMinimumWidth (dictcombo->sizeHint().width());
00514
00515
if (dictionary().isEmpty() || whichelement!=-1)
00516 {
00517 setDictFromList (TRUE);
00518
if (whichelement!=-1)
00519 dictcombo->setCurrentItem(whichelement);
00520 }
00521
else
00522 {
00523
00524
if (langfnames.count()>=1)
00525 {
00526 setDictFromList (TRUE);
00527 dictcombo->setCurrentItem(0);
00528 }
00529
else
00530 setDictFromList (FALSE);
00531 }
00532 sDictionary (dictFromList());
00533 sPathDictionary (!dictFromList());
00534
00535 }
00536
00537
void KOSpellConfig::getAvailDictsIspell () {
00538
00539 langfnames.clear();
00540 dictcombo->clear();
00541 langfnames.append(
"");
00542 dictcombo->insertItem (i18n(
"ISpell Default"));
00543
00544
00545
QFileInfo dir (
"/usr/lib/ispell");
00546
if (!dir.exists() || !dir.isDir())
00547 dir.setFile (
"/usr/local/lib/ispell");
00548
if (!dir.exists() || !dir.isDir())
00549 dir.setFile (
"/usr/local/share/ispell");
00550
if (!dir.exists() || !dir.isDir())
00551 dir.setFile (
"/usr/share/ispell");
00552
00553
00554
00555
00556
00557
if (!dir.exists() || !dir.isDir())
return;
00558
00559 kdDebug(30006) <<
"KSpellConfig::getAvailDictsIspell "
00560 << dir.filePath() <<
" " << dir.dirPath() << endl;
00561
00562
QDir thedir (dir.filePath(),
"*.hash");
00563
00564 kdDebug(30006) <<
"KSpellConfig" << thedir.path() <<
"\n" << endl;
00565 kdDebug(30006) <<
"entryList().count()="
00566 << thedir.entryList().count() << endl;
00567
00568
for (
unsigned int i=0;i<thedir.entryList().count();i++)
00569 {
00570
QString fname, lname, hname;
00571 fname = thedir [i];
00572
00573
00574
if (fname.right(5) ==
".hash") fname.remove (fname.length()-5,5);
00575
00576
if (
interpret (fname, lname, hname) && langfnames[0].isEmpty())
00577 {
00578
00579
00580 langfnames.remove ( langfnames.begin() );
00581 langfnames.prepend ( fname );
00582
00583 hname=i18n(
"default spelling dictionary"
00584 ,
"Default - %1 [%2]").arg(hname).arg(fname);
00585
00586 dictcombo->changeItem (hname,0);
00587 }
00588
else
00589 {
00590 langfnames.append (fname);
00591 hname=hname+
" ["+fname+
"]";
00592
00593 dictcombo->insertItem (hname);
00594 }
00595 }
00596 }
00597
00598
void KOSpellConfig::setClient (
int c)
00599 {
00600 iclient = c;
00601
00602
if (clientcombo)
00603 clientcombo->setCurrentItem(c);
00604 }
00605
00606
int KOSpellConfig::client ()
const
00607
{
00608
return iclient;
00609 }
00610
00611
void KOSpellConfig::getAvailDictsAspell ()
00612 {
00613 langfnames.clear();
00614 dictcombo->clear();
00615 dictcombo->insertStringList( listOfAspellLanguages() );
00616 }
00617
00618
00619
00620
00621
00622
00623 void KOSpellConfig::setNoRootAffix (
bool b)
00624 {
00625 bnorootaffix=b;
00626
00627
if(cb1)
00628 cb1->setChecked(b);
00629 }
00630
00631 void KOSpellConfig::setRunTogether(
bool b)
00632 {
00633 bruntogether=b;
00634
00635
if(cb2)
00636 cb2->setChecked(b);
00637 }
00638
00639 void KOSpellConfig::setDictionary (
const QString &s)
00640 {
00641 qsdict=s;
00642
00643
if (qsdict.endsWith(
".hash"))
00644 qsdict.truncate(qsdict.length()-5);
00645
00646
00647
if(dictcombo)
00648 {
00649
int whichelement=-1;
00650
if (dictFromList())
00651 {
00652
if (iclient == KOS_CLIENT_ISPELL)
00653 {
00654 whichelement = langfnames.findIndex( qsdict );
00655 }
00656
else if(iclient == KOS_CLIENT_ASPELL)
00657 {
00658 whichelement = listOfLanguageFileName().findIndex( qsdict );
00659 }
00660
#if 0
00661
else if (iclient == KOS_CLIENT_HSPELL)
00662 {
00663 langfnames.clear();
00664 dictcombo->clear();
00665 dictcombo->insertItem(i18n(
"Hebrew"));
00666 }
00667
#endif
00668
if(whichelement >= 0)
00669 {
00670 dictcombo->setCurrentItem(whichelement);
00671 }
00672 }
00673 }
00674
00675
#if 0 // keep the distinction between e.g. british and american, don't resolve all to "en"
00676
QString ab, desc;
00677
interpret( qsdict, ab, desc );
00678 qsdict = ab;
00679
#endif
00680
}
00681
00682
void KOSpellConfig::setDictFromList (
bool dfl)
00683 {
00684 dictfromlist=dfl;
00685 }
00686
00687
void KOSpellConfig::setEncoding (
int enctype)
00688 {
00689 enc=enctype;
00690
00691
if(encodingcombo)
00692 encodingcombo->setCurrentItem(enctype);
00693 }
00694
00695
00696 bool KOSpellConfig::noRootAffix ()
const
00697
{
00698
return bnorootaffix;
00699 }
00700
00701
bool KOSpellConfig::runTogether()
const
00702
{
00703
return bruntogether;
00704 }
00705
00706
const QString KOSpellConfig::dictionary ()
const
00707
{
00708
return qsdict;
00709 }
00710
00711
int KOSpellConfig::encoding ()
const
00712
{
00713
return enc;
00714 }
00715
00716
void KOSpellConfig::sRunTogether(
bool)
00717 {
00718
setRunTogether (cb2->isChecked());
00719 emit configChanged();
00720 }
00721
00722
void KOSpellConfig::sNoAff(
bool)
00723 {
00724
setNoRootAffix (cb1->isChecked());
00725 emit configChanged();
00726 }
00727
00728
00729
QString KOSpellConfig::getLanguage(
int i )
00730 {
00731
if (iclient == KOS_CLIENT_ISPELL)
00732 {
00733
return langfnames[i];
00734 }
00735
else if(iclient == KOS_CLIENT_ASPELL)
00736 {
00737
return listOfLanguageFileName()[i];
00738 }
00739
#if 0
00740
else if (iclient == KOS_CLIENT_HSPELL)
00741 {
00742 langfnames.clear();
00743 dictcombo->clear();
00744 dictcombo->insertItem(i18n(
"Hebrew"));
00745 }
00746
#endif
00747
else
00748
return QString::null;
00749 }
00750
00751
void KOSpellConfig::sSetDictionary (
int i)
00752 {
00753
setDictionary (getLanguage( i ));
00754 setDictFromList (TRUE);
00755 emit configChanged();
00756 }
00757
00758
void
00759 KOSpellConfig::sDictionary(
bool on)
00760 {
00761
if (on)
00762 {
00763 dictcombo->setEnabled (TRUE);
00764
setDictionary (getLanguage( dictcombo->currentItem() ));
00765 setDictFromList (TRUE);
00766 }
00767
else
00768 {
00769 dictcombo->setEnabled (FALSE);
00770 }
00771 emit configChanged();
00772 }
00773
00774
void
00775 KOSpellConfig::sPathDictionary(
bool on)
00776 {
00777
return;
00778
00779
if (on)
00780 {
00781
00782
00783
00784 setDictFromList (FALSE);
00785 }
00786
else
00787 {
00788
00789
00790 }
00791 emit configChanged();
00792 }
00793
00794
00795 void KOSpellConfig::activateHelp(
void )
00796 {
00797 sHelp();
00798 }
00799
00800
void KOSpellConfig::sHelp(
void )
00801 {
00802 kapp->invokeHelp(
"configuration",
"kspell");
00803 }
00804
00805
void KOSpellConfig::operator= (
const KOSpellConfig &ksc)
00806 {
00807
00808
00809
setNoRootAffix (ksc.
noRootAffix());
00810
setRunTogether (ksc.
runTogether());
00811
setDictionary (ksc.
dictionary());
00812 setDictFromList (ksc.
dictFromList());
00813
00814 setEncoding (ksc.
encoding());
00815 setIgnoreAccent (ksc.
ignoreAccent());
00816 setIgnoreCase (ksc.
ignoreCase());
00817
00818
if ( isVisible() )
00819 fillInDialog();
00820
else
00821 d->shown =
false;
00822 }
00823
00824 void KOSpellConfig::setIgnoreList (
QStringList _ignorelist)
00825 {
00826 ignorelist=_ignorelist;
00827 }
00828
00829
QStringList KOSpellConfig::ignoreList ()
const
00830
{
00831
return ignorelist;
00832 }
00833
00834
bool KOSpellConfig::spellWordWithNumber()const
00835 {
00836
return m_bSpellWordWithNumber;
00837 }
00838
00839
bool KOSpellConfig::dontCheckTitleCase()const
00840 {
00841
return m_bDontCheckTitleCase;
00842 }
00843
00844
bool KOSpellConfig::dontCheckUpperWord()const
00845 {
00846
return m_bDontCheckUpperWord;
00847 }
00848
00849 void KOSpellConfig::setReplaceAllList (
QStringList _replacelist)
00850 {
00851 d->replacelist=_replacelist;
00852 }
00853
00854
QStringList KOSpellConfig::replaceAllList ()
const
00855
{
00856
return d->replacelist;
00857 }
00858
00859
void KOSpellConfig::setIgnoreCase (
bool b )
00860 {
00861 m_bIgnoreCase=b;
00862
if(cbIgnoreCase)
00863 cbIgnoreCase->setChecked(b);
00864
00865 }
00866
00867
void KOSpellConfig::setIgnoreAccent (
bool b )
00868 {
00869 m_bIgnoreAccent=b;
00870
if(cbIgnoreAccent)
00871 cbIgnoreAccent->setChecked(b);
00872
00873 }
00874
00875
void KOSpellConfig::setSpellWordWithNumber (
bool b )
00876 {
00877 m_bSpellWordWithNumber = b;
00878
if(cbSpellWordWithNumber)
00879 cbSpellWordWithNumber->setChecked(b);
00880
00881 }
00882
00883
void KOSpellConfig::setDontCheckTitleCase(
bool b)
00884 {
00885 m_bDontCheckTitleCase = b;
00886
if(cbDontCheckTitleCase)
00887 cbDontCheckTitleCase->setChecked(b);
00888
00889 }
00890
00891
void KOSpellConfig::setDontCheckUpperWord(
bool b)
00892 {
00893 m_bDontCheckUpperWord=b;
00894
if(cbDontCheckUpperWord)
00895 cbDontCheckUpperWord->setChecked(b);
00896
00897 }
00898
00899
00900
QStringList KOSpellConfig::s_aspellLanguageList =
QStringList();
00901 QStringList KOSpellConfig::s_aspellLanguageFileName = QStringList();
00902
00903 QStringList KOSpellConfig::listOfAspellLanguages()
00904 {
00905
if ( s_aspellLanguageList.count()==0 )
00906 createListOfLanguages();
00907
return s_aspellLanguageList;
00908 }
00909
00910 QStringList KOSpellConfig::listOfLanguageFileName()
00911 {
00912
if ( s_aspellLanguageFileName.count()==0 )
00913 createListOfLanguages();
00914
return s_aspellLanguageFileName;
00915 }
00916
00917
QString KOSpellConfig::fileNameFromLanguage(
const QString & _lang)
00918 {
00919
int pos = s_aspellLanguageList.findIndex( _lang );
00920
if ( pos != -1)
00921 {
00922
return s_aspellLanguageFileName[ pos ];
00923 }
00924
return QString::null;
00925 }
00926
00927
QString KOSpellConfig::languageFromFileName(
const QString &_lang )
00928 {
00929
int pos = s_aspellLanguageFileName.findIndex( _lang );
00930
if ( pos != -1)
00931
return s_aspellLanguageList[ pos ];
00932
else
00933
return QString::null;
00934 }
00935
00936
void KOSpellConfig::createListOfLanguages()
00937 {
00938 s_aspellLanguageFileName.append(
"");
00939 s_aspellLanguageList.append(i18n(
"ASpell Default"));
00940
00941
00942
00943
QFileInfo dir (
"/usr/lib/aspell");
00944
if (!dir.exists() || !dir.isDir())
00945 dir.setFile (
"/usr/local/lib/aspell");
00946
if (!dir.exists() || !dir.isDir())
00947 dir.setFile (
"/usr/share/aspell");
00948
if (!dir.exists() || !dir.isDir())
00949 dir.setFile (
"/usr/local/share/aspell");
00950
if (!dir.exists() || !dir.isDir())
return;
00951
00952 kdDebug(30006) <<
"KOSpellConfig::getAvailDictsAspell "
00953 << dir.filePath() <<
" " << dir.dirPath() << endl;
00954
00955
QDir thedir (dir.filePath(),
"*");
00956
00957 kdDebug(30006) <<
"KOSpellConfig" << thedir.path() <<
"\n" << endl;
00958 kdDebug(30006) <<
"entryList().count()="
00959 << thedir.entryList().count() << endl;
00960
00961
for (
unsigned int i=0; i<thedir.entryList().count(); i++)
00962 {
00963
QString fname, lname, hname;
00964 fname = thedir [i];
00965
00966
00967
00968
00969
if (fname[0] !=
'.')
00970 {
00971
00972
00973
if (fname.right(6) ==
".multi")
00974 fname.remove (fname.length()-6,6);
00975
00976
if (
interpret (fname, lname, hname) && s_aspellLanguageFileName[0].isEmpty())
00977 {
00978
00979
00980 s_aspellLanguageFileName.remove ( s_aspellLanguageFileName.begin() );
00981 s_aspellLanguageFileName.prepend ( fname );
00982
00983 hname=i18n(
"default spelling dictionary"
00984 ,
"Default - %1").arg(hname);
00985 s_aspellLanguageList[0]=hname;
00986 }
00987
else
00988 {
00989 s_aspellLanguageFileName.append( fname);
00990 s_aspellLanguageList.append( hname );
00991 }
00992 }
00993 }
00994
00995 }
00996
00997
int KOSpellConfig::indexFromLanguageFileName(
const QString &name)
00998 {
00999
int whichelement = 0;
01000
for (
unsigned int i=0; i<listOfLanguageFileName().count(); i++)
01001 {
01002
if (listOfLanguageFileName()[i] == name)
01003 {
01004 whichelement=i;
01005
break;
01006 }
01007 }
01008
return whichelement;
01009 }
01010
01011
01012
void KOSpellConfig::showEvent(
QShowEvent* ev )
01013 {
01014
if ( !d->shown )
01015 {
01016 d->shown =
true;
01017 fillInDialog();
01018 }
01019 QWidget::showEvent( ev );
01020 }
01021
01022
#include "koSconfig.moc"
01023
01024
01025