summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHyunho Kang <hhstark.kang@samsung.com>2017-04-24 21:50:34 +0900
committerHyunho Kang <hhstark.kang@samsung.com>2017-04-25 01:31:16 +0000
commit3443c9aaba4597ce061381be401676ae9d8d2167 (patch)
treec24897ba8b4d3403c081321c81c03db3809bf789
parent2e72673deeb2e568b4a7415db047073b1a016910 (diff)
downloadwidget-service-3443c9aaba4597ce061381be401676ae9d8d2167.tar.gz
widget-service-3443c9aaba4597ce061381be401676ae9d8d2167.tar.bz2
widget-service-3443c9aaba4597ce061381be401676ae9d8d2167.zip
Change-Id: Ic943aa3bc20ffaf7d2146bf5db7aa166fb99d22c Signed-off-by: Hyunho Kang <hhstark.kang@samsung.com> (cherry picked from commit e7a9a1855d7c2a05c547378b947d83ed77cae892)
-rw-r--r--src/widget_service.c96
1 files changed, 96 insertions, 0 deletions
diff --git a/src/widget_service.c b/src/widget_service.c
index d922a61..2652843 100644
--- a/src/widget_service.c
+++ b/src/widget_service.c
@@ -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;
}