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" KDELIBSUFF "/ispell"); 00444 if (!dir.exists() || !dir.isDir()) 00445 dir.setFile ("/usr/local/lib" KDELIBSUFF "/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 if (!dir.exists() || !dir.isDir()) 00451 dir.setFile ("/usr/pkg/lib"); 00452 /* TODO get them all instead of just one of them. 00453 * If /usr/local/lib exists, it skips the rest 00454 if (!dir.exists() || !dir.isDir()) 00455 dir.setFile ("/usr/local/lib"); 00456 */ 00457 if (!dir.exists() || !dir.isDir()) return; 00458 00459 kdDebug(750) << "KSpellConfig::getAvailDictsIspell " 00460 << dir.filePath() << " " << dir.dirPath() << endl; 00461 00462 const QDir thedir (dir.filePath(),"*.hash"); 00463 const QStringList entryList = thedir.entryList(); 00464 00465 kdDebug(750) << "KSpellConfig" << thedir.path() << "\n" << endl; 00466 kdDebug(750) << "entryList().count()=" 00467 << entryList.count() << endl; 00468 00469 QStringList::const_iterator entryListItr = entryList.constBegin(); 00470 const QStringList::const_iterator entryListEnd = entryList.constEnd(); 00471 00472 for ( ; entryListItr != entryListEnd; ++entryListItr) 00473 { 00474 QString fname, lname, hname; 00475 fname = *entryListItr; 00476 00477 // remove .hash 00478 if (fname.endsWith(".hash")) fname.remove (fname.length()-5,5); 00479 00480 if (interpret (fname, lname, hname) && langfnames.first().isEmpty()) 00481 { // This one is the KDE default language 00482 // so place it first in the lists (overwrite "Default") 00483 00484 langfnames.remove ( langfnames.begin() ); 00485 langfnames.prepend ( fname ); 00486 00487 hname=i18n("default spelling dictionary" 00488 ,"Default - %1 [%2]").arg(hname).arg(fname); 00489 00490 dictcombo->changeItem (hname,0); 00491 } 00492 else 00493 { 00494 langfnames.append (fname); 00495 hname=hname+" ["+fname+"]"; 00496 00497 dictcombo->insertItem (hname); 00498 } 00499 } 00500 } 00501 00502 void KSpellConfig::getAvailDictsAspell () { 00503 00504 langfnames.clear(); 00505 dictcombo->clear(); 00506 00507 langfnames.append(""); // Default 00508 dictcombo->insertItem (i18n("ASpell Default")); 00509 00510 // Aspell now have /usr/lib/aspell as 00511 // ASPELL_DATADIR default. 00512 QFileInfo dir ( ASPELL_DATADIR ); 00513 if (!dir.exists() || !dir.isDir()) 00514 dir.setFile ("/usr/lib" KDELIBSUFF "/aspell-0.60"); 00515 if (!dir.exists() || !dir.isDir()) 00516 dir.setFile ("/usr/local/lib" KDELIBSUFF "/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()) 00522 dir.setFile ("/usr/pkg/lib/aspell"); 00523 if (!dir.exists() || !dir.isDir()) return; 00524 00525 kdDebug(750) << "KSpellConfig::getAvailDictsAspell " 00526 << dir.filePath() << " " << dir.dirPath() << endl; 00527 00528 const QDir thedir (dir.filePath(),"*"); 00529 const QStringList entryList = thedir.entryList(); 00530 00531 kdDebug(750) << "KSpellConfig" << thedir.path() << "\n" << endl; 00532 kdDebug(750) << "entryList().count()=" 00533 << entryList.count() << endl; 00534 00535 QStringList::const_iterator entryListItr = entryList.constBegin(); 00536 const QStringList::const_iterator entryListEnd = entryList.constEnd(); 00537 00538 for ( ; entryListItr != entryListEnd; ++entryListItr) 00539 { 00540 QString fname, lname, hname; 00541 fname = *entryListItr; 00542 00543 // consider only simple dicts without '-' in the name 00544 // FIXME: may be this is wrong an the list should contain 00545 // all *.multi files too, to allow using special dictionaries 00546 00547 // Well, KSpell2 has a better way to do this, but this code has to be 00548 // cleaned up somehow: since aspell 0.6 we have quite a lot of files in the 00549 // aspell dictionary that are not dictionaries. These must not be presented as "languages" 00550 // We only keep 00551 // *.rws: dictionary 00552 // *.multi: definition file to load several subdictionaries 00553 if ( !( fname.endsWith(".rws") || fname.endsWith(".multi") ) ) { 00554 // remove noise from the language list 00555 continue; 00556 } 00557 if (fname[0] != '.') 00558 { 00559 00560 // remove .multi 00561 if (fname.endsWith(".multi")) fname.remove (fname.length()-6,6); 00562 // remove .rws 00563 if (fname.endsWith(".rws")) fname.remove (fname.length()-4,4); 00564 00565 if (interpret (fname, lname, hname) && langfnames.first().isEmpty()) 00566 { // This one is the KDE default language 00567 // so place it first in the lists (overwrite "Default") 00568 00569 langfnames.remove ( langfnames.begin() ); 00570 langfnames.prepend ( fname ); 00571 00572 hname=i18n("default spelling dictionary" 00573 ,"Default - %1").arg(hname); 00574 00575 dictcombo->changeItem (hname,0); 00576 } 00577 else 00578 { 00579 langfnames.append (fname); 00580 dictcombo->insertItem (hname); 00581 } 00582 } 00583 } 00584 } 00585 00586 void 00587 KSpellConfig::fillDicts( QComboBox* box, QStringList* dictionaries ) 00588 { 00589 langfnames.clear(); 00590 if ( box ) { 00591 if ( iclient == KS_CLIENT_ISPELL ) { 00592 box->clear(); 00593 langfnames.append(""); // Default 00594 box->insertItem( i18n("ISpell Default") ); 00595 00596 // dictionary path 00597 QFileInfo dir ("/usr/lib/ispell"); 00598 if (!dir.exists() || !dir.isDir()) 00599 dir.setFile ("/usr/local/lib/ispell"); 00600 if (!dir.exists() || !dir.isDir()) 00601 dir.setFile ("/usr/local/share/ispell"); 00602 if (!dir.exists() || !dir.isDir()) 00603 dir.setFile ("/usr/share/ispell"); 00604 if (!dir.exists() || !dir.isDir()) 00605 dir.setFile ("/usr/pkg/lib"); 00606 /* TODO get them all instead of just one of them. 00607 * If /usr/local/lib exists, it skips the rest 00608 if (!dir.exists() || !dir.isDir()) 00609 dir.setFile ("/usr/local/lib"); 00610 */ 00611 if (!dir.exists() || !dir.isDir()) return; 00612 00613 kdDebug(750) << "KSpellConfig::getAvailDictsIspell " 00614 << dir.filePath() << " " << dir.dirPath() << endl; 00615 00616 const QDir thedir (dir.filePath(),"*.hash"); 00617 const QStringList entryList = thedir.entryList(); 00618 00619 kdDebug(750) << "KSpellConfig" << thedir.path() << "\n" << endl; 00620 kdDebug(750) << "entryList().count()=" 00621 << entryList.count() << endl; 00622 00623 QStringList::const_iterator entryListItr = entryList.constBegin(); 00624 const QStringList::const_iterator entryListEnd = entryList.constEnd(); 00625 00626 for ( ; entryListItr != entryListEnd; ++entryListItr) 00627 { 00628 QString fname, lname, hname; 00629 fname = *entryListItr; 00630 00631 // remove .hash 00632 if (fname.endsWith(".hash")) fname.remove (fname.length()-5,5); 00633 00634 if (interpret (fname, lname, hname) && langfnames.first().isEmpty()) 00635 { // This one is the KDE default language 00636 // so place it first in the lists (overwrite "Default") 00637 00638 langfnames.remove ( langfnames.begin() ); 00639 langfnames.prepend ( fname ); 00640 00641 hname=i18n("default spelling dictionary" 00642 ,"Default - %1 [%2]").arg(hname).arg(fname); 00643 00644 box->changeItem (hname,0); 00645 } 00646 else 00647 { 00648 langfnames.append (fname); 00649 hname=hname+" ["+fname+"]"; 00650 00651 box->insertItem (hname); 00652 } 00653 } 00654 } else if ( iclient == KS_CLIENT_HSPELL ) { 00655 box->clear(); 00656 box->insertItem( i18n("Hebrew") ); 00657 langfnames.append(""); // Default 00658 sChangeEncoding( KS_E_CP1255 ); 00659 } else if ( iclient == KS_CLIENT_ZEMBEREK ) { 00660 box->clear(); 00661 box->insertItem( i18n("Turkish") ); 00662 langfnames.append(""); 00663 sChangeEncoding( KS_E_UTF8 ); 00664 } 00665 else { 00666 box->clear(); 00667 langfnames.append(""); // Default 00668 box->insertItem (i18n("ASpell Default")); 00669 00670 // dictionary path 00671 // FIXME: use "aspell dump config" to find out the dict-dir 00672 QFileInfo dir ("/usr/lib" KDELIBSUFF "/aspell"); 00673 if (!dir.exists() || !dir.isDir()) 00674 dir.setFile ("/usr/lib" KDELIBSUFF "/aspell-0.60"); 00675 if (!dir.exists() || !dir.isDir()) 00676 dir.setFile ("/usr/local/lib" KDELIBSUFF "/aspell"); 00677 if (!dir.exists() || !dir.isDir()) 00678 dir.setFile ("/usr/share/aspell"); 00679 if (!dir.exists() || !dir.isDir()) 00680 dir.setFile ("/usr/local/share/aspell"); 00681 if (!dir.exists() || !dir.isDir()) 00682 dir.setFile ("/usr/pkg/lib/aspell"); 00683 if (!dir.exists() || !dir.isDir()) return; 00684 00685 kdDebug(750) << "KSpellConfig::getAvailDictsAspell " 00686 << dir.filePath() << " " << dir.dirPath() << endl; 00687 00688 const QDir thedir (dir.filePath(),"*"); 00689 const QStringList entryList = thedir.entryList(); 00690 00691 kdDebug(750) << "KSpellConfig" << thedir.path() << "\n" << endl; 00692 kdDebug(750) << "entryList().count()=" 00693 << entryList.count() << endl; 00694 00695 QStringList::const_iterator entryListItr = entryList.constBegin(); 00696 const QStringList::const_iterator entryListEnd = entryList.constEnd(); 00697 00698 for ( ; entryListItr != entryListEnd; ++entryListItr) 00699 { 00700 QString fname, lname, hname; 00701 fname = *entryListItr; 00702 00703 // consider only simple dicts without '-' in the name 00704 // FIXME: may be this is wrong an the list should contain 00705 // all *.multi files too, to allow using special dictionaries 00706 00707 // Well, KSpell2 has a better way to do this, but this code has to be 00708 // cleaned up somehow: since aspell 0.6 we have quite a lot of files in the 00709 // aspell dictionary that are not dictionaries. These must not be presented as "languages" 00710 // We only keep 00711 // *.rws: dictionary 00712 // *.multi: definition file to load several subdictionaries 00713 if ( !( fname.endsWith(".rws") || fname.endsWith(".multi") ) ) { 00714 // remove noise from the language list 00715 continue; 00716 } 00717 if (fname[0] != '.') 00718 { 00719 00720 // remove .multi 00721 if (fname.endsWith(".multi")) fname.remove (fname.length()-6,6); 00722 // remove .rws 00723 if (fname.endsWith(".rws")) fname.remove (fname.length()-4,4); 00724 00725 if (interpret (fname, lname, hname) && langfnames.first().isEmpty()) 00726 { // This one is the KDE default language 00727 // so place it first in the lists (overwrite "Default") 00728 00729 langfnames.remove ( langfnames.begin() ); 00730 langfnames.prepend ( fname ); 00731 00732 hname=i18n("default spelling dictionary" 00733 ,"Default - %1").arg(hname); 00734 00735 box->changeItem (hname,0); 00736 } 00737 else 00738 { 00739 langfnames.append (fname); 00740 box->insertItem (hname); 00741 } 00742 } 00743 } 00744 } 00745 int whichelement = langfnames.findIndex(qsdict); 00746 if ( whichelement >= 0 ) { 00747 box->setCurrentItem( whichelement ); 00748 } 00749 if ( dictionaries ) 00750 *dictionaries = langfnames; 00751 } 00752 } 00753 00754 /* 00755 * Options setting routines. 00756 */ 00757 00758 void 00759 KSpellConfig::setClient (int c) 00760 { 00761 iclient = c; 00762 00763 if (clientcombo) 00764 clientcombo->setCurrentItem(c); 00765 } 00766 00767 void 00768 KSpellConfig::setNoRootAffix (bool b) 00769 { 00770 bnorootaffix=b; 00771 00772 if(cb1) 00773 cb1->setChecked(b); 00774 } 00775 00776 void 00777 KSpellConfig::setRunTogether(bool b) 00778 { 00779 bruntogether=b; 00780 00781 if(cb2) 00782 cb2->setChecked(b); 00783 } 00784 00785 void 00786 KSpellConfig::setDictionary (const QString s) 00787 { 00788 qsdict=s; //.copy(); 00789 00790 if (qsdict.length()>5) 00791 if ((signed)qsdict.find(".hash")==(signed)qsdict.length()-5) 00792 qsdict.remove (qsdict.length()-5,5); 00793 00794 00795 if(dictcombo) 00796 { 00797 int whichelement=-1; 00798 if (dictFromList()) 00799 { 00800 whichelement = langfnames.findIndex(s); 00801 00802 if(whichelement >= 0) 00803 { 00804 dictcombo->setCurrentItem(whichelement); 00805 } 00806 } 00807 } 00808 00809 00810 } 00811 00812 void 00813 KSpellConfig::setDictFromList (bool dfl) 00814 { 00815 // kdebug (KDEBUG_INFO, 750, "sdfl = %d", dfl); 00816 dictfromlist=dfl; 00817 } 00818 00819 /* 00820 void KSpellConfig::setPersonalDict (const char *s) 00821 { 00822 qspdict=s; 00823 } 00824 */ 00825 00826 void 00827 KSpellConfig::setEncoding (int enctype) 00828 { 00829 enc=enctype; 00830 00831 if(encodingcombo) 00832 encodingcombo->setCurrentItem(enctype); 00833 } 00834 00835 /* 00836 Options reading routines. 00837 */ 00838 int 00839 KSpellConfig::client () const 00840 { 00841 return iclient; 00842 } 00843 00844 00845 bool 00846 KSpellConfig::noRootAffix () const 00847 { 00848 return bnorootaffix; 00849 } 00850 00851 bool 00852 KSpellConfig::runTogether() const 00853 { 00854 return bruntogether; 00855 } 00856 00857 const 00858 QString KSpellConfig::dictionary () const 00859 { 00860 return qsdict; 00861 } 00862 00863 /* 00864 const QString KSpellConfig::personalDict () const 00865 { 00866 return qspdict; 00867 } 00868 */ 00869 00870 int 00871 KSpellConfig::encoding () const 00872 { 00873 return enc; 00874 } 00875 00876 void 00877 KSpellConfig::sRunTogether(bool) 00878 { 00879 setRunTogether (cb2->isChecked()); 00880 emit configChanged(); 00881 } 00882 00883 void 00884 KSpellConfig::sNoAff(bool) 00885 { 00886 setNoRootAffix (cb1->isChecked()); 00887 emit configChanged(); 00888 } 00889 00890 /* 00891 void 00892 KSpellConfig::sBrowseDict() 00893 { 00894 return; 00895 00896 QString qs( KFileDialog::getOpenFileName ("/usr/local/lib","*.hash") ); 00897 if ( !qs.isNull() ) 00898 kle1->setText (qs); 00899 00900 } 00901 */ 00902 00903 /* 00904 void KSpellConfig::sBrowsePDict() 00905 { 00906 //how do I find home directory path?? 00907 QString qs( KFileDialog::getOpenFileName ("",".ispell_*") ); 00908 if ( !qs.isNull() ) 00909 kle2->setText (qs); 00910 00911 00912 } 00913 */ 00914 00915 void 00916 KSpellConfig::sSetDictionary (int i) 00917 { 00918 setDictionary (langfnames[i]); 00919 setDictFromList (true); 00920 QTimer::singleShot( 0, this, SIGNAL( configChanged() ) ); 00921 } 00922 00923 void 00924 KSpellConfig::sDictionary(bool on) 00925 { 00926 if (on) 00927 { 00928 dictcombo->setEnabled (true); 00929 setDictionary (langfnames[dictcombo->currentItem()] ); 00930 setDictFromList (true); 00931 } 00932 else 00933 { 00934 dictcombo->setEnabled (false); 00935 } 00936 emit configChanged(); 00937 } 00938 00939 void 00940 KSpellConfig::sPathDictionary(bool on) 00941 { 00942 return; //enough for now 00943 00944 00945 if (on) 00946 { 00947 //kle1->setEnabled (true); 00948 // browsebutton1->setEnabled (true); 00949 //setDictionary (kle1->text()); 00950 setDictFromList (false); 00951 } 00952 else 00953 { 00954 //kle1->setEnabled (false); 00955 //browsebutton1->setEnabled (false); 00956 } 00957 emit configChanged(); 00958 } 00959 00960 00961 void KSpellConfig::activateHelp( void ) 00962 { 00963 sHelp(); 00964 } 00965 00966 void KSpellConfig::sHelp( void ) 00967 { 00968 kapp->invokeHelp("configuration", "kspell"); 00969 } 00970 00971 /* 00972 void KSpellConfig::textChanged1 (const char *s) 00973 { 00974 setDictionary (s); 00975 } 00976 00977 void KSpellConfig::textChanged2 (const char *) 00978 { 00979 // setPersonalDict (s); 00980 } 00981 */ 00982 00983 void 00984 KSpellConfig::operator= (const KSpellConfig &ksc) 00985 { 00986 //We want to copy the data members, but not the 00987 //pointers to the child widgets 00988 setNoRootAffix (ksc.noRootAffix()); 00989 setRunTogether (ksc.runTogether()); 00990 setDictionary (ksc.dictionary()); 00991 setDictFromList (ksc.dictFromList()); 00992 // setPersonalDict (ksc.personalDict()); 00993 setEncoding (ksc.encoding()); 00994 setClient (ksc.client()); 00995 00996 fillInDialog(); 00997 } 00998 00999 // KDE 4: Make it const QStringList & 01000 void 01001 KSpellConfig::setIgnoreList (QStringList _ignorelist) 01002 { 01003 ignorelist=_ignorelist; 01004 } 01005 01006 QStringList 01007 KSpellConfig::ignoreList () const 01008 { 01009 return ignorelist; 01010 } 01011 01012 // KDE 4: Make it const QStringList & 01013 void 01014 KSpellConfig::setReplaceAllList (QStringList _replacelist) 01015 { 01016 d->replacelist=_replacelist; 01017 } 01018 01019 QStringList 01020 KSpellConfig::replaceAllList() const 01021 { 01022 return d->replacelist; 01023 } 01024 01025 #include "ksconfig.moc" 01026 01027 01028