summaryrefslogtreecommitdiffabout
path: root/libkcal/calendar.cpp
Unidiff
Diffstat (limited to 'libkcal/calendar.cpp') (more/less context) (show whitespace changes)
-rw-r--r--libkcal/calendar.cpp9
1 files changed, 6 insertions, 3 deletions
diff --git a/libkcal/calendar.cpp b/libkcal/calendar.cpp
index 8535191..1350f6d 100644
--- a/libkcal/calendar.cpp
+++ b/libkcal/calendar.cpp
@@ -1,58 +1,57 @@
1/* 1/*
2 This file is part of libkcal. 2 This file is part of libkcal.
3 Copyright (c) 1998 Preston Brown 3 Copyright (c) 1998 Preston Brown
4 Copyright (c) 2000,2001 Cornelius Schumacher <schumacher@kde.org> 4 Copyright (c) 2000,2001 Cornelius Schumacher <schumacher@kde.org>
5 5
6 This library is free software; you can redistribute it and/or 6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public 7 modify it under the terms of the GNU Library General Public
8 License as published by the Free Software Foundation; either 8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version. 9 version 2 of the License, or (at your option) any later version.
10
11 This library is distributed in the hope that it will be useful, 10 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details. 13 Library General Public License for more details.
15 14
16 You should have received a copy of the GNU Library General Public License 15 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to 16 along with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
20*/ 19*/
21 20
22#include <stdlib.h> 21#include <stdlib.h>
23#include <time.h> 22#include <time.h>
24 23
25#include <kdebug.h> 24#include <kdebug.h>
26#include <kglobal.h> 25#include <kglobal.h>
27#include <klocale.h> 26#include <klocale.h>
28 27
29#include "exceptions.h" 28#include "exceptions.h"
30#include "calfilter.h" 29#include "calfilter.h"
31 30
32#include "calendar.h" 31#include "calendar.h"
33#include "syncdefines.h" 32#include "syncdefines.h"
34 33
35using namespace KCal; 34using namespace KCal;
36 35
37Calendar::Calendar() 36Calendar::Calendar()
38{ 37{
39 38
40 init(); 39 init();
41 setTimeZoneId( " 00:00 Europe/London(UTC)" ); 40 setTimeZoneId( " 00:00 Europe/London(UTC)" );
42} 41}
43 42
44Calendar::Calendar( const QString &timeZoneId ) 43Calendar::Calendar( const QString &timeZoneId )
45{ 44{
46 45
47 init(); 46 init();
48 setTimeZoneId(timeZoneId); 47 setTimeZoneId(timeZoneId);
49} 48}
50 49
51void Calendar::init() 50void Calendar::init()
52{ 51{
53 mObserver = 0; 52 mObserver = 0;
54 mNewObserver = false; 53 mNewObserver = false;
55 mUndoIncidence = 0; 54 mUndoIncidence = 0;
56 mDeleteIncidencesOnClose = true; 55 mDeleteIncidencesOnClose = true;
57 mModified = false; 56 mModified = false;
58 mDefaultCalendar = 1; 57 mDefaultCalendar = 1;
@@ -375,115 +374,119 @@ void Calendar::addIncidenceBranch(Incidence *i)
375 addIncidenceBranch( inc ); 374 addIncidenceBranch( inc );
376 } 375 }
377} 376}
378 377
379bool Calendar::addIncidence(Incidence *i) 378bool Calendar::addIncidence(Incidence *i)
380{ 379{
381 Incidence::AddVisitor<Calendar> v(this); 380 Incidence::AddVisitor<Calendar> v(this);
382 if ( i->calID() == 0 ) 381 if ( i->calID() == 0 )
383 i->setCalID_block( mDefaultCalendar ); 382 i->setCalID_block( mDefaultCalendar );
384 i->setCalEnabled( true ); 383 i->setCalEnabled( true );
385 return i->accept(v); 384 return i->accept(v);
386} 385}
387void Calendar::deleteIncidence(Incidence *in) 386void Calendar::deleteIncidence(Incidence *in)
388{ 387{
389 if ( in->typeID() == eventID ) 388 if ( in->typeID() == eventID )
390 deleteEvent( (Event*) in ); 389 deleteEvent( (Event*) in );
391 else if ( in->typeID() == todoID ) 390 else if ( in->typeID() == todoID )
392 deleteTodo( (Todo*) in); 391 deleteTodo( (Todo*) in);
393 else if ( in->typeID() == journalID ) 392 else if ( in->typeID() == journalID )
394 deleteJournal( (Journal*) in ); 393 deleteJournal( (Journal*) in );
395} 394}
396 395
397Incidence* Calendar::incidence( const QString& uid ) 396Incidence* Calendar::incidence( const QString& uid )
398{ 397{
399 Incidence* i; 398 Incidence* i;
400 399
401 if( (i = todo( uid )) != 0 ) 400 if( (i = todo( uid )) != 0 )
402 return i; 401 return i;
403 if( (i = event( uid )) != 0 ) 402 if( (i = event( uid )) != 0 )
404 return i; 403 return i;
405 if( (i = journal( uid )) != 0 ) 404 if( (i = journal( uid )) != 0 )
406 return i; 405 return i;
407 406
408 return 0; 407 return 0;
409} 408}
410 409
411QPtrList<Todo> Calendar::todos() 410QPtrList<Todo> Calendar::todos()
412{ 411{
413 QPtrList<Todo> tl = rawTodos(); 412 QPtrList<Todo> tl = rawTodos();
414 mFilter->apply( &tl ); 413 mFilter->apply( &tl );
415 return tl; 414 return tl;
416} 415}
417 416
418// When this is called, the todo have already been added to the calendar. 417// When this is called, the todo have already been added to the calendar.
419// This method is only about linking related todos 418// This method is only about linking related todos
420void Calendar::setupRelations( Incidence *incidence ) 419void Calendar::setupRelations( Incidence *incidence )
421{ 420{
422 QString uid = incidence->uid(); 421 QString uid = incidence->uid();
423 //qDebug("Calendar::setupRelations "); 422 //qDebug("Calendar::setupRelations %s", incidence->summary().latin1());
424 // First, go over the list of orphans and see if this is their parent 423 // First, go over the list of orphans and see if this is their parent
425 while( Incidence* i = mOrphans[ uid ] ) { 424 while( Incidence* i = mOrphans[ uid ] ) {
426 mOrphans.remove( uid ); 425 mOrphans.remove( uid );
427 i->setRelatedTo( incidence ); 426 i->setRelatedTo( incidence );
427 //qDebug("Add child %s ti inc %s", i->summary().latin1(),incidence->summary().latin1());
428 incidence->addRelation( i ); 428 incidence->addRelation( i );
429 mOrphanUids.remove( i->uid() ); 429 mOrphanUids.remove( i->uid() );
430 } 430 }
431 431
432 // Now see about this incidences parent 432 // Now see about this incidences parent
433 if( !incidence->relatedTo() && !incidence->relatedToUid().isEmpty() ) { 433 if( !incidence->relatedTo() && !incidence->relatedToUid().isEmpty() ) {
434 // This incidence has a uid it is related to, but is not registered to it yet 434 // This incidence has a uid it is related to, but is not registered to it yet
435 // Try to find it 435 // Try to find it
436 Incidence* parent = this->incidence( incidence->relatedToUid() ); 436 //qDebug("Test parent for %s", incidence->summary().latin1());
437 Incidence* parent = this->incidenceForUid( incidence->relatedToUid(), true );
437 if( parent ) { 438 if( parent ) {
438 // Found it 439 // Found it
440 // qDebug("parent found for for %s", incidence->summary().latin1());
439 incidence->setRelatedTo( parent ); 441 incidence->setRelatedTo( parent );
440 parent->addRelation( incidence ); 442 parent->addRelation( incidence );
441 } else { 443 } else {
444 // qDebug("NO parent found for for %s", incidence->summary().latin1());
442 // Not found, put this in the mOrphans list 445 // Not found, put this in the mOrphans list
443 mOrphans.insert( incidence->relatedToUid(), incidence ); 446 mOrphans.insert( incidence->relatedToUid(), incidence );
444 mOrphanUids.insert( incidence->uid(), incidence ); 447 mOrphanUids.insert( incidence->uid(), incidence );
445 } 448 }
446 } 449 }
447} 450}
448 451
449// If a task with subtasks is deleted, move it's subtasks to the orphans list 452// If a task with subtasks is deleted, move it's subtasks to the orphans list
450void Calendar::removeRelations( Incidence *incidence ) 453void Calendar::removeRelations( Incidence *incidence )
451{ 454{
452 // qDebug("Calendar::removeRelations "); 455 // qDebug("Calendar::removeRelations ");
453 QString uid = incidence->uid(); 456 QString uid = incidence->uid();
454 457
455 QPtrList<Incidence> relations = incidence->relations(); 458 QPtrList<Incidence> relations = incidence->relations();
456 for( Incidence* i = relations.first(); i; i = relations.next() ) 459 for( Incidence* i = relations.first(); i; i = relations.next() )
457 if( !mOrphanUids.find( i->uid() ) ) { 460 if( !mOrphanUids.find( i->uid() ) ) {
458 mOrphans.insert( uid, i ); 461 mOrphans.insert( uid, i );
459 mOrphanUids.insert( i->uid(), i ); 462 mOrphanUids.insert( i->uid(), i );
460 i->setRelatedTo( 0 ); 463 i->setRelatedTo( 0 );
461 i->setRelatedToUid( uid ); 464 i->setRelatedToUid( uid );
462 } 465 }
463 466
464 // If this incidence is related to something else, tell that about it 467 // If this incidence is related to something else, tell that about it
465 if( incidence->relatedTo() ) 468 if( incidence->relatedTo() )
466 incidence->relatedTo()->removeRelation( incidence ); 469 incidence->relatedTo()->removeRelation( incidence );
467 470
468 // Remove this one from the orphans list 471 // Remove this one from the orphans list
469 if( mOrphanUids.remove( uid ) ) { 472 if( mOrphanUids.remove( uid ) ) {
470 QString r2uid = incidence->relatedToUid(); 473 QString r2uid = incidence->relatedToUid();
471 QPtrList<Incidence> tempList; 474 QPtrList<Incidence> tempList;
472 while( Incidence* i = mOrphans[ r2uid ] ) { 475 while( Incidence* i = mOrphans[ r2uid ] ) {
473 mOrphans.remove( r2uid ); 476 mOrphans.remove( r2uid );
474 if ( i != incidence ) tempList.append( i ); 477 if ( i != incidence ) tempList.append( i );
475 } 478 }
476 Incidence* inc = tempList.first(); 479 Incidence* inc = tempList.first();
477 while ( inc ) { 480 while ( inc ) {
478 mOrphans.insert( r2uid, inc ); 481 mOrphans.insert( r2uid, inc );
479 inc = tempList.next(); 482 inc = tempList.next();
480 } 483 }
481 } 484 }
482 // LR: and another big bad bug found 485 // LR: and another big bad bug found
483#if 0 486#if 0
484 // This incidence is located in the orphans list - it should be removed 487 // This incidence is located in the orphans list - it should be removed
485 if( !( incidence->relatedTo() != 0 && mOrphans.remove( incidence->relatedTo()->uid() ) ) ) { 488 if( !( incidence->relatedTo() != 0 && mOrphans.remove( incidence->relatedTo()->uid() ) ) ) {
486 // Removing wasn't that easy 489 // Removing wasn't that easy
487 for( QDictIterator<Incidence> it( mOrphans ); it.current(); ++it ) { 490 for( QDictIterator<Incidence> it( mOrphans ); it.current(); ++it ) {
488 if( it.current()->uid() == uid ) { 491 if( it.current()->uid() == uid ) {
489 mOrphans.remove( it.currentKey() ); 492 mOrphans.remove( it.currentKey() );