1/****************************************************************************
2**
3** Copyright (C) 2015 The Qt Company Ltd.
4** Contact: http://www.qt.io/licensing/
5**
6** This file is part of the QtOrganizer module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL21$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see http://www.qt.io/terms-conditions. For further
15** information use the contact form at http://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 2.1 or version 3 as published by the Free
20** Software Foundation and appearing in the file LICENSE.LGPLv21 and
21** LICENSE.LGPLv3 included in the packaging of this file. Please review the
22** following information to ensure the GNU Lesser General Public License
23** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
24** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25**
26** As a special exception, The Qt Company gives you certain additional
27** rights. These rights are described in The Qt Company LGPL Exception
28** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29**
30** $QT_END_LICENSE$
31**
32****************************************************************************/
33
34#include "qorganizerevent.h"
35
36#include "qorganizereventtime.h"
37#include "qorganizeritemlocation.h"
38#include "qorganizeritemrecurrence.h"
39
40QT_BEGIN_NAMESPACE_ORGANIZER
41
42/*!
43 \class QOrganizerEvent
44 \brief The QOrganizerEvent class provides an event in time which may reoccur
45 \inmodule QtOrganizer
46 \ingroup organizer-items
47
48 A QOrganizerEvent is an item which occurs at a particular point in time
49 and may be associated with a location or have other details. It may have
50 a set of recurrence rules or dates on which the event occurs associated
51 with it, and also exceptions to those recurrences.
52 */
53
54/*!
55 Sets the start date time of the event to \a startDateTime (for recurring events, this applies to
56 the first instance). For all-day events, the time part can be set to any valid value.
57*/
58void QOrganizerEvent::setStartDateTime(const QDateTime &startDateTime)
59{
60 QOrganizerEventTime etr = detail(detailType: QOrganizerItemDetail::TypeEventTime);
61 etr.setStartDateTime(startDateTime);
62 saveDetail(detail: &etr);
63}
64
65/*!
66 Returns the date time at which the event starts (for recurring events, this applies to the first
67 instance). For all-day events, the time part is meaningless.
68 */
69QDateTime QOrganizerEvent::startDateTime() const
70{
71 QOrganizerEventTime etr = detail(detailType: QOrganizerItemDetail::TypeEventTime);
72 return etr.startDateTime();
73}
74
75/*!
76 Sets the end date time of the event to \a endDateTime (for recurring events, this applies to the
77 first instance). For all-day events, the time part can be set to any valid value, and the date is
78 to be interpreted as the inclusive end date.
79 */
80void QOrganizerEvent::setEndDateTime(const QDateTime &endDateTime)
81{
82 QOrganizerEventTime etr = detail(detailType: QOrganizerItemDetail::TypeEventTime);
83 etr.setEndDateTime(endDateTime);
84 saveDetail(detail: &etr);
85}
86
87/*!
88 Returns the date time at which the event ends (for recurring events, this applies to the first
89 instance). For all-day events, the time part is meaningless, and the date is to be interpreted
90 as the inclusive end date.
91 */
92QDateTime QOrganizerEvent::endDateTime() const
93{
94 QOrganizerEventTime etr = detail(detailType: QOrganizerItemDetail::TypeEventTime);
95 return etr.endDateTime();
96}
97
98/*!
99 Sets whether the time-of-day component of the event's start date-time or end date-time is
100 insignificant (eg. this is generally set to true for a birthday). If \a isAllDay is true,
101 the time-of-day component is considered insignificant, and the event will be an all-day
102 item.
103 */
104void QOrganizerEvent::setAllDay(bool isAllDay)
105{
106 QOrganizerEventTime etr = detail(detailType: QOrganizerItemDetail::TypeEventTime);
107 etr.setAllDay(isAllDay);
108 saveDetail(detail: &etr);
109}
110
111/*!
112 Returns true if and only if the time component of the start date/time or end date/time are
113 insignificant.
114*/
115bool QOrganizerEvent::isAllDay() const
116{
117 QOrganizerEventTime etr = detail(detailType: QOrganizerItemDetail::TypeEventTime);
118 return etr.isAllDay();
119}
120
121/*!
122 Sets the list of dates \a rdates to be dates on which the event occurs.
123*/
124void QOrganizerEvent::setRecurrenceDates(const QSet<QDate> &rdates)
125{
126 QOrganizerItemRecurrence rec = detail(detailType: QOrganizerItemDetail::TypeRecurrence);
127 rec.setRecurrenceDates(rdates);
128 saveDetail(detail: &rec);
129}
130
131/*!
132 Sets a single date \a rdate to be the date on which the event occurs.
133 \sa setRecurrenceDates()
134*/
135void QOrganizerEvent::setRecurrenceDate(const QDate &rdate)
136{
137 setRecurrenceDates(QSet<QDate>() << rdate);
138}
139
140/*!
141 Returns the list of dates which have been explicitly set as dates on which the event occurs.
142*/
143QSet<QDate> QOrganizerEvent::recurrenceDates() const
144{
145 QOrganizerItemRecurrence rec = detail(detailType: QOrganizerItemDetail::TypeRecurrence);
146 return rec.recurrenceDates();
147}
148
149/*!
150 Sets the list of recurrence rules \a rrules to be the rules which define when the event occurs,
151 other than those dates specified explicitly via setRecurrenceDates().
152*/
153void QOrganizerEvent::setRecurrenceRules(const QSet<QOrganizerRecurrenceRule> &rrules)
154{
155 QOrganizerItemRecurrence rec = detail(detailType: QOrganizerItemDetail::TypeRecurrence);
156 rec.setRecurrenceRules(rrules);
157 saveDetail(detail: &rec);
158}
159
160/*!
161 Sets a single recurrence rule \a rrule to be the rule which define when the event occurs, other
162 than those dates specified explicitly via setRecurrenceDates().
163 \sa setRecurrenceRules()
164*/
165void QOrganizerEvent::setRecurrenceRule(const QOrganizerRecurrenceRule &rrule)
166{
167 setRecurrenceRules(QSet<QOrganizerRecurrenceRule>() << rrule);
168}
169
170/*!
171 Returns the list of recurrence rules which define when the event occurs.
172*/
173QSet<QOrganizerRecurrenceRule> QOrganizerEvent::recurrenceRules() const
174{
175 QOrganizerItemRecurrence rec = detail(detailType: QOrganizerItemDetail::TypeRecurrence);
176 return rec.recurrenceRules();
177}
178
179/*!
180 Returns a recurrence rule which has been explicitly set for the event.
181 Note: if more than one rule exists, the order of the rules is undefined, so any one could be returned.
182 */
183QOrganizerRecurrenceRule QOrganizerEvent::recurrenceRule() const
184{
185 QSet<QOrganizerRecurrenceRule> rrules = recurrenceRules();
186 if (!rrules.isEmpty())
187 return *rrules.begin();
188 return QOrganizerRecurrenceRule();
189}
190
191/*!
192 Sets the given list of dates \a exdates to be dates on which the event explicitly does not occur,
193 even if the recurrence rules suggest that the event should occur on those dates. Any previously
194 specified exception dates will be cleared when this function is called.
195 */
196void QOrganizerEvent::setExceptionDates(const QSet<QDate> &exdates)
197{
198 QOrganizerItemRecurrence rec = detail(detailType: QOrganizerItemDetail::TypeRecurrence);
199 rec.setExceptionDates(exdates);
200 saveDetail(detail: &rec);
201}
202
203/*!
204 Sets the given single date \a exdate to be the date on which the event explicitly does not occur,
205 event if the recurrence rules suggest that the event should occur on this date. Any previously
206 specified exception dates will be cleared when this function is called.
207 \sa setExceptionDates()
208 */
209void QOrganizerEvent::setExceptionDate(const QDate &exdate)
210{
211 setExceptionDates(QSet<QDate>() << exdate);
212}
213
214/*!
215 Returns the list of dates on which the event explicitly does not occur despite
216 the recurrence rules for the event
217*/
218QSet<QDate> QOrganizerEvent::exceptionDates() const
219{
220 QOrganizerItemRecurrence rec = detail(detailType: QOrganizerItemDetail::TypeRecurrence);
221 return rec.exceptionDates();
222}
223
224/*!
225 Sets the given list of recurrence rules \a exrules to be the rules which define when
226 the event does not occur. Any previously specified exception rules will be cleared
227 when this function is called.
228*/
229void QOrganizerEvent::setExceptionRules(const QSet<QOrganizerRecurrenceRule> &exrules)
230{
231 QOrganizerItemRecurrence rec = detail(detailType: QOrganizerItemDetail::TypeRecurrence);
232 rec.setExceptionRules(exrules);
233 saveDetail(detail: &rec);
234}
235
236/*!
237 Sets the given single recurrence rules \a xrule to be the rule which defines when
238 the event does not occur. Any previously specified exception rules will be cleared
239 when this function is called.
240 \sa setExceptionRules()
241 */
242void QOrganizerEvent::setExceptionRule(const QOrganizerRecurrenceRule &xrule)
243{
244 setExceptionRules(QSet<QOrganizerRecurrenceRule>() << xrule);
245}
246
247/*!
248 Returns an exception rule which has been explicitly set for the event.
249
250 Note: if more than one exception rule exists, the order of the rules is undefined, so any one
251 could be returned.
252 */
253QOrganizerRecurrenceRule QOrganizerEvent::exceptionRule() const
254{
255 QSet<QOrganizerRecurrenceRule> exrules = exceptionRules();
256 if (!exrules.isEmpty())
257 return *exrules.begin();
258 return QOrganizerRecurrenceRule();
259}
260
261/*!
262 Returns the list of exception rules for the event.
263*/
264QSet<QOrganizerRecurrenceRule> QOrganizerEvent::exceptionRules() const
265{
266 QOrganizerItemRecurrence rec = detail(detailType: QOrganizerItemDetail::TypeRecurrence);
267 return rec.exceptionRules();
268}
269
270/*!
271 Sets the priority of this event to \a priority.
272*/
273void QOrganizerEvent::setPriority(QOrganizerItemPriority::Priority priority)
274{
275 QOrganizerItemPriority pd = detail(detailType: QOrganizerItemDetail::TypePriority);
276 pd.setPriority(priority);
277 saveDetail(detail: &pd);
278}
279
280/*!
281 Returns the priority of the event.
282*/
283QOrganizerItemPriority::Priority QOrganizerEvent::priority() const
284{
285 QOrganizerItemPriority pd = detail(detailType: QOrganizerItemDetail::TypePriority);
286 return pd.priority();
287}
288
289/*!
290 Returns the label of the location at which the event occurs.
291*/
292QString QOrganizerEvent::location() const
293{
294 QOrganizerItemLocation ld = detail(detailType: QOrganizerItemDetail::TypeLocation);
295 return ld.label();
296}
297
298/*!
299 Sets the label of the location at which the event occurs to \a label.
300*/
301void QOrganizerEvent::setLocation(const QString &label)
302{
303 QOrganizerItemLocation ld = detail(detailType: QOrganizerItemDetail::TypeLocation);
304 ld.setLabel(label);
305 saveDetail(detail: &ld);
306}
307
308QT_END_NAMESPACE_ORGANIZER
309

source code of qtpim/src/organizer/items/qorganizerevent.cpp