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;
73 for ( it = resourceManager()->activeBegin();
74 it != resourceManager()->activeEnd(); ++it ) {
75 if ( !(*it)->readOnly() ) {
77 if ( resourceManager()->standardResource() == *it ) {
88 *CalendarResources::StandardDestinationPolicy::destination(
Incidence * )
90 return resourceManager()->standardResource();
94 *CalendarResources::AskDestinationPolicy::destination(
Incidence * )
96 TQPtrList<KRES::Resource> list;
98 CalendarResourceManager::ActiveIterator it;
99 for ( it = resourceManager()->activeBegin();
100 it != resourceManager()->activeEnd(); ++it ) {
101 if ( !(*it)->readOnly() ) {
103 if ( resourceManager()->standardResource() == *it )
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;
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 ) ) {
358 kdDebug(5800) <<
"CalendarResources::addIncidence "
360 <<
"; addingInProgress = " << d->mBatchAddingInProgress
361 <<
"; lastUsedResource = " << d->mLastUsedResource
368 if ( !d->mBatchAddingInProgress || d->mLastUsedResource == 0 ) {
372 if (
resource && d->mBatchAddingInProgress ) {
373 d->mLastUsedResource->beginAddingIncidences();
378 kdDebug(5800) <<
"CalendarResources:: resource= "
380 <<
" with id = " <<
resource->identifier()
381 <<
" with type = " <<
resource->type()
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() ) {
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;
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;
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;
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 ) {
825 CalendarResources::Ticket
828 kdDebug(5800) <<
"CalendarResources::requestSaveTicket()" << endl;
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;
912 const TQString &subres )
916 kdDebug(5800) <<
"CalendarResource::endChange()" << endl;
926 if ( mPendingDeleteFromResourceMap ) {
928 mPendingDeleteFromResourceMap =
false;
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"
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.
void endAddingIncidences()
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.
CalendarResources(const TQString &timeZoneId, const TQString &family=TQString::fromLatin1("calendar"))
Construct CalendarResource object using a Time Zone and a Family name.
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.
~CalendarResources()
Destructor.
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.
void clearException()
Clears the exception status.
static Todo::List sortTodos(Todo::List *todoList, TodoSortField sortField, SortDirection sortDirection)
Sort a list of Todos.
void calendarLoaded()
Signal that the Calendar has been loaded into memory.
void setTimeZoneId(const TQString &timeZoneId)
Set the Time Zone Id for the Calendar.
bool isModified() const
Determine the Calendar's modification status.
virtual Incidence::List incidences()
Return a filtered list of all Incidences for this Calendar.
void calendarSaved()
Signal that the Calendar has been saved.
void notifyIncidenceDeleted(Incidence *incidence)
Let Calendar subclasses notify that they removed an Incidence.
static Event::List sortEvents(Event::List *eventList, EventSortField sortField, SortDirection sortDirection)
Sort a list of Events.
void setModified(bool modified)
Set if the Calendar had been modified.
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 calendarChanged()
Signal that the Calendar has been modified.
TQString timeZoneId() const
Get the Time Zone ID for the Calendar.
void setException(ErrorFormat *e)
Sets information about the last error occurred.
void notifyIncidenceAdded(Incidence *incidence)
Let Calendar subclasses notify that they inserted an Incidence.
virtual Journal::List journals(JournalSortField sortField=JournalSortUnsorted, SortDirection sortDirection=SortDirectionAscending)
Return a sorted, filtered list of all Journals for this Calendar.
Incidence * incidence(const TQString &uid)
Returns the Incidence associated with the given unique identifier.
virtual Todo::List todos(TodoSortField sortField=TodoSortUnsorted, SortDirection sortDirection=SortDirectionAscending)
Return a sorted, filtered list of all Todos for this Calendar.
static Journal::List sortJournals(Journal::List *journalList, JournalSortField sortField, SortDirection sortDirection)
Sort a list of Journals.
This class provides an Event in the sense of RFC2445.
void registerObserver(Observer *)
Register observer.
This class provides the base class common to all calendar components.
TQString summary() const
Return short summary.
This class provides a Journal in the sense of RFC2445.
This class provides the interfaces for a calendar resource.
virtual TDEABC::Lock * lock()=0
Return object for locking the 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.
This class provides a Todo in the sense of RFC2445.
Namespace KCal is for global classes, objects and/or functions in libkcal.
TodoSortField
How Todos are to be sorted.
@ TodoSortUnsorted
Todos are to be unsorted.
JournalSortField
How Journals are to be sorted.
@ JournalSortUnsorted
Journals are to be unsorted.
EventSortField
How Events are to be sorted.
@ EventSortUnsorted
Events are to be unsorted.
SortDirection
Sort direction.