summaryrefslogtreecommitdiffabout
path: root/kabc/syncprefwidget.cpp
authorulf69 <ulf69>2004-08-04 22:45:22 (UTC)
committer ulf69 <ulf69>2004-08-04 22:45:22 (UTC)
commitc3a704f5acda9cf9fee66e5c0b1b864f3b7dd852 (patch) (unidiff)
treedc59744a6d59ba241e793ce051da485d0bf16d06 /kabc/syncprefwidget.cpp
parentb83866e08ddcc5cb2734801977927f48b53a2e1c (diff)
downloadkdepimpi-c3a704f5acda9cf9fee66e5c0b1b864f3b7dd852.zip
kdepimpi-c3a704f5acda9cf9fee66e5c0b1b864f3b7dd852.tar.gz
kdepimpi-c3a704f5acda9cf9fee66e5c0b1b864f3b7dd852.tar.bz2
final changes for addressbook sync config dialog
Diffstat (limited to 'kabc/syncprefwidget.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/syncprefwidget.cpp681
1 files changed, 298 insertions, 383 deletions
diff --git a/kabc/syncprefwidget.cpp b/kabc/syncprefwidget.cpp
index 51a8040..a2bde72 100644
--- a/kabc/syncprefwidget.cpp
+++ b/kabc/syncprefwidget.cpp
@@ -1,495 +1,410 @@
1/* 1/*
2 This file is part of KABC for platform independent KDE tools. 2 This file is part of KABC for platform independent KDE tools.
3 Copyright (c) 2004 Ulf Schenk 3 Copyright (c) 2004 Ulf Schenk
4 4
5 This program is free software; you can redistribute it and/or modify 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 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 7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version. 8 (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details. 13 GNU General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 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 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. 17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 18
19 As a special exception, permission is given to link this program 19 As a special exception, permission is given to link this program
20 with any edition of Qt, and distribute the resulting executable, 20 with any edition of Qt, and distribute the resulting executable,
21 without including the source code for Qt in the source distribution. 21 without including the source code for Qt in the source distribution.
22*/ 22*/
23 23
24/* 24/*
25$Id$ 25$Id$
26*/ 26*/
27 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 28
73#include <qlayout.h> 29#include <qlayout.h>
74#include <qbuttongroup.h> 30#include <qbuttongroup.h>
75#include <qcheckbox.h> 31#include <qcheckbox.h>
76#include <qradiobutton.h> 32#include <qradiobutton.h>
77#include <qvbox.h> 33#include <qvbox.h>
78#include <qhbox.h> 34#include <qhbox.h>
79#include <qlabel.h> 35#include <qlabel.h>
80#include <qlineedit.h> 36#include <qlineedit.h>
81#include <qpushbutton.h> 37#include <qpushbutton.h>
38#include <qscrollview.h>
39#include <qcombobox.h>
82 40
83 41
84#include <klocale.h> 42#include <klocale.h>
85#include <kdialog.h> 43#include <kdialog.h>
86 44
87 45#include "ksyncprofile.h"
46#include "resource.h"
88#include "syncprefwidget.h" 47#include "syncprefwidget.h"
89 48
90 49
91SyncPrefWidget::SyncPrefWidget(QWidget *parent) : 50SyncPrefWidget_Settings::SyncPrefWidget_Settings(QWidget *parent, const char *name) :
92 KRES::SyncWidget(parent) 51 KRES::SyncWidget(parent, name)
93{ 52{
94 53 init();
95//US setCaption( i18n("Synchronization Preferences"));
96
97//US mSyncProfiles.setAutoDelete( true );
98 init();
99} 54}
100 55
101 56
102SyncPrefWidget::~SyncPrefWidget() 57SyncPrefWidget_Settings::~SyncPrefWidget_Settings()
103{ 58{
104} 59}
105 60
106//US #include <qlayout.h> 61void SyncPrefWidget_Settings::init()
107//US #include <qscrollview.h>
108void SyncPrefWidget::init()
109{ 62{
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 ); 63 QGridLayout *topLayout = new QGridLayout( this, 6,2 );
140 topLayout->setMargin( KDialog::marginHint() ); 64 topLayout->setMargin( KDialog::marginHint() );
141 topLayout->setSpacing( KDialog::spacingHint() ); 65 topLayout->setSpacing( KDialog::spacingHint() );
142 66
143 //lab = new QLabel(i18n("Sync settings not yet implemented. DO NOT USE!"), topFrame); 67 int iii = 0;
144 int iii = 0; 68 mIncludeInRing = new QCheckBox( i18n("Include in multiple sync"), this );
145 //topLayout->addMultiCellWidget(lab , iii,iii,0,1); 69 topLayout->addMultiCellWidget(mIncludeInRing, iii,iii,0,1);
146 //++iii; 70 ++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 71
195 mShowSummaryAfterSync = new QCheckBox( i18n("Show summary after sync"), this ); 72 mAskForPreferences = new QCheckBox( i18n("Ask for preferences before sync"), this );
196 topLayout->addMultiCellWidget(mShowSummaryAfterSync, iii,iii,0,1); 73 topLayout->addMultiCellWidget(mAskForPreferences, iii,iii,0,1);
197 ++iii; 74 ++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 75
220/*US 76 mShowSummaryAfterSync = new QCheckBox( i18n("Show summary after sync"), this );
221 localFileWidget = new QVBox( topFrame); 77 topLayout->addMultiCellWidget(mShowSummaryAfterSync, iii,iii,0,1);
222 topLayout->addMultiCellWidget(localFileWidget, iii,iii,0,1); 78 ++iii;
223 ++iii;
224 QHBox* temphb = new QHBox( localFileWidget );
225 lab = new QLabel( i18n("Local file:"), temphb);
226 mRemoteFile = new QLineEdit(localFileWidget);
227 79
228 button = new QPushButton( i18n("Choose..."), temphb ); 80 mWriteBackExisting= new QCheckBox( i18n("Write back existing entries only"), this );
229 connect ( button, SIGNAL( clicked()), this, SLOT ( chooseFile() ) ); 81 topLayout->addMultiCellWidget(mWriteBackExisting, iii,iii,0,1);
230*/ 82 ++iii;
231 QHBox* temphb;
232 83
233 remoteFileWidget = new QVBox( this); 84 mWriteBackFile = new QCheckBox( i18n("Write back synced data"), this );
234 topLayout->addMultiCellWidget(remoteFileWidget, iii,iii,0,1); 85 topLayout->addMultiCellWidget(mWriteBackFile, iii,iii,0,1);
235 ++iii; 86 ++iii;
236 lab = new QLabel( i18n("Pre sync (download) command:"), remoteFileWidget);
237 mRemotePrecommand = new QLineEdit(remoteFileWidget);
238 87
239 lab = new QLabel( i18n("Local temp file:"), remoteFileWidget); 88}
240 mLocalTempFile = new QLineEdit(remoteFileWidget);
241 89
90void SyncPrefWidget_Settings::loadSettings( KRES::Resource *res )
91{
92 KABC::Resource* resource = (KABC::Resource*)( res );
93 KSyncProfile* prof = resource->getSyncProfile();
94
95 if (prof == 0)
96 {
97 qDebug("SyncPrefWidget_Settings::loadSettings: something is wrong, because resource does have no syncprofile" );
98 return;
99 }
100
101 mIncludeInRing->setChecked( prof->getIncludeInRingSync() );
102 mAskForPreferences->setChecked( prof->getAskForPreferences());
103 mShowSummaryAfterSync->setChecked( prof->getShowSummaryAfterSync());
104 mWriteBackExisting->setChecked( prof->getWriteBackExisting() );
105 mWriteBackFile->setChecked( prof->getWriteBackFile());
106}
242 107
243 lab = new QLabel( i18n("Post sync (upload) command:"), remoteFileWidget); 108void SyncPrefWidget_Settings::saveSettings( KRES::Resource *res )
244 mRemotePostcommand = new QLineEdit(remoteFileWidget); 109{
110 KABC::Resource* resource = (KABC::Resource*)( res );
111 KSyncProfile* prof = resource->getSyncProfile();
112
113 if (prof == 0)
114 {
115 qDebug("SyncPrefWidget_Settings::saveSettings: something is wrong, because resource does have no syncprofile" );
116 return;
117 }
118
119 prof->setIncludeInRingSync( mIncludeInRing->isChecked() );
120 prof->setAskForPreferences( mAskForPreferences->isChecked());
121 prof->setShowSummaryAfterSync( mShowSummaryAfterSync->isChecked() );
122 prof->setWriteBackExisting(mWriteBackExisting->isChecked() );
123 prof->setWriteBackFile( mWriteBackFile->isChecked());
124}
245 125
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 126
127/***********************************************************************
128 *
129 *
130 **********************************************************************/
254 131
255} 132SyncPrefWidget_Conflict::SyncPrefWidget_Conflict(QWidget *parent, const char *name) :
256/*US 133 KRES::SyncWidget(parent, name)
257void SyncPrefWidget::slotOK()
258{ 134{
259 if ( mMyMachineName->text() == "undefined" ) { 135 init();
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} 136}
273void SyncPrefWidget::accept() 137
138
139SyncPrefWidget_Conflict::~SyncPrefWidget_Conflict()
274{ 140{
275 slotOK();
276} 141}
277void KOSyncPrefsDialog::chooseFile() 142
143void SyncPrefWidget_Conflict::init()
278{ 144{
279 QString fn =KOPrefs::instance()->mLastSyncedLocalFile; 145 QGridLayout *topLayout = new QGridLayout( this, 6,2 );
146 topLayout->setMargin( KDialog::marginHint() );
147 topLayout->setSpacing( KDialog::spacingHint() );
280 148
281 fn =KFileDialog:: getOpenFileName( fn, i18n("Sync filename(*.ics/*.vcs)"), this ); 149 int iii = 0;
282 if ( fn == "" ) 150
283 return; 151 QButtonGroup* gr = new QButtonGroup ( 1, Qt::Horizontal, i18n("In case of conflicts"), this);
284 mRemoteFile->setText( fn ); 152 topLayout->addMultiCellWidget(gr, iii,iii,0,1);
153 ++iii;
154 loc = new QRadioButton ( i18n("Take local entry on conflict"), gr );
155 rem = new QRadioButton ( i18n("Take remote entry on conflict"), gr );
156 newest = new QRadioButton ( i18n("Take newest entry on conflict"), gr );
157 ask = new QRadioButton ( i18n("Ask for every entry on conflict"), gr );
158 f_loc= new QRadioButton ( i18n("Force: Take local entry always"), gr );
159 f_rem = new QRadioButton ( i18n("Force: Take remote entry always"), gr );
160 // both = new QRadioButton ( i18n("Take both on conflict"), gr );
285} 161}
286 162
287void KOSyncPrefsDialog::textChanged( const QString & s ) 163void SyncPrefWidget_Conflict::loadSettings( KRES::Resource *res )
288{ 164{
289 if ( mProfileBox->count() == 0 ) 165 KABC::Resource* resource = (KABC::Resource*)( res );
290 return; 166 KSyncProfile* prof = resource->getSyncProfile();
291 if ( currentSelection < 3 ) { 167
292 //KMessageBox::error(this,i18n("This profil name\ncannot be edited!\n"),i18n("KO/Pi config error")); 168 if (prof == 0)
293 mProfileBox->blockSignals( true ); 169 {
294 mProfileBox->setCurrentItem(mProfileBox-> currentItem ()); 170 qDebug("SyncPrefWidget_Conflict::loadSettings: something is wrong, because resource does have no syncprofile" );
295 mProfileBox->blockSignals( false ); 171 return;
296 return; 172 }
297 } 173
298 //qDebug("cur i %d ",mProfileBox-> currentItem () ); 174 switch ( prof->getSyncPrefs() ) {
299 mProfileBox->changeItem ( s, mProfileBox-> currentItem () ) ; 175 case 0:
300 KSyncProfile* prof = mSyncProfiles.at(mProfileBox-> currentItem ()) ; 176 loc->setChecked( true);
301 prof->setName( s ); 177 break;
302 mSyncProfileNames[mProfileBox-> currentItem ()] = s; 178 case 1:
179 rem->setChecked( true );
180 break;
181 case 2:
182 newest->setChecked( true);
183 break;
184 case 3:
185 ask->setChecked( true);
186 break;
187 case 4:
188 f_loc->setChecked( true);
189 break;
190 case 5:
191 f_rem->setChecked( true);
192 break;
193 case 6:
194 //both->setChecked( true);
195 break;
196 default:
197 break;
198 }
303} 199}
304void KOSyncPrefsDialog::profileChanged( int item ) 200
201void SyncPrefWidget_Conflict::saveSettings( KRES::Resource *res )
305{ 202{
306 //qDebug("KOSyncPrefsDialog::profileChanged %d ", item ); 203 KABC::Resource* resource = (KABC::Resource*)( res );
307 KSyncProfile* prof; 204 KSyncProfile* prof = resource->getSyncProfile();
308 saveProfile(); 205
309 currentSelection = item; 206 if (prof == 0)
310 prof = mSyncProfiles.at(item) ; 207 {
311 mRemotePrecommand->setText(prof->getPreSyncCommand()); 208 qDebug("SyncPrefWidget_Conftlict::saveSettings: something is wrong, because resource does have no syncprofile" );
312 mRemotePostcommand->setText(prof->getPostSyncCommand()); 209 return;
313 mLocalTempFile->setText(prof->getLocalTempFile()); 210 }
314 mRemoteFile->setText(prof->getRemoteFileName()) ; 211
315 mShowSummaryAfterSync->setChecked( prof->getShowSummaryAfterSync()); 212 int syncprefs = rem->isChecked()*1+newest->isChecked()*2+ ask->isChecked()*3+ f_loc->isChecked()*4+ f_rem->isChecked()*5 ;//+ both->isChecked()*6 ;
316 mAskForPreferences->setChecked( prof->getAskForPreferences()); 213 prof->setSyncPrefs( syncprefs );
317 mWriteBackExisting->setChecked( prof->getWriteBackExisting() ); 214
318 mWriteBackFile->setChecked( prof->getWriteBackFile()); 215}
319 mIncludeInRing->setChecked( prof->getIncludeInRingSync() ); 216
320 217
321 switch ( prof->getSyncPrefs() ) { 218/***********************************************************************
322 case 0: 219 *
323 loc->setChecked( true); 220 *
324 break; 221 **********************************************************************/
325 case 1: 222
326 rem->setChecked( true ); 223SyncPrefWidget_Remote::SyncPrefWidget_Remote(QWidget *parent, const char *name) :
327 break; 224 KRES::SyncWidget(parent, name)
328 case 2: 225{
329 newest->setChecked( true); 226 init();
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} 227}
356 228
357void KOSyncPrefsDialog::fillSSH() 229
230SyncPrefWidget_Remote::~SyncPrefWidget_Remote()
358{ 231{
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} 232}
363void KOSyncPrefsDialog::fillFTP() 233
234void SyncPrefWidget_Remote::init()
364{ 235{
365 mRemotePrecommand->setText("cd /tmp;ftp ftp://zaurus:a@192.168.0.65/kdepim/apps/korganizer/mycalendar.ics" ); 236 QLabel * lab;
366 mLocalTempFile->setText("/tmp/mycalendar.ics" ); 237 QPushButton* button;
367 mRemotePostcommand->setText("ftp -u ftp://zaurus:a@192.168.0.65/kdepim/apps/korganizer/mycalendar.ics /tmp/mycalendar.ics" ); 238
239
240 QGridLayout *topLayout = new QGridLayout( this, 6,2 );
241 topLayout->setMargin( KDialog::marginHint() );
242 topLayout->setSpacing( KDialog::spacingHint() );
243
244 int iii = 0;
245
246 QButtonGroup* gr;
247
248 QButtonGroup *proGr = new QButtonGroup ( 1, Qt::Horizontal, i18n("Profile kind"), this);
249 gr = proGr;
250 topLayout->addMultiCellWidget(gr, iii,iii,0,1);
251 ++iii;
252 mProfileKind = new QComboBox( gr );
253
254 mProfileKind->insertItem( i18n("Local file"), Local );
255 mProfileKind->insertItem( i18n("Remote file (w down/upload cmd)"),Remote );
256 mProfileKind->insertItem( i18n("Mobile device (cell phone)"), Mobile );
257
258 connect( mProfileKind, SIGNAL( activated( int ) ),
259 this, SLOT (kindChanged( int ) ) );
260
261
262 QHBox* temphb;
263
264 remoteFileWidget = new QVBox( this);
265 topLayout->addMultiCellWidget(remoteFileWidget, iii,iii,0,1);
266 ++iii;
267 lab = new QLabel( i18n("Pre sync (download) command:"), remoteFileWidget);
268 mRemotePrecommand = new QLineEdit(remoteFileWidget);
269
270 lab = new QLabel( i18n("Local temp file (=Location):"), remoteFileWidget);
271 mLocalTempFile = new QLineEdit(remoteFileWidget);
272 mLocalTempFile->setEnabled(false);
273
274
275 lab = new QLabel( i18n("Post sync (upload) command:"), remoteFileWidget);
276 mRemotePostcommand = new QLineEdit(remoteFileWidget);
277
278 lab = new QLabel( i18n("Fill in default values for:"), remoteFileWidget);
279 temphb = new QHBox( remoteFileWidget );
280 button = new QPushButton( i18n("ssh/scp"), temphb );
281 connect ( button, SIGNAL( clicked()), this, SLOT (fillSSH() ) );
282 button = new QPushButton( i18n("ftp"), temphb );
283 connect ( button, SIGNAL( clicked()), this, SLOT (fillFTP() ) );
284 lab = new QLabel( i18n("Hint: Use $PWD$ for placeholder of password!"), remoteFileWidget);
368 285
369} 286}
370void KOSyncPrefsDialog::kindChanged( bool b ) 287
288void SyncPrefWidget_Remote::loadSettings( KRES::Resource *res )
371{ 289{
290 KABC::Resource* resource = (KABC::Resource*)( res );
291 KSyncProfile* prof = resource->getSyncProfile();
292
293 if (prof == 0)
294 {
295 qDebug("SyncPrefWidget_Remote::loadSettings: something is wrong, because resource does have no syncprofile" );
296 return;
297 }
372 298
373 localFileWidget->setEnabled(b); 299 int val;
374 remoteFileWidget->setEnabled(!b);
375 300
301 if (prof->getIsPhoneSync())
302 val = Mobile;
303 else if (!prof->getIsLocalFileSync())
304 val = Remote;
305 else // default value
306 val = Local;
307
308 mProfileKind->setCurrentItem( val );
309 kindChanged( val );
310
311
312 mRemotePrecommand->setText(prof->getPreSyncCommand());
313 mLocalTempFile->setText(resource->fileName());
314 mRemotePostcommand->setText(prof->getPostSyncCommand());
376} 315}
377void KOSyncPrefsDialog::deleteProfile() 316
317void SyncPrefWidget_Remote::saveSettings( KRES::Resource *res )
378{ 318{
379 //qDebug("KOSyncPrefsDialog::deleteProfile() "); 319 KABC::Resource* resource = (KABC::Resource*)( res );
380 if ( currentSelection >= 0 ) { 320 KSyncProfile* prof = resource->getSyncProfile();
381 if ( currentSelection < 3 ) { 321
382 KMessageBox::error(this,i18n("This profil cannot be deleted!\n"),i18n("KO/Pi config error")); 322 if (prof == 0)
383 return; 323 {
384 } 324 qDebug("SyncPrefWidget_Remote::saveSettings: something is wrong, because resource does have no syncprofile" );
385 KSyncProfile* temp = mSyncProfiles.at(currentSelection); 325 return;
386 mSyncProfiles.remove( temp ); 326 }
387 mSyncProfileNames.remove( mSyncProfileNames.at( currentSelection )); 327
388 insertProfiles(); 328 int val = mProfileKind->currentItem();
389 } 329
330 if (val == Mobile)
331 {
332 prof->setIsLocalFileSync(true);
333 prof->setIsPhoneSync(true);
334 }
335 else if (val == Remote)
336 {
337 prof->setIsLocalFileSync(false);
338 prof->setIsPhoneSync(false);
339 }
340 else // default value is Local
341 {
342 prof->setIsLocalFileSync(true);
343 prof->setIsPhoneSync(false);
344 }
345
346
347 prof->setPreSyncCommand( mRemotePrecommand->text());
348//US prof->setLocalTempFile( mLocalTempFile->text());
349 prof->setPostSyncCommand( mRemotePostcommand->text() );
390} 350}
391 351
392void KOSyncPrefsDialog::saveProfile() 352
353void SyncPrefWidget_Remote::fillSSH()
393{ 354{
394 KSyncProfile* prof; 355 QString location = mLocalTempFile->text();
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 356
357 mRemotePrecommand->setText("scp zaurus@192.168.0.65:/home/zaurus/kdepim/"+location + " " + location );
358//US mLocalTempFile->setText("/tmp/mycalendar.ics" );
359 mRemotePostcommand->setText("scp " + location + " zaurus@192.168.0.65:/home/zaurus/kdepim/"+location );
411} 360}
412 361
413void KOSyncPrefsDialog::insertProfiles() 362void SyncPrefWidget_Remote::fillFTP()
414{ 363{
415 int curItem = mProfileBox->currentItem(); 364 QString location = mLocalTempFile->text();
416 mProfileBox->blockSignals( true ); 365
417 mProfileBox->clear(); 366 mRemotePrecommand->setText("cd /tmp;ftp ftp://zaurus:a@192.168.0.65/kdepim/" + location );
418 mProfileBox->insertStringList (mSyncProfileNames ); 367//US mLocalTempFile->setText("/tmp/mycalendar.ics" );
419 int item = mSyncProfileNames.count() -1; 368 mRemotePostcommand->setText("ftp -u ftp://zaurus:a@192.168.0.65/kdepim/"+location+ " " + location);
420 if ( curItem >= 0 && mSyncProfileNames.count() > 0 && curItem < mSyncProfileNames.count() ) 369
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} 370}
433 371
434void KOSyncPrefsDialog::addProfile ( KSyncProfile* temp ) 372
373void SyncPrefWidget_Remote::kindChanged( int newKind )
435{ 374{
436 saveProfile(); 375
437 mSyncProfiles.append( temp ); 376 if (newKind == Mobile)
438 mSyncProfileNames << temp->getName(); 377 remoteFileWidget->setEnabled(false);
439 insertProfiles(); 378 else if (newKind == Remote)
440 int last = mProfileBox->count() -1; 379 remoteFileWidget->setEnabled(true);
441 mProfileBox->blockSignals( true ); 380 else // default value is local
442 mProfileBox->setCurrentItem( last ); 381 remoteFileWidget->setEnabled(false);
443 mProfileBox->blockSignals( false ); 382
444 profileChanged(last);
445} 383}
446void KOSyncPrefsDialog::newProfile() 384
385/***********************************************************************
386 *
387 *
388 **********************************************************************/
389
390
391SyncPrefWidgetContainer::SyncPrefWidgetContainer()
392 : SyncWidgetContainer()
447{ 393{
448 addProfile ( new KSyncProfile () );
449} 394}
450 395
451void KOSyncPrefsDialog::cloneProfile() 396KRES::SyncWidget* SyncPrefWidgetContainer::generateSettingsTab(QWidget *parent = 0, const char *name = 0)
452{ 397{
453 if ( currentSelection >= 0 ) 398 return new SyncPrefWidget_Settings(parent, name);
454 addProfile (mSyncProfiles.at(currentSelection)->clone()) ;
455 else
456 newProfile();
457} 399}
458 400
459 401KRES::SyncWidget* SyncPrefWidgetContainer::generateConflictsTab(QWidget *parent = 0, const char *name = 0)
460void KOSyncPrefsDialog::usrReadConfig()
461{ 402{
462 KConfig *config = KOGlobals::config(); 403 return new SyncPrefWidget_Conflict(parent, name);
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} 404}
477 405
478 406KRES::SyncWidget* SyncPrefWidgetContainer::generateRemoteTab(QWidget *parent = 0, const char *name = 0)
479void KOSyncPrefsDialog::usrWriteConfig()
480{ 407{
481 saveProfile(); 408 return new SyncPrefWidget_Remote(parent, name);
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} 409}
495*/ 410