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 <JSTizenException.h>
23 #include <JSTizenExceptionFactory.h>
24 #include <SecurityExceptions.h>
25 #include <TimeUtilConverter.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 #define TIZEN_CALENDAR_ITEM_PROPERTIES_ATTRIBUTENAME "CalendarItemProperties"
55 JSClassDefinition JSCalendarItemProperties::m_classInfo = {
57 kJSClassAttributeNone,
58 TIZEN_CALENDAR_ITEM_PROPERTIES_ATTRIBUTENAME,
67 NULL, //DeleteProperty,
68 NULL, //GetPropertyNames,
69 NULL, //CallAsFunction,
70 NULL, //CallAsConstructor,
75 JSStaticValue JSCalendarItemProperties::m_property[] = {
77 { TIZEN_CALENDAR_ITEM_DESCRIPTION, getPropertyDescription, setPropertyDescription, kJSPropertyAttributeNone },
78 { TIZEN_CALENDAR_ITEM_SUMMARY, getPropertySummary, setPropertySummary, kJSPropertyAttributeNone },
79 { TIZEN_CALENDAR_ITEM_START_DATE, getPropertyStartTime, setPropertyStartTime, kJSPropertyAttributeNone },
80 { TIZEN_CALENDAR_ITEM_LOCATION, getPropertyLocation, setPropertyLocation, kJSPropertyAttributeNone },
81 { TIZEN_CALENDAR_ITEM_GEOLOCATION, getPropertyGeolocation, setPropertyGeolocation, kJSPropertyAttributeNone },
82 { TIZEN_CALENDAR_ITEM_ORGANIZER, getPropertyOrganizer, setPropertyOrganizer, kJSPropertyAttributeNone },
83 { TIZEN_CALENDAR_ITEM_VISIBILITY, getPropertyVisibility, setPropertyVisibility, kJSPropertyAttributeNone },
84 { TIZEN_CALENDAR_ITEM_STATUS, getPropertyStatus, setPropertyStatus, kJSPropertyAttributeNone },
85 { TIZEN_CALENDAR_ITEM_ALARMS, getPropertyAlarms, setPropertyAlarms, kJSPropertyAttributeNone },
86 { TIZEN_CALENDAR_ITEM_CATEGORIES, getPropertyCategories, setPropertyCategories, kJSPropertyAttributeNone },
87 { TIZEN_CALENDAR_ITEM_DURATION, getPropertyDuration, setPropertyDuration, kJSPropertyAttributeNone },
88 { TIZEN_CALENDAR_ITEM_IS_ALL_DAY, getPropertyIsAllDay, setPropertyIsAllDay, kJSPropertyAttributeNone },
89 { TIZEN_CALENDAR_ITEM_ATTENDEES, getPropertyAttendees, setPropertyAttendees, kJSPropertyAttributeNone },
90 { TIZEN_CALENDAR_EVENT_AVAILABILITY, getPropertyAvailability, setPropertyAvailability, kJSPropertyAttributeNone },
91 { TIZEN_CALENDAR_TASK_DUE_DATE, getPropertyDueDate, setPropertyDueDate, kJSPropertyAttributeNone },
92 { TIZEN_CALENDAR_TASK_COMPLETED_DATE, getPropertyCompletedDate, setPropertyCompletedDate, kJSPropertyAttributeNone },
93 { TIZEN_CALENDAR_TASK_PROGRESS, getPropertyProgress, setPropertyProgress, kJSPropertyAttributeNone },
94 { TIZEN_CALENDAR_ITEM_PRIORITY, getPropertyPriority, setPropertyPriority, kJSPropertyAttributeNone },
95 { TIZEN_CALENDAR_EVENT_END_DATE, getPropertyEndDate, setPropertyEndDate, kJSPropertyAttributeNone },
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 AceSecurityStatus status = CALENDAR_CHECK_ACCESS(CALENDAR_FUNCTION_API_CONVERT_TO_STRING);
201 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
205 if (!privateObject) {
206 ThrowMsg(ConversionException, "Object is null.");
209 CalendarEventPtr item = privateObject->getObject();
211 ThrowMsg(ConversionException, "Parameter conversion failed.");
214 CalendarConverter converter(context);
216 CalendarEvent::VObjectFormat format = CalendarEvent::UNDEFINED_FORMAT;
217 if (argumentCount>=1) {
218 format = converter.toVObjectFormat(converter.toString(arguments[0]));
220 ThrowMsg(ConversionException, "Wrong parameter type.");
223 ICalendarPtr calendar = CalendarFactory::getInstance().createCalendarObject();
224 calendar->setType(item->getCalendarType());
226 IEventExportEventToStringPtr dplEvent(new IEventExportEventToString());
227 dplEvent->setEvent(item);
228 dplEvent->setFormat(format);
229 dplEvent->setForSynchronousCall();
230 calendar->exportEventToString(dplEvent);
232 if (dplEvent->getResult()) {
233 TIME_TRACER_ITEM_END(__FUNCTION__, 0);
234 return converter.toJSValueRef(dplEvent->getEventString());
236 ThrowMsg(UnknownException, "Converting to string failed by unknown reason.");
239 Catch(UnsupportedException)
241 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
242 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
244 Catch(InvalidArgumentException)
246 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
247 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
249 Catch(ConversionException)
251 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
252 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
254 Catch (NotFoundException)
256 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
257 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
261 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
262 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
266 JSValueRef JSCalendarItemProperties::clone(JSContextRef context,
268 JSObjectRef thisObject,
269 size_t argumentCount,
270 const JSValueRef arguments[],
271 JSValueRef* exception)
273 TIME_TRACER_ITEM_BEGIN("clone(TASK)", 0);
274 TIME_TRACER_ITEM_BEGIN("clone(EVENT)", 0);
275 CalendarItemPropertiesPrivObject *privateObject =
276 static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(thisObject));
278 AceSecurityStatus status = CALENDAR_CHECK_ACCESS(CALENDAR_FUNCTION_API_CLONE);
280 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
284 if (!privateObject) {
285 ThrowMsg(ConversionException, "Object is null.");
288 CalendarEventPtr item = privateObject->getObject(); // item to copy
290 ThrowMsg(ConversionException, "Parameter conversion failed.");
292 JSContextRef globalContext = privateObject->getContext();
294 // Call the copy constructor.
295 CalendarEventPtr clonedItem( new CalendarEvent(*item));
298 clonedItem->resetId();
299 clonedItem->setRecurrenceId(UNDEFINED_ITEM_ID);
301 if (CalendarEvent::TASK_TYPE==clonedItem->getCalendarType()) {
302 TIME_TRACER_ITEM_END("clone(TASK)", 0);
303 return JSCalendarTask::createJSCalendarTask(context, clonedItem);
304 } else if (CalendarEvent::EVENT_TYPE==clonedItem->getCalendarType()) {
305 TIME_TRACER_ITEM_END("clone(EVENT)", 0);
306 // Use global context for potential async api invocation.
307 return JSCalendarEvent::createJSCalendarEvent(globalContext, clonedItem);
309 ThrowMsg(ConversionException, "Wrong object type.");
312 Catch(UnsupportedException)
314 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
315 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
317 Catch(InvalidArgumentException)
319 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
320 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
322 Catch(ConversionException)
324 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
325 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
327 Catch (NotFoundException)
329 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
330 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
334 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
335 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
339 JSValueRef JSCalendarItemProperties::getPropertyDescription(JSContextRef context,
341 JSStringRef propertyName,
342 JSValueRef* exception)
346 Converter converter(context);
347 CalendarEventPtr event = getPrivateObject(object);
348 return converter.toJSValueRef(event->getDescription());
352 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
354 return JSValueMakeUndefined(context);
357 bool JSCalendarItemProperties::setPropertyDescription(JSContextRef context,
359 JSStringRef propertyName,
361 JSValueRef* exception)
365 Converter converter(context);
366 CalendarEventPtr event = getPrivateObject(object);
367 std::string description = converter.toString(value);
368 event->setDescription(description);
373 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
379 JSValueRef JSCalendarItemProperties::getPropertySummary(JSContextRef context,
381 JSStringRef propertyName,
382 JSValueRef* exception)
386 Converter converter(context);
387 CalendarEventPtr event = getPrivateObject(object);
388 return converter.toJSValueRef(event->getSubject());
392 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
394 return JSValueMakeUndefined(context);
397 bool JSCalendarItemProperties::setPropertySummary(JSContextRef context,
399 JSStringRef propertyName,
401 JSValueRef* exception)
405 Converter converter(context);
406 CalendarEventPtr event = getPrivateObject(object);
407 std::string subject = converter.toString(value);
408 event->setSubject(subject);
413 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
419 JSValueRef JSCalendarItemProperties::getPropertyStartTime(JSContextRef context,
421 JSStringRef propertyName,
422 JSValueRef* exception)
426 CalendarItemPropertiesPrivObject *privateObject =
427 static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(object));
428 TimeUtilConverter timeConverter(context);
429 CalendarEventPtr event = privateObject->getObject();
431 LoggerI("start time before converted to TZDate: "<<event->getStartTime()<<", time zone: "<<event->getTimeZone());
432 if (UNDEFINED_TIME==event->getStartTime()) {
433 return JSValueMakeUndefined(context);
435 return timeConverter.toJSValueRefTZDate((double)(event->getStartTime()*1000.0), event->getTimeZone());
440 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
442 return JSValueMakeUndefined(context);
445 bool JSCalendarItemProperties::setPropertyStartTime(JSContextRef context,
447 JSStringRef propertyName,
449 JSValueRef* exception)
453 if (!JSValueIsObjectOfClass(context, value, JSTZDate::getClassRef())) {
454 ThrowMsg(ConversionException, "Wrong parameter type.");
457 CalendarEventPtr event = getPrivateObject(object);
458 TimeUtilConverter converter(context);
459 std::time_t duration = event->getEndTime() - event->getStartTime();
464 long long int startTime = (long long int) (converter.getTimeInMilliseconds(value)/1000);
465 event->setStartTime(startTime);
466 event->setEndTime(startTime + duration);
468 std::string timeZone = converter.getPropertiesInTZDate(value).timezone;
469 event->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);
809 TimeUtilConverter converter(context);
811 DurationProperties duration;
812 if(UNDEFINED_TIME!=item->getDuration()->length) {
813 duration.length = item->getDuration()->length;
814 duration.unit = item->getDuration()->unit;
815 LoggerD("Duration length: "<<duration.length<<", unit: "<<duration.unit);
816 return converter.makeDurationObject( duration );
819 // Alternatively generate the duration object using start/end time.
820 if(UNDEFINED_TIME==item->getStartTime() || UNDEFINED_TIME==item->getEndTime()) {
821 LoggerD("Start or end time is not defined.");
822 return JSValueMakeUndefined(context);
825 long long length = item->getEndTime() - item->getStartTime(); // in seconds only
826 LoggerD("item->getStartTime():"<< item->getStartTime() << ", length:" << length);
827 duration.length = length;
828 duration.unit = SECONDS_UNIT;
830 return converter.makeDurationObject( duration );
834 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
836 return JSValueMakeUndefined(context);
839 bool JSCalendarItemProperties::setPropertyDuration(JSContextRef context,
841 JSStringRef propertyName,
843 JSValueRef* exception)
847 CalendarEventPtr event = getPrivateObject(object);
848 TimeUtilConverter converter(context);
849 long length = converter.getDurationLength(value);
850 int unit = converter.getDurationUnit(value);
852 DeviceAPI::Common::JSTizenExceptionFactory::postException(context, exception, DeviceAPI::Common::JSTizenException::INVALID_VALUES_ERROR);
855 if( SECONDS_UNIT==unit ) {
856 event->setEndTime(event->getStartTime() + length);
857 } else if ( MINUTES_UNIT==unit ) {
858 event->setEndTime(event->getStartTime() + length*60);
859 } else if ( HOURS_UNIT==unit ) {
860 event->setEndTime(event->getStartTime() + length*60*60);
861 } else if ( DAYS_UNIT==unit ) {
862 event->setEndTime(event->getStartTime() + length*24*60*60);
863 } else if ( MSECS_UNIT==unit ) {
864 event->setEndTime(event->getStartTime() + length/1000);
866 DeviceAPI::Common::JSTizenExceptionFactory::postException(context, exception, DeviceAPI::Common::JSTizenException::INVALID_VALUES_ERROR);
870 event->getDuration()->length = length;
871 event->getDuration()->unit = unit;
877 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
883 JSValueRef JSCalendarItemProperties::getPropertyIsAllDay(JSContextRef context,
885 JSStringRef propertyName,
886 JSValueRef* exception)
890 CalendarConverter converter(context);
891 CalendarEventPtr event = getPrivateObject(object);
892 return converter.toJSValueRef(event->getIsAllDay());
896 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
898 return JSValueMakeUndefined(context);
901 bool JSCalendarItemProperties::setPropertyIsAllDay(JSContextRef context,
903 JSStringRef propertyName,
905 JSValueRef* exception)
909 CalendarEventPtr event = getPrivateObject(object);
910 Converter converter(context);
911 event->setIsAllDay(converter.toBool(value));
916 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
922 JSValueRef JSCalendarItemProperties::getPropertyAvailability(JSContextRef context,
924 JSStringRef propertyName,
925 JSValueRef* exception)
929 CalendarConverter converter(context);
930 CalendarEventPtr event = getPrivateObject(object);
931 std::string availability = converter.toTizenValue(event->getAvailability());
932 return converter.toJSValueRef(availability);
936 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
938 return JSValueMakeUndefined(context);
941 bool JSCalendarItemProperties::setPropertyAvailability(JSContextRef context,
943 JSStringRef propertyName,
945 JSValueRef* exception)
947 CalendarEventPtr event(NULL);
950 event = getPrivateObject(object);
951 CalendarConverter converter(context);
952 CalendarEvent::EventAvailability availability =
953 converter.toEventAvailability(converter.toString(value));
954 event->setAvailability(availability);
959 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
965 JSValueRef JSCalendarItemProperties::getPropertyAttendees(JSContextRef context,
967 JSStringRef propertyName,
968 JSValueRef* exception)
972 CalendarEventPtr event = getPrivateObject(object);
973 EventAttendeeListPtr attendees = event->getAttendees();
975 JSObjectRef jsResult = JSCreateArrayObject(context, 0, NULL);
976 if (NULL == jsResult) {
977 ThrowMsg(NullPointerException, "Can not create array object.");
979 for(unsigned int i=0; i<attendees->size(); i++) {
980 if (!JSSetArrayElement(context, jsResult, i, JSCalendarAttendee::createJSCalendarAttendee(context, attendees->at(i)))) {
981 ThrowMsg(UnknownException, "Can not insert value into array.");
989 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
991 return JSValueMakeUndefined(context);
994 bool JSCalendarItemProperties::setPropertyAttendees(JSContextRef context,
996 JSStringRef propertyName,
998 JSValueRef* exception)
1002 CalendarEventPtr event = getPrivateObject(object);
1003 CalendarConverter converter(context);
1004 event->setAttendees(converter.toVectorOfAttendeesFromReference(value));
1009 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
1015 JSValueRef JSCalendarItemProperties::getPropertyDueDate(JSContextRef context,
1017 JSStringRef propertyName,
1018 JSValueRef* exception)
1022 CalendarItemPropertiesPrivObject *privateObject =
1023 static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(object));
1024 CalendarEventPtr task = privateObject->getObject();
1025 if(CalendarEvent::TASK_TYPE != task->getCalendarType()) {
1026 return JSValueMakeUndefined(context);
1029 ThrowMsg(NullPointerException, "Task object is NULL.");
1032 if (UNDEFINED_TIME==task->getEndTime()) {
1033 return JSValueMakeUndefined(context);
1035 TimeUtilConverter timeConverter(context);
1036 return timeConverter.toJSValueRefTZDate((double)(task->getEndTime()*1000.0), task->getTimeZone());
1041 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
1043 return JSValueMakeUndefined(context);
1046 bool JSCalendarItemProperties::setPropertyDueDate(JSContextRef context,
1048 JSStringRef propertyName,
1050 JSValueRef* exception)
1054 CalendarEventPtr task = getPrivateObject(object);
1056 ThrowMsg(NullPointerException, "Task object is NULL.");
1058 if(CalendarEvent::TASK_TYPE != task->getCalendarType()) {
1059 ThrowMsg(InvalidArgumentException, "Wrong type of calendar.");
1061 if (!JSValueIsObjectOfClass(context, value, JSTZDate::getClassRef())) {
1062 ThrowMsg(ConversionException, "Wrong parameter type.");
1065 TimeUtilConverter converter(context);
1066 long long int dueDate = (long long int) (converter.getTimeInMilliseconds(value)/1000);
1068 task->setEndTime(dueDate);
1070 if( task->getTimeZone().empty() ) {
1071 std::string timeZone = converter.getPropertiesInTZDate(value).timezone;
1072 task->setTimeZone(timeZone);
1078 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
1084 JSValueRef JSCalendarItemProperties::getPropertyCompletedDate(JSContextRef context,
1086 JSStringRef propertyName,
1087 JSValueRef* exception)
1091 CalendarItemPropertiesPrivObject *privateObject =
1092 static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(object));
1093 CalendarEventPtr task = privateObject->getObject();
1094 if(CalendarEvent::TASK_TYPE != task->getCalendarType()) {
1095 return JSValueMakeUndefined(context);
1098 ThrowMsg(NullPointerException, "Task object is NULL.");
1101 if (UNDEFINED_TIME==task->getCompletedDate()) {
1102 return JSValueMakeUndefined(context);
1104 TimeUtilConverter timeConverter(context);
1105 return timeConverter.toJSValueRefTZDate((double)(task->getCompletedDate()*1000.0), task->getTimeZone());
1110 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
1112 return JSValueMakeUndefined(context);
1115 bool JSCalendarItemProperties::setPropertyCompletedDate(JSContextRef context,
1117 JSStringRef propertyName,
1119 JSValueRef* exception)
1123 CalendarEventPtr task = getPrivateObject(object);
1125 ThrowMsg(NullPointerException, "Task object is NULL.");
1127 if(CalendarEvent::TASK_TYPE != task->getCalendarType()) {
1128 ThrowMsg(InvalidArgumentException, "Wrong calendar type.");
1130 if (!JSValueIsObjectOfClass(context, value, JSTZDate::getClassRef())) {
1131 ThrowMsg(ConversionException, "Wrong parameter type.");
1134 TimeUtilConverter converter(context);
1135 long long int completedDate = (long long int) (converter.getTimeInMilliseconds(value)/1000);
1137 task->setCompletedDate(completedDate);
1139 if( task->getTimeZone().empty() ) {
1140 std::string timeZone = converter.getPropertiesInTZDate(value).timezone;
1141 task->setTimeZone(timeZone);
1147 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
1153 JSValueRef JSCalendarItemProperties::getPropertyProgress(JSContextRef context,
1155 JSStringRef propertyName,
1156 JSValueRef* exception)
1160 CalendarEventPtr task = getPrivateObject(object);
1161 if(CalendarEvent::TASK_TYPE != task->getCalendarType()) {
1162 return JSValueMakeUndefined(context);
1165 Converter converter(context);
1166 return converter.toJSValueRef(task->getProgress());
1170 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
1172 return JSValueMakeUndefined(context);
1175 bool JSCalendarItemProperties::setPropertyProgress(JSContextRef context,
1177 JSStringRef propertyName,
1179 JSValueRef* exception)
1183 CalendarEventPtr task = getPrivateObject(object);
1184 if(CalendarEvent::TASK_TYPE != task->getCalendarType()) {
1185 return JSValueMakeUndefined(context);
1188 Converter converter(context);
1189 int progress = converter.toInt(value);
1190 task->setProgress(progress);
1195 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
1201 JSValueRef JSCalendarItemProperties::getPropertyPriority(JSContextRef context,
1203 JSStringRef propertyName,
1204 JSValueRef* exception)
1208 CalendarConverter converter(context);
1209 CalendarEventPtr item = getPrivateObject(object);
1211 ThrowMsg(NullPointerException, "Item object is NULL.");
1214 std::string priority = converter.toTizenValue(item->getPriority());
1215 return converter.toJSValueRef(priority);
1219 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
1221 return JSValueMakeUndefined(context);
1224 bool JSCalendarItemProperties::setPropertyPriority(JSContextRef context,
1226 JSStringRef propertyName,
1228 JSValueRef* exception)
1230 CalendarEventPtr item = getPrivateObject(object);
1233 CalendarConverter converter(context);
1234 CalendarEvent::TaskPriority priority =
1235 converter.toTaskPriority(converter.toString(value));
1236 item->setPriority(priority);
1241 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
1247 JSValueRef JSCalendarItemProperties::getPropertyEndDate(JSContextRef context,
1249 JSStringRef propertyName,
1250 JSValueRef* exception)
1254 CalendarItemPropertiesPrivObject *privateObject =
1255 static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(object));
1256 CalendarEventPtr event = privateObject->getObject();
1257 if(CalendarEvent::EVENT_TYPE != event->getCalendarType()) {
1258 return JSValueMakeUndefined(context);
1261 ThrowMsg(NullPointerException, "Event object is NULL.");
1264 if (UNDEFINED_TIME==event->getEndTime()) {
1265 return JSValueMakeUndefined(context);
1267 TimeUtilConverter timeConverter(context);
1268 return timeConverter.toJSValueRefTZDate((double)(event->getEndTime()*1000.0), event->getTimeZone());
1273 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
1275 return JSValueMakeUndefined(context);
1278 bool JSCalendarItemProperties::setPropertyEndDate(JSContextRef context,
1280 JSStringRef propertyName,
1282 JSValueRef* exception)
1286 CalendarEventPtr event = getPrivateObject(object);
1288 ThrowMsg(NullPointerException, "Event object is NULL.");
1290 if(CalendarEvent::EVENT_TYPE != event->getCalendarType()) {
1291 ThrowMsg(InvalidArgumentException, "Wrong calendar type.");
1293 if (!JSValueIsObjectOfClass(context, value, JSTZDate::getClassRef())) {
1294 ThrowMsg(ConversionException, "Wrong parameter type.");
1297 TimeUtilConverter converter(context);
1298 long long int endDate = (long long int) (converter.getTimeInMilliseconds(value)/1000);
1300 event->setEndTime(endDate);
1302 if( event->getTimeZone().empty() ) {
1303 std::string timeZone = converter.getPropertiesInTZDate(value).timezone;
1304 event->setTimeZone(timeZone);
1310 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
1316 JSValueRef JSCalendarItemProperties::getPropertyLastModificationDate(JSContextRef context,
1318 JSStringRef propertyName,
1319 JSValueRef* exception)
1323 CalendarEventPtr item = getPrivateObject(object);
1325 ThrowMsg(NullPointerException, "Item object is NULL.");
1328 if (UNDEFINED_TIME==item->getLastModifiedDate()) {
1329 return JSValueMakeNull(context);
1331 TimeUtilConverter timeConverter(context);
1332 return timeConverter.toJSValueRefTZDate((double)(item->getLastModifiedDate()*1000.0), item->getTimeZone());
1337 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
1339 return JSValueMakeUndefined(context);
1342 JSValueRef JSCalendarItemProperties::getPropertyCalendarId(JSContextRef context,
1344 JSStringRef propertyName,
1345 JSValueRef* exception)
1349 CalendarEventPtr item = getPrivateObject(object);
1351 if (UNDEFINED_CALENDAR_ID==item->getCalendarId()) {
1352 return JSValueMakeNull(context);
1354 CalendarConverter converter(context);
1355 std::stringstream ss;
1356 ss<<item->getCalendarId();
1357 return converter.toJSValueRef(ss.str());
1363 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
1365 return JSValueMakeUndefined(context);