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