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