summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libkdepim/ksyncprefsdialog.cpp468
-rw-r--r--libkdepim/ksyncprefsdialog.h110
2 files changed, 578 insertions, 0 deletions
diff --git a/libkdepim/ksyncprefsdialog.cpp b/libkdepim/ksyncprefsdialog.cpp
new file mode 100644
index 0000000..8d610d8
--- a/dev/null
+++ b/libkdepim/ksyncprefsdialog.cpp
@@ -0,0 +1,468 @@
1/*
2 This file is part of KOrganizer.
3 Copyright (c) 2004 Lutz Rogowski <rogowski@kde.org>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18
19 As a special exception, permission is given to link this program
20 with any edition of Qt, and distribute the resulting executable,
21 without including the source code for Qt in the source distribution.
22*/
23
24#include <qlayout.h>
25#include <qlabel.h>
26#include <qgroupbox.h>
27#include <qbuttongroup.h>
28#include <qlineedit.h>
29#include <qfont.h>
30#include <qslider.h>
31#include <qfile.h>
32#include <qdir.h>
33#include <qtextstream.h>
34#include <qcombobox.h>
35#include <qvbox.h>
36#include <qhbox.h>
37#include <qspinbox.h>
38#include <qdatetime.h>
39#include <qcheckbox.h>
40#include <qradiobutton.h>
41#include <qpushbutton.h>
42#include <qstrlist.h>
43#include <qapplication.h>
44#include <qlayout.h>
45#include <qscrollview.h>
46
47#include <kcolorbutton.h>
48#include <kdebug.h>
49#include <klocale.h>
50#include <kglobal.h>
51#include <kfontdialog.h>
52#include <kmessagebox.h>
53#include <kcolordialog.h>
54#include <kiconloader.h>
55#include <kemailsettings.h>
56#include <kstandarddirs.h>
57#include <kfiledialog.h>
58#include <kmessagebox.h>
59
60//#include <kurlrequester.h>
61#include <klineedit.h>
62#include "ksyncprofile.h"
63
64
65//#include "koprefs.h"
66
67#include "ksyncprefsdialog.h"
68//#include "koglobals.h"
69
70
71KSyncPrefsDialog::KSyncPrefsDialog(QWidget *parent, char *name, bool modal) :
72 KDialog(parent,name,true)
73{
74
75 setCaption( i18n("Synchronization Preferences"));
76
77 mSyncProfiles.setAutoDelete( true );
78 setupSyncAlgTab();
79}
80
81
82KSyncPrefsDialog::~KSyncPrefsDialog()
83{
84}
85
86void KSyncPrefsDialog::setupSyncAlgTab()
87{
88 QLabel * lab;
89 //QFrame *page = addPage(i18n("Sync Prefs"),0,0);
90 QVBox * mainbox = new QVBox( this );
91 QScrollView* sv = new QScrollView( mainbox );
92 QHBoxLayout * lay = new QHBoxLayout( this );
93 lay->addWidget( mainbox );
94 QHBox * b_box = new QHBox( mainbox );
95
96 QPushButton* button = new QPushButton( i18n("Ok"), b_box );
97 connect ( button, SIGNAL( clicked()), this, SLOT (slotOK() ) );
98 button = new QPushButton( i18n("Cancel"), b_box );
99 connect ( button, SIGNAL( clicked()), this, SLOT (reject() ) );
100 //QBoxLayout * sl = new QVBoxLayout(this );
101 //sl->addWidget ( sv );
102 sv->setResizePolicy ( QScrollView::AutoOneFit );
103 QFrame *topFrame = new QFrame ( sv );
104 sv->addChild( topFrame );
105 mSetupSyncAlgTab = topFrame;
106 QGridLayout *topLayout = new QGridLayout(topFrame,6,2);
107 topLayout->setSpacing(spacingHint());
108 topLayout->setMargin(marginHint());
109
110 //lab = new QLabel(i18n("Sync settings not yet implemented. DO NOT USE!"), topFrame);
111 int iii = 0;
112 //topLayout->addMultiCellWidget(lab , iii,iii,0,1);
113 //++iii;
114
115 mMyMachineName = new QLineEdit(topFrame);
116 lab = new QLabel(mMyMachineName, i18n("Local device name:"), topFrame);
117 topLayout->addWidget(lab ,iii,0);
118 topLayout->addWidget(mMyMachineName,iii,1);
119 ++iii;
120
121 QHBox* buttonbox = new QHBox( topFrame);
122 topLayout->addMultiCellWidget(buttonbox, iii,iii,0,1);
123 ++iii;
124 button = new QPushButton( i18n("New profile"), buttonbox );
125 connect ( button, SIGNAL( clicked()), this, SLOT (newProfile() ) );
126
127 button = new QPushButton( i18n("Clone profile"), buttonbox );
128 connect ( button, SIGNAL( clicked()), this, SLOT ( cloneProfile() ) );
129
130 button = new QPushButton( i18n("Delete profile"), buttonbox );
131 connect ( button, SIGNAL( clicked()), this, SLOT (deleteProfile() ) );
132
133 mProfileBox = new QComboBox(topFrame);
134 mProfileBox->setEditable ( true );
135 connect ( mProfileBox, SIGNAL(activated ( int ) ), this, SLOT (profileChanged( int ) ) );
136 connect ( mProfileBox, SIGNAL( textChanged ( const QString & ) ), this, SLOT (textChanged( const QString & ) ) );
137
138 lab = new QLabel(mProfileBox, i18n("Profile:"), topFrame);
139 topLayout->addWidget(lab ,iii,0);
140 topLayout->addWidget(mProfileBox, iii,1);
141 ++iii;
142
143 mIncludeInRing = new QCheckBox( i18n("Include in multiple sync"), topFrame );
144 topLayout->addMultiCellWidget(mIncludeInRing, iii,iii,0,1);
145 ++iii;
146
147 mAskForPreferences = new QCheckBox( i18n("Ask for preferences before sync"), topFrame );
148 topLayout->addMultiCellWidget(mAskForPreferences, iii,iii,0,1);
149 ++iii;
150 QButtonGroup* gr = new QButtonGroup ( 1, Qt::Horizontal, i18n("Sync preferences"), topFrame);
151 topLayout->addMultiCellWidget(gr, iii,iii,0,1);
152 ++iii;
153 loc = new QRadioButton ( i18n("Take local entry on conflict"), gr );
154 rem = new QRadioButton ( i18n("Take remote entry on conflict"), gr );
155 newest = new QRadioButton ( i18n("Take newest entry on conflict"), gr );
156 ask = new QRadioButton ( i18n("Ask for every entry on conflict"), gr );
157 f_loc= new QRadioButton ( i18n("Force: Take local entry always"), gr );
158 f_rem = new QRadioButton ( i18n("Force: Take remote entry always"), gr );
159 // both = new QRadioButton ( i18n("Take both on conflict"), gr );
160
161 mShowSummaryAfterSync = new QCheckBox( i18n("Show summary after sync"), topFrame );
162 topLayout->addMultiCellWidget(mShowSummaryAfterSync, iii,iii,0,1);
163 ++iii;
164
165 mWriteBackExisting= new QCheckBox( i18n("Write back existing entries only"), topFrame );
166 topLayout->addMultiCellWidget(mWriteBackExisting, iii,iii,0,1);
167 ++iii;
168
169 mWriteBackFile = new QCheckBox( i18n("Write back file"), topFrame );
170 topLayout->addMultiCellWidget(mWriteBackFile, iii,iii,0,1);
171 ++iii;
172
173 proGr = new QButtonGroup ( 1, Qt::Horizontal, i18n("Profile kind"), topFrame);
174 gr = proGr;
175 topLayout->addMultiCellWidget(gr, iii,iii,0,1);
176 ++iii;
177 mIsLocal = new QRadioButton ( i18n("Local file"), gr );
178 mIsNotLocal = new QRadioButton ( i18n("Remote file (w down/upload command)"), gr );
179 connect (mIsLocal, SIGNAL( toggled(bool)), this, SLOT (kindChanged(bool) ) );
180
181 localFileWidget = new QVBox( topFrame);
182 topLayout->addMultiCellWidget(localFileWidget, iii,iii,0,1);
183 ++iii;
184 QHBox* temphb = new QHBox( localFileWidget );
185 lab = new QLabel( i18n("Local file:"), temphb);
186 mRemoteFile = new QLineEdit(localFileWidget);
187
188 button = new QPushButton( i18n("Choose..."), temphb );
189 connect ( button, SIGNAL( clicked()), this, SLOT ( chooseFile() ) );
190
191
192 remoteFileWidget = new QVBox( topFrame);
193 topLayout->addMultiCellWidget(remoteFileWidget, iii,iii,0,1);
194 ++iii;
195 lab = new QLabel( i18n("Pre sync (download) command:"), remoteFileWidget);
196 mRemotePrecommand = new QLineEdit(remoteFileWidget);
197
198 lab = new QLabel( i18n("Local temp file:"), remoteFileWidget);
199 mLocalTempFile = new QLineEdit(remoteFileWidget);
200
201
202 lab = new QLabel( i18n("Post sync (upload) command:"), remoteFileWidget);
203 mRemotePostcommand = new QLineEdit(remoteFileWidget);
204
205 lab = new QLabel( i18n("Fill in default values for:"), remoteFileWidget);
206 temphb = new QHBox( remoteFileWidget );
207 button = new QPushButton( i18n("ssh/scp"), temphb );
208 connect ( button, SIGNAL( clicked()), this, SLOT (fillSSH() ) );
209 button = new QPushButton( i18n("ftp"), temphb );
210 connect ( button, SIGNAL( clicked()), this, SLOT (fillFTP() ) );
211 lab = new QLabel( i18n("Hint: Use $PWD$ for placeholder of password!"), remoteFileWidget);
212
213
214}
215void KSyncPrefsDialog::slotOK()
216{
217 if ( mMyMachineName->text() == "undefined" ) {
218 KMessageBox::error(this,i18n("Local device name undefined!\nPlease define device name!"),i18n("KO/Pi config error"));
219 return;
220 }
221 int i;
222 for (i = 0; i < mSyncProfileNames.count(); ++ i) {
223 if ( mSyncProfileNames.contains( mSyncProfileNames[i]) > 1 ) {
224 KMessageBox::error(this,i18n("Multiple profiles with same name!\nPlease use unique profile names!"),i18n("KO/Pi config error"));
225 return;
226 }
227 }
228 usrWriteConfig();
229 QDialog::accept();
230}
231void KSyncPrefsDialog::accept()
232{
233 slotOK();
234}
235void KSyncPrefsDialog::chooseFile()
236{
237 QString fn = QDir::homeDirPath();
238
239 fn =KFileDialog:: getOpenFileName( fn, i18n("Sync filename(*.ics/*.vcs)"), this );
240 if ( fn == "" )
241 return;
242 mRemoteFile->setText( fn );
243}
244
245void KSyncPrefsDialog::textChanged( const QString & s )
246{
247 if ( mProfileBox->count() == 0 )
248 return;
249 if ( currentSelection < 3 ) {
250 //KMessageBox::error(this,i18n("This profil name\ncannot be edited!\n"),i18n("KO/Pi config error"));
251 mProfileBox->blockSignals( true );
252 mProfileBox->setCurrentItem(mProfileBox-> currentItem ());
253 mProfileBox->blockSignals( false );
254 return;
255 }
256 //qDebug("cur i %d ",mProfileBox-> currentItem () );
257 mProfileBox->changeItem ( s, mProfileBox-> currentItem () ) ;
258 KSyncProfile* prof = mSyncProfiles.at(mProfileBox-> currentItem ()) ;
259 prof->setName( s );
260 mSyncProfileNames[mProfileBox-> currentItem ()] = s;
261}
262void KSyncPrefsDialog::profileChanged( int item )
263{
264 //qDebug("KSyncPrefsDialog::profileChanged %d ", item );
265 KSyncProfile* prof;
266 saveProfile();
267 currentSelection = item;
268 prof = mSyncProfiles.at(item) ;
269 mRemotePrecommand->setText(prof->getPreSyncCommand());
270 mRemotePostcommand->setText(prof->getPostSyncCommand());
271 mLocalTempFile->setText(prof->getLocalTempFile());
272 mRemoteFile->setText(prof->getRemoteFileName()) ;
273 mShowSummaryAfterSync->setChecked( prof->getShowSummaryAfterSync());
274 mAskForPreferences->setChecked( prof->getAskForPreferences());
275 mWriteBackExisting->setChecked( prof->getWriteBackExisting() );
276 mWriteBackFile->setChecked( prof->getWriteBackFile());
277 mIncludeInRing->setChecked( prof->getIncludeInRingSync() );
278
279 switch ( prof->getSyncPrefs() ) {
280 case 0:
281 loc->setChecked( true);
282 break;
283 case 1:
284 rem->setChecked( true );
285 break;
286 case 2:
287 newest->setChecked( true);
288 break;
289 case 3:
290 ask->setChecked( true);
291 break;
292 case 4:
293 f_loc->setChecked( true);
294 break;
295 case 5:
296 f_rem->setChecked( true);
297 break;
298 case 6:
299 //both->setChecked( true);
300 break;
301 default:
302 break;
303 }
304 mIsLocal->setChecked(prof->getIsLocalFileSync()) ;
305 mIsNotLocal->setChecked(!prof->getIsLocalFileSync());
306 proGr->setEnabled( item > 2 );
307 if ( item < 3 ) {
308 localFileWidget->setEnabled(false);
309 remoteFileWidget->setEnabled(false);
310
311 } else
312 kindChanged( prof->getIsLocalFileSync() );
313}
314
315void KSyncPrefsDialog::fillSSH()
316{
317 mRemotePrecommand->setText("scp zaurus@192.168.0.65:/home/zaurus/kdepim/apps/korganizer/mycalendar.ics /tmp/mycalendar.ics" );
318 mLocalTempFile->setText("/tmp/mycalendar.ics" );
319 mRemotePostcommand->setText("scp /tmp/mycalendar.ics zaurus@192.168.0.65:/home/zaurus/kdepim/apps/korganizer/mycalendar.ics" );
320}
321void KSyncPrefsDialog::fillFTP()
322{
323 mRemotePrecommand->setText("cd /tmp;ftp ftp://zaurus:a@192.168.0.65/kdepim/apps/korganizer/mycalendar.ics" );
324 mLocalTempFile->setText("/tmp/mycalendar.ics" );
325 mRemotePostcommand->setText("ftp -u ftp://zaurus:a@192.168.0.65/kdepim/apps/korganizer/mycalendar.ics /tmp/mycalendar.ics" );
326
327}
328void KSyncPrefsDialog::kindChanged( bool b )
329{
330
331 localFileWidget->setEnabled(b);
332 remoteFileWidget->setEnabled(!b);
333
334}
335void KSyncPrefsDialog::deleteProfile()
336{
337 //qDebug("KSyncPrefsDialog::deleteProfile() ");
338 if ( currentSelection >= 0 ) {
339 if ( currentSelection < 3 ) {
340 KMessageBox::error(this,i18n("This profil cannot be deleted!\n"),i18n("KO/Pi config error"));
341 return;
342 }
343 KSyncProfile* temp = mSyncProfiles.at(currentSelection);
344 mSyncProfiles.remove( temp );
345 mSyncProfileNames.remove( mSyncProfileNames.at( currentSelection ));
346 insertProfiles();
347 }
348}
349
350void KSyncPrefsDialog::saveProfile()
351{
352 KSyncProfile* prof;
353 if ( currentSelection >= 0 ) {
354 prof = mSyncProfiles.at(currentSelection) ;
355 prof->setPreSyncCommand( mRemotePrecommand->text());
356 prof->setPostSyncCommand( mRemotePostcommand->text() );
357 prof->setLocalTempFile( mLocalTempFile->text());
358 prof->setRemoteFileName( mRemoteFile->text() );
359 prof->setShowSummaryAfterSync( mShowSummaryAfterSync->isChecked() );
360 prof->setAskForPreferences( mAskForPreferences->isChecked());
361 prof->setWriteBackExisting(mWriteBackExisting->isChecked() );
362 prof->setWriteBackFile( mWriteBackFile->isChecked());
363 prof->setIncludeInRingSync( mIncludeInRing->isChecked() );
364 int syncprefs = rem->isChecked()*1+newest->isChecked()*2+ ask->isChecked()*3+ f_loc->isChecked()*4+ f_rem->isChecked()*5 ;//+ both->isChecked()*6 ;
365 prof->setSyncPrefs( syncprefs);
366 prof->setIsLocalFileSync( mIsLocal->isChecked() );
367 }
368
369}
370
371void KSyncPrefsDialog::insertProfiles()
372{
373 int curItem = mProfileBox->currentItem();
374 mProfileBox->blockSignals( true );
375 mProfileBox->clear();
376 mProfileBox->insertStringList (mSyncProfileNames );
377 int item = mSyncProfileNames.count() -1;
378 if ( curItem >= 0 && mSyncProfileNames.count() > 0 && curItem < mSyncProfileNames.count() )
379 mProfileBox->setCurrentItem( curItem );
380 else if ( item >= 0 ) {
381 mProfileBox->setCurrentItem( item );
382 }
383 currentSelection = -1;
384 if ( mSyncProfileNames.count() > 0 ) {
385 //qDebug(" profileChanged( mProfileBox->currentItem() ");
386 profileChanged( mProfileBox->currentItem() );
387 currentSelection = mProfileBox->currentItem();
388 }
389 mProfileBox->blockSignals( false );
390}
391
392void KSyncPrefsDialog::addProfile ( KSyncProfile* temp )
393{
394 saveProfile();
395 mSyncProfiles.append( temp );
396 mSyncProfileNames << temp->getName();
397 insertProfiles();
398 int last = mProfileBox->count() -1;
399 mProfileBox->blockSignals( true );
400 mProfileBox->setCurrentItem( last );
401 mProfileBox->blockSignals( false );
402 profileChanged(last);
403}
404void KSyncPrefsDialog::newProfile()
405{
406 addProfile ( new KSyncProfile () );
407}
408
409void KSyncPrefsDialog::cloneProfile()
410{
411 if ( currentSelection >= 0 )
412 addProfile (mSyncProfiles.at(currentSelection)->clone()) ;
413 else
414 newProfile();
415}
416
417void KSyncPrefsDialog::setLocalMachineName ( const QString& name )
418{
419 mMyMachineName->setText( name );
420
421}
422QString KSyncPrefsDialog::getLocalMachineName ( )
423{
424 return mMyMachineName->text();
425}
426
427QStringList KSyncPrefsDialog::getSyncProfileNames()
428{
429 return mSyncProfileNames;
430}
431void KSyncPrefsDialog::usrReadConfig()
432{
433 //KConfig *config = KOGlobals::config();
434 KConfig config ( locateLocal( "config","syncprofilesrc" ) );
435 config.setGroup("SyncProfiles");
436 mSyncProfileNames =config.readListEntry("SyncProfileNames");
437 int i;
438 KSyncProfile* temp ;
439 mSyncProfiles.clear();
440 for ( i = 0; i < mSyncProfileNames.count();++i ) {
441 temp = new KSyncProfile ();
442 temp->setName( mSyncProfileNames[i] );
443 temp->readConfig( &config );
444 mSyncProfiles.append( temp );
445 }
446 insertProfiles();
447 //mMyMachineName->setText(KOPrefs::instance()->mLocalMachineName );
448}
449
450
451void KSyncPrefsDialog::usrWriteConfig()
452{
453 saveProfile();
454 if ( currentSelection >= 0 )
455 profileChanged(currentSelection);
456 //KConfig *config = KOGlobals::config();
457 KConfig config ( locateLocal( "config","syncprofilesrc" ) );
458 config.setGroup("SyncProfiles");
459 KSyncProfile* prof = mSyncProfiles.first();
460 while ( prof ) {
461 prof->writeConfig(&config);
462 prof = mSyncProfiles.next();
463 }
464 //KOPrefs::instance()->mSyncProfileNames = mSyncProfileNames;
465 //KOPrefs::instance()->mLocalMachineName = mMyMachineName->text();
466 config.writeEntry("SyncProfileNames",&mSyncProfileNames);
467}
468
diff --git a/libkdepim/ksyncprefsdialog.h b/libkdepim/ksyncprefsdialog.h
new file mode 100644
index 0000000..90fa286
--- a/dev/null
+++ b/libkdepim/ksyncprefsdialog.h
@@ -0,0 +1,110 @@
1/*
2 This file is part of KOrganizer.
3 Copyright (c) 2000,2001 Cornelius Schumacher <schumacher@kde.org>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18
19 As a special exception, permission is given to link this program
20 with any edition of Qt, and distribute the resulting executable,
21 without including the source code for Qt in the source distribution.
22*/
23#ifndef _KSYNCPREFSDIALOG_H
24#define _KSYNCPREFSDIALOG_H
25
26
27#include <kdialogbase.h>
28#include <qptrlist.h>
29
30//#include <libkdepim/kprefsdialog.h>
31
32class KColorButton;
33class QSpinBox;;
34class QRadioButton;
35class QCheckBox;
36class QSlider;
37class KURLRequester;
38class QComboBox;
39class QButtonGroup;
40class QLineEdit;
41class QVBox;
42class QStringList;
43class KSyncProfile;
44
45/** Dialog to change the korganizer configuration.
46 */
47class KSyncPrefsDialog : public KDialog
48{
49 Q_OBJECT
50 public:
51 /** Initialize dialog and pages */
52 KSyncPrefsDialog(QWidget *parent=0,char *name=0,bool modal=false);
53 ~KSyncPrefsDialog();
54 void usrReadConfig();
55 void setLocalMachineName ( const QString& name );
56 QString getLocalMachineName ( );
57
58 QStringList getSyncProfileNames();
59
60 public slots:
61 protected slots:
62 void accept();
63 void deleteProfile();
64 void newProfile();
65 void cloneProfile();
66 void kindChanged(bool);
67 void fillSSH();
68 void fillFTP();
69 void textChanged( const QString & );
70 void profileChanged( int );
71 void chooseFile();
72 void slotOK();
73
74 protected:
75 void usrWriteConfig();
76
77 void setupSyncAlgTab();
78
79 private:
80 int currentSelection;
81 QPtrList<KSyncProfile> mSyncProfiles;
82 QStringList mSyncProfileNames;
83 QLineEdit * mMyMachineName;
84 QComboBox * mProfileBox;
85 QRadioButton* mIsLocal;
86 QRadioButton* mIsNotLocal;
87 QCheckBox* mIncludeInRing;
88 void addProfile ( KSyncProfile* );
89 void insertProfiles();
90 void saveProfile();
91 QButtonGroup* proGr;
92
93 QRadioButton* loc, *rem, *newest, *ask, *f_loc,* f_rem, *both;
94
95
96 QLineEdit * mRemotePostcommand;
97 QLineEdit * mRemotePrecommand;
98 QLineEdit * mRemoteFile;
99 QLineEdit * mLocalTempFile;
100 QWidget* mSetupSyncAlgTab;
101
102 QVBox* localFileWidget;
103 QVBox* remoteFileWidget;
104 QCheckBox* mWriteBackFile;
105 QCheckBox* mWriteBackExisting;
106 QCheckBox* mAskForPreferences;
107 QCheckBox* mShowSummaryAfterSync;
108};
109
110#endif