Revert to original C impl
[profile/tv/apps/native/settings.git] / ug / channel / src / view_result_page.c
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (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://www.apache.org/licenses/LICENSE-2.0
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 #include <Elementary.h>
18 #include <app.h>
19 #include <system_info.h>
20 #include "dbg.h"
21 #include "defs.h"
22 #include "util.h"
23 #include "viewmgr_auto_program.h"
24 #include "ug_auto_program.h"
25 #include "view_search_page.h"
26 #include "view_result_page.h"
27
28 #define RESULT_MSG_SIZE 60
29
30 #define _GET_PRIV(o) evas_object_data_get(o, "RESDATA")
31 #define _SET_PRIV(o, data) evas_object_data_set(o, "RESDATA", data)
32
33 struct _data {
34         Evas_Object *win;
35         Evas_Object *base;
36         Evas_Object *ok_btn;
37         struct viewmgr *vmgr;
38         struct _ugdata *ugd;
39 };
40
41 /**
42  * @Evas_Smart_Cb type callback for handling the click callback event for
43  * "OK" button.
44  *
45  * When "OK" button is clicked, channel ug will exit.
46  *
47  * @param[in] data: the user data related to current view
48  * @param[in] obj: the corresponding object on which the button click event
49  * occurred
50  *
51  * @param[in] ev: event information
52  */
53 static void _ok_btn_clicked_cb(void *data, Evas_Object *obj, void *ev)
54 {
55         struct _ugdata *ugd;
56         struct _data *priv;
57
58         if (!data) {
59                 _ERR("Invalid argument");
60                 return;
61         }
62
63         priv = data;
64         ugd = priv->ugd;
65
66         if (!ugd || !ugd->ug)  {
67                 _ERR("ugd->ug is NULL");
68                 return;
69         }
70
71         ug_destroy_me(ugd->ug);
72 }
73
74 /**
75  * Initializes the base layout for scanning result view.
76  *
77  * Create the layout of scanning result view.
78  *
79  * @param[in] vmgr: the handler to the struct object for managing the view
80  * @param[in] data: the user data related to current view
81  * @return The base or NULL if creatting failed
82  */
83 static Evas_Object *_create(struct viewmgr *vmgr, void *data)
84 {
85         Evas_Object *base;
86         Evas_Object *win;
87         struct _data *priv;
88         struct _ugdata *ugd;
89
90         if (!vmgr || !data) {
91                 _ERR("Invalid argument");
92                 return NULL;
93         }
94
95         ugd = data;
96
97         win = viewmgr_get_win(vmgr);
98         if (!win)
99                 return NULL;
100
101         priv = calloc(1, sizeof(*priv));
102         if (!priv)
103                 return NULL;
104
105         base = util_add_layout(win, AUTO_PRGM_EDJ_FILE, GROUP_RES);
106         if (!base) {
107                 free(priv);
108                 return NULL;
109         }
110
111         elm_win_resize_object_add(win, base);
112
113         priv->win = win;
114         priv->base = base;
115         priv->ugd = ugd;
116         priv->vmgr = vmgr;
117
118         _SET_PRIV(base, priv);
119
120         return base;
121 }
122
123 /**
124  * Invoked after _create() function as defined in viewmgr_push().
125  *
126  * Create the button in result view, and show the information about the
127  * number of found channels.
128  *
129  * @param[in] base: the layout of the view
130  */
131 static void _update(Evas_Object *base)
132 {
133         Evas_Object *ok_btn;
134         struct _data *priv;
135         char msg[RESULT_MSG_SIZE];
136         int chs;
137
138         if (!base) {
139                 _ERR("Invalid argument");
140                 return;
141         }
142
143         priv = _GET_PRIV(base);
144         if (!priv) {
145                 _ERR("Data get failed");
146                 return;
147         }
148
149         chs = priv->ugd->find_chs;
150
151         snprintf(msg, sizeof(msg), "%s<br>%d %s", COMPLETE_MAIN_TITLE,
152                         chs, TEXT_CH_MEMORIZED);
153         elm_object_part_text_set(priv->base, PART_RES_MAIN_TITLE, msg);
154
155         ok_btn = util_add_button(priv->base, BTN_STYLE,
156                         PART_OK_BTN, TEXT_BUTTON_OK, EINA_TRUE);
157         if (!ok_btn) {
158                 _ERR("ok_btn is NULL");
159                 return;
160         }
161
162         priv->ok_btn = ok_btn;
163         elm_object_focus_set(ok_btn, EINA_TRUE);
164         evas_object_smart_callback_add(ok_btn, SIGNAL_CLICKED,
165                         _ok_btn_clicked_cb, priv);
166
167         util_focus_next_set(ok_btn);
168 }
169
170 /**
171  * Resume the application.
172  *
173  * @param[in] base: the layout of the view
174  */
175 static void _resume(Evas_Object *base)
176 {
177         evas_object_show(base);
178 }
179
180 /**
181  * Pause the application.
182  *
183  * Hide the layout
184  *
185  * @param[in] base: the layout of the view
186  */
187 static void _pause(Evas_Object *base)
188 {
189         evas_object_hide(base);
190 }
191
192 /**
193  * Called after the main loop of the view exits.
194  *
195  * Delete the layout and release the resourse
196  *
197  * @param[in] base: the layout of the view
198  */
199 static void _terminate(Evas_Object *base)
200 {
201         struct _data *priv;
202
203         if (!base) {
204                 _ERR("Invalid argument");
205                 return;
206         }
207
208         priv = _GET_PRIV(base);
209         if (!priv) {
210                 _ERR("Data get failed");
211                 return;
212         }
213
214         if (priv->base)
215                 evas_object_del(priv->base);
216
217         free(priv);
218 }
219
220 /**
221  * This struct is for registering the callbacks for the view
222  */
223 static struct view_class _vclass = {
224         .title = VIEW_RESULT,
225         .create = _create,
226         .update = _update,
227         .resume = _resume,
228         .pause = _pause,
229         .terminate = _terminate,
230 };
231
232  /**
233  * Returns current view_class which implements the result view's life cycle
234  *
235  * @return view_class
236  */
237 struct view_class *view_resultpage_get_vclass(void)
238 {
239         return &_vclass;
240 }