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