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           mManager( manager ) {}
00078 
00079         virtual ResourceCalendar *destination( Incidence *incidence ) = 0;
00080 
00081       protected:
00082         CalendarResourceManager *resourceManager()
00083          { return mManager; }
00084 
00085       private:
00086         CalendarResourceManager *mManager;
00087     };
00088 
00092     class StandardDestinationPolicy : public DestinationPolicy
00093     {
00094       public:
00095         StandardDestinationPolicy( CalendarResourceManager *manager ) :
00096           DestinationPolicy( manager ) {}
00097 
00098         ResourceCalendar *destination( Incidence *incidence );
00099 
00100       private:
00101         class Private;
00102         Private *d;
00103     };
00104 
00108     class AskDestinationPolicy : public DestinationPolicy
00109     {
00110       public:
00111         AskDestinationPolicy( CalendarResourceManager *manager,
00112                               QWidget *parent = 0 ) :
00113           DestinationPolicy( manager ), mParent( parent ) {}
00114 
00115         ResourceCalendar *destination( Incidence *incidence );
00116 
00117       private:
00118         QWidget *mParent;
00119 
00120         class Private;
00121         Private *d;
00122     };
00123 
00127     class Ticket
00128     {
00129         friend class CalendarResources;
00130       public:
00131         ResourceCalendar *resource() const
00132           { return mResource; }
00133 
00134       private:
00135         Ticket( ResourceCalendar *r ) : mResource( r ) {}
00136 
00137         ResourceCalendar *mResource;
00138 
00139         class Private;
00140         Private *d;
00141     };
00142 
00159     CalendarResources(
00160       const QString &timeZoneId,
00161       const QString &family = QString::fromLatin1( "calendar" ) );
00162 
00166     ~CalendarResources();
00167 
00173     void load();
00174 
00180     bool reload( const QString &tz );
00181 
00185     void close();
00186 
00200     virtual bool save( Ticket *ticket, Incidence *incidence = 0 );
00201 
00205     void save();
00206 
00212     bool isSaving();
00213 
00219     CalendarResourceManager *resourceManager() const
00220       { return mManager; }
00221 
00230     ResourceCalendar *resource( Incidence *incidence );
00231 
00240     void readConfig( KConfig *config = 0 );
00241 
00246     void setStandardDestinationPolicy();
00247 
00252     void setAskDestinationPolicy();
00253 
00264     Ticket *requestSaveTicket( ResourceCalendar *resource );
00265 
00271     virtual void releaseSaveTicket( Ticket *ticket );
00272 
00281     void resourceAdded( ResourceCalendar *resource );
00282 
00283 // Incidence Specific Methods //
00284 
00292     bool addIncidence( Incidence *incidence );
00293 
00302     bool addIncidence( Incidence *incidence, ResourceCalendar *resource );
00303 
00309     bool beginChange( Incidence *incidence );
00310 
00316     bool endChange( Incidence *incidence );
00317 
00318 // Event Specific Methods //
00319 
00330     bool addEvent( Event *event );
00331 
00343     bool addEvent( Event *event, ResourceCalendar *resource );
00344 
00355     bool deleteEvent( Event *event );
00356 
00365     Event::List rawEvents(
00366       EventSortField sortField = EventSortUnsorted,
00367       SortDirection sortDirection = SortDirectionAscending );
00368 
00378     Event::List rawEventsForDate( const QDateTime &qdt );
00379 
00391     Event::List rawEvents( const QDate &start, const QDate &end,
00392                            bool inclusive = false );
00393 
00405     Event::List rawEventsForDate(
00406       const QDate &date,
00407       EventSortField sortField = EventSortUnsorted,
00408       SortDirection sortDirection = SortDirectionAscending );
00409 
00418     Event *event( const QString &uid );
00419 
00420 // Todo Specific Methods //
00421 
00432     bool addTodo( Todo *todo );
00433 
00445     bool addTodo( Todo *todo, ResourceCalendar *resource );
00446 
00457     bool deleteTodo( Todo *todo );
00458 
00467     Todo::List rawTodos( TodoSortField sortField = TodoSortUnsorted,
00468                          SortDirection sortDirection = SortDirectionAscending );
00469 
00478     Todo::List rawTodosForDate( const QDate &date );
00479 
00488     Todo *todo( const QString &uid );
00489 
00490 // Journal Specific Methods //
00491 
00502     bool addJournal( Journal *journal );
00503 
00515     bool addJournal( Journal *journal, ResourceCalendar *resource );
00516 
00527     bool deleteJournal( Journal *journal );
00528 
00537     Journal::List rawJournals(
00538       JournalSortField sortField = JournalSortUnsorted,
00539       SortDirection sortDirection = SortDirectionAscending );
00540 
00548     Journal::List rawJournalsForDate( const QDate &date );
00549 
00558     Journal *journal( const QString &uid );
00559 
00560 // Alarm Specific Methods //
00561 
00570     Alarm::List alarms( const QDateTime &from, const QDateTime &to );
00571 
00579     Alarm::List alarmsTo( const QDateTime &to );
00580 
00588     void setTimeZoneIdViewOnly( const QString& tz );
00589 
00590   signals:
00594     void signalResourceModified( ResourceCalendar *resource );
00595 
00599     void signalResourceAdded( ResourceCalendar *resource );
00600 
00604     void signalResourceDeleted( ResourceCalendar *resource );
00605 
00609     void signalErrorMessage( const QString &err );
00610 
00611   protected:
00612     void connectResource( ResourceCalendar *resource );
00613     void resourceModified( ResourceCalendar *resource );
00614     void resourceDeleted( ResourceCalendar *resource );
00615 
00628     virtual void doSetTimeZoneId( const QString &timeZoneId );
00629 
00637     int incrementChangeCount( ResourceCalendar *resource );
00638 
00646     int decrementChangeCount( ResourceCalendar *resource );
00647 
00648   protected slots:
00649     void slotLoadError( ResourceCalendar *resource, const QString &err );
00650     void slotSaveError( ResourceCalendar *resource, const QString &err );
00651 
00652   private:
00656     void init( const QString &family );
00657 
00658     bool mOpen;
00659 
00660     KRES::Manager<ResourceCalendar>* mManager;
00661     QMap <Incidence*, ResourceCalendar*> mResourceMap;
00662 
00663     DestinationPolicy *mDestinationPolicy;
00664     StandardDestinationPolicy *mStandardPolicy;
00665     AskDestinationPolicy *mAskPolicy;
00666 
00667     QMap<ResourceCalendar *, Ticket *> mTickets;
00668     QMap<ResourceCalendar *, int> mChangeCounts;
00669 
00670     class Private;
00671     Private *d;
00672 };
00673 
00674 }
00675 
00676 #endif
KDE Home | KDE Accessibility Home | Description of Access Keys