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"
38 static const char *_name = "ring";
60 static void __cal_ring_set_window_property(Evas_Object *win)
64 w = elm_win_xwindow_get(win);
66 ecore_x_netwm_window_type_set(w, ECORE_X_WINDOW_TYPE_NOTIFICATION);
67 utilx_set_system_notification_level(ecore_x_display_get(), w, UTILX_NOTIFICATION_LEVEL_NORMAL);
70 static void __cal_ring_stop_alarm(cal_ring_data *p)
75 wav_player_stop(p->mm_id);
86 static void __cal_ring_window_delete_callback(void *data, Evas *e, Evas_Object *obj, void *event)
90 c_retm_if(!data, "data is null");
92 cal_ring_data *p = data;
95 ecore_timer_del(p->tmr);
98 CALENDAR_SVC_FREE_CS_LIST(&p->cslist);
103 static void __cal_ring__cal_ring_fill_cs(cal_struct *cs, Evas_Object *ly)
111 str = CALENDAR_SVC_STRUCT_GET_STR(cs, CAL_VALUE_TXT_SUMMARY);
113 str = C_("IDS_CLD_BODY_NO_TITLE");
115 edje_object_part_text_set(CAL_UTIL_GET_EDJ_DATA(ly), "text/title", str);
118 localtime_r(&now, &tm);
120 cal_util_set_time_text(CAL_UTIL_GET_EDJ_DATA(ly), "text/ampm", NULL, CAL_UTIL_TIME_FORMAT_4, &tm);
121 cal_util_set_time_text(CAL_UTIL_GET_EDJ_DATA(ly), "text/currenttime", NULL, CAL_UTIL_TIME_FORMAT_2, &tm);
123 cal_util_emit_signal(CAL_UTIL_GET_EDJ_DATA(ly), "min,%02d", tm.tm_min);
133 hour = tm.tm_hour - 12;
136 cal_util_emit_signal(CAL_UTIL_GET_EDJ_DATA(ly), "hour,%02d", hour * 5 + (tm.tm_min / 12));
137 edje_object_signal_emit(CAL_UTIL_GET_EDJ_DATA(ly), ampm, "prog");
141 static void __cal_ring_play_alarm_completed_cb(int id, void *user_data)
145 c_retm_if(NULL == user_data, "user_data is NULL");
146 cal_ring_data *p = user_data;
148 if (0 == p->is_stop) {
149 wav_player_start(p->ring_path, SOUND_TYPE_RINGTONE, __cal_ring_play_alarm_completed_cb, p, &mm_id);
152 evas_object_del(p->win);
157 static void __cal_ring_play_alarm(cal_ring_data *p, const char *path)
159 c_retm_if(NULL == p, "p is NULL.");
160 c_retm_if(NULL == path, "path is NULL.");
165 __cal_ring_stop_alarm(p);
167 p->ring_path = strdup(path);
169 r = wav_player_start(path, SOUND_TYPE_RINGTONE, __cal_ring_play_alarm_completed_cb, p, &mm_id);
170 c_retm_if(r!= WAV_PLAYER_ERROR_NONE, "wav_player_start is failed.");
177 static void __cal_ring_fill(cal_ring_data *p)
180 const char *tone = NULL;
186 return; // aleady exist
189 return; // TODO: exit??
191 cs = eina_list_data_get(p->cslist);
193 return; // TODO: exit??
195 __cal_ring__cal_ring_fill_cs(cs, p->ly);
196 p->cid = CALENDAR_SVC_STRUCT_GET_INT(cs, CAL_VALUE_INT_INDEX);
197 DBG("Current event id: %d", p->cid);
199 CALENDAR_SVC_STRUCT_GET_LIST(cs, CAL_VALUE_LST_ALARM, &al);
202 cnt = g_list_length(al);
203 c_retm_if(!cnt, "length of alarm list is 0");
206 c_retm_if(!val, "data of alarm list is null");
208 tone = CALENDAR_SVC_VALUE_GET_STR(val, CAL_VALUE_TXT_ALARMS_TONE);
211 if (!tone || tone[0] == '\0')
214 DBG("Ring tone: %s", tone);
215 __cal_ring_play_alarm(p, tone);
217 p->cslist = eina_list_remove(p->cslist, cs);
218 CALENDAR_SVC_STRUCT_FREE(&cs);
221 static void __cal_ring_stop_button_callback(void *data, Evas_Object *eo, const char *e, const char *s)
225 c_retm_if(!data, "data is null");
227 cal_ring_data *p = data;
237 evas_object_del(p->win);
242 static Evas_Object* __cal_ring_create_view(struct appdata *ad)
244 c_retvm_if(!ad, NULL, "ad is null");
246 cal_ring_data *p = calloc(1, sizeof(cal_ring_data));
247 c_retvm_if(!p, NULL, "p is null");
254 p->win = cal_util_add_window(CALENDAR_RING , NULL, NULL);
257 ERR("cal_util_add_window(CALENDAR_RING, NULL, NULL) is failed");
262 __cal_ring_set_window_property(p->win);
263 evas_object_data_set(p->win, "priv", p);
265 p->ly = cal_util_add_layout(p->win, p->name);
268 ERR("cal_util_add_layout() is failed");
269 evas_object_del(p->win);
274 elm_win_resize_object_add(p->win, p->ly);
276 edje_object_part_text_set(CAL_UTIL_GET_EDJ_DATA(p->ly), "text/stop", _("Stop"));
277 edje_object_signal_callback_add(CAL_UTIL_GET_EDJ_DATA(p->ly), "stop", "edj", __cal_ring_stop_button_callback, p);
279 evas_object_event_callback_add(p->win, EVAS_CALLBACK_DEL, __cal_ring_window_delete_callback, p);
281 pm_change_state(LCD_NORMAL);
283 evas_object_show(p->win);
288 static Eina_Bool __cal_ring_timer_callback(void *data)
292 cal_ring_data *p = data;
294 // TODO: add quickpanel noti??
295 DBG("Alarm ring timeout!");
297 __cal_ring_stop_alarm(p);
299 evas_object_del(p->win);
304 return ECORE_CALLBACK_CANCEL;
307 static int __cal_ring_append_alarm(Evas_Object *win, Eina_List *cslist)
309 cal_ring_data *p = CAL_UTIL_GET_PRIV_DATA(win);
311 if (!p || CAL_STRCMP(p->name, _name))
313 ERR("Invalid object");
317 p->cslist = eina_list_merge(p->cslist, cslist);
323 p->tmr = ecore_timer_add(60.0, __cal_ring_timer_callback, p);
330 static int __cal_ring_create_alarm(struct appdata *ad, Eina_List *cslist)
332 c_retvm_if(!ad, -1, "ad is null");
333 c_retvm_if(!cslist, -1, "cslist is null");
335 Evas_Object *win = __cal_ring_create_view(ad);
336 c_retvm_if(!win, -1, "__cal_ring_create_view returned null");
338 return __cal_ring_append_alarm(win, cslist);
341 int cal_ring_add_alarm(struct appdata *ad, Eina_List *csl)
343 c_retvm_if(!ad, -1, "ad is null");
344 c_retvm_if(!csl, -1, "csl is null");
346 return __cal_ring_create_alarm(ad, csl);