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 <tqintdict.h> 00033 #include <tqmap.h> 00034 00035 #include "calendar.h" 00036 #include "resourcecalendar.h" 00037 00038 #include "libkcal_export.h" 00039 00040 #include <tderesources/manager.h> 00041 00042 class TQWidget; 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 00070 public: 00074 class DestinationPolicy 00075 { 00076 public: 00077 DestinationPolicy( CalendarResourceManager *manager, 00078 TQWidget *parent = 0 ) : 00079 mManager( manager ), mParent( parent ) {} 00080 virtual ~DestinationPolicy() {} 00081 00082 virtual ResourceCalendar *destination( Incidence *incidence ) = 0; 00083 virtual TQWidget *parent() { return mParent; } 00084 virtual void setParent( TQWidget *newparent ) { mParent = newparent; } 00085 bool hasCalendarResources(); 00086 protected: 00087 CalendarResourceManager *resourceManager() 00088 { return mManager; } 00089 00090 private: 00091 CalendarResourceManager *mManager; 00092 TQWidget *mParent; 00093 }; 00094 00098 class StandardDestinationPolicy : public DestinationPolicy 00099 { 00100 public: 00101 StandardDestinationPolicy( CalendarResourceManager *manager, 00102 TQWidget *parent = 0 ) : 00103 DestinationPolicy( manager, parent ) {} 00104 virtual ~StandardDestinationPolicy() {} 00105 00106 ResourceCalendar *destination( Incidence *incidence ); 00107 00108 private: 00109 class Private; 00110 Private *d; 00111 }; 00112 00116 class AskDestinationPolicy : public DestinationPolicy 00117 { 00118 public: 00119 AskDestinationPolicy( CalendarResourceManager *manager, 00120 TQWidget *parent = 0 ) : 00121 DestinationPolicy( manager, parent ) {} 00122 virtual ~AskDestinationPolicy() {} 00123 00124 ResourceCalendar *destination( Incidence *incidence ); 00125 00126 private: 00127 class Private; 00128 Private *d; 00129 }; 00130 00134 class Ticket 00135 { 00136 friend class CalendarResources; 00137 public: 00138 ResourceCalendar *resource() const 00139 { return mResource; } 00140 00141 private: 00142 Ticket( ResourceCalendar *r ) : mResource( r ) {} 00143 00144 ResourceCalendar *mResource; 00145 00146 class Private; 00147 Private *d; 00148 }; 00149 00166 CalendarResources( 00167 const TQString &timeZoneId, 00168 const TQString &family = TQString::fromLatin1( "calendar" ) ); 00169 00173 ~CalendarResources(); 00174 00180 void load(); 00181 00187 bool reload( const TQString &tz ); 00188 00192 void close(); 00193 00197 void closeEvents(); 00198 00202 void closeTodos(); 00203 00207 void closeJournals(); 00208 00222 virtual bool save( Ticket *ticket, Incidence *incidence = 0 ); 00223 00227 void save(); 00228 00234 bool isSaving(); 00235 00241 CalendarResourceManager *resourceManager() const 00242 { return mManager; } 00243 00252 ResourceCalendar *resource( Incidence *incidence ); 00253 00262 void readConfig( TDEConfig *config = 0 ); 00263 00268 void setStandardDestinationPolicy(); 00269 00274 void setAskDestinationPolicy(); 00275 00284 TQWidget *dialogParentWidget(); 00291 void setDialogParentWidget( TQWidget *parent ); 00292 00303 Ticket *requestSaveTicket( ResourceCalendar *resource ); 00304 00310 virtual void releaseSaveTicket( Ticket *ticket ); 00311 00320 void resourceAdded( ResourceCalendar *resource ); 00321 00322 // Incidence Specific Methods // 00323 00331 bool addIncidence( Incidence *incidence ); 00332 00343 KDE_DEPRECATED bool addIncidence( Incidence *incidence, ResourceCalendar *resource ); 00344 00355 bool addIncidence( Incidence *incidence, 00356 ResourceCalendar *resource, const TQString &subresource ); 00357 00365 KDE_DEPRECATED bool beginChange( Incidence *incidence ); 00366 00379 bool beginChange( Incidence *incidence, ResourceCalendar *resource, const TQString &subresource ); 00380 00388 KDE_DEPRECATED bool endChange( Incidence *incidence ); 00389 00402 bool endChange( Incidence *incidence, 00403 ResourceCalendar *resource, const TQString &subresource ); 00404 00405 // Event Specific Methods // 00406 00417 bool addEvent( Event *event ); 00418 00430 KDE_DEPRECATED bool addEvent( Event *event, ResourceCalendar *resource ); 00431 00445 bool addEvent( Event *event, ResourceCalendar *resource, const TQString &subresource ); 00446 00457 bool deleteEvent( Event *event ); 00458 00467 Event::List rawEvents( 00468 EventSortField sortField = EventSortUnsorted, 00469 SortDirection sortDirection = SortDirectionAscending ); 00470 00480 Event::List rawEventsForDate( const TQDateTime &qdt ); 00481 00493 Event::List rawEvents( const TQDate &start, const TQDate &end, 00494 bool inclusive = false ); 00495 00507 Event::List rawEventsForDate( 00508 const TQDate &date, 00509 EventSortField sortField = EventSortUnsorted, 00510 SortDirection sortDirection = SortDirectionAscending ); 00511 00520 Event *event( const TQString &uid ); 00521 00522 // Todo Specific Methods // 00523 00534 bool addTodo( Todo *todo ); 00535 00547 KDE_DEPRECATED bool addTodo( Todo *todo, ResourceCalendar *resource ); 00548 00562 bool addTodo( Todo *todo, ResourceCalendar *resource, const TQString &subresource ); 00563 00574 bool deleteTodo( Todo *todo ); 00575 00584 Todo::List rawTodos( TodoSortField sortField = TodoSortUnsorted, 00585 SortDirection sortDirection = SortDirectionAscending ); 00586 00595 Todo::List rawTodosForDate( const TQDate &date ); 00596 00605 Todo *todo( const TQString &uid ); 00606 00607 // Journal Specific Methods // 00608 00619 bool addJournal( Journal *journal ); 00620 00632 KDE_DEPRECATED bool addJournal( Journal *journal, ResourceCalendar *resource ); 00633 00647 bool addJournal( Journal *journal, ResourceCalendar *resource, const TQString &subresource ); 00648 00659 bool deleteJournal( Journal *journal ); 00660 00669 Journal::List rawJournals( 00670 JournalSortField sortField = JournalSortUnsorted, 00671 SortDirection sortDirection = SortDirectionAscending ); 00672 00680 Journal::List rawJournalsForDate( const TQDate &date ); 00681 00690 Journal *journal( const TQString &uid ); 00691 00692 // Alarm Specific Methods // 00693 00702 Alarm::List alarms( const TQDateTime &from, const TQDateTime &to ); 00703 00711 Alarm::List alarmsTo( const TQDateTime &to ); 00712 00720 void setTimeZoneIdViewOnly( const TQString& tz ); 00721 00722 //issue 2508 00723 bool hasCalendarResources(); 00724 signals: 00728 void signalResourceModified( ResourceCalendar *resource ); 00729 00733 void signalResourceAdded( ResourceCalendar *resource ); 00734 00738 void signalResourceDeleted( ResourceCalendar *resource ); 00739 00743 void signalErrorMessage( const TQString &err ); 00744 00745 protected: 00746 void connectResource( ResourceCalendar *resource ); 00747 void resourceModified( ResourceCalendar *resource ); 00748 void resourceDeleted( ResourceCalendar *resource ); 00749 00762 virtual void doSetTimeZoneId( const TQString &timeZoneId ); 00763 00771 int incrementChangeCount( ResourceCalendar *resource ); 00772 00780 int decrementChangeCount( ResourceCalendar *resource ); 00781 00782 protected slots: 00783 void slotLoadError( ResourceCalendar *resource, const TQString &err ); 00784 void slotSaveError( ResourceCalendar *resource, const TQString &err ); 00785 00792 void beginAddingIncidences(); 00793 00798 void endAddingIncidences(); 00799 00800 private: 00801 00805 void init( const TQString &family ); 00806 00807 bool mOpen; 00808 00809 KRES::Manager<ResourceCalendar>* mManager; 00810 TQMap <Incidence*, ResourceCalendar*> mResourceMap; 00811 00812 DestinationPolicy *mDestinationPolicy; 00813 StandardDestinationPolicy *mStandardPolicy; 00814 AskDestinationPolicy *mAskPolicy; 00815 bool mPendingDeleteFromResourceMap; 00816 00817 TQMap<ResourceCalendar *, Ticket *> mTickets; 00818 TQMap<ResourceCalendar *, int> mChangeCounts; 00819 00820 class Private; 00821 Private *d; 00822 }; 00823 00824 } 00825 00826 #endif