summaryrefslogtreecommitdiffstats
path: root/bibletime/frontend/coptionsdialog.cpp
blob: 0b1baad552e8970cffc72d9027845997839717d3 (plain)
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
/*********
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
* Copyright 1999-2006 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/



#include "coptionsdialog.h"
#include "cprofile.h"

#include "backend/cswordbackend.h"
#include "backend/cswordmoduleinfo.h"
#include "backend/cdisplaytemplatemgr.h"
#include "backend/cdisplayrendering.h"

#include "frontend/displaywindow/cbiblereadwindow.h"
#include "frontend/displaywindow/ccommentaryreadwindow.h"
#include "frontend/displaywindow/clexiconreadwindow.h"
#include "frontend/displaywindow/cbookreadwindow.h"
#include "frontend/displaywindow/creadwindow.h"

#include "util/cresmgr.h"
#include "util/ctoolclass.h"

#include <stdio.h>
#include <stdlib.h>

//QT includes
#include <tqhbox.h>
#include <tqlayout.h>
#include <tqvbox.h>
#include <tqdict.h>
#include <tqcheckbox.h>
#include <tqcombobox.h>
#include <tqbuttongroup.h>
#include <tqhbuttongroup.h>
#include <tqradiobutton.h>
#include <tqcolor.h>
#include <tqtooltip.h>
#include <tqwidgetstack.h>

#include <tqstringlist.h>
#include <tqinputdialog.h>
#include <tqdir.h>

//KDE includes
#include <kapp.h>
#include <tdelocale.h>
#include <tdeglobal.h>
#include <kstandarddirs.h>
#include <kkeydialog.h>
#include <tdehtml_part.h>
#include <tdehtmlview.h>
#include <kiconloader.h>
#include <ktabctl.h>
#include <kapp.h>
#include <tdelistbox.h>
#include <kkeydialog.h>
#include <tdeaction.h>
#include <tdeconfigbase.h>
#include <tdeconfig.h>

//Sword includes
#include <localemgr.h>
#include <swlocale.h>

using std::string;
using std::list;

COptionsDialog::COptionsDialog(TQWidget *parent, const char *name, TDEActionCollection* actionCollection )
: KDialogBase(IconList, i18n("Configure BibleTime"), Ok | Cancel | Apply, Ok, parent, name, true, true, TQString(), TQString(), TQString()) {

	m_settings.keys.application.actionCollection = actionCollection;
	setIconListAllVisible(true);

	initDisplay();
	initLanguages();
	initSword();
	initAccelerators();
}

COptionsDialog::~COptionsDialog() {
	//the actionCollections objects are deleted by their TQWidget parent
}

/**  */
void COptionsDialog::newDisplayWindowFontSelected(const TQFont &newFont) {
	CBTConfig::FontSettingsPair oldSettings = m_settings.fonts.fontMap[ m_settings.fonts.usage->currentText() ];
	m_settings.fonts.fontMap.replace( m_settings.fonts.usage->currentText(), CBTConfig::FontSettingsPair(oldSettings.first, newFont) );
}

/** Called when the combobox contents is changed */
void COptionsDialog::newDisplayWindowFontAreaSelected(const TQString& usage) {
	useOwnFontClicked( m_settings.fonts.fontMap[usage].first );
	m_settings.fonts.useOwnFontBox->setChecked( m_settings.fonts.fontMap[usage].first );

	m_settings.fonts.fontChooser->setFont( m_settings.fonts.fontMap[usage].second );
}

/** Called if the OK button was clicked */
void COptionsDialog::slotOk() {
	saveAccelerators();
	saveLanguages();
	saveSword();
	saveDisplay();

	KDialogBase::slotOk();
	emit signalSettingsChanged( );
}

/*called if the apply button was clicked*/
void COptionsDialog::slotApply() {
	saveAccelerators();
	saveLanguages();
	saveSword();
	saveDisplay();

	KDialogBase::slotApply();
	emit signalSettingsChanged( );
}

/** Opens the page which contaisn the given part ID. */
const bool COptionsDialog::showPart( COptionsDialog::Parts /*ID*/ ) {
	bool ret = false;
	/* switch (ID) {
	  default:
	   break;
	 }*/
	return ret;
}

