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);
810 if(UNDEFINED_TIME==item->getStartTime() || UNDEFINED_TIME==item->getEndTime()) {
811 LoggerD("Start or end time is not defined.");
812 return JSValueMakeUndefined(context);
815 TimeUtilConverter converter(context);
816 long long length = item->getEndTime() - item->getStartTime(); // in seconds only
817 LoggerD("item->getStartTime():"<< item->getStartTime() << ", length:" << length);
818 return converter.makeMillisecondDurationObject( length*1000 );
822 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
824 return JSValueMakeUndefined(context);
827 bool JSCalendarItemProperties::setPropertyDuration(JSContextRef context,
829 JSStringRef propertyName,
831 JSValueRef* exception)
835 CalendarEventPtr event = getPrivateObject(object);
836 TimeUtilConverter converter(context);
837 long length = converter.getDurationLength(value);
838 int unit = converter.getDurationUnit(value);
840 DeviceAPI::Common::JSTizenExceptionFactory::postException(context, exception, DeviceAPI::Common::JSTizenException::INVALID_VALUES_ERROR);
843 if( SECONDS_UNIT==unit ) {
844 event->setEndTime(event->getStartTime() + length);
845 } else if ( MINUTES_UNIT==unit ) {
846 event->setEndTime(event->getStartTime() + length*60);
847 } else if ( HOURS_UNIT==unit ) {
848 event->setEndTime(event->getStartTime() + length*60*60);
849 } else if ( DAYS_UNIT==unit ) {
850 event->setEndTime(event->getStartTime() + length*24*60*60);
851 } else if ( MSECS_UNIT==unit ) {
852 event->setEndTime(event->getStartTime() + length/1000);
854 DeviceAPI::Common::JSTizenExceptionFactory::postException(context, exception, DeviceAPI::Common::JSTizenException::INVALID_VALUES_ERROR);
862 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
868 JSValueRef JSCalendarItemProperties::getPropertyIsAllDay(JSContextRef context,
870 JSStringRef propertyName,
871 JSValueRef* exception)
875 CalendarConverter converter(context);
876 CalendarEventPtr event = getPrivateObject(object);
877 return converter.toJSValueRef(event->getIsAllDay());
881 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
883 return JSValueMakeUndefined(context);
886 bool JSCalendarItemProperties::setPropertyIsAllDay(JSContextRef context,
888 JSStringRef propertyName,
890 JSValueRef* exception)
894 CalendarEventPtr event = getPrivateObject(object);
895 Converter converter(context);
896 event->setIsAllDay(converter.toBool(value));
901 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
907 JSValueRef JSCalendarItemProperties::getPropertyAvailability(JSContextRef context,
909 JSStringRef propertyName,
910 JSValueRef* exception)
914 CalendarConverter converter(context);
915 CalendarEventPtr event = getPrivateObject(object);
916 std::string availability = converter.toTizenValue(event->getAvailability());
917 return converter.toJSValueRef(availability);
921 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
923 return JSValueMakeUndefined(context);
926 bool JSCalendarItemProperties::setPropertyAvailability(JSContextRef context,
928 JSStringRef propertyName,
930 JSValueRef* exception)
932 CalendarEventPtr event(NULL);
935 event = getPrivateObject(object);
936 CalendarConverter converter(context);
937 CalendarEvent::EventAvailability availability =
938 converter.toEventAvailability(converter.toString(value));
939 event->setAvailability(availability);
944 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
950 JSValueRef JSCalendarItemProperties::getPropertyAttendees(JSContextRef context,
952 JSStringRef propertyName,
953 JSValueRef* exception)
957 CalendarEventPtr event = getPrivateObject(object);
958 EventAttendeeListPtr attendees = event->getAttendees();
960 JSObjectRef jsResult = JSCreateArrayObject(context, 0, NULL);
961 if (NULL == jsResult) {
962 ThrowMsg(NullPointerException, "Can not create array object.");
964 for(unsigned int i=0; i<attendees->size(); i++) {
965 if (!JSSetArrayElement(context, jsResult, i, JSCalendarAttendee::createJSCalendarAttendee(context, attendees->at(i)))) {
966 ThrowMsg(UnknownException, "Can not insert value into array.");
974 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
976 return JSValueMakeUndefined(context);
979 bool JSCalendarItemProperties::setPropertyAttendees(JSContextRef context,
981 JSStringRef propertyName,
983 JSValueRef* exception)
987 CalendarEventPtr event = getPrivateObject(object);
988 CalendarConverter converter(context);
989 event->setAttendees(converter.toVectorOfAttendeesFromReference(value));
994 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
1000 JSValueRef JSCalendarItemProperties::getPropertyDueDate(JSContextRef context,
1002 JSStringRef propertyName,
1003 JSValueRef* exception)
1007 CalendarItemPropertiesPrivObject *privateObject =
1008 static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(object));
1009 CalendarEventPtr task = privateObject->getObject();
1010 if(CalendarEvent::TASK_TYPE != task->getCalendarType()) {
1011 return JSValueMakeUndefined(context);
1014 ThrowMsg(NullPointerException, "Task object is NULL.");
1017 if (UNDEFINED_TIME==task->getEndTime()) {
1018 return JSValueMakeUndefined(context);
1020 TimeUtilConverter timeConverter(context);
1021 return timeConverter.toJSValueRefTZDate((double)(task->getEndTime()*1000.0), task->getTimeZone());
1026 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
1028 return JSValueMakeUndefined(context);
1031 bool JSCalendarItemProperties::setPropertyDueDate(JSContextRef context,
1033 JSStringRef propertyName,
1035 JSValueRef* exception)
1039 CalendarEventPtr task = getPrivateObject(object);
1041 ThrowMsg(NullPointerException, "Task object is NULL.");
1043 if(CalendarEvent::TASK_TYPE != task->getCalendarType()) {
1044 ThrowMsg(InvalidArgumentException, "Wrong type of calendar.");
1046 if (!JSValueIsObjectOfClass(context, value, JSTZDate::getClassRef())) {
1047 ThrowMsg(ConversionException, "Wrong parameter type.");
1050 TimeUtilConverter converter(context);
1051 long long int dueDate = (long long int) (converter.getTimeInMilliseconds(value)/1000);
1053 task->setEndTime(dueDate);
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::getPropertyCompletedDate(JSContextRef context,
1071 JSStringRef propertyName,
1072 JSValueRef* exception)
1076 CalendarItemPropertiesPrivObject *privateObject =
1077 static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(object));
1078 CalendarEventPtr task = privateObject->getObject();
1079 if(CalendarEvent::TASK_TYPE != task->getCalendarType()) {
1080 return JSValueMakeUndefined(context);
1083 ThrowMsg(NullPointerException, "Task object is NULL.");
1086 if (UNDEFINED_TIME==task->getCompletedDate()) {
1087 return JSValueMakeUndefined(context);
1089 TimeUtilConverter timeConverter(context);
1090 return timeConverter.toJSValueRefTZDate((double)(task->getCompletedDate()*1000.0), task->getTimeZone());
1095 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
1097 return JSValueMakeUndefined(context);
1100 bool JSCalendarItemProperties::setPropertyCompletedDate(JSContextRef context,
1102 JSStringRef propertyName,
1104 JSValueRef* exception)
1108 CalendarEventPtr task = getPrivateObject(object);
1110 ThrowMsg(NullPointerException, "Task object is NULL.");
1112 if(CalendarEvent::TASK_TYPE != task->getCalendarType()) {
1113 ThrowMsg(InvalidArgumentException, "Wrong calendar type.");
1115 if (!JSValueIsObjectOfClass(context, value, JSTZDate::getClassRef())) {
1116 ThrowMsg(ConversionException, "Wrong parameter type.");
1119 TimeUtilConverter converter(context);
1120 long long int completedDate = (long long int) (converter.getTimeInMilliseconds(value)/1000);
1122 task->setCompletedDate(completedDate);
1124 if( task->getTimeZone().empty() ) {
1125 std::string timeZone = converter.getPropertiesInTZDate(value).timezone;
1126 task->setTimeZone(timeZone);
1132 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
1138 JSValueRef JSCalendarItemProperties::getPropertyProgress(JSContextRef context,
1140 JSStringRef propertyName,
1141 JSValueRef* exception)
1145 CalendarEventPtr task = getPrivateObject(object);
1146 if(CalendarEvent::TASK_TYPE != task->getCalendarType()) {
1147 return JSValueMakeUndefined(context);
1150 Converter converter(context);
1151 return converter.toJSValueRef(task->getProgress());
1155 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
1157 return JSValueMakeUndefined(context);
1160 bool JSCalendarItemProperties::setPropertyProgress(JSContextRef context,
1162 JSStringRef propertyName,
1164 JSValueRef* exception)
1168 CalendarEventPtr task = getPrivateObject(object);
1169 if(CalendarEvent::TASK_TYPE != task->getCalendarType()) {
1170 return JSValueMakeUndefined(context);
1173 Converter converter(context);
1174 int progress = converter.toInt(value);
1175 task->setProgress(progress);
1180 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
1186 JSValueRef JSCalendarItemProperties::getPropertyPriority(JSContextRef context,
1188 JSStringRef propertyName,
1189 JSValueRef* exception)
1193 CalendarConverter converter(context);
1194 CalendarEventPtr item = getPrivateObject(object);
1196 ThrowMsg(NullPointerException, "Item object is NULL.");
1199 std::string priority = converter.toTizenValue(item->getPriority());
1200 return converter.toJSValueRef(priority);
1204 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
1206 return JSValueMakeUndefined(context);
1209 bool JSCalendarItemProperties::setPropertyPriority(JSContextRef context,
1211 JSStringRef propertyName,
1213 JSValueRef* exception)
1215 CalendarEventPtr item = getPrivateObject(object);
1218 CalendarConverter converter(context);
1219 CalendarEvent::TaskPriority priority =
1220 converter.toTaskPriority(converter.toString(value));
1221 item->setPriority(priority);
1226 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
1232 JSValueRef JSCalendarItemProperties::getPropertyEndDate(JSContextRef context,
1234 JSStringRef propertyName,
1235 JSValueRef* exception)
1239 CalendarItemPropertiesPrivObject *privateObject =
1240 static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(object));
1241 CalendarEventPtr event = privateObject->getObject();
1242 if(CalendarEvent::EVENT_TYPE != event->getCalendarType()) {
1243 return JSValueMakeUndefined(context);
1246 ThrowMsg(NullPointerException, "Event object is NULL.");
1249 if (UNDEFINED_TIME==event->getEndTime()) {
1250 return JSValueMakeUndefined(context);
1252 TimeUtilConverter timeConverter(context);
1253 return timeConverter.toJSValueRefTZDate((double)(event->getEndTime()*1000.0), event->getTimeZone());
1258 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
1260 return JSValueMakeUndefined(context);
1263 bool JSCalendarItemProperties::setPropertyEndDate(JSContextRef context,
1265 JSStringRef propertyName,
1267 JSValueRef* exception)
1271 CalendarEventPtr event = getPrivateObject(object);
1273 ThrowMsg(NullPointerException, "Event object is NULL.");
1275 if(CalendarEvent::EVENT_TYPE != event->getCalendarType()) {
1276 ThrowMsg(InvalidArgumentException, "Wrong calendar type.");
1278 if (!JSValueIsObjectOfClass(context, value, JSTZDate::getClassRef())) {
1279 ThrowMsg(ConversionException, "Wrong parameter type.");
1282 TimeUtilConverter converter(context);
1283 long long int endDate = (long long int) (converter.getTimeInMilliseconds(value)/1000);
1285 event->setEndTime(endDate);
1287 if( event->getTimeZone().empty() ) {
1288 std::string timeZone = converter.getPropertiesInTZDate(value).timezone;
1289 event->setTimeZone(timeZone);
1295 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
1301 JSValueRef JSCalendarItemProperties::getPropertyLastModificationDate(JSContextRef context,
1303 JSStringRef propertyName,
1304 JSValueRef* exception)
1308 CalendarEventPtr item = getPrivateObject(object);
1310 ThrowMsg(NullPointerException, "Item object is NULL.");
1313 if (UNDEFINED_TIME==item->getLastModifiedDate()) {
1314 return JSValueMakeNull(context);
1316 TimeUtilConverter timeConverter(context);
1317 return timeConverter.toJSValueRefTZDate((double)(item->getLastModifiedDate()*1000.0), item->getTimeZone());
1322 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
1324 return JSValueMakeUndefined(context);
1327 JSValueRef JSCalendarItemProperties::getPropertyCalendarId(JSContextRef context,
1329 JSStringRef propertyName,
1330 JSValueRef* exception)
1334 CalendarEventPtr item = getPrivateObject(object);
1336 if (UNDEFINED_CALENDAR_ID==item->getCalendarId()) {
1337 return JSValueMakeNull(context);
1339 CalendarConverter converter(context);
1340 std::stringstream ss;
1341 ss<<item->getCalendarId();
1342 return converter.toJSValueRef(ss.str());
1348 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
1350 return JSValueMakeUndefined(context);