• Skip to content
  • Skip to link menu
KDE 4.3 API Reference
  • KDE API Reference
  • kdelibs
  • Sitemap
  • Contact Us
 

KDE3Support

k3sconfig.cpp

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

KDE3Support

Skip menu "KDE3Support"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.6.1
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal