libkcal

calendarresources.h

Go to the documentation of this file.
00001 /*
00002     This file is part of libkcal.
00003 
00004     Copyright (c) 2003 Cornelius Schumacher <schumacher@kde.org>
00005     Copyright (C) 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com>
00006 
00007     This library is free software; you can redistribute it and/or
00008     modify it under the terms of the GNU Library General Public
00009     License as published by the Free Software Foundation; either
00010     version 2 of the License, or (at your option) any later version.
00011 
00012     This library is distributed in the hope that it will be useful,
00013     but WITHOUT ANY WARRANTY; without even the implied warranty of
00014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015     Library General Public License for more details.
00016 
00017     You should have received a copy of the GNU Library General Public License
00018     along with this library; see the file COPYING.LIB.  If not, write to
00019     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00020     Boston, MA 02110-1301, USA.
00021 */
00029 #ifndef KCAL_CALENDARRESOURCES_H
00030 #define KCAL_CALENDARRESOURCES_H
00031 
00032 #include <tqintdict.h>
00033 #include <tqmap.h>
00034 
00035 #include "calendar.h"
00036 #include "resourcecalendar.h"
00037 
00038 #include "libkcal_export.h"
00039 
00040 #include <kresources/manager.h>
00041 
00042 class TQWidget;
00043 
00048 namespace KCal {
00049 
00050 class CalFormat;
00051 
00064 class LIBKCAL_EXPORT CalendarResources :
00065       public Calendar,
00066       public KRES::ManagerObserver<ResourceCalendar>
00067 {
00068   Q_OBJECT
00069   TQ_OBJECT
00070   public:
00074     class DestinationPolicy
00075     {
00076       public:
00077         DestinationPolicy( CalendarResourceManager *manager,
00078                               TQWidget *parent = 0  ) :
00079           mManager( manager ), mParent( parent ) {}
00080 
00081         virtual ResourceCalendar *destination( Incidence *incidence ) = 0;
00082         virtual TQWidget *parent() { return mParent; }
00083         virtual void setParent( TQWidget *newparent ) { mParent = newparent; }
00084         bool hasCalendarResources();
00085       protected:
00086         CalendarResourceManager *resourceManager()
00087          { return mManager; }
00088 
00089       private:
00090         CalendarResourceManager *mManager;
00091         TQWidget *mParent;
00092     };
00093 
00097     class StandardDestinationPolicy : public DestinationPolicy
00098     {
00099       public:
00100         StandardDestinationPolicy( CalendarResourceManager *manager,
00101                               TQWidget *parent = 0  ) :
00102           DestinationPolicy( manager, parent ) {}
00103 
00104         ResourceCalendar *destination( Incidence *incidence );
00105 
00106       private:
00107         class Private;
00108         Private *d;
00109     };
00110 
00114     class AskDestinationPolicy : public DestinationPolicy
00115     {
00116       public:
00117         AskDestinationPolicy( CalendarResourceManager *manager,
00118                               TQWidget *parent = 0 ) :
00119           DestinationPolicy( manager, parent ) {}
00120 
00121         ResourceCalendar *destination( Incidence *incidence );
00122 
00123       private:
00124         class Private;
00125         Private *d;
00126     };
00127 
00131     class Ticket
00132     {
00133         friend class CalendarResources;
00134       public:
00135         ResourceCalendar *resource() const
00136           { return mResource; }
00137 
00138       private:
00139         Ticket( ResourceCalendar *r ) : mResource( r ) {}
00140 
00141         ResourceCalendar *mResource;
00142 
00143         class Private;
00144         Private *d;
00145     };
00146 
00163     CalendarResources(
00164       const TQString &timeZoneId,
00165       const TQString &family = TQString::fromLatin1( "calendar" ) );
00166 
00170     ~CalendarResources();
00171 
00177     void load();
00178 
00184     bool reload( const TQString &tz );
00185 
00189     void close();
00190 
00194     void closeEvents();
00195 
00199     void closeTodos();
00200 
00204     void closeJournals();
00205 
00219     virtual bool save( Ticket *ticket, Incidence *incidence = 0 );
00220 
00224     void save();
00225 
00231     bool isSaving();
00232 
00238     CalendarResourceManager *resourceManager() const
00239       { return mManager; }
00240 
00249     ResourceCalendar *resource( Incidence *incidence );
00250 
00259     void readConfig( KConfig *config = 0 );
00260 
00265     void setStandardDestinationPolicy();
00266 
00271     void setAskDestinationPolicy();
00272 
00281     TQWidget *dialogParentWidget();
00288     void setDialogParentWidget( TQWidget *parent );
00289 
00300     Ticket *requestSaveTicket( ResourceCalendar *resource );
00301 
00307     virtual void releaseSaveTicket( Ticket *ticket );
00308 
00317     void resourceAdded( ResourceCalendar *resource );
00318 
00319 // Incidence Specific Methods //
00320 
00328     bool addIncidence( Incidence *incidence );
00329 
00340     KDE_DEPRECATED bool addIncidence( Incidence *incidence, ResourceCalendar *resource );
00341 
00352     bool addIncidence( Incidence *incidence,
00353                        ResourceCalendar *resource, const TQString &subresource );
00354 
00362     KDE_DEPRECATED bool beginChange( Incidence *incidence );
00363 
00376     bool beginChange( Incidence *incidence, ResourceCalendar *resource, const TQString &subresource );
00377 
00385     KDE_DEPRECATED bool endChange( Incidence *incidence );
00386 
00399     bool endChange( Incidence *incidence,
00400                     ResourceCalendar *resource, const TQString &subresource );
00401 
00402 // Event Specific Methods //
00403 
00414     bool addEvent( Event *event );
00415 
00427     KDE_DEPRECATED bool addEvent( Event *event, ResourceCalendar *resource );
00428 
00442     bool addEvent( Event *event, ResourceCalendar *resource, const TQString &subresource );
00443 
00454     bool deleteEvent( Event *event );
00455 
00464     Event::List rawEvents(
00465       EventSortField sortField = EventSortUnsorted,
00466       SortDirection sortDirection = SortDirectionAscending );
00467 
00477     Event::List rawEventsForDate( const TQDateTime &qdt );
00478 
00490     Event::List rawEvents( const TQDate &start, const TQDate &end,
00491                            bool inclusive = false );
00492 
00504     Event::List rawEventsForDate(
00505       const TQDate &date,
00506       EventSortField sortField = EventSortUnsorted,
00507       SortDirection sortDirection = SortDirectionAscending );
00508 
00517     Event *event( const TQString &uid );
00518 
00519 // Todo Specific Methods //
00520 
00531     bool addTodo( Todo *todo );
00532 
00544     KDE_DEPRECATED bool addTodo( Todo *todo, ResourceCalendar *resource );
00545 
00559     bool addTodo( Todo *todo, ResourceCalendar *resource, const TQString &subresource );
00560 
00571     bool deleteTodo( Todo *todo );
00572 
00581     Todo::List rawTodos( TodoSortField sortField = TodoSortUnsorted,
00582                          SortDirection sortDirection = SortDirectionAscending );
00583 
00592     Todo::List rawTodosForDate( const TQDate &date );
00593 
00602     Todo *todo( const TQString &uid );
00603 
00604 // Journal Specific Methods //
00605 
00616     bool addJournal( Journal *journal );
00617 
00629     KDE_DEPRECATED bool addJournal( Journal *journal, ResourceCalendar *resource );
00630 
00644     bool addJournal( Journal *journal, ResourceCalendar *resource, const TQString &subresource );
00645 
00656     bool deleteJournal( Journal *journal );
00657 
00666     Journal::List rawJournals(
00667       JournalSortField sortField = JournalSortUnsorted,
00668       SortDirection sortDirection = SortDirectionAscending );
00669 
00677     Journal::List rawJournalsForDate( const TQDate &date );
00678 
00687     Journal *journal( const TQString &uid );
00688 
00689 // Alarm Specific Methods //
00690 
00699     Alarm::List alarms( const TQDateTime &from, const TQDateTime &to );
00700 
00708     Alarm::List alarmsTo( const TQDateTime &to );
00709 
00717     void setTimeZoneIdViewOnly( const TQString& tz );
00718 
00719   //issue 2508
00720     bool hasCalendarResources();
00721   signals:
00725     void signalResourceModified( ResourceCalendar *resource );
00726 
00730     void signalResourceAdded( ResourceCalendar *resource );
00731 
00735     void signalResourceDeleted( ResourceCalendar *resource );
00736 
00740     void signalErrorMessage( const TQString &err );
00741 
00742   protected:
00743     void connectResource( ResourceCalendar *resource );
00744     void resourceModified( ResourceCalendar *resource );
00745     void resourceDeleted( ResourceCalendar *resource );
00746 
00759     virtual void doSetTimeZoneId( const TQString &timeZoneId );
00760 
00768     int incrementChangeCount( ResourceCalendar *resource );
00769 
00777     int decrementChangeCount( ResourceCalendar *resource );
00778 
00779   protected slots:
00780     void slotLoadError( ResourceCalendar *resource, const TQString &err );
00781     void slotSaveError( ResourceCalendar *resource, const TQString &err );
00782 
00789     void beginAddingIncidences();
00790 
00795     void endAddingIncidences();
00796 
00797   private:
00798 
00802     void init( const TQString &family );
00803 
00804     bool mOpen;
00805 
00806     KRES::Manager<ResourceCalendar>* mManager;
00807     TQMap <Incidence*, ResourceCalendar*> mResourceMap;
00808 
00809     DestinationPolicy *mDestinationPolicy;
00810     StandardDestinationPolicy *mStandardPolicy;
00811     AskDestinationPolicy *mAskPolicy;
00812     bool mPendingDeleteFromResourceMap;
00813 
00814     TQMap<ResourceCalendar *, Ticket *> mTickets;
00815     TQMap<ResourceCalendar *, int> mChangeCounts;
00816 
00817     class Private;
00818     Private *d;
00819 };
00820 
00821 }
00822 
00823 #endif