00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include <qcheckbox.h>
00023 #include <qcombobox.h>
00024 #include <qlabel.h>
00025 #include <qlayout.h>
00026 #include <qpushbutton.h>
00027
00028 #include <kapplication.h>
00029 #include <kconfig.h>
00030 #include <kdebug.h>
00031 #include <kdialog.h>
00032 #include <kfiledialog.h>
00033 #include <kglobal.h>
00034 #include <klineedit.h>
00035 #include <klocale.h>
00036
00037 #include "ksconfig.h"
00038
00039 class KSpellConfigPrivate
00040 {
00041 public:
00042 QStringList replacelist;
00043 };
00044
00045
00046 KSpellConfig::KSpellConfig (const KSpellConfig &_ksc)
00047 : QWidget(0, 0), nodialog(true)
00048 , kc(0)
00049 , cb1(0)
00050 , cb2(0)
00051 , dictlist(0)
00052 , dictcombo(0)
00053 , encodingcombo(0)
00054 , clientcombo(0)
00055 {
00056 d= new KSpellConfigPrivate;
00057 setReplaceAllList( _ksc.replaceAllList ());
00058 setNoRootAffix (_ksc.noRootAffix());
00059 setRunTogether (_ksc.runTogether());
00060 setDictionary (_ksc.dictionary());
00061 setDictFromList (_ksc.dictFromList());
00062
00063 setIgnoreList (_ksc.ignoreList());
00064 setEncoding (_ksc.encoding());
00065 setClient (_ksc.client());
00066 }
00067
00068
00069 KSpellConfig::KSpellConfig( QWidget *parent, const char *name,
00070 KSpellConfig *_ksc, bool addHelpButton )
00071 : QWidget (parent, name), nodialog(false)
00072 , kc(0)
00073 , cb1(0)
00074 , cb2(0)
00075 , dictlist(0)
00076 , dictcombo(0)
00077 , encodingcombo(0)
00078 , clientcombo(0)
00079 {
00080 d= new KSpellConfigPrivate;
00081 kc = KGlobal::config();
00082 if( _ksc == 0 )
00083 {
00084 readGlobalSettings();
00085 }
00086 else
00087 {
00088 setNoRootAffix (_ksc->noRootAffix());
00089 setRunTogether (_ksc->runTogether());
00090 setDictionary (_ksc->dictionary());
00091 setDictFromList (_ksc->dictFromList());
00092
00093 setIgnoreList (_ksc->ignoreList());
00094 setEncoding (_ksc->encoding());
00095 setClient (_ksc->client());
00096 }
00097
00098 QGridLayout *glay = new QGridLayout (this, 6, 3, 0, KDialog::spacingHint() );
00099 cb1 = new QCheckBox(i18n("Create root/affix combinations"
00100 " not in dictionary"), this );
00101 connect( cb1, SIGNAL(toggled(bool)), SLOT(sNoAff(bool)) );
00102 glay->addMultiCellWidget( cb1, 0, 0, 0, 2 );
00103
00104 cb2 = new QCheckBox( i18n("Consider run-together words"
00105 " as spelling errors"), this );
00106 connect( cb2, SIGNAL(toggled(bool)), SLOT(sRunTogether(bool)) );
00107 glay->addMultiCellWidget( cb2, 1, 1, 0, 2 );
00108
00109 dictcombo = new QComboBox( this );
00110 dictcombo->setInsertionPolicy (QComboBox::NoInsertion);
00111 connect (dictcombo, SIGNAL (activated (int)),
00112 this, SLOT (sSetDictionary (int)));
00113 glay->addMultiCellWidget( dictcombo, 2, 2, 1, 2 );
00114
00115 dictlist = new QLabel (dictcombo, i18n("Dictionary:"), this);
00116 glay->addWidget( dictlist, 2 ,0 );
00117
00118 encodingcombo = new QComboBox( this );
00119 encodingcombo->insertItem ("US-ASCII");
00120 encodingcombo->insertItem ("ISO 8859-1");
00121 encodingcombo->insertItem ("ISO 8859-2");
00122 encodingcombo->insertItem ("ISO 8859-3");
00123 encodingcombo->insertItem ("ISO 8859-4");
00124 encodingcombo->insertItem ("ISO 8859-5");
00125 encodingcombo->insertItem ("ISO 8859-7");
00126 encodingcombo->insertItem ("ISO 8859-8");
00127 encodingcombo->insertItem ("ISO 8859-9");
00128 encodingcombo->insertItem ("ISO 8859-13");
00129 encodingcombo->insertItem ("ISO 8859-15");
00130 encodingcombo->insertItem ("UTF-8");
00131 encodingcombo->insertItem ("KOI8-R");
00132 encodingcombo->insertItem ("KOI8-U");
00133 encodingcombo->insertItem ("CP1251");
00134 encodingcombo->insertItem ("CP1255");
00135
00136 connect (encodingcombo, SIGNAL (activated(int)), this,
00137 SLOT (sChangeEncoding(int)));
00138 glay->addMultiCellWidget (encodingcombo, 3, 3, 1, 2);
00139
00140 QLabel *tmpQLabel = new QLabel( encodingcombo, i18n("Encoding:"), this);
00141 glay->addWidget( tmpQLabel, 3, 0 );
00142
00143
00144 clientcombo = new QComboBox( this );
00145 clientcombo->insertItem (i18n("International Ispell"));
00146 clientcombo->insertItem (i18n("Aspell"));
00147 clientcombo->insertItem (i18n("Hspell"));
00148 connect (clientcombo, SIGNAL (activated(int)), this,
00149 SLOT (sChangeClient(int)));
00150 glay->addMultiCellWidget( clientcombo, 4, 4, 1, 2 );
00151
00152 tmpQLabel = new QLabel( clientcombo, i18n("Client:"), this );
00153 glay->addWidget( tmpQLabel, 4, 0 );
00154
00155 if( addHelpButton == true )
00156 {
00157 QPushButton *pushButton = new QPushButton( i18n("&Help"), this );
00158 connect( pushButton, SIGNAL(clicked()), this, SLOT(sHelp()) );
00159 glay->addWidget(pushButton, 5, 2);
00160 }
00161
00162 fillInDialog();
00163 }
00164
00165 KSpellConfig::~KSpellConfig ()
00166 {
00167 delete d;
00168 }
00169
00170
00171 bool
00172 KSpellConfig::dictFromList () const
00173 {
00174 return dictfromlist;
00175 }
00176
00177 bool
00178 KSpellConfig::readGlobalSettings ()
00179 {
00180 KConfigGroupSaver cs(kc,"KSpell");
00181
00182 setNoRootAffix (kc->readNumEntry ("KSpell_NoRootAffix", 0));
00183 setRunTogether (kc->readNumEntry ("KSpell_RunTogether", 0));
00184 setDictionary (kc->readEntry ("KSpell_Dictionary", ""));
00185 setDictFromList (kc->readNumEntry ("KSpell_DictFromList", FALSE));
00186 setEncoding (kc->readNumEntry ("KSpell_Encoding", KS_E_ASCII));
00187 setClient (kc->readNumEntry ("KSpell_Client", KS_CLIENT_ISPELL));
00188
00189 return TRUE;
00190 }
00191
00192 bool
00193 KSpellConfig::writeGlobalSettings ()
00194 {
00195 KConfigGroupSaver cs(kc,"KSpell");
00196 kc->writeEntry ("KSpell_NoRootAffix",(int) noRootAffix (), TRUE, TRUE);
00197 kc->writeEntry ("KSpell_RunTogether", (int) runTogether (), TRUE, TRUE);
00198 kc->writeEntry ("KSpell_Dictionary", dictionary (), TRUE, TRUE);
00199 kc->writeEntry ("KSpell_DictFromList",(int) dictFromList(), TRUE, TRUE);
00200 kc->writeEntry ("KSpell_Encoding", (int) encoding(),
00201 TRUE, TRUE);
00202 kc->writeEntry ("KSpell_Client", client(),
00203 TRUE, TRUE);
00204 kc->sync();
00205 return TRUE;
00206 }
00207
00208 void
00209 KSpellConfig::sChangeEncoding(int i)
00210 {
00211 kdDebug(750) << "KSpellConfig::sChangeEncoding(" << i << ")" << endl;
00212 setEncoding (i);
00213 emit configChanged();
00214 }
00215
00216 void
00217 KSpellConfig::sChangeClient (int i)
00218 {
00219 setClient (i);
00220
00221
00222 if (dictcombo) {
00223 if (iclient == KS_CLIENT_ISPELL)
00224 getAvailDictsIspell();
00225 else if (iclient == KS_CLIENT_HSPELL)
00226 {
00227 langfnames.clear();
00228 dictcombo->clear();
00229 dictcombo->insertItem(i18n("Hebrew"));
00230 sChangeEncoding(KS_E_CP1255);
00231 }
00232 else
00233 getAvailDictsAspell();
00234 }
00235 emit configChanged();
00236 }
00237
00238 bool
00239 KSpellConfig::interpret (QString &fname, QString &lname,
00240 QString &hname)
00241
00242 {
00243
00244 kdDebug(750) << "KSpellConfig::interpret [" << fname << "]" << endl;
00245
00246 QString dname(fname);
00247
00248 if(dname.right(1)=="+")
00249 dname.remove(dname.length()-1, 1);
00250
00251 if(dname.right(3)=="sml" || dname.right(3)=="med" || dname.right(3)=="lrg" || dname.right(3)=="xlg")
00252 dname.remove(dname.length()-3,3);
00253
00254 QString extension;
00255
00256 int i = dname.find('-');
00257 if (i != -1)
00258 {
00259 extension = dname.mid(i+1);
00260 dname.truncate(i);
00261 }
00262
00263
00264 if (dname.length() == 2) {
00265 lname = dname;
00266 hname = KGlobal::locale()->twoAlphaToLanguageName(lname);
00267 }
00268 else if ((dname.length() == 5) && (dname[2] == '_')) {
00269 lname = dname.left(2);
00270 hname = KGlobal::locale()->twoAlphaToLanguageName(lname);
00271 QString country = KGlobal::locale()->twoAlphaToCountryName(dname.right(2));
00272 if (extension.isEmpty())
00273 extension = country;
00274 else
00275 extension = country + " - " + extension;
00276 }
00277
00278 else if (dname=="english" || dname=="american" ||
00279 dname=="british" || dname=="canadian") {
00280 lname="en"; hname=i18n("English");
00281 }
00282 else if (dname=="espa~nol" || dname=="espanol") {
00283 lname="es"; hname=i18n("Spanish");
00284 }
00285 else if (dname=="dansk") {
00286 lname="da"; hname=i18n("Danish");
00287 }
00288 else if (dname=="deutsch") {
00289 lname="de"; hname=i18n("German");
00290 }
00291 else if (dname=="german") {
00292 lname="de"; hname=i18n("German (new spelling)");
00293 }
00294 else if (dname=="portuguesb" || dname=="br") {
00295 lname="br"; hname=i18n("Brazilian Portuguese");
00296 }
00297 else if (dname=="portugues") {
00298 lname="pt"; hname=i18n("Portuguese");
00299 }
00300 else if (dname=="esperanto") {
00301 lname="eo"; hname=i18n("Esperanto");
00302 }
00303 else if (dname=="norsk") {
00304 lname="no"; hname=i18n("Norwegian");
00305 }
00306 else if (dname=="polish") {
00307 lname="pl"; hname=i18n("Polish"); sChangeEncoding(KS_E_LATIN2);
00308 }
00309 else if (dname=="russian") {
00310 lname="ru"; hname=i18n("Russian");
00311 }
00312 else if (dname=="slovensko") {
00313 lname="si"; hname=i18n("Slovenian"); sChangeEncoding(KS_E_LATIN2);
00314 }
00315 else if (dname=="slovak"){
00316 lname="sk"; hname=i18n("Slovak"); sChangeEncoding(KS_E_LATIN2);
00317 }
00318 else if (dname=="czech") {
00319 lname="cs"; hname=i18n("Czech"); sChangeEncoding(KS_E_LATIN2);
00320 }
00321 else if (dname=="svenska") {
00322 lname="sv"; hname=i18n("Swedish");
00323 }
00324 else if (dname=="swiss") {
00325 lname="de"; hname=i18n("Swiss German");
00326 }
00327 else if (dname=="ukrainian") {
00328 lname="uk"; hname=i18n("Ukrainian");
00329 }
00330 else if (dname=="lietuviu" || dname=="lithuanian") {
00331 lname="lt"; hname=i18n("Lithuanian");
00332 }
00333 else if (dname=="francais" || dname=="french") {
00334 lname="fr"; hname=i18n("French");
00335 }
00336 else if (dname=="belarusian") {
00337 lname="be"; hname=i18n("Belarusian");
00338 }
00339 else if( dname == "magyar" ) {
00340 lname="hu"; hname=i18n("Hungarian");
00341 sChangeEncoding(KS_E_LATIN2);
00342 }
00343 else {
00344 lname=""; hname=i18n("Unknown ispell dictionary", "Unknown");
00345 }
00346 if (!extension.isEmpty())
00347 {
00348 hname = hname + " (" + extension + ")";
00349 }
00350
00351
00352 if ( (KGlobal::locale()->language()==QString::fromLatin1("C") &&
00353 lname==QString::fromLatin1("en")) ||
00354 KGlobal::locale()->language()==lname)
00355 return TRUE;
00356
00357 return FALSE;
00358 }
00359
00360 void
00361 KSpellConfig::fillInDialog ()
00362 {
00363 if (nodialog)
00364 return;
00365
00366 kdDebug(750) << "KSpellConfig::fillinDialog" << endl;
00367
00368 cb1->setChecked (noRootAffix());
00369 cb2->setChecked (runTogether());
00370 encodingcombo->setCurrentItem (encoding());
00371 clientcombo->setCurrentItem (client());
00372
00373
00374 if (iclient == KS_CLIENT_ISPELL)
00375 getAvailDictsIspell();
00376 else if (iclient == KS_CLIENT_HSPELL)
00377 {
00378 langfnames.clear();
00379 dictcombo->clear();
00380 dictcombo->insertItem(i18n("Hebrew"));
00381 }
00382 else
00383 getAvailDictsAspell();
00384
00385
00386 int whichelement=-1;
00387
00388 if (dictFromList())
00389 for (unsigned int i=0; i<langfnames.count(); i++)
00390 {
00391 if (langfnames[i] == dictionary())
00392 whichelement=i;
00393 }
00394
00395 dictcombo->setMinimumWidth (dictcombo->sizeHint().width());
00396
00397 if (dictionary().isEmpty() || whichelement!=-1)
00398 {
00399 setDictFromList (TRUE);
00400 if (whichelement!=-1)
00401 dictcombo->setCurrentItem(whichelement);
00402 }
00403 else
00404
00405 if (langfnames.count()>=1)
00406 {
00407 setDictFromList (TRUE);
00408 dictcombo->setCurrentItem(0);
00409 }
00410 else
00411 setDictFromList (FALSE);
00412
00413 sDictionary (dictFromList());
00414 sPathDictionary (!dictFromList());
00415
00416 }
00417
00418
00419 void KSpellConfig::getAvailDictsIspell () {
00420
00421 langfnames.clear();
00422 dictcombo->clear();
00423 langfnames.append("");
00424 dictcombo->insertItem (i18n("ISpell Default"));
00425
00426
00427 QFileInfo dir ("/usr/lib/ispell");
00428 if (!dir.exists() || !dir.isDir())
00429 dir.setFile ("/usr/local/lib/ispell");
00430 if (!dir.exists() || !dir.isDir())
00431 dir.setFile ("/usr/local/share/ispell");
00432 if (!dir.exists() || !dir.isDir())
00433 dir.setFile ("/usr/share/ispell");
00434
00435
00436
00437
00438
00439 if (!dir.exists() || !dir.isDir()) return;
00440
00441 kdDebug(750) << "KSpellConfig::getAvailDictsIspell "
00442 << dir.filePath() << " " << dir.dirPath() << endl;
00443
00444 QDir thedir (dir.filePath(),"*.hash");
00445
00446 kdDebug(750) << "KSpellConfig" << thedir.path() << "\n" << endl;
00447 kdDebug(750) << "entryList().count()="
00448 << thedir.entryList().count() << endl;
00449
00450 for (unsigned int i=0;i<thedir.entryList().count();i++)
00451 {
00452 QString fname, lname, hname;
00453 fname = thedir [i];
00454
00455
00456 if (fname.right(5) == ".hash") fname.remove (fname.length()-5,5);
00457
00458 if (interpret (fname, lname, hname) && langfnames[0].isEmpty())
00459 {
00460
00461
00462 langfnames.remove ( langfnames.begin() );
00463 langfnames.prepend ( fname );
00464
00465 hname=i18n("default spelling dictionary"
00466 ,"Default - %1 [%2]").arg(hname).arg(fname);
00467
00468 dictcombo->changeItem (hname,0);
00469 }
00470 else
00471 {
00472 langfnames.append (fname);
00473 hname=hname+" ["+fname+"]";
00474
00475 dictcombo->insertItem (hname);
00476 }
00477 }
00478 }
00479
00480 void KSpellConfig::getAvailDictsAspell () {
00481
00482 langfnames.clear();
00483 dictcombo->clear();
00484
00485 langfnames.append("");
00486 dictcombo->insertItem (i18n("ASpell Default"));
00487
00488
00489
00490 QFileInfo dir ("/usr/lib/aspell");
00491 if (!dir.exists() || !dir.isDir())
00492 dir.setFile ("/usr/local/lib/aspell");
00493 if (!dir.exists() || !dir.isDir())
00494 dir.setFile ("/usr/share/aspell");
00495 if (!dir.exists() || !dir.isDir())
00496 dir.setFile ("/usr/local/share/aspell");
00497 if (!dir.exists() || !dir.isDir()) return;
00498
00499 kdDebug(750) << "KSpellConfig::getAvailDictsAspell "
00500 << dir.filePath() << " " << dir.dirPath() << endl;
00501
00502 QDir thedir (dir.filePath(),"*");
00503
00504 kdDebug(750) << "KSpellConfig" << thedir.path() << "\n" << endl;
00505 kdDebug(750) << "entryList().count()="
00506 << thedir.entryList().count() << endl;
00507
00508 for (unsigned int i=0; i<thedir.entryList().count(); i++)
00509 {
00510 QString fname, lname, hname;
00511 fname = thedir [i];
00512
00513
00514
00515
00516 if (fname[0] != '.')
00517 {
00518
00519
00520 if (fname.right(6) == ".multi") fname.remove (fname.length()-6,6);
00521
00522 if (interpret (fname, lname, hname) && langfnames[0].isEmpty())
00523 {
00524
00525
00526 langfnames.remove ( langfnames.begin() );
00527 langfnames.prepend ( fname );
00528
00529 hname=i18n("default spelling dictionary"
00530 ,"Default - %1").arg(hname);
00531
00532 dictcombo->changeItem (hname,0);
00533 }
00534 else
00535 {
00536 langfnames.append (fname);
00537 dictcombo->insertItem (hname);
00538 }
00539 }
00540 }
00541 }
00542
00543
00544
00545
00546
00547 void
00548 KSpellConfig::setClient (int c)
00549 {
00550 iclient = c;
00551
00552 if (clientcombo)
00553 clientcombo->setCurrentItem(c);
00554 }
00555
00556 void
00557 KSpellConfig::setNoRootAffix (bool b)
00558 {
00559 bnorootaffix=b;
00560
00561 if(cb1)
00562 cb1->setChecked(b);
00563 }
00564
00565 void
00566 KSpellConfig::setRunTogether(bool b)
00567 {
00568 bruntogether=b;
00569
00570 if(cb2)
00571 cb2->setChecked(b);
00572 }
00573
00574 void
00575 KSpellConfig::setDictionary (const QString s)
00576 {
00577 qsdict=s;
00578
00579 if (qsdict.length()>5)
00580 if ((signed)qsdict.find(".hash")==(signed)qsdict.length()-5)
00581 qsdict.remove (qsdict.length()-5,5);
00582
00583
00584 if(dictcombo)
00585 {
00586 int whichelement=-1;
00587 if (dictFromList())
00588 {
00589 for (unsigned int i=0;i<langfnames.count();i++)
00590 {
00591 if (langfnames[i] == s)
00592 whichelement=i;
00593 }
00594
00595 if(whichelement >= 0)
00596 {
00597 dictcombo->setCurrentItem(whichelement);
00598 }
00599 }
00600 }
00601
00602
00603 }
00604
00605 void
00606 KSpellConfig::setDictFromList (bool dfl)
00607 {
00608
00609 dictfromlist=dfl;
00610 }
00611
00612
00613
00614
00615
00616
00617
00618
00619 void
00620 KSpellConfig::setEncoding (int enctype)
00621 {
00622 enc=enctype;
00623
00624 if(encodingcombo)
00625 encodingcombo->setCurrentItem(enctype);
00626 }
00627
00628
00629
00630
00631 int
00632 KSpellConfig::client () const
00633 {
00634 return iclient;
00635 }
00636
00637
00638 bool
00639 KSpellConfig::noRootAffix () const
00640 {
00641 return bnorootaffix;
00642 }
00643
00644 bool
00645 KSpellConfig::runTogether() const
00646 {
00647 return bruntogether;
00648 }
00649
00650 const
00651 QString KSpellConfig::dictionary () const
00652 {
00653 return qsdict;
00654 }
00655
00656
00657
00658
00659
00660
00661
00662
00663 int
00664 KSpellConfig::encoding () const
00665 {
00666 return enc;
00667 }
00668
00669 void
00670 KSpellConfig::sRunTogether(bool)
00671 {
00672 setRunTogether (cb2->isChecked());
00673 emit configChanged();
00674 }
00675
00676 void
00677 KSpellConfig::sNoAff(bool)
00678 {
00679 setNoRootAffix (cb1->isChecked());
00680 emit configChanged();
00681 }
00682
00683
00684
00685
00686
00687
00688
00689
00690
00691
00692
00693
00694
00695
00696
00697
00698
00699
00700
00701
00702
00703
00704
00705
00706
00707
00708 void
00709 KSpellConfig::sSetDictionary (int i)
00710 {
00711 setDictionary (langfnames[i]);
00712 setDictFromList (TRUE);
00713 emit configChanged();
00714 }
00715
00716 void
00717 KSpellConfig::sDictionary(bool on)
00718 {
00719 if (on)
00720 {
00721 dictcombo->setEnabled (TRUE);
00722 setDictionary (langfnames[dictcombo->currentItem()] );
00723 setDictFromList (TRUE);
00724 }
00725 else
00726 {
00727 dictcombo->setEnabled (FALSE);
00728 }
00729 emit configChanged();
00730 }
00731
00732 void
00733 KSpellConfig::sPathDictionary(bool on)
00734 {
00735 return;
00736
00737
00738 if (on)
00739 {
00740
00741
00742
00743 setDictFromList (FALSE);
00744 }
00745 else
00746 {
00747
00748
00749 }
00750 emit configChanged();
00751 }
00752
00753
00754 void KSpellConfig::activateHelp( void )
00755 {
00756 sHelp();
00757 }
00758
00759 void KSpellConfig::sHelp( void )
00760 {
00761 kapp->invokeHelp("configuration", "kspell");
00762 }
00763
00764
00765
00766
00767
00768
00769
00770
00771
00772
00773
00774
00775
00776 void
00777 KSpellConfig::operator= (const KSpellConfig &ksc)
00778 {
00779
00780
00781 setNoRootAffix (ksc.noRootAffix());
00782 setRunTogether (ksc.runTogether());
00783 setDictionary (ksc.dictionary());
00784 setDictFromList (ksc.dictFromList());
00785
00786 setEncoding (ksc.encoding());
00787 setClient (ksc.client());
00788
00789 fillInDialog();
00790 }
00791
00792 void
00793 KSpellConfig::setIgnoreList (QStringList _ignorelist)
00794 {
00795 ignorelist=_ignorelist;
00796 }
00797
00798 QStringList
00799 KSpellConfig::ignoreList () const
00800 {
00801 return ignorelist;
00802 }
00803
00804 void
00805 KSpellConfig::setReplaceAllList (QStringList _replacelist)
00806 {
00807 d->replacelist=_replacelist;
00808 }
00809
00810 QStringList
00811 KSpellConfig::replaceAllList () const
00812 {
00813 return d->replacelist;
00814 }
00815
00816 #include "ksconfig.moc"
00817
00818
00819