2 // Tizen Web Device API
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
20 #include <dpl/log/log.h>
21 #include <CommonsJavaScript/PrivateObject.h>
22 #include <CommonsJavaScript/Converter.h>
23 #include <CommonsJavaScript/JSUtils.h>
24 #include <JSTizenException.h>
25 #include <JSTizenExceptionFactory.h>
26 #include <SecurityExceptions.h>
27 #include <TimeUtilConverter.h>
29 #include <JSSimpleCoordinates.h>
30 #include "EventAlarm.h"
32 #include "ICalendar.h"
33 #include "CalendarFactory.h"
34 #include <DurationProperties.h>
35 #include "JSCalendarItemProperties.h"
36 #include "CalendarConverter.h"
37 #include "JSCalendarEventId.h"
38 #include "JSCalendarAlarm.h"
39 #include "JSCalendarAttendee.h"
40 #include "JSCalendarEvent.h"
41 #include "JSCalendarTask.h"
42 #include "plugin_config.h"
44 #include <GlobalContextManager.h>
46 using namespace WrtDeviceApis::Commons;
47 using namespace WrtDeviceApis::CommonsJavaScript;
48 using namespace DeviceAPI::Common;
49 using namespace DeviceAPI::Time;
54 #define TIZEN_CALENDAR_ITEM_PROPERTIES_ATTRIBUTENAME "CalendarItemProperties"
56 JSClassDefinition JSCalendarItemProperties::m_classInfo = {
58 kJSClassAttributeNone,
59 TIZEN_CALENDAR_ITEM_PROPERTIES_ATTRIBUTENAME,
68 NULL, //DeleteProperty,
69 NULL, //GetPropertyNames,
70 NULL, //CallAsFunction,
71 NULL, //CallAsConstructor,
76 JSStaticValue JSCalendarItemProperties::m_property[] = {
78 { TIZEN_CALENDAR_ITEM_DESCRIPTION, getPropertyDescription, setPropertyDescription, kJSPropertyAttributeNone },
79 { TIZEN_CALENDAR_ITEM_SUMMARY, getPropertySummary, setPropertySummary, kJSPropertyAttributeNone },
80 { TIZEN_CALENDAR_ITEM_START_DATE, getPropertyStartTime, setPropertyStartTime, kJSPropertyAttributeNone },
81 { TIZEN_CALENDAR_ITEM_LOCATION, getPropertyLocation, setPropertyLocation, kJSPropertyAttributeNone },
82 { TIZEN_CALENDAR_ITEM_GEOLOCATION, getPropertyGeolocation, setPropertyGeolocation, kJSPropertyAttributeNone },
83 { TIZEN_CALENDAR_ITEM_ORGANIZER, getPropertyOrganizer, setPropertyOrganizer, kJSPropertyAttributeNone },
84 { TIZEN_CALENDAR_ITEM_VISIBILITY, getPropertyVisibility, setPropertyVisibility, kJSPropertyAttributeNone },
85 { TIZEN_CALENDAR_ITEM_STATUS, getPropertyStatus, setPropertyStatus, kJSPropertyAttributeNone },
86 { TIZEN_CALENDAR_ITEM_ALARMS, getPropertyAlarms, setPropertyAlarms, kJSPropertyAttributeNone },
87 { TIZEN_CALENDAR_ITEM_CATEGORIES, getPropertyCategories, setPropertyCategories, kJSPropertyAttributeNone },
88 { TIZEN_CALENDAR_ITEM_DURATION, getPropertyDuration, setPropertyDuration, kJSPropertyAttributeNone },
89 { TIZEN_CALENDAR_ITEM_IS_ALL_DAY, getPropertyIsAllDay, setPropertyIsAllDay, kJSPropertyAttributeNone },
90 { TIZEN_CALENDAR_ITEM_ATTENDEES, getPropertyAttendees, setPropertyAttendees, kJSPropertyAttributeNone },
91 { TIZEN_CALENDAR_EVENT_AVAILABILITY, getPropertyAvailability, setPropertyAvailability, kJSPropertyAttributeNone },
92 { TIZEN_CALENDAR_TASK_DUE_DATE, getPropertyDueDate, setPropertyDueDate, kJSPropertyAttributeNone },
93 { TIZEN_CALENDAR_TASK_COMPLETED_DATE, getPropertyCompletedDate, setPropertyCompletedDate, kJSPropertyAttributeNone },
94 { TIZEN_CALENDAR_TASK_PROGRESS, getPropertyProgress, setPropertyProgress, kJSPropertyAttributeNone },
95 { TIZEN_CALENDAR_ITEM_PRIORITY, getPropertyPriority, setPropertyPriority, kJSPropertyAttributeNone },
96 { TIZEN_CALENDAR_EVENT_END_DATE, getPropertyEndDate, setPropertyEndDate, kJSPropertyAttributeNone },
97 { TIZEN_CALENDAR_EVENT_LAST_MODIFICATION_DATE, getPropertyLastModificationDate, NULL, kJSPropertyAttributeReadOnly },
98 { TIZEN_CALENDAR_ITEM_CALENDAR_ID, getPropertyCalendarId, NULL, kJSPropertyAttributeReadOnly },
103 JSStaticFunction JSCalendarItemProperties::m_function[] = {
104 { CALENDAR_FUNCTION_API_CONVERT_TO_STRING, convertToString, kJSPropertyAttributeNone },
105 { CALENDAR_FUNCTION_API_CLONE, clone, kJSPropertyAttributeNone },
110 JSClassRef JSCalendarItemProperties::m_jsClassRef = JSClassCreate(JSCalendarItemProperties::getClassInfo());
112 void JSCalendarItemProperties::initialize(JSContextRef context,
115 if (!JSObjectGetPrivate(object)) {
116 LogDebug("Create calendar item private object.");
117 CalendarEventPtr item( new CalendarEvent() );
118 CalendarItemPropertiesPrivObject *priv = new CalendarItemPropertiesPrivObject(context, item);
119 if (!JSObjectSetPrivate(object, static_cast<void*>(priv))) {
123 LogDebug("Private object already set.");
127 void JSCalendarItemProperties::finalize(JSObjectRef object)
129 CalendarItemPropertiesPrivObject *priv = static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(object));
132 JSObjectSetPrivate(object, NULL);
136 const JSClassRef JSCalendarItemProperties::getClassRef()
139 m_jsClassRef = JSClassCreate(&m_classInfo);
144 const JSClassDefinition* JSCalendarItemProperties::getClassInfo()
149 CalendarEventPtr JSCalendarItemProperties::getPrivateObject(JSObjectRef object)
151 CalendarItemPropertiesPrivObject *priv =
152 static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(object));
154 ThrowMsg(NullPointerException, "Private object is null");
156 CalendarEventPtr result = priv->getObject();
158 ThrowMsg(NullPointerException, "Private object is null");
163 void JSCalendarItemProperties::setPrivateObject(const CalendarEventPtr &event,
165 const JSObjectRef object)
169 CalendarItemPropertiesPrivObject *priv =
170 static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(object));
172 priv = new CalendarItemPropertiesPrivObject(ctx, event);
173 if (!JSObjectSetPrivate(object, static_cast<void*>(priv))) {
179 LogError("Error during replacing event object");
183 JSObjectRef JSCalendarItemProperties::createJSCalendarItemProperties(JSContextRef context, CalendarEventPtr item)
185 CalendarItemPropertiesPrivObject *priv = new CalendarItemPropertiesPrivObject(context, item);
186 return JSObjectMake(context, getClassRef(), priv);
189 JSValueRef JSCalendarItemProperties::convertToString(JSContextRef context,
191 JSObjectRef thisObject,
192 size_t argumentCount,
193 const JSValueRef arguments[],
194 JSValueRef* exception)
196 CalendarItemPropertiesPrivObject *privateObject =
197 static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(thisObject));
199 AceSecurityStatus status = CALENDAR_CHECK_ACCESS(CALENDAR_FUNCTION_API_CONVERT_TO_STRING);
201 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
205 if (!privateObject) {
206 ThrowMsg(ConversionException, "Object is null.");
209 CalendarEventPtr item = privateObject->getObject();
211 ThrowMsg(ConversionException, "Parameter conversion failed.");
214 CalendarConverter converter(context);
216 CalendarEvent::VObjectFormat format = CalendarEvent::UNDEFINED_FORMAT;
217 if (argumentCount>=1) {
218 format = converter.toVObjectFormat(converter.toString(arguments[0]));
220 ThrowMsg(ConversionException, "Wrong parameter type.");
223 ICalendarPtr calendar = CalendarFactory::getInstance().createCalendarObject();
224 calendar->setType(item->getCalendarType());
226 IEventExportEventToStringPtr dplEvent(new IEventExportEventToString());
227 dplEvent->setEvent(item);
228 dplEvent->setFormat(format);
229 dplEvent->setForSynchronousCall();
230 calendar->exportEventToString(dplEvent);
232 if (dplEvent->getResult()) {
233 return converter.toJSValueRef(dplEvent->getEventString());
235 ThrowMsg(UnknownException, "Converting to string failed by unknown reason.");
238 Catch(UnsupportedException)
240 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
241 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
243 Catch(InvalidArgumentException)
245 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
246 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
248 Catch(ConversionException)
250 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
251 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
253 Catch (NotFoundException)
255 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
256 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
260 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
261 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
265 JSValueRef JSCalendarItemProperties::clone(JSContextRef context,
267 JSObjectRef thisObject,
268 size_t argumentCount,
269 const JSValueRef arguments[],
270 JSValueRef* exception)
272 CalendarItemPropertiesPrivObject *privateObject =
273 static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(thisObject));
275 AceSecurityStatus status = CALENDAR_CHECK_ACCESS(CALENDAR_FUNCTION_API_CLONE);
277 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
281 if (!privateObject) {
282 ThrowMsg(ConversionException, "Object is null.");
285 CalendarEventPtr item = privateObject->getObject(); // item to copy
287 ThrowMsg(ConversionException, "Parameter conversion failed.");
289 JSContextRef globalContext = privateObject->getContext();
291 // Call the copy constructor.
292 CalendarEventPtr clonedItem( new CalendarEvent(*item));
295 clonedItem->resetId();
296 clonedItem->setRecurrenceId(UNDEFINED_ITEM_ID);
298 if (CalendarEvent::TASK_TYPE==clonedItem->getCalendarType()) {
299 return JSCalendarTask::createJSCalendarTask(context, clonedItem);
300 } else if (CalendarEvent::EVENT_TYPE==clonedItem->getCalendarType()) {
301 // Use global context for potential async api invocation.
302 return JSCalendarEvent::createJSCalendarEvent(globalContext, clonedItem);
304 ThrowMsg(ConversionException, "Wrong object type.");
307 Catch(UnsupportedException)
309 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
310 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
312 Catch(InvalidArgumentException)
314 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
315 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
317 Catch(ConversionException)
319 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
320 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
322 Catch (NotFoundException)
324 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
325 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
329 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
330 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
334 JSValueRef JSCalendarItemProperties::getPropertyDescription(JSContextRef context,
336 JSStringRef propertyName,
337 JSValueRef* exception)
341 Converter converter(context);
342 CalendarEventPtr event = getPrivateObject(object);
343 return converter.toJSValueRef(event->getDescription());
347 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
349 return JSValueMakeUndefined(context);
352 bool JSCalendarItemProperties::setPropertyDescription(JSContextRef context,
354 JSStringRef propertyName,
356 JSValueRef* exception)
360 Converter converter(context);
361 CalendarEventPtr event = getPrivateObject(object);
362 std::string description = converter.toString(value);
363 event->setDescription(description);
368 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
369 DeviceAPI::Common::JSTizenExceptionFactory::postException(context, exception, DeviceAPI::Common::JSTizenException::TYPE_MISMATCH_ERROR);
375 JSValueRef JSCalendarItemProperties::getPropertySummary(JSContextRef context,
377 JSStringRef propertyName,
378 JSValueRef* exception)
382 Converter converter(context);
383 CalendarEventPtr event = getPrivateObject(object);
384 return converter.toJSValueRef(event->getSubject());
388 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
390 return JSValueMakeUndefined(context);
393 bool JSCalendarItemProperties::setPropertySummary(JSContextRef context,
395 JSStringRef propertyName,
397 JSValueRef* exception)
401 Converter converter(context);
402 CalendarEventPtr event = getPrivateObject(object);
403 std::string subject = converter.toString(value);
404 event->setSubject(subject);
409 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
410 DeviceAPI::Common::JSTizenExceptionFactory::postException(context, exception, DeviceAPI::Common::JSTizenException::TYPE_MISMATCH_ERROR);
416 JSValueRef JSCalendarItemProperties::getPropertyStartTime(JSContextRef context,
418 JSStringRef propertyName,
419 JSValueRef* exception)
423 CalendarItemPropertiesPrivObject *privateObject =
424 static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(object));
425 TimeUtilConverter timeConverter(context);
426 CalendarEventPtr event = privateObject->getObject();
428 LogInfo("start time before converted to TZDate: "<<event->getStartTime()<<", time zone: "<<event->getTimeZone());
429 if (UNDEFINED_TIME==event->getStartTime()) {
430 return JSValueMakeUndefined(context);
432 return timeConverter.toJSValueRefTZDate((double)(event->getStartTime()*1000.0), event->getTimeZone());
437 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
439 return JSValueMakeUndefined(context);
442 bool JSCalendarItemProperties::setPropertyStartTime(JSContextRef context,
444 JSStringRef propertyName,
446 JSValueRef* exception)
450 if (!JSValueIsObjectOfClass(context, value, JSTZDate::getClassRef())) {
451 ThrowMsg(ConversionException, "Wrong parameter type.");
454 CalendarEventPtr event = getPrivateObject(object);
455 TimeUtilConverter converter(context);
456 std::time_t duration = event->getEndTime() - event->getStartTime();
461 long long int startTime = (long long int) (converter.getTimeInMilliseconds(value)/1000);
462 event->setStartTime(startTime);
463 event->setEndTime(startTime + duration);
465 std::string timeZone = converter.getPropertiesInTZDate(value).timezone;
466 event->setTimeZone(timeZone);
471 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
472 DeviceAPI::Common::JSTizenExceptionFactory::postException(context, exception, DeviceAPI::Common::JSTizenException::TYPE_MISMATCH_ERROR);
478 JSValueRef JSCalendarItemProperties::getPropertyLocation(JSContextRef context,
480 JSStringRef propertyName,
481 JSValueRef* exception)
485 Converter converter(context);
486 CalendarEventPtr event = getPrivateObject(object);
487 return converter.toJSValueRef(event->getLocation());
491 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
493 return JSValueMakeUndefined(context);
496 bool JSCalendarItemProperties::setPropertyLocation(JSContextRef context,
498 JSStringRef propertyName,
500 JSValueRef* exception)
504 Converter converter(context);
505 CalendarEventPtr event = getPrivateObject(object);
506 std::string location = converter.toString(value);
507 event->setLocation(location);
512 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
513 DeviceAPI::Common::JSTizenExceptionFactory::postException(context, exception, DeviceAPI::Common::JSTizenException::TYPE_MISMATCH_ERROR);
519 JSValueRef JSCalendarItemProperties::getPropertyCategories(JSContextRef context,
521 JSStringRef propertyName,
522 JSValueRef* exception)
526 CalendarEventPtr item = getPrivateObject(object);
527 JSContextRef globalContext = GlobalContextManager::getInstance()->getGlobalContext(context);
529 CalendarConverter converter(globalContext);
531 if(item->getCategoriesJSRef()) {
532 return item->getCategoriesJSRef();
534 LogDebug("Create a JS object for categories.");
535 StringArrayPtr categories = item->getCategories();
536 JSValueRef jsCategories = converter.toJSValueRefStringArray(categories);
537 item->setCategoriesJSRef(converter.toJSObjectRef(jsCategories));
539 JSValueProtect(globalContext, jsCategories);
540 item->setContext(globalContext);
546 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
548 return JSValueMakeUndefined(context);
551 bool JSCalendarItemProperties::setPropertyCategories(JSContextRef context,
553 JSStringRef propertyName,
555 JSValueRef* exception)
559 CalendarEventPtr event = getPrivateObject(object);
560 CalendarConverter converter(context);
561 event->setCategories(converter.toStringArray(value));
566 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
567 DeviceAPI::Common::JSTizenExceptionFactory::postException(context, exception, DeviceAPI::Common::JSTizenException::TYPE_MISMATCH_ERROR);
573 JSValueRef JSCalendarItemProperties::getPropertyStatus(JSContextRef context,
575 JSStringRef propertyName,
576 JSValueRef* exception)
580 CalendarConverter converter(context);
581 CalendarEventPtr event = getPrivateObject(object);
582 std::string status = converter.toTizenValue(event->getStatus());
583 return converter.toJSValueRef(status);
587 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
589 return JSValueMakeUndefined(context);
592 bool JSCalendarItemProperties::setPropertyStatus(JSContextRef context,
594 JSStringRef propertyName,
596 JSValueRef* exception)
598 CalendarEventPtr event(NULL);
601 event = getPrivateObject(object);
602 CalendarConverter converter(context);
603 CalendarEvent::EventStatus status =
604 converter.toEventStatus(converter.toString(value));
605 event->setStatus(status);
610 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
611 DeviceAPI::Common::JSTizenExceptionFactory::postException(context, exception, DeviceAPI::Common::JSTizenException::TYPE_MISMATCH_ERROR);
617 JSValueRef JSCalendarItemProperties::getPropertyAlarms(JSContextRef context,
619 JSStringRef propertyName,
620 JSValueRef* exception)
624 CalendarEventPtr event = getPrivateObject(object);
626 JSObjectRef jsResult = JSCreateArrayObject(context, 0, NULL);
627 if (NULL == jsResult) {
628 ThrowMsg(NullPointerException, "Can not create array object.");
630 for( unsigned int i=0; i<event->getAlarms()->size(); i++) {
631 if (!JSSetArrayElement(context, jsResult, i, JSCalendarAlarm::createJSCalendarAlarm(context, event->getAlarms()->at(i)))) {
632 ThrowMsg(UnknownException, "Can not insert value into array.");
639 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
641 return JSValueMakeUndefined(context);
644 bool JSCalendarItemProperties::setPropertyAlarms(JSContextRef context,
646 JSStringRef propertyName,
648 JSValueRef* exception)
650 CalendarEventPtr event(NULL);
653 event = getPrivateObject(object);
654 CalendarConverter converter(context);
656 EventAlarmListPtr alarms = converter.toVectorOfEventAlarmsFromReference(value);
658 event->setAlarms(alarms);
663 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
664 DeviceAPI::Common::JSTizenExceptionFactory::postException(context, exception, DeviceAPI::Common::JSTizenException::TYPE_MISMATCH_ERROR);
670 JSValueRef JSCalendarItemProperties::getPropertyOrganizer(JSContextRef context,
672 JSStringRef propertyName,
673 JSValueRef* exception)
677 Converter converter(context);
678 CalendarEventPtr event = getPrivateObject(object);
679 return converter.toJSValueRef(event->getOrganizer());
683 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
685 return JSValueMakeUndefined(context);
688 bool JSCalendarItemProperties::setPropertyOrganizer(JSContextRef context,
690 JSStringRef propertyName,
692 JSValueRef* exception)
696 Converter converter(context);
697 CalendarEventPtr event = getPrivateObject(object);
698 std::string organizer = converter.toString(value);
699 event->setOrganizer(organizer);
704 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
705 DeviceAPI::Common::JSTizenExceptionFactory::postException(context, exception, DeviceAPI::Common::JSTizenException::TYPE_MISMATCH_ERROR);
711 JSValueRef JSCalendarItemProperties::getPropertyVisibility(JSContextRef context,
713 JSStringRef propertyName,
714 JSValueRef* exception)
718 CalendarConverter converter(context);
719 CalendarEventPtr event = getPrivateObject(object);
720 std::string visibility = converter.toTizenValue(event->getVisibility());
721 return converter.toJSValueRef(visibility);
725 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
727 return JSValueMakeUndefined(context);
730 bool JSCalendarItemProperties::setPropertyVisibility(JSContextRef context,
732 JSStringRef propertyName,
734 JSValueRef* exception)
736 CalendarEventPtr event(NULL);
739 event = getPrivateObject(object);
740 CalendarConverter converter(context);
741 CalendarEvent::EventVisibility visibility =
742 converter.toEventVisibility(converter.toString(value));
743 event->setVisibility(visibility);
748 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
749 DeviceAPI::Common::JSTizenExceptionFactory::postException(context, exception, DeviceAPI::Common::JSTizenException::TYPE_MISMATCH_ERROR);
755 JSValueRef JSCalendarItemProperties::getPropertyGeolocation(JSContextRef context,
757 JSStringRef propertyName,
758 JSValueRef* exception)
762 CalendarEventPtr event = getPrivateObject(object);
763 DeviceAPI::Tizen::SimpleCoordinatesPtr geoLocation( new DeviceAPI::Tizen::SimpleCoordinates(event->getLatitude(), event->getLongitude()) );
765 return DeviceAPI::Tizen::JSSimpleCoordinates::createJSObject(context, geoLocation);
769 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
772 return JSValueMakeUndefined(context);
775 bool JSCalendarItemProperties::setPropertyGeolocation(JSContextRef context,
777 JSStringRef propertyName,
779 JSValueRef* exception)
783 CalendarEventPtr event = getPrivateObject(object);
785 if (JSValueIsNull(context, value) || JSValueIsUndefined(context, value)) {
786 event->setLatitude(UNDEFINED_GEO);
787 event->setLongitude(UNDEFINED_GEO);
789 DeviceAPI::Tizen::SimpleCoordinatesPtr geoLocation = DeviceAPI::Tizen::JSSimpleCoordinates::getSimpleCoordinates(context, value);
791 event->setLatitude(geoLocation->getLatitude());
792 event->setLongitude(geoLocation->getLongitude());
798 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
799 DeviceAPI::Common::JSTizenExceptionFactory::postException(context, exception, DeviceAPI::Common::JSTizenException::TYPE_MISMATCH_ERROR);
805 JSValueRef JSCalendarItemProperties::getPropertyDuration(JSContextRef context,
807 JSStringRef propertyName,
808 JSValueRef* exception)
812 CalendarEventPtr event = getPrivateObject(object);
814 TimeUtilConverter converter(context);
815 long length = event->getEndTime() - event->getStartTime(); // in seconds only
816 LogDebug("event->getStartTime():"<< event->getStartTime() << ", length:" << length);
817 return converter.makeMillisecondDurationObject( length*1000 );
821 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
823 return JSValueMakeUndefined(context);
826 bool JSCalendarItemProperties::setPropertyDuration(JSContextRef context,
828 JSStringRef propertyName,
830 JSValueRef* exception)
834 CalendarEventPtr event = getPrivateObject(object);
835 TimeUtilConverter converter(context);
836 long length = converter.getDurationLength(value);
837 int unit = converter.getDurationUnit(value);
839 DeviceAPI::Common::JSTizenExceptionFactory::postException(context, exception, DeviceAPI::Common::JSTizenException::INVALID_VALUES_ERROR);
842 if( SECONDS_UNIT==unit ) {
843 event->setEndTime(event->getStartTime() + length);
844 } else if ( MINUTES_UNIT==unit ) {
845 event->setEndTime(event->getStartTime() + length*60);
846 } else if ( HOURS_UNIT==unit ) {
847 event->setEndTime(event->getStartTime() + length*60*60);
848 } else if ( DAYS_UNIT==unit ) {
849 event->setEndTime(event->getStartTime() + length*24*60*60);
850 } else if ( MSECS_UNIT==unit ) {
851 event->setEndTime(event->getStartTime() + length/1000);
853 DeviceAPI::Common::JSTizenExceptionFactory::postException(context, exception, DeviceAPI::Common::JSTizenException::INVALID_VALUES_ERROR);
861 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
862 DeviceAPI::Common::JSTizenExceptionFactory::postException(context, exception, DeviceAPI::Common::JSTizenException::TYPE_MISMATCH_ERROR);
868 JSValueRef JSCalendarItemProperties::getPropertyIsAllDay(JSContextRef context,
870 JSStringRef propertyName,
871 JSValueRef* exception)
875 CalendarConverter converter(context);
876 CalendarEventPtr event = getPrivateObject(object);
877 return converter.toJSValueRef(event->getIsAllDay());
881 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
883 return JSValueMakeUndefined(context);
886 bool JSCalendarItemProperties::setPropertyIsAllDay(JSContextRef context,
888 JSStringRef propertyName,
890 JSValueRef* exception)
894 CalendarEventPtr event = getPrivateObject(object);
895 Converter converter(context);
896 event->setIsAllDay(converter.toBool(value));
901 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
902 DeviceAPI::Common::JSTizenExceptionFactory::postException(context, exception, DeviceAPI::Common::JSTizenException::TYPE_MISMATCH_ERROR);
908 JSValueRef JSCalendarItemProperties::getPropertyAvailability(JSContextRef context,
910 JSStringRef propertyName,
911 JSValueRef* exception)
915 CalendarConverter converter(context);
916 CalendarEventPtr event = getPrivateObject(object);
917 std::string availability = converter.toTizenValue(event->getAvailability());
918 return converter.toJSValueRef(availability);
922 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
924 return JSValueMakeUndefined(context);
927 bool JSCalendarItemProperties::setPropertyAvailability(JSContextRef context,
929 JSStringRef propertyName,
931 JSValueRef* exception)
933 CalendarEventPtr event(NULL);
936 event = getPrivateObject(object);
937 CalendarConverter converter(context);
938 CalendarEvent::EventAvailability availability =
939 converter.toEventAvailability(converter.toString(value));
940 event->setAvailability(availability);
945 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
946 DeviceAPI::Common::JSTizenExceptionFactory::postException(context, exception, DeviceAPI::Common::JSTizenException::TYPE_MISMATCH_ERROR);
952 JSValueRef JSCalendarItemProperties::getPropertyAttendees(JSContextRef context,
954 JSStringRef propertyName,
955 JSValueRef* exception)
959 CalendarEventPtr event = getPrivateObject(object);
960 EventAttendeeListPtr attendees = event->getAttendees();
962 JSObjectRef jsResult = JSCreateArrayObject(context, 0, NULL);
963 if (NULL == jsResult) {
964 ThrowMsg(NullPointerException, "Can not create array object.");
966 for(unsigned int i=0; i<attendees->size(); i++) {
967 if (!JSSetArrayElement(context, jsResult, i, JSCalendarAttendee::createJSCalendarAttendee(context, attendees->at(i)))) {
968 ThrowMsg(UnknownException, "Can not insert value into array.");
976 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
978 return JSValueMakeUndefined(context);
981 bool JSCalendarItemProperties::setPropertyAttendees(JSContextRef context,
983 JSStringRef propertyName,
985 JSValueRef* exception)
989 CalendarEventPtr event = getPrivateObject(object);
990 CalendarConverter converter(context);
991 event->setAttendees(converter.toVectorOfAttendeesFromReference(value));
996 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
997 DeviceAPI::Common::JSTizenExceptionFactory::postException(context, exception, DeviceAPI::Common::JSTizenException::TYPE_MISMATCH_ERROR);
1003 JSValueRef JSCalendarItemProperties::getPropertyDueDate(JSContextRef context,
1005 JSStringRef propertyName,
1006 JSValueRef* exception)
1010 CalendarItemPropertiesPrivObject *privateObject =
1011 static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(object));
1012 CalendarEventPtr task = privateObject->getObject();
1013 if(CalendarEvent::TASK_TYPE != task->getCalendarType()) {
1014 return JSValueMakeUndefined(context);
1017 ThrowMsg(NullPointerException, "Task object is NULL.");
1020 if (UNDEFINED_TIME==task->getEndTime()) {
1021 return JSValueMakeUndefined(context);
1023 TimeUtilConverter timeConverter(context);
1024 return timeConverter.toJSValueRefTZDate((double)(task->getEndTime()*1000.0), task->getTimeZone());
1029 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
1031 return JSValueMakeUndefined(context);
1034 bool JSCalendarItemProperties::setPropertyDueDate(JSContextRef context,
1036 JSStringRef propertyName,
1038 JSValueRef* exception)
1042 CalendarEventPtr task = getPrivateObject(object);
1044 ThrowMsg(NullPointerException, "Task object is NULL.");
1046 if(CalendarEvent::TASK_TYPE != task->getCalendarType()) {
1047 ThrowMsg(InvalidArgumentException, "Wrong type of calendar.");
1049 if (!JSValueIsObjectOfClass(context, value, JSTZDate::getClassRef())) {
1050 ThrowMsg(ConversionException, "Wrong parameter type.");
1053 TimeUtilConverter converter(context);
1054 long long int dueDate = (long long int) (converter.getTimeInMilliseconds(value)/1000);
1056 task->setEndTime(dueDate);
1058 if( task->getTimeZone().empty() ) {
1059 std::string timeZone = converter.getPropertiesInTZDate(value).timezone;
1060 task->setTimeZone(timeZone);
1066 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
1067 DeviceAPI::Common::JSTizenExceptionFactory::postException(context, exception, DeviceAPI::Common::JSTizenException::TYPE_MISMATCH_ERROR);
1073 JSValueRef JSCalendarItemProperties::getPropertyCompletedDate(JSContextRef context,
1075 JSStringRef propertyName,
1076 JSValueRef* exception)
1080 CalendarItemPropertiesPrivObject *privateObject =
1081 static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(object));
1082 CalendarEventPtr task = privateObject->getObject();
1083 if(CalendarEvent::TASK_TYPE != task->getCalendarType()) {
1084 return JSValueMakeUndefined(context);
1087 ThrowMsg(NullPointerException, "Task object is NULL.");
1090 if (UNDEFINED_TIME==task->getCompletedDate()) {
1091 return JSValueMakeUndefined(context);
1093 TimeUtilConverter timeConverter(context);
1094 return timeConverter.toJSValueRefTZDate((double)(task->getCompletedDate()*1000.0), task->getTimeZone());
1099 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
1101 return JSValueMakeUndefined(context);
1104 bool JSCalendarItemProperties::setPropertyCompletedDate(JSContextRef context,
1106 JSStringRef propertyName,
1108 JSValueRef* exception)
1112 CalendarEventPtr task = getPrivateObject(object);
1114 ThrowMsg(NullPointerException, "Task object is NULL.");
1116 if(CalendarEvent::TASK_TYPE != task->getCalendarType()) {
1117 ThrowMsg(InvalidArgumentException, "Wrong calendar type.");
1119 if (!JSValueIsObjectOfClass(context, value, JSTZDate::getClassRef())) {
1120 ThrowMsg(ConversionException, "Wrong parameter type.");
1123 TimeUtilConverter converter(context);
1124 long long int completedDate = (long long int) (converter.getTimeInMilliseconds(value)/1000);
1126 task->setCompletedDate(completedDate);
1128 if( task->getTimeZone().empty() ) {
1129 std::string timeZone = converter.getPropertiesInTZDate(value).timezone;
1130 task->setTimeZone(timeZone);
1136 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
1137 DeviceAPI::Common::JSTizenExceptionFactory::postException(context, exception, DeviceAPI::Common::JSTizenException::TYPE_MISMATCH_ERROR);
1143 JSValueRef JSCalendarItemProperties::getPropertyProgress(JSContextRef context,
1145 JSStringRef propertyName,
1146 JSValueRef* exception)
1150 CalendarEventPtr task = getPrivateObject(object);
1151 if(CalendarEvent::TASK_TYPE != task->getCalendarType()) {
1152 return JSValueMakeUndefined(context);
1155 Converter converter(context);
1156 return converter.toJSValueRef(task->getProgress());
1160 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
1162 return JSValueMakeUndefined(context);
1165 bool JSCalendarItemProperties::setPropertyProgress(JSContextRef context,
1167 JSStringRef propertyName,
1169 JSValueRef* exception)
1173 CalendarEventPtr task = getPrivateObject(object);
1174 if(CalendarEvent::TASK_TYPE != task->getCalendarType()) {
1175 return JSValueMakeUndefined(context);
1178 Converter converter(context);
1179 int progress = converter.toInt(value);
1180 task->setProgress(progress);
1185 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
1186 DeviceAPI::Common::JSTizenExceptionFactory::postException(context, exception, DeviceAPI::Common::JSTizenException::TYPE_MISMATCH_ERROR);
1192 JSValueRef JSCalendarItemProperties::getPropertyPriority(JSContextRef context,
1194 JSStringRef propertyName,
1195 JSValueRef* exception)
1199 CalendarConverter converter(context);
1200 CalendarEventPtr item = getPrivateObject(object);
1202 ThrowMsg(NullPointerException, "Item object is NULL.");
1205 std::string priority = converter.toTizenValue(item->getPriority());
1206 return converter.toJSValueRef(priority);
1210 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
1212 return JSValueMakeUndefined(context);
1215 bool JSCalendarItemProperties::setPropertyPriority(JSContextRef context,
1217 JSStringRef propertyName,
1219 JSValueRef* exception)
1221 CalendarEventPtr item = getPrivateObject(object);
1224 CalendarConverter converter(context);
1225 CalendarEvent::TaskPriority priority =
1226 converter.toTaskPriority(converter.toString(value));
1227 item->setPriority(priority);
1232 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
1233 DeviceAPI::Common::JSTizenExceptionFactory::postException(context, exception, DeviceAPI::Common::JSTizenException::TYPE_MISMATCH_ERROR);
1239 JSValueRef JSCalendarItemProperties::getPropertyEndDate(JSContextRef context,
1241 JSStringRef propertyName,
1242 JSValueRef* exception)
1246 CalendarItemPropertiesPrivObject *privateObject =
1247 static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(object));
1248 CalendarEventPtr event = privateObject->getObject();
1249 if(CalendarEvent::EVENT_TYPE != event->getCalendarType()) {
1250 return JSValueMakeUndefined(context);
1253 ThrowMsg(NullPointerException, "Event object is NULL.");
1256 if (UNDEFINED_TIME==event->getEndTime()) {
1257 return JSValueMakeUndefined(context);
1259 TimeUtilConverter timeConverter(context);
1260 return timeConverter.toJSValueRefTZDate((double)(event->getEndTime()*1000.0), event->getTimeZone());
1265 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
1267 return JSValueMakeUndefined(context);
1270 bool JSCalendarItemProperties::setPropertyEndDate(JSContextRef context,
1272 JSStringRef propertyName,
1274 JSValueRef* exception)
1278 CalendarEventPtr event = getPrivateObject(object);
1280 ThrowMsg(NullPointerException, "Event object is NULL.");
1282 if(CalendarEvent::EVENT_TYPE != event->getCalendarType()) {
1283 ThrowMsg(InvalidArgumentException, "Wrong calendar type.");
1285 if (!JSValueIsObjectOfClass(context, value, JSTZDate::getClassRef())) {
1286 ThrowMsg(ConversionException, "Wrong parameter type.");
1289 TimeUtilConverter converter(context);
1290 long long int endDate = (long long int) (converter.getTimeInMilliseconds(value)/1000);
1292 event->setEndTime(endDate);
1294 if( event->getTimeZone().empty() ) {
1295 std::string timeZone = converter.getPropertiesInTZDate(value).timezone;
1296 event->setTimeZone(timeZone);
1302 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
1303 DeviceAPI::Common::JSTizenExceptionFactory::postException(context, exception, DeviceAPI::Common::JSTizenException::TYPE_MISMATCH_ERROR);
1309 JSValueRef JSCalendarItemProperties::getPropertyLastModificationDate(JSContextRef context,
1311 JSStringRef propertyName,
1312 JSValueRef* exception)
1316 CalendarEventPtr item = getPrivateObject(object);
1318 ThrowMsg(NullPointerException, "Item object is NULL.");
1321 if (UNDEFINED_TIME==item->getLastModifiedDate()) {
1322 return JSValueMakeNull(context);
1324 TimeUtilConverter timeConverter(context);
1325 return timeConverter.toJSValueRefTZDate((double)(item->getLastModifiedDate()*1000.0), item->getTimeZone());
1330 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
1332 return JSValueMakeUndefined(context);
1335 JSValueRef JSCalendarItemProperties::getPropertyCalendarId(JSContextRef context,
1337 JSStringRef propertyName,
1338 JSValueRef* exception)
1342 CalendarEventPtr item = getPrivateObject(object);
1344 if (UNDEFINED_CALENDAR_ID==item->getCalendarId()) {
1345 return JSValueMakeNull(context);
1347 CalendarConverter converter(context);
1348 std::stringstream ss;
1349 ss<<item->getCalendarId();
1350 return converter.toJSValueRef(ss.str());
1356 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
1358 return JSValueMakeUndefined(context);