2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <dpl/log/log.h>
20 #include <CommonsJavaScript/PrivateObject.h>
21 #include <CommonsJavaScript/Converter.h>
22 #include <CommonsJavaScript/JSUtils.h>
23 #include <Tizen/Common/JSTizenException.h>
24 #include <Tizen/Common/JSTizenExceptionFactory.h>
25 #include <Tizen/Common/SecurityExceptions.h>
26 #include <Tizen/TimeUtil/TimeUtilConverter.h>
27 #include <Tizen/TimeUtil/JSTZDate.h>
28 #include <Tizen/Tizen/JSSimpleCoordinates.h>
29 #include <API/Calendar/EventAlarm.h>
30 #include <API/Calendar/EventId.h>
31 #include <API/Calendar/ICalendar.h>
32 #include <API/Calendar/CalendarFactory.h>
33 #include "API/TimeUtil/DurationProperties.h"
34 #include "JSCalendarItemProperties.h"
35 #include "CalendarConverter.h"
36 #include "JSCalendarEventId.h"
37 #include "JSCalendarAlarm.h"
38 #include "JSCalendarRecurrenceRule.h"
39 #include "JSCalendarAttendee.h"
40 #include "JSCalendarEvent.h"
41 #include "JSCalendarTask.h"
42 #include "plugin_config.h"
44 using namespace TizenApis::Api::Calendar;
45 using namespace WrtDeviceApis::Commons;
46 using namespace WrtDeviceApis::CommonsJavaScript;
47 using namespace TizenApis::Commons;
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,
78 setPropertyDescription, kJSPropertyAttributeNone },
79 { TIZEN_CALENDAR_ITEM_SUMMARY, getPropertySummary,
80 setPropertySummary, kJSPropertyAttributeNone },
81 { TIZEN_CALENDAR_ITEM_START_DATE, getPropertyStartTime,
82 setPropertyStartTime, kJSPropertyAttributeNone },
83 { TIZEN_CALENDAR_ITEM_LOCATION, getPropertyLocation,
84 setPropertyLocation, kJSPropertyAttributeNone },
85 { TIZEN_CALENDAR_ITEM_GEOLOCATION, getPropertyGeolocation,
86 setPropertyGeolocation, kJSPropertyAttributeNone },
87 { TIZEN_CALENDAR_ITEM_ORGANIZER, getPropertyOrganizer,
88 setPropertyOrganizer, kJSPropertyAttributeNone },
89 { TIZEN_CALENDAR_ITEM_VISIBILITY, getPropertyVisibility,
90 setPropertyVisibility, kJSPropertyAttributeNone },
91 { TIZEN_CALENDAR_ITEM_STATUS, getPropertyStatus,
92 setPropertyStatus, kJSPropertyAttributeNone },
93 { TIZEN_CALENDAR_ITEM_ALARMS, getPropertyAlarms,
94 setPropertyAlarms, kJSPropertyAttributeNone },
95 { TIZEN_CALENDAR_ITEM_CATEGORIES, getPropertyCategories,
96 setPropertyCategories, kJSPropertyAttributeNone },
97 { TIZEN_CALENDAR_ITEM_DURATION, getPropertyDuration,
98 setPropertyDuration, kJSPropertyAttributeNone },
99 { TIZEN_CALENDAR_ITEM_IS_ALL_DAY, getPropertyIsAllDay,
100 setPropertyIsAllDay, kJSPropertyAttributeNone },
101 { TIZEN_CALENDAR_ITEM_ATTENDEES, getPropertyAttendees,
102 setPropertyAttendees, kJSPropertyAttributeNone },
103 { TIZEN_CALENDAR_EVENT_RECURRENCE_RULE, getPropertyRecurrenceRule,
104 setPropertyRecurrenceRule, kJSPropertyAttributeNone },
105 { TIZEN_CALENDAR_EVENT_AVAILABILITY, getPropertyAvailability,
106 setPropertyAvailability, kJSPropertyAttributeNone },
107 { TIZEN_CALENDAR_TASK_DUE_DATE, getPropertyDueDate,
108 setPropertyDueDate, kJSPropertyAttributeNone },
109 { TIZEN_CALENDAR_TASK_COMPLETED_DATE, getPropertyCompletedDate,
110 setPropertyCompletedDate, kJSPropertyAttributeNone },
111 { TIZEN_CALENDAR_TASK_PROGRESS, getPropertyProgress,
112 setPropertyProgress, kJSPropertyAttributeNone },
113 { TIZEN_CALENDAR_ITEM_PRIORITY, getPropertyPriority,
114 setPropertyPriority, kJSPropertyAttributeNone },
115 { TIZEN_CALENDAR_EVENT_END_DATE, getPropertyEndDate,
116 setPropertyEndDate, kJSPropertyAttributeNone },
121 JSStaticFunction JSCalendarItemProperties::m_function[] = {
122 { CALENDAR_FUNCTION_API_CONVERT_TO_STRING, convertToString, kJSPropertyAttributeNone },
123 { CALENDAR_FUNCTION_API_CLONE, clone, kJSPropertyAttributeNone },
128 JSClassRef JSCalendarItemProperties::m_jsClassRef = JSClassCreate(JSCalendarItemProperties::getClassInfo());
130 void JSCalendarItemProperties::initialize(JSContextRef context,
133 if (!JSObjectGetPrivate(object)) {
134 LogDebug("Create calendar item private object.");
135 CalendarEventPtr item( new CalendarEvent() );
136 CalendarItemPropertiesPrivObject *priv = new CalendarItemPropertiesPrivObject(context, item);
137 if (!JSObjectSetPrivate(object, static_cast<void*>(priv))) {
141 LogDebug("Private object alrerady set.");
145 void JSCalendarItemProperties::finalize(JSObjectRef object)
148 CalendarItemPropertiesPrivObject *priv = static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(object));
151 JSObjectSetPrivate(object, NULL);
155 const JSClassRef JSCalendarItemProperties::getClassRef()
158 m_jsClassRef = JSClassCreate(&m_classInfo);
163 const JSClassDefinition* JSCalendarItemProperties::getClassInfo()
168 CalendarEventPtr JSCalendarItemProperties::getPrivateObject(JSObjectRef object)
171 CalendarItemPropertiesPrivObject *priv =
172 static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(object));
174 ThrowMsg(NullPointerException, "Private object is null");
176 CalendarEventPtr result = priv->getObject();
178 ThrowMsg(NullPointerException, "Private object is null");
183 void JSCalendarItemProperties::setPrivateObject(const CalendarEventPtr &event,
185 const JSObjectRef object)
190 CalendarItemPropertiesPrivObject *priv =
191 static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(object));
193 priv = new CalendarItemPropertiesPrivObject(ctx, event);
194 if (!JSObjectSetPrivate(object, static_cast<void*>(priv))) {
200 LogError("Error during replacing event object");
204 JSObjectRef JSCalendarItemProperties::createJSCalendarItemProperties(JSContextRef context, CalendarEventPtr item)
206 CalendarItemPropertiesPrivObject *priv = new CalendarItemPropertiesPrivObject(context, item);
207 return JSObjectMake(context, getClassRef(), priv);
210 JSValueRef JSCalendarItemProperties::convertToString(JSContextRef context,
212 JSObjectRef thisObject,
213 size_t argumentCount,
214 const JSValueRef arguments[],
215 JSValueRef* exception)
219 CalendarItemPropertiesPrivObject *privateObject =
220 static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(thisObject));
222 AceSecurityStatus status = CALENDAR_CHECK_ACCESS(CALENDAR_FUNCTION_API_CONVERT_TO_STRING);
224 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
228 if (!privateObject) {
229 ThrowMsg(ConversionException, "Object is null.");
232 CalendarEventPtr item = privateObject->getObject();
234 ThrowMsg(ConversionException, "Parameter conversion failed.");
237 CalendarConverter converter(context);
239 CalendarEvent::VObjectFormat format = CalendarEvent::UNDEFINED_FORMAT;
240 if (argumentCount>=1) {
241 format = converter.toVObjectFormat(converter.toString(arguments[0]));
243 ThrowMsg(ConversionException, "Wrong parameter type.");
246 ICalendarPtr calendar = CalendarFactory::getInstance().createCalendarObject();
247 calendar->setType(item->getCalendarType());
249 IEventExportEventToStringPtr dplEvent(new IEventExportEventToString());
250 dplEvent->setEvent(item);
251 dplEvent->setFormat(format);
252 dplEvent->setForSynchronousCall();
253 calendar->exportEventToString(dplEvent);
255 if (dplEvent->getResult()) {
256 return converter.toJSValueRef(dplEvent->getEventString());
258 ThrowMsg(UnknownException, "Converting to string failed by unknown reason.");
261 Catch(UnsupportedException)
263 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
264 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
266 Catch(InvalidArgumentException)
268 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
269 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
271 Catch(ConversionException)
273 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
274 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
276 Catch (NotFoundException)
278 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
279 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
283 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
284 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
287 return JSValueMakeUndefined(context);
290 JSValueRef JSCalendarItemProperties::clone(JSContextRef context,
292 JSObjectRef thisObject,
293 size_t argumentCount,
294 const JSValueRef arguments[],
295 JSValueRef* exception)
299 CalendarItemPropertiesPrivObject *privateObject =
300 static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(thisObject));
302 AceSecurityStatus status = CALENDAR_CHECK_ACCESS(CALENDAR_FUNCTION_API_CLONE);
304 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
308 if (!privateObject) {
309 ThrowMsg(ConversionException, "Object is null.");
312 CalendarEventPtr item = privateObject->getObject(); // item to copy
314 ThrowMsg(ConversionException, "Parameter conversion failed.");
316 JSContextRef globalContext = privateObject->getContext();
318 // Call the copy constructor.
319 CalendarEventPtr clonedItem( new CalendarEvent(*item));
322 clonedItem->resetId();
323 clonedItem->setRecurrenceId(0);
325 if (CalendarEvent::TASK_TYPE==clonedItem->getCalendarType()) {
326 return JSCalendarTask::createJSCalendarTask(context, clonedItem);
327 } else if (CalendarEvent::EVENT_TYPE==clonedItem->getCalendarType()) {
328 // Use global context for potential async api invocation.
329 return JSCalendarEvent::createJSCalendarEvent(globalContext, clonedItem);
331 ThrowMsg(ConversionException, "Wrong object type.");
334 Catch(UnsupportedException)
336 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
337 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
339 Catch(InvalidArgumentException)
341 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
342 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
344 Catch(ConversionException)
346 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
347 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
349 Catch (NotFoundException)
351 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
352 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
356 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
357 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
360 return JSValueMakeUndefined(context);
363 JSValueRef JSCalendarItemProperties::getPropertyDescription(JSContextRef context,
365 JSStringRef propertyName,
366 JSValueRef* exception)
371 Converter converter(context);
372 CalendarEventPtr event = getPrivateObject(object);
373 return converter.toJSValueRef(event->getDescription());
377 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
379 return JSValueMakeUndefined(context);
382 bool JSCalendarItemProperties::setPropertyDescription(JSContextRef context,
384 JSStringRef propertyName,
386 JSValueRef* exception)
391 Converter converter(context);
392 CalendarEventPtr event = getPrivateObject(object);
393 std::string description = converter.toString(value);
394 event->setDescription(description);
399 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
400 TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
406 JSValueRef JSCalendarItemProperties::getPropertySummary(JSContextRef context,
408 JSStringRef propertyName,
409 JSValueRef* exception)
414 Converter converter(context);
415 CalendarEventPtr event = getPrivateObject(object);
416 return converter.toJSValueRef(event->getSubject());
420 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
422 return JSValueMakeUndefined(context);
425 bool JSCalendarItemProperties::setPropertySummary(JSContextRef context,
427 JSStringRef propertyName,
429 JSValueRef* exception)
434 Converter converter(context);
435 CalendarEventPtr event = getPrivateObject(object);
436 std::string subject = converter.toString(value);
437 event->setSubject(subject);
442 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
443 TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
449 JSValueRef JSCalendarItemProperties::getPropertyStartTime(JSContextRef context,
451 JSStringRef propertyName,
452 JSValueRef* exception)
457 CalendarItemPropertiesPrivObject *privateObject =
458 static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(object));
459 TimeUtilConverter timeConverter(context);
460 CalendarEventPtr event = privateObject->getObject();
462 LogInfo("start time before converted to TZDate: "<<event->getStartTime()<<", time zone: "<<event->getTimeZone());
463 if (UNDEFINED_TIME==event->getStartTime()) {
464 return JSValueMakeUndefined(context);
466 return timeConverter.toJSValueRefTZDate((double)(event->getStartTime()*1000.0), event->getTimeZone());
471 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
473 return JSValueMakeUndefined(context);
476 bool JSCalendarItemProperties::setPropertyStartTime(JSContextRef context,
478 JSStringRef propertyName,
480 JSValueRef* exception)
485 if (!JSValueIsObjectOfClass(context, value, JSTZDate::getClassRef())) {
486 ThrowMsg(ConversionException, "Wrong parameter type.");
489 CalendarEventPtr event = getPrivateObject(object);
490 TimeUtilConverter converter(context);
491 std::time_t duration = event->getEndTime() - event->getStartTime();
496 long long int startTime = (long long int) (converter.getTimeInMilliseconds(value)/1000);
497 event->setStartTime(startTime);
498 event->setEndTime(startTime + duration);
500 std::string timeZone = converter.getPropertiesInTZDate(value).timezone;
501 event->setTimeZone(timeZone);
506 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
507 TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
513 JSValueRef JSCalendarItemProperties::getPropertyLocation(JSContextRef context,
515 JSStringRef propertyName,
516 JSValueRef* exception)
521 Converter converter(context);
522 CalendarEventPtr event = getPrivateObject(object);
523 return converter.toJSValueRef(event->getLocation());
527 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
529 return JSValueMakeUndefined(context);
532 bool JSCalendarItemProperties::setPropertyLocation(JSContextRef context,
534 JSStringRef propertyName,
536 JSValueRef* exception)
541 Converter converter(context);
542 CalendarEventPtr event = getPrivateObject(object);
543 std::string location = converter.toString(value);
544 event->setLocation(location);
549 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
550 TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
556 JSValueRef JSCalendarItemProperties::getPropertyCategories(JSContextRef context,
558 JSStringRef propertyName,
559 JSValueRef* exception)
564 CalendarConverter converter(context);
565 CalendarEventPtr event = getPrivateObject(object);
566 StringArrayPtr categories = event->getCategories();
568 return converter.toJSValueRef(categories);
573 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
575 return JSValueMakeUndefined(context);
578 bool JSCalendarItemProperties::setPropertyCategories(JSContextRef context,
580 JSStringRef propertyName,
582 JSValueRef* exception)
587 CalendarEventPtr event = getPrivateObject(object);
588 CalendarConverter converter(context);
589 event->setCategories(converter.toStringArray(value));
594 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
595 TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
601 JSValueRef JSCalendarItemProperties::getPropertyStatus(JSContextRef context,
603 JSStringRef propertyName,
604 JSValueRef* exception)
609 CalendarConverter converter(context);
610 CalendarEventPtr event = getPrivateObject(object);
611 std::string status = converter.toTizenValue(event->getStatus());
612 return converter.toJSValueRef(status);
616 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
618 return JSValueMakeUndefined(context);
621 bool JSCalendarItemProperties::setPropertyStatus(JSContextRef context,
623 JSStringRef propertyName,
625 JSValueRef* exception)
628 CalendarEventPtr event(NULL);
631 event = getPrivateObject(object);
632 CalendarConverter converter(context);
633 CalendarEvent::EventStatus status =
634 converter.toEventStatus(converter.toString(value));
635 event->setStatus(status);
640 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
641 TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
647 JSValueRef JSCalendarItemProperties::getPropertyAlarms(JSContextRef context,
649 JSStringRef propertyName,
650 JSValueRef* exception)
655 CalendarEventPtr event = getPrivateObject(object);
657 JSObjectRef jsResult = JSCreateArrayObject(context, 0, NULL);
658 if (NULL == jsResult) {
659 ThrowMsg(NullPointerException, "Can not create array object.");
661 for( unsigned int i=0; i<event->getAlarms()->size(); i++) {
662 if (!JSSetArrayElement(context, jsResult, i, JSCalendarAlarm::createJSCalendarAlarm(context, event->getAlarms()->at(i)))) {
663 ThrowMsg(UnknownException, "Can not insert value into array.");
670 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
672 return JSValueMakeUndefined(context);
675 bool JSCalendarItemProperties::setPropertyAlarms(JSContextRef context,
677 JSStringRef propertyName,
679 JSValueRef* exception)
682 CalendarEventPtr event(NULL);
685 event = getPrivateObject(object);
686 CalendarConverter converter(context);
688 EventAlarmListPtr alarms = converter.toVectorOfEventAlarmsFromReference(value);
690 event->setAlarms(alarms);
695 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
696 TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
702 JSValueRef JSCalendarItemProperties::getPropertyOrganizer(JSContextRef context,
704 JSStringRef propertyName,
705 JSValueRef* exception)
710 Converter converter(context);
711 CalendarEventPtr event = getPrivateObject(object);
712 return converter.toJSValueRef(event->getOrganizer());
716 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
718 return JSValueMakeUndefined(context);
721 bool JSCalendarItemProperties::setPropertyOrganizer(JSContextRef context,
723 JSStringRef propertyName,
725 JSValueRef* exception)
730 Converter converter(context);
731 CalendarEventPtr event = getPrivateObject(object);
732 std::string organizer = converter.toString(value);
733 event->setOrganizer(organizer);
738 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
739 TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
745 JSValueRef JSCalendarItemProperties::getPropertyVisibility(JSContextRef context,
747 JSStringRef propertyName,
748 JSValueRef* exception)
753 CalendarConverter converter(context);
754 CalendarEventPtr event = getPrivateObject(object);
755 std::string visibility = converter.toTizenValue(event->getVisibility());
756 return converter.toJSValueRef(visibility);
760 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
762 return JSValueMakeUndefined(context);
765 bool JSCalendarItemProperties::setPropertyVisibility(JSContextRef context,
767 JSStringRef propertyName,
769 JSValueRef* exception)
772 CalendarEventPtr event(NULL);
775 event = getPrivateObject(object);
776 CalendarConverter converter(context);
777 CalendarEvent::EventVisibility visibility =
778 converter.toEventVisibility(converter.toString(value));
779 event->setVisibility(visibility);
784 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
785 TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
791 JSValueRef JSCalendarItemProperties::getPropertyGeolocation(JSContextRef context,
793 JSStringRef propertyName,
794 JSValueRef* exception)
799 CalendarEventPtr event = getPrivateObject(object);
800 TizenApis::Api::Tizen::SimpleCoordinatesPtr geoLocation(
801 new TizenApis::Api::Tizen::SimpleCoordinates(event->getLatitude(), event->getLongitude()) );
803 return TizenApis::Tizen1_0::Tizen::JSSimpleCoordinates::createJSObject(context, geoLocation);
807 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
810 return JSValueMakeUndefined(context);
813 bool JSCalendarItemProperties::setPropertyGeolocation(JSContextRef context,
815 JSStringRef propertyName,
817 JSValueRef* exception)
822 CalendarEventPtr event = getPrivateObject(object);
823 TizenApis::Api::Tizen::SimpleCoordinatesPtr geoLocation =
824 TizenApis::Tizen1_0::Tizen::JSSimpleCoordinates::getSimpleCoordinates(context, value);
826 event->setLatitude(geoLocation->getLatitude());
827 event->setLongitude(geoLocation->getLongitude());
832 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
833 TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
839 JSValueRef JSCalendarItemProperties::getPropertyDuration(JSContextRef context,
841 JSStringRef propertyName,
842 JSValueRef* exception)
847 CalendarEventPtr event = getPrivateObject(object);
849 TimeUtilConverter converter(context);
850 long length = event->getEndTime() - event->getStartTime(); // in seconds only
851 LogDebug("event->getStartTime():"<< event->getStartTime() << ", length:" << length);
852 return converter.makeMillisecondDurationObject( length*1000 );
856 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
858 return JSValueMakeUndefined(context);
861 bool JSCalendarItemProperties::setPropertyDuration(JSContextRef context,
863 JSStringRef propertyName,
865 JSValueRef* exception)
870 CalendarEventPtr event = getPrivateObject(object);
871 TimeUtilConverter converter(context);
872 long length = converter.getDurationLength(value);
873 int unit = converter.getDurationUnit(value);
875 TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::INVALID_VALUES_ERROR);
878 if( SECONDS_UNIT==unit ) {
879 event->setEndTime(event->getStartTime() + length);
880 } else if ( MINUTES_UNIT==unit ) {
881 event->setEndTime(event->getStartTime() + length*60);
882 } else if ( HOURS_UNIT==unit ) {
883 event->setEndTime(event->getStartTime() + length*60*60);
884 } else if ( DAYS_UNIT==unit ) {
885 event->setEndTime(event->getStartTime() + length*24*60*60);
886 } else if ( MSECS_UNIT==unit ) {
887 event->setEndTime(event->getStartTime() + length/1000);
889 TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::INVALID_VALUES_ERROR);
897 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
898 TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
904 JSValueRef JSCalendarItemProperties::getPropertyRecurrenceRule(JSContextRef context,
906 JSStringRef propertyName,
907 JSValueRef* exception)
912 CalendarItemPropertiesPrivObject *priv =
913 static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(object));
915 CalendarEventPtr event = getPrivateObject(object);
916 EventRecurrenceRulePtr rrule;
917 if (event->getIsDetached()) {
918 LogDebug("This is a detached event.");
919 return JSValueMakeUndefined(context);
921 rrule = event->getRecurrenceRule();
924 if (EventRecurrenceRule::NO_RECURRENCE==rrule->getFrequency()) {
925 return JSValueMakeUndefined(context);
927 return JSCalendarRecurrenceRule::createJSCalendarRecurrenceRule(priv->getContext(), rrule);
932 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
934 return JSValueMakeUndefined(context);
937 bool JSCalendarItemProperties::setPropertyRecurrenceRule(JSContextRef context,
939 JSStringRef propertyName,
941 JSValueRef* exception)
944 CalendarEventPtr event(NULL);
947 event = getPrivateObject(object);
948 if (event->getIsDetached()) {
949 LogWarning("Can't set the recurrenceRule of a detached event!");
950 TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::NOT_SUPPORTED_ERROR);
952 event->setRecurrenceRule(JSCalendarRecurrenceRule::getPrivateObject(JSValueToObject(context, value, NULL)));
957 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
958 TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
964 JSValueRef JSCalendarItemProperties::getPropertyIsAllDay(JSContextRef context,
966 JSStringRef propertyName,
967 JSValueRef* exception)
972 CalendarConverter converter(context);
973 CalendarEventPtr event = getPrivateObject(object);
974 return converter.toJSValueRef(event->getIsAllDay());
978 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
980 return JSValueMakeUndefined(context);
983 bool JSCalendarItemProperties::setPropertyIsAllDay(JSContextRef context,
985 JSStringRef propertyName,
987 JSValueRef* exception)
991 CalendarEventPtr event = getPrivateObject(object);
992 Converter converter(context);
993 event->setIsAllDay(converter.toBool(value));
998 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
999 TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
1005 JSValueRef JSCalendarItemProperties::getPropertyAvailability(JSContextRef context,
1007 JSStringRef propertyName,
1008 JSValueRef* exception)
1010 LogDebug("entered");
1013 CalendarConverter converter(context);
1014 CalendarEventPtr event = getPrivateObject(object);
1015 std::string availability = converter.toTizenValue(event->getAvailability());
1016 return converter.toJSValueRef(availability);
1020 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
1022 return JSValueMakeUndefined(context);
1025 bool JSCalendarItemProperties::setPropertyAvailability(JSContextRef context,
1027 JSStringRef propertyName,
1029 JSValueRef* exception)
1031 LogDebug("entered");
1032 CalendarEventPtr event(NULL);
1035 event = getPrivateObject(object);
1036 CalendarConverter converter(context);
1037 CalendarEvent::EventAvailability availability =
1038 converter.toEventAvailability(converter.toString(value));
1039 event->setAvailability(availability);
1044 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
1045 TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
1051 JSValueRef JSCalendarItemProperties::getPropertyAttendees(JSContextRef context,
1053 JSStringRef propertyName,
1054 JSValueRef* exception)
1056 LogDebug("entered");
1059 CalendarEventPtr event = getPrivateObject(object);
1060 EventAttendeeListPtr attendees = event->getAttendees();
1062 JSObjectRef jsResult = JSCreateArrayObject(context, 0, NULL);
1063 if (NULL == jsResult) {
1064 ThrowMsg(NullPointerException, "Can not create array object.");
1066 for(unsigned int i=0; i<attendees->size(); i++) {
1067 if (!JSSetArrayElement(context, jsResult, i, JSCalendarAttendee::createJSCalendarAttendee(context, attendees->at(i)))) {
1068 ThrowMsg(UnknownException, "Can not insert value into array.");
1076 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
1078 return JSValueMakeUndefined(context);
1081 bool JSCalendarItemProperties::setPropertyAttendees(JSContextRef context,
1083 JSStringRef propertyName,
1085 JSValueRef* exception)
1087 LogDebug("entered");
1090 CalendarEventPtr event = getPrivateObject(object);
1091 CalendarConverter converter(context);
1092 event->setAttendees(converter.toVectorOfAttendeesFromReference(value));
1097 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
1098 TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
1104 JSValueRef JSCalendarItemProperties::getPropertyDueDate(JSContextRef context,
1106 JSStringRef propertyName,
1107 JSValueRef* exception)
1109 LogDebug("entered");
1112 CalendarItemPropertiesPrivObject *privateObject =
1113 static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(object));
1114 CalendarEventPtr task = privateObject->getObject();
1115 if(CalendarEvent::TASK_TYPE != task->getCalendarType()) {
1116 return JSValueMakeUndefined(context);
1119 ThrowMsg(NullPointerException, "Task object is NULL.");
1122 if (UNDEFINED_TIME==task->getEndTime()) {
1123 return JSValueMakeUndefined(context);
1125 TimeUtilConverter timeConverter(context);
1126 return timeConverter.toJSValueRefTZDate((double)(task->getEndTime()*1000.0), task->getTimeZone());
1131 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
1133 return JSValueMakeUndefined(context);
1136 bool JSCalendarItemProperties::setPropertyDueDate(JSContextRef context,
1138 JSStringRef propertyName,
1140 JSValueRef* exception)
1142 LogDebug("entered");
1145 CalendarEventPtr task = getPrivateObject(object);
1147 ThrowMsg(NullPointerException, "Task object is NULL.");
1149 if(CalendarEvent::TASK_TYPE != task->getCalendarType()) {
1150 ThrowMsg(InvalidArgumentException, "Wrong type of calendar.");
1152 if (!JSValueIsObjectOfClass(context, value, JSTZDate::getClassRef())) {
1153 ThrowMsg(ConversionException, "Wrong parameter type.");
1156 TimeUtilConverter converter(context);
1157 long long int dueDate = (long long int) (converter.getTimeInMilliseconds(value)/1000);
1159 task->setEndTime(dueDate);
1161 if( task->getTimeZone().empty() ) {
1162 std::string timeZone = converter.getPropertiesInTZDate(value).timezone;
1163 task->setTimeZone(timeZone);
1169 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
1170 TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
1176 JSValueRef JSCalendarItemProperties::getPropertyCompletedDate(JSContextRef context,
1178 JSStringRef propertyName,
1179 JSValueRef* exception)
1181 LogDebug("entered");
1184 CalendarItemPropertiesPrivObject *privateObject =
1185 static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(object));
1186 CalendarEventPtr task = privateObject->getObject();
1187 if(CalendarEvent::TASK_TYPE != task->getCalendarType()) {
1188 return JSValueMakeUndefined(context);
1191 ThrowMsg(NullPointerException, "Task object is NULL.");
1194 if (UNDEFINED_TIME==task->getCompletedDate()) {
1195 return JSValueMakeUndefined(context);
1197 TimeUtilConverter timeConverter(context);
1198 return timeConverter.toJSValueRefTZDate((double)(task->getCompletedDate()*1000.0), task->getTimeZone());
1203 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
1205 return JSValueMakeUndefined(context);
1208 bool JSCalendarItemProperties::setPropertyCompletedDate(JSContextRef context,
1210 JSStringRef propertyName,
1212 JSValueRef* exception)
1214 LogDebug("entered");
1217 CalendarEventPtr task = getPrivateObject(object);
1219 ThrowMsg(NullPointerException, "Task object is NULL.");
1221 if(CalendarEvent::TASK_TYPE != task->getCalendarType()) {
1222 ThrowMsg(InvalidArgumentException, "Wrong calendar type.");
1224 if (!JSValueIsObjectOfClass(context, value, JSTZDate::getClassRef())) {
1225 ThrowMsg(ConversionException, "Wrong parameter type.");
1228 TimeUtilConverter converter(context);
1229 long long int completedDate = (long long int) (converter.getTimeInMilliseconds(value)/1000);
1231 task->setCompletedDate(completedDate);
1233 if( task->getTimeZone().empty() ) {
1234 std::string timeZone = converter.getPropertiesInTZDate(value).timezone;
1235 task->setTimeZone(timeZone);
1241 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
1242 TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
1248 JSValueRef JSCalendarItemProperties::getPropertyProgress(JSContextRef context,
1250 JSStringRef propertyName,
1251 JSValueRef* exception)
1253 LogDebug("entered");
1256 CalendarEventPtr task = getPrivateObject(object);
1257 if(CalendarEvent::TASK_TYPE != task->getCalendarType()) {
1258 return JSValueMakeUndefined(context);
1261 Converter converter(context);
1262 return converter.toJSValueRef(task->getProgress());
1266 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
1268 return JSValueMakeUndefined(context);
1271 bool JSCalendarItemProperties::setPropertyProgress(JSContextRef context,
1273 JSStringRef propertyName,
1275 JSValueRef* exception)
1277 LogDebug("entered");
1280 CalendarEventPtr task = getPrivateObject(object);
1281 if(CalendarEvent::TASK_TYPE != task->getCalendarType()) {
1282 return JSValueMakeUndefined(context);
1285 Converter converter(context);
1286 int progress = converter.toInt(value);
1287 task->setProgress(progress);
1292 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
1293 TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
1299 JSValueRef JSCalendarItemProperties::getPropertyPriority(JSContextRef context,
1301 JSStringRef propertyName,
1302 JSValueRef* exception)
1304 LogDebug("entered");
1307 CalendarConverter converter(context);
1308 CalendarEventPtr item = getPrivateObject(object);
1310 ThrowMsg(NullPointerException, "Item object is NULL.");
1313 std::string priority = converter.toTizenValue(item->getPriority());
1314 return converter.toJSValueRef(priority);
1318 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
1320 return JSValueMakeUndefined(context);
1323 bool JSCalendarItemProperties::setPropertyPriority(JSContextRef context,
1325 JSStringRef propertyName,
1327 JSValueRef* exception)
1329 LogDebug("entered");
1330 CalendarEventPtr item = getPrivateObject(object);
1333 CalendarConverter converter(context);
1334 CalendarEvent::TaskPriority priority =
1335 converter.toTaskPriority(converter.toString(value));
1336 item->setPriority(priority);
1341 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
1342 TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
1348 JSValueRef JSCalendarItemProperties::getPropertyEndDate(JSContextRef context,
1350 JSStringRef propertyName,
1351 JSValueRef* exception)
1353 LogDebug("entered");
1356 CalendarItemPropertiesPrivObject *privateObject =
1357 static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(object));
1358 CalendarEventPtr event = privateObject->getObject();
1359 if(CalendarEvent::EVENT_TYPE != event->getCalendarType()) {
1360 return JSValueMakeUndefined(context);
1363 ThrowMsg(NullPointerException, "Event object is NULL.");
1366 if (UNDEFINED_TIME==event->getEndTime()) {
1367 return JSValueMakeUndefined(context);
1369 TimeUtilConverter timeConverter(context);
1370 return timeConverter.toJSValueRefTZDate((double)(event->getEndTime()*1000.0), event->getTimeZone());
1375 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
1377 return JSValueMakeUndefined(context);
1380 bool JSCalendarItemProperties::setPropertyEndDate(JSContextRef context,
1382 JSStringRef propertyName,
1384 JSValueRef* exception)
1386 LogDebug("entered");
1389 CalendarEventPtr event = getPrivateObject(object);
1391 ThrowMsg(NullPointerException, "Event object is NULL.");
1393 if(CalendarEvent::EVENT_TYPE != event->getCalendarType()) {
1394 ThrowMsg(InvalidArgumentException, "Wrong calendar type.");
1396 if (!JSValueIsObjectOfClass(context, value, JSTZDate::getClassRef())) {
1397 ThrowMsg(ConversionException, "Wrong parameter type.");
1400 TimeUtilConverter converter(context);
1401 long long int endDate = (long long int) (converter.getTimeInMilliseconds(value)/1000);
1403 event->setEndTime(endDate);
1405 if( event->getTimeZone().empty() ) {
1406 std::string timeZone = converter.getPropertiesInTZDate(value).timezone;
1407 event->setTimeZone(timeZone);
1413 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
1414 TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
1420 bool JSCalendarItemProperties::validate(JSContextRef ctx,
1421 const JSObjectRef object,
1422 JSValueRef* exception)
1424 LogDebug("entered");
1425 CalendarItemPropertiesPrivObject *priv =
1426 static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(object));
1430 CalendarEventPtr event = priv->getObject();
1434 return event->validate();