-rw-r--r-- | libkcal/calendarlocal.cpp | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/libkcal/calendarlocal.cpp b/libkcal/calendarlocal.cpp index eef8327..5baa7dc 100644 --- a/libkcal/calendarlocal.cpp +++ b/libkcal/calendarlocal.cpp | |||
@@ -131,257 +131,257 @@ bool CalendarLocal::mergeCalendar( Calendar* remote ) | |||
131 | // if inc not in remote, delete in local | 131 | // if inc not in remote, delete in local |
132 | // 2 look for raw inc in remote | 132 | // 2 look for raw inc in remote |
133 | // if inc in local, replace it | 133 | // if inc in local, replace it |
134 | // if not in local, add it to default calendar | 134 | // if not in local, add it to default calendar |
135 | QPtrList<Incidence> localInc = rawIncidences(); | 135 | QPtrList<Incidence> localInc = rawIncidences(); |
136 | Incidence* inL = localInc.first(); | 136 | Incidence* inL = localInc.first(); |
137 | while ( inL ) { | 137 | while ( inL ) { |
138 | if ( ! inL->isReadOnly () ) | 138 | if ( ! inL->isReadOnly () ) |
139 | if ( !remote->incidenceForUid( inL->uid(), true )) | 139 | if ( !remote->incidenceForUid( inL->uid(), true )) |
140 | deleteIncidence( inL ); | 140 | deleteIncidence( inL ); |
141 | inL = localInc.next(); | 141 | inL = localInc.next(); |
142 | } | 142 | } |
143 | QPtrList<Incidence> er = remote->rawIncidences(); | 143 | QPtrList<Incidence> er = remote->rawIncidences(); |
144 | Incidence* inR = er.first(); | 144 | Incidence* inR = er.first(); |
145 | while ( inR ) { | 145 | while ( inR ) { |
146 | inL = incidenceForUid( inR->uid(),false ); | 146 | inL = incidenceForUid( inR->uid(),false ); |
147 | if ( inL ) { | 147 | if ( inL ) { |
148 | if ( ! inL->isReadOnly () || inL->uid().left(15) == QString("last-syncEvent-") ) { | 148 | if ( ! inL->isReadOnly () || inL->uid().left(15) == QString("last-syncEvent-") ) { |
149 | int calID = inL->calID(); | 149 | int calID = inL->calID(); |
150 | deleteIncidence( inL ); | 150 | deleteIncidence( inL ); |
151 | inL = inR->clone(); | 151 | inL = inR->clone(); |
152 | inL->setCalID( calID ); | 152 | inL->setCalID( calID ); |
153 | addIncidence( inL ); | 153 | addIncidence( inL ); |
154 | } | 154 | } |
155 | } else { | 155 | } else { |
156 | inL = inR->clone(); | 156 | inL = inR->clone(); |
157 | inL->setCalID( 0 );// add to default cal | 157 | inL->setCalID( 0 );// add to default cal |
158 | addIncidence( inL ); | 158 | addIncidence( inL ); |
159 | } | 159 | } |
160 | inR = er.next(); | 160 | inR = er.next(); |
161 | } | 161 | } |
162 | return true; | 162 | return true; |
163 | } | 163 | } |
164 | 164 | ||
165 | 165 | ||
166 | bool CalendarLocal::addCalendarFile( QString name, int id ) | 166 | bool CalendarLocal::addCalendarFile( QString name, int id ) |
167 | { | 167 | { |
168 | CalendarLocal calendar( timeZoneId() ); | 168 | CalendarLocal calendar( timeZoneId() ); |
169 | calendar.setDefaultCalendar( id ); | 169 | calendar.setDefaultCalendar( id ); |
170 | if ( calendar.load( name ) ) { | 170 | if ( calendar.load( name ) ) { |
171 | addCalendar( &calendar ); | 171 | addCalendar( &calendar ); |
172 | return true; | 172 | return true; |
173 | } | 173 | } |
174 | return false; | 174 | return false; |
175 | } | 175 | } |
176 | void CalendarLocal::setSyncEventsReadOnly() | 176 | void CalendarLocal::setSyncEventsReadOnly() |
177 | { | 177 | { |
178 | Event * ev; | 178 | Event * ev; |
179 | ev = mEventList.first(); | 179 | ev = mEventList.first(); |
180 | while ( ev ) { | 180 | while ( ev ) { |
181 | if ( ev->uid().left(15) == QString("last-syncEvent-") ) | 181 | if ( ev->uid().left(15) == QString("last-syncEvent-") ) |
182 | ev->setReadOnly( true ); | 182 | ev->setReadOnly( true ); |
183 | ev = mEventList.next(); | 183 | ev = mEventList.next(); |
184 | } | 184 | } |
185 | } | 185 | } |
186 | void CalendarLocal::addCalendar( Calendar* cal ) | 186 | void CalendarLocal::addCalendar( Calendar* cal ) |
187 | { | 187 | { |
188 | cal->setDontDeleteIncidencesOnClose(); | 188 | cal->setDontDeleteIncidencesOnClose(); |
189 | { | 189 | { |
190 | QPtrList<Event> EventList = cal->rawEvents(); | 190 | QPtrList<Event> EventList = cal->rawEvents(); |
191 | Event * ev = EventList.first(); | 191 | Event * ev = EventList.first(); |
192 | while ( ev ) { | 192 | while ( ev ) { |
193 | ev->unRegisterObserver( cal ); | 193 | ev->unRegisterObserver( cal ); |
194 | ev->registerObserver( this ); | 194 | ev->registerObserver( this ); |
195 | mEventList.append( ev ); | 195 | mEventList.append( ev ); |
196 | ev = EventList.next(); | 196 | ev = EventList.next(); |
197 | } | 197 | } |
198 | } | 198 | } |
199 | { | 199 | { |
200 | 200 | ||
201 | QPtrList<Todo> TodoList = cal->rawTodos(); | 201 | QPtrList<Todo> TodoList = cal->rawTodos(); |
202 | Todo * ev = TodoList.first(); | 202 | Todo * ev = TodoList.first(); |
203 | while ( ev ) { | 203 | while ( ev ) { |
204 | QString rel = ev->relatedToUid(); | 204 | QString rel = ev->relatedToUid(); |
205 | if ( !rel.isEmpty() ){ | 205 | if ( !rel.isEmpty() ){ |
206 | ev->setRelatedTo ( 0 ); | 206 | ev->setRelatedTo ( 0 ); |
207 | ev->setRelatedToUid( rel ); | 207 | ev->setRelatedToUid( rel ); |
208 | } | 208 | } |
209 | ev = TodoList.next(); | 209 | ev = TodoList.next(); |
210 | } | 210 | } |
211 | //TodoList = cal->rawTodos(); | 211 | //TodoList = cal->rawTodos(); |
212 | ev = TodoList.first(); | 212 | ev = TodoList.first(); |
213 | while ( ev ) { | 213 | while ( ev ) { |
214 | ev->unRegisterObserver( cal ); | 214 | ev->unRegisterObserver( cal ); |
215 | ev->registerObserver( this ); | 215 | ev->registerObserver( this ); |
216 | mTodoList.append( ev ); | 216 | mTodoList.append( ev ); |
217 | setupRelations( ev ); | 217 | setupRelations( ev ); |
218 | ev = TodoList.next(); | 218 | ev = TodoList.next(); |
219 | } | 219 | } |
220 | } | 220 | } |
221 | { | 221 | { |
222 | QPtrList<Journal> JournalList = cal->journals(); | 222 | QPtrList<Journal> JournalList = cal->journals(); |
223 | Journal * ev = JournalList.first(); | 223 | Journal * ev = JournalList.first(); |
224 | while ( ev ) { | 224 | while ( ev ) { |
225 | ev->unRegisterObserver( cal ); | 225 | ev->unRegisterObserver( cal ); |
226 | ev->registerObserver( this ); | 226 | ev->registerObserver( this ); |
227 | mJournalList.append( ev ); | 227 | mJournalList.append( ev ); |
228 | ev = JournalList.next(); | 228 | ev = JournalList.next(); |
229 | } | 229 | } |
230 | } | 230 | } |
231 | setModified( true ); | 231 | setModified( true ); |
232 | } | 232 | } |
233 | bool CalendarLocal::load( const QString &fileName ) | 233 | bool CalendarLocal::load( const QString &fileName ) |
234 | { | 234 | { |
235 | FileStorage storage( this, fileName ); | 235 | FileStorage storage( this, fileName ); |
236 | return storage.load(); | 236 | return storage.load(); |
237 | } | 237 | } |
238 | 238 | ||
239 | bool CalendarLocal::save( const QString &fileName, CalFormat *format ) | 239 | bool CalendarLocal::save( const QString &fileName, CalFormat *format ) |
240 | { | 240 | { |
241 | FileStorage storage( this, fileName, format ); | 241 | FileStorage storage( this, fileName, format ); |
242 | return storage.save(); | 242 | return storage.save(); |
243 | } | 243 | } |
244 | 244 | ||
245 | void CalendarLocal::stopAllTodos() | 245 | void CalendarLocal::stopAllTodos() |
246 | { | 246 | { |
247 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) | 247 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) |
248 | it->setRunning( false ); | 248 | it->setRunning( false ); |
249 | 249 | ||
250 | } | 250 | } |
251 | void CalendarLocal::close() | 251 | void CalendarLocal::close() |
252 | { | 252 | { |
253 | 253 | ||
254 | Todo * i; | 254 | Todo * i; |
255 | for( i = mTodoList.first(); i; i = mTodoList.next() ) i->setRunning(false); | 255 | for( i = mTodoList.first(); i; i = mTodoList.next() ) i->setRunning(false); |
256 | 256 | ||
257 | mEventList.setAutoDelete( true ); | 257 | mEventList.setAutoDelete( true ); |
258 | mTodoList.setAutoDelete( true ); | 258 | mTodoList.setAutoDelete( true ); |
259 | mJournalList.setAutoDelete( false ); | 259 | mJournalList.setAutoDelete( true ); |
260 | 260 | ||
261 | mEventList.clear(); | 261 | mEventList.clear(); |
262 | mTodoList.clear(); | 262 | mTodoList.clear(); |
263 | mJournalList.clear(); | 263 | mJournalList.clear(); |
264 | 264 | ||
265 | mEventList.setAutoDelete( false ); | 265 | mEventList.setAutoDelete( false ); |
266 | mTodoList.setAutoDelete( false ); | 266 | mTodoList.setAutoDelete( false ); |
267 | mJournalList.setAutoDelete( false ); | 267 | mJournalList.setAutoDelete( false ); |
268 | 268 | ||
269 | setModified( false ); | 269 | setModified( false ); |
270 | } | 270 | } |
271 | 271 | ||
272 | bool CalendarLocal::addAnniversaryNoDup( Event *event ) | 272 | bool CalendarLocal::addAnniversaryNoDup( Event *event ) |
273 | { | 273 | { |
274 | QString cat; | 274 | QString cat; |
275 | bool isBirthday = true; | 275 | bool isBirthday = true; |
276 | if( event->categoriesStr() == i18n( "Anniversary" ) ) { | 276 | if( event->categoriesStr() == i18n( "Anniversary" ) ) { |
277 | isBirthday = false; | 277 | isBirthday = false; |
278 | cat = i18n( "Anniversary" ); | 278 | cat = i18n( "Anniversary" ); |
279 | } else if( event->categoriesStr() == i18n( "Birthday" ) ) { | 279 | } else if( event->categoriesStr() == i18n( "Birthday" ) ) { |
280 | isBirthday = true; | 280 | isBirthday = true; |
281 | cat = i18n( "Birthday" ); | 281 | cat = i18n( "Birthday" ); |
282 | } else { | 282 | } else { |
283 | qDebug("addAnniversaryNoDup called without fitting category! "); | 283 | qDebug("addAnniversaryNoDup called without fitting category! "); |
284 | return false; | 284 | return false; |
285 | } | 285 | } |
286 | Event * eve; | 286 | Event * eve; |
287 | for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { | 287 | for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { |
288 | if ( !(eve->categories().contains( cat ) )) | 288 | if ( !(eve->categories().contains( cat ) )) |
289 | continue; | 289 | continue; |
290 | // now we have an event with fitting category | 290 | // now we have an event with fitting category |
291 | if ( eve->dtStart().date() != event->dtStart().date() ) | 291 | if ( eve->dtStart().date() != event->dtStart().date() ) |
292 | continue; | 292 | continue; |
293 | // now we have an event with fitting category+date | 293 | // now we have an event with fitting category+date |
294 | if ( eve->summary() != event->summary() ) | 294 | if ( eve->summary() != event->summary() ) |
295 | continue; | 295 | continue; |
296 | // now we have an event with fitting category+date+summary | 296 | // now we have an event with fitting category+date+summary |
297 | return false; | 297 | return false; |
298 | } | 298 | } |
299 | return addEvent( event ); | 299 | return addEvent( event ); |
300 | 300 | ||
301 | } | 301 | } |
302 | bool CalendarLocal::addEventNoDup( Event *event ) | 302 | bool CalendarLocal::addEventNoDup( Event *event ) |
303 | { | 303 | { |
304 | Event * eve; | 304 | Event * eve; |
305 | for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { | 305 | for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { |
306 | if ( *eve == *event ) { | 306 | if ( *eve == *event ) { |
307 | //qDebug("CalendarLocal::Duplicate event found! Not inserted! "); | 307 | //qDebug("CalendarLocal::Duplicate event found! Not inserted! "); |
308 | return false; | 308 | return false; |
309 | } | 309 | } |
310 | } | 310 | } |
311 | return addEvent( event ); | 311 | return addEvent( event ); |
312 | } | 312 | } |
313 | 313 | ||
314 | bool CalendarLocal::addEvent( Event *event ) | 314 | bool CalendarLocal::addEvent( Event *event ) |
315 | { | 315 | { |
316 | insertEvent( event ); | 316 | insertEvent( event ); |
317 | 317 | ||
318 | event->registerObserver( this ); | 318 | event->registerObserver( this ); |
319 | 319 | ||
320 | setModified( true ); | 320 | setModified( true ); |
321 | if ( event->calID() == 0 ) | 321 | if ( event->calID() == 0 ) |
322 | event->setCalID( mDefaultCalendar ); | 322 | event->setCalID( mDefaultCalendar ); |
323 | event->setCalEnabled( true ); | 323 | event->setCalEnabled( true ); |
324 | 324 | ||
325 | return true; | 325 | return true; |
326 | } | 326 | } |
327 | 327 | ||
328 | void CalendarLocal::deleteEvent( Event *event ) | 328 | void CalendarLocal::deleteEvent( Event *event ) |
329 | { | 329 | { |
330 | if ( mUndoIncidence ) delete mUndoIncidence; | 330 | if ( mUndoIncidence ) delete mUndoIncidence; |
331 | mUndoIncidence = event->clone(); | 331 | mUndoIncidence = event->clone(); |
332 | if ( mEventList.removeRef( event ) ) { | 332 | if ( mEventList.removeRef( event ) ) { |
333 | setModified( true ); | 333 | setModified( true ); |
334 | } | 334 | } |
335 | } | 335 | } |
336 | 336 | ||
337 | 337 | ||
338 | Event *CalendarLocal::event( const QString &uid ) | 338 | Event *CalendarLocal::event( const QString &uid ) |
339 | { | 339 | { |
340 | Event *event; | 340 | Event *event; |
341 | Event *retVal = 0; | 341 | Event *retVal = 0; |
342 | for ( event = mEventList.first(); event; event = mEventList.next() ) { | 342 | for ( event = mEventList.first(); event; event = mEventList.next() ) { |
343 | if ( event->calEnabled() && event->uid() == uid ) { | 343 | if ( event->calEnabled() && event->uid() == uid ) { |
344 | if ( retVal ) { | 344 | if ( retVal ) { |
345 | if ( retVal->calID() > event->calID() ) { | 345 | if ( retVal->calID() > event->calID() ) { |
346 | retVal = event; | 346 | retVal = event; |
347 | } | 347 | } |
348 | } else { | 348 | } else { |
349 | retVal = event; | 349 | retVal = event; |
350 | } | 350 | } |
351 | } | 351 | } |
352 | } | 352 | } |
353 | return retVal; | 353 | return retVal; |
354 | } | 354 | } |
355 | bool CalendarLocal::addTodoNoDup( Todo *todo ) | 355 | bool CalendarLocal::addTodoNoDup( Todo *todo ) |
356 | { | 356 | { |
357 | Todo * eve; | 357 | Todo * eve; |
358 | for ( eve = mTodoList.first(); eve ; eve = mTodoList.next() ) { | 358 | for ( eve = mTodoList.first(); eve ; eve = mTodoList.next() ) { |
359 | if ( *eve == *todo ) { | 359 | if ( *eve == *todo ) { |
360 | //qDebug("duplicate todo found! not inserted! "); | 360 | //qDebug("duplicate todo found! not inserted! "); |
361 | return false; | 361 | return false; |
362 | } | 362 | } |
363 | } | 363 | } |
364 | return addTodo( todo ); | 364 | return addTodo( todo ); |
365 | } | 365 | } |
366 | bool CalendarLocal::addTodo( Todo *todo ) | 366 | bool CalendarLocal::addTodo( Todo *todo ) |
367 | { | 367 | { |
368 | mTodoList.append( todo ); | 368 | mTodoList.append( todo ); |
369 | 369 | ||
370 | todo->registerObserver( this ); | 370 | todo->registerObserver( this ); |
371 | 371 | ||
372 | // Set up subtask relations | 372 | // Set up subtask relations |
373 | setupRelations( todo ); | 373 | setupRelations( todo ); |
374 | 374 | ||
375 | setModified( true ); | 375 | setModified( true ); |
376 | if ( todo->calID() == 0 ) | 376 | if ( todo->calID() == 0 ) |
377 | todo->setCalID( mDefaultCalendar ); | 377 | todo->setCalID( mDefaultCalendar ); |
378 | todo->setCalEnabled( true ); | 378 | todo->setCalEnabled( true ); |
379 | return true; | 379 | return true; |
380 | } | 380 | } |
381 | 381 | ||
382 | void CalendarLocal::deleteTodo( Todo *todo ) | 382 | void CalendarLocal::deleteTodo( Todo *todo ) |
383 | { | 383 | { |
384 | // Handle orphaned children | 384 | // Handle orphaned children |
385 | if ( mUndoIncidence ) delete mUndoIncidence; | 385 | if ( mUndoIncidence ) delete mUndoIncidence; |
386 | removeRelations( todo ); | 386 | removeRelations( todo ); |
387 | mUndoIncidence = todo->clone(); | 387 | mUndoIncidence = todo->clone(); |