• 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;
448  TQStringList dirs;
449  dirs
450  << "/usr/" SYSTEM_LIBDIR "/ispell"
451  << "/usr/lib/ispell"
452  << "/usr/local/" SYSTEM_LIBDIR "/ispell"
453  << "/usr/local/lib/ispell"
454  << "/usr/local/share/ispell"
455  << "/usr/share/ispell"
456  << "/usr/pkg/lib";
457  for (TQStringList::ConstIterator it=dirs.begin(); it != dirs.end(); ++it) {
458  dir.setFile(*it);
459  if (dir.exists() && dir.isDir()) {
460  break;
461  }
462  }
463  /* TODO get them all instead of just one of them.
464  * If /usr/local/lib exists, it skips the rest
465  */
466  if (!dir.exists() || !dir.isDir()) return;
467 
468  kdDebug(750) << "KSpellConfig::getAvailDictsIspell "
469  << dir.filePath() << " " << dir.dirPath() << endl;
470 
471  const TQDir thedir (dir.filePath(),"*.hash");
472  const TQStringList entryList = thedir.entryList();
473 
474  kdDebug(750) << "KSpellConfig" << thedir.path() << "\n" << endl;
475  kdDebug(750) << "entryList().count()="
476  << entryList.count() << endl;
477 
478  TQStringList::const_iterator entryListItr = entryList.constBegin();
479  const TQStringList::const_iterator entryListEnd = entryList.constEnd();
480 
481  for ( ; entryListItr != entryListEnd; ++entryListItr)
482  {
483  TQString fname, lname, hname;
484  fname = *entryListItr;
485 
486  // remove .hash
487  if (fname.endsWith(".hash")) fname.remove (fname.length()-5,5);
488 
489  if (interpret (fname, lname, hname) && langfnames.first().isEmpty())
490  { // This one is the KDE default language
491  // so place it first in the lists (overwrite "Default")
492 
493  langfnames.remove ( langfnames.begin() );
494  langfnames.prepend ( fname );
495 
496  hname=i18n("default spelling dictionary"
497  ,"Default - %1 [%2]").arg(hname).arg(fname);
498 
499  dictcombo->changeItem (hname,0);
500  }
501  else
502  {
503  langfnames.append (fname);
504  hname=hname+" ["+fname+"]";
505 
506  dictcombo->insertItem (hname);
507  }
508  }
509 }
510 
511 void KSpellConfig::getAvailDictsAspell () {
512 
513  langfnames.clear();
514  dictcombo->clear();
515 
516  langfnames.append(""); // Default
517  dictcombo->insertItem (i18n("ASpell Default"));
518 
519  // Aspell now have /usr/lib/aspell as
520  // ASPELL_DATADIR default.
521  TQFileInfo dir ( ASPELL_DATADIR );
522  if (!dir.exists() || !dir.isDir())
523  dir.setFile ("/usr/lib" KDELIBSUFF "/aspell-0.60");
524  if (!dir.exists() || !dir.isDir())
525  dir.setFile ("/usr/local/lib" KDELIBSUFF "/aspell");
526  if (!dir.exists() || !dir.isDir())
527  dir.setFile ("/usr/share/aspell");
528  if (!dir.exists() || !dir.isDir())
529  dir.setFile ("/usr/local/share/aspell");
530  if (!dir.exists() || !dir.isDir())
531  dir.setFile ("/usr/pkg/lib/aspell");
532  if (!dir.exists() || !dir.isDir()) return;
533 
534  kdDebug(750) << "KSpellConfig::getAvailDictsAspell "
535  << dir.filePath() << " " << dir.dirPath() << endl;
536 
537  const TQDir thedir (dir.filePath(),"*");
538  const TQStringList entryList = thedir.entryList();
539 
540  kdDebug(750) << "KSpellConfig" << thedir.path() << "\n" << endl;
541  kdDebug(750) << "entryList().count()="
542  << entryList.count() << endl;
543 
544  TQStringList::const_iterator entryListItr = entryList.constBegin();
545  const TQStringList::const_iterator entryListEnd = entryList.constEnd();
546 
547  for ( ; entryListItr != entryListEnd; ++entryListItr)
548  {
549  TQString fname, lname, hname;
550  fname = *entryListItr;
551 
552  // consider only simple dicts without '-' in the name
553  // FIXME: may be this is wrong an the list should contain
554  // all *.multi files too, to allow using special dictionaries
555 
556  // Well, KSpell2 has a better way to do this, but this code has to be
557  // cleaned up somehow: since aspell 0.6 we have quite a lot of files in the
558  // aspell dictionary that are not dictionaries. These must not be presented as "languages"
559  // We only keep
560  // *.rws: dictionary
561  // *.multi: definition file to load several subdictionaries
562  if ( !( fname.endsWith(".rws") || fname.endsWith(".multi") ) ) {
563  // remove noise from the language list
564  continue;
565  }
566  if (fname[0] != '.')
567  {
568 
569  // remove .multi
570  if (fname.endsWith(".multi")) fname.remove (fname.length()-6,6);
571  // remove .rws
572  if (fname.endsWith(".rws")) fname.remove (fname.length()-4,4);
573 
574  if (interpret (fname, lname, hname) && langfnames.first().isEmpty())
575  { // This one is the KDE default language
576  // so place it first in the lists (overwrite "Default")
577 
578  langfnames.remove ( langfnames.begin() );
579  langfnames.prepend ( fname );
580 
581  hname=i18n("default spelling dictionary"
582  ,"Default - %1").arg(hname);
583 
584  dictcombo->changeItem (hname,0);
585  }
586  else
587  {
588  langfnames.append (fname);
589  dictcombo->insertItem (hname);
590  }
591  }
592  }
593 }
594 
595 void
596 KSpellConfig::fillDicts( TQComboBox* box, TQStringList* dictionaries )
597 {
598  langfnames.clear();
599  if ( box ) {
600  if ( iclient == KS_CLIENT_ISPELL ) {
601  box->clear();
602  langfnames.append(""); // Default
603  box->insertItem( i18n("ISpell Default") );
604 
605  // dictionary path
606  TQFileInfo dir ("/usr/lib/ispell");
607  if (!dir.exists() || !dir.isDir())
608  dir.setFile ("/usr/local/lib/ispell");
609  if (!dir.exists() || !dir.isDir())
610  dir.setFile ("/usr/local/share/ispell");
611  if (!dir.exists() || !dir.isDir())
612  dir.setFile ("/usr/share/ispell");
613  if (!dir.exists() || !dir.isDir())
614  dir.setFile ("/usr/pkg/lib");
615  /* TODO get them all instead of just one of them.
616  * If /usr/local/lib exists, it skips the rest
617  if (!dir.exists() || !dir.isDir())
618  dir.setFile ("/usr/local/lib");
619  */
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 

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.1.2
This website is maintained by Timothy Pearson.