summaryrefslogtreecommitdiffabout
path: root/libkcal/calendarlocal.cpp
Side-by-side diff
Diffstat (limited to 'libkcal/calendarlocal.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libkcal/calendarlocal.cpp81
1 files changed, 66 insertions, 15 deletions
diff --git a/libkcal/calendarlocal.cpp b/libkcal/calendarlocal.cpp
index ad8ace3..980663f 100644
--- a/libkcal/calendarlocal.cpp
+++ b/libkcal/calendarlocal.cpp
@@ -58,94 +58,145 @@ CalendarLocal::CalendarLocal(const QString &timeZoneId)
}
void CalendarLocal::init()
{
mNextAlarmIncidence = 0;
}
CalendarLocal::~CalendarLocal()
{
registerObserver( 0 );
if ( mDeleteIncidencesOnClose )
close();
}
bool CalendarLocal::mergeCalendarFile( QString name )
{
CalendarLocal calendar( timeZoneId() );
calendar.setDefaultCalendar( 1 );
if ( calendar.load( 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 ( retVal->calID() > it->calID() ) {
+ if ( isDup )
+ *isDup = retVal->calID();
retVal = it;
}
} else {
retVal = it;
}
}
return retVal;
}
bool CalendarLocal::mergeCalendar( Calendar* remote )
{
// 1 look for raw inc in local
// if inc not in remote, delete in local
// 2 look for raw inc in remote
// if inc in local, replace it
// if not in local, add it to default calendar
QPtrList<Incidence> localInc = rawIncidences();
Incidence* inL = localInc.first();
while ( inL ) {
if ( ! inL->isReadOnly () )
if ( !remote->incidenceForUid( inL->uid(), true ))
deleteIncidence( inL );
inL = localInc.next();
}
@@ -212,53 +263,49 @@ void CalendarLocal::addCalendar( Calendar* cal )
QPtrList<Event> EventList = cal->rawEvents();
QPtrList<Event> el;
Event * ev = EventList.first();
while ( ev ) {
if ( ev->uid().left( 15 ) == QString("last-syncEvent-") ) {
Event * se = event( ev->uid() );
if ( se )
el.append( se );
ev->setCalID_block( 1 );
}
ev->unRegisterObserver( cal );
ev->registerObserver( this );
mEventList.append( ev );
ev = EventList.next();
}
for ( ev = el.first(); ev; ev = el.next() ) {
deleteIncidence ( ev );
}
}
{
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 );
ev->registerObserver( this );
mTodoList.append( ev );
setupRelations( ev );
ev = TodoList.next();
}
}
{
QPtrList<Journal> JournalList = cal->journals();
Journal * ev = JournalList.first();
while ( ev ) {
ev->unRegisterObserver( cal );
ev->registerObserver( this );
mJournalList.append( ev );
ev = JournalList.next();
}
}
setModified( true );
}
@@ -391,55 +438,59 @@ bool CalendarLocal::addTodoNoDup( Todo *todo )
//qDebug("duplicate todo found! not inserted! ");
return false;
}
}
return addTodo( todo );
}
bool CalendarLocal::addTodo( Todo *todo )
{
mTodoList.append( todo );
todo->registerObserver( this );
// Set up subtask relations
setupRelations( todo );
setModified( true );
if ( todo->calID() == 0 )
todo->setCalID_block( mDefaultCalendar );
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() )
if ( it->calEnabled() ) el.append( it );
return el;
}
Todo *CalendarLocal::todo( QString syncProf, QString id )
{
Todo *todo;
for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) {
if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo;
}
return 0;
}
void CalendarLocal::removeSyncInfo( QString syncProfile)
{
QPtrList<Incidence> all = rawIncidences() ;
Incidence *inc;
for ( inc = all.first(); inc; inc = all.next() ) {
inc->removeID( syncProfile );