tizen 2.3 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         {
177                 SETTING_TRACE_ERROR("ug_get_parent_layout(ug) Fail");
178                 return NULL;
179         }
180
181         appmgrUg_main_init(ad);
182         appmgrUg_pkginfo_init(ad);
183         appmgrUg_appinfo_init(ad);
184
185         appmgrUg_init_itcs(ad);
186
187         //elm_theme_extension_add(NULL, SETTING_THEME_EDJ_NAME);
188
189         ad->lo_main = setting_create_win_layout(ad->lo_parent, ad->win);
190         ad->navi = appmgrUg_create_navi(ad->lo_main, ad);
191         if (NULL == ad->navi)
192         {
193                 SETTING_TRACE_ERROR("calloc() Fail");
194                 return NULL;
195         }
196         elm_object_part_content_set(ad->lo_main, "elm.swallow.content", ad->navi);
197
198         app_control_get_extra_data(service, "viewtype", &viewtype);
199         app_control_get_extra_data(service, "keyword", &search_keyword);
200
201         if (0 == safeStrCmp(viewtype, "application-info"))
202         {
203                 //register view table
204                 setting_view_node_table_register(&setting_view_appmgr_pkginfo, NULL);
205
206                 SETTING_TRACE("viewtype : %s", viewtype);
207                 char *pkgid = NULL;
208                 app_control_get_extra_data(service, "pkgname", &pkgid);
209                 SETTING_TRACE("pkgname : %s", pkgid);
210                 ad->sel_pkgid = pkgid;
211                 ad->sel_total = -1;
212                 ad->sel_data_size = -1;
213                 ad->support_taskmanager = TRUE;
214                 ad->sel_is_disabled = FALSE;
215                 ad->sel_icon = NULL;
216                 ad->sel_label = NULL;
217                 setting_view_create(ad->pkginfo_view, ad);
218         }
219         else
220         {
221                 //register view table
222                 setting_view_node_table_register(&setting_view_appmgr_main, NULL);
223                 setting_view_node_table_register(&setting_view_appmgr_pkginfo, &setting_view_appmgr_main);
224
225                 ad->tabtype = appmgrUg_get_tabtype(search_keyword);
226                 setting_view_create(ad->main_view, ad);
227         }
228         free(viewtype);
229
230         evas_object_event_callback_add(ad->lo_parent, EVAS_CALLBACK_RESIZE, appmgrUg_resize,
231                         ad);
232         return ad->lo_main;
233 }
234
235 static void appmgrUg_on_destroy(ui_gadget_h ug, app_control_h service, void *priv)
236 {
237         SettingAppMgrUG *ad = priv;
238
239         retm_if(NULL == ug || NULL == ad, "ug=%p, priv=%p is Invalid", ug, ad);
240
241         evas_object_event_callback_del(ad->lo_parent, EVAS_CALLBACK_RESIZE, appmgrUg_resize);
242
243         if (ad->runinfo_view->is_create)
244                 setting_view_destroy(ad->runinfo_view, ad);
245         if (ad->pkginfo_view->is_create)
246                 setting_view_destroy(ad->pkginfo_view, ad);
247         if (ad->main_view->is_create)
248                 setting_view_destroy(ad->main_view, ad);
249
250         if (ad->lo_main)
251         {
252                 evas_object_del(ad->lo_main);
253                 ad->lo_main = NULL;
254         }
255 }
256
257 static void appmgrUg_on_pause(ui_gadget_h ug, app_control_h service, void *priv)
258 {
259         SettingAppMgrUG *ad = priv;
260
261         retm_if(NULL == ug || NULL == ad, "ug=%p, priv=%p is Invalid", ug, ad);
262
263         if (ad->runinfo_view->is_create)
264                 setting_view_update(ad->runinfo_view, ad);
265 }
266
267 static void appmgrUg_on_resume(ui_gadget_h ug, app_control_h service, void *priv)
268 {
269         SettingAppMgrUG *ad = priv;
270
271         retm_if(NULL == ug || NULL == ad, "ug=%p, priv=%p is Invalid", ug, ad);
272
273         if (ad->pkginfo_view->is_create)
274                 setting_view_update(ad->pkginfo_view, ad);
275         if (ad->main_view->is_create)
276                 setting_view_update(ad->main_view, ad);
277
278         evas_object_show(ad->lo_main);
279 }
280
281 static void appmgrUg_on_event(ui_gadget_h ug, enum ug_event event,
282                 app_control_h service, void *priv)
283 {
284         retm_if(NULL == ug || NULL == priv, "ug=%p, priv=%p is Invalid", ug, priv);
285
286         switch (event)
287         {
288         case UG_EVENT_LOW_MEMORY:
289         case UG_EVENT_LOW_BATTERY:
290         case UG_EVENT_LANG_CHANGE:
291         case UG_EVENT_ROTATE_PORTRAIT:
292         case UG_EVENT_ROTATE_PORTRAIT_UPSIDEDOWN:
293         case UG_EVENT_ROTATE_LANDSCAPE:
294         case UG_EVENT_ROTATE_LANDSCAPE_UPSIDEDOWN:
295         case UG_EVENT_REGION_CHANGE:
296         default:
297                 break;
298         }
299 }
300
301 static void appmgrUg_on_key_event(ui_gadget_h ug, enum ug_key_event event,
302                 app_control_h service, void *priv)
303 {
304         if (!ug)
305                 return;
306
307         switch (event) {
308         case UG_KEY_EVENT_END:
309                 ug_destroy_me(ug);
310                 break;
311         default:
312                 break;
313         }
314 }
315
316 UG_MODULE_API int UG_MODULE_INIT(struct ug_module_ops *ops)
317 {
318         SettingAppMgrUG *ad;
319
320         retv_if(NULL == ops, -1);
321
322         ad = calloc(1, sizeof(SettingAppMgrUG));
323         if (NULL == ad)
324         {
325                 SETTING_TRACE_ERROR("calloc() Fail");
326                 return -1;
327         }
328
329         ops->create = appmgrUg_on_create;
330         ops->start = NULL;
331         ops->pause = appmgrUg_on_pause;
332         ops->resume = appmgrUg_on_resume;
333         ops->destroy = appmgrUg_on_destroy;
334         ops->message = NULL;
335         ops->event = appmgrUg_on_event;
336         ops->key_event = appmgrUg_on_key_event;
337         ops->priv = ad;
338         ops->opt = UG_OPT_INDICATOR_ENABLE;
339
340         return 0;
341 }
342
343
344 UG_MODULE_API void UG_MODULE_EXIT(struct ug_module_ops *ops)
345 {
346         ret_if(NULL == ops);
347
348         FREE(ops->priv);
349 }
350
351 UG_MODULE_API int setting_plugin_search_init(app_control_h service, void *priv,
352                 char** applocale)
353 {
354         int i, size;
355         Setting_Cfg_Node_T *node;
356         Eina_List **pplist = priv;
357         char ug_args[APPMGRUG_MAX_STR_LEN];
358         const Setting_Cfg_Node_T search_configs[] = {
359                 {MGRAPP_STR_DOWNLOADS, NULL, NULL, 0, Cfg_Item_unResetable, 0, Cfg_Item_View_Node, NULL, NULL, NULL, NULL},
360                 {MGRAPP_STR_RUNNING, NULL, NULL, 0, Cfg_Item_unResetable, 0, Cfg_Item_View_Node, NULL, NULL, NULL, NULL},
361                 {MGRAPP_STR_ALL, NULL, NULL, 0, Cfg_Item_unResetable, 0, Cfg_Item_View_Node, NULL, NULL, NULL, NULL},
362                 {MGRAPP_STR_DEFAULT, NULL, NULL, 0, Cfg_Item_unResetable, 0, Cfg_Item_View_Node, NULL, NULL, NULL, NULL}
363         };
364
365         retv_if(NULL == priv, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
366         retv_if(NULL == applocale, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
367
368         *applocale = strdup("setting:/usr/apps/org.tizen.setting/res/locale");
369
370         size = sizeof(search_configs)/sizeof(Setting_Cfg_Node_T);
371
372         for (i=0;i<size;i++)
373         {
374                 sprintf(ug_args, "keyword:%s", search_configs[i].key_name);
375                 node = setting_plugin_search_item_subindex_add(
376                                 search_configs[i].key_name,
377                                 ug_args,
378                                 IMG_MANAGE_APPS,
379                                 search_configs[i].item_type,
380                                 search_configs[i].data, "Application Manager");
381
382                 *pplist = eina_list_append(*pplist, node);
383         }
384         return 0;
385 }