/** Initializes the startup section of the OD. */
void COptionsDialog::initDisplay() {
	TQFrame* page = addPage(i18n("Display"), TQString(), DesktopIcon(CResMgr::settings::startup::icon,32));
	TQVBoxLayout* layout = new TQVBoxLayout(page);
	layout->setSpacing( 5 );

	{//daily tips
		m_settings.startup.showTips = new TQCheckBox(page);
		m_settings.startup.showTips->setText(i18n("Show tip of the day"));
		TQToolTip::add
			(m_settings.startup.showTips, CResMgr::settings::startup::dailyTip::tooltip );


		m_settings.startup.showTips->setChecked( CBTConfig::get
					(CBTConfig::tips) );
	}
	layout->addWidget(m_settings.startup.showTips);
	layout->addSpacing(5);

	{ //startup logo
		m_settings.startup.showLogo = new TQCheckBox(page);
		m_settings.startup.showLogo->setText(i18n("Show startuplogo"));
		TQToolTip::add
			(m_settings.startup.showLogo, CResMgr::settings::startup::showLogo::tooltip);


		m_settings.startup.showLogo->setChecked(CBTConfig::get
													(CBTConfig::logo));
		layout->addWidget(m_settings.startup.showLogo);
		layout->addSpacing(20);
	}

	layout->addWidget(
		CToolClass::explanationLabel(page, i18n("Display templates"),
									 i18n("Display templates define how text is displayed. Please choose a template you like.")
									)
	);

	layout->addSpacing( 5 );

	TQHBoxLayout* hboxlayout = new TQHBoxLayout();

	m_settings.displayStyle.styleChooser = new TQComboBox( page ); //create first to enable buddy for label
	connect( m_settings.displayStyle.styleChooser, TQT_SIGNAL( activated( int ) ),
			 this, TQT_SLOT( updateStylePreview() ) );

	hboxlayout->addWidget(
		new TQLabel(m_settings.displayStyle.styleChooser, i18n("Available display styles:"), page)
	);
	hboxlayout->addWidget( m_settings.displayStyle.styleChooser );
	hboxlayout->addStretch();
	layout->addLayout( hboxlayout );

	m_settings.displayStyle.stylePreview = new TDEHTMLPart(page);
	layout->addWidget(
		new TQLabel(
			m_settings.displayStyle.stylePreview->view(),
			i18n("Style preview"), page
		)
	);
	layout->addWidget(m_settings.displayStyle.stylePreview->view());

	m_settings.displayStyle.styleChooser->insertStringList(
		CPointers::displayTemplateManager()->availableTemplates()
	);

	for (int i = 0; i < m_settings.displayStyle.styleChooser->count(); ++i) {
		if ( m_settings.displayStyle.styleChooser->text(i) == CBTConfig::get(CBTConfig::displayStyle) ) {
			m_settings.displayStyle.styleChooser->setCurrentItem( i );
			break;
		}
	}

	updateStylePreview(); //render it
}

/** Init fonts section. */
void COptionsDialog::initLanguages() {
	TQFrame* page = addPage(i18n("Languages"), TQString(), DesktopIcon(CResMgr::settings::fonts::icon, 32));
	TQVBoxLayout* layout = new TQVBoxLayout(page,5);
	layout->setResizeMode( TQLayout::Minimum );

	{ //Sword locales
		layout->addWidget(
			CToolClass::explanationLabel(page, i18n("Specify a language for names of Bible books"),
										 i18n("Sword has a number of locales available which can be used to internationalize the \
  names of books of the Bible. You can specify which locale to use. If you want to \
  create a new locale, see http://www.crosswire.org/sword/develop for details."))
		);

		m_settings.fonts.swordLocaleCombo = new TQComboBox(page);
		TQLabel* label = new TQLabel(m_settings.fonts.swordLocaleCombo, i18n("Language for names of Bible books"), page);
		TQToolTip::add
			(m_settings.fonts.swordLocaleCombo, CResMgr::settings::sword::general::language::tooltip);


		TQHBoxLayout* hBoxLayout = new TQHBoxLayout();
		hBoxLayout->addWidget(label);
		hBoxLayout->addWidget(m_settings.fonts.swordLocaleCombo);
		hBoxLayout->addStretch();
		layout->addLayout(hBoxLayout);

		TQStringList languageNames;
		languageNames.append( languageMgr()->languageForAbbrev("en_US")->translatedName() );
		//   languageNames.append( i18n("English") );

		list<sword::SWBuf> locales = sword::LocaleMgr::getSystemLocaleMgr()->getAvailableLocales();
		//   locales.push_back(SWBuf("en_US"));

		for (list<sword::SWBuf>::const_iterator it = locales.begin(); it != locales.end(); it++) {
			//    tqWarning("working on %s", (*it).c_str());
			const CLanguageMgr::Language* const l = CPointers::languageMgr()->languageForAbbrev(
														sword::LocaleMgr::getSystemLocaleMgr()->getLocale((*it).c_str())->getName()
													);

			if (l->isValid()) {
				languageNames.append( l->translatedName() );
			}
			else {
				languageNames.append(
					sword::LocaleMgr::getSystemLocaleMgr()->getLocale((*it).c_str())->getDescription()
				);
			}
		}

		languageNames.sort();
		m_settings.fonts.swordLocaleCombo->insertStringList( languageNames );

		const CLanguageMgr::Language* const l = CPointers::languageMgr()->languageForAbbrev(
													CBTConfig::get
														(CBTConfig::language)
													);

		TQString currentLanguageName;
		if ( l->isValid() && languageNames.contains(l->translatedName()) ) { //tranlated language name is in the box
			currentLanguageName = l->translatedName();
		}
		else { //a language like "German Abbrevs" might be the language to set
			sword::SWLocale* locale = sword::LocaleMgr::LocaleMgr::getSystemLocaleMgr()->getLocale(
										  CBTConfig::get
											  (CBTConfig::language).local8Bit()
										  );
			if (locale) {
				currentLanguageName = TQString::fromLatin1(locale->getDescription());
			}
		}

		if (currentLanguageName.isEmpty()) { // set english as default if nothing was chosen
			//    currentLanguageName = i18n("English");
			Q_ASSERT(languageMgr()->languageForAbbrev("en_US"));
			currentLanguageName = languageMgr()->languageForAbbrev("en_US")->translatedName();
		}

		//now set the item with the right name as current item
		for (int i = 0; i < m_settings.fonts.swordLocaleCombo->count(); ++i) {
			if (currentLanguageName == m_settings.fonts.swordLocaleCombo->text(i)) {
				m_settings.fonts.swordLocaleCombo->setCurrentItem(i);
				break; //item found, finish the loop
			}
		}

		layout->addSpacing( 20 );
	}
	{ //Font settings
		layout->addWidget(
			CToolClass::explanationLabel(
				page,
				i18n("Select custom fonts per-language"),
				i18n("Here you find a list of all languages of the installed works. \
 You can specify a custom font for each language that needs a special font \
 to be displayed correctly.")
			)
		);
		layout->addSpacing(5);
		TQHBoxLayout* hLayout = new TQHBoxLayout();

		m_settings.fonts.usage = new TQComboBox(page);
		TQToolTip::add
			(m_settings.fonts.usage, CResMgr::settings::fonts::typeChooser::tooltip);


		hLayout->addWidget(m_settings.fonts.usage);

		CLanguageMgr::LangMap langMap = languageMgr()->availableLanguages();

		for ( CLanguageMgr::LangMapIterator it( langMap ); it.current(); ++it ) {
			const TQString name = it.current()->translatedName().isEmpty() ?
								 it.current()->abbrev() : it.current()->translatedName();
			m_settings.fonts.fontMap.insert(name, CBTConfig::get
												(it.current()) );
		}

		for( TQMap<TQString, CBTConfig::FontSettingsPair>::Iterator it = m_settings.fonts.fontMap.begin(); it != m_settings.fonts.fontMap.end(); ++it ) {
			if ( m_settings.fonts.fontMap[it.key()].first ) { //show font icon
				m_settings.fonts.usage->insertItem(SmallIcon("fonts"), it.key() );
			}
			else { //don't show icon for font
				m_settings.fonts.usage->insertItem(it.key());
			}
		}

		m_settings.fonts.useOwnFontBox = new TQCheckBox(i18n("Use custom font"), page, "font checkbox");
		connect(m_settings.fonts.useOwnFontBox, TQT_SIGNAL(toggled(bool)), TQT_SLOT(useOwnFontClicked(bool)));
		hLayout->addWidget(m_settings.fonts.useOwnFontBox);

		layout->addLayout(hLayout);
		//#warning TODO: remember the last selected font and jump there.

		m_settings.fonts.fontChooser = new TDEFontChooser(page, "fonts", false, TQStringList(), true, 5);
		m_settings.fonts.fontChooser->setSampleText(i18n("The quick brown fox jumps over the lazy dog."));
		layout->addWidget(m_settings.fonts.fontChooser);

		connect(m_settings.fonts.fontChooser, TQT_SIGNAL(fontSelected(const TQFont&)), TQT_SLOT(newDisplayWindowFontSelected(const TQFont&)));
		connect(m_settings.fonts.usage, TQT_SIGNAL(activated(const TQString&)), TQT_SLOT(newDisplayWindowFontAreaSelected(const TQString&)));

		m_settings.fonts.fontChooser->setFont( m_settings.fonts.fontMap[m_settings.fonts.usage->currentText()].second );
		useOwnFontClicked( m_settings.fonts.fontMap[m_settings.fonts.usage->currentText()].first );
		m_settings.fonts.useOwnFontBox->setChecked( m_settings.fonts.fontMap[m_settings.fonts.usage->currentText()].first );
		m_settings.fonts.fontChooser->setMinimumSize(m_settings.fonts.fontChooser->sizeHint());
	}
}


