tizen 2.4 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_extension.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(SETTING_GENLIST_GROUP_INDEX_STYLE, &(ad->itc_grp_title));
69         setting_create_Gendial_itc("multiline_sub", &(ad->itc_multiline));
70         setting_create_Gendial_itc(SETTING_GENLIST_ICON_1LINE_STYLE, &(ad->itc_1txt_1ic_2));
71         setting_create_Gendial_itc(SETTING_GENLIST_ICON_1LINE_STYLE, &(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         #if OLD_GENLIST_STYLE
81         ad->itc_main.item_style = SETTING_GENLIST_2LINE_STYLE;
82         ad->itc_main.func.text_get = appmgrUg_main_gl_label_get;
83         ad->itc_main.func.content_get = appmgrUg_main_gl_icon_get;
84         ad->itc_main.func.state_get = NULL;
85         ad->itc_main.func.del = _main_gl_del_cb;
86         #else
87         ad->itc_main.item_style = SETTING_GENLIST_2LINE_STYLE;
88         ad->itc_main.func.text_get = appmgrUg_main_gl_label_new_get;
89         ad->itc_main.func.content_get = appmgrUg_main_gl_icon_new_get;
90         ad->itc_main.func.state_get = NULL;
91         ad->itc_main.func.del = _main_gl_del_cb;
92         #endif
93
94         ad->itc_1ic.item_style = "1icon";
95         ad->itc_1ic.func.text_get = NULL;
96         ad->itc_1ic.func.content_get = appmgrUg_run_gl_stop_btn;
97         ad->itc_1ic.func.state_get = NULL;
98         ad->itc_1ic.func.del = NULL;
99
100         #if OLD_GENLIST_STYLE
101         ad->itc_info_title.item_style = SETTING_GENLIST_2LINE_STYLE;
102         ad->itc_info_title.func.text_get = appmgrUg_info_title_gl_label_get;
103         ad->itc_info_title.func.content_get = appmgrUg_info_title_gl_icon_get;
104         ad->itc_info_title.func.state_get = NULL;
105         ad->itc_info_title.func.del = NULL;
106         #else
107         ad->itc_info_title.item_style = SETTING_GENLIST_2LINE_STYLE;
108         ad->itc_info_title.func.text_get = appmgrUg_info_title_gl_label_get;
109         ad->itc_info_title.func.content_get = appmgrUg_info_title_gl_icon_get;
110         ad->itc_info_title.func.state_get = NULL;
111         ad->itc_info_title.func.del = NULL;
112         #endif
113
114         ad->itc_2button1.item_style = "1icon";
115         ad->itc_2button1.func.text_get = NULL;
116         ad->itc_2button1.func.content_get = appmgrUg_info_2button1_gl_icon_get;
117         ad->itc_2button1.func.state_get = NULL;
118         ad->itc_2button1.func.del = NULL;
119
120         ad->itc_2button2.item_style = "1icon";
121         ad->itc_2button2.func.text_get = NULL;
122         ad->itc_2button2.func.content_get = appmgrUg_info_2button2_gl_icon_get;
123         ad->itc_2button2.func.state_get = NULL;
124         ad->itc_2button2.func.del = NULL;
125
126         setting_create_Gendial_itc("1icon", &(ad->itc_1button));
127         ad->itc_1button.func.text_get = NULL;
128         ad->itc_1button.func.content_get = appmgrUg_info_1button_gl_icon_get;
129         ad->itc_1button.func.del = NULL;
130
131         setting_create_Gendial_itc(SETTING_GENLIST_2LINE_STYLE, &(ad->itc_2txt_2));
132         ad->itc_2txt_2.func.text_get = appmgrUg_pkg_size_gl_label_get;
133 }
134
135 static void appmgrUg_navi_back(void *data, Evas_Object *obj, void *event_info)
136 {
137         SETTING_TRACE_BEGIN;
138         SettingAppMgrUG *ad = data;
139
140         ret_if(data == NULL);
141         retm_if(ad->pkg_request, "pkg_request(%d)", ad->pkg_request);
142
143         elm_naviframe_item_pop(obj);
144 }
145
146 static inline Evas_Object *appmgrUg_create_navi(Evas_Object *parent,
147                                                 SettingAppMgrUG *ad)
148 {
149         Evas_Object *navi;
150
151         retv_if(NULL == parent, NULL);
152
153         navi = elm_naviframe_add(parent);
154         elm_naviframe_prev_btn_auto_pushed_set(navi, EINA_FALSE);
155
156         eext_object_event_callback_add(navi, EEXT_CALLBACK_BACK, appmgrUg_navi_back, ad);
157         eext_object_event_callback_add(navi, EEXT_CALLBACK_MORE, eext_naviframe_more_cb, ad);
158
159         evas_object_show(navi);
160         return navi;
161 }
162
163 static int appmgrUg_get_tabtype(char *keyword)
164 {
165         retv_if(NULL == keyword, APPMGRUG_TAB_DOWNLOAD);
166
167         if (0 == safeStrCmp(keyword, MGRAPP_STR_DOWNLOADS))
168                 return APPMGRUG_TAB_DOWNLOAD;
169         else if (0 == safeStrCmp(keyword, MGRAPP_STR_RUNNING))
170                 return APPMGRUG_TAB_RUNNING;
171         else if (0 == safeStrCmp(keyword, MGRAPP_STR_ALL))
172                 return APPMGRUG_TAB_ALL;
173         else
174                 return APPMGRUG_TAB_DOWNLOAD;
175 }
176
177 static void *appmgrUg_on_create(ui_gadget_h ug, enum ug_mode mode,
178                                 app_control_h service, void *priv)
179 {
180         SETTING_TRACE_BEGIN;
181
182         char *viewtype = NULL;
183         SettingAppMgrUG *ad = priv;
184         char *search_keyword = NULL;
185
186         retvm_if(NULL == ug || NULL == ad, NULL, "ug=%p, priv=%p is Invalid", ug, ad);
187
188         bindtextdomain(SETTING_PACKAGE, SETTING_LOCALEDIR);
189         textdomain(SETTING_PACKAGE);
190
191         ad->ug = ug;
192         ad->win = ug_get_window();
193         ad->lo_parent = ug_get_parent_layout(ug);
194         if (NULL == ad->lo_parent) {
195                 SETTING_TRACE_ERROR("ug_get_parent_layout(ug) Fail");
196                 return NULL;
197         }
198
199         appmgrUg_main_init(ad);
200         appmgrUg_pkginfo_init(ad);
201         appmgrUg_appinfo_init(ad);
202
203         appmgrUg_init_itcs(ad);
204
205         /*elm_theme_extension_add(NULL, SETTING_THEME_EDJ_NAME); */
206
207         ad->lo_main = setting_create_win_layout(ad->win);
208         ad->navi = appmgrUg_create_navi(ad->lo_main, ad);
209         if (NULL == ad->navi) {
210                 SETTING_TRACE_ERROR("calloc() Fail");
211                 return NULL;
212         }
213         elm_object_part_content_set(ad->lo_main, "elm.swallow.content", ad->navi);
214
215         app_control_get_extra_data(service, "viewtype", &viewtype);
216         app_control_get_extra_data(service, "keyword", &search_keyword);
217
218         if (0 == safeStrCmp(viewtype, "application-info")) {
219                 /*register view table */
220                 setting_view_node_table_register(&setting_view_appmgr_pkginfo, NULL);
221
222                 SETTING_TRACE("viewtype : %s", viewtype);
223                 char *pkgid = NULL;
224                 app_control_get_extra_data(service, "pkgname", &pkgid);
225                 SETTING_TRACE("pkgname : %s", pkgid);
226                 ad->sel_pkgid = pkgid;
227                 ad->sel_total = -1;
228                 ad->sel_data_size = -1;
229                 ad->support_taskmanager = TRUE;
230                 ad->sel_is_disabled = FALSE;
231                 ad->sel_icon = NULL;
232                 ad->sel_label = NULL;
233                 setting_view_create(ad->pkginfo_view, ad);
234         } else {
235                 /*register view table */
236                 setting_view_node_table_register(&setting_view_appmgr_main, NULL);
237                 setting_view_node_table_register(&setting_view_appmgr_pkginfo, &setting_view_appmgr_main);
238
239                 ad->tabtype = appmgrUg_get_tabtype(search_keyword);
240                 setting_view_create(ad->main_view, ad);
241         }
242         free(viewtype);
243
244         evas_object_event_callback_add(ad->lo_parent, EVAS_CALLBACK_RESIZE, appmgrUg_resize,
245                                        ad);
246         return ad->lo_main;
247 }
248
249 static void appmgrUg_on_destroy(ui_gadget_h ug, app_control_h service, void *priv)
250 {
251         SettingAppMgrUG *ad = priv;
252
253         retm_if(NULL == ug || NULL == ad, "ug=%p, priv=%p is Invalid", ug, ad);
254
255         evas_object_event_callback_del(ad->lo_parent, EVAS_CALLBACK_RESIZE, appmgrUg_resize);
256
257         if (ad->runinfo_view->is_create)
258                 setting_view_destroy(ad->runinfo_view, ad);
259         if (ad->pkginfo_view->is_create)
260                 setting_view_destroy(ad->pkginfo_view, ad);
261         if (ad->main_view->is_create)
262                 setting_view_destroy(ad->main_view, ad);
263
264         if (ad->lo_main) {
265                 evas_object_del(ad->lo_main);
266                 ad->lo_main = NULL;
267         }
268 }
269
270 static void appmgrUg_on_pause(ui_gadget_h ug, app_control_h service, void *priv)
271 {
272         SettingAppMgrUG *ad = priv;
273
274         retm_if(NULL == ug || NULL == ad, "ug=%p, priv=%p is Invalid", ug, ad);
275
276         if (ad->runinfo_view->is_create)
277                 setting_view_update(ad->runinfo_view, ad);
278 }
279
280 static void appmgrUg_on_resume(ui_gadget_h ug, app_control_h service, void *priv)
281 {
282         SettingAppMgrUG *ad = priv;
283
284         retm_if(NULL == ug || NULL == ad, "ug=%p, priv=%p is Invalid", ug, ad);
285
286         if (ad->pkginfo_view->is_create)
287                 setting_view_update(ad->pkginfo_view, ad);
288         if (ad->main_view->is_create)
289                 setting_view_update(ad->main_view, ad);
290
291         evas_object_show(ad->lo_main);
292 }
293
294 static void appmgrUg_on_event(ui_gadget_h ug, enum ug_event event,
295                               app_control_h service, void *priv)
296 {
297         retm_if(NULL == ug || NULL == priv, "ug=%p, priv=%p is Invalid", ug, priv);
298
299         switch (event) {
300                 case UG_EVENT_LOW_MEMORY:
301                 case UG_EVENT_LOW_BATTERY:
302                 case UG_EVENT_LANG_CHANGE:
303                 case UG_EVENT_ROTATE_PORTRAIT:
304                 case UG_EVENT_ROTATE_PORTRAIT_UPSIDEDOWN:
305                 case UG_EVENT_ROTATE_LANDSCAPE:
306                 case UG_EVENT_ROTATE_LANDSCAPE_UPSIDEDOWN:
307                 case UG_EVENT_REGION_CHANGE:
308                 default:
309                         break;
310         }
311 }
312
313 static void appmgrUg_on_key_event(ui_gadget_h ug, enum ug_key_event event,
314                                   app_control_h service, void *priv)
315 {
316         if (!ug)
317                 return;
318
319         switch (event) {
320                 case UG_KEY_EVENT_END:
321                         ug_destroy_me(ug);
322                         break;
323                 default:
324                         break;
325         }
326 }
327
328 UG_MODULE_API int UG_MODULE_INIT(struct ug_module_ops *ops)
329 {
330         SettingAppMgrUG *ad;
331
332         retv_if(NULL == ops, -1);
333
334         ad = calloc(1, sizeof(SettingAppMgrUG));
335         if (NULL == ad) {
336                 SETTING_TRACE_ERROR("calloc() Fail");
337                 return -1;
338         }
339
340         ops->create = appmgrUg_on_create;
341         ops->start = NULL;
342         ops->pause = appmgrUg_on_pause;
343         ops->resume = appmgrUg_on_resume;
344         ops->destroy = appmgrUg_on_destroy;
345         ops->message = NULL;
346         ops->event = appmgrUg_on_event;
347         ops->key_event = appmgrUg_on_key_event;
348         ops->priv = ad;
349         ops->opt = UG_OPT_INDICATOR_ENABLE;
350
351         return 0;
352 }
353
354
355 UG_MODULE_API void UG_MODULE_EXIT(struct ug_module_ops *ops)
356 {
357         ret_if(NULL == ops);
358
359         FREE(ops->priv);
360 }
361
362 UG_MODULE_API int setting_plugin_search_init(app_control_h service, void *priv,
363                                              char **applocale)
364 {
365         int i, size;
366         Setting_Cfg_Node_T *node;
367         Eina_List **pplist = priv;
368         char ug_args[APPMGRUG_MAX_STR_LEN];
369         const Setting_Cfg_Node_T search_configs[] = {
370                 {MGRAPP_STR_DOWNLOADS, NULL, NULL, 0, Cfg_Item_unResetable, 0, Cfg_Item_View_Node, NULL, NULL, NULL, NULL},
371                 {MGRAPP_STR_RUNNING, NULL, NULL, 0, Cfg_Item_unResetable, 0, Cfg_Item_View_Node, NULL, NULL, NULL, NULL},
372                 {MGRAPP_STR_ALL, NULL, NULL, 0, Cfg_Item_unResetable, 0, Cfg_Item_View_Node, NULL, NULL, NULL, NULL},
373         };
374
375         retv_if(NULL == priv, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
376         retv_if(NULL == applocale, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
377
378         *applocale = strdup("setting:/usr/apps/org.tizen.setting/res/locale");
379
380         size = sizeof(search_configs) / sizeof(Setting_Cfg_Node_T);
381
382         for (i = 0; i < size; i++) {
383                 sprintf(ug_args, "keyword:%s", search_configs[i].key_name);
384                 node = setting_plugin_search_item_subindex_add(
385                            search_configs[i].key_name,
386                            ug_args,
387                            IMG_Applications,
388                            search_configs[i].item_type,
389                            search_configs[i].data, "Application Manager");
390
391                 *pplist = eina_list_append(*pplist, node);
392         }
393         return 0;
394 }