3 * Copyright 2012 Samsung Electronics Co., Ltd
5 * Licensed under the Flora License, Version 1.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://floralicense.org/license/
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.
21 static inline void __cal_reminder_get_week_str(int week, char *buf, int sz)
23 snprintf(buf, sz, "%d %s %s", week,C_("IDS_COM_POP_WEEK_LC"), C_("IDS_CLD_BODY_BEFORE_LC"));
26 static inline void __cal_reminder_get_day_str(int day, char *buf, int sz)
28 snprintf(buf, sz, "%d %s %s", day, C_("IDS_COM_POP_DAY_LC"), C_("IDS_CLD_BODY_BEFORE_LC"));
31 static inline void __cal_reminder_get_hour_str(int hour, char *buf, int sz)
33 snprintf(buf, sz, "%d %s %s", hour, S_("IDS_COM_POP_HOUR_LC"), C_("IDS_CLD_BODY_BEFORE_LC"));
36 static inline void __cal_reminder_get_min_str(int min, char *buf, int sz)
38 snprintf(buf, sz, "%d %s %s", min, S_("IDS_COM_BODY_MINUTE_LC"), C_("IDS_CLD_BODY_BEFORE_LC"));
41 static inline void __cal_reminder_get_str(const Cal_Reminder* reminder, char *buf, int sz)
43 int min = reminder->alarm_value;
45 if ((min % _WEEK) == 0) {
46 __cal_reminder_get_week_str(min / _WEEK, buf, sz);
50 if ((min % _DAY) == 0) {
51 __cal_reminder_get_day_str(min / _DAY, buf, sz);
55 if ((min % _HOUR) == 0) {
56 __cal_reminder_get_hour_str(min / _HOUR, buf, sz);
60 __cal_reminder_get_min_str(min, buf, sz);
63 void cal_reminder_get_string(const Cal_Reminder* reminder, char *buf, int size)
68 switch (reminder->tick_unit) {
69 case CALENDAR_ALARM_TIME_UNIT_SPECIFIC:
70 cal_util_get_time_text(buf, size, CAL_UTIL_DATE_FORMAT_1, CAL_UTIL_TIME_FORMAT_5, &reminder->datetime);
72 case CALENDAR_ALARM_NONE:
73 g_snprintf(buf, size, "%s", S_("IDS_COM_BODY_OFF"));
75 case CALENDAR_ALARM_TIME_UNIT_MINUTE:
76 if (reminder->alarm_value == 0)
77 g_snprintf(buf, size, "%s", C_("IDS_CLD_BODY_ON_TIME"));
79 __cal_reminder_get_str(reminder, buf, size);
82 ERR("ERROR!! %d", reminder->tick_unit);
87 Cal_Reminder* cal_reminder_create(calendar_record_h calendar_alarm)
89 c_retv_if(!calendar_alarm, NULL);
91 calendar_error_e error = CALENDAR_ERROR_NONE;
94 error = calendar_record_get_int(calendar_alarm, _calendar_alarm.tick, &tick);
95 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_get_int() is failed(%x)", error);
97 calendar_alarm_time_unit_type_e tick_unit = CALENDAR_ALARM_NONE;
99 error = calendar_record_get_int(calendar_alarm, _calendar_alarm.tick_unit, &tick_unit);
100 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_get_int() is failed(%x)", error);
102 calendar_time_s alarm_time = {0};
104 error = calendar_record_get_lli(calendar_alarm, _calendar_alarm.time, &alarm_time.time.utime);
105 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_get_caltime() is failed(%x)", error);
107 _calendar_show_error(error);
109 Cal_Reminder* reminder = calloc(1, sizeof(Cal_Reminder));
110 c_retv_if(!reminder, NULL);
112 cal_util_convert_lli_to_tm(NULL, alarm_time.time.utime, &reminder->datetime);
114 if (tick_unit == CALENDAR_ALARM_NONE) {
115 reminder->tick_unit = CALENDAR_ALARM_NONE;
119 if (tick_unit == CALENDAR_ALARM_TIME_UNIT_SPECIFIC) {
120 reminder->tick_unit = CALENDAR_ALARM_TIME_UNIT_SPECIFIC;
125 case CALENDAR_ALARM_TIME_UNIT_MONTH:
126 reminder->alarm_value = tick * _DAY * 30; // TODO: BUG!! not used!!
128 case CALENDAR_ALARM_TIME_UNIT_WEEK:
129 reminder->alarm_value = tick * _WEEK;
131 case CALENDAR_ALARM_TIME_UNIT_DAY:
132 reminder->alarm_value = tick * _DAY;
134 case CALENDAR_ALARM_TIME_UNIT_HOUR:
135 reminder->alarm_value = tick * _HOUR;
137 case CALENDAR_ALARM_TIME_UNIT_MINUTE:
138 reminder->alarm_value = tick;
141 reminder->alarm_value = 0;
145 reminder->tick_unit = CALENDAR_ALARM_TIME_UNIT_MINUTE;
150 calendar_record_h cal_reminder_get_cal_val(const Cal_Reminder* reminder)
152 c_retv_if(!reminder, NULL);
154 calendar_record_h calendar_alarm = NULL;
156 calendar_error_e error = CALENDAR_ERROR_NONE;
158 error = calendar_record_create(_calendar_alarm._uri, &calendar_alarm);
159 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_create() is failed(%x)", error);
161 if (reminder->tick_unit == CALENDAR_ALARM_NONE) {
163 error = calendar_record_set_int(calendar_alarm, _calendar_alarm.tick_unit, CALENDAR_ALARM_NONE);
164 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_set_int() is failed(%x)", error);
166 return calendar_alarm;
169 long long int lli_time;
170 cal_util_convert_tm_to_lli(NULL, &reminder->datetime, &lli_time);
172 error = calendar_record_set_lli(calendar_alarm, _calendar_alarm.time, lli_time);
173 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_set_lli() is failed(%x)", error);
175 error = calendar_record_set_int(calendar_alarm, _calendar_alarm.tick_unit, CALENDAR_ALARM_TIME_UNIT_SPECIFIC);
176 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_set_int() is failed(%x)", error);
178 int min = reminder->alarm_value;
180 calendar_alarm_time_unit_type_e tick_unit;
182 if (reminder->tick_unit == CALENDAR_ALARM_TIME_UNIT_SPECIFIC) {
184 tick_unit = CALENDAR_ALARM_TIME_UNIT_SPECIFIC;
185 } else if (min == -1) {
187 tick_unit = CALENDAR_ALARM_TIME_UNIT_MINUTE;
188 } else if ((min % _WEEK) == 0) {
190 tick_unit = CALENDAR_ALARM_TIME_UNIT_WEEK;
191 } else if ((min % _DAY) == 0) {
193 tick_unit = CALENDAR_ALARM_TIME_UNIT_DAY;
194 } else if ((min % _HOUR) == 0) {
196 tick_unit = CALENDAR_ALARM_TIME_UNIT_HOUR;
199 tick_unit = CALENDAR_ALARM_TIME_UNIT_MINUTE;
202 error = calendar_record_set_int(calendar_alarm, _calendar_alarm.tick, tick);
203 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_set_int() is failed(%x)", error);
205 error = calendar_record_set_int(calendar_alarm, _calendar_alarm.tick_unit, tick_unit);
206 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_set_int() is failed(%x)", error);
208 return calendar_alarm;