summaryrefslogtreecommitdiffabout
path: root/libkdepim/ksyncprefsdialog.cpp
blob: 6e6e63199d8c50d107d1468b46f4f939676eae87 (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
/*
    This file is part of KOrganizer.
    Copyright (c) 2004 Lutz Rogowski <rogowski@kde.org>

    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.
*/

#include <qlayout.h>
#include <qlabel.h>
#include <qgroupbox.h>
#include <qbuttongroup.h>
#include <qlineedit.h>
#include <qfont.h>
#include <qslider.h>
#include <qfile.h>
#include <qdir.h>
#include <qtextstream.h>
#include <qcombobox.h>
#include <qvbox.h>
#include <qhbox.h>
#include <qspinbox.h>
#include <qdatetime.h>
#include <qcheckbox.h>
#include <qradiobutton.h>
#include <qpushbutton.h>
#include <qstrlist.h>
#include <qapplication.h>
#include <qlayout.h>
#include <qscrollview.h>
 
#include <kcolorbutton.h>
#include <kdebug.h>
#include <klocale.h>
#include <kglobal.h>
#include <kfontdialog.h>
#include <kmessagebox.h>
#include <kcolordialog.h>
#include <kiconloader.h>
#include <kemailsettings.h>
#include <kstandarddirs.h>
#include <kfiledialog.h>
#include <kmessagebox.h>

//#include <kurlrequester.h>
#include <klineedit.h>
#include "ksyncprofile.h"


//#include "koprefs.h"

#include "ksyncprefsdialog.h"
//#include "koglobals.h"


KSyncPrefsDialog::KSyncPrefsDialog(QWidget *parent, char *name, bool modal) :
  KDialog(parent,name,true)
{

  setCaption( i18n("Synchronization Preferences"));

  mSyncProfiles.setAutoDelete( true );
   setupSyncAlgTab();
}


KSyncPrefsDialog::~KSyncPrefsDialog()
{
}
  
void KSyncPrefsDialog::setupSyncAlgTab()
{
  QLabel * lab;
  //QFrame *page = addPage(i18n("Sync Prefs"),0,0);
  QVBox * mainbox = new QVBox( this );
   QScrollView* sv = new QScrollView( mainbox );
   QHBoxLayout * lay = new QHBoxLayout( this );
   lay->addWidget( mainbox );
   QHBox * b_box = new QHBox( mainbox );

   QPushButton* button = new QPushButton( i18n("Ok"), b_box );
   connect ( button, SIGNAL( clicked()), this, SLOT (slotOK() ) );
   button = new QPushButton( i18n("Cancel"), b_box );
   connect ( button, SIGNAL( clicked()), this, SLOT (reject() ) );
   //QBoxLayout * sl = new QVBoxLayout(this );
   //sl->addWidget ( sv );  
   sv->setResizePolicy ( QScrollView::AutoOneFit );
   QFrame *topFrame = new QFrame ( sv );
   sv->addChild( topFrame );
   mSetupSyncAlgTab = topFrame;
   QGridLayout *topLayout = new QGridLayout(topFrame,6,2);
   topLayout->setSpacing(spacingHint());
   topLayout->setMargin(marginHint());  

   //lab = new QLabel(i18n("Sync settings not yet implemented. DO NOT USE!"), topFrame);
   int iii = 0;
   //topLayout->addMultiCellWidget(lab , iii,iii,0,1);
   //++iii;

   mMyMachineName = new QLineEdit(topFrame);
   lab = new QLabel(mMyMachineName, i18n("Local device name:"), topFrame);
   topLayout->addWidget(lab ,iii,0);
   topLayout->addWidget(mMyMachineName,iii,1);
   ++iii;
  
   QHBox* buttonbox = new QHBox( topFrame);
   topLayout->addMultiCellWidget(buttonbox, iii,iii,0,1);
   ++iii;
   button = new QPushButton( i18n("New profile"), buttonbox );
   connect ( button, SIGNAL( clicked()), this, SLOT (newProfile() ) ); 

   button = new QPushButton( i18n("Clone profile"), buttonbox );
   connect ( button, SIGNAL( clicked()), this, SLOT ( cloneProfile() ) );

   button = new QPushButton( i18n("Delete profile"), buttonbox );
   connect ( button, SIGNAL( clicked()), this, SLOT (deleteProfile() ) );

   mProfileBox = new QComboBox(topFrame);
   mProfileBox->setEditable ( true ); 
   connect ( mProfileBox, SIGNAL(activated ( int ) ), this, SLOT (profileChanged( int ) ) );
   connect ( mProfileBox, SIGNAL(  textChanged ( const QString & ) ), this, SLOT (textChanged( const QString & ) ) );
  
   lab = new QLabel(mProfileBox, i18n("Profile:"), topFrame);
   topLayout->addWidget(lab ,iii,0);
   topLayout->addWidget(mProfileBox, iii,1); 
   ++iii;

   mIncludeInRing = new QCheckBox( i18n("Include in multiple calendar sync"), topFrame   );
   topLayout->addMultiCellWidget(mIncludeInRing, iii,iii,0,1);
   ++iii;
   mIncludeInRingAB = new QCheckBox( i18n("Include in multiple addressbook sync"), topFrame   );
   topLayout->addMultiCellWidget(mIncludeInRingAB, iii,iii,0,1);
   ++iii;
   mIncludeInRingPWM = new QCheckBox( i18n("Include in multiple pwmanager sync"), topFrame   );
   topLayout->addMultiCellWidget(mIncludeInRingPWM, iii,iii,0,1);
   ++iii;

   mAskForPreferences = new QCheckBox( i18n("Ask for preferences before sync"), topFrame   );
   topLayout->addMultiCellWidget(mAskForPreferences, iii,iii,0,1);
   ++iii;
    QButtonGroup* gr = new QButtonGroup ( 1,  Qt::Horizontal, i18n("Sync preferences"), topFrame);
   topLayout->addMultiCellWidget(gr, iii,iii,0,1);
   ++iii;
   loc = new QRadioButton ( i18n("Take local entry on conflict"), gr );
   rem = new QRadioButton ( i18n("Take remote entry on conflict"), gr );
   newest = new QRadioButton ( i18n("Take newest entry on conflict"), gr );
   ask = new QRadioButton ( i18n("Ask for every entry on conflict"), gr );
   f_loc= new QRadioButton ( i18n("Force: Take local entry always"), gr );
   f_rem = new QRadioButton ( i18n("Force: Take remote entry always"), gr );
   // both = new QRadioButton ( i18n("Take both on conflict"), gr );

   mShowSummaryAfterSync = new QCheckBox( i18n("Show summary after sync"), topFrame   );
   topLayout->addMultiCellWidget(mShowSummaryAfterSync, iii,iii,0,1);
   ++iii;  

   mWriteBackFile = new QCheckBox( i18n("Write back synced data"), topFrame   );
   topLayout->addMultiCellWidget(mWriteBackFile, iii,iii,0,1);
   ++iii;
   
   mWriteBackExisting= new QCheckBox( i18n("-- Write back (on remote) existing entries only"), topFrame   );
   topLayout->addMultiCellWidget(mWriteBackExisting, iii,iii,0,1);
   ++iii;
 
   mWriteBackFuture= new QCheckBox( i18n("-- Write back (calendar) entries in future only"), topFrame   );
   topLayout->addMultiCellWidget(mWriteBackFuture, iii,iii,0,1);
   ++iii;
   topLayout->addMultiCellWidget(new QLabel( i18n("---- Max. weeks in future: ") , topFrame  ), iii,iii,0,0);
   mWriteBackFutureWeeks= new QSpinBox(1,104, 1, topFrame);
   topLayout->addMultiCellWidget(mWriteBackFutureWeeks, iii,iii,1,1);
   ++iii;
 
   proGr = new QButtonGroup ( 1,  Qt::Horizontal, i18n("Profile kind"), topFrame);
   gr = proGr;
   topLayout->addMultiCellWidget(gr, iii,iii,0,1);
   ++iii;
   mIsLocal = new QRadioButton ( i18n("Local file"), gr );
   mIsNotLocal = new QRadioButton ( i18n("Remote file (w down/upload command)"), gr );
   connect (mIsLocal, SIGNAL( toggled(bool)), this, SLOT (kindChanged(bool) ) ); 
   mIsPhone = new QRadioButton ( i18n("Mobile device (cell phone)"), gr );
   connect (mIsPhone, SIGNAL( toggled(bool)), this, SLOT (kindChanged(bool) ) ); 


   phoneWidget = new QVBox( topFrame);
   topLayout->addMultiCellWidget(phoneWidget, iii,iii,0,1);
   ++iii; 
   mWriteContactToSIM= new QCheckBox( i18n("Sync contacts with phone SIM card (If not, sync with phone memory)"), phoneWidget );
   QHBox* temphb = new QHBox( phoneWidget );
   new QLabel( i18n("I/O device: "), temphb ); 
   mPhoneDevice = new QLineEdit( temphb);
   button = new QPushButton( i18n("Help..."), temphb );
   connect ( button, SIGNAL( clicked()), this, SLOT ( helpDevice() ) );


    temphb = new QHBox( phoneWidget );
   new QLabel( i18n("Connection: "), temphb ); 
   mPhoneConnection = new QLineEdit( temphb);
   button = new QPushButton( i18n("Help..."), temphb );
   connect ( button, SIGNAL( clicked()), this, SLOT ( helpConnection() ) );


    temphb = new QHBox( phoneWidget );
   new QLabel( i18n("Model(opt.): "), temphb ); 
   mPhoneModel = new QLineEdit( temphb);
   button = new QPushButton( i18n("Help..."), temphb );
   connect ( button, SIGNAL( clicked()), this, SLOT ( helpModel() ) );

   // *** local
   localFileWidget = new QVBox( topFrame);
   topLayout->addMultiCellWidget(localFileWidget, iii,iii,0,1);
   ++iii;
   temphb = new QHBox( localFileWidget );

   lab = new QLabel( i18n("Local file Cal:"), temphb );
   lab = new QLabel( i18n("Local file ABook:"), temphb );
   lab = new QLabel( i18n("Local file PWMgr:"), temphb );
   temphb = new QHBox( localFileWidget );
   button = new QPushButton( i18n("Choose..."), temphb );
   connect ( button, SIGNAL( clicked()), this, SLOT ( chooseFile() ) );
   button = new QPushButton( i18n("Choose..."), temphb );
   connect ( button, SIGNAL( clicked()), this, SLOT ( chooseFileAB() ) );
   button = new QPushButton( i18n("Choose..."), temphb );
   connect ( button, SIGNAL( clicked()), this, SLOT ( chooseFilePWM() ) );
   temphb = new QHBox( localFileWidget );

   mRemoteFile = new QLineEdit( temphb);
   mRemoteFileAB = new QLineEdit( temphb);
   mRemoteFilePWM = new QLineEdit( temphb);

   // *** remote
   remoteFileWidget = new QVBox( topFrame);
   topLayout->addMultiCellWidget(remoteFileWidget, iii,iii,0,1);
   ++iii;
   temphb = new QHBox( remoteFileWidget );
   new QLabel( i18n("Calendar:"), temphb);
   new QLabel( i18n("AddressBook:"), temphb);
   new QLabel( i18n("PWManager:"), temphb);

   lab = new QLabel( i18n("Pre sync (download) command:"), remoteFileWidget);
   temphb = new QHBox( remoteFileWidget );
   mRemotePrecommand = new QLineEdit(temphb);
   mRemotePrecommandAB = new QLineEdit(temphb);
   mRemotePrecommandPWM = new QLineEdit(temphb);

   lab = new QLabel( i18n("Local temp file:"), remoteFileWidget);
   temphb = new QHBox( remoteFileWidget );
   mLocalTempFile = new QLineEdit(temphb);
   mLocalTempFileAB = new QLineEdit(temphb);
   mLocalTempFilePWM = new QLineEdit(temphb);

   lab = new QLabel( i18n("Post sync (upload) command:"), remoteFileWidget);
   temphb = new QHBox( remoteFileWidget );
   mRemotePostcommand = new QLineEdit(temphb );
   mRemotePostcommandAB = new QLineEdit(temphb );
   mRemotePostcommandPWM = new QLineEdit(temphb );

   lab = new QLabel( i18n("Fill in default values for:"), remoteFileWidget);
   temphb = new QHBox( remoteFileWidget );
   button = new QPushButton( i18n("ssh/scp"), temphb );
   connect ( button, SIGNAL( clicked()), this, SLOT (fillSSH() ) );
   button = new QPushButton( i18n("ftp"), temphb );
   connect ( button, SIGNAL( clicked()), this, SLOT (fillFTP() ) );
   lab = new QLabel( i18n("Hint: Use $PWD$ for placeholder of password!"), remoteFileWidget);
   

}
void KSyncPrefsDialog::slotOK()
{
    if ( mMyMachineName->text() == "undefined" ) {
        KMessageBox::error(this,i18n("Local device name undefined!\nPlease define device name!"),i18n("KO/Pi config error"));
        return;
    }
    int i;
    for (i = 0; i < mSyncProfileNames.count(); ++ i) {
        if ( mSyncProfileNames.contains( mSyncProfileNames[i]) > 1  ) {
            KMessageBox::error(this,i18n("Multiple profiles with same name!\nPlease use unique profile names!"),i18n("KO/Pi config error"));
            return;
        }
    }
    usrWriteConfig();
    QDialog::accept();
}
void KSyncPrefsDialog::accept()
{
    slotOK();
}
void KSyncPrefsDialog::chooseFile()
{
    QString fn = QDir::homeDirPath();

    fn =KFileDialog:: getOpenFileName( fn, i18n("Sync filename(*.ics/*.vcs)"), this );
    if ( fn == "" )
        return;
    mRemoteFile->setText( fn );
}

void KSyncPrefsDialog::chooseFileAB()
{
    QString fn = QDir::homeDirPath();

    fn =KFileDialog:: getOpenFileName( fn, i18n("Sync filename(*.vcf)"), this );
    if ( fn == "" )
        return;
    mRemoteFileAB->setText( fn );
}

void KSyncPrefsDialog::chooseFilePWM()
{
    QString fn = QDir::homeDirPath();

    fn =KFileDialog:: getOpenFileName( fn, i18n("Sync filename(*.pwm)"), this );
    if ( fn == "" )
        return;
    mRemoteFilePWM->setText( fn );
}

void KSyncPrefsDialog::textChanged( const QString &  s )
{
    if ( mProfileBox->count() == 0 )
        return;
    if ( currentSelection < 3 ) {
        //KMessageBox::error(this,i18n("This profil name\ncannot be edited!\n"),i18n("KO/Pi config error"));
        mProfileBox->blockSignals( true );
        mProfileBox->setCurrentItem(mProfileBox-> currentItem ());
        mProfileBox->blockSignals( false );
        return;
    }
    //qDebug("cur i %d ",mProfileBox-> currentItem () );
    mProfileBox->changeItem ( s, mProfileBox-> currentItem () ) ;
    KSyncProfile* prof = mSyncProfiles.at(mProfileBox-> currentItem ()) ;
    prof->setName( s );
    mSyncProfileNames[mProfileBox-> currentItem ()] = s;
}
void KSyncPrefsDialog::profileChanged( int item )
{
    //qDebug("KSyncPrefsDialog::profileChanged %d ", item ); 
    KSyncProfile* prof;
    saveProfile();
    currentSelection = item;
    prof = mSyncProfiles.at(item) ;
    mRemotePrecommand->setText(prof->getPreSyncCommand());
    mRemotePostcommand->setText(prof->getPostSyncCommand());
    mLocalTempFile->setText(prof->getLocalTempFile());
    mRemoteFile->setText(prof->getRemoteFileName()) ;

    mRemotePrecommandAB->setText(prof->getPreSyncCommandAB());
    mRemotePostcommandAB->setText(prof->getPostSyncCommandAB());
    mLocalTempFileAB->setText(prof->getLocalTempFileAB());
    mRemoteFileAB->setText(prof->getRemoteFileNameAB()) ;

    mRemotePrecommandPWM->setText(prof->getPreSyncCommandPWM());
    mRemotePostcommandPWM->setText(prof->getPostSyncCommandPWM());
    mLocalTempFilePWM->setText(prof->getLocalTempFilePWM());
    mRemoteFilePWM->setText(prof->getRemoteFileNamePWM()) ;

    mWriteContactToSIM->setChecked( prof->getWriteContactToSIM());
    mPhoneDevice->setText(prof->getPhoneDevice());
    mPhoneConnection->setText(prof->getPhoneConnection());
    mPhoneModel->setText(prof->getPhoneModel());

    mShowSummaryAfterSync->setChecked( prof->getShowSummaryAfterSync());
    mAskForPreferences->setChecked( prof->getAskForPreferences());
    mWriteBackExisting->setChecked( prof->getWriteBackExisting() );
    mWriteBackFile->setChecked( prof->getWriteBackFile());
    mIncludeInRing->setChecked( prof->getIncludeInRingSync() );
    mIncludeInRingAB->setChecked( prof->getIncludeInRingSyncAB() );
    mIncludeInRingPWM->setChecked( prof->getIncludeInRingSyncPWM() );
    mWriteBackFuture->setChecked( prof->getWriteBackFuture());
    mWriteBackFutureWeeks->setValue( prof->getWriteBackFutureWeeks() );
    
    switch ( prof->getSyncPrefs() ) {
    case 0:
        loc->setChecked( true);
        break;
    case 1:
        rem->setChecked( true );
        break;
    case 2:
        newest->setChecked( true);
        break;
    case 3:
        ask->setChecked( true);
        break;
    case 4:
        f_loc->setChecked( true);
        break;
    case 5:
        f_rem->setChecked( true);
        break;
    case 6:
        //both->setChecked( true);
        break; 
    default:
        break;
    }
    mIsLocal->setChecked(prof->getIsLocalFileSync()) ;
    mIsPhone->setChecked(prof->getIsPhoneSync()) ;
    mIsNotLocal->setChecked(!prof->getIsLocalFileSync() && !prof->getIsPhoneSync() );
    proGr->setEnabled( item > 2 );
    if ( item < 3 ) {
        localFileWidget->hide();
        remoteFileWidget->hide();
        phoneWidget->hide();

    } else
        kindChanged( prof->getIsLocalFileSync() );
}

void KSyncPrefsDialog::fillSSH()
{
    mRemotePrecommand->setText("scp zaurus@192.168.0.65:/home/zaurus/kdepim/apps/korganizer/mycalendar.ics /tmp/mycalendar.ics" );
    mLocalTempFile->setText("/tmp/mycalendar.ics" );
    mRemotePostcommand->setText("scp /tmp/mycalendar.ics zaurus@192.168.0.65:/home/zaurus/kdepim/apps/korganizer/mycalendar.ics" );
    mRemotePrecommandAB->setText("scp zaurus@192.168.0.65:/home/zaurus/kdepim/apps/kabc/std.vcf /tmp/std.vcf" );
    mLocalTempFileAB->setText("/tmp/std.vcf" );
    mRemotePostcommandAB->setText("scp /tmp/std.vcf zaurus@192.168.0.65:/home/zaurus/kdepim/apps/kabc/std.vcf" );
    mRemotePrecommandPWM->setText("scp zaurus@192.168.0.65:/home/zaurus/kdepim/apps/pwmanager/passwords.pwm /tmp/passwords.pwm" );
    mLocalTempFilePWM->setText("/tmp/passwords.pwm" );
    mRemotePostcommandPWM->setText("scp /tmp/passwords.pwm zaurus@192.168.0.65:/home/zaurus/kdepim/apps/pwmanager/pwmanager.pwm" );
}
void KSyncPrefsDialog::fillFTP()
{
    mRemotePrecommand->setText("cd /tmp;ftp ftp://zaurus:a@192.168.0.65/kdepim/apps/korganizer/mycalendar.ics" );
    mLocalTempFile->setText("/tmp/mycalendar.ics" );
    mRemotePostcommand->setText("ftp -u ftp://zaurus:a@192.168.0.65/kdepim/apps/korganizer/mycalendar.ics /tmp/mycalendar.ics" );
    mRemotePrecommandAB->setText("cd /tmp;ftp ftp://zaurus:a@192.168.0.65/kdepim/apps/kabc/std.vcf" );
    mLocalTempFileAB->setText("/tmp/std.vcf" );
    mRemotePostcommandAB->setText("ftp -u ftp://zaurus:a@192.168.0.65/kdepim/apps/kabc/std.vcf /tmp/std.vcf" );

    mRemotePrecommandPWM->setText("cd /tmp;ftp ftp://zaurus:a@192.168.0.65/kdepim/apps/pwmanager/passwords.pwm" );
    mLocalTempFilePWM->setText("/tmp/passwords.pwm" );
    mRemotePostcommandPWM->setText("ftp -u ftp://zaurus:a@192.168.0.65/kdepim/apps/pwmanager/passwords.pwm /tmp/passwords.pwm" );
   
}
void KSyncPrefsDialog::kindChanged( bool b )
{
  
    if ( mIsLocal->isChecked () )
        localFileWidget->show();
    else
        localFileWidget->hide();

    if ( mIsNotLocal->isChecked () )
        remoteFileWidget->show();
    else
        remoteFileWidget->hide();

    if ( mIsPhone->isChecked () ) {
        phoneWidget->show();
    }
    else {
        phoneWidget->hide();
    }
   
}
void KSyncPrefsDialog::deleteProfile()
{
    //qDebug("KSyncPrefsDialog::deleteProfile() "); 
    if ( currentSelection >= 0 ) {
        if ( currentSelection < 3 ) {
            KMessageBox::error(this,i18n("This profil cannot be deleted!\n"),i18n("KO/Pi config error"));
            return;
        }
        KSyncProfile* temp = mSyncProfiles.at(currentSelection);
        mSyncProfiles.remove( temp );
        mSyncProfileNames.remove( mSyncProfileNames.at( currentSelection ));
        insertProfiles();
    }
}

void KSyncPrefsDialog::saveProfile()
{
    KSyncProfile* prof;
    if ( currentSelection >= 0 ) {
        prof = mSyncProfiles.at(currentSelection) ;
        prof->setPreSyncCommand( mRemotePrecommand->text());
        prof->setPostSyncCommand( mRemotePostcommand->text() );
        prof->setLocalTempFile( mLocalTempFile->text());
        prof->setRemoteFileName( mRemoteFile->text() );
        prof->setPreSyncCommandAB( mRemotePrecommandAB->text());
        prof->setPostSyncCommandAB( mRemotePostcommandAB->text() );
        prof->setLocalTempFileAB( mLocalTempFileAB->text());
        prof->setRemoteFileNameAB( mRemoteFileAB->text() );
        prof->setPreSyncCommandPWM( mRemotePrecommandPWM->text());
        prof->setPostSyncCommandPWM( mRemotePostcommandPWM->text() );
        prof->setLocalTempFilePWM( mLocalTempFilePWM->text());
        prof->setRemoteFileNamePWM( mRemoteFilePWM->text() );
        prof->setShowSummaryAfterSync( mShowSummaryAfterSync->isChecked() );
        prof->setAskForPreferences( mAskForPreferences->isChecked());
        prof->setWriteBackExisting(mWriteBackExisting->isChecked() );
        prof->setWriteBackFile( mWriteBackFile->isChecked());
        prof->setIncludeInRingSync( mIncludeInRing->isChecked() );
        prof->setIncludeInRingSyncAB( mIncludeInRingAB->isChecked() );
        prof->setIncludeInRingSyncPWM( mIncludeInRingPWM->isChecked() );
        int syncprefs = rem->isChecked()*1+newest->isChecked()*2+  ask->isChecked()*3+  f_loc->isChecked()*4+  f_rem->isChecked()*5 ;//+  both->isChecked()*6 ;
        prof->setSyncPrefs( syncprefs);
        prof->setIsLocalFileSync( mIsLocal->isChecked() );
        prof->setIsPhoneSync( mIsPhone->isChecked() );
        prof->setWriteBackFuture(mWriteBackFuture->isChecked());
        prof->setWriteBackFutureWeeks(mWriteBackFutureWeeks->value());

        prof->setWriteContactToSIM(mWriteContactToSIM->isChecked());
        prof->setPhoneDevice(  mPhoneDevice->text() );
        prof->setPhoneConnection(  mPhoneConnection->text() );
        prof->setPhoneModel(  mPhoneModel->text() );

    }

}

void KSyncPrefsDialog::insertProfiles()
{
    int curItem = mProfileBox->currentItem();
    mProfileBox->blockSignals( true );
    mProfileBox->clear();
    mProfileBox->insertStringList (mSyncProfileNames ); 
    int item = mSyncProfileNames.count() -1; 
    if ( curItem >= 0 &&  mSyncProfileNames.count() > 0 && curItem < mSyncProfileNames.count() )
        mProfileBox->setCurrentItem( curItem );  
    else if ( item >= 0 ) {
        mProfileBox->setCurrentItem( item );
    }
    currentSelection = -1;
    if ( mSyncProfileNames.count() > 0 ) {
        //qDebug(" profileChanged( mProfileBox->currentItem()  ");
        profileChanged( mProfileBox->currentItem() );
        currentSelection = mProfileBox->currentItem();
    }
    mProfileBox->blockSignals( false );
}
   
void KSyncPrefsDialog::addProfile ( KSyncProfile* temp )
{
    saveProfile();
    mSyncProfiles.append( temp );
    mSyncProfileNames << temp->getName();
    insertProfiles();
    int last = mProfileBox->count() -1;
    mProfileBox->blockSignals( true );
    mProfileBox->setCurrentItem( last );
    mProfileBox->blockSignals( false );
    profileChanged(last);
}
void KSyncPrefsDialog::newProfile()
{
    addProfile ( new KSyncProfile () );
}

void KSyncPrefsDialog::cloneProfile()
{ 
    if ( currentSelection >= 0 ) 
        addProfile (mSyncProfiles.at(currentSelection)->clone()) ;
    else
        newProfile();
}

void KSyncPrefsDialog::setLocalMachineName ( const QString& name )
{
    mMyMachineName->setText( name );

}
QString KSyncPrefsDialog::getLocalMachineName ( )
{
    return mMyMachineName->text();
}

QStringList KSyncPrefsDialog::getSyncProfileNames()
{
    return mSyncProfileNames;
}
void KSyncPrefsDialog::usrReadConfig()
{ 
    //KConfig *config = KOGlobals::config();
    KConfig config ( locateLocal( "config","ksyncprofilesrc"  ) ); 
    config.setGroup("General");
    mSyncProfileNames =config.readListEntry("SyncProfileNames");
    mMyMachineName->setText(config.readEntry("LocalMachineName","undefined"));
    int i;
    KSyncProfile* temp ;
    mSyncProfiles.clear();
    for ( i = 0; i < mSyncProfileNames.count();++i ) {
        temp = new KSyncProfile ();
        temp->setName( mSyncProfileNames[i] );
        temp->readConfig( &config );
        mSyncProfiles.append( temp );
    }
    insertProfiles();
    //mMyMachineName->setText(KOPrefs::instance()->mLocalMachineName );
}


void KSyncPrefsDialog::usrWriteConfig()
{
    saveProfile();
    if ( currentSelection >= 0 ) 
        profileChanged(currentSelection);
    //KConfig *config = KOGlobals::config();
    KConfig config ( locateLocal( "config","ksyncprofilesrc"  ) ); 
    KSyncProfile* prof = mSyncProfiles.first();
    QStringList externalSyncProfileNames;
    externalSyncProfileNames.append("Sharp_DTM");;
    while ( prof ) {
        prof->writeConfig(&config);
        if ( prof->getIsPhoneSync( ) )
            externalSyncProfileNames.append(prof->getName( ) );
        prof = mSyncProfiles.next();
    }
    //KOPrefs::instance()->mSyncProfileNames = mSyncProfileNames;
    //KOPrefs::instance()->mLocalMachineName = mMyMachineName->text();
    config.setGroup("General");
    config.writeEntry("SyncProfileNames",mSyncProfileNames);
    config.writeEntry("ExternSyncProfiles",externalSyncProfileNames);
    config.writeEntry("LocalMachineName",mMyMachineName->text());
    config.sync();
}

void  KSyncPrefsDialog::helpDevice()
{
    QString hint = i18n("Insert device where\nphone is connected. E.g.:\n");
#ifdef _WIN32_
    hint += "Leave empty for Irda.\n"
        "com1:\n(first serial port)\n"
        "usb not supported\n"
        "???\n(bluetooth device address)\n";

#else
    hint += "/dev/ircomm\n(Irda)\n"
        "/dev/ttyS0\n(first serial port)\n"
        "/dev/ttyUSB0\n(first device usb port)\n"
        "???\n(bluetooth device address)\n";
#endif
    KMessageBox::information(this,hint,i18n("KDE-Pim sync config"));
}
void  KSyncPrefsDialog::helpModel()
{
    QString hint = i18n("Leave empty or\ninsert name of phone model:\n");
    hint += "E.g. for Nokia 6310i:\n6310i\nAlso possible:\nobex\nfor Obex connection";
    KMessageBox::information(this,hint,i18n("KDE-Pim sync config"));

}
void  KSyncPrefsDialog::helpConnection()
{
    QString hint = i18n("Insert kind of connection,e.g.:\n");
    hint += "irda | Nokia FBUS over infrared\n"
        "irdaat | AT commands infrared\n(for Siemens/Sony-Erricsson)\n"
        "irdaobex | set also model as obex\n"
        "fbus | Nokia FBUS2 serial\n";
    KMessageBox::information(this,hint,i18n("KDE-Pim sync config"));
}