-rw-r--r-- | kde2file/caldump/main.cpp | 45 |
1 files changed, 24 insertions, 21 deletions
diff --git a/kde2file/caldump/main.cpp b/kde2file/caldump/main.cpp index 8d81307..03571b9 100644 --- a/kde2file/caldump/main.cpp +++ b/kde2file/caldump/main.cpp @@ -105,33 +105,33 @@ int main( int argc, char *argv[] ) if ( args->isSet( "read" ) ) { read = true; qDebug("read "); } QString fileName = QDir::homeDirPath ()+"/.kdecalendardump.ics"; CalendarResources *calendarResource = 0; CalendarLocal *localCalendar = 0; KConfig c( locate( "config", "korganizerrc" ) ); c.setGroup( "Time & Date" ); QString tz = c.readEntry( "TimeZoneId" ); calendarResource = new CalendarResources( tz ); calendarResource->readConfig(); calendarResource->load(); qDebug("************************************* "); qDebug("**************kdecaldump************* "); qDebug("************************************* "); - qDebug("Using timezone id: %s", calendarResource->timeZoneId().latin1()); + qDebug("Using timezone ID: %s", calendarResource->timeZoneId().latin1()); if ( !read ) { localCalendar = new CalendarLocal(); localCalendar->setTimeZoneId( calendarResource->timeZoneId()); KCal::Incidence::List allInc = calendarResource->rawIncidences(); Incidence::List::ConstIterator it; int num = 0; for( it = allInc.begin(); it != allInc.end(); ++it ) { ResourceCalendar * re = calendarResource->resource( (*it) ); if ( re && !re->readOnly() ) { ++num; Incidence* cl = (*it)->clone(); cl->setLastModified( (*it)->lastModified() ); if ( cl->type() == "Journal" ) localCalendar->addJournal( (Journal *) cl ); else if ( cl->type() == "Todo" ) @@ -139,40 +139,42 @@ int main( int argc, char *argv[] ) else if ( cl->type() == "Event" ) localCalendar->addEvent( (Event *) cl ); } } FileStorage* storage = new FileStorage( calendarResource ); storage->setFileName( fileName ); storage->setSaveFormat( new ICalFormat() ); storage->save(); delete storage; qDebug("************************************* "); qDebug("************kdecaldump*************** "); qDebug("************************************* "); qDebug("%d calendar entries dumped to file %s", num, fileName.latin1()); } else { + qDebug("*************************load"); localCalendar = new CalendarLocal(); localCalendar->setTimeZoneId( calendarResource->timeZoneId()); FileStorage* storage = new FileStorage( localCalendar ); storage->setFileName( fileName ); int num = 0; int del = 0; int add = 0; if ( storage->load() ) { + qDebug("*************************loaded!"); KCal::Incidence::List newInc = localCalendar->rawIncidences(); Incidence::List::ConstIterator it; for( it = newInc.begin(); it != newInc.end(); ++it ) { Incidence* cl = (*it)->clone(); Incidence *incOld = calendarResource->incidence( cl->uid() ); ResourceCalendar * res = 0; if ( incOld ) res = calendarResource->resource( incOld ); if ( res ) { ++num; if ( incOld->type() == "Journal" ) calendarResource->deleteJournal( (Journal *) incOld ); else if ( incOld->type() == "Todo" ) calendarResource->deleteTodo( (Todo *) incOld ); else if ( incOld->type() == "Event" ) calendarResource->deleteEvent( (Event *) incOld ); @@ -185,61 +187,62 @@ int main( int argc, char *argv[] ) calendarResource->addEvent( (Event *) cl, res ); } else { if ( incOld ) { qDebug("ERROR: no resource found for old incidence "); if ( incOld->type() == "Journal" ) calendarResource->deleteJournal( (Journal *) incOld ); else if ( incOld->type() == "Todo" ) calendarResource->deleteTodo( (Todo *) incOld ); else if ( incOld->type() == "Event" ) calendarResource->deleteEvent( (Event *) incOld ); } calendarResource->addIncidence( cl ); ++add; } - KCal::Incidence::List allInc = calendarResource->rawIncidences(); + } + KCal::Incidence::List allInc = calendarResource->rawIncidences(); - for( it = allInc.begin(); it != allInc.end(); ++it ) { - ResourceCalendar * re = calendarResource->resource( (*it) ); - if ( re && !re->readOnly() ) { - Incidence* cl = localCalendar->incidence( (*it)->uid() ); - if ( !cl ) { - ++del; - cl = (*it); - if ( cl->type() == "Journal" ) - calendarResource->deleteJournal( (Journal *) cl ); - else if ( cl->type() == "Todo" ) - calendarResource->deleteTodo( (Todo *) cl ); - else if ( cl->type() == "Event" ) - calendarResource->deleteEvent( (Event *) cl ); - //QDateTime lm = cl->lastModified(); - //cl->setResources( (*it)->resources() ); - //cl->setLastModified(lm); - } - } + for( it = allInc.begin(); it != allInc.end(); ++it ) { + ResourceCalendar * re = calendarResource->resource( (*it) ); + if ( re && !re->readOnly() ) { + Incidence* cl = localCalendar->incidence( (*it)->uid() ); + if ( !cl ) { + ++del; + cl = (*it); + if ( cl->type() == "Journal" ) + calendarResource->deleteJournal( (Journal *) cl ); + else if ( cl->type() == "Todo" ) + calendarResource->deleteTodo( (Todo *) cl ); + else if ( cl->type() == "Event" ) + calendarResource->deleteEvent( (Event *) cl ); + //QDateTime lm = cl->lastModified(); + //cl->setResources( (*it)->resources() ); + //cl->setLastModified(lm); + } } } + calendarResource->save(); qDebug("************************************* "); qDebug("************kdecaldump*************** "); qDebug("************************************* "); qDebug("Calendar entries\nchanged %d\ndeleted %d\nadded %d\nfrom file %s", num,del, add, fileName.latin1()); } else - qDebug("error loading file /tmp/kdedumpall.ics"); + qDebug("ERROR loading file %s",fileName.latin1() ); } if ( localCalendar ) { localCalendar->close(); delete localCalendar; } if ( calendarResource ) { calendarResource->close(); delete calendarResource; } qDebug("ente "); return 0; } |