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 JSValueMakeNull(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 JSValueMakeNull(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 CalendarConverterFactory::ConverterType converter =
667 CalendarConverterFactory::getConverter(context);
668 CalendarEventPtr event = getPrivateObject(object);
670 JSObjectRef jsResult = JSCreateArrayObject(context, 0, NULL);
671 if (NULL == jsResult) {
672 ThrowMsg(NullPointerException, "Could not create js array object");
674 for( unsigned int i=0; i<event->getAlarmsTick().size(); i++) {
675 EventAlarmPtr alarm(new EventAlarm());
676 TizenApis::Api::TimeUtil::DurationProperties duration;
677 duration.unit = TizenApis::Api::TimeUtil::MINUTES_UNIT;
678 duration.length = event->getAlarmsTick().at(i);
679 alarm->setDuration(duration); // Default unit is minute.
680 std::vector<CalendarEvent::EventAlarmType> methodVector;
681 methodVector.push_back(event->getAlarmsType().at(i)); // Only one alarm type is saved.
682 alarm->setMethods(methodVector);
683 alarm->setTimeZone(event->getTimeZone());
684 alarm->setDescription(event->getAlarmsDescription().at(i));
686 if (!JSSetArrayElement(context, jsResult, i, JSCalendarAlarm::createJSCalendarAlarm(context, alarm))) {
687 ThrowMsg(UnknownException, "Could not insert value into js array");
694 LogWarning("trying to get incorrect value");
696 return JSValueMakeUndefined(context);
699 bool JSCalendarItemProperties::setPropertyAlarms(JSContextRef context,
701 JSStringRef propertyName,
703 JSValueRef* exception)
706 CalendarEventPtr event(NULL);
709 event = getPrivateObject(object);
710 CalendarConverterFactory::ConverterType converter =
711 CalendarConverterFactory::getConverter(context);
713 EventAlarmListPtr alarms = converter->toVectorOfEventAlarmsFromReference(value);
714 std::vector<CalendarEvent::EventAlarmType> alarmsType;
715 std::vector<long> alarmsTick;
716 std::vector<std::string> alarmsDescription;
718 // Set the multiple alarms.
719 for( unsigned int i=0; i<alarms->size(); i++) {
720 EventAlarmPtr theAlarm = alarms->at(i);
721 alarmsType.push_back(theAlarm->getMethods().at(0));
722 alarmsDescription.push_back(theAlarm->getDescription());
723 if( 0 < theAlarm->getAbsoluteDate() ) {
724 alarmsTick.push_back(theAlarm->getAbsoluteDate()/60);
727 long length = theAlarm->getDuration().length;
728 switch(theAlarm->getDuration().unit) {
729 case TizenApis::Api::TimeUtil::MSECS_UNIT:
730 tick = length/(1000*60);
732 case TizenApis::Api::TimeUtil::SECONDS_UNIT:
735 case TizenApis::Api::TimeUtil::MINUTES_UNIT:
738 case TizenApis::Api::TimeUtil::HOURS_UNIT:
741 case TizenApis::Api::TimeUtil::DAYS_UNIT:
745 ThrowMsg(ConversionException, "Wrong alarm unit type.");
748 alarmsTick.push_back(tick);
751 event->setAlarmsType(alarmsType);
752 event->setAlarmsTick(alarmsTick);
757 LogWarning("trying to set incorrect value");
758 TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
764 JSValueRef JSCalendarItemProperties::getPropertyOrganizer(JSContextRef context,
766 JSStringRef propertyName,
767 JSValueRef* exception)
772 Converter converter(context);
773 CalendarEventPtr event = getPrivateObject(object);
774 return converter.toJSValueRef(event->getOrganizer());
778 LogWarning("trying to get incorrect value");
780 return JSValueMakeUndefined(context);
783 bool JSCalendarItemProperties::setPropertyOrganizer(JSContextRef context,
785 JSStringRef propertyName,
787 JSValueRef* exception)
792 if (!JSValueIsString(context, value)) {
793 Throw(InvalidArgumentException);
796 Converter converter(context);
797 CalendarEventPtr event = getPrivateObject(object);
798 std::string organizer = converter.toString(value);
799 event->setOrganizer(organizer);
804 LogWarning("trying to set incorrect value");
805 TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
811 JSValueRef JSCalendarItemProperties::getPropertyVisibility(JSContextRef context,
813 JSStringRef propertyName,
814 JSValueRef* exception)
819 CalendarConverterFactory::ConverterType converter =
820 CalendarConverterFactory::getConverter(context);
821 CalendarEventPtr event = getPrivateObject(object);
822 std::string visibility = converter->toTizenValue(event->getVisibility());
823 return converter->toJSValueRef(visibility);
827 LogWarning("trying to get incorrect value");
829 return JSValueMakeUndefined(context);
832 bool JSCalendarItemProperties::setPropertyVisibility(JSContextRef context,
834 JSStringRef propertyName,
836 JSValueRef* exception)
839 CalendarEventPtr event(NULL);
842 if (!JSValueIsString(context, value)) {
843 Throw(InvalidArgumentException);
846 event = getPrivateObject(object);
847 CalendarConverterFactory::ConverterType converter =
848 CalendarConverterFactory::getConverter(context);
849 CalendarEvent::EventVisibility visibility =
850 converter->toEventVisibility(converter->toString(value));
851 event->setVisibility(visibility);
856 LogError("Error during setting a value");
857 event->setVisibility(CalendarEvent::INVALID_VISIBILITY);
858 TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
864 JSValueRef JSCalendarItemProperties::getPropertyGeolocation(JSContextRef context,
866 JSStringRef propertyName,
867 JSValueRef* exception)
872 CalendarConverter converter(context);
873 CalendarEventPtr event = getPrivateObject(object);
874 CalendarItemGeoPtr geoInfo = event->getGeolocation();
876 return JSCalendarItemGeo::createJSCalendarItemGeo(context, geoInfo);
880 LogWarning("trying to get incorrect value");
883 return JSValueMakeUndefined(context);
886 bool JSCalendarItemProperties::setPropertyGeolocation(JSContextRef context,
888 JSStringRef propertyName,
890 JSValueRef* exception)
893 CalendarEventPtr event(NULL);
896 event = getPrivateObject(object);
897 CalendarConverter converter(context);
898 event->setGeolocation(converter.toGeolocation(value));
903 LogWarning("trying to set incorrect value");
904 TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
910 JSValueRef JSCalendarItemProperties::getPropertyDuration(JSContextRef context,
912 JSStringRef propertyName,
913 JSValueRef* exception)
918 CalendarEventPtr event = getPrivateObject(object);
919 CalendarItemPropertiesPrivObject *priv =
920 static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(object));
922 // Use the global context saved in the event struct.
923 TimeUtilConverter converter(priv->getContext());
924 long length = event->getEndTime() - event->getStartTime(); // in seconds only
925 LogDebug("event->getStartTime():"<< event->getStartTime() << ", length:" << length);
926 return converter.makeMillisecondDurationObject( length*1000 );
930 LogWarning("trying to get incorrect value");
932 return JSValueMakeUndefined(context);
935 bool JSCalendarItemProperties::setPropertyDuration(JSContextRef context,
937 JSStringRef propertyName,
939 JSValueRef* exception)
944 CalendarEventPtr event = getPrivateObject(object);
945 TimeUtilConverter converter(context);
946 long length = converter.getDurationLength(value);
947 int unit = converter.getDurationUnit(value);
949 TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::INVALID_VALUES_ERROR);
952 if( SECONDS_UNIT==unit ) {
953 event->setEndTime(event->getStartTime() + length);
954 } else if ( MINUTES_UNIT==unit ) {
955 event->setEndTime(event->getStartTime() + length*60);
956 } else if ( HOURS_UNIT==unit ) {
957 event->setEndTime(event->getStartTime() + length*60*60);
958 } else if ( DAYS_UNIT==unit ) {
959 event->setEndTime(event->getStartTime() + length*24*60*60);
960 } else if ( MSECS_UNIT==unit ) {
961 event->setEndTime(event->getStartTime() + length/1000);
963 TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::INVALID_VALUES_ERROR);
971 LogWarning("trying to set incorrect value");
972 TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
978 JSValueRef JSCalendarItemProperties::getPropertyRecurrenceRule(JSContextRef context,
980 JSStringRef propertyName,
981 JSValueRef* exception)
986 CalendarConverterFactory::ConverterType converter =
987 CalendarConverterFactory::getConverter(context);
988 CalendarEventPtr event = getPrivateObject(object);
989 EventRecurrenceRulePtr rrule = event->getRecurrenceRule();
992 return JSCalendarRecurrenceRule::createJSCalendarRecurrenceRule(context, rrule);
997 LogWarning("trying to get incorrect value");
999 return JSValueMakeUndefined(context);
1002 bool JSCalendarItemProperties::setPropertyRecurrenceRule(JSContextRef context,
1004 JSStringRef propertyName,
1006 JSValueRef* exception)
1008 LogDebug("entered");
1009 CalendarEventPtr event(NULL);
1012 event = getPrivateObject(object);
1013 event->setRecurrenceRule(JSCalendarRecurrenceRule::getPrivateObject(JSValueToObject(context, value, NULL)));
1018 LogWarning("trying to set incorrect value");
1019 TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
1025 JSValueRef JSCalendarItemProperties::getPropertyIsAllDay(JSContextRef context,
1027 JSStringRef propertyName,
1028 JSValueRef* exception)
1030 LogDebug("entered");
1033 CalendarConverterFactory::ConverterType converter =
1034 CalendarConverterFactory::getConverter(context);
1035 CalendarEventPtr event = getPrivateObject(object);
1036 return converter->toJSValueRef(event->getIsAllDay());
1040 LogWarning("trying to get incorrect value");
1042 return JSValueMakeUndefined(context);
1045 bool JSCalendarItemProperties::setPropertyIsAllDay(JSContextRef context,
1047 JSStringRef propertyName,
1049 JSValueRef* exception)
1053 if (!JSValueIsBoolean(context, value)) {
1054 Throw(InvalidArgumentException);
1057 CalendarEventPtr event = getPrivateObject(object);
1058 Converter converter(context);
1059 event->setIsAllDay(converter.toBool(value));
1064 LogWarning("trying to get incorrect value");
1065 TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
1071 JSValueRef JSCalendarItemProperties::getPropertyAvailability(JSContextRef context,
1073 JSStringRef propertyName,
1074 JSValueRef* exception)
1076 LogDebug("entered");
1079 CalendarConverterFactory::ConverterType converter =
1080 CalendarConverterFactory::getConverter(context);
1081 CalendarEventPtr event = getPrivateObject(object);
1082 std::string availability = converter->toTizenValue(event->getAvailability());
1083 return converter->toJSValueRef(availability);
1087 LogWarning("trying to get incorrect value");
1089 return JSValueMakeUndefined(context);
1092 bool JSCalendarItemProperties::setPropertyAvailability(JSContextRef context,
1094 JSStringRef propertyName,
1096 JSValueRef* exception)
1098 LogDebug("entered");
1099 CalendarEventPtr event(NULL);
1102 if (!JSValueIsString(context, value)) {
1103 Throw(InvalidArgumentException);
1106 event = getPrivateObject(object);
1107 CalendarConverterFactory::ConverterType converter =
1108 CalendarConverterFactory::getConverter(context);
1109 CalendarEvent::EventAvailability availability =
1110 converter->toEventAvailability(converter->toString(value));
1111 event->setAvailability(availability);
1116 LogError("Error during setting a value");
1117 event->setAvailability(CalendarEvent::INVALID_AVAILABILITY);
1118 TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
1124 JSValueRef JSCalendarItemProperties::getPropertyAttendees(JSContextRef context,
1126 JSStringRef propertyName,
1127 JSValueRef* exception)
1129 LogDebug("entered");
1132 CalendarEventPtr event = getPrivateObject(object);
1133 EventAttendeeListPtr attendees = event->getAttendees();
1135 JSObjectRef jsResult = JSCreateArrayObject(context, 0, NULL);
1136 if (NULL == jsResult) {
1137 ThrowMsg(NullPointerException, "Could not create js array object");
1139 for(unsigned int i=0; i<attendees->size(); i++) {
1140 if (!JSSetArrayElement(context, jsResult, i, JSCalendarAttendee::createJSCalendarAttendee(context, attendees->at(i)))) {
1141 ThrowMsg(UnknownException, "Could not insert value into js array");
1149 LogWarning("trying to get incorrect value");
1151 return JSValueMakeUndefined(context);
1154 bool JSCalendarItemProperties::setPropertyAttendees(JSContextRef context,
1156 JSStringRef propertyName,
1158 JSValueRef* exception)
1160 LogDebug("entered");
1163 CalendarEventPtr event = getPrivateObject(object);
1164 CalendarConverterFactory::ConverterType converter =
1165 CalendarConverterFactory::getConverter(context);
1166 event->setAttendees(converter->toVectorOfAttendeesFromReference(value));
1171 LogWarning("trying to set incorrect attendee value");
1172 TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
1178 JSValueRef JSCalendarItemProperties::getPropertyDueDate(JSContextRef context,
1180 JSStringRef propertyName,
1181 JSValueRef* exception)
1183 LogDebug("entered");
1186 CalendarItemPropertiesPrivObject *privateObject =
1187 static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(object));
1188 CalendarEventPtr task = privateObject->getObject();
1189 if(CalendarEvent::TASK_TYPE != task->getCalendarType()) {
1190 return JSValueMakeUndefined(context);
1193 Throw(NullPointerException);
1195 if (task->getEndTime() != 0) {
1196 // Use the global context saved in the event struct.
1197 return JSTZDate::createJSObject(privateObject->getContext(), task->getEndTime(), task->getTimeZone());
1199 return JSValueMakeUndefined(context);
1204 LogWarning("trying to get incorrect value");
1206 return JSValueMakeUndefined(context);
1209 bool JSCalendarItemProperties::setPropertyDueDate(JSContextRef context,
1211 JSStringRef propertyName,
1213 JSValueRef* exception)
1215 LogDebug("entered");
1218 CalendarEventPtr task = getPrivateObject(object);
1220 Throw(NullPointerException);
1222 if(CalendarEvent::TASK_TYPE != task->getCalendarType()) {
1223 Throw(InvalidArgumentException);
1225 if (!JSValueIsObjectOfClass(context, value, JSTZDate::getClassRef())) {
1226 Throw(InvalidArgumentException);
1229 TimeUtilConverter converter(context);
1230 std::time_t dueDate = converter.toTZDateTimeT(value);
1232 task->setEndTime(dueDate);
1234 if( task->getTimeZone().empty() ) {
1235 std::string timeZone = converter.getPropertiesInTZDate(value).timezone;
1236 task->setTimeZone(timeZone);
1242 LogWarning("trying to set incorrect value");
1243 TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
1249 JSValueRef JSCalendarItemProperties::getPropertyCompletedDate(JSContextRef context,
1251 JSStringRef propertyName,
1252 JSValueRef* exception)
1254 LogDebug("entered");
1257 CalendarItemPropertiesPrivObject *privateObject =
1258 static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(object));
1259 CalendarEventPtr task = privateObject->getObject();
1260 if(CalendarEvent::TASK_TYPE != task->getCalendarType()) {
1261 return JSValueMakeUndefined(context);
1264 Throw(NullPointerException);
1266 if (task->getEndTime() != 0) {
1267 // Use the global context saved in the event struct.
1268 return JSTZDate::createJSObject(privateObject->getContext(), task->getEndTime(), task->getTimeZone());
1270 return JSValueMakeUndefined(context);
1275 LogWarning("trying to get incorrect value");
1277 return JSValueMakeUndefined(context);
1280 bool JSCalendarItemProperties::setPropertyCompletedDate(JSContextRef context,
1282 JSStringRef propertyName,
1284 JSValueRef* exception)
1286 LogDebug("entered");
1289 CalendarEventPtr task = getPrivateObject(object);
1291 Throw(NullPointerException);
1293 if(CalendarEvent::TASK_TYPE != task->getCalendarType()) {
1294 Throw(InvalidArgumentException);
1296 if (!JSValueIsObjectOfClass(context, value, JSTZDate::getClassRef())) {
1297 Throw(InvalidArgumentException);
1300 TimeUtilConverter converter(context);
1301 std::time_t completedDate = converter.toTZDateTimeT(value);
1303 task->setEndTime(completedDate);
1305 if( task->getTimeZone().empty() ) {
1306 std::string timeZone = converter.getPropertiesInTZDate(value).timezone;
1307 task->setTimeZone(timeZone);
1313 LogWarning("trying to set incorrect value");
1314 TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
1320 JSValueRef JSCalendarItemProperties::getPropertyProgress(JSContextRef context,
1322 JSStringRef propertyName,
1323 JSValueRef* exception)
1325 LogDebug("entered");
1328 CalendarEventPtr task = getPrivateObject(object);
1329 if(CalendarEvent::TASK_TYPE != task->getCalendarType()) {
1330 return JSValueMakeUndefined(context);
1333 Converter converter(context);
1334 return converter.toJSValueRef(task->getProgress());
1338 LogWarning("trying to get incorrect value");
1340 return JSValueMakeUndefined(context);
1343 bool JSCalendarItemProperties::setPropertyProgress(JSContextRef context,
1345 JSStringRef propertyName,
1347 JSValueRef* exception)
1349 LogDebug("entered");
1352 if (!JSValueIsNumber(context, value)) {
1353 Throw(InvalidArgumentException);
1356 CalendarEventPtr task = getPrivateObject(object);
1357 if(CalendarEvent::TASK_TYPE != task->getCalendarType()) {
1358 return JSValueMakeUndefined(context);
1361 Converter converter(context);
1362 int progress = converter.toInt(value);
1363 task->setProgress(progress);
1368 LogWarning("trying to set incorrect value");
1369 TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
1375 JSValueRef JSCalendarItemProperties::getPropertyPriority(JSContextRef context,
1377 JSStringRef propertyName,
1378 JSValueRef* exception)
1380 LogDebug("entered");
1383 CalendarConverterFactory::ConverterType converter =
1384 CalendarConverterFactory::getConverter(context);
1385 CalendarEventPtr item = getPrivateObject(object);
1387 Throw(NullPointerException);
1389 if(CalendarEvent::LOW_PRIORITY <= item->getPriority() ||
1390 CalendarEvent::HIGH_PRIORITY >= item->getPriority()) {
1391 return JSValueMakeUndefined(context);
1394 std::string priority = converter->toTizenValue(item->getPriority());
1395 return converter->toJSValueRef(priority);
1399 LogWarning("trying to get incorrect value");
1401 return JSValueMakeUndefined(context);
1404 bool JSCalendarItemProperties::setPropertyPriority(JSContextRef context,
1406 JSStringRef propertyName,
1408 JSValueRef* exception)
1410 LogDebug("entered");
1411 CalendarEventPtr item = getPrivateObject(object);
1415 if (!JSValueIsString(context, value)) {
1416 Throw(InvalidArgumentException);
1419 CalendarConverterFactory::ConverterType converter =
1420 CalendarConverterFactory::getConverter(context);
1421 CalendarEvent::TaskPriority priority =
1422 converter->toTaskPriority(converter->toString(value));
1423 item->setPriority(priority);
1428 LogWarning("trying to set incorrect value");
1430 item->setPriority(CalendarEvent::INVALID_PRIORITY);
1432 TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
1438 JSValueRef JSCalendarItemProperties::getPropertyEndDate(JSContextRef context,
1440 JSStringRef propertyName,
1441 JSValueRef* exception)
1443 LogDebug("entered");
1446 CalendarItemPropertiesPrivObject *privateObject =
1447 static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(object));
1448 CalendarEventPtr event = privateObject->getObject();
1449 if(CalendarEvent::EVENT_TYPE != event->getCalendarType()) {
1450 return JSValueMakeUndefined(context);
1453 Throw(NullPointerException);
1455 if (event->getEndTime() != 0) {
1456 // Use the global context saved in the event struct.
1457 return JSTZDate::createJSObject(privateObject->getContext(), event->getEndTime(), event->getTimeZone());
1459 return JSValueMakeUndefined(context);
1464 LogWarning("trying to get incorrect value");
1466 return JSValueMakeUndefined(context);
1469 bool JSCalendarItemProperties::setPropertyEndDate(JSContextRef context,
1471 JSStringRef propertyName,
1473 JSValueRef* exception)
1475 LogDebug("entered");
1478 CalendarEventPtr event = getPrivateObject(object);
1480 Throw(NullPointerException);
1482 if(CalendarEvent::EVENT_TYPE != event->getCalendarType()) {
1483 Throw(InvalidArgumentException);
1485 if (!JSValueIsObjectOfClass(context, value, JSTZDate::getClassRef())) {
1486 Throw(InvalidArgumentException);
1489 TimeUtilConverter converter(context);
1490 std::time_t endDate = converter.toTZDateTimeT(value);
1492 event->setEndTime(endDate);
1494 if( event->getTimeZone().empty() ) {
1495 std::string timeZone = converter.getPropertiesInTZDate(value).timezone;
1496 event->setTimeZone(timeZone);
1502 LogWarning("trying to set incorrect value");
1503 TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
1509 bool JSCalendarItemProperties::validate(JSContextRef ctx,
1510 const JSObjectRef object,
1511 JSValueRef* exception)
1513 LogDebug("entered");
1514 CalendarItemPropertiesPrivObject *priv =
1515 static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(object));
1519 CalendarEventPtr event = priv->getObject();
1523 return event->validate();