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 | kJSPropertyAttributeDontDelete },
81 { TIZEN_CALENDAR_ITEM_SUMMARY, getPropertySummary, setPropertySummary, kJSPropertyAttributeNone | kJSPropertyAttributeDontDelete },
82 { TIZEN_CALENDAR_ITEM_START_DATE, getPropertyStartDate, setPropertyStartDate, kJSPropertyAttributeNone | kJSPropertyAttributeDontDelete },
83 { TIZEN_CALENDAR_ITEM_LOCATION, getPropertyLocation, setPropertyLocation, kJSPropertyAttributeNone | kJSPropertyAttributeDontDelete },
84 { TIZEN_CALENDAR_ITEM_GEOLOCATION, getPropertyGeolocation, setPropertyGeolocation, kJSPropertyAttributeNone | kJSPropertyAttributeDontDelete },
85 { TIZEN_CALENDAR_ITEM_ORGANIZER, getPropertyOrganizer, setPropertyOrganizer, kJSPropertyAttributeNone | kJSPropertyAttributeDontDelete },
86 { TIZEN_CALENDAR_ITEM_VISIBILITY, getPropertyVisibility, setPropertyVisibility, kJSPropertyAttributeNone | kJSPropertyAttributeDontDelete },
87 { TIZEN_CALENDAR_ITEM_STATUS, getPropertyStatus, setPropertyStatus, kJSPropertyAttributeNone | kJSPropertyAttributeDontDelete },
88 { TIZEN_CALENDAR_ITEM_ALARMS, getPropertyAlarms, setPropertyAlarms, kJSPropertyAttributeNone | kJSPropertyAttributeDontDelete },
89 { TIZEN_CALENDAR_ITEM_CATEGORIES, getPropertyCategories, setPropertyCategories, kJSPropertyAttributeNone | kJSPropertyAttributeDontDelete },
90 { TIZEN_CALENDAR_ITEM_DURATION, getPropertyDuration, setPropertyDuration, kJSPropertyAttributeNone | kJSPropertyAttributeDontDelete },
91 { TIZEN_CALENDAR_ITEM_IS_ALL_DAY, getPropertyIsAllDay, setPropertyIsAllDay, kJSPropertyAttributeNone | kJSPropertyAttributeDontDelete },
92 { TIZEN_CALENDAR_ITEM_ATTENDEES, getPropertyAttendees, setPropertyAttendees, kJSPropertyAttributeNone | kJSPropertyAttributeDontDelete },
93 { TIZEN_CALENDAR_TASK_DUE_DATE, getPropertyDueDate, setPropertyDueDate, kJSPropertyAttributeNone | kJSPropertyAttributeDontDelete },
94 { TIZEN_CALENDAR_ITEM_PRIORITY, getPropertyPriority, setPropertyPriority, kJSPropertyAttributeNone | kJSPropertyAttributeDontDelete },
95 { TIZEN_CALENDAR_EVENT_END_DATE, getPropertyEndDate, setPropertyEndDate, kJSPropertyAttributeNone | kJSPropertyAttributeDontDelete },
96 { TIZEN_CALENDAR_EVENT_LAST_MODIFICATION_DATE, getPropertyLastModificationDate, NULL, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
97 { TIZEN_CALENDAR_ITEM_CALENDAR_ID, getPropertyCalendarId, NULL, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
102 JSStaticFunction JSCalendarItemProperties::m_function[] = {
103 { CALENDAR_FUNCTION_API_CONVERT_TO_STRING, convertToString, kJSPropertyAttributeNone },
104 { CALENDAR_FUNCTION_API_CLONE, clone, kJSPropertyAttributeNone },
109 JSClassRef JSCalendarItemProperties::m_jsClassRef = JSClassCreate(JSCalendarItemProperties::getClassInfo());
111 void JSCalendarItemProperties::initialize(JSContextRef context,
114 if (!JSObjectGetPrivate(object)) {
115 LoggerD("Create calendar item private object.");
116 CalendarEventPtr item( new CalendarEvent() );
117 CalendarItemPropertiesPrivObject *priv = new CalendarItemPropertiesPrivObject(context, item);
118 if (!JSObjectSetPrivate(object, static_cast<void*>(priv))) {
122 LoggerD("Private object already set.");
126 void JSCalendarItemProperties::finalize(JSObjectRef object)
128 CalendarItemPropertiesPrivObject *priv = static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(object));
131 JSObjectSetPrivate(object, NULL);
135 const JSClassRef JSCalendarItemProperties::getClassRef()
138 m_jsClassRef = JSClassCreate(&m_classInfo);
143 const JSClassDefinition* JSCalendarItemProperties::getClassInfo()
148 CalendarEventPtr JSCalendarItemProperties::getPrivateObject(JSObjectRef object)
150 CalendarItemPropertiesPrivObject *priv =
151 static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(object));
153 ThrowMsg(NullPointerException, "Private object is null");
155 CalendarEventPtr result = priv->getObject();
157 ThrowMsg(NullPointerException, "Private object is null");
162 void JSCalendarItemProperties::setPrivateObject(const CalendarEventPtr &event,
164 const JSObjectRef object)
168 CalendarItemPropertiesPrivObject *priv =
169 static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(object));
171 priv = new CalendarItemPropertiesPrivObject(ctx, event);
172 if (!JSObjectSetPrivate(object, static_cast<void*>(priv))) {
178 LoggerE("Error during replacing event object");
182 JSObjectRef JSCalendarItemProperties::createJSCalendarItemProperties(JSContextRef context, CalendarEventPtr item)
184 CalendarItemPropertiesPrivObject *priv = new CalendarItemPropertiesPrivObject(context, item);
185 return JSObjectMake(context, getClassRef(), priv);
188 JSValueRef JSCalendarItemProperties::convertToString(JSContextRef context,
190 JSObjectRef thisObject,
191 size_t argumentCount,
192 const JSValueRef arguments[],
193 JSValueRef* exception)
195 TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
196 CalendarItemPropertiesPrivObject *privateObject =
197 static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(thisObject));
199 TIZEN_CHECK_ACCESS(context, exception, privateObject, CALENDAR_FUNCTION_API_CONVERT_TO_STRING);
203 if (!privateObject) {
204 ThrowMsg(ConversionException, "Object is null.");
207 CalendarEventPtr item = privateObject->getObject();
209 ThrowMsg(ConversionException, "Parameter conversion failed.");
212 CalendarConverter converter(context);
214 CalendarEvent::VObjectFormat format = CalendarEvent::UNDEFINED_FORMAT;
215 if (argumentCount>=1) {
216 format = converter.toVObjectFormat(converter.toString(arguments[0]));
218 if (CalendarEvent::UNDEFINED_FORMAT==format) {
219 ThrowMsg(ConversionException, "Wrong parameter type.");
222 ICalendarPtr calendar = CalendarFactory::getInstance().createCalendarObject();
223 calendar->setType(item->getCalendarType());
225 IEventExportEventToStringPtr dplEvent(new IEventExportEventToString());
226 dplEvent->setEvent(item);
227 dplEvent->setFormat(format);
228 dplEvent->setForSynchronousCall();
229 calendar->exportEventToString(dplEvent);
231 if (dplEvent->getResult()) {
232 TIME_TRACER_ITEM_END(__FUNCTION__, 0);
233 return converter.toJSValueRef(dplEvent->getEventString());
235 ThrowMsg(UnknownException, "Converting to string failed by unknown reason.");
238 Catch(UnsupportedException)
240 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
241 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
243 Catch(InvalidArgumentException)
245 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
246 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
248 Catch(ConversionException)
250 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
251 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
253 Catch (NotFoundException)
255 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
256 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
260 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
261 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
265 JSValueRef JSCalendarItemProperties::clone(JSContextRef context,
267 JSObjectRef thisObject,
268 size_t argumentCount,
269 const JSValueRef arguments[],
270 JSValueRef* exception)
272 TIME_TRACER_ITEM_BEGIN("clone(TASK)", 0);
273 TIME_TRACER_ITEM_BEGIN("clone(EVENT)", 0);
274 CalendarItemPropertiesPrivObject *privateObject =
275 static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(thisObject));
277 TIZEN_CHECK_ACCESS(context, exception, privateObject, CALENDAR_FUNCTION_API_CLONE);
281 if (!privateObject) {
282 ThrowMsg(ConversionException, "Object is null.");
285 CalendarEventPtr item = privateObject->getObject(); // item to copy
287 ThrowMsg(ConversionException, "Parameter conversion failed.");
289 JSContextRef globalContext = GlobalContextManager::getInstance()->getGlobalContext(context);
291 // Call the copy constructor.
292 CalendarEventPtr clonedItem( new CalendarEvent(*item));
295 clonedItem->resetId();
296 clonedItem->setRecurrenceId(UNDEFINED_ITEM_ID);
298 if (CalendarEvent::TASK_TYPE==clonedItem->getCalendarType()) {
299 TIME_TRACER_ITEM_END("clone(TASK)", 0);
300 return JSCalendarTask::createJSCalendarTask(context, clonedItem, privateObject);
301 } else if (CalendarEvent::EVENT_TYPE==clonedItem->getCalendarType()) {
302 TIME_TRACER_ITEM_END("clone(EVENT)", 0);
303 // Use global context for potential async api invocation.
304 return JSCalendarEvent::createJSCalendarEvent(globalContext, clonedItem, privateObject);
306 ThrowMsg(ConversionException, "Wrong object type.");
309 Catch(UnsupportedException)
311 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
312 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
314 Catch(InvalidArgumentException)
316 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
317 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
319 Catch(ConversionException)
321 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
322 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
324 Catch (NotFoundException)
326 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
327 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
331 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
332 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
336 JSValueRef JSCalendarItemProperties::getPropertyDescription(JSContextRef context,
338 JSStringRef propertyName,
339 JSValueRef* exception)
343 Converter converter(context);
344 CalendarEventPtr event = getPrivateObject(object);
345 return converter.toJSValueRef(event->getDescription());
349 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
351 return JSValueMakeUndefined(context);
354 bool JSCalendarItemProperties::setPropertyDescription(JSContextRef context,
356 JSStringRef propertyName,
358 JSValueRef* exception)
362 Converter converter(context);
363 CalendarEventPtr event = getPrivateObject(object);
364 std::string description = converter.toString(value);
365 event->setDescription(description);
370 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
376 JSValueRef JSCalendarItemProperties::getPropertySummary(JSContextRef context,
378 JSStringRef propertyName,
379 JSValueRef* exception)
383 Converter converter(context);
384 CalendarEventPtr event = getPrivateObject(object);
385 return converter.toJSValueRef(event->getSubject());
389 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
391 return JSValueMakeUndefined(context);
394 bool JSCalendarItemProperties::setPropertySummary(JSContextRef context,
396 JSStringRef propertyName,
398 JSValueRef* exception)
402 Converter converter(context);
403 CalendarEventPtr event = getPrivateObject(object);
404 std::string subject = converter.toString(value);
405 event->setSubject(subject);
410 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
416 JSValueRef JSCalendarItemProperties::getPropertyStartDate(JSContextRef context,
418 JSStringRef propertyName,
419 JSValueRef* exception)
423 CalendarItemPropertiesPrivObject *privateObject = static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(object));
425 TimeUtilConverter timeConverter(context);
426 CalendarEventPtr item = privateObject->getObject();
428 LoggerI("start time before converted to TZDate: "<<item->getStartTime()<<", time zone: "<<item->getTimeZone());
429 if (UNDEFINED_TIME==item->getStartTime()) {
430 return JSValueMakeNull(context);
432 return timeConverter.toJSValueRefTZDate((double)(item->getStartTime()*1000.0), item->getTimeZone());
437 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
440 return JSValueMakeUndefined(context);
443 bool JSCalendarItemProperties::setPropertyStartDate(JSContextRef context,
445 JSStringRef propertyName,
447 JSValueRef* exception)
451 CalendarEventPtr item = getPrivateObject(object);
453 if (JSValueIsNull(context, value)) {
454 item->setStartTime(UNDEFINED_TIME);
456 } else if (!JSValueIsObjectOfClass(context, value, JSTZDate::getClassRef())) {
457 ThrowMsg(ConversionException, "Wrong parameter type.");
460 TimeUtilConverter timeConverter(context);
462 long long int startTime = (long long int) (timeConverter.getTimeInMilliseconds(value)/1000);
463 item->setStartTime(startTime);
465 std::string timeZone = timeConverter.getPropertiesInTZDate(value).timezone;
466 item->setTimeZone(timeZone);
472 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
478 JSValueRef JSCalendarItemProperties::getPropertyLocation(JSContextRef context,
480 JSStringRef propertyName,
481 JSValueRef* exception)
485 Converter converter(context);
486 CalendarEventPtr event = getPrivateObject(object);
487 return converter.toJSValueRef(event->getLocation());
491 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
493 return JSValueMakeUndefined(context);
496 bool JSCalendarItemProperties::setPropertyLocation(JSContextRef context,
498 JSStringRef propertyName,
500 JSValueRef* exception)
504 Converter converter(context);
505 CalendarEventPtr event = getPrivateObject(object);
506 std::string location = converter.toString(value);
507 event->setLocation(location);
512 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
518 JSValueRef JSCalendarItemProperties::getPropertyCategories(JSContextRef context,
520 JSStringRef propertyName,
521 JSValueRef* exception)
525 CalendarEventPtr item = getPrivateObject(object);
526 JSContextRef globalContext = GlobalContextManager::getInstance()->getGlobalContext(context);
528 CalendarConverter converter(globalContext);
530 if(item->getCategoriesJSRef()) {
531 return item->getCategoriesJSRef();
533 LoggerD("Create a JS object for categories.");
534 StringArrayPtr categories = item->getCategories();
535 JSValueRef jsCategories = converter.toJSValueRefStringArray(categories);
536 item->setCategoriesJSRef(converter.toJSObjectRef(jsCategories));
538 JSValueProtect(globalContext, jsCategories);
539 item->setContext(globalContext);
545 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
547 return JSValueMakeUndefined(context);
550 bool JSCalendarItemProperties::setPropertyCategories(JSContextRef context,
552 JSStringRef propertyName,
554 JSValueRef* exception)
558 CalendarEventPtr item = getPrivateObject(object);
559 CalendarConverter converter(context);
560 item->setCategories(converter.toStringArray(value));
562 if(item->getCategoriesJSRef()) {
563 LoggerI("Replace a JS object for categories.");
564 JSValueUnprotect(item->getContext(), item->getCategoriesJSRef());
565 item->setCategoriesJSRef(converter.toJSObjectRef(value));
566 JSValueProtect(item->getContext(), value);
573 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
579 JSValueRef JSCalendarItemProperties::getPropertyStatus(JSContextRef context,
581 JSStringRef propertyName,
582 JSValueRef* exception)
586 CalendarConverter converter(context);
587 CalendarEventPtr event = getPrivateObject(object);
588 std::string status = converter.toTizenValue(event->getStatus());
589 return converter.toJSValueRef(status);
593 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
595 return JSValueMakeUndefined(context);
598 bool JSCalendarItemProperties::setPropertyStatus(JSContextRef context,
600 JSStringRef propertyName,
602 JSValueRef* exception)
604 CalendarEventPtr event(NULL);
607 event = getPrivateObject(object);
608 CalendarConverter converter(context);
609 CalendarEvent::EventStatus status =
610 converter.toEventStatus(converter.toString(value));
611 event->setStatus(status);
616 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
622 JSValueRef JSCalendarItemProperties::getPropertyAlarms(JSContextRef context,
624 JSStringRef propertyName,
625 JSValueRef* exception)
629 CalendarEventPtr item = getPrivateObject(object);
631 if(item->getAlarmsJSRef()) {
632 return item->getAlarmsJSRef();
634 LoggerI("Create a JS object for alarms.");
635 JSObjectRef jsAlarms = JSCreateArrayObject(context, 0, NULL);
636 if (NULL == jsAlarms) {
637 ThrowMsg(NullPointerException, "Cannot create an array object.");
639 for( unsigned int i=0; i<item->getAlarms()->size(); i++) {
640 if (!JSSetArrayElement(context, jsAlarms, i, JSCalendarAlarm::createJSCalendarAlarm(context, item->getAlarms()->at(i)))) {
641 ThrowMsg(UnknownException, "Cannot insert a value into array.");
645 JSContextRef globalContext = GlobalContextManager::getInstance()->getGlobalContext(context);
646 CalendarConverter converter(globalContext);
647 item->setAlarmsJSRef(converter.toJSObjectRef(jsAlarms));
648 JSValueProtect(globalContext, jsAlarms);
649 item->setContext(globalContext);
656 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
658 return JSValueMakeUndefined(context);
661 bool JSCalendarItemProperties::setPropertyAlarms(JSContextRef context,
663 JSStringRef propertyName,
665 JSValueRef* exception)
667 CalendarEventPtr item(NULL);
670 item = getPrivateObject(object);
671 CalendarConverter converter(context);
673 EventAlarmListPtr alarms = converter.toVectorOfEventAlarmsFromReference(value);
675 item->setAlarms(alarms);
677 if(item->getAlarmsJSRef()) {
678 LoggerI("Replace a JS object for alarms.");
679 JSValueUnprotect(item->getContext(), item->getAlarmsJSRef());
680 item->setAlarmsJSRef(converter.toJSObjectRef(value));
681 JSValueProtect(item->getContext(), value);
688 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
694 JSValueRef JSCalendarItemProperties::getPropertyOrganizer(JSContextRef context,
696 JSStringRef propertyName,
697 JSValueRef* exception)
701 Converter converter(context);
702 CalendarEventPtr event = getPrivateObject(object);
703 return converter.toJSValueRef(event->getOrganizer());
707 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
709 return JSValueMakeUndefined(context);
712 bool JSCalendarItemProperties::setPropertyOrganizer(JSContextRef context,
714 JSStringRef propertyName,
716 JSValueRef* exception)
720 Converter converter(context);
721 CalendarEventPtr event = getPrivateObject(object);
722 std::string organizer = converter.toString(value);
723 event->setOrganizer(organizer);
728 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
734 JSValueRef JSCalendarItemProperties::getPropertyVisibility(JSContextRef context,
736 JSStringRef propertyName,
737 JSValueRef* exception)
741 CalendarConverter converter(context);
742 CalendarEventPtr event = getPrivateObject(object);
743 std::string visibility = converter.toTizenValue(event->getVisibility());
744 return converter.toJSValueRef(visibility);
748 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
750 return JSValueMakeUndefined(context);
753 bool JSCalendarItemProperties::setPropertyVisibility(JSContextRef context,
755 JSStringRef propertyName,
757 JSValueRef* exception)
759 CalendarEventPtr event(NULL);
762 event = getPrivateObject(object);
763 CalendarConverter converter(context);
764 CalendarEvent::EventVisibility visibility =
765 converter.toEventVisibility(converter.toString(value));
766 event->setVisibility(visibility);
771 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
777 JSValueRef JSCalendarItemProperties::getPropertyGeolocation(JSContextRef context,
779 JSStringRef propertyName,
780 JSValueRef* exception)
784 CalendarEventPtr item = getPrivateObject(object);
785 if( UNDEFINED_GEO==item->getGeolocation()->getLatitude() ) {
786 return JSValueMakeUndefined(context);
788 return DeviceAPI::Tizen::JSSimpleCoordinates::createJSObject(context, item->getGeolocation());
793 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
796 return JSValueMakeUndefined(context);
799 bool JSCalendarItemProperties::setPropertyGeolocation(JSContextRef context,
801 JSStringRef propertyName,
803 JSValueRef* exception)
807 CalendarEventPtr item = getPrivateObject(object);
809 if (JSValueIsNull(context, value)) {
810 item->getGeolocation()->setLatitude(UNDEFINED_GEO);
811 item->getGeolocation()->setLongitude(UNDEFINED_GEO);
813 DeviceAPI::Tizen::SimpleCoordinatesPtr geoLocation = DeviceAPI::Tizen::JSSimpleCoordinates::getSimpleCoordinates(context, value);
815 item->setGeolocation(geoLocation);
821 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
827 JSValueRef JSCalendarItemProperties::getPropertyDuration(JSContextRef context,
829 JSStringRef propertyName,
830 JSValueRef* exception)
834 CalendarEventPtr item = getPrivateObject(object);
836 if(UNDEFINED_TIME!=item->getDuration()->length) {
837 LoggerD("Duration length: "<<item->getDuration()->length<<", unit: "<<item->getDuration()->unit);
838 return JSTimeDuration::createJSObject(context, item->getDuration());
840 return JSValueMakeNull(context);
845 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
847 return JSValueMakeUndefined(context);
850 bool JSCalendarItemProperties::setPropertyDuration(JSContextRef context,
852 JSStringRef propertyName,
854 JSValueRef* exception)
858 CalendarEventPtr item = getPrivateObject(object);
860 if (JSValueIsNull(context, value)) {
861 DurationPropertiesPtr duration(new DeviceAPI::Time::DurationProperties());
862 item->setDuration(duration);
863 item->setEndTime(UNDEFINED_TIME);
867 TimeUtilConverter timeUtilConverter(context);
869 DurationPropertiesPtr duration = timeUtilConverter.getDuration(value);
870 LoggerD("length: "<<duration->length<< ", unit:" <<duration->unit);
871 item->setDuration(duration);
873 item->setEndTime(UNDEFINED_TIME);
879 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
885 JSValueRef JSCalendarItemProperties::getPropertyIsAllDay(JSContextRef context,
887 JSStringRef propertyName,
888 JSValueRef* exception)
892 CalendarConverter converter(context);
893 CalendarEventPtr event = getPrivateObject(object);
894 return converter.toJSValueRef(event->getIsAllDay());
898 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
900 return JSValueMakeUndefined(context);
903 bool JSCalendarItemProperties::setPropertyIsAllDay(JSContextRef context,
905 JSStringRef propertyName,
907 JSValueRef* exception)
911 CalendarEventPtr event = getPrivateObject(object);
912 Converter converter(context);
913 event->setIsAllDay(converter.toBool(value));
918 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
924 JSValueRef JSCalendarItemProperties::getPropertyAttendees(JSContextRef context,
926 JSStringRef propertyName,
927 JSValueRef* exception)
931 CalendarEventPtr item = getPrivateObject(object);
933 if(item->getAttendeesJSRef()) {
934 return item->getAttendeesJSRef();
936 LoggerI("Create a JS object for attendees.");
937 JSObjectRef jsAttendees = JSCreateArrayObject(context, 0, NULL);
938 if (NULL == jsAttendees) {
939 ThrowMsg(NullPointerException, "Cannot create an array object.");
941 EventAttendeeListPtr attendees = item->getAttendees();
942 for(unsigned int i=0; i<attendees->size(); i++) {
943 if (!JSSetArrayElement(context, jsAttendees, i, JSCalendarAttendee::createJSCalendarAttendee(context, attendees->at(i)))) {
944 ThrowMsg(UnknownException, "Cannot insert a value into array.");
948 JSContextRef globalContext = GlobalContextManager::getInstance()->getGlobalContext(context);
949 CalendarConverter converter(globalContext);
950 item->setAttendeesJSRef(converter.toJSObjectRef(jsAttendees));
951 JSValueProtect(globalContext, jsAttendees);
952 item->setContext(globalContext);
959 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
961 return JSValueMakeUndefined(context);
964 bool JSCalendarItemProperties::setPropertyAttendees(JSContextRef context,
966 JSStringRef propertyName,
968 JSValueRef* exception)
972 CalendarEventPtr item = getPrivateObject(object);
973 CalendarConverter converter(context);
974 item->setAttendees(converter.toVectorOfAttendeesFromReference(value));
976 if(item->getAttendeesJSRef()) {
977 LoggerI("Replace a JS object for attendees.");
978 JSValueUnprotect(item->getContext(), item->getAttendeesJSRef());
979 item->setAttendeesJSRef(converter.toJSObjectRef(value));
980 JSValueProtect(item->getContext(), value);
987 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
993 JSValueRef JSCalendarItemProperties::getPropertyDueDate(JSContextRef context,
995 JSStringRef propertyName,
996 JSValueRef* exception)
1000 CalendarItemPropertiesPrivObject *privateObject =
1001 static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(object));
1002 CalendarEventPtr task = privateObject->getObject();
1003 if(CalendarEvent::TASK_TYPE != task->getCalendarType()) {
1004 return JSValueMakeUndefined(context);
1007 ThrowMsg(NullPointerException, "Task object is NULL.");
1010 if (UNDEFINED_TIME==task->getEndTime()) {
1011 return JSValueMakeNull(context);
1013 TimeUtilConverter timeConverter(context);
1014 return timeConverter.toJSValueRefTZDate((double)(task->getEndTime()*1000.0), task->getTimeZone());
1019 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
1021 return JSValueMakeUndefined(context);
1024 bool JSCalendarItemProperties::setPropertyDueDate(JSContextRef context,
1026 JSStringRef propertyName,
1028 JSValueRef* exception)
1032 CalendarEventPtr task = getPrivateObject(object);
1034 ThrowMsg(NullPointerException, "Task object is NULL.");
1036 if(CalendarEvent::TASK_TYPE != task->getCalendarType()) {
1037 ThrowMsg(InvalidArgumentException, "Wrong type of calendar.");
1040 if (JSValueIsNull(context, value)) {
1041 task->setEndTime(UNDEFINED_TIME);
1043 } else if (!JSValueIsObjectOfClass(context, value, JSTZDate::getClassRef())) {
1044 ThrowMsg(ConversionException, "Wrong parameter type.");
1047 TimeUtilConverter converter(context);
1048 long long int dueDate = (long long int) (converter.getTimeInMilliseconds(value)/1000);
1050 task->setEndTime(dueDate);
1052 DurationPropertiesPtr duration(new DeviceAPI::Time::DurationProperties());
1053 task->setDuration(duration);
1055 if( task->getTimeZone().empty() ) {
1056 std::string timeZone = converter.getPropertiesInTZDate(value).timezone;
1057 task->setTimeZone(timeZone);
1063 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
1069 JSValueRef JSCalendarItemProperties::getPropertyPriority(JSContextRef context,
1071 JSStringRef propertyName,
1072 JSValueRef* exception)
1076 CalendarConverter converter(context);
1077 CalendarEventPtr item = getPrivateObject(object);
1079 ThrowMsg(NullPointerException, "Item object is NULL.");
1082 std::string priority = converter.toTizenValue(item->getPriority());
1083 return converter.toJSValueRef(priority);
1087 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
1089 return JSValueMakeUndefined(context);
1092 bool JSCalendarItemProperties::setPropertyPriority(JSContextRef context,
1094 JSStringRef propertyName,
1096 JSValueRef* exception)
1098 CalendarEventPtr item = getPrivateObject(object);
1101 CalendarConverter converter(context);
1102 CalendarEvent::TaskPriority priority =
1103 converter.toTaskPriority(converter.toString(value));
1104 item->setPriority(priority);
1109 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
1115 JSValueRef JSCalendarItemProperties::getPropertyEndDate(JSContextRef context,
1117 JSStringRef propertyName,
1118 JSValueRef* exception)
1122 CalendarItemPropertiesPrivObject *privateObject =
1123 static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(object));
1124 CalendarEventPtr event = privateObject->getObject();
1125 if(CalendarEvent::EVENT_TYPE != event->getCalendarType()) {
1126 return JSValueMakeUndefined(context);
1129 ThrowMsg(NullPointerException, "Event object is NULL.");
1132 if (UNDEFINED_TIME==event->getEndTime()) {
1133 return JSValueMakeNull(context);
1135 TimeUtilConverter timeConverter(context);
1136 return timeConverter.toJSValueRefTZDate((double)(event->getEndTime()*1000.0), event->getTimeZone());
1141 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
1143 return JSValueMakeUndefined(context);
1146 bool JSCalendarItemProperties::setPropertyEndDate(JSContextRef context,
1148 JSStringRef propertyName,
1150 JSValueRef* exception)
1154 CalendarEventPtr event = getPrivateObject(object);
1156 ThrowMsg(NullPointerException, "Event object is NULL.");
1158 if(CalendarEvent::EVENT_TYPE != event->getCalendarType()) {
1159 ThrowMsg(InvalidArgumentException, "Wrong calendar type.");
1162 if (JSValueIsNull(context, value)) {
1163 event->setEndTime(UNDEFINED_TIME);
1165 } else if (!JSValueIsObjectOfClass(context, value, JSTZDate::getClassRef())) {
1166 ThrowMsg(ConversionException, "Wrong parameter type.");
1169 TimeUtilConverter converter(context);
1170 long long int endDate = (long long int) (converter.getTimeInMilliseconds(value)/1000);
1172 event->setEndTime(endDate);
1174 DurationPropertiesPtr duration(new DeviceAPI::Time::DurationProperties());
1175 event->setDuration(duration);
1177 if( event->getTimeZone().empty() ) {
1178 std::string timeZone = converter.getPropertiesInTZDate(value).timezone;
1179 event->setTimeZone(timeZone);
1185 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
1191 JSValueRef JSCalendarItemProperties::getPropertyLastModificationDate(JSContextRef context,
1193 JSStringRef propertyName,
1194 JSValueRef* exception)
1198 CalendarEventPtr item = getPrivateObject(object);
1200 ThrowMsg(NullPointerException, "Item object is NULL.");
1203 if (UNDEFINED_TIME==item->getLastModifiedDate()) {
1204 return JSValueMakeNull(context);
1206 TimeUtilConverter timeConverter(context);
1207 return timeConverter.toJSValueRefTZDate((double)(item->getLastModifiedDate()*1000.0), item->getTimeZone());
1212 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
1214 return JSValueMakeUndefined(context);
1217 JSValueRef JSCalendarItemProperties::getPropertyCalendarId(JSContextRef context,
1219 JSStringRef propertyName,
1220 JSValueRef* exception)
1224 CalendarEventPtr item = getPrivateObject(object);
1226 if (UNDEFINED_CALENDAR_ID==item->getCalendarId()) {
1227 return JSValueMakeNull(context);
1229 CalendarConverter converter(context);
1230 std::stringstream ss;
1231 ss<<item->getCalendarId();
1232 return converter.toJSValueRef(ss.str());
1238 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
1240 return JSValueMakeUndefined(context);