31 #include <tqdatetime.h> 33 #include <tqptrlist.h> 36 #include <kstandarddirs.h> 37 #include <tdelocale.h> 40 #include "vcalformat.h" 41 #include "icalformat.h" 42 #include "exceptions.h" 43 #include "incidence.h" 45 #include "filestorage.h" 47 #include <tderesources/manager.h> 48 #include <tderesources/selectdialog.h> 49 #include <tdeabc/lock.h> 51 #include "resourcecalendar.h" 52 #include "resourcelocal.h" 59 class CalendarResources::Private {
62 Private() : mLastUsedResource( 0 ), mBatchAddingInProgress( false )
67 bool mBatchAddingInProgress;
70 bool CalendarResources::DestinationPolicy::hasCalendarResources( )
72 CalendarResourceManager::ActiveIterator it;
75 if ( !(*it)->readOnly() ) {
88 *CalendarResources::StandardDestinationPolicy::destination(
Incidence * )
94 *CalendarResources::AskDestinationPolicy::destination(
Incidence * )
96 TQPtrList<KRES::Resource> list;
98 CalendarResourceManager::ActiveIterator it;
101 if ( !(*it)->readOnly() ) {
104 list.insert( 0, *it );
111 r = KRES::SelectDialog::getResource( list, parent() );
116 const TQString &family )
117 :
Calendar( timeZoneId ), d( new Private() )
122 void CalendarResources::init(
const TQString &family )
124 kdDebug(5800) <<
"CalendarResources::init( " << family <<
" )" << endl;
126 mManager =
new CalendarResourceManager( family );
127 mManager->addObserver(
this );
129 mStandardPolicy =
new StandardDestinationPolicy( mManager );
130 mAskPolicy =
new AskDestinationPolicy( mManager );
131 mDestinationPolicy = mStandardPolicy;
132 mPendingDeleteFromResourceMap =
false;
142 delete mStandardPolicy;
148 mManager->readConfig( config );
150 CalendarResourceManager::Iterator it;
151 for ( it = mManager->begin(); it != mManager->end(); ++it ) {
152 connectResource( *it );
158 kdDebug(5800) <<
"CalendarResources::load()" << endl;
160 if ( !mManager->standardResource() ) {
161 kdDebug(5800) <<
"Warning! No standard resource yet." << endl;
166 CalendarResourceManager::Iterator i1;
167 for ( i1 = mManager->begin(); i1 != mManager->end(); ++i1 ) {
171 TQValueList<ResourceCalendar *> failed;
174 CalendarResourceManager::ActiveIterator it;
175 for ( it = mManager->activeBegin(); it != mManager->activeEnd(); ++it ) {
176 if ( !(*it)->load() ) {
177 failed.append( *it );
180 Incidence::List::Iterator incit;
181 for ( incit = incidences.begin(); incit != incidences.end(); ++incit ) {
182 (*incit)->registerObserver(
this );
187 TQValueList<ResourceCalendar *>::ConstIterator it2;
188 for ( it2 = failed.begin(); it2 != failed.end(); ++it2 ) {
189 (*it2)->setActive(
false );
208 mDestinationPolicy = mStandardPolicy;
213 mDestinationPolicy = mAskPolicy;
218 return mDestinationPolicy->parent();
223 mDestinationPolicy->setParent( parent );
228 kdDebug(5800) <<
"CalendarResources::close" << endl;
231 CalendarResourceManager::ActiveIterator it;
232 for ( it = mManager->activeBegin(); it != mManager->activeEnd(); ++it ) {
243 kdDebug(5800) <<
"CalendarResources::close" << endl;
246 CalendarResourceManager::ActiveIterator it;
247 for ( it = mManager->activeBegin(); it != mManager->activeEnd(); ++it ) {
258 kdDebug(5800) <<
"CalendarResources::close" << endl;
261 CalendarResourceManager::ActiveIterator it;
262 for ( it = mManager->activeBegin(); it != mManager->activeEnd(); ++it ) {
273 kdDebug(5800) <<
"CalendarResources::close" << endl;
276 CalendarResourceManager::ActiveIterator it;
277 for ( it = mManager->activeBegin(); it != mManager->activeEnd(); ++it ) {
288 kdDebug(5800) <<
"CalendarResources::save()" << endl;
291 CalendarResourceManager::ActiveIterator it;
292 for ( it = mManager->activeBegin(); it != mManager->activeEnd(); ++it ) {
302 CalendarResourceManager::ActiveIterator it;
303 for ( it = mManager->activeBegin(); it != mManager->activeEnd(); ++it ) {
304 if ( (*it)->isSaving() ) {
314 const TQString &subresource )
317 bool validRes =
false;
318 CalendarResourceManager::ActiveIterator it;
319 for ( it = mManager->activeBegin(); it != mManager->activeEnd(); ++it ) {
324 kdDebug(5800)<<
"CalendarResources: validRes is " << validRes << endl;
327 if ( mResourceMap.contains( incidence ) ) {
331 if ( validRes &&
beginChange( incidence, resource, subresource ) &&
337 endChange( incidence, resource, subresource );
343 mResourceMap.remove( incidence );
358 kdDebug(5800) <<
"CalendarResources::addIncidence " 360 <<
"; addingInProgress = " << d->mBatchAddingInProgress
361 <<
"; lastUsedResource = " << d->mLastUsedResource
368 if ( !d->mBatchAddingInProgress || d->mLastUsedResource == 0 ) {
369 resource = mDestinationPolicy->destination( incidence );
372 if ( resource && d->mBatchAddingInProgress ) {
373 d->mLastUsedResource->beginAddingIncidences();
378 kdDebug(5800) <<
"CalendarResources:: resource= " 379 << resource->resourceName()
380 <<
" with id = " << resource->identifier()
381 <<
" with type = " << resource->type()
385 if (
beginChange( incidence, resource, TQString() ) &&
392 endChange( incidence, resource, TQString() );
400 mResourceMap.remove( incidence );
401 d->mLastUsedResource->endAddingIncidences();
402 d->mLastUsedResource = 0;
413 kdDebug(5800) <<
"CalendarResources::addEvent" << endl;
423 const TQString &subresource )
430 kdDebug(5800) <<
"CalendarResources::deleteEvent" << endl;
433 if ( mResourceMap.find( event ) != mResourceMap.end() ) {
434 status = mResourceMap[
event]->deleteEvent( event );
436 mPendingDeleteFromResourceMap =
true;
439 CalendarResourceManager::ActiveIterator it;
440 for ( it = mManager->activeBegin(); it != mManager->activeEnd(); ++it ) {
441 status = (*it)->deleteEvent( event ) || status;
455 CalendarResourceManager::ActiveIterator it;
456 for ( it = mManager->activeBegin(); it != mManager->activeEnd(); ++it ) {
457 Event*
event = (*it)->event( uid );
459 mResourceMap[
event] = *it;
470 kdDebug(5800) <<
"CalendarResources::addTodo" << endl;
480 const TQString &subresource )
487 kdDebug(5800) <<
"CalendarResources::deleteTodo" << endl;
490 if ( mResourceMap.find( todo ) != mResourceMap.end() ) {
491 status = mResourceMap[
todo]->deleteTodo( todo );
493 mPendingDeleteFromResourceMap =
true;
495 CalendarResourceManager::ActiveIterator it;
497 for ( it = mManager->activeBegin(); it != mManager->activeEnd(); ++it ) {
498 status = (*it)->deleteTodo( todo ) || status;
511 CalendarResourceManager::ActiveIterator it;
512 for ( it = mManager->activeBegin(); it != mManager->activeEnd(); ++it ) {
514 Todo::List::ConstIterator it2;
515 for ( it2 = todos.begin(); it2 != todos.end(); ++it2 ) {
516 result.append( *it2 );
517 mResourceMap[ *it2 ] = *it;
520 return sortTodos( &result, sortField, sortDirection );
525 kdDebug(5800) <<
"CalendarResources::todo(uid)" << endl;
527 CalendarResourceManager::ActiveIterator it;
528 for ( it = mManager->activeBegin(); it != mManager->activeEnd(); ++it ) {
531 mResourceMap[
todo] = *it;
544 CalendarResourceManager::ActiveIterator it;
545 for ( it = mManager->activeBegin(); it != mManager->activeEnd(); ++it ) {
547 Todo::List::ConstIterator it2;
548 for ( it2 = todos.begin(); it2 != todos.end(); ++it2 ) {
549 result.append( *it2 );
550 mResourceMap[ *it2 ] = *it;
559 kdDebug(5800) <<
"CalendarResources::alarmsTo" << endl;
562 CalendarResourceManager::ActiveIterator resit;
563 for ( resit = mManager->activeBegin(); resit != mManager->activeEnd(); ++resit ) {
565 Alarm::List::Iterator alarmit;
566 for ( alarmit = list.begin(); alarmit != list.end(); ++alarmit )
567 result.append( *alarmit );
573 const TQDateTime &to )
576 CalendarResourceManager::ActiveIterator resit;
577 for ( resit = mManager->activeBegin(); resit != mManager->activeEnd(); ++resit ) {
579 Alarm::List::Iterator alarmit;
580 for ( alarmit = list.begin(); alarmit != list.end(); ++alarmit )
581 result.append( *alarmit );
586 bool CalendarResources::hasCalendarResources()
588 return mDestinationPolicy->hasCalendarResources();
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;
613 kdDebug(5800) <<
"CalendarResources::rawEvents(start,end,inclusive)" << endl;
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;
630 kdDebug(5800) <<
"CalendarResources::rawEventsForDate(qdt)" << endl;
634 CalendarResourceManager::ActiveIterator it;
635 for ( it = mManager->activeBegin(); it != mManager->activeEnd(); ++it ) {
637 Event::List::ConstIterator it2;
638 for ( it2 = list.begin(); it2 != list.end(); ++it2 ) {
639 result.append( *it2 );
640 mResourceMap[ *it2 ] = *it;
649 kdDebug(5800) <<
"CalendarResources::rawEvents()" << endl;
652 CalendarResourceManager::ActiveIterator it;
653 for ( it = mManager->activeBegin(); it != mManager->activeEnd(); ++it ) {
655 Event::List::ConstIterator it2;
656 for ( it2 = list.begin(); it2 != list.end(); ++it2 ) {
657 result.append( *it2 );
658 mResourceMap[ *it2 ] = *it;
661 return sortEvents( &result, sortField, sortDirection );
667 kdDebug(5800) <<
"CalendarResources::addJournal" << endl;
678 const TQString &subresource )
686 kdDebug(5800) <<
"CalendarResources::deleteJournal" << endl;
689 if ( mResourceMap.find( journal ) != mResourceMap.end() ) {
690 status = mResourceMap[
journal]->deleteJournal( journal );
692 mPendingDeleteFromResourceMap =
true;
694 CalendarResourceManager::ActiveIterator it;
696 for ( it = mManager->activeBegin(); it != mManager->activeEnd(); ++it ) {
697 status = (*it)->deleteJournal( journal ) || status;
707 kdDebug(5800) <<
"CalendarResources::journal(uid)" << endl;
709 CalendarResourceManager::ActiveIterator it;
710 for ( it = mManager->activeBegin(); it != mManager->activeEnd(); ++it ) {
725 kdDebug(5800) <<
"CalendarResources::rawJournals()" << endl;
728 CalendarResourceManager::ActiveIterator it;
729 for ( it = mManager->activeBegin(); it != mManager->activeEnd(); ++it ) {
731 Journal::List::ConstIterator it2;
732 for ( it2 = journals.begin(); it2 != journals.end(); ++it2 ) {
733 result.append( *it2 );
734 mResourceMap[ *it2 ] = *it;
737 return sortJournals( &result, sortField, sortDirection );
745 CalendarResourceManager::ActiveIterator it;
746 for ( it = mManager->activeBegin(); it != mManager->activeEnd(); ++it ) {
748 Journal::List::ConstIterator it2;
749 for ( it2 = journals.begin(); it2 != journals.end(); ++it2 ) {
750 result.append( *it2 );
751 mResourceMap[ *it2 ] = *it;
765 const TQString & ) ),
768 const TQString & ) ),
774 if ( mResourceMap.find( incidence ) != mResourceMap.end() ) {
782 kdDebug(5800) <<
"Resource added: " << resource->resourceName() << endl;
784 if ( !resource->isActive() )
787 if ( resource->open() ) {
791 connectResource( resource );
798 kdDebug(5800) <<
"Resource modified: " << resource->resourceName() << endl;
805 kdDebug(5800) <<
"Resource deleted: " << resource->resourceName() << endl;
814 CalendarResourceManager::Iterator i1;
815 for ( i1 = mManager->begin(); i1 != mManager->end(); ++i1 ) {
816 (*i1)->setTimeZoneId( timeZoneId );
825 CalendarResources::Ticket
828 kdDebug(5800) <<
"CalendarResources::requestSaveTicket()" << endl;
830 TDEABC::Lock *lock = resource->
lock();
834 return new Ticket( resource );
841 kdDebug(5800) <<
"CalendarResources::save( Ticket *)" << endl;
843 if ( !ticket || !ticket->resource() )
846 kdDebug(5800) <<
"tick " << ticket->resource()->resourceName() << endl;
849 if ( ticket->resource()->save( incidence ) ) {
859 ticket->resource()->lock()->unlock();
870 const TQString &subres )
874 kdDebug(5800) <<
"CalendarResources::beginChange()" << endl;
880 res = mDestinationPolicy->destination( incidence );
882 kdError() <<
"Unable to get destination resource." << endl;
887 mPendingDeleteFromResourceMap =
false;
893 kdDebug(5800) <<
"CalendarResources::beginChange(): unable to get ticket." 898 mTickets[ res ] = ticket;
907 return endChange( incidence, 0, TQString() );
912 const TQString &subres )
916 kdDebug(5800) <<
"CalendarResource::endChange()" << endl;
926 if ( mPendingDeleteFromResourceMap ) {
927 mResourceMap.remove( incidence );
928 mPendingDeleteFromResourceMap =
false;
932 bool ok =
save( mTickets[ res ], incidence );
934 mTickets.remove( res );
945 kdDebug(5800) <<
"CalendarResources: beginAddingIncidences() " << endl;
946 d->mBatchAddingInProgress =
true;
951 kdDebug(5800) <<
"CalendarResources: endAddingIncidences() " << endl;
952 d->mBatchAddingInProgress =
false;
954 if ( d->mLastUsedResource ) {
955 d->mLastUsedResource->endAddingIncidences();
958 d->mLastUsedResource = 0;
963 if ( !mChangeCounts.contains( r ) ) {
964 mChangeCounts.insert( r, 0 );
967 int count = mChangeCounts[ r ];
969 mChangeCounts[ r ] = count;
976 if ( !mChangeCounts.contains( r ) ) {
977 kdError() <<
"No change count for resource." << endl;
981 int count = mChangeCounts[ r ];
984 kdError() <<
"Can't decrement change count. It already is 0." << endl;
987 mChangeCounts[ r ] = count;
992 void CalendarResources::slotLoadError(
ResourceCalendar *,
const TQString &err )
997 void CalendarResources::slotSaveError(
ResourceCalendar *,
const TQString &err )
1002 #include "calendarresources.moc" void load()
Loads all Incidences from the Resources.
bool addTodo(Todo *todo)
Insert a Todo into a Calendar Resource.
JournalSortField
How Journals are to be sorted.
Journals are to be unsorted.
void readConfig(TDEConfig *config=0)
Read the Resources settings from a config file.
void calendarChanged()
Signal that the Calendar has been modified.
static Journal::List sortJournals(Journal::List *journalList, JournalSortField sortField, SortDirection sortDirection)
Sort a list of Journals.
Journal::List rawJournalsForDate(const TQDate &date)
Return an unfiltered list of all Journals for on the specifed date.
Todo * todo(const TQString &uid)
Returns the Todo associated with the given unique identifier.
bool deleteTodo(Todo *todo)
Remove an Todo from the Calendar.
This class provides a Todo in the sense of RFC2445.
This is the main "calendar" object class.
void resourceAdded(ResourceCalendar *resource)
Add a Resource to the Calendar.
Journal * journal(const TQString &uid)
Returns the Journal associated with the given unique identifier.
void setModified(bool modified)
Set if the Calendar had been modified.
void setTimeZoneIdViewOnly(const TQString &tz)
Set the viewing time zone, which requires that all resources are saved, and then reloaded such that t...
This class provides an Event in the sense of RFC2445.
void signalResourceAdded(ResourceCalendar *resource)
Signal that an Incidence has been inserted to the Resource.
virtual void doSetTimeZoneId(const TQString &timeZoneId)
Let CalendarResource subclasses set the Time Zone ID.
Todo::List rawTodos(TodoSortField sortField=TodoSortUnsorted, SortDirection sortDirection=SortDirectionAscending)
Return a sorted, unfiltered list of all Todos for this Calendar.
void save()
Sync changes in memory to persistant storage.
virtual void releaseSaveTicket(Ticket *ticket)
Release the save Ticket.
This class provides the interfaces for a calendar resource.
void beginAddingIncidences()
All addIncidence( Incidence * ), addTodo( Todo * ) addEvent( Event * ) and addJournal( Journal * ) ca...
Alarm::List alarms(const TQDateTime &from, const TQDateTime &to)
Return a list of Alarms within a time range for this Calendar.
Event::List rawEvents(EventSortField sortField=EventSortUnsorted, SortDirection sortDirection=SortDirectionAscending)
Return a sorted, unfiltered list of all Events.
KDE_DEPRECATED bool beginChange(Incidence *incidence)
Flag that a change to a Calendar Incidence is starting.
TQString timeZoneId() const
Get the Time Zone ID for the Calendar.
KDE_DEPRECATED bool endChange(Incidence *incidence)
Flag that a change to a Calendar Incidence has completed.
virtual TDEABC::Lock * lock()=0
Return object for locking the resource.
TQString summary() const
Return short summary.
void notifyIncidenceAdded(Incidence *incidence)
Let Calendar subclasses notify that they inserted an Incidence.
bool isSaving()
Determine if the Calendar is currently being saved.
void clearException()
Clears the exception status.
void notifyIncidenceDeleted(Incidence *incidence)
Let Calendar subclasses notify that they removed an Incidence.
void closeEvents()
Clear out the current Calendar, freeing all used memory etc.
bool addIncidence(Incidence *incidence)
Insert an Incidence into the Calendar.
void setAskDestinationPolicy()
Set the destination policy such that Incidences are added to a Resource which is queried.
void setStandardDestinationPolicy()
Set the destination policy such that Incidences are always added to the standard Resource.
virtual KDE_DEPRECATED bool addIncidence(Incidence *)
Add incidence to resource.
Provides a Calendar composed of several Calendar Resources.
bool deleteJournal(Journal *journal)
Remove a Journal from the Calendar.
bool isModified() const
Determine the Calendar's modification status.
void setException(ErrorFormat *e)
Sets information about the last error occurred.
bool load()
Load resource data.
This class provides the base class common to all calendar components.
void signalResourceModified(ResourceCalendar *resource)
Signal that the Resource has been modified.
Journal::List rawJournals(JournalSortField sortField=JournalSortUnsorted, SortDirection sortDirection=SortDirectionAscending)
Return a sorted, unfiltered list of all Journals for this Calendar.
Incidence * incidence(const TQString &uid)
Returns the Incidence associated with the given unique identifier.
This class provides a Journal in the sense of RFC2445.
int decrementChangeCount(ResourceCalendar *resource)
Decrement the number of times this Resource has been changed by 1.
bool deleteEvent(Event *event)
Remove an Event from the Calendar.
static Todo::List sortTodos(Todo::List *todoList, TodoSortField sortField, SortDirection sortDirection)
Sort a list of Todos.
ResourceCalendar * resource(Incidence *incidence)
Get the Resource associated with a specified Incidence.
bool addJournal(Journal *journal)
Insert a Journal into the Calendar.
~CalendarResources()
Destructor.
Todo::List rawTodosForDate(const TQDate &date)
Return an unfiltered list of all Todos which are due on the specified date.
bool addEvent(Event *event)
Insert an Event into the Calendar.
ErrorFormat * exception()
Returns an exception, if there is any, containing information about the last error that occurred...
CalendarResources(const TQString &timeZoneId, const TQString &family=TQString::fromLatin1("calendar"))
Construct CalendarResource object using a Time Zone and a Family name.
Todos are to be unsorted.
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.
void close()
Clear out the current Calendar, freeing all used memory etc.
Events are to be unsorted.
Namespace KCal is for global classes, objects and/or functions in libkcal.
void endAddingIncidences()
SortDirection
Sort direction.
void calendarLoaded()
Signal that the Calendar has been loaded into memory.
void setDialogParentWidget(TQWidget *parent)
Set the widget parent for new dialogs.
void closeJournals()
Clear out the current Calendar, freeing all used memory etc.
virtual Journal::List journals(JournalSortField sortField=JournalSortUnsorted, SortDirection sortDirection=SortDirectionAscending)
Return a sorted, filtered list of all Journals for this Calendar.
Alarm::List alarmsTo(const TQDateTime &to)
Return a list of Alarms that occur before the specified timestamp.
Event::List rawEventsForDate(const TQDateTime &qdt)
Return an unfiltered list of all Events which occur on the given timestamp.
void setTimeZoneId(const TQString &timeZoneId)
Set the Time Zone Id for the Calendar.
TodoSortField
How Todos are to be sorted.
virtual Todo::List todos(TodoSortField sortField=TodoSortUnsorted, SortDirection sortDirection=SortDirectionAscending)
Return a sorted, filtered list of all Todos for this Calendar.
void calendarSaved()
Signal that the Calendar has been saved.
void closeTodos()
Clear out the current Calendar, freeing all used memory etc.
void signalResourceDeleted(ResourceCalendar *resource)
Signal that an Incidence has been removed from the Resource.
EventSortField
How Events are to be sorted.
bool reload(const TQString &tz)
Reloads all incidences from all resources.
int incrementChangeCount(ResourceCalendar *resource)
Increment the number of times this Resource has been changed by 1.
virtual Incidence::List incidences()
Return a filtered list of all Incidences for this Calendar.
void signalErrorMessage(const TQString &err)
Signal an error message.
static Event::List sortEvents(Event::List *eventList, EventSortField sortField, SortDirection sortDirection)
Sort a list of Events.
TQWidget * dialogParentWidget()
Returns the current parent for new dialogs.
void registerObserver(Observer *)
Register observer.
CalendarResourceManager * resourceManager() const
Get the CalendarResourceManager used by this calendar.
Ticket * requestSaveTicket(ResourceCalendar *resource)
Request ticket for saving the Calendar.
Event * event(const TQString &uid)
Returns the Event associated with the given unique identifier.