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 "JSCalendarRecurrenceRule.h"
40 #include "JSCalendarAttendee.h"
41 #include "JSCalendarEvent.h"
42 #include "JSCalendarTask.h"
43 #include "plugin_config.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_RECURRENCE_RULE, getPropertyRecurrenceRule, setPropertyRecurrenceRule, kJSPropertyAttributeNone },
92 { TIZEN_CALENDAR_EVENT_AVAILABILITY, getPropertyAvailability, setPropertyAvailability, kJSPropertyAttributeNone },
93 { TIZEN_CALENDAR_TASK_DUE_DATE, getPropertyDueDate, setPropertyDueDate, kJSPropertyAttributeNone },
94 { TIZEN_CALENDAR_TASK_COMPLETED_DATE, getPropertyCompletedDate, setPropertyCompletedDate, kJSPropertyAttributeNone },
95 { TIZEN_CALENDAR_TASK_PROGRESS, getPropertyProgress, setPropertyProgress, kJSPropertyAttributeNone },
96 { TIZEN_CALENDAR_ITEM_PRIORITY, getPropertyPriority, setPropertyPriority, kJSPropertyAttributeNone },
97 { TIZEN_CALENDAR_EVENT_END_DATE, getPropertyEndDate, setPropertyEndDate, kJSPropertyAttributeNone },
98 { TIZEN_CALENDAR_EVENT_LAST_MODIFICATION_DATE, getPropertyLastModificationDate, NULL, kJSPropertyAttributeReadOnly },
99 { TIZEN_CALENDAR_ITEM_CALENDAR_ID, getPropertyCalendarId, NULL, kJSPropertyAttributeReadOnly },
104 JSStaticFunction JSCalendarItemProperties::m_function[] = {
105 { CALENDAR_FUNCTION_API_CONVERT_TO_STRING, convertToString, kJSPropertyAttributeNone },
106 { CALENDAR_FUNCTION_API_CLONE, clone, kJSPropertyAttributeNone },
111 JSClassRef JSCalendarItemProperties::m_jsClassRef = JSClassCreate(JSCalendarItemProperties::getClassInfo());
113 void JSCalendarItemProperties::initialize(JSContextRef context,
116 if (!JSObjectGetPrivate(object)) {
117 LogDebug("Create calendar item private object.");
118 CalendarEventPtr item( new CalendarEvent() );
119 CalendarItemPropertiesPrivObject *priv = new CalendarItemPropertiesPrivObject(context, item);
120 if (!JSObjectSetPrivate(object, static_cast<void*>(priv))) {
124 LogDebug("Private object already set.");
128 void JSCalendarItemProperties::finalize(JSObjectRef object)
130 CalendarItemPropertiesPrivObject *priv = static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(object));
133 JSObjectSetPrivate(object, NULL);
137 const JSClassRef JSCalendarItemProperties::getClassRef()
140 m_jsClassRef = JSClassCreate(&m_classInfo);
145 const JSClassDefinition* JSCalendarItemProperties::getClassInfo()
150 CalendarEventPtr JSCalendarItemProperties::getPrivateObject(JSObjectRef object)
152 CalendarItemPropertiesPrivObject *priv =
153 static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(object));
155 ThrowMsg(NullPointerException, "Private object is null");
157 CalendarEventPtr result = priv->getObject();
159 ThrowMsg(NullPointerException, "Private object is null");
164 void JSCalendarItemProperties::setPrivateObject(const CalendarEventPtr &event,
166 const JSObjectRef object)
170 CalendarItemPropertiesPrivObject *priv =
171 static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(object));
173 priv = new CalendarItemPropertiesPrivObject(ctx, event);
174 if (!JSObjectSetPrivate(object, static_cast<void*>(priv))) {
180 LogError("Error during replacing event object");
184 JSObjectRef JSCalendarItemProperties::createJSCalendarItemProperties(JSContextRef context, CalendarEventPtr item)
186 CalendarItemPropertiesPrivObject *priv = new CalendarItemPropertiesPrivObject(context, item);
187 return JSObjectMake(context, getClassRef(), priv);
190 JSValueRef JSCalendarItemProperties::convertToString(JSContextRef context,
192 JSObjectRef thisObject,
193 size_t argumentCount,
194 const JSValueRef arguments[],
195 JSValueRef* exception)
197 CalendarItemPropertiesPrivObject *privateObject =
198 static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(thisObject));
200 AceSecurityStatus status = CALENDAR_CHECK_ACCESS(CALENDAR_FUNCTION_API_CONVERT_TO_STRING);
202 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
206 if (!privateObject) {
207 ThrowMsg(ConversionException, "Object is null.");
210 CalendarEventPtr item = privateObject->getObject();
212 ThrowMsg(ConversionException, "Parameter conversion failed.");
215 CalendarConverter converter(context);
217 CalendarEvent::VObjectFormat format = CalendarEvent::UNDEFINED_FORMAT;
218 if (argumentCount>=1) {
219 format = converter.toVObjectFormat(converter.toString(arguments[0]));
221 ThrowMsg(ConversionException, "Wrong parameter type.");
224 ICalendarPtr calendar = CalendarFactory::getInstance().createCalendarObject();
225 calendar->setType(item->getCalendarType());
227 IEventExportEventToStringPtr dplEvent(new IEventExportEventToString());
228 dplEvent->setEvent(item);
229 dplEvent->setFormat(format);
230 dplEvent->setForSynchronousCall();
231 calendar->exportEventToString(dplEvent);
233 if (dplEvent->getResult()) {
234 return converter.toJSValueRef(dplEvent->getEventString());
236 ThrowMsg(UnknownException, "Converting to string failed by unknown reason.");
239 Catch(UnsupportedException)
241 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
242 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
244 Catch(InvalidArgumentException)
246 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
247 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
249 Catch(ConversionException)
251 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
252 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
254 Catch (NotFoundException)
256 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
257 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
261 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
262 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
266 JSValueRef JSCalendarItemProperties::clone(JSContextRef context,
268 JSObjectRef thisObject,
269 size_t argumentCount,
270 const JSValueRef arguments[],
271 JSValueRef* exception)
273 CalendarItemPropertiesPrivObject *privateObject =
274 static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(thisObject));
276 AceSecurityStatus status = CALENDAR_CHECK_ACCESS(CALENDAR_FUNCTION_API_CLONE);
278 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
282 if (!privateObject) {
283 ThrowMsg(ConversionException, "Object is null.");
286 CalendarEventPtr item = privateObject->getObject(); // item to copy
288 ThrowMsg(ConversionException, "Parameter conversion failed.");
290 JSContextRef globalContext = privateObject->getContext();
292 // Call the copy constructor.
293 CalendarEventPtr clonedItem( new CalendarEvent(*item));
296 clonedItem->resetId();
297 clonedItem->setRecurrenceId(UNDEFINED_ITEM_ID);
299 if (CalendarEvent::TASK_TYPE==clonedItem->getCalendarType()) {
300 return JSCalendarTask::createJSCalendarTask(context, clonedItem);
301 } else if (CalendarEvent::EVENT_TYPE==clonedItem->getCalendarType()) {
302 // Use global context for potential async api invocation.
303 return JSCalendarEvent::createJSCalendarEvent(globalContext, clonedItem);
305 ThrowMsg(ConversionException, "Wrong object type.");
308 Catch(UnsupportedException)
310 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
311 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
313 Catch(InvalidArgumentException)
315 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
316 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
318 Catch(ConversionException)
320 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
321 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
323 Catch (NotFoundException)
325 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
326 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
330 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
331 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
335 JSValueRef JSCalendarItemProperties::getPropertyDescription(JSContextRef context,
337 JSStringRef propertyName,
338 JSValueRef* exception)
342 Converter converter(context);
343 CalendarEventPtr event = getPrivateObject(object);
344 return converter.toJSValueRef(event->getDescription());
348 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
350 return JSValueMakeUndefined(context);
353 bool JSCalendarItemProperties::setPropertyDescription(JSContextRef context,
355 JSStringRef propertyName,
357 JSValueRef* exception)
361 Converter converter(context);
362 CalendarEventPtr event = getPrivateObject(object);
363 std::string description = converter.toString(value);
364 event->setDescription(description);
369 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
370 DeviceAPI::Common::JSTizenExceptionFactory::postException(context, exception, DeviceAPI::Common::JSTizenException::TYPE_MISMATCH_ERROR);
376 JSValueRef JSCalendarItemProperties::getPropertySummary(JSContextRef context,
378 JSStringRef propertyName,
379 JSValueRef* exception)
383 Converter converter(context);
384 CalendarEventPtr event = getPrivateObject(object);
385 return converter.toJSValueRef(event->getSubject());
389 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
391 return JSValueMakeUndefined(context);
394 bool JSCalendarItemProperties::setPropertySummary(JSContextRef context,
396 JSStringRef propertyName,
398 JSValueRef* exception)
402 Converter converter(context);
403 CalendarEventPtr event = getPrivateObject(object);
404 std::string subject = converter.toString(value);
405 event->setSubject(subject);
410 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
411 DeviceAPI::Common::JSTizenExceptionFactory::postException(context, exception, DeviceAPI::Common::JSTizenException::TYPE_MISMATCH_ERROR);
417 JSValueRef JSCalendarItemProperties::getPropertyStartTime(JSContextRef context,
419 JSStringRef propertyName,
420 JSValueRef* exception)
424 CalendarItemPropertiesPrivObject *privateObject =
425 static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(object));
426 TimeUtilConverter timeConverter(context);
427 CalendarEventPtr event = privateObject->getObject();
429 LogInfo("start time before converted to TZDate: "<<event->getStartTime()<<", time zone: "<<event->getTimeZone());
430 if (UNDEFINED_TIME==event->getStartTime()) {
431 return JSValueMakeUndefined(context);
433 return timeConverter.toJSValueRefTZDate((double)(event->getStartTime()*1000.0), event->getTimeZone());
438 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
440 return JSValueMakeUndefined(context);
443 bool JSCalendarItemProperties::setPropertyStartTime(JSContextRef context,
445 JSStringRef propertyName,
447 JSValueRef* exception)
451 if (!JSValueIsObjectOfClass(context, value, JSTZDate::getClassRef())) {
452 ThrowMsg(ConversionException, "Wrong parameter type.");
455 CalendarEventPtr event = getPrivateObject(object);
456 TimeUtilConverter converter(context);
457 std::time_t duration = event->getEndTime() - event->getStartTime();
462 long long int startTime = (long long int) (converter.getTimeInMilliseconds(value)/1000);
463 event->setStartTime(startTime);
464 event->setEndTime(startTime + duration);
466 std::string timeZone = converter.getPropertiesInTZDate(value).timezone;
467 event->setTimeZone(timeZone);
472 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
473 DeviceAPI::Common::JSTizenExceptionFactory::postException(context, exception, DeviceAPI::Common::JSTizenException::TYPE_MISMATCH_ERROR);
479 JSValueRef JSCalendarItemProperties::getPropertyLocation(JSContextRef context,
481 JSStringRef propertyName,
482 JSValueRef* exception)
486 Converter converter(context);
487 CalendarEventPtr event = getPrivateObject(object);
488 return converter.toJSValueRef(event->getLocation());
492 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
494 return JSValueMakeUndefined(context);
497 bool JSCalendarItemProperties::setPropertyLocation(JSContextRef context,
499 JSStringRef propertyName,
501 JSValueRef* exception)
505 Converter converter(context);
506 CalendarEventPtr event = getPrivateObject(object);
507 std::string location = converter.toString(value);
508 event->setLocation(location);
513 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
514 DeviceAPI::Common::JSTizenExceptionFactory::postException(context, exception, DeviceAPI::Common::JSTizenException::TYPE_MISMATCH_ERROR);
520 JSValueRef JSCalendarItemProperties::getPropertyCategories(JSContextRef context,
522 JSStringRef propertyName,
523 JSValueRef* exception)
527 CalendarConverter converter(context);
528 CalendarEventPtr event = getPrivateObject(object);
529 StringArrayPtr categories = event->getCategories();
531 return converter.toJSValueRef(categories);
536 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
538 return JSValueMakeUndefined(context);
541 bool JSCalendarItemProperties::setPropertyCategories(JSContextRef context,
543 JSStringRef propertyName,
545 JSValueRef* exception)
549 CalendarEventPtr event = getPrivateObject(object);
550 CalendarConverter converter(context);
551 event->setCategories(converter.toStringArray(value));
556 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
557 DeviceAPI::Common::JSTizenExceptionFactory::postException(context, exception, DeviceAPI::Common::JSTizenException::TYPE_MISMATCH_ERROR);
563 JSValueRef JSCalendarItemProperties::getPropertyStatus(JSContextRef context,
565 JSStringRef propertyName,
566 JSValueRef* exception)
570 CalendarConverter converter(context);
571 CalendarEventPtr event = getPrivateObject(object);
572 std::string status = converter.toTizenValue(event->getStatus());
573 return converter.toJSValueRef(status);
577 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
579 return JSValueMakeUndefined(context);
582 bool JSCalendarItemProperties::setPropertyStatus(JSContextRef context,
584 JSStringRef propertyName,
586 JSValueRef* exception)
588 CalendarEventPtr event(NULL);
591 event = getPrivateObject(object);
592 CalendarConverter converter(context);
593 CalendarEvent::EventStatus status =
594 converter.toEventStatus(converter.toString(value));
595 event->setStatus(status);
600 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
601 DeviceAPI::Common::JSTizenExceptionFactory::postException(context, exception, DeviceAPI::Common::JSTizenException::TYPE_MISMATCH_ERROR);
607 JSValueRef JSCalendarItemProperties::getPropertyAlarms(JSContextRef context,
609 JSStringRef propertyName,
610 JSValueRef* exception)
614 CalendarEventPtr event = getPrivateObject(object);
616 JSObjectRef jsResult = JSCreateArrayObject(context, 0, NULL);
617 if (NULL == jsResult) {
618 ThrowMsg(NullPointerException, "Can not create array object.");
620 for( unsigned int i=0; i<event->getAlarms()->size(); i++) {
621 if (!JSSetArrayElement(context, jsResult, i, JSCalendarAlarm::createJSCalendarAlarm(context, event->getAlarms()->at(i)))) {
622 ThrowMsg(UnknownException, "Can not insert value into array.");
629 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
631 return JSValueMakeUndefined(context);
634 bool JSCalendarItemProperties::setPropertyAlarms(JSContextRef context,
636 JSStringRef propertyName,
638 JSValueRef* exception)
640 CalendarEventPtr event(NULL);
643 event = getPrivateObject(object);
644 CalendarConverter converter(context);
646 EventAlarmListPtr alarms = converter.toVectorOfEventAlarmsFromReference(value);
648 event->setAlarms(alarms);
653 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
654 DeviceAPI::Common::JSTizenExceptionFactory::postException(context, exception, DeviceAPI::Common::JSTizenException::TYPE_MISMATCH_ERROR);
660 JSValueRef JSCalendarItemProperties::getPropertyOrganizer(JSContextRef context,
662 JSStringRef propertyName,
663 JSValueRef* exception)
667 Converter converter(context);
668 CalendarEventPtr event = getPrivateObject(object);
669 return converter.toJSValueRef(event->getOrganizer());
673 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
675 return JSValueMakeUndefined(context);
678 bool JSCalendarItemProperties::setPropertyOrganizer(JSContextRef context,
680 JSStringRef propertyName,
682 JSValueRef* exception)
686 Converter converter(context);
687 CalendarEventPtr event = getPrivateObject(object);
688 std::string organizer = converter.toString(value);
689 event->setOrganizer(organizer);
694 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
695 DeviceAPI::Common::JSTizenExceptionFactory::postException(context, exception, DeviceAPI::Common::JSTizenException::TYPE_MISMATCH_ERROR);
701 JSValueRef JSCalendarItemProperties::getPropertyVisibility(JSContextRef context,
703 JSStringRef propertyName,
704 JSValueRef* exception)
708 CalendarConverter converter(context);
709 CalendarEventPtr event = getPrivateObject(object);
710 std::string visibility = converter.toTizenValue(event->getVisibility());
711 return converter.toJSValueRef(visibility);
715 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
717 return JSValueMakeUndefined(context);
720 bool JSCalendarItemProperties::setPropertyVisibility(JSContextRef context,
722 JSStringRef propertyName,
724 JSValueRef* exception)
726 CalendarEventPtr event(NULL);
729 event = getPrivateObject(object);
730 CalendarConverter converter(context);
731 CalendarEvent::EventVisibility visibility =
732 converter.toEventVisibility(converter.toString(value));
733 event->setVisibility(visibility);
738 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
739 DeviceAPI::Common::JSTizenExceptionFactory::postException(context, exception, DeviceAPI::Common::JSTizenException::TYPE_MISMATCH_ERROR);
745 JSValueRef JSCalendarItemProperties::getPropertyGeolocation(JSContextRef context,
747 JSStringRef propertyName,
748 JSValueRef* exception)
752 CalendarEventPtr event = getPrivateObject(object);
753 DeviceAPI::Tizen::SimpleCoordinatesPtr geoLocation(
754 new DeviceAPI::Tizen::SimpleCoordinates(event->getLatitude(), event->getLongitude()) );
756 return DeviceAPI::Tizen::JSSimpleCoordinates::createJSObject(context, geoLocation);
760 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
763 return JSValueMakeUndefined(context);
766 bool JSCalendarItemProperties::setPropertyGeolocation(JSContextRef context,
768 JSStringRef propertyName,
770 JSValueRef* exception)
774 CalendarEventPtr event = getPrivateObject(object);
775 DeviceAPI::Tizen::SimpleCoordinatesPtr geoLocation =
776 DeviceAPI::Tizen::JSSimpleCoordinates::getSimpleCoordinates(context, value);
778 event->setLatitude(geoLocation->getLatitude());
779 event->setLongitude(geoLocation->getLongitude());
784 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
785 DeviceAPI::Common::JSTizenExceptionFactory::postException(context, exception, DeviceAPI::Common::JSTizenException::TYPE_MISMATCH_ERROR);
791 JSValueRef JSCalendarItemProperties::getPropertyDuration(JSContextRef context,
793 JSStringRef propertyName,
794 JSValueRef* exception)
798 CalendarEventPtr event = getPrivateObject(object);
800 TimeUtilConverter converter(context);
801 long length = event->getEndTime() - event->getStartTime(); // in seconds only
802 LogDebug("event->getStartTime():"<< event->getStartTime() << ", length:" << length);
803 return converter.makeMillisecondDurationObject( length*1000 );
807 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
809 return JSValueMakeUndefined(context);
812 bool JSCalendarItemProperties::setPropertyDuration(JSContextRef context,
814 JSStringRef propertyName,
816 JSValueRef* exception)
820 CalendarEventPtr event = getPrivateObject(object);
821 TimeUtilConverter converter(context);
822 long length = converter.getDurationLength(value);
823 int unit = converter.getDurationUnit(value);
825 DeviceAPI::Common::JSTizenExceptionFactory::postException(context, exception, DeviceAPI::Common::JSTizenException::INVALID_VALUES_ERROR);
828 if( SECONDS_UNIT==unit ) {
829 event->setEndTime(event->getStartTime() + length);
830 } else if ( MINUTES_UNIT==unit ) {
831 event->setEndTime(event->getStartTime() + length*60);
832 } else if ( HOURS_UNIT==unit ) {
833 event->setEndTime(event->getStartTime() + length*60*60);
834 } else if ( DAYS_UNIT==unit ) {
835 event->setEndTime(event->getStartTime() + length*24*60*60);
836 } else if ( MSECS_UNIT==unit ) {
837 event->setEndTime(event->getStartTime() + length/1000);
839 DeviceAPI::Common::JSTizenExceptionFactory::postException(context, exception, DeviceAPI::Common::JSTizenException::INVALID_VALUES_ERROR);
847 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
848 DeviceAPI::Common::JSTizenExceptionFactory::postException(context, exception, DeviceAPI::Common::JSTizenException::TYPE_MISMATCH_ERROR);
854 JSValueRef JSCalendarItemProperties::getPropertyRecurrenceRule(JSContextRef context,
856 JSStringRef propertyName,
857 JSValueRef* exception)
861 CalendarItemPropertiesPrivObject *priv =
862 static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(object));
864 CalendarEventPtr event = getPrivateObject(object);
865 EventRecurrenceRulePtr rrule;
866 if (event->getIsDetached()) {
867 LogDebug("This is a detached event.");
868 return JSValueMakeUndefined(context);
870 rrule = event->getRecurrenceRule();
873 if (EventRecurrenceRule::NO_RECURRENCE==rrule->getFrequency()) {
874 return JSValueMakeUndefined(context);
876 return JSCalendarRecurrenceRule::createJSCalendarRecurrenceRule(priv->getContext(), rrule);
881 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
883 return JSValueMakeUndefined(context);
886 bool JSCalendarItemProperties::setPropertyRecurrenceRule(JSContextRef context,
888 JSStringRef propertyName,
890 JSValueRef* exception)
892 CalendarEventPtr event(NULL);
895 event = getPrivateObject(object);
896 if (event->getIsDetached()) {
897 LogWarning("Can't set the recurrenceRule of a detached event!");
898 DeviceAPI::Common::JSTizenExceptionFactory::postException(context, exception, DeviceAPI::Common::JSTizenException::NOT_SUPPORTED_ERROR);
900 event->setRecurrenceRule(JSCalendarRecurrenceRule::getPrivateObject(JSValueToObject(context, value, NULL)));
905 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
906 DeviceAPI::Common::JSTizenExceptionFactory::postException(context, exception, DeviceAPI::Common::JSTizenException::TYPE_MISMATCH_ERROR);
912 JSValueRef JSCalendarItemProperties::getPropertyIsAllDay(JSContextRef context,
914 JSStringRef propertyName,
915 JSValueRef* exception)
919 CalendarConverter converter(context);
920 CalendarEventPtr event = getPrivateObject(object);
921 return converter.toJSValueRef(event->getIsAllDay());
925 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
927 return JSValueMakeUndefined(context);
930 bool JSCalendarItemProperties::setPropertyIsAllDay(JSContextRef context,
932 JSStringRef propertyName,
934 JSValueRef* exception)
938 CalendarEventPtr event = getPrivateObject(object);
939 Converter converter(context);
940 event->setIsAllDay(converter.toBool(value));
945 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
946 DeviceAPI::Common::JSTizenExceptionFactory::postException(context, exception, DeviceAPI::Common::JSTizenException::TYPE_MISMATCH_ERROR);
952 JSValueRef JSCalendarItemProperties::getPropertyAvailability(JSContextRef context,
954 JSStringRef propertyName,
955 JSValueRef* exception)
959 CalendarConverter converter(context);
960 CalendarEventPtr event = getPrivateObject(object);
961 std::string availability = converter.toTizenValue(event->getAvailability());
962 return converter.toJSValueRef(availability);
966 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
968 return JSValueMakeUndefined(context);
971 bool JSCalendarItemProperties::setPropertyAvailability(JSContextRef context,
973 JSStringRef propertyName,
975 JSValueRef* exception)
977 CalendarEventPtr event(NULL);
980 event = getPrivateObject(object);
981 CalendarConverter converter(context);
982 CalendarEvent::EventAvailability availability =
983 converter.toEventAvailability(converter.toString(value));
984 event->setAvailability(availability);
989 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
990 DeviceAPI::Common::JSTizenExceptionFactory::postException(context, exception, DeviceAPI::Common::JSTizenException::TYPE_MISMATCH_ERROR);
996 JSValueRef JSCalendarItemProperties::getPropertyAttendees(JSContextRef context,
998 JSStringRef propertyName,
999 JSValueRef* exception)
1003 CalendarEventPtr event = getPrivateObject(object);
1004 EventAttendeeListPtr attendees = event->getAttendees();
1006 JSObjectRef jsResult = JSCreateArrayObject(context, 0, NULL);
1007 if (NULL == jsResult) {
1008 ThrowMsg(NullPointerException, "Can not create array object.");
1010 for(unsigned int i=0; i<attendees->size(); i++) {
1011 if (!JSSetArrayElement(context, jsResult, i, JSCalendarAttendee::createJSCalendarAttendee(context, attendees->at(i)))) {
1012 ThrowMsg(UnknownException, "Can not insert value into array.");
1020 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
1022 return JSValueMakeUndefined(context);
1025 bool JSCalendarItemProperties::setPropertyAttendees(JSContextRef context,
1027 JSStringRef propertyName,
1029 JSValueRef* exception)
1033 CalendarEventPtr event = getPrivateObject(object);
1034 CalendarConverter converter(context);
1035 event->setAttendees(converter.toVectorOfAttendeesFromReference(value));
1040 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
1041 DeviceAPI::Common::JSTizenExceptionFactory::postException(context, exception, DeviceAPI::Common::JSTizenException::TYPE_MISMATCH_ERROR);
1047 JSValueRef JSCalendarItemProperties::getPropertyDueDate(JSContextRef context,
1049 JSStringRef propertyName,
1050 JSValueRef* exception)
1054 CalendarItemPropertiesPrivObject *privateObject =
1055 static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(object));
1056 CalendarEventPtr task = privateObject->getObject();
1057 if(CalendarEvent::TASK_TYPE != task->getCalendarType()) {
1058 return JSValueMakeUndefined(context);
1061 ThrowMsg(NullPointerException, "Task object is NULL.");
1064 if (UNDEFINED_TIME==task->getEndTime()) {
1065 return JSValueMakeUndefined(context);
1067 TimeUtilConverter timeConverter(context);
1068 return timeConverter.toJSValueRefTZDate((double)(task->getEndTime()*1000.0), task->getTimeZone());
1073 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
1075 return JSValueMakeUndefined(context);
1078 bool JSCalendarItemProperties::setPropertyDueDate(JSContextRef context,
1080 JSStringRef propertyName,
1082 JSValueRef* exception)
1086 CalendarEventPtr task = getPrivateObject(object);
1088 ThrowMsg(NullPointerException, "Task object is NULL.");
1090 if(CalendarEvent::TASK_TYPE != task->getCalendarType()) {
1091 ThrowMsg(InvalidArgumentException, "Wrong type of calendar.");
1093 if (!JSValueIsObjectOfClass(context, value, JSTZDate::getClassRef())) {
1094 ThrowMsg(ConversionException, "Wrong parameter type.");
1097 TimeUtilConverter converter(context);
1098 long long int dueDate = (long long int) (converter.getTimeInMilliseconds(value)/1000);
1100 task->setEndTime(dueDate);
1102 if( task->getTimeZone().empty() ) {
1103 std::string timeZone = converter.getPropertiesInTZDate(value).timezone;
1104 task->setTimeZone(timeZone);
1110 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
1111 DeviceAPI::Common::JSTizenExceptionFactory::postException(context, exception, DeviceAPI::Common::JSTizenException::TYPE_MISMATCH_ERROR);
1117 JSValueRef JSCalendarItemProperties::getPropertyCompletedDate(JSContextRef context,
1119 JSStringRef propertyName,
1120 JSValueRef* exception)
1124 CalendarItemPropertiesPrivObject *privateObject =
1125 static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(object));
1126 CalendarEventPtr task = privateObject->getObject();
1127 if(CalendarEvent::TASK_TYPE != task->getCalendarType()) {
1128 return JSValueMakeUndefined(context);
1131 ThrowMsg(NullPointerException, "Task object is NULL.");
1134 if (UNDEFINED_TIME==task->getCompletedDate()) {
1135 return JSValueMakeUndefined(context);
1137 TimeUtilConverter timeConverter(context);
1138 return timeConverter.toJSValueRefTZDate((double)(task->getCompletedDate()*1000.0), task->getTimeZone());
1143 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
1145 return JSValueMakeUndefined(context);
1148 bool JSCalendarItemProperties::setPropertyCompletedDate(JSContextRef context,
1150 JSStringRef propertyName,
1152 JSValueRef* exception)
1156 CalendarEventPtr task = getPrivateObject(object);
1158 ThrowMsg(NullPointerException, "Task object is NULL.");
1160 if(CalendarEvent::TASK_TYPE != task->getCalendarType()) {
1161 ThrowMsg(InvalidArgumentException, "Wrong calendar type.");
1163 if (!JSValueIsObjectOfClass(context, value, JSTZDate::getClassRef())) {
1164 ThrowMsg(ConversionException, "Wrong parameter type.");
1167 TimeUtilConverter converter(context);
1168 long long int completedDate = (long long int) (converter.getTimeInMilliseconds(value)/1000);
1170 task->setCompletedDate(completedDate);
1172 if( task->getTimeZone().empty() ) {
1173 std::string timeZone = converter.getPropertiesInTZDate(value).timezone;
1174 task->setTimeZone(timeZone);
1180 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
1181 DeviceAPI::Common::JSTizenExceptionFactory::postException(context, exception, DeviceAPI::Common::JSTizenException::TYPE_MISMATCH_ERROR);
1187 JSValueRef JSCalendarItemProperties::getPropertyProgress(JSContextRef context,
1189 JSStringRef propertyName,
1190 JSValueRef* exception)
1194 CalendarEventPtr task = getPrivateObject(object);
1195 if(CalendarEvent::TASK_TYPE != task->getCalendarType()) {
1196 return JSValueMakeUndefined(context);
1199 Converter converter(context);
1200 return converter.toJSValueRef(task->getProgress());
1204 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
1206 return JSValueMakeUndefined(context);
1209 bool JSCalendarItemProperties::setPropertyProgress(JSContextRef context,
1211 JSStringRef propertyName,
1213 JSValueRef* exception)
1217 CalendarEventPtr task = getPrivateObject(object);
1218 if(CalendarEvent::TASK_TYPE != task->getCalendarType()) {
1219 return JSValueMakeUndefined(context);
1222 Converter converter(context);
1223 int progress = converter.toInt(value);
1224 task->setProgress(progress);
1229 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
1230 DeviceAPI::Common::JSTizenExceptionFactory::postException(context, exception, DeviceAPI::Common::JSTizenException::TYPE_MISMATCH_ERROR);
1236 JSValueRef JSCalendarItemProperties::getPropertyPriority(JSContextRef context,
1238 JSStringRef propertyName,
1239 JSValueRef* exception)
1243 CalendarConverter converter(context);
1244 CalendarEventPtr item = getPrivateObject(object);
1246 ThrowMsg(NullPointerException, "Item object is NULL.");
1249 std::string priority = converter.toTizenValue(item->getPriority());
1250 return converter.toJSValueRef(priority);
1254 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
1256 return JSValueMakeUndefined(context);
1259 bool JSCalendarItemProperties::setPropertyPriority(JSContextRef context,
1261 JSStringRef propertyName,
1263 JSValueRef* exception)
1265 CalendarEventPtr item = getPrivateObject(object);
1268 CalendarConverter converter(context);
1269 CalendarEvent::TaskPriority priority =
1270 converter.toTaskPriority(converter.toString(value));
1271 item->setPriority(priority);
1276 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
1277 DeviceAPI::Common::JSTizenExceptionFactory::postException(context, exception, DeviceAPI::Common::JSTizenException::TYPE_MISMATCH_ERROR);
1283 JSValueRef JSCalendarItemProperties::getPropertyEndDate(JSContextRef context,
1285 JSStringRef propertyName,
1286 JSValueRef* exception)
1290 CalendarItemPropertiesPrivObject *privateObject =
1291 static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(object));
1292 CalendarEventPtr event = privateObject->getObject();
1293 if(CalendarEvent::EVENT_TYPE != event->getCalendarType()) {
1294 return JSValueMakeUndefined(context);
1297 ThrowMsg(NullPointerException, "Event object is NULL.");
1300 if (UNDEFINED_TIME==event->getEndTime()) {
1301 return JSValueMakeUndefined(context);
1303 TimeUtilConverter timeConverter(context);
1304 return timeConverter.toJSValueRefTZDate((double)(event->getEndTime()*1000.0), event->getTimeZone());
1309 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
1311 return JSValueMakeUndefined(context);
1314 bool JSCalendarItemProperties::setPropertyEndDate(JSContextRef context,
1316 JSStringRef propertyName,
1318 JSValueRef* exception)
1322 CalendarEventPtr event = getPrivateObject(object);
1324 ThrowMsg(NullPointerException, "Event object is NULL.");
1326 if(CalendarEvent::EVENT_TYPE != event->getCalendarType()) {
1327 ThrowMsg(InvalidArgumentException, "Wrong calendar type.");
1329 if (!JSValueIsObjectOfClass(context, value, JSTZDate::getClassRef())) {
1330 ThrowMsg(ConversionException, "Wrong parameter type.");
1333 TimeUtilConverter converter(context);
1334 long long int endDate = (long long int) (converter.getTimeInMilliseconds(value)/1000);
1336 event->setEndTime(endDate);
1338 if( event->getTimeZone().empty() ) {
1339 std::string timeZone = converter.getPropertiesInTZDate(value).timezone;
1340 event->setTimeZone(timeZone);
1346 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
1347 DeviceAPI::Common::JSTizenExceptionFactory::postException(context, exception, DeviceAPI::Common::JSTizenException::TYPE_MISMATCH_ERROR);
1353 JSValueRef JSCalendarItemProperties::getPropertyLastModificationDate(JSContextRef context,
1355 JSStringRef propertyName,
1356 JSValueRef* exception)
1360 CalendarEventPtr item = getPrivateObject(object);
1362 ThrowMsg(NullPointerException, "Item object is NULL.");
1365 if (UNDEFINED_TIME==item->getLastModifiedDate()) {
1366 return JSValueMakeNull(context);
1368 TimeUtilConverter timeConverter(context);
1369 return timeConverter.toJSValueRefTZDate((double)(item->getLastModifiedDate()*1000.0), item->getTimeZone());
1374 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
1376 return JSValueMakeUndefined(context);
1379 JSValueRef JSCalendarItemProperties::getPropertyCalendarId(JSContextRef context,
1381 JSStringRef propertyName,
1382 JSValueRef* exception)
1386 CalendarEventPtr item = getPrivateObject(object);
1388 if (UNDEFINED_CALENDAR_ID==item->getCalendarId()) {
1389 return JSValueMakeNull(context);
1391 CalendarConverter converter(context);
1392 std::stringstream ss;
1393 ss<<item->getCalendarId();
1394 return converter.toJSValueRef(ss.str());
1400 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
1402 return JSValueMakeUndefined(context);
1405 bool JSCalendarItemProperties::validate(JSContextRef ctx,
1406 const JSObjectRef object,
1407 JSValueRef* exception)
1409 CalendarItemPropertiesPrivObject *priv =
1410 static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(object));
1414 CalendarEventPtr event = priv->getObject();
1418 return event->validate();