2 * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #include <ui-gadget.h>
19 #include "view_uigadget.h"
23 #define DATA_ID "ugdata"
29 Evas_Object *main_item_box;
30 Evas_Object *subitem_box;
32 const char *display_name;
33 ui_gadget_h ug_handler;
34 Eina_Bool ug_is_existed;
35 struct setting_mgr *mgr;
36 struct settingview_data *view;
40 * This function is invoked to hide view layout.
42 * @param base [in] The view layout evas object.
45 static void _hide(Evas_Object *base)
50 evas_object_hide(base);
54 * Hide current ug launcher view, then pop this view from view list and return to main view.
56 * @param data [in] The function specific data which hold _data pointer.
59 static void _back_to_mainview(struct _data *data)
65 settingmgr_view_pop(data->mgr);
69 * This callback function is invoked with base layout for layout arrangement
70 * after UI Gadget create create operation is completed.
72 * @param ug [in] The handler data representing a UI gadget.
73 * @param mode [in] The UI gadget mode.
74 * @param priv [in] The function specific data passed by UG caller.
77 static void _ug_layout_cb(ui_gadget_h ug, enum ug_mode mode, void *priv)
82 * After UG module invoke ug_send_message to send result,
83 * UG library call this callback function registered by calling ug_create.
85 * @param ug [in] The handler data representing a UI gadget.
86 * @param result [in] The Service handler.
87 * @param priv [in] The function specific data passed by UG caller.
90 static void _ug_result_cb(ui_gadget_h ug, service_h result, void *priv)
95 * This function is invoked to show sub item buttons evas object.
97 * @param box [in] The box evas object contained sub item buttons.
100 static void _show_item_btns(Evas_Object *box)
108 list = elm_box_children_get(box);
110 _ERR("button list is null.");
114 EINA_LIST_FOREACH(list, l, btn)
115 evas_object_show(btn);
117 eina_list_free(list);
121 * Send the destroy request, use ug_destroy_me,
122 * then UG library calls this callback function registered by UG caller.
124 * @param ug [in] The handler data representing a UI gadget.
125 * @param priv [in] The function specific data passed by UG caller.
128 static void _ug_destroy_cb(ui_gadget_h ug, void *priv)
133 _ERR("Invalid parameters in ug destroy callback.");
139 _show_item_btns(data->subitem_box);
141 elm_object_focus_set(data->subbtn, EINA_TRUE);
142 elm_object_part_text_set(data->base, UG_TITLE_TEXT, "");
145 data->ug_is_existed = EINA_FALSE;
146 _back_to_mainview(data);
150 * This function is invoked to create UI Gadget with specific UG name.
152 * @param data [in] The function specific data which hold _data pointer.
153 * @return 0 if success, -1 if fail.
155 static int _load_uigadget(struct _data *data)
159 struct settingitem *parent;
161 struct ug_cbs cbs = {
162 .layout_cb = _ug_layout_cb,
163 .result_cb = _ug_result_cb,
164 .destroy_cb = _ug_destroy_cb,
169 _ERR("private data is null.");
175 parent = viewdata_get_parentitem(data->view);
176 name = settingitem_get_settingui_name(parent);
177 elm_object_part_text_set(data->base,
178 UG_TITLE_TEXT, data->display_name);
180 ug = ug_create(NULL, name, UG_MODE_FRAMEVIEW, NULL, &cbs);
182 _ERR("ug create failed.");
185 data->ug_is_existed = EINA_TRUE;
186 data->ug_handler = ug;
187 settingmgr_freeze_timeout(data->mgr);
194 * This function is invoked to hide sub item buttons evas object.
196 * @param box [in] The box evas object contained sub item buttons.
199 static void _hide_item_btns(Evas_Object *box)
205 _ERR("item box is null.");
209 list = elm_box_children_get(box);
211 _ERR("button list is null.");
215 EINA_LIST_FOREACH(list, l, btn)
216 evas_object_hide(btn);
218 eina_list_free(list);
222 * This function is invoked to create UG launcher view layout.
224 * @param mgr [in] The setting_mgr data pointer passed by @settingmgr_view_push.
225 * @param view [in] The settingview_data data pointer passed by @settingmgr_view_push.
226 * @param prev [in] The parameter data which passed by prev view or NULL.
227 * @return View layout evas object, NULL on error.
229 static Evas_Object *_create(struct setting_mgr *mgr,
230 struct settingview_data *view, void *prev)
232 Evas_Object *win, *base;
234 struct evas_obj_data *param;
237 if (!mgr || !prev || !view) {
238 _ERR("mgr is null.");
244 _hide_item_btns(param->subitem_box);
246 win = settingmgr_get_win(mgr);
248 _ERR("Invalid argument");
252 data = calloc(1, sizeof(struct _data));
254 _ERR("calloc struct _data failed.");
258 base = elm_layout_add(win);
260 _ERR("add base layout failed.");
265 elm_layout_file_set(base, EDJ_FILE, UG_GROUP);
271 data->subitem_box = param->subitem_box;
272 data->display_name = param->display_name;
273 data->subbtn = param->cur_btn;
274 data->ug_is_existed = EINA_FALSE;
276 evas_object_data_set(base, DATA_ID, data);
278 r = _load_uigadget(data);
280 _ERR("load ui gadget failed.");
282 evas_object_del(base);
290 * This function is invoked to show view layout.
292 * @param base [in] The view layout evas object.
295 static void _show(Evas_Object *base)
298 _ERR("Invalid argument!");
302 evas_object_show(base);
306 * This function is invoked to destroy view layout.
308 * @param base [in] The view layout evas object.
311 static void _destroy(Evas_Object *base)
316 _ERR("Invalid argument!");
320 data = evas_object_data_get(base, DATA_ID);
322 _ERR("Fail to get uglauncher data");
326 if (data->ug_is_existed == EINA_TRUE)
327 ug_destroy(data->ug_handler);
330 viewdata_release(data->view);
332 evas_object_del(base);
336 static struct setting_class _vclass = {
337 .title = VCLASS_TITLE_UG,
346 * This function is invoked to get UI Gadget launcher view class object.
348 * @return The setting_class data static pointer, NULL on error.
350 struct setting_class *view_uigadget_get_vclass(void)