Update change log and spec for wrt-plugins-tizen_0.2.84
[framework/web/wrt-plugins-tizen.git] / src / platform / Tizen / Calendar / EventWrapper.cpp
index 9065f34..63a9df5 100755 (executable)
@@ -281,7 +281,7 @@ void EventWrapper::deleteEvent()
             ThrowMsg(PlatformException, "Can't delete the instance. Error code " << error);
         }
 
-        m_abstractEvent->getRecurrenceRule()->getExceptions().push_back(recurrenceId);
+        (*m_abstractEvent->getRecurrenceRule()->getExceptions()).push_back(recurrenceId);
         LogDebug("The recurring event is updated.");
     }
 }
@@ -544,7 +544,7 @@ void EventWrapper::setRecurrenceRuleToPlatformEvent()
     }
     case EventRecurrenceRule::YEARLY_RECURRENCE:
     {
-        if(CAL_SUCCESS!=calendar_svc_struct_set_int(m_platformEvent, CALS_VALUE_INT_RRULE_FREQ, CAL_REPEAT_EVERY_YEAR)) {
+        if(CAL_SUCCESS!=calendar_svc_struct_set_int(m_platformEvent, CALS_VALUE_INT_RRULE_FREQ, CALS_FREQ_YEARLY)) {
             ThrowMsg(PlatformException, "Failed setting frequency.");
         }
         break;
@@ -556,12 +556,12 @@ void EventWrapper::setRecurrenceRuleToPlatformEvent()
     }
 
     // set byday
-    std::vector<std::string> daysOfTheWeek = rrule->getDaysOfTheWeek();
-    if( 0 != daysOfTheWeek.size() ) {
+    StringArrayPtr daysOfTheWeek = rrule->getDaysOfTheWeek();
+    if( 0 != daysOfTheWeek->size() ) {
         std::string byday = "";
-        for(unsigned int i=0; i<daysOfTheWeek.size(); i++) {
-            byday.append(daysOfTheWeek.at(i));
-            if(i!=daysOfTheWeek.size()-1) {
+        for(unsigned int i=0; i<daysOfTheWeek->size(); i++) {
+            byday.append(daysOfTheWeek->at(i));
+            if(i!=daysOfTheWeek->size()-1) {
                 byday.append(",");
             }
         }
@@ -586,17 +586,17 @@ void EventWrapper::setRecurrenceRuleToPlatformEvent()
     }
 
     // set the exceptions
-    if ( !rrule->getExceptions().empty() )
+    if ( !rrule->getExceptions()->empty() )
     {
-        LogInfo("Set the exceptions of length: "<<rrule->getExceptions().size());
+        LogInfo("Set the exceptions of length: "<<rrule->getExceptions()->size());
 
         std::string exdate = "";
-        for( unsigned int i=0; i<rrule->getExceptions().size(); i++ )
+        for( unsigned int i=0; i<rrule->getExceptions()->size(); i++ )
         {
             std::stringstream ss;
-            ss<<rrule->getExceptions().at(i);
+            ss<<rrule->getExceptions()->at(i);
             exdate.append(ss.str());
-            if(i!=rrule->getExceptions().size()-1) {
+            if(i!=rrule->getExceptions()->size()-1) {
                 exdate.append(",");
             }
         }
@@ -637,50 +637,89 @@ void EventWrapper::setAlarmsToPlatformEvent()
         ThrowMsg(UnknownException, "Null platform pointer.");
     }
 
-    if( 0 != m_abstractEvent->getAlarmsTick().size() ) {
+    if( 0 != m_abstractEvent->getAlarms()->size() ) {
+        int errorCode;
         GList* list = NULL;
         calendar_svc_struct_get_list(m_platformEvent, CAL_VALUE_LST_ALARM, &list);
 
-        for( unsigned int i=0; i<m_abstractEvent->getAlarmsTick().size(); i++ )
+        for( unsigned int i=0; i<m_abstractEvent->getAlarms()->size(); i++ )
         {
             LogInfo("Set the alarms #"<<i);
+            EventAlarmPtr theAlarm = m_abstractEvent->getAlarms()->at(i);
 
             cal_value *value = calendar_svc_value_new(CAL_VALUE_LST_ALARM);
 
-            // We have to use alarm tick and tick unit for alarm creation.
-            int errorCode = calendar_svc_value_set_int(
-                    value,
-                    CAL_VALUE_INT_ALARMS_TICK,
-                    m_abstractEvent->getAlarmsTick().at(i));
-            if (CAL_SUCCESS != errorCode) {
-                if (value) {
-                    calendar_svc_value_free(&value);
+            cal_sch_remind_tick_unit_t tickUnit = CAL_SCH_TIME_UNIT_OFF;
+            int tick = 0;
+            if( UNDEFINED_TIME!=theAlarm->getAbsoluteDate() ) {
+                tickUnit = CAL_SCH_TIME_UNIT_SPECIFIC;
+            } else {
+                if( TizenApis::Api::TimeUtil::MSECS_UNIT==theAlarm->getDuration().unit ) {
+                    tickUnit = CAL_SCH_TIME_UNIT_MIN; // minimum calendar time unit.
+                    tick = theAlarm->getDuration().length / 60000;
+                } else if( TizenApis::Api::TimeUtil::SECONDS_UNIT==theAlarm->getDuration().unit ) {
+                    tickUnit = CAL_SCH_TIME_UNIT_MIN;
+                    tick = theAlarm->getDuration().length / 1000;
+                } else if( TizenApis::Api::TimeUtil::MINUTES_UNIT==theAlarm->getDuration().unit ) {
+                    tickUnit = CAL_SCH_TIME_UNIT_MIN;
+                    tick = theAlarm->getDuration().length;
+                } else if( TizenApis::Api::TimeUtil::HOURS_UNIT==theAlarm->getDuration().unit ) {
+                    tickUnit = CAL_SCH_TIME_UNIT_HOUR;
+                    tick = theAlarm->getDuration().length;
+                } else if( TizenApis::Api::TimeUtil::DAYS_UNIT==theAlarm->getDuration().unit ) {
+                    tickUnit = CAL_SCH_TIME_UNIT_DAY;
+                    tick = theAlarm->getDuration().length;
+                } else {
+                    LogError("Wrong alarm time unit: "<<theAlarm->getDuration().unit);
+                }
+            }
+
+            if( CAL_SCH_TIME_UNIT_SPECIFIC==tickUnit ) {
+                long long int time = theAlarm->getAbsoluteDate();
+                LogInfo("Save absolute date: "<<time);
+                errorCode = calendar_svc_value_set_lli(value,
+                        CAL_VALUE_LLI_ALARMS_TIME,
+                        time);
+                if (CAL_SUCCESS != errorCode) {
+                    if (value) {
+                        calendar_svc_value_free(&value);
+                    }
+                    ThrowMsg(PlatformException, "Can't set alarm time: "<<errorCode);
+                }
+            } else {
+                errorCode = calendar_svc_value_set_int(
+                        value,
+                        CAL_VALUE_INT_ALARMS_TICK,
+                        tick);
+                if (CAL_SUCCESS != errorCode) {
+                    if (value) {
+                        calendar_svc_value_free(&value);
+                    }
+                    ThrowMsg(PlatformException, "Can't set alarm tick: "<<errorCode);
                 }
-                LogError("Can't set CAL_VALUE_INT_ALARMS_TICK, error: " << errorCode);
-                ThrowMsg(PlatformException, "Can't set alarm tick.");
             }
+
             errorCode = calendar_svc_value_set_int(
                     value,
                     CAL_VALUE_INT_ALARMS_TICK_UNIT,
-                    CAL_SCH_TIME_UNIT_MIN);
+                    tickUnit);
             if (CAL_SUCCESS != errorCode) {
                 if (value) {
                     calendar_svc_value_free(&value);
                 }
-                LogError("Can't set CAL_VALUE_INT_ALARMS_TICK_UNIT, error: " << errorCode);
-                ThrowMsg(PlatformException, "Can't set alarm tick unit.");
+                ThrowMsg(PlatformException, "Can't set alarm tick unit: "<<errorCode);
             }
 
             // Set the alarm type.
             cal_alert_type_t alarmType = CAL_ALERT_MELODY;
-            switch (m_abstractEvent->getAlarmsType().at(i)) {
-            case CalendarEvent::NO_ALARM:
+            switch (theAlarm->getMethods().at(0)) {
+            case EventAlarm::NO_ALARM:
                 alarmType = CAL_ALERT_MUTE;
                 break;
-            case CalendarEvent::SOUND_ALARM:
+            case EventAlarm::SOUND_ALARM:
                 alarmType = CAL_ALERT_MELODY;
                 break;
-            case CalendarEvent::SILENT_ALARM:
+            case EventAlarm::SILENT_ALARM:
                 alarmType = CAL_ALERT_VIBRATION;
                 break;
             default:
@@ -695,21 +734,19 @@ void EventWrapper::setAlarmsToPlatformEvent()
                 if (value) {
                     calendar_svc_value_free(&value);
                 }
-                LogError("Can't set CAL_VALUE_INT_ALARMS_TYPE, error: " << errorCode);
-                ThrowMsg(PlatformException, "Can't set alarm type.");
+                ThrowMsg(PlatformException, "Can't set alarm type: "<<errorCode);
             }
 
             // Set the display text
             errorCode = calendar_svc_value_set_str(
                     value,
                     CAL_VALUE_TXT_ALARMS_DESCRIPTION,
-                    m_abstractEvent->getAlarmsDescription().at(i).c_str());
+                    theAlarm->getDescription().c_str());
             if (CAL_SUCCESS != errorCode) {
                 if (value) {
                     calendar_svc_value_free(&value);
                 }
-                LogError("Can't set CAL_VALUE_TXT_ALARMS_DESCRIPTION, error: " << errorCode);
-                ThrowMsg(PlatformException, "Can't set alarm description.");
+                ThrowMsg(PlatformException, "Can't set alarm description: "<<errorCode);
             }
 
             list = g_list_append(list, value);
@@ -1123,6 +1160,7 @@ void EventWrapper::setAttendeesToPlatformEvent()
             std::stringstream ss(attendeeList->at(i)->getAddressBookId());
             int addressBookId;
             ss>>addressBookId;
+            LogInfo("addressBookId: "<<addressBookId);
             if (CAL_SUCCESS !=
                 calendar_svc_value_set_int(attendee, CAL_VALUE_INT_ATTENDEE_DETAIL_CT_INDEX,
                                            addressBookId)) {
@@ -1382,19 +1420,19 @@ void EventWrapper::setRecurrenceRuleFromPlatformEvent()
     }
 
     // load the byday
-    std::vector<std::string> daysOfTheWeek;
+    StringArrayPtr daysOfTheWeek(new StringArray());
     char* byday = calendar_svc_struct_get_str(m_platformEvent, CALS_VALUE_TXT_RRULE_BYDAY);
     LogInfo("Loaded byday: "<<byday);
     if (byday) {
         char *saveptr = NULL;
         char* pch = strtok_r(byday, ",", &saveptr);
         while (NULL != pch) {
-            daysOfTheWeek.push_back(pch);
+            (*daysOfTheWeek).push_back(pch);
             pch = strtok_r(NULL, ",", &saveptr);
         }
     }
     rrule->setDaysOfTheWeek(daysOfTheWeek);
-    LogInfo("Number of daysOfTheWeek: "<<rrule->getDaysOfTheWeek().size());
+    LogInfo("Number of daysOfTheWeek: "<<rrule->getDaysOfTheWeek()->size());
 
     // load the recurrence interval
     int interval = calendar_svc_struct_get_int(m_platformEvent, CALS_VALUE_INT_RRULE_INTERVAL);
@@ -1410,7 +1448,7 @@ void EventWrapper::setRecurrenceRuleFromPlatformEvent()
     LogDebug("endDate from platform = " << endDate);
 
     // load the exceptions
-    std::vector<long long int> exceptions;
+    NumberArrayPtr exceptions(new NumberArray());
     char* exdate = calendar_svc_struct_get_str(m_platformEvent, CAL_VALUE_TXT_EXDATE);
     LogInfo("Loaded exdate: "<<exdate);
     if (exdate) {
@@ -1420,12 +1458,12 @@ void EventWrapper::setRecurrenceRuleFromPlatformEvent()
             std::stringstream ss(pch);
             long long int oneException;
             ss>>oneException;
-            exceptions.push_back(oneException);
+            (*exceptions).push_back(oneException);
             pch = strtok_r(NULL, ",", &saveptr);
         }
     }
     rrule->setExceptions(exceptions);
-    LogInfo("Number of exceptions: "<<rrule->getExceptions().size());
+    LogInfo("Number of exceptions: "<<rrule->getExceptions()->size());
 
     // set the loaded recurrence rule
     m_abstractEvent->setRecurrenceRule(rrule);
@@ -1437,59 +1475,94 @@ void EventWrapper::setAlarmsFromPlatformEvent()
         ThrowMsg(UnknownException, "Null platform pointer.");
     }
 
-    std::vector<long> alarmsTick;
-    std::vector<CalendarEvent::EventAlarmType> alarmsType;
-    std::vector<std::string> alarmsDescription;
-
     GList* alarmList = NULL;
     calendar_svc_struct_get_list(m_platformEvent, CAL_VALUE_LST_ALARM, &alarmList);
     cal_value* alarmValue = NULL;
+    int tick, tickUnit;
     for (; alarmList; alarmList = g_list_next(alarmList)) {
         LogDebug("Processing alarm...");
         alarmValue = static_cast<cal_value*>(alarmList->data);
 
-        int tick = calendar_svc_value_get_int(alarmValue, CAL_VALUE_INT_ALARMS_TICK);
-        if (CAL_ERR_FAIL == tick) {
-            LogError("Cannot read alarm tick. Stop processing alarms.");
+        EventAlarmPtr theAlarm( new EventAlarm() );
+
+        tickUnit = calendar_svc_value_get_int(alarmValue, CAL_VALUE_INT_ALARMS_TICK_UNIT);
+        if (CAL_ERR_FAIL == tickUnit) {
+            LogError("Cannot read alarm tick unit. Stop processing alarms.");
             return;
         }
-        alarmsTick.push_back(tick);
 
+        if( CAL_SCH_TIME_UNIT_SPECIFIC==tickUnit ) {
+            long long int absoluteDate = calendar_svc_value_get_lli(
+                    alarmValue,
+                    CAL_VALUE_LLI_ALARMS_TIME);
+            if (CAL_ERR_FAIL == absoluteDate) {
+                LogError("Cannot read alarm time. Stop processing alarms.");
+                return;
+            }
+            LogInfo("Load absolute date: "<<absoluteDate);
+            theAlarm->setAbsoluteDate(absoluteDate);
+        } else {
+            tick = calendar_svc_value_get_int(alarmValue, CAL_VALUE_INT_ALARMS_TICK);
+            if (CAL_ERR_FAIL == tick) {
+                LogError("Cannot read alarm tick. Stop processing alarms.");
+                return;
+            }
+
+            TizenApis::Api::TimeUtil::DurationProperties duration;
+            if( CAL_SCH_TIME_UNIT_MIN==tickUnit ) {
+                duration.unit = TizenApis::Api::TimeUtil::MINUTES_UNIT;
+                duration.length = tick;
+            } else if( CAL_SCH_TIME_UNIT_HOUR==tickUnit ) {
+                duration.unit = TizenApis::Api::TimeUtil::HOURS_UNIT;
+                duration.length = tick;
+            } else if( CAL_SCH_TIME_UNIT_DAY==tickUnit ) {
+                duration.unit = TizenApis::Api::TimeUtil::DAYS_UNIT;
+                duration.length = tick;
+            } else if( CAL_SCH_TIME_UNIT_WEEK==tickUnit) {
+                duration.unit = TizenApis::Api::TimeUtil::DAYS_UNIT;
+                duration.length = tick*7;
+            } else {
+                LogWarning("Wrong tick unit: "<<tickUnit);
+            }
+
+            theAlarm->setDuration(duration);
+        }
+
+        std::vector<EventAlarm::EventAlarmType> methods;
         cal_alert_type_t type = static_cast<cal_alert_type_t>(calendar_svc_value_get_int(alarmValue, CAL_VALUE_INT_ALARMS_TYPE));
         if ( 0 > type) {
             LogError("Cannot read alarm type. Setting the default value.");
         }
         switch (type) {
         case CAL_ALERT_VIBRATION:
-            alarmsType.push_back(CalendarEvent::SILENT_ALARM);
+            methods.push_back(EventAlarm::SILENT_ALARM);
             break;
         case CAL_ALERT_MELODY:
         case CAL_ALERT_INCREASING_MELODY:
         case CAL_ALERT_VIBRATION_THEN_MELODY:
         case CAL_ALERT_VIBMELODY:
         case CAL_ALERT_VIB_INCREASING_MELODY:
-            alarmsType.push_back(CalendarEvent::SOUND_ALARM);
+            methods.push_back(EventAlarm::SOUND_ALARM);
             break;
         case CAL_ALERT_MUTE:
         default:
-            alarmsType.push_back(CalendarEvent::NO_ALARM);
+            methods.push_back(EventAlarm::NO_ALARM);
             break;
         }
+        theAlarm->setMethods(methods);
 
         char* description = calendar_svc_value_get_str(alarmValue, CAL_VALUE_TXT_ALARMS_DESCRIPTION);
         if (NULL == description) {
-            LogError("Cannot read alarm description. Setting NULL.");
-            alarmsDescription.push_back("");
+            LogError("Cannot read alarm description. Setting empty string.");
+            theAlarm->setDescription("");
         } else {
-            alarmsDescription.push_back(description);
+            theAlarm->setDescription(description);
         }
 
-        // Save the vectors.
-        m_abstractEvent->setAlarmsTick(alarmsTick);
-        m_abstractEvent->setAlarmsType(alarmsType);
-        m_abstractEvent->setAlarmsDescription(alarmsDescription);
+        // Save the alarm.
+        m_abstractEvent->getAlarms()->push_back(theAlarm);
     }
-    LogInfo("Number of alarms: "<<m_abstractEvent->getAlarmsTick().size());
+    LogInfo("Number of alarms: "<<m_abstractEvent->getAlarms()->size());
 }
 
 void EventWrapper::setStatusFromPlatformEvent()
@@ -1858,6 +1931,7 @@ void EventWrapper::setAttendeesFromPlatformEvent()
 
         // load addressBookId
         int attendeeAddressBookId = calendar_svc_value_get_int(attendee, CAL_VALUE_INT_ATTENDEE_DETAIL_CT_INDEX);
+        LogInfo("attendeeAddressBookId: "<<attendeeAddressBookId);
         if ( 0>attendeeAddressBookId) {
             LogError("Cannot read attendee address book id. Setting an empty string.");
             attendeeAddressBookId = -1;