3 Copyright (c) 2000-2012 Samsung Electronics Co., Ltd All Rights Reserved
5 This file is part of org.tizen.efl-calendar
6 Written by Taeho Kang <taeho84.kang@samsung.com>
8 PROPRIETARY/CONFIDENTIAL
10 This software is the confidential and proprietary information of
11 SAMSUNG ELECTRONICS ("Confidential Information"). You shall not
12 disclose such Confidential Information and shall use it only in
13 accordance with the terms of the license agreement you entered
14 into with SAMSUNG ELECTRONICS.
16 SAMSUNG make no representations or warranties about the suitability
17 of the software, either express or implied, including but not limited
18 to the implied warranties of merchantability, fitness for a particular
19 purpose, or non-infringement. SAMSUNG shall not be liable for any
20 damages suffered by licensee as a result of using, modifying or
21 distributing this software or its derivatives.
30 #include <wav_player.h>
34 #include "view-ring.h"
36 #define DEFAULT_TONE RESDIR "/sounds/On_time.wav"
37 #define CAL_ALARM_RING_TIMER 60.0
39 static const char *_name = "ring";
57 static void __cal_ring_set_window_property(Evas_Object *win)
61 w = elm_win_xwindow_get(win);
63 ecore_x_netwm_window_type_set(w, ECORE_X_WINDOW_TYPE_NOTIFICATION);
64 utilx_set_system_notification_level(ecore_x_display_get(), w, UTILX_NOTIFICATION_LEVEL_NORMAL);
67 static void __cal_ring_stop_alarm(cal_ring_data *p)
72 wav_player_stop(p->mm_id);
82 static void __cal_ring_window_delete_callback(void *data, Evas *e, Evas_Object *obj, void *event)
86 c_retm_if(!data, "data is null");
88 cal_ring_data *p = data;
90 __cal_ring_stop_alarm(p);
93 ecore_timer_del(p->tmr);
96 CALENDAR_SVC_FREE_CS_LIST(&p->cslist);
98 struct appdata *ad = p->ad;
100 ad->alarm_window = NULL;
105 static void __cal_ring_fill_cs(cal_struct *cs, Evas_Object *ly)
107 c_retm_if(!cs, "cs is null");
108 c_retm_if(!ly, "ly is null");
110 const char *str = CALENDAR_SVC_STRUCT_GET_STR(cs, CAL_VALUE_TXT_SUMMARY);
111 if (!CAL_STRLEN(str))
112 str = C_("IDS_CLD_BODY_NO_TITLE");
114 const char *prev_title = edje_object_part_text_get(CAL_UTIL_GET_EDJ_DATA(ly), "text/title");
115 if (CAL_STRLEN(prev_title)) {
116 char buffer[512] = {0};
117 snprintf(buffer, sizeof(buffer), "%s, %s", prev_title, str);
119 edje_object_part_text_set(CAL_UTIL_GET_EDJ_DATA(ly), "text/title", buffer);
121 edje_object_part_text_set(CAL_UTIL_GET_EDJ_DATA(ly), "text/title", str);
124 time_t now = time(NULL);
125 localtime_r(&now, &tm);
127 cal_util_set_time_text(CAL_UTIL_GET_EDJ_DATA(ly), "text/currenttime", NULL, CAL_UTIL_TIME_FORMAT_1, &tm);
129 cal_util_emit_signal(CAL_UTIL_GET_EDJ_DATA(ly), "min,%02d", tm.tm_min);
132 const char *ampm = NULL;
134 if (tm.tm_hour < 12) {
139 hour = tm.tm_hour - 12;
142 cal_util_emit_signal(CAL_UTIL_GET_EDJ_DATA(ly), "hour,%02d", hour * 5 + (tm.tm_min / 12));
143 edje_object_signal_emit(CAL_UTIL_GET_EDJ_DATA(ly), ampm, "prog");
147 static void __cal_ring_play_alarm_completed_cb(int id, void *user_data)
151 c_retm_if(!user_data, "user_data is NULL");
153 cal_ring_data *p = user_data;
160 wav_player_start(p->ring_path, SOUND_TYPE_RINGTONE, __cal_ring_play_alarm_completed_cb, p, &mm_id);
165 static void __cal_ring_play_alarm(cal_ring_data *p, const char *path)
167 c_retm_if(!p, "p is NULL.");
168 c_retm_if(!path, "path is NULL.");
170 __cal_ring_stop_alarm(p);
172 p->ring_path = strdup(path);
175 int r = wav_player_start(path, SOUND_TYPE_RINGTONE, __cal_ring_play_alarm_completed_cb, p, &mm_id);
176 c_retm_if(r!= WAV_PLAYER_ERROR_NONE, "wav_player_start is failed.");
181 static void __cal_ring_fill(cal_ring_data *p)
183 c_retm_if(!p, "p is null");
184 c_retm_if(!p->cslist, "p->cslist is null");
187 cal_struct *cs = NULL;
189 EINA_LIST_FOREACH (p->cslist, l, cs) {
196 __cal_ring_fill_cs(cs, p->ly);
200 int r = CALENDAR_SVC_STRUCT_GET_LIST(cs, CAL_VALUE_LST_ALARM, &al);
201 if (r != CAL_SUCCESS) {
202 ERR("CALENDAR_SVC_STRUCT_GET_LIST() is failed(%d)", r);
207 int count = g_list_length(al);
208 c_retm_if(!count, "length of alarm list is 0");
210 cal_value *val = al->data;
211 c_retm_if(!val, "data of alarm list is null");
213 const char *tone = CALENDAR_SVC_VALUE_GET_STR(val, CAL_VALUE_TXT_ALARMS_TONE);
215 if (!CAL_STRLEN(tone))
218 __cal_ring_play_alarm(p, tone);
221 CALENDAR_SVC_STRUCT_FREE(&cs);
224 CALENDAR_SVC_FREE_CS_LIST(&p->cslist);
227 static void __cal_ring_stop_button_callback(void *data, Evas_Object *eo, const char *e, const char *s)
231 c_retm_if(!data, "data is null");
233 cal_ring_data *p = data;
240 evas_object_del(p->win);
243 static Evas_Object* __cal_ring_create_view(struct appdata *ad)
245 c_retvm_if(!ad, NULL, "ad is null");
247 cal_ring_data *p = NULL;
249 if (ad->alarm_window) {
250 p = CAL_UTIL_GET_PRIV_DATA (ad->alarm_window);
251 c_retvm_if(!p, NULL, "p is null");
253 return ad->alarm_window;
256 p = calloc(1, sizeof(cal_ring_data));
257 c_retvm_if(!p, NULL, "p is null");
263 p->win = cal_util_add_window(CALENDAR_RING , NULL, NULL);
266 ERR("cal_util_add_window(CALENDAR_RING, NULL, NULL) is failed");
271 ad->alarm_window = p->win;
273 __cal_ring_set_window_property(p->win);
274 evas_object_data_set(p->win, "priv", p);
276 p->ly = cal_util_add_layout(p->win, p->name);
279 ERR("cal_util_add_layout() is failed");
280 evas_object_del(p->win);
285 elm_win_resize_object_add(p->win, p->ly);
287 edje_object_part_text_set(CAL_UTIL_GET_EDJ_DATA(p->ly), "text/stop", _("Stop"));
288 edje_object_signal_callback_add(CAL_UTIL_GET_EDJ_DATA(p->ly), "stop", "edj", __cal_ring_stop_button_callback, p);
290 evas_object_event_callback_add(p->win, EVAS_CALLBACK_DEL, __cal_ring_window_delete_callback, p);
292 pm_change_state(LCD_NORMAL);
294 evas_object_show(p->win);
299 static Eina_Bool __cal_ring_timer_callback(void *data)
303 c_retvm_if(!data, ECORE_CALLBACK_CANCEL, "data is null");
305 cal_ring_data *p = data;
307 __cal_ring_stop_alarm(p);
309 evas_object_del(p->win);
313 return ECORE_CALLBACK_CANCEL;
316 static int __cal_ring_append_alarm(Evas_Object *win, Eina_List *cslist)
318 c_retvm_if(!win, -1, "win is null");
319 c_retvm_if(!cslist, -1, "cslist is null");
321 cal_ring_data *p = CAL_UTIL_GET_PRIV_DATA(win);
322 c_retvm_if(!p, -1, "p is null");
324 p->cslist = eina_list_merge(p->cslist, cslist);
329 ecore_timer_del(p->tmr);
331 p->tmr = ecore_timer_add(CAL_ALARM_RING_TIMER, __cal_ring_timer_callback, p);
332 c_retvm_if(!p->tmr, -1, "p->tmr is null");
337 int cal_ring_add_alarm(struct appdata *ad, Eina_List *cslist)
339 c_retvm_if(!ad, -1, "ad is null");
340 c_retvm_if(!cslist, -1, "csl is null");
342 Evas_Object *win = __cal_ring_create_view(ad);
343 c_retvm_if(!win, -1, "__cal_ring_create_view returned null");
345 return __cal_ring_append_alarm(win, cslist);