tizen 2.4 release
[apps/home/attach-panel.git] / src / ug.c
1 /*
2  * Copyright (c) 2015 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 <app_control.h>
18 #include <bundle.h>
19 #include <Elementary.h>
20 #include <ui-gadget.h>
21
22 #include "attach_panel.h"
23 #include "attach_panel_internal.h"
24 #include "attach_bundle.h"
25 #include "content_list.h"
26 #include "gesture.h"
27 #include "log.h"
28
29
30
31 static void __result_cb(ui_gadget_h ui_gadget, app_control_h result, void *priv)
32 {
33         content_s *content_info = priv;
34         char *enable = NULL;
35         char **select = NULL;
36
37         int i = 0;
38         int length = 0;
39         int ret = 0;
40
41         ret_if(!content_info);
42
43         if (ATTACH_PANEL_STATE_HIDE == _gesture_get_state())
44                 return;
45
46         ret = app_control_get_extra_data(result, "__ATTACH_PANEL_FLICK_DOWN__", &enable);
47         if (APP_CONTROL_ERROR_NONE == ret) {
48                 ret_if(!enable);
49
50                 _D("attach panel flick %s", enable);
51                 if (!strcmp(enable, MODE_ENABLE)) {
52                         content_info->attach_panel->flick = EINA_TRUE;
53                 } else if (!strcmp(enable, MODE_DISABLE)) {
54                         content_info->attach_panel->flick = EINA_FALSE;
55                 } else {
56                         _E("__ATTACH_PANEL_FLICK_DOWN__ value is wrong type(%s)", enable);
57                         content_info->attach_panel->flick = EINA_TRUE;
58                 }
59                 return;
60         }
61
62         ret = app_control_get_extra_data(result, "__ATTACH_PANEL_FULL_MODE__", &enable);
63         if (APP_CONTROL_ERROR_NONE == ret) {
64                 ret_if(!enable);
65
66                 _D("attach panel full mode %s", enable);
67                 if (!strcmp(enable, MODE_ENABLE)) {
68                         _gesture_set_full_mode(content_info->attach_panel);
69                 } else {
70                         _E("__ATTACH_PANEL_FULL_MODE__ value is wrong type(%s)", enable);
71                 }
72                 return;
73         }
74
75         /* This can be called by clicking the 'Cancel' button on the UGs */
76         ret = app_control_get_extra_data(result, "__ATTACH_PANEL_SHOW_PANEL__", &enable);
77         if (APP_CONTROL_ERROR_NONE == ret) {
78                 ret_if(!enable);
79
80                 _D("attach panel show panel %s", enable);
81                 if (!strcmp(enable, MODE_TRUE)) {
82                         if (ATTACH_PANEL_STATE_HIDE == _gesture_get_state()) {
83                                 /* This is same with attach_panel_show() */
84                                 _content_list_set_resume(content_info->attach_panel->content_list, ATTACH_PANEL_CONTENT_CATEGORY_UG);
85                                 _content_list_send_message(content_info->attach_panel->content_list, "__ATTACH_PANEL_INITIALIZE__", MODE_ENABLE, ATTACH_PANEL_CONTENT_CATEGORY_UG);
86                                 _gesture_show(content_info->attach_panel);
87                         }
88                 } else {
89                         if (ATTACH_PANEL_STATE_HIDE != _gesture_get_state()) {
90                                 /* This is same with attach_panel_hide() */
91                                 _content_list_set_pause(content_info->attach_panel->content_list, ATTACH_PANEL_CONTENT_CATEGORY_UG);
92                                 _gesture_hide(content_info->attach_panel);
93                         }
94                 }
95                 return;
96         }
97
98         /* This can be called on the state of recording video. */
99         ret = app_control_get_extra_data(result, "__ATTACH_PANEL_SHOW_TOOLBAR__", &enable);
100         if (APP_CONTROL_ERROR_NONE == ret) {
101                 ret_if(!enable);
102
103                 _D("attach panel show toolbar %s", enable);
104                 if (!strcmp(enable, MODE_TRUE)) {
105                         elm_object_signal_emit(content_info->attach_panel->ui_manager, "toolbar,show", "toolbar");
106                 } else {
107                         elm_object_signal_emit(content_info->attach_panel->ui_manager, "toolbar,hide", "toolbar");
108                 }
109                 return;
110         }
111
112         _D("The core of the panel sends the results to the caller");
113
114         /* This is just for protocol log */
115         _D("relay callback is called");
116         ret = app_control_get_extra_data_array(result, "http://tizen.org/appcontrol/data/selected", &select, &length);
117         if (APP_CONTROL_ERROR_NONE == ret && select) {
118                 for (i = 0; i < length; i++) {
119                         _D("selected is %s[%d]", select[i], i);
120                 }
121         }
122
123         ret = app_control_get_extra_data_array(result, "http://tizen.org/appcontrol/data/path", &select, &length);
124         if (APP_CONTROL_ERROR_NONE == ret && select) {
125                 for (i = 0; i < length; i++) {
126                         _D("path is %s[%d]", select[i], i);
127                 }
128         }
129
130         if (content_info->attach_panel->result_cb) {
131                 content_info->attach_panel->result_cb(content_info->attach_panel
132                                 , content_info->innate_content_info->content_category
133                                 , result
134                                 , APP_CONTROL_RESULT_SUCCEEDED
135                                 , content_info->attach_panel->result_data);
136
137                 if (ATTACH_PANEL_STATE_FULL == _gesture_get_state()) {
138                         /* This is same with attach_panel_hide() */
139                         _content_list_set_pause(content_info->attach_panel->content_list, ATTACH_PANEL_CONTENT_CATEGORY_UG);
140                         _gesture_hide(content_info->attach_panel);
141                 }
142         } else {
143                 _D("content_info->attach_panel->result_cb is NULL");
144         }
145 }
146
147
148
149 static void __resize_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
150 {
151         Evas_Object *ui_manager = obj;
152
153         int x, y, w, h;
154
155         ret_if(!ui_manager);
156
157         evas_object_geometry_get(ui_manager, &x, &y, &w, &h);
158         _D("%s resize(%d, %d, %d, %d)", data, x, y, w, h);
159 }
160
161
162
163 Evas_Object *_ug_create(const char *appid, const char *operation, const char *selection_mode, const char *mime, bundle *b, content_s *content_info)
164 {
165         app_control_h app_control = NULL;
166         ui_gadget_h ui_gadget = NULL;
167         Evas_Object *ug = NULL;
168         struct ug_cbs cbs = {
169                 .layout_cb = NULL,
170                 .result_cb = __result_cb,
171                 .destroy_cb = NULL,
172                 .priv = content_info,
173         };
174         int ret = APP_CONTROL_ERROR_NONE;
175
176         ret = app_control_create(&app_control);
177         goto_if(APP_CONTROL_ERROR_NONE != ret, ERROR);
178
179         ret = app_control_set_operation(app_control, operation);
180         goto_if(APP_CONTROL_ERROR_NONE != ret, ERROR);
181
182         ret = app_control_add_extra_data(app_control, "__CALLER_PANEL__", "attach-panel");
183         goto_if(APP_CONTROL_ERROR_NONE != ret, ERROR);
184
185         ret = app_control_add_extra_data(app_control, APP_CONTROL_DATA_SELECTION_MODE, selection_mode);
186         goto_if(APP_CONTROL_ERROR_NONE != ret, ERROR);
187
188         if (mime) {
189                 ret = app_control_set_mime(app_control, mime);
190                 goto_if(APP_CONTROL_ERROR_NONE != ret, ERROR);
191         }
192
193         if (b) {
194                 _D("app control add the extra data for ug");
195                 _bundle_add_to_app_control(b, app_control);
196         }
197
198         ui_gadget = ug_create(NULL, appid, UG_MODE_FRAMEVIEW, app_control, &cbs);
199         if (!ui_gadget) {
200                 _E("The UG of %s is failed to launch", appid);
201                 goto ERROR;
202         }
203
204         ug = ug_get_layout(ui_gadget);
205         goto_if(!ug, ERROR);
206
207         evas_object_show(ug);
208         evas_object_data_set(ug, DATA_KEY_UG, ui_gadget);
209         evas_object_event_callback_add(ug, EVAS_CALLBACK_RESIZE, __resize_cb, "ug");
210
211         ret = app_control_destroy(app_control);
212         if (APP_CONTROL_ERROR_NONE != ret) {
213                 _E("cannot destroy app_control");
214         }
215
216         return ug;
217
218 ERROR:
219         if (app_control) app_control_destroy(app_control);
220
221         return NULL;
222 }
223
224
225
226 void _ug_destroy(Evas_Object *ug)
227 {
228         ui_gadget_h ui_gadget = NULL;
229
230         ret_if(!ug);
231
232         evas_object_event_callback_del(ug, EVAS_CALLBACK_RESIZE, __resize_cb);
233         ui_gadget = evas_object_data_del(ug, DATA_KEY_UG);
234         ret_if(!ui_gadget);
235
236         ug_destroy(ui_gadget);
237 }