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

tdeui

  • tdeui
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 <tdeapplication.h>
29 #include <tdeconfig.h>
30 #include <kdebug.h>
31 #include <kdialog.h>
32 #include <tdefiledialog.h>
33 #include <tdeglobal.h>
34 #include <klineedit.h>
35 #include <tdelocale.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 = TDEGlobal::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  TDEConfigGroupSaver 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 #if defined(__OpenBSD__) || defined(__FreeBSD__)
192  setClient ( kc->readNumEntry ("KSpell_Client", KS_CLIENT_ASPELL) );
193 #else
194  setClient ( kc->readNumEntry ("KSpell_Client", KS_CLIENT_ISPELL) );
195 #endif
196 
197  return true;
198 }
199 
200 bool
201 KSpellConfig::writeGlobalSettings ()
202 {
203  TDEConfigGroupSaver cs( kc,"KSpell" );
204 
205  kc->writeEntry ("KSpell_NoRootAffix",(int) noRootAffix(), true, true);
206  kc->writeEntry ("KSpell_RunTogether", (int) runTogether(), true, true);
207  kc->writeEntry ("KSpell_Dictionary", dictionary(), true, true);
208  kc->writeEntry ("KSpell_DictFromList",(int) dictFromList(), true, true);
209  kc->writeEntry ("KSpell_Encoding", (int) encoding(),
210  true, true);
211  kc->writeEntry ("KSpell_Client", client(),
212  true, true);
213  kc->sync();
214 
215  return true;
216 }
217 
218 void
219 KSpellConfig::sChangeEncoding( int i )
220 {
221  kdDebug(750) << "KSpellConfig::sChangeEncoding(" << i << ")" << endl;
222  setEncoding( i );
223  emit configChanged();
224 }
225 
226 void
227 KSpellConfig::sChangeClient( int i )
228 {
229  setClient( i );
230 
231  // read in new dict list
232  if ( dictcombo ) {
233  if ( iclient == KS_CLIENT_ISPELL )
234  getAvailDictsIspell();
235  else if ( iclient == KS_CLIENT_HSPELL )
236  {
237  langfnames.clear();
238  dictcombo->clear();
239  dictcombo->insertItem( i18n("Hebrew") );
240  sChangeEncoding( KS_E_CP1255 );
241  } else if ( iclient == KS_CLIENT_ZEMBEREK ) {
242  langfnames.clear();
243  dictcombo->clear();
244  dictcombo->insertItem( i18n("Turkish") );
245  sChangeEncoding( KS_E_UTF8 );
246  }
247  else
248  getAvailDictsAspell();
249  }
250  emit configChanged();
251 }
252 
253 // KDE 4: Make it const TQString & fname (only fname)
254 bool
255 KSpellConfig::interpret( TQString &fname, TQString &lname,
256  TQString &hname )
257 
258 {
259 
260  kdDebug(750) << "KSpellConfig::interpret [" << fname << "]" << endl;
261 
262  TQString dname( fname );
263 
264  if( dname.endsWith( "+" ) )
265  dname.remove( dname.length()-1, 1 );
266 
267  if( dname.endsWith("sml") || dname.endsWith("med") || dname.endsWith("lrg") ||
268  dname.endsWith("xlg"))
269  dname.remove(dname.length()-3,3);
270 
271  TQString extension;
272 
273  int i = dname.find('-');
274  if ( i != -1 )
275  {
276  extension = dname.mid(i+1);
277  dname.truncate(i);
278  }
279 
280  // Aspell uses 2 alpha language codes or 2 alpha language + 2 alpha country,
281  // but since aspell 0.6 also 3-character ISO-codes can be used
282  if ( (dname.length() == 2) || (dname.length() == 3) ) {
283  lname = dname;
284  hname = TDEGlobal::locale()->twoAlphaToLanguageName( lname );
285  }
286  else if ( (dname.length() == 5) && (dname[2] == '_') ) {
287  lname = dname.left(2);
288  hname = TDEGlobal::locale()->twoAlphaToLanguageName(lname);
289  TQString country = TDEGlobal::locale()->twoAlphaToCountryName( dname.right(2) );
290  if ( extension.isEmpty() )
291  extension = country;
292  else
293  extension = country + " - " + extension;
294  }
295  //These are mostly the ispell-langpack defaults
296  else if ( dname=="english" || dname=="american" ||
297  dname=="british" || dname=="canadian" ) {
298  lname="en"; hname=i18n("English");
299  }
300  else if ( dname == "espa~nol" || dname == "espanol" ) {
301  lname="es"; hname=i18n("Spanish");
302  }
303  else if (dname=="dansk") {
304  lname="da"; hname=i18n("Danish");
305  }
306  else if (dname=="deutsch") {
307  lname="de"; hname=i18n("German");
308  }
309  else if (dname=="german") {
310  lname="de"; hname=i18n("German (new spelling)");
311  }
312  else if (dname=="portuguesb" || dname=="br") {
313  lname="br"; hname=i18n("Brazilian Portuguese");
314  }
315  else if (dname=="portugues") {
316  lname="pt"; hname=i18n("Portuguese");
317  }
318  else if (dname=="esperanto") {
319  lname="eo"; hname=i18n("Esperanto");
320  }
321  else if (dname=="norsk") {
322  lname="no"; hname=i18n("Norwegian");
323  }
324  else if (dname=="polish") {
325  lname="pl"; hname=i18n("Polish"); sChangeEncoding(KS_E_LATIN2);
326  }
327  else if (dname=="russian") {
328  lname="ru"; hname=i18n("Russian");
329  }
330  else if (dname=="slovensko") {
331  lname="si"; hname=i18n("Slovenian"); sChangeEncoding(KS_E_LATIN2);
332  }
333  else if (dname=="slovak"){
334  lname="sk"; hname=i18n("Slovak"); sChangeEncoding(KS_E_LATIN2);
335  }
336  else if (dname=="czech") {
337  lname="cs"; hname=i18n("Czech"); sChangeEncoding(KS_E_LATIN2);
338  }
339  else if (dname=="svenska") {
340  lname="sv"; hname=i18n("Swedish");
341  }
342  else if (dname=="swiss") {
343  lname="de"; hname=i18n("Swiss German");
344  }
345  else if (dname=="ukrainian") {
346  lname="uk"; hname=i18n("Ukrainian");
347  }
348  else if (dname=="lietuviu" || dname=="lithuanian") {
349  lname="lt"; hname=i18n("Lithuanian");
350  }
351  else if (dname=="francais" || dname=="french") {
352  lname="fr"; hname=i18n("French");
353  }
354  else if (dname=="belarusian") { // waiting for post 2.2 to not dissapoint translators
355  lname="be"; hname=i18n("Belarusian");
356  }
357  else if( dname == "magyar" ) {
358  lname="hu"; hname=i18n("Hungarian");
359  sChangeEncoding(KS_E_LATIN2);
360  }
361  else {
362  lname=""; hname=i18n("Unknown ispell dictionary", "Unknown");
363  }
364  if (!extension.isEmpty())
365  {
366  hname = hname + " (" + extension + ")";
367  }
368 
369  //We have explicitly chosen English as the default here.
370  if ( ( TDEGlobal::locale()->language() == TQString::fromLatin1("C") &&
371  lname==TQString::fromLatin1("en") ) ||
372  TDEGlobal::locale()->language() == lname )
373  return true;
374 
375  return false;
376 }
377 
378 void
379 KSpellConfig::fillInDialog ()
380 {
381  if ( nodialog )
382  return;
383 
384  kdDebug(750) << "KSpellConfig::fillinDialog" << endl;
385 
386  cb1->setChecked( noRootAffix() );
387  cb2->setChecked( runTogether() );
388  encodingcombo->setCurrentItem( encoding() );
389  clientcombo->setCurrentItem( client() );
390 
391  // get list of available dictionaries
392  if ( iclient == KS_CLIENT_ISPELL )
393  getAvailDictsIspell();
394  else if ( iclient == KS_CLIENT_HSPELL )
395  {
396  langfnames.clear();
397  dictcombo->clear();
398  langfnames.append(""); // Default
399  dictcombo->insertItem( i18n("Hebrew") );
400  } else if ( iclient == KS_CLIENT_ZEMBEREK ) {
401  langfnames.clear();
402  dictcombo->clear();
403  langfnames.append("");
404  dictcombo->insertItem( i18n("Turkish") );
405  }
406  else
407  getAvailDictsAspell();
408 
409  // select the used dictionary in the list
410  int whichelement=-1;
411 
412  if ( dictFromList() )
413  whichelement = langfnames.findIndex(dictionary());
414 
415  dictcombo->setMinimumWidth (dictcombo->sizeHint().width());
416 
417  if (dictionary().isEmpty() || whichelement!=-1)
418  {
419  setDictFromList (true);
420  if (whichelement!=-1)
421  dictcombo->setCurrentItem(whichelement);
422  }
423  else
424  // Current dictionary vanished, present the user with a default if possible.
425  if ( !langfnames.empty() )
426  {
427  setDictFromList( true );
428  dictcombo->setCurrentItem(0);
429  }
430  else
431  setDictFromList( false );
432 
433  sDictionary( dictFromList() );
434  sPathDictionary( !dictFromList() );
435 
436 }
437 
438 
439 void KSpellConfig::getAvailDictsIspell () {
440 
441  langfnames.clear();
442  dictcombo->clear();
443  langfnames.append(""); // Default
444  dictcombo->insertItem( i18n("ISpell Default") );
445 
446  // dictionary path
447  TQFileInfo dir ("/usr/lib" KDELIBSUFF "/ispell");
448  if (!dir.exists() || !dir.isDir())
449  dir.setFile ("/usr/local/lib" KDELIBSUFF "/ispell");
450  if (!dir.exists() || !dir.isDir())
451  dir.setFile ("/usr/local/share/ispell");
452  if (!dir.exists() || !dir.isDir())
453  dir.setFile ("/usr/share/ispell");
454  if (!dir.exists() || !dir.isDir())
455  dir.setFile ("/usr/pkg/lib");
456  /* TODO get them all instead of just one of them.
457  * If /usr/local/lib exists, it skips the rest
458  if (!dir.exists() || !dir.isDir())
459  dir.setFile ("/usr/local/lib");
460  */
461  if (!dir.exists() || !dir.isDir()) return;
462 
463  kdDebug(750) << "KSpellConfig::getAvailDictsIspell "
464  << dir.filePath() << " " << dir.dirPath() << endl;
465 
466  const TQDir thedir (dir.filePath(),"*.hash");
467  const TQStringList entryList = thedir.entryList();
468 
469  kdDebug(750) << "KSpellConfig" << thedir.path() << "\n" << endl;
470  kdDebug(750) << "entryList().count()="
471  << entryList.count() << endl;
472 
473  TQStringList::const_iterator entryListItr = entryList.constBegin();
474  const TQStringList::const_iterator entryListEnd = entryList.constEnd();
475 
476  for ( ; entryListItr != entryListEnd; ++entryListItr)
477  {
478  TQString fname, lname, hname;
479  fname = *entryListItr;
480 
481  // remove .hash
482  if (fname.endsWith(".hash")) fname.remove (fname.length()-5,5);
483 
484  if (interpret (fname, lname, hname) && langfnames.first().isEmpty())
485  { // This one is the KDE default language
486  // so place it first in the lists (overwrite "Default")
487 
488  langfnames.remove ( langfnames.begin() );
489  langfnames.prepend ( fname );
490 
491  hname=i18n("default spelling dictionary"
492  ,"Default - %1 [%2]").arg(hname).arg(fname);
493 
494  dictcombo->changeItem (hname,0);
495  }
496  else
497  {
498  langfnames.append (fname);
499  hname=hname+" ["+fname+"]";
500 
501  dictcombo->insertItem (hname);
502  }
503  }
504 }
505 
506 void KSpellConfig::getAvailDictsAspell () {
507 
508  langfnames.clear();
509  dictcombo->clear();
510 
511  langfnames.append(""); // Default
512  dictcombo->insertItem (i18n("ASpell Default"));
513 
514  // Aspell now have /usr/lib/aspell as
515  // ASPELL_DATADIR default.
516  TQFileInfo dir ( ASPELL_DATADIR );
517  if (!dir.exists() || !dir.isDir())
518  dir.setFile ("/usr/lib" KDELIBSUFF "/aspell-0.60");
519  if (!dir.exists() || !dir.isDir())
520  dir.setFile ("/usr/local/lib" KDELIBSUFF "/aspell");
521  if (!dir.exists() || !dir.isDir())
522  dir.setFile ("/usr/share/aspell");
523  if (!dir.exists() || !dir.isDir())
524  dir.setFile ("/usr/local/share/aspell");
525  if (!dir.exists() || !dir.isDir())
526  dir.setFile ("/usr/pkg/lib/aspell");
527  if (!dir.exists() || !dir.isDir()) return;
528 
529  kdDebug(750) << "KSpellConfig::getAvailDictsAspell "
530  << dir.filePath() << " " << dir.dirPath() << endl;
531 
532  const TQDir thedir (dir.filePath(),"*");
533  const TQStringList entryList = thedir.entryList();
534 
535  kdDebug(750) << "KSpellConfig" << thedir.path() << "\n" << endl;
536  kdDebug(750) << "entryList().count()="
537  << entryList.count() << endl;
538 
539  TQStringList::const_iterator entryListItr = entryList.constBegin();
540  const TQStringList::const_iterator entryListEnd = entryList.constEnd();
541 
542  for ( ; entryListItr != entryListEnd; ++entryListItr)
543  {
544  TQString fname, lname, hname;
545  fname = *entryListItr;
546 
547  // consider only simple dicts without '-' in the name
548  // FIXME: may be this is wrong an the list should contain
549  // all *.multi files too, to allow using special dictionaries
550 
551  // Well, KSpell2 has a better way to do this, but this code has to be
552  // cleaned up somehow: since aspell 0.6 we have quite a lot of files in the
553  // aspell dictionary that are not dictionaries. These must not be presented as "languages"
554  // We only keep
555  // *.rws: dictionary
556  // *.multi: definition file to load several subdictionaries
557  if ( !( fname.endsWith(".rws") || fname.endsWith(".multi") ) ) {
558  // remove noise from the language list
559  continue;
560  }
561  if (fname[0] != '.')
562  {
563 
564  // remove .multi
565  if (fname.endsWith(".multi")) fname.remove (fname.length()-6,6);
566  // remove .rws
567  if (fname.endsWith(".rws")) fname.remove (fname.length()-4,4);
568 
569  if (interpret (fname, lname, hname) && langfnames.first().isEmpty())
570  { // This one is the KDE default language
571  // so place it first in the lists (overwrite "Default")
572 
573  langfnames.remove ( langfnames.begin() );
574  langfnames.prepend ( fname );
575 
576  hname=i18n("default spelling dictionary"
577  ,"Default - %1").arg(hname);
578 
579  dictcombo->changeItem (hname,0);
580  }
581  else
582  {
583  langfnames.append (fname);
584  dictcombo->insertItem (hname);
585  }
586  }
587  }
588 }
589 
590 void
591 KSpellConfig::fillDicts( TQComboBox* box, TQStringList* dictionaries )
592 {
593  langfnames.clear();
594  if ( box ) {
595  if ( iclient == KS_CLIENT_ISPELL ) {
596  box->clear();
597  langfnames.append(""); // Default
598  box->insertItem( i18n("ISpell Default") );
599 
600  // dictionary path
601  TQFileInfo dir ("/usr/lib/ispell");
602  if (!dir.exists() || !dir.isDir())
603  dir.setFile ("/usr/local/lib/ispell");
604  if (!dir.exists() || !dir.isDir())
605  dir.setFile ("/usr/local/share/ispell");
606  if (!dir.exists() || !dir.isDir())
607  dir.setFile ("/usr/share/ispell");
608  if (!dir.exists() || !dir.isDir())
609  dir.setFile ("/usr/pkg/lib");
610  /* TODO get them all instead of just one of them.
611  * If /usr/local/lib exists, it skips the rest
612  if (!dir.exists() || !dir.isDir())
613  dir.setFile ("/usr/local/lib");
614  */
615  if (!dir.exists() || !dir.isDir()) return;
616 
617  kdDebug(750) << "KSpellConfig::getAvailDictsIspell "
618  << dir.filePath() << " " << dir.dirPath() << endl;
619 
620  const TQDir thedir (dir.filePath(),"*.hash");
621  const TQStringList entryList = thedir.entryList();
622 
623  kdDebug(750) << "KSpellConfig" << thedir.path() << "\n" << endl;
624  kdDebug(750) << "entryList().count()="
625  << entryList.count() << endl;
626 
627  TQStringList::const_iterator entryListItr = entryList.constBegin();
628  const TQStringList::const_iterator entryListEnd = entryList.constEnd();
629 
630  for ( ; entryListItr != entryListEnd; ++entryListItr)
631  {
632  TQString fname, lname, hname;
633  fname = *entryListItr;
634 
635  // remove .hash
636  if (fname.endsWith(".hash")) fname.remove (fname.length()-5,5);
637 
638  if (interpret (fname, lname, hname) && langfnames.first().isEmpty())
639  { // This one is the KDE default language
640  // so place it first in the lists (overwrite "Default")
641 
642  langfnames.remove ( langfnames.begin() );
643  langfnames.prepend ( fname );
644 
645  hname=i18n("default spelling dictionary"
646  ,"Default - %1 [%2]").arg(hname).arg(fname);
647 
648  box->changeItem (hname,0);
649  }
650  else
651  {
652  langfnames.append (fname);
653  hname=hname+" ["+fname+"]";
654 
655  box->insertItem (hname);
656  }
657  }
658  } else if ( iclient == KS_CLIENT_HSPELL ) {
659  box->clear();
660  box->insertItem( i18n("Hebrew") );
661  langfnames.append(""); // Default
662  sChangeEncoding( KS_E_CP1255 );
663  } else if ( iclient == KS_CLIENT_ZEMBEREK ) {
664  box->clear();
665  box->insertItem( i18n("Turkish") );
666  langfnames.append("");
667  sChangeEncoding( KS_E_UTF8 );
668  }
669  else {
670  box->clear();
671  langfnames.append(""); // Default
672  box->insertItem (i18n("ASpell Default"));
673 
674  // dictionary path
675  // FIXME: use "aspell dump config" to find out the dict-dir
676  TQFileInfo dir ("/usr/lib" KDELIBSUFF "/aspell");
677  if (!dir.exists() || !dir.isDir())
678  dir.setFile ("/usr/lib" KDELIBSUFF "/aspell-0.60");
679  if (!dir.exists() || !dir.isDir())
680  dir.setFile ("/usr/local/lib" KDELIBSUFF "/aspell");
681  if (!dir.exists() || !dir.isDir())
682  dir.setFile ("/usr/share/aspell");
683  if (!dir.exists() || !dir.isDir())
684  dir.setFile ("/usr/local/share/aspell");
685  if (!dir.exists() || !dir.isDir())
686  dir.setFile ("/usr/pkg/lib/aspell");
687  if (!dir.exists() || !dir.isDir()) return;
688 
689  kdDebug(750) << "KSpellConfig::getAvailDictsAspell "
690  << dir.filePath() << " " << dir.dirPath() << endl;
691 
692  const TQDir thedir (dir.filePath(),"*");
693  const TQStringList entryList = thedir.entryList();
694 
695  kdDebug(750) << "KSpellConfig" << thedir.path() << "\n" << endl;
696  kdDebug(750) << "entryList().count()="
697  << entryList.count() << endl;
698 
699  TQStringList::const_iterator entryListItr = entryList.constBegin();
700  const TQStringList::const_iterator entryListEnd = entryList.constEnd();
701 
702  for ( ; entryListItr != entryListEnd; ++entryListItr)
703  {
704  TQString fname, lname, hname;
705  fname = *entryListItr;
706 
707  // consider only simple dicts without '-' in the name
708  // FIXME: may be this is wrong an the list should contain
709  // all *.multi files too, to allow using special dictionaries
710 
711  // Well, KSpell2 has a better way to do this, but this code has to be
712  // cleaned up somehow: since aspell 0.6 we have quite a lot of files in the
713  // aspell dictionary that are not dictionaries. These must not be presented as "languages"
714  // We only keep
715  // *.rws: dictionary
716  // *.multi: definition file to load several subdictionaries
717  if ( !( fname.endsWith(".rws") || fname.endsWith(".multi") ) ) {
718  // remove noise from the language list
719  continue;
720  }
721  if (fname[0] != '.')
722  {
723 
724  // remove .multi
725  if (fname.endsWith(".multi")) fname.remove (fname.length()-6,6);
726  // remove .rws
727  if (fname.endsWith(".rws")) fname.remove (fname.length()-4,4);
728 
729  if (interpret (fname, lname, hname) && langfnames.first().isEmpty())
730  { // This one is the KDE default language
731  // so place it first in the lists (overwrite "Default")
732 
733  langfnames.remove ( langfnames.begin() );
734  langfnames.prepend ( fname );
735 
736  hname=i18n("default spelling dictionary"
737  ,"Default - %1").arg(hname);
738 
739  box->changeItem (hname,0);
740  }
741  else
742  {
743  langfnames.append (fname);
744  box->insertItem (hname);
745  }
746  }
747  }
748  }
749  int whichelement = langfnames.findIndex(qsdict);
750  if ( whichelement >= 0 ) {
751  box->setCurrentItem( whichelement );
752  }
753  if ( dictionaries )
754  *dictionaries = langfnames;
755  }
756 }
757 
758 /*
759  * Options setting routines.
760  */
761 
762 void
763 KSpellConfig::setClient (int c)
764 {
765  iclient = c;
766 
767  if (clientcombo)
768  clientcombo->setCurrentItem(c);
769 }
770 
771 void
772 KSpellConfig::setNoRootAffix (bool b)
773 {
774  bnorootaffix=b;
775 
776  if(cb1)
777  cb1->setChecked(b);
778 }
779 
780 void
781 KSpellConfig::setRunTogether(bool b)
782 {
783  bruntogether=b;
784 
785  if(cb2)
786  cb2->setChecked(b);
787 }
788 
789 void
790 KSpellConfig::setDictionary (const TQString s)
791 {
792  qsdict=s; //.copy();
793 
794  if (qsdict.length()>5)
795  if ((signed)qsdict.find(".hash")==(signed)qsdict.length()-5)
796  qsdict.remove (qsdict.length()-5,5);
797 
798 
799  if(dictcombo)
800  {
801  int whichelement=-1;
802  if (dictFromList())
803  {
804  whichelement = langfnames.findIndex(s);
805 
806  if(whichelement >= 0)
807  {
808  dictcombo->setCurrentItem(whichelement);
809  }
810  }
811  }
812 
813 
814 }
815 
816 void
817 KSpellConfig::setDictFromList (bool dfl)
818 {
819  // kdebug (KDEBUG_INFO, 750, "sdfl = %d", dfl);
820  dictfromlist=dfl;
821 }
822 
823 /*
824 void KSpellConfig::setPersonalDict (const char *s)
825 {
826  qspdict=s;
827 }
828 */
829 
830 void
831 KSpellConfig::setEncoding (int enctype)
832 {
833  enc=enctype;
834 
835  if(encodingcombo)
836  encodingcombo->setCurrentItem(enctype);
837 }
838 
839 /*
840  Options reading routines.
841  */
842 int
843 KSpellConfig::client () const
844 {
845  return iclient;
846 }
847 
848 
849 bool
850 KSpellConfig::noRootAffix () const
851 {
852  return bnorootaffix;
853 }
854 
855 bool
856 KSpellConfig::runTogether() const
857 {
858  return bruntogether;
859 }
860 
861 const
862 TQString KSpellConfig::dictionary () const
863 {
864  return qsdict;
865 }
866 
867 /*
868 const TQString KSpellConfig::personalDict () const
869 {
870  return qspdict;
871 }
872 */
873 
874 int
875 KSpellConfig::encoding () const
876 {
877  return enc;
878 }
879 
880 void
881 KSpellConfig::sRunTogether(bool)
882 {
883  setRunTogether (cb2->isChecked());
884  emit configChanged();
885 }
886 
887 void
888 KSpellConfig::sNoAff(bool)
889 {
890  setNoRootAffix (cb1->isChecked());
891  emit configChanged();
892 }
893 
894 /*
895 void
896 KSpellConfig::sBrowseDict()
897 {
898  return;
899 
900  TQString qs( KFileDialog::getOpenFileName ("/usr/local/lib","*.hash") );
901  if ( !qs.isNull() )
902  kle1->setText (qs);
903 
904 }
905 */
906 
907 /*
908 void KSpellConfig::sBrowsePDict()
909 {
910  //how do I find home directory path??
911  TQString qs( KFileDialog::getOpenFileName ("",".ispell_*") );
912  if ( !qs.isNull() )
913  kle2->setText (qs);
914 
915 
916 }
917 */
918 
919 void
920 KSpellConfig::sSetDictionary (int i)
921 {
922  setDictionary (langfnames[i]);
923  setDictFromList (true);
924  TQTimer::singleShot( 0, this, TQT_SIGNAL( configChanged() ) );
925 }
926 
927 void
928 KSpellConfig::sDictionary(bool on)
929 {
930  if (on)
931  {
932  dictcombo->setEnabled (true);
933  setDictionary (langfnames[dictcombo->currentItem()] );
934  setDictFromList (true);
935  }
936  else
937  {
938  dictcombo->setEnabled (false);
939  }
940  emit configChanged();
941 }
942 
943 void
944 KSpellConfig::sPathDictionary(bool on)
945 {
946  return; //enough for now
947 
948 
949  if (on)
950  {
951  //kle1->setEnabled (true);
952  // browsebutton1->setEnabled (true);
953  //setDictionary (kle1->text());
954  setDictFromList (false);
955  }
956  else
957  {
958  //kle1->setEnabled (false);
959  //browsebutton1->setEnabled (false);
960  }
961  emit configChanged();
962 }
963 
964 
965 void KSpellConfig::activateHelp( void )
966 {
967  sHelp();
968 }
969 
970 void KSpellConfig::sHelp( void )
971 {
972  kapp->invokeHelp("configuration", "tdespell");
973 }
974 
975 /*
976 void KSpellConfig::textChanged1 (const char *s)
977 {
978  setDictionary (s);
979 }
980 
981 void KSpellConfig::textChanged2 (const char *)
982 {
983  // setPersonalDict (s);
984 }
985 */
986 
987 void
988 KSpellConfig::operator= (const KSpellConfig &ksc)
989 {
990  //We want to copy the data members, but not the
991  //pointers to the child widgets
992  setNoRootAffix (ksc.noRootAffix());
993  setRunTogether (ksc.runTogether());
994  setDictionary (ksc.dictionary());
995  setDictFromList (ksc.dictFromList());
996  // setPersonalDict (ksc.personalDict());
997  setEncoding (ksc.encoding());
998  setClient (ksc.client());
999 
1000  fillInDialog();
1001 }
1002 
1003 // KDE 4: Make it const TQStringList &
1004 void
1005 KSpellConfig::setIgnoreList (TQStringList _ignorelist)
1006 {
1007  ignorelist=_ignorelist;
1008 }
1009 
1010 TQStringList
1011 KSpellConfig::ignoreList () const
1012 {
1013  return ignorelist;
1014 }
1015 
1016 // KDE 4: Make it const TQStringList &
1017 void
1018 KSpellConfig::setReplaceAllList (TQStringList _replacelist)
1019 {
1020  d->replacelist=_replacelist;
1021 }
1022 
1023 TQStringList
1024 KSpellConfig::replaceAllList() const
1025 {
1026  return d->replacelist;
1027 }
1028 
1029 #include "ksconfig.moc"
1030 
1031 
1032 
TDELocale::twoAlphaToCountryName
TQString twoAlphaToCountryName(const TQString &code) const
KPushButton
This is nothing but a TQPushButton with drag-support and KGuiItem support.
Definition: kpushbutton.h:37
TDELocale::language
TQString language() const
TDEConfigGroupSaver
KSpellConfig::setNoRootAffix
void setNoRootAffix(bool)
Set an ISpell option.
Definition: ksconfig.cpp:772
KSpellConfig::KSpellConfig
KSpellConfig(TQWidget *parent=0, const char *name=0, KSpellConfig *spellConfig=0, bool addHelpButton=true)
Constructs a KSpellConfig with default or custom settings.
Definition: ksconfig.cpp:71
KSpellConfig::interpret
bool interpret(TQString &fname, TQString &lname, TQString &hname)
This takes a dictionary file name and provides both a language abbreviation appropriate for the $LANG...
Definition: ksconfig.cpp:255
kdDebug
kdbgstream kdDebug(int area=0)
KSpellConfig::fillDicts
void fillDicts(TQComboBox *box, TQStringList *dictionaries=0)
Get the translated dictionary names and, optionally, the corresponding internal dictionary names...
Definition: ksconfig.cpp:591
KSpellConfig::setDictionary
void setDictionary(const TQString qs)
Set the name of the dictionary to use.
Definition: ksconfig.cpp:790
KSpellConfig::setReplaceAllList
void setReplaceAllList(TQStringList _replaceAllList)
The _replaceAllList contains word you like that replace word.
Definition: ksconfig.cpp:1018
KSpellConfig::sHelp
void sHelp()
Invokes the help documentation for tdespell.
Definition: ksconfig.cpp:970
KSpellConfig::writeGlobalSettings
bool writeGlobalSettings()
Call this method before this class is deleted if you want the settings you have (or the user has) cho...
Definition: ksconfig.cpp:201
tdelocale.h
KDialog::spacingHint
static int spacingHint()
Return the number of pixels you shall use between widgets inside a dialog according to the KDE standa...
Definition: kdialog.cpp:110
TDEConfigBase::writeEntry
void writeEntry(const TQString &pKey, const TQString &pValue, bool bPersistent=true, bool bGlobal=false, bool bNLS=false)
KSpellConfig::noRootAffix
bool noRootAffix() const
Options reading routines.
Definition: ksconfig.cpp:850
KSpellConfig::~KSpellConfig
virtual ~KSpellConfig()
Deconstructor.
Definition: ksconfig.cpp:169
KSpellConfig::setRunTogether
void setRunTogether(bool)
Set an ISpell option.
Definition: ksconfig.cpp:781
TDEGlobal::locale
static TDELocale * locale()
KSpellConfig
A configuration class/dialog for KSpell.
Definition: ksconfig.h:87
KSpellConfig::setIgnoreList
void setIgnoreList(TQStringList _ignorelist)
Options setting routines.
Definition: ksconfig.cpp:1005
KSpellConfig::client
int client() const
Spell checker client, see KSpellClients.
Definition: ksconfig.cpp:843
TDEGlobal::config
static TDEConfig * config()
endl
kndbgstream & endl(kndbgstream &s)
KSpellConfig::activateHelp
void activateHelp(void)
Use this function to activate the help information for this widget.
Definition: ksconfig.cpp:965
TDEConfigBase::readEntry
TQString readEntry(const TQString &pKey, const TQString &aDefault=TQString::null) const
TDEConfigBase::sync
virtual void sync()
TDEConfigBase::readNumEntry
int readNumEntry(const TQString &pKey, int nDefault=0) const
TDELocale::twoAlphaToLanguageName
TQString twoAlphaToLanguageName(const TQString &code) const

tdeui

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

tdeui

Skip menu "tdeui"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeui by doxygen 1.8.11
This website is maintained by Timothy Pearson.