tizen 2.3.1 release
[apps/home/settings.git] / setting-appmgr / src / setting-appmgr.c
1 /*
2  * setting
3  *
4  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  */
19 #ifndef UG_MODULE_API
20 #define UG_MODULE_API __attribute__ ((visibility("default")))
21 #endif
22
23 #include <efl_assist.h>
24 #include <setting-cfg.h>
25
26 #include "setting-appmgr-pkginfo.h"
27 #include "setting-appmgr-pkginfo-utils.h"
28 #include "setting-appmgr-runinfo.h"
29 #include "setting-appmgr-utils.h"
30 #include "setting-appmgr-main.h"
31 #include "setting-appmgr.h"
32
33 static void appmgrUg_resize(void *data, Evas *e, Evas_Object *obj, void *event_info)
34 {
35         SettingAppMgrUG *ad = data;
36
37         ret_if(NULL == data);
38
39         if (ad->runinfo_view->is_create)
40                 setting_view_update(ad->runinfo_view, ad);
41         if (ad->pkginfo_view->is_create)
42                 setting_view_update(ad->pkginfo_view, ad);
43         if (ad->main_view->is_create)
44                 setting_view_update(ad->main_view, ad);
45 }
46 #if 0
47 static void _app_mgr_item_del(void *data, Evas_Object *obj)
48 {
49         SETTING_TRACE_BEGIN;
50         setting_retm_if(data == NULL, "Data parameter is NULL");
51         Setting_GenGroupItem_Data *item_data = (Setting_GenGroupItem_Data *) data;
52         if (item_data) {
53                 FREE(item_data);
54         }
55 }
56 #endif
57
58 static void
59 _main_gl_del_cb(void *data, Evas_Object *obj EINA_UNUSED)
60 {
61         retv_if(data == NULL, NULL);
62         /*appmgr_listinfo *info = data; */
63         /*info->item = NULL; */
64 }
65
66 static inline void appmgrUg_init_itcs(SettingAppMgrUG *ad)
67 {
68         setting_create_Gendial_itc("groupindex", &(ad->itc_grp_title));
69         setting_create_Gendial_itc("multiline_sub", &(ad->itc_multiline));
70         setting_create_Gendial_itc("1line", &(ad->itc_1txt_1ic_2));
71         setting_create_Gendial_itc("1line", &(ad->itc_1txt));
72         setting_create_Gendial_itc("multiline_sub.main", &(ad->itc_multiline_2txt));
73
74         ad->itc_sep.item_style = "dialogue/separator.transparent.2";
75         ad->itc_sep.func.text_get = NULL;
76         ad->itc_sep.func.content_get = NULL;
77         ad->itc_sep.func.state_get = NULL;
78         ad->itc_sep.func.del = NULL;
79
80         ad->itc_main.item_style = "2line.top";
81         ad->itc_main.func.text_get = appmgrUg_main_gl_label_get;
82         ad->itc_main.func.content_get = appmgrUg_main_gl_icon_get;
83         ad->itc_main.func.state_get = NULL;
84         ad->itc_main.func.del = _main_gl_del_cb;
85
86         ad->itc_1ic.item_style = "1icon";
87         ad->itc_1ic.func.text_get = NULL;
88         ad->itc_1ic.func.content_get = appmgrUg_run_gl_stop_btn;
89         ad->itc_1ic.func.state_get = NULL;
90         ad->itc_1ic.func.del = NULL;
91
92         ad->itc_info_title.item_style = "2line.top";
93         ad->itc_info_title.func.text_get = appmgrUg_info_title_gl_label_get;
94         ad->itc_info_title.func.content_get = appmgrUg_info_title_gl_icon_get;
95         ad->itc_info_title.func.state_get = NULL;
96         ad->itc_info_title.func.del = NULL;
97
98         ad->itc_2button1.item_style = "1icon";
99         ad->itc_2button1.func.text_get = NULL;
100         ad->itc_2button1.func.content_get = appmgrUg_info_2button1_gl_icon_get;
101         ad->itc_2button1.func.state_get = NULL;
102         ad->itc_2button1.func.del = NULL;
103
104         ad->itc_2button2.item_style = "1icon";
105         ad->itc_2button2.func.text_get = NULL;
106         ad->itc_2button2.func.content_get = appmgrUg_info_2button2_gl_icon_get;
107         ad->itc_2button2.func.state_get = NULL;
108         ad->itc_2button2.func.del = NULL;
109
110         setting_create_Gendial_itc("1icon", &(ad->itc_1button));
111         ad->itc_1button.func.text_get = NULL;
112         ad->itc_1button.func.content_get = appmgrUg_info_1button_gl_icon_get;
113         ad->itc_1button.func.del = NULL;
114
115         setting_create_Gendial_itc("2line.top", &(ad->itc_2txt_2));
116         ad->itc_2txt_2.func.text_get = appmgrUg_pkg_size_gl_label_get;
117 }
118
119 static void appmgrUg_navi_back(void *data, Evas_Object *obj, void *event_info)
120 {
121         SettingAppMgrUG *ad = data;
122
123         ret_if(data == NULL);
124         retm_if(ad->pkg_request, "pkg_request(%d)", ad->pkg_request);
125
126         elm_naviframe_item_pop(obj);
127 }
128
129 static inline Evas_Object *appmgrUg_create_navi(Evas_Object *parent,
130                                                 SettingAppMgrUG *ad)
131 {
132         Evas_Object *navi;
133
134         retv_if(NULL == parent, NULL);
135
136         navi = elm_naviframe_add(parent);
137         elm_naviframe_prev_btn_auto_pushed_set(navi, EINA_FALSE);
138
139         ea_object_event_callback_add(navi, EA_CALLBACK_BACK, appmgrUg_navi_back, ad);
140         ea_object_event_callback_add(navi, EA_CALLBACK_MORE, ea_naviframe_more_cb, ad);
141
142         evas_object_show(navi);
143         return navi;
144 }
145
146 static int appmgrUg_get_tabtype(char *keyword)
147 {
148         retv_if(NULL == keyword, APPMGRUG_TAB_DOWNLOAD);
149
150         if (0 == safeStrCmp(keyword, MGRAPP_STR_DOWNLOADS))
151                 return APPMGRUG_TAB_DOWNLOAD;
152         else if (0 == safeStrCmp(keyword, MGRAPP_STR_RUNNING))
153                 return APPMGRUG_TAB_RUNNING;
154         else if (0 == safeStrCmp(keyword, MGRAPP_STR_ALL))
155                 return APPMGRUG_TAB_ALL;
156         else if (0 == safeStrCmp(keyword, MGRAPP_STR_DEFAULT))
157                 return APPMGRUG_TAB_DEFAULT;
158         else
159                 return APPMGRUG_TAB_DOWNLOAD;
160 }
161
162 static void *appmgrUg_on_create(ui_gadget_h ug, enum ug_mode mode,
163                                 app_control_h service, void *priv)
164 {
165         SETTING_TRACE_BEGIN;
166         char *viewtype = NULL;
167         SettingAppMgrUG *ad = priv;
168         char *search_keyword = NULL;
169
170         retvm_if(NULL == ug || NULL == ad, NULL, "ug=%p, priv=%p is Invalid", ug, ad);
171
172         ad->ug = ug;
173         ad->win = ug_get_window();
174         ad->lo_parent = ug_get_parent_layout(ug);
175         if (NULL == ad->lo_parent) {
176                 SETTING_TRACE_ERROR("ug_get_parent_layout(ug) Fail");
177                 return NULL;
178         }
179
180         appmgrUg_main_init(ad);
181         appmgrUg_pkginfo_init(ad);
182         appmgrUg_appinfo_init(ad);
183
184         appmgrUg_init_itcs(ad);
185
186         /*elm_theme_extension_add(NULL, SETTING_THEME_EDJ_NAME); */
187
188         ad->lo_main = setting_create_win_layout(ad->lo_parent, ad->win);
189         ad->navi = appmgrUg_create_navi(ad->lo_main, ad);
190         if (NULL == ad->navi) {
191                 SETTING_TRACE_ERROR("calloc() Fail");
192                 return NULL;
193         }
194         elm_object_part_content_set(ad->lo_main, "elm.swallow.content", ad->navi);
195
196         app_control_get_extra_data(service, "viewtype", &viewtype);
197         app_control_get_extra_data(service, "keyword", &search_keyword);
198
199         if (0 == safeStrCmp(viewtype, "application-info")) {
200                 /*register view table */
201                 setting_view_node_table_register(&setting_view_appmgr_pkginfo, NULL);
202
203                 SETTING_TRACE("viewtype : %s", viewtype);
204                 char *pkgid = NULL;
205                 app_control_get_extra_data(service, "pkgname", &pkgid);
206                 SETTING_TRACE("pkgname : %s", pkgid);
207                 ad->sel_pkgid = pkgid;
208                 ad->sel_total = -1;
209                 ad->sel_data_size = -1;
210                 ad->support_taskmanager = TRUE;
211                 ad->sel_is_disabled = FALSE;
212                 ad->sel_icon = NULL;
213                 ad->sel_label = NULL;
214                 setting_view_create(ad->pkginfo_view, ad);
215         } else {
216                 /*register view table */
217                 setting_view_node_table_register(&setting_view_appmgr_main, NULL);
218                 setting_view_node_table_register(&setting_view_appmgr_pkginfo, &setting_view_appmgr_main);
219
220                 ad->tabtype = appmgrUg_get_tabtype(search_keyword);
221                 setting_view_create(ad->main_view, ad);
222         }
223         free(viewtype);
224
225         evas_object_event_callback_add(ad->lo_parent, EVAS_CALLBACK_RESIZE, appmgrUg_resize,
226                                        ad);
227         return ad->lo_main;
228 }
229
230 static void appmgrUg_on_destroy(ui_gadget_h ug, app_control_h service, void *priv)
231 {
232         SettingAppMgrUG *ad = priv;
233
234         retm_if(NULL == ug || NULL == ad, "ug=%p, priv=%p is Invalid", ug, ad);
235
236         evas_object_event_callback_del(ad->lo_parent, EVAS_CALLBACK_RESIZE, appmgrUg_resize);
237
238         if (ad->runinfo_view->is_create)
239                 setting_view_destroy(ad->runinfo_view, ad);
240         if (ad->pkginfo_view->is_create)
241                 setting_view_destroy(ad->pkginfo_view, ad);
242         if (ad->main_view->is_create)
243                 setting_view_destroy(ad->main_view, ad);
244
245         if (ad->lo_main) {
246                 evas_object_del(ad->lo_main);
247                 ad->lo_main = NULL;
248         }
249 }
250
251 static void appmgrUg_on_pause(ui_gadget_h ug, app_control_h service, void *priv)
252 {
253         SettingAppMgrUG *ad = priv;
254
255         retm_if(NULL == ug || NULL == ad, "ug=%p, priv=%p is Invalid", ug, ad);
256
257         if (ad->runinfo_view->is_create)
258                 setting_view_update(ad->runinfo_view, ad);
259 }
260
261 static void appmgrUg_on_resume(ui_gadget_h ug, app_control_h service, void *priv)
262 {
263         SettingAppMgrUG *ad = priv;
264
265         retm_if(NULL == ug || NULL == ad, "ug=%p, priv=%p is Invalid", ug, ad);
266
267         if (ad->pkginfo_view->is_create)
268                 setting_view_update(ad->pkginfo_view, ad);
269         if (ad->main_view->is_create)
270                 setting_view_update(ad->main_view, ad);
271
272         evas_object_show(ad->lo_main);
273 }
274
275 static void appmgrUg_on_event(ui_gadget_h ug, enum ug_event event,
276                               app_control_h service, void *priv)
277 {
278         retm_if(NULL == ug || NULL == priv, "ug=%p, priv=%p is Invalid", ug, priv);
279
280         switch (event) {
281                 case UG_EVENT_LOW_MEMORY:
282                 case UG_EVENT_LOW_BATTERY:
283                 case UG_EVENT_LANG_CHANGE:
284                 case UG_EVENT_ROTATE_PORTRAIT:
285                 case UG_EVENT_ROTATE_PORTRAIT_UPSIDEDOWN:
286                 case UG_EVENT_ROTATE_LANDSCAPE:
287                 case UG_EVENT_ROTATE_LANDSCAPE_UPSIDEDOWN:
288                 case UG_EVENT_REGION_CHANGE:
289                 default:
290                         break;
291         }
292 }
293
294 static void appmgrUg_on_key_event(ui_gadget_h ug, enum ug_key_event event,
295                                   app_control_h service, void *priv)
296 {
297         if (!ug)
298                 return;
299
300         switch (event) {
301                 case UG_KEY_EVENT_END:
302                         ug_destroy_me(ug);
303                         break;
304                 default:
305                         break;
306         }
307 }
308
309 UG_MODULE_API int UG_MODULE_INIT(struct ug_module_ops *ops)
310 {
311         SettingAppMgrUG *ad;
312
313         retv_if(NULL == ops, -1);
314
315         ad = calloc(1, sizeof(SettingAppMgrUG));
316         if (NULL == ad) {
317                 SETTING_TRACE_ERROR("calloc() Fail");
318                 return -1;
319         }
320
321         ops->create = appmgrUg_on_create;
322         ops->start = NULL;
323         ops->pause = appmgrUg_on_pause;
324         ops->resume = appmgrUg_on_resume;
325         ops->destroy = appmgrUg_on_destroy;
326         ops->message = NULL;
327         ops->event = appmgrUg_on_event;
328         ops->key_event = appmgrUg_on_key_event;
329         ops->priv = ad;
330         ops->opt = UG_OPT_INDICATOR_ENABLE;
331
332         return 0;
333 }
334
335
336 UG_MODULE_API void UG_MODULE_EXIT(struct ug_module_ops *ops)
337 {
338         ret_if(NULL == ops);
339
340         FREE(ops->priv);
341 }
342
343 UG_MODULE_API int setting_plugin_search_init(app_control_h service, void *priv,
344                                              char **applocale)
345 {
346         int i, size;
347         Setting_Cfg_Node_T *node;
348         Eina_List **pplist = priv;
349         char ug_args[APPMGRUG_MAX_STR_LEN];
350         const Setting_Cfg_Node_T search_configs[] = {
351                 {MGRAPP_STR_DOWNLOADS, NULL, NULL, 0, Cfg_Item_unResetable, 0, Cfg_Item_View_Node, NULL, NULL, NULL, NULL},
352                 {MGRAPP_STR_RUNNING, NULL, NULL, 0, Cfg_Item_unResetable, 0, Cfg_Item_View_Node, NULL, NULL, NULL, NULL},
353                 {MGRAPP_STR_ALL, NULL, NULL, 0, Cfg_Item_unResetable, 0, Cfg_Item_View_Node, NULL, NULL, NULL, NULL},
354                 {MGRAPP_STR_DEFAULT, NULL, NULL, 0, Cfg_Item_unResetable, 0, Cfg_Item_View_Node, NULL, NULL, NULL, NULL}
355         };
356
357         retv_if(NULL == priv, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
358         retv_if(NULL == applocale, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
359
360         *applocale = strdup("setting:/usr/apps/org.tizen.setting/res/locale");
361
362         size = sizeof(search_configs) / sizeof(Setting_Cfg_Node_T);
363
364         for (i = 0; i < size; i++) {
365                 sprintf(ug_args, "keyword:%s", search_configs[i].key_name);
366                 node = setting_plugin_search_item_subindex_add(
367                            search_configs[i].key_name,
368                            ug_args,
369                            IMG_MANAGE_APPS,
370                            search_configs[i].item_type,
371                            search_configs[i].data, "Application Manager");
372
373                 *pplist = eina_list_append(*pplist, node);
374         }
375         return 0;
376 }