Fix logic of getting localized values 80/48580/2 accepted/tizen/mobile/20150923.231048 accepted/tizen/tv/20150923.231056 accepted/tizen/wearable/20150923.231109 submit/tizen/20150923.091423
authorSangyoon Jang <s89.jang@samsung.com>
Wed, 23 Sep 2015 07:51:35 +0000 (16:51 +0900)
committerSangyoon Jang <s89.jang@samsung.com>
Wed, 23 Sep 2015 09:10:57 +0000 (02:10 -0700)
try to get value whose locale is same as system locale
if failed, then try again with default locale

Change-Id: I3bcac5bbf34e338f859c77c7345b6099d935c50e
Signed-off-by: Sangyoon Jang <s89.jang@samsung.com>
src/pkgmgrinfo_appinfo.c
src/pkgmgrinfo_pkginfo.c

index c681971..931f9cd 100644 (file)
@@ -939,7 +939,7 @@ API int pkgmgrinfo_appinfo_get_exec(pkgmgrinfo_appinfo_h handle, char **exec)
 
 API int pkgmgrinfo_appinfo_get_icon(pkgmgrinfo_appinfo_h handle, char **icon)
 {
-        char *locale;
+        const char *locale;
         icon_x *ptr;
         icon_x *start;
         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
@@ -952,21 +952,18 @@ API int pkgmgrinfo_appinfo_get_icon(pkgmgrinfo_appinfo_h handle, char **icon)
 
        start = info->app_info->icon;
        for (ptr = start; ptr != NULL; ptr = ptr->next) {
-               if (ptr->lang == NULL)
+               if (ptr->text == NULL || ptr->lang == NULL || strcmp(ptr->lang, locale))
                        continue;
+               *icon = (char *)ptr->text;
+               return PMINFO_R_OK;
+       }
 
-               if (strcmp(ptr->lang, locale) == 0) {
-                       *icon = (char *)ptr->text;
-                       if (strcasecmp(*icon, "(null)") == 0) {
-                               locale = DEFAULT_LOCALE;
-                               continue;
-                       } else {
-                               return PMINFO_R_OK;
-                       }
-               } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
-                       *icon = (char *)ptr->text;
-                       return PMINFO_R_OK;
-               }
+       locale = DEFAULT_LOCALE;
+       for (ptr = start; ptr != NULL; ptr = ptr->next) {
+               if (ptr->text == NULL || ptr->lang == NULL || strcmp(ptr->lang, locale))
+                       continue;
+               *icon = (char *)ptr->text;
+               return PMINFO_R_OK;
        }
 
        return PMINFO_R_ERROR;
@@ -975,7 +972,7 @@ API int pkgmgrinfo_appinfo_get_icon(pkgmgrinfo_appinfo_h handle, char **icon)
 
 API int pkgmgrinfo_appinfo_get_label(pkgmgrinfo_appinfo_h handle, char **label)
 {
-       char *locale;
+       const char *locale;
        label_x *ptr;
        label_x *start;
        pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
@@ -988,21 +985,18 @@ API int pkgmgrinfo_appinfo_get_label(pkgmgrinfo_appinfo_h handle, char **label)
 
        start = info->app_info->label;
        for (ptr = start; ptr != NULL; ptr = ptr->next) {
-               if (ptr->lang == NULL)
+               if (ptr->text == NULL || ptr->lang == NULL || strcmp(ptr->lang, locale))
                        continue;
+               *label = (char *)ptr->text;
+               return PMINFO_R_OK;
+       }
 
-               if (strcmp(ptr->lang, locale) == 0) {
-                       *label = (char *)ptr->text;
-                       if (strcasecmp(*label, "(null)") == 0) {
-                               locale = DEFAULT_LOCALE;
-                               continue;
-                       } else {
-                               return PMINFO_R_OK;
-                       }
-               } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
-                       *label = (char *)ptr->text;
-                       return PMINFO_R_OK;
-               }
+       locale = DEFAULT_LOCALE;
+       for (ptr = start; ptr != NULL; ptr = ptr->next) {
+               if (ptr->text == NULL || ptr->lang == NULL || strcmp(ptr->lang, locale))
+                       continue;
+               *label = (char *)ptr->text;
+               return PMINFO_R_OK;
        }
 
        return PMINFO_R_ERROR;
