• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • kdeui
 

kdeui

  • kdeui
ksconfig.cpp
1 /* This file is part of the KDE libraries
2  Copyright (C) 1997 David Sweet <dsweet@kde.org>
3  Copyright (C) 2000-2001 Wolfram Diestel <wolfram@steloj.de>
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Library General Public
7  License version 2 as published by the Free Software Foundation.
8 
9  This library is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  Library General Public License for more details.
13 
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB. If not, write to
16  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  Boston, MA 02110-1301, USA.
18 */
19 
20 #include <config.h>
21 
22 #include <tqcheckbox.h>
23 #include <tqcombobox.h>
24 #include <tqlabel.h>
25 #include <tqlayout.h>
26 #include <tqtimer.h>
27 
28 #include <kapplication.h>
29 #include <kconfig.h>
30 #include <kdebug.h>
31 #include <kdialog.h>
32 #include <kfiledialog.h>
33 #include <kglobal.h>
34 #include <klineedit.h>
35 #include <klocale.h>
36 #include <kpushbutton.h>
37 #include <kstdguiitem.h>
38 
39 #include "ksconfig.h"
40 
41 class KSpellConfigPrivate
42 {
43 public:
44  TQStringList replacelist;
45 };
46 
47 
48 KSpellConfig::KSpellConfig (const KSpellConfig &_ksc)
49  : TQWidget(0, 0), nodialog(true)
50  , kc(0)
51  , cb1(0)
52  , cb2(0)
53  , dictlist(0)
54  , dictcombo(0)
55  , encodingcombo(0)
56  , clientcombo(0)
57 {
58  d = new KSpellConfigPrivate;
59  setReplaceAllList( _ksc.replaceAllList() );
60  setNoRootAffix( _ksc.noRootAffix() );
61  setRunTogether( _ksc.runTogether() );
62  setDictionary( _ksc.dictionary() );
63  setDictFromList( _ksc.dictFromList() );
64  // setPersonalDict (_ksc.personalDict());
65  setIgnoreList( _ksc.ignoreList() );
66  setEncoding( _ksc.encoding() );
67  setClient( _ksc.client() );
68 }
69 
70 
71 KSpellConfig::KSpellConfig( TQWidget *parent, const char *name,
72  KSpellConfig *_ksc, bool addHelpButton )
73  : TQWidget (parent, name), nodialog(false)
74  , kc(0)
75  , cb1(0)
76  , cb2(0)
77  , dictlist(0)
78  , dictcombo(0)
79  , encodingcombo(0)
80  , clientcombo(0)
81 {
82  d = new KSpellConfigPrivate;
83  kc = KGlobal::config();
84 
85  if( !_ksc )
86  {
87  readGlobalSettings();
88  }
89  else
90  {
91  setNoRootAffix( _ksc->noRootAffix() );
92  setRunTogether( _ksc->runTogether() );
93  setDictionary( _ksc->dictionary() );
94  setDictFromList( _ksc->dictFromList() );
95  //setPersonalDict (_ksc->personalDict());
96  setIgnoreList( _ksc->ignoreList() );
97  setEncoding( _ksc->encoding() );
98  setClient( _ksc->client() );
99  }
100 
101  TQGridLayout *glay = new TQGridLayout( this, 6, 3, 0, KDialog::spacingHint() );
102  cb1 = new TQCheckBox( i18n("Create &root/affix combinations"
103  " not in dictionary"), this, "NoRootAffix" );
104  connect( cb1, TQT_SIGNAL(toggled(bool)), TQT_SLOT(sNoAff(bool)) );
105  glay->addMultiCellWidget( cb1, 0, 0, 0, 2 );
106 
107  cb2 = new TQCheckBox( i18n("Consider run-together &words"
108  " as spelling errors"), this, "RunTogether" );
109  connect( cb2, TQT_SIGNAL(toggled(bool)), TQT_SLOT(sRunTogether(bool)) );
110  glay->addMultiCellWidget( cb2, 1, 1, 0, 2 );
111 
112  dictcombo = new TQComboBox( this, "DictFromList" );
113  dictcombo->setInsertionPolicy( TQComboBox::NoInsertion );
114  connect( dictcombo, TQT_SIGNAL (activated(int)),
115  this, TQT_SLOT (sSetDictionary(int)) );
116  glay->addMultiCellWidget( dictcombo, 2, 2, 1, 2 );
117 
118  dictlist = new TQLabel( dictcombo, i18n("&Dictionary:"), this );
119  glay->addWidget( dictlist, 2 ,0 );
120 
121  encodingcombo = new TQComboBox( this, "Encoding" );
122  encodingcombo->insertItem( "US-ASCII" );
123  encodingcombo->insertItem( "ISO 8859-1" );
124  encodingcombo->insertItem( "ISO 8859-2" );
125  encodingcombo->insertItem( "ISO 8859-3" );
126  encodingcombo->insertItem( "ISO 8859-4" );
127  encodingcombo->insertItem( "ISO 8859-5" );
128  encodingcombo->insertItem( "ISO 8859-7" );
129  encodingcombo->insertItem( "ISO 8859-8" );
130  encodingcombo->insertItem( "ISO 8859-9" );
131  encodingcombo->insertItem( "ISO 8859-13" );
132  encodingcombo->insertItem( "ISO 8859-15" );
133  encodingcombo->insertItem( "UTF-8" );
134  encodingcombo->insertItem( "KOI8-R" );
135  encodingcombo->insertItem( "KOI8-U" );
136  encodingcombo->insertItem( "CP1251" );
137  encodingcombo->insertItem( "CP1255" );
138 
139  connect( encodingcombo, TQT_SIGNAL(activated(int)), this,
140  TQT_SLOT(sChangeEncoding(int)) );
141  glay->addMultiCellWidget( encodingcombo, 3, 3, 1, 2 );
142 
143  TQLabel *tmpQLabel = new TQLabel( encodingcombo, i18n("&Encoding:"), this);
144  glay->addWidget( tmpQLabel, 3, 0 );
145 
146 
147  clientcombo = new TQComboBox( this, "Client" );
148  clientcombo->insertItem( i18n("International Ispell") );
149  clientcombo->insertItem( i18n("Aspell") );
150  clientcombo->insertItem( i18n("Hspell") );
151  clientcombo->insertItem( i18n("Zemberek") );
152  connect( clientcombo, TQT_SIGNAL (activated(int)), this,
153  TQT_SLOT (sChangeClient(int)) );
154  glay->addMultiCellWidget( clientcombo, 4, 4, 1, 2 );
155 
156  tmpQLabel = new TQLabel( clientcombo, i18n("&Client:"), this );
157  glay->addWidget( tmpQLabel, 4, 0 );
158 
159  if( addHelpButton )
160  {
161  TQPushButton *pushButton = new KPushButton( KStdGuiItem::help(), this );
162  connect( pushButton, TQT_SIGNAL(clicked()), this, TQT_SLOT(sHelp()) );
163  glay->addWidget(pushButton, 5, 2);
164  }
165 
166  fillInDialog();
167 }
168 
169 KSpellConfig::~KSpellConfig()
170 {
171  delete d;
172 }
173 
174 
175 bool
176 KSpellConfig::dictFromList() const
177 {
178  return dictfromlist;
179 }
180 
181 bool
182 KSpellConfig::readGlobalSettings()
183 {
184  KConfigGroupSaver cs( kc,"KSpell" );
185 
186  setNoRootAffix ( kc->readNumEntry("KSpell_NoRootAffix", 0) );
187  setRunTogether ( kc->readNumEntry("KSpell_RunTogether", 0) );
188  setDictionary ( kc->readEntry("KSpell_Dictionary") );
189  setDictFromList ( kc->readNumEntry("KSpell_DictFromList", false) );
190  setEncoding ( kc->readNumEntry ("KSpell_Encoding", KS_E_UTF8) );
191  setClient ( kc->readNumEntry ("KSpell_Client", KS_CLIENT_ISPELL) );
192 
193  return true;
194 }
195 
196 bool
197 KSpellConfig::writeGlobalSettings ()
198 {
199  KConfigGroupSaver cs( kc,"KSpell" );
200 
201  kc->writeEntry ("KSpell_NoRootAffix",(int) noRootAffix(), true, true);
202  kc->writeEntry ("KSpell_RunTogether", (int) runTogether(), true, true);
203  kc->writeEntry ("KSpell_Dictionary", dictionary(), true, true);
204  kc->writeEntry ("KSpell_DictFromList",(int) dictFromList(), true, true);
205  kc->writeEntry ("KSpell_Encoding", (int) encoding(),
206  true, true);
207  kc->writeEntry ("KSpell_Client", client(),
208  true, true);
209  kc->sync();
210 
211  return true;
212 }
213 
214 void
215 KSpellConfig::sChangeEncoding( int i )
216 {
217  kdDebug(750) << "KSpellConfig::sChangeEncoding(" << i << ")" << endl;
218  setEncoding( i );
219  emit configChanged();
220 }
221 
222 void
223 KSpellConfig::sChangeClient( int i )
224 {
225  setClient( i );
226 
227  // read in new dict list
228  if ( dictcombo ) {
229  if ( iclient == KS_CLIENT_ISPELL )
230  getAvailDictsIspell();
231  else if ( iclient == KS_CLIENT_HSPELL )
232  {
233  langfnames.clear();
234  dictcombo->clear();
235  dictcombo->insertItem( i18n("Hebrew") );
236  sChangeEncoding( KS_E_CP1255 );
237  } else if ( iclient == KS_CLIENT_ZEMBEREK ) {
238  langfnames.clear();
239  dictcombo->clear();
240  dictcombo->insertItem( i18n("Turkish") );
241  sChangeEncoding( KS_E_UTF8 );
242  }
243  else
244  getAvailDictsAspell();
245  }
246  emit configChanged();
247 }
248 
249 // KDE 4: Make it const TQString & fname (only fname)
250 bool
251 KSpellConfig::interpret( TQString &fname, TQString &lname,
252  TQString &hname )
253 
254 {
255 
256  kdDebug(750) << "KSpellConfig::interpret [" << fname << "]" << endl;
257 
258  TQString dname( fname );
259 
260  if( dname.endsWith( "+" ) )
261  dname.remove( dname.length()-1, 1 );
262 
263  if( dname.endsWith("sml") || dname.endsWith("med") || dname.endsWith("lrg") ||
264  dname.endsWith("xlg"))
265  dname.remove(dname.length()-3,3);
266 
267  TQString extension;
268 
269  int i = dname.find('-');
270  if ( i != -1 )
271  {
272  extension = dname.mid(i+1);
273  dname.truncate(i);
274  }
275 
276  // Aspell uses 2 alpha language codes or 2 alpha language + 2 alpha country,
277  // but since aspell 0.6 also 3-character ISO-codes can be used
278  if ( (dname.length() == 2) || (dname.length() == 3) ) {
279  lname = dname;
280  hname = KGlobal::locale()->twoAlphaToLanguageName( lname );
281  }
282  else if ( (dname.length() == 5) && (dname[2] == '_') ) {
283  lname = dname.left(2);
284  hname = KGlobal::locale()->twoAlphaToLanguageName(lname);
285  TQString country = KGlobal::locale()->twoAlphaToCountryName( dname.right(2) );
286  if ( extension.isEmpty() )
287  extension = country;
288  else
289  extension = country + " - " + extension;
290  }
291  //These are mostly the ispell-langpack defaults
292  else if ( dname=="english" || dname=="american" ||
293  dname=="british" || dname=="canadian" ) {
294  lname="en"; hname=i18n("English");
295  }
296  else if ( dname == "espa~nol" || dname == "espanol" ) {
297  lname="es"; hname=i18n("Spanish");
298  }
299  else if (dname=="dansk") {
300  lname="da"; hname=i18n("Danish");
301  }
302  else if (dname=="deutsch") {
303  lname="de"; hname=i18n("German");
304  }
305  else if (dname=="german") {
306  lname="de"; hname=i18n("German (new spelling)");
307  }
308  else if (dname=="portuguesb" || dname=="br") {
309  lname="br"; hname=i18n("Brazilian Portuguese");
310  }
311  else if (dname=="portugues") {
312  lname="pt"; hname=i18n("Portuguese");
313  }
314  else if (dname=="esperanto") {
315  lname="eo"; hname=i18n("Esperanto");
316  }
317  else if (dname=="norsk") {
318  lname="no"; hname=i18n("Norwegian");
319  }
320  else if (dname=="polish") {
321  lname="pl"; hname=i18n("Polish"); sChangeEncoding(KS_E_LATIN2);
322  }
323  else if (dname=="russian") {
324  lname="ru"; hname=i18n("Russian");
325  }
326  else if (dname=="slovensko") {
327  lname="si"; hname=i18n("Slovenian"); sChangeEncoding(KS_E_LATIN2);
328  }
329  else if (dname=="slovak"){
330  lname="sk"; hname=i18n("Slovak"); sChangeEncoding(KS_E_LATIN2);
331  }
332  else if (dname=="czech") {
333  lname="cs"; hname=i18n("Czech"); sChangeEncoding(KS_E_LATIN2);
334  }
335  else if (dname=="svenska") {
336  lname="sv"; hname=i18n("Swedish");
337  }
338  else if (dname=="swiss") {
339  lname="de"; hname=i18n("Swiss German");
340  }
341  else if (dname=="ukrainian") {
342  lname="uk"; hname=i18n("Ukrainian");
343  }
344  else if (dname=="lietuviu" || dname=="lithuanian") {
345  lname="lt"; hname=i18n("Lithuanian");
346  }
347  else if (dname=="francais" || dname=="french") {
348  lname="fr"; hname=i18n("French");
349  }
350  else if (dname=="belarusian") { // waiting for post 2.2 to not dissapoint translators
351  lname="be"; hname=i18n("Belarusian");
352  }
353  else if( dname == "magyar" ) {
354  lname="hu"; hname=i18n("Hungarian");
355  sChangeEncoding(KS_E_LATIN2);
356  }
357  else {
358  lname=""; hname=i18n("Unknown ispell dictionary", "Unknown");
359  }
360  if (!extension.isEmpty())
361  {
362  hname = hname + " (" + extension + ")";
363  }
364 
365  //We have explicitly chosen English as the default here.
366  if ( ( KGlobal::locale()->language() == TQString::fromLatin1("C") &&
367  lname==TQString::fromLatin1("en") ) ||
368  KGlobal::locale()->language() == lname )
369  return true;
370 
371  return false;
372 }
373 
374 void
375 KSpellConfig::fillInDialog ()
376 {
377  if ( nodialog )
378  return;
379 
380  kdDebug(750) << "KSpellConfig::fillinDialog" << endl;
381 
382  cb1->setChecked( noRootAffix() );
383  cb2->setChecked( runTogether() );
384  encodingcombo->setCurrentItem( encoding() );
385  clientcombo->setCurrentItem( client() );
386 
387  // get list of available dictionaries
388  if ( iclient == KS_CLIENT_ISPELL )
389  getAvailDictsIspell();
390  else if ( iclient == KS_CLIENT_HSPELL )
391  {
392  langfnames.clear();
393  dictcombo->clear();
394  langfnames.append(""); // Default
395  dictcombo->insertItem( i18n("Hebrew") );
396  } else if ( iclient == KS_CLIENT_ZEMBEREK ) {
397  langfnames.clear();
398  dictcombo->clear();
399  langfnames.append("");
400  dictcombo->insertItem( i18n("Turkish") );
401  }
402  else
403  getAvailDictsAspell();
404 
405  // select the used dictionary in the list
406  int whichelement=-1;
407 
408  if ( dictFromList() )
409  whichelement = langfnames.findIndex(dictionary());
410 
411  dictcombo->setMinimumWidth (dictcombo->sizeHint().width());
412 
413  if (dictionary().isEmpty() || whichelement!=-1)
414  {
415  setDictFromList (true);
416  if (whichelement!=-1)
417  dictcombo->setCurrentItem(whichelement);
418  }
419  else
420  // Current dictionary vanished, present the user with a default if possible.
421  if ( !langfnames.empty() )
422  {
423  setDictFromList( true );
424  dictcombo->setCurrentItem(0);
425  }
426  else
427  setDictFromList( false );
428 
429  sDictionary( dictFromList() );
430  sPathDictionary( !dictFromList() );
431 
432 }
433 
434 
435 void KSpellConfig::getAvailDictsIspell () {
436 
437  langfnames.clear();
438  dictcombo->clear();
439  langfnames.append(""); // Default
440  dictcombo->insertItem( i18n("ISpell Default") );
441 
442  // dictionary path
443  TQFileInfo dir ("/usr/lib" KDELIBSUFF "/ispell");
444  if (!dir.exists() || !dir.isDir())
445  dir.setFile ("/usr/local/lib" KDELIBSUFF "/ispell");
446  if (!dir.exists() || !dir.isDir())
447  dir.setFile ("/usr/local/share/ispell");
448  if (!dir.exists() || !dir.isDir())
449  dir.setFile ("/usr/share/ispell");
450  if (!dir.exists() || !dir.isDir())
451  dir.setFile ("/usr/pkg/lib");
452  /* TODO get them all instead of just one of them.
453  * If /usr/local/lib exists, it skips the rest
454  if (!dir.exists() || !dir.isDir())
455  dir.setFile ("/usr/local/lib");
456  */
457  if (!dir.exists() || !dir.isDir()) return;
458 
459  kdDebug(750) << "KSpellConfig::getAvailDictsIspell "
460  << dir.filePath() << " " << dir.dirPath() << endl;
461 
462  const TQDir thedir (dir.filePath(),"*.hash");
463  const TQStringList entryList = thedir.entryList();
464 
465  kdDebug(750) << "KSpellConfig" << thedir.path() << "\n" << endl;
466  kdDebug(750) << "entryList().count()="
467  << entryList.count() << endl;
468 
469  TQStringList::const_iterator entryListItr = entryList.constBegin();
470  const TQStringList::const_iterator entryListEnd = entryList.constEnd();
471 
472  for ( ; entryListItr != entryListEnd; ++entryListItr)
473  {
474  TQString fname, lname, hname;
475  fname = *entryListItr;
476 
477  // remove .hash
478  if (fname.endsWith(".hash")) fname.remove (fname.length()-5,5);
479 
480  if (interpret (fname, lname, hname) && langfnames.first().isEmpty())
481  { // This one is the KDE default language
482  // so place it first in the lists (overwrite "Default")
483 
484  langfnames.remove ( langfnames.begin() );
485  langfnames.prepend ( fname );
486 
487  hname=i18n("default spelling dictionary"
488  ,"Default - %1 [%2]").arg(hname).arg(fname);
489 
490  dictcombo->changeItem (hname,0);
491  }
492  else
493  {
494  langfnames.append (fname);
495  hname=hname+" ["+fname+"]";
496 
497  dictcombo->insertItem (hname);
498  }
499  }
500 }
501 
502 void KSpellConfig::getAvailDictsAspell () {
503 
504  langfnames.clear();
505  dictcombo->clear();
506 
507  langfnames.append(""); // Default
508  dictcombo->insertItem (i18n("ASpell Default"));
509 
510  // Aspell now have /usr/lib/aspell as
511  // ASPELL_DATADIR default.
512  TQFileInfo dir ( ASPELL_DATADIR );
513  if (!dir.exists() || !dir.isDir())
514  dir.setFile ("/usr/lib" KDELIBSUFF "/aspell-0.60");
515  if (!dir.exists() || !dir.isDir())
516  dir.setFile ("/usr/local/lib" KDELIBSUFF "/aspell");
517  if (!dir.exists() || !dir.isDir())
518  dir.setFile ("/usr/share/aspell");
519  if (!dir.exists() || !dir.isDir())
520  dir.setFile ("/usr/local/share/aspell");
521  if (!dir.exists() || !dir.isDir())
522  dir.setFile ("/usr/pkg/lib/aspell");
523  if (!dir.exists() || !dir.isDir()) return;
524 
525  kdDebug(750) << "KSpellConfig::getAvailDictsAspell "
526  << dir.filePath() << " " << dir.dirPath() << endl;
527 
528  const TQDir thedir (dir.filePath(),"*");
529  const TQStringList entryList = thedir.entryList();
530 
531  kdDebug(750) << "KSpellConfig" << thedir.path() << "\n" << endl;
532  kdDebug(750) << "entryList().count()="
533  << entryList.count() << endl;
534 
535  TQStringList::const_iterator entryListItr = entryList.constBegin();
536  const TQStringList::const_iterator entryListEnd = entryList.constEnd();
537 
538  for ( ; entryListItr != entryListEnd; ++entryListItr)
539  {
540  TQString fname, lname, hname;
541  fname = *entryListItr;
542 
543  // consider only simple dicts without '-' in the name
544  // FIXME: may be this is wrong an the list should contain
545  // all *.multi files too, to allow using special dictionaries
546 
547  // Well, KSpell2 has a better way to do this, but this code has to be
548  // cleaned up somehow: since aspell 0.6 we have quite a lot of files in the
549  // aspell dictionary that are not dictionaries. These must not be presented as "languages"
550  // We only keep
551  // *.rws: dictionary
552  // *.multi: definition file to load several subdictionaries
553  if ( !( fname.endsWith(".rws") || fname.endsWith(".multi") ) ) {
554  // remove noise from the language list
555  continue;
556  }
557  if (fname[0] != '.')
558  {
559 
560  // remove .multi
561  if (fname.endsWith(".multi")) fname.remove (fname.length()-6,6);
562  // remove .rws
563  if (fname.endsWith(".rws")) fname.remove (fname.length()-4,4);
564 
565  if (interpret (fname, lname, hname) && langfnames.first().isEmpty())
566  { // This one is the KDE default language
567  // so place it first in the lists (overwrite "Default")
568 
569  langfnames.remove ( langfnames.begin() );
570  langfnames.prepend ( fname );
571 
572  hname=i18n("default spelling dictionary"
573  ,"Default - %1").arg(hname);
574 
575  dictcombo->changeItem (hname,0);
576  }
577  else
578  {
579  langfnames.append (fname);
580  dictcombo->insertItem (hname);
581  }
582  }
583  }
584 }
585 
586 void
587 KSpellConfig::fillDicts( TQComboBox* box, TQStringList* dictionaries )
588 {
589  langfnames.clear();
590  if ( box ) {
591  if ( iclient == KS_CLIENT_ISPELL ) {
592  box->clear();
593  langfnames.append(""); // Default
594  box->insertItem( i18n("ISpell Default") );
595 
596  // dictionary path
597  TQFileInfo dir ("/usr/lib/ispell");
598  if (!dir.exists() || !dir.isDir())
599  dir.setFile ("/usr/local/lib/ispell");
600  if (!dir.exists() || !dir.isDir())
601  dir.setFile ("/usr/local/share/ispell");
602  if (!dir.exists() || !dir.isDir())
603  dir.setFile ("/usr/share/ispell");
604  if (!dir.exists() || !dir.isDir())
605  dir.setFile ("/usr/pkg/lib");
606  /* TODO get them all instead of just one of them.
607  * If /usr/local/lib exists, it skips the rest
608  if (!dir.exists() || !dir.isDir())
609  dir.setFile ("/usr/local/lib");
610  */
611  if (!dir.exists() || !dir.isDir()) return;
612 
613  kdDebug(750) << "KSpellConfig::getAvailDictsIspell "
614  << dir.filePath() << " " << dir.dirPath() << endl;
615 
616  const TQDir thedir (dir.filePath(),"*.hash");
617  const TQStringList entryList = thedir.entryList();
618 
619  kdDebug(750) << "KSpellConfig" << thedir.path() << "\n" << endl;
620  kdDebug(750) << "entryList().count()="
621  << entryList.count() << endl;
622 
623  TQStringList::const_iterator entryListItr = entryList.constBegin();
624  const TQStringList::const_iterator entryListEnd = entryList.constEnd();
625 
626  for ( ; entryListItr != entryListEnd; ++entryListItr)
627  {
628  TQString fname, lname, hname;
629  fname = *entryListItr;
630 
631  // remove .hash
632  if (fname.endsWith(".hash")) fname.remove (fname.length()-5,5);
633 
634  if (interpret (fname, lname, hname) && langfnames.first().isEmpty())
635  { // This one is the KDE default language
636  // so place it first in the lists (overwrite "Default")
637 
638  langfnames.remove ( langfnames.begin() );
639  langfnames.prepend ( fname );
640 
641  hname=i18n("default spelling dictionary"
642  ,"Default - %1 [%2]").arg(hname).arg(fname);
643 
644  box->changeItem (hname,0);
645  }
646  else
647  {
648  langfnames.append (fname);
649  hname=hname+" ["+fname+"]";
650 
651  box->insertItem (hname);
652  }
653  }
654  } else if ( iclient == KS_CLIENT_HSPELL ) {
655  box->clear();
656  box->insertItem( i18n("Hebrew") );
657  langfnames.append(""); // Default
658  sChangeEncoding( KS_E_CP1255 );
659  } else if ( iclient == KS_CLIENT_ZEMBEREK ) {
660  box->clear();
661  box->insertItem( i18n("Turkish") );
662  langfnames.append("");
663  sChangeEncoding( KS_E_UTF8 );
664  }
665  else {
666  box->clear();
667  langfnames.append(""); // Default
668  box->insertItem (i18n("ASpell Default"));
669 
670  // dictionary path
671  // FIXME: use "aspell dump config" to find out the dict-dir
672  TQFileInfo dir ("/usr/lib" KDELIBSUFF "/aspell");
673  if (!dir.exists() || !dir.isDir())
674  dir.setFile ("/usr/lib" KDELIBSUFF "/aspell-0.60");
675  if (!dir.exists() || !dir.isDir())
676  dir.setFile ("/usr/local/lib" KDELIBSUFF "/aspell");
677  if (!dir.exists() || !dir.isDir())
678  dir.setFile ("/usr/share/aspell");
679  if (!dir.exists() || !dir.isDir())
680  dir.setFile ("/usr/local/share/aspell");
681  if (!dir.exists() || !dir.isDir())
682  dir.setFile ("/usr/pkg/lib/aspell");
683  if (!dir.exists() || !dir.isDir()) return;
684 
685  kdDebug(750) << "KSpellConfig::getAvailDictsAspell "
686  << dir.filePath() << " " << dir.dirPath() << endl;
687 
688  const TQDir thedir (dir.filePath(),"*");
689  const TQStringList entryList = thedir.entryList();
690 
691  kdDebug(750) << "KSpellConfig" << thedir.path() << "\n" << endl;
692  kdDebug(750) << "entryList().count()="
693  << entryList.count() << endl;
694 
695  TQStringList::const_iterator entryListItr = entryList.constBegin();
696  const TQStringList::const_iterator entryListEnd = entryList.constEnd();
697 
698  for ( ; entryListItr != entryListEnd; ++entryListItr)
699  {
700  TQString fname, lname, hname;
701  fname = *entryListItr;
702 
703  // consider only simple dicts without '-' in the name
704  // FIXME: may be this is wrong an the list should contain
705  // all *.multi files too, to allow using special dictionaries
706 
707  // Well, KSpell2 has a better way to do this, but this code has to be
708  // cleaned up somehow: since aspell 0.6 we have quite a lot of files in the
709  // aspell dictionary that are not dictionaries. These must not be presented as "languages"
710  // We only keep
711  // *.rws: dictionary
712  // *.multi: definition file to load several subdictionaries
713  if ( !( fname.endsWith(".rws") || fname.endsWith(".multi") ) ) {
714  // remove noise from the language list
715  continue;
716  }
717  if (fname[0] != '.')
718  {
719 
720  // remove .multi
721  if (fname.endsWith(".multi")) fname.remove (fname.length()-6,6);
722  // remove .rws
723  if (fname.endsWith(".rws")) fname.remove (fname.length()-4,4);
724 
725  if (interpret (fname, lname, hname) && langfnames.first().isEmpty())
726  { // This one is the KDE default language
727  // so place it first in the lists (overwrite "Default")
728 
729  langfnames.remove ( langfnames.begin() );
730  langfnames.prepend ( fname );
731 
732  hname=i18n("default spelling dictionary"
733  ,"Default - %1").arg(hname);
734 
735  box->changeItem (hname,0);
736  }
737  else
738  {
739  langfnames.append (fname);
740  box->insertItem (hname);
741  }
742  }
743  }
744  }
745  int whichelement = langfnames.findIndex(qsdict);
746  if ( whichelement >= 0 ) {
747  box->setCurrentItem( whichelement );
748  }
749  if ( dictionaries )
750  *dictionaries = langfnames;
751  }
752 }
753 
754 /*
755  * Options setting routines.
756  */
757 
758 void
759 KSpellConfig::setClient (int c)
760 {
761  iclient = c;
762 
763  if (clientcombo)
764  clientcombo->setCurrentItem(c);
765 }
766 
767 void
768 KSpellConfig::setNoRootAffix (bool b)
769 {
770  bnorootaffix=b;
771 
772  if(cb1)
773  cb1->setChecked(b);
774 }
775 
776 void
777 KSpellConfig::setRunTogether(bool b)
778 {
779  bruntogether=b;
780 
781  if(cb2)
782  cb2->setChecked(b);
783 }
784 
785 void
786 KSpellConfig::setDictionary (const TQString s)
787 {
788  qsdict=s; //.copy();
789 
790  if (qsdict.length()>5)
791  if ((signed)qsdict.find(".hash")==(signed)qsdict.length()-5)
792  qsdict.remove (qsdict.length()-5,5);
793 
794 
795  if(dictcombo)
796  {
797  int whichelement=-1;
798  if (dictFromList())
799  {
800  whichelement = langfnames.findIndex(s);
801 
802  if(whichelement >= 0)
803  {
804  dictcombo->setCurrentItem(whichelement);
805  }
806  }
807  }
808 
809 
810 }
811 
812 void
813 KSpellConfig::setDictFromList (bool dfl)
814 {
815  // kdebug (KDEBUG_INFO, 750, "sdfl = %d", dfl);
816  dictfromlist=dfl;
817 }
818 
819 /*
820 void KSpellConfig::setPersonalDict (const char *s)
821 {
822  qspdict=s;
823 }
824 */
825 
826 void
827 KSpellConfig::setEncoding (int enctype)
828 {
829  enc=enctype;
830 
831  if(encodingcombo)
832  encodingcombo->setCurrentItem(enctype);
833 }
834 
835 /*
836  Options reading routines.
837  */
838 int
839 KSpellConfig::client () const
840 {
841  return iclient;
842 }
843 
844 
845 bool
846 KSpellConfig::noRootAffix () const
847 {
848  return bnorootaffix;
849 }
850 
851 bool
852 KSpellConfig::runTogether() const
853 {
854  return bruntogether;
855 }
856 
857 const
858 TQString KSpellConfig::dictionary () const
859 {
860  return qsdict;
861 }
862 
863 /*
864 const TQString KSpellConfig::personalDict () const
865 {
866  return qspdict;
867 }
868 */
869 
870 int
871 KSpellConfig::encoding () const
872 {
873  return enc;
874 }
875 
876 void
877 KSpellConfig::sRunTogether(bool)
878 {
879  setRunTogether (cb2->isChecked());
880  emit configChanged();
881 }
882 
883 void
884 KSpellConfig::sNoAff(bool)
885 {
886  setNoRootAffix (cb1->isChecked());
887  emit configChanged();
888 }
889 
890 /*
891 void
892 KSpellConfig::sBrowseDict()
893 {
894  return;
895 
896  TQString qs( KFileDialog::getOpenFileName ("/usr/local/lib","*.hash") );
897  if ( !qs.isNull() )
898  kle1->setText (qs);
899 
900 }
901 */
902 
903 /*
904 void KSpellConfig::sBrowsePDict()
905 {
906  //how do I find home directory path??
907  TQString qs( KFileDialog::getOpenFileName ("",".ispell_*") );
908  if ( !qs.isNull() )
909  kle2->setText (qs);
910 
911 
912 }
913 */
914 
915 void
916 KSpellConfig::sSetDictionary (int i)
917 {
918  setDictionary (langfnames[i]);
919  setDictFromList (true);
920  TQTimer::singleShot( 0, this, TQT_SIGNAL( configChanged() ) );
921 }
922 
923 void
924 KSpellConfig::sDictionary(bool on)
925 {
926  if (on)
927  {
928  dictcombo->setEnabled (true);
929  setDictionary (langfnames[dictcombo->currentItem()] );
930  setDictFromList (true);
931  }
932  else
933  {
934  dictcombo->setEnabled (false);
935  }
936  emit configChanged();
937 }
938 
939 void
940 KSpellConfig::sPathDictionary(bool on)
941 {
942  return; //enough for now
943 
944 
945  if (on)
946  {
947  //kle1->setEnabled (true);
948  // browsebutton1->setEnabled (true);
949  //setDictionary (kle1->text());
950  setDictFromList (false);
951  }
952  else
953  {
954  //kle1->setEnabled (false);
955  //browsebutton1->setEnabled (false);
956  }
957  emit configChanged();
958 }
959 
960 
961 void KSpellConfig::activateHelp( void )
962 {
963  sHelp();
964 }
965 
966 void KSpellConfig::sHelp( void )
967 {
968  kapp->invokeHelp("configuration", "kspell");
969 }
970 
971 /*
972 void KSpellConfig::textChanged1 (const char *s)
973 {
974  setDictionary (s);
975 }
976 
977 void KSpellConfig::textChanged2 (const char *)
978 {
979  // setPersonalDict (s);
980 }
981 */
982 
983 void
984 KSpellConfig::operator= (const KSpellConfig &ksc)
985 {
986  //We want to copy the data members, but not the
987  //pointers to the child widgets
988  setNoRootAffix (ksc.noRootAffix());
989  setRunTogether (ksc.runTogether());
990  setDictionary (ksc.dictionary());
991  setDictFromList (ksc.dictFromList());
992  // setPersonalDict (ksc.personalDict());
993  setEncoding (ksc.encoding());
994  setClient (ksc.client());
995 
996  fillInDialog();
997 }
998 
999 // KDE 4: Make it const TQStringList &
1000 void
1001 KSpellConfig::setIgnoreList (TQStringList _ignorelist)
1002 {
1003  ignorelist=_ignorelist;
1004 }
1005 
1006 TQStringList
1007 KSpellConfig::ignoreList () const
1008 {
1009  return ignorelist;
1010 }
1011 
1012 // KDE 4: Make it const TQStringList &
1013 void
1014 KSpellConfig::setReplaceAllList (TQStringList _replacelist)
1015 {
1016  d->replacelist=_replacelist;
1017 }
1018 
1019 TQStringList
1020 KSpellConfig::replaceAllList() const
1021 {
1022  return d->replacelist;
1023 }
1024 
1025 #include "ksconfig.moc"
1026 
1027 
1028 

kdeui

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

kdeui

Skip menu "kdeui"
  • arts
  • dcop
  • dnssd
  • interfaces
  •     interface
  •     library
  •   kspeech
  •   ktexteditor
  • kabc
  • kate
  • kcmshell
  • kdecore
  • kded
  • kdefx
  • kdeprint
  • kdesu
  • kdeui
  • kdoctools
  • khtml
  • kimgio
  • kinit
  • kio
  •   bookmarks
  •   httpfilter
  •   kfile
  •   kio
  •   kioexec
  •   kpasswdserver
  •   kssl
  • kioslave
  •   http
  • kjs
  • kmdi
  •   kmdi
  • knewstuff
  • kparts
  • krandr
  • kresources
  • kspell2
  • kunittest
  • kutils
  • kwallet
  • libkmid
  • libkscreensaver
Generated for kdeui by doxygen 1.8.3.1
This website is maintained by Timothy Pearson.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. |