2 // Tizen Web Device API
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
18 #include <Commons/Exception.h>
19 #include "CalendarEvent.h"
25 CalendarEvent::CalendarEvent():
26 m_id(UNDEFINED_ITEM_ID),
27 m_parentId(UNDEFINED_ITEM_ID),
28 m_calendarId(UNDEFINED_CALENDAR_ID),
29 m_startTime(UNDEFINED_TIME),
30 m_endTime(UNDEFINED_TIME),
31 m_recurrence(new EventRecurrenceRule()),
32 m_status(UNDEFINED_STATUS),
33 m_alarms(new EventAlarmList()),
34 m_categories(new StringArray()),
35 m_categoriesJSRef(NULL),
37 m_lastModifiedDate(UNDEFINED_TIME),
38 m_visibility(PUBLIC_VISIBILITY),
39 m_availability(BUSY_FB),
41 m_recurrenceId(UNDEFINED_TIME),
42 m_attendees(new EventAttendeeList()),
44 m_geolocation(new DeviceAPI::Tizen::SimpleCoordinates(UNDEFINED_GEO, UNDEFINED_GEO)),
45 m_timeZone(DEFAULT_TIMEZONE),
46 m_priority(LOW_PRIORITY),
47 m_createdDate(UNDEFINED_TIME),
48 m_completedDate(UNDEFINED_TIME),
50 m_calendarType(EVENT_TYPE),
55 CalendarEvent::CalendarEvent(const CalendarEvent &original)
57 LoggerD("Copy constructor called.");
59 m_id = original.getId();
60 m_parentId = original.getParentId();
61 m_calendarId = original.getCalendarId();
62 m_description = original.getDescription();
63 m_subject = original.getSubject();
64 m_startTime = original.getStartTime();
65 m_endTime = original.getEndTime();
66 m_location = original.getLocation();
68 EventRecurrenceRulePtr recurrenceRulePtr( new EventRecurrenceRule() );
69 m_recurrence = recurrenceRulePtr;
70 m_recurrence->setFrequency(original.getRecurrenceRule()->getFrequency());
71 m_recurrence->setInterval(original.getRecurrenceRule()->getInterval());
72 m_recurrence->setEndDate(original.getRecurrenceRule()->getEndDate());
73 m_recurrence->setOccurrenceCount(original.getRecurrenceRule()->getOccurrenceCount());
74 m_recurrence->setDaysOfTheMonth(original.getRecurrenceRule()->getDaysOfTheMonth());
75 m_recurrence->setDaysOfTheWeek(original.getRecurrenceRule()->getDaysOfTheWeek());
76 m_recurrence->setDaysOfTheWeekJSRef(NULL);
77 m_recurrence->setDaysOfTheYear(original.getRecurrenceRule()->getDaysOfTheYear());
78 m_recurrence->setWeeksOfTheYear(original.getRecurrenceRule()->getWeeksOfTheYear());
79 m_recurrence->setSetPositions(original.getRecurrenceRule()->getSetPositions());
80 m_recurrence->setSetPositionsJSRef(NULL);
81 m_recurrence->setExceptions(original.getRecurrenceRule()->getExceptions());
82 m_recurrence->setExceptionsJSRef(NULL);
83 m_recurrence->setTimeZone(original.getRecurrenceRule()->getTimeZone());
85 m_status = original.getStatus();
87 LoggerD("Copying alarms...");
88 EventAlarmListPtr alarmsPtr( new EventAlarmList() );
90 for( unsigned int i=0; i<original.getAlarms()->size(); i++) {
91 EventAlarmPtr alarmPtr( new EventAlarm() );
92 alarmPtr->setAbsoluteDate(original.getAlarms()->at(i)->getAbsoluteDate());
93 alarmPtr->setDuration(original.getAlarms()->at(i)->getDuration());
94 alarmPtr->setMethod(original.getAlarms()->at(i)->getMethod());
95 alarmPtr->setTimeZone(original.getAlarms()->at(i)->getTimeZone());
96 alarmPtr->setDescription(original.getAlarms()->at(i)->getDescription());
97 m_alarms->push_back(alarmPtr);
100 StringArrayPtr categoriesPtr( new StringArray() );
101 m_categories = categoriesPtr;
102 *m_categories = *(original.getCategories());
103 m_categoriesJSRef = NULL;
105 m_isAllDay = original.getIsAllDay();
106 m_organizer = original.getOrganizer();
107 m_lastModifiedDate = original.getLastModifiedDate();
108 m_visibility = original.getVisibility();
109 m_availability = original.getAvailability();
110 m_uid = original.getUId();
111 m_recurrenceId = original.getRecurrenceId();
113 LoggerD("Copying attendees...");
114 EventAttendeeListPtr attendeesPtr( new EventAttendeeList() );
115 m_attendees = attendeesPtr;
116 for( unsigned int i=0; i<original.getAttendees()->size(); i++) {
117 EventAttendeePtr attendeePtr( new EventAttendee() );
118 attendeePtr->setName(original.getAttendees()->at(i)->getName());
119 attendeePtr->setURI(original.getAttendees()->at(i)->getURI());
120 attendeePtr->setRole(original.getAttendees()->at(i)->getRole());
121 attendeePtr->setStatus(original.getAttendees()->at(i)->getStatus());
122 attendeePtr->setRSVP(original.getAttendees()->at(i)->getRSVP());
123 attendeePtr->setType(original.getAttendees()->at(i)->getType());
124 attendeePtr->setGroup(original.getAttendees()->at(i)->getGroup());
125 attendeePtr->setDelegatorURI(original.getAttendees()->at(i)->getDelegatorURI());
126 attendeePtr->setDelegateURI(original.getAttendees()->at(i)->getDelegateURI());
127 attendeePtr->setAddressBookId(original.getAttendees()->at(i)->getAddressBookId());
128 attendeePtr->setContactId(original.getAttendees()->at(i)->getContactId());
129 m_attendees->push_back(attendeePtr);
132 m_isDetached = original.getIsDetached();
134 DeviceAPI::Tizen::SimpleCoordinatesPtr geolocationPtr( new DeviceAPI::Tizen::SimpleCoordinates(original.getGeolocation()->getLatitude(), original.getGeolocation()->getLongitude()));
135 m_geolocation = geolocationPtr;
137 m_timeZone = original.getTimeZone();
138 m_priority = original.getPriority();
139 m_createdDate = original.getCreatedDate();
140 m_completedDate = original.getCompletedDate();
141 m_progress = original.getProgress();
142 m_calendarType = original.getCalendarType();
144 LoggerD("Copying done.");
147 CalendarEvent::~CalendarEvent()
149 if(m_categoriesJSRef) {
150 LoggerD("Unprotect JS categories.");
151 JSValueUnprotect(m_context, m_categoriesJSRef);
155 int CalendarEvent::getId() const
160 void CalendarEvent::setId(int value)
165 std::stringstream ss;
168 LoggerD("m_id: "<<m_id<<", m_uid: "<<m_uid);
171 void CalendarEvent::resetId()
173 m_id = UNDEFINED_ITEM_ID;
174 m_uid = UNDEFINED_ID;
177 bool CalendarEvent::getIdIsSet() const
179 return !(m_id==UNDEFINED_ITEM_ID);
182 int CalendarEvent::getParentId() const
187 void CalendarEvent::setParentId(int value)
192 int CalendarEvent::getCalendarId() const
197 void CalendarEvent::setCalendarId(int value)
199 m_calendarId = value;
202 std::string CalendarEvent::getDescription() const
204 return m_description;
207 void CalendarEvent::setDescription(const std::string &value)
209 m_description = value;
212 std::string CalendarEvent::getSubject() const
217 void CalendarEvent::setSubject(const std::string &value)
222 long long int CalendarEvent::getStartTime() const
227 void CalendarEvent::setStartTime(long long int value)
232 long long int CalendarEvent::getEndTime() const
237 void CalendarEvent::setEndTime(long long int value)
242 std::string CalendarEvent::getLocation() const
247 void CalendarEvent::setLocation(const std::string &value)
252 EventRecurrenceRulePtr CalendarEvent::getRecurrenceRule() const
257 void CalendarEvent::setRecurrenceRule(EventRecurrenceRulePtr value)
259 m_recurrence = value;
262 CalendarEvent::EventStatus CalendarEvent::getStatus() const
264 return m_status == UNDEFINED_STATUS ? TENTATIVE_STATUS : m_status;
267 void CalendarEvent::setStatus(EventStatus value)
272 EventAlarmListPtr CalendarEvent::getAlarms() const
276 void CalendarEvent::setAlarms(const EventAlarmListPtr value)
281 StringArrayPtr CalendarEvent::getCategories() const
285 void CalendarEvent::setCategories(const StringArrayPtr value)
287 m_categories = value;
290 JSObjectRef CalendarEvent::getCategoriesJSRef() const
292 return m_categoriesJSRef;
294 void CalendarEvent::setCategoriesJSRef(const JSObjectRef value)
296 m_categoriesJSRef = value;
299 void CalendarEvent::display() const
301 LoggerD("m_id " << m_id);
302 LoggerD("m_parentId " << m_parentId);
303 LoggerD("m_calendarId " << m_calendarId);
304 LoggerD("m_calendarType " << m_calendarType);
305 LoggerD("m_description " << m_description);
306 LoggerD("m_subject " << m_subject);
308 LoggerD("m_startTime " << m_startTime);
310 LoggerD("m_endTime " << m_endTime);
311 LoggerD("m_location " << m_location);
312 LoggerD("m_recurrence " << m_recurrence);
313 LoggerD("m_status " << m_status);
314 LoggerD("m_isAllDay " << m_isAllDay);
315 LoggerD("m_organizer " << m_organizer);
316 LoggerD("m_lastModifiedDate " << m_lastModifiedDate);
317 LoggerD("m_visibility " << m_visibility);
318 LoggerD("m_availability " << m_availability);
320 if(m_recurrence->getFrequency()!=EventRecurrenceRule::NO_RECURRENCE) {
321 LoggerD("recurrence frequency " << m_recurrence->getFrequency());
322 LoggerD("recurrence interval " << m_recurrence->getInterval());
323 LoggerD("recurrence recurrenceCount " << m_recurrence->getOccurrenceCount());
324 LoggerD("recurrence endDate " << m_recurrence->getEndDate());
328 bool CalendarEvent::validate() const
330 LoggerI("Nothing to validate.");
334 bool CalendarEvent::getIsAllDay() const
339 void CalendarEvent::setIsAllDay(bool value)
344 std::string CalendarEvent::getOrganizer() const
349 void CalendarEvent::setOrganizer(const std::string &value)
354 long long int CalendarEvent::getLastModifiedDate() const
356 return m_lastModifiedDate;
359 void CalendarEvent::setLastModifiedDate(long long int value)
361 m_lastModifiedDate = value;
364 CalendarEvent::EventVisibility CalendarEvent::getVisibility() const
366 return m_visibility == UNDEFINED_VISIBILITY ? PUBLIC_VISIBILITY : m_visibility;
369 void CalendarEvent::setVisibility(EventVisibility value)
371 m_visibility = value;
374 CalendarEvent::EventAvailability CalendarEvent::getAvailability() const
376 return m_availability == UNDEFINED_AVAILABILITY ? BUSY_FB : m_availability;
379 void CalendarEvent::setAvailability(EventAvailability value)
381 m_availability = value;
384 std::string CalendarEvent::getUId() const
389 void CalendarEvent::setUId(const std::string &value)
394 long long int CalendarEvent::getRecurrenceId() const
396 return m_recurrenceId;
399 void CalendarEvent::setRecurrenceId(long long int value)
401 m_recurrenceId = value;
404 EventAttendeeListPtr CalendarEvent::getAttendees() const
409 void CalendarEvent::setAttendees(const EventAttendeeListPtr value)
414 bool CalendarEvent::getIsDetached() const
419 void CalendarEvent::setIsDetached(bool value)
421 m_isDetached = value;
424 DeviceAPI::Tizen::SimpleCoordinatesPtr CalendarEvent::getGeolocation() const
426 return m_geolocation;
429 void CalendarEvent::setGeolocation(DeviceAPI::Tizen::SimpleCoordinatesPtr value)
431 m_geolocation = value;
434 std::string CalendarEvent::getTimeZone() const
439 void CalendarEvent::setTimeZone(std::string value)
444 CalendarEvent::TaskPriority CalendarEvent::getPriority() const
449 void CalendarEvent::setPriority(TaskPriority value)
454 long long int CalendarEvent::getCreatedDate() const
456 return m_createdDate;
459 void CalendarEvent::setCreatedDate(long long int value)
461 m_createdDate = value;
464 long long int CalendarEvent::getCompletedDate() const
466 return m_completedDate;
469 void CalendarEvent::setCompletedDate(long long int value)
471 m_completedDate = value;
474 int CalendarEvent::getProgress() const
479 void CalendarEvent::setProgress(int value)
484 CalendarEvent::CalendarType CalendarEvent::getCalendarType() const
486 return m_calendarType;
489 void CalendarEvent::setCalendarType(CalendarType type)
491 m_calendarType = type;
494 JSContextRef CalendarEvent::getContext() const
499 void CalendarEvent::setContext(const JSContextRef contextRef)
501 m_context = contextRef;