/** Init accel key section. */
void COptionsDialog::initAccelerators() {
	TQVBox* page = addVBoxPage(i18n("HotKeys"), TQString(), DesktopIcon(CResMgr::settings::keys::icon,32));

	CBTConfig::setupAccelSettings(
		CBTConfig::application,
		m_settings.keys.application.actionCollection
	);

	TQHBox* hbox = new TQHBox(page);
	TQLabel* label = new TQLabel(i18n("Choose type:"), hbox);
	m_settings.keys.typeChooser = new TQComboBox(hbox);
	connect(
		m_settings.keys.typeChooser, TQT_SIGNAL(activated(const TQString&)),
		TQT_SLOT(slotKeyChooserTypeChanged(const TQString&))
	);
	TQLabel* dummy = new TQLabel( hbox ); // empty label for stretch

	hbox->setStretchFactor(label, 0);
	hbox->setStretchFactor(m_settings.keys.typeChooser, 0);
	hbox->setStretchFactor(dummy, 1);

	page->setStretchFactor(hbox, 0);

	m_settings.keys.keyChooserStack = new TQWidgetStack(page);
	Q_ASSERT(m_settings.keys.keyChooserStack);

	page->setStretchFactor(m_settings.keys.keyChooserStack, 5);

	m_settings.keys.application.title = i18n("BibleTime"); //don't set the app action collection to NULL
	m_settings.keys.general = Settings::KeySettings::WindowType(i18n("All text windows"));
	m_settings.keys.bible = Settings::KeySettings::WindowType(i18n("Bible windows"));
	m_settings.keys.commentary = Settings::KeySettings::WindowType(i18n("Commentary windows"));
	m_settings.keys.lexicon = Settings::KeySettings::WindowType(i18n("Lexicon windows"));
	m_settings.keys.book = Settings::KeySettings::WindowType(i18n("Book windows"));

	m_settings.keys.typeChooser->insertItem(m_settings.keys.application.title);
	m_settings.keys.typeChooser->insertItem(m_settings.keys.general.title);
	m_settings.keys.typeChooser->insertItem(m_settings.keys.bible.title);
	m_settings.keys.typeChooser->insertItem(m_settings.keys.commentary.title);
	m_settings.keys.typeChooser->insertItem(m_settings.keys.lexicon.title);
	m_settings.keys.typeChooser->insertItem(m_settings.keys.book.title);


	Q_ASSERT(m_settings.keys.application.actionCollection);
	m_settings.keys.application.keyChooser = new KKeyChooser(
				m_settings.keys.application.actionCollection,
				m_settings.keys.keyChooserStack
			);

	// ----- All display windows ------ //
	m_settings.keys.general.actionCollection = new TDEActionCollection(this, "displayActions", 0);
	CDisplayWindow::insertKeyboardActions( m_settings.keys.general.actionCollection);
	CBTConfig::setupAccelSettings(
		CBTConfig::allWindows,
		m_settings.keys.general.actionCollection
	);
	m_settings.keys.general.keyChooser = new KKeyChooser(
											 m_settings.keys.general.actionCollection,
											 m_settings.keys.keyChooserStack
										 );

	// ----- Bible windows ------ //
	m_settings.keys.bible.actionCollection = new TDEActionCollection(this, "bibleActions", 0);
	CBibleReadWindow::insertKeyboardActions( m_settings.keys.bible.actionCollection);
	CBTConfig::setupAccelSettings(
		CBTConfig::bibleWindow,
		m_settings.keys.bible.actionCollection
	);

	// ----- Commentary windows ------ //
	m_settings.keys.commentary.actionCollection= new TDEActionCollection(this, "commentaryActions", 0);
	CCommentaryReadWindow::insertKeyboardActions( m_settings.keys.commentary.actionCollection);
	CBTConfig::setupAccelSettings(
		CBTConfig::commentaryWindow,
		m_settings.keys.commentary.actionCollection
	);

	// ----- Lexicon windows ------ //
	m_settings.keys.lexicon.actionCollection = new TDEActionCollection(this, "lexiconActions", 0);
	CLexiconReadWindow::insertKeyboardActions(  m_settings.keys.lexicon.actionCollection );
	CBTConfig::setupAccelSettings(
		CBTConfig::lexiconWindow,
		m_settings.keys.lexicon.actionCollection
	);

	// ----- Book windows ------ //
	m_settings.keys.book.actionCollection= new TDEActionCollection(this, "bookActions", 0);
	CBookReadWindow::insertKeyboardActions( m_settings.keys.book.actionCollection);
	CBTConfig::setupAccelSettings(
		CBTConfig::bookWindow,
		m_settings.keys.book.actionCollection
	);

	slotKeyChooserTypeChanged(m_settings.keys.application.title);
}

