summaryrefslogtreecommitdiffabout
path: root/libkcal
Unidiff
Diffstat (limited to 'libkcal') (more/less context) (ignore whitespace changes)
-rw-r--r--libkcal/phoneformat.cpp15
1 files changed, 8 insertions, 7 deletions
diff --git a/libkcal/phoneformat.cpp b/libkcal/phoneformat.cpp
index ef69bce..6d0da5c 100644
--- a/libkcal/phoneformat.cpp
+++ b/libkcal/phoneformat.cpp
@@ -230,98 +230,96 @@ ulong PhoneFormat::getCsumEvent( Event* event )
230 230
231 default: 231 default:
232 list.append( "255" ); 232 list.append( "255" );
233 list.append( QString() ); 233 list.append( QString() );
234 list.append( "0" ); 234 list.append( "0" );
235 list.append( QString() ); 235 list.append( QString() );
236 list.append( "0" ); 236 list.append( "0" );
237 list.append( "20991231T000000" ); 237 list.append( "20991231T000000" );
238 break; 238 break;
239 } 239 }
240 if ( writeEndDate ) { 240 if ( writeEndDate ) {
241 241
242 if ( rec->endDate().isValid() ) { // 15 + 16 242 if ( rec->endDate().isValid() ) { // 15 + 16
243 list.append( "1" ); 243 list.append( "1" );
244 list.append( PhoneParser::dtToString( rec->endDate()) ); 244 list.append( PhoneParser::dtToString( rec->endDate()) );
245 } else { 245 } else {
246 list.append( "0" ); 246 list.append( "0" );
247 list.append( "20991231T000000" ); 247 list.append( "20991231T000000" );
248 } 248 }
249 249
250 } 250 }
251 attList << list.join(""); 251 attList << list.join("");
252 attList << event->categoriesStr(); 252 attList << event->categoriesStr();
253 //qDebug("csum cat %s", event->categoriesStr().latin1()); 253 //qDebug("csum cat %s", event->categoriesStr().latin1());
254 254
255 attList << event->secrecyStr(); 255 attList << event->secrecyStr();
256 return PhoneFormat::getCsum(attList ); 256 return PhoneFormat::getCsum(attList );
257} 257}
258ulong PhoneFormat::getCsum( const QStringList & attList) 258ulong PhoneFormat::getCsum( const QStringList & attList)
259{ 259{
260 int max = attList.count(); 260 int max = attList.count();
261 ulong cSum = 0; 261 ulong cSum = 0;
262 int j,k,i; 262 int j,k,i;
263 int add; 263 int add;
264 for ( i = 0; i < max ; ++i ) { 264 for ( i = 0; i < max ; ++i ) {
265 QString s = attList[i]; 265 QString s = attList[i];
266 if ( ! s.isEmpty() ){ 266 if ( ! s.isEmpty() ){
267 j = s.length(); 267 j = s.length();
268 for ( k = 0; k < j; ++k ) { 268 for ( k = 0; k < j; ++k ) {
269 int mul = k +1; 269 int mul = k +1;
270 add = s[k].unicode (); 270 add = s[k].unicode ();
271 if ( k < 16 ) 271 if ( k < 16 )
272 mul = mul * mul; 272 mul = mul * mul;
273 int ii = i+1; 273 int ii = i+1;
274 add = add * mul *ii*ii*ii; 274 add = add * mul *ii*ii*ii;
275 cSum += add; 275 cSum += add;
276 } 276 }
277 } 277 }
278 if ( i == 0 )
279 qDebug("csum: i == 0 %d ", cSum);
280 278
281 } 279 }
282 QString dump = attList.join(","); 280 QString dump = attList.join(",");
283 qDebug("csum: %d %s", cSum,dump.latin1()); 281 qDebug("csum: %d %s", cSum,dump.latin1());
284 282
285 return cSum; 283 return cSum;
286 284
287} 285}
288//extern "C" GSM_Error GSM_InitConnection(GSM_StateMachine *s, int ReplyNum); 286//extern "C" GSM_Error GSM_InitConnection(GSM_StateMachine *s, int ReplyNum);
289#include <stdlib.h> 287#include <stdlib.h>
290#define DEBUGMODE false 288#define DEBUGMODE false
291bool PhoneFormat::load( Calendar *calendar, Calendar *existingCal) 289bool PhoneFormat::load( Calendar *calendar, Calendar *existingCal)
292{ 290{
293 291
294 QString fileName; 292 QString fileName;
295#ifdef _WIN32_ 293#ifdef _WIN32_
296 fileName = locateLocal("data", "korganizer") + "\\tempfile.vcs"; 294 fileName = locateLocal("data", "korganizer") + "\\tempfile.vcs";
297#else 295#else
298 fileName = "/tmp/kdepimtemp.vcs"; 296 fileName = "/tmp/kdepimtemp.vcs";
299#endif 297#endif
300 QString command ="./kammu --backup " + fileName + " -yes" ; 298 QString command ="./kammu --backup " + fileName + " -yes" ;
301 int ret = system ( command.latin1() ); 299 int ret = system ( command.latin1() );
302 if ( ret != 0 ) { 300 if ( ret != 0 ) {
303 qDebug("Error::command returned %d", ret); 301 qDebug("Error::command returned %d", ret);
304 return false; 302 return false;
305 } 303 }
306 qDebug("Command returned %d", ret); 304 qDebug("Command returned %d", ret);
307 VCalFormat vfload; 305 VCalFormat vfload;
308 vfload.setLocalTime ( true ); 306 vfload.setLocalTime ( true );
309 qDebug("loading file ..."); 307 qDebug("loading file ...");
310 308
311 if ( ! vfload.load( calendar, fileName ) ) 309 if ( ! vfload.load( calendar, fileName ) )
312 return false; 310 return false;
313 QPtrList<Event> er = calendar->rawEvents(); 311 QPtrList<Event> er = calendar->rawEvents();
314 Event* ev = er.first(); 312 Event* ev = er.first();
315 qDebug("reading events... "); 313 qDebug("reading events... ");
316 while ( ev ) { 314 while ( ev ) {
317 QStringList cat = ev->categories(); 315 QStringList cat = ev->categories();
318 if ( cat.contains( "MeetingDEF" )) { 316 if ( cat.contains( "MeetingDEF" )) {
319 ev->setCategories( QStringList() ); 317 ev->setCategories( QStringList() );
320 } 318 }
321 int id = ev->pilotId(); 319 int id = ev->pilotId();
322 Event *event; 320 Event *event;
323 event = existingCal->event( mProfileName ,QString::number( id ) ); 321 event = existingCal->event( mProfileName ,QString::number( id ) );
324 if ( event ) { 322 if ( event ) {
325 event = (Event*)event->clone(); 323 event = (Event*)event->clone();
326 copyEvent( event, ev ); 324 copyEvent( event, ev );
327 calendar->deleteEvent( ev ); 325 calendar->deleteEvent( ev );
@@ -422,215 +420,218 @@ void PhoneFormat::copyTodo( Todo* to, Todo* from )
422 if ( !from->summary().isEmpty() ) 420 if ( !from->summary().isEmpty() )
423 to->setSummary( from->summary() ); 421 to->setSummary( from->summary() );
424 422
425 QPtrListIterator<Alarm> it( from->alarms() ); 423 QPtrListIterator<Alarm> it( from->alarms() );
426 if ( it.current() ) 424 if ( it.current() )
427 to->clearAlarms(); 425 to->clearAlarms();
428 const Alarm *a; 426 const Alarm *a;
429 while( (a = it.current()) ) { 427 while( (a = it.current()) ) {
430 Alarm *b = new Alarm( *a ); 428 Alarm *b = new Alarm( *a );
431 b->setParent( to ); 429 b->setParent( to );
432 to->addAlarm( b ); 430 to->addAlarm( b );
433 ++it; 431 ++it;
434 } 432 }
435 QStringList cat = to->categories(); 433 QStringList cat = to->categories();
436 QStringList catFrom = from->categories(); 434 QStringList catFrom = from->categories();
437 QString nCat; 435 QString nCat;
438 int iii; 436 int iii;
439 for ( iii = 0; iii < catFrom.count();++iii ) { 437 for ( iii = 0; iii < catFrom.count();++iii ) {
440 nCat = catFrom[iii]; 438 nCat = catFrom[iii];
441 if ( !nCat.isEmpty() ) 439 if ( !nCat.isEmpty() )
442 if ( !cat.contains( nCat )) { 440 if ( !cat.contains( nCat )) {
443 cat << nCat; 441 cat << nCat;
444 } 442 }
445 } 443 }
446 to->setCategories( cat ); 444 to->setCategories( cat );
447 if ( from->isCompleted() ) { 445 if ( from->isCompleted() ) {
448 to->setCompleted( true ); 446 to->setCompleted( true );
449 if( from->completed().isValid() ) 447 if( from->completed().isValid() )
450 to->setCompleted( from->completed() ); 448 to->setCompleted( from->completed() );
451 } else { 449 } else {
452 // set percentcomplete only, if to->isCompleted() 450 // set percentcomplete only, if to->isCompleted()
453 if ( to->isCompleted() ) 451 if ( to->isCompleted() )
454 to->setPercentComplete(from->percentComplete()); 452 to->setPercentComplete(from->percentComplete());
455 } 453 }
456 if( to->priority() == 2 && from->priority() == 1 ) 454 if( to->priority() == 2 && from->priority() == 1 )
457 ; //skip 455 ; //skip
458 else if (to->priority() == 4 && from->priority() == 5 ) 456 else if (to->priority() == 4 && from->priority() == 5 )
459 ; 457 ;
460 else 458 else
461 to->setPriority(from->priority()); 459 to->setPriority(from->priority());
462 460
463} 461}
464#include <qcstring.h> 462#include <qcstring.h>
465 463
466void PhoneFormat::afterSave( Incidence* inc) 464void PhoneFormat::afterSave( Incidence* inc)
467{ 465{
468 uint csum; 466 uint csum;
469 inc->removeID( mProfileName ); 467 inc->removeID( mProfileName );
470#if 0
471 if ( inc->type() == "Event") 468 if ( inc->type() == "Event")
472 csum = PhoneFormat::getCsumEvent( (Event*) inc ); 469 csum = PhoneFormat::getCsumEvent( (Event*) inc );
473 else 470 else
474 csum = PhoneFormat::getCsumTodo( (Todo*) inc ); 471 csum = PhoneFormat::getCsumTodo( (Todo*) inc );
475 inc->setCsum( mProfileName, QString::number( csum )); 472 inc->setCsum( mProfileName, QString::number( csum ));
476#endif 473
477 inc->setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); 474 inc->setTempSyncStat( SYNC_TEMPSTATE_NEW_ID );
478 475
479} 476}
480bool PhoneFormat::save( Calendar *calendar) 477bool PhoneFormat::save( Calendar *calendar)
481{ 478{
482 QLabel status ( i18n(" Opening device ..."), 0 ); 479 QLabel status ( i18n(" Opening device ..."), 0 );
483 int w = status.sizeHint().width()+20 ; 480 int w = status.sizeHint().width()+20 ;
484 if ( w < 200 ) w = 230; 481 if ( w < 200 ) w = 230;
485 int h = status.sizeHint().height()+20 ; 482 int h = status.sizeHint().height()+20 ;
486 int dw = QApplication::desktop()->width(); 483 int dw = QApplication::desktop()->width();
487 int dh = QApplication::desktop()->height(); 484 int dh = QApplication::desktop()->height();
488 status.setCaption(i18n("Writing to phone...") ); 485 status.setCaption(i18n("Writing to phone...") );
489 status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 486 status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
490 status.show(); 487 status.show();
491 status.raise(); 488 status.raise();
492 qApp->processEvents(); 489 qApp->processEvents();
493 QString message; 490 QString message;
494#ifdef _WIN32_ 491#ifdef _WIN32_
495 QString fileName = locateLocal("data", "korganizer") + "\\tempfile.vcs"; 492 QString fileName = locateLocal("data", "korganizer") + "\\tempfile.vcs";
496#else 493#else
497 QString fileName = "/tmp/kdepimtemp.vcs"; 494 QString fileName = "/tmp/kdepimtemp.vcs";
498#endif 495#endif
499 496
500 // 1 remove events which should be deleted 497 // 1 remove events which should be deleted
501 QPtrList<Event> er = calendar->rawEvents(); 498 QPtrList<Event> er = calendar->rawEvents();
502 Event* ev = er.first(); 499 Event* ev = er.first();
503 while ( ev ) { 500 while ( ev ) {
504 if ( ev->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { 501 if ( ev->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) {
505 calendar->deleteEvent( ev ); 502 calendar->deleteEvent( ev );
506 } else { 503 } else {
507 504
508 } 505 }
509 ev = er.next(); 506 ev = er.next();
510 } 507 }
511 // 2 remove todos which should be deleted 508 // 2 remove todos which should be deleted
512 QPtrList<Todo> tl = calendar->rawTodos(); 509 QPtrList<Todo> tl = calendar->rawTodos();
513 Todo* to = tl.first(); 510 Todo* to = tl.first();
514 while ( to ) { 511 while ( to ) {
515 if ( to->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { 512 if ( to->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) {
516 calendar->deleteTodo( to ); 513 calendar->deleteTodo( to );
517 } 514 } else {
515 if ( to->isCompleted()) {
516 calendar->deleteTodo( to );
517 }
518 }
518 to = tl.next(); 519 to = tl.next();
519 } 520 }
520 // 3 save file 521 // 3 save file
521 VCalFormat vfsave; 522 VCalFormat vfsave;
522 vfsave.setLocalTime ( true ); 523 vfsave.setLocalTime ( true );
523 if ( ! vfsave.save( calendar, fileName ) ) 524 if ( ! vfsave.save( calendar, fileName ) )
524 return false; 525 return false;
525 // 4 call kammu 526 // 4 call kammu
526 QString command ="./kammu --restore " + fileName ; 527 QString command ="./kammu --restore " + fileName ;
527 int ret; 528 int ret;
528 while ( (ret = system ( command.latin1())) != 0 ) { 529 while ( (ret = system ( command.latin1())) != 0 ) {
529 qDebug("Error S::command returned %d. asking users", ret); 530 qDebug("Error S::command returned %d. asking users", ret);
530 int retval = KMessageBox::warningContinueCancel(0, 531 int retval = KMessageBox::warningContinueCancel(0,
531 i18n("Error accessing device!\nPlease turn on connection\nand retry!"),i18n("KO/Pi phone sync"),i18n("Retry"),i18n("Cancel")); 532 i18n("Error accessing device!\nPlease turn on connection\nand retry!"),i18n("KO/Pi phone sync"),i18n("Retry"),i18n("Cancel"));
532 if ( retval != KMessageBox::Continue ) 533 if ( retval != KMessageBox::Continue )
533 return false; 534 return false;
534 } 535 }
535 if ( ret != 0 ) { 536 if ( ret != 0 ) {
536 qDebug("Error S::command returned %d", ret); 537 qDebug("Error S::command returned %d", ret);
537 return false; 538 return false;
538 } 539 }
539 // 5 reread data 540 // 5 reread data
540 message = i18n(" Rereading all data ... "); 541 message = i18n(" Rereading all data ... ");
541 status.setText ( message ); 542 status.setText ( message );
542 qApp->processEvents(); 543 qApp->processEvents();
543 CalendarLocal* calendarTemp = new CalendarLocal(); 544 CalendarLocal* calendarTemp = new CalendarLocal();
544 calendarTemp->setTimeZoneId( calendar->timeZoneId()); 545 calendarTemp->setTimeZoneId( calendar->timeZoneId());
545 if ( ! load( calendarTemp,calendar) ){ 546 if ( ! load( calendarTemp,calendar) ){
546 qDebug("error reloading calendar "); 547 qDebug("error reloading calendar ");
547 delete calendarTemp; 548 delete calendarTemp;
548 return false; 549 return false;
549 } 550 }
550 // 6 compare data 551 // 6 compare data
551 552
552//algo 6 compare event 553//algo 6 compare event
553 er = calendar->rawEvents(); 554 er = calendar->rawEvents();
554 ev = er.first(); 555 ev = er.first();
555 message = i18n(" Comparing event # "); 556 message = i18n(" Comparing event # ");
556 QPtrList<Event> er1 = calendarTemp->rawEvents(); 557 QPtrList<Event> er1 = calendarTemp->rawEvents();
557 Event* ev1; 558 Event* ev1;
558 int procCount = 0; 559 int procCount = 0;
559 while ( ev ) { 560 while ( ev ) {
560 //qDebug("event new ID %s",ev->summary().latin1()); 561 //qDebug("event new ID %s",ev->summary().latin1());
561 status.setText ( message + QString::number ( ++procCount ) ); 562 status.setText ( message + QString::number ( ++procCount ) );
562 qApp->processEvents(); 563 qApp->processEvents();
563 uint csum; 564 uint csum;
564 csum = PhoneFormat::getCsumEvent( ev ); 565 csum = PhoneFormat::getCsumEvent( ev );
565 QString cSum = QString::number( csum ); 566 QString cSum = QString::number( csum );
566 ev->setCsum( mProfileName, cSum ); 567 //ev->setCsum( mProfileName, cSum );
567 //qDebug("Event cSum %s ", cSum.latin1()); 568 //qDebug("Event cSum %s ", cSum.latin1());
568 ev1 = er1.first(); 569 ev1 = er1.first();
569 while ( ev1 ) { 570 while ( ev1 ) {
570 if ( ev1->getCsum( mProfileName ) == cSum ) { 571 if ( ev1->getCsum( mProfileName ) == cSum ) {
571 er1.remove( ev1 ); 572 er1.remove( ev1 );
572 afterSave( ev ); 573 afterSave( ev );
573 ev->setID(mProfileName, ev1->getID(mProfileName) ); 574 ev->setID(mProfileName, ev1->getID(mProfileName) );
574 //qDebug("Event found on phone for %s ", ev->summary().latin1()); 575 //qDebug("Event found on phone for %s ", ev->summary().latin1());
575 576
576 break; 577 break;
577 } 578 }
578 ev1 = er1.next(); 579 ev1 = er1.next();
579 } 580 }
580 if ( ! ev1 ) { 581 if ( ! ev1 ) {
581 ev->removeID(mProfileName); 582 ev->removeID(mProfileName);
582 qDebug("ERROR: No event found on phone for %s ", ev->summary().latin1()); 583 qDebug("ERROR: No event found on phone for %s ", ev->summary().latin1());
583 } 584 }
584 585
585 586
586 ev = er.next(); 587 ev = er.next();
587 } 588 }
588 //algo 6 compare todo 589 //algo 6 compare todo
589 tl = calendar->rawTodos(); 590 tl = calendar->rawTodos();
590 to = tl.first(); 591 to = tl.first();
591 procCount = 0; 592 procCount = 0;
592 QPtrList<Todo> tl1 = calendarTemp->rawTodos(); 593 QPtrList<Todo> tl1 = calendarTemp->rawTodos();
593 Todo* to1 ; 594 Todo* to1 ;
594 message = i18n(" Comparing todo # "); 595 message = i18n(" Comparing todo # ");
595 while ( to ) { 596 while ( to ) {
596 qDebug("todo2 %d ", procCount); 597 qDebug("todo2 %d ", procCount);
597 status.setText ( message + QString::number ( ++procCount ) ); 598 status.setText ( message + QString::number ( ++procCount ) );
598 qApp->processEvents(); 599 qApp->processEvents();
599 uint csum; 600 uint csum;
600 csum = PhoneFormat::getCsumTodo( to ); 601 csum = PhoneFormat::getCsumTodo( to );
601 QString cSum = QString::number( csum ); 602 QString cSum = QString::number( csum );
602 to->setCsum( mProfileName, cSum ); 603 //to->setCsum( mProfileName, cSum );
603 qDebug("Todo cSum %s ", cSum.latin1()); 604 qDebug("Todo cSum %s ", cSum.latin1());
604 Todo* to1 = tl1.first(); 605 Todo* to1 = tl1.first();
605 while ( to1 ) { 606 while ( to1 ) {
606 if ( to1->getCsum( mProfileName ) == cSum ) { 607 if ( to1->getCsum( mProfileName ) == cSum ) {
607 tl1.remove( to1 ); 608 tl1.remove( to1 );
608 afterSave( to ); 609 afterSave( to );
609 to->setID(mProfileName, to1->getID(mProfileName) ); 610 to->setID(mProfileName, to1->getID(mProfileName) );
610 break; 611 break;
611 } 612 }
612 to1 = tl1.next(); 613 to1 = tl1.next();
613 } 614 }
614 if ( ! to1 ) { 615 if ( ! to1 ) {
615 to->removeID(mProfileName); 616 to->removeID(mProfileName);
616 qDebug("ERROR: No todo found on phone for %s ", to->summary().latin1()); 617 qDebug("ERROR: No todo found on phone for %s ", to->summary().latin1());
617 } 618 }
618 619
619 to = tl.next(); 620 to = tl.next();
620 } 621 }
621 delete calendarTemp; 622 delete calendarTemp;
622 return true; 623 return true;
623 624
624 625
625 626
626} 627}
627 628
628 629
629QString PhoneFormat::toString( Calendar * ) 630QString PhoneFormat::toString( Calendar * )
630{ 631{
631 return QString::null; 632 return QString::null;
632} 633}
633bool PhoneFormat::fromString( Calendar *calendar, const QString & text) 634bool PhoneFormat::fromString( Calendar *calendar, const QString & text)
634{ 635{
635 return false; 636 return false;
636} 637}