index 1427f53..8ffdf1f 100644 (file)
@@ -1121,7 +1121,7 @@ API int pkgmgrinfo_pkginfo_get_data_size(pkgmgrinfo_pkginfo_h handle, int *size)
 
 API int pkgmgrinfo_pkginfo_get_icon(pkgmgrinfo_pkginfo_h handle, char **icon)
 {
-       char *locale;
+       const char *locale;
        icon_x *ptr;
        pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
 
@@ -1132,21 +1132,18 @@ API int pkgmgrinfo_pkginfo_get_icon(pkgmgrinfo_pkginfo_h handle, char **icon)
        retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
 
        for (ptr = info->pkg_info->icon; ptr != NULL; ptr = ptr->next) {
-               if (ptr->lang == NULL)
+               if (ptr->text == NULL || ptr->lang == NULL || strcmp(ptr->lang, locale))
                        continue;
+               *icon = (char *)ptr->text;
+               return PMINFO_R_OK;
+       }
 
-               if (strcmp(ptr->lang, locale) == 0) {
-                       *icon = (char *)ptr->text;
-                       if (strcasecmp(*icon, "(null)") == 0) {
-                               locale = DEFAULT_LOCALE;
-                               continue;
-                       } else {
-                               return PMINFO_R_OK;
-                       }
-               } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
-                       *icon = (char *)ptr->text;
-                       return PMINFO_R_OK;
-               }
+       locale = DEFAULT_LOCALE;
+       for (ptr = info->pkg_info->icon; ptr != NULL; ptr = ptr->next) {
+               if (ptr->text == NULL || ptr->lang == NULL || strcmp(ptr->lang, locale))
+                       continue;
+               *icon = (char *)ptr->text;
+               return PMINFO_R_OK;
        }
 
        return PMINFO_R_ERROR;
@@ -1154,7 +1151,7 @@ API int pkgmgrinfo_pkginfo_get_icon(pkgmgrinfo_pkginfo_h handle, char **icon)
 
 API int pkgmgrinfo_pkginfo_get_label(pkgmgrinfo_pkginfo_h handle, char **label)
 {
-       char *locale;
+       const char *locale;
        label_x *ptr;
        pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
 
@@ -1165,21 +1162,18 @@ API int pkgmgrinfo_pkginfo_get_label(pkgmgrinfo_pkginfo_h handle, char **label)
        retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
 
        for (ptr = info->pkg_info->label; ptr != NULL; ptr = ptr->next) {
-               if (ptr->lang == NULL)
+               if (ptr->text == NULL || ptr->lang == NULL || strcmp(ptr->lang, locale))
                        continue;
+               *label = (char *)ptr->text;
+               return PMINFO_R_OK;
+       }
 
-               if (strcmp(ptr->lang, locale) == 0) {
-                       *label = (char *)ptr->text;
-                       if (strcasecmp(*label, "(null)") == 0) {
-                               locale = DEFAULT_LOCALE;
-                               continue;
-                       } else {
-                               return PMINFO_R_OK;
-                       }
-               } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
-                       *label = (char *)ptr->text;
-                       return PMINFO_R_OK;
-               }
+       locale = DEFAULT_LOCALE;
+       for (ptr = info->pkg_info->label; ptr != NULL; ptr = ptr->next) {
+               if (ptr->text == NULL || ptr->lang == NULL || strcmp(ptr->lang, locale))
+                       continue;
+               *label = (char *)ptr->text;
+               return PMINFO_R_OK;
        }
 
        return PMINFO_R_ERROR;
@@ -1187,7 +1181,7 @@ API int pkgmgrinfo_pkginfo_get_label(pkgmgrinfo_pkginfo_h handle, char **label)
 
 API int pkgmgrinfo_pkginfo_get_description(pkgmgrinfo_pkginfo_h handle, char **description)
 {
-       char *locale;
+       const char *locale;
        description_x *ptr;
        pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
 
@@ -1198,21 +1192,18 @@ API int pkgmgrinfo_pkginfo_get_description(pkgmgrinfo_pkginfo_h handle, char **d
        retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
 
        for (ptr = info->pkg_info->description; ptr != NULL; ptr = ptr->next) {
-               if (ptr->lang == NULL)
+               if (ptr->text == NULL || ptr->lang == NULL || strcmp(ptr->lang, locale))
                        continue;
+               *description = (char *)ptr->text;
+               return PMINFO_R_OK;
+       }
 
-               if (strcmp(ptr->lang, locale) == 0) {
-                       *description = (char *)ptr->text;
-                       if (strcasecmp(*description, PKGMGR_PARSER_EMPTY_STR) == 0) {
-                               locale = DEFAULT_LOCALE;
-                               continue;
-                       } else {
-                               return PMINFO_R_OK;
-                       }
-               } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
-                       *description = (char *)ptr->text;
-                       return PMINFO_R_OK;
-               }
+       locale = DEFAULT_LOCALE;
+       for (ptr = info->pkg_info->description; ptr != NULL; ptr = ptr->next) {
+               if (ptr->text == NULL || ptr->lang == NULL || strcmp(ptr->lang, locale))
+                       continue;
+               *description = (char *)ptr->text;
+               return PMINFO_R_OK;
        }
 
        return PMINFO_R_ERROR;