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         bool hasCalendarResources();
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 
00324     KDE_DEPRECATED bool addIncidence( Incidence *incidence, ResourceCalendar *resource );
00325 
00336     bool addIncidence( Incidence *incidence,
00337                        ResourceCalendar *resource, const QString &subresource );
00338 
00346     KDE_DEPRECATED bool beginChange( Incidence *incidence );
00347 
00360     bool beginChange( Incidence *incidence, ResourceCalendar *resource, const QString &subresource );
00361 
00369     KDE_DEPRECATED bool endChange( Incidence *incidence );
00370 
00383     bool endChange( Incidence *incidence,
00384                     ResourceCalendar *resource, const QString &subresource );
00385 
00386 // Event Specific Methods //
00387 
00398     bool addEvent( Event *event );
00399 
00411     KDE_DEPRECATED bool addEvent( Event *event, ResourceCalendar *resource );
00412 
00426     bool addEvent( Event *event, ResourceCalendar *resource, const QString &subresource );
00427 
00438     bool deleteEvent( Event *event );
00439 
00448     Event::List rawEvents(
00449       EventSortField sortField = EventSortUnsorted,
00450       SortDirection sortDirection = SortDirectionAscending );
00451 
00461     Event::List rawEventsForDate( const QDateTime &qdt );
00462 
00474     Event::List rawEvents( const QDate &start, const QDate &end,
00475                            bool inclusive = false );
00476 
00488     Event::List rawEventsForDate(
00489       const QDate &date,
00490       EventSortField sortField = EventSortUnsorted,
00491       SortDirection sortDirection = SortDirectionAscending );
00492 
00501     Event *event( const QString &uid );
00502 
00503 // Todo Specific Methods //
00504 
00515     bool addTodo( Todo *todo );
00516 
00528     KDE_DEPRECATED bool addTodo( Todo *todo, ResourceCalendar *resource );
00529 
00543     bool addTodo( Todo *todo, ResourceCalendar *resource, const QString &subresource );
00544 
00555     bool deleteTodo( Todo *todo );
00556 
00565     Todo::List rawTodos( TodoSortField sortField = TodoSortUnsorted,
00566                          SortDirection sortDirection = SortDirectionAscending );
00567 
00576     Todo::List rawTodosForDate( const QDate &date );
00577 
00586     Todo *todo( const QString &uid );
00587 
00588 // Journal Specific Methods //
00589 
00600     bool addJournal( Journal *journal );
00601 
00613     KDE_DEPRECATED bool addJournal( Journal *journal, ResourceCalendar *resource );
00614 
00628     bool addJournal( Journal *journal, ResourceCalendar *resource, const QString &subresource );
00629 
00640     bool deleteJournal( Journal *journal );
00641 
00650     Journal::List rawJournals(
00651       JournalSortField sortField = JournalSortUnsorted,
00652       SortDirection sortDirection = SortDirectionAscending );
00653 
00661     Journal::List rawJournalsForDate( const QDate &date );
00662 
00671     Journal *journal( const QString &uid );
00672 
00673 // Alarm Specific Methods //
00674 
00683     Alarm::List alarms( const QDateTime &from, const QDateTime &to );
00684 
00692     Alarm::List alarmsTo( const QDateTime &to );
00693 
00701     void setTimeZoneIdViewOnly( const QString& tz );
00702 
00703   //issue 2508
00704     bool hasCalendarResources();
00705   signals:
00709     void signalResourceModified( ResourceCalendar *resource );
00710 
00714     void signalResourceAdded( ResourceCalendar *resource );
00715 
00719     void signalResourceDeleted( ResourceCalendar *resource );
00720 
00724     void signalErrorMessage( const QString &err );
00725 
00726   protected:
00727     void connectResource( ResourceCalendar *resource );
00728     void resourceModified( ResourceCalendar *resource );
00729     void resourceDeleted( ResourceCalendar *resource );
00730 
00743     virtual void doSetTimeZoneId( const QString &timeZoneId );
00744 
00752     int incrementChangeCount( ResourceCalendar *resource );
00753 
00761     int decrementChangeCount( ResourceCalendar *resource );
00762 
00763   protected slots:
00764     void slotLoadError( ResourceCalendar *resource, const QString &err );
00765     void slotSaveError( ResourceCalendar *resource, const QString &err );
00766 
00773     void beginAddingIncidences();
00774 
00779     void endAddingIncidences();
00780 
00781   private:
00782 
00786     void init( const QString &family );
00787 
00788     bool mOpen;
00789 
00790     KRES::Manager<ResourceCalendar>* mManager;
00791     QMap <Incidence*, ResourceCalendar*> mResourceMap;
00792 
00793     DestinationPolicy *mDestinationPolicy;
00794     StandardDestinationPolicy *mStandardPolicy;
00795     AskDestinationPolicy *mAskPolicy;
00796     bool mPendingDeleteFromResourceMap;
00797 
00798     QMap<ResourceCalendar *, Ticket *> mTickets;
00799     QMap<ResourceCalendar *, int> mChangeCounts;
00800 
00801     class Private;
00802     Private *d;
00803 };
00804 
00805 }
00806 
00807 #endif
KDE Home | KDE Accessibility Home | Description of Access Keys