summaryrefslogtreecommitdiffabout
path: root/libkdepim/kcmconfigs/kdepimconfigwidget.cpp
blob: 11a2b45f499668016c4a22284713498da4eea1e3 (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
/*
    This file is part of KdePim/Pi.
    Copyright (c) 2004 Ulf Schenk

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program 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 General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

    As a special exception, permission is given to link this program
    with any edition of Qt, and distribute the resulting executable,
    without including the source code for Qt in the source distribution.
*/

/*
Enhanced Version of the file for platform independent KDE tools.
Copyright (c) 2004 Ulf Schenk

$Id$
*/

#include <qlayout.h>
#include <qtabwidget.h>
#include <qcombobox.h>
#include <q3groupbox.h>
#include <qlabel.h>
#include <qlineedit.h>
#include <q3buttongroup.h>
#include <qcheckbox.h>
#include <qfile.h>
#include <q3vbox.h>
#include <qdir.h>
#include <qregexp.h>
#include <qspinbox.h>
#include <QDesktopWidget>
//Added by qt3to4:
#include <Q3HBoxLayout>
#include <Q3GridLayout>
#include <Q3VBoxLayout>

#include <kdialog.h>
#include <kprefsdialog.h>
#include <klocale.h>
#include <kglobalsettings.h>
#include <kdateedit.h>
#include <kglobal.h>
#include <stdlib.h>

/*US
#include <qcheckbox.h>
#include <qframe.h>
#include <qpushbutton.h>
#include <qcombobox.h>
#include <qlineedit.h>
#include <qlabel.h>
#include <qfile.h>

#include <kconfig.h>
#include <kdebug.h>
#include <kdialog.h>
#include <klistview.h>
#include <klocale.h>
#include <kglobal.h>
#include <kmessagebox.h>
#include <kstandarddirs.h>

#ifndef KAB_EMBEDDED
#include <ktrader.h>
#else // KAB_EMBEDDED
#include <mergewidget.h>
#include <distributionlistwidget.h>
#endif // KAB_EMBEDDED

#include "addresseewidget.h"
#include "extensionconfigdialog.h"
#include "extensionwidget.h"
*/

#include "qapplication.h"

#include "kpimglobalprefs.h"

#include "kdepimconfigwidget.h"
#include <kprefs.h>
#include <kmessagebox.h>



KDEPIMConfigWidget::KDEPIMConfigWidget(KPimGlobalPrefs *prefs, QWidget *parent, const char *name )
  : KPrefsWidget(prefs, parent, name )
{
  mExternalAppsMap.insert(ExternalAppHandler::EMAIL, i18n("Email"));
  mExternalAppsMap.insert(ExternalAppHandler::PHONE, i18n("Phone"));
  mExternalAppsMap.insert(ExternalAppHandler::SMS, i18n("SMS"));
  mExternalAppsMap.insert(ExternalAppHandler::FAX, i18n("Fax"));
  mExternalAppsMap.insert(ExternalAppHandler::PAGER, i18n("Pager"));
  mExternalAppsMap.insert(ExternalAppHandler::SIP, i18n("SIP"));


  Q3VBoxLayout *topLayout = new Q3VBoxLayout( this, 0,
                                            KDialog::spacingHint() );

  tabWidget = new QTabWidget( this );
  topLayout->addWidget( tabWidget );


  setupLocaleTab();
  setupLocaleDateTab();
  setupTimeZoneTab();
  setupExternalAppTab();
  setupStoreTab();
  setupBackupTab();
}
void KDEPIMConfigWidget::showTimeZoneTab()
{
    tabWidget->setCurrentPage ( 3 ) ;
}
void KDEPIMConfigWidget::setupBackupTab()
{
    Q3VBox *colorPage = new Q3VBox( this );
    tabWidget->addTab( colorPage, i18n( "Backup" ) );
    QWidget* topFrame = new QWidget( colorPage ); 
    Q3VBoxLayout *topLayout = new Q3VBoxLayout(topFrame);
    KPrefsWidBool *sb = addWidBool(i18n("Backup enabled"),
                      &(KPimGlobalPrefs::instance()->mBackupEnabled),topFrame);
    topLayout->addWidget((QWidget*)sb->checkBox());
    QWidget* bupFrame = new QWidget( topFrame ); 
    topLayout->addWidget((bupFrame));
    QObject::connect ( sb->checkBox(), SIGNAL (toggled ( bool ) ), bupFrame, SLOT ( setEnabled( bool ) ) );
    Q3VBoxLayout *bupLayout = new Q3VBoxLayout(bupFrame);
    sb = addWidBool(i18n("Use standard backup dir"),
                      &(KPimGlobalPrefs::instance()->mBackupUseDefaultDir),bupFrame);
    bupLayout->addWidget((QWidget*)sb->checkBox());
    mBackupUrl = new KURLRequester( bupFrame );
    mBackupUrl->setPathIsDir();
    mBackupUrl->setURL( KGlobalSettings::backupDataDir() );
    QObject::connect ( sb->checkBox(), SIGNAL (toggled ( bool ) ), mBackupUrl ,SLOT ( setDisabled( bool ) ) );
    bupLayout->addWidget( mBackupUrl );

    mBackupUrl->setEnabled( !KPimGlobalPrefs::instance()->mBackupUseDefaultDir );
    bupFrame->setEnabled( KPimGlobalPrefs::instance()->mBackupEnabled );
    Q3HBox *dummy = new Q3HBox(bupFrame);
    new QLabel(i18n("Number of Backups:"),dummy);
    mBackupNumbersSpin = new QSpinBox(1,21,1,dummy);
    new QLabel(i18n(" "),dummy);
    bupLayout->addWidget( dummy );

    dummy = new Q3HBox(bupFrame);
    new QLabel(i18n("Make backup every "),dummy);
    mBackupDayCountSpin = new QSpinBox(1,28,1,dummy);
    new QLabel(i18n(" days"),dummy);
    new QLabel(i18n(" "),dummy);
    bupLayout->addWidget( dummy ); 
    QString localKdeDir;
    localKdeDir = readEnvPath("LOCALMICROKDEHOME");
    if ( ! localKdeDir.isEmpty() ) {
        sb->checkBox()->setEnabled( false );
        sb->checkBox()->setChecked( true );
        mBackupUrl->setEnabled( false );
        KPimGlobalPrefs::instance()->mBackupUseDefaultDir = true;
    }

}
void KDEPIMConfigWidget::setupStoreTab()
{
    Q3VBox *colorPage = new Q3VBox( this );
    tabWidget->addTab( colorPage, i18n( "Colors" ) );
    QWidget* cw = new QWidget( colorPage ); 
    KPrefsWidColor *holidayColor =
      addWidColor(i18n("Alternating background of list views"),
                  &(KPimGlobalPrefs::instance()->mAlternateColor),cw);
    Q3HBoxLayout *topLayout = new Q3HBoxLayout(cw);
    topLayout->addWidget(holidayColor->label());
    topLayout->addWidget( (QWidget* )holidayColor->button());


    Q3VBox *storePage = new Q3VBox( this ); 
    if (  QApplication::desktop()->height() > 240 )
    new QLabel( i18n("Your current storage dir is:\n%1\nYour mail is stored in:\n(storagedir)/apps/kopiemail/localmail").arg(KGlobal::dirs()->localkdedir()), storePage  );
    new QLabel( i18n("<b>New data storage dir:</b>"), storePage );
    mStoreUrl = new KURLRequester( storePage );
    mStoreUrl->setPathIsDir();
    mStoreUrl->setURL( KGlobal::dirs()->localkdedir() );
#ifdef DESKTOP_VERSION     
    QString confFile = qApp->applicationDirPath ()+ "/.microkdehome" ;
    QFileInfo fi ( confFile );
    if ( fi.exists() ) {
        KConfig cfg (   confFile );
        cfg.setGroup("Global");
        QString localKdeDir = cfg.readEntry( "MICROKDEHOME", "x_x_x" );
        if ( localKdeDir != "x_x_x" ) {
            mStoreUrl->setURL( localKdeDir );
            qDebug("Reading config from %s ", confFile.latin1());
        }
    }
               
#endif 
    new QLabel( i18n("New dirs are created automatically"), storePage  );
    Q3HBox *bb = new Q3HBox( storePage );
    QPushButton * pb;
    if ( QApplication::desktop()->width() < 640 )
        pb = new QPushButton ( i18n("Save"), bb  );
    else
        pb = new QPushButton ( i18n("Save settings"), bb  );
    connect(pb, SIGNAL( clicked() ), this, SLOT ( saveStoreSettings() ) );
    pb = new QPushButton ( i18n("Save standard"), bb  );
    connect(pb, SIGNAL( clicked() ), this, SLOT ( setStandardStore() ) );
#ifdef DESKTOP_VERSION
    pb = new QPushButton ( i18n("Save using LOCAL storage"), bb  );
    connect(pb, SIGNAL( clicked() ), this, SLOT ( setLocalStore() ) );
#endif
    new QLabel( i18n("<b>New settings are used\nafter a restart</b>"), storePage );
    mDataStoragePath = new QLabel( i18n("Settings are stored in\n%1").arg(QDir::homeDirPath() + "/.microkdehome" ), storePage  );
    tabWidget->addTab( storePage, i18n( "Data storage path" ) );

#ifdef DESKTOP_VERSION  
      if ( mStoreUrl->url().startsWith( "LOCAL:" ) ) {
	mDataStoragePath->setText( i18n("Settings are stored in\n%1").arg( qApp->applicationDirPath ()+"/.microkdehome" ));
      }
#endif
}
void KDEPIMConfigWidget::setLocalStore()
{
    mStoreUrl->setURL(  "LOCAL:kdepimpi"  );
    saveStoreSettings();
    QString message = i18n("'LOCAL' mode makes is possible to run\nKA/Pi and KO/Pi from a USB memory stick.\nIn LOCAL mode the data is stored\nin a path relative to the executable.\nNote, that in LOCAL mode only addressbook\nresource files in\n <path of the executable>/<dirname after LOCAL:>/apps/kabc/*.vcf\n are supported.\nIf you use the standard addressbook settings\nyou do not have to reconfigure any path,\njust restart the application and import\nyour addressbook and calendar data.");
    KMessageBox::information( this, message);
}
void KDEPIMConfigWidget::setStandardStore()
{
    mStoreUrl->setURL(  QDir::homeDirPath() + "/kdepim"  );
    saveStoreSettings();
}
void KDEPIMConfigWidget::saveStoreSettings()
{
#ifdef DESKTOP_VERSION
        if ( !mStoreUrl->url().startsWith( "LOCAL:" ) ) {
            QString file = qApp->applicationDirPath ()+"/.microkdehome";
            QFileInfo fi ( file );
            if ( fi.exists() ) {
                bool res = QFile::remove( file );
                if ( ! res )
                    KMessageBox::information( this, i18n("ERROR: Cannot remove file\n%1\nPlease remove it manually.").arg( file ));
            }
        }
#endif
    if ( !mStoreUrl->url().isEmpty() ) {
        QString path = QDir::homeDirPath();
        QString url = mStoreUrl->url();
#ifdef DESKTOP_VERSION
        if ( url.startsWith( "LOCAL:" ) ) {
            path = qApp->applicationDirPath () ;
        }
#endif
        KConfig cfg (   path + "/.microkdehome" );
        cfg.setGroup("Global");
        cfg.writeEntry( "MICROKDEHOME", url ); 
        qDebug("cfg.writeEntry( MICROKDEHOME, %s  ", url.latin1());
        cfg.sync();
	mDataStoragePath->setText( i18n("Settings are stored in\n%1").arg( path+"/.microkdehome" ));
    } else {
        mStoreUrl->setURL(  QDir::homeDirPath() + "/kdepim"  );
        saveStoreSettings();
    }
}
void KDEPIMConfigWidget::setupExternalAppTab()
{
  QWidget *externalAppsPage = new QWidget( this );
  Q3VBoxLayout* layout = new Q3VBoxLayout( externalAppsPage, KDialog::marginHintSmall(),
                                            KDialog::spacingHintSmall() );

  mExternalApps = new QComboBox( externalAppsPage );

  QMap<ExternalAppHandler::Types, QString>::Iterator it;
  for( it = mExternalAppsMap.begin(); it != mExternalAppsMap.end(); ++it )
    mExternalApps->insertItem( it.data(), it.key() );

  layout->addWidget( mExternalApps );

  connect( mExternalApps, SIGNAL( activated( int ) ),
           this, SLOT (externalapp_changed( int ) ) );


  mExternalAppGroupBox = new Q3GroupBox( 0, Qt::Vertical, i18n( "Used Mail Client" ), externalAppsPage );
  Q3GridLayout *boxLayout = new Q3GridLayout( mExternalAppGroupBox->layout(), 4, 2,    -1, "gridlayout" );
  mExternalAppGroupBox->layout()->setMargin(4);

  mClient = new QComboBox( mExternalAppGroupBox );
  boxLayout->addMultiCellWidget( mClient, 0, 0, 0, 1 );

  connect( mClient, SIGNAL( activated( int ) ),
           this, SLOT (client_changed( int ) ) );

  QLabel* lab = new QLabel( i18n("Channel:"), mExternalAppGroupBox);
  boxLayout->addWidget( lab, 1, 0 );
  mChannel = new QLineEdit(mExternalAppGroupBox);
  mChannel->setReadOnly(true);
  boxLayout->addMultiCellWidget( mChannel, 2 , 2, 0, 1 );

  lab = new QLabel( i18n("Message:"), mExternalAppGroupBox);
  boxLayout->addWidget( lab, 3, 0 );
  mMessage = new QLineEdit(mExternalAppGroupBox);
  mMessage->setReadOnly(true);
  boxLayout->addWidget( mMessage , 4, 0);

  lab = new QLabel( i18n("Parameters:"), mExternalAppGroupBox);
  boxLayout->addWidget( lab, 3, 1 );
  mParameters = new QLineEdit(mExternalAppGroupBox);
  mParameters->setReadOnly(true);
  boxLayout->addWidget( mParameters, 4, 1 );
      lab = new QLabel( i18n("HINT: Delimiter=; Name=%1,Email=%2"), mExternalAppGroupBox);
      boxLayout->addMultiCellWidget( lab, 5, 5, 0, 1 );


  if (  QApplication::desktop()->height() > 240 ) {
      lab = new QLabel( i18n("extra Message:"), mExternalAppGroupBox);
      boxLayout->addWidget( lab, 6, 0 );
      mMessage2 = new QLineEdit(mExternalAppGroupBox);
      mMessage2->setReadOnly(true);
      boxLayout->addWidget( mMessage2 , 7, 0);

      lab = new QLabel( i18n("extra Parameters:"), mExternalAppGroupBox);
      boxLayout->addWidget( lab, 6, 1 );
      mParameters2 = new QLineEdit(mExternalAppGroupBox);
      mParameters2->setReadOnly(true);
      boxLayout->addWidget( mParameters2, 7, 1 );

      lab = new QLabel( i18n("HINT: Emails=%1,Attachments=%2"), mExternalAppGroupBox);
      boxLayout->addMultiCellWidget( lab, 8, 8, 0, 1 );
      connect( mMessage2, SIGNAL( textChanged ( const QString & )), this, SLOT( textChanged ( const QString & ))  );
      connect( mParameters2, SIGNAL( textChanged ( const QString & )), this, SLOT( textChanged ( const QString & ))  );
  } else {
      mMessage2 = 0;
      mParameters2 = 0;
  }

  connect( mChannel, SIGNAL( textChanged ( const QString & )), this, SLOT( textChanged ( const QString & ))  );
  connect( mMessage, SIGNAL( textChanged ( const QString & )), this, SLOT( textChanged ( const QString & ))  );
  connect( mParameters, SIGNAL( textChanged ( const QString & )), this, SLOT( textChanged ( const QString & ))  );


  layout->addWidget( mExternalAppGroupBox );
  tabWidget->addTab( externalAppsPage, i18n( "External Apps." ) );

}

  
void KDEPIMConfigWidget::setupLocaleDateTab()
{
  QWidget *topFrame = new QWidget( this );
  Q3GridLayout *topLayout = new Q3GridLayout( topFrame, 3, 2);

   topLayout->setSpacing(KDialog::spacingHintSmall());
   topLayout->setMargin(KDialog::marginHintSmall());  
   int iii = 0;

   
   KPrefsWidRadios *syncPrefsGroup =
       addWidRadios(i18n("Date Format:"),&(KPimGlobalPrefs::instance()->mPreferredDate),topFrame);
   QString format;
   if ( QApplication::desktop()->width() < 480 )
       format = "(%d.%m.%Y)";
   else 
       format = "(%d.%m.%Y|%A %d %B %Y)";
   syncPrefsGroup->addRadio(i18n("24.03.2004 "+format));
   if ( QApplication::desktop()->width() < 480 )
       format = "(%m.%d.%Y)";
   else 
       format = "(%m.%d.%Y|%A %B %d %Y)";
   syncPrefsGroup->addRadio(i18n("03.24.2004 "+format));
   if ( QApplication::desktop()->width() < 480 )
       format = "(%Y-%m-%d)";
   else 
       format = "(%Y-%m-%d|%A %Y %B %d)";
   syncPrefsGroup->addRadio(i18n("2004-03-24 "+format));
   syncPrefsGroup->addRadio(i18n("User defined"));
   if ( QApplication::desktop()->width() < 480 ) {
       syncPrefsGroup->groupBox()->layout()->setMargin( 5 );
       syncPrefsGroup->groupBox()->layout()->setSpacing( 0 );
   }  
   topLayout->addMultiCellWidget( (QWidget*)syncPrefsGroup->groupBox(),iii,iii,0,1);
   ++iii;   
   ++iii;
   QLabel * lab;
   mUserDateFormatLong = new QLineEdit(topFrame);
   lab = new QLabel(mUserDateFormatLong, i18n("User long date:"), topFrame);
   topLayout->addWidget(lab ,iii,0);
   topLayout->addWidget(mUserDateFormatLong,iii,1);
   ++iii;
   mUserDateFormatShort = new QLineEdit(topFrame);
   lab = new QLabel(mUserDateFormatShort, i18n("User short date:"), topFrame);
   topLayout->addWidget(lab ,iii,0);
   topLayout->addWidget(mUserDateFormatShort,iii,1);
   ++iii;
   lab = new QLabel( i18n("Monday 19 April 2004: %A %d %B %Y"), topFrame);
   topLayout->addMultiCellWidget(lab ,iii,iii,0,1);
   ++iii;
   //qDebug(" QApplication::desktop()->height()xx %d ",  QApplication::desktop()->height() ); 
   if (  QApplication::desktop()->height() > 240 ) {
       lab = new QLabel( i18n("Mon 19.04.04: %a %d.%m.%y"), topFrame);
       topLayout->addMultiCellWidget(lab ,iii,iii,0,1);
       ++iii;  
       lab = new QLabel( i18n("Mon, 19.Apr.04: %a, %d.%b.%y"), topFrame);
       topLayout->addMultiCellWidget(lab ,iii,iii,0,1);
       ++iii;
   }

  connect( mUserDateFormatLong, SIGNAL( textChanged ( const QString & )), this, SLOT( textChanged ( const QString & ))  );
  connect( mUserDateFormatShort, SIGNAL( textChanged ( const QString & )), this, SLOT( textChanged ( const QString & ))  );


   tabWidget->addTab( topFrame, i18n( "Date Format" ) );
}

void KDEPIMConfigWidget::setupLocaleTab()
{

  QWidget *topFrame = new QWidget( this );
   Q3GridLayout *topLayout = new Q3GridLayout(topFrame,4,2);

   topLayout->setSpacing(KDialog::spacingHint());
   topLayout->setMargin(KDialog::marginHint());  
   int iii = 0;
 KPrefsWidRadios *syncPrefsGroup =
      addWidRadios(i18n("Language:(needs restart)"),&(KPimGlobalPrefs::instance()->mPreferredLanguage),topFrame);
   syncPrefsGroup->addRadio(i18n("English"));
   syncPrefsGroup->addRadio(i18n("German")); 
   syncPrefsGroup->addRadio(i18n("French")); 
   syncPrefsGroup->addRadio(i18n("Italian")); 
   syncPrefsGroup->addRadio(i18n("User defined (usertranslation.txt)")); 
   if (  QApplication::desktop()->width() <  300   ) {
       syncPrefsGroup->groupBox()->layout()->setMargin( 5 );
       syncPrefsGroup->groupBox()->layout()->setSpacing( 0 );
   }
   topLayout->addMultiCellWidget( (QWidget*)syncPrefsGroup->groupBox(),iii,iii,0,1);
   ++iii;   
 

   tabWidget->addTab( topFrame, i18n( "Language" ) );
   topFrame = new QWidget( this );
   topLayout = new Q3GridLayout(topFrame,4,2);
   
   topLayout->setSpacing(KDialog::spacingHint());
   topLayout->setMargin(KDialog::marginHint());  
   iii = 0;
   syncPrefsGroup =
       addWidRadios(i18n("Time Format(nr):"),&(KPimGlobalPrefs::instance()->mPreferredTime),topFrame);
   if (  QApplication::desktop()->width() >  300   )
       syncPrefsGroup->groupBox()->setOrientation (Qt::Vertical);
   syncPrefsGroup->addRadio(i18n("24:00"));
   syncPrefsGroup->addRadio(i18n("12:00am"));
   syncPrefsGroup->groupBox()->setOrientation (Qt::Vertical);
   topLayout->addMultiCellWidget( syncPrefsGroup->groupBox(),iii,iii,0,1);
   ++iii;   

   KPrefsWidBool *sb = addWidBool(i18n("Week starts on Sunday"),
                      &(KPimGlobalPrefs::instance()->mWeekStartsOnSunday),topFrame);
   topLayout->addMultiCellWidget((QWidget*)sb->checkBox(), iii,iii,0,1);
   ++iii;   


   tabWidget->addTab( topFrame, i18n( "Time Format" ) );

}


void KDEPIMConfigWidget::setupTimeZoneTab()
{
    QWidget *topFrame;
    Q3GridLayout *topLayout ;

 




  topFrame = new QWidget( this );
  topLayout = new Q3GridLayout( topFrame, 5, 2);
  topLayout->setSpacing(KDialog::spacingHintSmall());
  topLayout->setMargin(KDialog::marginHintSmall());

  Q3HBox *timeZoneBox = new Q3HBox( topFrame );
  topLayout->addMultiCellWidget( timeZoneBox, 0, 0, 0, 1 );

  new QLabel( i18n("Timezone:"), timeZoneBox );
  mTimeZoneCombo = new QComboBox( timeZoneBox ); 
  if ( QApplication::desktop()->width() <  300 ) {
       mTimeZoneCombo->setMaximumWidth(150);
    }

  QStringList list;
  list = KGlobal::locale()->timeZoneList();
  mTimeZoneCombo->insertStringList(list);

    // find the currently set time zone and select it
  QString sCurrentlySet = KPimGlobalPrefs::instance()->mTimeZoneId;
  int nCurrentlySet = 11;
  for (int i = 0; i < mTimeZoneCombo->count(); i++)
    {
      if (mTimeZoneCombo->text(i) == sCurrentlySet)
        {
         nCurrentlySet = i;
         break;
        }
    }
  mTimeZoneCombo->setCurrentItem(nCurrentlySet);
  int iii = 1;
  KPrefsWidBool *sb =
      addWidBool(i18n("Add 30 min to selected Timezone"),
                 &(KPimGlobalPrefs::instance()->mTimeZoneAdd30min),topFrame);
  topLayout->addMultiCellWidget((QWidget*)sb->checkBox(), iii,iii,0,1);
  ++iii;  
  sb =
      addWidBool(i18n("Timezone has daylight saving"),
                 &(KPimGlobalPrefs::instance()->mUseDaylightsaving),topFrame);
  topLayout->addMultiCellWidget((QWidget*)sb->checkBox(), iii,iii,0,1);
  ++iii; 
  QLabel* lab; 

  lab = new QLabel(  i18n("Actual start and end is the\nsunday before this date."), topFrame );
  topLayout->addMultiCellWidget(lab, iii,iii,0,1);
  ++iii;
 
  lab = new QLabel(  i18n("The year in the date is ignored."), topFrame );
  topLayout->addMultiCellWidget(lab, iii,iii,0,1);
  ++iii; 
  lab = new QLabel(  i18n("Daylight start:"), topFrame );
  topLayout->addWidget(lab, iii,0);
  mStartDateSavingEdit = new KDateEdit(topFrame);
  topLayout->addWidget(mStartDateSavingEdit, iii,1);
  ++iii;

  lab = new QLabel(  i18n("Daylight end:"), topFrame );
  topLayout->addWidget(lab, iii,0);
  mEndDateSavingEdit = new KDateEdit(topFrame);
  topLayout->addWidget(mEndDateSavingEdit, iii,1);
  ++iii;
  QDate current ( 2001, 1,1);
  mStartDateSavingEdit->setDate(current.addDays(KPimGlobalPrefs::instance()->mDaylightsavingStart-1));
  mEndDateSavingEdit->setDate(current.addDays(KPimGlobalPrefs::instance()->mDaylightsavingEnd-1));

  connect( mStartDateSavingEdit, SIGNAL(  dateChanged(QDate)), this, SLOT( modified())  );
  connect( mEndDateSavingEdit, SIGNAL(  dateChanged(QDate)), this, SLOT( modified())  );
  connect( mTimeZoneCombo, SIGNAL( activated( int ) ), this, SLOT (modified() ) );
  tabWidget->addTab( topFrame, i18n( "Time Zone" ) );
 

  topFrame = new QWidget( this );
  topLayout = new Q3GridLayout( topFrame, 3, 2);
  topLayout->setSpacing(KDialog::spacingHintSmall());
  topLayout->setMargin(KDialog::marginHintSmall());
  tabWidget->addTab( topFrame, i18n( "Fonts" ) );

  QLabel* labb = new QLabel( i18n("Global application font for all apps:"),  topFrame );
  topLayout->addMultiCellWidget(labb,0,0,0,2);
  int i = 1;
  KPrefsWidFont *timeLabelsFont =
      addWidFont(i18n("Kx/Pi"),i18n("Application Font"),
                 &(KPimGlobalPrefs::instance()->mApplicationFont),topFrame);
  topLayout->addWidget(timeLabelsFont->label(),i,0);
  topLayout->addWidget(timeLabelsFont->preview(),i,1);
  topLayout->addWidget(timeLabelsFont->button(),i,2);
}

void KDEPIMConfigWidget::externalapp_changed( int newApp )
{
  // first store the current data
  saveEditFieldSettings();

  // set mCurrentApp
  mCurrentApp = (ExternalAppHandler::Types)newApp;

  // set mCurrentClient
  switch(mCurrentApp)
  {
    case(ExternalAppHandler::EMAIL):
      mCurrentClient = mEmailClient;
      break;
    case(ExternalAppHandler::PHONE):
      mCurrentClient = mPhoneClient;
      break;
    case(ExternalAppHandler::SMS):
      mCurrentClient = mSMSClient;
      break;
    case(ExternalAppHandler::FAX):
      mCurrentClient = mFaxClient;
      break;
    case(ExternalAppHandler::PAGER):
      mCurrentClient = mPagerClient;
      break;
    case(ExternalAppHandler::SIP):
      mCurrentClient = mSipClient;
      break;
    default:
      return;
  }

  // and at last update the widgets
  updateClientWidgets();
}



void KDEPIMConfigWidget::client_changed( int newClient )
{
  if (newClient == mCurrentClient)
    return;

  // first store the current data
  saveEditFieldSettings();


  //then reset the clientvariable
  mCurrentClient = newClient;

  // and at last update the widgets
  updateClientWidgets();

  KPrefsWidget::modified();
}

void KDEPIMConfigWidget::saveEditFieldSettings()
{

  switch(mCurrentApp)
  {
    case(ExternalAppHandler::EMAIL):
      mEmailClient = mClient->currentItem();
      break;
    case(ExternalAppHandler::PHONE):
      mPhoneClient= mClient->currentItem();
      break;
    case(ExternalAppHandler::SMS):
      mSMSClient = mClient->currentItem();
      break;
    case(ExternalAppHandler::FAX):
      mFaxClient = mClient->currentItem();
      break;
    case(ExternalAppHandler::PAGER):
      mPagerClient = mClient->currentItem();
      break;
    case(ExternalAppHandler::SIP):
      mSipClient = mClient->currentItem();
      break;
    default:
      return;
  }

  //store the current data back to the apropriate membervariables if we had set it to "other"
  if ((mCurrentApp == ExternalAppHandler::EMAIL) && (mCurrentClient == KPimGlobalPrefs::OTHER_EMC))
  {
    mEmailOtherChannel = mChannel->text();
    mEmailOtherMessage = mMessage->text();
    mEmailOtherMessageParameters = mParameters->text();
    if ( mMessage2 )
        mEmailOtherMessage2 = mMessage2->text();   
    if ( mParameters2 )
        mEmailOtherMessageParameters2 = mParameters2->text();
  }
  else if ((mCurrentApp == ExternalAppHandler::PHONE) && (mCurrentClient == KPimGlobalPrefs::OTHER_PHC))
  {
    mPhoneOtherChannel = mChannel->text();
    mPhoneOtherMessage = mMessage->text();
    mPhoneOtherMessageParameters = mParameters->text();
  }
  else if ((mCurrentApp == ExternalAppHandler::SMS) && (mCurrentClient == KPimGlobalPrefs::OTHER_SMC))
  {
    mSMSOtherChannel = mChannel->text();
    mSMSOtherMessage = mMessage->text();
    mSMSOtherMessageParameters = mParameters->text();
  }
  else if ((mCurrentApp == ExternalAppHandler::FAX) && (mCurrentClient == KPimGlobalPrefs::OTHER_FAC))
  {
    mFaxOtherChannel = mChannel->text();
    mFaxOtherMessage = mMessage->text();
    mFaxOtherMessageParameters = mParameters->text();
  }
  else if ((mCurrentApp == ExternalAppHandler::PAGER) && (mCurrentClient == KPimGlobalPrefs::OTHER_PAC))
  {
    mPagerOtherChannel = mChannel->text();
    mPagerOtherMessage = mMessage->text();
    mPagerOtherMessageParameters = mParameters->text();
  }
  else if ((mCurrentApp == ExternalAppHandler::SIP) && (mCurrentClient == KPimGlobalPrefs::OTHER_SIC))
  {
    mSipOtherChannel = mChannel->text();
    mSipOtherMessage = mMessage->text();
    mSipOtherMessageParameters = mParameters->text();
  }


}

void KDEPIMConfigWidget::updateClientWidgets()
{
  bool blocked = signalsBlocked();
  blockSignals( true );

  // at this point we assume, that mCurrentApp and mCurrentClient are set to the values that we want to display
  QMap<ExternalAppHandler::Types, QString>::Iterator it = mExternalAppsMap.find ( mCurrentApp );
  if (it == mExternalAppsMap.end())
    return;

  // update group box
  mExternalAppGroupBox->setTitle(i18n( "Used %1 Client" ).arg(it.data()));

  //update the entries in the client combobox
  mClient->clear();

  Q3PtrList<DefaultAppItem> items = ExternalAppHandler::instance()->getAvailableDefaultItems(mCurrentApp);
  DefaultAppItem* dai;
  for ( dai=items.first(); dai != 0; dai=items.next() )
  {
    mClient->insertItem( i18n(dai->_label), dai->_id );

    if (dai->_id == mCurrentClient)
    {
      //restore the edit fields with the data of the local membervariables if we had set it to "other".
      //Otherwise take the default data from externalapphandler.
      mChannel->setText(dai->_channel);
      mMessage->setText(dai->_message);
      mParameters->setText(dai->_parameters);  
      if ( mMessage2 )
          mMessage2->setText(dai->_message2); 
    if ( mParameters2 )
      mParameters2->setText(dai->_parameters2);


      if ((mCurrentApp == ExternalAppHandler::EMAIL) && (mCurrentClient == KPimGlobalPrefs::OTHER_EMC))
      {
        mChannel->setText(mEmailOtherChannel);
        mMessage->setText(mEmailOtherMessage);
        mParameters->setText(mEmailOtherMessageParameters); 
        if ( mMessage2 )
        mMessage2->setText(mEmailOtherMessage2);
    if ( mParameters2 )
        mParameters2->setText(mEmailOtherMessageParameters2);
      }
      else if ((mCurrentApp == ExternalAppHandler::PHONE) && (mCurrentClient == KPimGlobalPrefs::OTHER_PHC))
      {
        mChannel->setText(mPhoneOtherChannel);
        mMessage->setText(mPhoneOtherMessage);
        mParameters->setText(mPhoneOtherMessageParameters);
      }
      else if ((mCurrentApp == ExternalAppHandler::SMS) && (mCurrentClient == KPimGlobalPrefs::OTHER_SMC))
      {
        mChannel->setText(mSMSOtherChannel);
        mMessage->setText(mSMSOtherMessage);
        mParameters->setText(mSMSOtherMessageParameters);
      }
      else if ((mCurrentApp == ExternalAppHandler::FAX) && (mCurrentClient == KPimGlobalPrefs::OTHER_FAC))
      {
        mChannel->setText(mFaxOtherChannel);
        mMessage->setText(mFaxOtherMessage);
        mParameters->setText(mFaxOtherMessageParameters);
      }
      else if ((mCurrentApp == ExternalAppHandler::PAGER) && (mCurrentClient == KPimGlobalPrefs::OTHER_PAC))
      {
        mChannel->setText(mPagerOtherChannel);
        mMessage->setText(mPagerOtherMessage);
        mParameters->setText(mPagerOtherMessageParameters);
      }
      else if ((mCurrentApp == ExternalAppHandler::SIP) && (mCurrentClient == KPimGlobalPrefs::OTHER_SIC))
      {
        mChannel->setText(mSipOtherChannel);
        mMessage->setText(mSipOtherMessage);
        mParameters->setText(mSipOtherMessageParameters);
      }
    }

  }

  bool readonly;
  bool enabled;
  if ( ((mCurrentApp == ExternalAppHandler::EMAIL) && (mCurrentClient == KPimGlobalPrefs::OTHER_EMC))
     ||((mCurrentApp == ExternalAppHandler::PHONE) && (mCurrentClient == KPimGlobalPrefs::OTHER_PHC))
     ||((mCurrentApp == ExternalAppHandler::SMS) && (mCurrentClient == KPimGlobalPrefs::OTHER_SMC))
     ||((mCurrentApp == ExternalAppHandler::FAX) && (mCurrentClient == KPimGlobalPrefs::OTHER_FAC))
     ||((mCurrentApp == ExternalAppHandler::PAGER) && (mCurrentClient == KPimGlobalPrefs::OTHER_PAC))
     ||((mCurrentApp == ExternalAppHandler::SIP) && (mCurrentClient == KPimGlobalPrefs::OTHER_SIC)))
     {
       readonly = false;
	 }
	 else
	 {
       readonly = true;
	 }

  if ( ((mCurrentApp == ExternalAppHandler::EMAIL) && (mCurrentClient == KPimGlobalPrefs::NONE_EMC))
     ||((mCurrentApp == ExternalAppHandler::PHONE) && (mCurrentClient == KPimGlobalPrefs::NONE_PHC))
     ||((mCurrentApp == ExternalAppHandler::SMS) && (mCurrentClient == KPimGlobalPrefs::NONE_SMC))
     ||((mCurrentApp == ExternalAppHandler::FAX) && (mCurrentClient == KPimGlobalPrefs::NONE_FAC))
     ||((mCurrentApp == ExternalAppHandler::PAGER) && (mCurrentClient == KPimGlobalPrefs::NONE_PAC))
     ||((mCurrentApp == ExternalAppHandler::SIP) && (mCurrentClient == KPimGlobalPrefs::NONE_SIC)))
     {
       enabled = false;
	 }
	 else
	 {
       enabled = true;
	 }


  mChannel->setReadOnly(readonly);
  mMessage->setReadOnly(readonly);
  mParameters->setReadOnly(readonly); 
  if ( mMessage2 )
  mMessage2->setReadOnly(readonly);
    if ( mParameters2 )
  mParameters2->setReadOnly(readonly);

  mChannel->setEnabled(enabled);
  mMessage->setEnabled(enabled);
  mParameters->setEnabled(enabled);
  if ( mMessage2 )
  mMessage2->setEnabled(enabled);
    if ( mParameters2 )
  mParameters2->setEnabled(enabled);



  mClient->setCurrentItem(mCurrentClient);


  // enable/disable the extra message/parameter field
  if (mCurrentApp == ExternalAppHandler::EMAIL)
  {
  }
  else
  {
  if ( mMessage2 )
    mMessage2->setText( "" );
    if ( mParameters2 )
    mParameters2->setText( "" );
  }

  if (enabled == true) {
  if ( mMessage2 )
    mMessage2->setEnabled(mCurrentApp == ExternalAppHandler::EMAIL);
    if ( mParameters2 )
    mParameters2->setEnabled(mCurrentApp == ExternalAppHandler::EMAIL);
  }


  blockSignals( blocked );

}

void KDEPIMConfigWidget::usrReadConfig()
{
  KPimGlobalPrefs* prefs = KPimGlobalPrefs::instance();

  bool blocked = signalsBlocked();
  blockSignals( true );

  if (KPimGlobalPrefs::instance()->mBackupUseDefaultDir )
      mBackupUrl->setURL( KGlobalSettings::backupDataDir() );
  else {
      mBackupUrl->setURL(prefs->mBackupDatadir);

  }
  mBackupNumbersSpin->setValue( prefs->mBackupNumbers );
  mBackupDayCountSpin->setValue( prefs->mBackupDayCount);

  QString dummy = prefs->mUserDateFormatLong;
  mUserDateFormatLong->setText(dummy.replace( QRegExp("K"), QString(",") ));
  dummy = prefs->mUserDateFormatShort;
  mUserDateFormatShort->setText(dummy.replace( QRegExp("K"), QString(",") ));

  QDate current ( 2001, 1,1);
  mStartDateSavingEdit->setDate(current.addDays(prefs->mDaylightsavingStart-1));
  mEndDateSavingEdit->setDate(current.addDays(prefs->mDaylightsavingEnd-1));
  setCombo(mTimeZoneCombo,i18n(prefs->mTimeZoneId));

  mEmailClient = prefs->mEmailClient;
  mEmailOtherChannel = prefs->mEmailOtherChannel;
  mEmailOtherMessage = prefs->mEmailOtherMessage;
  mEmailOtherMessageParameters = prefs->mEmailOtherMessageParameters;
  mEmailOtherMessage2 = prefs->mEmailOtherMessage2;
  mEmailOtherMessageParameters2 = prefs->mEmailOtherMessageParameters2;

  mPhoneClient = prefs->mPhoneClient;
  mPhoneOtherChannel = prefs->mPhoneOtherChannel;
  mPhoneOtherMessage = prefs->mPhoneOtherMessage;
  mPhoneOtherMessageParameters = prefs->mPhoneOtherMessageParameters;

  mFaxClient = prefs->mFaxClient;
  mFaxOtherChannel = prefs->mFaxOtherChannel;
  mFaxOtherMessage = prefs->mFaxOtherMessage;
  mFaxOtherMessageParameters = prefs->mFaxOtherMessageParameters;

  mSMSClient = prefs->mSMSClient;
  mSMSOtherChannel = prefs->mSMSOtherChannel;
  mSMSOtherMessage = prefs->mSMSOtherMessage;
  mSMSOtherMessageParameters = prefs->mSMSOtherMessageParameters;

  mPagerClient = prefs->mPagerClient;
  mPagerOtherChannel = prefs->mPagerOtherChannel;
  mPagerOtherMessage = prefs->mPagerOtherMessage;
  mPagerOtherMessageParameters = prefs->mPagerOtherMessageParameters;

  mSipClient = prefs->mSipClient;
  mSipOtherChannel = prefs->mSipOtherChannel;
  mSipOtherMessage = prefs->mSipOtherMessage;
  mSipOtherMessageParameters = prefs->mSipOtherMessageParameters;

  mCurrentApp = ExternalAppHandler::EMAIL;
  mCurrentClient = mEmailClient;

  updateClientWidgets();

  blockSignals( blocked );

}

void KDEPIMConfigWidget::usrWriteConfig()
{
  KPimGlobalPrefs* prefs = KPimGlobalPrefs::instance();

  saveEditFieldSettings();

  prefs->mBackupNumbers  = mBackupNumbersSpin->value();
  prefs->mBackupDayCount = mBackupDayCountSpin->value();
  QString bup_url = mBackupUrl->url();
  if ( bup_url.right(1) != "/" && bup_url.right(1) != "\\" )
    bup_url += "/";

  prefs->mBackupDatadir = bup_url;

  prefs->mUserDateFormatShort = mUserDateFormatShort->text().replace( QRegExp(","), QString("K") );
  prefs->mUserDateFormatLong = mUserDateFormatLong->text().replace( QRegExp(","), QString("K") );

  prefs->mTimeZoneId = mTimeZoneCombo->currentText();
  QDate date;
  date = mStartDateSavingEdit->date();
  int sub = 0;
  if ( QDate::leapYear( date.year() ) && date.dayOfYear() > 59 )
      sub = 1;
  prefs->mDaylightsavingStart = date.dayOfYear()-sub;
  date = mEndDateSavingEdit->date();
  if ( QDate::leapYear( date.year() ) && date.dayOfYear() > 59  )
      sub = 1;
  else 
      sub = 0;
  prefs->mDaylightsavingEnd = date.dayOfYear()-sub;


  prefs->mEmailClient = mEmailClient;
  prefs->mEmailOtherChannel = mEmailOtherChannel;
  prefs->mEmailOtherMessage = mEmailOtherMessage;
  prefs->mEmailOtherMessageParameters = mEmailOtherMessageParameters;
  prefs->mEmailOtherMessage2 = mEmailOtherMessage2;
  prefs->mEmailOtherMessageParameters2 = mEmailOtherMessageParameters2;

  prefs->mPhoneClient = mPhoneClient;
  prefs->mPhoneOtherChannel = mPhoneOtherChannel;
  prefs->mPhoneOtherMessage = mPhoneOtherMessage;
  prefs->mPhoneOtherMessageParameters = mPhoneOtherMessageParameters;

  prefs->mFaxClient = mFaxClient;
  prefs->mFaxOtherChannel = mFaxOtherChannel;
  prefs->mFaxOtherMessage = mFaxOtherMessage;
  prefs->mFaxOtherMessageParameters = mFaxOtherMessageParameters;

  prefs->mSMSClient = mSMSClient;
  prefs->mSMSOtherChannel = mSMSOtherChannel;
  prefs->mSMSOtherMessage = mSMSOtherMessage;
  prefs->mSMSOtherMessageParameters = mSMSOtherMessageParameters;

  prefs->mPagerClient = mPagerClient;
  prefs->mPagerOtherChannel = mPagerOtherChannel;
  prefs->mPagerOtherMessage = mPagerOtherMessage;
  prefs->mPagerOtherMessageParameters = mPagerOtherMessageParameters;


  prefs->mSipClient = mSipClient;
  prefs->mSipOtherChannel = mSipOtherChannel;
  prefs->mSipOtherMessage = mSipOtherMessage;
  prefs->mSipOtherMessageParameters = mSipOtherMessageParameters;

  //release the cache that other views can access the changed values instantanious
  ExternalAppHandler::instance()->loadConfig();
  KPimGlobalPrefs::instance()->setGlobalConfig();
}


void KDEPIMConfigWidget::setCombo(QComboBox *combo, const QString & text,
                               const QStringList *tags)
{
  if (tags) {
    int i = tags->findIndex(text);
    if (i > 0) combo->setCurrentItem(i);
  } else {
    for(int i=0;i<combo->count();++i) {
      if (combo->text(i) == text) {
        combo->setCurrentItem(i);
        break;
      }
    }
  }
}


void KDEPIMConfigWidget::textChanged( const QString& text )
{
  emit changed( true );
}