summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/calendarview.cpp11
-rw-r--r--libkdepim/ksyncmanager.cpp16
-rw-r--r--libkdepim/ksyncmanager.h1
3 files changed, 24 insertions, 4 deletions
diff --git a/korganizer/calendarview.cpp b/korganizer/calendarview.cpp
index a08f243..326db88 100644
--- a/korganizer/calendarview.cpp
+++ b/korganizer/calendarview.cpp
@@ -161,1539 +161,1546 @@ class KOBeamPrefs : public QDialog
161 tz->setChecked( true ); 161 tz->setChecked( true );
162 QPushButton * ok = new QPushButton( i18n("Beam via IR!"), this ); 162 QPushButton * ok = new QPushButton( i18n("Beam via IR!"), this );
163 lay->addWidget( ok ); 163 lay->addWidget( ok );
164 QPushButton * cancel = new QPushButton( i18n("Cancel"), this ); 164 QPushButton * cancel = new QPushButton( i18n("Cancel"), this );
165 lay->addWidget( cancel ); 165 lay->addWidget( cancel );
166 connect ( ok,SIGNAL(clicked() ),this , SLOT ( accept() ) ); 166 connect ( ok,SIGNAL(clicked() ),this , SLOT ( accept() ) );
167 connect (cancel, SIGNAL(clicked() ), this, SLOT ( reject()) ); 167 connect (cancel, SIGNAL(clicked() ), this, SLOT ( reject()) );
168 resize( 200, 200 ); 168 resize( 200, 200 );
169 } 169 }
170 170
171 bool beamVcal() { return vcal->isChecked(); } 171 bool beamVcal() { return vcal->isChecked(); }
172 bool beamLocal() { return local->isChecked(); } 172 bool beamLocal() { return local->isChecked(); }
173private: 173private:
174 QRadioButton* vcal, *ical, *local, *tz; 174 QRadioButton* vcal, *ical, *local, *tz;
175}; 175};
176class KOCatPrefs : public QDialog 176class KOCatPrefs : public QDialog
177{ 177{
178 public: 178 public:
179 KOCatPrefs( QWidget *parent=0, const char *name=0 ) : 179 KOCatPrefs( QWidget *parent=0, const char *name=0 ) :
180 QDialog( parent, name, true ) 180 QDialog( parent, name, true )
181 { 181 {
182 setCaption( i18n("Manage new Categories") ); 182 setCaption( i18n("Manage new Categories") );
183 QVBoxLayout* lay = new QVBoxLayout( this ); 183 QVBoxLayout* lay = new QVBoxLayout( this );
184 lay->setSpacing( 3 ); 184 lay->setSpacing( 3 );
185 lay->setMargin( 3 ); 185 lay->setMargin( 3 );
186 QLabel * lab = new QLabel( i18n("After importing/loading/syncing\nthere may be new categories in\nevents or todos\nwhich are not in the category list.\nPlease choose what to do:\n "), this ); 186 QLabel * lab = new QLabel( i18n("After importing/loading/syncing\nthere may be new categories in\nevents or todos\nwhich are not in the category list.\nPlease choose what to do:\n "), this );
187 lay->addWidget( lab ); 187 lay->addWidget( lab );
188 QButtonGroup* format = new QButtonGroup( 1, Horizontal, i18n("New categories not in list:"), this ); 188 QButtonGroup* format = new QButtonGroup( 1, Horizontal, i18n("New categories not in list:"), this );
189 lay->addWidget( format ); 189 lay->addWidget( format );
190 format->setExclusive ( true ) ; 190 format->setExclusive ( true ) ;
191 addCatBut = new QRadioButton(i18n("Add to category list"), format ); 191 addCatBut = new QRadioButton(i18n("Add to category list"), format );
192 new QRadioButton(i18n("Remove from Events/Todos"), format ); 192 new QRadioButton(i18n("Remove from Events/Todos"), format );
193 addCatBut->setChecked( true ); 193 addCatBut->setChecked( true );
194 QPushButton * ok = new QPushButton( i18n("OK"), this ); 194 QPushButton * ok = new QPushButton( i18n("OK"), this );
195 lay->addWidget( ok ); 195 lay->addWidget( ok );
196 QPushButton * cancel = new QPushButton( i18n("Cancel"), this ); 196 QPushButton * cancel = new QPushButton( i18n("Cancel"), this );
197 lay->addWidget( cancel ); 197 lay->addWidget( cancel );
198 connect ( ok,SIGNAL(clicked() ),this , SLOT ( accept() ) ); 198 connect ( ok,SIGNAL(clicked() ),this , SLOT ( accept() ) );
199 connect (cancel, SIGNAL(clicked() ), this, SLOT ( reject()) ); 199 connect (cancel, SIGNAL(clicked() ), this, SLOT ( reject()) );
200 resize( 200, 200 ); 200 resize( 200, 200 );
201 } 201 }
202 202
203 bool addCat() { return addCatBut->isChecked(); } 203 bool addCat() { return addCatBut->isChecked(); }
204private: 204private:
205 QRadioButton* addCatBut; 205 QRadioButton* addCatBut;
206}; 206};
207 207
208 208
209 209
210CalendarView::CalendarView( CalendarResources *calendar, 210CalendarView::CalendarView( CalendarResources *calendar,
211 QWidget *parent, const char *name ) 211 QWidget *parent, const char *name )
212 : CalendarViewBase( parent, name ), 212 : CalendarViewBase( parent, name ),
213 mCalendar( calendar ), 213 mCalendar( calendar ),
214 mResourceManager( calendar->resourceManager() ) 214 mResourceManager( calendar->resourceManager() )
215{ 215{
216 216
217 mEventEditor = 0; 217 mEventEditor = 0;
218 mTodoEditor = 0; 218 mTodoEditor = 0;
219 219
220 init(); 220 init();
221} 221}
222 222
223CalendarView::CalendarView( Calendar *calendar, 223CalendarView::CalendarView( Calendar *calendar,
224 QWidget *parent, const char *name ) 224 QWidget *parent, const char *name )
225 : CalendarViewBase( parent, name ), 225 : CalendarViewBase( parent, name ),
226 mCalendar( calendar ), 226 mCalendar( calendar ),
227 mResourceManager( 0 ) 227 mResourceManager( 0 )
228{ 228{
229 229
230 mEventEditor = 0; 230 mEventEditor = 0;
231 mTodoEditor = 0; 231 mTodoEditor = 0;
232 init();} 232 init();}
233 233
234void CalendarView::init() 234void CalendarView::init()
235{ 235{
236 beamDialog = new KOBeamPrefs(); 236 beamDialog = new KOBeamPrefs();
237 mDatePickerMode = 0; 237 mDatePickerMode = 0;
238 mCurrentSyncDevice = ""; 238 mCurrentSyncDevice = "";
239 writeLocale(); 239 writeLocale();
240 mViewManager = new KOViewManager( this ); 240 mViewManager = new KOViewManager( this );
241 mDialogManager = new KODialogManager( this ); 241 mDialogManager = new KODialogManager( this );
242 mEventViewerDialog = 0; 242 mEventViewerDialog = 0;
243 mModified = false; 243 mModified = false;
244 mReadOnly = false; 244 mReadOnly = false;
245 mSelectedIncidence = 0; 245 mSelectedIncidence = 0;
246 mCalPrinter = 0; 246 mCalPrinter = 0;
247 mFilters.setAutoDelete(true); 247 mFilters.setAutoDelete(true);
248 248
249 mCalendar->registerObserver( this ); 249 mCalendar->registerObserver( this );
250 // TODO: Make sure that view is updated, when calendar is changed. 250 // TODO: Make sure that view is updated, when calendar is changed.
251 251
252 mStorage = new FileStorage( mCalendar ); 252 mStorage = new FileStorage( mCalendar );
253 mNavigator = new DateNavigator( this, "datevav", mViewManager ); 253 mNavigator = new DateNavigator( this, "datevav", mViewManager );
254 254
255 QBoxLayout *topLayout = (QBoxLayout*)layout(); 255 QBoxLayout *topLayout = (QBoxLayout*)layout();
256#ifndef KORG_NOSPLITTER 256#ifndef KORG_NOSPLITTER
257 // create the main layout frames. 257 // create the main layout frames.
258 mPanner = new QSplitter(QSplitter::Horizontal,this,"CalendarView::Panner"); 258 mPanner = new QSplitter(QSplitter::Horizontal,this,"CalendarView::Panner");
259 topLayout->addWidget(mPanner); 259 topLayout->addWidget(mPanner);
260 260
261 mLeftSplitter = new QSplitter(QSplitter::Vertical,mPanner, 261 mLeftSplitter = new QSplitter(QSplitter::Vertical,mPanner,
262 "CalendarView::LeftFrame"); 262 "CalendarView::LeftFrame");
263 mPanner->setResizeMode(mLeftSplitter,QSplitter::KeepSize); 263 mPanner->setResizeMode(mLeftSplitter,QSplitter::KeepSize);
264 264
265 mDateNavigator = new KDateNavigator(mLeftSplitter, mCalendar, TRUE, 265 mDateNavigator = new KDateNavigator(mLeftSplitter, mCalendar, TRUE,
266 "CalendarView::DateNavigator", QDate::currentDate() ); 266 "CalendarView::DateNavigator", QDate::currentDate() );
267 mLeftSplitter->setResizeMode(mDateNavigator,QSplitter::KeepSize); 267 mLeftSplitter->setResizeMode(mDateNavigator,QSplitter::KeepSize);
268 mTodoList = new KOTodoView(mCalendar, mLeftSplitter, "todolist_small2"); 268 mTodoList = new KOTodoView(mCalendar, mLeftSplitter, "todolist_small2");
269 mFilterView = new KOFilterView(&mFilters,mLeftSplitter,"CalendarView::FilterView"); 269 mFilterView = new KOFilterView(&mFilters,mLeftSplitter,"CalendarView::FilterView");
270 270
271#ifdef KORG_NORESOURCEVIEW 271#ifdef KORG_NORESOURCEVIEW
272 mResourceView = 0; 272 mResourceView = 0;
273#else 273#else
274 if ( mResourceManager ) { 274 if ( mResourceManager ) {
275 mResourceView = new ResourceView( mResourceManager, mLeftSplitter ); 275 mResourceView = new ResourceView( mResourceManager, mLeftSplitter );
276 mResourceView->updateView(); 276 mResourceView->updateView();
277 connect( mResourceView, SIGNAL( resourcesChanged() ), 277 connect( mResourceView, SIGNAL( resourcesChanged() ),
278 SLOT( updateView() ) ); 278 SLOT( updateView() ) );
279 } else { 279 } else {
280 mResourceView = 0; 280 mResourceView = 0;
281 } 281 }
282#endif 282#endif
283 QWidget *rightBox = new QWidget( mPanner ); 283 QWidget *rightBox = new QWidget( mPanner );
284 QBoxLayout *rightLayout = new QVBoxLayout( rightBox ); 284 QBoxLayout *rightLayout = new QVBoxLayout( rightBox );
285 285
286 mNavigatorBar = new NavigatorBar( QDate::currentDate(), rightBox, "useBigPixmaps" ); 286 mNavigatorBar = new NavigatorBar( QDate::currentDate(), rightBox, "useBigPixmaps" );
287 rightLayout->addWidget( mNavigatorBar ); 287 rightLayout->addWidget( mNavigatorBar );
288 288
289 mRightFrame = new QWidgetStack( rightBox ); 289 mRightFrame = new QWidgetStack( rightBox );
290 rightLayout->addWidget( mRightFrame, 1 ); 290 rightLayout->addWidget( mRightFrame, 1 );
291 291
292 mLeftFrame = mLeftSplitter; 292 mLeftFrame = mLeftSplitter;
293#else 293#else
294 QWidget *mainBox = new QWidget( this ); 294 QWidget *mainBox = new QWidget( this );
295 QWidget *leftFrame = new QWidget( mainBox ); 295 QWidget *leftFrame = new QWidget( mainBox );
296 296
297 QBoxLayout * mainBoxLayout; 297 QBoxLayout * mainBoxLayout;
298 QBoxLayout * leftFrameLayout; 298 QBoxLayout * leftFrameLayout;
299 if ( KOPrefs::instance()->mVerticalScreen ) { 299 if ( KOPrefs::instance()->mVerticalScreen ) {
300 mainBoxLayout = new QVBoxLayout(mainBox); 300 mainBoxLayout = new QVBoxLayout(mainBox);
301 leftFrameLayout = new QHBoxLayout(leftFrame ); 301 leftFrameLayout = new QHBoxLayout(leftFrame );
302 } else { 302 } else {
303 mainBoxLayout = new QHBoxLayout(mainBox); 303 mainBoxLayout = new QHBoxLayout(mainBox);
304 leftFrameLayout = new QVBoxLayout(leftFrame ); 304 leftFrameLayout = new QVBoxLayout(leftFrame );
305 } 305 }
306 topLayout->addWidget( mainBox ); 306 topLayout->addWidget( mainBox );
307 mainBoxLayout->addWidget (leftFrame); 307 mainBoxLayout->addWidget (leftFrame);
308 mDateNavigator = new KDateNavigator(leftFrame, mCalendar, TRUE, 308 mDateNavigator = new KDateNavigator(leftFrame, mCalendar, TRUE,
309 "CalendarView::DateNavigator", QDate::currentDate()); 309 "CalendarView::DateNavigator", QDate::currentDate());
310 // mDateNavigator->blockSignals( true ); 310 // mDateNavigator->blockSignals( true );
311 leftFrameLayout->addWidget( mDateNavigator ); 311 leftFrameLayout->addWidget( mDateNavigator );
312 mFilterView = new KOFilterView(&mFilters,leftFrame,"CalendarView::FilterView"); 312 mFilterView = new KOFilterView(&mFilters,leftFrame,"CalendarView::FilterView");
313 mTodoList = new KOTodoView(mCalendar, leftFrame, "todolistsmall"); 313 mTodoList = new KOTodoView(mCalendar, leftFrame, "todolistsmall");
314 314
315 if ( QApplication::desktop()->width() < 480 ) { 315 if ( QApplication::desktop()->width() < 480 ) {
316 leftFrameLayout->addWidget(mFilterView); 316 leftFrameLayout->addWidget(mFilterView);
317 leftFrameLayout->addWidget(mTodoList, 2 ); 317 leftFrameLayout->addWidget(mTodoList, 2 );
318 318
319 } else { 319 } else {
320 leftFrameLayout->addWidget(mTodoList,2 ); 320 leftFrameLayout->addWidget(mTodoList,2 );
321 leftFrameLayout->addWidget(mFilterView ); 321 leftFrameLayout->addWidget(mFilterView );
322 } 322 }
323 mFilterView->hide(); 323 mFilterView->hide();
324 QWidget *rightBox = new QWidget( mainBox ); 324 QWidget *rightBox = new QWidget( mainBox );
325 mainBoxLayout->addWidget ( rightBox, 10 ); 325 mainBoxLayout->addWidget ( rightBox, 10 );
326 QBoxLayout *rightLayout = new QVBoxLayout( rightBox ); 326 QBoxLayout *rightLayout = new QVBoxLayout( rightBox );
327 mNavigatorBar = new NavigatorBar( QDate::currentDate(), rightBox, "useBigPixmaps" ); 327 mNavigatorBar = new NavigatorBar( QDate::currentDate(), rightBox, "useBigPixmaps" );
328 mRightFrame = new QWidgetStack( rightBox ); 328 mRightFrame = new QWidgetStack( rightBox );
329 rightLayout->addWidget( mNavigatorBar ); 329 rightLayout->addWidget( mNavigatorBar );
330 rightLayout->addWidget( mRightFrame, 10 ); 330 rightLayout->addWidget( mRightFrame, 10 );
331 331
332 mLeftFrame = leftFrame; 332 mLeftFrame = leftFrame;
333 if ( KOPrefs::instance()->mVerticalScreen ) { 333 if ( KOPrefs::instance()->mVerticalScreen ) {
334 mTodoList->setFixedHeight( mDateNavigator->sizeHint().height() ); 334 mTodoList->setFixedHeight( mDateNavigator->sizeHint().height() );
335 leftFrame->setFixedHeight( mDateNavigator->sizeHint().height() ); 335 leftFrame->setFixedHeight( mDateNavigator->sizeHint().height() );
336 } else { 336 } else {
337 mTodoList->setFixedWidth( mDateNavigator->sizeHint().width() ); 337 mTodoList->setFixedWidth( mDateNavigator->sizeHint().width() );
338 leftFrame->setFixedWidth( mDateNavigator->sizeHint().width() ); 338 leftFrame->setFixedWidth( mDateNavigator->sizeHint().width() );
339 } 339 }
340 340
341 //qDebug("Calendarview Size %d %d ", width(), height()); 341 //qDebug("Calendarview Size %d %d ", width(), height());
342#endif 342#endif
343 343
344 connect( mNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ), 344 connect( mNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ),
345 SLOT( showDates( const KCal::DateList & ) ) ); 345 SLOT( showDates( const KCal::DateList & ) ) );
346 connect( mNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ), 346 connect( mNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ),
347 mDateNavigator, SLOT( selectDates( const KCal::DateList & ) ) ); 347 mDateNavigator, SLOT( selectDates( const KCal::DateList & ) ) );
348 348
349 connect( mNavigatorBar, SIGNAL( goPrevYear() ), 349 connect( mNavigatorBar, SIGNAL( goPrevYear() ),
350 mNavigator, SLOT( selectPreviousYear() ) ); 350 mNavigator, SLOT( selectPreviousYear() ) );
351 connect( mNavigatorBar, SIGNAL( goNextYear() ), 351 connect( mNavigatorBar, SIGNAL( goNextYear() ),
352 mNavigator, SLOT( selectNextYear() ) ); 352 mNavigator, SLOT( selectNextYear() ) );
353 connect( mNavigatorBar, SIGNAL( goPrevMonth() ), 353 connect( mNavigatorBar, SIGNAL( goPrevMonth() ),
354 mNavigator, SLOT( selectPreviousMonth() ) ); 354 mNavigator, SLOT( selectPreviousMonth() ) );
355 connect( mNavigatorBar, SIGNAL( goNextMonth() ), 355 connect( mNavigatorBar, SIGNAL( goNextMonth() ),
356 mNavigator, SLOT( selectNextMonth() ) ); 356 mNavigator, SLOT( selectNextMonth() ) );
357 357
358 connect( mNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ), 358 connect( mNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ),
359 mNavigatorBar, SLOT( selectDates( const KCal::DateList & ) ) ); 359 mNavigatorBar, SLOT( selectDates( const KCal::DateList & ) ) );
360 360
361 connect( mDateNavigator, SIGNAL( weekClicked( const QDate & ) ), 361 connect( mDateNavigator, SIGNAL( weekClicked( const QDate & ) ),
362 mNavigator, SLOT( selectWeek( const QDate & ) ) ); 362 mNavigator, SLOT( selectWeek( const QDate & ) ) );
363 363
364 connect( mDateNavigator, SIGNAL( goPrevYear() ), 364 connect( mDateNavigator, SIGNAL( goPrevYear() ),
365 mNavigator, SLOT( selectPreviousYear() ) ); 365 mNavigator, SLOT( selectPreviousYear() ) );
366 connect( mDateNavigator, SIGNAL( goNextYear() ), 366 connect( mDateNavigator, SIGNAL( goNextYear() ),
367 mNavigator, SLOT( selectNextYear() ) ); 367 mNavigator, SLOT( selectNextYear() ) );
368 connect( mDateNavigator, SIGNAL( goPrevMonth() ), 368 connect( mDateNavigator, SIGNAL( goPrevMonth() ),
369 mNavigator, SLOT( selectPreviousMonth() ) ); 369 mNavigator, SLOT( selectPreviousMonth() ) );
370 connect( mDateNavigator, SIGNAL( goNextMonth() ), 370 connect( mDateNavigator, SIGNAL( goNextMonth() ),
371 mNavigator, SLOT( selectNextMonth() ) ); 371 mNavigator, SLOT( selectNextMonth() ) );
372 372
373 connect( mDateNavigator, SIGNAL( goPrevious() ), 373 connect( mDateNavigator, SIGNAL( goPrevious() ),
374 mNavigator, SLOT( selectPrevious() ) ); 374 mNavigator, SLOT( selectPrevious() ) );
375 connect( mDateNavigator, SIGNAL( goNext() ), 375 connect( mDateNavigator, SIGNAL( goNext() ),
376 mNavigator, SLOT( selectNext() ) ); 376 mNavigator, SLOT( selectNext() ) );
377 connect( mDateNavigator, SIGNAL( monthSelected ( int ) ), 377 connect( mDateNavigator, SIGNAL( monthSelected ( int ) ),
378 mNavigator, SLOT( slotMonthSelect( int ) ) ); 378 mNavigator, SLOT( slotMonthSelect( int ) ) );
379 connect( mNavigatorBar, SIGNAL( monthSelected ( int ) ), 379 connect( mNavigatorBar, SIGNAL( monthSelected ( int ) ),
380 mNavigator, SLOT( slotMonthSelect( int ) ) ); 380 mNavigator, SLOT( slotMonthSelect( int ) ) );
381 381
382 connect( mDateNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ), 382 connect( mDateNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ),
383 mNavigator, SLOT( selectDates( const KCal::DateList & ) ) ); 383 mNavigator, SLOT( selectDates( const KCal::DateList & ) ) );
384 384
385 connect( mDateNavigator, SIGNAL( eventDropped( Event * ) ), 385 connect( mDateNavigator, SIGNAL( eventDropped( Event * ) ),
386 SLOT( eventAdded( Event *) ) ); 386 SLOT( eventAdded( Event *) ) );
387 387
388 connect(mDateNavigator,SIGNAL(dayPassed(QDate)),SLOT(updateView())); 388 connect(mDateNavigator,SIGNAL(dayPassed(QDate)),SLOT(updateView()));
389 389
390 connect( this, SIGNAL( configChanged() ), 390 connect( this, SIGNAL( configChanged() ),
391 mDateNavigator, SLOT( updateConfig() ) ); 391 mDateNavigator, SLOT( updateConfig() ) );
392 392
393 connect( mTodoList, SIGNAL( newTodoSignal() ), 393 connect( mTodoList, SIGNAL( newTodoSignal() ),
394 SLOT( newTodo() ) ); 394 SLOT( newTodo() ) );
395 connect( mTodoList, SIGNAL( newSubTodoSignal( Todo *) ), 395 connect( mTodoList, SIGNAL( newSubTodoSignal( Todo *) ),
396 SLOT( newSubTodo( Todo * ) ) ); 396 SLOT( newSubTodo( Todo * ) ) );
397 connect( mTodoList, SIGNAL( editTodoSignal( Todo * ) ), 397 connect( mTodoList, SIGNAL( editTodoSignal( Todo * ) ),
398 SLOT( editTodo( Todo * ) ) ); 398 SLOT( editTodo( Todo * ) ) );
399 connect( mTodoList, SIGNAL( showTodoSignal( Todo * ) ), 399 connect( mTodoList, SIGNAL( showTodoSignal( Todo * ) ),
400 SLOT( showTodo( Todo *) ) ); 400 SLOT( showTodo( Todo *) ) );
401 connect( mTodoList, SIGNAL( deleteTodoSignal( Todo *) ), 401 connect( mTodoList, SIGNAL( deleteTodoSignal( Todo *) ),
402 SLOT( deleteTodo( Todo *) ) ); 402 SLOT( deleteTodo( Todo *) ) );
403 connect( this, SIGNAL( configChanged()), mTodoList, SLOT( updateConfig() ) ); 403 connect( this, SIGNAL( configChanged()), mTodoList, SLOT( updateConfig() ) );
404 connect( mTodoList, SIGNAL( purgeCompletedSignal() ), 404 connect( mTodoList, SIGNAL( purgeCompletedSignal() ),
405 SLOT( purgeCompleted() ) ); 405 SLOT( purgeCompleted() ) );
406 connect( mTodoList, SIGNAL( todoModifiedSignal( Todo *, int ) ), 406 connect( mTodoList, SIGNAL( todoModifiedSignal( Todo *, int ) ),
407 SIGNAL( todoModified( Todo *, int ) ) ); 407 SIGNAL( todoModified( Todo *, int ) ) );
408 408
409 connect( mTodoList, SIGNAL( cloneTodoSignal( Incidence * ) ), 409 connect( mTodoList, SIGNAL( cloneTodoSignal( Incidence * ) ),
410 this, SLOT ( cloneIncidence( Incidence * ) ) ); 410 this, SLOT ( cloneIncidence( Incidence * ) ) );
411 connect( mTodoList, SIGNAL( cancelTodoSignal( Incidence * ) ), 411 connect( mTodoList, SIGNAL( cancelTodoSignal( Incidence * ) ),
412 this, SLOT (cancelIncidence( Incidence * ) ) ); 412 this, SLOT (cancelIncidence( Incidence * ) ) );
413 413
414 connect( mTodoList, SIGNAL( moveTodoSignal( Incidence * ) ), 414 connect( mTodoList, SIGNAL( moveTodoSignal( Incidence * ) ),
415 this, SLOT ( moveIncidence( Incidence * ) ) ); 415 this, SLOT ( moveIncidence( Incidence * ) ) );
416 connect( mTodoList, SIGNAL( beamTodoSignal( Incidence * ) ), 416 connect( mTodoList, SIGNAL( beamTodoSignal( Incidence * ) ),
417 this, SLOT ( beamIncidence( Incidence * ) ) ); 417 this, SLOT ( beamIncidence( Incidence * ) ) );
418 418
419 connect( mTodoList, SIGNAL( unparentTodoSignal( Todo * ) ), 419 connect( mTodoList, SIGNAL( unparentTodoSignal( Todo * ) ),
420 this, SLOT ( todo_unsub( Todo * ) ) ); 420 this, SLOT ( todo_unsub( Todo * ) ) );
421 421
422 connect( mTodoList, SIGNAL( reparentTodoSignal( Todo *,Todo * ) ), 422 connect( mTodoList, SIGNAL( reparentTodoSignal( Todo *,Todo * ) ),
423 this, SLOT ( todo_resub( Todo *,Todo * ) ) ); 423 this, SLOT ( todo_resub( Todo *,Todo * ) ) );
424 connect( this, SIGNAL( todoModified( Todo *, int )), mTodoList, 424 connect( this, SIGNAL( todoModified( Todo *, int )), mTodoList,
425 SLOT( updateTodo( Todo *, int ) ) ); 425 SLOT( updateTodo( Todo *, int ) ) );
426 connect( this, SIGNAL( todoModified( Todo *, int )), this, 426 connect( this, SIGNAL( todoModified( Todo *, int )), this,
427 SLOT( changeTodoDisplay( Todo *, int ) ) ); 427 SLOT( changeTodoDisplay( Todo *, int ) ) );
428 428
429 429
430 connect( mFilterView, SIGNAL( filterChanged() ), SLOT( updateFilter() ) ); 430 connect( mFilterView, SIGNAL( filterChanged() ), SLOT( updateFilter() ) );
431 connect( mFilterView, SIGNAL( editFilters() ), SLOT( editFilters() ) ); 431 connect( mFilterView, SIGNAL( editFilters() ), SLOT( editFilters() ) );
432 connect( mCalendar, SIGNAL( addAlarm(const QDateTime &, const QString & ) ), SLOT( addAlarm(const QDateTime &, const QString & ) ) ); 432 connect( mCalendar, SIGNAL( addAlarm(const QDateTime &, const QString & ) ), SLOT( addAlarm(const QDateTime &, const QString & ) ) );
433 connect( mCalendar, SIGNAL( removeAlarm(const QDateTime &, const QString & ) ), SLOT( removeAlarm(const QDateTime &, const QString & ) ) ); 433 connect( mCalendar, SIGNAL( removeAlarm(const QDateTime &, const QString & ) ), SLOT( removeAlarm(const QDateTime &, const QString & ) ) );
434 434
435 435
436 436
437 437
438 438
439 connect(QApplication::clipboard(),SIGNAL(dataChanged()), 439 connect(QApplication::clipboard(),SIGNAL(dataChanged()),
440 SLOT(checkClipboard())); 440 SLOT(checkClipboard()));
441 connect( mTodoList,SIGNAL( incidenceSelected( Incidence * ) ), 441 connect( mTodoList,SIGNAL( incidenceSelected( Incidence * ) ),
442 SLOT( processTodoListSelection( Incidence * ) ) ); 442 SLOT( processTodoListSelection( Incidence * ) ) );
443 connect(mTodoList,SIGNAL(isModified(bool)),SLOT(setModified(bool))); 443 connect(mTodoList,SIGNAL(isModified(bool)),SLOT(setModified(bool)));
444 444
445 // kdDebug() << "CalendarView::CalendarView() done" << endl; 445 // kdDebug() << "CalendarView::CalendarView() done" << endl;
446 446
447 mDateFrame = new QVBox(0,0,WType_Popup); 447 mDateFrame = new QVBox(0,0,WType_Popup);
448 //mDateFrame->setFrameStyle(QFrame::PopupPanel | QFrame::Raised); 448 //mDateFrame->setFrameStyle(QFrame::PopupPanel | QFrame::Raised);
449 mDateFrame->setFrameStyle( QFrame::WinPanel |QFrame::Raised ); 449 mDateFrame->setFrameStyle( QFrame::WinPanel |QFrame::Raised );
450 mDateFrame->setLineWidth(3); 450 mDateFrame->setLineWidth(3);
451 mDateFrame->hide(); 451 mDateFrame->hide();
452 mDateFrame->setCaption( i18n( "Pick a date to display")); 452 mDateFrame->setCaption( i18n( "Pick a date to display"));
453 mDatePicker = new KDatePicker ( mDateFrame , QDate::currentDate() ); 453 mDatePicker = new KDatePicker ( mDateFrame , QDate::currentDate() );
454 454
455 connect(mDatePicker,SIGNAL(dateSelected(QDate)),SLOT(slotSelectPickerDate(QDate))); 455 connect(mDatePicker,SIGNAL(dateSelected(QDate)),SLOT(slotSelectPickerDate(QDate)));
456 456
457 mEventEditor = mDialogManager->getEventEditor(); 457 mEventEditor = mDialogManager->getEventEditor();
458 mTodoEditor = mDialogManager->getTodoEditor(); 458 mTodoEditor = mDialogManager->getTodoEditor();
459 459
460 mFlagEditDescription = false; 460 mFlagEditDescription = false;
461 461
462 mSuspendTimer = new QTimer( this ); 462 mSuspendTimer = new QTimer( this );
463 mAlarmTimer = new QTimer( this ); 463 mAlarmTimer = new QTimer( this );
464 mRecheckAlarmTimer = new QTimer( this ); 464 mRecheckAlarmTimer = new QTimer( this );
465 connect( mRecheckAlarmTimer, SIGNAL( timeout () ), SLOT( recheckTimerAlarm() ) ); 465 connect( mRecheckAlarmTimer, SIGNAL( timeout () ), SLOT( recheckTimerAlarm() ) );
466 connect( mSuspendTimer, SIGNAL( timeout () ), SLOT( suspendAlarm() ) ); 466 connect( mSuspendTimer, SIGNAL( timeout () ), SLOT( suspendAlarm() ) );
467 connect( mAlarmTimer, SIGNAL( timeout () ), SLOT( timerAlarm() ) ); 467 connect( mAlarmTimer, SIGNAL( timeout () ), SLOT( timerAlarm() ) );
468 mAlarmDialog = new AlarmDialog( this ); 468 mAlarmDialog = new AlarmDialog( this );
469 connect( mAlarmDialog, SIGNAL( addAlarm(const QDateTime &, const QString & ) ), SLOT( addSuspendAlarm(const QDateTime &, const QString & ) ) ); 469 connect( mAlarmDialog, SIGNAL( addAlarm(const QDateTime &, const QString & ) ), SLOT( addSuspendAlarm(const QDateTime &, const QString & ) ) );
470 mAlarmDialog->setServerNotification( false ); 470 mAlarmDialog->setServerNotification( false );
471 mAlarmDialog->setSuspendTime( KOPrefs::instance()->mAlarmSuspendTime ); 471 mAlarmDialog->setSuspendTime( KOPrefs::instance()->mAlarmSuspendTime );
472 472
473 473
474#ifndef DESKTOP_VERSION 474#ifndef DESKTOP_VERSION
475//US listen for arriving address resultsets 475//US listen for arriving address resultsets
476 connect(ExternalAppHandler::instance(), SIGNAL(receivedBirthdayListEvent(const QString&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&)), 476 connect(ExternalAppHandler::instance(), SIGNAL(receivedBirthdayListEvent(const QString&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&)),
477 this, SLOT(insertBirthdays(const QString&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&))); 477 this, SLOT(insertBirthdays(const QString&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&)));
478#endif 478#endif
479 479
480} 480}
481 481
482 482
483CalendarView::~CalendarView() 483CalendarView::~CalendarView()
484{ 484{
485 // kdDebug() << "~CalendarView()" << endl; 485 // kdDebug() << "~CalendarView()" << endl;
486 //qDebug("CalendarView::~CalendarView() "); 486 //qDebug("CalendarView::~CalendarView() ");
487 delete mDialogManager; 487 delete mDialogManager;
488 delete mViewManager; 488 delete mViewManager;
489 delete mStorage; 489 delete mStorage;
490 delete mDateFrame ; 490 delete mDateFrame ;
491 delete beamDialog; 491 delete beamDialog;
492 //kdDebug() << "~CalendarView() done" << endl; 492 //kdDebug() << "~CalendarView() done" << endl;
493} 493}
494void CalendarView::timerAlarm() 494void CalendarView::timerAlarm()
495{ 495{
496 //qDebug("CalendarView::timerAlarm() "); 496 //qDebug("CalendarView::timerAlarm() ");
497 computeAlarm(mAlarmNotification ); 497 computeAlarm(mAlarmNotification );
498} 498}
499 499
500void CalendarView::suspendAlarm() 500void CalendarView::suspendAlarm()
501{ 501{
502 //qDebug(" CalendarView::suspendAlarm() "); 502 //qDebug(" CalendarView::suspendAlarm() ");
503 computeAlarm(mSuspendAlarmNotification ); 503 computeAlarm(mSuspendAlarmNotification );
504 504
505} 505}
506 506
507void CalendarView::startAlarm( QString mess , QString filename) 507void CalendarView::startAlarm( QString mess , QString filename)
508{ 508{
509 mAlarmDialog->eventNotification( mess, KOPrefs::instance()->mAlarmPlayBeeps, filename, true,KOPrefs::instance()->mAlarmBeepInterval ,KOPrefs::instance()->mAlarmSuspendCount ); 509 mAlarmDialog->eventNotification( mess, KOPrefs::instance()->mAlarmPlayBeeps, filename, true,KOPrefs::instance()->mAlarmBeepInterval ,KOPrefs::instance()->mAlarmSuspendCount );
510 QTimer::singleShot( 3000, this, SLOT( checkNextTimerAlarm() ) ); 510 QTimer::singleShot( 3000, this, SLOT( checkNextTimerAlarm() ) );
511 511
512} 512}
513 513
514void CalendarView::checkNextTimerAlarm() 514void CalendarView::checkNextTimerAlarm()
515{ 515{
516 mCalendar->checkAlarmForIncidence( 0, true ); 516 mCalendar->checkAlarmForIncidence( 0, true );
517} 517}
518 518
519void CalendarView::computeAlarm( QString msg ) 519void CalendarView::computeAlarm( QString msg )
520{ 520{
521 521
522 QString mess = msg; 522 QString mess = msg;
523 QString mAlarmMessage = mess.mid( 9 ); 523 QString mAlarmMessage = mess.mid( 9 );
524 QString filename = MainWindow::resourcePath(); 524 QString filename = MainWindow::resourcePath();
525 filename += "koalarm.wav"; 525 filename += "koalarm.wav";
526 QString tempfilename; 526 QString tempfilename;
527 if ( mess.left( 13 ) == "suspend_alarm") { 527 if ( mess.left( 13 ) == "suspend_alarm") {
528 bool error = false; 528 bool error = false;
529 int len = mess.mid( 13 ).find("+++"); 529 int len = mess.mid( 13 ).find("+++");
530 if ( len < 2 ) 530 if ( len < 2 )
531 error = true; 531 error = true;
532 else { 532 else {
533 tempfilename = mess.mid( 13, len ); 533 tempfilename = mess.mid( 13, len );
534 if ( !QFile::exists( tempfilename ) ) 534 if ( !QFile::exists( tempfilename ) )
535 error = true; 535 error = true;
536 } 536 }
537 if ( ! error ) { 537 if ( ! error ) {
538 filename = tempfilename; 538 filename = tempfilename;
539 } 539 }
540 mAlarmMessage = mess.mid( 13+len+3 ); 540 mAlarmMessage = mess.mid( 13+len+3 );
541 //qDebug("suspend file %s ",tempfilename.latin1() ); 541 //qDebug("suspend file %s ",tempfilename.latin1() );
542 startAlarm( mAlarmMessage, filename); 542 startAlarm( mAlarmMessage, filename);
543 return; 543 return;
544 } 544 }
545 if ( mess.left( 11 ) == "timer_alarm") { 545 if ( mess.left( 11 ) == "timer_alarm") {
546 //mTimerTime = 0; 546 //mTimerTime = 0;
547 startAlarm( mess.mid( 11 ), filename ); 547 startAlarm( mess.mid( 11 ), filename );
548 return; 548 return;
549 } 549 }
550 if ( mess.left( 10 ) == "proc_alarm") { 550 if ( mess.left( 10 ) == "proc_alarm") {
551 bool error = false; 551 bool error = false;
552 int len = mess.mid( 10 ).find("+++"); 552 int len = mess.mid( 10 ).find("+++");
553 if ( len < 2 ) 553 if ( len < 2 )
554 error = true; 554 error = true;
555 else { 555 else {
556 tempfilename = mess.mid( 10, len ); 556 tempfilename = mess.mid( 10, len );
557 if ( !QFile::exists( tempfilename ) ) 557 if ( !QFile::exists( tempfilename ) )
558 error = true; 558 error = true;
559 } 559 }
560 if ( error ) { 560 if ( error ) {
561 mAlarmMessage = "Procedure Alarm\nError - File not found\n"; 561 mAlarmMessage = "Procedure Alarm\nError - File not found\n";
562 mAlarmMessage += mess.mid( 10+len+3+9 ); 562 mAlarmMessage += mess.mid( 10+len+3+9 );
563 } else { 563 } else {
564 //QCopEnvelope e("QPE/Application/kopi", "-writeFileSilent"); 564 //QCopEnvelope e("QPE/Application/kopi", "-writeFileSilent");
565 //qDebug("-----system command %s ",tempfilename.latin1() ); 565 //qDebug("-----system command %s ",tempfilename.latin1() );
566#ifndef _WIN32_ 566#ifndef _WIN32_
567 if ( vfork () == 0 ) { 567 if ( vfork () == 0 ) {
568 execl ( tempfilename.latin1(), 0 ); 568 execl ( tempfilename.latin1(), 0 );
569 return; 569 return;
570 } 570 }
571#else 571#else
572 QProcess* p = new QProcess(); 572 QProcess* p = new QProcess();
573 p->addArgument( tempfilename.latin1() ); 573 p->addArgument( tempfilename.latin1() );
574 p->start(); 574 p->start();
575 return; 575 return;
576#endif 576#endif
577 577
578 return; 578 return;
579 } 579 }
580 580
581 //qDebug("+++++++system command %s ",tempfilename.latin1() ); 581 //qDebug("+++++++system command %s ",tempfilename.latin1() );
582 } 582 }
583 if ( mess.left( 11 ) == "audio_alarm") { 583 if ( mess.left( 11 ) == "audio_alarm") {
584 bool error = false; 584 bool error = false;
585 int len = mess.mid( 11 ).find("+++"); 585 int len = mess.mid( 11 ).find("+++");
586 if ( len < 2 ) 586 if ( len < 2 )
587 error = true; 587 error = true;
588 else { 588 else {
589 tempfilename = mess.mid( 11, len ); 589 tempfilename = mess.mid( 11, len );
590 if ( !QFile::exists( tempfilename ) ) 590 if ( !QFile::exists( tempfilename ) )
591 error = true; 591 error = true;
592 } 592 }
593 if ( ! error ) { 593 if ( ! error ) {
594 filename = tempfilename; 594 filename = tempfilename;
595 } 595 }
596 mAlarmMessage = mess.mid( 11+len+3+9 ); 596 mAlarmMessage = mess.mid( 11+len+3+9 );
597 //qDebug("audio file command %s ",tempfilename.latin1() ); 597 //qDebug("audio file command %s ",tempfilename.latin1() );
598 } 598 }
599 if ( mess.left( 9 ) == "cal_alarm") { 599 if ( mess.left( 9 ) == "cal_alarm") {
600 mAlarmMessage = mess.mid( 9 ) ; 600 mAlarmMessage = mess.mid( 9 ) ;
601 } 601 }
602 602
603 startAlarm( mAlarmMessage, filename ); 603 startAlarm( mAlarmMessage, filename );
604 604
605 605
606} 606}
607 607
608void CalendarView::addSuspendAlarm(const QDateTime &qdt, const QString &noti ) 608void CalendarView::addSuspendAlarm(const QDateTime &qdt, const QString &noti )
609{ 609{
610 //qDebug("+++++addSUSPENDAlarm %s %s ", qdt.toString().latin1() , noti.latin1() ); 610 //qDebug("+++++addSUSPENDAlarm %s %s ", qdt.toString().latin1() , noti.latin1() );
611 611
612 mSuspendAlarmNotification = noti; 612 mSuspendAlarmNotification = noti;
613 int ms = QDateTime::currentDateTime().secsTo( qdt )*1000; 613 int ms = QDateTime::currentDateTime().secsTo( qdt )*1000;
614 //qDebug("Suspend Alarm timer started with secs: %d ", ms/1000); 614 //qDebug("Suspend Alarm timer started with secs: %d ", ms/1000);
615 mSuspendTimer->start( ms , true ); 615 mSuspendTimer->start( ms , true );
616 616
617} 617}
618 618
619void CalendarView::addAlarm(const QDateTime &qdt, const QString &noti ) 619void CalendarView::addAlarm(const QDateTime &qdt, const QString &noti )
620{ 620{
621 //qDebug("+++++addAlarm %s %s ", qdt.toString().latin1() , noti.latin1() ); 621 //qDebug("+++++addAlarm %s %s ", qdt.toString().latin1() , noti.latin1() );
622 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) { 622 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) {
623#ifndef DESKTOP_VERSION 623#ifndef DESKTOP_VERSION
624 AlarmServer::addAlarm ( qdt,"koalarm", noti.latin1() ); 624 AlarmServer::addAlarm ( qdt,"koalarm", noti.latin1() );
625#endif 625#endif
626 return; 626 return;
627 } 627 }
628 int maxSec; 628 int maxSec;
629 //maxSec = 5; //testing only 629 //maxSec = 5; //testing only
630 maxSec = 86400+3600; // one day+1hour 630 maxSec = 86400+3600; // one day+1hour
631 mAlarmNotification = noti; 631 mAlarmNotification = noti;
632 int sec = QDateTime::currentDateTime().secsTo( qdt ); 632 int sec = QDateTime::currentDateTime().secsTo( qdt );
633 if ( sec > maxSec ) { 633 if ( sec > maxSec ) {
634 mRecheckAlarmTimer->start( maxSec * 1000 ); 634 mRecheckAlarmTimer->start( maxSec * 1000 );
635 // qDebug("recheck Alarm timer started with secs: %d next alarm in sec:%d", maxSec,sec ); 635 // qDebug("recheck Alarm timer started with secs: %d next alarm in sec:%d", maxSec,sec );
636 return; 636 return;
637 } else { 637 } else {
638 mRecheckAlarmTimer->stop(); 638 mRecheckAlarmTimer->stop();
639 } 639 }
640 //qDebug("Alarm timer started with secs: %d ", sec); 640 //qDebug("Alarm timer started with secs: %d ", sec);
641 mAlarmTimer->start( sec *1000 , true ); 641 mAlarmTimer->start( sec *1000 , true );
642 642
643} 643}
644// called by mRecheckAlarmTimer to get next alarm 644// called by mRecheckAlarmTimer to get next alarm
645// we need this, because a QTimer has only a max range of 25 days 645// we need this, because a QTimer has only a max range of 25 days
646void CalendarView::recheckTimerAlarm() 646void CalendarView::recheckTimerAlarm()
647{ 647{
648 mAlarmTimer->stop(); 648 mAlarmTimer->stop();
649 mRecheckAlarmTimer->stop(); 649 mRecheckAlarmTimer->stop();
650 mCalendar->checkAlarmForIncidence( 0, true ); 650 mCalendar->checkAlarmForIncidence( 0, true );
651} 651}
652void CalendarView::removeAlarm(const QDateTime &qdt, const QString &noti ) 652void CalendarView::removeAlarm(const QDateTime &qdt, const QString &noti )
653{ 653{
654 //qDebug("-----removeAlarm %s %s ", qdt.toString().latin1() , noti.latin1() ); 654 //qDebug("-----removeAlarm %s %s ", qdt.toString().latin1() , noti.latin1() );
655 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) { 655 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) {
656#ifndef DESKTOP_VERSION 656#ifndef DESKTOP_VERSION
657 AlarmServer::deleteAlarm (qdt ,"koalarm" ,noti.latin1() ); 657 AlarmServer::deleteAlarm (qdt ,"koalarm" ,noti.latin1() );
658#endif 658#endif
659 return; 659 return;
660 } 660 }
661 mAlarmTimer->stop(); 661 mAlarmTimer->stop();
662} 662}
663void CalendarView::selectWeekNum ( int num ) 663void CalendarView::selectWeekNum ( int num )
664{ 664{
665 dateNavigator()->selectWeek( num ); 665 dateNavigator()->selectWeek( num );
666 mViewManager->showWeekView(); 666 mViewManager->showWeekView();
667} 667}
668KOViewManager *CalendarView::viewManager() 668KOViewManager *CalendarView::viewManager()
669{ 669{
670 return mViewManager; 670 return mViewManager;
671} 671}
672 672
673KODialogManager *CalendarView::dialogManager() 673KODialogManager *CalendarView::dialogManager()
674{ 674{
675 return mDialogManager; 675 return mDialogManager;
676} 676}
677 677
678QDate CalendarView::startDate() 678QDate CalendarView::startDate()
679{ 679{
680 DateList dates = mNavigator->selectedDates(); 680 DateList dates = mNavigator->selectedDates();
681 681
682 return dates.first(); 682 return dates.first();
683} 683}
684 684
685QDate CalendarView::endDate() 685QDate CalendarView::endDate()
686{ 686{
687 DateList dates = mNavigator->selectedDates(); 687 DateList dates = mNavigator->selectedDates();
688 688
689 return dates.last(); 689 return dates.last();
690} 690}
691 691
692 692
693void CalendarView::createPrinter() 693void CalendarView::createPrinter()
694{ 694{
695#ifndef KORG_NOPRINTER 695#ifndef KORG_NOPRINTER
696 if (!mCalPrinter) { 696 if (!mCalPrinter) {
697 mCalPrinter = new CalPrinter(this, mCalendar); 697 mCalPrinter = new CalPrinter(this, mCalendar);
698 connect(this, SIGNAL(configChanged()), mCalPrinter, SLOT(updateConfig())); 698 connect(this, SIGNAL(configChanged()), mCalPrinter, SLOT(updateConfig()));
699 } 699 }
700#endif 700#endif
701} 701}
702 702
703 703
704//KOPrefs::instance()->mWriteBackFile 704//KOPrefs::instance()->mWriteBackFile
705//KOPrefs::instance()->mWriteBackExistingOnly 705//KOPrefs::instance()->mWriteBackExistingOnly
706 706
707// 0 syncPrefsGroup->addRadio(i18n("Take local entry on conflict")); 707// 0 syncPrefsGroup->addRadio(i18n("Take local entry on conflict"));
708// 1 syncPrefsGroup->addRadio(i18n("Take remote entry on conflict")); 708// 1 syncPrefsGroup->addRadio(i18n("Take remote entry on conflict"));
709// 2 syncPrefsGroup->addRadio(i18n("Take newest entry on conflict")); 709// 2 syncPrefsGroup->addRadio(i18n("Take newest entry on conflict"));
710// 3 syncPrefsGroup->addRadio(i18n("Ask for every entry on conflict")); 710// 3 syncPrefsGroup->addRadio(i18n("Ask for every entry on conflict"));
711// 4 syncPrefsGroup->addRadio(i18n("Force take local entry always")); 711// 4 syncPrefsGroup->addRadio(i18n("Force take local entry always"));
712// 5 syncPrefsGroup->addRadio(i18n("Force take remote entry always")); 712// 5 syncPrefsGroup->addRadio(i18n("Force take remote entry always"));
713 713
714int CalendarView::takeEvent( Incidence* local, Incidence* remote, int mode , bool full ) 714int CalendarView::takeEvent( Incidence* local, Incidence* remote, int mode , bool full )
715{ 715{
716 716
717 // 0 equal 717 // 0 equal
718 // 1 take local 718 // 1 take local
719 // 2 take remote 719 // 2 take remote
720 // 3 cancel 720 // 3 cancel
721 QDateTime lastSync = mLastCalendarSync; 721 QDateTime lastSync = mLastCalendarSync;
722 QDateTime localMod = local->lastModified(); 722 QDateTime localMod = local->lastModified();
723 QDateTime remoteMod = remote->lastModified(); 723 QDateTime remoteMod = remote->lastModified();
724 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 724 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
725 bool remCh, locCh; 725 bool remCh, locCh;
726 remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) ); 726 remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) );
727 //if ( remCh ) 727 //if ( remCh )
728 //qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() ); 728 //qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() );
729 locCh = ( localMod > mLastCalendarSync ); 729 locCh = ( localMod > mLastCalendarSync );
730 if ( !remCh && ! locCh ) { 730 if ( !remCh && ! locCh ) {
731 //qDebug("both not changed "); 731 //qDebug("both not changed ");
732 lastSync = localMod.addDays(1); 732 lastSync = localMod.addDays(1);
733 if ( mode <= SYNC_PREF_ASK ) 733 if ( mode <= SYNC_PREF_ASK )
734 return 0; 734 return 0;
735 } else { 735 } else {
736 if ( locCh ) { 736 if ( locCh ) {
737 //qDebug("loc changed %d %s %s", local->revision() , localMod.toString().latin1(), mLastCalendarSync.toString().latin1()); 737 //qDebug("loc changed %d %s %s", local->revision() , localMod.toString().latin1(), mLastCalendarSync.toString().latin1());
738 lastSync = localMod.addDays( -1 ); 738 lastSync = localMod.addDays( -1 );
739 if ( !remCh ) 739 if ( !remCh )
740 remoteMod = ( lastSync.addDays( -1 ) ); 740 remoteMod = ( lastSync.addDays( -1 ) );
741 } else { 741 } else {
742 //qDebug(" not loc changed "); 742 //qDebug(" not loc changed ");
743 lastSync = localMod.addDays( 1 ); 743 lastSync = localMod.addDays( 1 );
744 if ( remCh ) 744 if ( remCh )
745 remoteMod =( lastSync.addDays( 1 ) ); 745 remoteMod =( lastSync.addDays( 1 ) );
746 746
747 } 747 }
748 } 748 }
749 full = true; 749 full = true;
750 if ( mode < SYNC_PREF_ASK ) 750 if ( mode < SYNC_PREF_ASK )
751 mode = SYNC_PREF_ASK; 751 mode = SYNC_PREF_ASK;
752 } else { 752 } else {
753 if ( localMod == remoteMod ) 753 if ( localMod == remoteMod )
754 // if ( local->revision() == remote->revision() ) 754 // if ( local->revision() == remote->revision() )
755 return 0; 755 return 0;
756 756
757 } 757 }
758 // qDebug(" %d %d conflict on %s %s ", mode, full, local->summary().latin1(), remote->summary().latin1() ); 758 // qDebug(" %d %d conflict on %s %s ", mode, full, local->summary().latin1(), remote->summary().latin1() );
759 759
760 //qDebug("%s %d %s %d", localMod.toString().latin1() , local->revision(), remoteMod.toString().latin1(), remote->revision()); 760 //qDebug("%s %d %s %d", localMod.toString().latin1() , local->revision(), remoteMod.toString().latin1(), remote->revision());
761 //qDebug("%d %d %d %d ", localMod.time().second(), localMod.time().msec(), remoteMod.time().second(), remoteMod.time().msec() ); 761 //qDebug("%d %d %d %d ", localMod.time().second(), localMod.time().msec(), remoteMod.time().second(), remoteMod.time().msec() );
762 //full = true; //debug only 762 //full = true; //debug only
763 if ( full ) { 763 if ( full ) {
764 bool equ = false; 764 bool equ = false;
765 if ( local->type() == "Event" ) { 765 if ( local->type() == "Event" ) {
766 equ = (*((Event*) local) == *((Event*) remote)); 766 equ = (*((Event*) local) == *((Event*) remote));
767 } 767 }
768 else if ( local->type() =="Todo" ) 768 else if ( local->type() =="Todo" )
769 equ = (*((Todo*) local) == (*(Todo*) remote)); 769 equ = (*((Todo*) local) == (*(Todo*) remote));
770 else if ( local->type() =="Journal" ) 770 else if ( local->type() =="Journal" )
771 equ = (*((Journal*) local) == *((Journal*) remote)); 771 equ = (*((Journal*) local) == *((Journal*) remote));
772 if ( equ ) { 772 if ( equ ) {
773 //qDebug("equal "); 773 //qDebug("equal ");
774 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 774 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
775 local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) ); 775 local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) );
776 } 776 }
777 if ( mode < SYNC_PREF_FORCE_LOCAL ) 777 if ( mode < SYNC_PREF_FORCE_LOCAL )
778 return 0; 778 return 0;
779 779
780 }//else //debug only 780 }//else //debug only
781 //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1()); 781 //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1());
782 } 782 }
783 int result; 783 int result;
784 bool localIsNew; 784 bool localIsNew;
785 //qDebug("%s -- %s mLastCalendarSync %s lastsync %s --- local %s remote %s ",local->summary().latin1(), remote->summary().latin1(),mLastCalendarSync.toString().latin1() ,lastSync.toString().latin1() , localMod.toString().latin1() , remoteMod.toString().latin1() ); 785 //qDebug("%s -- %s mLastCalendarSync %s lastsync %s --- local %s remote %s ",local->summary().latin1(), remote->summary().latin1(),mLastCalendarSync.toString().latin1() ,lastSync.toString().latin1() , localMod.toString().latin1() , remoteMod.toString().latin1() );
786 786
787 if ( full && mode < SYNC_PREF_NEWEST ) 787 if ( full && mode < SYNC_PREF_NEWEST )
788 mode = SYNC_PREF_ASK; 788 mode = SYNC_PREF_ASK;
789 789
790 switch( mode ) { 790 switch( mode ) {
791 case SYNC_PREF_LOCAL: 791 case SYNC_PREF_LOCAL:
792 if ( lastSync > remoteMod ) 792 if ( lastSync > remoteMod )
793 return 1; 793 return 1;
794 if ( lastSync > localMod ) 794 if ( lastSync > localMod )
795 return 2; 795 return 2;
796 return 1; 796 return 1;
797 break; 797 break;
798 case SYNC_PREF_REMOTE: 798 case SYNC_PREF_REMOTE:
799 if ( lastSync > remoteMod ) 799 if ( lastSync > remoteMod )
800 return 1; 800 return 1;
801 if ( lastSync > localMod ) 801 if ( lastSync > localMod )
802 return 2; 802 return 2;
803 return 2; 803 return 2;
804 break; 804 break;
805 case SYNC_PREF_NEWEST: 805 case SYNC_PREF_NEWEST:
806 if ( localMod > remoteMod ) 806 if ( localMod > remoteMod )
807 return 1; 807 return 1;
808 else 808 else
809 return 2; 809 return 2;
810 break; 810 break;
811 case SYNC_PREF_ASK: 811 case SYNC_PREF_ASK:
812 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); 812 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() );
813 if ( lastSync > remoteMod ) 813 if ( lastSync > remoteMod )
814 return 1; 814 return 1;
815 if ( lastSync > localMod ) 815 if ( lastSync > localMod )
816 return 2; 816 return 2;
817 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); 817 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() );
818 localIsNew = localMod >= remoteMod; 818 localIsNew = localMod >= remoteMod;
819 if ( localIsNew ) 819 if ( localIsNew )
820 getEventViewerDialog()->setColorMode( 1 ); 820 getEventViewerDialog()->setColorMode( 1 );
821 else 821 else
822 getEventViewerDialog()->setColorMode( 2 ); 822 getEventViewerDialog()->setColorMode( 2 );
823 getEventViewerDialog()->setIncidence(local); 823 getEventViewerDialog()->setIncidence(local);
824 if ( localIsNew ) 824 if ( localIsNew )
825 getEventViewerDialog()->setColorMode( 2 ); 825 getEventViewerDialog()->setColorMode( 2 );
826 else 826 else
827 getEventViewerDialog()->setColorMode( 1 ); 827 getEventViewerDialog()->setColorMode( 1 );
828 getEventViewerDialog()->addIncidence(remote); 828 getEventViewerDialog()->addIncidence(remote);
829 getEventViewerDialog()->setColorMode( 0 ); 829 getEventViewerDialog()->setColorMode( 0 );
830 //qDebug("local %d remote %d ",local->relatedTo(),remote->relatedTo() ); 830 //qDebug("local %d remote %d ",local->relatedTo(),remote->relatedTo() );
831 getEventViewerDialog()->setCaption( mCurrentSyncDevice +i18n(" : Conflict! Please choose entry!")); 831 getEventViewerDialog()->setCaption( mCurrentSyncDevice +i18n(" : Conflict! Please choose entry!"));
832 getEventViewerDialog()->showMe(); 832 getEventViewerDialog()->showMe();
833 result = getEventViewerDialog()->executeS( localIsNew ); 833 result = getEventViewerDialog()->executeS( localIsNew );
834 return result; 834 return result;
835 835
836 break; 836 break;
837 case SYNC_PREF_FORCE_LOCAL: 837 case SYNC_PREF_FORCE_LOCAL:
838 return 1; 838 return 1;
839 break; 839 break;
840 case SYNC_PREF_FORCE_REMOTE: 840 case SYNC_PREF_FORCE_REMOTE:
841 return 2; 841 return 2;
842 break; 842 break;
843 843
844 default: 844 default:
845 // SYNC_PREF_TAKE_BOTH not implemented 845 // SYNC_PREF_TAKE_BOTH not implemented
846 break; 846 break;
847 } 847 }
848 return 0; 848 return 0;
849} 849}
850Event* CalendarView::getLastSyncEvent() 850Event* CalendarView::getLastSyncEvent()
851{ 851{
852 Event* lse; 852 Event* lse;
853 //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() ); 853 //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() );
854 lse = mCalendar->event( "last-syncEvent-"+mCurrentSyncDevice ); 854 lse = mCalendar->event( "last-syncEvent-"+mCurrentSyncDevice );
855 if (!lse) { 855 if (!lse) {
856 lse = new Event(); 856 lse = new Event();
857 lse->setUid( "last-syncEvent-"+mCurrentSyncDevice ); 857 lse->setUid( "last-syncEvent-"+mCurrentSyncDevice );
858 QString sum = ""; 858 QString sum = "";
859 if ( mSyncManager->mExternSyncProfiles.contains( mCurrentSyncDevice ) ) 859 if ( mSyncManager->mExternSyncProfiles.contains( mCurrentSyncDevice ) )
860 sum = "E: "; 860 sum = "E: ";
861 lse->setSummary(sum+mCurrentSyncDevice + i18n(" - sync event")); 861 lse->setSummary(sum+mCurrentSyncDevice + i18n(" - sync event"));
862 lse->setDtStart( mLastCalendarSync ); 862 lse->setDtStart( mLastCalendarSync );
863 lse->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); 863 lse->setDtEnd( mLastCalendarSync.addSecs( 7200 ) );
864 lse->setCategories( i18n("SyncEvent") ); 864 lse->setCategories( i18n("SyncEvent") );
865 lse->setReadOnly( true ); 865 lse->setReadOnly( true );
866 mCalendar->addEvent( lse ); 866 mCalendar->addEvent( lse );
867 } 867 }
868 868
869 return lse; 869 return lse;
870 870
871} 871}
872 872
873// we check, if the to delete event has a id for a profile 873// we check, if the to delete event has a id for a profile
874// if yes, we set this id in the profile to delete 874// if yes, we set this id in the profile to delete
875void CalendarView::checkExternSyncEvent( QPtrList<Event> lastSync , Incidence* toDelete ) 875void CalendarView::checkExternSyncEvent( QPtrList<Event> lastSync , Incidence* toDelete )
876{ 876{
877 if ( lastSync.count() == 0 ) { 877 if ( lastSync.count() == 0 ) {
878 //qDebug(" lastSync.count() == 0"); 878 //qDebug(" lastSync.count() == 0");
879 return; 879 return;
880 } 880 }
881 if ( toDelete->type() == "Journal" ) 881 if ( toDelete->type() == "Journal" )
882 return; 882 return;
883 883
884 Event* eve = lastSync.first(); 884 Event* eve = lastSync.first();
885 885
886 while ( eve ) { 886 while ( eve ) {
887 QString id = toDelete->getID( eve->uid().mid( 15 ) ); // this is the sync profile name 887 QString id = toDelete->getID( eve->uid().mid( 15 ) ); // this is the sync profile name
888 if ( !id.isEmpty() ) { 888 if ( !id.isEmpty() ) {
889 QString des = eve->description(); 889 QString des = eve->description();
890 QString pref = "e"; 890 QString pref = "e";
891 if ( toDelete->type() == "Todo" ) 891 if ( toDelete->type() == "Todo" )
892 pref = "t"; 892 pref = "t";
893 des += pref+ id + ","; 893 des += pref+ id + ",";
894 eve->setReadOnly( false ); 894 eve->setReadOnly( false );
895 eve->setDescription( des ); 895 eve->setDescription( des );
896 //qDebug("setdes %s ", des.latin1()); 896 //qDebug("setdes %s ", des.latin1());
897 eve->setReadOnly( true ); 897 eve->setReadOnly( true );
898 } 898 }
899 eve = lastSync.next(); 899 eve = lastSync.next();
900 } 900 }
901 901
902} 902}
903void CalendarView::checkExternalId( Incidence * inc ) 903void CalendarView::checkExternalId( Incidence * inc )
904{ 904{
905 QPtrList<Event> lastSync = mCalendar->getExternLastSyncEvents() ; 905 QPtrList<Event> lastSync = mCalendar->getExternLastSyncEvents() ;
906 checkExternSyncEvent( lastSync, inc ); 906 checkExternSyncEvent( lastSync, inc );
907 907
908} 908}
909bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int mode ) 909bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int mode )
910{ 910{
911 bool syncOK = true; 911 bool syncOK = true;
912 int addedEvent = 0; 912 int addedEvent = 0;
913 int addedEventR = 0; 913 int addedEventR = 0;
914 int deletedEventR = 0; 914 int deletedEventR = 0;
915 int deletedEventL = 0; 915 int deletedEventL = 0;
916 int changedLocal = 0; 916 int changedLocal = 0;
917 int changedRemote = 0; 917 int changedRemote = 0;
918 //QPtrList<Event> el = local->rawEvents(); 918 //QPtrList<Event> el = local->rawEvents();
919 Event* eventR; 919 Event* eventR;
920 QString uid; 920 QString uid;
921 int take; 921 int take;
922 Event* eventL; 922 Event* eventL;
923 Event* eventRSync; 923 Event* eventRSync;
924 Event* eventLSync; 924 Event* eventLSync;
925 QPtrList<Event> eventRSyncSharp = remote->getExternLastSyncEvents(); 925 QPtrList<Event> eventRSyncSharp = remote->getExternLastSyncEvents();
926 QPtrList<Event> eventLSyncSharp = local->getExternLastSyncEvents(); 926 QPtrList<Event> eventLSyncSharp = local->getExternLastSyncEvents();
927 bool fullDateRange = false; 927 bool fullDateRange = false;
928 local->resetTempSyncStat(); 928 local->resetTempSyncStat();
929 if ( mSyncKDE )
930 remote->resetPilotStat(1);
931 mLastCalendarSync = QDateTime::currentDateTime(); 929 mLastCalendarSync = QDateTime::currentDateTime();
930 if ( mSyncKDE ) {
931 remote->resetPilotStat(1);
932 if ( KSyncManager::mRequestedSyncEvent.isValid() ) {
933 mLastCalendarSync = KSyncManager::mRequestedSyncEvent;
934 qDebug("using extern time for calendar sync: %s ", mLastCalendarSync.toString().latin1() );
935 } else {
936 qDebug("ERROR: KSyncManager::mRequestedSyncEvent has invalid datatime ");
937 }
938 }
932 QDateTime modifiedCalendar = mLastCalendarSync;; 939 QDateTime modifiedCalendar = mLastCalendarSync;;
933 eventLSync = getLastSyncEvent(); 940 eventLSync = getLastSyncEvent();
934 eventR = remote->event("last-syncEvent-"+mCurrentSyncName ); 941 eventR = remote->event("last-syncEvent-"+mCurrentSyncName );
935 if ( eventR ) { 942 if ( eventR ) {
936 eventRSync = (Event*) eventR->clone(); 943 eventRSync = (Event*) eventR->clone();
937 remote->deleteEvent(eventR ); 944 remote->deleteEvent(eventR );
938 945
939 } else { 946 } else {
940 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL || mSyncKDE) { 947 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL || mSyncKDE) {
941 eventRSync = (Event*)eventLSync->clone(); 948 eventRSync = (Event*)eventLSync->clone();
942 } else { 949 } else {
943 fullDateRange = true; 950 fullDateRange = true;
944 eventRSync = new Event(); 951 eventRSync = new Event();
945 eventRSync->setSummary(mCurrentSyncName + i18n(" - sync event")); 952 eventRSync->setSummary(mCurrentSyncName + i18n(" - sync event"));
946 eventRSync->setUid("last-syncEvent-"+mCurrentSyncName ); 953 eventRSync->setUid("last-syncEvent-"+mCurrentSyncName );
947 eventRSync->setDtStart( mLastCalendarSync ); 954 eventRSync->setDtStart( mLastCalendarSync );
948 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); 955 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 7200 ) );
949 eventRSync->setCategories( i18n("SyncEvent") ); 956 eventRSync->setCategories( i18n("SyncEvent") );
950 } 957 }
951 } 958 }
952 if ( eventLSync->dtStart() == mLastCalendarSync ) 959 if ( eventLSync->dtStart() == mLastCalendarSync )
953 fullDateRange = true; 960 fullDateRange = true;
954 961
955 if ( ! fullDateRange ) { 962 if ( ! fullDateRange ) {
956 if ( eventLSync->dtStart() != eventRSync->dtStart() ) { 963 if ( eventLSync->dtStart() != eventRSync->dtStart() ) {
957 964
958 // qDebug("set fulldate to true %s %s" ,eventLSync->dtStart().toString().latin1(), eventRSync->dtStart().toString().latin1() ); 965 // qDebug("set fulldate to true %s %s" ,eventLSync->dtStart().toString().latin1(), eventRSync->dtStart().toString().latin1() );
959 //qDebug("%d %d %d %d ", eventLSync->dtStart().time().second(), eventLSync->dtStart().time().msec() , eventRSync->dtStart().time().second(), eventRSync->dtStart().time().msec()); 966 //qDebug("%d %d %d %d ", eventLSync->dtStart().time().second(), eventLSync->dtStart().time().msec() , eventRSync->dtStart().time().second(), eventRSync->dtStart().time().msec());
960 fullDateRange = true; 967 fullDateRange = true;
961 } 968 }
962 } 969 }
963 if ( mSyncKDE ) { 970 if ( mSyncKDE ) {
964 fullDateRange = ( eventLSync->dtStart() == mLastCalendarSync ); 971 fullDateRange = ( eventLSync->dtStart() == mLastCalendarSync );
965 } 972 }
966 if ( fullDateRange ) 973 if ( fullDateRange )
967 mLastCalendarSync = QDateTime::currentDateTime().addDays( -100*365); 974 mLastCalendarSync = QDateTime::currentDateTime().addDays( -100*365);
968 else 975 else
969 mLastCalendarSync = eventLSync->dtStart(); 976 mLastCalendarSync = eventLSync->dtStart();
970 // for resyncing if own file has changed 977 // for resyncing if own file has changed
971 if ( mCurrentSyncDevice == "deleteaftersync" ) { 978 if ( mCurrentSyncDevice == "deleteaftersync" ) {
972 mLastCalendarSync = loadedFileVersion; 979 mLastCalendarSync = loadedFileVersion;
973 //qDebug("setting mLastCalendarSync "); 980 //qDebug("setting mLastCalendarSync ");
974 } 981 }
975 //qDebug("*************************** "); 982 //qDebug("*************************** ");
976 qDebug("mLastCalendarSync %s full: %d",mLastCalendarSync.toString().latin1(), fullDateRange); 983 qDebug("mLastCalendarSync %s full: %d",mLastCalendarSync.toString().latin1(), fullDateRange);
977 QPtrList<Incidence> er = remote->rawIncidences(); 984 QPtrList<Incidence> er = remote->rawIncidences();
978 Incidence* inR = er.first(); 985 Incidence* inR = er.first();
979 Incidence* inL; 986 Incidence* inL;
980 QProgressBar bar( er.count(),0 ); 987 QProgressBar bar( er.count(),0 );
981 bar.setCaption (i18n("Syncing - close to abort!") ); 988 bar.setCaption (i18n("Syncing - close to abort!") );
982 989
983 int w = 300; 990 int w = 300;
984 if ( QApplication::desktop()->width() < 320 ) 991 if ( QApplication::desktop()->width() < 320 )
985 w = 220; 992 w = 220;
986 int h = bar.sizeHint().height() ; 993 int h = bar.sizeHint().height() ;
987 int dw = QApplication::desktop()->width(); 994 int dw = QApplication::desktop()->width();
988 int dh = QApplication::desktop()->height(); 995 int dh = QApplication::desktop()->height();
989 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 996 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
990 bar.show(); 997 bar.show();
991 int modulo = (er.count()/10)+1; 998 int modulo = (er.count()/10)+1;
992 int incCounter = 0; 999 int incCounter = 0;
993 while ( inR ) { 1000 while ( inR ) {
994 if ( ! bar.isVisible() ) 1001 if ( ! bar.isVisible() )
995 return false; 1002 return false;
996 if ( incCounter % modulo == 0 ) 1003 if ( incCounter % modulo == 0 )
997 bar.setProgress( incCounter ); 1004 bar.setProgress( incCounter );
998 ++incCounter; 1005 ++incCounter;
999 uid = inR->uid(); 1006 uid = inR->uid();
1000 bool skipIncidence = false; 1007 bool skipIncidence = false;
1001 if ( uid.left(15) == QString("last-syncEvent-") ) 1008 if ( uid.left(15) == QString("last-syncEvent-") )
1002 skipIncidence = true; 1009 skipIncidence = true;
1003 QString idS; 1010 QString idS;
1004 qApp->processEvents(); 1011 qApp->processEvents();
1005 if ( !skipIncidence ) { 1012 if ( !skipIncidence ) {
1006 inL = local->incidence( uid ); 1013 inL = local->incidence( uid );
1007 if ( inL ) { // maybe conflict - same uid in both calendars 1014 if ( inL ) { // maybe conflict - same uid in both calendars
1008 if ( (take = takeEvent( inL, inR, mode, fullDateRange )) > 0 ) { 1015 if ( (take = takeEvent( inL, inR, mode, fullDateRange )) > 0 ) {
1009 //qDebug("take %d %s ", take, inL->summary().latin1()); 1016 //qDebug("take %d %s ", take, inL->summary().latin1());
1010 if ( take == 3 ) 1017 if ( take == 3 )
1011 return false; 1018 return false;
1012 if ( take == 1 ) {// take local 1019 if ( take == 1 ) {// take local
1013 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) 1020 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL )
1014 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); 1021 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) );
1015 else 1022 else
1016 idS = inR->IDStr(); 1023 idS = inR->IDStr();
1017 remote->deleteIncidence( inR ); 1024 remote->deleteIncidence( inR );
1018 inR = inL->clone(); 1025 inR = inL->clone();
1019 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 1026 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
1020 if ( mGlobalSyncMode != SYNC_MODE_EXTERNAL ) 1027 if ( mGlobalSyncMode != SYNC_MODE_EXTERNAL )
1021 inR->setIDStr( idS ); 1028 inR->setIDStr( idS );
1022 remote->addIncidence( inR ); 1029 remote->addIncidence( inR );
1023 if ( mSyncKDE ) 1030 if ( mSyncKDE )
1024 inR->setPilotId( 2 ); 1031 inR->setPilotId( 2 );
1025 ++changedRemote; 1032 ++changedRemote;
1026 } else { 1033 } else {
1027 idS = inL->IDStr(); 1034 idS = inL->IDStr();
1028 int pid = inL->pilotId(); 1035 int pid = inL->pilotId();
1029 local->deleteIncidence( inL ); 1036 local->deleteIncidence( inL );
1030 inL = inR->clone(); 1037 inL = inR->clone();
1031 if ( mSyncKDE ) 1038 if ( mSyncKDE )
1032 inL->setPilotId( pid ); 1039 inL->setPilotId( pid );
1033 inL->setIDStr( idS ); 1040 inL->setIDStr( idS );
1034 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1041 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1035 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); 1042 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) );
1036 inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) ); 1043 inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) );
1037 } 1044 }
1038 local->addIncidence( inL ); 1045 local->addIncidence( inL );
1039 ++changedLocal; 1046 ++changedLocal;
1040 } 1047 }
1041 } 1048 }
1042 } else { // no conflict 1049 } else { // no conflict
1043 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1050 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1044 QString des = eventLSync->description(); 1051 QString des = eventLSync->description();
1045 QString pref = "e"; 1052 QString pref = "e";
1046 if ( inR->type() == "Todo" ) 1053 if ( inR->type() == "Todo" )
1047 pref = "t"; 1054 pref = "t";
1048 if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it 1055 if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it
1049 inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE ); 1056 inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE );
1050 //remote->deleteIncidence( inR ); 1057 //remote->deleteIncidence( inR );
1051 ++deletedEventR; 1058 ++deletedEventR;
1052 } else { 1059 } else {
1053 inR->setLastModified( modifiedCalendar ); 1060 inR->setLastModified( modifiedCalendar );
1054 inL = inR->clone(); 1061 inL = inR->clone();
1055 inL->setIDStr( ":" ); 1062 inL->setIDStr( ":" );
1056 local->addIncidence( inL ); 1063 local->addIncidence( inL );
1057 ++addedEvent; 1064 ++addedEvent;
1058 } 1065 }
1059 } else { 1066 } else {
1060 if ( inR->lastModified() > mLastCalendarSync || mode == 5 ) { 1067 if ( inR->lastModified() > mLastCalendarSync || mode == 5 ) {
1061 inR->setLastModified( modifiedCalendar ); 1068 inR->setLastModified( modifiedCalendar );
1062 inL = inR->clone(); 1069 inL = inR->clone();
1063 inL->setIDStr( ":" ); 1070 inL->setIDStr( ":" );
1064 local->addIncidence( inL ); 1071 local->addIncidence( inL );
1065 ++addedEvent; 1072 ++addedEvent;
1066 } else { 1073 } else {
1067 checkExternSyncEvent(eventRSyncSharp, inR); 1074 checkExternSyncEvent(eventRSyncSharp, inR);
1068 remote->deleteIncidence( inR ); 1075 remote->deleteIncidence( inR );
1069 ++deletedEventR; 1076 ++deletedEventR;
1070 } 1077 }
1071 } 1078 }
1072 } 1079 }
1073 } 1080 }
1074 inR = er.next(); 1081 inR = er.next();
1075 } 1082 }
1076 QPtrList<Incidence> el = local->rawIncidences(); 1083 QPtrList<Incidence> el = local->rawIncidences();
1077 inL = el.first(); 1084 inL = el.first();
1078 modulo = (el.count()/10)+1; 1085 modulo = (el.count()/10)+1;
1079 bar.setCaption (i18n("Add / remove events") ); 1086 bar.setCaption (i18n("Add / remove events") );
1080 bar.setTotalSteps ( el.count() ) ; 1087 bar.setTotalSteps ( el.count() ) ;
1081 bar.show(); 1088 bar.show();
1082 incCounter = 0; 1089 incCounter = 0;
1083 1090
1084 while ( inL ) { 1091 while ( inL ) {
1085 1092
1086 qApp->processEvents(); 1093 qApp->processEvents();
1087 if ( ! bar.isVisible() ) 1094 if ( ! bar.isVisible() )
1088 return false; 1095 return false;
1089 if ( incCounter % modulo == 0 ) 1096 if ( incCounter % modulo == 0 )
1090 bar.setProgress( incCounter ); 1097 bar.setProgress( incCounter );
1091 ++incCounter; 1098 ++incCounter;
1092 uid = inL->uid(); 1099 uid = inL->uid();
1093 bool skipIncidence = false; 1100 bool skipIncidence = false;
1094 if ( uid.left(15) == QString("last-syncEvent-") ) 1101 if ( uid.left(15) == QString("last-syncEvent-") )
1095 skipIncidence = true; 1102 skipIncidence = true;
1096 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL && inL->type() == "Journal" ) 1103 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL && inL->type() == "Journal" )
1097 skipIncidence = true; 1104 skipIncidence = true;
1098 if ( !skipIncidence ) { 1105 if ( !skipIncidence ) {
1099 inR = remote->incidence( uid ); 1106 inR = remote->incidence( uid );
1100 if ( ! inR ) { 1107 if ( ! inR ) {
1101 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1108 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1102 if ( !inL->getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { 1109 if ( !inL->getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) {
1103 checkExternSyncEvent(eventLSyncSharp, inL); 1110 checkExternSyncEvent(eventLSyncSharp, inL);
1104 local->deleteIncidence( inL ); 1111 local->deleteIncidence( inL );
1105 ++deletedEventL; 1112 ++deletedEventL;
1106 } else { 1113 } else {
1107 if ( ! mSyncManager->mWriteBackExistingOnly ) { 1114 if ( ! mSyncManager->mWriteBackExistingOnly ) {
1108 inL->removeID(mCurrentSyncDevice ); 1115 inL->removeID(mCurrentSyncDevice );
1109 ++addedEventR; 1116 ++addedEventR;
1110 //qDebug("remote added Incidence %s ", inL->summary().latin1()); 1117 //qDebug("remote added Incidence %s ", inL->summary().latin1());
1111 inL->setLastModified( modifiedCalendar ); 1118 inL->setLastModified( modifiedCalendar );
1112 inR = inL->clone(); 1119 inR = inL->clone();
1113 inR->setIDStr( ":" ); 1120 inR->setIDStr( ":" );
1114 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 1121 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
1115 remote->addIncidence( inR ); 1122 remote->addIncidence( inR );
1116 } 1123 }
1117 } 1124 }
1118 } else { 1125 } else {
1119 if ( inL->lastModified() < mLastCalendarSync && mode != 4 ) { 1126 if ( inL->lastModified() < mLastCalendarSync && mode != 4 ) {
1120 checkExternSyncEvent(eventLSyncSharp, inL); 1127 checkExternSyncEvent(eventLSyncSharp, inL);
1121 local->deleteIncidence( inL ); 1128 local->deleteIncidence( inL );
1122 ++deletedEventL; 1129 ++deletedEventL;
1123 } else { 1130 } else {
1124 if ( ! mSyncManager->mWriteBackExistingOnly ) { 1131 if ( ! mSyncManager->mWriteBackExistingOnly ) {
1125 ++addedEventR; 1132 ++addedEventR;
1126 inL->setLastModified( modifiedCalendar ); 1133 inL->setLastModified( modifiedCalendar );
1127 inR = inL->clone(); 1134 inR = inL->clone();
1128 inR->setIDStr( ":" ); 1135 inR->setIDStr( ":" );
1129 remote->addIncidence( inR ); 1136 remote->addIncidence( inR );
1130 } 1137 }
1131 } 1138 }
1132 } 1139 }
1133 } 1140 }
1134 } 1141 }
1135 inL = el.next(); 1142 inL = el.next();
1136 } 1143 }
1137 int delFut = 0; 1144 int delFut = 0;
1138 int remRem = 0; 1145 int remRem = 0;
1139 if ( mSyncManager->mWriteBackInFuture ) { 1146 if ( mSyncManager->mWriteBackInFuture ) {
1140 er = remote->rawIncidences(); 1147 er = remote->rawIncidences();
1141 remRem = er.count(); 1148 remRem = er.count();
1142 inR = er.first(); 1149 inR = er.first();
1143 QDateTime dt; 1150 QDateTime dt;
1144 QDateTime cur = QDateTime::currentDateTime().addDays( -7 ); 1151 QDateTime cur = QDateTime::currentDateTime().addDays( -7 );
1145 QDateTime end = cur.addDays( (mSyncManager->mWriteBackInFuture +1 ) *7 ); 1152 QDateTime end = cur.addDays( (mSyncManager->mWriteBackInFuture +1 ) *7 );
1146 while ( inR ) { 1153 while ( inR ) {
1147 if ( inR->type() == "Todo" ) { 1154 if ( inR->type() == "Todo" ) {
1148 Todo * t = (Todo*)inR; 1155 Todo * t = (Todo*)inR;
1149 if ( t->hasDueDate() ) 1156 if ( t->hasDueDate() )
1150 dt = t->dtDue(); 1157 dt = t->dtDue();
1151 else 1158 else
1152 dt = cur.addSecs( 62 ); 1159 dt = cur.addSecs( 62 );
1153 } 1160 }
1154 else if (inR->type() == "Event" ) { 1161 else if (inR->type() == "Event" ) {
1155 bool ok; 1162 bool ok;
1156 dt = inR->getNextOccurence( cur, &ok ); 1163 dt = inR->getNextOccurence( cur, &ok );
1157 if ( !ok ) 1164 if ( !ok )
1158 dt = cur.addSecs( -62 ); 1165 dt = cur.addSecs( -62 );
1159 } 1166 }
1160 else 1167 else
1161 dt = inR->dtStart(); 1168 dt = inR->dtStart();
1162 if ( dt < cur || dt > end ) { 1169 if ( dt < cur || dt > end ) {
1163 remote->deleteIncidence( inR ); 1170 remote->deleteIncidence( inR );
1164 ++delFut; 1171 ++delFut;
1165 } 1172 }
1166 inR = er.next(); 1173 inR = er.next();
1167 } 1174 }
1168 } 1175 }
1169 bar.hide(); 1176 bar.hide();
1170 mLastCalendarSync = QDateTime::currentDateTime().addSecs( 1 ); 1177 mLastCalendarSync = QDateTime::currentDateTime().addSecs( 1 );
1171 eventLSync->setReadOnly( false ); 1178 eventLSync->setReadOnly( false );
1172 eventLSync->setDtStart( mLastCalendarSync ); 1179 eventLSync->setDtStart( mLastCalendarSync );
1173 eventRSync->setDtStart( mLastCalendarSync ); 1180 eventRSync->setDtStart( mLastCalendarSync );
1174 eventLSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); 1181 eventLSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) );
1175 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); 1182 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) );
1176 eventRSync->setLocation( i18n("Remote from: ")+mCurrentSyncName ) ; 1183 eventRSync->setLocation( i18n("Remote from: ")+mCurrentSyncName ) ;
1177 eventLSync->setLocation(i18n("Local from: ") + mCurrentSyncName ); 1184 eventLSync->setLocation(i18n("Local from: ") + mCurrentSyncName );
1178 eventLSync->setReadOnly( true ); 1185 eventLSync->setReadOnly( true );
1179 if ( mGlobalSyncMode == SYNC_MODE_NORMAL && !mSyncKDE) // kde is abnormal... 1186 if ( mGlobalSyncMode == SYNC_MODE_NORMAL && !mSyncKDE) // kde is abnormal...
1180 remote->addEvent( eventRSync ); 1187 remote->addEvent( eventRSync );
1181 else 1188 else
1182 delete eventRSync; 1189 delete eventRSync;
1183 QString mes; 1190 QString mes;
1184 mes .sprintf( i18n("Synchronization summary:\n\n %d items added to local\n %d items added to remote\n %d items updated on local\n %d items updated on remote\n %d items deleted on local\n %d items deleted on remote\n"),addedEvent, addedEventR, changedLocal, changedRemote, deletedEventL, deletedEventR ); 1191 mes .sprintf( i18n("Synchronization summary:\n\n %d items added to local\n %d items added to remote\n %d items updated on local\n %d items updated on remote\n %d items deleted on local\n %d items deleted on remote\n"),addedEvent, addedEventR, changedLocal, changedRemote, deletedEventL, deletedEventR );
1185 QString delmess; 1192 QString delmess;
1186 if ( delFut ) { 1193 if ( delFut ) {
1187 delmess.sprintf( i18n("%d items skipped on remote,\nbecause they are in the past or\nmore than %d weeks in the future.\nAfter skipping, remote has\n%d calendar/todo items."), delFut,mSyncManager->mWriteBackInFuture, remRem-delFut); 1194 delmess.sprintf( i18n("%d items skipped on remote,\nbecause they are in the past or\nmore than %d weeks in the future.\nAfter skipping, remote has\n%d calendar/todo items."), delFut,mSyncManager->mWriteBackInFuture, remRem-delFut);
1188 mes += delmess; 1195 mes += delmess;
1189 } 1196 }
1190 if ( mSyncManager->mShowSyncSummary ) { 1197 if ( mSyncManager->mShowSyncSummary ) {
1191 KMessageBox::information(this, mes, i18n("KO/Pi Synchronization") ); 1198 KMessageBox::information(this, mes, i18n("KO/Pi Synchronization") );
1192 } 1199 }
1193 qDebug( mes ); 1200 qDebug( mes );
1194 mCalendar->checkAlarmForIncidence( 0, true ); 1201 mCalendar->checkAlarmForIncidence( 0, true );
1195 return syncOK; 1202 return syncOK;
1196} 1203}
1197 1204
1198void CalendarView::setSyncDevice( QString s ) 1205void CalendarView::setSyncDevice( QString s )
1199{ 1206{
1200 mCurrentSyncDevice= s; 1207 mCurrentSyncDevice= s;
1201} 1208}
1202void CalendarView::setSyncName( QString s ) 1209void CalendarView::setSyncName( QString s )
1203{ 1210{
1204 mCurrentSyncName= s; 1211 mCurrentSyncName= s;
1205} 1212}
1206bool CalendarView::syncCalendar(QString filename, int mode) 1213bool CalendarView::syncCalendar(QString filename, int mode)
1207{ 1214{
1208 //qDebug("syncCalendar %s ", filename.latin1()); 1215 //qDebug("syncCalendar %s ", filename.latin1());
1209 mGlobalSyncMode = SYNC_MODE_NORMAL; 1216 mGlobalSyncMode = SYNC_MODE_NORMAL;
1210 CalendarLocal* calendar = new CalendarLocal(); 1217 CalendarLocal* calendar = new CalendarLocal();
1211 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 1218 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
1212 FileStorage* storage = new FileStorage( calendar ); 1219 FileStorage* storage = new FileStorage( calendar );
1213 bool syncOK = false; 1220 bool syncOK = false;
1214 storage->setFileName( filename ); 1221 storage->setFileName( filename );
1215 // qDebug("loading ... "); 1222 // qDebug("loading ... ");
1216 if ( storage->load() ) { 1223 if ( storage->load() ) {
1217 getEventViewerDialog()->setSyncMode( true ); 1224 getEventViewerDialog()->setSyncMode( true );
1218 syncOK = synchronizeCalendar( mCalendar, calendar, mode ); 1225 syncOK = synchronizeCalendar( mCalendar, calendar, mode );
1219 getEventViewerDialog()->setSyncMode( false ); 1226 getEventViewerDialog()->setSyncMode( false );
1220 if ( syncOK ) { 1227 if ( syncOK ) {
1221 if ( mSyncManager->mWriteBackFile ) 1228 if ( mSyncManager->mWriteBackFile )
1222 { 1229 {
1223 storage->setSaveFormat( new ICalFormat() ); 1230 storage->setSaveFormat( new ICalFormat() );
1224 storage->save(); 1231 storage->save();
1225 } 1232 }
1226 } 1233 }
1227 setModified( true ); 1234 setModified( true );
1228 } 1235 }
1229 delete storage; 1236 delete storage;
1230 delete calendar; 1237 delete calendar;
1231 if ( syncOK ) 1238 if ( syncOK )
1232 updateView(); 1239 updateView();
1233 return syncOK; 1240 return syncOK;
1234} 1241}
1235 1242
1236void CalendarView::syncExternal( int mode ) 1243void CalendarView::syncExternal( int mode )
1237{ 1244{
1238 mGlobalSyncMode = SYNC_MODE_EXTERNAL; 1245 mGlobalSyncMode = SYNC_MODE_EXTERNAL;
1239 1246
1240 qApp->processEvents(); 1247 qApp->processEvents();
1241 CalendarLocal* calendar = new CalendarLocal(); 1248 CalendarLocal* calendar = new CalendarLocal();
1242 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 1249 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
1243 bool syncOK = false; 1250 bool syncOK = false;
1244 bool loadSuccess = false; 1251 bool loadSuccess = false;
1245 PhoneFormat* phoneFormat = 0; 1252 PhoneFormat* phoneFormat = 0;
1246 emit tempDisableBR(true); 1253 emit tempDisableBR(true);
1247#ifndef DESKTOP_VERSION 1254#ifndef DESKTOP_VERSION
1248 SharpFormat* sharpFormat = 0; 1255 SharpFormat* sharpFormat = 0;
1249 if ( mode == 0 ) { // sharp 1256 if ( mode == 0 ) { // sharp
1250 sharpFormat = new SharpFormat () ; 1257 sharpFormat = new SharpFormat () ;
1251 loadSuccess = sharpFormat->load( calendar, mCalendar ); 1258 loadSuccess = sharpFormat->load( calendar, mCalendar );
1252 1259
1253 } else 1260 } else
1254#endif 1261#endif
1255 if ( mode == 1 ) { // phone 1262 if ( mode == 1 ) { // phone
1256 phoneFormat = new PhoneFormat (mCurrentSyncDevice, 1263 phoneFormat = new PhoneFormat (mCurrentSyncDevice,
1257 mSyncManager->mPhoneDevice, 1264 mSyncManager->mPhoneDevice,
1258 mSyncManager->mPhoneConnection, 1265 mSyncManager->mPhoneConnection,
1259 mSyncManager->mPhoneModel); 1266 mSyncManager->mPhoneModel);
1260 loadSuccess = phoneFormat->load( calendar,mCalendar); 1267 loadSuccess = phoneFormat->load( calendar,mCalendar);
1261 1268
1262 } else { 1269 } else {
1263 emit tempDisableBR(false); 1270 emit tempDisableBR(false);
1264 return; 1271 return;
1265 } 1272 }
1266 if ( loadSuccess ) { 1273 if ( loadSuccess ) {
1267 getEventViewerDialog()->setSyncMode( true ); 1274 getEventViewerDialog()->setSyncMode( true );
1268 syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs ); 1275 syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs );
1269 getEventViewerDialog()->setSyncMode( false ); 1276 getEventViewerDialog()->setSyncMode( false );
1270 qApp->processEvents(); 1277 qApp->processEvents();
1271 if ( syncOK ) { 1278 if ( syncOK ) {
1272 if ( mSyncManager->mWriteBackFile ) 1279 if ( mSyncManager->mWriteBackFile )
1273 { 1280 {
1274 QPtrList<Incidence> iL = mCalendar->rawIncidences(); 1281 QPtrList<Incidence> iL = mCalendar->rawIncidences();
1275 Incidence* inc = iL.first(); 1282 Incidence* inc = iL.first();
1276 if ( phoneFormat ) { 1283 if ( phoneFormat ) {
1277 while ( inc ) { 1284 while ( inc ) {
1278 inc->removeID(mCurrentSyncDevice); 1285 inc->removeID(mCurrentSyncDevice);
1279 inc = iL.next(); 1286 inc = iL.next();
1280 } 1287 }
1281 } 1288 }
1282#ifndef DESKTOP_VERSION 1289#ifndef DESKTOP_VERSION
1283 if ( sharpFormat ) 1290 if ( sharpFormat )
1284 sharpFormat->save(calendar); 1291 sharpFormat->save(calendar);
1285#endif 1292#endif
1286 if ( phoneFormat ) 1293 if ( phoneFormat )
1287 phoneFormat->save(calendar); 1294 phoneFormat->save(calendar);
1288 iL = calendar->rawIncidences(); 1295 iL = calendar->rawIncidences();
1289 inc = iL.first(); 1296 inc = iL.first();
1290 Incidence* loc; 1297 Incidence* loc;
1291 while ( inc ) { 1298 while ( inc ) {
1292 if ( inc->tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) { 1299 if ( inc->tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) {
1293 loc = mCalendar->incidence(inc->uid() ); 1300 loc = mCalendar->incidence(inc->uid() );
1294 if ( loc ) { 1301 if ( loc ) {
1295 loc->setID(mCurrentSyncDevice, inc->getID(mCurrentSyncDevice) ); 1302 loc->setID(mCurrentSyncDevice, inc->getID(mCurrentSyncDevice) );
1296 loc->setCsum( mCurrentSyncDevice, inc->getCsum(mCurrentSyncDevice) ); 1303 loc->setCsum( mCurrentSyncDevice, inc->getCsum(mCurrentSyncDevice) );
1297 } 1304 }
1298 } 1305 }
1299 inc = iL.next(); 1306 inc = iL.next();
1300 } 1307 }
1301 Incidence* lse = getLastSyncEvent(); 1308 Incidence* lse = getLastSyncEvent();
1302 if ( lse ) { 1309 if ( lse ) {
1303 lse->setReadOnly( false ); 1310 lse->setReadOnly( false );
1304 lse->setDescription( "" ); 1311 lse->setDescription( "" );
1305 lse->setReadOnly( true ); 1312 lse->setReadOnly( true );
1306 } 1313 }
1307 } 1314 }
1308 } 1315 }
1309 setModified( true ); 1316 setModified( true );
1310 } else { 1317 } else {
1311 QString question = i18n("Sorry, the database access\ncommand failed!\n\nNothing synced!\n") ; 1318 QString question = i18n("Sorry, the database access\ncommand failed!\n\nNothing synced!\n") ;
1312 QMessageBox::information( 0, i18n("KO/Pi Import - ERROR"), 1319 QMessageBox::information( 0, i18n("KO/Pi Import - ERROR"),
1313 question, i18n("Ok")) ; 1320 question, i18n("Ok")) ;
1314 1321
1315 } 1322 }
1316 delete calendar; 1323 delete calendar;
1317 updateView(); 1324 updateView();
1318 emit tempDisableBR(false); 1325 emit tempDisableBR(false);
1319 return ;//syncOK; 1326 return ;//syncOK;
1320 1327
1321} 1328}
1322 1329
1323bool CalendarView::importBday() 1330bool CalendarView::importBday()
1324{ 1331{
1325#ifndef KORG_NOKABC 1332#ifndef KORG_NOKABC
1326 1333
1327#ifdef DESKTOP_VERSION 1334#ifdef DESKTOP_VERSION
1328 KABC::StdAddressBook* AddressBook = KABC::StdAddressBook::self( true ); 1335 KABC::StdAddressBook* AddressBook = KABC::StdAddressBook::self( true );
1329 KABC::AddressBook::Iterator it; 1336 KABC::AddressBook::Iterator it;
1330 int count = 0; 1337 int count = 0;
1331 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) { 1338 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) {
1332 ++count; 1339 ++count;
1333 } 1340 }
1334 QProgressBar bar(count,0 ); 1341 QProgressBar bar(count,0 );
1335 int w = 300; 1342 int w = 300;
1336 if ( QApplication::desktop()->width() < 320 ) 1343 if ( QApplication::desktop()->width() < 320 )
1337 w = 220; 1344 w = 220;
1338 int h = bar.sizeHint().height() ; 1345 int h = bar.sizeHint().height() ;
1339 int dw = QApplication::desktop()->width(); 1346 int dw = QApplication::desktop()->width();
1340 int dh = QApplication::desktop()->height(); 1347 int dh = QApplication::desktop()->height();
1341 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 1348 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
1342 bar.show(); 1349 bar.show();
1343 bar.setCaption (i18n("Reading addressbook - close to abort!") ); 1350 bar.setCaption (i18n("Reading addressbook - close to abort!") );
1344 qApp->processEvents(); 1351 qApp->processEvents();
1345 count = 0; 1352 count = 0;
1346 int addCount = 0; 1353 int addCount = 0;
1347 KCal::Attendee* a = 0; 1354 KCal::Attendee* a = 0;
1348 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) { 1355 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) {
1349 if ( ! bar.isVisible() ) 1356 if ( ! bar.isVisible() )
1350 return false; 1357 return false;
1351 bar.setProgress( count++ ); 1358 bar.setProgress( count++ );
1352 qApp->processEvents(); 1359 qApp->processEvents();
1353 //qDebug("add BDay %s %s", (*it).realName().latin1(),(*it).birthday().date().toString().latin1() ); 1360 //qDebug("add BDay %s %s", (*it).realName().latin1(),(*it).birthday().date().toString().latin1() );
1354 if ( (*it).birthday().date().isValid() ){ 1361 if ( (*it).birthday().date().isValid() ){
1355 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ; 1362 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ;
1356 if ( addAnniversary( (*it).birthday().date(), (*it).assembledName(), a, true ) ) 1363 if ( addAnniversary( (*it).birthday().date(), (*it).assembledName(), a, true ) )
1357 ++addCount; 1364 ++addCount;
1358 } 1365 }
1359 QDate anni = KGlobal::locale()->readDate( (*it).custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d"); 1366 QDate anni = KGlobal::locale()->readDate( (*it).custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d");
1360 if ( anni.isValid() ){ 1367 if ( anni.isValid() ){
1361 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ; 1368 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ;
1362 if ( addAnniversary( anni, (*it).assembledName(), a, false ) ) 1369 if ( addAnniversary( anni, (*it).assembledName(), a, false ) )
1363 ++addCount; 1370 ++addCount;
1364 } 1371 }
1365 } 1372 }
1366 updateView(); 1373 updateView();
1367 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!")); 1374 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!"));
1368#else //DESKTOP_VERSION 1375#else //DESKTOP_VERSION
1369 1376
1370 ExternalAppHandler::instance()->requestBirthdayListFromKAPI("QPE/Application/kopi", this->name() /* name is here the unique uid*/); 1377 ExternalAppHandler::instance()->requestBirthdayListFromKAPI("QPE/Application/kopi", this->name() /* name is here the unique uid*/);
1371 // the result should now arrive through method insertBirthdays 1378 // the result should now arrive through method insertBirthdays
1372 1379
1373#endif //DESKTOP_VERSION 1380#endif //DESKTOP_VERSION
1374 1381
1375#endif //KORG_NOKABC 1382#endif //KORG_NOKABC
1376 1383
1377 1384
1378 return true; 1385 return true;
1379} 1386}
1380 1387
1381// This method will be called from Ka/Pi as a response to requestBirthdayListFromKAPI 1388// This method will be called from Ka/Pi as a response to requestBirthdayListFromKAPI
1382void CalendarView::insertBirthdays(const QString& uid, const QStringList& birthdayList, 1389void CalendarView::insertBirthdays(const QString& uid, const QStringList& birthdayList,
1383 const QStringList& anniversaryList, const QStringList& realNameList, 1390 const QStringList& anniversaryList, const QStringList& realNameList,
1384 const QStringList& emailList, const QStringList& assembledNameList, 1391 const QStringList& emailList, const QStringList& assembledNameList,
1385 const QStringList& uidList) 1392 const QStringList& uidList)
1386{ 1393{
1387 qDebug("CalendarView::insertBirthdays"); 1394 qDebug("CalendarView::insertBirthdays");
1388 if (uid == this->name()) 1395 if (uid == this->name())
1389 { 1396 {
1390 int count = birthdayList.count(); 1397 int count = birthdayList.count();
1391 int addCount = 0; 1398 int addCount = 0;
1392 KCal::Attendee* a = 0; 1399 KCal::Attendee* a = 0;
1393 1400
1394 qDebug("CalView 1 %i", count); 1401 qDebug("CalView 1 %i", count);
1395 1402
1396 QProgressBar bar(count,0 ); 1403 QProgressBar bar(count,0 );
1397 int w = 300; 1404 int w = 300;
1398 if ( QApplication::desktop()->width() < 320 ) 1405 if ( QApplication::desktop()->width() < 320 )
1399 w = 220; 1406 w = 220;
1400 int h = bar.sizeHint().height() ; 1407 int h = bar.sizeHint().height() ;
1401 int dw = QApplication::desktop()->width(); 1408 int dw = QApplication::desktop()->width();
1402 int dh = QApplication::desktop()->height(); 1409 int dh = QApplication::desktop()->height();
1403 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 1410 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
1404 bar.show(); 1411 bar.show();
1405 bar.setCaption (i18n("inserting birthdays - close to abort!") ); 1412 bar.setCaption (i18n("inserting birthdays - close to abort!") );
1406 qApp->processEvents(); 1413 qApp->processEvents();
1407 1414
1408 QDate birthday; 1415 QDate birthday;
1409 QDate anniversary; 1416 QDate anniversary;
1410 QString realName; 1417 QString realName;
1411 QString email; 1418 QString email;
1412 QString assembledName; 1419 QString assembledName;
1413 QString uid; 1420 QString uid;
1414 bool ok = true; 1421 bool ok = true;
1415 for ( int i = 0; i < count; i++) 1422 for ( int i = 0; i < count; i++)
1416 { 1423 {
1417 if ( ! bar.isVisible() ) 1424 if ( ! bar.isVisible() )
1418 return; 1425 return;
1419 bar.setProgress( i ); 1426 bar.setProgress( i );
1420 qApp->processEvents(); 1427 qApp->processEvents();
1421 1428
1422 birthday = KGlobal::locale()->readDate(birthdayList[i], KLocale::ISODate, &ok); 1429 birthday = KGlobal::locale()->readDate(birthdayList[i], KLocale::ISODate, &ok);
1423 if (!ok) { 1430 if (!ok) {
1424 ;//qDebug("CalendarView::insertBirthdays found invalid birthday: %s",birthdayList[i].latin1()); 1431 ;//qDebug("CalendarView::insertBirthdays found invalid birthday: %s",birthdayList[i].latin1());
1425 } 1432 }
1426 1433
1427 anniversary = KGlobal::locale()->readDate(anniversaryList[i], KLocale::ISODate, &ok); 1434 anniversary = KGlobal::locale()->readDate(anniversaryList[i], KLocale::ISODate, &ok);
1428 if (!ok) { 1435 if (!ok) {
1429 ;//qDebug("CalendarView::insertBirthdays found invalid anniversary: %s",anniversaryList[i].latin1()); 1436 ;//qDebug("CalendarView::insertBirthdays found invalid anniversary: %s",anniversaryList[i].latin1());
1430 } 1437 }
1431 realName = realNameList[i]; 1438 realName = realNameList[i];
1432 email = emailList[i]; 1439 email = emailList[i];
1433 assembledName = assembledNameList[i]; 1440 assembledName = assembledNameList[i];
1434 uid = uidList[i]; 1441 uid = uidList[i];
1435 //qDebug("insert birthday in KO/Pi: %s,%s,%s,%s: %s, %s", realName.latin1(), email.latin1(), assembledName.latin1(), uid.latin1(), birthdayList[i].latin1(), anniversaryList[i].latin1() ); 1442 //qDebug("insert birthday in KO/Pi: %s,%s,%s,%s: %s, %s", realName.latin1(), email.latin1(), assembledName.latin1(), uid.latin1(), birthdayList[i].latin1(), anniversaryList[i].latin1() );
1436 1443
1437 if ( birthday.isValid() ){ 1444 if ( birthday.isValid() ){
1438 a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction, 1445 a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction,
1439 KCal::Attendee::ReqParticipant,uid) ; 1446 KCal::Attendee::ReqParticipant,uid) ;
1440 if ( addAnniversary( birthday, assembledName, a, true ) ) 1447 if ( addAnniversary( birthday, assembledName, a, true ) )
1441 ++addCount; 1448 ++addCount;
1442 } 1449 }
1443 1450
1444 if ( anniversary.isValid() ){ 1451 if ( anniversary.isValid() ){
1445 a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction, 1452 a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction,
1446 KCal::Attendee::ReqParticipant,uid) ; 1453 KCal::Attendee::ReqParticipant,uid) ;
1447 if ( addAnniversary( anniversary, assembledName, a, false ) ) 1454 if ( addAnniversary( anniversary, assembledName, a, false ) )
1448 ++addCount; 1455 ++addCount;
1449 } 1456 }
1450 } 1457 }
1451 1458
1452 updateView(); 1459 updateView();
1453 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!")); 1460 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!"));
1454 1461
1455 } 1462 }
1456 1463
1457} 1464}
1458 1465
1459 1466
1460 1467
1461bool CalendarView::addAnniversary( QDate date, QString name, KCal::Attendee* a, bool birthday) 1468bool CalendarView::addAnniversary( QDate date, QString name, KCal::Attendee* a, bool birthday)
1462{ 1469{
1463 //qDebug("addAnni "); 1470 //qDebug("addAnni ");
1464 Event * ev = new Event(); 1471 Event * ev = new Event();
1465 if ( a ) { 1472 if ( a ) {
1466 ev->addAttendee( a ); 1473 ev->addAttendee( a );
1467 } 1474 }
1468 QString kind; 1475 QString kind;
1469 if ( birthday ) 1476 if ( birthday )
1470 kind = i18n( "Birthday" ); 1477 kind = i18n( "Birthday" );
1471 else 1478 else
1472 kind = i18n( "Anniversary" ); 1479 kind = i18n( "Anniversary" );
1473 ev->setSummary( name + " - " + kind ); 1480 ev->setSummary( name + " - " + kind );
1474 ev->setOrganizer(a->email()); 1481 ev->setOrganizer(a->email());
1475 ev->setCategories( kind ); 1482 ev->setCategories( kind );
1476 ev->setDtStart( QDateTime(date) ); 1483 ev->setDtStart( QDateTime(date) );
1477 ev->setDtEnd( QDateTime(date) ); 1484 ev->setDtEnd( QDateTime(date) );
1478 ev->setFloats( true ); 1485 ev->setFloats( true );
1479 Recurrence * rec = ev->recurrence(); 1486 Recurrence * rec = ev->recurrence();
1480 rec->setYearly(Recurrence::rYearlyMonth,1,-1); 1487 rec->setYearly(Recurrence::rYearlyMonth,1,-1);
1481 rec->addYearlyNum( date.month() ); 1488 rec->addYearlyNum( date.month() );
1482 if ( !mCalendar->addAnniversaryNoDup( ev ) ) { 1489 if ( !mCalendar->addAnniversaryNoDup( ev ) ) {
1483 delete ev; 1490 delete ev;
1484 return false; 1491 return false;
1485 } 1492 }
1486 return true; 1493 return true;
1487 1494
1488} 1495}
1489bool CalendarView::importQtopia( const QString &categories, 1496bool CalendarView::importQtopia( const QString &categories,
1490 const QString &datebook, 1497 const QString &datebook,
1491 const QString &todolist ) 1498 const QString &todolist )
1492{ 1499{
1493 1500
1494 QtopiaFormat qtopiaFormat; 1501 QtopiaFormat qtopiaFormat;
1495 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories)); 1502 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories));
1496 if ( !categories.isEmpty() ) qtopiaFormat.load( mCalendar, categories ); 1503 if ( !categories.isEmpty() ) qtopiaFormat.load( mCalendar, categories );
1497 if ( !datebook.isEmpty() ) qtopiaFormat.load( mCalendar, datebook ); 1504 if ( !datebook.isEmpty() ) qtopiaFormat.load( mCalendar, datebook );
1498 if ( !todolist.isEmpty() ) qtopiaFormat.load( mCalendar, todolist ); 1505 if ( !todolist.isEmpty() ) qtopiaFormat.load( mCalendar, todolist );
1499 1506
1500 updateView(); 1507 updateView();
1501 return true; 1508 return true;
1502 1509
1503#if 0 1510#if 0
1504 mGlobalSyncMode = SYNC_MODE_QTOPIA; 1511 mGlobalSyncMode = SYNC_MODE_QTOPIA;
1505 mCurrentSyncDevice = "qtopia-XML"; 1512 mCurrentSyncDevice = "qtopia-XML";
1506 if ( mSyncManager->mAskForPreferences ) 1513 if ( mSyncManager->mAskForPreferences )
1507 edit_sync_options(); 1514 edit_sync_options();
1508 qApp->processEvents(); 1515 qApp->processEvents();
1509 CalendarLocal* calendar = new CalendarLocal(); 1516 CalendarLocal* calendar = new CalendarLocal();
1510 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 1517 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
1511 bool syncOK = false; 1518 bool syncOK = false;
1512 QtopiaFormat qtopiaFormat; 1519 QtopiaFormat qtopiaFormat;
1513 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories)); 1520 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories));
1514 bool loadOk = true; 1521 bool loadOk = true;
1515 if ( !categories.isEmpty() ) 1522 if ( !categories.isEmpty() )
1516 loadOk = qtopiaFormat.load( calendar, categories ); 1523 loadOk = qtopiaFormat.load( calendar, categories );
1517 if ( loadOk && !datebook.isEmpty() ) 1524 if ( loadOk && !datebook.isEmpty() )
1518 loadOk = qtopiaFormat.load( calendar, datebook ); 1525 loadOk = qtopiaFormat.load( calendar, datebook );
1519 if ( loadOk && !todolist.isEmpty() ) 1526 if ( loadOk && !todolist.isEmpty() )
1520 loadOk = qtopiaFormat.load( calendar, todolist ); 1527 loadOk = qtopiaFormat.load( calendar, todolist );
1521 1528
1522 if ( loadOk ) { 1529 if ( loadOk ) {
1523 getEventViewerDialog()->setSyncMode( true ); 1530 getEventViewerDialog()->setSyncMode( true );
1524 syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs ); 1531 syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs );
1525 getEventViewerDialog()->setSyncMode( false ); 1532 getEventViewerDialog()->setSyncMode( false );
1526 qApp->processEvents(); 1533 qApp->processEvents();
1527 if ( syncOK ) { 1534 if ( syncOK ) {
1528 if ( mSyncManager->mWriteBackFile ) 1535 if ( mSyncManager->mWriteBackFile )
1529 { 1536 {
1530 // write back XML file 1537 // write back XML file
1531 1538
1532 } 1539 }
1533 setModified( true ); 1540 setModified( true );
1534 } 1541 }
1535 } else { 1542 } else {
1536 QString question = i18n("Sorry, the file loading\ncommand failed!\n\nNothing synced!\n") ; 1543 QString question = i18n("Sorry, the file loading\ncommand failed!\n\nNothing synced!\n") ;
1537 QMessageBox::information( 0, i18n("KO/Pi Sync - ERROR"), 1544 QMessageBox::information( 0, i18n("KO/Pi Sync - ERROR"),
1538 question, i18n("Ok")) ; 1545 question, i18n("Ok")) ;
1539 } 1546 }
1540 delete calendar; 1547 delete calendar;
1541 updateView(); 1548 updateView();
1542 return syncOK; 1549 return syncOK;
1543 1550
1544 1551
1545#endif 1552#endif
1546 1553
1547} 1554}
1548 1555
1549void CalendarView::setSyncEventsReadOnly() 1556void CalendarView::setSyncEventsReadOnly()
1550{ 1557{
1551 Event * ev; 1558 Event * ev;
1552 QPtrList<Event> eL = mCalendar->rawEvents(); 1559 QPtrList<Event> eL = mCalendar->rawEvents();
1553 ev = eL.first(); 1560 ev = eL.first();
1554 while ( ev ) { 1561 while ( ev ) {
1555 if ( ev->uid().left(15) == QString("last-syncEvent-") ) 1562 if ( ev->uid().left(15) == QString("last-syncEvent-") )
1556 ev->setReadOnly( true ); 1563 ev->setReadOnly( true );
1557 ev = eL.next(); 1564 ev = eL.next();
1558 } 1565 }
1559} 1566}
1560bool CalendarView::openCalendar(QString filename, bool merge) 1567bool CalendarView::openCalendar(QString filename, bool merge)
1561{ 1568{
1562 1569
1563 if (filename.isEmpty()) { 1570 if (filename.isEmpty()) {
1564 return false; 1571 return false;
1565 } 1572 }
1566 1573
1567 if (!QFile::exists(filename)) { 1574 if (!QFile::exists(filename)) {
1568 KMessageBox::error(this,i18n("File does not exist:\n '%1'.").arg(filename)); 1575 KMessageBox::error(this,i18n("File does not exist:\n '%1'.").arg(filename));
1569 return false; 1576 return false;
1570 } 1577 }
1571 1578
1572 globalFlagBlockAgenda = 1; 1579 globalFlagBlockAgenda = 1;
1573 if (!merge) mCalendar->close(); 1580 if (!merge) mCalendar->close();
1574 1581
1575 mStorage->setFileName( filename ); 1582 mStorage->setFileName( filename );
1576 1583
1577 if ( mStorage->load() ) { 1584 if ( mStorage->load() ) {
1578 if ( merge ) ;//setModified( true ); 1585 if ( merge ) ;//setModified( true );
1579 else { 1586 else {
1580 //setModified( true ); 1587 //setModified( true );
1581 mViewManager->setDocumentId( filename ); 1588 mViewManager->setDocumentId( filename );
1582 mDialogManager->setDocumentId( filename ); 1589 mDialogManager->setDocumentId( filename );
1583 mTodoList->setDocumentId( filename ); 1590 mTodoList->setDocumentId( filename );
1584 } 1591 }
1585 globalFlagBlockAgenda = 2; 1592 globalFlagBlockAgenda = 2;
1586 // if ( getLastSyncEvent() ) 1593 // if ( getLastSyncEvent() )
1587 // getLastSyncEvent()->setReadOnly( true ); 1594 // getLastSyncEvent()->setReadOnly( true );
1588 mCalendar->reInitAlarmSettings(); 1595 mCalendar->reInitAlarmSettings();
1589 setSyncEventsReadOnly(); 1596 setSyncEventsReadOnly();
1590 updateUnmanagedViews(); 1597 updateUnmanagedViews();
1591 updateView(); 1598 updateView();
1592 if ( filename != MainWindow::defaultFileName() ) { 1599 if ( filename != MainWindow::defaultFileName() ) {
1593 saveCalendar( MainWindow::defaultFileName() ); 1600 saveCalendar( MainWindow::defaultFileName() );
1594 } else { 1601 } else {
1595 QFileInfo finf ( MainWindow::defaultFileName()); 1602 QFileInfo finf ( MainWindow::defaultFileName());
1596 if ( finf.exists() ) { 1603 if ( finf.exists() ) {
1597 setLoadedFileVersion( finf.lastModified () ); 1604 setLoadedFileVersion( finf.lastModified () );
1598 } 1605 }
1599 } 1606 }
1600 return true; 1607 return true;
1601 } else { 1608 } else {
1602 // while failing to load, the calendar object could 1609 // while failing to load, the calendar object could
1603 // have become partially populated. Clear it out. 1610 // have become partially populated. Clear it out.
1604 if ( !merge ) { 1611 if ( !merge ) {
1605 mCalendar->close(); 1612 mCalendar->close();
1606 mViewManager->setDocumentId( filename ); 1613 mViewManager->setDocumentId( filename );
1607 mDialogManager->setDocumentId( filename ); 1614 mDialogManager->setDocumentId( filename );
1608 mTodoList->setDocumentId( filename ); 1615 mTodoList->setDocumentId( filename );
1609 } 1616 }
1610 1617
1611 //KMessageBox::error(this,i18n("Couldn't load calendar\n '%1'.").arg(filename)); 1618 //KMessageBox::error(this,i18n("Couldn't load calendar\n '%1'.").arg(filename));
1612 1619
1613 QTimer::singleShot ( 1, this, SLOT ( showOpenError() ) ); 1620 QTimer::singleShot ( 1, this, SLOT ( showOpenError() ) );
1614 globalFlagBlockAgenda = 2; 1621 globalFlagBlockAgenda = 2;
1615 mCalendar->reInitAlarmSettings(); 1622 mCalendar->reInitAlarmSettings();
1616 setSyncEventsReadOnly(); 1623 setSyncEventsReadOnly();
1617 updateUnmanagedViews(); 1624 updateUnmanagedViews();
1618 updateView(); 1625 updateView();
1619 } 1626 }
1620 return false; 1627 return false;
1621} 1628}
1622void CalendarView::showOpenError() 1629void CalendarView::showOpenError()
1623{ 1630{
1624 KMessageBox::error(this,i18n("Couldn't load calendar\n.")); 1631 KMessageBox::error(this,i18n("Couldn't load calendar\n."));
1625} 1632}
1626void CalendarView::setLoadedFileVersion(QDateTime dt) 1633void CalendarView::setLoadedFileVersion(QDateTime dt)
1627{ 1634{
1628 loadedFileVersion = dt; 1635 loadedFileVersion = dt;
1629} 1636}
1630bool CalendarView::checkFileChanged(QString fn) 1637bool CalendarView::checkFileChanged(QString fn)
1631{ 1638{
1632 QFileInfo finf ( fn ); 1639 QFileInfo finf ( fn );
1633 if ( !finf.exists() ) 1640 if ( !finf.exists() )
1634 return true; 1641 return true;
1635 QDateTime dt = finf.lastModified (); 1642 QDateTime dt = finf.lastModified ();
1636 if ( dt <= loadedFileVersion ) 1643 if ( dt <= loadedFileVersion )
1637 return false; 1644 return false;
1638 return true; 1645 return true;
1639 1646
1640} 1647}
1641void CalendarView::watchSavedFile() 1648void CalendarView::watchSavedFile()
1642{ 1649{
1643 QFileInfo finf ( MainWindow::defaultFileName()); 1650 QFileInfo finf ( MainWindow::defaultFileName());
1644 if ( !finf.exists() ) 1651 if ( !finf.exists() )
1645 return; 1652 return;
1646 QDateTime dt = finf.lastModified (); 1653 QDateTime dt = finf.lastModified ();
1647 if ( dt < loadedFileVersion ) { 1654 if ( dt < loadedFileVersion ) {
1648 //qDebug("watch %s %s ", dt.toString().latin1(), loadedFileVersion.toString().latin1()); 1655 //qDebug("watch %s %s ", dt.toString().latin1(), loadedFileVersion.toString().latin1());
1649 QTimer::singleShot( 1000 , this, SLOT ( watchSavedFile() ) ); 1656 QTimer::singleShot( 1000 , this, SLOT ( watchSavedFile() ) );
1650 return; 1657 return;
1651 } 1658 }
1652 loadedFileVersion = dt; 1659 loadedFileVersion = dt;
1653} 1660}
1654 1661
1655bool CalendarView::checkFileVersion(QString fn) 1662bool CalendarView::checkFileVersion(QString fn)
1656{ 1663{
1657 QFileInfo finf ( fn ); 1664 QFileInfo finf ( fn );
1658 if ( !finf.exists() ) 1665 if ( !finf.exists() )
1659 return true; 1666 return true;
1660 QDateTime dt = finf.lastModified (); 1667 QDateTime dt = finf.lastModified ();
1661 //qDebug("loaded file version %s",loadedFileVersion.toString().latin1()); 1668 //qDebug("loaded file version %s",loadedFileVersion.toString().latin1());
1662 //qDebug("file on disk version %s",dt.toString().latin1()); 1669 //qDebug("file on disk version %s",dt.toString().latin1());
1663 if ( dt <= loadedFileVersion ) 1670 if ( dt <= loadedFileVersion )
1664 return true; 1671 return true;
1665 int km = KMessageBox::warningYesNoCancel(this, i18n("\nThe file on disk has changed!\nFile size: %1 bytes.\nLast modified: %2\nDo you want to:\n\n - Save and overwrite file?\n - Sync with file, then save?\n - Cancel without saving? \n").arg( QString::number( finf.size())).arg( KGlobal::locale()->formatDateTime(finf.lastModified (), true, true)) , 1672 int km = KMessageBox::warningYesNoCancel(this, i18n("\nThe file on disk has changed!\nFile size: %1 bytes.\nLast modified: %2\nDo you want to:\n\n - Save and overwrite file?\n - Sync with file, then save?\n - Cancel without saving? \n").arg( QString::number( finf.size())).arg( KGlobal::locale()->formatDateTime(finf.lastModified (), true, true)) ,
1666 i18n("KO/Pi Warning"),i18n("Overwrite"), 1673 i18n("KO/Pi Warning"),i18n("Overwrite"),
1667 i18n("Sync+save")); 1674 i18n("Sync+save"));
1668 1675
1669 if ( km == KMessageBox::Cancel ) 1676 if ( km == KMessageBox::Cancel )
1670 return false; 1677 return false;
1671 if ( km == KMessageBox::Yes ) 1678 if ( km == KMessageBox::Yes )
1672 return true; 1679 return true;
1673 1680
1674 setSyncDevice("deleteaftersync" ); 1681 setSyncDevice("deleteaftersync" );
1675 mSyncManager->mAskForPreferences = true; 1682 mSyncManager->mAskForPreferences = true;
1676 mSyncManager->mSyncAlgoPrefs = 3; 1683 mSyncManager->mSyncAlgoPrefs = 3;
1677 mSyncManager->mWriteBackFile = false; 1684 mSyncManager->mWriteBackFile = false;
1678 mSyncManager->mWriteBackExistingOnly = false; 1685 mSyncManager->mWriteBackExistingOnly = false;
1679 mSyncManager->mShowSyncSummary = false; 1686 mSyncManager->mShowSyncSummary = false;
1680 syncCalendar( fn, 3 ); 1687 syncCalendar( fn, 3 );
1681 Event * e = getLastSyncEvent(); 1688 Event * e = getLastSyncEvent();
1682 mCalendar->deleteEvent ( e ); 1689 mCalendar->deleteEvent ( e );
1683 updateView(); 1690 updateView();
1684 return true; 1691 return true;
1685} 1692}
1686 1693
1687bool CalendarView::saveCalendar( QString filename ) 1694bool CalendarView::saveCalendar( QString filename )
1688{ 1695{
1689 1696
1690 // Store back all unsaved data into calendar object 1697 // Store back all unsaved data into calendar object
1691 // qDebug("file %s %d ", filename.latin1() , mViewManager->currentView() ); 1698 // qDebug("file %s %d ", filename.latin1() , mViewManager->currentView() );
1692 if ( mViewManager->currentView() ) 1699 if ( mViewManager->currentView() )
1693 mViewManager->currentView()->flushView(); 1700 mViewManager->currentView()->flushView();
1694 1701
1695 1702
1696 QDateTime lfv = QDateTime::currentDateTime().addSecs( -2); 1703 QDateTime lfv = QDateTime::currentDateTime().addSecs( -2);
1697 mStorage->setSaveFormat( new ICalFormat() ); 1704 mStorage->setSaveFormat( new ICalFormat() );
1698 mStorage->setFileName( filename ); 1705 mStorage->setFileName( filename );
1699 bool success; 1706 bool success;
diff --git a/libkdepim/ksyncmanager.cpp b/libkdepim/ksyncmanager.cpp
index feb184b..e09050e 100644
--- a/libkdepim/ksyncmanager.cpp
+++ b/libkdepim/ksyncmanager.cpp
@@ -1,1396 +1,1408 @@
1/* 1/*
2 This file is part of KDE-Pim/Pi. 2 This file is part of KDE-Pim/Pi.
3 Copyright (c) 2004 Ulf Schenk 3 Copyright (c) 2004 Ulf Schenk
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public 6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either 7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version. 8 version 2 of the License, or (at your option) any later version.
9 9
10 This library is distributed in the hope that it will be useful, 10 This library 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 GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details. 13 Library General Public License for more details.
14 14
15 You should have received a copy of the GNU Library General Public License 15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to 16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20 20
21// $Id$ 21// $Id$
22 22
23#include "ksyncmanager.h" 23#include "ksyncmanager.h"
24 24
25#include <stdlib.h> 25#include <stdlib.h>
26 26
27#ifndef _WIN32_ 27#ifndef _WIN32_
28#include <unistd.h> 28#include <unistd.h>
29#endif 29#endif
30 30
31 31
32#include "ksyncprofile.h" 32#include "ksyncprofile.h"
33#include "ksyncprefsdialog.h" 33#include "ksyncprefsdialog.h"
34#include "kpimprefs.h" 34#include "kpimprefs.h"
35#include <kmessagebox.h> 35#include <kmessagebox.h>
36 36
37#include <qdir.h> 37#include <qdir.h>
38#include <qprogressbar.h> 38#include <qprogressbar.h>
39#include <qpopupmenu.h> 39#include <qpopupmenu.h>
40#include <qpushbutton.h> 40#include <qpushbutton.h>
41#include <qradiobutton.h> 41#include <qradiobutton.h>
42#include <qbuttongroup.h> 42#include <qbuttongroup.h>
43#include <qtimer.h> 43#include <qtimer.h>
44#include <qmessagebox.h> 44#include <qmessagebox.h>
45#include <qapplication.h> 45#include <qapplication.h>
46#include <qlineedit.h> 46#include <qlineedit.h>
47#include <qdialog.h> 47#include <qdialog.h>
48#include <qlayout.h> 48#include <qlayout.h>
49#include <qtextcodec.h> 49#include <qtextcodec.h>
50#include <qlabel.h> 50#include <qlabel.h>
51#include <qcheckbox.h> 51#include <qcheckbox.h>
52 52
53#include <klocale.h> 53#include <klocale.h>
54#include <kglobal.h> 54#include <kglobal.h>
55#include <kconfig.h> 55#include <kconfig.h>
56#include <kfiledialog.h> 56#include <kfiledialog.h>
57 57
58QDateTime KSyncManager::mRequestedSyncEvent;
59
60
58KSyncManager::KSyncManager(QWidget* parent, KSyncInterface* implementation, TargetApp ta, KPimPrefs* prefs, QPopupMenu* syncmenu) 61KSyncManager::KSyncManager(QWidget* parent, KSyncInterface* implementation, TargetApp ta, KPimPrefs* prefs, QPopupMenu* syncmenu)
59 : QObject(), mParent(parent), mImplementation(implementation), mTargetApp(ta), mPrefs(prefs ),mSyncMenu(syncmenu) 62 : QObject(), mParent(parent), mImplementation(implementation), mTargetApp(ta), mPrefs(prefs ),mSyncMenu(syncmenu)
60{ 63{
61 mServerSocket = 0; 64 mServerSocket = 0;
62 bar = new QProgressBar ( 1, 0 ); 65 bar = new QProgressBar ( 1, 0 );
63 bar->setCaption (""); 66 bar->setCaption ("");
64 67
65 int w = 300; 68 int w = 300;
66 if ( QApplication::desktop()->width() < 320 ) 69 if ( QApplication::desktop()->width() < 320 )
67 w = 220; 70 w = 220;
68 int h = bar->sizeHint().height() ; 71 int h = bar->sizeHint().height() ;
69 int dw = QApplication::desktop()->width(); 72 int dw = QApplication::desktop()->width();
70 int dh = QApplication::desktop()->height(); 73 int dh = QApplication::desktop()->height();
71 bar->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 74 bar->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
72 if ( mPrefs->mPassiveSyncAutoStart ) 75 if ( mPrefs->mPassiveSyncAutoStart )
73 enableQuick( false ); 76 enableQuick( false );
74 77
75} 78}
76 79
77KSyncManager::~KSyncManager() 80KSyncManager::~KSyncManager()
78{ 81{
79 delete bar; 82 delete bar;
80} 83}
81 84
82 85
83void KSyncManager::fillSyncMenu() 86void KSyncManager::fillSyncMenu()
84{ 87{
85 if ( mSyncMenu->count() ) 88 if ( mSyncMenu->count() )
86 mSyncMenu->clear(); 89 mSyncMenu->clear();
87 90
88 mSyncMenu->insertItem( i18n("Configure..."), 0 ); 91 mSyncMenu->insertItem( i18n("Configure..."), 0 );
89 mSyncMenu->insertSeparator(); 92 mSyncMenu->insertSeparator();
90 QPopupMenu *clearMenu = new QPopupMenu ( mSyncMenu ); 93 QPopupMenu *clearMenu = new QPopupMenu ( mSyncMenu );
91 mSyncMenu->insertItem( i18n("Remove sync info"),clearMenu, 5000 ); 94 mSyncMenu->insertItem( i18n("Remove sync info"),clearMenu, 5000 );
92 clearMenu->insertItem( i18n("For all profiles"), 1 ); 95 clearMenu->insertItem( i18n("For all profiles"), 1 );
93 clearMenu->insertSeparator(); 96 clearMenu->insertSeparator();
94 connect ( clearMenu, SIGNAL( activated ( int ) ), this, SLOT (slotClearMenu( int ) ) ); 97 connect ( clearMenu, SIGNAL( activated ( int ) ), this, SLOT (slotClearMenu( int ) ) );
95 mSyncMenu->insertSeparator(); 98 mSyncMenu->insertSeparator();
96 if ( mServerSocket == 0 ) { 99 if ( mServerSocket == 0 ) {
97 mSyncMenu->insertItem( i18n("Enable Pi-Sync"), 2 ); 100 mSyncMenu->insertItem( i18n("Enable Pi-Sync"), 2 );
98 } else { 101 } else {
99 mSyncMenu->insertItem( i18n("Disable Pi-Sync"), 3 ); 102 mSyncMenu->insertItem( i18n("Disable Pi-Sync"), 3 );
100 } 103 }
101 mSyncMenu->insertSeparator(); 104 mSyncMenu->insertSeparator();
102 mSyncMenu->insertItem( i18n("Multiple sync"), 1 ); 105 mSyncMenu->insertItem( i18n("Multiple sync"), 1 );
103 mSyncMenu->insertSeparator(); 106 mSyncMenu->insertSeparator();
104 KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); 107 KConfig config ( locateLocal( "config","ksyncprofilesrc" ) );
105 config.setGroup("General"); 108 config.setGroup("General");
106 QStringList prof = config.readListEntry("SyncProfileNames"); 109 QStringList prof = config.readListEntry("SyncProfileNames");
107 mLocalMachineName = config.readEntry("LocalMachineName","undefined"); 110 mLocalMachineName = config.readEntry("LocalMachineName","undefined");
108 if ( prof.count() < 2 ) { 111 if ( prof.count() < 2 ) {
109 prof.clear(); 112 prof.clear();
110 QString externalName; 113 QString externalName;
111#ifdef DESKTOP_VERSION 114#ifdef DESKTOP_VERSION
112#ifdef _WIN32_ 115#ifdef _WIN32_
113 externalName = "OutLook(not_implemented)"; 116 externalName = "OutLook(not_implemented)";
114#else 117#else
115 externalName = "KDE_Desktop"; 118 externalName = "KDE_Desktop";
116#endif 119#endif
117#else 120#else
118 externalName = "Sharp_DTM"; 121 externalName = "Sharp_DTM";
119#endif 122#endif
120 prof << externalName; 123 prof << externalName;
121 prof << i18n("Local_file"); 124 prof << i18n("Local_file");
122 prof << i18n("Last_file"); 125 prof << i18n("Last_file");
123 KSyncProfile* temp = new KSyncProfile (); 126 KSyncProfile* temp = new KSyncProfile ();
124 temp->setName( prof[0] ); 127 temp->setName( prof[0] );
125 temp->writeConfig(&config); 128 temp->writeConfig(&config);
126 temp->setName( prof[1] ); 129 temp->setName( prof[1] );
127 temp->writeConfig(&config); 130 temp->writeConfig(&config);
128 temp->setName( prof[2] ); 131 temp->setName( prof[2] );
129 temp->writeConfig(&config); 132 temp->writeConfig(&config);
130 config.setGroup("General"); 133 config.setGroup("General");
131 config.writeEntry("SyncProfileNames",prof); 134 config.writeEntry("SyncProfileNames",prof);
132 config.writeEntry("ExternSyncProfiles",externalName); 135 config.writeEntry("ExternSyncProfiles",externalName);
133 config.sync(); 136 config.sync();
134 delete temp; 137 delete temp;
135 } 138 }
136 mExternSyncProfiles = config.readListEntry("ExternSyncProfiles"); 139 mExternSyncProfiles = config.readListEntry("ExternSyncProfiles");
137 mSyncProfileNames = prof; 140 mSyncProfileNames = prof;
138 unsigned int i; 141 unsigned int i;
139 for ( i = 0; i < prof.count(); ++i ) { 142 for ( i = 0; i < prof.count(); ++i ) {
140 mSyncMenu->insertItem( prof[i], 1000+i ); 143 mSyncMenu->insertItem( prof[i], 1000+i );
141 clearMenu->insertItem( prof[i], 1000+i ); 144 clearMenu->insertItem( prof[i], 1000+i );
142 if ( i == 2 ) 145 if ( i == 2 )
143 mSyncMenu->insertSeparator(); 146 mSyncMenu->insertSeparator();
144 } 147 }
145 QDir app_dir; 148 QDir app_dir;
146 //US do not display SharpDTM if app is pwmpi, or no sharpfiles available 149 //US do not display SharpDTM if app is pwmpi, or no sharpfiles available
147 if ( mTargetApp == PWMPI) { 150 if ( mTargetApp == PWMPI) {
148 mSyncMenu->removeItem( 1000 ); 151 mSyncMenu->removeItem( 1000 );
149 clearMenu->removeItem( 1000 ); 152 clearMenu->removeItem( 1000 );
150 } 153 }
151#ifndef DESKTOP_VERSION 154#ifndef DESKTOP_VERSION
152 else if (!app_dir.exists(QDir::homeDirPath()+"/Applications/dtm" ) ) { 155 else if (!app_dir.exists(QDir::homeDirPath()+"/Applications/dtm" ) ) {
153 mSyncMenu->removeItem( 1000 ); 156 mSyncMenu->removeItem( 1000 );
154 clearMenu->removeItem( 1000 ); 157 clearMenu->removeItem( 1000 );
155 } 158 }
156#endif 159#endif
157 mSyncMenu->removeItem( 1002 ); 160 mSyncMenu->removeItem( 1002 );
158 clearMenu->removeItem( 1002 ); 161 clearMenu->removeItem( 1002 );
159} 162}
160void KSyncManager::slotClearMenu( int action ) 163void KSyncManager::slotClearMenu( int action )
161{ 164{
162 QString syncDevice; 165 QString syncDevice;
163 if ( action > 999 ) { 166 if ( action > 999 ) {
164 syncDevice = mSyncProfileNames[action - 1000] ; 167 syncDevice = mSyncProfileNames[action - 1000] ;
165 } 168 }
166 169
167 170
168 171
169 int result = 0; 172 int result = 0;
170 QString sd; 173 QString sd;
171 if ( syncDevice.isEmpty() ) 174 if ( syncDevice.isEmpty() )
172 sd = i18n("Do you want to\nclear all sync info\nof all profiles?"); 175 sd = i18n("Do you want to\nclear all sync info\nof all profiles?");
173 else 176 else
174 sd = i18n("Do you want to\nclear the sync\ninfo of profile\n%1?\n"). arg( syncDevice ); 177 sd = i18n("Do you want to\nclear the sync\ninfo of profile\n%1?\n"). arg( syncDevice );
175 178
176 result = QMessageBox::warning( mParent, i18n("Warning!"),sd,i18n("OK"), i18n("Cancel"), 0, 179 result = QMessageBox::warning( mParent, i18n("Warning!"),sd,i18n("OK"), i18n("Cancel"), 0,
177 0, 1 ); 180 0, 1 );
178 if ( result ) 181 if ( result )
179 return; 182 return;
180 mImplementation->removeSyncInfo( syncDevice ); 183 mImplementation->removeSyncInfo( syncDevice );
181} 184}
182void KSyncManager::slotSyncMenu( int action ) 185void KSyncManager::slotSyncMenu( int action )
183{ 186{
184 qDebug("syncaction %d ", action); 187 qDebug("syncaction %d ", action);
185 if ( action == 5000 ) 188 if ( action == 5000 )
186 return; 189 return;
187 if ( action == 0 ) { 190 if ( action == 0 ) {
188 191
189 // seems to be a Qt2 event handling bug 192 // seems to be a Qt2 event handling bug
190 // syncmenu.clear causes a segfault at first time 193 // syncmenu.clear causes a segfault at first time
191 // when we call it after the main event loop, it is ok 194 // when we call it after the main event loop, it is ok
192 // same behaviour when calling OM/Pi via QCOP for the first time 195 // same behaviour when calling OM/Pi via QCOP for the first time
193 QTimer::singleShot ( 1, this, SLOT ( confSync() ) ); 196 QTimer::singleShot ( 1, this, SLOT ( confSync() ) );
194 //confSync(); 197 //confSync();
195 198
196 return; 199 return;
197 } 200 }
198 if ( action == 1 ) { 201 if ( action == 1 ) {
199 multiSync( true ); 202 multiSync( true );
200 return; 203 return;
201 } 204 }
202 if ( action == 2 ) { 205 if ( action == 2 ) {
203 enableQuick(); 206 enableQuick();
204 QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) ); 207 QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) );
205 return; 208 return;
206 } 209 }
207 if ( action == 3 ) { 210 if ( action == 3 ) {
208 delete mServerSocket; 211 delete mServerSocket;
209 mServerSocket = 0; 212 mServerSocket = 0;
210 QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) ); 213 QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) );
211 return; 214 return;
212 } 215 }
213 216
214 if (blockSave()) 217 if (blockSave())
215 return; 218 return;
216 219
217 setBlockSave(true); 220 setBlockSave(true);
218 bool silent = false; 221 bool silent = false;
219 if ( action == 999 ) { 222 if ( action == 999 ) {
220 //special mode for silent syncing 223 //special mode for silent syncing
221 action = 1000; 224 action = 1000;
222 silent = true; 225 silent = true;
223 } 226 }
224 227
225 mCurrentSyncProfile = action - 1000 ; 228 mCurrentSyncProfile = action - 1000 ;
226 mCurrentSyncDevice = mSyncProfileNames[mCurrentSyncProfile] ; 229 mCurrentSyncDevice = mSyncProfileNames[mCurrentSyncProfile] ;
227 mCurrentSyncName = mLocalMachineName ; 230 mCurrentSyncName = mLocalMachineName ;
228 KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); 231 KConfig config ( locateLocal( "config","ksyncprofilesrc" ) );
229 KSyncProfile* temp = new KSyncProfile (); 232 KSyncProfile* temp = new KSyncProfile ();
230 temp->setName(mSyncProfileNames[mCurrentSyncProfile]); 233 temp->setName(mSyncProfileNames[mCurrentSyncProfile]);
231 temp->readConfig(&config); 234 temp->readConfig(&config);
232 if (silent) { 235 if (silent) {
233 mAskForPreferences = false; 236 mAskForPreferences = false;
234 mShowSyncSummary = false; 237 mShowSyncSummary = false;
235 mWriteBackFile = true; 238 mWriteBackFile = true;
236 mSyncAlgoPrefs = 2;// take newest 239 mSyncAlgoPrefs = 2;// take newest
237 } 240 }
238 else { 241 else {
239 mAskForPreferences = temp->getAskForPreferences(); 242 mAskForPreferences = temp->getAskForPreferences();
240 mShowSyncSummary = temp->getShowSummaryAfterSync(); 243 mShowSyncSummary = temp->getShowSummaryAfterSync();
241 mWriteBackFile = temp->getWriteBackFile(); 244 mWriteBackFile = temp->getWriteBackFile();
242 mSyncAlgoPrefs = temp->getSyncPrefs(); 245 mSyncAlgoPrefs = temp->getSyncPrefs();
243 } 246 }
244 mWriteBackExistingOnly = temp->getWriteBackExisting(); 247 mWriteBackExistingOnly = temp->getWriteBackExisting();
245 mIsKapiFile = temp->getIsKapiFile(); 248 mIsKapiFile = temp->getIsKapiFile();
246 mWriteBackInFuture = 0; 249 mWriteBackInFuture = 0;
247 if ( temp->getWriteBackFuture() ) 250 if ( temp->getWriteBackFuture() )
248 mWriteBackInFuture = temp->getWriteBackFutureWeeks( ); 251 mWriteBackInFuture = temp->getWriteBackFutureWeeks( );
249 252
250 if ( action == 1000 ) { 253 if ( action == 1000 ) {
251#ifdef DESKTOP_VERSION 254#ifdef DESKTOP_VERSION
252 syncKDE(); 255 syncKDE();
253#else 256#else
254 syncSharp(); 257 syncSharp();
255#endif 258#endif
256 259
257 } else if ( action == 1001 ) { 260 } else if ( action == 1001 ) {
258 syncLocalFile(); 261 syncLocalFile();
259 262
260 } else if ( action == 1002 ) { 263 } else if ( action == 1002 ) {
261 mWriteBackFile = false; 264 mWriteBackFile = false;
262 mAskForPreferences = false; 265 mAskForPreferences = false;
263 mShowSyncSummary = false; 266 mShowSyncSummary = false;
264 mSyncAlgoPrefs = 3; 267 mSyncAlgoPrefs = 3;
265 quickSyncLocalFile(); 268 quickSyncLocalFile();
266 269
267 } else if ( action >= 1003 ) { 270 } else if ( action >= 1003 ) {
268 if ( temp->getIsLocalFileSync() ) { 271 if ( temp->getIsLocalFileSync() ) {
269 switch(mTargetApp) 272 switch(mTargetApp)
270 { 273 {
271 case (KAPI): 274 case (KAPI):
272 if ( syncWithFile( temp->getRemoteFileNameAB( ), false ) ) 275 if ( syncWithFile( temp->getRemoteFileNameAB( ), false ) )
273 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNameAB(); 276 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNameAB();
274 break; 277 break;
275 case (KOPI): 278 case (KOPI):
276 if ( syncWithFile( temp->getRemoteFileName( ), false ) ) 279 if ( syncWithFile( temp->getRemoteFileName( ), false ) )
277 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileName(); 280 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileName();
278 break; 281 break;
279 case (PWMPI): 282 case (PWMPI):
280 if ( syncWithFile( temp->getRemoteFileNamePWM( ), false ) ) 283 if ( syncWithFile( temp->getRemoteFileNamePWM( ), false ) )
281 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNamePWM(); 284 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNamePWM();
282 break; 285 break;
283 default: 286 default:
284 qDebug("KSyncManager::slotSyncMenu: invalid apptype selected"); 287 qDebug("KSyncManager::slotSyncMenu: invalid apptype selected");
285 break; 288 break;
286 289
287 } 290 }
288 } else { 291 } else {
289 if ( temp->getIsPhoneSync() ) { 292 if ( temp->getIsPhoneSync() ) {
290 mPhoneDevice = temp->getPhoneDevice( ) ; 293 mPhoneDevice = temp->getPhoneDevice( ) ;
291 mPhoneConnection = temp->getPhoneConnection( ); 294 mPhoneConnection = temp->getPhoneConnection( );
292 mPhoneModel = temp->getPhoneModel( ); 295 mPhoneModel = temp->getPhoneModel( );
293 syncPhone(); 296 syncPhone();
294 } else if ( temp->getIsPiSync() ) { 297 } else if ( temp->getIsPiSync() ) {
295 if ( mTargetApp == KAPI ) { 298 if ( mTargetApp == KAPI ) {
296 mPassWordPiSync = temp->getRemotePwAB(); 299 mPassWordPiSync = temp->getRemotePwAB();
297 mActiveSyncPort = temp->getRemotePortAB(); 300 mActiveSyncPort = temp->getRemotePortAB();
298 mActiveSyncIP = temp->getRemoteIPAB(); 301 mActiveSyncIP = temp->getRemoteIPAB();
299 } else if ( mTargetApp == KOPI ) { 302 } else if ( mTargetApp == KOPI ) {
300 mPassWordPiSync = temp->getRemotePw(); 303 mPassWordPiSync = temp->getRemotePw();
301 mActiveSyncPort = temp->getRemotePort(); 304 mActiveSyncPort = temp->getRemotePort();
302 mActiveSyncIP = temp->getRemoteIP(); 305 mActiveSyncIP = temp->getRemoteIP();
303 } else { 306 } else {
304 mPassWordPiSync = temp->getRemotePwPWM(); 307 mPassWordPiSync = temp->getRemotePwPWM();
305 mActiveSyncPort = temp->getRemotePortPWM(); 308 mActiveSyncPort = temp->getRemotePortPWM();
306 mActiveSyncIP = temp->getRemoteIPPWM(); 309 mActiveSyncIP = temp->getRemoteIPPWM();
307 } 310 }
308 syncPi(); 311 syncPi();
309 while ( !mPisyncFinished ) { 312 while ( !mPisyncFinished ) {
310 //qDebug("waiting "); 313 //qDebug("waiting ");
311 qApp->processEvents(); 314 qApp->processEvents();
312 } 315 }
313 } else 316 } else
314 syncRemote( temp ); 317 syncRemote( temp );
315 318
316 } 319 }
317 } 320 }
318 delete temp; 321 delete temp;
319 setBlockSave(false); 322 setBlockSave(false);
320} 323}
321 324
322void KSyncManager::enableQuick( bool ask ) 325void KSyncManager::enableQuick( bool ask )
323{ 326{
324 bool autoStart; 327 bool autoStart;
325 bool changed = false; 328 bool changed = false;
326 if ( ask ) { 329 if ( ask ) {
327 QDialog dia ( 0, "input-dialog", true ); 330 QDialog dia ( 0, "input-dialog", true );
328 QLineEdit lab ( &dia ); 331 QLineEdit lab ( &dia );
329 QVBoxLayout lay( &dia ); 332 QVBoxLayout lay( &dia );
330 lab.setText( mPrefs->mPassiveSyncPort ); 333 lab.setText( mPrefs->mPassiveSyncPort );
331 lay.setMargin(7); 334 lay.setMargin(7);
332 lay.setSpacing(7); 335 lay.setSpacing(7);
333 int po = 9197+mTargetApp; 336 int po = 9197+mTargetApp;
334 QLabel label ( i18n("Port number (Default: %1)").arg(po), &dia ); 337 QLabel label ( i18n("Port number (Default: %1)").arg(po), &dia );
335 lay.addWidget( &label); 338 lay.addWidget( &label);
336 lay.addWidget( &lab); 339 lay.addWidget( &lab);
337 340
338 QLineEdit lepw ( &dia ); 341 QLineEdit lepw ( &dia );
339 lepw.setText( mPrefs->mPassiveSyncPw ); 342 lepw.setText( mPrefs->mPassiveSyncPw );
340 QLabel label2 ( i18n("Password to enable\naccess from remote:"), &dia ); 343 QLabel label2 ( i18n("Password to enable\naccess from remote:"), &dia );
341 lay.addWidget( &label2); 344 lay.addWidget( &label2);
342 lay.addWidget( &lepw); 345 lay.addWidget( &lepw);
343 QCheckBox autostart(i18n("Automatically start\nat application startup"), &dia ); 346 QCheckBox autostart(i18n("Automatically start\nat application startup"), &dia );
344 lay.addWidget( &autostart); 347 lay.addWidget( &autostart);
345 autostart.setChecked( mPrefs->mPassiveSyncAutoStart ); 348 autostart.setChecked( mPrefs->mPassiveSyncAutoStart );
346#ifdef DESKTOP_VERSION 349#ifdef DESKTOP_VERSION
347#ifdef _WIN32_ 350#ifdef _WIN32_
348 QCheckBox syncdesktop( i18n("Automatically sync with Outlook\nwhen receiving sync request"),&dia ); 351 QCheckBox syncdesktop( i18n("Automatically sync with Outlook\nwhen receiving sync request"),&dia );
349#else 352#else
350 QCheckBox syncdesktop( i18n("Automatically sync with KDE-Desktop\nwhen receiving sync request"),&dia ); 353 QCheckBox syncdesktop( i18n("Automatically sync with KDE-Desktop\nwhen receiving sync request"),&dia );
351#endif 354#endif
352 lay.addWidget( &syncdesktop); 355 lay.addWidget( &syncdesktop);
353#else 356#else
354 mPrefs->mPassiveSyncWithDesktop = false; 357 mPrefs->mPassiveSyncWithDesktop = false;
355 QCheckBox syncdesktop( i18n("Automatically sync\nwith KDE-Desktop"),&dia ); 358 QCheckBox syncdesktop( i18n("Automatically sync\nwith KDE-Desktop"),&dia );
356 syncdesktop.hide(); 359 syncdesktop.hide();
357#endif 360#endif
358 syncdesktop.setChecked( mPrefs->mPassiveSyncWithDesktop ); 361 syncdesktop.setChecked( mPrefs->mPassiveSyncWithDesktop );
359 362
360 dia.setFixedSize( 230,120 ); 363 dia.setFixedSize( 230,120 );
361 dia.setCaption( i18n("Enter port for Pi-Sync") ); 364 dia.setCaption( i18n("Enter port for Pi-Sync") );
362 QPushButton pb ( "OK", &dia); 365 QPushButton pb ( "OK", &dia);
363 lay.addWidget( &pb ); 366 lay.addWidget( &pb );
364 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); 367 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) );
365 dia.show(); 368 dia.show();
366 if ( ! dia.exec() ) 369 if ( ! dia.exec() )
367 return; 370 return;
368 dia.hide(); 371 dia.hide();
369 qApp->processEvents(); 372 qApp->processEvents();
370 if ( mPrefs->mPassiveSyncPw != lepw.text() ) { 373 if ( mPrefs->mPassiveSyncPw != lepw.text() ) {
371 changed = true; 374 changed = true;
372 mPrefs->mPassiveSyncPw = lepw.text(); 375 mPrefs->mPassiveSyncPw = lepw.text();
373 } 376 }
374 if ( mPrefs->mPassiveSyncPort != lab.text() ) { 377 if ( mPrefs->mPassiveSyncPort != lab.text() ) {
375 mPrefs->mPassiveSyncPort = lab.text(); 378 mPrefs->mPassiveSyncPort = lab.text();
376 changed = true; 379 changed = true;
377 } 380 }
378 autoStart = autostart.isChecked(); 381 autoStart = autostart.isChecked();
379 if (mPrefs->mPassiveSyncWithDesktop != syncdesktop.isChecked() ) { 382 if (mPrefs->mPassiveSyncWithDesktop != syncdesktop.isChecked() ) {
380 changed = true; 383 changed = true;
381 mPrefs->mPassiveSyncWithDesktop = syncdesktop.isChecked(); 384 mPrefs->mPassiveSyncWithDesktop = syncdesktop.isChecked();
382 } 385 }
383 } 386 }
384 else 387 else
385 autoStart = mPrefs->mPassiveSyncAutoStart; 388 autoStart = mPrefs->mPassiveSyncAutoStart;
386 if ( autoStart != mPrefs->mPassiveSyncAutoStart ) 389 if ( autoStart != mPrefs->mPassiveSyncAutoStart )
387 changed = true; 390 changed = true;
388 bool ok; 391 bool ok;
389 mPrefs->mPassiveSyncAutoStart = false; 392 mPrefs->mPassiveSyncAutoStart = false;
390 Q_UINT16 port = mPrefs->mPassiveSyncPort.toUInt(&ok); 393 Q_UINT16 port = mPrefs->mPassiveSyncPort.toUInt(&ok);
391 if ( ! ok ) { 394 if ( ! ok ) {
392 KMessageBox::information( 0, i18n("No valid port")); 395 KMessageBox::information( 0, i18n("No valid port"));
393 return; 396 return;
394 } 397 }
395 //qDebug("port %d ", port); 398 //qDebug("port %d ", port);
396 mServerSocket = new KServerSocket ( mPrefs->mPassiveSyncPw, port ,1 ); 399 mServerSocket = new KServerSocket ( mPrefs->mPassiveSyncPw, port ,1 );
397 mServerSocket->setFileName( defaultFileName() ); 400 mServerSocket->setFileName( defaultFileName() );
398 //qDebug("connected "); 401 //qDebug("connected ");
399 if ( !mServerSocket->ok() ) { 402 if ( !mServerSocket->ok() ) {
400 KMessageBox::information( 0, i18n("Failed to bind or\nlisten to the port!")); 403 KMessageBox::information( 0, i18n("Failed to bind or\nlisten to the port!"));
401 delete mServerSocket; 404 delete mServerSocket;
402 mServerSocket = 0; 405 mServerSocket = 0;
403 return; 406 return;
404 } 407 }
405 mPrefs->mPassiveSyncAutoStart = autoStart; 408 mPrefs->mPassiveSyncAutoStart = autoStart;
406 if ( changed ) { 409 if ( changed ) {
407 mPrefs->writeConfig(); 410 mPrefs->writeConfig();
408 } 411 }
409 connect( mServerSocket, SIGNAL ( request_file() ),this, SIGNAL ( request_file() ) ); 412 connect( mServerSocket, SIGNAL ( request_file() ),this, SIGNAL ( request_file() ) );
410 connect( mServerSocket, SIGNAL ( file_received( bool ) ), this, SIGNAL ( getFile( bool ) ) ); 413 connect( mServerSocket, SIGNAL ( file_received( bool ) ), this, SIGNAL ( getFile( bool ) ) );
411} 414}
412 415
413void KSyncManager::syncLocalFile() 416void KSyncManager::syncLocalFile()
414{ 417{
415 418
416 QString fn =mPrefs->mLastSyncedLocalFile; 419 QString fn =mPrefs->mLastSyncedLocalFile;
417 QString ext; 420 QString ext;
418 421
419 switch(mTargetApp) 422 switch(mTargetApp)
420 { 423 {
421 case (KAPI): 424 case (KAPI):
422 ext = "(*.vcf)"; 425 ext = "(*.vcf)";
423 break; 426 break;
424 case (KOPI): 427 case (KOPI):
425 ext = "(*.ics/*.vcs)"; 428 ext = "(*.ics/*.vcs)";
426 break; 429 break;
427 case (PWMPI): 430 case (PWMPI):
428 ext = "(*.pwm)"; 431 ext = "(*.pwm)";
429 break; 432 break;
430 default: 433 default:
431 qDebug("KSyncManager::syncLocalFile: invalid apptype selected"); 434 qDebug("KSyncManager::syncLocalFile: invalid apptype selected");
432 break; 435 break;
433 436
434 } 437 }
435 438
436 fn =KFileDialog:: getOpenFileName( fn, i18n("Sync filename"+ext), mParent ); 439 fn =KFileDialog:: getOpenFileName( fn, i18n("Sync filename"+ext), mParent );
437 if ( fn == "" ) 440 if ( fn == "" )
438 return; 441 return;
439 if ( syncWithFile( fn, false ) ) { 442 if ( syncWithFile( fn, false ) ) {
440 qDebug("syncLocalFile() successful "); 443 qDebug("syncLocalFile() successful ");
441 } 444 }
442 445
443} 446}
444 447
445bool KSyncManager::syncWithFile( QString fn , bool quick ) 448bool KSyncManager::syncWithFile( QString fn , bool quick )
446{ 449{
447 bool ret = false; 450 bool ret = false;
448 QFileInfo info; 451 QFileInfo info;
449 info.setFile( fn ); 452 info.setFile( fn );
450 QString mess; 453 QString mess;
451 bool loadbup = true; 454 bool loadbup = true;
452 if ( !info. exists() ) { 455 if ( !info. exists() ) {
453 mess = i18n( "Sync file \n...%1\ndoes not exist!\nNothing synced!\n").arg(fn.right( 30) ); 456 mess = i18n( "Sync file \n...%1\ndoes not exist!\nNothing synced!\n").arg(fn.right( 30) );
454 int result = QMessageBox::warning( mParent, i18n("Warning!"), 457 int result = QMessageBox::warning( mParent, i18n("Warning!"),
455 mess ); 458 mess );
456 return ret; 459 return ret;
457 } 460 }
458 int result = 0; 461 int result = 0;
459 if ( !quick ) { 462 if ( !quick ) {
460 mess = i18n("Sync with file \n...%1\nfrom:\n%2\n").arg(fn.right( 25)).arg(KGlobal::locale()->formatDateTime(info.lastModified (), true, false )); 463 mess = i18n("Sync with file \n...%1\nfrom:\n%2\n").arg(fn.right( 25)).arg(KGlobal::locale()->formatDateTime(info.lastModified (), true, false ));
461 result = QMessageBox::warning( mParent, i18n("Warning!"), 464 result = QMessageBox::warning( mParent, i18n("Warning!"),
462 mess, 465 mess,
463 i18n("Sync"), i18n("Cancel"), 0, 466 i18n("Sync"), i18n("Cancel"), 0,
464 0, 1 ); 467 0, 1 );
465 if ( result ) 468 if ( result )
466 return false; 469 return false;
467 } 470 }
468 if ( mAskForPreferences ) 471 if ( mAskForPreferences )
469 if ( !edit_sync_options()) { 472 if ( !edit_sync_options()) {
470 mParent->topLevelWidget()->setCaption( i18n("Syncing aborted. Nothing synced.") ); 473 mParent->topLevelWidget()->setCaption( i18n("Syncing aborted. Nothing synced.") );
471 return false; 474 return false;
472 } 475 }
473 if ( result == 0 ) { 476 if ( result == 0 ) {
474 //qDebug("Now sycing ... "); 477 //qDebug("Now sycing ... ");
475 if ( ret = mImplementation->sync( this, fn, mSyncAlgoPrefs ) ) 478 if ( ret = mImplementation->sync( this, fn, mSyncAlgoPrefs ) )
476 mParent->topLevelWidget()->setCaption( i18n("Synchronization successful") ); 479 mParent->topLevelWidget()->setCaption( i18n("Synchronization successful") );
477 else 480 else
478 mParent->topLevelWidget()->setCaption( i18n("Sync cancelled or failed. Nothing synced.") ); 481 mParent->topLevelWidget()->setCaption( i18n("Sync cancelled or failed. Nothing synced.") );
479 if ( ! quick ) 482 if ( ! quick )
480 mPrefs->mLastSyncedLocalFile = fn; 483 mPrefs->mLastSyncedLocalFile = fn;
481 } 484 }
482 return ret; 485 return ret;
483} 486}
484 487
485void KSyncManager::quickSyncLocalFile() 488void KSyncManager::quickSyncLocalFile()
486{ 489{
487 490
488 if ( syncWithFile( mPrefs->mLastSyncedLocalFile, true ) ) { 491 if ( syncWithFile( mPrefs->mLastSyncedLocalFile, true ) ) {
489 qDebug("quick syncLocalFile() successful "); 492 qDebug("quick syncLocalFile() successful ");
490 493
491 } 494 }
492} 495}
493 496
494void KSyncManager::multiSync( bool askforPrefs ) 497void KSyncManager::multiSync( bool askforPrefs )
495{ 498{
496 if (blockSave()) 499 if (blockSave())
497 return; 500 return;
498 setBlockSave(true); 501 setBlockSave(true);
499 QString question = i18n("Do you really want\nto multiple sync\nwith all checked profiles?\nSyncing takes some\ntime - all profiles\nare synced twice!"); 502 QString question = i18n("Do you really want\nto multiple sync\nwith all checked profiles?\nSyncing takes some\ntime - all profiles\nare synced twice!");
500 if ( QMessageBox::information( mParent, i18n("KDE-Pim Sync"), 503 if ( QMessageBox::information( mParent, i18n("KDE-Pim Sync"),
501 question, 504 question,
502 i18n("Yes"), i18n("No"), 505 i18n("Yes"), i18n("No"),
503 0, 0 ) != 0 ) { 506 0, 0 ) != 0 ) {
504 setBlockSave(false); 507 setBlockSave(false);
505 mParent->topLevelWidget()->setCaption(i18n("Aborted! Nothing synced!")); 508 mParent->topLevelWidget()->setCaption(i18n("Aborted! Nothing synced!"));
506 return; 509 return;
507 } 510 }
508 mCurrentSyncDevice = i18n("Multiple profiles") ; 511 mCurrentSyncDevice = i18n("Multiple profiles") ;
509 mSyncAlgoPrefs = mPrefs->mRingSyncAlgoPrefs; 512 mSyncAlgoPrefs = mPrefs->mRingSyncAlgoPrefs;
510 if ( askforPrefs ) { 513 if ( askforPrefs ) {
511 if ( !edit_sync_options()) { 514 if ( !edit_sync_options()) {
512 mParent->topLevelWidget()->setCaption( i18n("Syncing aborted. Nothing synced.") ); 515 mParent->topLevelWidget()->setCaption( i18n("Syncing aborted. Nothing synced.") );
513 return; 516 return;
514 } 517 }
515 mPrefs->mRingSyncAlgoPrefs = mSyncAlgoPrefs; 518 mPrefs->mRingSyncAlgoPrefs = mSyncAlgoPrefs;
516 } 519 }
517 mParent->topLevelWidget()->setCaption(i18n("Multiple sync started.") ); 520 mParent->topLevelWidget()->setCaption(i18n("Multiple sync started.") );
518 qApp->processEvents(); 521 qApp->processEvents();
519 int num = ringSync() ; 522 int num = ringSync() ;
520 if ( num > 1 ) 523 if ( num > 1 )
521 ringSync(); 524 ringSync();
522 setBlockSave(false); 525 setBlockSave(false);
523 if ( num ) 526 if ( num )
524 emit save(); 527 emit save();
525 if ( num ) 528 if ( num )
526 mParent->topLevelWidget()->setCaption(i18n("%1 profiles synced. Multiple sync complete!").arg(num) ); 529 mParent->topLevelWidget()->setCaption(i18n("%1 profiles synced. Multiple sync complete!").arg(num) );
527 else 530 else
528 mParent->topLevelWidget()->setCaption(i18n("Nothing synced! No profiles defined for multisync!")); 531 mParent->topLevelWidget()->setCaption(i18n("Nothing synced! No profiles defined for multisync!"));
529 return; 532 return;
530} 533}
531 534
532int KSyncManager::ringSync() 535int KSyncManager::ringSync()
533{ 536{
534 int syncedProfiles = 0; 537 int syncedProfiles = 0;
535 unsigned int i; 538 unsigned int i;
536 QTime timer; 539 QTime timer;
537 KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); 540 KConfig config ( locateLocal( "config","ksyncprofilesrc" ) );
538 QStringList syncProfileNames = mSyncProfileNames; 541 QStringList syncProfileNames = mSyncProfileNames;
539 KSyncProfile* temp = new KSyncProfile (); 542 KSyncProfile* temp = new KSyncProfile ();
540 mAskForPreferences = false; 543 mAskForPreferences = false;
541 for ( i = 0; i < syncProfileNames.count(); ++i ) { 544 for ( i = 0; i < syncProfileNames.count(); ++i ) {
542 mCurrentSyncProfile = i; 545 mCurrentSyncProfile = i;
543 temp->setName(syncProfileNames[mCurrentSyncProfile]); 546 temp->setName(syncProfileNames[mCurrentSyncProfile]);
544 temp->readConfig(&config); 547 temp->readConfig(&config);
545 548
546 bool includeInRingSync; 549 bool includeInRingSync;
547 switch(mTargetApp) 550 switch(mTargetApp)
548 { 551 {
549 case (KAPI): 552 case (KAPI):
550 includeInRingSync = temp->getIncludeInRingSyncAB(); 553 includeInRingSync = temp->getIncludeInRingSyncAB();
551 break; 554 break;
552 case (KOPI): 555 case (KOPI):
553 includeInRingSync = temp->getIncludeInRingSync(); 556 includeInRingSync = temp->getIncludeInRingSync();
554 break; 557 break;
555 case (PWMPI): 558 case (PWMPI):
556 includeInRingSync = temp->getIncludeInRingSyncPWM(); 559 includeInRingSync = temp->getIncludeInRingSyncPWM();
557 break; 560 break;
558 default: 561 default:
559 qDebug("KSyncManager::ringSync: invalid apptype selected"); 562 qDebug("KSyncManager::ringSync: invalid apptype selected");
560 break; 563 break;
561 564
562 } 565 }
563 566
564 567
565 if ( includeInRingSync && ( i < 1 || i > 2 )) { 568 if ( includeInRingSync && ( i < 1 || i > 2 )) {
566 mParent->topLevelWidget()->setCaption(i18n("Profile ")+syncProfileNames[mCurrentSyncProfile]+ i18n(" is synced ... ")); 569 mParent->topLevelWidget()->setCaption(i18n("Profile ")+syncProfileNames[mCurrentSyncProfile]+ i18n(" is synced ... "));
567 ++syncedProfiles; 570 ++syncedProfiles;
568 // mAskForPreferences = temp->getAskForPreferences(); 571 // mAskForPreferences = temp->getAskForPreferences();
569 mWriteBackFile = temp->getWriteBackFile(); 572 mWriteBackFile = temp->getWriteBackFile();
570 mWriteBackExistingOnly = temp->getWriteBackExisting(); 573 mWriteBackExistingOnly = temp->getWriteBackExisting();
571 mWriteBackInFuture = 0; 574 mWriteBackInFuture = 0;
572 if ( temp->getWriteBackFuture() ) 575 if ( temp->getWriteBackFuture() )
573 mWriteBackInFuture = temp->getWriteBackFutureWeeks( ); 576 mWriteBackInFuture = temp->getWriteBackFutureWeeks( );
574 mShowSyncSummary = false; 577 mShowSyncSummary = false;
575 mCurrentSyncDevice = syncProfileNames[i] ; 578 mCurrentSyncDevice = syncProfileNames[i] ;
576 mCurrentSyncName = mLocalMachineName; 579 mCurrentSyncName = mLocalMachineName;
577 if ( i == 0 ) { 580 if ( i == 0 ) {
578#ifdef DESKTOP_VERSION 581#ifdef DESKTOP_VERSION
579 syncKDE(); 582 syncKDE();
580#else 583#else
581 syncSharp(); 584 syncSharp();
582#endif 585#endif
583 } else { 586 } else {
584 if ( temp->getIsLocalFileSync() ) { 587 if ( temp->getIsLocalFileSync() ) {
585 switch(mTargetApp) 588 switch(mTargetApp)
586 { 589 {
587 case (KAPI): 590 case (KAPI):
588 if ( syncWithFile( temp->getRemoteFileNameAB( ), false ) ) 591 if ( syncWithFile( temp->getRemoteFileNameAB( ), false ) )
589 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNameAB(); 592 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNameAB();
590 break; 593 break;
591 case (KOPI): 594 case (KOPI):
592 if ( syncWithFile( temp->getRemoteFileName( ), false ) ) 595 if ( syncWithFile( temp->getRemoteFileName( ), false ) )
593 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileName(); 596 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileName();
594 break; 597 break;
595 case (PWMPI): 598 case (PWMPI):
596 if ( syncWithFile( temp->getRemoteFileNamePWM( ), false ) ) 599 if ( syncWithFile( temp->getRemoteFileNamePWM( ), false ) )
597 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNamePWM(); 600 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNamePWM();
598 break; 601 break;
599 default: 602 default:
600 qDebug("KSyncManager::slotSyncMenu: invalid apptype selected"); 603 qDebug("KSyncManager::slotSyncMenu: invalid apptype selected");
601 break; 604 break;
602 } 605 }
603 } else { 606 } else {
604 if ( temp->getIsPhoneSync() ) { 607 if ( temp->getIsPhoneSync() ) {
605 mPhoneDevice = temp->getPhoneDevice( ) ; 608 mPhoneDevice = temp->getPhoneDevice( ) ;
606 mPhoneConnection = temp->getPhoneConnection( ); 609 mPhoneConnection = temp->getPhoneConnection( );
607 mPhoneModel = temp->getPhoneModel( ); 610 mPhoneModel = temp->getPhoneModel( );
608 syncPhone(); 611 syncPhone();
609 } else if ( temp->getIsPiSync() ) { 612 } else if ( temp->getIsPiSync() ) {
610 if ( mTargetApp == KAPI ) { 613 if ( mTargetApp == KAPI ) {
611 mPassWordPiSync = temp->getRemotePwAB(); 614 mPassWordPiSync = temp->getRemotePwAB();
612 mActiveSyncPort = temp->getRemotePortAB(); 615 mActiveSyncPort = temp->getRemotePortAB();
613 mActiveSyncIP = temp->getRemoteIPAB(); 616 mActiveSyncIP = temp->getRemoteIPAB();
614 } else if ( mTargetApp == KOPI ) { 617 } else if ( mTargetApp == KOPI ) {
615 mPassWordPiSync = temp->getRemotePw(); 618 mPassWordPiSync = temp->getRemotePw();
616 mActiveSyncPort = temp->getRemotePort(); 619 mActiveSyncPort = temp->getRemotePort();
617 mActiveSyncIP = temp->getRemoteIP(); 620 mActiveSyncIP = temp->getRemoteIP();
618 } else { 621 } else {
619 mPassWordPiSync = temp->getRemotePwPWM(); 622 mPassWordPiSync = temp->getRemotePwPWM();
620 mActiveSyncPort = temp->getRemotePortPWM(); 623 mActiveSyncPort = temp->getRemotePortPWM();
621 mActiveSyncIP = temp->getRemoteIPPWM(); 624 mActiveSyncIP = temp->getRemoteIPPWM();
622 } 625 }
623 syncPi(); 626 syncPi();
624 while ( !mPisyncFinished ) { 627 while ( !mPisyncFinished ) {
625 //qDebug("waiting "); 628 //qDebug("waiting ");
626 qApp->processEvents(); 629 qApp->processEvents();
627 } 630 }
628 timer.start(); 631 timer.start();
629 while ( timer.elapsed () < 2000 ) { 632 while ( timer.elapsed () < 2000 ) {
630 qApp->processEvents(); 633 qApp->processEvents();
631 } 634 }
632 } else 635 } else
633 syncRemote( temp, false ); 636 syncRemote( temp, false );
634 637
635 } 638 }
636 } 639 }
637 timer.start(); 640 timer.start();
638 mParent->topLevelWidget()->setCaption(i18n("Multiple sync in progress ... please wait!") ); 641 mParent->topLevelWidget()->setCaption(i18n("Multiple sync in progress ... please wait!") );
639 while ( timer.elapsed () < 2000 ) { 642 while ( timer.elapsed () < 2000 ) {
640 qApp->processEvents(); 643 qApp->processEvents();
641#ifndef _WIN32_ 644#ifndef _WIN32_
642 sleep (1); 645 sleep (1);
643#endif 646#endif
644 } 647 }
645 648
646 } 649 }
647 650
648 } 651 }
649 delete temp; 652 delete temp;
650 return syncedProfiles; 653 return syncedProfiles;
651} 654}
652 655
653void KSyncManager::syncRemote( KSyncProfile* prof, bool ask) 656void KSyncManager::syncRemote( KSyncProfile* prof, bool ask)
654{ 657{
655 QString question; 658 QString question;
656 if ( ask ) { 659 if ( ask ) {
657 question = i18n("Do you really want\nto remote sync\nwith profile \n")+ prof->getName()+" ?\n"; 660 question = i18n("Do you really want\nto remote sync\nwith profile \n")+ prof->getName()+" ?\n";
658 if ( QMessageBox::information( mParent, i18n("Sync"), 661 if ( QMessageBox::information( mParent, i18n("Sync"),
659 question, 662 question,
660 i18n("Yes"), i18n("No"), 663 i18n("Yes"), i18n("No"),
661 0, 0 ) != 0 ) 664 0, 0 ) != 0 )
662 return; 665 return;
663 } 666 }
664 667
665 QString preCommand; 668 QString preCommand;
666 QString localTempFile; 669 QString localTempFile;
667 QString postCommand; 670 QString postCommand;
668 671
669 switch(mTargetApp) 672 switch(mTargetApp)
670 { 673 {
671 case (KAPI): 674 case (KAPI):
672 preCommand = prof->getPreSyncCommandAB(); 675 preCommand = prof->getPreSyncCommandAB();
673 postCommand = prof->getPostSyncCommandAB(); 676 postCommand = prof->getPostSyncCommandAB();
674 localTempFile = prof->getLocalTempFileAB(); 677 localTempFile = prof->getLocalTempFileAB();
675 break; 678 break;
676 case (KOPI): 679 case (KOPI):
677 preCommand = prof->getPreSyncCommand(); 680 preCommand = prof->getPreSyncCommand();
678 postCommand = prof->getPostSyncCommand(); 681 postCommand = prof->getPostSyncCommand();
679 localTempFile = prof->getLocalTempFile(); 682 localTempFile = prof->getLocalTempFile();
680 break; 683 break;
681 case (PWMPI): 684 case (PWMPI):
682 preCommand = prof->getPreSyncCommandPWM(); 685 preCommand = prof->getPreSyncCommandPWM();
683 postCommand = prof->getPostSyncCommandPWM(); 686 postCommand = prof->getPostSyncCommandPWM();
684 localTempFile = prof->getLocalTempFilePWM(); 687 localTempFile = prof->getLocalTempFilePWM();
685 break; 688 break;
686 default: 689 default:
687 qDebug("KSyncManager::syncRemote: invalid apptype selected"); 690 qDebug("KSyncManager::syncRemote: invalid apptype selected");
688 break; 691 break;
689 } 692 }
690 693
691 694
692 int fi; 695 int fi;
693 if ( (fi = preCommand.find("$PWD$")) > 0 ) { 696 if ( (fi = preCommand.find("$PWD$")) > 0 ) {
694 QString pwd = getPassword(); 697 QString pwd = getPassword();
695 preCommand = preCommand.left( fi )+ pwd + preCommand.mid( fi+5 ); 698 preCommand = preCommand.left( fi )+ pwd + preCommand.mid( fi+5 );
696 699
697 } 700 }
698 int maxlen = 30; 701 int maxlen = 30;
699 if ( QApplication::desktop()->width() > 320 ) 702 if ( QApplication::desktop()->width() > 320 )
700 maxlen += 25; 703 maxlen += 25;
701 mParent->topLevelWidget()->setCaption ( i18n( "Copy remote file to local machine..." ) ); 704 mParent->topLevelWidget()->setCaption ( i18n( "Copy remote file to local machine..." ) );
702 int fileSize = 0; 705 int fileSize = 0;
703 int result = system ( preCommand ); 706 int result = system ( preCommand );
704 // 0 : okay 707 // 0 : okay
705 // 256: no such file or dir 708 // 256: no such file or dir
706 // 709 //
707 qDebug("Sync: Remote copy result(0 = okay): %d ",result ); 710 qDebug("Sync: Remote copy result(0 = okay): %d ",result );
708 if ( result != 0 ) { 711 if ( result != 0 ) {
709 unsigned int len = maxlen; 712 unsigned int len = maxlen;
710 while ( len < preCommand.length() ) { 713 while ( len < preCommand.length() ) {
711 preCommand.insert( len , "\n" ); 714 preCommand.insert( len , "\n" );
712 len += maxlen +2; 715 len += maxlen +2;
713 } 716 }
714 question = i18n("Sorry, the copy command failed!\nCommand was:\n%1\n \nTry command on console to get more\ndetailed info about the reason.\n").arg (preCommand) ; 717 question = i18n("Sorry, the copy command failed!\nCommand was:\n%1\n \nTry command on console to get more\ndetailed info about the reason.\n").arg (preCommand) ;
715 QMessageBox::information( mParent, i18n("Sync - ERROR"), 718 QMessageBox::information( mParent, i18n("Sync - ERROR"),
716 question, 719 question,
717 i18n("Okay!")) ; 720 i18n("Okay!")) ;
718 mParent->topLevelWidget()->setCaption ("KDE-Pim"); 721 mParent->topLevelWidget()->setCaption ("KDE-Pim");
719 return; 722 return;
720 } 723 }
721 mParent->topLevelWidget()->setCaption ( i18n( "Copying succeed." ) ); 724 mParent->topLevelWidget()->setCaption ( i18n( "Copying succeed." ) );
722 //qDebug(" file **%s** ",prof->getLocalTempFile().latin1() ); 725 //qDebug(" file **%s** ",prof->getLocalTempFile().latin1() );
723 726
724 if ( syncWithFile( localTempFile, true ) ) { 727 if ( syncWithFile( localTempFile, true ) ) {
725 728
726 if ( mWriteBackFile ) { 729 if ( mWriteBackFile ) {
727 int fi; 730 int fi;
728 if ( (fi = postCommand.find("$PWD$")) > 0 ) { 731 if ( (fi = postCommand.find("$PWD$")) > 0 ) {
729 QString pwd = getPassword(); 732 QString pwd = getPassword();
730 postCommand = postCommand.left( fi )+ pwd + postCommand.mid( fi+5 ); 733 postCommand = postCommand.left( fi )+ pwd + postCommand.mid( fi+5 );
731 734
732 } 735 }
733 mParent->topLevelWidget()->setCaption ( i18n( "Writing back file ..." ) ); 736 mParent->topLevelWidget()->setCaption ( i18n( "Writing back file ..." ) );
734 result = system ( postCommand ); 737 result = system ( postCommand );
735 qDebug("Sync:Writing back file result: %d ", result); 738 qDebug("Sync:Writing back file result: %d ", result);
736 if ( result != 0 ) { 739 if ( result != 0 ) {
737 mParent->topLevelWidget()->setCaption ( i18n( "Writing back file result: " )+QString::number( result ) ); 740 mParent->topLevelWidget()->setCaption ( i18n( "Writing back file result: " )+QString::number( result ) );
738 return; 741 return;
739 } else { 742 } else {
740 mParent->topLevelWidget()->setCaption ( i18n( "Syncronization sucessfully completed" ) ); 743 mParent->topLevelWidget()->setCaption ( i18n( "Syncronization sucessfully completed" ) );
741 } 744 }
742 } 745 }
743 } 746 }
744 return; 747 return;
745} 748}
746bool KSyncManager::edit_pisync_options() 749bool KSyncManager::edit_pisync_options()
747{ 750{
748 QDialog dia( mParent, "dia", true ); 751 QDialog dia( mParent, "dia", true );
749 dia.setCaption( i18n("Pi-Sync options for device: " ) +mCurrentSyncDevice ); 752 dia.setCaption( i18n("Pi-Sync options for device: " ) +mCurrentSyncDevice );
750 QVBoxLayout lay ( &dia ); 753 QVBoxLayout lay ( &dia );
751 lay.setSpacing( 5 ); 754 lay.setSpacing( 5 );
752 lay.setMargin( 3 ); 755 lay.setMargin( 3 );
753 QLabel lab1 ( i18n("Password for remote access:"), &dia); 756 QLabel lab1 ( i18n("Password for remote access:"), &dia);
754 lay.addWidget( &lab1 ); 757 lay.addWidget( &lab1 );
755 QLineEdit le1 (&dia ); 758 QLineEdit le1 (&dia );
756 lay.addWidget( &le1 ); 759 lay.addWidget( &le1 );
757 QLabel lab2 ( i18n("Remote IP address:"), &dia); 760 QLabel lab2 ( i18n("Remote IP address:"), &dia);
758 lay.addWidget( &lab2 ); 761 lay.addWidget( &lab2 );
759 QLineEdit le2 (&dia ); 762 QLineEdit le2 (&dia );
760 lay.addWidget( &le2 ); 763 lay.addWidget( &le2 );
761 QLabel lab3 ( i18n("Remote port number:"), &dia); 764 QLabel lab3 ( i18n("Remote port number:"), &dia);
762 lay.addWidget( &lab3 ); 765 lay.addWidget( &lab3 );
763 QLineEdit le3 (&dia ); 766 QLineEdit le3 (&dia );
764 lay.addWidget( &le3 ); 767 lay.addWidget( &le3 );
765 QPushButton pb ( "OK", &dia); 768 QPushButton pb ( "OK", &dia);
766 lay.addWidget( &pb ); 769 lay.addWidget( &pb );
767 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); 770 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) );
768 le1.setText( mPassWordPiSync ); 771 le1.setText( mPassWordPiSync );
769 le2.setText( mActiveSyncIP ); 772 le2.setText( mActiveSyncIP );
770 le3.setText( mActiveSyncPort ); 773 le3.setText( mActiveSyncPort );
771 if ( dia.exec() ) { 774 if ( dia.exec() ) {
772 mPassWordPiSync = le1.text(); 775 mPassWordPiSync = le1.text();
773 mActiveSyncPort = le3.text(); 776 mActiveSyncPort = le3.text();
774 mActiveSyncIP = le2.text(); 777 mActiveSyncIP = le2.text();
775 return true; 778 return true;
776 } 779 }
777 return false; 780 return false;
778} 781}
779bool KSyncManager::edit_sync_options() 782bool KSyncManager::edit_sync_options()
780{ 783{
781 784
782 QDialog dia( mParent, "dia", true ); 785 QDialog dia( mParent, "dia", true );
783 dia.setCaption( i18n("Device: " ) +mCurrentSyncDevice ); 786 dia.setCaption( i18n("Device: " ) +mCurrentSyncDevice );
784 QButtonGroup gr ( 1, Qt::Horizontal, i18n("Sync preferences"), &dia); 787 QButtonGroup gr ( 1, Qt::Horizontal, i18n("Sync preferences"), &dia);
785 QVBoxLayout lay ( &dia ); 788 QVBoxLayout lay ( &dia );
786 lay.setSpacing( 2 ); 789 lay.setSpacing( 2 );
787 lay.setMargin( 3 ); 790 lay.setMargin( 3 );
788 lay.addWidget(&gr); 791 lay.addWidget(&gr);
789 QRadioButton loc ( i18n("Take local entry on conflict"), &gr ); 792 QRadioButton loc ( i18n("Take local entry on conflict"), &gr );
790 QRadioButton rem ( i18n("Take remote entry on conflict"), &gr ); 793 QRadioButton rem ( i18n("Take remote entry on conflict"), &gr );
791 QRadioButton newest( i18n("Take newest entry on conflict"), &gr ); 794 QRadioButton newest( i18n("Take newest entry on conflict"), &gr );
792 QRadioButton ask( i18n("Ask for every entry on conflict"), &gr ); 795 QRadioButton ask( i18n("Ask for every entry on conflict"), &gr );
793 QRadioButton f_loc( i18n("Force: Take local entry always"), &gr ); 796 QRadioButton f_loc( i18n("Force: Take local entry always"), &gr );
794 QRadioButton f_rem( i18n("Force: Take remote entry always"), &gr ); 797 QRadioButton f_rem( i18n("Force: Take remote entry always"), &gr );
795 //QRadioButton both( i18n("Take both on conflict"), &gr ); 798 //QRadioButton both( i18n("Take both on conflict"), &gr );
796 QPushButton pb ( "OK", &dia); 799 QPushButton pb ( "OK", &dia);
797 lay.addWidget( &pb ); 800 lay.addWidget( &pb );
798 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); 801 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) );
799 switch ( mSyncAlgoPrefs ) { 802 switch ( mSyncAlgoPrefs ) {
800 case 0: 803 case 0:
801 loc.setChecked( true); 804 loc.setChecked( true);
802 break; 805 break;
803 case 1: 806 case 1:
804 rem.setChecked( true ); 807 rem.setChecked( true );
805 break; 808 break;
806 case 2: 809 case 2:
807 newest.setChecked( true); 810 newest.setChecked( true);
808 break; 811 break;
809 case 3: 812 case 3:
810 ask.setChecked( true); 813 ask.setChecked( true);
811 break; 814 break;
812 case 4: 815 case 4:
813 f_loc.setChecked( true); 816 f_loc.setChecked( true);
814 break; 817 break;
815 case 5: 818 case 5:
816 f_rem.setChecked( true); 819 f_rem.setChecked( true);
817 break; 820 break;
818 case 6: 821 case 6:
819 // both.setChecked( true); 822 // both.setChecked( true);
820 break; 823 break;
821 default: 824 default:
822 break; 825 break;
823 } 826 }
824 if ( dia.exec() ) { 827 if ( dia.exec() ) {
825 mSyncAlgoPrefs = rem.isChecked()*1+newest.isChecked()*2+ ask.isChecked()*3+ f_loc.isChecked()*4+ f_rem.isChecked()*5;//+ both.isChecked()*6 ; 828 mSyncAlgoPrefs = rem.isChecked()*1+newest.isChecked()*2+ ask.isChecked()*3+ f_loc.isChecked()*4+ f_rem.isChecked()*5;//+ both.isChecked()*6 ;
826 return true; 829 return true;
827 } 830 }
828 return false; 831 return false;
829} 832}
830 833
831QString KSyncManager::getPassword( ) 834QString KSyncManager::getPassword( )
832{ 835{
833 QString retfile = ""; 836 QString retfile = "";
834 QDialog dia ( mParent, "input-dialog", true ); 837 QDialog dia ( mParent, "input-dialog", true );
835 QLineEdit lab ( &dia ); 838 QLineEdit lab ( &dia );
836 lab.setEchoMode( QLineEdit::Password ); 839 lab.setEchoMode( QLineEdit::Password );
837 QVBoxLayout lay( &dia ); 840 QVBoxLayout lay( &dia );
838 lay.setMargin(7); 841 lay.setMargin(7);
839 lay.setSpacing(7); 842 lay.setSpacing(7);
840 lay.addWidget( &lab); 843 lay.addWidget( &lab);
841 dia.setFixedSize( 230,50 ); 844 dia.setFixedSize( 230,50 );
842 dia.setCaption( i18n("Enter password") ); 845 dia.setCaption( i18n("Enter password") );
843 QPushButton pb ( "OK", &dia); 846 QPushButton pb ( "OK", &dia);
844 lay.addWidget( &pb ); 847 lay.addWidget( &pb );
845 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); 848 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) );
846 dia.show(); 849 dia.show();
847 int res = dia.exec(); 850 int res = dia.exec();
848 if ( res ) 851 if ( res )
849 retfile = lab.text(); 852 retfile = lab.text();
850 dia.hide(); 853 dia.hide();
851 qApp->processEvents(); 854 qApp->processEvents();
852 return retfile; 855 return retfile;
853 856
854} 857}
855 858
856 859
857void KSyncManager::confSync() 860void KSyncManager::confSync()
858{ 861{
859 static KSyncPrefsDialog* sp = 0; 862 static KSyncPrefsDialog* sp = 0;
860 if ( ! sp ) { 863 if ( ! sp ) {
861 sp = new KSyncPrefsDialog( mParent, "syncprefs", true ); 864 sp = new KSyncPrefsDialog( mParent, "syncprefs", true );
862 } 865 }
863 sp->usrReadConfig(); 866 sp->usrReadConfig();
864#ifndef DESKTOP_VERSION 867#ifndef DESKTOP_VERSION
865 sp->showMaximized(); 868 sp->showMaximized();
866#else 869#else
867 sp->show(); 870 sp->show();
868#endif 871#endif
869 sp->exec(); 872 sp->exec();
870 QStringList oldSyncProfileNames = mSyncProfileNames; 873 QStringList oldSyncProfileNames = mSyncProfileNames;
871 mSyncProfileNames = sp->getSyncProfileNames(); 874 mSyncProfileNames = sp->getSyncProfileNames();
872 mLocalMachineName = sp->getLocalMachineName (); 875 mLocalMachineName = sp->getLocalMachineName ();
873 int ii; 876 int ii;
874 for ( ii = 0; ii < oldSyncProfileNames.count(); ++ii ) { 877 for ( ii = 0; ii < oldSyncProfileNames.count(); ++ii ) {
875 if ( ! mSyncProfileNames.contains( oldSyncProfileNames[ii] ) ) 878 if ( ! mSyncProfileNames.contains( oldSyncProfileNames[ii] ) )
876 mImplementation->removeSyncInfo( oldSyncProfileNames[ii] ); 879 mImplementation->removeSyncInfo( oldSyncProfileNames[ii] );
877 } 880 }
878 QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) ); 881 QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) );
879} 882}
880void KSyncManager::syncKDE() 883void KSyncManager::syncKDE()
881{ 884{
882 emit save(); 885 emit save();
883 switch(mTargetApp) 886 switch(mTargetApp)
884 { 887 {
885 case (KAPI): 888 case (KAPI):
886 889
887 break; 890 break;
888 case (KOPI): 891 case (KOPI):
889 { 892 {
890#ifdef DESKTOP_VERSION 893#ifdef DESKTOP_VERSION
891 QString command = qApp->applicationDirPath () + "/kdecaldump"; 894 QString command = qApp->applicationDirPath () + "/kdecaldump";
892#else 895#else
893 QString command = "kdecaldump"; 896 QString command = "kdecaldump";
894#endif 897#endif
895 if ( ! QFile::exists ( command ) ) 898 if ( ! QFile::exists ( command ) )
896 command = "kdecaldump"; 899 command = "kdecaldump";
897 QString fileName = QDir::homeDirPath ()+"/.kdecalendardump.ics"; 900 QString fileName = QDir::homeDirPath ()+"/.kdecalendardump.ics";
898 system ( command.latin1()); 901 system ( command.latin1());
899 if ( syncWithFile( fileName,true ) ) { 902 if ( syncWithFile( fileName,true ) ) {
900 if ( mWriteBackFile ) { 903 if ( mWriteBackFile ) {
901 command += " --read"; 904 command += " --read";
902 system ( command.latin1()); 905 system ( command.latin1());
903 } 906 }
904 } 907 }
905 908
906 } 909 }
907 break; 910 break;
908 case (PWMPI): 911 case (PWMPI):
909 912
910 break; 913 break;
911 default: 914 default:
912 qDebug("KSyncManager::slotSyncMenu: invalid apptype selected"); 915 qDebug("KSyncManager::slotSyncMenu: invalid apptype selected");
913 break; 916 break;
914 917
915 } 918 }
916} 919}
917 920
918void KSyncManager::syncSharp() 921void KSyncManager::syncSharp()
919{ 922{
920 923
921 if ( ! syncExternalApplication("sharp") ) 924 if ( ! syncExternalApplication("sharp") )
922 qDebug("ERROR sync sharp "); 925 qDebug("ERROR sync sharp ");
923} 926}
924 927
925bool KSyncManager::syncExternalApplication(QString resource) 928bool KSyncManager::syncExternalApplication(QString resource)
926{ 929{
927 930
928 emit save(); 931 emit save();
929 932
930 if ( mAskForPreferences ) 933 if ( mAskForPreferences )
931 if ( !edit_sync_options()) { 934 if ( !edit_sync_options()) {
932 mParent->topLevelWidget()->setCaption( i18n("Syncing aborted. Nothing synced.") ); 935 mParent->topLevelWidget()->setCaption( i18n("Syncing aborted. Nothing synced.") );
933 return false; 936 return false;
934 } 937 }
935 938
936 qDebug("Sync extern %s", resource.latin1()); 939 qDebug("Sync extern %s", resource.latin1());
937 940
938 bool syncOK = mImplementation->syncExternal(this, resource); 941 bool syncOK = mImplementation->syncExternal(this, resource);
939 942
940 return syncOK; 943 return syncOK;
941 944
942} 945}
943 946
944void KSyncManager::syncPhone() 947void KSyncManager::syncPhone()
945{ 948{
946 949
947 syncExternalApplication("phone"); 950 syncExternalApplication("phone");
948 951
949} 952}
950 953
951void KSyncManager::showProgressBar(int percentage, QString caption, int total) 954void KSyncManager::showProgressBar(int percentage, QString caption, int total)
952{ 955{
953 if (!bar->isVisible()) 956 if (!bar->isVisible())
954 { 957 {
955 bar->setCaption (caption); 958 bar->setCaption (caption);
956 bar->setTotalSteps ( total ) ; 959 bar->setTotalSteps ( total ) ;
957 960
958 bar->show(); 961 bar->show();
959 } 962 }
960 963
961 bar->setProgress( percentage ); 964 bar->setProgress( percentage );
962} 965}
963 966
964void KSyncManager::hideProgressBar() 967void KSyncManager::hideProgressBar()
965{ 968{
966 bar->hide(); 969 bar->hide();
967} 970}
968 971
969bool KSyncManager::isProgressBarCanceled() 972bool KSyncManager::isProgressBarCanceled()
970{ 973{
971 return !bar->isVisible(); 974 return !bar->isVisible();
972} 975}
973 976
974QString KSyncManager::syncFileName() 977QString KSyncManager::syncFileName()
975{ 978{
976 979
977 QString fn = "tempfile"; 980 QString fn = "tempfile";
978 switch(mTargetApp) 981 switch(mTargetApp)
979 { 982 {
980 case (KAPI): 983 case (KAPI):
981 fn = "tempsyncab.vcf"; 984 fn = "tempsyncab.vcf";
982 break; 985 break;
983 case (KOPI): 986 case (KOPI):
984 fn = "tempsynccal.ics"; 987 fn = "tempsynccal.ics";
985 break; 988 break;
986 case (PWMPI): 989 case (PWMPI):
987 fn = "tempsyncpw.pwm"; 990 fn = "tempsyncpw.pwm";
988 break; 991 break;
989 default: 992 default:
990 break; 993 break;
991 } 994 }
992#ifdef _WIN32_ 995#ifdef _WIN32_
993 return locateLocal( "tmp", fn ); 996 return locateLocal( "tmp", fn );
994#else 997#else
995 return (QString( "/tmp/" )+ fn ); 998 return (QString( "/tmp/" )+ fn );
996#endif 999#endif
997} 1000}
998 1001
999void KSyncManager::syncPi() 1002void KSyncManager::syncPi()
1000{ 1003{
1001 mPisyncFinished = false; 1004 mPisyncFinished = false;
1002 qApp->processEvents(); 1005 qApp->processEvents();
1003 if ( mAskForPreferences ) 1006 if ( mAskForPreferences )
1004 if ( !edit_pisync_options()) { 1007 if ( !edit_pisync_options()) {
1005 mParent->topLevelWidget()->setCaption( i18n("Syncing aborted. Nothing synced.") ); 1008 mParent->topLevelWidget()->setCaption( i18n("Syncing aborted. Nothing synced.") );
1006 return; 1009 return;
1007 } 1010 }
1008 bool ok; 1011 bool ok;
1009 Q_UINT16 port = mActiveSyncPort.toUInt(&ok); 1012 Q_UINT16 port = mActiveSyncPort.toUInt(&ok);
1010 if ( ! ok ) { 1013 if ( ! ok ) {
1011 mParent->topLevelWidget()->setCaption( i18n("Sorry, no valid port.Syncing cancelled.") ); 1014 mParent->topLevelWidget()->setCaption( i18n("Sorry, no valid port.Syncing cancelled.") );
1012 return; 1015 return;
1013 } 1016 }
1014 KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, port, mActiveSyncIP, this ); 1017 KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, port, mActiveSyncIP, this );
1015 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int )), this, SLOT(deleteCommandSocket(KCommandSocket*, int)) ); 1018 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int )), this, SLOT(deleteCommandSocket(KCommandSocket*, int)) );
1016 mParent->topLevelWidget()->setCaption( i18n("Sending request for remote file ...") ); 1019 mParent->topLevelWidget()->setCaption( i18n("Sending request for remote file ...") );
1017 commandSocket->readFile( syncFileName() ); 1020 commandSocket->readFile( syncFileName() );
1018} 1021}
1019 1022
1020void KSyncManager::deleteCommandSocket(KCommandSocket*s, int state) 1023void KSyncManager::deleteCommandSocket(KCommandSocket*s, int state)
1021{ 1024{
1022 //enum { success, errorW, errorR, quiet }; 1025 //enum { success, errorW, errorR, quiet };
1023 if ( state == KCommandSocket::errorR ||state == KCommandSocket::errorTO ) { 1026 if ( state == KCommandSocket::errorR ||state == KCommandSocket::errorTO ) {
1024 mParent->topLevelWidget()->setCaption( i18n("ERROR: Receiving remote file failed.") ); 1027 mParent->topLevelWidget()->setCaption( i18n("ERROR: Receiving remote file failed.") );
1025 delete s; 1028 delete s;
1026 if ( state == KCommandSocket::errorR ) { 1029 if ( state == KCommandSocket::errorR ) {
1027 KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this ); 1030 KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this );
1028 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) ); 1031 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) );
1029 commandSocket->sendStop(); 1032 commandSocket->sendStop();
1030 } 1033 }
1031 mPisyncFinished = true; 1034 mPisyncFinished = true;
1032 return; 1035 return;
1033 1036
1034 } else if ( state == KCommandSocket::errorW ) { 1037 } else if ( state == KCommandSocket::errorW ) {
1035 mParent->topLevelWidget()->setCaption( i18n("ERROR:Writing back file failed.") ); 1038 mParent->topLevelWidget()->setCaption( i18n("ERROR:Writing back file failed.") );
1036 mPisyncFinished = true; 1039 mPisyncFinished = true;
1037 1040
1038 } else if ( state == KCommandSocket::successR ) { 1041 } else if ( state == KCommandSocket::successR ) {
1039 QTimer::singleShot( 1, this , SLOT ( readFileFromSocket())); 1042 QTimer::singleShot( 1, this , SLOT ( readFileFromSocket()));
1040 1043
1041 } else if ( state == KCommandSocket::successW ) { 1044 } else if ( state == KCommandSocket::successW ) {
1042 mParent->topLevelWidget()->setCaption( i18n("Pi-Sync succesful!") ); 1045 mParent->topLevelWidget()->setCaption( i18n("Pi-Sync succesful!") );
1043 mPisyncFinished = true; 1046 mPisyncFinished = true;
1044 } 1047 }
1045 1048
1046 delete s; 1049 delete s;
1047} 1050}
1048 1051
1049void KSyncManager::readFileFromSocket() 1052void KSyncManager::readFileFromSocket()
1050{ 1053{
1051 QString fileName = syncFileName(); 1054 QString fileName = syncFileName();
1052 mParent->topLevelWidget()->setCaption( i18n("Remote file saved to temp file.") ); 1055 mParent->topLevelWidget()->setCaption( i18n("Remote file saved to temp file.") );
1053 if ( ! syncWithFile( fileName , true ) ) { 1056 if ( ! syncWithFile( fileName , true ) ) {
1054 mParent->topLevelWidget()->setCaption( i18n("Syncing failed.") ); 1057 mParent->topLevelWidget()->setCaption( i18n("Syncing failed.") );
1055 mPisyncFinished = true; 1058 mPisyncFinished = true;
1056 return; 1059 return;
1057 } 1060 }
1058 KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this ); 1061 KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this );
1059 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) ); 1062 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) );
1060 if ( mWriteBackFile ) 1063 if ( mWriteBackFile )
1061 commandSocket->writeFile( fileName ); 1064 commandSocket->writeFile( fileName );
1062 else { 1065 else {
1063 commandSocket->sendStop(); 1066 commandSocket->sendStop();
1064 mParent->topLevelWidget()->setCaption( i18n("Pi-Sync succesful!") ); 1067 mParent->topLevelWidget()->setCaption( i18n("Pi-Sync succesful!") );
1065 mPisyncFinished = true; 1068 mPisyncFinished = true;
1066 } 1069 }
1067} 1070}
1068 1071
1069KServerSocket:: KServerSocket ( QString pw, Q_UINT16 port, int backlog, QObject * parent, const char * name ) : QServerSocket( port, backlog, parent, name ) 1072KServerSocket:: KServerSocket ( QString pw, Q_UINT16 port, int backlog, QObject * parent, const char * name ) : QServerSocket( port, backlog, parent, name )
1070{ 1073{
1071 mPassWord = pw; 1074 mPassWord = pw;
1072 mSocket = 0; 1075 mSocket = 0;
1073 mSyncActionDialog = 0; 1076 mSyncActionDialog = 0;
1074 blockRC = false; 1077 blockRC = false;
1075}; 1078};
1076 1079
1077void KServerSocket::newConnection ( int socket ) 1080void KServerSocket::newConnection ( int socket )
1078{ 1081{
1079 // qDebug("KServerSocket:New connection %d ", socket); 1082 // qDebug("KServerSocket:New connection %d ", socket);
1080 if ( mSocket ) { 1083 if ( mSocket ) {
1081 qDebug("KServerSocket::newConnection Socket deleted! "); 1084 qDebug("KServerSocket::newConnection Socket deleted! ");
1082 delete mSocket; 1085 delete mSocket;
1083 mSocket = 0; 1086 mSocket = 0;
1084 } 1087 }
1085 mSocket = new QSocket( this ); 1088 mSocket = new QSocket( this );
1086 connect( mSocket , SIGNAL(readyRead()), this, SLOT(readClient()) ); 1089 connect( mSocket , SIGNAL(readyRead()), this, SLOT(readClient()) );
1087 connect( mSocket , SIGNAL(delayedCloseFinished()), this, SLOT(discardClient()) ); 1090 connect( mSocket , SIGNAL(delayedCloseFinished()), this, SLOT(discardClient()) );
1088 mSocket->setSocket( socket ); 1091 mSocket->setSocket( socket );
1089} 1092}
1090 1093
1091void KServerSocket::discardClient() 1094void KServerSocket::discardClient()
1092{ 1095{
1093 //qDebug(" KServerSocket::discardClient()"); 1096 //qDebug(" KServerSocket::discardClient()");
1094 if ( mSocket ) { 1097 if ( mSocket ) {
1095 delete mSocket; 1098 delete mSocket;
1096 mSocket = 0; 1099 mSocket = 0;
1097 } 1100 }
1098 //emit endConnect(); 1101 //emit endConnect();
1099} 1102}
1100void KServerSocket::readClient() 1103void KServerSocket::readClient()
1101{ 1104{
1102 if ( blockRC ) 1105 if ( blockRC )
1103 return; 1106 return;
1104 if ( mSocket == 0 ) { 1107 if ( mSocket == 0 ) {
1105 qDebug("ERROR::KServerSocket::readClient(): mSocket == 0 "); 1108 qDebug("ERROR::KServerSocket::readClient(): mSocket == 0 ");
1106 return; 1109 return;
1107 } 1110 }
1108 //qDebug("KServerSocket::readClient()"); 1111 //qDebug("KServerSocket::readClient()");
1109 if ( mSocket->canReadLine() ) { 1112 if ( mSocket->canReadLine() ) {
1110 QString line = mSocket->readLine(); 1113 QString line = mSocket->readLine();
1111 //qDebug("KServerSocket readline: %s ", line.latin1()); 1114 //qDebug("KServerSocket readline: %s ", line.latin1());
1112 QStringList tokens = QStringList::split( QRegExp("[ \r\n][ \r\n]*"), line ); 1115 QStringList tokens = QStringList::split( QRegExp("[ \r\n][ \r\n]*"), line );
1113 if ( tokens[0] == "GET" ) { 1116 if ( tokens[0] == "GET" ) {
1114 if ( tokens[1] == mPassWord ) 1117 if ( tokens[1] == mPassWord ) {
1115 //emit sendFile( mSocket ); 1118 //emit sendFile( mSocket );
1119 bool ok = false;
1120 QDateTime dt = KGlobal::locale()->readDateTime( tokens[2], KLocale::ISODate, &ok);
1121 if ( ok )
1122 KSyncManager::mRequestedSyncEvent = dt;
1123 else
1124 KSyncManager::mRequestedSyncEvent = QDateTime();
1116 send_file(); 1125 send_file();
1126 }
1117 else { 1127 else {
1118 KMessageBox::error( 0, i18n("Got send file request\nwith invalid password")); 1128 KMessageBox::error( 0, i18n("Got send file request\nwith invalid password"));
1119 //qDebug("password %s, invalid password %s ",mPassWord.latin1(), tokens[1].latin1() ); 1129 //qDebug("password %s, invalid password %s ",mPassWord.latin1(), tokens[1].latin1() );
1120 } 1130 }
1121 } 1131 }
1122 if ( tokens[0] == "PUT" ) { 1132 if ( tokens[0] == "PUT" ) {
1123 if ( tokens[1] == mPassWord ) { 1133 if ( tokens[1] == mPassWord ) {
1124 //emit getFile( mSocket ); 1134 //emit getFile( mSocket );
1125 blockRC = true; 1135 blockRC = true;
1126 get_file(); 1136 get_file();
1127 } 1137 }
1128 else { 1138 else {
1129 KMessageBox::error( 0, i18n("Got receive file request\nwith invalid password")); 1139 KMessageBox::error( 0, i18n("Got receive file request\nwith invalid password"));
1130 //qDebug("password %s, invalid password %s ",mPassWord.latin1(), tokens[1].latin1() ); 1140 //qDebug("password %s, invalid password %s ",mPassWord.latin1(), tokens[1].latin1() );
1131 } 1141 }
1132 } 1142 }
1133 if ( tokens[0] == "STOP" ) { 1143 if ( tokens[0] == "STOP" ) {
1134 //emit endConnect(); 1144 //emit endConnect();
1135 end_connect(); 1145 end_connect();
1136 } 1146 }
1137 } 1147 }
1138} 1148}
1139void KServerSocket::end_connect() 1149void KServerSocket::end_connect()
1140{ 1150{
1141 delete mSyncActionDialog; 1151 delete mSyncActionDialog;
1142 mSyncActionDialog = 0; 1152 mSyncActionDialog = 0;
1143} 1153}
1144void KServerSocket::send_file() 1154void KServerSocket::send_file()
1145{ 1155{
1146 //qDebug("MainWindow::sendFile(QSocket* s) "); 1156 //qDebug("MainWindow::sendFile(QSocket* s) ");
1147 if ( mSyncActionDialog ) 1157 if ( mSyncActionDialog )
1148 delete mSyncActionDialog; 1158 delete mSyncActionDialog;
1149 mSyncActionDialog = new QDialog ( 0, "input-dialog", true ); 1159 mSyncActionDialog = new QDialog ( 0, "input-dialog", true );
1150 mSyncActionDialog->setCaption(i18n("Received sync request")); 1160 mSyncActionDialog->setCaption(i18n("Received sync request"));
1151 QLabel* label = new QLabel( i18n("Synchronizing from remote ...\n\nDo not use this application!\n\nIf syncing fails\nyou can close this dialog."), mSyncActionDialog ); 1161 QLabel* label = new QLabel( i18n("Synchronizing from remote ...\n\nDo not use this application!\n\nIf syncing fails\nyou can close this dialog."), mSyncActionDialog );
1152 QVBoxLayout* lay = new QVBoxLayout( mSyncActionDialog ); 1162 QVBoxLayout* lay = new QVBoxLayout( mSyncActionDialog );
1153 lay->addWidget( label); 1163 lay->addWidget( label);
1154 lay->setMargin(7); 1164 lay->setMargin(7);
1155 lay->setSpacing(7); 1165 lay->setSpacing(7);
1156 mSyncActionDialog->setFixedSize( 230, 120); 1166 mSyncActionDialog->setFixedSize( 230, 120);
1157 mSyncActionDialog->show(); 1167 mSyncActionDialog->show();
1158 mSyncActionDialog->raise(); 1168 mSyncActionDialog->raise();
1159 emit request_file(); 1169 emit request_file();
1160 qApp->processEvents(); 1170 qApp->processEvents();
1161 QString fileName = mFileName; 1171 QString fileName = mFileName;
1162 QFile file( fileName ); 1172 QFile file( fileName );
1163 if (!file.open( IO_ReadOnly ) ) { 1173 if (!file.open( IO_ReadOnly ) ) {
1164 delete mSyncActionDialog; 1174 delete mSyncActionDialog;
1165 mSyncActionDialog = 0; 1175 mSyncActionDialog = 0;
1166 qDebug("KSS::error open file "); 1176 qDebug("KSS::error open file ");
1167 mSocket->close(); 1177 mSocket->close();
1168 if ( mSocket->state() == QSocket::Idle ) 1178 if ( mSocket->state() == QSocket::Idle )
1169 QTimer::singleShot( 10, this , SLOT ( discardClient())); 1179 QTimer::singleShot( 10, this , SLOT ( discardClient()));
1170 return ; 1180 return ;
1171 1181
1172 } 1182 }
1173 mSyncActionDialog->setCaption( i18n("Sending file...") ); 1183 mSyncActionDialog->setCaption( i18n("Sending file...") );
1174 QTextStream ts( &file ); 1184 QTextStream ts( &file );
1175 ts.setEncoding( QTextStream::Latin1 ); 1185 ts.setEncoding( QTextStream::Latin1 );
1176 1186
1177 QTextStream os( mSocket ); 1187 QTextStream os( mSocket );
1178 os.setEncoding( QTextStream::Latin1 ); 1188 os.setEncoding( QTextStream::Latin1 );
1179 while ( ! ts.atEnd() ) { 1189 while ( ! ts.atEnd() ) {
1180 os << ts.readLine() << "\r\n"; 1190 os << ts.readLine() << "\r\n";
1181 } 1191 }
1182 //os << ts.read(); 1192 //os << ts.read();
1183 file.close(); 1193 file.close();
1184 mSyncActionDialog->setCaption( i18n("Waiting for synced file...") ); 1194 mSyncActionDialog->setCaption( i18n("Waiting for synced file...") );
1185 mSocket->close(); 1195 mSocket->close();
1186 if ( mSocket->state() == QSocket::Idle ) 1196 if ( mSocket->state() == QSocket::Idle )
1187 QTimer::singleShot( 10, this , SLOT ( discardClient())); 1197 QTimer::singleShot( 10, this , SLOT ( discardClient()));
1188} 1198}
1189void KServerSocket::get_file() 1199void KServerSocket::get_file()
1190{ 1200{
1191 mSyncActionDialog->setCaption( i18n("Receiving synced file...") ); 1201 mSyncActionDialog->setCaption( i18n("Receiving synced file...") );
1192 1202
1193 piTime.start(); 1203 piTime.start();
1194 piFileString = ""; 1204 piFileString = "";
1195 QTimer::singleShot( 1, this , SLOT (readBackFileFromSocket( ) )); 1205 QTimer::singleShot( 1, this , SLOT (readBackFileFromSocket( ) ));
1196} 1206}
1197 1207
1198 1208
1199void KServerSocket::readBackFileFromSocket() 1209void KServerSocket::readBackFileFromSocket()
1200{ 1210{
1201 //qDebug("readBackFileFromSocket() %d ", piTime.elapsed ()); 1211 //qDebug("readBackFileFromSocket() %d ", piTime.elapsed ());
1202 while ( mSocket->canReadLine () ) { 1212 while ( mSocket->canReadLine () ) {
1203 piTime.restart(); 1213 piTime.restart();
1204 QString line = mSocket->readLine (); 1214 QString line = mSocket->readLine ();
1205 piFileString += line; 1215 piFileString += line;
1206 //qDebug("readline: %s ", line.latin1()); 1216 //qDebug("readline: %s ", line.latin1());
1207 mSyncActionDialog->setCaption( i18n("Received %1 bytes").arg( piFileString.length() ) ); 1217 mSyncActionDialog->setCaption( i18n("Received %1 bytes").arg( piFileString.length() ) );
1208 1218
1209 } 1219 }
1210 if ( piTime.elapsed () < 3000 ) { 1220 if ( piTime.elapsed () < 3000 ) {
1211 // wait for more 1221 // wait for more
1212 //qDebug("waitformore "); 1222 //qDebug("waitformore ");
1213 QTimer::singleShot( 100, this , SLOT (readBackFileFromSocket( ) )); 1223 QTimer::singleShot( 100, this , SLOT (readBackFileFromSocket( ) ));
1214 return; 1224 return;
1215 } 1225 }
1216 QString fileName = mFileName; 1226 QString fileName = mFileName;
1217 QFile file ( fileName ); 1227 QFile file ( fileName );
1218 if (!file.open( IO_WriteOnly ) ) { 1228 if (!file.open( IO_WriteOnly ) ) {
1219 delete mSyncActionDialog; 1229 delete mSyncActionDialog;
1220 mSyncActionDialog = 0; 1230 mSyncActionDialog = 0;
1221 qDebug("KSS:Error open read back file "); 1231 qDebug("KSS:Error open read back file ");
1222 piFileString = ""; 1232 piFileString = "";
1223 emit file_received( false ); 1233 emit file_received( false );
1224 blockRC = false; 1234 blockRC = false;
1225 return ; 1235 return ;
1226 1236
1227 } 1237 }
1228 1238
1229 // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1)); 1239 // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1));
1230 QTextStream ts ( &file ); 1240 QTextStream ts ( &file );
1231 ts.setEncoding( QTextStream::Latin1 ); 1241 ts.setEncoding( QTextStream::Latin1 );
1232 mSyncActionDialog->setCaption( i18n("Writing file to disk...") ); 1242 mSyncActionDialog->setCaption( i18n("Writing file to disk...") );
1233 ts << piFileString; 1243 ts << piFileString;
1234 mSocket->close(); 1244 mSocket->close();
1235 if ( mSocket->state() == QSocket::Idle ) 1245 if ( mSocket->state() == QSocket::Idle )
1236 QTimer::singleShot( 10, this , SLOT ( discardClient())); 1246 QTimer::singleShot( 10, this , SLOT ( discardClient()));
1237 file.close(); 1247 file.close();
1238 piFileString = ""; 1248 piFileString = "";
1239 emit file_received( true ); 1249 emit file_received( true );
1240 delete mSyncActionDialog; 1250 delete mSyncActionDialog;
1241 mSyncActionDialog = 0; 1251 mSyncActionDialog = 0;
1242 blockRC = false; 1252 blockRC = false;
1243 1253
1244} 1254}
1245 1255
1246KCommandSocket::KCommandSocket ( QString password, Q_UINT16 port, QString host, QObject * parent, const char * name ): QObject( parent, name ) 1256KCommandSocket::KCommandSocket ( QString password, Q_UINT16 port, QString host, QObject * parent, const char * name ): QObject( parent, name )
1247{ 1257{
1248 mPassWord = password; 1258 mPassWord = password;
1249 mSocket = 0; 1259 mSocket = 0;
1250 mPort = port; 1260 mPort = port;
1251 mHost = host; 1261 mHost = host;
1252 1262
1253 mRetVal = quiet; 1263 mRetVal = quiet;
1254 mTimerSocket = new QTimer ( this ); 1264 mTimerSocket = new QTimer ( this );
1255 connect( mTimerSocket, SIGNAL ( timeout () ), this, SLOT ( deleteSocket() ) ); 1265 connect( mTimerSocket, SIGNAL ( timeout () ), this, SLOT ( deleteSocket() ) );
1256} 1266}
1257void KCommandSocket::readFile( QString fn ) 1267void KCommandSocket::readFile( QString fn )
1258{ 1268{
1259 if ( !mSocket ) { 1269 if ( !mSocket ) {
1260 mSocket = new QSocket( this ); 1270 mSocket = new QSocket( this );
1261 connect( mSocket, SIGNAL(readyRead()), this, SLOT(startReadFileFromSocket()) ); 1271 connect( mSocket, SIGNAL(readyRead()), this, SLOT(startReadFileFromSocket()) );
1262 connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); 1272 connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) );
1263 } 1273 }
1264 mFileString = ""; 1274 mFileString = "";
1265 mFileName = fn; 1275 mFileName = fn;
1266 mFirst = true; 1276 mFirst = true;
1267 mSocket->connectToHost( mHost, mPort ); 1277 mSocket->connectToHost( mHost, mPort );
1268 QTextStream os( mSocket ); 1278 QTextStream os( mSocket );
1269 os.setEncoding( QTextStream::Latin1 ); 1279 os.setEncoding( QTextStream::Latin1 );
1270 os << "GET " << mPassWord << "\r\n"; 1280
1281 QString curDt = KGlobal::locale()->formatDateTime(QDateTime::currentDateTime().addSecs(-1),true, true,KLocale::ISODate );
1282 os << "GET " << mPassWord << curDt <<"\r\n";
1271 mTimerSocket->start( 20000 ); 1283 mTimerSocket->start( 20000 );
1272} 1284}
1273 1285
1274void KCommandSocket::writeFile( QString fileName ) 1286void KCommandSocket::writeFile( QString fileName )
1275{ 1287{
1276 if ( !mSocket ) { 1288 if ( !mSocket ) {
1277 mSocket = new QSocket( this ); 1289 mSocket = new QSocket( this );
1278 connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); 1290 connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) );
1279 connect( mSocket, SIGNAL(connected ()), this, SLOT(writeFileToSocket()) ); 1291 connect( mSocket, SIGNAL(connected ()), this, SLOT(writeFileToSocket()) );
1280 } 1292 }
1281 mFileName = fileName ; 1293 mFileName = fileName ;
1282 mSocket->connectToHost( mHost, mPort ); 1294 mSocket->connectToHost( mHost, mPort );
1283} 1295}
1284void KCommandSocket::writeFileToSocket() 1296void KCommandSocket::writeFileToSocket()
1285{ 1297{
1286 QFile file2( mFileName ); 1298 QFile file2( mFileName );
1287 if (!file2.open( IO_ReadOnly ) ) { 1299 if (!file2.open( IO_ReadOnly ) ) {
1288 mRetVal= errorW; 1300 mRetVal= errorW;
1289 mSocket->close(); 1301 mSocket->close();
1290 if ( mSocket->state() == QSocket::Idle ) 1302 if ( mSocket->state() == QSocket::Idle )
1291 QTimer::singleShot( 10, this , SLOT ( deleteSocket())); 1303 QTimer::singleShot( 10, this , SLOT ( deleteSocket()));
1292 return ; 1304 return ;
1293 } 1305 }
1294 QTextStream ts2( &file2 ); 1306 QTextStream ts2( &file2 );
1295 ts2.setEncoding( QTextStream::Latin1 ); 1307 ts2.setEncoding( QTextStream::Latin1 );
1296 QTextStream os2( mSocket ); 1308 QTextStream os2( mSocket );
1297 os2.setEncoding( QTextStream::Latin1 ); 1309 os2.setEncoding( QTextStream::Latin1 );
1298 os2 << "PUT " << mPassWord << "\r\n";; 1310 os2 << "PUT " << mPassWord << "\r\n";;
1299 while ( ! ts2.atEnd() ) { 1311 while ( ! ts2.atEnd() ) {
1300 os2 << ts2.readLine() << "\r\n"; 1312 os2 << ts2.readLine() << "\r\n";
1301 } 1313 }
1302 mRetVal= successW; 1314 mRetVal= successW;
1303 file2.close(); 1315 file2.close();
1304 mSocket->close(); 1316 mSocket->close();
1305 if ( mSocket->state() == QSocket::Idle ) 1317 if ( mSocket->state() == QSocket::Idle )
1306 QTimer::singleShot( 10, this , SLOT ( deleteSocket())); 1318 QTimer::singleShot( 10, this , SLOT ( deleteSocket()));
1307} 1319}
1308void KCommandSocket::sendStop() 1320void KCommandSocket::sendStop()
1309{ 1321{
1310 if ( !mSocket ) { 1322 if ( !mSocket ) {
1311 mSocket = new QSocket( this ); 1323 mSocket = new QSocket( this );
1312 connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); 1324 connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) );
1313 } 1325 }
1314 mSocket->connectToHost( mHost, mPort ); 1326 mSocket->connectToHost( mHost, mPort );
1315 QTextStream os2( mSocket ); 1327 QTextStream os2( mSocket );
1316 os2.setEncoding( QTextStream::Latin1 ); 1328 os2.setEncoding( QTextStream::Latin1 );
1317 os2 << "STOP\r\n"; 1329 os2 << "STOP\r\n";
1318 mSocket->close(); 1330 mSocket->close();
1319 if ( mSocket->state() == QSocket::Idle ) 1331 if ( mSocket->state() == QSocket::Idle )
1320 QTimer::singleShot( 10, this , SLOT ( deleteSocket())); 1332 QTimer::singleShot( 10, this , SLOT ( deleteSocket()));
1321} 1333}
1322 1334
1323void KCommandSocket::startReadFileFromSocket() 1335void KCommandSocket::startReadFileFromSocket()
1324{ 1336{
1325 if ( ! mFirst ) 1337 if ( ! mFirst )
1326 return; 1338 return;
1327 mFirst = false; 1339 mFirst = false;
1328 mTimerSocket->stop(); 1340 mTimerSocket->stop();
1329 mFileString = ""; 1341 mFileString = "";
1330 mTime.start(); 1342 mTime.start();
1331 QTimer::singleShot( 1, this , SLOT (readFileFromSocket( ) )); 1343 QTimer::singleShot( 1, this , SLOT (readFileFromSocket( ) ));
1332 1344
1333} 1345}
1334void KCommandSocket::readFileFromSocket() 1346void KCommandSocket::readFileFromSocket()
1335{ 1347{
1336 //qDebug("readBackFileFromSocket() %d ", mTime.elapsed ()); 1348 //qDebug("readBackFileFromSocket() %d ", mTime.elapsed ());
1337 while ( mSocket->canReadLine () ) { 1349 while ( mSocket->canReadLine () ) {
1338 mTime.restart(); 1350 mTime.restart();
1339 QString line = mSocket->readLine (); 1351 QString line = mSocket->readLine ();
1340 mFileString += line; 1352 mFileString += line;
1341 //qDebug("readline: %s ", line.latin1()); 1353 //qDebug("readline: %s ", line.latin1());
1342 } 1354 }
1343 if ( mTime.elapsed () < 3000 ) { 1355 if ( mTime.elapsed () < 3000 ) {
1344 // wait for more 1356 // wait for more
1345 //qDebug("waitformore "); 1357 //qDebug("waitformore ");
1346 QTimer::singleShot( 100, this , SLOT (readFileFromSocket( ) )); 1358 QTimer::singleShot( 100, this , SLOT (readFileFromSocket( ) ));
1347 return; 1359 return;
1348 } 1360 }
1349 QString fileName = mFileName; 1361 QString fileName = mFileName;
1350 QFile file ( fileName ); 1362 QFile file ( fileName );
1351 if (!file.open( IO_WriteOnly ) ) { 1363 if (!file.open( IO_WriteOnly ) ) {
1352 mFileString = ""; 1364 mFileString = "";
1353 mRetVal = errorR; 1365 mRetVal = errorR;
1354 qDebug("KSS:Error open temp sync file for writing: %s",fileName.latin1() ); 1366 qDebug("KSS:Error open temp sync file for writing: %s",fileName.latin1() );
1355 deleteSocket(); 1367 deleteSocket();
1356 return ; 1368 return ;
1357 1369
1358 } 1370 }
1359 // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1)); 1371 // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1));
1360 QTextStream ts ( &file ); 1372 QTextStream ts ( &file );
1361 ts.setEncoding( QTextStream::Latin1 ); 1373 ts.setEncoding( QTextStream::Latin1 );
1362 ts << mFileString; 1374 ts << mFileString;
1363 file.close(); 1375 file.close();
1364 mFileString = ""; 1376 mFileString = "";
1365 mRetVal = successR; 1377 mRetVal = successR;
1366 mSocket->close(); 1378 mSocket->close();
1367 // if state is not idle, deleteSocket(); is called via 1379 // if state is not idle, deleteSocket(); is called via
1368 // connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); 1380 // connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) );
1369 if ( mSocket->state() == QSocket::Idle ) 1381 if ( mSocket->state() == QSocket::Idle )
1370 deleteSocket(); 1382 deleteSocket();
1371} 1383}
1372 1384
1373void KCommandSocket::deleteSocket() 1385void KCommandSocket::deleteSocket()
1374{ 1386{
1375 //qDebug("KCommandSocket::deleteSocket() "); 1387 //qDebug("KCommandSocket::deleteSocket() ");
1376 if ( mTimerSocket->isActive () ) { 1388 if ( mTimerSocket->isActive () ) {
1377 mTimerSocket->stop(); 1389 mTimerSocket->stop();
1378 mRetVal = errorTO; 1390 mRetVal = errorTO;
1379 qDebug("Connection to remote host timed out"); 1391 qDebug("Connection to remote host timed out");
1380 if ( mSocket ) { 1392 if ( mSocket ) {
1381 mSocket->close(); 1393 mSocket->close();
1382 //if ( mSocket->state() == QSocket::Idle ) 1394 //if ( mSocket->state() == QSocket::Idle )
1383 // deleteSocket(); 1395 // deleteSocket();
1384 delete mSocket; 1396 delete mSocket;
1385 mSocket = 0; 1397 mSocket = 0;
1386 } 1398 }
1387 KMessageBox::error( 0, i18n("Connection to remote\nhost timed out!\nDid you forgot to enable\nsyncing on remote host? ")); 1399 KMessageBox::error( 0, i18n("Connection to remote\nhost timed out!\nDid you forgot to enable\nsyncing on remote host? "));
1388 emit commandFinished( this, mRetVal ); 1400 emit commandFinished( this, mRetVal );
1389 return; 1401 return;
1390 } 1402 }
1391 //qDebug("KCommandSocket::deleteSocket() %d", mRetVal ); 1403 //qDebug("KCommandSocket::deleteSocket() %d", mRetVal );
1392 if ( mSocket) 1404 if ( mSocket)
1393 delete mSocket; 1405 delete mSocket;
1394 mSocket = 0; 1406 mSocket = 0;
1395 emit commandFinished( this, mRetVal ); 1407 emit commandFinished( this, mRetVal );
1396} 1408}
diff --git a/libkdepim/ksyncmanager.h b/libkdepim/ksyncmanager.h
index aa32e28..2af891b 100644
--- a/libkdepim/ksyncmanager.h
+++ b/libkdepim/ksyncmanager.h
@@ -1,213 +1,214 @@
1/* 1/*
2 This file is part of KDE-Pim/Pi. 2 This file is part of KDE-Pim/Pi.
3 Copyright (c) 2004 Ulf Schenk 3 Copyright (c) 2004 Ulf Schenk
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public 6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either 7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version. 8 version 2 of the License, or (at your option) any later version.
9 9
10 This library is distributed in the hope that it will be useful, 10 This library 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 GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details. 13 Library General Public License for more details.
14 14
15 You should have received a copy of the GNU Library General Public License 15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to 16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19 19
20 $Id$ 20 $Id$
21*/ 21*/
22#ifndef _KSYNCMANAGER_H 22#ifndef _KSYNCMANAGER_H
23#define _KSYNCMANAGER_H 23#define _KSYNCMANAGER_H
24 24
25#include <qobject.h> 25#include <qobject.h>
26#include <qstring.h> 26#include <qstring.h>
27#include <qsocket.h> 27#include <qsocket.h>
28#include <qdatetime.h> 28#include <qdatetime.h>
29#include <qserversocket.h> 29#include <qserversocket.h>
30#include <qtextstream.h> 30#include <qtextstream.h>
31#include <qregexp.h> 31#include <qregexp.h>
32 32
33class QPopupMenu; 33class QPopupMenu;
34class KSyncProfile; 34class KSyncProfile;
35class KPimPrefs; 35class KPimPrefs;
36class QWidget; 36class QWidget;
37class KSyncManager; 37class KSyncManager;
38class KSyncInterface; 38class KSyncInterface;
39class QProgressBar; 39class QProgressBar;
40 40
41 41
42class KServerSocket : public QServerSocket 42class KServerSocket : public QServerSocket
43{ 43{
44 Q_OBJECT 44 Q_OBJECT
45 45
46 public: 46 public:
47 KServerSocket ( QString password, Q_UINT16 port, int backlog = 0, QObject * parent=0, const char * name=0 ); 47 KServerSocket ( QString password, Q_UINT16 port, int backlog = 0, QObject * parent=0, const char * name=0 );
48 48
49 void newConnection ( int socket ) ; 49 void newConnection ( int socket ) ;
50 void setFileName( QString fn ) {mFileName = fn;}; 50 void setFileName( QString fn ) {mFileName = fn;};
51 signals: 51 signals:
52 void file_received( bool ); 52 void file_received( bool );
53 void request_file(); 53 void request_file();
54 void saveFile(); 54 void saveFile();
55 void endConnect(); 55 void endConnect();
56 private slots: 56 private slots:
57 void discardClient(); 57 void discardClient();
58 void readClient(); 58 void readClient();
59 void readBackFileFromSocket(); 59 void readBackFileFromSocket();
60 private : 60 private :
61 bool blockRC; 61 bool blockRC;
62 void send_file(); 62 void send_file();
63 void get_file(); 63 void get_file();
64 void end_connect(); 64 void end_connect();
65 QDialog* mSyncActionDialog; 65 QDialog* mSyncActionDialog;
66 QSocket* mSocket; 66 QSocket* mSocket;
67 QString mPassWord; 67 QString mPassWord;
68 QString mFileName; 68 QString mFileName;
69 QTime piTime; 69 QTime piTime;
70 QString piFileString; 70 QString piFileString;
71}; 71};
72 72
73class KCommandSocket : public QObject 73class KCommandSocket : public QObject
74{ 74{
75 Q_OBJECT 75 Q_OBJECT
76 public: 76 public:
77 enum state { successR, errorR, successW, errorW, errorTO, quiet }; 77 enum state { successR, errorR, successW, errorW, errorTO, quiet };
78 KCommandSocket ( QString password, Q_UINT16 port, QString host, QObject * parent=0, const char * name=0 ); 78 KCommandSocket ( QString password, Q_UINT16 port, QString host, QObject * parent=0, const char * name=0 );
79 void readFile( QString ); 79 void readFile( QString );
80 void writeFile( QString ); 80 void writeFile( QString );
81 void sendStop(); 81 void sendStop();
82 82
83 signals: 83 signals:
84 void commandFinished( KCommandSocket*, int ); 84 void commandFinished( KCommandSocket*, int );
85 private slots: 85 private slots:
86 void startReadFileFromSocket(); 86 void startReadFileFromSocket();
87 void readFileFromSocket(); 87 void readFileFromSocket();
88 void deleteSocket(); 88 void deleteSocket();
89 void writeFileToSocket(); 89 void writeFileToSocket();
90 private : 90 private :
91 QSocket* mSocket; 91 QSocket* mSocket;
92 QString mPassWord; 92 QString mPassWord;
93 Q_UINT16 mPort; 93 Q_UINT16 mPort;
94 QString mHost; 94 QString mHost;
95 QString mFileName; 95 QString mFileName;
96 QTimer* mTimerSocket; 96 QTimer* mTimerSocket;
97 int mRetVal; 97 int mRetVal;
98 QTime mTime; 98 QTime mTime;
99 QString mFileString; 99 QString mFileString;
100 bool mFirst; 100 bool mFirst;
101}; 101};
102 102
103 103
104class KSyncManager : public QObject 104class KSyncManager : public QObject
105{ 105{
106 Q_OBJECT 106 Q_OBJECT
107 107
108 public: 108 public:
109 enum TargetApp { 109 enum TargetApp {
110 KOPI = 0, 110 KOPI = 0,
111 KAPI = 1, 111 KAPI = 1,
112 PWMPI = 2 }; 112 PWMPI = 2 };
113 113
114 KSyncManager(QWidget* parent, KSyncInterface* implementation, TargetApp ta, KPimPrefs* prefs, QPopupMenu* syncmenu); 114 KSyncManager(QWidget* parent, KSyncInterface* implementation, TargetApp ta, KPimPrefs* prefs, QPopupMenu* syncmenu);
115 ~KSyncManager() ; 115 ~KSyncManager() ;
116 116
117 void multiSync( bool askforPrefs ); 117 void multiSync( bool askforPrefs );
118 bool blockSave() { return mBlockSaveFlag; } 118 bool blockSave() { return mBlockSaveFlag; }
119 void setBlockSave(bool sa) { mBlockSaveFlag = sa; } 119 void setBlockSave(bool sa) { mBlockSaveFlag = sa; }
120 void setDefaultFileName( QString s) { mDefFileName = s ;} 120 void setDefaultFileName( QString s) { mDefFileName = s ;}
121 QString defaultFileName() { return mDefFileName ;} 121 QString defaultFileName() { return mDefFileName ;}
122 QString syncFileName(); 122 QString syncFileName();
123 void enableQuick( bool ask = true); 123 void enableQuick( bool ask = true);
124 124
125 QString getCurrentSyncDevice() { return mCurrentSyncDevice; } 125 QString getCurrentSyncDevice() { return mCurrentSyncDevice; }
126 QString getCurrentSyncName() { return mCurrentSyncName; } 126 QString getCurrentSyncName() { return mCurrentSyncName; }
127 127
128 void showProgressBar(int percentage, QString caption = QString::null, int total=100); 128 void showProgressBar(int percentage, QString caption = QString::null, int total=100);
129 void hideProgressBar(); 129 void hideProgressBar();
130 bool isProgressBarCanceled(); 130 bool isProgressBarCanceled();
131 131
132 // sync stuff 132 // sync stuff
133 QString mLocalMachineName; 133 QString mLocalMachineName;
134 QStringList mExternSyncProfiles; 134 QStringList mExternSyncProfiles;
135 QStringList mSyncProfileNames; 135 QStringList mSyncProfileNames;
136 bool mAskForPreferences; 136 bool mAskForPreferences;
137 bool mShowSyncSummary; 137 bool mShowSyncSummary;
138 bool mIsKapiFile; 138 bool mIsKapiFile;
139 bool mWriteBackExistingOnly; 139 bool mWriteBackExistingOnly;
140 int mSyncAlgoPrefs; 140 int mSyncAlgoPrefs;
141 bool mWriteBackFile; 141 bool mWriteBackFile;
142 int mWriteBackInFuture; 142 int mWriteBackInFuture;
143 QString mPhoneDevice; 143 QString mPhoneDevice;
144 QString mPhoneConnection; 144 QString mPhoneConnection;
145 QString mPhoneModel; 145 QString mPhoneModel;
146 QString mPassWordPiSync; 146 QString mPassWordPiSync;
147 QString mActiveSyncPort; 147 QString mActiveSyncPort;
148 QString mActiveSyncIP ; 148 QString mActiveSyncIP ;
149 static QDateTime mRequestedSyncEvent;
149 150
150 signals: 151 signals:
151 void save(); 152 void save();
152 void request_file(); 153 void request_file();
153 void getFile( bool ); 154 void getFile( bool );
154 155
155 public slots: 156 public slots:
156 void slotSyncMenu( int ); 157 void slotSyncMenu( int );
157 void slotClearMenu( int action ); 158 void slotClearMenu( int action );
158 void deleteCommandSocket(KCommandSocket*s, int state); 159 void deleteCommandSocket(KCommandSocket*s, int state);
159 void readFileFromSocket(); 160 void readFileFromSocket();
160 void fillSyncMenu(); 161 void fillSyncMenu();
161 162
162 private: 163 private:
163 void syncPi(); 164 void syncPi();
164 KServerSocket * mServerSocket; 165 KServerSocket * mServerSocket;
165 KPimPrefs* mPrefs; 166 KPimPrefs* mPrefs;
166 QString mDefFileName; 167 QString mDefFileName;
167 QString mCurrentSyncDevice; 168 QString mCurrentSyncDevice;
168 QString mCurrentSyncName; 169 QString mCurrentSyncName;
169 void quickSyncLocalFile(); 170 void quickSyncLocalFile();
170 bool syncWithFile( QString fn , bool quick ); 171 bool syncWithFile( QString fn , bool quick );
171 void syncLocalFile(); 172 void syncLocalFile();
172 void syncPhone(); 173 void syncPhone();
173 void syncSharp(); 174 void syncSharp();
174 void syncKDE(); 175 void syncKDE();
175 bool syncExternalApplication(QString); 176 bool syncExternalApplication(QString);
176 int mCurrentSyncProfile ; 177 int mCurrentSyncProfile ;
177 void syncRemote( KSyncProfile* prof, bool ask = true); 178 void syncRemote( KSyncProfile* prof, bool ask = true);
178 bool edit_sync_options(); 179 bool edit_sync_options();
179 bool edit_pisync_options(); 180 bool edit_pisync_options();
180 int ringSync(); 181 int ringSync();
181 QString getPassword( ); 182 QString getPassword( );
182 bool mPisyncFinished; 183 bool mPisyncFinished;
183 bool mBlockSaveFlag; 184 bool mBlockSaveFlag;
184 QWidget* mParent; 185 QWidget* mParent;
185 KSyncInterface* mImplementation; 186 KSyncInterface* mImplementation;
186 TargetApp mTargetApp; 187 TargetApp mTargetApp;
187 QPopupMenu* mSyncMenu; 188 QPopupMenu* mSyncMenu;
188 QProgressBar* bar; 189 QProgressBar* bar;
189 190
190private slots: 191private slots:
191 void confSync(); 192 void confSync();
192 193
193 194
194}; 195};
195 196
196 197
197class KSyncInterface 198class KSyncInterface
198{ 199{
199 public : 200 public :
200 virtual void removeSyncInfo( QString syncProfile) = 0; 201 virtual void removeSyncInfo( QString syncProfile) = 0;
201 virtual bool sync(KSyncManager* manager, QString filename, int mode) = 0; 202 virtual bool sync(KSyncManager* manager, QString filename, int mode) = 0;
202 virtual bool syncExternal(KSyncManager* manager, QString resource) 203 virtual bool syncExternal(KSyncManager* manager, QString resource)
203 { 204 {
204 // empty implementation, because some syncable applications do not 205 // empty implementation, because some syncable applications do not
205 // have an external(sharpdtm) syncmode, like pwmanager. 206 // have an external(sharpdtm) syncmode, like pwmanager.
206 return false; 207 return false;
207 } 208 }
208 209
209 210
210}; 211};
211 212
212 213
213#endif 214#endif