summaryrefslogtreecommitdiffabout
path: root/libkcal/calendar.cpp
Unidiff
Diffstat (limited to 'libkcal/calendar.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libkcal/calendar.cpp66
1 files changed, 34 insertions, 32 deletions
diff --git a/libkcal/calendar.cpp b/libkcal/calendar.cpp
index 9b38d3f..bf095cf 100644
--- a/libkcal/calendar.cpp
+++ b/libkcal/calendar.cpp
@@ -9,48 +9,50 @@
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 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,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details. 13 Library General Public License for more details.
14 14
15 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
16 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
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20 20
21#include <stdlib.h> 21#include <stdlib.h>
22#include <time.h> 22#include <time.h>
23 23
24#include <kdebug.h> 24#include <kdebug.h>
25#include <kglobal.h> 25#include <kglobal.h>
26#include <klocale.h> 26#include <klocale.h>
27 27
28#include "exceptions.h" 28#include "exceptions.h"
29#include "calfilter.h" 29#include "calfilter.h"
30 30
31#include "calendar.h" 31#include "calendar.h"
32#include "syncdefines.h" 32#include "syncdefines.h"
33//Added by qt3to4:
34#include <Q3PtrList>
33 35
34using namespace KCal; 36using namespace KCal;
35 37
36Calendar::Calendar() 38Calendar::Calendar()
37{ 39{
38 40
39 init(); 41 init();
40 setTimeZoneId( " 00:00 Europe/London(UTC)" ); 42 setTimeZoneId( " 00:00 Europe/London(UTC)" );
41} 43}
42 44
43Calendar::Calendar( const QString &timeZoneId ) 45Calendar::Calendar( const QString &timeZoneId )
44{ 46{
45 47
46 init(); 48 init();
47 setTimeZoneId(timeZoneId); 49 setTimeZoneId(timeZoneId);
48} 50}
49 51
50void Calendar::init() 52void Calendar::init()
51{ 53{
52 mObserver = 0; 54 mObserver = 0;
53 mNewObserver = false; 55 mNewObserver = false;
54 mUndoIncidence = 0; 56 mUndoIncidence = 0;
55 mDeleteIncidencesOnClose = true; 57 mDeleteIncidencesOnClose = true;
56 mModified = false; 58 mModified = false;
@@ -250,265 +252,265 @@ bool Calendar::isLocalTime() const
250} 252}
251 253
252const QString &Calendar::getEmail() 254const QString &Calendar::getEmail()
253{ 255{
254 return mOwnerEmail; 256 return mOwnerEmail;
255} 257}
256 258
257void Calendar::setEmail(const QString &e) 259void Calendar::setEmail(const QString &e)
258{ 260{
259 mOwnerEmail = e; 261 mOwnerEmail = e;
260 262
261 setModified( true ); 263 setModified( true );
262} 264}
263 265
264void Calendar::setFilter(CalFilter *filter) 266void Calendar::setFilter(CalFilter *filter)
265{ 267{
266 mFilter = filter; 268 mFilter = filter;
267} 269}
268 270
269CalFilter *Calendar::filter() 271CalFilter *Calendar::filter()
270{ 272{
271 return mFilter; 273 return mFilter;
272} 274}
273 275
274QPtrList<Incidence> Calendar::incidences() 276Q3PtrList<Incidence> Calendar::incidences()
275{ 277{
276 QPtrList<Incidence> incidences; 278 Q3PtrList<Incidence> incidences;
277 279
278 Incidence *i; 280 Incidence *i;
279 281
280 QPtrList<Event> e = events(); 282 Q3PtrList<Event> e = events();
281 for( i = e.first(); i; i = e.next() ) incidences.append( i ); 283 for( i = e.first(); i; i = e.next() ) incidences.append( i );
282 284
283 QPtrList<Todo> t = todos(); 285 Q3PtrList<Todo> t = todos();
284 for( i = t.first(); i; i = t.next() ) incidences.append( i ); 286 for( i = t.first(); i; i = t.next() ) incidences.append( i );
285 287
286 QPtrList<Journal> j = journals(); 288 Q3PtrList<Journal> j = journals();
287 for( i = j.first(); i; i = j.next() ) incidences.append( i ); 289 for( i = j.first(); i; i = j.next() ) incidences.append( i );
288 290
289 return incidences; 291 return incidences;
290} 292}
291 293
292void Calendar::resetPilotStat(int id ) 294void Calendar::resetPilotStat(int id )
293{ 295{
294 QPtrList<Incidence> incidences; 296 Q3PtrList<Incidence> incidences;
295 297
296 Incidence *i; 298 Incidence *i;
297 299
298 QPtrList<Event> e = rawEvents(); 300 Q3PtrList<Event> e = rawEvents();
299 for( i = e.first(); i; i = e.next() ) i->setPilotId( id ); 301 for( i = e.first(); i; i = e.next() ) i->setPilotId( id );
300 302
301 QPtrList<Todo> t = rawTodos(); 303 Q3PtrList<Todo> t = rawTodos();
302 for( i = t.first(); i; i = t.next() ) i->setPilotId( id ); 304 for( i = t.first(); i; i = t.next() ) i->setPilotId( id );
303 305
304 QPtrList<Journal> j = journals(); 306 Q3PtrList<Journal> j = journals();
305 for( i = j.first(); i; i = j.next() ) i->setPilotId( id ); 307 for( i = j.first(); i; i = j.next() ) i->setPilotId( id );
306} 308}
307void Calendar::resetTempSyncStat() 309void Calendar::resetTempSyncStat()
308{ 310{
309 QPtrList<Incidence> incidences; 311 Q3PtrList<Incidence> incidences;
310 312
311 Incidence *i; 313 Incidence *i;
312 314
313 QPtrList<Event> e = rawEvents(); 315 Q3PtrList<Event> e = rawEvents();
314 for( i = e.first(); i; i = e.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 316 for( i = e.first(); i; i = e.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
315 317
316 QPtrList<Todo> t = rawTodos(); 318 Q3PtrList<Todo> t = rawTodos();
317 for( i = t.first(); i; i = t.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 319 for( i = t.first(); i; i = t.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
318 320
319 QPtrList<Journal> j = journals(); 321 Q3PtrList<Journal> j = journals();
320 for( i = j.first(); i; i = j.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 322 for( i = j.first(); i; i = j.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
321} 323}
322QPtrList<Incidence> Calendar::rawIncidences() 324Q3PtrList<Incidence> Calendar::rawIncidences()
323{ 325{
324 QPtrList<Incidence> incidences; 326 Q3PtrList<Incidence> incidences;
325 327
326 Incidence *i; 328 Incidence *i;
327 329
328 QPtrList<Event> e = rawEvents(); 330 Q3PtrList<Event> e = rawEvents();
329 for( i = e.first(); i; i = e.next() ) incidences.append( i ); 331 for( i = e.first(); i; i = e.next() ) incidences.append( i );
330 332
331 QPtrList<Todo> t = rawTodos(); 333 Q3PtrList<Todo> t = rawTodos();
332 for( i = t.first(); i; i = t.next() ) incidences.append( i ); 334 for( i = t.first(); i; i = t.next() ) incidences.append( i );
333 335
334 QPtrList<Journal> j = journals(); 336 Q3PtrList<Journal> j = journals();
335 for( i = j.first(); i; i = j.next() ) incidences.append( i ); 337 for( i = j.first(); i; i = j.next() ) incidences.append( i );
336 338
337 return incidences; 339 return incidences;
338} 340}
339 341
340QPtrList<Event> Calendar::events( const QDate &date, bool sorted ) 342Q3PtrList<Event> Calendar::events( const QDate &date, bool sorted )
341{ 343{
342 QPtrList<Event> el = rawEventsForDate(date,sorted); 344 Q3PtrList<Event> el = rawEventsForDate(date,sorted);
343 mFilter->apply(&el); 345 mFilter->apply(&el);
344 return el; 346 return el;
345} 347}
346 348
347QPtrList<Event> Calendar::events( const QDateTime &qdt ) 349Q3PtrList<Event> Calendar::events( const QDateTime &qdt )
348{ 350{
349 QPtrList<Event> el = rawEventsForDate(qdt); 351 Q3PtrList<Event> el = rawEventsForDate(qdt);
350 mFilter->apply(&el); 352 mFilter->apply(&el);
351 return el; 353 return el;
352} 354}
353 355
354QPtrList<Event> Calendar::events( const QDate &start, const QDate &end, 356Q3PtrList<Event> Calendar::events( const QDate &start, const QDate &end,
355 bool inclusive) 357 bool inclusive)
356{ 358{
357 QPtrList<Event> el = rawEvents(start,end,inclusive); 359 Q3PtrList<Event> el = rawEvents(start,end,inclusive);
358 mFilter->apply(&el); 360 mFilter->apply(&el);
359 return el; 361 return el;
360} 362}
361 363
362QPtrList<Event> Calendar::events() 364Q3PtrList<Event> Calendar::events()
363{ 365{
364 QPtrList<Event> el = rawEvents(); 366 Q3PtrList<Event> el = rawEvents();
365 mFilter->apply(&el); 367 mFilter->apply(&el);
366 return el; 368 return el;
367} 369}
368void Calendar::addIncidenceBranch(Incidence *i) 370void Calendar::addIncidenceBranch(Incidence *i)
369{ 371{
370 addIncidence( i ); 372 addIncidence( i );
371 Incidence * inc; 373 Incidence * inc;
372 QPtrList<Incidence> Relations = i->relations(); 374 Q3PtrList<Incidence> Relations = i->relations();
373 for (inc=Relations.first();inc;inc=Relations.next()) { 375 for (inc=Relations.first();inc;inc=Relations.next()) {
374 addIncidenceBranch( inc ); 376 addIncidenceBranch( inc );
375 } 377 }
376} 378}
377 379
378bool Calendar::addIncidence(Incidence *i) 380bool Calendar::addIncidence(Incidence *i)
379{ 381{
380 Incidence::AddVisitor<Calendar> v(this); 382 Incidence::AddVisitor<Calendar> v(this);
381 if ( i->calID() == 0 ) 383 if ( i->calID() == 0 )
382 i->setCalID_block( mDefaultCalendar ); 384 i->setCalID_block( mDefaultCalendar );
383 i->setCalEnabled( true ); 385 i->setCalEnabled( true );
384 return i->accept(v); 386 return i->accept(v);
385} 387}
386void Calendar::deleteIncidence(Incidence *in) 388void Calendar::deleteIncidence(Incidence *in)
387{ 389{
388 if ( in->typeID() == eventID ) 390 if ( in->typeID() == eventID )
389 deleteEvent( (Event*) in ); 391 deleteEvent( (Event*) in );
390 else if ( in->typeID() == todoID ) 392 else if ( in->typeID() == todoID )
391 deleteTodo( (Todo*) in); 393 deleteTodo( (Todo*) in);
392 else if ( in->typeID() == journalID ) 394 else if ( in->typeID() == journalID )
393 deleteJournal( (Journal*) in ); 395 deleteJournal( (Journal*) in );
394} 396}
395 397
396Incidence* Calendar::incidence( const QString& uid ) 398Incidence* Calendar::incidence( const QString& uid )
397{ 399{
398 Incidence* i; 400 Incidence* i;
399 401
400 if( (i = todo( uid )) != 0 ) 402 if( (i = todo( uid )) != 0 )
401 return i; 403 return i;
402 if( (i = event( uid )) != 0 ) 404 if( (i = event( uid )) != 0 )
403 return i; 405 return i;
404 if( (i = journal( uid )) != 0 ) 406 if( (i = journal( uid )) != 0 )
405 return i; 407 return i;
406 408
407 return 0; 409 return 0;
408} 410}
409 411
410QPtrList<Todo> Calendar::todos() 412Q3PtrList<Todo> Calendar::todos()
411{ 413{
412 QPtrList<Todo> tl = rawTodos(); 414 Q3PtrList<Todo> tl = rawTodos();
413 mFilter->apply( &tl ); 415 mFilter->apply( &tl );
414 return tl; 416 return tl;
415} 417}
416 418
417// When this is called, the todo have already been added to the calendar. 419// When this is called, the todo have already been added to the calendar.
418// This method is only about linking related todos 420// This method is only about linking related todos
419void Calendar::setupRelations( Incidence *incidence ) 421void Calendar::setupRelations( Incidence *incidence )
420{ 422{
421 QString uid = incidence->uid(); 423 QString uid = incidence->uid();
422 qDebug("Calendar::setupRelations %s", incidence->summary().latin1()); 424 qDebug("Calendar::setupRelations %s", incidence->summary().latin1());
423 // First, go over the list of orphans and see if this is their parent 425 // First, go over the list of orphans and see if this is their parent
424 while( Incidence* i = mOrphans[ uid ] ) { 426 while( Incidence* i = mOrphans[ uid ] ) {
425 mOrphans.remove( uid ); 427 mOrphans.remove( uid );
426 i->setRelatedTo( incidence ); 428 i->setRelatedTo( incidence );
427 qDebug("Add child %s ti inc %s", i->summary().latin1(),incidence->summary().latin1()); 429 qDebug("Add child %s ti inc %s", i->summary().latin1(),incidence->summary().latin1());
428 incidence->addRelation( i ); 430 incidence->addRelation( i );
429 mOrphanUids.remove( i->uid() ); 431 mOrphanUids.remove( i->uid() );
430 } 432 }
431 433
432 // Now see about this incidences parent 434 // Now see about this incidences parent
433 if( !incidence->relatedTo() && !incidence->relatedToUid().isEmpty() ) { 435 if( !incidence->relatedTo() && !incidence->relatedToUid().isEmpty() ) {
434 // This incidence has a uid it is related to, but is not registered to it yet 436 // This incidence has a uid it is related to, but is not registered to it yet
435 // Try to find it 437 // Try to find it
436 qDebug("Test parent for %s", incidence->summary().latin1()); 438 qDebug("Test parent for %s", incidence->summary().latin1());
437 Incidence* parent = this->incidenceForUid( incidence->relatedToUid(), true ); 439 Incidence* parent = this->incidenceForUid( incidence->relatedToUid(), true );
438 if( parent ) { 440 if( parent ) {
439 // Found it 441 // Found it
440 qDebug("parent found for for %s", incidence->summary().latin1()); 442 qDebug("parent found for for %s", incidence->summary().latin1());
441 incidence->setRelatedTo( parent ); 443 incidence->setRelatedTo( parent );
442 parent->addRelation( incidence ); 444 parent->addRelation( incidence );
443 } else { 445 } else {
444 qDebug("NO parent found for for %s", incidence->summary().latin1()); 446 qDebug("NO parent found for for %s", incidence->summary().latin1());
445 // Not found, put this in the mOrphans list 447 // Not found, put this in the mOrphans list
446 mOrphans.insert( incidence->relatedToUid(), incidence ); 448 mOrphans.insert( incidence->relatedToUid(), incidence );
447 mOrphanUids.insert( incidence->uid(), incidence ); 449 mOrphanUids.insert( incidence->uid(), incidence );
448 } 450 }
449 } 451 }
450} 452}
451 453
452// If a task with subtasks is deleted, move it's subtasks to the orphans list 454// If a task with subtasks is deleted, move it's subtasks to the orphans list
453void Calendar::removeRelations( Incidence *incidence ) 455void Calendar::removeRelations( Incidence *incidence )
454{ 456{
455 // qDebug("Calendar::removeRelations "); 457 // qDebug("Calendar::removeRelations ");
456 QString uid = incidence->uid(); 458 QString uid = incidence->uid();
457 459
458 QPtrList<Incidence> relations = incidence->relations(); 460 Q3PtrList<Incidence> relations = incidence->relations();
459 for( Incidence* i = relations.first(); i; i = relations.next() ) 461 for( Incidence* i = relations.first(); i; i = relations.next() )
460 if( !mOrphanUids.find( i->uid() ) ) { 462 if( !mOrphanUids.find( i->uid() ) ) {
461 mOrphans.insert( uid, i ); 463 mOrphans.insert( uid, i );
462 mOrphanUids.insert( i->uid(), i ); 464 mOrphanUids.insert( i->uid(), i );
463 i->setRelatedTo( 0 ); 465 i->setRelatedTo( 0 );
464 i->setRelatedToUid( uid ); 466 i->setRelatedToUid( uid );
465 } 467 }
466 468
467 // If this incidence is related to something else, tell that about it 469 // If this incidence is related to something else, tell that about it
468 if( incidence->relatedTo() ) 470 if( incidence->relatedTo() )
469 incidence->relatedTo()->removeRelation( incidence ); 471 incidence->relatedTo()->removeRelation( incidence );
470 472
471 // Remove this one from the orphans list 473 // Remove this one from the orphans list
472 if( mOrphanUids.remove( uid ) ) { 474 if( mOrphanUids.remove( uid ) ) {
473 QString r2uid = incidence->relatedToUid(); 475 QString r2uid = incidence->relatedToUid();
474 QPtrList<Incidence> tempList; 476 Q3PtrList<Incidence> tempList;
475 while( Incidence* i = mOrphans[ r2uid ] ) { 477 while( Incidence* i = mOrphans[ r2uid ] ) {
476 mOrphans.remove( r2uid ); 478 mOrphans.remove( r2uid );
477 if ( i != incidence ) tempList.append( i ); 479 if ( i != incidence ) tempList.append( i );
478 } 480 }
479 Incidence* inc = tempList.first(); 481 Incidence* inc = tempList.first();
480 while ( inc ) { 482 while ( inc ) {
481 mOrphans.insert( r2uid, inc ); 483 mOrphans.insert( r2uid, inc );
482 inc = tempList.next(); 484 inc = tempList.next();
483 } 485 }
484 } 486 }
485 // LR: and another big bad bug found 487 // LR: and another big bad bug found
486#if 0 488#if 0
487 // This incidence is located in the orphans list - it should be removed 489 // This incidence is located in the orphans list - it should be removed
488 if( !( incidence->relatedTo() != 0 && mOrphans.remove( incidence->relatedTo()->uid() ) ) ) { 490 if( !( incidence->relatedTo() != 0 && mOrphans.remove( incidence->relatedTo()->uid() ) ) ) {
489 // Removing wasn't that easy 491 // Removing wasn't that easy
490 for( QDictIterator<Incidence> it( mOrphans ); it.current(); ++it ) { 492 for( Q3DictIterator<Incidence> it( mOrphans ); it.current(); ++it ) {
491 if( it.current()->uid() == uid ) { 493 if( it.current()->uid() == uid ) {
492 mOrphans.remove( it.currentKey() ); 494 mOrphans.remove( it.currentKey() );
493 break; 495 break;
494 } 496 }
495 } 497 }
496 } 498 }
497#endif 499#endif
498} 500}
499 501
500void Calendar::registerObserver( Observer *observer ) 502void Calendar::registerObserver( Observer *observer )
501{ 503{
502 mObserver = observer; 504 mObserver = observer;
503 mNewObserver = true; 505 mNewObserver = true;
504} 506}
505 507
506void Calendar::setModified( bool modified ) 508void Calendar::setModified( bool modified )
507{ 509{
508 if ( mObserver ) mObserver->calendarModified( modified, this ); 510 if ( mObserver ) mObserver->calendarModified( modified, this );
509 if ( modified != mModified || mNewObserver ) { 511 if ( modified != mModified || mNewObserver ) {
510 mNewObserver = false; 512 mNewObserver = false;
511 // if ( mObserver ) mObserver->calendarModified( modified, this ); 513 // if ( mObserver ) mObserver->calendarModified( modified, this );
512 mModified = modified; 514 mModified = modified;
513 } 515 }
514} 516}