From: Sangyoon Jang Date: Tue, 6 Jan 2015 05:29:41 +0000 (+0900) Subject: Add api from tizen 2.3 : pkgmgrinfo_appinfo_get_localed_label X-Git-Tag: accepted/tizen/mobile/20150121.045016^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;ds=sidebyside;h=b6b74a6099b668c20b5bde619972ab49c34bb1b7;p=platform%2Fcore%2Fappfw%2Fpkgmgr-info.git Add api from tizen 2.3 : pkgmgrinfo_appinfo_get_localed_label Change-Id: I3ea422055376763ef5ed0a1dc8d8ae6a2cb75084 Signed-off-by: Sangyoon Jang --- diff --git a/include/pkgmgr-info.h b/include/pkgmgr-info.h index f08cd9e..901015b 100644 --- a/include/pkgmgr-info.h +++ b/include/pkgmgr-info.h @@ -2523,6 +2523,41 @@ static int get_app_label(const char *appid) int pkgmgrinfo_appinfo_get_label(pkgmgrinfo_appinfo_h handle, char **label); /** + * @fn int pkgmgrinfo_appinfo_get_localed_label(const char *appid, const char *locale, char **label) + * @brief This API gets exactly matched label by given appid and locale + * + * @par This API is for package-manager client application + * @par Sync (or) Async : Synchronous API + * + * @param[in] appid pointer to appid + * @param[in] locale pointer to locale + * @param[out] label pointer to hold app label + * @return 0 if success, error code(<0) if fail + * @retval PMINFO_R_OK success + * @retval PMINFO_R_EINVAL invalid argument + * @retval PMINFO_R_ERROR internal error + * @code +static int get_localed_label(const char *appid, const char *locale) +{ + int ret = 0; + char *label = NULL; + + ret = pkgmgrinfo_appinfo_get_localed_label(appid, locale, &label); + if (ret != PMINFO_R_OK) + return -1; + + printf("localed label: %s\n", label); + + free(label); + + return 0; +} + * @endcode + */ +int pkgmgrinfo_appinfo_get_localed_label(const char *appid, const char *locale, char **label); +int pkgmgrinfo_appinfo_usr_get_localed_label(const char *appid, const char *locale, uid_t uid, char **label); + +/** * @fn int pkgmgrinfo_appinfo_get_component(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_component *component) * @brief This API gets the component of the application * diff --git a/src/pkgmgr-info.c b/src/pkgmgr-info.c index a7392a7..b82c865 100644 --- a/src/pkgmgr-info.c +++ b/src/pkgmgr-info.c @@ -5545,6 +5545,76 @@ API int pkgmgrinfo_appinfo_get_label(pkgmgrinfo_appinfo_h handle, char **label) return PMINFO_R_OK; } +static char *_get_localed_label(const char *appid, const char *locale, uid_t uid) +{ + char *result = NULL; + char *query = NULL; + sqlite3_stmt *stmt = NULL; + sqlite3 *db = NULL; + char *val; + char *manifest_db; + + manifest_db = getUserPkgParserDBPathUID(uid); + if (manifest_db == NULL) { + _LOGE("Failed to get manifest db path"); + goto err; + } + + if (sqlite3_open_v2(manifest_db, &db, SQLITE_OPEN_READONLY, NULL) != SQLITE_OK) { + _LOGE("DB open fail\n"); + goto err; + } + + query = sqlite3_mprintf("select app_label from package_app_localized_info where app_id=%Q and app_locale=%Q", appid, locale); + if (query == NULL) { + _LOGE("Out of memory"); + goto err; + } + + if (sqlite3_prepare_v2(db, query, -1, &stmt, NULL) != SQLITE_OK) { + _LOGE("prepare_v2 fail\n"); + goto err; + } + + if (sqlite3_step(stmt) == SQLITE_ROW) { + val = (char *)sqlite3_column_text(stmt, 0); + if (val != NULL) + result = strdup(val); + } + +err: + sqlite3_finalize(stmt); + sqlite3_free(query); + sqlite3_close(db); + + return result; +} + +API int pkgmgrinfo_appinfo_usr_get_localed_label(const char *appid, const char *locale, uid_t uid, char **label) +{ + char *val; + int ret; + + retvm_if(appid == NULL || locale == NULL || label == NULL, PMINFO_R_EINVAL, "Argument is NULL"); + + val = _get_localed_label(appid, locale, uid); + if (val == NULL) + val = _get_localed_label(appid, DEFAULT_LOCALE, uid); + + if (val == NULL) { + ret = PMINFO_R_ERROR; + } else { + *label = val; + ret = PMINFO_R_OK; + } + + return ret; +} + +API int pkgmgrinfo_appinfo_get_localed_label(const char *appid, const char *locale, char **label) +{ + return pkgmgrinfo_appinfo_usr_get_localed_label(appid, locale, GLOBAL_USER, label); +} API int pkgmgrinfo_appinfo_get_component(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_component *component) {