cedric pushed a commit to branch master.

http://git.enlightenment.org/core/elementary.git/commit/?id=876889b8a75acbb7eaf520eff7ce420b8757d835

commit 876889b8a75acbb7eaf520eff7ce420b8757d835
Author: Shilpa Singh <shilpa.si...@samsung.com>
Date:   Mon Nov 9 12:21:09 2015 -0800

    calendar: weekdays do not get translated when language is dynamically 
changed issue fix
    
    Summary:
    When calendar widget is already created and if we change language,
    weekdays do not get translated because weekday string is statically
    stored only during create.
    Update the weekdays again when object is changed.
    
    @fix
    
    Test Plan:
    1.Create and show calendar widget
    2.Change the language
    Weekdays do not get translated
    
    Reviewers: Hermet, cedric
    
    Reviewed By: cedric
    
    Differential Revision: https://phab.enlightenment.org/D3149
    
    Signed-off-by: Cedric BAIL <ced...@osg.samsung.com>
---
 src/lib/elm_calendar.c        | 122 +++++++++++++++---------------------------
 src/lib/elm_widget_calendar.h |   1 +
 2 files changed, 43 insertions(+), 80 deletions(-)

diff --git a/src/lib/elm_calendar.c b/src/lib/elm_calendar.c
index 038307b..c90dfa0 100644
--- a/src/lib/elm_calendar.c
+++ b/src/lib/elm_calendar.c
@@ -27,50 +27,6 @@ static const Evas_Smart_Cb_Description _smart_callbacks[] = {
    {NULL, NULL}
 };
 
