diff --git a/kcal/calendarresources.cpp b/kcal/calendarresources.cpp index ec3c6496f..863865814 100644 --- a/kcal/calendarresources.cpp +++ b/kcal/calendarresources.cpp @@ -1,916 +1,917 @@ /* This file is part of the kcal library. Copyright (c) 2003 Cornelius Schumacher Copyright (C) 2003-2004 Reinhold Kainhofer This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ /** @file This file is part of the API for handling calendar data and defines the CalendarResources class. @brief This class provides a Calendar which is composed of other Calendars known as "Resources". @author Cornelius Schumacher \ @author Reinhold Kainhofer \ */ #include "calendarresources.moc" #include "incidence.h" #include "journal.h" #include "resourcecalendar.h" #include "kresources/manager.h" #include "kresources/selectdialog.h" #include "kabc/lock.h" #include #include #include #include #include #include #include using namespace KCal; /** Private classes that helps to provide binary compatibility between releases. @internal */ //@cond PRIVATE class KCal::CalendarResources::Private { public: Private( const QString &family ) : mManager( new CalendarResourceManager( family ) ), mStandardPolicy( new StandardDestinationPolicy( mManager ) ), mDestinationPolicy( mStandardPolicy ), - mAskPolicy( new AskDestinationPolicy( mManager ) ) + mAskPolicy( new AskDestinationPolicy( mManager ) ), + mPendingDeleteFromResourceMap( false ) {} ~Private() { delete mManager; delete mStandardPolicy; delete mAskPolicy; } bool mOpen; //flag that indicates if the resources are "open" KRES::Manager* mManager; QMap mResourceMap; StandardDestinationPolicy *mStandardPolicy; DestinationPolicy *mDestinationPolicy; AskDestinationPolicy *mAskPolicy; QMap mTickets; QMap mChangeCounts; + bool mPendingDeleteFromResourceMap; + template< class IncidenceList > void appendIncidences( IncidenceList &result, const IncidenceList &extra, ResourceCalendar * ); }; class KCal::CalendarResources::DestinationPolicy::Private { public: Private( CalendarResourceManager *manager, QWidget *parent ) : mManager( manager ), mParent( parent ) {} CalendarResourceManager *mManager; QWidget *mParent; }; class KCal::CalendarResources::StandardDestinationPolicy::Private { public: Private() {} }; class KCal::CalendarResources::AskDestinationPolicy::Private { public: Private() {} }; class KCal::CalendarResources::Ticket::Private { public: Private( ResourceCalendar *resource ) : mResource( resource ) {} ResourceCalendar *mResource; }; //@endcond CalendarResources::DestinationPolicy::DestinationPolicy( CalendarResourceManager *manager, QWidget *parent ) : d( new KCal::CalendarResources::DestinationPolicy::Private( manager, parent ) ) { } CalendarResources::DestinationPolicy::~DestinationPolicy() { delete d; } QWidget *CalendarResources::DestinationPolicy::parent() { return d->mParent; } void CalendarResources::DestinationPolicy::setParent( QWidget *parent ) { d->mParent = parent; } CalendarResourceManager *CalendarResources::DestinationPolicy::resourceManager() { return d->mManager; } CalendarResources::StandardDestinationPolicy::StandardDestinationPolicy( CalendarResourceManager *manager, QWidget *parent ) : DestinationPolicy( manager, parent ), d( new KCal::CalendarResources::StandardDestinationPolicy::Private ) { } CalendarResources::StandardDestinationPolicy::~StandardDestinationPolicy() { delete d; } ResourceCalendar *CalendarResources::StandardDestinationPolicy::destination( Incidence *incidence ) { Q_UNUSED( incidence ); return resourceManager()->standardResource(); } CalendarResources::AskDestinationPolicy::AskDestinationPolicy( CalendarResourceManager *manager, QWidget *parent ) : DestinationPolicy( manager, parent ), d( new KCal::CalendarResources::AskDestinationPolicy::Private ) { } CalendarResources::AskDestinationPolicy::~AskDestinationPolicy() { delete d; } ResourceCalendar *CalendarResources::AskDestinationPolicy::destination( Incidence *incidence ) { Q_UNUSED( incidence ); QList list; CalendarResourceManager::ActiveIterator it; for ( it = resourceManager()->activeBegin(); it != resourceManager()->activeEnd(); ++it ) { if ( !(*it)->readOnly() ) { //Insert the first the Standard resource to get be the default selected. if ( resourceManager()->standardResource() == *it ) { list.insert( 0, *it ); } else { list.append( *it ); } } } KRES::Resource *r; r = KRES::SelectDialog::getResource( list, parent() ); return static_cast( r ); } CalendarResources::CalendarResources( const KDateTime::Spec &timeSpec, const QString &family ) : Calendar( timeSpec ), d( new KCal::CalendarResources::Private( family ) ) { - mPendingDeleteFromResourceMap = false; d->mManager->addObserver( this ); } CalendarResources::CalendarResources( const QString &timeZoneId, const QString &family ) : Calendar( timeZoneId ), d( new KCal::CalendarResources::Private( family ) ) { - mPendingDeleteFromResourceMap = false; d->mManager->addObserver( this ); } CalendarResources::~CalendarResources() { close(); delete d; } void CalendarResources::readConfig( KConfig *config ) { d->mManager->readConfig( config ); CalendarResourceManager::Iterator it; for ( it = d->mManager->begin(); it != d->mManager->end(); ++it ) { connectResource( *it ); } } void CalendarResources::load() { if ( !d->mManager->standardResource() ) { kDebug() << "Warning! No standard resource yet."; } // set the timezone for all resources. Otherwise we'll have those terrible tz // troubles ;-(( CalendarResourceManager::Iterator i1; for ( i1 = d->mManager->begin(); i1 != d->mManager->end(); ++i1 ) { (*i1)->setTimeSpec( timeSpec() ); } QList failed; // Open all active resources CalendarResourceManager::ActiveIterator it; for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { if ( !(*it)->load() ) { failed.append( *it ); } Incidence::List incidences = (*it)->rawIncidences(); Incidence::List::Iterator incit; for ( incit = incidences.begin(); incit != incidences.end(); ++incit ) { (*incit)->registerObserver( this ); notifyIncidenceAdded( *incit ); } } QList::ConstIterator it2; for ( it2 = failed.begin(); it2 != failed.end(); ++it2 ) { (*it2)->setActive( false ); emit signalResourceModified( *it2 ); } d->mOpen = true; emit calendarLoaded(); } bool CalendarResources::reload() { save(); close(); load(); return true; } CalendarResourceManager *CalendarResources::resourceManager() const { return d->mManager; } void CalendarResources::setStandardDestinationPolicy() { d->mDestinationPolicy = d->mStandardPolicy; } void CalendarResources::setAskDestinationPolicy() { d->mDestinationPolicy = d->mAskPolicy; } QWidget *CalendarResources::dialogParentWidget() { return d->mDestinationPolicy->parent(); } void CalendarResources::setDialogParentWidget( QWidget *parent ) { d->mDestinationPolicy->setParent( parent ); } void CalendarResources::close() { if ( d->mOpen ) { CalendarResourceManager::ActiveIterator it; for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { (*it)->close(); } setModified( false ); d->mOpen = false; } } bool CalendarResources::save() { bool status = true; if ( d->mOpen && isModified() ) { status = false; CalendarResourceManager::ActiveIterator it; for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { status = (*it)->save() || status; } setModified( false ); } return status; } bool CalendarResources::isSaving() { CalendarResourceManager::ActiveIterator it; for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { if ( (*it)->isSaving() ) { return true; } } return false; } bool CalendarResources::addIncidence( Incidence *incidence, ResourceCalendar *resource ) { // FIXME: Use proper locking via begin/endChange! bool validRes = false; CalendarResourceManager::ActiveIterator it; for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { if ( (*it) == resource ) { validRes = true; } } ResourceCalendar *oldResource = 0; if ( d->mResourceMap.contains( incidence ) ) { oldResource = d->mResourceMap[incidence]; } d->mResourceMap[incidence] = resource; if ( validRes && beginChange( incidence ) && resource->addIncidence( incidence ) ) { // d->mResourceMap[incidence] = resource; incidence->registerObserver( this ); notifyIncidenceAdded( incidence ); setModified( true ); endChange( incidence ); return true; } else { if ( oldResource ) { d->mResourceMap[incidence] = oldResource; } else { d->mResourceMap.remove( incidence ); } } return false; } bool CalendarResources::addIncidence( Incidence *incidence ) { ResourceCalendar *resource = d->mDestinationPolicy->destination( incidence ); if ( resource ) { d->mResourceMap[ incidence ] = resource; if ( beginChange( incidence ) && resource->addIncidence( incidence ) ) { incidence->registerObserver( this ); notifyIncidenceAdded( incidence ); d->mResourceMap[ incidence ] = resource; setModified( true ); endChange( incidence ); return true; } else { d->mResourceMap.remove( incidence ); } } else { kDebug() << "no resource"; } return false; } bool CalendarResources::addEvent( Event *event ) { return addIncidence( event ); } bool CalendarResources::addEvent( Event *Event, ResourceCalendar *resource ) { return addIncidence( Event, resource ); } bool CalendarResources::deleteEvent( Event *event ) { bool status; if ( d->mResourceMap.find( event ) != d->mResourceMap.end() ) { status = d->mResourceMap[event]->deleteEvent( event ); if ( status ) { - mPendingDeleteFromResourceMap = true; + d->mPendingDeleteFromResourceMap = true; } } else { status = false; CalendarResourceManager::ActiveIterator it; for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { status = (*it)->deleteEvent( event ) || status; } } if ( status ) { notifyIncidenceDeleted( event ); } setModified( status ); return status; } void CalendarResources::deleteAllEvents() { CalendarResourceManager::ActiveIterator it; for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { (*it)->deleteAllEvents(); } } Event *CalendarResources::event( const QString &uid ) { CalendarResourceManager::ActiveIterator it; for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { Event *event = (*it)->event( uid ); if ( event ) { d->mResourceMap[event] = *it; return event; } } // Not found return 0; } bool CalendarResources::addTodo( Todo *todo ) { return addIncidence( todo ); } bool CalendarResources::addTodo( Todo *todo, ResourceCalendar *resource ) { return addIncidence( todo, resource ); } bool CalendarResources::deleteTodo( Todo *todo ) { bool status; if ( d->mResourceMap.find( todo ) != d->mResourceMap.end() ) { status = d->mResourceMap[todo]->deleteTodo( todo ); if ( status ) { - mPendingDeleteFromResourceMap = true; + d->mPendingDeleteFromResourceMap = true; } } else { CalendarResourceManager::ActiveIterator it; status = false; for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { status = (*it)->deleteTodo( todo ) || status; } } setModified( status ); return status; } void CalendarResources::deleteAllTodos() { CalendarResourceManager::ActiveIterator it; for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { (*it)->deleteAllTodos(); } } Todo::List CalendarResources::rawTodos( TodoSortField sortField, SortDirection sortDirection ) { Todo::List result; CalendarResourceManager::ActiveIterator it; for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { d->appendIncidences( result, (*it)->rawTodos( TodoSortUnsorted ), *it ); } return sortTodos( &result, sortField, sortDirection ); } Todo *CalendarResources::todo( const QString &uid ) { CalendarResourceManager::ActiveIterator it; for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { Todo *todo = (*it)->todo( uid ); if ( todo ) { d->mResourceMap[todo] = *it; return todo; } } // Not found return 0; } Todo::List CalendarResources::rawTodosForDate( const QDate &date ) { Todo::List result; CalendarResourceManager::ActiveIterator it; for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { d->appendIncidences( result, (*it)->rawTodosForDate( date ), *it ); } return result; } Alarm::List CalendarResources::alarmsTo( const KDateTime &to ) { Alarm::List result; CalendarResourceManager::ActiveIterator it; for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { result += (*it)->alarmsTo( to ); } return result; } Alarm::List CalendarResources::alarms( const KDateTime &from, const KDateTime &to ) { Alarm::List result; CalendarResourceManager::ActiveIterator it; for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { result += (*it)->alarms( from, to ); } return result; } /****************************** PROTECTED METHODS ****************************/ Event::List CalendarResources::rawEventsForDate( const QDate &date, const KDateTime::Spec ×pec, EventSortField sortField, SortDirection sortDirection ) { Event::List result; CalendarResourceManager::ActiveIterator it; for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { d->appendIncidences( result, (*it)->rawEventsForDate( date, timespec ), *it ); } return sortEvents( &result, sortField, sortDirection ); } Event::List CalendarResources::rawEvents( const QDate &start, const QDate &end, const KDateTime::Spec ×pec, bool inclusive ) { Event::List result; CalendarResourceManager::ActiveIterator it; for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { d->appendIncidences( result, (*it)->rawEvents( start, end, timespec, inclusive ), *it ); } return result; } Event::List CalendarResources::rawEventsForDate( const KDateTime &kdt ) { // @TODO: Remove the code duplication by the resourcemap iteration block. Event::List result; CalendarResourceManager::ActiveIterator it; for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { d->appendIncidences( result, (*it)->rawEventsForDate( kdt ), *it ); } return result; } Event::List CalendarResources::rawEvents( EventSortField sortField, SortDirection sortDirection ) { Event::List result; CalendarResourceManager::ActiveIterator it; for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { d->appendIncidences( result, (*it)->rawEvents( EventSortUnsorted ), *it ); } return sortEvents( &result, sortField, sortDirection ); } bool CalendarResources::addJournal( Journal *journal ) { return addIncidence( journal ); } bool CalendarResources::deleteJournal( Journal *journal ) { bool status; if ( d->mResourceMap.find( journal ) != d->mResourceMap.end() ) { status = d->mResourceMap[journal]->deleteJournal( journal ); if ( status ) { - mPendingDeleteFromResourceMap = true; + d->mPendingDeleteFromResourceMap = true; } } else { CalendarResourceManager::ActiveIterator it; status = false; for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { status = (*it)->deleteJournal( journal ) || status; } } setModified( status ); return status; } void CalendarResources::deleteAllJournals() { CalendarResourceManager::ActiveIterator it; for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { (*it)->deleteAllJournals(); } } bool CalendarResources::addJournal( Journal *journal, ResourceCalendar *resource ) { return addIncidence( journal, resource ); } Journal *CalendarResources::journal( const QString &uid ) { CalendarResourceManager::ActiveIterator it; for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { Journal *journal = (*it)->journal( uid ); if ( journal ) { d->mResourceMap[journal] = *it; return journal; } } // Not found return 0; } Journal::List CalendarResources::rawJournals( JournalSortField sortField, SortDirection sortDirection ) { Journal::List result; CalendarResourceManager::ActiveIterator it; for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { d->appendIncidences( result, (*it)->rawJournals( JournalSortUnsorted ), *it ); } return sortJournals( &result, sortField, sortDirection ); } Journal::List CalendarResources::rawJournalsForDate( const QDate &date ) { Journal::List result; CalendarResourceManager::ActiveIterator it; for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { d->appendIncidences( result, (*it)->rawJournalsForDate( date ), *it ); } return result; } //@cond PRIVATE template< class IncidenceList > void CalendarResources::Private::appendIncidences( IncidenceList &result, const IncidenceList &extra, ResourceCalendar *resource ) { result += extra; for ( typename IncidenceList::ConstIterator it = extra.begin(); it != extra.end(); ++it ) { mResourceMap[ *it ] = resource; } } //@endcond void CalendarResources::connectResource( ResourceCalendar *resource ) { connect( resource, SIGNAL( resourceChanged( ResourceCalendar * ) ), SIGNAL( calendarChanged() ) ); connect( resource, SIGNAL( resourceSaved( ResourceCalendar * ) ), SIGNAL( calendarSaved() ) ); connect( resource, SIGNAL( resourceLoadError( ResourceCalendar *, const QString & ) ), SLOT( slotLoadError( ResourceCalendar *, const QString & ) ) ); connect( resource, SIGNAL( resourceSaveError( ResourceCalendar *, const QString & ) ), SLOT( slotSaveError( ResourceCalendar *, const QString & ) ) ); } ResourceCalendar *CalendarResources::resource( Incidence *incidence ) { if ( d->mResourceMap.find( incidence ) != d->mResourceMap.end() ) { return d->mResourceMap[ incidence ]; } return 0; } void CalendarResources::resourceAdded( ResourceCalendar *resource ) { if ( !resource->isActive() ) { return; } if ( resource->open() ) { resource->load(); } connectResource( resource ); emit signalResourceAdded( resource ); } void CalendarResources::resourceModified( ResourceCalendar *resource ) { emit signalResourceModified( resource ); } void CalendarResources::resourceDeleted( ResourceCalendar *resource ) { emit signalResourceDeleted( resource ); } void CalendarResources::doSetTimeSpec( const KDateTime::Spec &timeSpec ) { // set the timezone for all resources. Otherwise we'll have those terrible // tz troubles ;-(( CalendarResourceManager::Iterator i1; for ( i1 = d->mManager->begin(); i1 != d->mManager->end(); ++i1 ) { (*i1)->setTimeSpec( timeSpec ); } } CalendarResources::Ticket::Ticket( ResourceCalendar *resource ) : d( new KCal::CalendarResources::Ticket::Private( resource ) ) { } CalendarResources::Ticket::~Ticket() { delete d; } CalendarResources::Ticket *CalendarResources::requestSaveTicket( ResourceCalendar *resource ) { KABC::Lock *lock = resource->lock(); if ( !lock ) { return 0; } if ( lock->lock() ) { return new Ticket( resource ); } else { return 0; } } ResourceCalendar *CalendarResources::Ticket::resource() const { return d->mResource; } bool CalendarResources::save( Ticket *ticket, Incidence *incidence ) { if ( !ticket || !ticket->resource() ) { return false; } // @TODO: Check if the resource was changed at all. If not, don't save. if ( ticket->resource()->save( incidence ) ) { releaseSaveTicket( ticket ); return true; } return false; } void CalendarResources::releaseSaveTicket( Ticket *ticket ) { ticket->resource()->lock()->unlock(); delete ticket; } bool CalendarResources::beginChange( Incidence *incidence ) { ResourceCalendar *r = resource( incidence ); if ( !r ) { r = d->mDestinationPolicy->destination( incidence ); if ( !r ) { kError() << "Unable to get destination resource."; return false; } d->mResourceMap[ incidence ] = r; } - mPendingDeleteFromResourceMap = false; + d->mPendingDeleteFromResourceMap = false; int count = incrementChangeCount( r ); if ( count == 1 ) { Ticket *ticket = requestSaveTicket( r ); if ( !ticket ) { kDebug() << "unable to get ticket."; decrementChangeCount( r ); return false; } else { d->mTickets[ r ] = ticket; } } return true; } bool CalendarResources::endChange( Incidence *incidence ) { ResourceCalendar *r = resource( incidence ); if ( !r ) { return false; } int count = decrementChangeCount( r ); - if ( mPendingDeleteFromResourceMap ) { + if ( d->mPendingDeleteFromResourceMap ) { d->mResourceMap.remove( incidence ); - mPendingDeleteFromResourceMap = false; + d->mPendingDeleteFromResourceMap = false; } if ( count == 0 ) { bool ok = save( d->mTickets[ r ], incidence ); if ( ok ) { d->mTickets.remove( r ); } else { return false; } } return true; } int CalendarResources::incrementChangeCount( ResourceCalendar *r ) { if ( !d->mChangeCounts.contains( r ) ) { d->mChangeCounts.insert( r, 0 ); } int count = d->mChangeCounts[ r ]; ++count; d->mChangeCounts[ r ] = count; return count; } int CalendarResources::decrementChangeCount( ResourceCalendar *r ) { if ( !d->mChangeCounts.contains( r ) ) { kError() << "No change count for resource."; return 0; } int count = d->mChangeCounts[ r ]; --count; if ( count < 0 ) { kError() << "Can't decrement change count. It already is 0."; count = 0; } d->mChangeCounts[ r ] = count; return count; } void CalendarResources::slotLoadError( ResourceCalendar *r, const QString &err ) { Q_UNUSED( r ); emit signalErrorMessage( err ); } void CalendarResources::slotSaveError( ResourceCalendar *r, const QString &err ) { Q_UNUSED( r ); emit signalErrorMessage( err ); } diff --git a/kcal/calendarresources.h b/kcal/calendarresources.h index a27c1a0db..9fd098228 100644 --- a/kcal/calendarresources.h +++ b/kcal/calendarresources.h @@ -1,712 +1,711 @@ /* This file is part of the kcal library. Copyright (c) 2003 Cornelius Schumacher Copyright (C) 2003-2004 Reinhold Kainhofer This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ /** @file This file is part of the API for handling calendar data and defines the CalendarResources class. @author Cornelius Schumacher \ @author Reinhold Kainhofer \ */ #ifndef KCAL_CALENDARRESOURCES_H #define KCAL_CALENDARRESOURCES_H #include #include "calendar.h" #include "resourcecalendar.h" #include "kcal_export.h" class QWidget; namespace KCal { /** @brief This class provides a Calendar which is composed of other Calendars known as "Resources". Examples of Calendar Resources are: - Calendars stored as local ICS formatted files - a set of incidences (one-per-file) within a local directory - birthdays and anniversaries contained in an addressbook */ class KCAL_EXPORT CalendarResources : public Calendar, public KRES::ManagerObserver { Q_OBJECT public: /** @class DestinationPolicy */ class DestinationPolicy { public: /** Constructs a destination policy. @param manager is a pointer to the CalendarResourceManager. @param parent is a pointer to a QWidget to use for new dialogs. */ explicit DestinationPolicy( CalendarResourceManager *manager, QWidget *parent = 0 ); /** Destructor. */ virtual ~DestinationPolicy(); /** Returns parent widget to use for new dialogs. */ virtual QWidget *parent(); /** Sets the parent widget for new dialogs. @param parent is a pointer to a QWidget containing the parent. */ virtual void setParent( QWidget *parent ); /** Returns the destination ResourceCalendar for the specified incidence. @param incidence is a pointer to a valid Incidence object. */ virtual ResourceCalendar *destination( Incidence *incidence ) = 0; protected: /** Returns the CalendarResourceManager used by this calendar. */ CalendarResourceManager *resourceManager(); private: //@cond PRIVATE Q_DISABLE_COPY( DestinationPolicy ) class Private; Private *d; //@endcond }; /** @class StandardDestinationPolicy */ class StandardDestinationPolicy : public DestinationPolicy { public: /** Constructs a standard destination policy. @param manager is a pointer to the CalendarResourceManager. @param parent is a pointer to a QWidget to use for new dialogs. */ explicit StandardDestinationPolicy( CalendarResourceManager *manager, QWidget *parent = 0 ); /** Destructor. */ virtual ~StandardDestinationPolicy(); /** Returns the destination ResourceCalendar for the specified incidence. @param incidence is a pointer to a valid Incidence object. */ ResourceCalendar *destination( Incidence *incidence ); private: //@cond PRIVATE Q_DISABLE_COPY( StandardDestinationPolicy ) class Private; Private *d; //@endcond }; /** @class AskDestinationPolicy */ class AskDestinationPolicy : public DestinationPolicy { public: /** Constructs an Ask destination policy. @param manager is a pointer to the CalendarResourceManager. @param parent is a pointer to a QWidget to use for new dialogs. */ explicit AskDestinationPolicy( CalendarResourceManager *manager, QWidget *parent = 0 ); /** Destructor. */ virtual ~AskDestinationPolicy(); /** Returns the destination ResourceCalendar for the specified incidence. @param incidence is a pointer to a valid Incidence object. */ ResourceCalendar *destination( Incidence *incidence ); private: //@cond PRIVATE Q_DISABLE_COPY( AskDestinationPolicy ) class Private; Private *d; //@endcond }; /** @class Ticket */ class Ticket { friend class CalendarResources; public: /** Returns the ResourceCalendar associated with the ticket. */ ResourceCalendar *resource() const; /** Destructor. */ ~Ticket(); private: /** Constructs a Ticket for a ResourceCalendar. @param resource is a pointer to a valid ResourceCalendar object. */ Ticket( ResourceCalendar *resource ); //@cond PRIVATE Q_DISABLE_COPY( Ticket ) class Private; Private *d; //@endcond }; /** Construct CalendarResource object using a time specification (time zone, etc.) and a Family name. @param timeSpec is a time specification which is used for creating or modifying incidences in the Calendar. It is also used for viewing incidences (see setViewTimeSpec()). @param family is any QString representing a unique name. */ CalendarResources( const KDateTime::Spec &timeSpec, const QString &family = QLatin1String( "calendar" ) ); /** Construct CalendarResource object using a time zone ID and a Family name. @param timeZoneId is used for creating or modifying incidences in the Calendar. It is also used for viewing incidences. The time zone does not alter existing incidences. @param family is any QString representing a unique name. */ CalendarResources( const QString &timeZoneId, const QString &family = QLatin1String( "calendar" ) ); /** Destroys the Calendar Resources. */ ~CalendarResources(); /** Loads all Incidences from the Resources. The Resources must be added first using either readConfig(KConfig *config), which adds the system Resources, or manually using resourceAdded(ResourceCalendar *resource). */ void load(); /** * Reloads all Incidences from all Resources. * @return true if the reload was successful; otherwise failure. */ bool reload(); /** @copydoc Calendar::close() */ void close(); /** Saves this Calendar. If the save is successful the Ticket is deleted. Otherwise, the caller must release the Ticket with releaseSaveTicket() to abandon the save operation or call save() to try the save again. @param ticket is a pointer to the Ticket object. @param incidence is a pointer to the Incidence object. If incidence is null, save the entire Calendar (all Resources) else only the specified Incidence is saved. @return true if the save was successful; false otherwise. */ virtual bool save( Ticket *ticket, Incidence *incidence = 0 ); /** @copydoc Calendar::save() */ bool save(); /** @copydoc Calendar::isSaving() */ bool isSaving(); /** Returns the CalendarResourceManager used by this calendar. */ CalendarResourceManager *resourceManager() const; /** Returns the Resource associated with a specified Incidence. @param incidence is a pointer to an Incidence whose Resource is to be located. */ ResourceCalendar *resource( Incidence *incidence ); /** Reads the Resources settings from a config file. @param config The KConfig object which points to the config file. If no object is given (@p config is 0) the standard config file is used. @note Call this method before load(). */ void readConfig( KConfig *config = 0 ); /** Set the destination policy such that Incidences are always added to the standard Resource. */ void setStandardDestinationPolicy(); /** Set the destination policy such that Incidences are added to a Resource which is queried. */ void setAskDestinationPolicy(); /** Returns the current parent for new dialogs. This is a bad hack, but we need to properly set the parent for the resource selection dialog. Otherwise the dialog will not be modal to the editor dialog in korganizer and the user can still work in the editor dialog (and thus crash korganizer). Afterwards we need to reset it (to avoid pointers to widgets that are already deleted) so we also need the accessor @return a pointer to the parent QWidget. @see setDialogParentWidget() */ QWidget *dialogParentWidget(); /** Set the widget parent for new dialogs. This is a bad hack, but we need to properly set the parent for the resource selection dialog. Otherwise the dialog will not be modal to the editor dialog in korganizer and the user can still work in the editor dialog (and thus crash korganizer). @param parent is a pointer to the parent QWidget. @see dialogparentWidget() */ void setDialogParentWidget( QWidget *parent ); /** Requests a ticket for saving the Calendar. If a ticket is returned the Calendar is locked for write access until save() or releaseSaveTicket() is called. @param resource is a pointer to the ResourceCalendar object. @return a pointer to a Ticket object indicating that the Calendar is locked for write access; otherwise a null pointer. @see releaseSaveTicket() */ Ticket *requestSaveTicket( ResourceCalendar *resource ); /** Releases the save Ticket. The Calendar is unlocked without saving. @param ticket is a pointer to a Ticket object. @see requestSaveTicket() */ virtual void releaseSaveTicket( Ticket *ticket ); /** Add an active Resource to the Calendar, and loads that resource if it is open. Additionally, emits the @b signalResourceAdded signal. @note This method must be public, because in-process added Resources do not emit the corresponding signal, so this method has to be called manually! @param resource is a pointer to the ResourceCalendar to add. @see signalResourceAdded() */ void resourceAdded( ResourceCalendar *resource ); // Incidence Specific Methods // /** @copydoc Calendar::addIncidence() */ bool addIncidence( Incidence *incidence ); /** Inserts an Incidence into a Calendar Resource. @param incidence is a pointer to the Incidence to insert. @param resource is a pointer to the ResourceCalendar to be added to. @return true if the Incidence was successfully inserted; false otherwise. */ bool addIncidence( Incidence *incidence, ResourceCalendar *resource ); /** @copydoc Calendar::beginChange() */ bool beginChange( Incidence *incidence ); /** @copydoc Calendar::endChange() */ bool endChange( Incidence *incidence ); // Event Specific Methods // /** @copydoc Calendar::addEvent() */ bool addEvent( Event *event ); /** Inserts an Event into a Calendar Resource. @param event is a pointer to the Event to insert. @param resource is a pointer to the ResourceCalendar to be added to. @return true if the Event was successfully inserted; false otherwise. @note In most cases use addIncidence( Incidence *incidence, ResourceCalendar *resource ) instead. */ bool addEvent( Event *event, ResourceCalendar *resource ); /** @copydoc Calendar::deleteEvent() */ bool deleteEvent( Event *event ); /** @copydoc Calendar::deleteAllEvents() */ void deleteAllEvents(); /** @copydoc Calendar::rawEvents(EventSortField, SortDirection) */ Event::List rawEvents( EventSortField sortField = EventSortUnsorted, SortDirection sortDirection = SortDirectionAscending ); /** @copydoc Calendar::rawEventsForDate( const KDateTime &) */ Event::List rawEventsForDate( const KDateTime &dt ); /** @copydoc Calendar::rawEvents(const QDate &, const QDate &, const KDateTime::Spec &, bool) */ Event::List rawEvents( const QDate &start, const QDate &end, const KDateTime::Spec ×pec = KDateTime::Spec(), bool inclusive = false ); /** @copydoc Calendar::rawEventsForDate(const QDate &,const KDateTime::Spec &,EventSortField,SortDirection) */ Event::List rawEventsForDate( const QDate &date, const KDateTime::Spec ×pec = KDateTime::Spec(), EventSortField sortField = EventSortUnsorted, SortDirection sortDirection = SortDirectionAscending ); /** @copydoc Calendar::event() */ Event *event( const QString &uid ); // Todo Specific Methods // /** @copydoc Calendar::addTodo() */ bool addTodo( Todo *todo ); /** Inserts a Todo into a Calendar Resource. @param todo is a pointer to the Todo to insert. @param resource is a pointer to the ResourceCalendar to be added to. @return true if the Todo was successfully inserted; false otherwise. @note In most cases use addIncidence( Incidence *incidence, ResourceCalendar *resource ) instead. */ bool addTodo( Todo *todo, ResourceCalendar *resource ); /** @copydoc Calendar::deleteTodo() */ bool deleteTodo( Todo *todo ); /** @copydoc Calendar::deleteAllTodos() */ void deleteAllTodos(); /** @copydoc Calendar::rawTodos() */ Todo::List rawTodos( TodoSortField sortField = TodoSortUnsorted, SortDirection sortDirection = SortDirectionAscending ); /** @copydoc Calendar::rawTodosForDate() */ Todo::List rawTodosForDate( const QDate &date ); /** @copydoc Calendar::todo() */ Todo *todo( const QString &uid ); // Journal Specific Methods // /** @copydoc Calendar::addJournal() */ bool addJournal( Journal *journal ); /** Inserts a Journal into a Calendar Resource. @param journal is a pointer to the Journal to insert. @param resource is a pointer to the ResourceCalendar to be added to. @return true if the Journal was successfully inserted; false otherwise. @note In most cases use addIncidence( Incidence *incidence, ResourceCalendar *resource ) instead. */ bool addJournal( Journal *journal, ResourceCalendar *resource ); /** @copydoc Calendar::deleteJournal() */ bool deleteJournal( Journal *journal ); /** @copydoc Calendar::deleteAllJournals() */ void deleteAllJournals(); /** @copydoc Calendar::rawJournals() */ Journal::List rawJournals( JournalSortField sortField = JournalSortUnsorted, SortDirection sortDirection = SortDirectionAscending ); /** @copydoc Calendar::rawJournalsForDate() */ Journal::List rawJournalsForDate( const QDate &date ); /** @copydoc Calendar::journal() */ Journal *journal( const QString &uid ); // Alarm Specific Methods // /** @copydoc Calendar::alarms() */ Alarm::List alarms( const KDateTime &from, const KDateTime &to ); /** Return a list of Alarms that occur before the specified timestamp. @param to is the ending timestamp. @return the list of Alarms occurring before the specified KDateTime. */ Alarm::List alarmsTo( const KDateTime &to ); using QObject::event; // prevent warning about hidden virtual method Q_SIGNALS: /** Signals that the Resource has been modified. @param resource is a pointer to a ResourceCalendar that was changed. @see resourceModified() */ void signalResourceModified( ResourceCalendar *resource ); /** Signals that an Incidence has been inserted to the Resource. @param resource is a pointer to a ResourceCalendar that was added. @see resourceAdded() */ void signalResourceAdded( ResourceCalendar *resource ); /** Signals that an Incidence has been removed from the Resource. @param resource is a pointer to a ResourceCalendar that was removed. @see resourceDeleted() */ void signalResourceDeleted( ResourceCalendar *resource ); /** Signals an error message. @param err is the error message. */ void signalErrorMessage( const QString &err ); protected: /** Connects all necessary signals and slots to the resource. @param resource is a pointer to a ResourceCalendar. */ void connectResource( ResourceCalendar *resource ); /** Emits the @b signalResourceModified signal for the specified @p resource. @param resource is a pointer to a ResourceCalendar that was changed. @see signalResourceDeleted() */ void resourceModified( ResourceCalendar *resource ); /** Emits the @b signalResourceDeleted signal for the specified @p resource. @param resource is a pointer to a ResourceCalendar that was removed. @see signalResourceModified() */ void resourceDeleted( ResourceCalendar *resource ); /** @copydoc Calendar::doSetTimeSpec() */ virtual void doSetTimeSpec( const KDateTime::Spec &timeSpec ); /** Increment the number of times this Resource has been changed by 1. @param resource is a pointer to the ResourceCalendar to be counted. @return the new number of times this Resource has been changed. @see decrementChangeCount() */ int incrementChangeCount( ResourceCalendar *resource ); /** Decrement the number of times this Resource has been changed by 1. @param resource is a pointer to the ResourceCalendar to be counted. @return the new number of times this Resource has been changed. @see incrementChangeCount() */ int decrementChangeCount( ResourceCalendar *resource ); protected Q_SLOTS: /** Emits the @b signalErrorMessage signal with an error message when an error occurs loading a ResourceCalendar. @param resource is a pointer to the ResourceCalendar that failed to load. @param err is the error message. @see slotSaveError() */ void slotLoadError( ResourceCalendar *resource, const QString &err ); /** Emits the @b signalErrorMessage signal with an error message when an error occurs saving a ResourceCalendar. @param resource is a pointer to the ResourceCalendar that failed to save. @param err is the error message. @see slotLoadError() */ void slotSaveError( ResourceCalendar *resource, const QString &err ); private: //@cond PRIVATE Q_DISABLE_COPY( CalendarResources ) class Private; Private *d; - bool mPendingDeleteFromResourceMap; //@endcond }; } #endif