libkcal

calendarresources.cpp
Go to the documentation of this file.
1/*
2 This file is part of libkcal.
3
4 Copyright (c) 2003 Cornelius Schumacher <schumacher@kde.org>
5 Copyright (C) 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com>
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Library General Public
9 License as published by the Free Software Foundation; either
10 version 2 of the License, or (at your option) any later version.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Library General Public License for more details.
16
17 You should have received a copy of the GNU Library General Public License
18 along with this library; see the file COPYING.LIB. If not, write to
19 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 Boston, MA 02110-1301, USA.
21*/
29#include <stdlib.h>
30
31#include <tqdatetime.h>
32#include <tqstring.h>
33#include <tqptrlist.h>
34
35#include <kdebug.h>
36#include <tdestandarddirs.h>
37#include <tdelocale.h>
38
39#include "vcaldrag.h"
40#include "vcalformat.h"
41#include "icalformat.h"
42#include "exceptions.h"
43#include "incidence.h"
44#include "journal.h"
45#include "filestorage.h"
46
47#include <tderesources/manager.h>
48#include <tderesources/selectdialog.h>
49#include <tdeabc/lock.h>
50
51#include "resourcecalendar.h"
52#include "resourcelocal.h"
53
54#include "calendarresources.h"
55
56using namespace KCal;
57
58
59class CalendarResources::Private {
60 public:
61
62 Private() : mLastUsedResource( 0 ), mBatchAddingInProgress( false )
63 {
64 }
65
66 ResourceCalendar *mLastUsedResource;
67 bool mBatchAddingInProgress;
68};
69
70bool CalendarResources::DestinationPolicy::hasCalendarResources( )
71{
72 CalendarResourceManager::ActiveIterator it;
73 for ( it = resourceManager()->activeBegin();
74 it != resourceManager()->activeEnd(); ++it ) {
75 if ( !(*it)->readOnly() ) {
76 //Insert the first the Standard resource to get be the default selected.
77 if ( resourceManager()->standardResource() == *it ) {
78 return true;
79 } else {
80 return true;
81 }
82 }
83 }
84 return false;
85}
86
88*CalendarResources::StandardDestinationPolicy::destination( Incidence * )
89{
90 return resourceManager()->standardResource();
91}
92
94*CalendarResources::AskDestinationPolicy::destination( Incidence * )
95{
96 TQPtrList<KRES::Resource> list;
97
98 CalendarResourceManager::ActiveIterator it;
99 for ( it = resourceManager()->activeBegin();
100 it != resourceManager()->activeEnd(); ++it ) {
101 if ( !(*it)->readOnly() ) {
102 //Insert the first the Standard resource to get be the default selected.
103 if ( resourceManager()->standardResource() == *it )
104 list.insert( 0, *it );
105 else
106 list.append( *it );
107 }
108 }
109
110 KRES::Resource *r;
111 r = KRES::SelectDialog::getResource( list, parent() );
112 return static_cast<ResourceCalendar *>( r );
113}
114
115CalendarResources::CalendarResources( const TQString &timeZoneId,
116 const TQString &family )
117 : Calendar( timeZoneId ), d( new Private() )
118{
119 init( family );
120}
121
122void CalendarResources::init( const TQString &family )
123{
124 kdDebug(5800) << "CalendarResources::init( " << family << " )" << endl;
125
126 mManager = new CalendarResourceManager( family );
127 mManager->addObserver( this );
128
129 mStandardPolicy = new StandardDestinationPolicy( mManager );
130 mAskPolicy = new AskDestinationPolicy( mManager );
131 mDestinationPolicy = mStandardPolicy;
132 mPendingDeleteFromResourceMap = false;
133
134 connect( this, TQ_SIGNAL(batchAddingBegins()), this, TQ_SLOT(beginAddingIncidences()) );
135 connect( this, TQ_SIGNAL(batchAddingEnds()), this, TQ_SLOT(endAddingIncidences()) );
136}
137
139{
140 close();
141 delete mManager;
142 delete mStandardPolicy;
143 delete mAskPolicy;
144}
145
146void CalendarResources::readConfig( TDEConfig *config )
147{
148 mManager->readConfig( config );
149
150 CalendarResourceManager::Iterator it;
151 for ( it = mManager->begin(); it != mManager->end(); ++it ) {
152 connectResource( *it );
153 }
154}
155
157{
158 kdDebug(5800) << "CalendarResources::load()" << endl;
159
160 if ( !mManager->standardResource() ) {
161 kdDebug(5800) << "Warning! No standard resource yet." << endl;
162 }
163
164 // set the timezone for all resources. Otherwise we'll have those terrible tz
165 // troubles ;-((
166 CalendarResourceManager::Iterator i1;
167 for ( i1 = mManager->begin(); i1 != mManager->end(); ++i1 ) {
168 (*i1)->setTimeZoneId( timeZoneId() );
169 }
170
171 TQValueList<ResourceCalendar *> failed;
172
173 // Open all active resources
174 CalendarResourceManager::ActiveIterator it;
175 for ( it = mManager->activeBegin(); it != mManager->activeEnd(); ++it ) {
176 if ( !(*it)->load() ) {
177 failed.append( *it );
178 }
179 Incidence::List incidences = (*it)->rawIncidences();
180 Incidence::List::Iterator incit;
181 for ( incit = incidences.begin(); incit != incidences.end(); ++incit ) {
182 (*incit)->registerObserver( this );
183 notifyIncidenceAdded( *incit );
184 }
185 }
186
187 TQValueList<ResourceCalendar *>::ConstIterator it2;
188 for ( it2 = failed.begin(); it2 != failed.end(); ++it2 ) {
189 (*it2)->setActive( false );
190 emit signalResourceModified( *it2 );
191 }
192
193 mOpen = true;
194 emit calendarLoaded();
195}
196
197bool CalendarResources::reload( const TQString &tz )
198{
199 save();
200 close();
201 setTimeZoneId( tz );
202 load();
203 return true;
204}
205
207{
208 mDestinationPolicy = mStandardPolicy;
209}
210
212{
213 mDestinationPolicy = mAskPolicy;
214}
215
217{
218 return mDestinationPolicy->parent();
219}
220
222{
223 mDestinationPolicy->setParent( parent );
224}
225
227{
228 kdDebug(5800) << "CalendarResources::close" << endl;
229
230 if ( mOpen ) {
231 CalendarResourceManager::ActiveIterator it;
232 for ( it = mManager->activeBegin(); it != mManager->activeEnd(); ++it ) {
233 (*it)->close();
234 }
235
236 setModified( false );
237 mOpen = false;
238 }
239}
240
242{
243 kdDebug(5800) << "CalendarResources::close" << endl;
244
245 if ( mOpen ) {
246 CalendarResourceManager::ActiveIterator it;
247 for ( it = mManager->activeBegin(); it != mManager->activeEnd(); ++it ) {
248 (*it)->close();
249 }
250
251 setModified( false );
252 mOpen = false;
253 }
254}
255
257{
258 kdDebug(5800) << "CalendarResources::close" << endl;
259
260 if ( mOpen ) {
261 CalendarResourceManager::ActiveIterator it;
262 for ( it = mManager->activeBegin(); it != mManager->activeEnd(); ++it ) {
263 (*it)->close();
264 }
265
266 setModified( false );
267 mOpen = false;
268 }
269}
270
272{
273 kdDebug(5800) << "CalendarResources::close" << endl;
274
275 if ( mOpen ) {
276 CalendarResourceManager::ActiveIterator it;
277 for ( it = mManager->activeBegin(); it != mManager->activeEnd(); ++it ) {
278 (*it)->close();
279 }
280
281 setModified( false );
282 mOpen = false;
283 }
284}
285
287{
288 kdDebug(5800) << "CalendarResources::save()" << endl;
289
290 if ( mOpen && isModified() ) {
291 CalendarResourceManager::ActiveIterator it;
292 for ( it = mManager->activeBegin(); it != mManager->activeEnd(); ++it ) {
293 (*it)->save();
294 }
295
296 setModified( false );
297 }
298}
299
301{
302 CalendarResourceManager::ActiveIterator it;
303 for ( it = mManager->activeBegin(); it != mManager->activeEnd(); ++it ) {
304 if ( (*it)->isSaving() ) {
305 return true;
306 }
307 }
308
309 return false;
310}
311
313 ResourceCalendar *resource,
314 const TQString &subresource )
315{
316 // FIXME: Use proper locking via begin/endChange!
317 bool validRes = false;
318 CalendarResourceManager::ActiveIterator it;
319 for ( it = mManager->activeBegin(); it != mManager->activeEnd(); ++it ) {
320 if ( (*it) == resource )
321 validRes = true;
322 }
323
324 kdDebug(5800)<< "CalendarResources: validRes is " << validRes << endl;
325
326 ResourceCalendar *oldResource = 0;
327 if ( mResourceMap.contains( incidence ) ) {
328 oldResource = mResourceMap[incidence];
329 }
330 mResourceMap[incidence] = resource;
331 if ( validRes && beginChange( incidence, resource, subresource ) &&
332 resource->addIncidence( incidence, subresource ) ) {
333 // mResourceMap[incidence] = resource;
336 setModified( true );
337 endChange( incidence, resource, subresource );
338 return true;
339 } else {
340 if ( oldResource ) {
341 mResourceMap[incidence] = oldResource;
342 } else {
343 mResourceMap.remove( incidence );
344 }
345 }
346
347 return false;
348}
349
351 ResourceCalendar *resource )
352{
353 return addIncidence( incidence, resource, TQString() );
354}
355
357{
358 kdDebug(5800) << "CalendarResources::addIncidence "
359 << incidence->summary()
360 << "; addingInProgress = " << d->mBatchAddingInProgress
361 << "; lastUsedResource = " << d->mLastUsedResource
362 << endl;
363
365
366 ResourceCalendar *resource = d->mLastUsedResource;
367
368 if ( !d->mBatchAddingInProgress || d->mLastUsedResource == 0 ) {
369 resource = mDestinationPolicy->destination( incidence );
370 d->mLastUsedResource = resource;
371
372 if ( resource && d->mBatchAddingInProgress ) {
373 d->mLastUsedResource->beginAddingIncidences();
374 }
375 }
376
377 if ( resource ) {
378 kdDebug(5800) << "CalendarResources:: resource= "
379 << resource->resourceName()
380 << " with id = " << resource->identifier()
381 << " with type = " << resource->type()
382 << endl;
383 mResourceMap[incidence] = resource;
384
385 if ( beginChange( incidence, resource, TQString() ) &&
389
390 mResourceMap[ incidence ] = resource;
391 setModified( true );
392 endChange( incidence, resource, TQString() );
393 return true;
394 } else {
395 if ( resource->exception() ) {
397 }
398
399 // the incidence isn't going to be added, do cleanup:
400 mResourceMap.remove( incidence );
401 d->mLastUsedResource->endAddingIncidences();
402 d->mLastUsedResource = 0;
403 }
404 } else {
406 }
407
408 return false;
409}
410
412{
413 kdDebug(5800) << "CalendarResources::addEvent" << endl;
414 return addIncidence( event );
415}
416
418{
419 return addIncidence( Event, resource, TQString() );
420}
421
423 const TQString &subresource )
424{
425 return addIncidence( Event, resource, subresource );
426}
427
429{
430 kdDebug(5800) << "CalendarResources::deleteEvent" << endl;
431
432 bool status;
433 if ( mResourceMap.find( event ) != mResourceMap.end() ) {
434 status = mResourceMap[event]->deleteEvent( event );
435 if ( status )
436 mPendingDeleteFromResourceMap = true;
437 } else {
438 status = false;
439 CalendarResourceManager::ActiveIterator it;
440 for ( it = mManager->activeBegin(); it != mManager->activeEnd(); ++it ) {
441 status = (*it)->deleteEvent( event ) || status;
442 }
443 }
444
445 if ( status ) {
447 }
448
449 setModified( status );
450 return status;
451}
452
453Event *CalendarResources::event( const TQString &uid )
454{
455 CalendarResourceManager::ActiveIterator it;
456 for ( it = mManager->activeBegin(); it != mManager->activeEnd(); ++it ) {
457 Event* event = (*it)->event( uid );
458 if ( event ) {
459 mResourceMap[event] = *it;
460 return event;
461 }
462 }
463
464 // Not found
465 return 0;
466}
467
469{
470 kdDebug(5800) << "CalendarResources::addTodo" << endl;
471 return addIncidence( todo );
472}
473
475{
476 return addIncidence( todo, resource, TQString() );
477}
478
480 const TQString &subresource )
481{
482 return addIncidence( todo, resource, subresource );
483}
484
486{
487 kdDebug(5800) << "CalendarResources::deleteTodo" << endl;
488
489 bool status;
490 if ( mResourceMap.find( todo ) != mResourceMap.end() ) {
491 status = mResourceMap[todo]->deleteTodo( todo );
492 if ( status )
493 mPendingDeleteFromResourceMap = true;
494 } else {
495 CalendarResourceManager::ActiveIterator it;
496 status = false;
497 for ( it = mManager->activeBegin(); it != mManager->activeEnd(); ++it ) {
498 status = (*it)->deleteTodo( todo ) || status;
499 }
500 }
501
502 setModified( status );
503 return status;
504}
505
507 SortDirection sortDirection )
508{
509 Todo::List result;
510
511 CalendarResourceManager::ActiveIterator it;
512 for ( it = mManager->activeBegin(); it != mManager->activeEnd(); ++it ) {
513 Todo::List todos = (*it)->rawTodos( TodoSortUnsorted );
514 Todo::List::ConstIterator it2;
515 for ( it2 = todos.begin(); it2 != todos.end(); ++it2 ) {
516 result.append( *it2 );
517 mResourceMap[ *it2 ] = *it;
518 }
519 }
520 return sortTodos( &result, sortField, sortDirection );
521}
522
523Todo *CalendarResources::todo( const TQString &uid )
524{
525 kdDebug(5800) << "CalendarResources::todo(uid)" << endl;
526
527 CalendarResourceManager::ActiveIterator it;
528 for ( it = mManager->activeBegin(); it != mManager->activeEnd(); ++it ) {
529 Todo *todo = (*it)->todo( uid );
530 if ( todo ) {
531 mResourceMap[todo] = *it;
532 return todo;
533 }
534 }
535
536 // Not found
537 return 0;
538}
539
541{
542 Todo::List result;
543
544 CalendarResourceManager::ActiveIterator it;
545 for ( it = mManager->activeBegin(); it != mManager->activeEnd(); ++it ) {
546 Todo::List todos = (*it)->rawTodosForDate( date );
547 Todo::List::ConstIterator it2;
548 for ( it2 = todos.begin(); it2 != todos.end(); ++it2 ) {
549 result.append( *it2 );
550 mResourceMap[ *it2 ] = *it;
551 }
552 }
553
554 return result;
555}
556
558{
559 kdDebug(5800) << "CalendarResources::alarmsTo" << endl;
560
561 Alarm::List result;
562 CalendarResourceManager::ActiveIterator resit;
563 for ( resit = mManager->activeBegin(); resit != mManager->activeEnd(); ++resit ) {
564 Alarm::List list = (*resit)->alarmsTo( to );
565 Alarm::List::Iterator alarmit;
566 for ( alarmit = list.begin(); alarmit != list.end(); ++alarmit )
567 result.append( *alarmit );
568 }
569 return result;
570}
571
573 const TQDateTime &to )
574{
575 Alarm::List result;
576 CalendarResourceManager::ActiveIterator resit;
577 for ( resit = mManager->activeBegin(); resit != mManager->activeEnd(); ++resit ) {
578 Alarm::List list = (*resit)->alarms( from, to );
579 Alarm::List::Iterator alarmit;
580 for ( alarmit = list.begin(); alarmit != list.end(); ++alarmit )
581 result.append( *alarmit );
582 }
583 return result;
584}
585
586bool CalendarResources::hasCalendarResources()
587{
588 return mDestinationPolicy->hasCalendarResources();
589}
590
591/****************************** PROTECTED METHODS ****************************/
592
594 EventSortField sortField,
595 SortDirection sortDirection )
596{
597 Event::List result;
598 CalendarResourceManager::ActiveIterator it;
599 for ( it = mManager->activeBegin(); it != mManager->activeEnd(); ++it ) {
600 Event::List list = (*it)->rawEventsForDate( date );
601 Event::List::ConstIterator it2;
602 for ( it2 = list.begin(); it2 != list.end(); ++it2 ) {
603 result.append( *it2 );
604 mResourceMap[ *it2 ] = *it;
605 }
606 }
607 return sortEventsForDate( &result, date, sortField, sortDirection );
608}
609
610Event::List CalendarResources::rawEvents( const TQDate &start, const TQDate &end,
611 bool inclusive )
612{
613 kdDebug(5800) << "CalendarResources::rawEvents(start,end,inclusive)" << endl;
614
615 Event::List result;
616 CalendarResourceManager::ActiveIterator it;
617 for ( it = mManager->activeBegin(); it != mManager->activeEnd(); ++it ) {
618 Event::List list = (*it)->rawEvents( start, end, inclusive );
619 Event::List::ConstIterator it2;
620 for ( it2 = list.begin(); it2 != list.end(); ++it2 ) {
621 result.append( *it2 );
622 mResourceMap[ *it2 ] = *it;
623 }
624 }
625 return result;
626}
627
629{
630 kdDebug(5800) << "CalendarResources::rawEventsForDate(qdt)" << endl;
631
632 // @TODO: Remove the code duplication by the resourcemap iteration block.
633 Event::List result;
634 CalendarResourceManager::ActiveIterator it;
635 for ( it = mManager->activeBegin(); it != mManager->activeEnd(); ++it ) {
636 Event::List list = (*it)->rawEventsForDate( qdt );
637 Event::List::ConstIterator it2;
638 for ( it2 = list.begin(); it2 != list.end(); ++it2 ) {
639 result.append( *it2 );
640 mResourceMap[ *it2 ] = *it;
641 }
642 }
643 return result;
644}
645
647 SortDirection sortDirection )
648{
649 kdDebug(5800) << "CalendarResources::rawEvents()" << endl;
650
651 Event::List result;
652 CalendarResourceManager::ActiveIterator it;
653 for ( it = mManager->activeBegin(); it != mManager->activeEnd(); ++it ) {
654 Event::List list = (*it)->rawEvents( EventSortUnsorted );
655 Event::List::ConstIterator it2;
656 for ( it2 = list.begin(); it2 != list.end(); ++it2 ) {
657 result.append( *it2 );
658 mResourceMap[ *it2 ] = *it;
659 }
660 }
661 return sortEvents( &result, sortField, sortDirection );
662}
663
664
666{
667 kdDebug(5800) << "CalendarResources::addJournal" << endl;
668 return addIncidence( journal );
669}
670
672{
673 return addIncidence( journal, resource, TQString() );
674}
675
676
678 const TQString &subresource )
679{
680 return addIncidence( journal, resource, subresource );
681}
682
683
685{
686 kdDebug(5800) << "CalendarResources::deleteJournal" << endl;
687
688 bool status;
689 if ( mResourceMap.find( journal ) != mResourceMap.end() ) {
690 status = mResourceMap[journal]->deleteJournal( journal );
691 if ( status )
692 mPendingDeleteFromResourceMap = true;
693 } else {
694 CalendarResourceManager::ActiveIterator it;
695 status = false;
696 for ( it = mManager->activeBegin(); it != mManager->activeEnd(); ++it ) {
697 status = (*it)->deleteJournal( journal ) || status;
698 }
699 }
700
701 setModified( status );
702 return status;
703}
704
705Journal *CalendarResources::journal( const TQString &uid )
706{
707 kdDebug(5800) << "CalendarResources::journal(uid)" << endl;
708
709 CalendarResourceManager::ActiveIterator it;
710 for ( it = mManager->activeBegin(); it != mManager->activeEnd(); ++it ) {
711 Journal* journal = (*it)->journal( uid );
712 if ( journal ) {
713 mResourceMap[journal] = *it;
714 return journal;
715 }
716 }
717
718 // Not found
719 return 0;
720}
721
723 SortDirection sortDirection )
724{
725 kdDebug(5800) << "CalendarResources::rawJournals()" << endl;
726
727 Journal::List result;
728 CalendarResourceManager::ActiveIterator it;
729 for ( it = mManager->activeBegin(); it != mManager->activeEnd(); ++it ) {
730 Journal::List journals = (*it)->rawJournals( JournalSortUnsorted );
731 Journal::List::ConstIterator it2;
732 for ( it2 = journals.begin(); it2 != journals.end(); ++it2 ) {
733 result.append( *it2 );
734 mResourceMap[ *it2 ] = *it;
735 }
736 }
737 return sortJournals( &result, sortField, sortDirection );
738}
739
741{
742
743 Journal::List result;
744
745 CalendarResourceManager::ActiveIterator it;
746 for ( it = mManager->activeBegin(); it != mManager->activeEnd(); ++it ) {
747 Journal::List journals = (*it)->rawJournalsForDate( date );
748 Journal::List::ConstIterator it2;
749 for ( it2 = journals.begin(); it2 != journals.end(); ++it2 ) {
750 result.append( *it2 );
751 mResourceMap[ *it2 ] = *it;
752 }
753 }
754 return result;
755}
756
757void CalendarResources::connectResource( ResourceCalendar *resource )
758{
759 connect( resource, TQ_SIGNAL( resourceChanged( ResourceCalendar * ) ),
760 TQ_SIGNAL( calendarChanged() ) );
761 connect( resource, TQ_SIGNAL( resourceSaved( ResourceCalendar * ) ),
762 TQ_SIGNAL( calendarSaved() ) );
763
764 connect( resource, TQ_SIGNAL( resourceLoadError( ResourceCalendar *,
765 const TQString & ) ),
766 TQ_SLOT( slotLoadError( ResourceCalendar *, const TQString & ) ) );
767 connect( resource, TQ_SIGNAL( resourceSaveError( ResourceCalendar *,
768 const TQString & ) ),
769 TQ_SLOT( slotSaveError( ResourceCalendar *, const TQString & ) ) );
770}
771
773{
774 if ( mResourceMap.find( incidence ) != mResourceMap.end() ) {
775 return mResourceMap[ incidence ];
776 }
777 return 0;
778}
779
781{
782 kdDebug(5800) << "Resource added: " << resource->resourceName() << endl;
783
784 if ( !resource->isActive() )
785 return;
786
787 if ( resource->open() ) {
788 resource->load();
789 }
790
791 connectResource( resource );
792
794}
795
796void CalendarResources::resourceModified( ResourceCalendar *resource )
797{
798 kdDebug(5800) << "Resource modified: " << resource->resourceName() << endl;
799
801}
802
803void CalendarResources::resourceDeleted( ResourceCalendar *resource )
804{
805 kdDebug(5800) << "Resource deleted: " << resource->resourceName() << endl;
806
808}
809
810void CalendarResources::doSetTimeZoneId( const TQString &timeZoneId )
811{
812 // set the timezone for all resources. Otherwise we'll have those terrible
813 // tz troubles ;-((
814 CalendarResourceManager::Iterator i1;
815 for ( i1 = mManager->begin(); i1 != mManager->end(); ++i1 ) {
816 (*i1)->setTimeZoneId( timeZoneId );
817 }
818}
819
820void CalendarResources::setTimeZoneIdViewOnly( const TQString &timeZoneId )
821{
823}
824
825CalendarResources::Ticket
827{
828 kdDebug(5800) << "CalendarResources::requestSaveTicket()" << endl;
829
830 TDEABC::Lock *lock = resource->lock();
831 if ( !lock )
832 return 0;
833 if ( lock->lock() )
834 return new Ticket( resource );
835 else
836 return 0;
837}
838
839bool CalendarResources::save( Ticket *ticket, Incidence *incidence )
840{
841 kdDebug(5800) << "CalendarResources::save( Ticket *)" << endl;
842
843 if ( !ticket || !ticket->resource() )
844 return false;
845
846 kdDebug(5800) << "tick " << ticket->resource()->resourceName() << endl;
847
848 // @TODO: Check if the resource was changed at all. If not, don't save.
849 if ( ticket->resource()->save( incidence ) ) {
850 releaseSaveTicket( ticket );
851 return true;
852 }
853
854 return false;
855}
856
858{
859 ticket->resource()->lock()->unlock();
860 delete ticket;
861}
862
864{
865 return beginChange( incidence, 0, TQString() );
866}
867
869 ResourceCalendar *res,
870 const TQString &subres )
871{
872 Q_UNUSED( subres ); // possible future use
873
874 kdDebug(5800) << "CalendarResources::beginChange()" << endl;
875
876 if ( !res ) {
877 res = resource( incidence );
878 }
879 if ( !res ) {
880 res = mDestinationPolicy->destination( incidence );
881 if ( !res ) {
882 kdError() << "Unable to get destination resource." << endl;
883 return false;
884 }
885 mResourceMap[ incidence ] = res;
886 }
887 mPendingDeleteFromResourceMap = false;
888
889 int count = incrementChangeCount( res );
890 if ( count == 1 ) {
891 Ticket *ticket = requestSaveTicket( res );
892 if ( !ticket ) {
893 kdDebug(5800) << "CalendarResources::beginChange(): unable to get ticket."
894 << endl;
896 return false;
897 } else {
898 mTickets[ res ] = ticket;
899 }
900 }
901
902 return true;
903}
904
906{
907 return endChange( incidence, 0, TQString() );
908}
909
911 ResourceCalendar *res,
912 const TQString &subres )
913{
914 Q_UNUSED( subres ); // possible future use
915
916 kdDebug(5800) << "CalendarResource::endChange()" << endl;
917
918 if ( !res ) {
919 res = resource( incidence );
920 }
921 if ( !res )
922 return false;
923
924 int count = decrementChangeCount( res );
925
926 if ( mPendingDeleteFromResourceMap ) {
927 mResourceMap.remove( incidence );
928 mPendingDeleteFromResourceMap = false;
929 }
930
931 if ( count == 0 ) {
932 bool ok = save( mTickets[ res ], incidence );
933 if ( ok ) {
934 mTickets.remove( res );
935 } else {
936 return false;
937 }
938 }
939
940 return true;
941}
942
944{
945 kdDebug(5800) << "CalendarResources: beginAddingIncidences() " << endl;
946 d->mBatchAddingInProgress = true;
947}
948
950{
951 kdDebug(5800) << "CalendarResources: endAddingIncidences() " << endl;
952 d->mBatchAddingInProgress = false;
953
954 if ( d->mLastUsedResource ) {
955 d->mLastUsedResource->endAddingIncidences();
956 }
957
958 d->mLastUsedResource = 0;
959}
960
962{
963 if ( !mChangeCounts.contains( r ) ) {
964 mChangeCounts.insert( r, 0 );
965 }
966
967 int count = mChangeCounts[ r ];
968 ++count;
969 mChangeCounts[ r ] = count;
970
971 return count;
972}
973
975{
976 if ( !mChangeCounts.contains( r ) ) {
977 kdError() << "No change count for resource." << endl;
978 return 0;
979 }
980
981 int count = mChangeCounts[ r ];
982 --count;
983 if ( count < 0 ) {
984 kdError() << "Can't decrement change count. It already is 0." << endl;
985 count = 0;
986 }
987 mChangeCounts[ r ] = count;
988
989 return count;
990}
991
992void CalendarResources::slotLoadError( ResourceCalendar *, const TQString &err )
993{
994 emit signalErrorMessage( err );
995}
996
997void CalendarResources::slotSaveError( ResourceCalendar *, const TQString &err )
998{
999 emit signalErrorMessage( err );
1000}
1001
1002#include "calendarresources.moc"
Provides a Calendar composed of several Calendar Resources.
virtual void doSetTimeZoneId(const TQString &timeZoneId)
Let CalendarResource subclasses set the Time Zone ID.
int incrementChangeCount(ResourceCalendar *resource)
Increment the number of times this Resource has been changed by 1.
void setTimeZoneIdViewOnly(const TQString &tz)
Set the viewing time zone, which requires that all resources are saved, and then reloaded such that t...
bool deleteJournal(Journal *journal)
Remove a Journal from the Calendar.
Event * event(const TQString &uid)
Returns the Event associated with the given unique identifier.
ResourceCalendar * resource(Incidence *incidence)
Get the Resource associated with a specified Incidence.
void setDialogParentWidget(TQWidget *parent)
Set the widget parent for new dialogs.
void closeEvents()
Clear out the current Calendar, freeing all used memory etc.
Todo * todo(const TQString &uid)
Returns the Todo associated with the given unique identifier.
bool addTodo(Todo *todo)
Insert a Todo into a Calendar Resource.
void closeTodos()
Clear out the current Calendar, freeing all used memory etc.
void signalResourceModified(ResourceCalendar *resource)
Signal that the Resource has been modified.
void signalErrorMessage(const TQString &err)
Signal an error message.
void closeJournals()
Clear out the current Calendar, freeing all used memory etc.
void signalResourceDeleted(ResourceCalendar *resource)
Signal that an Incidence has been removed from the Resource.
Journal * journal(const TQString &uid)
Returns the Journal associated with the given unique identifier.
Journal::List rawJournals(JournalSortField sortField=JournalSortUnsorted, SortDirection sortDirection=SortDirectionAscending)
Return a sorted, unfiltered list of all Journals for this Calendar.
bool addEvent(Event *event)
Insert an Event into the Calendar.
int decrementChangeCount(ResourceCalendar *resource)
Decrement the number of times this Resource has been changed by 1.
void setStandardDestinationPolicy()
Set the destination policy such that Incidences are always added to the standard Resource.
void close()
Clear out the current Calendar, freeing all used memory etc.
bool addIncidence(Incidence *incidence)
Insert an Incidence into the Calendar.
Todo::List rawTodos(TodoSortField sortField=TodoSortUnsorted, SortDirection sortDirection=SortDirectionAscending)
Return a sorted, unfiltered list of all Todos for this Calendar.
void load()
Loads all Incidences from the Resources.
void beginAddingIncidences()
All addIncidence( Incidence * ), addTodo( Todo * ) addEvent( Event * ) and addJournal( Journal * ) ca...
bool addJournal(Journal *journal)
Insert a Journal into the Calendar.
Ticket * requestSaveTicket(ResourceCalendar *resource)
Request ticket for saving the Calendar.
TDE_DEPRECATED bool beginChange(Incidence *incidence)
Flag that a change to a Calendar Incidence is starting.
bool deleteEvent(Event *event)
Remove an Event from the Calendar.
TQWidget * dialogParentWidget()
Returns the current parent for new dialogs.
void resourceAdded(ResourceCalendar *resource)
Add a Resource to the Calendar.
Event::List rawEvents(EventSortField sortField=EventSortUnsorted, SortDirection sortDirection=SortDirectionAscending)
Return a sorted, unfiltered list of all Events.
Todo::List rawTodosForDate(const TQDate &date)
Return an unfiltered list of all Todos which are due on the specified date.
Alarm::List alarms(const TQDateTime &from, const TQDateTime &to)
Return a list of Alarms within a time range for this Calendar.
Alarm::List alarmsTo(const TQDateTime &to)
Return a list of Alarms that occur before the specified timestamp.
Journal::List rawJournalsForDate(const TQDate &date)
Return an unfiltered list of all Journals for on the specifed date.
void save()
Sync changes in memory to persistant storage.
bool reload(const TQString &tz)
Reloads all incidences from all resources.
bool isSaving()
Determine if the Calendar is currently being saved.
void setAskDestinationPolicy()
Set the destination policy such that Incidences are added to a Resource which is queried.
virtual void releaseSaveTicket(Ticket *ticket)
Release the save Ticket.
Event::List rawEventsForDate(const TQDateTime &qdt)
Return an unfiltered list of all Events which occur on the given timestamp.
bool deleteTodo(Todo *todo)
Remove an Todo from the Calendar.
TDE_DEPRECATED bool endChange(Incidence *incidence)
Flag that a change to a Calendar Incidence has completed.
void readConfig(TDEConfig *config=0)
Read the Resources settings from a config file.
void signalResourceAdded(ResourceCalendar *resource)
Signal that an Incidence has been inserted to the Resource.
This is the main "calendar" object class.
Definition: calendar.h:171
void clearException()
Clears the exception status.
Definition: calendar.cpp:74
static Todo::List sortTodos(Todo::List *todoList, TodoSortField sortField, SortDirection sortDirection)
Sort a list of Todos.
Definition: calendar.cpp:611
void calendarLoaded()
Signal that the Calendar has been loaded into memory.
void setTimeZoneId(const TQString &timeZoneId)
Set the Time Zone Id for the Calendar.
Definition: calendar.cpp:103
bool isModified() const
Determine the Calendar's modification status.
Definition: calendar.h:294
virtual Incidence::List incidences()
Return a filtered list of all Incidences for this Calendar.
Definition: calendar.cpp:178
void calendarSaved()
Signal that the Calendar has been saved.
void notifyIncidenceDeleted(Incidence *incidence)
Let Calendar subclasses notify that they removed an Incidence.
Definition: calendar.cpp:1001
static Event::List sortEvents(Event::List *eventList, EventSortField sortField, SortDirection sortDirection)
Sort a list of Events.
Definition: calendar.cpp:188
void setModified(bool modified)
Set if the Calendar had been modified.
Definition: calendar.cpp:950
static Event::List sortEventsForDate(Event::List *eventList, const TQDate &date, EventSortField sortField, SortDirection sortDirection)
Sort a list of Events that occur on a specified date.
Definition: calendar.cpp:291
void calendarChanged()
Signal that the Calendar has been modified.
TQString timeZoneId() const
Get the Time Zone ID for the Calendar.
Definition: calendar.cpp:112
void setException(ErrorFormat *e)
Sets information about the last error occurred.
Definition: calendar.cpp:85
void notifyIncidenceAdded(Incidence *incidence)
Let Calendar subclasses notify that they inserted an Incidence.
Definition: calendar.cpp:977
virtual Journal::List journals(JournalSortField sortField=JournalSortUnsorted, SortDirection sortDirection=SortDirectionAscending)
Return a sorted, filtered list of all Journals for this Calendar.
Definition: calendar.cpp:823
void batchAddingEnds()
void batchAddingBegins()
Incidence * incidence(const TQString &uid)
Returns the Incidence associated with the given unique identifier.
Definition: calendar.cpp:576
virtual Todo::List todos(TodoSortField sortField=TodoSortUnsorted, SortDirection sortDirection=SortDirectionAscending)
Return a sorted, filtered list of all Todos for this Calendar.
Definition: calendar.cpp:755
static Journal::List sortJournals(Journal::List *journalList, JournalSortField sortField, SortDirection sortDirection)
Sort a list of Journals.
Definition: calendar.cpp:770
Calendar format related error class.
Definition: exceptions.h:65
@ UserCancel
User canceled the operation.
Definition: exceptions.h:81
ErrorCodeFormat errorCode()
Return format error code.
Definition: exceptions.cpp:101
This class provides an Event in the sense of RFC2445.
Definition: event.h:33
void registerObserver(Observer *)
Register observer.
This class provides the base class common to all calendar components.
Definition: incidence.h:48
TQString summary() const
Return short summary.
Definition: incidence.cpp:293
This class provides a Journal in the sense of RFC2445.
Definition: journal.h:34
This class provides the interfaces for a calendar resource.
bool load()
Load resource data.
virtual TDE_DEPRECATED bool addIncidence(Incidence *)
Add incidence to resource.
ErrorFormat * exception()
Returns an exception, if there is any, containing information about the last error that occurred.
virtual TDEABC::Lock * lock()=0
Return object for locking the resource.
This class provides a Todo in the sense of RFC2445.
Definition: todo.h:32
Namespace KCal is for global classes, objects and/or functions in libkcal.
Definition: alarm.h:38
TodoSortField
How Todos are to be sorted.
Definition: calendar.h:91
@ TodoSortUnsorted
Todos are to be unsorted.
Definition: calendar.h:93
JournalSortField
How Journals are to be sorted.
Definition: calendar.h:111
@ JournalSortUnsorted
Journals are to be unsorted.
Definition: calendar.h:113
EventSortField
How Events are to be sorted.
Definition: calendar.h:75
@ EventSortUnsorted
Events are to be unsorted.
Definition: calendar.h:77
SortDirection
Sort direction.
Definition: calendar.h:63