/** Init Sword section. */
void COptionsDialog::initSword() {
	TQVBox* page = addVBoxPage(i18n("Desk"),TQString(), DesktopIcon(CResMgr::settings::sword::icon,32));
	KTabCtl* tabCtl = new KTabCtl(page);

	{ //Standard works
		TQFrame* currentTab = new TQFrame(tabCtl);
		tabCtl->addTab(currentTab, i18n("Standard works"));
		TQGridLayout* gridLayout = new TQGridLayout(currentTab,10,2, 5,5); //the last row is for stretching available space
		gridLayout->setResizeMode(TQLayout::Minimum);

		gridLayout->addMultiCellWidget(
			CToolClass::explanationLabel(currentTab, i18n("Standard works"),
										 i18n("Standard works are used when no particular work is specified, \
  for example when a hyperlink into a Bible or lexicon was clicked .")),
			0,0,0,-1 /*fill the horizontal space*/
		);

		m_settings.swords.standardBible = new TQComboBox(currentTab);
		TQLabel* label = new TQLabel(m_settings.swords.standardBible, i18n("Standard Bible"), currentTab);
		label->setAutoResize(true);
		TQToolTip::add
			(m_settings.swords.standardBible, CResMgr::settings::sword::modules::bible::tooltip);

		gridLayout->addWidget(label,1,0);
		gridLayout->addWidget(m_settings.swords.standardBible,1,1);

		m_settings.swords.standardCommentary = new TQComboBox(currentTab);
		label = new TQLabel(m_settings.swords.standardCommentary, i18n("Standard Commentary"), currentTab);
		label->setAutoResize(true);
		TQToolTip::add
			(m_settings.swords.standardCommentary, CResMgr::settings::sword::modules::commentary::tooltip);

		gridLayout->addWidget(label,2,0);
		gridLayout->addWidget(m_settings.swords.standardCommentary,2,1);


		m_settings.swords.standardLexicon = new TQComboBox(currentTab);
		label = new TQLabel(m_settings.swords.standardLexicon, i18n("Standard Lexicon"), currentTab);
		label->setAutoResize(true);
		TQToolTip::add
			(m_settings.swords.standardLexicon, CResMgr::settings::sword::modules::lexicon::tooltip);

		gridLayout->addWidget(label,3,0);
		gridLayout->addWidget(m_settings.swords.standardLexicon,3,1);

		m_settings.swords.standardDailyDevotional = new TQComboBox(currentTab);
		label = new TQLabel(m_settings.swords.standardDailyDevotional, i18n("Standard Daily Devotional"), currentTab);
		label->setAutoResize(true);
		TQToolTip::add
			(m_settings.swords.standardDailyDevotional, CResMgr::settings::sword::modules::dailyDevotional::tooltip);

		gridLayout->addWidget(label,4,0);
		gridLayout->addWidget(m_settings.swords.standardDailyDevotional,4,1);

		m_settings.swords.standardHebrewStrong = new TQComboBox(currentTab);
		label = new TQLabel(m_settings.swords.standardHebrewStrong, i18n("Standard Hebrew Strong's Lexicon"), currentTab);
		label->setAutoResize(true);
		TQToolTip::add
			(m_settings.swords.standardHebrewStrong, CResMgr::settings::sword::modules::hebrewStrongs::tooltip);

		gridLayout->addWidget(label,5,0);
		gridLayout->addWidget(m_settings.swords.standardHebrewStrong,5,1);

		m_settings.swords.standardGreekStrong = new TQComboBox(currentTab);
		label = new TQLabel(m_settings.swords.standardGreekStrong, i18n("Standard Greek Strong's Lexicon"), currentTab);
		label->setAutoResize(true);
		TQToolTip::add
			(m_settings.swords.standardGreekStrong, CResMgr::settings::sword::modules::greekStrongs::tooltip);

		gridLayout->addWidget(label,6,0);
		gridLayout->addWidget(m_settings.swords.standardGreekStrong,6,1);

		m_settings.swords.standardHebrewMorph = new TQComboBox(currentTab);
		label = new TQLabel(m_settings.swords.standardHebrewMorph, i18n("Standard Hebrew Morphological Lexicon"), currentTab);
		TQToolTip::add
			(m_settings.swords.standardHebrewMorph, CResMgr::settings::sword::modules::hebrewMorph::tooltip);

		gridLayout->addWidget(label,7,0);
		gridLayout->addWidget(m_settings.swords.standardHebrewMorph,7,1);

		m_settings.swords.standardGreekMorph = new TQComboBox(currentTab);
		label = new TQLabel(m_settings.swords.standardGreekMorph, i18n("Standard Greek Morphological Lexicon"), currentTab);
		label->setAutoResize(true);
		TQToolTip::add
			(m_settings.swords.standardGreekMorph, CResMgr::settings::sword::modules::greekMorph::tooltip);

		gridLayout->addWidget(label,8,0);
		gridLayout->addWidget(m_settings.swords.standardGreekMorph,8,1);

		gridLayout->setRowStretch(9,5);

		//fill the comboboxes with the right modules
		ListCSwordModuleInfo& modules = backend()->moduleList();
		TQString modDescript;
		ListCSwordModuleInfo::iterator end_it = modules.end();
		for (ListCSwordModuleInfo::iterator it(modules.begin()); it != end_it; ++it) {
			modDescript = (*it)->config(CSwordModuleInfo::Description);

			switch ((*it)->type()) {
				case CSwordModuleInfo::Bible:
				m_settings.swords.standardBible->insertItem(modDescript);
				break;
				case CSwordModuleInfo::Commentary:
				m_settings.swords.standardCommentary->insertItem(modDescript);
				break;
				case CSwordModuleInfo::Lexicon: {
					bool inserted = false;
					if ((*it)->has(CSwordModuleInfo::HebrewDef)) {
						m_settings.swords.standardHebrewStrong->insertItem(modDescript);
						inserted = true;
					}
					if ((*it)->has(CSwordModuleInfo::GreekDef)) {
						m_settings.swords.standardGreekStrong->insertItem(modDescript);
						inserted = true;
					}
					if ((*it)->has(CSwordModuleInfo::HebrewParse)) {
						m_settings.swords.standardHebrewMorph->insertItem(modDescript);
						inserted = true;
					}
					if ((*it)->has(CSwordModuleInfo::GreekParse)) {
						m_settings.swords.standardGreekMorph->insertItem(modDescript);
						inserted = true;
					}
					if ((*it)->category() == CSwordModuleInfo::DailyDevotional) {
						m_settings.swords.standardDailyDevotional->insertItem(modDescript);
						inserted = true;
					}

					if (!inserted) {//daily dvotionals, striong lexicons etc. are not very useful for word lookups
						m_settings.swords.standardLexicon->insertItem(modDescript);
					}

					break;
				}
				default://unknown type
				break;
			}
		}

		//using two lists and one loop is better than six loops with almost the same code :)
		TQPtrList<TQComboBox> comboList;
		comboList.setAutoDelete(false);//don't delete the combos accidentally
		TQStringList moduleList;

		for (int i = 0; i <= (int)CBTConfig::lastModuleType; ++i) {
			//fill the combobox list in the right order (i.e. same order as the CBTConfig::module enum list)
			CBTConfig::modules moduleType = (CBTConfig::modules)(i);
			switch (moduleType) {
				case CBTConfig::standardBible:
				comboList.append(m_settings.swords.standardBible);
				break;
				case CBTConfig::standardCommentary:
				comboList.append(m_settings.swords.standardCommentary);
				break;
				case CBTConfig::standardLexicon:
				comboList.append(m_settings.swords.standardLexicon);
				break;
				case CBTConfig::standardDailyDevotional:
				comboList.append(m_settings.swords.standardDailyDevotional);
				break;
				case CBTConfig::standardHebrewStrongsLexicon:
				comboList.append(m_settings.swords.standardHebrewStrong);
				break;
				case CBTConfig::standardGreekStrongsLexicon:
				comboList.append(m_settings.swords.standardGreekStrong);
				break;
				case CBTConfig::standardHebrewMorphLexicon:
				comboList.append(m_settings.swords.standardHebrewMorph);
				break;
				case CBTConfig::standardGreekMorphLexicon:
				comboList.append(m_settings.swords.standardGreekMorph);
				break;
			};

			//fill the module list
			CSwordModuleInfo* const m = CBTConfig::get
											( (CBTConfig::modules)(i) );
			if (m) {
				moduleList << m->config(CSwordModuleInfo::Description);
			}
			else {
				moduleList << TQString();
			}
		}

		TQString module = TQString();
		int item = 0;
		int count = 0;
		for (TQComboBox* combo = comboList.first(); combo; combo = comboList.next() ) {
			module = moduleList[comboList.at()];
			count = combo->count();
			combo->setMaximumWidth(300);

			for (item = 0; item < count; item++) {
				if (combo->text(item) == module ) {
					combo->setCurrentItem(item);
					break;
				}
			}
		}
	}
	{ // ---------- new tab: filters -------- //
		TQFrame* currentTab = new TQFrame(tabCtl);
		tabCtl->addTab(currentTab, i18n("Text filters"));
		TQVBoxLayout* layout = new TQVBoxLayout(currentTab,5);

		layout->addWidget( CToolClass::explanationLabel(currentTab, i18n("Text filters"),
						   i18n("Filters control the appearance of text. \
Here you can specify default settings for all filters. \
You can change the filter settings in each display window, of course.")) );

		layout->addSpacing(5);

		m_settings.swords.lineBreaks = new TQCheckBox(currentTab);
		m_settings.swords.lineBreaks->setText(i18n("Insert line break after each verse"));
		m_settings.swords.lineBreaks->setChecked(CBTConfig::get
					(CBTConfig::lineBreaks));
		layout->addWidget(m_settings.swords.lineBreaks);

		m_settings.swords.verseNumbers = new TQCheckBox(currentTab);
		m_settings.swords.verseNumbers->setText(i18n("Show verse numbers"));
		m_settings.swords.verseNumbers->setChecked(CBTConfig::get
					(CBTConfig::verseNumbers));
		layout->addWidget(m_settings.swords.verseNumbers);

		m_settings.swords.headings = new TQCheckBox(currentTab);
		m_settings.swords.headings->setText(i18n("Show section headings"));
		m_settings.swords.headings->setChecked(CBTConfig::get
												   (CBTConfig::headings));
		layout->addWidget(m_settings.swords.headings);


		m_settings.swords.scriptureReferences = new TQCheckBox(currentTab);
		m_settings.swords.scriptureReferences->setText(i18n("Show scripture cross-references"));
		m_settings.swords.scriptureReferences->setChecked(CBTConfig::get
					(CBTConfig::scriptureReferences));
		layout->addWidget(m_settings.swords.scriptureReferences);

		m_settings.swords.greekAccents = new TQCheckBox(currentTab);
		m_settings.swords.greekAccents->setText(i18n("Show Greek accents"));
		m_settings.swords.greekAccents->setChecked(CBTConfig::get
					(CBTConfig::greekAccents));
		layout->addWidget(m_settings.swords.greekAccents);

		m_settings.swords.hebrewPoints = new TQCheckBox(currentTab);
		m_settings.swords.hebrewPoints->setText(i18n("Show Hebrew vowel points"));
		m_settings.swords.hebrewPoints->setChecked(CBTConfig::get
					(CBTConfig::hebrewPoints));
		layout->addWidget(m_settings.swords.hebrewPoints);

		m_settings.swords.hebrewCantillation = new TQCheckBox(currentTab);
		m_settings.swords.hebrewCantillation->setText(i18n("Show Hebrew cantillation marks"));
		m_settings.swords.hebrewCantillation->setChecked(CBTConfig::get
					(CBTConfig::hebrewCantillation));
		layout->addWidget(m_settings.swords.hebrewCantillation);

		m_settings.swords.morphSegmentation = new TQCheckBox(currentTab);
		m_settings.swords.morphSegmentation->setText(i18n("Show morph segmentation"));
		m_settings.swords.morphSegmentation->setChecked(CBTConfig::get
					(CBTConfig::morphSegmentation));
		layout->addWidget(m_settings.swords.morphSegmentation);

		m_settings.swords.textualVariants = new TQCheckBox(currentTab);
		m_settings.swords.textualVariants->setText(i18n("Use textual variants"));
		m_settings.swords.textualVariants->setChecked(CBTConfig::get
					(CBTConfig::textualVariants));
		layout->addWidget(m_settings.swords.textualVariants);

		layout->addStretch(4);
	}
}

