libkcal

calendar.h

Go to the documentation of this file.
00001 /*
00002     This file is part of libkcal.
00003 
00004     Copyright (c) 1998 Preston Brown <pbrown@kde.org>
00005     Copyright (c) 2001,2003,2004 Cornelius Schumacher <schumacher@kde.org>
00006     Copyright (C) 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com>
00007 
00008     This library is free software; you can redistribute it and/or
00009     modify it under the terms of the GNU Library General Public
00010     License as published by the Free Software Foundation; either
00011     version 2 of the License, or (at your option) any later version.
00012 
00013     This library is distributed in the hope that it will be useful,
00014     but WITHOUT ANY WARRANTY; without even the implied warranty of
00015     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016     Library General Public License for more details.
00017 
00018     You should have received a copy of the GNU Library General Public License
00019     along with this library; see the file COPYING.LIB.  If not, write to
00020     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00021     Boston, MA 02110-1301, USA.
00022 */
00031 #ifndef KCAL_CALENDAR_H
00032 #define KCAL_CALENDAR_H
00033 
00034 #include "exceptions.h"
00035 #include "customproperties.h"
00036 #include "event.h"
00037 #include "todo.h"
00038 #include "journal.h"
00039 #include "kcalversion.h"
00040 #include "person.h"
00041 
00042 #include <kdepimmacros.h>
00043 
00044 #include <tqobject.h>
00045 #include <tqstring.h>
00046 #include <tqdatetime.h>
00047 #include <tqptrlist.h>
00048 #include <tqdict.h>
00049 
00054 namespace KCal {
00055 
00056 class CalFilter;
00057 
00062 enum SortDirection
00063 {
00065   SortDirectionAscending,
00067   SortDirectionDescending
00068 };
00069 
00074 enum EventSortField
00075 {
00077   EventSortUnsorted,
00079   EventSortStartDate,
00081   EventSortEndDate,
00083   EventSortSummary
00084 };
00085 
00090 enum TodoSortField
00091 {
00093   TodoSortUnsorted,
00095   TodoSortStartDate,
00097   TodoSortDueDate,
00099   TodoSortPriority,
00101   TodoSortPercentComplete,
00103   TodoSortSummary
00104 };
00105 
00110 enum JournalSortField
00111 {
00113   JournalSortUnsorted,
00115   JournalSortDate,
00117   JournalSortSummary
00118 };
00119 
00169 class LIBKCAL_EXPORT Calendar : public TQObject, public CustomProperties,
00170                                 public IncidenceBase::Observer
00171 {
00172     Q_OBJECT
00173 
00174   public:
00175 
00190     Calendar( const TQString &timeZoneId );
00191 
00195     virtual ~Calendar();
00196 
00202     void setProductId( const TQString &productId );
00203 
00209     TQString productId();
00210 
00214     void clearException();
00215 
00220     ErrorFormat *exception() const;
00221 
00227     void setOwner( const Person &owner );
00228 
00234     const Person &getOwner() const;
00235 
00250     void setTimeZoneId( const TQString &timeZoneId );
00251 
00258     virtual void setTimeZoneIdViewOnly( const TQString &timeZoneId ) = 0;
00259 
00265     TQString timeZoneId() const;
00266 
00270     void setLocalTime();
00271 
00278     bool isLocalTime() const;
00279 
00286     void setModified( bool modified );
00287 
00293     bool isModified() const { return mModified; }
00294 
00298     virtual void close() = 0;
00299 
00303     virtual void closeEvents() = 0;
00304 
00308     virtual void closeTodos() = 0;
00309 
00313     virtual void closeJournals() = 0;
00314 
00318     virtual void save() = 0;
00319 
00325     virtual bool reload( const TQString &tz ) = 0;
00326 
00332     virtual bool isSaving() { return false; }
00333 
00339     TQStringList categories();
00340 
00341 // Incidence Specific Methods //
00342 
00350     virtual bool addIncidence( Incidence *incidence );
00351 
00359     virtual bool deleteIncidence( Incidence *incidence );
00360 
00366     virtual Incidence::List incidences();
00367 
00375     virtual Incidence::List incidences( const TQDate &date );
00376 
00382     virtual Incidence::List rawIncidences();
00383 
00392     Incidence *incidence( const TQString &uid );
00393 
00402     Incidence *incidenceFromSchedulingID( const TQString &sid );
00403 
00408     Incidence::List incidencesFromSchedulingID( const TQString &UID );
00409 
00419     static Incidence::List mergeIncidenceList( const Event::List &events,
00420                                                const Todo::List &todos,
00421                                                const Journal::List &journals );
00422 
00428     virtual bool beginChange( Incidence *incidence );
00429 
00435     virtual bool endChange( Incidence *incidence );
00436 
00453     Incidence *dissociateOccurrence( Incidence *incidence, TQDate date,
00454                                      bool single = true );
00455 
00456 // Event Specific Methods //
00457 
00465     virtual bool addEvent( Event *event ) = 0;
00466 
00474     virtual bool deleteEvent( Event *event ) = 0;
00475 
00485     static Event::List sortEvents( Event::List *eventList,
00486                                    EventSortField sortField,
00487                                    SortDirection sortDirection );
00488 
00499     static Event::List sortEventsForDate( Event::List *eventList,
00500                                           const TQDate &date,
00501                                           EventSortField sortField,
00502                                           SortDirection sortDirection );
00503 
00512     virtual Event::List events(
00513       EventSortField sortField = EventSortUnsorted,
00514       SortDirection sortDirection = SortDirectionAscending );
00515 
00523     Event::List events( const TQDateTime &qdt );
00524 
00536     Event::List events( const TQDate &start, const TQDate &end,
00537                         bool inclusive = false);
00538 
00550     Event::List events(
00551       const TQDate &date,
00552       EventSortField sortField = EventSortUnsorted,
00553       SortDirection sortDirection = SortDirectionAscending );
00554 
00563     virtual Event::List rawEvents(
00564       EventSortField sortField = EventSortUnsorted,
00565       SortDirection sortDirection = SortDirectionAscending ) = 0;
00566 
00576     virtual Event::List rawEventsForDate( const TQDateTime &qdt ) = 0;
00577 
00589     virtual Event::List rawEvents( const TQDate &start, const TQDate &end,
00590                                    bool inclusive = false ) = 0;
00591 
00603     virtual Event::List rawEventsForDate(
00604       const TQDate &date,
00605       EventSortField sortField = EventSortUnsorted,
00606       SortDirection sortDirection = SortDirectionAscending ) = 0;
00607 
00616     virtual Event *event( const TQString &uid ) = 0;
00617 
00618 // Todo Specific Methods //
00619 
00627     virtual bool addTodo( Todo *todo ) = 0;
00628 
00636     virtual bool deleteTodo( Todo *todo ) = 0;
00637 
00647     static Todo::List sortTodos( Todo::List *todoList,
00648                                  TodoSortField sortField,
00649                                  SortDirection sortDirection );
00650 
00659     virtual Todo::List todos(
00660       TodoSortField sortField = TodoSortUnsorted,
00661       SortDirection sortDirection = SortDirectionAscending );
00662 
00670     virtual Todo::List todos( const TQDate &date );
00671 
00680     virtual Todo::List rawTodos(
00681       TodoSortField sortField = TodoSortUnsorted,
00682       SortDirection sortDirection = SortDirectionAscending ) = 0;
00683 
00691     virtual Todo::List rawTodosForDate( const TQDate &date ) = 0;
00692 
00701     virtual Todo *todo( const TQString &uid ) = 0;
00702 
00703 // Journal Specific Methods //
00704 
00712     virtual bool addJournal( Journal *journal ) = 0;
00713 
00721     virtual bool deleteJournal( Journal *journal ) = 0;
00722 
00732     static Journal::List sortJournals( Journal::List *journalList,
00733                                        JournalSortField sortField,
00734                                        SortDirection sortDirection );
00743     virtual Journal::List journals(
00744       JournalSortField sortField = JournalSortUnsorted,
00745       SortDirection sortDirection = SortDirectionAscending );
00746 
00754     virtual Journal::List journals( const TQDate &date );
00755 
00764     virtual Journal::List rawJournals(
00765       JournalSortField sortField = JournalSortUnsorted,
00766       SortDirection sortDirection = SortDirectionAscending ) = 0;
00767 
00775     virtual Journal::List rawJournalsForDate( const TQDate &date ) = 0;
00776 
00785     virtual Journal *journal( const TQString &uid ) = 0;
00786 
00799     void beginBatchAdding();
00800 
00809     void endBatchAdding();
00810 
00811 // Relations Specific Methods //
00812 
00819     virtual void setupRelations( Incidence *incidence );
00820 
00827     virtual void removeRelations( Incidence *incidence );
00828 
00829 // Filter Specific Methods //
00830 
00837     void setFilter( CalFilter *filter );
00838 
00845     CalFilter *filter();
00846 
00847 // Alarm Specific Methods //
00848 
00857     virtual Alarm::List alarms( const TQDateTime &from,
00858                                 const TQDateTime &to ) = 0;
00859 
00860 // Observer Specific Methods //
00861 
00867     class Observer
00868     {
00869       public:
00870         virtual ~Observer() {}
00878         virtual void calendarModified( bool /*modified*/,
00879                                        Calendar * /*calendar*/ ) {};
00880 
00886         virtual void calendarIncidenceAdded( Incidence * /*incidence*/ ) {}
00887 
00893         virtual void calendarIncidenceChanged( Incidence * /*incidence*/ ) {}
00894 
00900           virtual void calendarIncidenceDeleted( Incidence * /*incidence*/ ) {}
00901     };
00902 
00909     void registerObserver( Observer *observer );
00910 
00917     void unregisterObserver( Observer *observer );
00918 
00919   signals:
00923     void calendarChanged();
00924 
00928     void calendarSaved();
00929 
00933     void calendarLoaded();
00934 
00939     void batchAddingBegins();
00940 
00945     void batchAddingEnds();
00946 
00947   protected:
00952     void setException( ErrorFormat *e );
00953 
00959     void incidenceUpdated( IncidenceBase *incidenceBase );
00960 
00973     virtual void doSetTimeZoneId( const TQString &/*timeZoneId*/ ) {}
00974 
00980     void notifyIncidenceAdded( Incidence *incidence );
00981 
00987     void notifyIncidenceChanged( Incidence *incidence );
00988 
00994     void notifyIncidenceDeleted( Incidence *incidence );
00995 
01000     virtual void customPropertyUpdated();
01001 
01008     void setObserversEnabled( bool enabled );
01009 
01010     //TODO: Move appendAlarms() and appendRecurringAlarms() from
01011     //      calendarlocal here, as protected static methods
01012     //      returning static Alarm::List
01013 
01014   private:
01015 
01019     void init();
01020 
01021     TQString mProductId;
01022     Person mOwner;
01023     TQString mTimeZoneId;
01024     bool mLocalTime;
01025 
01026     bool mModified;
01027 
01028     CalFilter *mFilter;
01029     CalFilter *mDefaultFilter;
01030 
01031     TQPtrList<Observer> mObservers;
01032     bool mNewObserver;
01033     bool mObserversEnabled;
01034 
01035     // This list is used to put together related Todos
01036     TQDict<Incidence> mOrphans;
01037     TQDict<Incidence> mOrphanUids;
01038 
01039     ErrorFormat *mException;
01040     class Private;
01041     Private *d;
01042   };
01043 
01044 }
01045 
01046 #endif