| # kdeui Library API Documentation
Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Namespaces | Source Files

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

This file is part of the documentation for kdeui Library Version 3.4.1.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sat Jun 11 20:20:22 2005 by doxygen 1.4.1 written by Dimitri van Heesch, © 1997-2003