summaryrefslogtreecommitdiffabout
path: root/kabc/syncprefwidget.cpp
authorulf69 <ulf69>2004-08-02 18:35:42 (UTC)
committer ulf69 <ulf69>2004-08-02 18:35:42 (UTC)
commit3379a4f0774ae37f3e53e31f2aece6caa1bdf8f9 (patch) (unidiff)
treeb1ebd91a338ca69c45f9b5a5aa530989181b16f8 /kabc/syncprefwidget.cpp
parent3253686ca101ab27c92fa7a0d372be2d0e07003a (diff)
downloadkdepimpi-3379a4f0774ae37f3e53e31f2aece6caa1bdf8f9.zip
kdepimpi-3379a4f0774ae37f3e53e31f2aece6caa1bdf8f9.tar.gz
kdepimpi-3379a4f0774ae37f3e53e31f2aece6caa1bdf8f9.tar.bz2
a syncwidget, based on zautrix kopi sync-widget that scan be used from inside the "configure resource" dialog.
Diffstat (limited to 'kabc/syncprefwidget.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/syncprefwidget.cpp495
1 files changed, 495 insertions, 0 deletions
diff --git a/kabc/syncprefwidget.cpp b/kabc/syncprefwidget.cpp
new file mode 100644
index 0000000..51a8040
--- a/dev/null
+++ b/kabc/syncprefwidget.cpp
@@ -0,0 +1,495 @@
1/*
2 This file is part of KABC for platform independent KDE tools.
3 Copyright (c) 2004 Ulf Schenk
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/*
25$Id$
26*/
27
28/*US
29#include <qlayout.h>
30#include <qlabel.h>
31#include <qgroupbox.h>
32#include <qbuttongroup.h>
33#include <qlineedit.h>
34#include <qfont.h>
35#include <qslider.h>
36#include <qfile.h>
37#include <qtextstream.h>
38#include <qcombobox.h>
39#include <qvbox.h>
40#include <qhbox.h>
41#include <qspinbox.h>
42#include <qdatetime.h>
43#include <qcheckbox.h>
44#include <qradiobutton.h>
45#include <qpushbutton.h>
46#include <qstrlist.h>
47#include <qapplication.h>
48
49#include <kcolorbutton.h>
50#include <kdebug.h>
51#include <klocale.h>
52#include <kglobal.h>
53#include <kfontdialog.h>
54#include <kmessagebox.h>
55#include <kcolordialog.h>
56#include <kiconloader.h>
57#include <kemailsettings.h>
58#include <kstandarddirs.h>
59#include <kfiledialog.h>
60#include <kmessagebox.h>
61
62#include <kurlrequester.h>
63#include <klineedit.h>
64#include <libkdepim/ksyncprofile.h>
65
66
67#include "koprefs.h"
68
69#include "kosyncprefsdialog.h"
70#include "koglobals.h"
71*/
72
73#include <qlayout.h>
74#include <qbuttongroup.h>
75#include <qcheckbox.h>
76#include <qradiobutton.h>
77#include <qvbox.h>
78#include <qhbox.h>
79#include <qlabel.h>
80#include <qlineedit.h>
81#include <qpushbutton.h>
82
83
84#include <klocale.h>
85#include <kdialog.h>
86
87
88#include "syncprefwidget.h"
89
90
91SyncPrefWidget::SyncPrefWidget(QWidget *parent) :
92 KRES::SyncWidget(parent)
93{
94
95//US setCaption( i18n("Synchronization Preferences"));
96
97//US mSyncProfiles.setAutoDelete( true );
98 init();
99}
100
101
102SyncPrefWidget::~SyncPrefWidget()
103{
104}
105
106//US #include <qlayout.h>
107//US #include <qscrollview.h>
108void SyncPrefWidget::init()
109{
110 QLabel * lab;
111 QPushButton* button;
112
113/*US
114 //QFrame *page = addPage(i18n("Sync Prefs"),0,0);
115 QVBox * mainbox = new QVBox( this );
116 QScrollView* sv = new QScrollView( mainbox );
117 QHBoxLayout * lay = new QHBoxLayout( this );
118 lay->addWidget( mainbox );
119 QHBox * b_box = new QHBox( mainbox );
120*/
121/*US
122 QPushButton* button = new QPushButton( i18n("Ok"), b_box );
123 connect ( button, SIGNAL( clicked()), this, SLOT (slotOK() ) );
124 button = new QPushButton( i18n("Cancel"), b_box );
125 connect ( button, SIGNAL( clicked()), this, SLOT (reject() ) );
126*/
127 //QBoxLayout * sl = new QVBoxLayout(this );
128 //sl->addWidget ( sv );
129/*US
130 sv->setResizePolicy ( QScrollView::AutoOneFit );
131 QFrame *topFrame = new QFrame ( sv );
132 sv->addChild( topFrame );
133 mSetupSyncAlgTab = topFrame;
134 QGridLayout *topLayout = new QGridLayout(topFrame,6,2);
135 topLayout->setSpacing(spacingHint());
136 topLayout->setMargin(marginHint());
137*/
138//US new code for the layout
139 QGridLayout *topLayout = new QGridLayout( this, 6,2 );
140 topLayout->setMargin( KDialog::marginHint() );
141 topLayout->setSpacing( KDialog::spacingHint() );
142
143 //lab = new QLabel(i18n("Sync settings not yet implemented. DO NOT USE!"), topFrame);
144 int iii = 0;
145 //topLayout->addMultiCellWidget(lab , iii,iii,0,1);
146 //++iii;
147
148/*US
149 mMyMachineName = new QLineEdit(topFrame);
150 lab = new QLabel(mMyMachineName, i18n("Local device name:"), topFrame);
151 topLayout->addWidget(lab ,iii,0);
152 topLayout->addWidget(mMyMachineName,iii,1);
153 ++iii;
154
155 QHBox* buttonbox = new QHBox( topFrame);
156 topLayout->addMultiCellWidget(buttonbox, iii,iii,0,1);
157 ++iii;
158 button = new QPushButton( i18n("New profile"), buttonbox );
159 connect ( button, SIGNAL( clicked()), this, SLOT (newProfile() ) );
160
161 button = new QPushButton( i18n("Clone profile"), buttonbox );
162 connect ( button, SIGNAL( clicked()), this, SLOT ( cloneProfile() ) );
163
164 button = new QPushButton( i18n("Delete profile"), buttonbox );
165 connect ( button, SIGNAL( clicked()), this, SLOT (deleteProfile() ) );
166
167 mProfileBox = new QComboBox(topFrame);
168 mProfileBox->setEditable ( true );
169 connect ( mProfileBox, SIGNAL(activated ( int ) ), this, SLOT (profileChanged( int ) ) );
170 connect ( mProfileBox, SIGNAL( textChanged ( const QString & ) ), this, SLOT (textChanged( const QString & ) ) );
171
172 lab = new QLabel(mProfileBox, i18n("Profile:"), topFrame);
173 topLayout->addWidget(lab ,iii,0);
174 topLayout->addWidget(mProfileBox, iii,1);
175 ++iii;
176*/
177 mIncludeInRing = new QCheckBox( i18n("Include in multiple sync"), this );
178 topLayout->addMultiCellWidget(mIncludeInRing, iii,iii,0,1);
179 ++iii;
180
181 mAskForPreferences = new QCheckBox( i18n("Ask for preferences before sync"), this );
182 topLayout->addMultiCellWidget(mAskForPreferences, iii,iii,0,1);
183 ++iii;
184 QButtonGroup* gr = new QButtonGroup ( 1, Qt::Horizontal, i18n("Sync preferences"), this);
185 topLayout->addMultiCellWidget(gr, iii,iii,0,1);
186 ++iii;
187 loc = new QRadioButton ( i18n("Take local entry on conflict"), gr );
188 rem = new QRadioButton ( i18n("Take remote entry on conflict"), gr );
189 newest = new QRadioButton ( i18n("Take newest entry on conflict"), gr );
190 ask = new QRadioButton ( i18n("Ask for every entry on conflict"), gr );
191 f_loc= new QRadioButton ( i18n("Force: Take local entry always"), gr );
192 f_rem = new QRadioButton ( i18n("Force: Take remote entry always"), gr );
193 // both = new QRadioButton ( i18n("Take both on conflict"), gr );
194
195 mShowSummaryAfterSync = new QCheckBox( i18n("Show summary after sync"), this );
196 topLayout->addMultiCellWidget(mShowSummaryAfterSync, iii,iii,0,1);
197 ++iii;
198
199 mWriteBackExisting= new QCheckBox( i18n("Write back existing entries only"), this );
200 topLayout->addMultiCellWidget(mWriteBackExisting, iii,iii,0,1);
201 ++iii;
202
203 mWriteBackFile = new QCheckBox( i18n("Write back file"), this );
204 topLayout->addMultiCellWidget(mWriteBackFile, iii,iii,0,1);
205 ++iii;
206
207 mIsNotLocal = new QCheckBox( i18n("Remote file (w down/upload command)"), this );
208 topLayout->addMultiCellWidget(mIsNotLocal, iii,iii,0,1);
209 connect (mIsNotLocal, SIGNAL( checked(bool)), this, SLOT (kindChanged(bool) ) );
210/*US
211 proGr = new QButtonGroup ( 1, Qt::Horizontal, i18n("Profile kind"), this);
212 gr = proGr;
213 topLayout->addMultiCellWidget(gr, iii,iii,0,1);
214 ++iii;
215 mIsLocal = new QRadioButton ( i18n("Local file"), gr );
216 mIsNotLocal = new QRadioButton ( i18n("Remote file (w down/upload command)"), gr );
217 connect (mIsLocal, SIGNAL( toggled(bool)), this, SLOT (kindChanged(bool) ) );
218*/
219
220/*US
221 localFileWidget = new QVBox( topFrame);
222 topLayout->addMultiCellWidget(localFileWidget, iii,iii,0,1);
223 ++iii;
224 QHBox* temphb = new QHBox( localFileWidget );
225 lab = new QLabel( i18n("Local file:"), temphb);
226 mRemoteFile = new QLineEdit(localFileWidget);
227
228 button = new QPushButton( i18n("Choose..."), temphb );
229 connect ( button, SIGNAL( clicked()), this, SLOT ( chooseFile() ) );
230*/
231 QHBox* temphb;
232
233 remoteFileWidget = new QVBox( this);
234 topLayout->addMultiCellWidget(remoteFileWidget, iii,iii,0,1);
235 ++iii;
236 lab = new QLabel( i18n("Pre sync (download) command:"), remoteFileWidget);
237 mRemotePrecommand = new QLineEdit(remoteFileWidget);
238
239 lab = new QLabel( i18n("Local temp file:"), remoteFileWidget);
240 mLocalTempFile = new QLineEdit(remoteFileWidget);
241
242
243 lab = new QLabel( i18n("Post sync (upload) command:"), remoteFileWidget);
244 mRemotePostcommand = new QLineEdit(remoteFileWidget);
245
246 lab = new QLabel( i18n("Fill in default values for:"), remoteFileWidget);
247 temphb = new QHBox( remoteFileWidget );
248 button = new QPushButton( i18n("ssh/scp"), temphb );
249 connect ( button, SIGNAL( clicked()), this, SLOT (fillSSH() ) );
250 button = new QPushButton( i18n("ftp"), temphb );
251 connect ( button, SIGNAL( clicked()), this, SLOT (fillFTP() ) );
252 lab = new QLabel( i18n("Hint: Use $PWD$ for placeholder of password!"), remoteFileWidget);
253
254
255}
256/*US
257void SyncPrefWidget::slotOK()
258{
259 if ( mMyMachineName->text() == "undefined" ) {
260 KMessageBox::error(this,i18n("Local device name undefined!\nPlease define device name!"),i18n("KO/Pi config error"));
261 return;
262 }
263 int i;
264 for (i = 0; i < mSyncProfileNames.count(); ++ i) {
265 if ( mSyncProfileNames.contains( mSyncProfileNames[i]) > 1 ) {
266 KMessageBox::error(this,i18n("Multiple profiles with same name!\nPlease use unique profile names!"),i18n("KO/Pi config error"));
267 return;
268 }
269 }
270 usrWriteConfig();
271 QDialog::accept();
272}
273void SyncPrefWidget::accept()
274{
275 slotOK();
276}
277void KOSyncPrefsDialog::chooseFile()
278{
279 QString fn =KOPrefs::instance()->mLastSyncedLocalFile;
280
281 fn =KFileDialog:: getOpenFileName( fn, i18n("Sync filename(*.ics/*.vcs)"), this );
282 if ( fn == "" )
283 return;
284 mRemoteFile->setText( fn );
285}
286
287void KOSyncPrefsDialog::textChanged( const QString & s )
288{
289 if ( mProfileBox->count() == 0 )
290 return;
291 if ( currentSelection < 3 ) {
292 //KMessageBox::error(this,i18n("This profil name\ncannot be edited!\n"),i18n("KO/Pi config error"));
293 mProfileBox->blockSignals( true );
294 mProfileBox->setCurrentItem(mProfileBox-> currentItem ());
295 mProfileBox->blockSignals( false );
296 return;
297 }
298 //qDebug("cur i %d ",mProfileBox-> currentItem () );
299 mProfileBox->changeItem ( s, mProfileBox-> currentItem () ) ;
300 KSyncProfile* prof = mSyncProfiles.at(mProfileBox-> currentItem ()) ;
301 prof->setName( s );
302 mSyncProfileNames[mProfileBox-> currentItem ()] = s;
303}
304void KOSyncPrefsDialog::profileChanged( int item )
305{
306 //qDebug("KOSyncPrefsDialog::profileChanged %d ", item );
307 KSyncProfile* prof;
308 saveProfile();
309 currentSelection = item;
310 prof = mSyncProfiles.at(item) ;
311 mRemotePrecommand->setText(prof->getPreSyncCommand());
312 mRemotePostcommand->setText(prof->getPostSyncCommand());
313 mLocalTempFile->setText(prof->getLocalTempFile());
314 mRemoteFile->setText(prof->getRemoteFileName()) ;
315 mShowSummaryAfterSync->setChecked( prof->getShowSummaryAfterSync());
316 mAskForPreferences->setChecked( prof->getAskForPreferences());
317 mWriteBackExisting->setChecked( prof->getWriteBackExisting() );
318 mWriteBackFile->setChecked( prof->getWriteBackFile());
319 mIncludeInRing->setChecked( prof->getIncludeInRingSync() );
320
321 switch ( prof->getSyncPrefs() ) {
322 case 0:
323 loc->setChecked( true);
324 break;
325 case 1:
326 rem->setChecked( true );
327 break;
328 case 2:
329 newest->setChecked( true);
330 break;
331 case 3:
332 ask->setChecked( true);
333 break;
334 case 4:
335 f_loc->setChecked( true);
336 break;
337 case 5:
338 f_rem->setChecked( true);
339 break;
340 case 6:
341 //both->setChecked( true);
342 break;
343 default:
344 break;
345 }
346 mIsLocal->setChecked(prof->getIsLocalFileSync()) ;
347 mIsNotLocal->setChecked(!prof->getIsLocalFileSync());
348 proGr->setEnabled( item > 2 );
349 if ( item < 3 ) {
350 localFileWidget->setEnabled(false);
351 remoteFileWidget->setEnabled(false);
352
353 } else
354 kindChanged( prof->getIsLocalFileSync() );
355}
356
357void KOSyncPrefsDialog::fillSSH()
358{
359 mRemotePrecommand->setText("scp zaurus@192.168.0.65:/home/zaurus/kdepim/apps/korganizer/mycalendar.ics /tmp/mycalendar.ics" );
360 mLocalTempFile->setText("/tmp/mycalendar.ics" );
361 mRemotePostcommand->setText("scp /tmp/mycalendar.ics zaurus@192.168.0.65:/home/zaurus/kdepim/apps/korganizer/mycalendar.ics" );
362}
363void KOSyncPrefsDialog::fillFTP()
364{
365 mRemotePrecommand->setText("cd /tmp;ftp ftp://zaurus:a@192.168.0.65/kdepim/apps/korganizer/mycalendar.ics" );
366 mLocalTempFile->setText("/tmp/mycalendar.ics" );
367 mRemotePostcommand->setText("ftp -u ftp://zaurus:a@192.168.0.65/kdepim/apps/korganizer/mycalendar.ics /tmp/mycalendar.ics" );
368
369}
370void KOSyncPrefsDialog::kindChanged( bool b )
371{
372
373 localFileWidget->setEnabled(b);
374 remoteFileWidget->setEnabled(!b);
375
376}
377void KOSyncPrefsDialog::deleteProfile()
378{
379 //qDebug("KOSyncPrefsDialog::deleteProfile() ");
380 if ( currentSelection >= 0 ) {
381 if ( currentSelection < 3 ) {
382 KMessageBox::error(this,i18n("This profil cannot be deleted!\n"),i18n("KO/Pi config error"));
383 return;
384 }
385 KSyncProfile* temp = mSyncProfiles.at(currentSelection);
386 mSyncProfiles.remove( temp );
387 mSyncProfileNames.remove( mSyncProfileNames.at( currentSelection ));
388 insertProfiles();
389 }
390}
391
392void KOSyncPrefsDialog::saveProfile()
393{
394 KSyncProfile* prof;
395 if ( currentSelection >= 0 ) {
396 prof = mSyncProfiles.at(currentSelection) ;
397 prof->setPreSyncCommand( mRemotePrecommand->text());
398 prof->setPostSyncCommand( mRemotePostcommand->text() );
399 prof->setLocalTempFile( mLocalTempFile->text());
400 prof->setRemoteFileName( mRemoteFile->text() );
401 prof->setShowSummaryAfterSync( mShowSummaryAfterSync->isChecked() );
402 prof->setAskForPreferences( mAskForPreferences->isChecked());
403 prof->setWriteBackExisting(mWriteBackExisting->isChecked() );
404 prof->setWriteBackFile( mWriteBackFile->isChecked());
405 prof->setIncludeInRingSync( mIncludeInRing->isChecked() );
406 int syncprefs = rem->isChecked()*1+newest->isChecked()*2+ ask->isChecked()*3+ f_loc->isChecked()*4+ f_rem->isChecked()*5 ;//+ both->isChecked()*6 ;
407 prof->setSyncPrefs( syncprefs);
408 prof->setIsLocalFileSync( mIsLocal->isChecked() );
409 }
410
411}
412
413void KOSyncPrefsDialog::insertProfiles()
414{
415 int curItem = mProfileBox->currentItem();
416 mProfileBox->blockSignals( true );
417 mProfileBox->clear();
418 mProfileBox->insertStringList (mSyncProfileNames );
419 int item = mSyncProfileNames.count() -1;
420 if ( curItem >= 0 && mSyncProfileNames.count() > 0 && curItem < mSyncProfileNames.count() )
421 mProfileBox->setCurrentItem( curItem );
422 else if ( item >= 0 ) {
423 mProfileBox->setCurrentItem( item );
424 }
425 currentSelection = -1;
426 if ( mSyncProfileNames.count() > 0 ) {
427 //qDebug(" profileChanged( mProfileBox->currentItem() ");
428 profileChanged( mProfileBox->currentItem() );
429 currentSelection = mProfileBox->currentItem();
430 }
431 mProfileBox->blockSignals( false );
432}
433
434void KOSyncPrefsDialog::addProfile ( KSyncProfile* temp )
435{
436 saveProfile();
437 mSyncProfiles.append( temp );
438 mSyncProfileNames << temp->getName();
439 insertProfiles();
440 int last = mProfileBox->count() -1;
441 mProfileBox->blockSignals( true );
442 mProfileBox->setCurrentItem( last );
443 mProfileBox->blockSignals( false );
444 profileChanged(last);
445}
446void KOSyncPrefsDialog::newProfile()
447{
448 addProfile ( new KSyncProfile () );
449}
450
451void KOSyncPrefsDialog::cloneProfile()
452{
453 if ( currentSelection >= 0 )
454 addProfile (mSyncProfiles.at(currentSelection)->clone()) ;
455 else
456 newProfile();
457}
458
459
460void KOSyncPrefsDialog::usrReadConfig()
461{
462 KConfig *config = KOGlobals::config();
463 config->setGroup("SyncProfiles");
464 mSyncProfileNames = KOPrefs::instance()->mSyncProfileNames;
465 int i;
466 KSyncProfile* temp ;
467 mSyncProfiles.clear();
468 for ( i = 0; i < mSyncProfileNames.count();++i ) {
469 temp = new KSyncProfile ();
470 temp->setName( mSyncProfileNames[i] );
471 temp->readConfig( config );
472 mSyncProfiles.append( temp );
473 }
474 insertProfiles();
475 mMyMachineName->setText(KOPrefs::instance()->mLocalMachineName );
476}
477
478
479void KOSyncPrefsDialog::usrWriteConfig()
480{
481 saveProfile();
482 if ( currentSelection >= 0 )
483 profileChanged(currentSelection);
484 KConfig *config = KOGlobals::config();
485 config->setGroup("SyncProfiles");
486 KSyncProfile* prof = mSyncProfiles.first();
487 while ( prof ) {
488 prof->writeConfig(config);
489 prof = mSyncProfiles.next();
490 }
491 KOPrefs::instance()->mSyncProfileNames = mSyncProfileNames;
492 KOPrefs::instance()->mLocalMachineName = mMyMachineName->text();
493 config->writeEntry("SyncProfileNames",&mSyncProfileNames);
494}
495*/