libkcal

calendarresources.h
Go to the documentation of this file.
1 /*
2  This file is part of libkcal.
3 
4  Copyright (c) 2003 Cornelius Schumacher <schumacher@kde.org>
5  Copyright (C) 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com>
6 
7  This library is free software; you can redistribute it and/or
8  modify it under the terms of the GNU Library General Public
9  License as published by the Free Software Foundation; either
10  version 2 of the License, or (at your option) any later version.
11 
12  This library is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  Library General Public License for more details.
16 
17  You should have received a copy of the GNU Library General Public License
18  along with this library; see the file COPYING.LIB. If not, write to
19  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20  Boston, MA 02110-1301, USA.
21 */
29 #ifndef KCAL_CALENDARRESOURCES_H
30 #define KCAL_CALENDARRESOURCES_H
31 
32 #include <tqintdict.h>
33 #include <tqmap.h>
34 
35 #include "calendar.h"
36 #include "resourcecalendar.h"
37 
38 #include "libkcal_export.h"
39 
40 #include <kresources/manager.h>
41 
42 class TQWidget;
43 
48 namespace KCal {
49 
50 class CalFormat;
51 
64 class LIBKCAL_EXPORT CalendarResources :
65  public Calendar,
66  public KRES::ManagerObserver<ResourceCalendar>
67 {
68  Q_OBJECT
69  TQ_OBJECT
70  public:
74  class DestinationPolicy
75  {
76  public:
77  DestinationPolicy( CalendarResourceManager *manager,
78  TQWidget *parent = 0 ) :
79  mManager( manager ), mParent( parent ) {}
80 
81  virtual ResourceCalendar *destination( Incidence *incidence ) = 0;
82  virtual TQWidget *parent() { return mParent; }
83  virtual void setParent( TQWidget *newparent ) { mParent = newparent; }
84  bool hasCalendarResources();
85  protected:
86  CalendarResourceManager *resourceManager()
87  { return mManager; }
88 
89  private:
90  CalendarResourceManager *mManager;
91  TQWidget *mParent;
92  };
93 
97  class StandardDestinationPolicy : public DestinationPolicy
98  {
99  public:
100  StandardDestinationPolicy( CalendarResourceManager *manager,
101  TQWidget *parent = 0 ) :
102  DestinationPolicy( manager, parent ) {}
103 
104  ResourceCalendar *destination( Incidence *incidence );
105 
106  private:
107  class Private;
108  Private *d;
109  };
110 
114  class AskDestinationPolicy : public DestinationPolicy
115  {
116  public:
117  AskDestinationPolicy( CalendarResourceManager *manager,
118  TQWidget *parent = 0 ) :
119  DestinationPolicy( manager, parent ) {}
120 
121  ResourceCalendar *destination( Incidence *incidence );
122 
123  private:
124  class Private;
125  Private *d;
126  };
127 
131  class Ticket
132  {
133  friend class CalendarResources;
134  public:
135  ResourceCalendar *resource() const
136  { return mResource; }
137 
138  private:
139  Ticket( ResourceCalendar *r ) : mResource( r ) {}
140 
141  ResourceCalendar *mResource;
142 
143  class Private;
144  Private *d;
145  };
146 
164  const TQString &timeZoneId,
165  const TQString &family = TQString::fromLatin1( "calendar" ) );
166 
171 
177  void load();
178 
184  bool reload( const TQString &tz );
185 
189  void close();
190 
194  void closeEvents();
195 
199  void closeTodos();
200 
204  void closeJournals();
205 
219  virtual bool save( Ticket *ticket, Incidence *incidence = 0 );
220 
224  void save();
225 
231  bool isSaving();
232 
238  CalendarResourceManager *resourceManager() const
239  { return mManager; }
240 
249  ResourceCalendar *resource( Incidence *incidence );
250 
259  void readConfig( KConfig *config = 0 );
260 
265  void setStandardDestinationPolicy();
266 
271  void setAskDestinationPolicy();
272 
281  TQWidget *dialogParentWidget();
288  void setDialogParentWidget( TQWidget *parent );
289 
300  Ticket *requestSaveTicket( ResourceCalendar *resource );
301 
307  virtual void releaseSaveTicket( Ticket *ticket );
308 
317  void resourceAdded( ResourceCalendar *resource );
318 
319 // Incidence Specific Methods //
320 
328  bool addIncidence( Incidence *incidence );
329 
340  KDE_DEPRECATED bool addIncidence( Incidence *incidence, ResourceCalendar *resource );
341 
352  bool addIncidence( Incidence *incidence,
353  ResourceCalendar *resource, const TQString &subresource );
354 
362  KDE_DEPRECATED bool beginChange( Incidence *incidence );
363 
376  bool beginChange( Incidence *incidence, ResourceCalendar *resource, const TQString &subresource );
377 
385  KDE_DEPRECATED bool endChange( Incidence *incidence );
386 
399  bool endChange( Incidence *incidence,
400  ResourceCalendar *resource, const TQString &subresource );
401 
402 // Event Specific Methods //
403 
414  bool addEvent( Event *event );
415 
427  KDE_DEPRECATED bool addEvent( Event *event, ResourceCalendar *resource );
428 
442  bool addEvent( Event *event, ResourceCalendar *resource, const TQString &subresource );
443 
454  bool deleteEvent( Event *event );
455 
464  Event::List rawEvents(
465  EventSortField sortField = EventSortUnsorted,
466  SortDirection sortDirection = SortDirectionAscending );
467 
477  Event::List rawEventsForDate( const TQDateTime &qdt );
478 
490  Event::List rawEvents( const TQDate &start, const TQDate &end,
491  bool inclusive = false );
492 
504  Event::List rawEventsForDate(
505  const TQDate &date,
506  EventSortField sortField = EventSortUnsorted,
507  SortDirection sortDirection = SortDirectionAscending );
508 
517  Event *event( const TQString &uid );
518 
519 // Todo Specific Methods //
520 
531  bool addTodo( Todo *todo );
532 
544  KDE_DEPRECATED bool addTodo( Todo *todo, ResourceCalendar *resource );
545 
559  bool addTodo( Todo *todo, ResourceCalendar *resource, const TQString &subresource );
560 
571  bool deleteTodo( Todo *todo );
572 
581  Todo::List rawTodos( TodoSortField sortField = TodoSortUnsorted,
582  SortDirection sortDirection = SortDirectionAscending );
583 
592  Todo::List rawTodosForDate( const TQDate &date );
593 
602  Todo *todo( const TQString &uid );
603 
604 // Journal Specific Methods //
605 
616  bool addJournal( Journal *journal );
617 
629  KDE_DEPRECATED bool addJournal( Journal *journal, ResourceCalendar *resource );
630 
644  bool addJournal( Journal *journal, ResourceCalendar *resource, const TQString &subresource );
645 
656  bool deleteJournal( Journal *journal );
657 
666  Journal::List rawJournals(
668  SortDirection sortDirection = SortDirectionAscending );
669 
677  Journal::List rawJournalsForDate( const TQDate &date );
678 
687  Journal *journal( const TQString &uid );
688 
689 // Alarm Specific Methods //
690 
699  Alarm::List alarms( const TQDateTime &from, const TQDateTime &to );
700 
708  Alarm::List alarmsTo( const TQDateTime &to );
709 
717  void setTimeZoneIdViewOnly( const TQString& tz );
718 
719  //issue 2508
720  bool hasCalendarResources();
721  signals:
725  void signalResourceModified( ResourceCalendar *resource );
726 
730  void signalResourceAdded( ResourceCalendar *resource );
731 
735  void signalResourceDeleted( ResourceCalendar *resource );
736 
740  void signalErrorMessage( const TQString &err );
741 
742  protected:
743  void connectResource( ResourceCalendar *resource );
744  void resourceModified( ResourceCalendar *resource );
745  void resourceDeleted( ResourceCalendar *resource );
746 
759  virtual void doSetTimeZoneId( const TQString &timeZoneId );
760 
768  int incrementChangeCount( ResourceCalendar *resource );
769 
777  int decrementChangeCount( ResourceCalendar *resource );
778 
779  protected slots:
780  void slotLoadError( ResourceCalendar *resource, const TQString &err );
781  void slotSaveError( ResourceCalendar *resource, const TQString &err );
782 
789  void beginAddingIncidences();
790 
795  void endAddingIncidences();
796 
797  private:
798 
802  void init( const TQString &family );
803 
804  bool mOpen;
805 
806  KRES::Manager<ResourceCalendar>* mManager;
807  TQMap <Incidence*, ResourceCalendar*> mResourceMap;
808 
809  DestinationPolicy *mDestinationPolicy;
810  StandardDestinationPolicy *mStandardPolicy;
811  AskDestinationPolicy *mAskPolicy;
812  bool mPendingDeleteFromResourceMap;
813 
814  TQMap<ResourceCalendar *, Ticket *> mTickets;
815  TQMap<ResourceCalendar *, int> mChangeCounts;
816 
817  class Private;
818  Private *d;
819 };
820 
821 }
822 
823 #endif