void COptionsDialog::saveAccelerators() {
	if (m_settings.keys.general.keyChooser) {
		m_settings.keys.general.keyChooser->commitChanges();
	}

	if (m_settings.keys.bible.keyChooser) {
		m_settings.keys.bible.keyChooser->commitChanges();
	}

	if (m_settings.keys.commentary.keyChooser) {
		m_settings.keys.commentary.keyChooser->commitChanges();
	}

	if (m_settings.keys.lexicon.keyChooser) {
		m_settings.keys.lexicon.keyChooser->commitChanges();
	}

	if (m_settings.keys.book.keyChooser) {
		m_settings.keys.book.keyChooser->commitChanges();
	}

	CBTConfig::saveAccelSettings( //application
		CBTConfig::application,
		m_settings.keys.application.actionCollection
	);
	CBTConfig::saveAccelSettings( //read display windows
		CBTConfig::allWindows,
		m_settings.keys.general.actionCollection
	);
	CBTConfig::saveAccelSettings( //bible
		CBTConfig::bibleWindow,
		m_settings.keys.bible.actionCollection
	);
	CBTConfig::saveAccelSettings( //commentary
		CBTConfig::commentaryWindow,
		m_settings.keys.commentary.actionCollection
	);
	CBTConfig::saveAccelSettings( //lexicon
		CBTConfig::lexiconWindow,
		m_settings.keys.lexicon.actionCollection
	);
	CBTConfig::saveAccelSettings( //book
		CBTConfig::bookWindow,
		m_settings.keys.book.actionCollection
	);
}

