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 <qintdict.h>
00033 #include <qmap.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 QWidget;
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                               QWidget *parent = 0  ) :
00078           mManager( manager ), mParent( parent ) {}
00079 
00080         virtual ResourceCalendar *destination( Incidence *incidence ) = 0;
00081         virtual QWidget *parent() { return mParent; }
00082         virtual void setParent( QWidget *newparent ) { mParent = newparent; }
00083 
00084       protected:
00085         CalendarResourceManager *resourceManager()
00086          { return mManager; }
00087 
00088       private:
00089         CalendarResourceManager *mManager;
00090         QWidget *mParent;
00091     };
00092 
00096     class StandardDestinationPolicy : public DestinationPolicy
00097     {
00098       public:
00099         StandardDestinationPolicy( CalendarResourceManager *manager,
00100                               QWidget *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                               QWidget *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 QString &timeZoneId,
00164       const QString &family = QString::fromLatin1( "calendar" ) );
00165 
00169     ~CalendarResources();
00170 
00176     void load();
00177 
00183     bool reload( const QString &tz );
00184 
00188     void close();
00189 
00203     virtual bool save( Ticket *ticket, Incidence *incidence = 0 );
00204 
00208     void save();
00209 
00215     bool isSaving();
00216 
00222     CalendarResourceManager *resourceManager() const
00223       { return mManager; }
00224 
00233     ResourceCalendar *resource( Incidence *incidence );
00234 
00243     void readConfig( KConfig *config = 0 );
00244 
00249     void setStandardDestinationPolicy();
00250 
00255     void setAskDestinationPolicy();
00256     
00265     QWidget *dialogParentWidget();
00272     void setDialogParentWidget( QWidget *parent );
00273 
00284     Ticket *requestSaveTicket( ResourceCalendar *resource );
00285 
00291     virtual void releaseSaveTicket( Ticket *ticket );
00292 
00301     void resourceAdded( ResourceCalendar *resource );
00302 
00303 // Incidence Specific Methods //
00304 
00312     bool addIncidence( Incidence *incidence );
00313 
00322     bool addIncidence( Incidence *incidence, ResourceCalendar *resource );
00323 
00329     bool beginChange( Incidence *incidence );
00330 
00336     bool endChange( Incidence *incidence );
00337 
00338 // Event Specific Methods //
00339 
00350     bool addEvent( Event *event );
00351 
00363     bool addEvent( Event *event, ResourceCalendar *resource );
00364 
00375     bool deleteEvent( Event *event );
00376 
00385     Event::List rawEvents(
00386       EventSortField sortField = EventSortUnsorted,
00387       SortDirection sortDirection = SortDirectionAscending );
00388 
00398     Event::List rawEventsForDate( const QDateTime &qdt );
00399 
00411     Event::List rawEvents( const QDate &start, const QDate &end,
00412                            bool inclusive = false );
00413 
00425     Event::List rawEventsForDate(
00426       const QDate &date,
00427       EventSortField sortField = EventSortUnsorted,
00428       SortDirection sortDirection = SortDirectionAscending );
00429 
00438     Event *event( const QString &uid );
00439 
00440 // Todo Specific Methods //
00441 
00452     bool addTodo( Todo *todo );
00453 
00465     bool addTodo( Todo *todo, ResourceCalendar *resource );
00466 
00477     bool deleteTodo( Todo *todo );
00478 
00487     Todo::List rawTodos( TodoSortField sortField = TodoSortUnsorted,
00488                          SortDirection sortDirection = SortDirectionAscending );
00489 
00498     Todo::List rawTodosForDate( const QDate &date );
00499 
00508     Todo *todo( const QString &uid );
00509 
00510 // Journal Specific Methods //
00511 
00522     bool addJournal( Journal *journal );
00523 
00535     bool addJournal( Journal *journal, ResourceCalendar *resource );
00536 
00547     bool deleteJournal( Journal *journal );
00548 
00557     Journal::List rawJournals(
00558       JournalSortField sortField = JournalSortUnsorted,
00559       SortDirection sortDirection = SortDirectionAscending );
00560 
00568     Journal::List rawJournalsForDate( const QDate &date );
00569 
00578     Journal *journal( const QString &uid );
00579 
00580 // Alarm Specific Methods //
00581 
00590     Alarm::List alarms( const QDateTime &from, const QDateTime &to );
00591 
00599     Alarm::List alarmsTo( const QDateTime &to );
00600 
00608     void setTimeZoneIdViewOnly( const QString& tz );
00609 
00610   signals:
00614     void signalResourceModified( ResourceCalendar *resource );
00615 
00619     void signalResourceAdded( ResourceCalendar *resource );
00620 
00624     void signalResourceDeleted( ResourceCalendar *resource );
00625 
00629     void signalErrorMessage( const QString &err );
00630 
00631   protected:
00632     void connectResource( ResourceCalendar *resource );
00633     void resourceModified( ResourceCalendar *resource );
00634     void resourceDeleted( ResourceCalendar *resource );
00635 
00648     virtual void doSetTimeZoneId( const QString &timeZoneId );
00649 
00657     int incrementChangeCount( ResourceCalendar *resource );
00658 
00666     int decrementChangeCount( ResourceCalendar *resource );
00667 
00668   protected slots:
00669     void slotLoadError( ResourceCalendar *resource, const QString &err );
00670     void slotSaveError( ResourceCalendar *resource, const QString &err );
00671 
00672   private:
00676     void init( const QString &family );
00677 
00678     bool mOpen;
00679 
00680     KRES::Manager<ResourceCalendar>* mManager;
00681     QMap <Incidence*, ResourceCalendar*> mResourceMap;
00682 
00683     DestinationPolicy *mDestinationPolicy;
00684     StandardDestinationPolicy *mStandardPolicy;
00685     AskDestinationPolicy *mAskPolicy;
00686 
00687     QMap<ResourceCalendar *, Ticket *> mTickets;
00688     QMap<ResourceCalendar *, int> mChangeCounts;
00689 
00690     class Private;
00691     Private *d;
00692 };
00693 
00694 }
00695 
00696 #endif