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.
19 #include <CommonsJavaScript/PrivateObject.h>
20 #include <CommonsJavaScript/Converter.h>
21 #include <CommonsJavaScript/JSUtils.h>
22 #include <JSWebAPIErrorFactory.h>
23 #include <SecurityExceptions.h>
24 #include <TimeUtilConverter.h>
25 #include <JSTimeDuration.h>
27 #include <JSSimpleCoordinates.h>
28 #include "EventAlarm.h"
30 #include "ICalendar.h"
31 #include "CalendarFactory.h"
32 #include <DurationProperties.h>
33 #include "JSCalendarItemProperties.h"
34 #include "CalendarConverter.h"
35 #include "JSCalendarEventId.h"
36 #include "JSCalendarAlarm.h"
37 #include "JSCalendarAttendee.h"
38 #include "JSCalendarEvent.h"
39 #include "JSCalendarTask.h"
40 #include "plugin_config.h"
41 #include <GlobalContextManager.h>
42 #include <TimeTracer.h>
45 using namespace WrtDeviceApis::Commons;
46 using namespace WrtDeviceApis::CommonsJavaScript;
47 using namespace DeviceAPI::Common;
48 using namespace DeviceAPI::Time;
53 using WrtDeviceApis::Commons::UnknownException;
54 using WrtDeviceApis::Commons::NotFoundException;
56 #define TIZEN_CALENDAR_ITEM_PROPERTIES_ATTRIBUTENAME "CalendarItemProperties"
58 JSClassDefinition JSCalendarItemProperties::m_classInfo = {
60 kJSClassAttributeNone,
61 TIZEN_CALENDAR_ITEM_PROPERTIES_ATTRIBUTENAME,
70 NULL, //DeleteProperty,
71 NULL, //GetPropertyNames,
72 NULL, //CallAsFunction,
73 NULL, //CallAsConstructor,
78 JSStaticValue JSCalendarItemProperties::m_property[] = {
80 { TIZEN_CALENDAR_ITEM_DESCRIPTION, getPropertyDescription, setPropertyDescription, kJSPropertyAttributeNone },
81 { TIZEN_CALENDAR_ITEM_SUMMARY, getPropertySummary, setPropertySummary, kJSPropertyAttributeNone },
82 { TIZEN_CALENDAR_ITEM_START_DATE, getPropertyStartDate, setPropertyStartDate, kJSPropertyAttributeNone },
83 { TIZEN_CALENDAR_ITEM_LOCATION, getPropertyLocation, setPropertyLocation, kJSPropertyAttributeNone },
84 { TIZEN_CALENDAR_ITEM_GEOLOCATION, getPropertyGeolocation, setPropertyGeolocation, kJSPropertyAttributeNone },
85 { TIZEN_CALENDAR_ITEM_ORGANIZER, getPropertyOrganizer, setPropertyOrganizer, kJSPropertyAttributeNone },
86 { TIZEN_CALENDAR_ITEM_VISIBILITY, getPropertyVisibility, setPropertyVisibility, kJSPropertyAttributeNone },
87 { TIZEN_CALENDAR_ITEM_STATUS, getPropertyStatus, setPropertyStatus, kJSPropertyAttributeNone },
88 { TIZEN_CALENDAR_ITEM_ALARMS, getPropertyAlarms, setPropertyAlarms, kJSPropertyAttributeNone },
89 { TIZEN_CALENDAR_ITEM_CATEGORIES, getPropertyCategories, setPropertyCategories, kJSPropertyAttributeNone },
90 { TIZEN_CALENDAR_ITEM_DURATION, getPropertyDuration, setPropertyDuration, kJSPropertyAttributeNone },
91 { TIZEN_CALENDAR_ITEM_IS_ALL_DAY, getPropertyIsAllDay, setPropertyIsAllDay, kJSPropertyAttributeNone },
92 { TIZEN_CALENDAR_ITEM_ATTENDEES, getPropertyAttendees, setPropertyAttendees, kJSPropertyAttributeNone },
93 { TIZEN_CALENDAR_EVENT_AVAILABILITY, getPropertyAvailability, setPropertyAvailability, kJSPropertyAttributeNone },
94 { TIZEN_CALENDAR_TASK_DUE_DATE, getPropertyDueDate, setPropertyDueDate, kJSPropertyAttributeNone },
95 { TIZEN_CALENDAR_TASK_COMPLETED_DATE, getPropertyCompletedDate, setPropertyCompletedDate, kJSPropertyAttributeNone },
96 { TIZEN_CALENDAR_TASK_PROGRESS, getPropertyProgress, setPropertyProgress, kJSPropertyAttributeNone },
97 { TIZEN_CALENDAR_ITEM_PRIORITY, getPropertyPriority, setPropertyPriority, kJSPropertyAttributeNone },
98 { TIZEN_CALENDAR_EVENT_END_DATE, getPropertyEndDate, setPropertyEndDate, kJSPropertyAttributeNone },
99 { TIZEN_CALENDAR_EVENT_LAST_MODIFICATION_DATE, getPropertyLastModificationDate, NULL, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
100 { TIZEN_CALENDAR_ITEM_CALENDAR_ID, getPropertyCalendarId, NULL, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
105 JSStaticFunction JSCalendarItemProperties::m_function[] = {
106 { CALENDAR_FUNCTION_API_CONVERT_TO_STRING, convertToString, kJSPropertyAttributeNone },
107 { CALENDAR_FUNCTION_API_CLONE, clone, kJSPropertyAttributeNone },
112 JSClassRef JSCalendarItemProperties::m_jsClassRef = JSClassCreate(JSCalendarItemProperties::getClassInfo());
114 void JSCalendarItemProperties::initialize(JSContextRef context,
117 if (!JSObjectGetPrivate(object)) {
118 LoggerD("Create calendar item private object.");
119 CalendarEventPtr item( new CalendarEvent() );
120 CalendarItemPropertiesPrivObject *priv = new CalendarItemPropertiesPrivObject(context, item);
121 if (!JSObjectSetPrivate(object, static_cast<void*>(priv))) {
125 LoggerD("Private object already set.");
129 void JSCalendarItemProperties::finalize(JSObjectRef object)
131 CalendarItemPropertiesPrivObject *priv = static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(object));
134 JSObjectSetPrivate(object, NULL);
138 const JSClassRef JSCalendarItemProperties::getClassRef()
141 m_jsClassRef = JSClassCreate(&m_classInfo);
146 const JSClassDefinition* JSCalendarItemProperties::getClassInfo()
151 CalendarEventPtr JSCalendarItemProperties::getPrivateObject(JSObjectRef object)
153 CalendarItemPropertiesPrivObject *priv =
154 static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(object));
156 ThrowMsg(NullPointerException, "Private object is null");
158 CalendarEventPtr result = priv->getObject();
160 ThrowMsg(NullPointerException, "Private object is null");
165 void JSCalendarItemProperties::setPrivateObject(const CalendarEventPtr &event,
167 const JSObjectRef object)
171 CalendarItemPropertiesPrivObject *priv =
172 static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(object));
174 priv = new CalendarItemPropertiesPrivObject(ctx, event);
175 if (!JSObjectSetPrivate(object, static_cast<void*>(priv))) {
181 LoggerE("Error during replacing event object");
185 JSObjectRef JSCalendarItemProperties::createJSCalendarItemProperties(JSContextRef context, CalendarEventPtr item)
187 CalendarItemPropertiesPrivObject *priv = new CalendarItemPropertiesPrivObject(context, item);
188 return JSObjectMake(context, getClassRef(), priv);
191 JSValueRef JSCalendarItemProperties::convertToString(JSContextRef context,
193 JSObjectRef thisObject,
194 size_t argumentCount,
195 const JSValueRef arguments[],
196 JSValueRef* exception)
198 TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
199 CalendarItemPropertiesPrivObject *privateObject =
200 static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(thisObject));
202 AceSecurityStatus status = CALENDAR_CHECK_ACCESS(CALENDAR_FUNCTION_API_CONVERT_TO_STRING);
204 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
208 if (!privateObject) {
209 ThrowMsg(ConversionException, "Object is null.");
212 CalendarEventPtr item = privateObject->getObject();
214 ThrowMsg(ConversionException, "Parameter conversion failed.");
217 CalendarConverter converter(context);
219 CalendarEvent::VObjectFormat format = CalendarEvent::UNDEFINED_FORMAT;
220 if (argumentCount>=1) {
221 format = converter.toVObjectFormat(converter.toString(arguments[0]));
223 ThrowMsg(ConversionException, "Wrong parameter type.");
226 ICalendarPtr calendar = CalendarFactory::getInstance().createCalendarObject();
227 calendar->setType(item->getCalendarType());
229 IEventExportEventToStringPtr dplEvent(new IEventExportEventToString());
230 dplEvent->setEvent(item);
231 dplEvent->setFormat(format);
232 dplEvent->setForSynchronousCall();
233 calendar->exportEventToString(dplEvent);
235 if (dplEvent->getResult()) {
236 TIME_TRACER_ITEM_END(__FUNCTION__, 0);
237 return converter.toJSValueRef(dplEvent->getEventString());
239 ThrowMsg(UnknownException, "Converting to string failed by unknown reason.");
242 Catch(UnsupportedException)
244 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
245 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
247 Catch(InvalidArgumentException)
249 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
250 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
252 Catch(ConversionException)
254 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
255 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
257 Catch (NotFoundException)
259 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
260 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
264 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
265 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
269 JSValueRef JSCalendarItemProperties::clone(JSContextRef context,
271 JSObjectRef thisObject,
272 size_t argumentCount,
273 const JSValueRef arguments[],
274 JSValueRef* exception)
276 TIME_TRACER_ITEM_BEGIN("clone(TASK)", 0);
277 TIME_TRACER_ITEM_BEGIN("clone(EVENT)", 0);
278 CalendarItemPropertiesPrivObject *privateObject =
279 static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(thisObject));
281 AceSecurityStatus status = CALENDAR_CHECK_ACCESS(CALENDAR_FUNCTION_API_CLONE);
283 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
287 if (!privateObject) {
288 ThrowMsg(ConversionException, "Object is null.");
291 CalendarEventPtr item = privateObject->getObject(); // item to copy
293 ThrowMsg(ConversionException, "Parameter conversion failed.");
295 JSContextRef globalContext = GlobalContextManager::getInstance()->getGlobalContext(context);
297 // Call the copy constructor.
298 CalendarEventPtr clonedItem( new CalendarEvent(*item));
301 clonedItem->resetId();
302 clonedItem->setRecurrenceId(UNDEFINED_ITEM_ID);
304 if (CalendarEvent::TASK_TYPE==clonedItem->getCalendarType()) {
305 TIME_TRACER_ITEM_END("clone(TASK)", 0);
306 return JSCalendarTask::createJSCalendarTask(context, clonedItem);
307 } else if (CalendarEvent::EVENT_TYPE==clonedItem->getCalendarType()) {
308 TIME_TRACER_ITEM_END("clone(EVENT)", 0);
309 // Use global context for potential async api invocation.
310 return JSCalendarEvent::createJSCalendarEvent(globalContext, clonedItem);
312 ThrowMsg(ConversionException, "Wrong object type.");
315 Catch(UnsupportedException)
317 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
318 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
320 Catch(InvalidArgumentException)
322 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
323 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
325 Catch(ConversionException)
327 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
328 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
330 Catch (NotFoundException)
332 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
333 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
337 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
338 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
342 JSValueRef JSCalendarItemProperties::getPropertyDescription(JSContextRef context,
344 JSStringRef propertyName,
345 JSValueRef* exception)
349 Converter converter(context);
350 CalendarEventPtr event = getPrivateObject(object);
351 return converter.toJSValueRef(event->getDescription());
355 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
357 return JSValueMakeUndefined(context);
360 bool JSCalendarItemProperties::setPropertyDescription(JSContextRef context,
362 JSStringRef propertyName,
364 JSValueRef* exception)
368 Converter converter(context);
369 CalendarEventPtr event = getPrivateObject(object);
370 std::string description = converter.toString(value);
371 event->setDescription(description);
376 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
382 JSValueRef JSCalendarItemProperties::getPropertySummary(JSContextRef context,
384 JSStringRef propertyName,
385 JSValueRef* exception)
389 Converter converter(context);
390 CalendarEventPtr event = getPrivateObject(object);
391 return converter.toJSValueRef(event->getSubject());
395 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
397 return JSValueMakeUndefined(context);
400 bool JSCalendarItemProperties::setPropertySummary(JSContextRef context,
402 JSStringRef propertyName,
404 JSValueRef* exception)
408 Converter converter(context);
409 CalendarEventPtr event = getPrivateObject(object);
410 std::string subject = converter.toString(value);
411 event->setSubject(subject);
416 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
422 JSValueRef JSCalendarItemProperties::getPropertyStartDate(JSContextRef context,
424 JSStringRef propertyName,
425 JSValueRef* exception)
429 CalendarItemPropertiesPrivObject *privateObject = static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(object));
431 TimeUtilConverter timeConverter(context);
432 CalendarEventPtr item = privateObject->getObject();
434 LoggerI("start time before converted to TZDate: "<<item->getStartTime()<<", time zone: "<<item->getTimeZone());
435 if (UNDEFINED_TIME==item->getStartTime()) {
436 return JSValueMakeUndefined(context);
438 return timeConverter.toJSValueRefTZDate((double)(item->getStartTime()*1000.0), item->getTimeZone());
443 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
446 return JSValueMakeUndefined(context);
449 bool JSCalendarItemProperties::setPropertyStartDate(JSContextRef context,
451 JSStringRef propertyName,
453 JSValueRef* exception)
457 if (!JSValueIsObjectOfClass(context, value, JSTZDate::getClassRef())) {
458 ThrowMsg(ConversionException, "Wrong parameter type.");
461 CalendarEventPtr item = getPrivateObject(object);
462 TimeUtilConverter timeConverter(context);
464 long long int startTime = (long long int) (timeConverter.getTimeInMilliseconds(value)/1000);
465 item->setStartTime(startTime);
467 std::string timeZone = timeConverter.getPropertiesInTZDate(value).timezone;
468 item->setTimeZone(timeZone);
474 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
480 JSValueRef JSCalendarItemProperties::getPropertyLocation(JSContextRef context,
482 JSStringRef propertyName,
483 JSValueRef* exception)
487 Converter converter(context);
488 CalendarEventPtr event = getPrivateObject(object);
489 return converter.toJSValueRef(event->getLocation());
493 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
495 return JSValueMakeUndefined(context);
498 bool JSCalendarItemProperties::setPropertyLocation(JSContextRef context,
500 JSStringRef propertyName,
502 JSValueRef* exception)
506 Converter converter(context);
507 CalendarEventPtr event = getPrivateObject(object);
508 std::string location = converter.toString(value);
509 event->setLocation(location);
514 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
520 JSValueRef JSCalendarItemProperties::getPropertyCategories(JSContextRef context,
522 JSStringRef propertyName,
523 JSValueRef* exception)
527 CalendarEventPtr item = getPrivateObject(object);
528 JSContextRef globalContext = GlobalContextManager::getInstance()->getGlobalContext(context);
530 CalendarConverter converter(globalContext);
532 if(item->getCategoriesJSRef()) {
533 return item->getCategoriesJSRef();
535 LoggerD("Create a JS object for categories.");
536 StringArrayPtr categories = item->getCategories();
537 JSValueRef jsCategories = converter.toJSValueRefStringArray(categories);
538 item->setCategoriesJSRef(converter.toJSObjectRef(jsCategories));
540 JSValueProtect(globalContext, jsCategories);
541 item->setContext(globalContext);
547 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
549 return JSValueMakeUndefined(context);
552 bool JSCalendarItemProperties::setPropertyCategories(JSContextRef context,
554 JSStringRef propertyName,
556 JSValueRef* exception)
560 CalendarEventPtr event = getPrivateObject(object);
561 CalendarConverter converter(context);
562 event->setCategories(converter.toStringArray(value));
567 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
573 JSValueRef JSCalendarItemProperties::getPropertyStatus(JSContextRef context,
575 JSStringRef propertyName,
576 JSValueRef* exception)
580 CalendarConverter converter(context);
581 CalendarEventPtr event = getPrivateObject(object);
582 std::string status = converter.toTizenValue(event->getStatus());
583 return converter.toJSValueRef(status);
587 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
589 return JSValueMakeUndefined(context);
592 bool JSCalendarItemProperties::setPropertyStatus(JSContextRef context,
594 JSStringRef propertyName,
596 JSValueRef* exception)
598 CalendarEventPtr event(NULL);
601 event = getPrivateObject(object);
602 CalendarConverter converter(context);
603 CalendarEvent::EventStatus status =
604 converter.toEventStatus(converter.toString(value));
605 event->setStatus(status);
610 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
616 JSValueRef JSCalendarItemProperties::getPropertyAlarms(JSContextRef context,
618 JSStringRef propertyName,
619 JSValueRef* exception)
623 CalendarEventPtr event = getPrivateObject(object);
625 JSObjectRef jsResult = JSCreateArrayObject(context, 0, NULL);
626 if (NULL == jsResult) {
627 ThrowMsg(NullPointerException, "Can not create array object.");
629 for( unsigned int i=0; i<event->getAlarms()->size(); i++) {
630 if (!JSSetArrayElement(context, jsResult, i, JSCalendarAlarm::createJSCalendarAlarm(context, event->getAlarms()->at(i)))) {
631 ThrowMsg(UnknownException, "Can not insert value into array.");
638 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
640 return JSValueMakeUndefined(context);
643 bool JSCalendarItemProperties::setPropertyAlarms(JSContextRef context,
645 JSStringRef propertyName,
647 JSValueRef* exception)
649 CalendarEventPtr event(NULL);
652 event = getPrivateObject(object);
653 CalendarConverter converter(context);
655 EventAlarmListPtr alarms = converter.toVectorOfEventAlarmsFromReference(value);
657 event->setAlarms(alarms);
662 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
668 JSValueRef JSCalendarItemProperties::getPropertyOrganizer(JSContextRef context,
670 JSStringRef propertyName,
671 JSValueRef* exception)
675 Converter converter(context);
676 CalendarEventPtr event = getPrivateObject(object);
677 return converter.toJSValueRef(event->getOrganizer());
681 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
683 return JSValueMakeUndefined(context);
686 bool JSCalendarItemProperties::setPropertyOrganizer(JSContextRef context,
688 JSStringRef propertyName,
690 JSValueRef* exception)
694 Converter converter(context);
695 CalendarEventPtr event = getPrivateObject(object);
696 std::string organizer = converter.toString(value);
697 event->setOrganizer(organizer);
702 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
708 JSValueRef JSCalendarItemProperties::getPropertyVisibility(JSContextRef context,
710 JSStringRef propertyName,
711 JSValueRef* exception)
715 CalendarConverter converter(context);
716 CalendarEventPtr event = getPrivateObject(object);
717 std::string visibility = converter.toTizenValue(event->getVisibility());
718 return converter.toJSValueRef(visibility);
722 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
724 return JSValueMakeUndefined(context);
727 bool JSCalendarItemProperties::setPropertyVisibility(JSContextRef context,
729 JSStringRef propertyName,
731 JSValueRef* exception)
733 CalendarEventPtr event(NULL);
736 event = getPrivateObject(object);
737 CalendarConverter converter(context);
738 CalendarEvent::EventVisibility visibility =
739 converter.toEventVisibility(converter.toString(value));
740 event->setVisibility(visibility);
745 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
751 JSValueRef JSCalendarItemProperties::getPropertyGeolocation(JSContextRef context,
753 JSStringRef propertyName,
754 JSValueRef* exception)
758 CalendarEventPtr item = getPrivateObject(object);
759 if( UNDEFINED_GEO==item->getGeolocation()->getLatitude() ) {
760 return JSValueMakeUndefined(context);
762 return DeviceAPI::Tizen::JSSimpleCoordinates::createJSObject(context, item->getGeolocation());
767 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
770 return JSValueMakeUndefined(context);
773 bool JSCalendarItemProperties::setPropertyGeolocation(JSContextRef context,
775 JSStringRef propertyName,
777 JSValueRef* exception)
781 CalendarEventPtr item = getPrivateObject(object);
783 if (JSValueIsNull(context, value) || JSValueIsUndefined(context, value)) {
784 item->getGeolocation()->setLatitude(UNDEFINED_GEO);
785 item->getGeolocation()->setLongitude(UNDEFINED_GEO);
787 DeviceAPI::Tizen::SimpleCoordinatesPtr geoLocation = DeviceAPI::Tizen::JSSimpleCoordinates::getSimpleCoordinates(context, value);
789 item->setGeolocation(geoLocation);
795 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
801 JSValueRef JSCalendarItemProperties::getPropertyDuration(JSContextRef context,
803 JSStringRef propertyName,
804 JSValueRef* exception)
808 CalendarEventPtr item = getPrivateObject(object);
810 if(UNDEFINED_TIME!=item->getDuration()->length) {
811 LoggerD("Duration length: "<<item->getDuration()->length<<", unit: "<<item->getDuration()->unit);
812 return JSTimeDuration::createJSObject(context, item->getDuration());
815 // Alternatively generate the duration object using start/end time.
816 if(UNDEFINED_TIME==item->getStartTime() || UNDEFINED_TIME==item->getEndTime()) {
817 LoggerD("Start or end time is not defined.");
818 return JSValueMakeUndefined(context);
821 long long length = item->getEndTime() - item->getStartTime(); // in seconds only
822 LoggerD("item->getStartTime():"<< item->getStartTime() << ", length:" << length);
824 DurationPropertiesPtr durationPtr(new DurationProperties());
825 durationPtr->length = length;
826 durationPtr->unit = SECONDS_UNIT;
827 item->setDuration(durationPtr);
829 return JSTimeDuration::createJSObject(context, durationPtr);
833 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
835 return JSValueMakeUndefined(context);
838 bool JSCalendarItemProperties::setPropertyDuration(JSContextRef context,
840 JSStringRef propertyName,
842 JSValueRef* exception)
846 CalendarEventPtr item = getPrivateObject(object);
847 TimeUtilConverter timeUtilConverter(context);
849 DurationPropertiesPtr duration = timeUtilConverter.getDuration(value);
850 long long length = duration->length;
851 int unit = duration->unit;
853 DeviceAPI::Common::JSWebAPIErrorFactory::postException(context, exception, DeviceAPI::Common::JSWebAPIErrorFactory::INVALID_VALUES_ERROR);
857 LoggerD("length: "<<length<< ", unit:" <<unit);
858 item->setDuration(duration);
860 // Adjust the endDate because the endDate has priority over duration when saving the item.
861 long long int endDate;
862 if( DeviceAPI::Time::SECONDS_UNIT==unit ) {
863 endDate = item->getStartTime() + length;
864 } else if ( DeviceAPI::Time::MINUTES_UNIT==unit ) {
865 endDate = item->getStartTime() + length*60;
866 } else if ( DeviceAPI::Time::HOURS_UNIT==unit ) {
867 endDate = item->getStartTime() + length*60*60;
868 } else if ( DeviceAPI::Time::DAYS_UNIT==unit ) {
869 endDate = item->getStartTime() + length*24*60*60;
870 } else if ( DeviceAPI::Time::MSECS_UNIT==unit ) {
871 endDate = item->getStartTime() + length/1000;
873 LoggerW("Wrong duration unit: "<<unit);
876 item->setEndTime(endDate);
877 LoggerD("Set the endDate from the duration: "<<endDate);
883 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
889 JSValueRef JSCalendarItemProperties::getPropertyIsAllDay(JSContextRef context,
891 JSStringRef propertyName,
892 JSValueRef* exception)
896 CalendarConverter converter(context);
897 CalendarEventPtr event = getPrivateObject(object);
898 return converter.toJSValueRef(event->getIsAllDay());
902 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
904 return JSValueMakeUndefined(context);
907 bool JSCalendarItemProperties::setPropertyIsAllDay(JSContextRef context,
909 JSStringRef propertyName,
911 JSValueRef* exception)
915 CalendarEventPtr event = getPrivateObject(object);
916 Converter converter(context);
917 event->setIsAllDay(converter.toBool(value));
922 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
928 JSValueRef JSCalendarItemProperties::getPropertyAvailability(JSContextRef context,
930 JSStringRef propertyName,
931 JSValueRef* exception)
935 CalendarConverter converter(context);
936 CalendarEventPtr event = getPrivateObject(object);
937 std::string availability = converter.toTizenValue(event->getAvailability());
938 return converter.toJSValueRef(availability);
942 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
944 return JSValueMakeUndefined(context);
947 bool JSCalendarItemProperties::setPropertyAvailability(JSContextRef context,
949 JSStringRef propertyName,
951 JSValueRef* exception)
953 CalendarEventPtr event(NULL);
956 event = getPrivateObject(object);
957 CalendarConverter converter(context);
958 CalendarEvent::EventAvailability availability =
959 converter.toEventAvailability(converter.toString(value));
960 event->setAvailability(availability);
965 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
971 JSValueRef JSCalendarItemProperties::getPropertyAttendees(JSContextRef context,
973 JSStringRef propertyName,
974 JSValueRef* exception)
978 CalendarEventPtr event = getPrivateObject(object);
979 EventAttendeeListPtr attendees = event->getAttendees();
981 JSObjectRef jsResult = JSCreateArrayObject(context, 0, NULL);
982 if (NULL == jsResult) {
983 ThrowMsg(NullPointerException, "Can not create array object.");
985 for(unsigned int i=0; i<attendees->size(); i++) {
986 if (!JSSetArrayElement(context, jsResult, i, JSCalendarAttendee::createJSCalendarAttendee(context, attendees->at(i)))) {
987 ThrowMsg(UnknownException, "Can not insert value into array.");
995 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
997 return JSValueMakeUndefined(context);
1000 bool JSCalendarItemProperties::setPropertyAttendees(JSContextRef context,
1002 JSStringRef propertyName,
1004 JSValueRef* exception)
1008 CalendarEventPtr event = getPrivateObject(object);
1009 CalendarConverter converter(context);
1010 event->setAttendees(converter.toVectorOfAttendeesFromReference(value));
1015 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
1021 JSValueRef JSCalendarItemProperties::getPropertyDueDate(JSContextRef context,
1023 JSStringRef propertyName,
1024 JSValueRef* exception)
1028 CalendarItemPropertiesPrivObject *privateObject =
1029 static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(object));
1030 CalendarEventPtr task = privateObject->getObject();
1031 if(CalendarEvent::TASK_TYPE != task->getCalendarType()) {
1032 return JSValueMakeUndefined(context);
1035 ThrowMsg(NullPointerException, "Task object is NULL.");
1038 if (UNDEFINED_TIME==task->getEndTime()) {
1039 return JSValueMakeUndefined(context);
1041 TimeUtilConverter timeConverter(context);
1042 return timeConverter.toJSValueRefTZDate((double)(task->getEndTime()*1000.0), task->getTimeZone());
1047 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
1049 return JSValueMakeUndefined(context);
1052 bool JSCalendarItemProperties::setPropertyDueDate(JSContextRef context,
1054 JSStringRef propertyName,
1056 JSValueRef* exception)
1060 CalendarEventPtr task = getPrivateObject(object);
1062 ThrowMsg(NullPointerException, "Task object is NULL.");
1064 if(CalendarEvent::TASK_TYPE != task->getCalendarType()) {
1065 ThrowMsg(InvalidArgumentException, "Wrong type of calendar.");
1067 if (!JSValueIsObjectOfClass(context, value, JSTZDate::getClassRef())) {
1068 ThrowMsg(ConversionException, "Wrong parameter type.");
1071 TimeUtilConverter converter(context);
1072 long long int dueDate = (long long int) (converter.getTimeInMilliseconds(value)/1000);
1074 task->setEndTime(dueDate);
1076 if( task->getTimeZone().empty() ) {
1077 std::string timeZone = converter.getPropertiesInTZDate(value).timezone;
1078 task->setTimeZone(timeZone);
1084 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
1090 JSValueRef JSCalendarItemProperties::getPropertyCompletedDate(JSContextRef context,
1092 JSStringRef propertyName,
1093 JSValueRef* exception)
1097 CalendarItemPropertiesPrivObject *privateObject =
1098 static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(object));
1099 CalendarEventPtr task = privateObject->getObject();
1100 if(CalendarEvent::TASK_TYPE != task->getCalendarType()) {
1101 return JSValueMakeUndefined(context);
1104 ThrowMsg(NullPointerException, "Task object is NULL.");
1107 if (UNDEFINED_TIME==task->getCompletedDate()) {
1108 return JSValueMakeUndefined(context);
1110 TimeUtilConverter timeConverter(context);
1111 return timeConverter.toJSValueRefTZDate((double)(task->getCompletedDate()*1000.0), task->getTimeZone());
1116 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
1118 return JSValueMakeUndefined(context);
1121 bool JSCalendarItemProperties::setPropertyCompletedDate(JSContextRef context,
1123 JSStringRef propertyName,
1125 JSValueRef* exception)
1129 CalendarEventPtr task = getPrivateObject(object);
1131 ThrowMsg(NullPointerException, "Task object is NULL.");
1133 if(CalendarEvent::TASK_TYPE != task->getCalendarType()) {
1134 ThrowMsg(InvalidArgumentException, "Wrong calendar type.");
1136 if (!JSValueIsObjectOfClass(context, value, JSTZDate::getClassRef())) {
1137 ThrowMsg(ConversionException, "Wrong parameter type.");
1140 TimeUtilConverter converter(context);
1141 long long int completedDate = (long long int) (converter.getTimeInMilliseconds(value)/1000);
1143 task->setCompletedDate(completedDate);
1145 if( task->getTimeZone().empty() ) {
1146 std::string timeZone = converter.getPropertiesInTZDate(value).timezone;
1147 task->setTimeZone(timeZone);
1153 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
1159 JSValueRef JSCalendarItemProperties::getPropertyProgress(JSContextRef context,
1161 JSStringRef propertyName,
1162 JSValueRef* exception)
1166 CalendarEventPtr task = getPrivateObject(object);
1167 if(CalendarEvent::TASK_TYPE != task->getCalendarType()) {
1168 return JSValueMakeUndefined(context);
1171 Converter converter(context);
1172 return converter.toJSValueRef(task->getProgress());
1176 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
1178 return JSValueMakeUndefined(context);
1181 bool JSCalendarItemProperties::setPropertyProgress(JSContextRef context,
1183 JSStringRef propertyName,
1185 JSValueRef* exception)
1189 CalendarEventPtr task = getPrivateObject(object);
1190 if(CalendarEvent::TASK_TYPE != task->getCalendarType()) {
1191 return JSValueMakeUndefined(context);
1194 Converter converter(context);
1195 int progress = converter.toInt(value);
1196 task->setProgress(progress);
1201 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
1207 JSValueRef JSCalendarItemProperties::getPropertyPriority(JSContextRef context,
1209 JSStringRef propertyName,
1210 JSValueRef* exception)
1214 CalendarConverter converter(context);
1215 CalendarEventPtr item = getPrivateObject(object);
1217 ThrowMsg(NullPointerException, "Item object is NULL.");
1220 std::string priority = converter.toTizenValue(item->getPriority());
1221 return converter.toJSValueRef(priority);
1225 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
1227 return JSValueMakeUndefined(context);
1230 bool JSCalendarItemProperties::setPropertyPriority(JSContextRef context,
1232 JSStringRef propertyName,
1234 JSValueRef* exception)
1236 CalendarEventPtr item = getPrivateObject(object);
1239 CalendarConverter converter(context);
1240 CalendarEvent::TaskPriority priority =
1241 converter.toTaskPriority(converter.toString(value));
1242 item->setPriority(priority);
1247 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
1253 JSValueRef JSCalendarItemProperties::getPropertyEndDate(JSContextRef context,
1255 JSStringRef propertyName,
1256 JSValueRef* exception)
1260 CalendarItemPropertiesPrivObject *privateObject =
1261 static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(object));
1262 CalendarEventPtr event = privateObject->getObject();
1263 if(CalendarEvent::EVENT_TYPE != event->getCalendarType()) {
1264 return JSValueMakeUndefined(context);
1267 ThrowMsg(NullPointerException, "Event object is NULL.");
1270 if (UNDEFINED_TIME==event->getEndTime()) {
1271 return JSValueMakeUndefined(context);
1273 TimeUtilConverter timeConverter(context);
1274 return timeConverter.toJSValueRefTZDate((double)(event->getEndTime()*1000.0), event->getTimeZone());
1279 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
1281 return JSValueMakeUndefined(context);
1284 bool JSCalendarItemProperties::setPropertyEndDate(JSContextRef context,
1286 JSStringRef propertyName,
1288 JSValueRef* exception)
1292 CalendarEventPtr event = getPrivateObject(object);
1294 ThrowMsg(NullPointerException, "Event object is NULL.");
1296 if(CalendarEvent::EVENT_TYPE != event->getCalendarType()) {
1297 ThrowMsg(InvalidArgumentException, "Wrong calendar type.");
1299 if (!JSValueIsObjectOfClass(context, value, JSTZDate::getClassRef())) {
1300 ThrowMsg(ConversionException, "Wrong parameter type.");
1303 TimeUtilConverter converter(context);
1304 long long int endDate = (long long int) (converter.getTimeInMilliseconds(value)/1000);
1306 event->setEndTime(endDate);
1308 if( event->getTimeZone().empty() ) {
1309 std::string timeZone = converter.getPropertiesInTZDate(value).timezone;
1310 event->setTimeZone(timeZone);
1316 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
1322 JSValueRef JSCalendarItemProperties::getPropertyLastModificationDate(JSContextRef context,
1324 JSStringRef propertyName,
1325 JSValueRef* exception)
1329 CalendarEventPtr item = getPrivateObject(object);
1331 ThrowMsg(NullPointerException, "Item object is NULL.");
1334 if (UNDEFINED_TIME==item->getLastModifiedDate()) {
1335 return JSValueMakeNull(context);
1337 TimeUtilConverter timeConverter(context);
1338 return timeConverter.toJSValueRefTZDate((double)(item->getLastModifiedDate()*1000.0), item->getTimeZone());
1343 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
1345 return JSValueMakeUndefined(context);
1348 JSValueRef JSCalendarItemProperties::getPropertyCalendarId(JSContextRef context,
1350 JSStringRef propertyName,
1351 JSValueRef* exception)
1355 CalendarEventPtr item = getPrivateObject(object);
1357 if (UNDEFINED_CALENDAR_ID==item->getCalendarId()) {
1358 return JSValueMakeNull(context);
1360 CalendarConverter converter(context);
1361 std::stringstream ss;
1362 ss<<item->getCalendarId();
1363 return converter.toJSValueRef(ss.str());
1369 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
1371 return JSValueMakeUndefined(context);