bc30252882cfdc2fe7d5265bc5b8645fc865fdfc
[apps/core/preloaded/ug-setting-manage-applications-efl.git] / ug / src / mgr-app-uigadget.c
1 /*
2  *      Copyright 2012  Samsung Electronics Co., Ltd
3  *
4  *      Licensed under the Flora License, Version 1.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://floralicense.org/license/
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
18 #ifndef UG_MODULE_API
19 #define UG_MODULE_API __attribute__ ((visibility("default")))
20 #endif
21
22 #include "mgr-app-uigadget.h"
23 #include "mgr-app-common-debug.h"
24 #include "mgr-app-common-error.h"
25 #include "mgr-app-common-util.h"
26 #include "mgr-app-view-main.h"
27 #include "mgr-app-view-common.h"
28 #include "mgr-app-widget.h"
29
30 #define STR_VIEWTYPE                            "viewtype"
31 #define STR_MANAGE_APPLICATIONS         "manage-applications"
32
33
34 static void *on_create(ui_gadget_h ug, enum ug_mode mode, service_h service, void *priv)
35 {
36         MGR_APP_BEGIN();
37
38         struct ug_data *ugd = NULL;
39         char *arg = NULL;
40         int ret = SERVICE_ERROR_NONE;
41
42         retv_if(priv == NULL, NULL);
43
44         bindtextdomain(PACKAGE, LOCALEDIR);
45
46         ugd = priv;
47         ugd->ug = ug;
48
49         ugd->win_main = ug_get_parent_layout(ug);
50         retv_if(ugd->win_main == NULL, NULL);
51
52         ugd->bg = mgr_app_widget_create_bg(ugd->win_main);
53         if (!ugd->bg) {
54                 MGR_APP_DEBUG_ERR("ugd->bg is null");
55                 MGR_APP_MEM_FREE(ugd->win_main);
56                 return NULL;
57         }
58
59         ugd->layout_main = mgr_app_widget_create_main_layout(ugd->win_main);
60         if (!ugd->layout_main) {
61                 MGR_APP_DEBUG_ERR("ugd->layout_main is null");
62                 MGR_APP_MEM_FREE(ugd->win_main);
63                 MGR_APP_MEM_FREE(ugd->bg);
64                 MGR_APP_END();
65                 return NULL;
66         }
67
68         elm_object_part_content_set(ugd->layout_main, "elm.swallow.bg", ugd->bg);
69
70         ugd->navi_bar = mgr_app_view_create_base_navigation(ugd->layout_main);
71         if (!ugd->navi_bar) {
72                 MGR_APP_DEBUG_ERR("ugd->navi_bar is null");
73                 MGR_APP_MEM_FREE(ugd->win_main);
74                 MGR_APP_MEM_FREE(ugd->bg);
75                 MGR_APP_MEM_FREE(ugd->layout_main);
76                 MGR_APP_END();
77                 return NULL;
78         }
79
80         /* package manager listener */
81         if (ugd->pc_listen) {
82                 pkgmgr_client_free(ugd->pc_listen);
83                 ugd->pc_listen = NULL;
84         } else {
85                 ugd->pc_listen = pkgmgr_client_new(PC_LISTENING);
86                 if (!ugd->pc_listen) {
87                         MGR_APP_DEBUG_ERR("pc_listen is null");
88                         MGR_APP_MEM_FREE(ugd->win_main);
89                         MGR_APP_MEM_FREE(ugd->bg);
90                         MGR_APP_MEM_FREE(ugd->layout_main);
91                         MGR_APP_END();
92                         return NULL;
93                 }
94         }
95
96         ugd->uninstall = EINA_FALSE;
97
98         ret = service_get_extra_data(service, STR_VIEWTYPE, &arg);
99         switch (ret) {
100         case SERVICE_ERROR_NONE:
101                 MGR_APP_DEBUG("SERVICE_ERROR_NONE. arg: %s", arg);
102                 break;
103         case SERVICE_ERROR_INVALID_PARAMETER:
104                 MGR_APP_DEBUG_ERR("SERVICE_ERROR_INVALID_PARAMETER");
105                 break;
106         case SERVICE_ERROR_KEY_NOT_FOUND:
107                 MGR_APP_DEBUG_ERR("SERVICE_ERROR_KEY_NOT_FOUND");
108                 break;
109         case SERVICE_ERROR_OUT_OF_MEMORY:
110                 MGR_APP_DEBUG_ERR("SERVICE_ERROR_OUT_OF_MEMORY");
111                 break;
112         case SERVICE_ERROR_INVALID_DATA_TYPE:
113                 MGR_APP_DEBUG_ERR("SERVICE_ERROR_INVALID_DATA_TYPE");
114                 break;
115         default:
116                 MGR_APP_DEBUG_ERR("ret value has an error.");
117                 break;
118         }
119
120         if (arg && !strncmp(arg, STR_MANAGE_APPLICATIONS, strlen(STR_MANAGE_APPLICATIONS))) {
121                 mgrapp_view_list_create((void*)ugd);
122         } else {
123                 MGR_APP_DEBUG_ERR("argument has an error.");
124         }
125
126         MGR_APP_END();
127         return ugd->layout_main;
128 }
129
130 static void on_start(ui_gadget_h ug, service_h service, void *priv)
131 {
132         MGR_APP_BEGIN();
133         MGR_APP_END();
134 }
135
136 static void on_pause(ui_gadget_h ug, service_h service, void *priv)
137 {
138         MGR_APP_BEGIN();
139         
140         mgr_app_doubletap_sensor_disable();
141
142         MGR_APP_END();
143 }
144
145 static void on_resume(ui_gadget_h ug, service_h service, void *priv)
146 {
147         MGR_APP_BEGIN();
148
149         struct ug_data *ugd = NULL;
150         view_type_t target_view = VIEW_TYPE_NONE;
151
152         target_view = mgrapp_get_view_type();
153         if (VIEW_TYPE_APP_INFO == target_view) {
154                 ret_if(priv == NULL);
155                 ugd = priv;
156                 mgrapp_view_info_update((void*)ugd);
157         }
158         
159         mgr_app_doubletap_sensor_enable();
160
161         MGR_APP_END();
162 }
163
164 static void on_destroy(ui_gadget_h ug, service_h service, void *priv)
165 {
166         MGR_APP_BEGIN();
167
168         ret_if(priv == NULL);
169
170         struct ug_data *ugd = priv;
171
172         mgr_app_doubletap_sensor_destroy();
173
174         if (ugd->pc_listen) {
175                 pkgmgr_client_free(ugd->pc_listen);
176                 ugd->pc_listen = NULL;
177         }
178
179         if (ugd->layout_main) {
180                 evas_object_del(ugd->layout_main);
181                 ugd->layout_main = NULL;
182         }
183
184         MGR_APP_END();
185 }
186
187 static void on_message(ui_gadget_h ug, service_h msg, service_h service, void *priv)
188 {
189         MGR_APP_BEGIN();
190         MGR_APP_END();
191 }
192
193 static void on_event(ui_gadget_h ug, enum ug_event event, service_h service, void *priv)
194 {
195         MGR_APP_BEGIN();
196         switch (event) {
197         case UG_EVENT_LOW_MEMORY:
198                 break;
199         case UG_EVENT_LOW_BATTERY:
200                 break;
201         case UG_EVENT_LANG_CHANGE:
202                 break;
203         case UG_EVENT_ROTATE_PORTRAIT:
204                 break;
205         case UG_EVENT_ROTATE_PORTRAIT_UPSIDEDOWN:
206                 break;
207         case UG_EVENT_ROTATE_LANDSCAPE:
208                 break;
209         case UG_EVENT_ROTATE_LANDSCAPE_UPSIDEDOWN:
210                 break;
211         default:
212                 break;
213         }
214         MGR_APP_END();
215 }
216
217 static void on_key_event(ui_gadget_h ug, enum ug_key_event event, service_h service, void *priv)
218 {
219         MGR_APP_BEGIN();
220
221         switch (event) {
222         case UG_KEY_EVENT_END:
223                 ug_destroy_me(ug);
224                 break;
225         default:
226                 break;
227         }
228         MGR_APP_END();
229 }
230
231 UG_MODULE_API int UG_MODULE_INIT(struct ug_module_ops *ops)
232 {
233         MGR_APP_BEGIN();
234         struct ug_data *ugd = NULL;
235
236         retv_if(ops == NULL, -1);
237
238         MGR_APP_MEM_MALLOC(ugd, (1), struct ug_data);
239
240         ops->create     = on_create;
241         ops->start              = on_start;
242         ops->pause              = on_pause;
243         ops->resume     = on_resume;
244         ops->destroy    = on_destroy;
245         ops->message    = on_message;
246         ops->event              = on_event;
247         ops->key_event  = on_key_event;
248         ops->priv               = ugd;
249         ops->opt                = UG_OPT_INDICATOR_ENABLE;
250
251         MGR_APP_END();
252         return 0;
253 }
254
255 UG_MODULE_API void UG_MODULE_EXIT(struct ug_module_ops *ops)
256 {
257         MGR_APP_BEGIN();
258         struct ug_data *ugd = NULL;
259
260         ret_if(ops == NULL);
261
262         ugd = ops->priv;
263         MGR_APP_MEM_FREE(ugd);
264
265         MGR_APP_END();
266 }
267
268 UG_MODULE_API int setting_plugin_reset(service_h service, void *priv)
269 {
270         MGR_APP_BEGIN();
271         /* nothing to do for Setting>Reset */
272         MGR_APP_END();
273         return 0;
274 }