upload codes for TIZEN 2.0
[apps/home/clock.git] / alarm / src / alarm_subview_tone.c
1 /*
2 *
3 * Copyright 2012  Samsung Electronics Co., Ltd
4 *
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
8 *
9 *    http://www.tizenopensource.org/license
10 *
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.
16 *
17 */
18
19 #include "alarm_subview_tone.h"
20 #include "alarm_fwk_util.h"
21 /**********************************************************************
22 ******************Local function ref*************************************
23 ***********************************************************************/
24
25 /**
26 * send
27 * This function is  used to set layout cb
28 * @param           ug[in]             pointer to struct  ui_gadget
29 * @param           mode[in]           enum ug_mode
30 * @param           priv[in]           pointer to data
31 * @return          void
32 * @exception
33 */
34 static void alarmapp_tone_layout_cb(ui_gadget_h ug, enum ug_mode mode,
35                                     void *priv)
36 {
37         ret_if(!ug || !priv);
38         Evas_Object *base = ug_get_layout(ug);
39         ret_if(!base);
40         Evas_Object *win = ug_get_window();
41
42         switch (mode) {
43         case UG_MODE_FULLVIEW:
44                 evas_object_size_hint_weight_set(base, EVAS_HINT_EXPAND,
45                                                  EVAS_HINT_EXPAND);
46                 elm_win_resize_object_add(win, base);
47                 evas_object_show(base);
48                 break;
49         case UG_MODE_FRAMEVIEW:
50                 elm_object_part_content_set(win, STRING_ALARM_LAYOUT_CONTENT,
51                                             base);
52                 break;
53         default:
54                 break;
55         }
56 }
57
58 /**
59 * send
60 * This function is  used to set result cb
61 * @param           ug[in]             pointer to struct  ui_gadget
62 * @param           result[out]        bundle
63 * @param           priv[in]           pointer to data
64 * @return          void
65 * @exception
66 */
67 static void alarmapp_tone_result_cb(ui_gadget_h ug, service_h result,
68                                     void *priv)
69 {
70         retm_if(NULL_CHECK(ug), "ug null");
71         retm_if(NULL_CHECK(priv), "priv null");
72         const char *val;
73         struct appdata *ad = (struct appdata *)priv;
74         setting_view *view = ad->view_setting;
75         ret_if(!view);
76         if (result) {
77                 service_get_extra_data(result, STRING_ALARM_RESULT, &val);
78                 retm_if(NULL_CHECK(val), "val null");
79                 memset(view->tmp_alarm.tone, 0, sizeof(view->tmp_alarm.tone));
80                 memcpy(view->tmp_alarm.tone, val, sizeof(view->tmp_alarm.tone));
81                 alarm_view_setting.update(ad);
82                 FREEIF(val);
83         }
84 }
85
86 /**
87 * send
88 * This function is  used to set destroy cb
89 * @param           ug[in]             pointer to struct  ui_gadget
90 * @param           priv[in]           pointer to data
91 * @return          void
92 * @exception
93 */
94 static void alarmapp_tone_destroy_cb(ui_gadget_h ug, void *priv)
95 {
96         retm_if(NULL_CHECK(priv), "priv null");
97         struct appdata *ad = (struct appdata *)priv;
98         setting_view *view = ad->view_setting;
99         ret_if(!view);
100         ug_destroy(view->gadget);
101         view->gadget = NULL;
102         //then, do...
103         ad->page = PAGE_ALARM_SETTING;
104         alm_show_view(ad, EINA_FALSE);
105 }
106
107 /**
108 * send
109 * This function is  used to create ug: myfile
110 * @param           ad[in]             pointer to struct  appdata
111 * @return          void
112 * @exception
113 */
114 ui_gadget_h alarmapp_tone_create_ug_myfile(struct appdata *ad)
115 {
116         retvm_if(NULL_CHECK(ad), NULL, "ad null");
117         setting_view *view = ad->view_setting;
118         retv_if(!view, NULL);
119
120         ui_gadget_h ug;
121         struct ug_cbs cbs = { 0, };
122
123         cbs.layout_cb = alarmapp_tone_layout_cb;
124         cbs.result_cb = alarmapp_tone_result_cb;
125         cbs.destroy_cb = alarmapp_tone_destroy_cb;
126         cbs.priv = (void *)ad;
127
128         service_h service;
129         service_create(&service);
130         retv_if(!service, NULL);
131
132         service_add_extra_data(service, STRING_ALARM_bundle_MARKED_MODE, view->tmp_alarm.tone);
133         service_add_extra_data(service, STRING_ALARM_bundle_PATH, SETTING_DEFAULT_ALERT_PATH);
134         service_add_extra_data(service, STRING_ALARM_bundle_SELECT_TYPE,
135                    STRING_ALARM_bundle_SINGLE_FILE);
136         service_add_extra_data(service, STRING_ALARM_bundle_FILE_TYPE, STRING_ALARM_bundle_SOUND);
137         service_add_extra_data(service, STRING_ALARM_bundle_DRM_TYPE,
138                    STRING_ALARM_bundle_DRM_ALL);
139         ug = ug_create(NULL, STRING_ALARM_bundle_MYFILE_EFL, UG_MODE_FULLVIEW,
140                        service, &cbs);
141         service_destroy(service);
142         return ug;
143 }
144
145 /**********************************************************************
146 ******************Global function ref*************************************
147 ***********************************************************************/
148
149 /**
150 * send
151 * This function is  used to load view: tone view
152 * @param           ad[in]           pointer to struct  appdata
153 * @return          when success, return SUCCESS  or FAILED if error
154 * @exception
155 */
156 int load_page_tone(struct appdata *ad)
157 {
158         retvm_if(NULL_CHECK(ad), FAILED, "ad null");
159         ad->page = PAGE_ALARM_TONE;
160         setting_view *view = ad->view_setting;
161         /**init ug   */
162         UG_INIT_EFL(ad->win_main, UG_OPT_INDICATOR_ENABLE);
163         if (!view->gadget) {
164                 view->gadget = alarmapp_tone_create_ug_myfile(ad);
165         }
166         return SUCCESS;
167 }