Get preview path base on language 07/126707/1 accepted/tizen/3.0/common/20170508.153017 accepted/tizen/3.0/ivi/20170508.050505 accepted/tizen/3.0/mobile/20170508.050444 accepted/tizen/3.0/tv/20170508.050452 accepted/tizen/3.0/wearable/20170508.050455 submit/tizen_3.0-common/20170508.080135 submit/tizen_3.0-common/20170508.081301 submit/tizen_3.0-common/20170508.091535 submit/tizen_3.0/20170425.021233 submit/tizen_3.0_common/20170508.091735
authorHyunho Kang <hhstark.kang@samsung.com>
Mon, 24 Apr 2017 12:50:34 +0000 (21:50 +0900)
committerHyunho Kang <hhstark.kang@samsung.com>
Tue, 25 Apr 2017 01:31:16 +0000 (01:31 +0000)
Change-Id: Ic943aa3bc20ffaf7d2146bf5db7aa166fb99d22c
Signed-off-by: Hyunho Kang <hhstark.kang@samsung.com>
(cherry picked from commit e7a9a1855d7c2a05c547378b947d83ed77cae892)

src/widget_service.c

index d922a61..2652843 100644 (file)
@@ -25,6 +25,9 @@
 #include <glib.h>
 #include <sqlite3.h>
 
+#include <vconf.h>
+#include <vconf-keys.h>
+#include <unicode/uloc.h>
 #include <Ecore_Wayland.h>
 #include <aul.h>
 #include <tzplatform_config.h>
@@ -58,6 +61,9 @@ struct widget_instance_info_s {
 
 static GList *lifecycle_cbs;
 static bool _is_resolution_loaded = false;
+static const char *_iso3lang;
+static char _country[ULOC_COUNTRY_CAPACITY];
+static char *_syslang;
 
 static inline bool _is_widget_feature_enabled(void)
 {
@@ -1160,6 +1166,56 @@ static char *_get_preview_image_path(const char *widget_id, int width,
        return path;
 }
 
+static int update_lang_info(void)
+{
+       char *syslang;
+       UErrorCode err;
+       int country_len;
+
+       syslang = vconf_get_str(VCONFKEY_LANGSET);
+       if (!syslang) {
+               ErrPrint("Failed to get vconf-lang");
+               return -EFAULT;
+       }
+
+       if (_syslang && !strcmp(_syslang, syslang)) {
+               _D("Syslang is not changed: %s", syslang);
+               free(syslang);
+               return 0;
+       }
+
+       free(_syslang);
+       _syslang = syslang;
+
+       err = U_ZERO_ERROR;
+       uloc_setDefault((const char *)_syslang, &err);
+       if (!U_SUCCESS(err)) {
+               _E("Failed to set default lang: %s", u_errorName(err));
+               free(_syslang);
+               _syslang = NULL;
+               return -EFAULT;
+       }
+
+       _iso3lang = uloc_getISO3Language(uloc_getDefault());
+       if (!_iso3lang || !strlen(_iso3lang)) {
+               _E("Failed to get iso3lang");
+               free(_syslang);
+               _syslang = NULL;
+               return -EFAULT;
+       }
+
+       err = U_ZERO_ERROR;
+       country_len = uloc_getCountry(uloc_getDefault(), _country, ULOC_COUNTRY_CAPACITY, &err);
+       if (!U_SUCCESS(err) || country_len <= 0) {
+               _E("Failed to get locale: %s, %s, %d (%s)", u_errorName(err), _iso3lang, country_len, _country);
+               free(_syslang);
+               _syslang = NULL;
+               return -EFAULT;
+       }
+
+       return 0;
+}
+
 EAPI char *widget_service_get_preview_image_path(const char *widget_id,
                widget_size_type_e size_type)
 {
@@ -1168,6 +1224,10 @@ EAPI char *widget_service_get_preview_image_path(const char *widget_id,
        int height = -1;
        int w = -1;
        int h = -1;
+       char *lang_path;
+       int buf_len;
+       int i;
+       int printed;
 
        if (!_is_widget_feature_enabled()) {
                _E("not supported");
@@ -1201,6 +1261,42 @@ EAPI char *widget_service_get_preview_image_path(const char *widget_id,
        if (path == NULL && get_last_result() == WIDGET_ERROR_NOT_EXIST)
                path = _get_preview_image_path(widget_id, w, h, GLOBALAPP_USER);
 
+       if (path == NULL) {
+               _E("Can not find preview path");
+               set_last_result(WIDGET_ERROR_INVALID_PARAMETER);
+               return NULL;
+       }
+
+       if (update_lang_info() != 0)
+               return path;
+
+       buf_len = strlen(path) + strlen(_iso3lang) + strlen(_country) + 3; /* '/' '-' '/' */
+       lang_path = malloc(buf_len + 1);
+       if (!lang_path) {
+               set_last_result(WIDGET_ERROR_OUT_OF_MEMORY);
+               _E("Heap: %d", errno);
+               free(path);
+               return NULL;
+       }
+
+       for (i = strlen(path); i >= 0 && path[i] != '/'; i--);
+       i++; /* Skip '/' */
+
+       strncpy(lang_path, path, i);
+       printed = snprintf(lang_path + i, buf_len - i, "%s-%s/%s", _iso3lang, _country, path + i);
+       if (lang_path[i + printed] != '\0') {
+               _E("Path is truncated");
+               lang_path[i + printed] = '\0';
+       }
+
+       if (access(lang_path, R_OK) != 0) {
+               _D("Access failed: %s, %d", lang_path, errno);
+               free(lang_path);
+       } else {
+               free(path);
+               path = lang_path;
+       }
+
        return path;
 }