summaryrefslogtreecommitdiffstats
path: root/src/configdialog.cpp
blob: 6367d1bc265e245ecb1d18ce9131297fa5b4c8ec (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
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
/***************************************************************************
    copyright            : (C) 2001-2006 by Robby Stephenson
    email                : [email protected]
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of version 2 of the GNU General Public License as  *
 *   published by the Free Software Foundation;                            *
 *                                                                         *
 ***************************************************************************/

#include "configdialog.h"
#include "field.h"
#include "collection.h"
#include "collectionfactory.h"
#include "fetch/execexternalfetcher.h"
#include "fetch/fetchmanager.h"
#include "fetch/configwidget.h"
#include "controller.h"
#include "fetcherconfigdialog.h"
#include "tellico_kernel.h"
#include "latin1literal.h"
#include "tellico_utils.h"
#include "core/tellico_config.h"
#include "imagefactory.h"
#include "gui/combobox.h"
#include "gui/previewdialog.h"
#include "newstuff/dialog.h"
#include "../tellico_debug.h"

#include <klineedit.h>
#include <tdelocale.h>
#include <tdeconfig.h>
#include <kstandarddirs.h>
#include <knuminput.h>
#include <kpushbutton.h>
#include <kiconloader.h>
#include <ksortablevaluelist.h>
#include <tdeaccelmanager.h>
#include <tdehtmlview.h>
#include <tdefiledialog.h>
#include <kinputdialog.h>
#include <tdefontcombo.h>
#include <kcolorcombo.h>

#include <tqsize.h>
#include <tqlayout.h>
#include <tqlabel.h>
#include <tqcheckbox.h>
#include <tqptrlist.h>
#include <tqpixmap.h>
#include <tqgrid.h>
#include <tqwhatsthis.h>
#include <tqregexp.h>
#include <tqhgroupbox.h>
#include <tqvgroupbox.h>
#include <tqpushbutton.h>
#include <tqvbox.h>
#include <tqhbox.h>
#include <tqfileinfo.h>
#include <tqradiobutton.h>
#include <tqvbuttongroup.h>

namespace {
  static const int CONFIG_MIN_WIDTH = 640;
  static const int CONFIG_MIN_HEIGHT = 420;
}

using Tellico::SourceListViewItem;
using Tellico::ConfigDialog;

SourceListViewItem::SourceListViewItem(TDEListView* parent_, const GeneralFetcherInfo& info_,
                                       const TQString& groupName_)
    : TDEListViewItem(parent_, info_.name), m_info(info_),
      m_configGroup(groupName_), m_newSource(groupName_.isNull()), m_fetcher(0) {
  TQPixmap pix = Fetch::Manager::fetcherIcon(info_.type);
  if(!pix.isNull()) {
    setPixmap(0, pix);
  }
}

SourceListViewItem::SourceListViewItem(TDEListView* parent_, TQListViewItem* after_,
                                       const GeneralFetcherInfo& info_, const TQString& groupName_)
    : TDEListViewItem(parent_, after_, info_.name), m_info(info_),
      m_configGroup(groupName_), m_newSource(groupName_.isNull()), m_fetcher(0) {
  TQPixmap pix = Fetch::Manager::fetcherIcon(info_.type);
  if(!pix.isNull()) {
    setPixmap(0, pix);
  }
}

void SourceListViewItem::setFetcher(Fetch::Fetcher::Ptr fetcher) {
  m_fetcher = fetcher;
  TQPixmap pix = Fetch::Manager::fetcherIcon(fetcher.data());
  if(!pix.isNull()) {
    setPixmap(0, pix);
  }
}

ConfigDialog::ConfigDialog(TQWidget* parent_, const char* name_/*=0*/)
    : KDialogBase(IconList, i18n("Configure Tellico"), Help|Ok|Apply|Cancel|Default,
                  Ok, parent_, name_, true, false)
    , m_modifying(false)
    , m_okClicked(false) {
  setupGeneralPage();
  setupPrintingPage();
  setupTemplatePage();
  setupFetchPage();

  updateGeometry();
  TQSize s = sizeHint();
  resize(TQMAX(s.width(), CONFIG_MIN_WIDTH), TQMAX(s.height(), CONFIG_MIN_HEIGHT));

  // purely for asthetics make all widgets line up
  TQPtrList<TQWidget> widgets;
  widgets.append(m_fontCombo);
  widgets.append(m_fontSizeInput);
  widgets.append(m_baseColorCombo);
  widgets.append(m_textColorCombo);
  widgets.append(m_highBaseColorCombo);
  widgets.append(m_highTextColorCombo);
  int w = 0;
  for(TQPtrListIterator<TQWidget> it(widgets); it.current(); ++it) {
    it.current()->polish();
    w = TQMAX(w, it.current()->sizeHint().width());
  }
  for(TQPtrListIterator<TQWidget> it(widgets); it.current(); ++it) {
    it.current()->setMinimumWidth(w);
  }

  enableButtonOK(false);
  enableButtonApply(false);

  setHelp(TQString::fromLatin1("general-options"));
  connect(this, TQT_SIGNAL(aboutToShowPage(TQWidget*)), TQT_SLOT(slotUpdateHelpLink(TQWidget*)));
}

ConfigDialog::~ConfigDialog() {
  for(TQPtrListIterator<Fetch::ConfigWidget> it(m_newStuffConfigWidgets); it.current(); ++it) {
    it.current()->removed();
  }
}

void ConfigDialog::slotUpdateHelpLink(TQWidget* w_) {
  switch(pageIndex(w_)) {
    case 0:
      setHelp(TQString::fromLatin1("general-options"));
      break;

    case 1:
      setHelp(TQString::fromLatin1("printing-options"));
      break;

    case 2:
      setHelp(TQString::fromLatin1("template-options"));
      break;

    case 3:
      setHelp(TQString::fromLatin1("internet-sources-options"));
      break;

    default:
      break;
  }
}

void ConfigDialog::slotOk() {
  m_okClicked = true;
  slotApply();
  accept();
  m_okClicked = false;
}

void ConfigDialog::slotApply() {
  emit signalConfigChanged();
  enableButtonApply(false);
}

void ConfigDialog::slotDefault() {
  // only change the defaults on the active page
  Config::self()->useDefaults(true);
  switch(activePageIndex()) {
    case 0:
      readGeneralConfig(); break;
    case 1:
      readPrintingConfig(); break;
    case 2:
      readTemplateConfig(); break;
  }
  Config::self()->useDefaults(false);
  slotModified();
}

void ConfigDialog::setupGeneralPage() {
  TQPixmap pix = DesktopIcon(TQString::fromLatin1("tellico"), TDEIcon::SizeMedium);
  TQFrame* frame = addPage(i18n("General"), i18n("General Options"), pix);
  TQVBoxLayout* l = new TQVBoxLayout(frame, KDialog::marginHint(), KDialog::spacingHint());

  m_cbOpenLastFile = new TQCheckBox(i18n("&Reopen file at startup"), frame);
  TQWhatsThis::add(m_cbOpenLastFile, i18n("If checked, the file that was last open "
                                         "will be re-opened at program start-up."));
  l->addWidget(m_cbOpenLastFile);
  connect(m_cbOpenLastFile, TQT_SIGNAL(clicked()), TQT_SLOT(slotModified()));

  m_cbShowTipDay = new TQCheckBox(i18n("&Show \"Tip of the Day\" at startup"), frame);
  TQWhatsThis::add(m_cbShowTipDay, i18n("If checked, the \"Tip of the Day\" will be "
                                       "shown at program start-up."));
  l->addWidget(m_cbShowTipDay);
  connect(m_cbShowTipDay, TQT_SIGNAL(clicked()), TQT_SLOT(slotModified()));

  TQButtonGroup* imageGroup = new TQVButtonGroup(i18n("Image Storage Options"), frame);
  m_rbImageInFile = new TQRadioButton(i18n("Store images in data file"), imageGroup);
  m_rbImageInAppDir = new TQRadioButton(i18n("Store images in common application directory"), imageGroup);
  m_rbImageInLocalDir = new TQRadioButton(i18n("Store images in directory relative to data file"), imageGroup);
  TQWhatsThis::add(imageGroup, i18n("Images may be saved in the data file itself, which can "
                                   "cause Tellico to run slowly, stored in the Tellico "
                                   "application directory, or stored in a directory in the "
                                   "same location as the data file."));
  l->addWidget(imageGroup);
  connect(imageGroup, TQT_SIGNAL(clicked(int)), TQT_SLOT(slotModified()));

  TQVGroupBox* formatGroup = new TQVGroupBox(i18n("Formatting Options"), frame);
  l->addWidget(formatGroup);

  m_cbCapitalize = new TQCheckBox(i18n("Auto capitalize &titles and names"), formatGroup);
  TQWhatsThis::add(m_cbCapitalize, i18n("If checked, titles and names will "
                                       "be automatically capitalized."));
  connect(m_cbCapitalize, TQT_SIGNAL(clicked()), TQT_SLOT(slotModified()));

  m_cbFormat = new TQCheckBox(i18n("Auto &format titles and names"), formatGroup);
  TQWhatsThis::add(m_cbFormat, i18n("If checked, titles and names will "
                                   "be automatically formatted."));
  connect(m_cbFormat, TQT_SIGNAL(clicked()), TQT_SLOT(slotModified()));

  TQGrid* g1 = new TQGrid(2, formatGroup);
  g1->setSpacing(5);

  TQLabel* lab = new TQLabel(i18n("No capitali&zation:"), g1);
  m_leCapitals = new KLineEdit(g1);
  lab->setBuddy(m_leCapitals);
  TQString whats = i18n("<qt>A list of words which should not be capitalized. Multiple values "
                       "should be separated by a semi-colon.</qt>");
  TQWhatsThis::add(lab, whats);
  TQWhatsThis::add(m_leCapitals, whats);
  connect(m_leCapitals, TQT_SIGNAL(textChanged(const TQString&)), TQT_SLOT(slotModified()));

  lab = new TQLabel(i18n("Artic&les:"), g1);
  m_leArticles = new KLineEdit(g1);
  lab->setBuddy(m_leArticles);
  whats = i18n("<qt>A list of words which should be considered as articles "
               "if they are the first word in a title. Multiple values "
               "should be separated by a semi-colon.</qt>");
  TQWhatsThis::add(lab, whats);
  TQWhatsThis::add(m_leArticles, whats);
  connect(m_leArticles, TQT_SIGNAL(textChanged(const TQString&)), TQT_SLOT(slotModified()));

  lab = new TQLabel(i18n("Personal suffi&xes:"), g1);
  m_leSuffixes = new KLineEdit(g1);
  lab->setBuddy(m_leSuffixes);
  whats = i18n("<qt>A list of suffixes which might be used in personal names. Multiple values "
               "should be separated by a semi-colon.</qt>");
  TQWhatsThis::add(lab, whats);
  TQWhatsThis::add(m_leSuffixes, whats);
  connect(m_leSuffixes, TQT_SIGNAL(textChanged(const TQString&)), TQT_SLOT(slotModified()));

  lab = new TQLabel(i18n("Surname &prefixes:"), g1);
  m_lePrefixes = new KLineEdit(g1);
  lab->setBuddy(m_lePrefixes);
  whats = i18n("<qt>A list of prefixes which might be used in surnames. Multiple values "
               "should be separated by a semi-colon.</qt>");
  TQWhatsThis::add(lab, whats);
  TQWhatsThis::add(m_lePrefixes, whats);
  connect(m_lePrefixes, TQT_SIGNAL(textChanged(const TQString&)), TQT_SLOT(slotModified()));

  // stretch to fill lower area
  l->addStretch(1);
}

void ConfigDialog::setupPrintingPage() {
  // SuSE changed the icon name on me
  TQPixmap pix;
  TDEIconLoader* loader = TDEGlobal::iconLoader();
  if(loader) {
    pix = loader->loadIcon(TQString::fromLatin1("printer1"), TDEIcon::Desktop, TDEIcon::SizeMedium,
                           TDEIcon::DefaultState, 0, true /*canReturnNull */);
    if(pix.isNull()) {
      pix = loader->loadIcon(TQString::fromLatin1("printer2"), TDEIcon::Desktop, TDEIcon::SizeMedium,
                             TDEIcon::DefaultState, 0, true /*canReturnNull */);
    }
    if(pix.isNull()) {
      pix = loader->loadIcon(TQString::fromLatin1("print_printer"), TDEIcon::Desktop, TDEIcon::SizeMedium);
    }
  }
  TQFrame* frame = addPage(i18n("Printing"), i18n("Printing Options"), pix);
  TQVBoxLayout* l = new TQVBoxLayout(frame, KDialog::marginHint(), KDialog::spacingHint());

  TQVGroupBox* formatOptions = new TQVGroupBox(i18n("Formatting Options"), frame);
  l->addWidget(formatOptions);

  m_cbPrintFormatted = new TQCheckBox(i18n("&Format titles and names"), formatOptions);
  TQWhatsThis::add(m_cbPrintFormatted, i18n("If checked, titles and names will be automatically formatted."));
  connect(m_cbPrintFormatted, TQT_SIGNAL(clicked()), TQT_SLOT(slotModified()));

  m_cbPrintHeaders = new TQCheckBox(i18n("&Print field headers"), formatOptions);
  TQWhatsThis::add(m_cbPrintHeaders, i18n("If checked, the field names will be printed as table headers."));
  connect(m_cbPrintHeaders, TQT_SIGNAL(clicked()), TQT_SLOT(slotModified()));

  TQHGroupBox* groupOptions = new TQHGroupBox(i18n("Grouping Options"), frame);
  l->addWidget(groupOptions);

  m_cbPrintGrouped = new TQCheckBox(i18n("&Group the entries"), groupOptions);
  TQWhatsThis::add(m_cbPrintGrouped, i18n("If checked, the entries will be grouped by the selected field."));
  connect(m_cbPrintGrouped, TQT_SIGNAL(clicked()), TQT_SLOT(slotModified()));

  TQVGroupBox* imageOptions = new TQVGroupBox(i18n("Image Options"), frame);
  l->addWidget(imageOptions);

  TQGrid* grid = new TQGrid(3, imageOptions);
  grid->setSpacing(5);

  TQLabel* lab = new TQLabel(i18n("Maximum image &width:"), grid);
  m_imageWidthBox = new KIntSpinBox(0, 999, 1, 50, 10, grid);
  m_imageWidthBox->setSuffix(TQString::fromLatin1(" px"));
  lab->setBuddy(m_imageWidthBox);
  (void) new TQWidget(grid);
  TQString whats = i18n("The maximum width of the images in the printout. The aspect ration is preserved.");
  TQWhatsThis::add(lab, whats);
  TQWhatsThis::add(m_imageWidthBox, whats);
  connect(m_imageWidthBox, TQT_SIGNAL(valueChanged(int)), TQT_SLOT(slotModified()));
  // TQSpinBox doesn't emit valueChanged if you edit the value with
  // the lineEdit until you change the keyboard focus
  connect(m_imageWidthBox->child("qt_spinbox_edit"), TQT_SIGNAL(textChanged(const TQString&)), TQT_SLOT(slotModified()));

  lab = new TQLabel(i18n("&Maximum image height:"), grid);
  m_imageHeightBox = new KIntSpinBox(0, 999, 1, 50, 10, grid);
  m_imageHeightBox->setSuffix(TQString::fromLatin1(" px"));
  lab->setBuddy(m_imageHeightBox);
  (void) new TQWidget(grid);
  whats = i18n("The maximum height of the images in the printout. The aspect ration is preserved.");
  TQWhatsThis::add(lab, whats);
  TQWhatsThis::add(m_imageHeightBox, whats);
  connect(m_imageHeightBox, TQT_SIGNAL(valueChanged(int)), TQT_SLOT(slotModified()));
  // TQSpinBox doesn't emit valueChanged if you edit the value with
  // the lineEdit until you change the keyboard focus
  connect(m_imageHeightBox->child("qt_spinbox_edit"), TQT_SIGNAL(textChanged(const TQString&)), TQT_SLOT(slotModified()));

  // stretch to fill lower area
  l->addStretch(1);
}

void ConfigDialog::setupTemplatePage() {
  TQPixmap pix = DesktopIcon(TQString::fromLatin1("looknfeel"), TDEIcon::SizeMedium);
  TQFrame* frame = addPage(i18n("Templates"), i18n("Template Options"), pix);
  TQVBoxLayout* l = new TQVBoxLayout(frame, KDialog::marginHint(), KDialog::spacingHint());

  TQGridLayout* gridLayout = new TQGridLayout(l);
  gridLayout->setSpacing(KDialogBase::spacingHint());

  int row = -1;
  // so I can reuse an i18n string, a plain label can't have an '&'
  TQLabel* lab = new TQLabel(i18n("Collection &type:").remove('&'), frame);
  gridLayout->addWidget(lab, ++row, 0);
  const int collType = Kernel::self()->collectionType();
  lab = new TQLabel(CollectionFactory::nameMap()[collType], frame);
  gridLayout->addMultiCellWidget(lab, row, row, 1, 2);

  lab = new TQLabel(i18n("Template:"), frame);
  m_templateCombo = new GUI::ComboBox(frame);
  connect(m_templateCombo, TQT_SIGNAL(activated(int)), TQT_SLOT(slotModified()));
  lab->setBuddy(m_templateCombo);
  TQString whats = i18n("Select the template to use for the current type of collections. "
                       "Not all templates will use the font and color settings.");
  TQWhatsThis::add(lab, whats);
  TQWhatsThis::add(m_templateCombo, whats);
  gridLayout->addWidget(lab, ++row, 0);
  gridLayout->addWidget(m_templateCombo, row, 1);

  KPushButton* btn = new KPushButton(i18n("&Preview..."), frame);
  TQWhatsThis::add(btn, i18n("Show a preview of the template"));
  btn->setIconSet(SmallIconSet(TQString::fromLatin1("viewmag")));
  gridLayout->addWidget(btn, row, 2);
  connect(btn, TQT_SIGNAL(clicked()), TQT_SLOT(slotShowTemplatePreview()));

  // so the button is squeezed small
  gridLayout->setColStretch(0, 10);
  gridLayout->setColStretch(1, 10);

  loadTemplateList();

//  TQLabel* l1 = new TQLabel(i18n("The options below will be passed to the template, but not "
//                               "all templates will use them. Some fonts and colors may be "
//                               "specified directly in the template."), frame);
//  l1->setTextFormat(TQt::RichText);
//  l->addWidget(l1);

  TQGroupBox* fontGroup = new TQGroupBox(0, Qt::Vertical, i18n("Font Options"), frame);
  l->addWidget(fontGroup);

  row = -1;
  TQGridLayout* fontLayout = new TQGridLayout(fontGroup->layout());
  fontLayout->setSpacing(KDialogBase::spacingHint());

  lab = new TQLabel(i18n("Font:"), fontGroup);
  fontLayout->addWidget(lab, ++row, 0);
  m_fontCombo = new TDEFontCombo(fontGroup);
  fontLayout->addWidget(m_fontCombo, row, 1);
  connect(m_fontCombo, TQT_SIGNAL(activated(int)), TQT_SLOT(slotModified()));
  lab->setBuddy(m_fontCombo);
  whats = i18n("This font is passed to the template used in the Entry View.");
  TQWhatsThis::add(lab, whats);
  TQWhatsThis::add(m_fontCombo, whats);

  fontLayout->addWidget(new TQLabel(i18n("Size:"), fontGroup), ++row, 0);
  m_fontSizeInput = new KIntNumInput(fontGroup);
  m_fontSizeInput->setRange(5, 30); // 30 is same max as konq config
  m_fontSizeInput->setSuffix(TQString::fromLatin1("pt"));
  fontLayout->addWidget(m_fontSizeInput, row, 1);
  connect(m_fontSizeInput, TQT_SIGNAL(valueChanged(int)), TQT_SLOT(slotModified()));
  lab->setBuddy(m_fontSizeInput);
  TQWhatsThis::add(lab, whats);
  TQWhatsThis::add(m_fontSizeInput, whats);

  TQGroupBox* colGroup = new TQGroupBox(0, Qt::Vertical, i18n("Color Options"), frame);
  l->addWidget(colGroup);

  row = -1;
  TQGridLayout* colLayout = new TQGridLayout(colGroup->layout());
  colLayout->setSpacing(KDialogBase::spacingHint());

  lab = new TQLabel(i18n("Background color:"), colGroup);
  colLayout->addWidget(lab, ++row, 0);
  m_baseColorCombo = new KColorCombo(colGroup);
  colLayout->addWidget(m_baseColorCombo, row, 1);
  connect(m_baseColorCombo, TQT_SIGNAL(activated(int)), TQT_SLOT(slotModified()));
  lab->setBuddy(m_baseColorCombo);
  whats = i18n("This color is passed to the template used in the Entry View.");
  TQWhatsThis::add(lab, whats);
  TQWhatsThis::add(m_baseColorCombo, whats);

  lab = new TQLabel(i18n("Text color:"), colGroup);
  colLayout->addWidget(lab, ++row, 0);
  m_textColorCombo = new KColorCombo(colGroup);
  colLayout->addWidget(m_textColorCombo, row, 1);
  connect(m_textColorCombo, TQT_SIGNAL(activated(int)), TQT_SLOT(slotModified()));
  lab->setBuddy(m_textColorCombo);
  TQWhatsThis::add(lab, whats);
  TQWhatsThis::add(m_textColorCombo, whats);

  lab = new TQLabel(i18n("Highlight color:"), colGroup);
  colLayout->addWidget(lab, ++row, 0);
  m_highBaseColorCombo = new KColorCombo(colGroup);
  colLayout->addWidget(m_highBaseColorCombo, row, 1);
  connect(m_highBaseColorCombo, TQT_SIGNAL(activated(int)), TQT_SLOT(slotModified()));
  lab->setBuddy(m_highBaseColorCombo);
  TQWhatsThis::add(lab, whats);
  TQWhatsThis::add(m_highBaseColorCombo, whats);

  lab = new TQLabel(i18n("Highlighted text color:"), colGroup);
  colLayout->addWidget(lab, ++row, 0);
  m_highTextColorCombo = new KColorCombo(colGroup);
  colLayout->addWidget(m_highTextColorCombo, row, 1);
  connect(m_highTextColorCombo, TQT_SIGNAL(activated(int)), TQT_SLOT(slotModified()));
  lab->setBuddy(m_highTextColorCombo);
  TQWhatsThis::add(lab, whats);
  TQWhatsThis::add(m_highTextColorCombo, whats);

  TQVGroupBox* groupBox = new TQVGroupBox(i18n("Manage Templates"), frame);
  l->addWidget(groupBox);

  TQHBox* box1 = new TQHBox(groupBox);
  box1->setSpacing(KDialog::spacingHint());

  KPushButton* b1 = new KPushButton(i18n("Install..."), box1);
  b1->setIconSet(SmallIconSet(TQString::fromLatin1("add")));
  connect(b1, TQT_SIGNAL(clicked()), TQT_SLOT(slotInstallTemplate()));
  whats = i18n("Click to install a new template directly.");
  TQWhatsThis::add(b1, whats);

  KPushButton* b2 = new KPushButton(i18n("Download..."), box1);
  b2->setIconSet(SmallIconSet(TQString::fromLatin1("knewstuff")));
  connect(b2, TQT_SIGNAL(clicked()), TQT_SLOT(slotDownloadTemplate()));
  whats = i18n("Click to download additional templates via the Internet.");
  TQWhatsThis::add(b2, whats);

  KPushButton* b3 = new KPushButton(i18n("Delete..."), box1);
  b3->setIconSet(SmallIconSet(TQString::fromLatin1("remove")));
  connect(b3, TQT_SIGNAL(clicked()), TQT_SLOT(slotDeleteTemplate()));
  whats = i18n("Click to select and remove installed templates.");
  TQWhatsThis::add(b3, whats);

  // stretch to fill lower area
  l->addStretch(1);

  TDEAcceleratorManager::manage(frame);
}

void ConfigDialog::setupFetchPage() {
  TQPixmap pix = DesktopIcon(TQString::fromLatin1("network"), TDEIcon::SizeMedium);
  TQFrame* frame = addPage(i18n("Data Sources"), i18n("Data Source Options"), pix);
  TQHBoxLayout* l = new TQHBoxLayout(frame, KDialog::marginHint(), KDialog::spacingHint());

  TQVBoxLayout* leftLayout = new TQVBoxLayout(l);
  m_sourceListView = new TDEListView(frame);
  m_sourceListView->addColumn(i18n("Source"));
  m_sourceListView->setResizeMode(TQListView::LastColumn);
  m_sourceListView->setSorting(-1); // no sorting
  m_sourceListView->setSelectionMode(TQListView::Single);
  leftLayout->addWidget(m_sourceListView, 1);
  connect(m_sourceListView, TQT_SIGNAL(selectionChanged(TQListViewItem*)), TQT_SLOT(slotSelectedSourceChanged(TQListViewItem*)));
  connect(m_sourceListView, TQT_SIGNAL(doubleClicked(TQListViewItem*, const TQPoint&, int)), TQT_SLOT(slotModifySourceClicked()));

  TQHBox* hb = new TQHBox(frame);
  leftLayout->addWidget(hb);
  hb->setSpacing(KDialog::spacingHint());
  m_moveUpSourceBtn = new KPushButton(i18n("Move &Up"), hb);
  m_moveUpSourceBtn->setIconSet(SmallIconSet(TQString::fromLatin1("up")));
  TQWhatsThis::add(m_moveUpSourceBtn, i18n("The order of the data sources sets the order "
                                          "that Tellico uses when entries are automatically updated."));
  m_moveDownSourceBtn = new KPushButton(i18n("Move &Down"), hb);
  m_moveDownSourceBtn->setIconSet(SmallIconSet(TQString::fromLatin1("down")));
  TQWhatsThis::add(m_moveDownSourceBtn, i18n("The order of the data sources sets the order "
                                            "that Tellico uses when entries are automatically updated."));

  // these icons are rather arbitrary, but seem to vaguely fit
  TQVBoxLayout* vlay = new TQVBoxLayout(l);
  KPushButton* newSourceBtn = new KPushButton(i18n("&New..."), frame);
  newSourceBtn->setIconSet(SmallIconSet(TQString::fromLatin1("filenew")));
  TQWhatsThis::add(newSourceBtn, i18n("Click to add a new data source."));
  m_modifySourceBtn = new KPushButton(i18n("&Modify..."), frame);
  m_modifySourceBtn->setIconSet(SmallIconSet(TQString::fromLatin1("network")));
  TQWhatsThis::add(m_modifySourceBtn, i18n("Click to modify the selected data source."));
  m_removeSourceBtn = new KPushButton(i18n("&Delete"), frame);
  m_removeSourceBtn->setIconSet(SmallIconSet(TQString::fromLatin1("remove")));
  TQWhatsThis::add(m_removeSourceBtn, i18n("Click to delete the selected data source."));
  m_newStuffBtn = new KPushButton(i18n("Download..."), frame);
  m_newStuffBtn->setIconSet(SmallIconSet(TQString::fromLatin1("knewstuff")));
  TQWhatsThis::add(m_newStuffBtn, i18n("Click to download additional data sources via the Internet."));

#if !KDE_IS_VERSION(3,3,90)
  // only available in KDE 3.4 and up
  m_newStuffBtn->setEnabled(false);
#endif

  vlay->addWidget(newSourceBtn);
  vlay->addWidget(m_modifySourceBtn);
  vlay->addWidget(m_removeSourceBtn);
  // separate newstuff button from the rest
  vlay->addSpacing(2 * KDialog::spacingHint());
  vlay->addWidget(m_newStuffBtn);
  vlay->addStretch(1);

  connect(newSourceBtn, TQT_SIGNAL(clicked()), TQT_SLOT(slotNewSourceClicked()));
  connect(m_modifySourceBtn, TQT_SIGNAL(clicked()), TQT_SLOT(slotModifySourceClicked()));
  connect(m_moveUpSourceBtn, TQT_SIGNAL(clicked()), TQT_SLOT(slotMoveUpSourceClicked()));
  connect(m_moveDownSourceBtn, TQT_SIGNAL(clicked()), TQT_SLOT(slotMoveDownSourceClicked()));
  connect(m_removeSourceBtn, TQT_SIGNAL(clicked()), TQT_SLOT(slotRemoveSourceClicked()));
  connect(m_newStuffBtn, TQT_SIGNAL(clicked()), TQT_SLOT(slotNewStuffClicked()));

  TDEAcceleratorManager::manage(frame);
}

void ConfigDialog::readConfiguration() {
  m_modifying = true;

  readGeneralConfig();
  readPrintingConfig();
  readTemplateConfig();
  readFetchConfig();

  m_modifying = false;
}

void ConfigDialog::readGeneralConfig() {
  m_cbShowTipDay->setChecked(Config::showTipOfDay());
  m_cbOpenLastFile->setChecked(Config::reopenLastFile());
  switch(Config::imageLocation()) {
    case Config::ImagesInFile: m_rbImageInFile->setChecked(true); break;
    case Config::ImagesInAppDir: m_rbImageInAppDir->setChecked(true); break;
    case Config::ImagesInLocalDir: m_rbImageInLocalDir->setChecked(true); break;
  }

  bool autoCapitals = Config::autoCapitalization();
  m_cbCapitalize->setChecked(autoCapitals);

  bool autoFormat = Config::autoFormat();
  m_cbFormat->setChecked(autoFormat);

  const TQRegExp comma(TQString::fromLatin1("\\s*,\\s*"));
  const TQString semicolon = TQString::fromLatin1("; ");

  m_leCapitals->setText(Config::noCapitalizationString().replace(comma, semicolon));
  m_leArticles->setText(Config::articlesString().replace(comma, semicolon));
  m_leSuffixes->setText(Config::nameSuffixesString().replace(comma, semicolon));
  m_lePrefixes->setText(Config::surnamePrefixesString().replace(comma, semicolon));
}

void ConfigDialog::readPrintingConfig() {
  m_cbPrintHeaders->setChecked(Config::printFieldHeaders());
  m_cbPrintFormatted->setChecked(Config::printFormatted());
  m_cbPrintGrouped->setChecked(Config::printGrouped());
  m_imageWidthBox->setValue(Config::maxImageWidth());
  m_imageHeightBox->setValue(Config::maxImageHeight());
}

void ConfigDialog::readTemplateConfig() {
  // entry template selection
  const int collType = Kernel::self()->collectionType();
  TQString file = Config::templateName(collType);
  file.replace('_', ' ');
  TQString fileContext = file + TQString::fromLatin1(" XSL Template");
  m_templateCombo->setCurrentItem(i18n(fileContext.utf8(), file.utf8()));

  m_fontCombo->setCurrentFont(Config::templateFont(collType).family());
  m_fontSizeInput->setValue(Config::templateFont(collType).pointSize());
  m_baseColorCombo->setColor(Config::templateBaseColor(collType));
  m_textColorCombo->setColor(Config::templateTextColor(collType));
  m_highBaseColorCombo->setColor(Config::templateHighlightedBaseColor(collType));
  m_highTextColorCombo->setColor(Config::templateHighlightedTextColor(collType));
}

void ConfigDialog::readFetchConfig() {
  m_sourceListView->clear();
  m_configWidgets.clear();

  Fetch::FetcherVec fetchers = Fetch::Manager::self()->fetchers();
  for(Fetch::FetcherVec::Iterator it = fetchers.begin(); it != fetchers.end(); ++it) {
    GeneralFetcherInfo info(it->type(), it->source(), it->updateOverwrite());
    SourceListViewItem* item = new SourceListViewItem(m_sourceListView, m_sourceListView->lastItem(), info);
    item->setFetcher(it.data());
    // grab the config widget, taking ownership
    Fetch::ConfigWidget* cw = it->configWidget(this);
    if(cw) { // might return 0 when no widget available for fetcher type
      m_configWidgets.insert(item, cw);
      // there's weird layout bug if it's not hidden
      cw->hide();
    }
    kapp->processEvents();
  }

  if(m_sourceListView->childCount() == 0) {
    m_modifySourceBtn->setEnabled(false);
    m_removeSourceBtn->setEnabled(false);
  } else {
    // go ahead and select the first one
    m_sourceListView->setSelected(m_sourceListView->firstChild(), true);
  }
}

void ConfigDialog::saveConfiguration() {
  Config::setShowTipOfDay(m_cbShowTipDay->isChecked());

  int imageLocation;
  if(m_rbImageInFile->isChecked()) {
    imageLocation = Config::ImagesInFile;
  } else if(m_rbImageInAppDir->isChecked()) {
    imageLocation = Config::ImagesInAppDir;
  } else {
    imageLocation = Config::ImagesInLocalDir;
  }
  Config::setImageLocation(imageLocation);
  Config::setReopenLastFile(m_cbOpenLastFile->isChecked());

  Config::setAutoCapitalization(m_cbCapitalize->isChecked());
  Config::setAutoFormat(m_cbFormat->isChecked());

  const TQRegExp semicolon(TQString::fromLatin1("\\s*;\\s*"));
  const TQChar comma = ',';

  Config::setNoCapitalizationString(m_leCapitals->text().replace(semicolon, comma));
  Config::setArticlesString(m_leArticles->text().replace(semicolon, comma));
  Data::Field::articlesUpdated();
  Config::setNameSuffixesString(m_leSuffixes->text().replace(semicolon, comma));
  Config::setSurnamePrefixesString(m_lePrefixes->text().replace(semicolon, comma));

  Config::setPrintFieldHeaders(m_cbPrintHeaders->isChecked());
  Config::setPrintFormatted(m_cbPrintFormatted->isChecked());
  Config::setPrintGrouped(m_cbPrintGrouped->isChecked());
  Config::setMaxImageWidth(m_imageWidthBox->value());
  Config::setMaxImageHeight(m_imageHeightBox->value());

  // entry template selection
  const int collType = Kernel::self()->collectionType();
  Config::setTemplateName(collType, m_templateCombo->currentData().toString());
  TQFont font(m_fontCombo->currentFont(), m_fontSizeInput->value());
  Config::setTemplateFont(collType, font);
  Config::setTemplateBaseColor(collType, m_baseColorCombo->color());
  Config::setTemplateTextColor(collType, m_textColorCombo->color());
  Config::setTemplateHighlightedBaseColor(collType, m_highBaseColorCombo->color());
  Config::setTemplateHighlightedTextColor(collType, m_highTextColorCombo->color());

  // first, tell config widgets they got deleted
  for(TQPtrListIterator<Fetch::ConfigWidget> it(m_removedConfigWidgets); it.current(); ++it) {
    it.current()->removed();
  }
  m_removedConfigWidgets.clear();

  TDEConfig* masterConfig = TDEGlobal::config();

  bool reloadFetchers = false;
  int count = 0; // start group numbering at 0
  for(TQListViewItemIterator it(m_sourceListView); it.current(); ++it, ++count) {
    SourceListViewItem* item = static_cast<SourceListViewItem*>(it.current());
    Fetch::ConfigWidget* cw = m_configWidgets[item];
    if(!cw || (!cw->shouldSave() && !item->isNewSource())) {
      continue;
    }
    m_newStuffConfigWidgets.removeRef(cw);
    TQString group = TQString::fromLatin1("Data Source %1").arg(count);
    // in case we later change the order, clear the group now
    masterConfig->deleteGroup(group);
    TDEConfigGroup configGroup(masterConfig, group);
    configGroup.writeEntry("Name", item->text(0));
    configGroup.writeEntry("Type", item->fetchType());
    configGroup.writeEntry("UpdateOverwrite", item->updateOverwrite());
    cw->saveConfig(configGroup);
    item->setNewSource(false);
    // in case the ordering changed
    item->setConfigGroup(group);
    reloadFetchers = true;
  }
  // now update total number of sources
  TDEConfigGroup sourceGroup(masterConfig, "Data Sources");
  sourceGroup.writeEntry("Sources Count", count);
  // and purge old config groups
  TQString group = TQString::fromLatin1("Data Source %1").arg(count);
  while(masterConfig->hasGroup(group)) {
    masterConfig->deleteGroup(group);
    ++count;
    group = TQString::fromLatin1("Data Source %1").arg(count);
  }

  masterConfig->sync();
  Config::writeConfig();

  TQString s = m_sourceListView->selectedItem() ? m_sourceListView->selectedItem()->text(0) : TQString();
  if(reloadFetchers) {
    Fetch::Manager::self()->loadFetchers();
    Controller::self()->updatedFetchers();
    // reload fetcher items if OK was not clicked
    // meaning apply was clicked
    if(!m_okClicked) {
      readFetchConfig();
      if(!s.isEmpty()) {
        for(TQListViewItemIterator it(m_sourceListView); it.current(); ++it) {
          if(it.current()->text(0) == s) {
            m_sourceListView->setSelected(it.current(), true);
            m_sourceListView->ensureItemVisible(it.current());
            break;
          }
        }
      }
    }
  }
}

void ConfigDialog::slotModified() {
  if(m_modifying) {
    return;
  }
  enableButtonOK(true);
  enableButtonApply(true);
}

void ConfigDialog::slotNewSourceClicked() {
  FetcherConfigDialog dlg(this);
  if(dlg.exec() != TQDialog::Accepted) {
    return;
  }

  Fetch::Type type = dlg.sourceType();
  if(type == Fetch::Unknown) {
    return;
  }

  GeneralFetcherInfo info(type, dlg.sourceName(), dlg.updateOverwrite());
  SourceListViewItem* item = new SourceListViewItem(m_sourceListView, m_sourceListView->lastItem(), info);
  m_sourceListView->ensureItemVisible(item);
  m_sourceListView->setSelected(item, true);
  Fetch::ConfigWidget* cw = dlg.configWidget();
  if(cw) {
    cw->setAccepted(true);
    cw->slotSetModified();
    cw->reparent(this, TQPoint()); // keep the config widget around
    m_configWidgets.insert(item, cw);
  }
  m_modifySourceBtn->setEnabled(true);
  m_removeSourceBtn->setEnabled(true);
  slotModified(); // toggle apply button
}

void ConfigDialog::slotModifySourceClicked() {
  SourceListViewItem* item = static_cast<SourceListViewItem*>(m_sourceListView->selectedItem());
  if(!item) {
    return;
  }

  Fetch::ConfigWidget* cw = 0;
  if(m_configWidgets.contains(item)) {
    cw = m_configWidgets[item];
  }
  if(!cw) {
    // no config widget for this one
    // might be because support was compiled out
    myDebug() << "ConfigDialog::slotModifySourceClicked() - no config widget for source " << item->text(0) << endl;
    return;
  }
  FetcherConfigDialog dlg(item->text(0), item->fetchType(), item->updateOverwrite(), cw, this);

  if(dlg.exec() == TQDialog::Accepted) {
    cw->setAccepted(true); // mark to save
    TQString newName = dlg.sourceName();
    if(newName != item->text(0)) {
      item->setText(0, newName);
      cw->slotSetModified();
    }
    item->setUpdateOverwrite(dlg.updateOverwrite());
    slotModified(); // toggle apply button
  }
  cw->reparent(this, TQPoint()); // keep the config widget around
}

void ConfigDialog::slotRemoveSourceClicked() {
  SourceListViewItem* item = static_cast<SourceListViewItem*>(m_sourceListView->selectedItem());
  if(!item) {
    return;
  }

  Fetch::ConfigWidget* cw = m_configWidgets[item];
  if(cw) {
    m_removedConfigWidgets.append(cw);
    // it gets deleted by the parent
  }
  m_configWidgets.remove(item);
  delete item;
  m_sourceListView->setSelected(m_sourceListView->currentItem(), true);
  slotModified(); // toggle apply button
}

void ConfigDialog::slotMoveUpSourceClicked() {
  TQListViewItem* item = m_sourceListView->selectedItem();
  if(!item) {
    return;
  }
  SourceListViewItem* prev = static_cast<SourceListViewItem*>(item->itemAbove()); // could be 0
  if(prev) {
    GeneralFetcherInfo info(prev->fetchType(), prev->text(0), prev->updateOverwrite());
    SourceListViewItem* newItem = new SourceListViewItem(m_sourceListView, item, info, prev->configGroup());
    newItem->setFetcher(prev->fetcher());
    Fetch::ConfigWidget* cw = m_configWidgets[prev];
    m_configWidgets.remove(prev);
    m_configWidgets.insert(newItem, cw);
    delete prev;
    slotModified(); // toggle apply button
    slotSelectedSourceChanged(item);
  }
}

void ConfigDialog::slotMoveDownSourceClicked() {
  SourceListViewItem* item = static_cast<SourceListViewItem*>(m_sourceListView->selectedItem());
  if(!item) {
    return;
  }
  TQListViewItem* next = item->nextSibling(); // could be 0
  if(next) {
    GeneralFetcherInfo info(item->fetchType(), item->text(0), item->updateOverwrite());
    SourceListViewItem* newItem = new SourceListViewItem(m_sourceListView, next, info, item->configGroup());
    newItem->setFetcher(item->fetcher());
    Fetch::ConfigWidget* cw = m_configWidgets[item];
    m_configWidgets.remove(item);
    m_configWidgets.insert(newItem, cw);
    delete item;
    slotModified(); // toggle apply button
    m_sourceListView->setSelected(newItem, true);
  }
}

void ConfigDialog::slotSelectedSourceChanged(TQListViewItem* item_) {
  m_moveUpSourceBtn->setEnabled(item_ && item_->itemAbove());
  m_moveDownSourceBtn->setEnabled(item_ && item_->nextSibling());
}

void ConfigDialog::slotNewStuffClicked() {
  NewStuff::Dialog dlg(NewStuff::DataScript, this);
  dlg.exec();

  TQPtrList<NewStuff::DataSourceInfo> infoList = dlg.dataSourceInfo();
  for(TQPtrListIterator<NewStuff::DataSourceInfo> it(infoList); it.current(); ++it) {
    const NewStuff::DataSourceInfo& info = *it.current();
    Fetch::ExecExternalFetcher::ConfigWidget* cw = 0;
    SourceListViewItem* item = 0;

    // yes, this is checking if item exists
    if(info.isUpdate && (item = findItem(info.sourceExec))) {
      m_sourceListView->setSelected(item, true);
      cw = dynamic_cast<Fetch::ExecExternalFetcher::ConfigWidget*>(m_configWidgets[item]);
    } else {
      cw = new Fetch::ExecExternalFetcher::ConfigWidget(this);
      m_newStuffConfigWidgets.append(cw);

      GeneralFetcherInfo fetchInfo(Fetch::ExecExternal, info.sourceName, false);
      item = new SourceListViewItem(m_sourceListView, m_sourceListView->lastItem(), fetchInfo);
      m_configWidgets.insert(item, cw);
    }

    if(!cw) {
      continue;
    }

    TDEConfig spec(info.specFile, false, false);
    cw->readConfig(&spec);
    cw->slotSetModified();
    cw->setAccepted(true);

    if(item) {
      m_sourceListView->setSelected(item, true);
      m_sourceListView->ensureItemVisible(item);
    }
  }

  if(infoList.count() > 0) {
    m_modifySourceBtn->setEnabled(true);
    m_removeSourceBtn->setEnabled(true);
    slotModified(); // toggle apply button
  }
}

Tellico::SourceListViewItem* ConfigDialog::findItem(const TQString& path_) const {
  if(path_.isEmpty()) {
    kdWarning() << "ConfigDialog::findItem() - empty path" << endl;
    return 0;
  }

  // this is a bit ugly, loop over all items, find the execexternal one
  // that matches the path
  for(TQListViewItemIterator it(m_sourceListView); it.current(); ++it) {
    SourceListViewItem* item = static_cast<SourceListViewItem*>(it.current());
    if(item->fetchType() != Fetch::ExecExternal) {
      continue;
    }
    Fetch::ExecExternalFetcher* f = dynamic_cast<Fetch::ExecExternalFetcher*>(item->fetcher().data());
    if(f && f->execPath() == path_) {
      return item;
    }
  }
  myDebug() << "ConfigDialog::findItem() - no matching item found" << endl;
  return 0;
}

void ConfigDialog::slotShowTemplatePreview() {
  GUI::PreviewDialog* dlg = new GUI::PreviewDialog(this);

  const TQString templateName = m_templateCombo->currentData().toString();
  dlg->setXSLTFile(templateName + TQString::fromLatin1(".xsl"));

  StyleOptions options;
  options.fontFamily = m_fontCombo->currentFont();
  options.fontSize   = m_fontSizeInput->value();
  options.baseColor  = m_baseColorCombo->color();
  options.textColor  = m_textColorCombo->color();
  options.highlightedTextColor = m_highTextColorCombo->color();
  options.highlightedBaseColor = m_highBaseColorCombo->color();
  dlg->setXSLTOptions(options);

  Data::CollPtr c = CollectionFactory::collection(Kernel::self()->collectionType(), true);
  Data::EntryPtr e = new Data::Entry(c);
  for(Data::FieldVec::ConstIterator f = c->fields().begin(); f != c->fields().end(); ++f) {
    if(f->name() == Latin1Literal("title")) {
      e->setField(f->name(), m_templateCombo->currentText());
    } else if(f->type() == Data::Field::Image) {
      continue;
    } else if(f->type() == Data::Field::Choice) {
      e->setField(f->name(), f->allowed().front());
    } else if(f->type() == Data::Field::Number) {
      e->setField(f->name(), TQString::fromLatin1("1"));
    } else if(f->type() == Data::Field::Bool) {
      e->setField(f->name(), TQString::fromLatin1("true"));
    } else if(f->type() == Data::Field::Rating) {
      e->setField(f->name(), TQString::fromLatin1("5"));
    } else {
      e->setField(f->name(), f->title());
    }
  }

  dlg->showEntry(e);
  dlg->show();
  // dlg gets deleted by itself
  // the finished() signal is connected in its constructor to delayedDestruct
}

void ConfigDialog::loadTemplateList() {
  TQStringList files = TDEGlobal::dirs()->findAllResources("appdata", TQString::fromLatin1("entry-templates/*.xsl"),
                                                        false, true);
  KSortableValueList<TQString, TQString> templates;
  for(TQStringList::ConstIterator it = files.begin(); it != files.end(); ++it) {
    TQFileInfo fi(*it);
    TQString file = fi.fileName().section('.', 0, -2);
    TQString name = file;
    name.replace('_', ' ');
    TQString title = i18n((name + TQString::fromLatin1(" XSL Template")).utf8(), name.utf8());
    templates.insert(title, file);
  }
  templates.sort();

  TQString s = m_templateCombo->currentText();
  m_templateCombo->clear();
  for(KSortableValueList<TQString, TQString>::iterator it2 = templates.begin(); it2 != templates.end(); ++it2) {
    m_templateCombo->insertItem((*it2).index(), (*it2).value());
  }
  m_templateCombo->setCurrentItem(s);
}

void ConfigDialog::slotInstallTemplate() {
  TQString filter = i18n("*.xsl|XSL Files (*.xsl)") + '\n';
  filter += i18n("*.tar.gz *.tgz|Template Packages (*.tar.gz)") + '\n';
  filter += i18n("*|All Files");

  KURL u = KFileDialog::getOpenURL(TQString(), filter, this);
  if(u.isEmpty() || !u.isValid()) {
    return;
  }

  NewStuff::Manager man(TQT_TQOBJECT(this));
  if(man.installTemplate(u)) {
    loadTemplateList();
  }
}

void ConfigDialog::slotDownloadTemplate() {
  NewStuff::Dialog dlg(NewStuff::EntryTemplate, this);
  dlg.exec();
  loadTemplateList();
}

void ConfigDialog::slotDeleteTemplate() {
  TQDir dir(Tellico::saveLocation(TQString::fromLatin1("entry-templates/")));
  dir.setNameFilter(TQString::fromLatin1("*.xsl"));
  dir.setFilter(TQDir::Files | TQDir::Writable);
  TQStringList files = dir.entryList();
  TQMap<TQString, TQString> nameFileMap;
  for(TQStringList::Iterator it = files.begin(); it != files.end(); ++it) {
    (*it).truncate((*it).length()-4); // remove ".xsl"
    TQString name = (*it);
    name.replace('_', ' ');
    nameFileMap.insert(name, *it);
  }
  bool ok;
  TQString name = KInputDialog::getItem(i18n("Delete Template"),
                                       i18n("Select template to delete:"),
                                       nameFileMap.keys(), 0, false, &ok, this);
  if(ok && !name.isEmpty()) {
    TQString file = nameFileMap[name];
    NewStuff::Manager man(TQT_TQOBJECT(this));
    man.removeTemplate(file);
    loadTemplateList();
  }
}

#include "configdialog.moc"