• 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  setClient ( kc->readNumEntry ("KSpell_Client", DEFAULT_SPELL_CHECKER) );
192 
193  return true;
194 }
195 
196 bool
197 KSpellConfig::writeGlobalSettings ()
198 {
199  TDEConfigGroupSaver 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 = TDEGlobal::locale()->twoAlphaToLanguageName( lname );
281  }
282  else if ( (dname.length() == 5) && (dname[2] == '_') ) {
283  lname = dname.left(2);
284  hname = TDEGlobal::locale()->twoAlphaToLanguageName(lname);
285  TQString country = TDEGlobal::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 ( ( TDEGlobal::locale()->language() == TQString::fromLatin1("C") &&
367  lname==TQString::fromLatin1("en") ) ||
368  TDEGlobal::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;
444  TQStringList dirs;
445  dirs
446  << "/usr/" SYSTEM_LIBDIR "/ispell"
447  << "/usr/lib/ispell"
448  << "/usr/local/" SYSTEM_LIBDIR "/ispell"
449  << "/usr/local/lib/ispell"
450  << "/usr/local/share/ispell"
451  << "/usr/share/ispell"
452  << "/usr/pkg/lib";
453  for (TQStringList::ConstIterator it=dirs.begin(); it != dirs.end(); ++it) {
454  dir.setFile(*it);
455  if (dir.exists() && dir.isDir()) {
456  break;
457  }
458  }
459  /* TODO get them all instead of just one of them.
460  * If /usr/local/lib exists, it skips the rest
461  */
462  if (!dir.exists() || !dir.isDir()) return;
463 
464  kdDebug(750) << "KSpellConfig::getAvailDictsIspell "
465  << dir.filePath() << " " << dir.dirPath() << endl;
466 
467  const TQDir thedir (dir.filePath(),"*.hash");
468  const TQStringList entryList = thedir.entryList();
469 
470  kdDebug(750) << "KSpellConfig" << thedir.path() << "\n" << endl;
471  kdDebug(750) << "entryList().count()="
472  << entryList.count() << endl;
473 
474  TQStringList::const_iterator entryListItr = entryList.constBegin();
475  const TQStringList::const_iterator entryListEnd = entryList.constEnd();
476 
477  for ( ; entryListItr != entryListEnd; ++entryListItr)
478  {
479  TQString fname, lname, hname;
480  fname = *entryListItr;
481 
482  // remove .hash
483  if (fname.endsWith(".hash")) fname.remove (fname.length()-5,5);
484 
485  if (interpret (fname, lname, hname) && langfnames.first().isEmpty())
486  { // This one is the KDE default language
487  // so place it first in the lists (overwrite "Default")
488 
489  langfnames.remove ( langfnames.begin() );
490  langfnames.prepend ( fname );
491 
492  hname=i18n("default spelling dictionary"
493  ,"Default - %1 [%2]").arg(hname).arg(fname);
494 
495  dictcombo->changeItem (hname,0);
496  }
497  else
498  {
499  langfnames.append (fname);
500  hname=hname+" ["+fname+"]";
501 
502  dictcombo->insertItem (hname);
503  }
504  }
505 }
506 
507 void KSpellConfig::getAvailDictsAspell () {
508 
509  langfnames.clear();
510  dictcombo->clear();
511 
512  langfnames.append(""); // Default
513  dictcombo->insertItem (i18n("ASpell Default"));
514 
515  // Aspell now have /usr/lib/aspell as
516  // ASPELL_DATADIR default.
517  TQFileInfo dir ( ASPELL_DATADIR );
518  if (!dir.exists() || !dir.isDir())
519  dir.setFile ("/usr/lib" KDELIBSUFF "/aspell-0.60");
520  if (!dir.exists() || !dir.isDir())
521  dir.setFile ("/usr/local/lib" KDELIBSUFF "/aspell");
522  if (!dir.exists() || !dir.isDir())
523  dir.setFile ("/usr/share/aspell");
524  if (!dir.exists() || !dir.isDir())
525  dir.setFile ("/usr/local/share/aspell");
526  if (!dir.exists() || !dir.isDir())
527  dir.setFile ("/usr/pkg/lib/aspell");
528  if (!dir.exists() || !dir.isDir()) return;
529 
530  kdDebug(750) << "KSpellConfig::getAvailDictsAspell "
531  << dir.filePath() << " " << dir.dirPath() << endl;
532 
533  const TQDir thedir (dir.filePath(),"*");
534  const TQStringList entryList = thedir.entryList();
535 
536  kdDebug(750) << "KSpellConfig" << thedir.path() << "\n" << endl;
537  kdDebug(750) << "entryList().count()="
538  << entryList.count() << endl;
539 
540  TQStringList::const_iterator entryListItr = entryList.constBegin();
541  const TQStringList::const_iterator entryListEnd = entryList.constEnd();
542 
543  for ( ; entryListItr != entryListEnd; ++entryListItr)
544  {
545  TQString fname, lname, hname;
546  fname = *entryListItr;
547 
548  // consider only simple dicts without '-' in the name
549  // FIXME: may be this is wrong an the list should contain
550  // all *.multi files too, to allow using special dictionaries
551 
552  // Well, KSpell2 has a better way to do this, but this code has to be
553  // cleaned up somehow: since aspell 0.6 we have quite a lot of files in the
554  // aspell dictionary that are not dictionaries. These must not be presented as "languages"
555  // We only keep
556  // *.rws: dictionary
557  // *.multi: definition file to load several subdictionaries
558  if ( !( fname.endsWith(".rws") || fname.endsWith(".multi") ) ) {
559  // remove noise from the language list
560  continue;
561  }
562  if (fname[0] != '.')
563  {
564 
565  // remove .multi
566  if (fname.endsWith(".multi")) fname.remove (fname.length()-6,6);
567  // remove .rws
568  if (fname.endsWith(".rws")) fname.remove (fname.length()-4,4);
569 
570  if (interpret (fname, lname, hname) && langfnames.first().isEmpty())
571  { // This one is the KDE default language
572  // so place it first in the lists (overwrite "Default")
573 
574  langfnames.remove ( langfnames.begin() );
575  langfnames.prepend ( fname );
576 
577  hname=i18n("default spelling dictionary"
578  ,"Default - %1").arg(hname);
579 
580  dictcombo->changeItem (hname,0);
581  }
582  else
583  {
584  langfnames.append (fname);
585  dictcombo->insertItem (hname);
586  }
587  }
588  }
589 }
590 
591 void
592 KSpellConfig::fillDicts( TQComboBox* box, TQStringList* dictionaries )
593 {
594  langfnames.clear();
595  if ( box ) {
596  if ( iclient == KS_CLIENT_ISPELL ) {
597  box->clear();
598  langfnames.append(""); // Default
599  box->insertItem( i18n("ISpell Default") );
600 
601  // dictionary path
602 #ifdef ISPELL_LIBDIR
603  TQFileInfo dir (ISPELL_LIBDIR);
604 #else
605  TQFileInfo dir ("/usr/lib/ispell");
606  if (!dir.exists() || !dir.isDir())
607  dir.setFile ("/usr/local/lib/ispell");
608  if (!dir.exists() || !dir.isDir())
609  dir.setFile ("/usr/local/share/ispell");
610  if (!dir.exists() || !dir.isDir())
611  dir.setFile ("/usr/share/ispell");
612  if (!dir.exists() || !dir.isDir())
613  dir.setFile ("/usr/pkg/lib");
614  /* TODO get them all instead of just one of them.
615  * If /usr/local/lib exists, it skips the rest
616  if (!dir.exists() || !dir.isDir())
617  dir.setFile ("/usr/local/lib");
618  */
619 #endif
620  if (!dir.exists() || !dir.isDir()) return;
621 
622  kdDebug(750) << "KSpellConfig::getAvailDictsIspell "
623  << dir.filePath() << " " << dir.dirPath() << endl;
624 
625  const TQDir thedir (dir.filePath(),"*.hash");
626  const TQStringList entryList = thedir.entryList();
627 
628  kdDebug(750) << "KSpellConfig" << thedir.path() << "\n" << endl;
629  kdDebug(750) << "entryList().count()="
630  << entryList.count() << endl;
631 
632  TQStringList::const_iterator entryListItr = entryList.constBegin();
633  const TQStringList::const_iterator entryListEnd = entryList.constEnd();
634 
635  for ( ; entryListItr != entryListEnd; ++entryListItr)
636  {
637  TQString fname, lname, hname;
638  fname = *entryListItr;
639 
640  // remove .hash
641  if (fname.endsWith(".hash")) fname.remove (fname.length()-5,5);
642 
643  if (interpret (fname, lname, hname) && langfnames.first().isEmpty())
644  { // This one is the KDE default language
645  // so place it first in the lists (overwrite "Default")
646 
647  langfnames.remove ( langfnames.begin() );
648  langfnames.prepend ( fname );
649 
650  hname=i18n("default spelling dictionary"
651  ,"Default - %1 [%2]").arg(hname).arg(fname);
652 
653  box->changeItem (hname,0);
654  }
655  else
656  {
657  langfnames.append (fname);
658  hname=hname+" ["+fname+"]";
659 
660  box->insertItem (hname);
661  }
662  }
663  } else if ( iclient == KS_CLIENT_HSPELL ) {
664  box->clear();
665  box->insertItem( i18n("Hebrew") );
666  langfnames.append(""); // Default
667  sChangeEncoding( KS_E_CP1255 );
668  } else if ( iclient == KS_CLIENT_ZEMBEREK ) {
669  box->clear();
670  box->insertItem( i18n("Turkish") );
671  langfnames.append("");
672  sChangeEncoding( KS_E_UTF8 );
673  }
674  else {
675  box->clear();
676  langfnames.append(""); // Default
677  box->insertItem (i18n("ASpell Default"));
678 
679  // dictionary path
680  // FIXME: use "aspell dump config" to find out the dict-dir
681  TQFileInfo dir ("/usr/lib" KDELIBSUFF "/aspell");
682  if (!dir.exists() || !dir.isDir())
683  dir.setFile ("/usr/lib" KDELIBSUFF "/aspell-0.60");
684  if (!dir.exists() || !dir.isDir())
685  dir.setFile ("/usr/local/lib" KDELIBSUFF "/aspell");
686  if (!dir.exists() || !dir.isDir())
687  dir.setFile ("/usr/share/aspell");
688  if (!dir.exists() || !dir.isDir())
689  dir.setFile ("/usr/local/share/aspell");
690  if (!dir.exists() || !dir.isDir())
691  dir.setFile ("/usr/pkg/lib/aspell");
692  if (!dir.exists() || !dir.isDir()) return;
693 
694  kdDebug(750) << "KSpellConfig::getAvailDictsAspell "
695  << dir.filePath() << " " << dir.dirPath() << endl;
696 
697  const TQDir thedir (dir.filePath(),"*");
698  const TQStringList entryList = thedir.entryList();
699 
700  kdDebug(750) << "KSpellConfig" << thedir.path() << "\n" << endl;
701  kdDebug(750) << "entryList().count()="
702  << entryList.count() << endl;
703 
704  TQStringList::const_iterator entryListItr = entryList.constBegin();
705  const TQStringList::const_iterator entryListEnd = entryList.constEnd();
706 
707  for ( ; entryListItr != entryListEnd; ++entryListItr)
708  {
709  TQString fname, lname, hname;
710  fname = *entryListItr;
711 
712  // consider only simple dicts without '-' in the name
713  // FIXME: may be this is wrong an the list should contain
714  // all *.multi files too, to allow using special dictionaries
715 
716  // Well, KSpell2 has a better way to do this, but this code has to be
717  // cleaned up somehow: since aspell 0.6 we have quite a lot of files in the
718  // aspell dictionary that are not dictionaries. These must not be presented as "languages"
719  // We only keep
720  // *.rws: dictionary
721  // *.multi: definition file to load several subdictionaries
722  if ( !( fname.endsWith(".rws") || fname.endsWith(".multi") ) ) {
723  // remove noise from the language list
724  continue;
725  }
726  if (fname[0] != '.')
727  {
728 
729  // remove .multi
730  if (fname.endsWith(".multi")) fname.remove (fname.length()-6,6);
731  // remove .rws
732  if (fname.endsWith(".rws")) fname.remove (fname.length()-4,4);
733 
734  if (interpret (fname, lname, hname) && langfnames.first().isEmpty())
735  { // This one is the KDE default language
736  // so place it first in the lists (overwrite "Default")
737 
738  langfnames.remove ( langfnames.begin() );
739  langfnames.prepend ( fname );
740 
741  hname=i18n("default spelling dictionary"
742  ,"Default - %1").arg(hname);
743 
744  box->changeItem (hname,0);
745  }
746  else
747  {
748  langfnames.append (fname);
749  box->insertItem (hname);
750  }
751  }
752  }
753  }
754  int whichelement = langfnames.findIndex(qsdict);
755  if ( whichelement >= 0 ) {
756  box->setCurrentItem( whichelement );
757  }
758  if ( dictionaries )
759  *dictionaries = langfnames;
760  }
761 }
762 
763 /*
764  * Options setting routines.
765  */
766 
767 void
768 KSpellConfig::setClient (int c)
769 {
770  iclient = c;
771 
772  if (clientcombo)
773  clientcombo->setCurrentItem(c);
774 }
775 
776 void
777 KSpellConfig::setNoRootAffix (bool b)
778 {
779  bnorootaffix=b;
780 
781  if(cb1)
782  cb1->setChecked(b);
783 }
784 
785 void
786 KSpellConfig::setRunTogether(bool b)
787 {
788  bruntogether=b;
789 
790  if(cb2)
791  cb2->setChecked(b);
792 }
793 
794 void
795 KSpellConfig::setDictionary (const TQString s)
796 {
797  qsdict=s; //.copy();
798 
799  if (qsdict.length()>5)
800  if ((signed)qsdict.find(".hash")==(signed)qsdict.length()-5)
801  qsdict.remove (qsdict.length()-5,5);
802 
803 
804  if(dictcombo)
805  {
806  int whichelement=-1;
807  if (dictFromList())
808  {
809  whichelement = langfnames.findIndex(s);
810 
811  if(whichelement >= 0)
812  {
813  dictcombo->setCurrentItem(whichelement);
814  }
815  }
816  }
817 
818 
819 }
820 
821 void
822 KSpellConfig::setDictFromList (bool dfl)
823 {
824  // kdebug (KDEBUG_INFO, 750, "sdfl = %d", dfl);
825  dictfromlist=dfl;
826 }
827 
828 /*
829 void KSpellConfig::setPersonalDict (const char *s)
830 {
831  qspdict=s;
832 }
833 */
834 
835 void
836 KSpellConfig::setEncoding (int enctype)
837 {
838  enc=enctype;
839 
840  if(encodingcombo)
841  encodingcombo->setCurrentItem(enctype);
842 }
843 
844 /*
845  Options reading routines.
846  */
847 int
848 KSpellConfig::client () const
849 {
850  return iclient;
851 }
852 
853 
854 bool
855 KSpellConfig::noRootAffix () const
856 {
857  return bnorootaffix;
858 }
859 
860 bool
861 KSpellConfig::runTogether() const
862 {
863  return bruntogether;
864 }
865 
866 const
867 TQString KSpellConfig::dictionary () const
868 {
869  return qsdict;
870 }
871 
872 /*
873 const TQString KSpellConfig::personalDict () const
874 {
875  return qspdict;
876 }
877 */
878 
879 int
880 KSpellConfig::encoding () const
881 {
882  return enc;
883 }
884 
885 void
886 KSpellConfig::sRunTogether(bool)
887 {
888  setRunTogether (cb2->isChecked());
889  emit configChanged();
890 }
891 
892 void
893 KSpellConfig::sNoAff(bool)
894 {
895  setNoRootAffix (cb1->isChecked());
896  emit configChanged();
897 }
898 
899 /*
900 void
901 KSpellConfig::sBrowseDict()
902 {
903  return;
904 
905  TQString qs( KFileDialog::getOpenFileName ("/usr/local/lib","*.hash") );
906  if ( !qs.isNull() )
907  kle1->setText (qs);
908 
909 }
910 */
911 
912 /*
913 void KSpellConfig::sBrowsePDict()
914 {
915  //how do I find home directory path??
916  TQString qs( KFileDialog::getOpenFileName ("",".ispell_*") );
917  if ( !qs.isNull() )
918  kle2->setText (qs);
919 
920 
921 }
922 */
923 
924 void
925 KSpellConfig::sSetDictionary (int i)
926 {
927  setDictionary (langfnames[i]);
928  setDictFromList (true);
929  TQTimer::singleShot( 0, this, TQT_SIGNAL( configChanged() ) );
930 }
931 
932 void
933 KSpellConfig::sDictionary(bool on)
934 {
935  if (on)
936  {
937  dictcombo->setEnabled (true);
938  setDictionary (langfnames[dictcombo->currentItem()] );
939  setDictFromList (true);
940  }
941  else
942  {
943  dictcombo->setEnabled (false);
944  }
945  emit configChanged();
946 }
947 
948 void
949 KSpellConfig::sPathDictionary(bool on)
950 {
951  return; //enough for now
952 
953 
954  if (on)
955  {
956  //kle1->setEnabled (true);
957  // browsebutton1->setEnabled (true);
958  //setDictionary (kle1->text());
959  setDictFromList (false);
960  }
961  else
962  {
963  //kle1->setEnabled (false);
964  //browsebutton1->setEnabled (false);
965  }
966  emit configChanged();
967 }
968 
969 
970 void KSpellConfig::activateHelp( void )
971 {
972  sHelp();
973 }
974 
975 void KSpellConfig::sHelp( void )
976 {
977  kapp->invokeHelp("configuration", "tdespell");
978 }
979 
980 /*
981 void KSpellConfig::textChanged1 (const char *s)
982 {
983  setDictionary (s);
984 }
985 
986 void KSpellConfig::textChanged2 (const char *)
987 {
988  // setPersonalDict (s);
989 }
990 */
991 
992 void
993 KSpellConfig::operator= (const KSpellConfig &ksc)
994 {
995  //We want to copy the data members, but not the
996  //pointers to the child widgets
997  setNoRootAffix (ksc.noRootAffix());
998  setRunTogether (ksc.runTogether());
999  setDictionary (ksc.dictionary());
1000  setDictFromList (ksc.dictFromList());
1001  // setPersonalDict (ksc.personalDict());
1002  setEncoding (ksc.encoding());
1003  setClient (ksc.client());
1004 
1005  fillInDialog();
1006 }
1007 
1008 // KDE 4: Make it const TQStringList &
1009 void
1010 KSpellConfig::setIgnoreList (TQStringList _ignorelist)
1011 {
1012  ignorelist=_ignorelist;
1013 }
1014 
1015 TQStringList
1016 KSpellConfig::ignoreList () const
1017 {
1018  return ignorelist;
1019 }
1020 
1021 // KDE 4: Make it const TQStringList &
1022 void
1023 KSpellConfig::setReplaceAllList (TQStringList _replacelist)
1024 {
1025  d->replacelist=_replacelist;
1026 }
1027 
1028 TQStringList
1029 KSpellConfig::replaceAllList() const
1030 {
1031  return d->replacelist;
1032 }
1033 
1034 #include "ksconfig.moc"
1035 
1036 
1037 
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:777
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:251
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:592
KSpellConfig::setDictionary
void setDictionary(const TQString qs)
Set the name of the dictionary to use.
Definition: ksconfig.cpp:795
KSpellConfig::setReplaceAllList
void setReplaceAllList(TQStringList _replaceAllList)
The _replaceAllList contains word you like that replace word.
Definition: ksconfig.cpp:1023
KSpellConfig::sHelp
void sHelp()
Invokes the help documentation for tdespell.
Definition: ksconfig.cpp:975
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:197
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
KSpellConfig::noRootAffix
bool noRootAffix() const
Options reading routines.
Definition: ksconfig.cpp:855
KSpellConfig::~KSpellConfig
virtual ~KSpellConfig()
Deconstructor.
Definition: ksconfig.cpp:169
KSpellConfig::setRunTogether
void setRunTogether(bool)
Set an ISpell option.
Definition: ksconfig.cpp:786
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:1010
KSpellConfig::client
int client() const
Spell checker client, see KSpellClients.
Definition: ksconfig.cpp:848
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:970
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
  •     tdecore
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  • tdeioslave
  •   http
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeui by doxygen 1.8.8
This website is maintained by Timothy Pearson.