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   public:
00073     class DestinationPolicy
00074     {
00075       public:
00076         DestinationPolicy( CalendarResourceManager *manager,
00077                               TQWidget *parent = 0  ) :
00078           mManager( manager ), mParent( parent ) {}
00079 
00080         virtual ResourceCalendar *destination( Incidence *incidence ) = 0;
00081         virtual TQWidget *parent() { return mParent; }
00082         virtual void setParent( TQWidget *newparent ) { mParent = newparent; }
00083         bool hasCalendarResources();
00084       protected:
00085         CalendarResourceManager *resourceManager()
00086          { return mManager; }
00087 
00088       private:
00089         CalendarResourceManager *mManager;
00090         TQWidget *mParent;
00091     };
00092 
00096     class StandardDestinationPolicy : public DestinationPolicy
00097     {
00098       public:
00099         StandardDestinationPolicy( CalendarResourceManager *manager,
00100                               TQWidget *parent = 0  ) :
00101           DestinationPolicy( manager, parent ) {}
00102 
00103         ResourceCalendar *destination( Incidence *incidence );
00104 
00105       private:
00106         class Private;
00107         Private *d;
00108     };
00109 
00113     class AskDestinationPolicy : public DestinationPolicy
00114     {
00115       public:
00116         AskDestinationPolicy( CalendarResourceManager *manager,
00117                               TQWidget *parent = 0 ) :
00118           DestinationPolicy( manager, parent ) {}
00119 
00120         ResourceCalendar *destination( Incidence *incidence );
00121 
00122       private:
00123         class Private;
00124         Private *d;
00125     };
00126 
00130     class Ticket
00131     {
00132         friend class CalendarResources;
00133       public:
00134         ResourceCalendar *resource() const
00135           { return mResource; }
00136 
00137       private:
00138         Ticket( ResourceCalendar *r ) : mResource( r ) {}
00139 
00140         ResourceCalendar *mResource;
00141 
00142         class Private;
00143         Private *d;
00144     };
00145 
00162     CalendarResources(
00163       const TQString &timeZoneId,
00164       const TQString &family = TQString::fromLatin1( "calendar" ) );
00165 
00169     ~CalendarResources();
00170 
00176     void load();
00177 
00183     bool reload( const TQString &tz );
00184 
00188     void close();
00189 
00193     void closeEvents();
00194 
00198     void closeTodos();
00199 
00203     void closeJournals();
00204 
00218     virtual bool save( Ticket *ticket, Incidence *incidence = 0 );
00219 
00223     void save();
00224 
00230     bool isSaving();
00231 
00237     CalendarResourceManager *resourceManager() const
00238       { return mManager; }
00239 
00248     ResourceCalendar *resource( Incidence *incidence );
00249 
00258     void readConfig( KConfig *config = 0 );
00259 
00264     void setStandardDestinationPolicy();
00265 
00270     void setAskDestinationPolicy();
00271 
00280     TQWidget *dialogParentWidget();
00287     void setDialogParentWidget( TQWidget *parent );
00288 
00299     Ticket *requestSaveTicket( ResourceCalendar *resource );
00300 
00306     virtual void releaseSaveTicket( Ticket *ticket );
00307 
00316     void resourceAdded( ResourceCalendar *resource );
00317 
00318 // Incidence Specific Methods //
00319 
00327     bool addIncidence( Incidence *incidence );
00328 
00339     KDE_DEPRECATED bool addIncidence( Incidence *incidence, ResourceCalendar *resource );
00340 
00351     bool addIncidence( Incidence *incidence,
00352                        ResourceCalendar *resource, const TQString &subresource );
00353 
00361     KDE_DEPRECATED bool beginChange( Incidence *incidence );
00362 
00375     bool beginChange( Incidence *incidence, ResourceCalendar *resource, const TQString &subresource );
00376 
00384     KDE_DEPRECATED bool endChange( Incidence *incidence );
00385 
00398     bool endChange( Incidence *incidence,
00399                     ResourceCalendar *resource, const TQString &subresource );
00400 
00401 // Event Specific Methods //
00402 
00413     bool addEvent( Event *event );
00414 
00426     KDE_DEPRECATED bool addEvent( Event *event, ResourceCalendar *resource );
00427 
00441     bool addEvent( Event *event, ResourceCalendar *resource, const TQString &subresource );
00442 
00453     bool deleteEvent( Event *event );
00454 
00463     Event::List rawEvents(
00464       EventSortField sortField = EventSortUnsorted,
00465       SortDirection sortDirection = SortDirectionAscending );
00466 
00476     Event::List rawEventsForDate( const TQDateTime &qdt );
00477 
00489     Event::List rawEvents( const TQDate &start, const TQDate &end,
00490                            bool inclusive = false );
00491 
00503     Event::List rawEventsForDate(
00504       const TQDate &date,
00505       EventSortField sortField = EventSortUnsorted,
00506       SortDirection sortDirection = SortDirectionAscending );
00507 
00516     Event *event( const TQString &uid );
00517 
00518 // Todo Specific Methods //
00519 
00530     bool addTodo( Todo *todo );
00531 
00543     KDE_DEPRECATED bool addTodo( Todo *todo, ResourceCalendar *resource );
00544 
00558     bool addTodo( Todo *todo, ResourceCalendar *resource, const TQString &subresource );
00559 
00570     bool deleteTodo( Todo *todo );
00571 
00580     Todo::List rawTodos( TodoSortField sortField = TodoSortUnsorted,
00581                          SortDirection sortDirection = SortDirectionAscending );
00582 
00591     Todo::List rawTodosForDate( const TQDate &date );
00592 
00601     Todo *todo( const TQString &uid );
00602 
00603 // Journal Specific Methods //
00604 
00615     bool addJournal( Journal *journal );
00616 
00628     KDE_DEPRECATED bool addJournal( Journal *journal, ResourceCalendar *resource );
00629 
00643     bool addJournal( Journal *journal, ResourceCalendar *resource, const TQString &subresource );
00644 
00655     bool deleteJournal( Journal *journal );
00656 
00665     Journal::List rawJournals(
00666       JournalSortField sortField = JournalSortUnsorted,
00667       SortDirection sortDirection = SortDirectionAscending );
00668 
00676     Journal::List rawJournalsForDate( const TQDate &date );
00677 
00686     Journal *journal( const TQString &uid );
00687 
00688 // Alarm Specific Methods //
00689 
00698     Alarm::List alarms( const TQDateTime &from, const TQDateTime &to );
00699 
00707     Alarm::List alarmsTo( const TQDateTime &to );
00708 
00716     void setTimeZoneIdViewOnly( const TQString& tz );
00717 
00718   //issue 2508
00719     bool hasCalendarResources();
00720   signals:
00724     void signalResourceModified( ResourceCalendar *resource );
00725 
00729     void signalResourceAdded( ResourceCalendar *resource );
00730 
00734     void signalResourceDeleted( ResourceCalendar *resource );
00735 
00739     void signalErrorMessage( const TQString &err );
00740 
00741   protected:
00742     void connectResource( ResourceCalendar *resource );
00743     void resourceModified( ResourceCalendar *resource );
00744     void resourceDeleted( ResourceCalendar *resource );
00745 
00758     virtual void doSetTimeZoneId( const TQString &timeZoneId );
00759 
00767     int incrementChangeCount( ResourceCalendar *resource );
00768 
00776     int decrementChangeCount( ResourceCalendar *resource );
00777 
00778   protected slots:
00779     void slotLoadError( ResourceCalendar *resource, const TQString &err );
00780     void slotSaveError( ResourceCalendar *resource, const TQString &err );
00781 
00788     void beginAddingIncidences();
00789 
00794     void endAddingIncidences();
00795 
00796   private:
00797 
00801     void init( const TQString &family );
00802 
00803     bool mOpen;
00804 
00805     KRES::Manager<ResourceCalendar>* mManager;
00806     TQMap <Incidence*, ResourceCalendar*> mResourceMap;
00807 
00808     DestinationPolicy *mDestinationPolicy;
00809     StandardDestinationPolicy *mStandardPolicy;
00810     AskDestinationPolicy *mAskPolicy;
00811     bool mPendingDeleteFromResourceMap;
00812 
00813     TQMap<ResourceCalendar *, Ticket *> mTickets;
00814     TQMap<ResourceCalendar *, int> mChangeCounts;
00815 
00816     class Private;
00817     Private *d;
00818 };
00819 
00820 }
00821 
00822 #endif