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 <API/Calendar/EventAlarm.h>
29 #include <API/Calendar/EventId.h>
30 #include <API/Calendar/ICalendar.h>
31 #include <API/Calendar/CalendarFactory.h>
32 #include "API/TimeUtil/DurationProperties.h"
33 #include "JSCalendarItemProperties.h"
34 #include "CalendarConverter.h"
35 #include "JSCalendarEventId.h"
36 #include "JSCalendarAlarm.h"
37 #include "JSCalendarRecurrenceRule.h"
38 #include "JSCalendarAttendee.h"
39 #include "JSCalendarItemGeo.h"
40 #include "JSCalendarItem.h"
41 #include "plugin_config.h"
43 using namespace TizenApis::Api::Calendar;
44 using namespace WrtDeviceApis::Commons;
45 using namespace WrtDeviceApis::CommonsJavaScript;
46 using namespace TizenApis::Commons;
52 #define TIZEN_CALENDAR_ITEM_PROPERTIES_ATTRIBUTENAME "CalendarItemProperties"
54 JSClassDefinition JSCalendarItemProperties::m_classInfo = {
56 kJSClassAttributeNone,
57 TIZEN_CALENDAR_ITEM_PROPERTIES_ATTRIBUTENAME,
66 NULL, //DeleteProperty,
67 NULL, //GetPropertyNames,
68 NULL, //CallAsFunction,
69 NULL, //CallAsConstructor,
74 JSStaticValue JSCalendarItemProperties::m_property[] = {
76 { TIZEN_CALENDAR_ITEM_DESCRIPTION, getPropertyDescription,
77 setPropertyDescription, kJSPropertyAttributeNone },
78 { TIZEN_CALENDAR_ITEM_SUMMARY, getPropertySummary,
79 setPropertySummary, kJSPropertyAttributeNone },
80 { TIZEN_CALENDAR_ITEM_START_DATE, getPropertyStartTime,
81 setPropertyStartTime, kJSPropertyAttributeNone },
82 { TIZEN_CALENDAR_ITEM_LOCATION, getPropertyLocation,
83 setPropertyLocation, kJSPropertyAttributeNone },
84 { TIZEN_CALENDAR_ITEM_GEOLOCATION, getPropertyGeolocation,
85 setPropertyGeolocation, kJSPropertyAttributeNone },
86 { TIZEN_CALENDAR_ITEM_ORGANIZER, getPropertyOrganizer,
87 setPropertyOrganizer, kJSPropertyAttributeNone },
88 { TIZEN_CALENDAR_ITEM_VISIBILITY, getPropertyVisibility,
89 setPropertyVisibility, kJSPropertyAttributeNone },
90 { TIZEN_CALENDAR_ITEM_STATUS, getPropertyStatus,
91 setPropertyStatus, kJSPropertyAttributeNone },
92 { TIZEN_CALENDAR_ITEM_ALARMS, getPropertyAlarms,
93 setPropertyAlarms, kJSPropertyAttributeNone },
94 { TIZEN_CALENDAR_ITEM_CATEGORIES, getPropertyCategories,
95 setPropertyCategories, kJSPropertyAttributeNone },
96 { TIZEN_CALENDAR_ITEM_DURATION, getPropertyDuration,
97 setPropertyDuration, kJSPropertyAttributeNone },
98 { TIZEN_CALENDAR_ITEM_IS_ALL_DAY, getPropertyIsAllDay,
99 setPropertyIsAllDay, kJSPropertyAttributeNone },
100 { TIZEN_CALENDAR_ITEM_ATTENDEES, getPropertyAttendees,
101 setPropertyAttendees, kJSPropertyAttributeNone },
102 { TIZEN_CALENDAR_EVENT_RECURRENCE_RULE, getPropertyRecurrenceRule,
103 setPropertyRecurrenceRule, kJSPropertyAttributeNone },
104 { TIZEN_CALENDAR_EVENT_AVAILABILITY, getPropertyAvailability,
105 setPropertyAvailability, kJSPropertyAttributeNone },
106 { TIZEN_CALENDAR_TASK_DUE_DATE, getPropertyDueDate,
107 setPropertyDueDate, kJSPropertyAttributeNone },
108 { TIZEN_CALENDAR_TASK_COMPLETED_DATE, getPropertyCompletedDate,
109 setPropertyCompletedDate, kJSPropertyAttributeNone },
110 { TIZEN_CALENDAR_TASK_PROGRESS, getPropertyProgress,
111 setPropertyProgress, kJSPropertyAttributeNone },
112 { TIZEN_CALENDAR_ITEM_PRIORITY, getPropertyPriority,
113 setPropertyPriority, kJSPropertyAttributeNone },
114 { TIZEN_CALENDAR_EVENT_END_DATE, getPropertyEndDate,
115 setPropertyEndDate, kJSPropertyAttributeNone },
120 JSStaticFunction JSCalendarItemProperties::m_function[] = {
121 { CALENDAR_FUNCTION_API_CONVERT_TO_STRING, convertToString, kJSPropertyAttributeNone },
122 { CALENDAR_FUNCTION_API_CLONE, clone, kJSPropertyAttributeNone },
127 JSClassRef JSCalendarItemProperties::m_jsClassRef = JSClassCreate(JSCalendarItemProperties::getClassInfo());
129 void JSCalendarItemProperties::initialize(JSContextRef context,
133 CalendarItemPropertiesPrivObject *priv =
134 static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(object));
136 CalendarEventPtr privateData(new CalendarEvent());
137 priv = new CalendarItemPropertiesPrivObject(context, privateData);
138 JSObjectSetPrivate(object, static_cast<void*>(priv));
139 LogDebug("New CalendarItemPropertiesPrivObject is created.");
141 LogDebug("CalendarItemPropertiesPrivObject already exists.");
145 void JSCalendarItemProperties::finalize(JSObjectRef object)
148 CalendarItemPropertiesPrivObject *priv =
149 static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(object));
153 const JSClassRef JSCalendarItemProperties::getClassRef()
156 m_jsClassRef = JSClassCreate(&m_classInfo);
161 const JSClassDefinition* JSCalendarItemProperties::getClassInfo()
166 CalendarEventPtr JSCalendarItemProperties::getPrivateObject(JSObjectRef object)
169 CalendarItemPropertiesPrivObject *priv =
170 static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(object));
172 ThrowMsg(NullPointerException, "Private object is null");
174 CalendarEventPtr result = priv->getObject();
176 ThrowMsg(NullPointerException, "Private object is null");
181 void JSCalendarItemProperties::setPrivateObject(const CalendarEventPtr &event,
183 const JSObjectRef object)
188 CalendarItemPropertiesPrivObject *priv =
189 static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(object));
191 priv = new CalendarItemPropertiesPrivObject(ctx, event);
192 if (!JSObjectSetPrivate(object, static_cast<void*>(priv))) {
198 LogError("Error during replacing event object");
202 JSObjectRef JSCalendarItemProperties::createJSCalendarItemProperties(JSContextRef context, CalendarEventPtr item)
204 CalendarItemPropertiesPrivObject *priv = new CalendarItemPropertiesPrivObject(context, item);
205 return JSObjectMake(context, getClassRef(), priv);
208 JSValueRef JSCalendarItemProperties::convertToString(JSContextRef context,
210 JSObjectRef thisObject,
211 size_t argumentCount,
212 const JSValueRef arguments[],
213 JSValueRef* exception)
217 CalendarItemPropertiesPrivObject *privateObject =
218 static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(thisObject));
219 assert(privateObject);
221 AceSecurityStatus status = CALENDAR_CHECK_ACCESS(privateObject->getContext(),
222 CALENDAR_FUNCTION_API_CONVERT_TO_STRING);
224 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
228 CalendarEventPtr item = privateObject->getObject();
230 ThrowMsg(ConversionException, "Parameter conversion failed.");
233 if (argumentCount!=1) {
234 ThrowMsg(InvalidArgumentException, "Wrong number of parameters.");
237 if (!JSValueIsString(context, arguments[0])) {
238 ThrowMsg(ConversionException, "Wrong parameter type.");
241 CalendarEvent::VObjectFormat format = CalendarEvent::ICALENDAR_20;
242 CalendarConverter converter(context);
243 format = converter.toVObjectFormat(converter.toString(arguments[0]));
245 ICalendarPtr calendar = CalendarFactory::getInstance().createCalendarObject();
246 calendar->setType(item->getCalendarType());
248 IEventExportEventToStringPtr dplEvent(new IEventExportEventToString());
249 dplEvent->setEvent(item);
250 dplEvent->setFormat(format);
251 dplEvent->setForSynchronousCall();
252 calendar->exportEventToString(dplEvent);
254 if (dplEvent->getResult()) {
255 return converter.toJSValueRef(dplEvent->getEventString());
257 ThrowMsg(UnknownException, "Converting to string failed by unkown reason.");
260 Catch(UnsupportedException)
262 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
263 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
265 Catch(InvalidArgumentException)
267 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
268 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
270 Catch(ConversionException)
272 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
273 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
275 Catch (NotFoundException)
277 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
278 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
282 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
283 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
286 return JSValueMakeUndefined(context);
289 JSValueRef JSCalendarItemProperties::clone(JSContextRef context,
291 JSObjectRef thisObject,
292 size_t argumentCount,
293 const JSValueRef arguments[],
294 JSValueRef* exception)
298 CalendarItemPropertiesPrivObject *privateObject =
299 static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(thisObject));
300 assert(privateObject);
302 AceSecurityStatus status = CALENDAR_CHECK_ACCESS(privateObject->getContext(),
303 CALENDAR_FUNCTION_API_CLONE);
305 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
309 CalendarEventPtr item = privateObject->getObject(); // item to copy
311 ThrowMsg(ConversionException, "Parameter conversion failed.");
314 JSContextRef globalContext = privateObject->getContext();
316 if (argumentCount>0) {
317 ThrowMsg(InvalidArgumentException, "Wrong number of parameters.");
320 // Call the copy constructor.
321 CalendarEventPtr clonedItem( new CalendarEvent(*item));
324 clonedItem->resetId();
325 clonedItem->setRecurrenceId(0);
327 return JSCalendarItem::createJSCalendarItem(globalContext, clonedItem);
329 Catch(UnsupportedException)
331 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
332 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
334 Catch(InvalidArgumentException)
336 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
337 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
339 Catch(ConversionException)
341 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
342 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
344 Catch (NotFoundException)
346 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
347 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
351 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
352 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
355 return JSValueMakeUndefined(context);
358 JSValueRef JSCalendarItemProperties::getPropertyDescription(JSContextRef context,
360 JSStringRef propertyName,
361 JSValueRef* exception)
366 Converter converter(context);
367 CalendarEventPtr event = getPrivateObject(object);
368 return converter.toJSValueRef(event->getDescription());
372 LogWarning("trying to get incorrect value");
374 return JSValueMakeUndefined(context);
377 bool JSCalendarItemProperties::setPropertyDescription(JSContextRef context,
379 JSStringRef propertyName,
381 JSValueRef* exception)
386 if (!JSValueIsString(context, value)) {
387 Throw(InvalidArgumentException);
390 Converter converter(context);
391 CalendarEventPtr event = getPrivateObject(object);
392 std::string description = converter.toString(value);
393 event->setDescription(description);
398 LogWarning("trying to set incorrect value");
399 TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
405 JSValueRef JSCalendarItemProperties::getPropertySummary(JSContextRef context,
407 JSStringRef propertyName,
408 JSValueRef* exception)
413 Converter converter(context);
414 CalendarEventPtr event = getPrivateObject(object);
415 return converter.toJSValueRef(event->getSubject());
419 LogWarning("trying to get incorrect value");
421 return JSValueMakeUndefined(context);
424 bool JSCalendarItemProperties::setPropertySummary(JSContextRef context,
426 JSStringRef propertyName,
428 JSValueRef* exception)
433 if (!JSValueIsString(context, value)) {
434 Throw(InvalidArgumentException);
437 Converter converter(context);
438 CalendarEventPtr event = getPrivateObject(object);
439 std::string subject = converter.toString(value);
440 event->setSubject(subject);
445 LogWarning("trying to set incorrect value");
446 TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
452 JSValueRef JSCalendarItemProperties::getPropertyStartTime(JSContextRef context,
454 JSStringRef propertyName,
455 JSValueRef* exception)
460 CalendarItemPropertiesPrivObject *privateObject =
461 static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(object));
462 TimeUtilConverter timeConverter(privateObject->getContext());
463 CalendarEventPtr event = privateObject->getObject();
465 LogInfo("start time before converted to TZDate: "<<event->getStartTime()<<", time zone: "<<event->getTimeZone());
466 return timeConverter.FromUTCTimeTToTZDate(event->getStartTime(), event->getTimeZone());
470 LogWarning("trying to get incorrect value");
472 return JSValueMakeUndefined(context);
475 bool JSCalendarItemProperties::setPropertyStartTime(JSContextRef context,
477 JSStringRef propertyName,
479 JSValueRef* exception)
484 if (!JSValueIsObjectOfClass(context, value, JSTZDate::getClassRef())) {
485 Throw(InvalidArgumentException);
488 CalendarEventPtr event = getPrivateObject(object);
489 TimeUtilConverter converter(context);
490 std::time_t duration = event->getEndTime() - event->getStartTime();
495 std::time_t startTime = converter.toTZDateTimeT(value);
496 event->setStartTime(startTime);
497 event->setEndTime(startTime + duration);
499 std::string timeZone = converter.getPropertiesInTZDate(value).timezone;
500 event->setTimeZone(timeZone);
505 LogWarning("trying to set incorrect value");
506 TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
512 JSValueRef JSCalendarItemProperties::getPropertyLocation(JSContextRef context,
514 JSStringRef propertyName,
515 JSValueRef* exception)
520 Converter converter(context);
521 CalendarEventPtr event = getPrivateObject(object);
522 return converter.toJSValueRef(event->getLocation());
526 LogWarning("trying to get incorrect value");
528 return JSValueMakeUndefined(context);
531 bool JSCalendarItemProperties::setPropertyLocation(JSContextRef context,
533 JSStringRef propertyName,
535 JSValueRef* exception)
540 if (!JSValueIsString(context, value)) {
541 Throw(InvalidArgumentException);
544 Converter converter(context);
545 CalendarEventPtr event = getPrivateObject(object);
546 std::string location = converter.toString(value);
547 event->setLocation(location);
552 LogWarning("trying to set incorrect value");
553 TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
559 JSValueRef JSCalendarItemProperties::getPropertyCategories(JSContextRef context,
561 JSStringRef propertyName,
562 JSValueRef* exception)
567 Converter converter(context);
568 CalendarEventPtr event = getPrivateObject(object);
569 CategoryListPtr categories = event->getCategories();
571 return converter.toJSValueRef(*categories);
576 LogWarning("trying to get incorrect value");
578 return JSValueMakeUndefined(context);
581 bool JSCalendarItemProperties::setPropertyCategories(JSContextRef context,
583 JSStringRef propertyName,
585 JSValueRef* exception)
590 CalendarEventPtr event = getPrivateObject(object);
591 CalendarConverterFactory::ConverterType converter =
592 CalendarConverterFactory::getConverter(context);
593 event->setCategories(converter->toCategories(value));
598 LogWarning("trying to set incorrect value");
599 TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
605 JSValueRef JSCalendarItemProperties::getPropertyStatus(JSContextRef context,
607 JSStringRef propertyName,
608 JSValueRef* exception)
613 CalendarConverterFactory::ConverterType converter =
614 CalendarConverterFactory::getConverter(context);
615 CalendarEventPtr event = getPrivateObject(object);
616 std::string status = converter->toTizenValue(event->getStatus());
617 return converter->toJSValueRef(status);
621 LogWarning("trying to get incorrect value");
623 return JSValueMakeUndefined(context);
626 bool JSCalendarItemProperties::setPropertyStatus(JSContextRef context,
628 JSStringRef propertyName,
630 JSValueRef* exception)
633 CalendarEventPtr event(NULL);
636 if (!JSValueIsString(context, value)) {
637 Throw(InvalidArgumentException);
640 event = getPrivateObject(object);
641 CalendarConverterFactory::ConverterType converter =
642 CalendarConverterFactory::getConverter(context);
643 CalendarEvent::EventStatus status =
644 converter->toEventStatus(converter->toString(value));
645 event->setStatus(status);
650 LogWarning("trying to set incorrect value");
651 event->setStatus(CalendarEvent::INVALID_STATUS);
652 TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
658 JSValueRef JSCalendarItemProperties::getPropertyAlarms(JSContextRef context,
660 JSStringRef propertyName,
661 JSValueRef* exception)
666 CalendarItemPropertiesPrivObject *priv =
667 static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(object));
669 CalendarEventPtr event = getPrivateObject(object);
671 JSObjectRef jsResult = JSCreateArrayObject(priv->getContext(), 0, NULL);
672 if (NULL == jsResult) {
673 ThrowMsg(NullPointerException, "Could not create js array object");
675 for( unsigned int i=0; i<event->getAlarmsTick().size(); i++) {
676 EventAlarmPtr alarm(new EventAlarm());
677 TizenApis::Api::TimeUtil::DurationProperties duration;
678 duration.unit = TizenApis::Api::TimeUtil::MINUTES_UNIT;
679 duration.length = event->getAlarmsTick().at(i);
680 alarm->setDuration(duration); // Default unit is minute.
681 std::vector<CalendarEvent::EventAlarmType> methodVector;
682 methodVector.push_back(event->getAlarmsType().at(i)); // Only one alarm type is saved.
683 alarm->setMethods(methodVector);
684 alarm->setTimeZone(event->getTimeZone());
685 alarm->setDescription(event->getAlarmsDescription().at(i));
687 if (!JSSetArrayElement(priv->getContext(), jsResult, i, JSCalendarAlarm::createJSCalendarAlarm(priv->getContext(), alarm))) {
688 ThrowMsg(UnknownException, "Could not insert value into js array");
695 LogWarning("trying to get incorrect value");
697 return JSValueMakeUndefined(context);
700 bool JSCalendarItemProperties::setPropertyAlarms(JSContextRef context,
702 JSStringRef propertyName,
704 JSValueRef* exception)
707 CalendarEventPtr event(NULL);
710 event = getPrivateObject(object);
711 CalendarConverterFactory::ConverterType converter =
712 CalendarConverterFactory::getConverter(context);
714 EventAlarmListPtr alarms = converter->toVectorOfEventAlarmsFromReference(value);
715 std::vector<CalendarEvent::EventAlarmType> alarmsType;
716 std::vector<long> alarmsTick;
717 std::vector<std::string> alarmsDescription;
719 // Set the multiple alarms.
720 for( unsigned int i=0; i<alarms->size(); i++) {
721 EventAlarmPtr theAlarm = alarms->at(i);
722 alarmsType.push_back(theAlarm->getMethods().at(0));
723 alarmsDescription.push_back(theAlarm->getDescription());
724 if( 0 < theAlarm->getAbsoluteDate() ) {
725 alarmsTick.push_back(theAlarm->getAbsoluteDate()/60);
728 long length = theAlarm->getDuration().length;
729 switch(theAlarm->getDuration().unit) {
730 case TizenApis::Api::TimeUtil::MSECS_UNIT:
731 tick = length/(1000*60);
733 case TizenApis::Api::TimeUtil::SECONDS_UNIT:
736 case TizenApis::Api::TimeUtil::MINUTES_UNIT:
739 case TizenApis::Api::TimeUtil::HOURS_UNIT:
742 case TizenApis::Api::TimeUtil::DAYS_UNIT:
746 ThrowMsg(ConversionException, "Wrong alarm unit type.");
749 alarmsTick.push_back(tick);
752 event->setAlarmsType(alarmsType);
753 event->setAlarmsTick(alarmsTick);
754 event->setAlarmsDescription(alarmsDescription);
759 LogWarning("trying to set incorrect value");
760 TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
766 JSValueRef JSCalendarItemProperties::getPropertyOrganizer(JSContextRef context,
768 JSStringRef propertyName,
769 JSValueRef* exception)
774 Converter converter(context);
775 CalendarEventPtr event = getPrivateObject(object);
776 return converter.toJSValueRef(event->getOrganizer());
780 LogWarning("trying to get incorrect value");
782 return JSValueMakeUndefined(context);
785 bool JSCalendarItemProperties::setPropertyOrganizer(JSContextRef context,
787 JSStringRef propertyName,
789 JSValueRef* exception)
794 if (!JSValueIsString(context, value)) {
795 Throw(InvalidArgumentException);
798 Converter converter(context);
799 CalendarEventPtr event = getPrivateObject(object);
800 std::string organizer = converter.toString(value);
801 event->setOrganizer(organizer);
806 LogWarning("trying to set incorrect value");
807 TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
813 JSValueRef JSCalendarItemProperties::getPropertyVisibility(JSContextRef context,
815 JSStringRef propertyName,
816 JSValueRef* exception)
821 CalendarConverterFactory::ConverterType converter =
822 CalendarConverterFactory::getConverter(context);
823 CalendarEventPtr event = getPrivateObject(object);
824 std::string visibility = converter->toTizenValue(event->getVisibility());
825 return converter->toJSValueRef(visibility);
829 LogWarning("trying to get incorrect value");
831 return JSValueMakeUndefined(context);
834 bool JSCalendarItemProperties::setPropertyVisibility(JSContextRef context,
836 JSStringRef propertyName,
838 JSValueRef* exception)
841 CalendarEventPtr event(NULL);
844 if (!JSValueIsString(context, value)) {
845 Throw(InvalidArgumentException);
848 event = getPrivateObject(object);
849 CalendarConverterFactory::ConverterType converter =
850 CalendarConverterFactory::getConverter(context);
851 CalendarEvent::EventVisibility visibility =
852 converter->toEventVisibility(converter->toString(value));
853 event->setVisibility(visibility);
858 LogError("Error during setting a value");
859 event->setVisibility(CalendarEvent::INVALID_VISIBILITY);
860 TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
866 JSValueRef JSCalendarItemProperties::getPropertyGeolocation(JSContextRef context,
868 JSStringRef propertyName,
869 JSValueRef* exception)
874 CalendarConverter converter(context);
875 CalendarEventPtr event = getPrivateObject(object);
876 CalendarItemGeoPtr geoInfo = event->getGeolocation();
878 return JSCalendarItemGeo::createJSCalendarItemGeo(context, geoInfo);
882 LogWarning("trying to get incorrect value");
885 return JSValueMakeUndefined(context);
888 bool JSCalendarItemProperties::setPropertyGeolocation(JSContextRef context,
890 JSStringRef propertyName,
892 JSValueRef* exception)
895 CalendarEventPtr event(NULL);
898 event = getPrivateObject(object);
899 CalendarConverter converter(context);
900 event->setGeolocation(converter.toGeolocation(value));
905 LogWarning("trying to set incorrect value");
906 TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
912 JSValueRef JSCalendarItemProperties::getPropertyDuration(JSContextRef context,
914 JSStringRef propertyName,
915 JSValueRef* exception)
920 CalendarEventPtr event = getPrivateObject(object);
921 CalendarItemPropertiesPrivObject *priv =
922 static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(object));
924 // Use the global context saved in the event struct.
925 TimeUtilConverter converter(priv->getContext());
926 long length = event->getEndTime() - event->getStartTime(); // in seconds only
927 LogDebug("event->getStartTime():"<< event->getStartTime() << ", length:" << length);
928 return converter.makeMillisecondDurationObject( length*1000 );
932 LogWarning("trying to get incorrect value");
934 return JSValueMakeUndefined(context);
937 bool JSCalendarItemProperties::setPropertyDuration(JSContextRef context,
939 JSStringRef propertyName,
941 JSValueRef* exception)
946 CalendarEventPtr event = getPrivateObject(object);
947 TimeUtilConverter converter(context);
948 long length = converter.getDurationLength(value);
949 int unit = converter.getDurationUnit(value);
951 TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::INVALID_VALUES_ERROR);
954 if( SECONDS_UNIT==unit ) {
955 event->setEndTime(event->getStartTime() + length);
956 } else if ( MINUTES_UNIT==unit ) {
957 event->setEndTime(event->getStartTime() + length*60);
958 } else if ( HOURS_UNIT==unit ) {
959 event->setEndTime(event->getStartTime() + length*60*60);
960 } else if ( DAYS_UNIT==unit ) {
961 event->setEndTime(event->getStartTime() + length*24*60*60);
962 } else if ( MSECS_UNIT==unit ) {
963 event->setEndTime(event->getStartTime() + length/1000);
965 TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::INVALID_VALUES_ERROR);
973 LogWarning("trying to set incorrect value");
974 TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
980 JSValueRef JSCalendarItemProperties::getPropertyRecurrenceRule(JSContextRef context,
982 JSStringRef propertyName,
983 JSValueRef* exception)
988 CalendarItemPropertiesPrivObject *priv =
989 static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(object));
991 CalendarEventPtr event = getPrivateObject(object);
992 EventRecurrenceRulePtr rrule = event->getRecurrenceRule();
995 return JSCalendarRecurrenceRule::createJSCalendarRecurrenceRule(priv->getContext(), rrule);
1000 LogWarning("trying to get incorrect value");
1002 return JSValueMakeUndefined(context);
1005 bool JSCalendarItemProperties::setPropertyRecurrenceRule(JSContextRef context,
1007 JSStringRef propertyName,
1009 JSValueRef* exception)
1011 LogDebug("entered");
1012 CalendarEventPtr event(NULL);
1015 event = getPrivateObject(object);
1016 event->setRecurrenceRule(JSCalendarRecurrenceRule::getPrivateObject(JSValueToObject(context, value, NULL)));
1021 LogWarning("trying to set incorrect value");
1022 TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
1028 JSValueRef JSCalendarItemProperties::getPropertyIsAllDay(JSContextRef context,
1030 JSStringRef propertyName,
1031 JSValueRef* exception)
1033 LogDebug("entered");
1036 CalendarConverterFactory::ConverterType converter =
1037 CalendarConverterFactory::getConverter(context);
1038 CalendarEventPtr event = getPrivateObject(object);
1039 return converter->toJSValueRef(event->getIsAllDay());
1043 LogWarning("trying to get incorrect value");
1045 return JSValueMakeUndefined(context);
1048 bool JSCalendarItemProperties::setPropertyIsAllDay(JSContextRef context,
1050 JSStringRef propertyName,
1052 JSValueRef* exception)
1056 if (!JSValueIsBoolean(context, value)) {
1057 Throw(InvalidArgumentException);
1060 CalendarEventPtr event = getPrivateObject(object);
1061 Converter converter(context);
1062 event->setIsAllDay(converter.toBool(value));
1067 LogWarning("trying to get incorrect value");
1068 TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
1074 JSValueRef JSCalendarItemProperties::getPropertyAvailability(JSContextRef context,
1076 JSStringRef propertyName,
1077 JSValueRef* exception)
1079 LogDebug("entered");
1082 CalendarConverterFactory::ConverterType converter =
1083 CalendarConverterFactory::getConverter(context);
1084 CalendarEventPtr event = getPrivateObject(object);
1085 std::string availability = converter->toTizenValue(event->getAvailability());
1086 return converter->toJSValueRef(availability);
1090 LogWarning("trying to get incorrect value");
1092 return JSValueMakeUndefined(context);
1095 bool JSCalendarItemProperties::setPropertyAvailability(JSContextRef context,
1097 JSStringRef propertyName,
1099 JSValueRef* exception)
1101 LogDebug("entered");
1102 CalendarEventPtr event(NULL);
1105 if (!JSValueIsString(context, value)) {
1106 Throw(InvalidArgumentException);
1109 event = getPrivateObject(object);
1110 CalendarConverterFactory::ConverterType converter =
1111 CalendarConverterFactory::getConverter(context);
1112 CalendarEvent::EventAvailability availability =
1113 converter->toEventAvailability(converter->toString(value));
1114 event->setAvailability(availability);
1119 LogError("Error during setting a value");
1120 event->setAvailability(CalendarEvent::INVALID_AVAILABILITY);
1121 TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
1127 JSValueRef JSCalendarItemProperties::getPropertyAttendees(JSContextRef context,
1129 JSStringRef propertyName,
1130 JSValueRef* exception)
1132 LogDebug("entered");
1135 CalendarItemPropertiesPrivObject *priv =
1136 static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(object));
1138 CalendarEventPtr event = getPrivateObject(object);
1139 EventAttendeeListPtr attendees = event->getAttendees();
1141 JSObjectRef jsResult = JSCreateArrayObject(priv->getContext(), 0, NULL);
1142 if (NULL == jsResult) {
1143 ThrowMsg(NullPointerException, "Could not create js array object");
1145 for(unsigned int i=0; i<attendees->size(); i++) {
1146 if (!JSSetArrayElement(priv->getContext(), jsResult, i, JSCalendarAttendee::createJSCalendarAttendee(priv->getContext(), attendees->at(i)))) {
1147 ThrowMsg(UnknownException, "Could not insert value into js array");
1155 LogWarning("trying to get incorrect value");
1157 return JSValueMakeUndefined(context);
1160 bool JSCalendarItemProperties::setPropertyAttendees(JSContextRef context,
1162 JSStringRef propertyName,
1164 JSValueRef* exception)
1166 LogDebug("entered");
1169 CalendarEventPtr event = getPrivateObject(object);
1170 CalendarConverterFactory::ConverterType converter =
1171 CalendarConverterFactory::getConverter(context);
1172 event->setAttendees(converter->toVectorOfAttendeesFromReference(value));
1177 LogWarning("trying to set incorrect attendee value");
1178 TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
1184 JSValueRef JSCalendarItemProperties::getPropertyDueDate(JSContextRef context,
1186 JSStringRef propertyName,
1187 JSValueRef* exception)
1189 LogDebug("entered");
1192 CalendarItemPropertiesPrivObject *privateObject =
1193 static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(object));
1194 CalendarEventPtr task = privateObject->getObject();
1195 if(CalendarEvent::TASK_TYPE != task->getCalendarType()) {
1196 return JSValueMakeUndefined(context);
1199 Throw(NullPointerException);
1201 if (task->getEndTime() != 0) {
1202 // Use the global context saved in the event struct.
1203 return JSTZDate::createJSObject(privateObject->getContext(), task->getEndTime(), task->getTimeZone());
1205 return JSValueMakeUndefined(context);
1210 LogWarning("trying to get incorrect value");
1212 return JSValueMakeUndefined(context);
1215 bool JSCalendarItemProperties::setPropertyDueDate(JSContextRef context,
1217 JSStringRef propertyName,
1219 JSValueRef* exception)
1221 LogDebug("entered");
1224 CalendarEventPtr task = getPrivateObject(object);
1226 Throw(NullPointerException);
1228 if(CalendarEvent::TASK_TYPE != task->getCalendarType()) {
1229 Throw(InvalidArgumentException);
1231 if (!JSValueIsObjectOfClass(context, value, JSTZDate::getClassRef())) {
1232 Throw(InvalidArgumentException);
1235 TimeUtilConverter converter(context);
1236 std::time_t dueDate = converter.toTZDateTimeT(value);
1238 task->setEndTime(dueDate);
1240 if( task->getTimeZone().empty() ) {
1241 std::string timeZone = converter.getPropertiesInTZDate(value).timezone;
1242 task->setTimeZone(timeZone);
1248 LogWarning("trying to set incorrect value");
1249 TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
1255 JSValueRef JSCalendarItemProperties::getPropertyCompletedDate(JSContextRef context,
1257 JSStringRef propertyName,
1258 JSValueRef* exception)
1260 LogDebug("entered");
1263 CalendarItemPropertiesPrivObject *privateObject =
1264 static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(object));
1265 CalendarEventPtr task = privateObject->getObject();
1266 if(CalendarEvent::TASK_TYPE != task->getCalendarType()) {
1267 return JSValueMakeUndefined(context);
1270 Throw(NullPointerException);
1272 if (task->getEndTime() != 0) {
1273 // Use the global context saved in the event struct.
1274 return JSTZDate::createJSObject(privateObject->getContext(), task->getCompletedDate(), task->getTimeZone());
1276 return JSValueMakeUndefined(context);
1281 LogWarning("trying to get incorrect value");
1283 return JSValueMakeUndefined(context);
1286 bool JSCalendarItemProperties::setPropertyCompletedDate(JSContextRef context,
1288 JSStringRef propertyName,
1290 JSValueRef* exception)
1292 LogDebug("entered");
1295 CalendarEventPtr task = getPrivateObject(object);
1297 Throw(NullPointerException);
1299 if(CalendarEvent::TASK_TYPE != task->getCalendarType()) {
1300 Throw(InvalidArgumentException);
1302 if (!JSValueIsObjectOfClass(context, value, JSTZDate::getClassRef())) {
1303 Throw(InvalidArgumentException);
1306 TimeUtilConverter converter(context);
1307 std::time_t completedDate = converter.toTZDateTimeT(value);
1309 task->setCompletedDate(completedDate);
1311 if( task->getTimeZone().empty() ) {
1312 std::string timeZone = converter.getPropertiesInTZDate(value).timezone;
1313 task->setTimeZone(timeZone);
1319 LogWarning("trying to set incorrect value");
1320 TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
1326 JSValueRef JSCalendarItemProperties::getPropertyProgress(JSContextRef context,
1328 JSStringRef propertyName,
1329 JSValueRef* exception)
1331 LogDebug("entered");
1334 CalendarEventPtr task = getPrivateObject(object);
1335 if(CalendarEvent::TASK_TYPE != task->getCalendarType()) {
1336 return JSValueMakeUndefined(context);
1339 Converter converter(context);
1340 return converter.toJSValueRef(task->getProgress());
1344 LogWarning("trying to get incorrect value");
1346 return JSValueMakeUndefined(context);
1349 bool JSCalendarItemProperties::setPropertyProgress(JSContextRef context,
1351 JSStringRef propertyName,
1353 JSValueRef* exception)
1355 LogDebug("entered");
1358 if (!JSValueIsNumber(context, value)) {
1359 Throw(InvalidArgumentException);
1362 CalendarEventPtr task = getPrivateObject(object);
1363 if(CalendarEvent::TASK_TYPE != task->getCalendarType()) {
1364 return JSValueMakeUndefined(context);
1367 Converter converter(context);
1368 int progress = converter.toInt(value);
1369 task->setProgress(progress);
1374 LogWarning("trying to set incorrect value");
1375 TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
1381 JSValueRef JSCalendarItemProperties::getPropertyPriority(JSContextRef context,
1383 JSStringRef propertyName,
1384 JSValueRef* exception)
1386 LogDebug("entered");
1389 CalendarConverterFactory::ConverterType converter =
1390 CalendarConverterFactory::getConverter(context);
1391 CalendarEventPtr item = getPrivateObject(object);
1393 Throw(NullPointerException);
1395 if(CalendarEvent::LOW_PRIORITY <= item->getPriority() ||
1396 CalendarEvent::HIGH_PRIORITY >= item->getPriority()) {
1397 return JSValueMakeUndefined(context);
1400 std::string priority = converter->toTizenValue(item->getPriority());
1401 return converter->toJSValueRef(priority);
1405 LogWarning("trying to get incorrect value");
1407 return JSValueMakeUndefined(context);
1410 bool JSCalendarItemProperties::setPropertyPriority(JSContextRef context,
1412 JSStringRef propertyName,
1414 JSValueRef* exception)
1416 LogDebug("entered");
1417 CalendarEventPtr item = getPrivateObject(object);
1421 if (!JSValueIsString(context, value)) {
1422 Throw(InvalidArgumentException);
1425 CalendarConverterFactory::ConverterType converter =
1426 CalendarConverterFactory::getConverter(context);
1427 CalendarEvent::TaskPriority priority =
1428 converter->toTaskPriority(converter->toString(value));
1429 item->setPriority(priority);
1434 LogWarning("trying to set incorrect value");
1436 item->setPriority(CalendarEvent::INVALID_PRIORITY);
1438 TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
1444 JSValueRef JSCalendarItemProperties::getPropertyEndDate(JSContextRef context,
1446 JSStringRef propertyName,
1447 JSValueRef* exception)
1449 LogDebug("entered");
1452 CalendarItemPropertiesPrivObject *privateObject =
1453 static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(object));
1454 CalendarEventPtr event = privateObject->getObject();
1455 if(CalendarEvent::EVENT_TYPE != event->getCalendarType()) {
1456 return JSValueMakeUndefined(context);
1459 Throw(NullPointerException);
1461 if (event->getEndTime() != 0) {
1462 // Use the global context saved in the event struct.
1463 return JSTZDate::createJSObject(privateObject->getContext(), event->getEndTime(), event->getTimeZone());
1465 return JSValueMakeUndefined(context);
1470 LogWarning("trying to get incorrect value");
1472 return JSValueMakeUndefined(context);
1475 bool JSCalendarItemProperties::setPropertyEndDate(JSContextRef context,
1477 JSStringRef propertyName,
1479 JSValueRef* exception)
1481 LogDebug("entered");
1484 CalendarEventPtr event = getPrivateObject(object);
1486 Throw(NullPointerException);
1488 if(CalendarEvent::EVENT_TYPE != event->getCalendarType()) {
1489 Throw(InvalidArgumentException);
1491 if (!JSValueIsObjectOfClass(context, value, JSTZDate::getClassRef())) {
1492 Throw(InvalidArgumentException);
1495 TimeUtilConverter converter(context);
1496 std::time_t endDate = converter.toTZDateTimeT(value);
1498 event->setEndTime(endDate);
1500 if( event->getTimeZone().empty() ) {
1501 std::string timeZone = converter.getPropertiesInTZDate(value).timezone;
1502 event->setTimeZone(timeZone);
1508 LogWarning("trying to set incorrect value");
1509 TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
1515 bool JSCalendarItemProperties::validate(JSContextRef ctx,
1516 const JSObjectRef object,
1517 JSValueRef* exception)
1519 LogDebug("entered");
1520 CalendarItemPropertiesPrivObject *priv =
1521 static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(object));
1525 CalendarEventPtr event = priv->getObject();
1529 return event->validate();