summaryrefslogtreecommitdiffabout
Side-by-side diff
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--korganizer/calendarview.cpp17
-rw-r--r--libkcal/calendar.cpp9
-rw-r--r--libkcal/calendar.h3
-rw-r--r--libkcal/calendarlocal.cpp77
-rw-r--r--libkcal/calendarlocal.h3
-rw-r--r--libkcal/incidence.cpp6
-rw-r--r--libkcal/incidence.h1
7 files changed, 97 insertions, 19 deletions
diff --git a/korganizer/calendarview.cpp b/korganizer/calendarview.cpp
index 8d024c1..1800cf2 100644
--- a/korganizer/calendarview.cpp
+++ b/korganizer/calendarview.cpp
@@ -1601,12 +1601,13 @@ void CalendarView::checkExternSyncEvent( QPtrList<Event> lastSync , Incidence* t
void CalendarView::checkExternalId( Incidence * inc )
{
QPtrList<Event> lastSync = mCalendar->getExternLastSyncEvents() ;
checkExternSyncEvent( lastSync, inc );
}
+// SSSSSSSSSSSSSSSSSSSSSS
bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int mode )
{
bool syncOK = true;
int addedEvent = 0;
int addedEventR = 0;
@@ -1720,14 +1721,21 @@ bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int
bool skipIncidence = false;
if ( uid.left(15) == QString("last-syncEvent-") )
skipIncidence = true;
QString idS;
qApp->processEvents();
if ( !skipIncidence ) {
- inL = local->incidenceForUid( uid , false , true );
+ int hasCalId = 0;
+ inL = local->incidenceForUid( uid , false , true, &hasCalId );
+ if ( hasCalId && !inL )
+ inL = local->incidenceForUid( uid , false , true, &hasCalId );
+ else
+ hasCalId = 0;
if ( inL ) { // maybe conflict - same uid in both calendars
+ if ( hasCalId )
+ qDebug("KO: Cal id %d conflict detected: %s ", hasCalId, inL->summary().latin1());
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 )
@@ -1747,12 +1755,14 @@ bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int
++changedRemote;
} else {// take remote **********************
if ( !inL->isReadOnly() ) {
idS = inL->IDStr();
int pid = inL->pilotId();
int calID = inL->calID();
+ if ( hasCalId )
+ calID = hasCalId;
local->deleteIncidence( inL );
inL = inR->clone();
inL->setCalID_block( calID );
if ( mSyncManager->syncWithDesktop() )
inL->setPilotId( pid );
inL->setIDStr( idS );
@@ -1761,12 +1771,17 @@ bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int
inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) );
}
local->addIncidence( inL );
++changedLocal;
}
}
+ } else {
+ // take == 0; events equal
+ if ( hasCalId )
+ qDebug("EV EQUALLLL **************************** ");
+
}
} else { // no conflict ********** add or delete remote
if ( !filterIN || filterIN->filterCalendarItem( inR ) ){
if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
QString des = eventLSync->description();
QString pref = "e";
diff --git a/libkcal/calendar.cpp b/libkcal/calendar.cpp
index 8535191..1350f6d 100644
--- a/libkcal/calendar.cpp
+++ b/libkcal/calendar.cpp
@@ -4,13 +4,12 @@
Copyright (c) 2000,2001 Cornelius Schumacher <schumacher@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
-
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
@@ -417,31 +416,35 @@ QPtrList<Todo> Calendar::todos()
// When this is called, the todo have already been added to the calendar.
// This method is only about linking related todos
void Calendar::setupRelations( Incidence *incidence )
{
QString uid = incidence->uid();
- //qDebug("Calendar::setupRelations ");
+ //qDebug("Calendar::setupRelations %s", incidence->summary().latin1());
// First, go over the list of orphans and see if this is their parent
while( Incidence* i = mOrphans[ uid ] ) {
mOrphans.remove( uid );
i->setRelatedTo( incidence );
+ //qDebug("Add child %s ti inc %s", i->summary().latin1(),incidence->summary().latin1());
incidence->addRelation( i );
mOrphanUids.remove( i->uid() );
}
// Now see about this incidences parent
if( !incidence->relatedTo() && !incidence->relatedToUid().isEmpty() ) {
// This incidence has a uid it is related to, but is not registered to it yet
// Try to find it
- Incidence* parent = this->incidence( incidence->relatedToUid() );
+ //qDebug("Test parent for %s", incidence->summary().latin1());
+ Incidence* parent = this->incidenceForUid( incidence->relatedToUid(), true );
if( parent ) {
// Found it
+ // qDebug("parent found for for %s", incidence->summary().latin1());
incidence->setRelatedTo( parent );
parent->addRelation( incidence );
} else {
+ // qDebug("NO parent found for for %s", incidence->summary().latin1());
// Not found, put this in the mOrphans list
mOrphans.insert( incidence->relatedToUid(), incidence );
mOrphanUids.insert( incidence->uid(), incidence );
}
}
}
diff --git a/libkcal/calendar.h b/libkcal/calendar.h
index f301768..fbc40ad 100644
--- a/libkcal/calendar.h
+++ b/libkcal/calendar.h
@@ -74,13 +74,14 @@ public:
Clears out the current calendar, freeing all used memory etc.
*/
virtual void close() = 0;
virtual void addCalendar( Calendar* ) = 0;
virtual bool addCalendarFile( QString name, int id ) = 0;
virtual bool mergeCalendarFile( QString name ) = 0;
- virtual Incidence* incidenceForUid( const QString& uid, bool doNotCheckDuplicates , bool enabledOnly = false ) = 0;
+ virtual Incidence* incidenceForUid( const QString& uid, bool doNotCheckDuplicates , bool enabledOnly = false ,int * isDup = 0 ) = 0;
+ virtual Todo* todoForUid( const QString& uid, bool doNotCheckDuplicates = true, bool enabledOnly = false ,int * isDup = 0) = 0;
virtual void setSyncEventsReadOnly() = 0;
virtual void setSyncEventsEnabled() = 0;
virtual void stopAllTodos() = 0;
virtual void clearUndo( Incidence * newUndo );
/**
diff --git a/libkcal/calendarlocal.cpp b/libkcal/calendarlocal.cpp
index ad8ace3..980663f 100644
--- a/libkcal/calendarlocal.cpp
+++ b/libkcal/calendarlocal.cpp
@@ -77,57 +77,108 @@ bool CalendarLocal::mergeCalendarFile( QString name )
mergeCalendar( &calendar );
return true;
}
return false;
}
-Incidence* CalendarLocal::incidenceForUid( const QString& uid , bool doNotCheckDuplicates, bool enabledOnly )
+Todo* CalendarLocal::todoForUid( const QString& uid, bool doNotCheckDuplicates, bool enabledOnly,int * isDup )
{
+
+ int calID = 0;
+ if ( isDup && *isDup > 0 )
+ calID = *isDup;
Todo *todo;;
- Incidence *retVal = 0;
+ Todo *retVal = 0;
for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) {
if ( todo->uid() == uid ) {
- if ( enabledOnly )
- if ( !todo->calEnabled() )
+ if( calID ) {
+ if ( todo->calID() != calID )
+ continue;
+ }
+ else {
+ if ( enabledOnly ) {
+ if ( !todo->calEnabled() ) {
+ if ( isDup )
+ *isDup = todo->calID();
continue;
+ }
+ }
+ }
if ( doNotCheckDuplicates ) return todo;
if ( retVal ) {
if ( retVal->calID() > todo->calID() ) {
+ if ( isDup )
+ *isDup = retVal->calID();
retVal = todo;
}
} else {
retVal = todo;
}
}
}
+ return retVal;
+}
+//if ( isDup) and * isDup == 0: store duplicate found cal id in isDup
+//if ( isDup) and * isDup > 0: search only in calendar with ID *isDup, ignore enabledOnly
+
+Incidence* CalendarLocal::incidenceForUid( const QString& uid , bool doNotCheckDuplicates, bool enabledOnly, int * isDup )
+{
+ int calID = 0;
+ if ( isDup && *isDup > 0 )
+ calID = *isDup;
+ Incidence *retVal = todoForUid( uid , doNotCheckDuplicates,enabledOnly, isDup );
if ( retVal ) return retVal;
Event *event;
for ( event = mEventList.first(); event; event = mEventList.next() ) {
if ( event->uid() == uid ) {
- if ( enabledOnly )
- if ( !event->calEnabled() )
+ if( calID ) {
+ if ( event->calID() != calID )
continue;
+ }
+ else {
+ if ( enabledOnly ) {
+ if ( !event->calEnabled() ) {
+ if ( isDup )
+ *isDup =event->calID() ;
+ continue;
+ }
+ }
+ }
if ( doNotCheckDuplicates ) return event;
if ( retVal ) {
if ( retVal->calID() > event->calID() ) {
+ if ( isDup )
+ *isDup = retVal->calID();
retVal = event;
}
} else {
retVal = event;
}
}
}
if ( retVal ) return retVal;
for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() )
if ( it->uid() == uid ) {
- if ( enabledOnly )
- if ( !it->calEnabled() )
+ if( calID ) {
+ if ( event->calID() != calID )
continue;
+ }
+ else {
+ if ( enabledOnly ) {
+ if ( !it->calEnabled() ) {
+ if ( isDup )
+ *isDup = it->calID();
+ continue;
+ }
+ }
+ }
if ( doNotCheckDuplicates ) return it;
if ( retVal ) {
if ( retVal->calID() > it->calID() ) {
+ if ( isDup )
+ *isDup = retVal->calID();
retVal = it;
}
} else {
retVal = it;
}
}
@@ -230,17 +281,13 @@ void CalendarLocal::addCalendar( Calendar* cal )
}
{
QPtrList<Todo> TodoList = cal->rawTodos();
Todo * ev = TodoList.first();
while ( ev ) {
- QString rel = ev->relatedToUid();
- if ( !rel.isEmpty() ){
- ev->setRelatedTo ( 0 );
- ev->setRelatedToUid( rel );
- }
+ ev->resetRelatedTo();
ev = TodoList.next();
}
//TodoList = cal->rawTodos();
ev = TodoList.first();
while ( ev ) {
ev->unRegisterObserver( cal );
@@ -409,19 +456,23 @@ bool CalendarLocal::addTodo( Todo *todo )
todo->setCalEnabled( true );
return true;
}
void CalendarLocal::deleteTodo( Todo *todo )
{
+ QString uid = todo->uid();
// Handle orphaned children
removeRelations( todo );
clearUndo(todo);
if ( mTodoList.removeRef( todo ) ) {
setModified( true );
}
+ Todo* dup = todoForUid( uid );
+ if ( dup )
+ setupRelations( dup );
}
QPtrList<Todo> CalendarLocal::rawTodos()
{
QPtrList<Todo> el;
for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() )
diff --git a/libkcal/calendarlocal.h b/libkcal/calendarlocal.h
index b611704..1ceabce 100644
--- a/libkcal/calendarlocal.h
+++ b/libkcal/calendarlocal.h
@@ -44,13 +44,14 @@ class CalendarLocal : public Calendar
CalendarLocal( const QString &timeZoneId );
~CalendarLocal();
void addCalendar( Calendar* );
bool addCalendarFile( QString name, int id );
bool mergeCalendarFile( QString name );
bool mergeCalendar( Calendar* cal );
- Incidence* incidenceForUid( const QString& uid, bool doNotCheckDuplicates, bool enabledOnly = false );
+ Incidence* incidenceForUid( const QString& uid, bool doNotCheckDuplicates, bool enabledOnly = false,int * isDup = 0 );
+ Todo* todoForUid( const QString& uid, bool doNotCheckDuplicates = true, bool enabledOnly = false ,int * isDup = 0 );
void setSyncEventsReadOnly();
void setSyncEventsEnabled();
void stopAllTodos();
/**
Loads a calendar on disk in vCalendar or iCalendar format into the current
calendar. Any information already present is lost.
diff --git a/libkcal/incidence.cpp b/libkcal/incidence.cpp
index fe9f854..7dd9bd2 100644
--- a/libkcal/incidence.cpp
+++ b/libkcal/incidence.cpp
@@ -517,12 +517,18 @@ void Incidence::clearRelations()
mRelations.clear();
}
QString Incidence::relatedToUid() const
{
return mRelatedToUid;
}
+void Incidence::resetRelatedTo()
+{
+ QString store = mRelatedToUid;
+ setRelatedTo( 0 );
+ mRelatedToUid = store;
+}
void Incidence::setRelatedTo(Incidence *relatedTo)
{
//qDebug("Incidence::setRelatedTo %d ", relatedTo);
//qDebug("setRelatedTo(Incidence *relatedTo) %s %s", summary().latin1(), relatedTo->summary().latin1() );
if (mReadOnly || mRelatedTo == relatedTo) return;
diff --git a/libkcal/incidence.h b/libkcal/incidence.h
index dc49640..f89942f 100644
--- a/libkcal/incidence.h
+++ b/libkcal/incidence.h
@@ -170,12 +170,13 @@ class Incidence : public IncidenceBase
/** what event does this one relate to? This function should
* only be used when constructing a calendar before the related Event
* exists. */
QString relatedToUid() const;
/** point at some other event to which the event relates */
void setRelatedTo(Incidence *relatedTo);
+ void resetRelatedTo();
/** what event does this one relate to? */
Incidence *relatedTo() const;
/** All events that are related to this event */
QPtrList<Incidence> relations() const;
/** Add an event which is related to this event */
void addRelation(Incidence *);