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 <tdepimmacros.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 00175 public: 00176 00191 Calendar( const TQString &timeZoneId ); 00192 00196 virtual ~Calendar(); 00197 00203 void setProductId( const TQString &productId ); 00204 00210 TQString productId(); 00211 00215 void clearException(); 00216 00221 ErrorFormat *exception() const; 00222 00228 void setOwner( const Person &owner ); 00229 00235 const Person &getOwner() const; 00236 00251 void setTimeZoneId( const TQString &timeZoneId ); 00252 00259 virtual void setTimeZoneIdViewOnly( const TQString &timeZoneId ) = 0; 00260 00266 TQString timeZoneId() const; 00267 00271 void setLocalTime(); 00272 00279 bool isLocalTime() const; 00280 00287 void setModified( bool modified ); 00288 00294 bool isModified() const { return mModified; } 00295 00299 virtual void close() = 0; 00300 00304 virtual void closeEvents() = 0; 00305 00309 virtual void closeTodos() = 0; 00310 00314 virtual void closeJournals() = 0; 00315 00319 virtual void save() = 0; 00320 00326 virtual bool reload( const TQString &tz ) = 0; 00327 00333 virtual bool isSaving() { return false; } 00334 00340 TQStringList categories(); 00341 00342 // Incidence Specific Methods // 00343 00351 virtual bool addIncidence( Incidence *incidence ); 00352 00360 virtual bool deleteIncidence( Incidence *incidence ); 00361 00367 virtual Incidence::List incidences(); 00368 00376 virtual Incidence::List incidences( const TQDate &date ); 00377 00383 virtual Incidence::List rawIncidences(); 00384 00393 Incidence *incidence( const TQString &uid ); 00394 00403 Incidence *incidenceFromSchedulingID( const TQString &sid ); 00404 00409 Incidence::List incidencesFromSchedulingID( const TQString &UID ); 00410 00420 static Incidence::List mergeIncidenceList( const Event::List &events, 00421 const Todo::List &todos, 00422 const Journal::List &journals ); 00423 00429 virtual bool beginChange( Incidence *incidence ); 00430 00436 virtual bool endChange( Incidence *incidence ); 00437 00454 Incidence *dissociateOccurrence( Incidence *incidence, TQDate date, 00455 bool single = true ); 00456 00457 // Event Specific Methods // 00458 00466 virtual bool addEvent( Event *event ) = 0; 00467 00475 virtual bool deleteEvent( Event *event ) = 0; 00476 00486 static Event::List sortEvents( Event::List *eventList, 00487 EventSortField sortField, 00488 SortDirection sortDirection ); 00489 00500 static Event::List sortEventsForDate( Event::List *eventList, 00501 const TQDate &date, 00502 EventSortField sortField, 00503 SortDirection sortDirection ); 00504 00513 virtual Event::List events( 00514 EventSortField sortField = EventSortUnsorted, 00515 SortDirection sortDirection = SortDirectionAscending ); 00516 00524 Event::List events( const TQDateTime &qdt ); 00525 00537 Event::List events( const TQDate &start, const TQDate &end, 00538 bool inclusive = false); 00539 00551 Event::List events( 00552 const TQDate &date, 00553 EventSortField sortField = EventSortUnsorted, 00554 SortDirection sortDirection = SortDirectionAscending ); 00555 00564 virtual Event::List rawEvents( 00565 EventSortField sortField = EventSortUnsorted, 00566 SortDirection sortDirection = SortDirectionAscending ) = 0; 00567 00577 virtual Event::List rawEventsForDate( const TQDateTime &qdt ) = 0; 00578 00590 virtual Event::List rawEvents( const TQDate &start, const TQDate &end, 00591 bool inclusive = false ) = 0; 00592 00604 virtual Event::List rawEventsForDate( 00605 const TQDate &date, 00606 EventSortField sortField = EventSortUnsorted, 00607 SortDirection sortDirection = SortDirectionAscending ) = 0; 00608 00617 virtual Event *event( const TQString &uid ) = 0; 00618 00619 // Todo Specific Methods // 00620 00628 virtual bool addTodo( Todo *todo ) = 0; 00629 00637 virtual bool deleteTodo( Todo *todo ) = 0; 00638 00648 static Todo::List sortTodos( Todo::List *todoList, 00649 TodoSortField sortField, 00650 SortDirection sortDirection ); 00651 00660 virtual Todo::List todos( 00661 TodoSortField sortField = TodoSortUnsorted, 00662 SortDirection sortDirection = SortDirectionAscending ); 00663 00671 virtual Todo::List todos( const TQDate &date ); 00672 00681 virtual Todo::List rawTodos( 00682 TodoSortField sortField = TodoSortUnsorted, 00683 SortDirection sortDirection = SortDirectionAscending ) = 0; 00684 00692 virtual Todo::List rawTodosForDate( const TQDate &date ) = 0; 00693 00702 virtual Todo *todo( const TQString &uid ) = 0; 00703 00704 // Journal Specific Methods // 00705 00713 virtual bool addJournal( Journal *journal ) = 0; 00714 00722 virtual bool deleteJournal( Journal *journal ) = 0; 00723 00733 static Journal::List sortJournals( Journal::List *journalList, 00734 JournalSortField sortField, 00735 SortDirection sortDirection ); 00744 virtual Journal::List journals( 00745 JournalSortField sortField = JournalSortUnsorted, 00746 SortDirection sortDirection = SortDirectionAscending ); 00747 00755 virtual Journal::List journals( const TQDate &date ); 00756 00765 virtual Journal::List rawJournals( 00766 JournalSortField sortField = JournalSortUnsorted, 00767 SortDirection sortDirection = SortDirectionAscending ) = 0; 00768 00776 virtual Journal::List rawJournalsForDate( const TQDate &date ) = 0; 00777 00786 virtual Journal *journal( const TQString &uid ) = 0; 00787 00800 void beginBatchAdding(); 00801 00810 void endBatchAdding(); 00811 00812 // Relations Specific Methods // 00813 00820 virtual void setupRelations( Incidence *incidence ); 00821 00828 virtual void removeRelations( Incidence *incidence ); 00829 00830 // Filter Specific Methods // 00831 00838 void setFilter( CalFilter *filter ); 00839 00846 CalFilter *filter(); 00847 00848 // Alarm Specific Methods // 00849 00858 virtual Alarm::List alarms( const TQDateTime &from, 00859 const TQDateTime &to ) = 0; 00860 00861 // Observer Specific Methods // 00862 00868 class Observer 00869 { 00870 public: 00871 virtual ~Observer() {} 00879 virtual void calendarModified( bool /*modified*/, 00880 Calendar * /*calendar*/ ) {}; 00881 00887 virtual void calendarIncidenceAdded( Incidence * /*incidence*/ ) {} 00888 00894 virtual void calendarIncidenceChanged( Incidence * /*incidence*/ ) {} 00895 00901 virtual void calendarIncidenceDeleted( Incidence * /*incidence*/ ) {} 00902 }; 00903 00910 void registerObserver( Observer *observer ); 00911 00918 void unregisterObserver( Observer *observer ); 00919 00920 signals: 00924 void calendarChanged(); 00925 00929 void calendarSaved(); 00930 00934 void calendarLoaded(); 00935 00940 void batchAddingBegins(); 00941 00946 void batchAddingEnds(); 00947 00948 protected: 00953 void setException( ErrorFormat *e ); 00954 00960 void incidenceUpdated( IncidenceBase *incidenceBase ); 00961 00974 virtual void doSetTimeZoneId( const TQString &/*timeZoneId*/ ) {} 00975 00981 void notifyIncidenceAdded( Incidence *incidence ); 00982 00988 void notifyIncidenceChanged( Incidence *incidence ); 00989 00995 void notifyIncidenceDeleted( Incidence *incidence ); 00996 01001 virtual void customPropertyUpdated(); 01002 01009 void setObserversEnabled( bool enabled ); 01010 01011 //TODO: Move appendAlarms() and appendRecurringAlarms() from 01012 // calendarlocal here, as protected static methods 01013 // returning static Alarm::List 01014 01015 private: 01016 01020 void init(); 01021 01022 TQString mProductId; 01023 Person mOwner; 01024 TQString mTimeZoneId; 01025 bool mLocalTime; 01026 01027 bool mModified; 01028 01029 CalFilter *mFilter; 01030 CalFilter *mDefaultFilter; 01031 01032 TQPtrList<Observer> mObservers; 01033 bool mNewObserver; 01034 bool mObserversEnabled; 01035 01036 // This list is used to put together related Todos 01037 TQDict<Incidence> mOrphans; 01038 TQDict<Incidence> mOrphanUids; 01039 01040 ErrorFormat *mException; 01041 class Private; 01042 Private *d; 01043 }; 01044 01045 } 01046 01047 #endif