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