/** No descriptions */
void COptionsDialog::saveLanguages() {
	for(TQMap<TQString, CBTConfig::FontSettingsPair>::Iterator it = m_settings.fonts.fontMap.begin(); it != m_settings.fonts.fontMap.end(); ++it ) {
		const CLanguageMgr::Language* const lang = languageMgr()->languageForTranslatedName(it.key());
		if (!lang->isValid()) { //we probably use a language, for which we have only the abbrev
			CLanguageMgr::Language l(it.key(), it.key(), it.key()); //create a temp language
			CBTConfig::set(&l, it.data());
		}
		else {
			CBTConfig::set(lang, it.data());
		}
	}
}

/** No descriptions */
void COptionsDialog::saveDisplay() {
	CBTConfig::set
		( CBTConfig::logo, m_settings.startup.showLogo->isChecked() );
	CBTConfig::set
		( CBTConfig::tips, m_settings.startup.showTips->isChecked() );
	CBTConfig::set
		( CBTConfig::displayStyle, m_settings.displayStyle.styleChooser->currentText() );
}

/** No descriptions */
void COptionsDialog::saveSword() {
	for (int i = 0; i <= (int)CBTConfig::lastModuleType; ++i) {
		TQString moduleDescription = TQString();

		CBTConfig::modules moduleType = (CBTConfig::modules)(i);
		switch (moduleType) {
			case CBTConfig::standardBible:
			moduleDescription = m_settings.swords.standardBible->currentText();
			break;
			case CBTConfig::standardCommentary:
			moduleDescription = m_settings.swords.standardCommentary->currentText();
			break;
			case CBTConfig::standardLexicon:
			moduleDescription = m_settings.swords.standardLexicon->currentText();
			break;
			case CBTConfig::standardDailyDevotional:
			moduleDescription = m_settings.swords.standardDailyDevotional->currentText();
			break;
			case CBTConfig::standardHebrewStrongsLexicon:
			moduleDescription = m_settings.swords.standardHebrewStrong->currentText();
			break;
			case CBTConfig::standardGreekStrongsLexicon:
			moduleDescription = m_settings.swords.standardGreekStrong->currentText();
			break;
			case CBTConfig::standardHebrewMorphLexicon:
			moduleDescription = m_settings.swords.standardHebrewMorph->currentText();
			break;
			case CBTConfig::standardGreekMorphLexicon:
			moduleDescription = m_settings.swords.standardGreekMorph->currentText();
			break;
			default:
			tqWarning("Unhandled module type.");
		};

		CSwordModuleInfo* const module = backend()->findModuleByDescription(moduleDescription);
		CBTConfig::set
			(moduleType, module);
	}


	TQString languageAbbrev;

	const TQString currentLanguageName = m_settings.fonts.swordLocaleCombo->currentText();
	const CLanguageMgr::Language* const l = CPointers::languageMgr()->languageForTranslatedName( currentLanguageName );

	if (l && l->isValid()) {
		languageAbbrev = l->abbrev();
	}
	else { //it can be the lang abbrev like de_abbrev or the Sword description
		list <sword::SWBuf> locales = sword::LocaleMgr::getSystemLocaleMgr()->getAvailableLocales();

		for (list <sword::SWBuf>::iterator it = locales.begin(); it != locales.end(); it++) {
			SWLocale* locale = LocaleMgr::getSystemLocaleMgr()->getLocale((*it).c_str());
			Q_ASSERT(locale);

			if ( locale && (TQString::fromLatin1(locale->getDescription()) == currentLanguageName) ) {
				languageAbbrev = TQString::fromLatin1(locale->getName()); //we found the abbrevation for the current language
				break;
			}
		}

		if (languageAbbrev.isEmpty()) {
			languageAbbrev = currentLanguageName; //probably a non-standard locale name like de_abbrev
		}
	}

	if (!languageAbbrev.isEmpty()) {
		CBTConfig::set
			(CBTConfig::language, languageAbbrev);
	}

	CBTConfig::set
		(CBTConfig::lineBreaks, m_settings.swords.lineBreaks->isChecked());
	CBTConfig::set
		(CBTConfig::verseNumbers, m_settings.swords.verseNumbers->isChecked());
	CBTConfig::set
		(CBTConfig::headings, m_settings.swords.headings->isChecked());
	CBTConfig::set
		(CBTConfig::scriptureReferences, m_settings.swords.scriptureReferences->isChecked());
	CBTConfig::set
		(CBTConfig::hebrewPoints, m_settings.swords.hebrewPoints->isChecked());
	CBTConfig::set
		(CBTConfig::hebrewCantillation, m_settings.swords.hebrewCantillation->isChecked());
	CBTConfig::set
		(CBTConfig::morphSegmentation, m_settings.swords.morphSegmentation->isChecked());
	CBTConfig::set
		(CBTConfig::greekAccents, m_settings.swords.greekAccents->isChecked());
	CBTConfig::set
		(CBTConfig::textualVariants, m_settings.swords.textualVariants->isChecked());
}

