-rw-r--r-- | kde2file/caldump/main.cpp | 55 | ||||
-rw-r--r-- | korganizer/calendarview.cpp | 8 | ||||
-rw-r--r-- | libkcal/calendar.cpp | 16 | ||||
-rw-r--r-- | libkcal/calendar.h | 1 |
4 files changed, 56 insertions, 24 deletions
diff --git a/kde2file/caldump/main.cpp b/kde2file/caldump/main.cpp index 03571b9..755e792 100644 --- a/kde2file/caldump/main.cpp +++ b/kde2file/caldump/main.cpp @@ -144,80 +144,87 @@ int main( int argc, char *argv[] ) 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 ); - - if ( cl->type() == "Journal" ) - calendarResource->addJournal( (Journal *) cl, res ); - else if ( cl->type() == "Todo" ) - calendarResource->addTodo( (Todo *) cl, res ); - else if ( cl->type() == "Event" ) - calendarResource->addEvent( (Event *) cl, res ); - - } else { - if ( incOld ) { - qDebug("ERROR: no resource found for old incidence "); + if ( (*it)->pilotId() > 0 ) { //changed + Incidence* cl = (*it)->clone(); + Incidence *incOld = calendarResource->incidence( cl->uid() ); + ResourceCalendar * res = 0; + if ( incOld ) + res = calendarResource->resource( incOld ); + if ( res ) { + cl->setPilotId( incOld->pilotId() ); + ++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 ); + + if ( cl->type() == "Journal" ) + calendarResource->addJournal( (Journal *) cl, res ); + else if ( cl->type() == "Todo" ) + calendarResource->addTodo( (Todo *) cl, res ); + else if ( cl->type() == "Event" ) + 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; } + } else { // added + Incidence* cl = (*it)->clone(); calendarResource->addIncidence( cl ); ++add; } } 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); } } diff --git a/korganizer/calendarview.cpp b/korganizer/calendarview.cpp index 1f8ad5b..f727cd4 100644 --- a/korganizer/calendarview.cpp +++ b/korganizer/calendarview.cpp @@ -911,48 +911,53 @@ void CalendarView::checkExternalId( Incidence * inc ) QPtrList<Event> lastSync = mCalendar->getExternLastSyncEvents() ; checkExternSyncEvent( lastSync, inc ); } bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int mode ) { bool syncOK = true; int addedEvent = 0; int addedEventR = 0; int deletedEventR = 0; int deletedEventL = 0; int changedLocal = 0; int changedRemote = 0; //QPtrList<Event> el = local->rawEvents(); Event* eventR; QString uid; int take; Event* eventL; Event* eventRSync; Event* eventLSync; QPtrList<Event> eventRSyncSharp = remote->getExternLastSyncEvents(); QPtrList<Event> eventLSyncSharp = local->getExternLastSyncEvents(); bool fullDateRange = false; local->resetTempSyncStat(); +#ifdef DESKTOP_VERSION + //Needed for KDE - OL sync + local->resetPilotStat(); + remote->resetPilotStat(); +#endif mLastCalendarSync = QDateTime::currentDateTime(); QDateTime modifiedCalendar = mLastCalendarSync;; eventLSync = getLastSyncEvent(); eventR = remote->event("last-syncEvent-"+mCurrentSyncName ); if ( eventR ) { eventRSync = (Event*) eventR->clone(); remote->deleteEvent(eventR ); } else { if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { eventRSync = (Event*)eventLSync->clone(); } else { fullDateRange = true; eventRSync = new Event(); eventRSync->setSummary(mCurrentSyncName + i18n(" - sync event")); eventRSync->setUid("last-syncEvent-"+mCurrentSyncName ); eventRSync->setDtStart( mLastCalendarSync ); eventRSync->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); eventRSync->setCategories( i18n("SyncEvent") ); } } if ( eventLSync->dtStart() == mLastCalendarSync ) fullDateRange = true; @@ -1005,48 +1010,51 @@ bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int qApp->processEvents(); if ( !skipIncidence ) { inL = local->incidence( uid ); if ( inL ) { // maybe conflict - same uid in both calendars int maxrev = inL->revision(); if ( maxrev < inR->revision() ) maxrev = inR->revision(); if ( (take = takeEvent( inL, inR, mode, fullDateRange )) > 0 ) { //qDebug("take %d %s ", take, inL->summary().latin1()); if ( take == 3 ) return false; if ( take == 1 ) {// take local if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); else idS = inR->IDStr(); remote->deleteIncidence( inR ); if ( inL->revision() < maxrev ) inL->setRevision( maxrev ); inR = inL->clone(); inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); if ( mGlobalSyncMode != SYNC_MODE_EXTERNAL ) inR->setIDStr( idS ); remote->addIncidence( inR ); +#ifdef DESKTOP_VERSION + inR->setPilotId( 1 ); +#endif ++changedRemote; } else { if ( inR->revision() < maxrev ) inR->setRevision( maxrev ); idS = inL->IDStr(); local->deleteIncidence( inL ); inL = inR->clone(); inL->setIDStr( idS ); if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) ); } local->addIncidence( inL ); ++changedLocal; } } } else { // no conflict if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { QString des = eventLSync->description(); QString pref = "e"; if ( inR->type() == "Todo" ) pref = "t"; if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE ); diff --git a/libkcal/calendar.cpp b/libkcal/calendar.cpp index a3977d7..eeb5f48 100644 --- a/libkcal/calendar.cpp +++ b/libkcal/calendar.cpp @@ -227,48 +227,64 @@ void Calendar::setFilter(CalFilter *filter) } CalFilter *Calendar::filter() { return mFilter; } QPtrList<Incidence> Calendar::incidences() { QPtrList<Incidence> incidences; Incidence *i; QPtrList<Event> e = events(); for( i = e.first(); i; i = e.next() ) incidences.append( i ); QPtrList<Todo> t = todos(); for( i = t.first(); i; i = t.next() ) incidences.append( i ); QPtrList<Journal> j = journals(); for( i = j.first(); i; i = j.next() ) incidences.append( i ); return incidences; } + +void Calendar::resetPilotStat() +{ + QPtrList<Incidence> incidences; + + Incidence *i; + + QPtrList<Event> e = rawEvents(); + for( i = e.first(); i; i = e.next() ) i->setPilotId( 0 ); + + QPtrList<Todo> t = rawTodos(); + for( i = t.first(); i; i = t.next() ) i->setPilotId( 0 ); + + QPtrList<Journal> j = journals(); + for( i = j.first(); i; i = j.next() ) i->setPilotId( 0 ); +} void Calendar::resetTempSyncStat() { QPtrList<Incidence> incidences; Incidence *i; QPtrList<Event> e = rawEvents(); for( i = e.first(); i; i = e.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); QPtrList<Todo> t = rawTodos(); for( i = t.first(); i; i = t.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); QPtrList<Journal> j = journals(); for( i = j.first(); i; i = j.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); } QPtrList<Incidence> Calendar::rawIncidences() { QPtrList<Incidence> incidences; Incidence *i; QPtrList<Event> e = rawEvents(); for( i = e.first(); i; i = e.next() ) incidences.append( i ); diff --git a/libkcal/calendar.h b/libkcal/calendar.h index c45d81f..d5294eb 100644 --- a/libkcal/calendar.h +++ b/libkcal/calendar.h @@ -46,48 +46,49 @@ namespace KCal { information like all appointments/events, user information, etc. etc. one calendar is associated with each CalendarView (@see calendarview.h). This is an abstract base class defining the interface to a calendar. It is implemented by subclasses like @see CalendarLocal, which use different methods to store and access the data. Ownership of events etc. is handled by the following policy: As soon as an event (or any other subclass of IncidenceBase) object is added to the Calendar by addEvent() it is owned by the Calendar object. The Calendar takes care of deleting it. All Events returned by the query functions are returned as pointers, that means all changes to the returned events are immediately visible in the Calendar. You shouldn't delete any Event object you get from Calendar. */ class Calendar : public QObject, public CustomProperties, public IncidenceBase::Observer { Q_OBJECT public: Calendar(); Calendar(const QString &timeZoneId); virtual ~Calendar(); void deleteIncidence(Incidence *in); void resetTempSyncStat(); + void resetPilotStat(); /** Clears out the current calendar, freeing all used memory etc. */ virtual void close() = 0; /** Sync changes in memory to persistant storage. */ virtual void save() = 0; virtual QPtrList<Event> getExternLastSyncEvents() = 0; virtual bool isSaving() { return false; } /** Return the owner of the calendar's full name. */ const QString &getOwner() const; /** Set the owner of the calendar. Should be owner's full name. */ void setOwner( const QString &os ); /** Return the email address of the calendar owner. */ const QString &getEmail(); |