2 * Copyright (c) 2015 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 <app_control.h>
19 #include <Elementary.h>
20 #include <ui-gadget.h>
22 #include "attach_panel.h"
23 #include "attach_panel_internal.h"
24 #include "attach_bundle.h"
25 #include "content_list.h"
31 static void __result_cb(ui_gadget_h ui_gadget, app_control_h result, void *priv)
33 content_s *content_info = priv;
41 ret_if(!content_info);
43 if (ATTACH_PANEL_STATE_HIDE == _gesture_get_state())
46 ret = app_control_get_extra_data(result, "__ATTACH_PANEL_FLICK_DOWN__", &enable);
47 if (APP_CONTROL_ERROR_NONE == ret) {
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;
56 _E("__ATTACH_PANEL_FLICK_DOWN__ value is wrong type(%s)", enable);
57 content_info->attach_panel->flick = EINA_TRUE;
62 ret = app_control_get_extra_data(result, "__ATTACH_PANEL_FULL_MODE__", &enable);
63 if (APP_CONTROL_ERROR_NONE == ret) {
66 _D("attach panel full mode %s", enable);
67 if (!strcmp(enable, MODE_ENABLE)) {
68 _gesture_set_full_mode(content_info->attach_panel);
70 _E("__ATTACH_PANEL_FULL_MODE__ value is wrong type(%s)", enable);
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) {
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);
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);
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) {
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");
107 elm_object_signal_emit(content_info->attach_panel->ui_manager, "toolbar,hide", "toolbar");
112 _D("The core of the panel sends the results to the caller");
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);
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);
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
134 , APP_CONTROL_RESULT_SUCCEEDED
135 , content_info->attach_panel->result_data);
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);
143 _D("content_info->attach_panel->result_cb is NULL");
149 static void __resize_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
151 Evas_Object *ui_manager = obj;
157 evas_object_geometry_get(ui_manager, &x, &y, &w, &h);
158 _D("%s resize(%d, %d, %d, %d)", data, x, y, w, h);
163 Evas_Object *_ug_create(const char *appid, const char *operation, const char *selection_mode, const char *mime, bundle *b, content_s *content_info)
165 app_control_h app_control = NULL;
166 ui_gadget_h ui_gadget = NULL;
167 Evas_Object *ug = NULL;
168 struct ug_cbs cbs = {
170 .result_cb = __result_cb,
172 .priv = content_info,
174 int ret = APP_CONTROL_ERROR_NONE;
176 ret = app_control_create(&app_control);
177 goto_if(APP_CONTROL_ERROR_NONE != ret, ERROR);
179 ret = app_control_set_operation(app_control, operation);
180 goto_if(APP_CONTROL_ERROR_NONE != ret, ERROR);
182 ret = app_control_add_extra_data(app_control, "__CALLER_PANEL__", "attach-panel");
183 goto_if(APP_CONTROL_ERROR_NONE != ret, ERROR);
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);
189 ret = app_control_set_mime(app_control, mime);
190 goto_if(APP_CONTROL_ERROR_NONE != ret, ERROR);
194 _D("app control add the extra data for ug");
195 _bundle_add_to_app_control(b, app_control);
198 ui_gadget = ug_create(NULL, appid, UG_MODE_FRAMEVIEW, app_control, &cbs);
200 _E("The UG of %s is failed to launch", appid);
204 ug = ug_get_layout(ui_gadget);
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");
211 ret = app_control_destroy(app_control);
212 if (APP_CONTROL_ERROR_NONE != ret) {
213 _E("cannot destroy app_control");
219 if (app_control) app_control_destroy(app_control);
226 void _ug_destroy(Evas_Object *ug)
228 ui_gadget_h ui_gadget = NULL;
232 evas_object_event_callback_del(ug, EVAS_CALLBACK_RESIZE, __resize_cb);
233 ui_gadget = evas_object_data_del(ug, DATA_KEY_UG);
236 ug_destroy(ui_gadget);