/** This slot is called when the "Use own font for language" bo was clicked. */
void COptionsDialog::useOwnFontClicked( bool isOn ) {
	m_settings.fonts.fontChooser->setEnabled(isOn);
	m_settings.fonts.fontMap[ m_settings.fonts.usage->currentText() ].first = isOn;

	if (isOn) { //show font icon
		m_settings.fonts.usage->changeItem(
			SmallIcon("fonts"),
			m_settings.fonts.usage->currentText(),
			m_settings.fonts.usage->currentItem()
		);
	}
	else {    //don't show
		m_settings.fonts.usage->changeItem(
			m_settings.fonts.usage->currentText(),
			m_settings.fonts.usage->currentItem()
		);
	}
}

void COptionsDialog::updateStylePreview() {
	//update the style preview widget
	using namespace Rendering;

	const TQString styleName = m_settings.displayStyle.styleChooser->currentText();

	CTextRendering::KeyTree tree;

	CTextRendering::KeyTreeItem::Settings settings;
	settings.highlight = false;

	tree.append( new CTextRendering::KeyTreeItem(
					 TQString("\n<span class=\"entryname\"><a name=\"John316\" href=\"sword://Bible/WEB/John 3:16\">16</a></span>%1")
					 .arg(i18n("For God so loved the world, that he gave his one and only Son, that whoever believes in him should not perish, but have eternal life.")),
					 settings));

	tree.append( new CTextRendering::KeyTreeItem(
					 TQString("\n<span class=\"entryname\"><a name=\"John317\" href=\"sword://Bible/WEB/John 3:17\">17</a></span>%1")
					 .arg(i18n("For God didn't send his Son into the world to judge the world, but that the world should be saved through him.")),
					 settings));

	settings.highlight = true;

	tree.append( new CTextRendering::KeyTreeItem(
					 TQString("\n<span class=\"entryname\"><a name=\"John318\" href=\"sword://Bible/WEB/John 3:18\">18</a></span>%1")
					 .arg(i18n("He who believes in him is not judged. He who doesn't believe has been judged already, because he has not believed in the name of the one and only Son of God.")),
					 settings) );

	settings.highlight = false;

	tree.append( new CTextRendering::KeyTreeItem(
					 TQString("\n<span class=\"entryname\"><a name=\"John319\" href=\"sword://Bible/WEB/John 3:19\">19</a></span>%1")
					 .arg(i18n("This is the judgment, that the light has come into the world, and men loved the darkness rather than the light; for their works were evil.")),
					 settings));

	tree.append( new CTextRendering::KeyTreeItem(
					 TQString("\n<span class=\"entryname\"><a name=\"John320\" href=\"sword://Bible/WEB/John 3:20\">20</a></span>%1<br/>")
					 .arg(i18n("For everyone who does evil hates the light, and doesn't come to the light, lest his works would be exposed.")),
					 settings));

	tree.append( new CTextRendering::KeyTreeItem(
					 TQString("\n<span class=\"entryname\"><a name=\"John321\" href=\"sword://Bible/WEB/John 3:21\">21</a></span>%1")
					 .arg(i18n("But he who does the truth comes to the light, that his works may be revealed, that they have been done in God.")),
					 settings));

	const TQString oldStyleName = CBTConfig::get
									 (CBTConfig::displayStyle);
	CBTConfig::set
		(CBTConfig::displayStyle, styleName);

	CDisplayRendering render;
	m_settings.displayStyle.stylePreview->begin();
	m_settings.displayStyle.stylePreview->write( render.renderKeyTree(tree));
	m_settings.displayStyle.stylePreview->end();

	CBTConfig::set
		(CBTConfig::displayStyle, oldStyleName);
}

