Better wording
[kdepim.git] / calendarsupport / calendar.h
blob2fd50235de6999512ee8e45771f27caff78499ab
1 /*
2 Copyright (c) 2009 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
3 Author: Sebastian Sauer <sebsauer@kdab.com>
4 Author: Frank Osterfeld <frank@kdab.com>
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 #ifndef CALENDARSUPPORT_CALENDAR_H
22 #define CALENDARSUPPORT_CALENDAR_H
24 #include "calendarsupport_export.h"
26 #include <Akonadi/Collection>
27 #include <Akonadi/Item>
29 #include <KCalCore/CustomProperties>
30 #include <KCalCore/Incidence>
32 #include <KDateTime>
34 #include <QObject>
36 namespace KCalCore {
37 class CalFilter;
40 class QAbstractItemModel;
42 namespace CalendarSupport {
44 /**
45 Calendar KCalCore::Incidence sort directions.
47 enum SortDirection {
48 SortDirectionAscending, /**< Sort in ascending order (first to last) */
49 SortDirectionDescending /**< Sort in descending order (last to first) */
52 /**
53 Calendar Event sort keys.
55 enum EventSortField {
56 EventSortUnsorted, /**< Do not sort Events */
57 EventSortStartDate, /**< Sort Events chronologically, by start date */
58 EventSortEndDate, /**< Sort Events chronologically, by end date */
59 EventSortSummary /**< Sort Events alphabetically, by summary */
62 /**
63 Calendar Todo sort keys.
65 enum TodoSortField {
66 TodoSortUnsorted, /**< Do not sort Todos */
67 TodoSortStartDate, /**< Sort Todos chronologically, by start date */
68 TodoSortDueDate, /**< Sort Todos chronologically, by due date */
69 TodoSortPriority, /**< Sort Todos by priority */
70 TodoSortPercentComplete, /**< Sort Todos by percentage completed */
71 TodoSortSummary /**< Sort Todos alphabetically, by summary */
74 /**
75 Calendar Journal sort keys.
77 enum JournalSortField {
78 JournalSortUnsorted, /**< Do not sort Journals */
79 JournalSortDate, /**< Sort Journals chronologically by date */
80 JournalSortSummary /**< Sort Journals alphabetically, by summary */
83 /**
84 * Implements a KCalCore::Calendar that uses Akonadi as backend.
86 class CALENDARSUPPORT_EXPORT Calendar : public QObject,
87 public KCalCore::CustomProperties,
88 public KCalCore::IncidenceBase::IncidenceObserver
90 Q_OBJECT
92 Q_PROPERTY( int incidencesCount READ incidencesCount NOTIFY calendarChanged )
93 public:
95 /**
96 Sets the calendar Product ID to @p id.
97 @param id is a string containing the Product ID.
98 @see productId() const
100 void setProductId( const QString &id );
103 Returns the calendar's Product ID.
104 @see setProductId()
106 QString productId() const;
109 Sets the owner of the calendar to @p owner.
110 @param owner is a Person object.
111 @see owner()
113 void setOwner( const KCalCore::Person &owner );
116 Returns the owner of the calendar.
117 @return the owner Person object.
118 @see setOwner()
120 KCalCore::Person owner() const;
123 Sets the default time specification (time zone, etc.) used for creating
124 or modifying incidences in the Calendar.
126 The method also calls setViewTimeSpec(@p timeSpec).
128 @param timeSpec time specification
130 void setTimeSpec( const KDateTime::Spec &timeSpec );
133 Get the time specification (time zone etc.) used for creating or
134 modifying incidences in the Calendar.
135 @return time specification
137 KDateTime::Spec timeSpec() const;
140 Sets the time zone ID used for creating or modifying incidences in the
141 Calendar. This method has no effect on existing incidences.
143 The method also calls setViewTimeZoneId(@p timeZoneId).
145 @param timeZoneId is a string containing a time zone ID, which is
146 assumed to be valid. The time zone ID is used to set the time zone
147 for viewing KCalCore::Incidence date/times. If no time zone is found, the
148 viewing time specification is set to local clock time.
149 @e Example: "Europe/Berlin"
150 @see setTimeSpec()
152 void setTimeZoneId( const QString &timeZoneId );
155 Returns the time zone ID used for creating or modifying incidences in
156 the calendar.
158 @return the string containing the time zone ID, or empty string if the
159 creation/modification time specification is not a time zone.
161 QString timeZoneId() const;
164 Notes the time specification which the client application intends to
165 use for viewing the incidences in this calendar. This is simply a
166 convenience method which makes a note of the new time zone so that
167 it can be read back by viewTimeSpec(). The client application must
168 convert date/time values to the desired time zone itself.
170 The time specification is not used in any way by the Calendar or its
171 incidences; it is solely for use by the client application.
173 @param timeSpec time specification
175 @see viewTimeSpec()
177 void setViewTimeSpec( const KDateTime::Spec &timeSpec ) const;
180 Notes the time zone Id which the client application intends to use for
181 viewing the incidences in this calendar. This is simply a convenience
182 method which makes a note of the new time zone so that it can be read
183 back by viewTimeId(). The client application must convert date/time
184 values to the desired time zone itself.
186 The Id is not used in any way by the Calendar or its incidences.
187 It is solely for use by the client application.
189 @param timeZoneId is a string containing a time zone ID, which is
190 assumed to be valid. The time zone ID is used to set the time zone
191 for viewing KCalCore::Incidence date/times. If no time zone is found, the
192 viewing time specification is set to local clock time.
193 @e Example: "Europe/Berlin"
195 @see viewTimeZoneId()
197 void setViewTimeZoneId( const QString &timeZoneId ) const;
200 Returns the time specification used for viewing the incidences in
201 this calendar. This simply returns the time specification last
202 set by setViewTimeSpec().
203 @see setViewTimeSpec().
205 KDateTime::Spec viewTimeSpec() const;
208 Returns the time zone Id used for viewing the incidences in this
209 calendar. This simply returns the time specification last set by
210 setViewTimeSpec().
211 @see setViewTimeZoneId().
213 QString viewTimeZoneId() const;
216 Shifts the times of all incidences so that they appear at the same clock
217 time as before but in a new time zone. The shift is done from a viewing
218 time zone rather than from the actual incidence time zone.
220 For example, shifting an incidence whose start time is 09:00 America/New York,
221 using an old viewing time zone (@p oldSpec) of Europe/London, to a new time
222 zone (@p newSpec) of Europe/Paris, will result in the time being shifted
223 from 14:00 (which is the London time of the incidence start) to 14:00 Paris
224 time.
226 @param oldSpec the time specification which provides the clock times
227 @param newSpec the new time specification
229 @see isLocalTime()
231 void shiftTimes( const KDateTime::Spec &oldSpec, const KDateTime::Spec &newSpec );
234 Returns a list of all categories used by KCalCore::Incidences in the calendar @p cal.
236 @param cal the calendar to return incidences from
237 @return a QStringList containing all the categories.
239 static QStringList categories( Calendar *cal );
241 // KCalCore::Incidence Specific Methods //
244 Returns a filtered list of all KCalCore::Incidences for this Calendar.
245 @deprecated:
247 @return the list of all filtered KCalCore::Incidences.
249 Akonadi::Item::List incidences();
252 Returns a filtered list of all KCalCore::Incidences which occur on the given date.
254 @param date request filtered KCalCore::Incidence list for this QDate only.
255 @deprecated:
257 @return the list of filtered KCalCore::Incidences occurring on the specified date.
259 Akonadi::Item::List incidences( const QDate &date );
262 Returns an unfiltered list of all KCalCore::Incidences for this Calendar.
263 @deprecated:
265 @return the list of all unfiltered KCalCore::Incidences.
267 Akonadi::Item::List rawIncidences();
270 Returns the KCalCore::Incidence associated with the given unique identifier.
272 @param uid is a unique identifier string.
273 @deprecated:
275 @return a pointer to the KCalCore::Incidence.
276 A null pointer is returned if no such KCalCore::Incidence exists.
278 Akonadi::Item incidence( Akonadi::Item::Id id ) const;
280 Akonadi::Collection collection( const Akonadi::Collection::Id &id ) const;
283 Returns the KCalCore::Incidence associated with the given scheduling identifier.
285 @param sid is a unique scheduling identifier string.
286 @deprecated:
288 @return a pointer to the KCalCore::Incidence.
289 A null pointer is returned if no such KCalCore::Incidence exists.
291 Akonadi::Item incidenceFromSchedulingID( const QString &sid );
294 Searches all events and todos for an incidence with this
295 scheduling identifiere. Returns a list of matching results.
296 @deprecated:
298 @param sid is a unique scheduling identifier string.
300 Akonadi::Item::List incidencesFromSchedulingID( const QString &sid );
303 Create a merged list of KCalCore::Events, KCalCore::Todos, and KCalCore::Journals.
305 @param events is an KCalCore::Event list to merge.
306 @param todos is a KCalCore::Todo list to merge.
307 @param journals is a KCalCore::Journal list to merge.
308 @deprecated:
310 @return a list of merged KCalCore::Incidences.
312 static Akonadi::Item::List mergeIncidenceList( const Akonadi::Item::List &events,
313 const Akonadi::Item::List &todos,
314 const Akonadi::Item::List &journals );
317 Dissociate an KCalCore::Incidence from a recurring KCalCore::Incidence.
318 By default, only one single KCalCore::Incidence for the specified @a date
319 will be dissociated and returned. If @a single is false, then
320 the recurrence will be split at @a date, the old KCalCore::Incidence will
321 have its recurrence ending at @a date and the new KCalCore::Incidence
322 will have all recurrences past the @a date.
324 @param incidence is a pointer to a recurring KCalCore::Incidence.
325 @param date is the QDate within the recurring KCalCore::Incidence on which
326 the dissociation will be performed.
327 @param spec is the spec in which the @a date is formulated.
328 @param single is a flag meaning that a new KCalCore::Incidence should be created
329 from the recurring KCalCore::Incidences after @a date.
330 @deprecated:
332 @return a pointer to a new recurring KCalCore::Incidence if @a single is false.
334 KCalCore::Incidence::Ptr dissociateOccurrence( const Akonadi::Item &incidence,
335 const QDate &date,
336 const KDateTime::Spec &spec,
337 bool single = true );
339 // KCalCore::Event Specific Methods //
342 Sort a list of KCalCore::Events.
344 @param eventList is a pointer to a list of KCalCore::Events.
345 @param sortField specifies the EventSortField.
346 @param sortDirection specifies the SortDirection.
347 @deprecated:
349 @return a list of KCalCore::Events sorted as specified.
351 static Akonadi::Item::List sortEvents( const Akonadi::Item::List &eventList,
352 EventSortField sortField,
353 SortDirection sortDirection );
356 Returns a sorted, filtered list of all KCalCore::Events for this Calendar.
358 @param sortField specifies the EventSortField.
359 @param sortDirection specifies the SortDirection.
360 @deprecated:
362 @return the list of all filtered KCalCore::Events sorted as specified.
364 virtual Akonadi::Item::List events(
365 EventSortField sortField = EventSortUnsorted,
366 SortDirection sortDirection = SortDirectionAscending );
369 Returns a filtered list of all KCalCore::Events which occur on the given timestamp.
371 @param dt request filtered KCalCore::Event list for this KDateTime only.
372 @deprecated:
374 @return the list of filtered KCalCore::Events occurring on the specified timestamp.
376 Akonadi::Item::List events( const KDateTime &dt );
379 Returns a filtered list of all KCalCore::Events occurring within a date range.
381 @param start is the starting date.
382 @param end is the ending date.
383 @param timeSpec time zone etc. to interpret @p start and @p end,
384 or the calendar's default time spec if none is specified
385 @param inclusive if true only KCalCore::Events which are completely included
386 within the date range are returned.
387 @deprecated:
389 @return the list of filtered KCalCore::Events occurring within the specified
390 date range.
392 Akonadi::Item::List events( const QDate &start, const QDate &end,
393 const KDateTime::Spec &timeSpec = KDateTime::Spec(),
394 bool inclusive = false );
397 Returns a sorted, filtered list of all KCalCore::Events which occur on the given
398 date. The KCalCore::Events are sorted according to @a sortField and
399 @a sortDirection.
401 @param date request filtered KCalCore::Event list for this QDate only.
402 @param timeSpec time zone etc. to interpret @p start and @p end,
403 or the calendar's default time spec if none is specified
404 @param sortField specifies the EventSortField.
405 @param sortDirection specifies the SortDirection.
406 @deprecated:
408 @return the list of sorted, filtered KCalCore::Events occurring on @a date.
410 Akonadi::Item::List events(
411 const QDate &date,
412 const KDateTime::Spec &timeSpec = KDateTime::Spec(),
413 EventSortField sortField = EventSortUnsorted,
414 SortDirection sortDirection = SortDirectionAscending );
416 // KCalCore::Todo Specific Methods //
419 Sort a list of KCalCore::Todos.
421 @param todoList is a pointer to a list of KCalCore::Todos.
422 @param sortField specifies the TodoSortField.
423 @param sortDirection specifies the SortDirection.
424 @deprecated:
426 @return a list of KCalCore::Todos sorted as specified.
428 static Akonadi::Item::List sortTodos( const Akonadi::Item::List &todoList,
429 TodoSortField sortField,
430 SortDirection sortDirection );
433 Returns a sorted, filtered list of all KCalCore::Todos for this Calendar.
435 @param sortField specifies the TodoSortField.
436 @param sortDirection specifies the SortDirection.
437 @deprecated:
439 @return the list of all filtered KCalCore::Todos sorted as specified.
441 virtual Akonadi::Item::List todos(
442 TodoSortField sortField = TodoSortUnsorted,
443 SortDirection sortDirection = SortDirectionAscending );
446 Returns a filtered list of all KCalCore::Todos which are due on the specified date.
448 @param date request filtered KCalCore::Todos due on this QDate.
449 @deprecated:
451 @return the list of filtered KCalCore::Todos due on the specified date.
453 virtual Akonadi::Item::List todos( const QDate &date );
455 // KCalCore::Journal Specific Methods //
458 Sort a list of KCalCore::Journals.
460 @param journalList is a pointer to a list of KCalCore::Journals.
461 @param sortField specifies the JournalSortField.
462 @param sortDirection specifies the SortDirection.
463 @deprecated:
465 @return a list of KCalCore::Journals sorted as specified.
467 static Akonadi::Item::List sortJournals( const Akonadi::Item::List &journalList,
468 JournalSortField sortField,
469 SortDirection sortDirection );
472 Returns a sorted, filtered list of all KCalCore::Journals for this Calendar.
474 @param sortField specifies the JournalSortField.
475 @param sortDirection specifies the SortDirection.
476 @deprecated:
478 @return the list of all filtered KCalCore::Journals sorted as specified.
480 virtual Akonadi::Item::List journals(
481 JournalSortField sortField = JournalSortUnsorted,
482 SortDirection sortDirection = SortDirectionAscending );
485 Returns a filtered list of all KCalCore::Journals for on the specified date.
487 @param date request filtered KCalCore::Journals for this QDate only.
488 @deprecated:
490 @return the list of filtered KCalCore::Journals for the specified date.
492 virtual Akonadi::Item::List journals( const QDate &date );
495 Emits the beginBatchAdding() signal.
497 This should be called before adding a batch of incidences with
498 addIncidence( KCalCore::Incidence::Ptr ), addTodo( KCalCore::Todo::Ptr ),
499 addEvent( KCalCore::Event::Ptr ) or addJournal( KCalCore::Journal::Ptr ).
500 Some Calendars are connected to this signal, e.g: CalendarResources uses
501 it to know a series of incidenceAdds are related so the user isn't prompted
502 multiple times which resource to save the incidence to
504 @since 4.4
506 void beginBatchAdding();
509 Emits the endBatchAdding() signal.
511 Used with beginBatchAdding(). Should be called after
512 adding all incidences.
514 @since 4.4
516 void endBatchAdding();
518 // Filter Specific Methods //
521 Sets the calendar filter.
523 @param filter a pointer to a CalFilter object which will be
524 used to filter Calendar KCalCore::Incidences.
525 @deprecated:
527 @see filter()
529 void setFilter( KCalCore::CalFilter *filter );
532 Returns the calendar filter.
534 @return a pointer to the calendar CalFilter.
535 A null pointer is returned if no such CalFilter exists.
536 @deprecated:
538 @see setFilter()
540 KCalCore::CalFilter *filter();
542 // Observer Specific Methods //
545 @class CalendarObserver
547 The CalendarObserver class.
549 class CALENDARSUPPORT_EXPORT CalendarObserver //krazy:exclude=dpointer
551 public:
553 Destructor.
555 virtual ~CalendarObserver() {}
558 Notify the Observer that an KCalCore::Incidence has been inserted.
559 @deprecated:
561 @param incidence is a pointer to the KCalCore::Incidence that was inserted.
563 virtual void calendarIncidenceAdded( const Akonadi::Item &incidence );
566 Notify the Observer that an KCalCore::Incidence has been modified.
567 @deprecated:
569 @param incidence is a pointer to the KCalCore::Incidence that was modified.
571 virtual void calendarIncidenceChanged( const Akonadi::Item &incidence );
574 Notify the Observer that an KCalCore::Incidence has been removed.
575 @deprecated:
577 @param incidence is a pointer to the KCalCore::Incidence that was removed.
579 virtual void calendarIncidenceDeleted( const Akonadi::Item &incidence );
584 Registers an Observer for this Calendar.
586 @param observer is a pointer to an Observer object that will be
587 watching this Calendar.
589 @see unregisterObserver()
591 void registerObserver( CalendarObserver *observer );
594 Unregisters an Observer for this Calendar.
596 @param observer is a pointer to an Observer object that has been
597 watching this Calendar.
599 @see registerObserver()
601 void unregisterObserver( CalendarObserver *observer );
604 Returns if the parent collection's rights allow deleting this item.
605 Isn't merged with hasChangeRights() for convenience.
607 bool hasDeleteRights( const Akonadi::Item &item ) const;
610 Returns if the parent collection's rights allow changing this item.
611 Isn't merged with hasDeleteRights() for convenience.
613 bool hasChangeRights( const Akonadi::Item &item ) const;
615 Q_SIGNALS:
617 Signals that the calendar has been modified.
619 void calendarChanged();
622 @see beginBatchAdding()
623 @since 4.4
625 void batchAddingBegins();
628 @see endBatchAdding()
629 @since 4.4
631 void batchAddingEnds();
633 protected:
635 Let Calendar subclasses set the time specification.
636 @param timeSpec is the time specification (time zone, etc.) for
637 viewing KCalCore::Incidence dates.\n
639 virtual void doSetTimeSpec( const KDateTime::Spec &timeSpec );
642 Let Calendar subclasses notify that they inserted an KCalCore::Incidence.
643 @deprecated:
644 @param incidence is a pointer to the KCalCore::Incidence object that was inserted.
646 void notifyIncidenceAdded( const Akonadi::Item &incidence );
649 Let Calendar subclasses notify that they modified an KCalCore::Incidence.
650 @deprecated:
651 @param incidence is a pointer to the KCalCore::Incidence object that was modified.
653 void notifyIncidenceChanged( const Akonadi::Item &incidence );
656 Let Calendar subclasses notify that they removed an KCalCore::Incidence.
657 @deprecated:
658 @param incidence is a pointer to the KCalCore::Incidence object that was removed.
660 void notifyIncidenceDeleted( const Akonadi::Item &incidence );
663 @copydoc
664 CustomProperties::customPropertyUpdated()
666 virtual void customPropertyUpdated();
669 Let Calendar subclasses notify that they enabled an Observer.
670 @param enabled if true tells the calendar that a subclass has
671 enabled an Observer.
673 void setObserversEnabled( bool enabled );
676 Appends alarms of incidence in interval to list of alarms.
678 @param alarms is a List of KCalCore::Alarms to be appended onto.
679 @param incidence is a pointer to an KCalCore::Incidence containing the KCalCore::Alarm
680 to be appended.
681 @param from is the lower range of the next KCalCore::Alarm repitition.
682 @param to is the upper range of the next KCalCore::Alarm repitition.
683 @deprecated:
685 void appendAlarms( KCalCore::Alarm::List &alarms, const Akonadi::Item &incidence,
686 const KDateTime &from, const KDateTime &to );
689 Appends alarms of recurring events in interval to list of alarms.
691 @param alarms is a List of KCalCore::Alarms to be appended onto.
692 @param incidence is a pointer to an KCalCore::Incidence containing the KCalCore::Alarm
693 to be appended.
694 @param from is the lower range of the next KCalCore::Alarm repitition.
695 @param to is the upper range of the next KCalCore::Alarm repitition.
696 @deprecated:
698 void appendRecurringAlarms( KCalCore::Alarm::List &alarms, const Akonadi::Item &incidence,
699 const KDateTime &from, const KDateTime &to );
700 public:
701 explicit Calendar( QAbstractItemModel *treeModel, QAbstractItemModel *model,
702 const KDateTime::Spec &timeSpec, QObject *parent=0 );
703 ~Calendar();
705 QAbstractItemModel *model() const;
707 QAbstractItemModel *unfilteredModel() const;
708 void setUnfilteredModel( QAbstractItemModel *model );
710 QAbstractItemModel *treeModel() const;
712 void incidenceUpdated( const QString &uid, const KDateTime &recurrenceId );
713 void incidenceUpdate( const QString &uid, const KDateTime &recurrenceId );
715 Akonadi::Item ::List rawEvents( EventSortField sortField = EventSortUnsorted,
716 SortDirection sortDirection = SortDirectionAscending );
718 Akonadi::Item ::List rawEvents( const QDate &start, const QDate &end,
719 const KDateTime::Spec &timeSpec = KDateTime::Spec(),
720 bool inclusive = false );
722 Akonadi::Item ::List rawEventsForDate( const QDate &date,
723 const KDateTime::Spec &timeSpec = KDateTime::Spec(),
724 EventSortField sortField = EventSortUnsorted,
725 SortDirection sortDirection = SortDirectionAscending );
727 Akonadi::Item::List rawEventsForDate( const KDateTime &dt );
729 Akonadi::Item event( Akonadi::Item::Id id ) const;
731 Akonadi::Item::List rawTodos( TodoSortField sortField = TodoSortUnsorted,
732 SortDirection sortDirection = SortDirectionAscending );
734 Akonadi::Item::List rawTodosForDate( const QDate &date );
736 Akonadi::Item todo( Akonadi::Item::Id uid ) const;
738 Akonadi::Item::List rawJournals( JournalSortField sortField = JournalSortUnsorted,
739 SortDirection sortDirection = SortDirectionAscending );
741 Akonadi::Item::List rawJournalsForDate( const QDate &date );
743 Akonadi::Item journal( Akonadi::Item::Id id ) const;
745 KCalCore::Alarm::List alarms( const KDateTime &from, const KDateTime &to,
746 bool excludeBlockedAlarms = false );
748 KCalCore::Alarm::List alarmsTo( const KDateTime &to );
750 Akonadi::Item findParent( const Akonadi::Item &item ) const;
752 Akonadi::Item::List findChildren( const KCalCore::Incidence::Ptr &incidence ) const;
753 Akonadi::Item::List findChildren( const Akonadi::Item &item ) const;
754 bool isChild( const Akonadi::Item &parent, const Akonadi::Item &child ) const;
756 Akonadi::Item::Id itemIdForIncidenceUid( const QString &uid ) const;
757 Akonadi::Item itemForIncidenceUid( const QString &uid ) const;
760 * Returns the number of incidences in the calendar.
762 int incidencesCount() const;
764 using QObject::event; // prevent warning about hidden virtual method
766 Q_SIGNALS:
767 void signalErrorMessage( const QString & );
769 private:
770 Q_DISABLE_COPY( Calendar )
771 class Private;
772 Private *const d;
777 #endif