4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd.
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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include <app_manager.h>
21 #include "setting-appmgr-utils.h"
22 #include "setting-appmgr-runinfo.h"
24 #include <app_manager_extension.h>
26 static setting_view setting_view_appmgr_runinfo;
28 static Eina_Bool appmgrUg_run_back_cb(void *data, Elm_Object_Item *it)
31 SettingAppMgrUG *ad = data;
33 retv_if(NULL == data, EINA_FALSE);
35 setting_view_destroy(ad->runinfo_view, ad);
40 void appmgrUg_free_runinfo(gpointer data)
42 appmgr_runinfo *info = data;
51 static void appmgrUg_del_running_list(gpointer data, gpointer user_data)
53 appmgr_listinfo *pkg_info = data;
57 g_list_free_full(pkg_info->runinfos, appmgrUg_free_runinfo);
58 pkg_info->runinfos = NULL;
61 static inline int appmgrUg_run_get_app_info(const char *appid,
66 pkgmgrinfo_appinfo_h handle;
68 ret = pkgmgrinfo_appinfo_get_appinfo(appid, &handle);
69 if (PMINFO_R_OK != ret) {
70 SETTING_TRACE_ERROR("pkgmgrinfo_appinfo_get_appinfo() Fail(%d)", ret);
74 ret = pkgmgrinfo_appinfo_get_pkgid(handle, &value);
75 if (PMINFO_R_OK != ret) {
76 SETTING_TRACE_ERROR("pkgmgrinfo_appinfo_get_pkgid() Fail(%d)", ret);
77 pkgmgrinfo_appinfo_destroy_appinfo(handle);
80 out->appid = SAFE_STRDUP(value);
82 ret = pkgmgrinfo_appinfo_get_label(handle, &value);
83 warn_if(PMINFO_R_OK != ret, "pkgmgrinfo_appinfo_get_label() Fail(%d)", ret);
84 out->label = SAFE_STRDUP(value);
86 ret = pkgmgrinfo_appinfo_is_taskmanage(handle, &out->can_kill);
87 warn_if(PMINFO_R_OK != ret, "pkgmgrinfo_appinfo_is_taskmanage() Fail(%d)", ret);
89 pkgmgrinfo_appinfo_destroy_appinfo(handle);
93 static int appmgrUg_get_running_list_iter(const aul_app_info *info, void *data)
99 SettingAppMgrUG *ad = data;
100 appmgr_runinfo tmp_info = {NULL, NULL, false};
102 retv_if(NULL == data, 0);
103 retv_if(NULL == info, 0);
104 retv_if(NULL == info->appid, 0);
106 ret = appmgrUg_run_get_app_info(info->appid, &tmp_info);
108 SETTING_TRACE_ERROR("appmgrUg_run_get_app_info(%s) Fail", info->appid);
111 pkgid = tmp_info.appid; /*temporary using */
113 cur = g_list_find_custom(ad->pkg_list, pkgid, appmgrUg_compare_pkgname);
115 appmgr_listinfo *listinfo = cur->data;
116 appmgr_runinfo *runinfo = calloc(1, sizeof(appmgr_runinfo));
119 runinfo->appid = strdup(info->appid);
120 runinfo->label = strdup(tmp_info.label);
121 runinfo->can_kill = tmp_info.can_kill;
122 listinfo->runinfos = g_list_append(listinfo->runinfos, runinfo);
124 SETTING_TRACE_ERROR("calloc() Fail");
130 free(tmp_info.label);
134 static void appmgrUg_run_stop_iter(gpointer data, gpointer user_data)
137 appmgr_runinfo *info = data;
138 app_context_h app_context;
140 ret_if(NULL == data);
142 ret = app_manager_get_app_context(info->appid, &app_context);
143 if (APP_MANAGER_ERROR_NONE != ret) {
144 SETTING_TRACE_ERROR("app_manager_get_app_context(%s) Fail(%d)", info->appid, ret);
149 SETTING_TRACE_ERROR("app_manager_terminate_app is not External interface. need check in more detail.");
151 ret = app_manager_terminate_app(app_context);
152 if (APP_MANAGER_ERROR_NONE != ret) {
153 SETTING_TRACE_ERROR("app_manager_terminate_app() Fail(%d)", ret);
158 app_context_destroy(app_context);
161 void appmgrUg_run_stop_click(void *data, Evas_Object *obj,
164 SettingAppMgrUG *ad = data;
166 ret_if(NULL == data);
168 g_list_foreach(ad->runinfos, appmgrUg_run_stop_iter, NULL);
169 /*remove runinfos in running listinfo */
170 if (ad->info_run && ad->info_run->runinfos) {
171 g_list_free_full(ad->info_run->runinfos, appmgrUg_free_runinfo);
172 ad->info_run->runinfos = NULL;
175 if (APPMGRUG_TAB_RUNNING == ad->tabtype) {
176 elm_naviframe_item_pop(ad->navi);
177 } else if (APPMGRUG_TAB_DISABLED == ad->tabtype) {
178 elm_object_disabled_set(obj, EINA_TRUE);
181 setting_view_update(ad->main_view, ad);
184 static void appmgrUg_run_append_run_apps(SettingAppMgrUG *ad)
188 Setting_GenGroupItem_Data *d_item = NULL;
194 appmgr_runinfo *info;
200 SETTING_TRACE_ERROR("info is a null");
204 d_item = setting_create_Gendial_field_def(ad->gl_run, &ad->itc_1txt_1ic_2, NULL,
205 NULL, SWALLOW_Type_1ICON_SMALL_ICON, (char *)ad->sel_icon, NULL, 0, info->label,
207 if (NULL == d_item) {
208 SETTING_TRACE_ERROR("setting_create_Gendial_field_def() Fail");
211 elm_genlist_item_select_mode_set(d_item->item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
215 retm_if(NULL == d_item, "No item");
218 static int appmgrUg_run_create(void *data)
221 Elm_Object_Item *item;
222 SettingAppMgrUG *ad = data;
225 retv_if(NULL == data, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
227 Elm_Object_Item *navi_item = setting_push_layout_navi_bar_genlist(ad->lo_parent, ad->win,
228 MGRAPP_STR_ACTIVE_APP, NULL, NULL,
229 appmgrUg_run_back_cb,
230 NULL, ad, &ad->gl_run, ad->navi);
231 elm_naviframe_item_pop_cb_set(navi_item, appmgrUg_run_back_cb, ad);
233 elm_genlist_mode_set(ad->gl_run, ELM_LIST_COMPRESS);
235 //appmgrUg_append_separator(ad->gl_run, ad);
237 /* Title (pkg name, process N) */
238 item = elm_genlist_item_append(ad->gl_run, &ad->itc_info_title, ad, NULL,
239 ELM_GENLIST_ITEM_NONE, NULL, NULL);
240 elm_genlist_item_select_mode_set(item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
242 //appmgrUg_append_separator(ad->gl_run, ad);
245 snprintf(msg, sizeof(msg), _(MGRAPP_STR_APP_STOP_MSG), ad->sel_label, ad->sel_label);
246 setting_create_Gendial_field_titleItem(ad->gl_run, &ad->itc_multiline, msg, NULL);
249 elm_genlist_item_append(ad->gl_run, &ad->itc_1ic, ad, NULL, ELM_GENLIST_ITEM_NONE,
252 //appmgrUg_append_separator(ad->gl_run, ad);
254 /* group title(applications) */
255 setting_create_Gendial_field_titleItem(ad->gl_run, &ad->itc_grp_title,
256 MGRAPP_STR_APPS, NULL);
258 appmgrUg_run_append_run_apps(ad);
260 //appmgrUg_append_separator(ad->gl_run, ad);
262 setting_view_appmgr_runinfo.is_create = 1;
264 return SETTING_RETURN_SUCCESS;
267 static int appmgrUg_run_destroy(void *data)
270 SettingAppMgrUG *ad = data;
272 setting_view_appmgr_runinfo.is_create = 0;
273 elm_naviframe_item_pop(ad->navi);
275 retv_if(NULL == data, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
283 return SETTING_RETURN_SUCCESS;
286 static int appmgrUg_run_update(void *data)
290 SettingAppMgrUG *ad = data;
292 retv_if(NULL == data, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
294 elm_naviframe_item_pop(ad->navi);
297 return SETTING_RETURN_SUCCESS;
300 static int appmgrUg_run_cleanup(void *data)
302 return appmgrUg_run_destroy(data);
305 void appmgrUg_appinfo_init(SettingAppMgrUG *ad)
308 ret_if(ad->runinfo_view);
310 setting_view_appmgr_runinfo.create = appmgrUg_run_create;
311 setting_view_appmgr_runinfo.destroy = appmgrUg_run_destroy;
312 setting_view_appmgr_runinfo.update = appmgrUg_run_update;
313 setting_view_appmgr_runinfo.cleanup = appmgrUg_run_cleanup;
315 ad->runinfo_view = &setting_view_appmgr_runinfo;
318 Evas_Object *appmgrUg_run_gl_stop_btn(void *data, Evas_Object *obj,
323 SettingAppMgrUG *ad = data;
325 retv_if(NULL == data, NULL);
326 if (0 != safeStrCmp(part, "elm.icon"))
329 Evas_Object *box = elm_box_add(obj);
330 elm_box_horizontal_set(box, 1);
331 elm_box_align_set(box, 0.0, 0.5);
332 elm_box_padding_set(box, 10, 0);
334 btn = setting_create_button(box, MGRAPP_STR_STOP, NULL, appmgrUg_run_stop_click, ad);
338 appmgr_runinfo *info;
352 elm_object_disabled_set(btn, EINA_TRUE);
353 elm_object_disabled_set(obj, EINA_TRUE);
356 elm_box_pack_end(box, btn);
357 evas_object_show(btn);
358 evas_object_show(box);
362 int appmgrUg_get_running_list(SettingAppMgrUG *ad)
366 retv_if(NULL == ad, SETTING_RETURN_FAIL);
368 g_list_foreach(ad->pkg_list, appmgrUg_del_running_list, NULL);
370 ret = aul_app_get_running_app_info(appmgrUg_get_running_list_iter, ad);
371 warn_if(AUL_R_OK != ret, "aul_app_get_running_app_info() Fail", ret);
372 ad->is_runlist_ready = EINA_TRUE;
373 return SETTING_RETURN_SUCCESS;