-rw-r--r-- | libkcal/phoneformat.cpp | 104 |
1 files changed, 45 insertions, 59 deletions
diff --git a/libkcal/phoneformat.cpp b/libkcal/phoneformat.cpp index 281434e..101db57 100644 --- a/libkcal/phoneformat.cpp +++ b/libkcal/phoneformat.cpp @@ -291,341 +291,327 @@ bool PhoneFormat::load( Calendar *calendar, Calendar *existingCal) QString fileName; #ifdef _WIN32_ fileName = locateLocal("tmp", "phonefile.vcs"); #else fileName = "/tmp/phonefile.vcs"; #endif QString command; if ( ! PhoneAccess::readFromPhone( fileName )) { return false; } VCalFormat vfload; vfload.setLocalTime ( true ); qDebug("loading file ..."); if ( ! vfload.load( calendar, fileName ) ) return false; QPtrList<Event> er = calendar->rawEvents(); Event* ev = er.first(); qDebug("reading events... "); while ( ev ) { QStringList cat = ev->categories(); if ( cat.contains( "MeetingDEF" )) { ev->setCategories( QStringList() ); + } else + if ( cat.contains( "Birthday" )) { + ev->setFloats( true ); + QDate da = ev->dtStart().date(); + ev->setDtStart( QDateTime( da) ); + ev->setDtEnd( QDateTime( da.addDays(1)) ); + } + uint cSum; + cSum = PhoneFormat::getCsumEvent( ev ); int id = ev->pilotId(); Event *event; event = existingCal->event( mProfileName ,QString::number( id ) ); if ( event ) { event = (Event*)event->clone(); copyEvent( event, ev ); calendar->deleteEvent( ev ); calendar->addEvent( event); } else event = ev; - uint cSum; - cSum = PhoneFormat::getCsumEvent( event ); event->setCsum( mProfileName, QString::number( cSum )); event->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); event->setID( mProfileName,QString::number( id ) ); ev = er.next(); } { qDebug("reading todos... "); QPtrList<Todo> tr = calendar->rawTodos(); Todo* ev = tr.first(); while ( ev ) { QStringList cat = ev->categories(); if ( cat.contains( "MeetingDEF" )) { ev->setCategories( QStringList() ); } int id = ev->pilotId(); + uint cSum; + cSum = PhoneFormat::getCsumTodo( ev ); Todo *event; event = existingCal->todo( mProfileName ,QString::number( id ) ); if ( event ) { //qDebug("copy todo %s ", event->summary().latin1()); event = (Todo*)event->clone(); copyTodo( event, ev ); calendar->deleteTodo( ev ); calendar->addTodo( event); } else event = ev; - uint cSum; - cSum = PhoneFormat::getCsumTodo( event ); event->setCsum( mProfileName, QString::number( cSum )); event->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); event->setID( mProfileName,QString::number( id ) ); ev = tr.next(); } } return true; } void PhoneFormat::copyEvent( Event* to, Event* from ) { if ( from->dtStart().isValid() ) to->setDtStart( from->dtStart() ); if ( from->dtEnd().isValid() ) to->setDtEnd( from->dtEnd() ); if ( !from->location().isEmpty() ) to->setLocation( from->location() ); if ( !from->description().isEmpty() ) to->setDescription( from->description() ); if ( !from->summary().isEmpty() ) to->setSummary( from->summary() ); if ( from->alarms().count() ) { to->clearAlarms(); Alarm *a = from->alarms().first(); Alarm *b = to->newAlarm( ); b->setEnabled( a->enabled() ); - if ( a->hasStartOffset() ) { - b->setStartOffset( a->startOffset() ); - } - if ( a->hasTime() ) - b->setTime( a->time() ); + b->setStartOffset(Duration( a->offset() ) ); } QStringList cat = to->categories(); QStringList catFrom = from->categories(); QString nCat; int iii; for ( iii = 0; iii < catFrom.count();++iii ) { nCat = catFrom[iii]; if ( !nCat.isEmpty() ) if ( !cat.contains( nCat )) { cat << nCat; } } to->setCategories( cat ); - Recurrence * r = new Recurrence( *from->recurrence(),to); - to->setRecurrence( r ) ; + if ( from->doesRecur() ) { + Recurrence * r = new Recurrence( *from->recurrence(),to); + to->setRecurrence( r ) ; + } } void PhoneFormat::copyTodo( Todo* to, Todo* from ) { - if ( from->dtStart().isValid() ) + if ( from->hasStartDate() ) { + to->setHasStartDate( true ); to->setDtStart( from->dtStart() ); - if ( from->dtDue().isValid() ) + } + if ( from->hasDueDate() ){ + to->setHasDueDate( true ); to->setDtDue( from->dtDue() ); + } if ( !from->location().isEmpty() ) to->setLocation( from->location() ); if ( !from->description().isEmpty() ) to->setDescription( from->description() ); if ( !from->summary().isEmpty() ) to->setSummary( from->summary() ); if ( from->alarms().count() ) { to->clearAlarms(); Alarm *a = from->alarms().first(); Alarm *b = to->newAlarm( ); b->setEnabled( a->enabled() ); - if ( a->hasStartOffset() ) - b->setStartOffset( a->startOffset() ); - if ( a->hasTime() ) - b->setTime( a->time() ); + b->setStartOffset(Duration( a->offset() ) ); } QStringList cat = to->categories(); QStringList catFrom = from->categories(); QString nCat; int iii; for ( iii = 0; iii < catFrom.count();++iii ) { nCat = catFrom[iii]; if ( !nCat.isEmpty() ) if ( !cat.contains( nCat )) { cat << nCat; } } to->setCategories( cat ); if ( from->isCompleted() ) { to->setCompleted( true ); if( from->completed().isValid() ) to->setCompleted( from->completed() ); } else { // set percentcomplete only, if to->isCompleted() if ( to->isCompleted() ) to->setPercentComplete(from->percentComplete()); } if( to->priority() == 2 && from->priority() == 1 ) ; //skip else if (to->priority() == 4 && from->priority() == 5 ) ; else to->setPriority(from->priority()); } #include <qcstring.h> -void PhoneFormat::afterSave( Incidence* inc) +void PhoneFormat::afterSave( Incidence* inc,const QString& id ,const QString& csum) { - uint csum; - inc->removeID( mProfileName ); - if ( inc->type() == "Event") - csum = PhoneFormat::getCsumEvent( (Event*) inc ); - else - csum = PhoneFormat::getCsumTodo( (Todo*) inc ); - inc->setCsum( mProfileName, QString::number( csum )); - + inc->setID( mProfileName, id ); + inc->setCsum( mProfileName, csum); inc->setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); } bool PhoneFormat::writeToPhone( Calendar * calendar) { #ifdef _WIN32_ - QString fileName = locateLocal("tmp", "tempfile.vcs"); + QString fileName = locateLocal("tmp", "phonefile.vcs"); #else - QString fileName = "/tmp/kdepimtemp.vcs"; + QString fileName = "/tmp/phonefile.vcs"; #endif VCalFormat vfsave; vfsave.setLocalTime ( true ); QString id = calendar->timeZoneId(); calendar->setLocalTime(); if ( ! vfsave.save( calendar, fileName ) ) return false; calendar->setTimeZoneId( id ); return PhoneAccess::writeToPhone( fileName ); } bool PhoneFormat::save( Calendar *calendar) { - QLabel status ( i18n(" Opening device ..."), 0 ); - int w = status.sizeHint().width()+20 ; - if ( w < 200 ) w = 230; - int h = status.sizeHint().height()+20 ; - int dw = QApplication::desktop()->width(); - int dh = QApplication::desktop()->height(); - status.setCaption(i18n("Writing to phone...") ); - status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); - status.show(); - status.raise(); - qApp->processEvents(); - QString message; + // 1 remove events which should be deleted QPtrList<Event> er = calendar->rawEvents(); Event* ev = er.first(); while ( ev ) { if ( ev->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { calendar->deleteEvent( ev ); } else { } ev = er.next(); } // 2 remove todos which should be deleted QPtrList<Todo> tl = calendar->rawTodos(); Todo* to = tl.first(); while ( to ) { if ( to->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { calendar->deleteTodo( to ); } else { if ( to->isCompleted()) { calendar->deleteTodo( to ); } } to = tl.next(); } // 3 save file if ( !writeToPhone( calendar ) ) return false; - + QLabel status ( i18n(" Opening device ..."), 0 ); + int w = status.sizeHint().width()+20 ; + if ( w < 200 ) w = 230; + int h = status.sizeHint().height()+20 ; + int dw = QApplication::desktop()->width(); + int dh = QApplication::desktop()->height(); + status.setCaption(i18n("Writing to phone...") ); + status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); + QString message; + status.show(); + status.raise(); + qApp->processEvents(); // 5 reread data message = i18n(" Rereading all data ... "); status.setText ( message ); qApp->processEvents(); CalendarLocal* calendarTemp = new CalendarLocal(); calendarTemp->setTimeZoneId( calendar->timeZoneId()); if ( ! load( calendarTemp,calendar) ){ qDebug("error reloading calendar "); delete calendarTemp; return false; } // 6 compare data //algo 6 compare event er = calendar->rawEvents(); ev = er.first(); message = i18n(" Comparing event # "); QPtrList<Event> er1 = calendarTemp->rawEvents(); Event* ev1; int procCount = 0; while ( ev ) { //qDebug("event new ID %s",ev->summary().latin1()); status.setText ( message + QString::number ( ++procCount ) ); qApp->processEvents(); - uint csum; - csum = PhoneFormat::getCsumEvent( ev ); - QString cSum = QString::number( csum ); - //ev->setCsum( mProfileName, cSum ); - //qDebug("Event cSum %s ", cSum.latin1()); ev1 = er1.first(); while ( ev1 ) { - if ( ev1->getCsum( mProfileName ) == cSum ) { + if ( ev->contains( ev1 ) ) { + afterSave( ev ,ev1->getID(mProfileName),ev1->getCsum(mProfileName)); er1.remove( ev1 ); - afterSave( ev ); - ev->setID(mProfileName, ev1->getID(mProfileName) ); - //qDebug("Event found on phone for %s ", ev->summary().latin1()); - break; } ev1 = er1.next(); } if ( ! ev1 ) { // ev->removeID(mProfileName); qDebug("ERROR: No event found on phone for %s ", ev->summary().latin1()); } ev = er.next(); } //algo 6 compare todo tl = calendar->rawTodos(); to = tl.first(); procCount = 0; QPtrList<Todo> tl1 = calendarTemp->rawTodos(); Todo* to1 ; message = i18n(" Comparing todo # "); while ( to ) { status.setText ( message + QString::number ( ++procCount ) ); qApp->processEvents(); - uint csum; - csum = PhoneFormat::getCsumTodo( to ); - QString cSum = QString::number( csum ); - //to->setCsum( mProfileName, cSum ); - //qDebug("Todo cSum %s ", cSum.latin1()); Todo* to1 = tl1.first(); while ( to1 ) { - if ( to1->getCsum( mProfileName ) == cSum ) { + if ( to->contains( to1 ) ) { + afterSave( to ,to1->getID(mProfileName),to1->getCsum(mProfileName)); tl1.remove( to1 ); - afterSave( to ); - to->setID(mProfileName, to1->getID(mProfileName) ); break; } to1 = tl1.next(); } if ( ! to1 ) { //to->removeID(mProfileName); qDebug("ERROR: No todo found on phone for %s ", to->summary().latin1()); } to = tl.next(); } delete calendarTemp; return true; } QString PhoneFormat::toString( Calendar * ) { return QString::null; } bool PhoneFormat::fromString( Calendar *calendar, const QString & text) |