void COptionsDialog::slotKeyChooserTypeChanged(const TQString& title) {
	//delete all KKeyChoosers which may not share accels, because this class checks in all instances for key conflicts
	typedef TQPtrList<KKeyChooser> KeyChooserList;
	KeyChooserList list;
	list.append(m_settings.keys.bible.keyChooser);
	list.append(m_settings.keys.commentary.keyChooser);
	list.append(m_settings.keys.lexicon.keyChooser);
	list.append(m_settings.keys.book.keyChooser);

	//commit all changes in the keychoosers
	for (KeyChooserList::iterator it(list.begin()); it != list.end(); ++it) {
		if (*it) { //the list may contain NULL pointers
			(*it)->commitChanges();
		}
	}
	/* Delete all the keychoosers in the list,
	* the keychoosers are set to NULL, because they are TQGuardedPtr
	*/
	list.setAutoDelete(true);
	list.clear();

	Settings::KeySettings::WindowType* t = 0;
	if (title == m_settings.keys.application.title) { //Application wide
		t = &m_settings.keys.application;
	}
	else if (title == m_settings.keys.general.title) { // All display windows
		t = &m_settings.keys.general;
	}
	else if (title == m_settings.keys.bible.title) { // Bible windows
		t = &m_settings.keys.bible;
	}
	else if (title == m_settings.keys.commentary.title) { // Commentary windows
		t = &m_settings.keys.commentary;
	}
	else if (title == m_settings.keys.lexicon.title) { // Lexicon windows
		t = &m_settings.keys.lexicon;
	}
	else if (title == m_settings.keys.book.title) { // Book windows
		t = &m_settings.keys.book;
	}

	Q_ASSERT(t);
	if (!t->keyChooser) { //was deleted, create a new one
		t->keyChooser = new KKeyChooser(
							m_settings.keys.keyChooserStack
						);
		t->keyChooser->insert(
			t->actionCollection,
			t->title
		);
	}

	m_settings.keys.keyChooserStack->raiseWidget(t->keyChooser);
}

#include "coptionsdialog.moc"