tizen 2.4 release
[apps/home/attach-panel.git] / src / content_list.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 <Elementary.h>
19 #include <tizen.h>
20 #include <ui-gadget.h>
21
22 #include "attach_panel.h"
23 #include "attach_panel_internal.h"
24 #include "conf.h"
25 #include "content_list.h"
26 #include "log.h"
27
28
29
30 void _content_list_send_message(Eina_List *list, const char *key, const char *value, int is_ug)
31 {
32         content_s *content_info = NULL;
33         app_control_h app_control = NULL;
34         const Eina_List *l = NULL;
35
36         int ret = APP_CONTROL_ERROR_NONE;
37
38         ret_if(!list);
39         ret_if(!key);
40         ret_if(!value);
41
42         ret = app_control_create(&app_control);
43         ret_if(APP_CONTROL_ERROR_NONE != ret);
44
45         ret = app_control_add_extra_data(app_control, "__CALLER_PANEL__", "attach-panel");
46         if (APP_CONTROL_ERROR_NONE != ret) {
47                 _E("Fail to add extra data(__CALLER_PANEL__)");
48                 app_control_destroy(app_control);
49                 return;
50         }
51
52         ret = app_control_add_extra_data(app_control, key, value);
53         if (APP_CONTROL_ERROR_NONE != ret) {
54                 _E("Fail to add extra data(%s)", key);
55                 app_control_destroy(app_control);
56                 return;
57         }
58
59         EINA_LIST_FOREACH(list, l, content_info) {
60                 continue_if(!content_info);
61                 if (!content_info->content) {
62                         _D("ug is not created yet");
63                         continue;
64                 }
65                 innate_content_s *innate_content_info = content_info->innate_content_info;
66                 continue_if(!innate_content_info);
67
68                 if (is_ug == innate_content_info->is_ug) {
69                         ui_gadget_h ui_gadget = NULL;
70
71                         ui_gadget = evas_object_data_get(content_info->content, DATA_KEY_UG);
72                         if (!ui_gadget) {
73                                 _D("Fail to get the ui gadget");
74                                 continue;
75                         }
76                         ug_send_message(ui_gadget, app_control);
77                 }
78         }
79
80         ret = app_control_destroy(app_control);
81         ret_if(APP_CONTROL_ERROR_NONE != ret);
82 }
83
84
85
86 void _content_list_send_message_to_content(Eina_List *list, const char *key, const char *value, int cur_page_no)
87 {
88         content_s *content_info = NULL;
89         app_control_h app_control = NULL;
90         ui_gadget_h ui_gadget = NULL;
91
92         int ret = APP_CONTROL_ERROR_NONE;
93
94         ret_if(!list);
95         ret_if(!key);
96         ret_if(!value);
97
98         content_info = eina_list_nth(list, cur_page_no);
99         ret_if(!content_info);
100
101         if (!content_info->innate_content_info->is_ug) {
102                 _D("this page did not need to send message");
103                 return;
104         }
105
106         ret = app_control_create(&app_control);
107         ret_if(APP_CONTROL_ERROR_NONE != ret);
108
109         ret = app_control_add_extra_data(app_control, "__CALLER_PANEL__", "attach-panel");
110         if (APP_CONTROL_ERROR_NONE != ret) {
111                 _E("Fail to add extra data(__CALLER_PANEL__)");
112                 app_control_destroy(app_control);
113                 return;
114         }
115
116         ret = app_control_add_extra_data(app_control, key, value);
117         if (APP_CONTROL_ERROR_NONE != ret) {
118                 _E("Fail to add extra data(%s)", key);
119                 app_control_destroy(app_control);
120                 return;
121         }
122
123         ui_gadget = evas_object_data_get(content_info->content, DATA_KEY_UG);
124         if (!ui_gadget) {
125                 _D("Fail to get the ui gadget");
126                 app_control_destroy(app_control);
127                 return;
128         }
129         ug_send_message(ui_gadget, app_control);
130
131         ret = app_control_destroy(app_control);
132         ret_if(APP_CONTROL_ERROR_NONE != ret);
133 }
134
135
136
137 void _content_list_set_pause(Eina_List *list, int is_ug)
138 {
139         content_s *content_info = NULL;
140         const Eina_List *l = NULL;
141
142         ret_if(!list);
143
144         EINA_LIST_FOREACH(list, l, content_info) {
145                 continue_if(!content_info);
146                 innate_content_s *innate_content_info = content_info->innate_content_info;
147                 continue_if(!innate_content_info);
148                 if (is_ug == innate_content_info->is_ug) {
149                         ui_gadget_h ui_gadget = NULL;
150
151                         ui_gadget = evas_object_data_get(content_info->content, DATA_KEY_UG);
152                         if (!ui_gadget) {
153                                 _D("Fail to get the ui gadget");
154                                 continue;
155                         }
156                         ug_pause_ug(ui_gadget);
157                 }
158         }
159 }
160
161
162
163 void _content_list_set_resume(Eina_List *list, int is_ug)
164 {
165         content_s *content_info = NULL;
166         const Eina_List *l = NULL;
167
168         ret_if(!list);
169
170         EINA_LIST_FOREACH(list, l, content_info) {
171                 continue_if(!content_info);
172                 innate_content_s *innate_content_info = content_info->innate_content_info;
173                 continue_if(!innate_content_info);
174                 if (is_ug == innate_content_info->is_ug) {
175                         ui_gadget_h ui_gadget = NULL;
176
177                         ui_gadget = evas_object_data_get(content_info->content, DATA_KEY_UG);
178                         if (!ui_gadget) {
179                                 _D("Fail to get the ui gadget");
180                                 continue;
181                         }
182                         ug_resume_ug(ui_gadget);
183                 }
184         }
185 }