summaryrefslogtreecommitdiffabout
path: root/libkcal
Side-by-side diff
Diffstat (limited to 'libkcal') (more/less context) (ignore whitespace changes)
-rw-r--r--libkcal/calendar.cpp9
-rw-r--r--libkcal/calendar.h3
-rw-r--r--libkcal/calendarlocal.cpp81
-rw-r--r--libkcal/calendarlocal.h3
-rw-r--r--libkcal/incidence.cpp6
-rw-r--r--libkcal/incidence.h1
6 files changed, 83 insertions, 20 deletions
diff --git a/libkcal/calendar.cpp b/libkcal/calendar.cpp
index 8535191..1350f6d 100644
--- a/libkcal/calendar.cpp
+++ b/libkcal/calendar.cpp
@@ -6,9 +6,8 @@
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.
@@ -419,27 +418,31 @@ QPtrList<Todo> Calendar::todos()
// 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
@@ -76,9 +76,10 @@ public:
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
@@ -78,38 +78,77 @@ bool CalendarLocal::mergeCalendarFile( QString name )
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;
@@ -118,14 +157,26 @@ Incidence* CalendarLocal::incidenceForUid( const QString& uid , bool doNotCheckD
}
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 ( retVal->calID() > it->calID() ) {
+ if ( isDup )
+ *isDup = retVal->calID();
retVal = it;
}
} else {
retVal = it;
@@ -232,13 +283,9 @@ 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();
@@ -411,15 +458,19 @@ bool CalendarLocal::addTodo( Todo *todo )
}
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()
{
diff --git a/libkcal/calendarlocal.h b/libkcal/calendarlocal.h
index b611704..1ceabce 100644
--- a/libkcal/calendarlocal.h
+++ b/libkcal/calendarlocal.h
@@ -46,9 +46,10 @@ class CalendarLocal : public Calendar
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();
/**
diff --git a/libkcal/incidence.cpp b/libkcal/incidence.cpp
index fe9f854..7dd9bd2 100644
--- a/libkcal/incidence.cpp
+++ b/libkcal/incidence.cpp
@@ -519,8 +519,14 @@ void Incidence::clearRelations()
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);
diff --git a/libkcal/incidence.h b/libkcal/incidence.h
index dc49640..f89942f 100644
--- a/libkcal/incidence.h
+++ b/libkcal/incidence.h
@@ -172,8 +172,9 @@ class Incidence : public IncidenceBase
* 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;