summaryrefslogtreecommitdiffabout
path: root/libkcal/calendar.cpp
Unidiff
Diffstat (limited to 'libkcal/calendar.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libkcal/calendar.cpp10
1 files changed, 9 insertions, 1 deletions
diff --git a/libkcal/calendar.cpp b/libkcal/calendar.cpp
index 406cd48..ed39ddb 100644
--- a/libkcal/calendar.cpp
+++ b/libkcal/calendar.cpp
@@ -210,257 +210,265 @@ void Calendar::setLocalTime()
210 mLocalTime = true; 210 mLocalTime = true;
211 mTimeZone = 0; 211 mTimeZone = 0;
212 mTimeZoneId = ""; 212 mTimeZoneId = "";
213 213
214 setModified( true ); 214 setModified( true );
215} 215}
216 216
217bool Calendar::isLocalTime() const 217bool Calendar::isLocalTime() const
218{ 218{
219 return mLocalTime; 219 return mLocalTime;
220} 220}
221 221
222const QString &Calendar::getEmail() 222const QString &Calendar::getEmail()
223{ 223{
224 return mOwnerEmail; 224 return mOwnerEmail;
225} 225}
226 226
227void Calendar::setEmail(const QString &e) 227void Calendar::setEmail(const QString &e)
228{ 228{
229 mOwnerEmail = e; 229 mOwnerEmail = e;
230 230
231 setModified( true ); 231 setModified( true );
232} 232}
233 233
234void Calendar::setFilter(CalFilter *filter) 234void Calendar::setFilter(CalFilter *filter)
235{ 235{
236 mFilter = filter; 236 mFilter = filter;
237} 237}
238 238
239CalFilter *Calendar::filter() 239CalFilter *Calendar::filter()
240{ 240{
241 return mFilter; 241 return mFilter;
242} 242}
243 243
244QPtrList<Incidence> Calendar::incidences() 244QPtrList<Incidence> Calendar::incidences()
245{ 245{
246 QPtrList<Incidence> incidences; 246 QPtrList<Incidence> incidences;
247 247
248 Incidence *i; 248 Incidence *i;
249 249
250 QPtrList<Event> e = events(); 250 QPtrList<Event> e = events();
251 for( i = e.first(); i; i = e.next() ) incidences.append( i ); 251 for( i = e.first(); i; i = e.next() ) incidences.append( i );
252 252
253 QPtrList<Todo> t = todos(); 253 QPtrList<Todo> t = todos();
254 for( i = t.first(); i; i = t.next() ) incidences.append( i ); 254 for( i = t.first(); i; i = t.next() ) incidences.append( i );
255 255
256 QPtrList<Journal> j = journals(); 256 QPtrList<Journal> j = journals();
257 for( i = j.first(); i; i = j.next() ) incidences.append( i ); 257 for( i = j.first(); i; i = j.next() ) incidences.append( i );
258 258
259 return incidences; 259 return incidences;
260} 260}
261 261
262void Calendar::resetPilotStat(int id ) 262void Calendar::resetPilotStat(int id )
263{ 263{
264 QPtrList<Incidence> incidences; 264 QPtrList<Incidence> incidences;
265 265
266 Incidence *i; 266 Incidence *i;
267 267
268 QPtrList<Event> e = rawEvents(); 268 QPtrList<Event> e = rawEvents();
269 for( i = e.first(); i; i = e.next() ) i->setPilotId( id ); 269 for( i = e.first(); i; i = e.next() ) i->setPilotId( id );
270 270
271 QPtrList<Todo> t = rawTodos(); 271 QPtrList<Todo> t = rawTodos();
272 for( i = t.first(); i; i = t.next() ) i->setPilotId( id ); 272 for( i = t.first(); i; i = t.next() ) i->setPilotId( id );
273 273
274 QPtrList<Journal> j = journals(); 274 QPtrList<Journal> j = journals();
275 for( i = j.first(); i; i = j.next() ) i->setPilotId( id ); 275 for( i = j.first(); i; i = j.next() ) i->setPilotId( id );
276} 276}
277void Calendar::resetTempSyncStat() 277void Calendar::resetTempSyncStat()
278{ 278{
279 QPtrList<Incidence> incidences; 279 QPtrList<Incidence> incidences;
280 280
281 Incidence *i; 281 Incidence *i;
282 282
283 QPtrList<Event> e = rawEvents(); 283 QPtrList<Event> e = rawEvents();
284 for( i = e.first(); i; i = e.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 284 for( i = e.first(); i; i = e.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
285 285
286 QPtrList<Todo> t = rawTodos(); 286 QPtrList<Todo> t = rawTodos();
287 for( i = t.first(); i; i = t.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 287 for( i = t.first(); i; i = t.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
288 288
289 QPtrList<Journal> j = journals(); 289 QPtrList<Journal> j = journals();
290 for( i = j.first(); i; i = j.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 290 for( i = j.first(); i; i = j.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
291} 291}
292QPtrList<Incidence> Calendar::rawIncidences() 292QPtrList<Incidence> Calendar::rawIncidences()
293{ 293{
294 QPtrList<Incidence> incidences; 294 QPtrList<Incidence> incidences;
295 295
296 Incidence *i; 296 Incidence *i;
297 297
298 QPtrList<Event> e = rawEvents(); 298 QPtrList<Event> e = rawEvents();
299 for( i = e.first(); i; i = e.next() ) incidences.append( i ); 299 for( i = e.first(); i; i = e.next() ) incidences.append( i );
300 300
301 QPtrList<Todo> t = rawTodos(); 301 QPtrList<Todo> t = rawTodos();
302 for( i = t.first(); i; i = t.next() ) incidences.append( i ); 302 for( i = t.first(); i; i = t.next() ) incidences.append( i );
303 303
304 QPtrList<Journal> j = journals(); 304 QPtrList<Journal> j = journals();
305 for( i = j.first(); i; i = j.next() ) incidences.append( i ); 305 for( i = j.first(); i; i = j.next() ) incidences.append( i );
306 306
307 return incidences; 307 return incidences;
308} 308}
309 309
310QPtrList<Event> Calendar::events( const QDate &date, bool sorted ) 310QPtrList<Event> Calendar::events( const QDate &date, bool sorted )
311{ 311{
312 QPtrList<Event> el = rawEventsForDate(date,sorted); 312 QPtrList<Event> el = rawEventsForDate(date,sorted);
313 mFilter->apply(&el); 313 mFilter->apply(&el);
314 return el; 314 return el;
315} 315}
316 316
317QPtrList<Event> Calendar::events( const QDateTime &qdt ) 317QPtrList<Event> Calendar::events( const QDateTime &qdt )
318{ 318{
319 QPtrList<Event> el = rawEventsForDate(qdt); 319 QPtrList<Event> el = rawEventsForDate(qdt);
320 mFilter->apply(&el); 320 mFilter->apply(&el);
321 return el; 321 return el;
322} 322}
323 323
324QPtrList<Event> Calendar::events( const QDate &start, const QDate &end, 324QPtrList<Event> Calendar::events( const QDate &start, const QDate &end,
325 bool inclusive) 325 bool inclusive)
326{ 326{
327 QPtrList<Event> el = rawEvents(start,end,inclusive); 327 QPtrList<Event> el = rawEvents(start,end,inclusive);
328 mFilter->apply(&el); 328 mFilter->apply(&el);
329 return el; 329 return el;
330} 330}
331 331
332QPtrList<Event> Calendar::events() 332QPtrList<Event> Calendar::events()
333{ 333{
334 QPtrList<Event> el = rawEvents(); 334 QPtrList<Event> el = rawEvents();
335 mFilter->apply(&el); 335 mFilter->apply(&el);
336 return el; 336 return el;
337} 337}
338 338void Calendar::addIncidenceBranch(Incidence *i)
339{
340 addIncidence( i );
341 Incidence * inc;
342 QPtrList<Incidence> Relations = i->relations();
343 for (inc=Relations.first();inc;inc=Relations.next()) {
344 addIncidenceBranch( inc );
345 }
346}
339 347
340bool Calendar::addIncidence(Incidence *i) 348bool Calendar::addIncidence(Incidence *i)
341{ 349{
342 Incidence::AddVisitor<Calendar> v(this); 350 Incidence::AddVisitor<Calendar> v(this);
343 351
344 return i->accept(v); 352 return i->accept(v);
345} 353}
346void Calendar::deleteIncidence(Incidence *in) 354void Calendar::deleteIncidence(Incidence *in)
347{ 355{
348 if ( in->type() == "Event" ) 356 if ( in->type() == "Event" )
349 deleteEvent( (Event*) in ); 357 deleteEvent( (Event*) in );
350 else if ( in->type() =="Todo" ) 358 else if ( in->type() =="Todo" )
351 deleteTodo( (Todo*) in); 359 deleteTodo( (Todo*) in);
352 else if ( in->type() =="Journal" ) 360 else if ( in->type() =="Journal" )
353 deleteJournal( (Journal*) in ); 361 deleteJournal( (Journal*) in );
354} 362}
355 363
356Incidence* Calendar::incidence( const QString& uid ) 364Incidence* Calendar::incidence( const QString& uid )
357{ 365{
358 Incidence* i; 366 Incidence* i;
359 367
360 if( (i = todo( uid )) != 0 ) 368 if( (i = todo( uid )) != 0 )
361 return i; 369 return i;
362 if( (i = event( uid )) != 0 ) 370 if( (i = event( uid )) != 0 )
363 return i; 371 return i;
364 if( (i = journal( uid )) != 0 ) 372 if( (i = journal( uid )) != 0 )
365 return i; 373 return i;
366 374
367 return 0; 375 return 0;
368} 376}
369 377
370QPtrList<Todo> Calendar::todos() 378QPtrList<Todo> Calendar::todos()
371{ 379{
372 QPtrList<Todo> tl = rawTodos(); 380 QPtrList<Todo> tl = rawTodos();
373 mFilter->apply( &tl ); 381 mFilter->apply( &tl );
374 return tl; 382 return tl;
375} 383}
376 384
377// When this is called, the todo have already been added to the calendar. 385// When this is called, the todo have already been added to the calendar.
378// This method is only about linking related todos 386// This method is only about linking related todos
379void Calendar::setupRelations( Incidence *incidence ) 387void Calendar::setupRelations( Incidence *incidence )
380{ 388{
381 QString uid = incidence->uid(); 389 QString uid = incidence->uid();
382 //qDebug("Calendar::setupRelations "); 390 //qDebug("Calendar::setupRelations ");
383 // First, go over the list of orphans and see if this is their parent 391 // First, go over the list of orphans and see if this is their parent
384 while( Incidence* i = mOrphans[ uid ] ) { 392 while( Incidence* i = mOrphans[ uid ] ) {
385 mOrphans.remove( uid ); 393 mOrphans.remove( uid );
386 i->setRelatedTo( incidence ); 394 i->setRelatedTo( incidence );
387 incidence->addRelation( i ); 395 incidence->addRelation( i );
388 mOrphanUids.remove( i->uid() ); 396 mOrphanUids.remove( i->uid() );
389 } 397 }
390 398
391 // Now see about this incidences parent 399 // Now see about this incidences parent
392 if( !incidence->relatedTo() && !incidence->relatedToUid().isEmpty() ) { 400 if( !incidence->relatedTo() && !incidence->relatedToUid().isEmpty() ) {
393 // This incidence has a uid it is related to, but is not registered to it yet 401 // This incidence has a uid it is related to, but is not registered to it yet
394 // Try to find it 402 // Try to find it
395 Incidence* parent = this->incidence( incidence->relatedToUid() ); 403 Incidence* parent = this->incidence( incidence->relatedToUid() );
396 if( parent ) { 404 if( parent ) {
397 // Found it 405 // Found it
398 incidence->setRelatedTo( parent ); 406 incidence->setRelatedTo( parent );
399 parent->addRelation( incidence ); 407 parent->addRelation( incidence );
400 } else { 408 } else {
401 // Not found, put this in the mOrphans list 409 // Not found, put this in the mOrphans list
402 mOrphans.insert( incidence->relatedToUid(), incidence ); 410 mOrphans.insert( incidence->relatedToUid(), incidence );
403 mOrphanUids.insert( incidence->uid(), incidence ); 411 mOrphanUids.insert( incidence->uid(), incidence );
404 } 412 }
405 } 413 }
406} 414}
407 415
408// If a task with subtasks is deleted, move it's subtasks to the orphans list 416// If a task with subtasks is deleted, move it's subtasks to the orphans list
409void Calendar::removeRelations( Incidence *incidence ) 417void Calendar::removeRelations( Incidence *incidence )
410{ 418{
411 // qDebug("Calendar::removeRelations "); 419 // qDebug("Calendar::removeRelations ");
412 QString uid = incidence->uid(); 420 QString uid = incidence->uid();
413 421
414 QPtrList<Incidence> relations = incidence->relations(); 422 QPtrList<Incidence> relations = incidence->relations();
415 for( Incidence* i = relations.first(); i; i = relations.next() ) 423 for( Incidence* i = relations.first(); i; i = relations.next() )
416 if( !mOrphanUids.find( i->uid() ) ) { 424 if( !mOrphanUids.find( i->uid() ) ) {
417 mOrphans.insert( uid, i ); 425 mOrphans.insert( uid, i );
418 mOrphanUids.insert( i->uid(), i ); 426 mOrphanUids.insert( i->uid(), i );
419 i->setRelatedTo( 0 ); 427 i->setRelatedTo( 0 );
420 i->setRelatedToUid( uid ); 428 i->setRelatedToUid( uid );
421 } 429 }
422 430
423 // If this incidence is related to something else, tell that about it 431 // If this incidence is related to something else, tell that about it
424 if( incidence->relatedTo() ) 432 if( incidence->relatedTo() )
425 incidence->relatedTo()->removeRelation( incidence ); 433 incidence->relatedTo()->removeRelation( incidence );
426 434
427 // Remove this one from the orphans list 435 // Remove this one from the orphans list
428 if( mOrphanUids.remove( uid ) ) 436 if( mOrphanUids.remove( uid ) )
429 // This incidence is located in the orphans list - it should be removed 437 // This incidence is located in the orphans list - it should be removed
430 if( !( incidence->relatedTo() != 0 && mOrphans.remove( incidence->relatedTo()->uid() ) ) ) { 438 if( !( incidence->relatedTo() != 0 && mOrphans.remove( incidence->relatedTo()->uid() ) ) ) {
431 // Removing wasn't that easy 439 // Removing wasn't that easy
432 for( QDictIterator<Incidence> it( mOrphans ); it.current(); ++it ) { 440 for( QDictIterator<Incidence> it( mOrphans ); it.current(); ++it ) {
433 if( it.current()->uid() == uid ) { 441 if( it.current()->uid() == uid ) {
434 mOrphans.remove( it.currentKey() ); 442 mOrphans.remove( it.currentKey() );
435 break; 443 break;
436 } 444 }
437 } 445 }
438 } 446 }
439} 447}
440 448
441void Calendar::registerObserver( Observer *observer ) 449void Calendar::registerObserver( Observer *observer )
442{ 450{
443 mObserver = observer; 451 mObserver = observer;
444 mNewObserver = true; 452 mNewObserver = true;
445} 453}
446 454
447void Calendar::setModified( bool modified ) 455void Calendar::setModified( bool modified )
448{ 456{
449 if ( mObserver ) mObserver->calendarModified( modified, this ); 457 if ( mObserver ) mObserver->calendarModified( modified, this );
450 if ( modified != mModified || mNewObserver ) { 458 if ( modified != mModified || mNewObserver ) {
451 mNewObserver = false; 459 mNewObserver = false;
452 // if ( mObserver ) mObserver->calendarModified( modified, this ); 460 // if ( mObserver ) mObserver->calendarModified( modified, this );
453 mModified = modified; 461 mModified = modified;
454 } 462 }
455} 463}
456 464
457void Calendar::setLoadedProductId( const QString &id ) 465void Calendar::setLoadedProductId( const QString &id )
458{ 466{
459 mLoadedProductId = id; 467 mLoadedProductId = id;
460} 468}
461 469
462QString Calendar::loadedProductId() 470QString Calendar::loadedProductId()
463{ 471{
464 return mLoadedProductId; 472 return mLoadedProductId;
465} 473}
466 474