ksconfig.cpp

00001 /* This file is part of the KDE libraries
00002    Copyright (C) 1997 David Sweet <dsweet@kde.org>
00003    Copyright (C) 2000-2001 Wolfram Diestel <wolfram@steloj.de>
00004 
00005    This library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Library General Public
00007    License version 2 as published by the Free Software Foundation.
00008 
00009    This library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this library; see the file COPYING.LIB.  If not, write to
00016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017    Boston, MA 02110-1301, USA.
00018 */
00019 
00020 
00021 #include <qcheckbox.h>
00022 #include <qcombobox.h>
00023 #include <qlabel.h>
00024 #include <qlayout.h>
00025 
00026 #include <kapplication.h>
00027 #include <kconfig.h>
00028 #include <kdebug.h>
00029 #include <kdialog.h>
00030 #include <kfiledialog.h>
00031 #include <kglobal.h>
00032 #include <klineedit.h>
00033 #include <klocale.h>
00034 #include <kpushbutton.h>
00035 #include <kstdguiitem.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   //  setPersonalDict (_ksc.personalDict());
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 
00083   if( !_ksc )
00084   {
00085     readGlobalSettings();
00086   }
00087   else
00088   {
00089     setNoRootAffix( _ksc->noRootAffix() );
00090     setRunTogether( _ksc->runTogether() );
00091     setDictionary( _ksc->dictionary() );
00092     setDictFromList( _ksc->dictFromList() );
00093     //setPersonalDict (_ksc->personalDict());
00094     setIgnoreList( _ksc->ignoreList() );
00095     setEncoding( _ksc->encoding() );
00096     setClient( _ksc->client() );
00097   }
00098 
00099   QGridLayout *glay = new QGridLayout( this, 6, 3, 0, KDialog::spacingHint() );
00100   cb1 = new QCheckBox( i18n("Create &root/affix combinations"
00101                             " not in dictionary"), this, "NoRootAffix" );
00102   connect( cb1, SIGNAL(toggled(bool)), SLOT(sNoAff(bool)) );
00103   glay->addMultiCellWidget( cb1, 0, 0, 0, 2 );
00104 
00105   cb2 = new QCheckBox( i18n("Consider run-together &words"
00106                 " as spelling errors"), this, "RunTogether" );
00107   connect( cb2, SIGNAL(toggled(bool)), SLOT(sRunTogether(bool)) );
00108   glay->addMultiCellWidget( cb2, 1, 1, 0, 2 );
00109 
00110   dictcombo = new QComboBox( this, "DictFromList" );
00111   dictcombo->setInsertionPolicy( QComboBox::NoInsertion );
00112   connect( dictcombo, SIGNAL (activated(int)),
00113        this, SLOT (sSetDictionary(int)) );
00114   glay->addMultiCellWidget( dictcombo, 2, 2, 1, 2 );
00115 
00116   dictlist = new QLabel( dictcombo, i18n("&Dictionary:"), this );
00117   glay->addWidget( dictlist, 2 ,0 );
00118 
00119   encodingcombo = new QComboBox( this, "Encoding" );
00120   encodingcombo->insertItem( "US-ASCII" );
00121   encodingcombo->insertItem( "ISO 8859-1" );
00122   encodingcombo->insertItem( "ISO 8859-2" );
00123   encodingcombo->insertItem( "ISO 8859-3" );
00124   encodingcombo->insertItem( "ISO 8859-4" );
00125   encodingcombo->insertItem( "ISO 8859-5" );
00126   encodingcombo->insertItem( "ISO 8859-7" );
00127   encodingcombo->insertItem( "ISO 8859-8" );
00128   encodingcombo->insertItem( "ISO 8859-9" );
00129   encodingcombo->insertItem( "ISO 8859-13" );
00130   encodingcombo->insertItem( "ISO 8859-15" );
00131   encodingcombo->insertItem( "UTF-8" );
00132   encodingcombo->insertItem( "KOI8-R" );
00133   encodingcombo->insertItem( "KOI8-U" );
00134   encodingcombo->insertItem( "CP1251" );
00135   encodingcombo->insertItem( "CP1255" );
00136 
00137   connect( encodingcombo, SIGNAL(activated(int)), this,
00138        SLOT(sChangeEncoding(int)) );
00139   glay->addMultiCellWidget( encodingcombo, 3, 3, 1, 2 );
00140 
00141   QLabel *tmpQLabel = new QLabel( encodingcombo, i18n("&Encoding:"), this);
00142   glay->addWidget( tmpQLabel, 3, 0 );
00143 
00144 
00145   clientcombo = new QComboBox( this, "Client" );
00146   clientcombo->insertItem( i18n("International Ispell") );
00147   clientcombo->insertItem( i18n("Aspell") );
00148   clientcombo->insertItem( i18n("Hspell") );
00149   clientcombo->insertItem( i18n("Zemberek") );
00150   connect( clientcombo, SIGNAL (activated(int)), this,
00151        SLOT (sChangeClient(int)) );
00152   glay->addMultiCellWidget( clientcombo, 4, 4, 1, 2 );
00153 
00154   tmpQLabel = new QLabel( clientcombo, i18n("&Client:"), this );
00155   glay->addWidget( tmpQLabel, 4, 0 );
00156 
00157   if( addHelpButton )
00158   {
00159     QPushButton *pushButton = new KPushButton( KStdGuiItem::help(), this );
00160     connect( pushButton, SIGNAL(clicked()), this, SLOT(sHelp()) );
00161     glay->addWidget(pushButton, 5, 2);
00162   }
00163 
00164   fillInDialog();
00165 }
00166 
00167 KSpellConfig::~KSpellConfig()
00168 {
00169   delete d;
00170 }
00171 
00172 
00173 bool
00174 KSpellConfig::dictFromList() const
00175 {
00176   return dictfromlist;
00177 }
00178 
00179 bool
00180 KSpellConfig::readGlobalSettings()
00181 {
00182   KConfigGroupSaver cs( kc,"KSpell" );
00183 
00184   setNoRootAffix   ( kc->readNumEntry("KSpell_NoRootAffix", 0) );
00185   setRunTogether   ( kc->readNumEntry("KSpell_RunTogether", 0) );
00186   setDictionary    ( kc->readEntry("KSpell_Dictionary") );
00187   setDictFromList  ( kc->readNumEntry("KSpell_DictFromList", false) );
00188   setEncoding ( kc->readNumEntry ("KSpell_Encoding", KS_E_ASCII) );
00189   setClient ( kc->readNumEntry ("KSpell_Client", KS_CLIENT_ISPELL) );
00190 
00191   return true;
00192 }
00193 
00194 bool
00195 KSpellConfig::writeGlobalSettings ()
00196 {
00197   KConfigGroupSaver cs( kc,"KSpell" );
00198 
00199   kc->writeEntry ("KSpell_NoRootAffix",(int) noRootAffix(), true, true);
00200   kc->writeEntry ("KSpell_RunTogether", (int) runTogether(), true, true);
00201   kc->writeEntry ("KSpell_Dictionary", dictionary(), true, true);
00202   kc->writeEntry ("KSpell_DictFromList",(int) dictFromList(), true, true);
00203   kc->writeEntry ("KSpell_Encoding", (int) encoding(),
00204           true, true);
00205   kc->writeEntry ("KSpell_Client", client(),
00206           true, true);
00207   kc->sync();
00208 
00209   return true;
00210 }
00211 
00212 void
00213 KSpellConfig::sChangeEncoding( int i )
00214 {
00215   kdDebug(750) << "KSpellConfig::sChangeEncoding(" << i << ")" << endl;
00216   setEncoding( i );
00217   emit configChanged();
00218 }
00219 
00220 void
00221 KSpellConfig::sChangeClient( int i )
00222 {
00223   setClient( i );
00224 
00225   // read in new dict list
00226   if ( dictcombo ) {
00227     if ( iclient == KS_CLIENT_ISPELL )
00228       getAvailDictsIspell();
00229     else if ( iclient == KS_CLIENT_HSPELL )
00230     {
00231       langfnames.clear();
00232       dictcombo->clear();
00233       dictcombo->insertItem( i18n("Hebrew") );
00234       sChangeEncoding( KS_E_CP1255 );
00235     } else if ( iclient == KS_CLIENT_ZEMBEREK ) {
00236       langfnames.clear();
00237       dictcombo->clear();
00238       dictcombo->insertItem( i18n("Turkish") );
00239       sChangeEncoding( KS_E_UTF8 );
00240     } 
00241     else
00242       getAvailDictsAspell();
00243   }
00244   emit configChanged();
00245 }
00246 
00247 // KDE 4: Make it const QString & fname (only fname)
00248 bool
00249 KSpellConfig::interpret( QString &fname, QString &lname,
00250                          QString &hname )
00251 
00252 {
00253 
00254   kdDebug(750) << "KSpellConfig::interpret [" << fname << "]" << endl;
00255 
00256   QString dname( fname );
00257 
00258   if( dname.endsWith( "+" ) )
00259     dname.remove( dname.length()-1, 1 );
00260 
00261   if( dname.endsWith("sml") || dname.endsWith("med") || dname.endsWith("lrg") ||
00262       dname.endsWith("xlg"))
00263      dname.remove(dname.length()-3,3);
00264 
00265   QString extension;
00266 
00267   int i = dname.find('-');
00268   if ( i != -1 )
00269   {
00270     extension = dname.mid(i+1);
00271     dname.truncate(i);
00272   }
00273 
00274   // Aspell uses 2 alpha language codes or 2 alpha language + 2 alpha country,
00275   // but since aspell 0.6 also 3-character ISO-codes can be used
00276   if ( (dname.length() == 2) || (dname.length() == 3) ) {
00277     lname = dname;
00278     hname = KGlobal::locale()->twoAlphaToLanguageName( lname );
00279   }
00280   else if ( (dname.length() == 5) && (dname[2] == '_') ) {
00281     lname = dname.left(2);
00282     hname = KGlobal::locale()->twoAlphaToLanguageName(lname);
00283     QString country = KGlobal::locale()->twoAlphaToCountryName( dname.right(2) );
00284     if ( extension.isEmpty() )
00285       extension = country;
00286     else
00287       extension = country + " - " + extension;
00288   }
00289   //These are mostly the ispell-langpack defaults
00290   else if ( dname=="english" || dname=="american" ||
00291             dname=="british" || dname=="canadian" ) {
00292     lname="en"; hname=i18n("English");
00293   }
00294   else if ( dname == "espa~nol" || dname == "espanol" ) {
00295     lname="es"; hname=i18n("Spanish");
00296   }
00297   else if (dname=="dansk") {
00298     lname="da"; hname=i18n("Danish");
00299   }
00300   else if (dname=="deutsch") {
00301     lname="de"; hname=i18n("German");
00302   }
00303   else if (dname=="german") {
00304     lname="de"; hname=i18n("German (new spelling)");
00305   }
00306   else if (dname=="portuguesb" || dname=="br") {
00307     lname="br"; hname=i18n("Brazilian Portuguese");
00308   }
00309   else if (dname=="portugues") {
00310     lname="pt"; hname=i18n("Portuguese");
00311   }
00312   else if (dname=="esperanto") {
00313     lname="eo"; hname=i18n("Esperanto");
00314   }
00315   else if (dname=="norsk") {
00316     lname="no"; hname=i18n("Norwegian");
00317   }
00318   else if (dname=="polish") {
00319     lname="pl"; hname=i18n("Polish"); sChangeEncoding(KS_E_LATIN2);
00320   }
00321   else if (dname=="russian") {
00322     lname="ru"; hname=i18n("Russian");
00323   }
00324   else if (dname=="slovensko") {
00325     lname="si"; hname=i18n("Slovenian"); sChangeEncoding(KS_E_LATIN2);
00326   }
00327   else if (dname=="slovak"){
00328     lname="sk"; hname=i18n("Slovak"); sChangeEncoding(KS_E_LATIN2);
00329   }
00330   else if (dname=="czech") {
00331     lname="cs"; hname=i18n("Czech"); sChangeEncoding(KS_E_LATIN2);
00332   }
00333   else if (dname=="svenska") {
00334     lname="sv"; hname=i18n("Swedish");
00335   }
00336   else if (dname=="swiss") {
00337     lname="de"; hname=i18n("Swiss German");
00338   }
00339   else if (dname=="ukrainian") {
00340     lname="uk"; hname=i18n("Ukrainian");
00341   }
00342   else if (dname=="lietuviu" || dname=="lithuanian") {
00343      lname="lt"; hname=i18n("Lithuanian");
00344   }
00345   else if (dname=="francais" || dname=="french") {
00346     lname="fr"; hname=i18n("French");
00347   }
00348   else if (dname=="belarusian") {  // waiting for post 2.2 to not dissapoint translators
00349     lname="be"; hname=i18n("Belarusian");
00350   }
00351   else if( dname == "magyar" ) {
00352     lname="hu"; hname=i18n("Hungarian");
00353     sChangeEncoding(KS_E_LATIN2);
00354   }
00355   else {
00356     lname=""; hname=i18n("Unknown ispell dictionary", "Unknown");
00357   }
00358   if (!extension.isEmpty())
00359   {
00360     hname = hname + " (" + extension + ")";
00361   }
00362 
00363   //We have explicitly chosen English as the default here.
00364   if ( ( KGlobal::locale()->language() == QString::fromLatin1("C") &&
00365          lname==QString::fromLatin1("en") ) ||
00366        KGlobal::locale()->language() == lname )
00367     return true;
00368 
00369   return false;
00370 }
00371 
00372 void
00373 KSpellConfig::fillInDialog ()
00374 {
00375   if ( nodialog )
00376     return;
00377 
00378   kdDebug(750) << "KSpellConfig::fillinDialog" << endl;
00379 
00380   cb1->setChecked( noRootAffix() );
00381   cb2->setChecked( runTogether() );
00382   encodingcombo->setCurrentItem( encoding() );
00383   clientcombo->setCurrentItem( client() );
00384 
00385   // get list of available dictionaries
00386   if ( iclient == KS_CLIENT_ISPELL )
00387     getAvailDictsIspell();
00388   else if ( iclient == KS_CLIENT_HSPELL )
00389   {
00390     langfnames.clear();
00391     dictcombo->clear();
00392     langfnames.append(""); // Default
00393     dictcombo->insertItem( i18n("Hebrew") );
00394   } else if ( iclient == KS_CLIENT_ZEMBEREK ) {
00395     langfnames.clear();
00396     dictcombo->clear();
00397     langfnames.append("");
00398     dictcombo->insertItem( i18n("Turkish") );
00399   }
00400   else
00401     getAvailDictsAspell();
00402 
00403   // select the used dictionary in the list
00404   int whichelement=-1;
00405 
00406   if ( dictFromList() )
00407     whichelement = langfnames.findIndex(dictionary());
00408 
00409   dictcombo->setMinimumWidth (dictcombo->sizeHint().width());
00410 
00411   if (dictionary().isEmpty() ||  whichelement!=-1)
00412   {
00413     setDictFromList (true);
00414     if (whichelement!=-1)
00415       dictcombo->setCurrentItem(whichelement);
00416   }
00417   else
00418     // Current dictionary vanished, present the user with a default if possible.
00419     if ( !langfnames.empty() )
00420     {
00421       setDictFromList( true );
00422       dictcombo->setCurrentItem(0);
00423     }
00424     else
00425       setDictFromList( false );
00426 
00427   sDictionary( dictFromList() );
00428   sPathDictionary( !dictFromList() );
00429 
00430 }
00431 
00432 
00433 void KSpellConfig::getAvailDictsIspell () {
00434 
00435   langfnames.clear();
00436   dictcombo->clear();
00437   langfnames.append(""); // Default
00438   dictcombo->insertItem( i18n("ISpell Default") );
00439 
00440   // dictionary path
00441   QFileInfo dir ("/usr/lib/ispell");
00442   if (!dir.exists() || !dir.isDir())
00443     dir.setFile ("/usr/local/lib/ispell");
00444   if (!dir.exists() || !dir.isDir())
00445     dir.setFile ("/usr/local/share/ispell");
00446   if (!dir.exists() || !dir.isDir())
00447     dir.setFile ("/usr/share/ispell");
00448   /* TODO get them all instead of just one of them.
00449    * If /usr/local/lib exists, it skips the rest
00450   if (!dir.exists() || !dir.isDir())
00451     dir.setFile ("/usr/local/lib");
00452   */
00453   if (!dir.exists() || !dir.isDir()) return;
00454 
00455   kdDebug(750) << "KSpellConfig::getAvailDictsIspell "
00456            << dir.filePath() << " " << dir.dirPath() << endl;
00457 
00458   const QDir thedir (dir.filePath(),"*.hash");
00459   const QStringList entryList = thedir.entryList();
00460 
00461   kdDebug(750) << "KSpellConfig" << thedir.path() << "\n" << endl;
00462   kdDebug(750) << "entryList().count()="
00463            << entryList.count() << endl;
00464 
00465   QStringList::const_iterator entryListItr = entryList.constBegin();
00466   const QStringList::const_iterator entryListEnd = entryList.constEnd();
00467 
00468   for ( ; entryListItr != entryListEnd; ++entryListItr)
00469   {
00470     QString fname, lname, hname;
00471     fname = *entryListItr;
00472 
00473     // remove .hash
00474     if (fname.endsWith(".hash")) fname.remove (fname.length()-5,5);
00475 
00476     if (interpret (fname, lname, hname) && langfnames.first().isEmpty())
00477     { // This one is the KDE default language
00478       // so place it first in the lists (overwrite "Default")
00479 
00480       langfnames.remove ( langfnames.begin() );
00481       langfnames.prepend ( fname );
00482 
00483       hname=i18n("default spelling dictionary"
00484                  ,"Default - %1 [%2]").arg(hname).arg(fname);
00485 
00486       dictcombo->changeItem (hname,0);
00487     }
00488     else
00489     {
00490       langfnames.append (fname);
00491       hname=hname+" ["+fname+"]";
00492 
00493       dictcombo->insertItem (hname);
00494     }
00495   }
00496 }
00497 
00498 void KSpellConfig::getAvailDictsAspell () {
00499 
00500   langfnames.clear();
00501   dictcombo->clear();
00502 
00503   langfnames.append(""); // Default
00504   dictcombo->insertItem (i18n("ASpell Default"));
00505 
00506   // dictionary path
00507   // FIXME: use "aspell dump config" to find out the dict-dir
00508   QFileInfo dir ("/usr/lib/aspell");
00509   if (!dir.exists() || !dir.isDir())
00510     dir.setFile ("/usr/lib/aspell-0.60");
00511   if (!dir.exists() || !dir.isDir())
00512     dir.setFile ("/usr/local/lib/aspell");
00513   if (!dir.exists() || !dir.isDir())
00514     dir.setFile ("/usr/share/aspell");
00515   if (!dir.exists() || !dir.isDir())
00516     dir.setFile ("/usr/local/share/aspell");
00517   if (!dir.exists() || !dir.isDir()) return;
00518 
00519   kdDebug(750) << "KSpellConfig::getAvailDictsAspell "
00520            << dir.filePath() << " " << dir.dirPath() << endl;
00521 
00522   const QDir thedir (dir.filePath(),"*");
00523   const QStringList entryList = thedir.entryList();
00524 
00525   kdDebug(750) << "KSpellConfig" << thedir.path() << "\n" << endl;
00526   kdDebug(750) << "entryList().count()="
00527            << entryList.count() << endl;
00528 
00529   QStringList::const_iterator entryListItr = entryList.constBegin();
00530   const QStringList::const_iterator entryListEnd = entryList.constEnd();
00531 
00532   for ( ; entryListItr != entryListEnd; ++entryListItr)
00533   {
00534     QString fname, lname, hname;
00535     fname = *entryListItr;
00536 
00537     // consider only simple dicts without '-' in the name
00538     // FIXME: may be this is wrong an the list should contain
00539     // all *.multi files too, to allow using special dictionaries
00540 
00541     // Well, KSpell2 has a better way to do this, but this code has to be
00542     // cleaned up somehow: since aspell 0.6 we have quite a lot of files in the
00543     // aspell dictionary that are not dictionaries. These must not be presented as "languages"
00544     // We only keep
00545     // *.rws: dictionary
00546     // *.multi: definition file to load several subdictionaries
00547     if ( !( fname.endsWith(".rws") || fname.endsWith(".multi") ) ) {
00548         // remove noise from the language list
00549       continue;
00550     }
00551     if (fname[0] != '.')
00552     {
00553 
00554       // remove .multi
00555       if (fname.endsWith(".multi")) fname.remove (fname.length()-6,6);
00556       // remove .rws
00557       if (fname.endsWith(".rws")) fname.remove (fname.length()-4,4);
00558 
00559       if (interpret (fname, lname, hname) && langfnames.first().isEmpty())
00560       { // This one is the KDE default language
00561         // so place it first in the lists (overwrite "Default")
00562 
00563         langfnames.remove ( langfnames.begin() );
00564         langfnames.prepend ( fname );
00565 
00566         hname=i18n("default spelling dictionary"
00567                    ,"Default - %1").arg(hname);
00568 
00569         dictcombo->changeItem (hname,0);
00570       }
00571       else
00572       {
00573         langfnames.append (fname);
00574         dictcombo->insertItem (hname);
00575       }
00576     }
00577   }
00578 }
00579 
00580 void
00581 KSpellConfig::fillDicts( QComboBox* box, QStringList* dictionaries )
00582 {
00583   langfnames.clear();
00584   if ( box ) {
00585     if ( iclient == KS_CLIENT_ISPELL ) {
00586       box->clear();
00587       langfnames.append(""); // Default
00588       box->insertItem( i18n("ISpell Default") );
00589 
00590       // dictionary path
00591       QFileInfo dir ("/usr/lib/ispell");
00592       if (!dir.exists() || !dir.isDir())
00593         dir.setFile ("/usr/local/lib/ispell");
00594       if (!dir.exists() || !dir.isDir())
00595         dir.setFile ("/usr/local/share/ispell");
00596       if (!dir.exists() || !dir.isDir())
00597         dir.setFile ("/usr/share/ispell");
00598       /* TODO get them all instead of just one of them.
00599        * If /usr/local/lib exists, it skips the rest
00600        if (!dir.exists() || !dir.isDir())
00601        dir.setFile ("/usr/local/lib");
00602       */
00603       if (!dir.exists() || !dir.isDir()) return;
00604 
00605       kdDebug(750) << "KSpellConfig::getAvailDictsIspell "
00606                    << dir.filePath() << " " << dir.dirPath() << endl;
00607 
00608       const QDir thedir (dir.filePath(),"*.hash");
00609       const QStringList entryList = thedir.entryList();
00610 
00611       kdDebug(750) << "KSpellConfig" << thedir.path() << "\n" << endl;
00612       kdDebug(750) << "entryList().count()="
00613                    << entryList.count() << endl;
00614 
00615       QStringList::const_iterator entryListItr = entryList.constBegin();
00616       const QStringList::const_iterator entryListEnd = entryList.constEnd();
00617 
00618       for ( ; entryListItr != entryListEnd; ++entryListItr)
00619       {
00620         QString fname, lname, hname;
00621         fname = *entryListItr;
00622 
00623         // remove .hash
00624         if (fname.endsWith(".hash")) fname.remove (fname.length()-5,5);
00625 
00626         if (interpret (fname, lname, hname) && langfnames.first().isEmpty())
00627         { // This one is the KDE default language
00628           // so place it first in the lists (overwrite "Default")
00629 
00630           langfnames.remove ( langfnames.begin() );
00631           langfnames.prepend ( fname );
00632 
00633           hname=i18n("default spelling dictionary"
00634                      ,"Default - %1 [%2]").arg(hname).arg(fname);
00635 
00636           box->changeItem (hname,0);
00637         }
00638         else
00639         {
00640           langfnames.append (fname);
00641           hname=hname+" ["+fname+"]";
00642 
00643           box->insertItem (hname);
00644         }
00645       }
00646     } else if ( iclient == KS_CLIENT_HSPELL ) {
00647       box->clear();
00648       box->insertItem( i18n("Hebrew") );
00649       langfnames.append(""); // Default
00650       sChangeEncoding( KS_E_CP1255 );
00651     } else if ( iclient == KS_CLIENT_ZEMBEREK ) {
00652       box->clear();
00653       box->insertItem( i18n("Turkish") );
00654       langfnames.append("");
00655       sChangeEncoding( KS_E_UTF8 );
00656     }
00657     else {
00658       box->clear();
00659       langfnames.append(""); // Default
00660       box->insertItem (i18n("ASpell Default"));
00661 
00662       // dictionary path
00663       // FIXME: use "aspell dump config" to find out the dict-dir
00664       QFileInfo dir ("/usr/lib/aspell");
00665       if (!dir.exists() || !dir.isDir())
00666         dir.setFile ("/usr/lib/aspell-0.60");
00667       if (!dir.exists() || !dir.isDir())
00668         dir.setFile ("/usr/local/lib/aspell");
00669       if (!dir.exists() || !dir.isDir())
00670         dir.setFile ("/usr/share/aspell");
00671       if (!dir.exists() || !dir.isDir())
00672         dir.setFile ("/usr/local/share/aspell");
00673       if (!dir.exists() || !dir.isDir()) return;
00674 
00675       kdDebug(750) << "KSpellConfig::getAvailDictsAspell "
00676                    << dir.filePath() << " " << dir.dirPath() << endl;
00677 
00678       const QDir thedir (dir.filePath(),"*");
00679       const QStringList entryList = thedir.entryList();
00680 
00681       kdDebug(750) << "KSpellConfig" << thedir.path() << "\n" << endl;
00682       kdDebug(750) << "entryList().count()="
00683                    << entryList.count() << endl;
00684 
00685       QStringList::const_iterator entryListItr = entryList.constBegin();
00686       const QStringList::const_iterator entryListEnd = entryList.constEnd();
00687 
00688       for ( ; entryListItr != entryListEnd; ++entryListItr)
00689       {
00690         QString fname, lname, hname;
00691         fname = *entryListItr;
00692 
00693         // consider only simple dicts without '-' in the name
00694         // FIXME: may be this is wrong an the list should contain
00695         // all *.multi files too, to allow using special dictionaries
00696 
00697         // Well, KSpell2 has a better way to do this, but this code has to be
00698         // cleaned up somehow: since aspell 0.6 we have quite a lot of files in the
00699         // aspell dictionary that are not dictionaries. These must not be presented as "languages"
00700         // We only keep
00701         // *.rws: dictionary
00702         // *.multi: definition file to load several subdictionaries
00703         if ( !( fname.endsWith(".rws") || fname.endsWith(".multi") ) ) {
00704             // remove noise from the language list
00705           continue;
00706         }
00707         if (fname[0] != '.')
00708         {
00709 
00710           // remove .multi
00711           if (fname.endsWith(".multi")) fname.remove (fname.length()-6,6);
00712           // remove .rws
00713           if (fname.endsWith(".rws")) fname.remove (fname.length()-4,4);
00714 
00715           if (interpret (fname, lname, hname) && langfnames.first().isEmpty())
00716           { // This one is the KDE default language
00717             // so place it first in the lists (overwrite "Default")
00718 
00719             langfnames.remove ( langfnames.begin() );
00720             langfnames.prepend ( fname );
00721 
00722             hname=i18n("default spelling dictionary"
00723                        ,"Default - %1").arg(hname);
00724 
00725             box->changeItem (hname,0);
00726           }
00727           else
00728           {
00729             langfnames.append (fname);
00730             box->insertItem (hname);
00731           }
00732         }
00733       }
00734     }
00735     int whichelement = langfnames.findIndex(qsdict);
00736     if ( whichelement >= 0 ) {
00737       box->setCurrentItem( whichelement );
00738     }
00739     if ( dictionaries )
00740       *dictionaries = langfnames;
00741   }
00742 }
00743 
00744 /*
00745  * Options setting routines.
00746  */
00747 
00748 void
00749 KSpellConfig::setClient (int c)
00750 {
00751   iclient = c;
00752 
00753   if (clientcombo)
00754     clientcombo->setCurrentItem(c);
00755 }
00756 
00757 void
00758 KSpellConfig::setNoRootAffix (bool b)
00759 {
00760   bnorootaffix=b;
00761 
00762   if(cb1)
00763     cb1->setChecked(b);
00764 }
00765 
00766 void
00767 KSpellConfig::setRunTogether(bool b)
00768 {
00769   bruntogether=b;
00770 
00771   if(cb2)
00772     cb2->setChecked(b);
00773 }
00774 
00775 void
00776 KSpellConfig::setDictionary (const QString s)
00777 {
00778   qsdict=s; //.copy();
00779 
00780   if (qsdict.length()>5)
00781     if ((signed)qsdict.find(".hash")==(signed)qsdict.length()-5)
00782       qsdict.remove (qsdict.length()-5,5);
00783 
00784 
00785   if(dictcombo)
00786   {
00787     int whichelement=-1;
00788     if (dictFromList())
00789     {
00790       whichelement = langfnames.findIndex(s);
00791 
00792       if(whichelement >= 0)
00793       {
00794         dictcombo->setCurrentItem(whichelement);
00795       }
00796     }
00797   }
00798 
00799 
00800 }
00801 
00802 void
00803 KSpellConfig::setDictFromList (bool dfl)
00804 {
00805   //  kdebug (KDEBUG_INFO, 750, "sdfl = %d", dfl);
00806   dictfromlist=dfl;
00807 }
00808 
00809 /*
00810 void KSpellConfig::setPersonalDict (const char *s)
00811 {
00812   qspdict=s;
00813 }
00814 */
00815 
00816 void
00817 KSpellConfig::setEncoding (int enctype)
00818 {
00819   enc=enctype;
00820 
00821   if(encodingcombo)
00822     encodingcombo->setCurrentItem(enctype);
00823 }
00824 
00825 /*
00826   Options reading routines.
00827  */
00828 int
00829 KSpellConfig::client () const
00830 {
00831   return iclient;
00832 }
00833 
00834 
00835 bool
00836 KSpellConfig::noRootAffix () const
00837 {
00838   return bnorootaffix;
00839 }
00840 
00841 bool
00842 KSpellConfig::runTogether() const
00843 {
00844   return bruntogether;
00845 }
00846 
00847 const
00848 QString KSpellConfig::dictionary () const
00849 {
00850   return qsdict;
00851 }
00852 
00853 /*
00854 const QString KSpellConfig::personalDict () const
00855 {
00856   return qspdict;
00857 }
00858 */
00859 
00860 int
00861 KSpellConfig::encoding () const
00862 {
00863   return enc;
00864 }
00865 
00866 void
00867 KSpellConfig::sRunTogether(bool)
00868 {
00869   setRunTogether (cb2->isChecked());
00870   emit configChanged();
00871 }
00872 
00873 void
00874 KSpellConfig::sNoAff(bool)
00875 {
00876   setNoRootAffix (cb1->isChecked());
00877   emit configChanged();
00878 }
00879 
00880 /*
00881 void
00882 KSpellConfig::sBrowseDict()
00883 {
00884   return;
00885 
00886   QString qs( KFileDialog::getOpenFileName ("/usr/local/lib","*.hash") );
00887   if ( !qs.isNull() )
00888     kle1->setText (qs);
00889 
00890 }
00891 */
00892 
00893 /*
00894 void KSpellConfig::sBrowsePDict()
00895 {
00896   //how do I find home directory path??
00897   QString qs( KFileDialog::getOpenFileName ("",".ispell_*") );
00898   if ( !qs.isNull() )
00899       kle2->setText (qs);
00900 
00901 
00902 }
00903 */
00904 
00905 void
00906 KSpellConfig::sSetDictionary (int i)
00907 {
00908   setDictionary (langfnames[i]);
00909   setDictFromList (true);
00910   emit configChanged();
00911 }
00912 
00913 void
00914 KSpellConfig::sDictionary(bool on)
00915 {
00916   if (on)
00917   {
00918     dictcombo->setEnabled (true);
00919     setDictionary (langfnames[dictcombo->currentItem()] );
00920     setDictFromList (true);
00921   }
00922   else
00923   {
00924     dictcombo->setEnabled (false);
00925   }
00926   emit configChanged();
00927 }
00928 
00929 void
00930 KSpellConfig::sPathDictionary(bool on)
00931 {
00932   return; //enough for now
00933 
00934 
00935   if (on)
00936   {
00937     //kle1->setEnabled (true);
00938     //      browsebutton1->setEnabled (true);
00939     //setDictionary (kle1->text());
00940     setDictFromList (false);
00941   }
00942   else
00943   {
00944     //kle1->setEnabled (false);
00945     //browsebutton1->setEnabled (false);
00946   }
00947   emit configChanged();
00948 }
00949 
00950 
00951 void KSpellConfig::activateHelp( void )
00952 {
00953   sHelp();
00954 }
00955 
00956 void KSpellConfig::sHelp( void )
00957 {
00958   kapp->invokeHelp("configuration", "kspell");
00959 }
00960 
00961 /*
00962 void KSpellConfig::textChanged1 (const char *s)
00963 {
00964   setDictionary (s);
00965 }
00966 
00967 void KSpellConfig::textChanged2 (const char *)
00968 {
00969   //  setPersonalDict (s);
00970 }
00971 */
00972 
00973 void
00974 KSpellConfig::operator= (const KSpellConfig &ksc)
00975 {
00976   //We want to copy the data members, but not the
00977   //pointers to the child widgets
00978   setNoRootAffix (ksc.noRootAffix());
00979   setRunTogether (ksc.runTogether());
00980   setDictionary (ksc.dictionary());
00981   setDictFromList (ksc.dictFromList());
00982   //  setPersonalDict (ksc.personalDict());
00983   setEncoding (ksc.encoding());
00984   setClient (ksc.client());
00985 
00986   fillInDialog();
00987 }
00988 
00989 // KDE 4: Make it const QStringList &
00990 void
00991 KSpellConfig::setIgnoreList (QStringList _ignorelist)
00992 {
00993   ignorelist=_ignorelist;
00994 }
00995 
00996 QStringList
00997 KSpellConfig::ignoreList () const
00998 {
00999   return ignorelist;
01000 }
01001 
01002 // KDE 4: Make it const QStringList &
01003 void
01004 KSpellConfig::setReplaceAllList (QStringList _replacelist)
01005 {
01006   d->replacelist=_replacelist;
01007 }
01008 
01009 QStringList
01010 KSpellConfig::replaceAllList() const
01011 {
01012   return d->replacelist;
01013 }
01014 
01015 #include "ksconfig.moc"
01016 
01017 
01018 
KDE Home | KDE Accessibility Home | Description of Access Keys