4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Jungmin Cho <chivalry.cho@samsung.com>, Gwangho Hwang <gwang.hwang@samsung.com>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
26 #include "simple_util.h"
28 #define MAX_PATH_LEN 1024
30 #define AUL_APP_INFO_FLD_PKG_NAME "package"
31 #define AUL_APP_INFO_FLD_APP_PATH "exec"
32 #define AUL_APP_INFO_FLD_APP_TYPE "x_slp_packagetype"
33 #define AUL_APP_INFO_FLD_WIDTH "x_slp_baselayoutwidth"
34 #define AUL_APP_INFO_FLD_HEIGHT "x_slp_baselayoutheight"
35 #define AUL_APP_INFO_FLD_VERTICAL "x_slp_ishorizontalscale"
36 #define AUL_APP_INFO_FLD_MULTIPLE "x_slp_multiple"
37 #define AUL_APP_INFO_FLD_TASK_MANAGE "x_slp_taskmanage"
38 #define AUL_APP_INFO_FLD_MIMETYPE "mimetype"
39 #define AUL_APP_INFO_FLD_SERVICE "x_slp_service"
41 #define AUL_RETRIEVE_PKG_NAME "package = '?'"
42 #define AUL_RETRIEVE_APP_PATH "exec = '?'"
43 #define AUL_RETRIEVE_MIMETYPE "mimetype like '?'"
44 #define AUL_RETRIEVE_SERVICE "x_slp_service like '?'"
47 char *pkg_name; /* package */
48 char *app_path; /* exec */
49 char *original_app_path; /* exec */
50 char *pkg_type; /* x_slp_packagetype */
51 char *hwacc; /* hwacceleration */
54 static inline char *_get_pkgname(app_info_from_db *menu_info)
56 return menu_info ? menu_info->pkg_name : NULL;
59 static inline char *_get_app_path(app_info_from_db *menu_info)
64 if (!menu_info || menu_info->app_path == NULL)
67 while (menu_info->app_path[i] != 0) {
68 if (menu_info->app_path[i] == ' '
69 || menu_info->app_path[i] == '\t') {
77 free(menu_info->app_path);
78 menu_info->app_path = NULL;
79 } else if (path_len > 0) {
80 char *tmp_app_path = malloc(sizeof(char) * (path_len + 1));
81 if(tmp_app_path == NULL)
83 snprintf(tmp_app_path, path_len + 1, "%s", menu_info->app_path);
84 free(menu_info->app_path);
85 menu_info->app_path = tmp_app_path;
88 return menu_info->app_path;
91 static inline char *_get_original_app_path(app_info_from_db *menu_info)
93 return menu_info ? menu_info->original_app_path : NULL;
96 static inline void _free_app_info_from_db(app_info_from_db *menu_info)
98 if (menu_info != NULL) {
99 if (menu_info->pkg_name != NULL)
100 free(menu_info->pkg_name);
101 if (menu_info->app_path != NULL)
102 free(menu_info->app_path);
103 if (menu_info->original_app_path != NULL)
104 free(menu_info->original_app_path);
105 if (menu_info->hwacc != NULL)
106 free(menu_info->hwacc);
111 static inline app_info_from_db *_get_app_info_from_db_by_pkgname(
114 app_info_from_db *menu_info;
115 ail_appinfo_h handle;
119 menu_info = calloc(1, sizeof(app_info_from_db));
120 if (menu_info == NULL) {
124 ret = ail_get_appinfo(pkgname, &handle);
125 if (ret != AIL_ERROR_OK) {
126 _free_app_info_from_db(menu_info);
130 ret = ail_appinfo_get_str(handle, AIL_PROP_PACKAGE_STR, &str);
132 menu_info->pkg_name = strdup(str);
136 ret = ail_appinfo_get_str(handle, AIL_PROP_EXEC_STR, &str);
138 menu_info->app_path = strdup(str);
142 if (menu_info->app_path != NULL)
143 menu_info->original_app_path = strdup(menu_info->app_path);
145 ret = ail_appinfo_get_str(handle, AIL_PROP_X_SLP_PACKAGETYPE_STR, &str);
147 menu_info->pkg_type = strdup(str);
151 ret = ail_destroy_appinfo(handle);
152 if (ret != AIL_ERROR_OK) {
153 _E("ail_destroy_appinfo failed");
156 if (!_get_app_path(menu_info)) {
157 _free_app_info_from_db(menu_info);
164 static inline ail_cb_ret_e __appinfo_func(const ail_appinfo_h appinfo, void *user_data)
166 app_info_from_db *menu_info = (app_info_from_db *)user_data;
168 ail_cb_ret_e ret = AIL_CB_RET_CONTINUE;
173 ail_appinfo_get_str(appinfo, AIL_PROP_PACKAGE_STR, &package);
175 menu_info->pkg_name = strdup(package);
176 ret = AIL_CB_RET_CANCEL;
182 static inline app_info_from_db *_get_app_info_from_db_by_apppath(
185 app_info_from_db *menu_info = NULL;
193 menu_info = calloc(1, sizeof(app_info_from_db));
194 if (menu_info == NULL)
197 ret = ail_filter_new(&filter);
198 if (ret != AIL_ERROR_OK) {
199 _free_app_info_from_db(menu_info);
203 ret = ail_filter_add_str(filter, AIL_PROP_X_SLP_EXE_PATH, apppath);
204 if (ret != AIL_ERROR_OK) {
205 ail_filter_destroy(filter);
206 _free_app_info_from_db(menu_info);
210 ret = ail_filter_count_appinfo(filter, &count);
211 if (ret != AIL_ERROR_OK) {
212 ail_filter_destroy(filter);
213 _free_app_info_from_db(menu_info);
217 ail_filter_destroy(filter);
218 _free_app_info_from_db(menu_info);
222 ail_filter_list_appinfo_foreach(filter, __appinfo_func, (void *)menu_info);
224 ail_filter_destroy(filter);
226 menu_info->app_path = strdup(apppath);
227 menu_info->original_app_path = strdup(apppath);