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 "exceptions.h"
00037 #include "resourcecalendar.h"
00038 
00039 #include "libkcal_export.h"
00040 
00041 #include <kresources/manager.h>
00042 
00043 class QWidget;
00044 
00049 namespace KCal {
00050 
00051 class CalFormat;
00052 
00065 class LIBKCAL_EXPORT CalendarResources :
00066       public Calendar,
00067       public KRES::ManagerObserver<ResourceCalendar>
00068 {
00069   Q_OBJECT
00070   public:
00074     class DestinationPolicy
00075     {
00076       public:
00077         DestinationPolicy( CalendarResourceManager *manager,
00078                               QWidget *parent = 0  ) :
00079           mManager( manager ), mParent( parent ) {}
00080 
00081         virtual ResourceCalendar *destination( Incidence *incidence ) = 0;
00082         virtual QWidget *parent() { return mParent; }
00083         virtual void setParent( QWidget *newparent ) { mParent = newparent; }
00084         bool hasCalendarResources();
00085       protected:
00086         CalendarResourceManager *resourceManager()
00087          { return mManager; }
00088 
00089       private:
00090         CalendarResourceManager *mManager;
00091         QWidget *mParent;
00092     };
00093 
00097     class StandardDestinationPolicy : public DestinationPolicy
00098     {
00099       public:
00100         StandardDestinationPolicy( CalendarResourceManager *manager,
00101                               QWidget *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                               QWidget *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 QString &timeZoneId,
00165       const QString &family = QString::fromLatin1( "calendar" ) );
00166 
00170     ~CalendarResources();
00171 
00175     void clearException();
00176 
00181     ErrorFormat *exception();
00182 
00188     void load();
00189 
00195     bool reload( const QString &tz );
00196 
00200     void close();
00201 
00215     virtual bool save( Ticket *ticket, Incidence *incidence = 0 );
00216 
00220     void save();
00221 
00227     bool isSaving();
00228 
00234     CalendarResourceManager *resourceManager() const
00235       { return mManager; }
00236 
00245     ResourceCalendar *resource( Incidence *incidence );
00246 
00255     void readConfig( KConfig *config = 0 );
00256 
00261     void setStandardDestinationPolicy();
00262 
00267     void setAskDestinationPolicy();
00268 
00277     QWidget *dialogParentWidget();
00284     void setDialogParentWidget( QWidget *parent );
00285 
00296     Ticket *requestSaveTicket( ResourceCalendar *resource );
00297 
00303     virtual void releaseSaveTicket( Ticket *ticket );
00304 
00313     void resourceAdded( ResourceCalendar *resource );
00314 
00315 // Incidence Specific Methods //
00316 
00324     bool addIncidence( Incidence *incidence );
00325 
00336     KDE_DEPRECATED bool addIncidence( Incidence *incidence, ResourceCalendar *resource );
00337 
00348     bool addIncidence( Incidence *incidence,
00349                        ResourceCalendar *resource, const QString &subresource );
00350 
00358     KDE_DEPRECATED bool beginChange( Incidence *incidence );
00359 
00372     bool beginChange( Incidence *incidence, ResourceCalendar *resource, const QString &subresource );
00373 
00381     KDE_DEPRECATED bool endChange( Incidence *incidence );
00382 
00395     bool endChange( Incidence *incidence,
00396                     ResourceCalendar *resource, const QString &subresource );
00397 
00398 // Event Specific Methods //
00399 
00410     bool addEvent( Event *event );
00411 
00423     KDE_DEPRECATED bool addEvent( Event *event, ResourceCalendar *resource );
00424 
00438     bool addEvent( Event *event, ResourceCalendar *resource, const QString &subresource );
00439 
00450     bool deleteEvent( Event *event );
00451 
00460     Event::List rawEvents(
00461       EventSortField sortField = EventSortUnsorted,
00462       SortDirection sortDirection = SortDirectionAscending );
00463 
00473     Event::List rawEventsForDate( const QDateTime &qdt );
00474 
00486     Event::List rawEvents( const QDate &start, const QDate &end,
00487                            bool inclusive = false );
00488 
00500     Event::List rawEventsForDate(
00501       const QDate &date,
00502       EventSortField sortField = EventSortUnsorted,
00503       SortDirection sortDirection = SortDirectionAscending );
00504 
00513     Event *event( const QString &uid );
00514 
00515 // Todo Specific Methods //
00516 
00527     bool addTodo( Todo *todo );
00528 
00540     KDE_DEPRECATED bool addTodo( Todo *todo, ResourceCalendar *resource );
00541 
00555     bool addTodo( Todo *todo, ResourceCalendar *resource, const QString &subresource );
00556 
00567     bool deleteTodo( Todo *todo );
00568 
00577     Todo::List rawTodos( TodoSortField sortField = TodoSortUnsorted,
00578                          SortDirection sortDirection = SortDirectionAscending );
00579 
00588     Todo::List rawTodosForDate( const QDate &date );
00589 
00598     Todo *todo( const QString &uid );
00599 
00600 // Journal Specific Methods //
00601 
00612     bool addJournal( Journal *journal );
00613 
00625     KDE_DEPRECATED bool addJournal( Journal *journal, ResourceCalendar *resource );
00626 
00640     bool addJournal( Journal *journal, ResourceCalendar *resource, const QString &subresource );
00641 
00652     bool deleteJournal( Journal *journal );
00653 
00662     Journal::List rawJournals(
00663       JournalSortField sortField = JournalSortUnsorted,
00664       SortDirection sortDirection = SortDirectionAscending );
00665 
00673     Journal::List rawJournalsForDate( const QDate &date );
00674 
00683     Journal *journal( const QString &uid );
00684 
00685 // Alarm Specific Methods //
00686 
00695     Alarm::List alarms( const QDateTime &from, const QDateTime &to );
00696 
00704     Alarm::List alarmsTo( const QDateTime &to );
00705 
00713     void setTimeZoneIdViewOnly( const QString& tz );
00714 
00715   //issue 2508
00716     bool hasCalendarResources();
00717   signals:
00721     void signalResourceModified( ResourceCalendar *resource );
00722 
00726     void signalResourceAdded( ResourceCalendar *resource );
00727 
00731     void signalResourceDeleted( ResourceCalendar *resource );
00732 
00736     void signalErrorMessage( const QString &err );
00737 
00738   protected:
00739     void connectResource( ResourceCalendar *resource );
00740     void resourceModified( ResourceCalendar *resource );
00741     void resourceDeleted( ResourceCalendar *resource );
00742 
00755     virtual void doSetTimeZoneId( const QString &timeZoneId );
00756 
00764     int incrementChangeCount( ResourceCalendar *resource );
00765 
00773     int decrementChangeCount( ResourceCalendar *resource );
00774 
00775   protected slots:
00776     void slotLoadError( ResourceCalendar *resource, const QString &err );
00777     void slotSaveError( ResourceCalendar *resource, const QString &err );
00778 
00779   private:
00783     void init( const QString &family );
00784 
00785     bool mOpen;
00786 
00787     KRES::Manager<ResourceCalendar>* mManager;
00788     QMap <Incidence*, ResourceCalendar*> mResourceMap;
00789 
00790     DestinationPolicy *mDestinationPolicy;
00791     StandardDestinationPolicy *mStandardPolicy;
00792     AskDestinationPolicy *mAskPolicy;
00793     bool mPendingDeleteFromResourceMap;
00794 
00795     QMap<ResourceCalendar *, Ticket *> mTickets;
00796     QMap<ResourceCalendar *, int> mChangeCounts;
00797     ErrorFormat *mException;
00798 
00799     class Private;
00800     Private *d;
00801 };
00802 
00803 }
00804 
00805 #endif
KDE Home | KDE Accessibility Home | Description of Access Keys