2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 #include <dpl/log/log.h>
19 #include <CommonsJavaScript/Validator.h>
20 #include <CommonsJavaScript/JSUtils.h>
21 #include "JSCalendarItem.h"
22 #include "JSCalendarItemProperties.h"
23 #include "JSCalendarEventId.h"
24 #include "JSCalendarItemGeo.h"
25 #include "CalendarConverter.h"
26 #include "JSCalendar.h"
27 #include "JSCalendarManager.h"
28 #include "JSCalendarAttendee.h"
29 #include "JSCalendarRecurrenceRule.h"
30 #include "JSCalendarAlarm.h"
31 #include <Tizen/TimeUtil/TimeUtilConverter.h>
32 #include "API/TimeUtil/DurationProperties.h"
34 using namespace TizenApis::Api::Calendar;
35 using namespace WrtDeviceApis::Commons;
36 using namespace WrtDeviceApis::CommonsJavaScript;
39 const int DEFAULT_EVENT_INTERVAL = 1;
46 std::vector<std::string> CalendarConverter::m_allowedAttributes;
48 CalendarConverter::CalendarConverter(JSContextRef context, CalendarEvent::CalendarType calendarType) : Converter(context)
52 m_calendarType = calendarType;
54 // for WAC style search filter
55 if (m_allowedAttributes.size() == 0) {
56 m_allowedAttributes.push_back(TIZEN_CALENDAR_ITEM_ID);
57 m_allowedAttributes.push_back(TIZEN_CALENDAR_ITEM_SUMMARY);
58 m_allowedAttributes.push_back(TIZEN_CALENDAR_ITEM_DESCRIPTION);
59 m_allowedAttributes.push_back(TIZEN_CALENDAR_ITEM_LOCATION);
60 m_allowedAttributes.push_back("category");
61 m_allowedAttributes.push_back(TIZEN_CALENDAR_ITEM_STATUS);
62 m_allowedAttributes.push_back("initialStartDate");
63 m_allowedAttributes.push_back("endStartDate");
67 CalendarConverter::~CalendarConverter()
72 JSValueRef CalendarConverter::toJSValueRefItem(const CalendarEventPtr& arg)
74 return JSUtils::makeObject(m_context, JSCalendarItem::getClassRef(), arg);
77 JSValueRef CalendarConverter::toJSValueRef(const CalendarEventListPtr &arg)
79 return toJSValueRef_(*arg, &CalendarConverter::toJSValueRefItem, this);
82 JSValueRef CalendarConverter::toJSValueRefCalendar(const ICalendarPtr& arg)
84 CalendarPrivObject *priv = new CalendarPrivObject(m_context, arg);
85 return JSObjectMake(m_context, JSCalendar::getClassRef(), priv);
88 JSValueRef CalendarConverter::toJSValueRef(const std::vector<ICalendarPtr> &arg)
90 return toJSValueRef_(arg, &CalendarConverter::toJSValueRefCalendar, this);
93 CalendarEvent::EventAlarmType CalendarConverter::toEventAlarmType(std::string alarmMethod)
96 if (!alarmMethod.compare(TIZEN_CALENDAR_PROPERTY_DISPLAY_ALARM))
97 return CalendarEvent::SILENT_ALARM;
98 else if (!alarmMethod.compare(TIZEN_CALENDAR_PROPERTY_SOUND_ALARM))
99 return CalendarEvent::SOUND_ALARM;
101 Throw(ConversionException);
103 return CalendarEvent::SOUND_ALARM;
106 std::string CalendarConverter::toTizenValue(CalendarEvent::EventAlarmType abstractValue) const
108 switch (abstractValue) {
109 case CalendarEvent::SILENT_ALARM:
110 return TIZEN_CALENDAR_PROPERTY_DISPLAY_ALARM;
111 case CalendarEvent::SOUND_ALARM:
112 return TIZEN_CALENDAR_PROPERTY_SOUND_ALARM;
116 ThrowMsg(ConversionException, "Invalid alarm type");
119 CalendarEvent::EventStatus CalendarConverter::toEventStatus(std::string tizenValue) const
121 if(!tizenValue.compare(TIZEN_CALENDAR_PROPERTY_TENTATIVE_STATUS))
122 return CalendarEvent::TENTATIVE_STATUS;
123 else if (!tizenValue.compare(TIZEN_CALENDAR_PROPERTY_CONFIRMED_STATUS))
124 return CalendarEvent::CONFIRMED_STATUS;
125 else if (!tizenValue.compare(TIZEN_CALENDAR_PROPERTY_CANCELLED_STATUS))
126 return CalendarEvent::CANCELLED_STATUS;
127 else if (!tizenValue.compare(TIZEN_CALENDAR_PROPERTY_NEEDS_ACTION_STATUS))
128 return CalendarEvent::NEEDS_ACTION_STATUS;
129 else if (!tizenValue.compare(TIZEN_CALENDAR_PROPERTY_IN_PROCESS_STATUS))
130 return CalendarEvent::IN_PROCESS_STATUS;
131 else if (!tizenValue.compare(TIZEN_CALENDAR_PROPERTY_COMPLETED_STATUS))
132 return CalendarEvent::COMPLETED_STATUS;
134 // default value setting.
135 if(m_calendarType == CalendarEvent::EVENT_TYPE) {
136 return CalendarEvent::TENTATIVE_STATUS;
138 return CalendarEvent::NEEDS_ACTION_STATUS;
142 std::string CalendarConverter::toTizenValue(CalendarEvent::EventStatus abstractValue)
145 switch (abstractValue) {
146 case CalendarEvent::TENTATIVE_STATUS:
147 return TIZEN_CALENDAR_PROPERTY_TENTATIVE_STATUS;
148 case CalendarEvent::CONFIRMED_STATUS:
149 return TIZEN_CALENDAR_PROPERTY_CONFIRMED_STATUS;
150 case CalendarEvent::CANCELLED_STATUS:
151 return TIZEN_CALENDAR_PROPERTY_CANCELLED_STATUS;
152 case CalendarEvent::NEEDS_ACTION_STATUS:
153 return TIZEN_CALENDAR_PROPERTY_NEEDS_ACTION_STATUS;
154 case CalendarEvent::IN_PROCESS_STATUS:
155 return TIZEN_CALENDAR_PROPERTY_IN_PROCESS_STATUS;
156 case CalendarEvent::COMPLETED_STATUS:
157 return TIZEN_CALENDAR_PROPERTY_COMPLETED_STATUS;
162 ThrowMsg(ConversionException, "Invalid status");
165 EventRecurrenceRule::EventRecurrence CalendarConverter::toRecurrenceFrequency(
166 std::string tizenValue) const
168 if (!tizenValue.compare(TIZEN_CALENDAR_PROPERTY_DAILY_RECURRENCE))
169 return EventRecurrenceRule::DAILY_RECURRENCE;
170 else if (!tizenValue.compare(TIZEN_CALENDAR_PROPERTY_WEEKLY_RECURRENCE))
171 return EventRecurrenceRule::WEEKLY_RECURRENCE;
172 else if (!tizenValue.compare(TIZEN_CALENDAR_PROPERTY_MONTHLY_RECURRENCE))
173 return EventRecurrenceRule::MONTHLY_RECURRENCE;
174 else if (!tizenValue.compare(TIZEN_CALENDAR_PROPERTY_YEARLY_RECURRENCE))
175 return EventRecurrenceRule::YEARLY_RECURRENCE;
177 return EventRecurrenceRule::NO_RECURRENCE;
180 std::string CalendarConverter::toTizenValue(
181 EventRecurrenceRule::EventRecurrence abstractValue) const
183 switch (abstractValue) {
184 case EventRecurrenceRule::DAILY_RECURRENCE:
185 return TIZEN_CALENDAR_PROPERTY_DAILY_RECURRENCE;
186 case EventRecurrenceRule::WEEKLY_RECURRENCE:
187 case EventRecurrenceRule::WEEKDAY_RECURRENCE:
188 return TIZEN_CALENDAR_PROPERTY_WEEKLY_RECURRENCE;
189 case EventRecurrenceRule::MONTHLY_RECURRENCE:
190 case EventRecurrenceRule::MONTHLY_ON_DAY_RECURRENCE:
191 return TIZEN_CALENDAR_PROPERTY_MONTHLY_RECURRENCE;
192 case EventRecurrenceRule::YEARLY_RECURRENCE:
193 return TIZEN_CALENDAR_PROPERTY_YEARLY_RECURRENCE;
194 case EventRecurrenceRule::NO_RECURRENCE:
201 EventRecurrenceRulePtr CalendarConverter::toEventRecurrenceRule(JSValueRef rrule)
204 EventRecurrenceRulePtr result(new EventRecurrenceRule());
205 const ScopedJSStringRef frequencyStr(JSStringCreateWithUTF8CString(TIZEN_RECURRENCE_RULE_FREQUENCY));
206 const ScopedJSStringRef intervalStr(JSStringCreateWithUTF8CString(TIZEN_RECURRENCE_RULE_INTERVAL));
207 const ScopedJSStringRef untilDateStr(JSStringCreateWithUTF8CString(TIZEN_RECURRENCE_RULE_UNTIL_DATE));
208 const ScopedJSStringRef occurrenceCountStr(JSStringCreateWithUTF8CString(TIZEN_RECURRENCE_RULE_OCCURRENCE_COUNT));
209 // const ScopedJSStringRef daysOfTheMonthStr(JSStringCreateWithUTF8CString(TIZEN_RECURRENCE_RULE_DAYS_OF_THE_MONTH));
210 const ScopedJSStringRef daysOfTheWeekStr(JSStringCreateWithUTF8CString(TIZEN_RECURRENCE_RULE_DAYS_OF_THE_WEEK));
211 // const ScopedJSStringRef daysOfTheYearStr(JSStringCreateWithUTF8CString(TIZEN_RECURRENCE_RULE_DAYS_OF_THE_YEAR));
212 // const ScopedJSStringRef weeksOfTheYearStr(JSStringCreateWithUTF8CString(TIZEN_RECURRENCE_RULE_WEEKS_OF_THE_YEAR));
213 const ScopedJSStringRef setPositionStr(JSStringCreateWithUTF8CString(TIZEN_RECURRENCE_RULE_SET_POSITION));
214 const ScopedJSStringRef exceptionsStr(JSStringCreateWithUTF8CString(TIZEN_RECURRENCE_RULE_EXCEPTIONS));
216 JSObjectRef arg = toJSObjectRef(rrule);
218 JSValueRef frequencyData = JSObjectGetProperty(m_context, arg, frequencyStr.get(), NULL);
219 JSValueRef intervalData = JSObjectGetProperty(m_context, arg, intervalStr.get(), NULL);
220 JSValueRef untilDateData = JSObjectGetProperty(m_context, arg, untilDateStr.get(), NULL);
221 JSValueRef occurrenceCountData = JSObjectGetProperty(m_context, arg, occurrenceCountStr.get(), NULL);
222 // JSValueRef daysOfTheMonthData = JSObjectGetProperty(m_context, arg, daysOfTheMonthStr.get(), NULL);
223 JSValueRef daysOfTheWeekData = JSObjectGetProperty(m_context, arg, daysOfTheWeekStr.get(), NULL);
224 // JSValueRef daysOfTheYearData = JSObjectGetProperty(m_context, arg, daysOfTheYearStr.get(), NULL);
225 // JSValueRef weeksOfTheYearData = JSObjectGetProperty(m_context, arg, weeksOfTheYearStr.get(), NULL);
226 JSValueRef setPositionData = JSObjectGetProperty(m_context, arg, setPositionStr.get(), NULL);
227 JSValueRef exceptionsData = JSObjectGetProperty(m_context, arg, exceptionsStr.get(), NULL);
229 if (!JSValueIsUndefined(m_context, frequencyData)) {
230 result->setFrequency(toRecurrenceFrequency(toString(frequencyData)));
232 if (!JSValueIsUndefined(m_context, intervalData)) {
233 result->setInterval(toInt(intervalData));
235 result->setInterval(DEFAULT_EVENT_INTERVAL);
237 if (!JSValueIsUndefined(m_context, untilDateData)) {
238 if (!JSValueIsNull(m_context, untilDateData)) {
239 result->setEndDate(toDateTimeT(untilDateData));
241 result->setEndDate(0);
244 if (!JSValueIsUndefined(m_context, occurrenceCountData)) {
245 result->setOccurrenceCount(toLong(occurrenceCountData));
247 /* if (!JSValueIsUndefined(m_context, daysOfTheMonthData)) {
248 result->setDaysOfTheMonth(toVectorOfInts(daysOfTheMonthData));
250 if (!JSValueIsUndefined(m_context, daysOfTheWeekData)) {
251 result->setDaysOfTheWeek(toVectorOfStrings(daysOfTheWeekData));
253 /* if (!JSValueIsUndefined(m_context, daysOfTheYearData)) {
254 result->setDaysOfTheYear(toVectorOfInts(daysOfTheYearData));
256 if (!JSValueIsUndefined(m_context, weeksOfTheYearData)) {
257 result->setWeeksOfTheYear(toVectorOfInts(weeksOfTheYearData));
259 if (!JSValueIsUndefined(m_context, setPositionData)) {
260 Throw(UnsupportedException);
261 //result->setSetPosition(toBool(setPositionData));
263 if (!JSValueIsUndefined(m_context, exceptionsData)) {
264 result->setExceptions(toVectorOfTimeT(exceptionsData));
270 CalendarEvent::EventVisibility CalendarConverter::toEventVisibility(std::string tizenValue)
273 if(!tizenValue.compare(TIZEN_CALENDAR_PROPERTY_PUBLIC_VISIBILITY))
274 return CalendarEvent::PUBLIC_VISIBILITY;
275 else if (!tizenValue.compare(TIZEN_CALENDAR_PROPERTY_PRIVATE_VISIBILITY))
276 return CalendarEvent::PRIVATE_VISIBILITY;
277 else if (!tizenValue.compare(TIZEN_CALENDAR_PROPERTY_CONFIDENTIAL_VISIBILITY))
278 return CalendarEvent::CONFIDENTIAL_VISIBILITY;
280 return CalendarEvent::PUBLIC_VISIBILITY;
283 std::string CalendarConverter::toTizenValue(
284 CalendarEvent::EventVisibility abstractValue) const
286 switch (abstractValue) {
287 case CalendarEvent::PUBLIC_VISIBILITY:
288 return TIZEN_CALENDAR_PROPERTY_PUBLIC_VISIBILITY;
289 case CalendarEvent::PRIVATE_VISIBILITY:
290 return TIZEN_CALENDAR_PROPERTY_PRIVATE_VISIBILITY;
291 case CalendarEvent::CONFIDENTIAL_VISIBILITY:
292 return TIZEN_CALENDAR_PROPERTY_CONFIDENTIAL_VISIBILITY;
297 return TIZEN_CALENDAR_PROPERTY_PUBLIC_VISIBILITY;
300 CalendarEvent::EventAvailability CalendarConverter::toEventAvailability(std::string tizenValue)
303 if(!tizenValue.compare(TIZEN_CALENDAR_PROPERTY_BUSY))
304 return CalendarEvent::BUSY_FB;
305 else if (!tizenValue.compare(TIZEN_CALENDAR_PROPERTY_BUSY_UNAVAILABLE_FB))
306 return CalendarEvent::BUSY_UNAVAILABLE_FB;
307 else if (!tizenValue.compare(TIZEN_CALENDAR_PROPERTY_FREE))
308 return CalendarEvent::FREE_FB;
309 else if (!tizenValue.compare(TIZEN_CALENDAR_PROPERTY_BUSY_TENTATIVE))
310 return CalendarEvent::BUSY_TENTATIVE_FB;
312 return CalendarEvent::BUSY_FB;
315 std::string CalendarConverter::toTizenValue(
316 CalendarEvent::EventAvailability abstractValue) const
318 switch (abstractValue) {
319 case CalendarEvent::BUSY_FB:
320 return TIZEN_CALENDAR_PROPERTY_BUSY;
321 case CalendarEvent::BUSY_UNAVAILABLE_FB:
322 return TIZEN_CALENDAR_PROPERTY_BUSY_UNAVAILABLE_FB;
323 case CalendarEvent::FREE_FB:
324 return TIZEN_CALENDAR_PROPERTY_FREE;
325 case CalendarEvent::BUSY_TENTATIVE_FB:
326 return TIZEN_CALENDAR_PROPERTY_BUSY_TENTATIVE;
331 return TIZEN_CALENDAR_PROPERTY_BUSY;
334 EventAttendee::EventAttendeeRole CalendarConverter::toEventAttendeeRole(std::string tizenValue)
337 if(!tizenValue.compare(TIZEN_CALENDAR_PROPERTY_REQ_PARTICIPANT_ROLE))
338 return EventAttendee::REQ_PARTICIPANT_ROLE;
339 else if (!tizenValue.compare(TIZEN_CALENDAR_PROPERTY_OPT_PARTICIPANT_ROLE))
340 return EventAttendee::OPT_PARTICIPANT_ROLE;
341 else if (!tizenValue.compare(TIZEN_CALENDAR_PROPERTY_NON_PARTICIPANT_ROLE))
342 return EventAttendee::NON_PARTICIPANT_ROLE;
343 else if (!tizenValue.compare(TIZEN_CALENDAR_PROPERTY_CHAIR_ROLE))
344 return EventAttendee::CHAIR_ROLE;
346 return EventAttendee::REQ_PARTICIPANT_ROLE;
349 std::string CalendarConverter::toTizenValue(
350 EventAttendee::EventAttendeeRole abstractValue) const
352 switch (abstractValue) {
353 case EventAttendee::REQ_PARTICIPANT_ROLE:
354 return TIZEN_CALENDAR_PROPERTY_REQ_PARTICIPANT_ROLE;
355 case EventAttendee::OPT_PARTICIPANT_ROLE:
356 return TIZEN_CALENDAR_PROPERTY_OPT_PARTICIPANT_ROLE;
357 case EventAttendee::NON_PARTICIPANT_ROLE:
358 return TIZEN_CALENDAR_PROPERTY_NON_PARTICIPANT_ROLE;
359 case EventAttendee::CHAIR_ROLE:
360 return TIZEN_CALENDAR_PROPERTY_CHAIR_ROLE;
364 return TIZEN_CALENDAR_PROPERTY_REQ_PARTICIPANT_ROLE;
367 EventAttendee::EventAttendeeStatus CalendarConverter::toEventAttendeeStatus(std::string tizenValue)
370 if(!tizenValue.compare(TIZEN_CALENDAR_PROPERTY_PENDING_STATUS))
371 return EventAttendee::PENDING_AT_STATUS;
372 else if (!tizenValue.compare(TIZEN_CALENDAR_PROPERTY_ACCEPTED_STATUS))
373 return EventAttendee::ACCEPTED_AT_STATUS;
374 else if (!tizenValue.compare(TIZEN_CALENDAR_PROPERTY_DECLINED_STATUS))
375 return EventAttendee::DECLINED_AT_STATUS;
376 else if (!tizenValue.compare(TIZEN_CALENDAR_PROPERTY_TENTATIVE_STATUS))
377 return EventAttendee::TENTATIVE_AT_STATUS;
378 else if (!tizenValue.compare(TIZEN_CALENDAR_PROPERTY_DELEGATED_STATUS))
379 return EventAttendee::DELEGATED_AT_STATUS;
380 else if (!tizenValue.compare(TIZEN_CALENDAR_PROPERTY_COMPLETED_STATUS))
381 return EventAttendee::COMPLETED_AT_STATUS;
382 else if (!tizenValue.compare(TIZEN_CALENDAR_PROPERTY_IN_PROCESS_STATUS))
383 return EventAttendee::IN_PROCESS_AT_STATUS;
385 return EventAttendee::PENDING_AT_STATUS;
388 std::string CalendarConverter::toTizenValue(
389 EventAttendee::EventAttendeeStatus abstractValue) const
391 switch (abstractValue) {
392 case EventAttendee::PENDING_AT_STATUS:
393 return TIZEN_CALENDAR_PROPERTY_PENDING_STATUS;
394 case EventAttendee::ACCEPTED_AT_STATUS:
395 return TIZEN_CALENDAR_PROPERTY_ACCEPTED_STATUS;
396 case EventAttendee::DECLINED_AT_STATUS:
397 return TIZEN_CALENDAR_PROPERTY_DECLINED_STATUS;
398 case EventAttendee::TENTATIVE_AT_STATUS:
399 return TIZEN_CALENDAR_PROPERTY_TENTATIVE_STATUS;
400 case EventAttendee::DELEGATED_AT_STATUS:
401 return TIZEN_CALENDAR_PROPERTY_DELEGATED_STATUS;
402 case EventAttendee::COMPLETED_AT_STATUS:
403 return TIZEN_CALENDAR_PROPERTY_COMPLETED_STATUS;
404 case EventAttendee::IN_PROCESS_AT_STATUS:
405 return TIZEN_CALENDAR_PROPERTY_IN_PROCESS_STATUS;
409 return TIZEN_CALENDAR_PROPERTY_PENDING_STATUS;
412 EventAttendee::EventAttendeeType CalendarConverter::toEventAttendeeType(std::string tizenValue)
415 if(!tizenValue.compare(TIZEN_CALENDAR_PROPERTY_INDIVIDUAL_TYPE))
416 return EventAttendee::INDIVIDUAL_TYPE;
417 else if (!tizenValue.compare(TIZEN_CALENDAR_PROPERTY_GROUP_TYPE))
418 return EventAttendee::GROUP_TYPE;
419 else if (!tizenValue.compare(TIZEN_CALENDAR_PROPERTY_RESOURCE_TYPE))
420 return EventAttendee::RESOURCE_TYPE;
421 else if (!tizenValue.compare(TIZEN_CALENDAR_PROPERTY_ROOM_TYPE))
422 return EventAttendee::ROOM_TYPE;
423 else if (!tizenValue.compare(TIZEN_CALENDAR_PROPERTY_UNKNOWN_TYPE))
424 return EventAttendee::UNKNOWN_TYPE;
426 return EventAttendee::INDIVIDUAL_TYPE;
429 std::string CalendarConverter::toTizenValue(
430 EventAttendee::EventAttendeeType abstractValue) const
432 switch (abstractValue) {
433 case EventAttendee::INDIVIDUAL_TYPE:
434 return TIZEN_CALENDAR_PROPERTY_INDIVIDUAL_TYPE;
435 case EventAttendee::GROUP_TYPE:
436 return TIZEN_CALENDAR_PROPERTY_GROUP_TYPE;
437 case EventAttendee::RESOURCE_TYPE:
438 return TIZEN_CALENDAR_PROPERTY_RESOURCE_TYPE;
439 case EventAttendee::ROOM_TYPE:
440 return TIZEN_CALENDAR_PROPERTY_ROOM_TYPE;
441 case EventAttendee::UNKNOWN_TYPE:
442 return TIZEN_CALENDAR_PROPERTY_UNKNOWN_TYPE;
447 return TIZEN_CALENDAR_PROPERTY_INDIVIDUAL_TYPE;
450 JSValueRef CalendarConverter::toFunctionOrNull(const JSValueRef& arg)
452 if (Validator(m_context).isCallback(arg)) {
454 } else if (!JSValueIsNull(m_context,
455 arg) && !JSValueIsUndefined(m_context, arg)) {
456 ThrowMsg(InvalidArgumentException, "Not a function nor JS null.");
461 JSValueRef CalendarConverter::toFunction(const JSValueRef& arg)
463 if (Validator(m_context).isCallback(arg)) {
465 } else if (JSValueIsNull(m_context,
466 arg) || JSValueIsUndefined(m_context, arg)) {
467 ThrowMsg(ConversionException, "JS null passed as function.");
469 ThrowMsg(InvalidArgumentException, "Not a function nor JS null.");
472 void CalendarConverter::toEventFilterConvertId(
473 const EventFilterPtr &result,
474 const JSValueRef &filters)
476 const ScopedJSStringRef idStr(JSStringCreateWithUTF8CString(TIZEN_CALENDAR_ITEM_ID));
477 JSObjectRef filterObj = toJSObjectRef(filters);
478 if (JSObjectHasProperty(m_context, filterObj, idStr.get())) {
479 LogDebug("converting id");
480 JSValueRef value = JSObjectGetProperty(m_context, filterObj,
482 result->setIdFilter(toString(value));
486 void CalendarConverter::toEventFilterConvertSummary(
487 const EventFilterPtr &result,
488 const JSValueRef &filters)
490 const ScopedJSStringRef summaryStr(JSStringCreateWithUTF8CString(TIZEN_CALENDAR_ITEM_SUMMARY));
491 JSObjectRef filterObj = toJSObjectRef(filters);
492 if (JSObjectHasProperty(m_context, filterObj, summaryStr.get())) {
493 LogDebug("converting summary");
494 JSValueRef value = JSObjectGetProperty(m_context,
498 result->setSubjectFilter(toString(value));
502 void CalendarConverter::toEventFilterConvertDescription(
503 const EventFilterPtr &result,
504 const JSValueRef &filters)
506 const ScopedJSStringRef descriptionStr(JSStringCreateWithUTF8CString(
507 TIZEN_CALENDAR_ITEM_DESCRIPTION));
508 JSObjectRef filterObj = toJSObjectRef(filters);
509 if (JSObjectHasProperty(m_context, filterObj, descriptionStr.get())) {
510 LogDebug("converting description");
511 JSValueRef value = JSObjectGetProperty(m_context,
513 descriptionStr.get(),
515 result->setDescriptionFilter(toString(value));
519 void CalendarConverter::toEventFilterConvertLocation(
520 const EventFilterPtr &result,
521 const JSValueRef &filters)
523 const ScopedJSStringRef locationStr(JSStringCreateWithUTF8CString(
524 TIZEN_CALENDAR_ITEM_LOCATION));
525 JSObjectRef filterObj = toJSObjectRef(filters);
526 if (JSObjectHasProperty(m_context, filterObj, locationStr.get())) {
527 LogDebug("converting location");
528 JSValueRef value = JSObjectGetProperty(m_context,
532 result->setLocationFilter(toString(value));
536 void CalendarConverter::toEventFilterConvertCategory(
537 const EventFilterPtr &result,
538 const JSValueRef &filters)
540 const ScopedJSStringRef locationStr(JSStringCreateWithUTF8CString(
542 JSObjectRef filterObj = toJSObjectRef(filters);
543 if (JSObjectHasProperty(m_context, filterObj, locationStr.get())) {
544 LogDebug("converting category");
545 JSValueRef value = JSObjectGetProperty(m_context,
549 result->setCategoryFilter(toString(value));
553 void CalendarConverter::toEventFilterConvertStatus(
554 const EventFilterPtr &result,
555 const JSValueRef &filters)
557 const ScopedJSStringRef statusStr(JSStringCreateWithUTF8CString(TIZEN_CALENDAR_ITEM_STATUS));
558 JSObjectRef filterObj = toJSObjectRef(filters);
559 if (JSObjectHasProperty(m_context, filterObj, statusStr.get())) {
560 LogDebug("converting status");
561 JSValueRef value = JSObjectGetProperty(m_context,
565 std::vector<std::string> statuses = toVectorOfStrings(value);
566 for (std::size_t i = 0; i < statuses.size(); ++i) {
567 CalendarEvent::EventStatus status(toEventStatus(statuses[i]));
568 if (status == CalendarEvent::INVALID_STATUS) {
569 ThrowMsg(InvalidArgumentException,
570 "Status filter has wrong value");
572 result->addStatusFilter(status);
577 void CalendarConverter::toEventFilterConvertStartTime(
578 const EventFilterPtr &result,
579 const JSValueRef &filters)
581 const ScopedJSStringRef initialStartDateStr(JSStringCreateWithUTF8CString(
582 "initialStartDate"));
583 const ScopedJSStringRef endStartDateStr(JSStringCreateWithUTF8CString(
585 JSObjectRef filterObj = toJSObjectRef(filters);
586 if (JSObjectHasProperty(m_context, filterObj, initialStartDateStr.get()) ||
587 JSObjectHasProperty(m_context, filterObj, endStartDateStr.get())) {
588 LogDebug("converting startTime");
589 JSValueRef valueStart = JSObjectGetProperty(m_context,
591 initialStartDateStr.get(),
593 JSValueRef valueEnd = JSObjectGetProperty(m_context,
595 endStartDateStr.get(),
598 if ((JSValueIsNull(m_context,
600 JSValueIsUndefined(m_context, valueStart)) &&
601 (JSValueIsNull(m_context,
603 JSValueIsUndefined(m_context, valueEnd))) {
607 if (!JSValueIsNull(m_context, valueStart) &&
608 !JSValueIsUndefined(m_context, valueStart)) {
609 result->setStartTimeMinFilter(toDateTimeT(valueStart));
612 if (!JSValueIsNull(m_context, valueEnd) &&
613 !JSValueIsUndefined(m_context, valueEnd)) {
614 result->setStartTimeMaxFilter(toDateTimeT(valueEnd));
619 EventFilterPtr CalendarConverter::toEventFilter(const JSValueRef &filters)
622 EventFilterPtr result(new EventFilter());
623 Validator validator(m_context);
624 if (!JSValueIsObject(m_context, filters)) {
625 LogError("Wrong filter parameter");
626 Throw(InvalidArgumentException);
628 if (!validator.checkArrayKeys(m_allowedAttributes, filters)) {
629 LogError("Wrong filter's attribue");
630 Throw(ConversionException);
632 toEventFilterConvertId(result, filters);
633 toEventFilterConvertSummary(result, filters);
634 toEventFilterConvertDescription(result, filters);
635 toEventFilterConvertLocation(result, filters);
636 toEventFilterConvertCategory(result, filters);
637 toEventFilterConvertStatus(result, filters);
638 toEventFilterConvertStartTime(result, filters);
642 CategoryListPtr CalendarConverter::toCategories(JSValueRef categories)
645 CategoryListPtr result(new CategoryList());
646 *result = toVectorOfStrings(categories);
650 EventAttendeePtr CalendarConverter::toAttendee(JSValueRef attendee)
653 EventAttendeePtr result(new EventAttendee());
654 const ScopedJSStringRef nameStr(JSStringCreateWithUTF8CString(TIZEN_ATTENDEE_NAME));
655 const ScopedJSStringRef uriStr(JSStringCreateWithUTF8CString(TIZEN_ATTENDEE_URI));
656 const ScopedJSStringRef roleStr(JSStringCreateWithUTF8CString(TIZEN_ATTENDEE_ROLE));
657 const ScopedJSStringRef statusStr(JSStringCreateWithUTF8CString(TIZEN_ATTENDEE_STATUS));
658 const ScopedJSStringRef RSVPStr(JSStringCreateWithUTF8CString(TIZEN_ATTENDEE_RSVP));
659 const ScopedJSStringRef typeStr(JSStringCreateWithUTF8CString(TIZEN_ATTENDEE_TYPE));
660 const ScopedJSStringRef groupStr(JSStringCreateWithUTF8CString(TIZEN_ATTENDEE_GROUP));
661 const ScopedJSStringRef delegatorURIStr(JSStringCreateWithUTF8CString(TIZEN_ATTENDEE_DELEGATORURI));
662 const ScopedJSStringRef delegateURIStr(JSStringCreateWithUTF8CString(TIZEN_ATTENDEE_DELEGATEURI));
663 const ScopedJSStringRef contactRefStr(JSStringCreateWithUTF8CString(TIZEN_ATTENDEE_CONTACT_REF));
665 JSObjectRef arg = toJSObjectRef(attendee);
667 JSValueRef nameData = JSObjectGetProperty(m_context, arg, nameStr.get(), NULL);
668 JSValueRef uriData = JSObjectGetProperty(m_context, arg, uriStr.get(), NULL);
669 JSValueRef roleData = JSObjectGetProperty(m_context, arg, roleStr.get(), NULL);
670 JSValueRef statusData = JSObjectGetProperty(m_context, arg, statusStr.get(), NULL);
671 JSValueRef RSVPData = JSObjectGetProperty(m_context, arg, RSVPStr.get(), NULL);
672 JSValueRef typeData = JSObjectGetProperty(m_context, arg, typeStr.get(), NULL);
673 JSValueRef groupData = JSObjectGetProperty(m_context, arg, groupStr.get(), NULL);
674 JSValueRef delegatorURIData = JSObjectGetProperty(m_context, arg, delegatorURIStr.get(), NULL);
675 JSValueRef delegateURIData = JSObjectGetProperty(m_context, arg, delegateURIStr.get(), NULL);
676 JSValueRef contactRefData = JSObjectGetProperty(m_context, arg, contactRefStr.get(), NULL);
678 if (!JSValueIsUndefined(m_context, nameData)) {
679 result->setName(toString(nameData));
681 if (!JSValueIsUndefined(m_context, uriData)) {
682 result->setURI(toString(uriData));
684 if (!JSValueIsUndefined(m_context, roleData)) {
685 result->setRole(toEventAttendeeRole(toString(roleData)));
687 if (!JSValueIsUndefined(m_context, statusData)) {
688 result->setStatus(toEventAttendeeStatus(toString(statusData)));
690 if (!JSValueIsUndefined(m_context, RSVPData)) {
691 result->setRSVP(toBool(RSVPData));
693 if (!JSValueIsUndefined(m_context, typeData)) {
694 result->setType(toEventAttendeeType(toString(typeData)));
696 if (!JSValueIsUndefined(m_context, groupData)) {
697 result->setGroup(toString(groupData));
699 if (!JSValueIsUndefined(m_context, delegatorURIData)) {
700 result->setDelegatorURI(toString(delegatorURIData));
702 if (!JSValueIsUndefined(m_context, delegateURIData)) {
703 result->setDelegateURI(toString(delegateURIData));
705 if (!JSValueIsUndefined(m_context, contactRefData)) {
706 result->setPersonId(toString(contactRefData));
712 EventAttendeeListPtr CalendarConverter::toVectorOfAttendeesFromDictionary(JSValueRef attendees)
715 EventAttendeeListPtr result(new EventAttendeeList());
717 std::vector<EventAttendeePtr> resultVector;
718 JSObjectRef objArg = toJSObjectRef(attendees);
719 LogDebug("array length "<<JSGetArrayLength(m_context, objArg));
720 for (std::size_t i = 0; i < JSGetArrayLength(m_context, objArg); i++) {
721 JSValueRef element = JSGetArrayElement(m_context, objArg, i);
722 resultVector.push_back(toAttendee(element));
725 *result = resultVector;
729 EventAttendeeListPtr CalendarConverter::toVectorOfAttendeesFromReference(JSValueRef attendees)
732 EventAttendeeListPtr result(new EventAttendeeList());
734 std::vector<EventAttendeePtr> resultVector;
735 JSObjectRef objArg = toJSObjectRef(attendees);
736 LogDebug("array length "<<JSGetArrayLength(m_context, objArg));
737 for (std::size_t i = 0; i < JSGetArrayLength(m_context, objArg); i++) {
738 JSValueRef element = JSGetArrayElement(m_context, objArg, i);
739 resultVector.push_back(JSCalendarAttendee::getPrivateObject(JSValueToObject(m_context, element, NULL)));
742 *result = resultVector;
746 EventAlarmPtr CalendarConverter::toEventAlarm(JSValueRef alarm)
749 EventAlarmPtr result(new EventAlarm());
750 const ScopedJSStringRef absoluteDateStr(JSStringCreateWithUTF8CString(TIZEN_CALENDAR_ALARM_ABSOLUTE_DATE));
751 const ScopedJSStringRef beforeStr(JSStringCreateWithUTF8CString(TIZEN_CALENDAR_ALARM_BEFORE));
752 const ScopedJSStringRef methodStr(JSStringCreateWithUTF8CString(TIZEN_CALENDAR_ALARM_METHOD));
753 const ScopedJSStringRef descriptionStr(JSStringCreateWithUTF8CString(TIZEN_CALENDAR_ALARM_DESCRIPTION));
755 JSObjectRef arg = toJSObjectRef(alarm);
757 JSValueRef absoluteDateData = JSObjectGetProperty(m_context, arg, absoluteDateStr.get(), NULL);
758 JSValueRef beforeData = JSObjectGetProperty(m_context, arg, beforeStr.get(), NULL);
759 JSValueRef methodData = JSObjectGetProperty(m_context, arg, methodStr.get(), NULL);
760 JSValueRef descriptionData = JSObjectGetProperty(m_context, arg, descriptionStr.get(), NULL);
762 if (!JSValueIsUndefined(m_context, absoluteDateData)) {
763 TimeUtilConverter timeConverter(m_context);
764 result->setAbsoluteDate(timeConverter.toTZDateTimeT(absoluteDateData));
766 if (!JSValueIsUndefined(m_context, beforeData)) {
767 TimeUtilConverter timeConverter(m_context);
768 result->setDuration(timeConverter.getDurationPropertis(beforeData));
770 if (!JSValueIsUndefined(m_context, methodData)) {
771 std::string method = toString(methodData);
772 std::vector<CalendarEvent::EventAlarmType> convertedMethods;
773 convertedMethods.push_back(toEventAlarmType(method));
774 result->setMethods(convertedMethods);
776 if (!JSValueIsUndefined(m_context, descriptionData)) {
777 result->setDescription(toString(descriptionData));
783 EventAlarmListPtr CalendarConverter::toVectorOfEventAlarmsFromDictionary(JSValueRef alarms)
786 EventAlarmListPtr result(new EventAlarmList());
788 std::vector<EventAlarmPtr> resultVector;
789 JSObjectRef objArg = toJSObjectRef(alarms);
790 LogDebug("array length "<<JSGetArrayLength(m_context, objArg));
791 for (std::size_t i = 0; i < JSGetArrayLength(m_context, objArg); i++) {
792 JSValueRef element = JSGetArrayElement(m_context, objArg, i);
793 resultVector.push_back(toEventAlarm(element));
796 *result = resultVector;
800 EventAlarmListPtr CalendarConverter::toVectorOfEventAlarmsFromReference(JSValueRef alarms)
803 EventAlarmListPtr result(new EventAlarmList());
805 std::vector<EventAlarmPtr> resultVector;
806 JSObjectRef objArg = toJSObjectRef(alarms);
807 LogDebug("array length "<<JSGetArrayLength(m_context, objArg));
808 for (std::size_t i = 0; i < JSGetArrayLength(m_context, objArg); i++) {
809 JSValueRef element = JSGetArrayElement(m_context, objArg, i);
810 resultVector.push_back(JSCalendarAlarm::getPrivateObject(JSValueToObject(m_context, element, NULL)));
813 *result = resultVector;
817 CalendarEventPtr CalendarConverter::toEvent(const JSValueRef event)
820 CalendarEventPtr result(new CalendarEvent());
821 const ScopedJSStringRef descriptionStr(JSStringCreateWithUTF8CString(TIZEN_CALENDAR_ITEM_DESCRIPTION));
822 const ScopedJSStringRef summaryStr(JSStringCreateWithUTF8CString(TIZEN_CALENDAR_ITEM_SUMMARY));
823 const ScopedJSStringRef startTimeStr(JSStringCreateWithUTF8CString(TIZEN_CALENDAR_ITEM_START_DATE));
824 const ScopedJSStringRef durationStr(JSStringCreateWithUTF8CString(TIZEN_CALENDAR_ITEM_DURATION));
825 const ScopedJSStringRef locationStr(JSStringCreateWithUTF8CString(TIZEN_CALENDAR_ITEM_LOCATION));
826 const ScopedJSStringRef categoriesStr(JSStringCreateWithUTF8CString(TIZEN_CALENDAR_ITEM_CATEGORIES));
827 const ScopedJSStringRef statusStr(JSStringCreateWithUTF8CString(TIZEN_CALENDAR_ITEM_STATUS));
828 const ScopedJSStringRef alarmsStr(JSStringCreateWithUTF8CString(TIZEN_CALENDAR_ITEM_ALARMS));
829 const ScopedJSStringRef isAllDayStr(JSStringCreateWithUTF8CString(TIZEN_CALENDAR_ITEM_IS_ALL_DAY));
830 const ScopedJSStringRef organizerStr(JSStringCreateWithUTF8CString(TIZEN_CALENDAR_ITEM_ORGANIZER));
831 const ScopedJSStringRef attendeesStr(JSStringCreateWithUTF8CString(TIZEN_CALENDAR_ITEM_ATTENDEES));
832 const ScopedJSStringRef geolocationStr(JSStringCreateWithUTF8CString(TIZEN_CALENDAR_ITEM_GEOLOCATION));
833 const ScopedJSStringRef visibilityStr(JSStringCreateWithUTF8CString(TIZEN_CALENDAR_ITEM_VISIBILITY));
834 const ScopedJSStringRef availabilityStr(JSStringCreateWithUTF8CString(TIZEN_CALENDAR_EVENT_AVAILABILITY));
835 const ScopedJSStringRef recurrenceRuleStr(JSStringCreateWithUTF8CString(TIZEN_CALENDAR_EVENT_RECURRENCE_RULE));
836 const ScopedJSStringRef priorityStr(JSStringCreateWithUTF8CString(TIZEN_CALENDAR_ITEM_PRIORITY));
837 const ScopedJSStringRef dueDateStr(JSStringCreateWithUTF8CString(TIZEN_CALENDAR_TASK_DUE_DATE));
838 const ScopedJSStringRef completedDateStr(JSStringCreateWithUTF8CString(TIZEN_CALENDAR_TASK_COMPLETED_DATE));
839 const ScopedJSStringRef progressStr(JSStringCreateWithUTF8CString(TIZEN_CALENDAR_TASK_PROGRESS));
841 JSObjectRef arg = toJSObjectRef(event);
843 JSValueRef descriptionData = JSObjectGetProperty(m_context, arg, descriptionStr.get(), NULL);
844 JSValueRef summaryData = JSObjectGetProperty(m_context, arg, summaryStr.get(), NULL);
845 JSValueRef startTimeData = JSObjectGetProperty(m_context, arg, startTimeStr.get(), NULL);
846 JSValueRef durationData = JSObjectGetProperty(m_context, arg, durationStr.get(), NULL);
847 JSValueRef locationData = JSObjectGetProperty(m_context, arg, locationStr.get(), NULL);
848 JSValueRef categoriesData = JSObjectGetProperty(m_context, arg, categoriesStr.get(), NULL);
849 JSValueRef statusData = JSObjectGetProperty(m_context, arg, statusStr.get(), NULL);
850 JSValueRef alarmsData = JSObjectGetProperty(m_context, arg, alarmsStr.get(), NULL);
851 JSValueRef isAllDayData = JSObjectGetProperty(m_context, arg, isAllDayStr.get(), NULL);
852 JSValueRef organizerData = JSObjectGetProperty(m_context, arg, organizerStr.get(), NULL);
853 JSValueRef attendeesData = JSObjectGetProperty(m_context, arg, attendeesStr.get(), NULL);
854 JSValueRef geolocationData = JSObjectGetProperty(m_context, arg, geolocationStr.get(), NULL);
855 JSValueRef visibilityData = JSObjectGetProperty(m_context, arg, visibilityStr.get(), NULL);
856 JSValueRef availabilityData = JSObjectGetProperty(m_context, arg, availabilityStr.get(), NULL);
857 JSValueRef recurrenceRuleData = JSObjectGetProperty(m_context, arg, recurrenceRuleStr.get(), NULL);
858 JSValueRef priorityData = JSObjectGetProperty(m_context, arg, priorityStr.get(), NULL);
859 JSValueRef dueDateData = JSObjectGetProperty(m_context, arg, dueDateStr.get(), NULL);
860 JSValueRef completedDateData = JSObjectGetProperty(m_context, arg, completedDateStr.get(), NULL);
861 JSValueRef progressData = JSObjectGetProperty(m_context, arg, progressStr.get(), NULL);
863 TimeUtilConverter timeUtilConverter(m_context);
865 if (!JSValueIsUndefined(m_context, descriptionData)) {
866 result->setDescription(toString(descriptionData));
868 if (!JSValueIsUndefined(m_context, summaryData)) {
869 result->setSubject(toString(summaryData));
871 //It's important to set startTime before duration to set end date by time_t
872 if (!JSValueIsUndefined(m_context, startTimeData)) {
873 result->setStartTime(timeUtilConverter.toTZDateTimeT(startTimeData));
874 result->setTimeZone(timeUtilConverter.getPropertiesInTZDate(startTimeData).timezone);
875 LogInfo("start time converted from TZDate: "<<result->getStartTime()<<", time zone: "<<result->getTimeZone());
877 //set default value, current local time.
878 if(m_calendarType == CalendarEvent::EVENT_TYPE) {
879 //result->setStartTime(std::time(NULL));
882 if (!JSValueIsUndefined(m_context, durationData)) {
883 long length = timeUtilConverter.getDurationLength(durationData);
884 int unit = timeUtilConverter.getDurationUnit(durationData);
885 LogInfo("duration length: "<<length<<", unit "<<unit);
887 Throw(ConversionException);
889 if( SECONDS_UNIT==unit ) {
890 result->setEndTime(result->getStartTime() + length);
891 } else if ( MINUTES_UNIT==unit ) {
892 result->setEndTime(result->getStartTime() + length*60);
893 } else if ( HOURS_UNIT==unit ) {
894 result->setEndTime(result->getStartTime() + length*60*60);
895 } else if ( DAYS_UNIT==unit ) {
896 result->setEndTime(result->getStartTime() + length*24*60*60);
898 Throw(ConversionException);
901 if (!JSValueIsUndefined(m_context, locationData)) {
902 result->setLocation(toString(locationData));
904 if (!JSValueIsUndefined(m_context, categoriesData)) {
905 CategoryListPtr categories(new CategoryList());
906 *categories = toVectorOfStrings(categoriesData);
907 result->setCategories(categories);
909 if (!JSValueIsUndefined(m_context, statusData)) {
910 result->setStatus(toEventStatus(toString(statusData)));
912 result->setStatus(CalendarEvent::CONFIRMED_STATUS);
914 if (!JSValueIsUndefined(m_context, alarmsData)) {
915 EventAlarmListPtr alarms = toVectorOfEventAlarmsFromReference(alarmsData);
916 std::vector<CalendarEvent::EventAlarmType> alarmsType;
917 std::vector<long> alarmsTick;
918 std::vector<std::string> alarmsDescription;
920 for( unsigned int i=0; i<alarms->size(); i++) {
921 EventAlarmPtr theAlarm = alarms->at(i);
922 alarmsType.push_back(theAlarm->getMethods().at(0));
923 alarmsDescription.push_back(theAlarm->getDescription());
925 if( 0 < theAlarm->getAbsoluteDate() ) {
926 alarmsTick.push_back(theAlarm->getAbsoluteDate()/60); // minutes only in platform.
929 long length = theAlarm->getDuration().length;
930 switch(theAlarm->getDuration().unit) {
931 case TizenApis::Api::TimeUtil::MSECS_UNIT:
932 tick = length/(1000*60);
934 case TizenApis::Api::TimeUtil::SECONDS_UNIT:
937 case TizenApis::Api::TimeUtil::MINUTES_UNIT:
940 case TizenApis::Api::TimeUtil::HOURS_UNIT:
943 case TizenApis::Api::TimeUtil::DAYS_UNIT:
947 ThrowMsg(ConversionException, "Wrong alarm unit type.");
950 alarmsTick.push_back(tick);
953 result->setAlarmsType(alarmsType);
954 result->setAlarmsTick(alarmsTick);
956 if (!JSValueIsUndefined(m_context, isAllDayData)) {
957 result->setIsAllDay(toBool(isAllDayData));
959 if (!JSValueIsUndefined(m_context, organizerData)) {
960 result->setOrganizer(toString(organizerData));
962 if (!JSValueIsUndefined(m_context, attendeesData)) {
963 EventAttendeeListPtr attendees = toVectorOfAttendeesFromReference(attendeesData);
964 result->setAttendees(attendees);
966 if (!JSValueIsUndefined(m_context, geolocationData)) {
967 result->setGeolocation(toGeolocation(geolocationData));
969 if (!JSValueIsUndefined(m_context, visibilityData)) {
970 result->setVisibility(toEventVisibility(toString(visibilityData)));
972 if (!JSValueIsUndefined(m_context, availabilityData)) {
973 result->setAvailability(toEventAvailability(toString(availabilityData)));
975 if (!JSValueIsUndefined(m_context, recurrenceRuleData)) {
976 result->setRecurrenceRule(JSCalendarRecurrenceRule::getPrivateObject(JSValueToObject(m_context, recurrenceRuleData, NULL)));
978 if (!JSValueIsUndefined(m_context, priorityData)) {
979 result->setPriority(toTaskPriority(toString(priorityData)));
981 if (!JSValueIsUndefined(m_context, dueDateData)) {
982 result->setEndTime(timeUtilConverter.toTZDateTimeT(dueDateData));
984 if (!JSValueIsUndefined(m_context, completedDateData)) {
985 result->setCompletedDate(timeUtilConverter.toTZDateTimeT(completedDateData));
987 if (!JSValueIsUndefined(m_context, progressData)) {
988 result->setProgress(toInt(progressData));
994 CalendarEventListPtr CalendarConverter::toVectorOfEvents(JSValueRef events)
997 CalendarEventListPtr result(new CalendarEventList());
999 std::vector<CalendarEventPtr> resultVector;
1000 JSObjectRef objArg = toJSObjectRef(events);
1001 LogDebug("array length "<<JSGetArrayLength(m_context, objArg));
1002 for (std::size_t i = 0; i < JSGetArrayLength(m_context, objArg); i++) {
1003 JSValueRef element = JSGetArrayElement(m_context, objArg, i);
1004 JSObjectRef arg = JSValueToObject(m_context, element, NULL);
1005 resultVector.push_back(JSCalendarItem::getPrivateObject(arg));
1008 *result = resultVector;
1012 CalendarEventListPtr CalendarConverter::toVectorOfEventsFromProperty(JSValueRef events)
1014 LogDebug("entered");
1015 CalendarEventListPtr result(new CalendarEventList());
1017 std::vector<CalendarEventPtr> resultVector;
1018 JSObjectRef objArg = toJSObjectRef(events);
1019 LogDebug("array length "<<JSGetArrayLength(m_context, objArg));
1020 for (std::size_t i = 0; i < JSGetArrayLength(m_context, objArg); i++) {
1021 resultVector.push_back(toEvent(JSGetArrayElement(m_context, objArg, i)));
1024 *result = resultVector;
1028 EventIdPtr CalendarConverter::toEventId(JSValueRef eventId)
1030 LogDebug("entered");
1031 EventIdPtr result(new EventId());
1032 const ScopedJSStringRef uidStr(JSStringCreateWithUTF8CString("uid"));
1033 const ScopedJSStringRef recurrenceIdStr(JSStringCreateWithUTF8CString("recurrenceId"));
1035 JSObjectRef arg = toJSObjectRef(eventId);
1037 JSValueRef uidData = JSObjectGetProperty(m_context, arg, uidStr.get(), NULL);
1038 JSValueRef recurrenceIdData = JSObjectGetProperty(m_context, arg, recurrenceIdStr.get(), NULL);
1040 if (!JSValueIsUndefined(m_context, uidData)) {
1041 result->setUId(toString(uidData));
1043 if (!JSValueIsUndefined(m_context, recurrenceIdData)) {
1044 TimeUtilConverter timeUtilConverter(m_context);
1045 result->setRecurrenceId(timeUtilConverter.toTZDateTimeT(recurrenceIdData));
1051 CalendarItemGeoPtr CalendarConverter::toGeolocation(JSValueRef geoInfo)
1053 LogDebug("entered");
1054 CalendarItemGeoPtr result(new CalendarItemGeo());
1055 const ScopedJSStringRef latStr(JSStringCreateWithUTF8CString("latitude"));
1056 const ScopedJSStringRef lonStr(JSStringCreateWithUTF8CString("longitude"));
1058 JSObjectRef arg = toJSObjectRef(geoInfo);
1060 JSValueRef latData = JSObjectGetProperty(m_context, arg, latStr.get(), NULL);
1061 JSValueRef lonData = JSObjectGetProperty(m_context, arg, lonStr.get(), NULL);
1063 if (!JSValueIsUndefined(m_context, latData)) {
1064 result->setLatitude(toDouble(latData));
1066 if (!JSValueIsUndefined(m_context, lonData)) {
1067 result->setLongitude(toDouble(lonData));
1073 EventIdListPtr CalendarConverter::toVectorOfEventIds(JSValueRef eventIds)
1075 LogDebug("entered");
1076 EventIdListPtr result(new EventIdList());
1078 std::vector<EventIdPtr> resultVector;
1079 JSObjectRef objArg = toJSObjectRef(eventIds);
1080 LogDebug("array length "<<JSGetArrayLength(m_context, objArg));
1081 for (std::size_t i = 0; i < JSGetArrayLength(m_context, objArg); i++) {
1082 JSValueRef element = JSGetArrayElement(m_context, objArg, i);
1083 EventIdPtr idPtr = JSCalendarEventId::getPrivateObject(JSValueToObject(m_context, element, NULL));
1084 idPtr->setCalendarType(CalendarEvent::EVENT_TYPE);
1085 resultVector.push_back(idPtr);
1088 *result = resultVector;
1092 std::vector<time_t> CalendarConverter::toVectorOfTimeTFromTZDate(JSValueRef dates)
1094 LogDebug("entered");
1095 std::vector<time_t> result;
1096 TimeUtilConverter converter(m_context);
1098 JSObjectRef objArg = toJSObjectRef(dates);
1099 LogDebug("array length "<<JSGetArrayLength(m_context, objArg));
1100 for (std::size_t i = 0; i < JSGetArrayLength(m_context, objArg); i++) {
1101 JSValueRef element = JSGetArrayElement(m_context, objArg, i);
1102 result.push_back(converter.toTZDateTimeT(element));
1108 std::string CalendarConverter::toTizenValue(Api::Calendar::CalendarEvent::TaskPriority abstractValue) const
1110 switch (abstractValue) {
1111 case CalendarEvent::HIGH_PRIORITY:
1112 return TIZEN_CALENDAR_PROPERTY_HIGH_PRIORITY;
1113 case CalendarEvent::MEDIUM_PRIORITY:
1114 return TIZEN_CALENDAR_PROPERTY_MEDIUM_PRIORITY;
1115 case CalendarEvent::LOW_PRIORITY:
1116 return TIZEN_CALENDAR_PROPERTY_LOW_PRIORITY;
1120 return TIZEN_CALENDAR_PROPERTY_LOW_PRIORITY;
1123 CalendarEvent::TaskPriority CalendarConverter::toTaskPriority(std::string priority) const
1125 if (!priority.compare(TIZEN_CALENDAR_PROPERTY_HIGH_PRIORITY))
1126 return CalendarEvent::HIGH_PRIORITY;
1127 else if (!priority.compare(TIZEN_CALENDAR_PROPERTY_MEDIUM_PRIORITY))
1128 return CalendarEvent::MEDIUM_PRIORITY;
1129 else if (!priority.compare(TIZEN_CALENDAR_PROPERTY_LOW_PRIORITY))
1130 return CalendarEvent::LOW_PRIORITY;
1132 Throw(ConversionException);
1134 return CalendarEvent::LOW_PRIORITY;
1137 CalendarEvent::CalendarType CalendarConverter::toCalendarType(std::string type) const
1139 if (!type.compare(TIZEN_CALENDAR_PROPERTY_TYPE_EVENT))
1140 return CalendarEvent::EVENT_TYPE;
1141 else if (!type.compare(TIZEN_CALENDAR_PROPERTY_TYPE_TASK))
1142 return CalendarEvent::TASK_TYPE;
1144 Throw(ConversionException);
1146 return CalendarEvent::EVENT_TYPE;
1149 CalendarEvent::VObjectFormat CalendarConverter::toVObjectFormat(std::string format) const
1151 if (!format.compare(TIZEN_CALENDAR_PROPERTY_VCALENDAR_20_FORMAT))
1152 return CalendarEvent::ICALENDAR_20;
1153 else if (!format.compare(TIZEN_CALENDAR_PROPERTY_VCALENDAR_10_FORMAT))
1154 return CalendarEvent::VCALENDAR_10;
1156 return CalendarEvent::ICALENDAR_20;