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