summaryrefslogtreecommitdiffabout
path: root/libkcal/calendarlocal.cpp
authorzautrix <zautrix>2005-11-28 01:23:02 (UTC)
committer zautrix <zautrix>2005-11-28 01:23:02 (UTC)
commite08811c2246f63b2b63f9db6b65701344460f3d7 (patch) (unidiff)
treed450f486a9472d80eb86f605237b828a0e7ffae6 /libkcal/calendarlocal.cpp
parent854d4a0c686962cd73ac7418b5fbf4b2d73adab7 (diff)
downloadkdepimpi-e08811c2246f63b2b63f9db6b65701344460f3d7.zip
kdepimpi-e08811c2246f63b2b63f9db6b65701344460f3d7.tar.gz
kdepimpi-e08811c2246f63b2b63f9db6b65701344460f3d7.tar.bz2
ync
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
@@ -70,70 +70,121 @@ CalendarLocal::~CalendarLocal()
70 close(); 70 close();
71} 71}
72bool CalendarLocal::mergeCalendarFile( QString name ) 72bool CalendarLocal::mergeCalendarFile( QString name )
73{ 73{
74 CalendarLocal calendar( timeZoneId() ); 74 CalendarLocal calendar( timeZoneId() );
75 calendar.setDefaultCalendar( 1 ); 75 calendar.setDefaultCalendar( 1 );
76 if ( calendar.load( name ) ) { 76 if ( calendar.load( name ) ) {
77 mergeCalendar( &calendar ); 77 mergeCalendar( &calendar );
78 return true; 78 return true;
79 } 79 }
80 return false; 80 return false;
81} 81}
82 82
83Incidence* CalendarLocal::incidenceForUid( const QString& uid , bool doNotCheckDuplicates, bool enabledOnly ) 83Todo* CalendarLocal::todoForUid( const QString& uid, bool doNotCheckDuplicates, bool enabledOnly,int * isDup )
84{ 84{
85
86 int calID = 0;
87 if ( isDup && *isDup > 0 )
88 calID = *isDup;
85 Todo *todo;; 89 Todo *todo;;
86 Incidence *retVal = 0; 90 Todo *retVal = 0;
87 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { 91 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) {
88 if ( todo->uid() == uid ) { 92 if ( todo->uid() == uid ) {
89 if ( enabledOnly ) 93 if( calID ) {
90 if ( !todo->calEnabled() ) 94 if ( todo->calID() != calID )
91 continue; 95 continue;
96 }
97 else {
98 if ( enabledOnly ) {
99 if ( !todo->calEnabled() ) {
100 if ( isDup )
101 *isDup = todo->calID();
102 continue;
103 }
104 }
105 }
92 if ( doNotCheckDuplicates ) return todo; 106 if ( doNotCheckDuplicates ) return todo;
93 if ( retVal ) { 107 if ( retVal ) {
94 if ( retVal->calID() > todo->calID() ) { 108 if ( retVal->calID() > todo->calID() ) {
109 if ( isDup )
110 *isDup = retVal->calID();
95 retVal = todo; 111 retVal = todo;
96 } 112 }
97 } else { 113 } else {
98 retVal = todo; 114 retVal = todo;
99 } 115 }
100 } 116 }
101 } 117 }
118 return retVal;
119}
120//if ( isDup) and * isDup == 0: store duplicate found cal id in isDup
121//if ( isDup) and * isDup > 0: search only in calendar with ID *isDup, ignore enabledOnly
122
123Incidence* CalendarLocal::incidenceForUid( const QString& uid , bool doNotCheckDuplicates, bool enabledOnly, int * isDup )
124{
125 int calID = 0;
126 if ( isDup && *isDup > 0 )
127 calID = *isDup;
128 Incidence *retVal = todoForUid( uid , doNotCheckDuplicates,enabledOnly, isDup );
102 if ( retVal ) return retVal; 129 if ( retVal ) return retVal;
103 Event *event; 130 Event *event;
104 for ( event = mEventList.first(); event; event = mEventList.next() ) { 131 for ( event = mEventList.first(); event; event = mEventList.next() ) {
105 if ( event->uid() == uid ) { 132 if ( event->uid() == uid ) {
106 if ( enabledOnly ) 133 if( calID ) {
107 if ( !event->calEnabled() ) 134 if ( event->calID() != calID )
108 continue; 135 continue;
136 }
137 else {
138 if ( enabledOnly ) {
139 if ( !event->calEnabled() ) {
140 if ( isDup )
141 *isDup =event->calID() ;
142 continue;
143 }
144 }
145 }
109 if ( doNotCheckDuplicates ) return event; 146 if ( doNotCheckDuplicates ) return event;
110 if ( retVal ) { 147 if ( retVal ) {
111 if ( retVal->calID() > event->calID() ) { 148 if ( retVal->calID() > event->calID() ) {
149 if ( isDup )
150 *isDup = retVal->calID();
112 retVal = event; 151 retVal = event;
113 } 152 }
114 } else { 153 } else {
115 retVal = event; 154 retVal = event;
116 } 155 }
117 } 156 }
118 } 157 }
119 if ( retVal ) return retVal; 158 if ( retVal ) return retVal;
120 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) 159 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() )
121 if ( it->uid() == uid ) { 160 if ( it->uid() == uid ) {
122 if ( enabledOnly ) 161 if( calID ) {
123 if ( !it->calEnabled() ) 162 if ( event->calID() != calID )
124 continue; 163 continue;
164 }
165 else {
166 if ( enabledOnly ) {
167 if ( !it->calEnabled() ) {
168 if ( isDup )
169 *isDup = it->calID();
170 continue;
171 }
172 }
173 }
125 if ( doNotCheckDuplicates ) return it; 174 if ( doNotCheckDuplicates ) return it;
126 if ( retVal ) { 175 if ( retVal ) {
127 if ( retVal->calID() > it->calID() ) { 176 if ( retVal->calID() > it->calID() ) {
177 if ( isDup )
178 *isDup = retVal->calID();
128 retVal = it; 179 retVal = it;
129 } 180 }
130 } else { 181 } else {
131 retVal = it; 182 retVal = it;
132 } 183 }
133 } 184 }
134 return retVal; 185 return retVal;
135} 186}
136 187
137bool CalendarLocal::mergeCalendar( Calendar* remote ) 188bool CalendarLocal::mergeCalendar( Calendar* remote )
138{ 189{
139 // 1 look for raw inc in local 190 // 1 look for raw inc in local
@@ -224,29 +275,25 @@ void CalendarLocal::addCalendar( Calendar* cal )
224 mEventList.append( ev ); 275 mEventList.append( ev );
225 ev = EventList.next(); 276 ev = EventList.next();
226 } 277 }
227 for ( ev = el.first(); ev; ev = el.next() ) { 278 for ( ev = el.first(); ev; ev = el.next() ) {
228 deleteIncidence ( ev ); 279 deleteIncidence ( ev );
229 } 280 }
230 } 281 }
231 { 282 {
232 283
233 QPtrList<Todo> TodoList = cal->rawTodos(); 284 QPtrList<Todo> TodoList = cal->rawTodos();
234 Todo * ev = TodoList.first(); 285 Todo * ev = TodoList.first();
235 while ( ev ) { 286 while ( ev ) {
236 QString rel = ev->relatedToUid(); 287 ev->resetRelatedTo();
237 if ( !rel.isEmpty() ){
238 ev->setRelatedTo ( 0 );
239 ev->setRelatedToUid( rel );
240 }
241 ev = TodoList.next(); 288 ev = TodoList.next();
242 } 289 }
243 //TodoList = cal->rawTodos(); 290 //TodoList = cal->rawTodos();
244 ev = TodoList.first(); 291 ev = TodoList.first();
245 while ( ev ) { 292 while ( ev ) {
246 ev->unRegisterObserver( cal ); 293 ev->unRegisterObserver( cal );
247 ev->registerObserver( this ); 294 ev->registerObserver( this );
248 mTodoList.append( ev ); 295 mTodoList.append( ev );
249 setupRelations( ev ); 296 setupRelations( ev );
250 ev = TodoList.next(); 297 ev = TodoList.next();
251 } 298 }
252 } 299 }
@@ -403,31 +450,35 @@ bool CalendarLocal::addTodo( Todo *todo )
403 // Set up subtask relations 450 // Set up subtask relations
404 setupRelations( todo ); 451 setupRelations( todo );
405 452
406 setModified( true ); 453 setModified( true );
407 if ( todo->calID() == 0 ) 454 if ( todo->calID() == 0 )
408 todo->setCalID_block( mDefaultCalendar ); 455 todo->setCalID_block( mDefaultCalendar );
409 todo->setCalEnabled( true ); 456 todo->setCalEnabled( true );
410 return true; 457 return true;
411} 458}
412 459
413void CalendarLocal::deleteTodo( Todo *todo ) 460void CalendarLocal::deleteTodo( Todo *todo )
414{ 461{
462 QString uid = todo->uid();
415 // Handle orphaned children 463 // Handle orphaned children
416 removeRelations( todo ); 464 removeRelations( todo );
417 clearUndo(todo); 465 clearUndo(todo);
418 466
419 if ( mTodoList.removeRef( todo ) ) { 467 if ( mTodoList.removeRef( todo ) ) {
420 setModified( true ); 468 setModified( true );
421 } 469 }
470 Todo* dup = todoForUid( uid );
471 if ( dup )
472 setupRelations( dup );
422} 473}
423 474
424QPtrList<Todo> CalendarLocal::rawTodos() 475QPtrList<Todo> CalendarLocal::rawTodos()
425{ 476{
426 QPtrList<Todo> el; 477 QPtrList<Todo> el;
427 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) 478 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() )
428 if ( it->calEnabled() ) el.append( it ); 479 if ( it->calEnabled() ) el.append( it );
429 return el; 480 return el;
430} 481}
431Todo *CalendarLocal::todo( QString syncProf, QString id ) 482Todo *CalendarLocal::todo( QString syncProf, QString id )
432{ 483{
433 Todo *todo; 484 Todo *todo;