-/* This two functions should be moved in Eina for next release. */
-static Eina_Tmpstr *
-_eina_tmpstr_strftime(const char *format, const struct tm *tm)
-{
-   const size_t flen = strlen(format);
-   size_t buflen = 16; // An arbitrary starting size
-   char *buf = NULL;
-
-   do {
-      char *tmp;
-      size_t len;
-
-      tmp = realloc(buf, buflen * sizeof(char));
-      if (!tmp) goto on_error;
-      buf = tmp;
-
-      len = strftime(buf, buflen, format, tm);
-      // Check if we have the expected result and return it.
-      if ((len > 0 && len < buflen) || (len == 0 && flen == 0))
-        {
-           Eina_Tmpstr *r;
-
-           r = eina_tmpstr_add_length(buf, len + 1);
-           free(buf);
-           return r;
-        }
-
-      /* Possibly buf overflowed - try again with a bigger buffer */
-      buflen <<= 1; // multiply buffer size by 2
-   } while (buflen < 128 * flen);
-
- on_error:
-   free(buf);
-   return NULL;
-}
-
-static char *
-_eina_tmpstr_steal(Eina_Tmpstr *s)
-{
-   char *r = s ? strdup(s) : NULL;
-   eina_tmpstr_del(s);
-   return r;
-}
-
 static Eina_Bool _key_action_move(Evas_Object *obj, const char *params);
 
 static const Elm_Action key_actions[] = {
@@ -216,19 +172,19 @@ _disable(Elm_Calendar_Data *sd,
 static char *
 _format_month_year(struct tm *selected_time)
 {
-   return _eina_tmpstr_steal(_eina_tmpstr_strftime(E_("%B %Y"), 
selected_time));
+   return eina_strftime(E_("%B %Y"), selected_time);
 }
 
 static char *
 _format_month(struct tm *selected_time)
 {
-   return _eina_tmpstr_steal(_eina_tmpstr_strftime(E_("%B"), selected_time));
+   return eina_strftime(E_("%B"), selected_time);
 }
 
 static char *
 _format_year(struct tm *selected_time)
 {
-   return _eina_tmpstr_steal(_eina_tmpstr_strftime(E_("%Y"), selected_time));
+   return eina_strftime(E_("%Y"), selected_time);
 }
 
 static inline void
@@ -623,16 +579,49 @@ _set_headers(Evas_Object *obj)
    static char part[] = "ch_0.text";
    int i;
    ELM_CALENDAR_DATA_GET(obj, sd);
+   time_t weekday = 259200; /* Just the first sunday since epoch */
 
    elm_layout_freeze(obj);
 
    sd->filling = EINA_TRUE;
-   for (i = 0; i < ELM_DAY_LAST; i++)
+   if (sd->weekdays_set)
      {
-        part[3] = i + '0';
-        elm_layout_text_set
-          (obj, part, sd->weekdays[(i + sd->first_week_day) % ELM_DAY_LAST]);
+        for (i = 0; i < ELM_DAY_LAST; i++)
+          {
+             part[3] = i + '0';
+             elm_layout_text_set(obj, part, sd->weekdays[(i + 
sd->first_week_day) % ELM_DAY_LAST]);
+          }
      }
+   else
+     {
+        for (i = 0; i < ELM_DAY_LAST; i++)
+          {
+             struct tm *info;
+
+             /* I don't know of a better way of doing it */
+             info = gmtime(&weekday);
+             if (info)
+               {
+                  char *buf;
+                  buf = eina_strftime("%a", info);
+                  if (buf)
+                    {
+                       sd->weekdays[i] = eina_stringshare_add(buf);
+                       free(buf);
+                    }
+                  else
+                    {
+                       /* If we failed getting day, get a default value */
+                       sd->weekdays[i] = _days_abbrev[i];
+                       WRN("Failed getting weekday name for '%s' from locale.",
+                           _days_abbrev[i]);
+                    }
+               }
+             part[3] = i + '0';
+             elm_layout_text_set(obj, part, sd->weekdays[i]);
+             weekday += 86400; /* Advance by a day */
+          }
+    }
    sd->filling = EINA_FALSE;
 
    elm_layout_thaw(obj);
@@ -1032,9 +1021,8 @@ _style_changed(void *data,
 EOLIAN static void
 _elm_calendar_evas_object_smart_add(Eo *obj, Elm_Calendar_Data *priv)
 {
-   time_t weekday = 259200; /* Just the first sunday since epoch */
    time_t current_time;
-   int i, t;
+   int t;
 
    ELM_WIDGET_DATA_GET_OR_RETURN(obj, wd);
 
@@ -1075,33 +1063,6 @@ _elm_calendar_evas_object_smart_add(Eo *obj, 
Elm_Calendar_Data *priv)
       (wd->resize_obj, "load", "*",
        _style_changed, obj);
 
-   for (i = 0; i < ELM_DAY_LAST; i++)
-     {
-        struct tm *info;
-
-        /* I don't know of a better way of doing it */
-        info = gmtime(&weekday);
-        if (info)
-          {
-             Eina_Tmpstr *buf;
-
-             buf = _eina_tmpstr_strftime("%a", info);
-             if (buf)
-               {
-                  priv->weekdays[i] = eina_stringshare_add(buf);
-                  eina_tmpstr_del(buf);
-               }
-             else
-               {
-                  /* If we failed getting day, get a default value */
-                  priv->weekdays[i] = _days_abbrev[i];
-                  WRN("Failed getting weekday name for '%s' from locale.",
-                      _days_abbrev[i]);
-               }
-          }
-        weekday += 86400; /* Advance by a day */
-     }
-
    current_time = time(NULL);
    localtime_r(&current_time, &priv->shown_time);
    priv->current_time = priv->shown_time;
@@ -1285,6 +1246,7 @@ _elm_calendar_weekdays_names_set(Eo *obj, 
Elm_Calendar_Data *sd, const char **we
      {
         eina_stringshare_replace(&sd->weekdays[i], weekdays[i]);
      }
+   sd->weekdays_set = EINA_TRUE;
 
    evas_object_smart_changed(obj);
 }
diff --git a/src/lib/elm_widget_calendar.h b/src/lib/elm_widget_calendar.h
index b48f22f..e7d4d47 100644
--- a/src/lib/elm_widget_calendar.h
+++ b/src/lib/elm_widget_calendar.h
@@ -58,6 +58,7 @@ struct _Elm_Calendar_Data
    Eina_Bool                selected : 1;
    Eina_Bool                double_spinners : 1;
    Eina_Bool                filling : 1;
+   Eina_Bool                weekdays_set : 1;
 };
 
 struct _Elm_Calendar_Mark

-- 


Reply via email to