summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Hacohen <tom@stosb.com>2015-10-02 09:28:56 +0100
committerTom Hacohen <tom@stosb.com>2015-10-02 09:28:56 +0100
commitbc235cc1f9cad90d4f3efe455b42810b84c1c16f (patch)
treefe4314bf7d1819df9ed4296d73545806ab97dde7
parent0bad0c98bc344eef90c4912c6a02b95a86e93d35 (diff)
Revert "elm_calendar: weekdays do not get translated when language is ..."
As agreed on the ML, eina_tmpstr_strftime() should be removed. This reverts commit 10b94fb1409487e256a01b3c45ff5a9cd9f678da.
-rw-r--r--src/lib/elm_calendar.c126
-rw-r--r--src/lib/elm_widget_calendar.h1
2 files changed, 82 insertions, 45 deletions
diff --git a/src/lib/elm_calendar.c b/src/lib/elm_calendar.c
index e1c02db45..038307b89 100644
--- a/src/lib/elm_calendar.c
+++ b/src/lib/elm_calendar.c
@@ -27,6 +27,50 @@ static const Evas_Smart_Cb_Description _smart_callbacks[] = {
27 {NULL, NULL} 27 {NULL, NULL}
28}; 28};
29 29
30/* This two functions should be moved in Eina for next release. */
31static Eina_Tmpstr *
32_eina_tmpstr_strftime(const char *format, const struct tm *tm)
33{
34 const size_t flen = strlen(format);
35 size_t buflen = 16; // An arbitrary starting size
36 char *buf = NULL;
37
38 do {
39 char *tmp;
40 size_t len;
41
42 tmp = realloc(buf, buflen * sizeof(char));
43 if (!tmp) goto on_error;
44 buf = tmp;
45
46 len = strftime(buf, buflen, format, tm);
47 // Check if we have the expected result and return it.
48 if ((len > 0 && len < buflen) || (len == 0 && flen == 0))
49 {
50 Eina_Tmpstr *r;
51
52 r = eina_tmpstr_add_length(buf, len + 1);
53 free(buf);
54 return r;
55 }
56
57 /* Possibly buf overflowed - try again with a bigger buffer */
58 buflen <<= 1; // multiply buffer size by 2
59 } while (buflen < 128 * flen);
60
61 on_error:
62 free(buf);
63 return NULL;
64}
65
66static char *
67_eina_tmpstr_steal(Eina_Tmpstr *s)
68{
69 char *r = s ? strdup(s) : NULL;
70 eina_tmpstr_del(s);
71 return r;
72}
73
30static Eina_Bool _key_action_move(Evas_Object *obj, const char *params); 74static Eina_Bool _key_action_move(Evas_Object *obj, const char *params);
31 75
32static const Elm_Action key_actions[] = { 76static const Elm_Action key_actions[] = {
@@ -172,19 +216,19 @@ _disable(Elm_Calendar_Data *sd,
172static char * 216static char *
173_format_month_year(struct tm *selected_time) 217_format_month_year(struct tm *selected_time)
174{ 218{
175 return eina_tmpstr_strftime(E_("%B %Y"), selected_time); 219 return _eina_tmpstr_steal(_eina_tmpstr_strftime(E_("%B %Y"), selected_time));
176} 220}
177 221
178static char * 222static char *
179_format_month(struct tm *selected_time) 223_format_month(struct tm *selected_time)
180{ 224{
181 return eina_tmpstr_strftime(E_("%B"), selected_time); 225 return _eina_tmpstr_steal(_eina_tmpstr_strftime(E_("%B"), selected_time));
182} 226}
183 227
184static char * 228static char *
185_format_year(struct tm *selected_time) 229_format_year(struct tm *selected_time)
186{ 230{
187 return eina_tmpstr_strftime(E_("%Y"), selected_time); 231 return _eina_tmpstr_steal(_eina_tmpstr_strftime(E_("%Y"), selected_time));
188} 232}
189 233
190static inline void 234static inline void
@@ -245,7 +289,7 @@ _set_month_year(Elm_Calendar_Data *sd)
245 if (buf) 289 if (buf)
246 { 290 {
247 elm_layout_text_set(sd->obj, "year_text", buf); 291 elm_layout_text_set(sd->obj, "year_text", buf);
248 eina_tmpstr_del(buf); 292 free(buf);
249 } 293 }
250 else elm_layout_text_set(sd->obj, "year_text", ""); 294 else elm_layout_text_set(sd->obj, "year_text", "");
251 295
@@ -257,7 +301,7 @@ _set_month_year(Elm_Calendar_Data *sd)
257 if (buf) 301 if (buf)
258 { 302 {
259 elm_layout_text_set(sd->obj, "month_text", buf); 303 elm_layout_text_set(sd->obj, "month_text", buf);
260 eina_tmpstr_del(buf); 304 free(buf);
261 } 305 }
262 else elm_layout_text_set(sd->obj, "month_text", ""); 306 else elm_layout_text_set(sd->obj, "month_text", "");
263 sd->filling = EINA_FALSE; 307 sd->filling = EINA_FALSE;
@@ -579,49 +623,16 @@ _set_headers(Evas_Object *obj)
579 static char part[] = "ch_0.text"; 623 static char part[] = "ch_0.text";
580 int i; 624 int i;
581 ELM_CALENDAR_DATA_GET(obj, sd); 625 ELM_CALENDAR_DATA_GET(obj, sd);
582 time_t weekday = 259200; /* Just the first sunday since epoch */
583 626
584 elm_layout_freeze(obj); 627 elm_layout_freeze(obj);
585 628
586 sd->filling = EINA_TRUE; 629 sd->filling = EINA_TRUE;
587 if (sd->weekdays_set) 630 for (i = 0; i < ELM_DAY_LAST; i++)
588 { 631 {
589 for (i = 0; i < ELM_DAY_LAST; i++) 632 part[3] = i + '0';
590 { 633 elm_layout_text_set
591 part[3] = i + '0'; 634 (obj, part, sd->weekdays[(i + sd->first_week_day) % ELM_DAY_LAST]);
592 elm_layout_text_set(obj, part, sd->weekdays[(i + sd->first_week_day) % ELM_DAY_LAST]);
593 }
594 } 635 }
595 else
596 {
597 for (i = 0; i < ELM_DAY_LAST; i++)
598 {
599 struct tm *info;
600
601 /* I don't know of a better way of doing it */
602 info = gmtime(&weekday);
603 if (info)
604 {
605 Eina_Tmpstr *buf;
606 buf = eina_tmpstr_strftime("%a", info);
607 if (buf)
608 {
609 sd->weekdays[i] = eina_stringshare_add(buf);
610 eina_tmpstr_del(buf);
611 }
612 else
613 {
614 /* If we failed getting day, get a default value */
615 sd->weekdays[i] = _days_abbrev[i];
616 WRN("Failed getting weekday name for '%s' from locale.",
617 _days_abbrev[i]);
618 }
619 }
620 part[3] = i + '0';
621 elm_layout_text_set(obj, part, sd->weekdays[i]);
622 weekday += 86400; /* Advance by a day */
623 }
624 }
625 sd->filling = EINA_FALSE; 636 sd->filling = EINA_FALSE;
626 637
627 elm_layout_thaw(obj); 638 elm_layout_thaw(obj);
@@ -1021,8 +1032,9 @@ _style_changed(void *data,
1021EOLIAN static void 1032EOLIAN static void
1022_elm_calendar_evas_object_smart_add(Eo *obj, Elm_Calendar_Data *priv) 1033_elm_calendar_evas_object_smart_add(Eo *obj, Elm_Calendar_Data *priv)
1023{ 1034{
1035 time_t weekday = 259200; /* Just the first sunday since epoch */
1024 time_t current_time; 1036 time_t current_time;
1025 int t; 1037 int i, t;
1026 1038
1027 ELM_WIDGET_DATA_GET_OR_RETURN(obj, wd); 1039 ELM_WIDGET_DATA_GET_OR_RETURN(obj, wd);
1028 1040
@@ -1063,6 +1075,33 @@ _elm_calendar_evas_object_smart_add(Eo *obj, Elm_Calendar_Data *priv)
1063 (wd->resize_obj, "load", "*", 1075 (wd->resize_obj, "load", "*",
1064 _style_changed, obj); 1076 _style_changed, obj);
1065 1077
1078 for (i = 0; i < ELM_DAY_LAST; i++)
1079 {
1080 struct tm *info;
1081
1082 /* I don't know of a better way of doing it */
1083 info = gmtime(&weekday);
1084 if (info)
1085 {
1086 Eina_Tmpstr *buf;
1087
1088 buf = _eina_tmpstr_strftime("%a", info);
1089 if (buf)
1090 {
1091 priv->weekdays[i] = eina_stringshare_add(buf);
1092 eina_tmpstr_del(buf);
1093 }
1094 else
1095 {
1096 /* If we failed getting day, get a default value */
1097 priv->weekdays[i] = _days_abbrev[i];
1098 WRN("Failed getting weekday name for '%s' from locale.",
1099 _days_abbrev[i]);
1100 }
1101 }
1102 weekday += 86400; /* Advance by a day */
1103 }
1104
1066 current_time = time(NULL); 1105 current_time = time(NULL);
1067 localtime_r(&current_time, &priv->shown_time); 1106 localtime_r(&current_time, &priv->shown_time);
1068 priv->current_time = priv->shown_time; 1107 priv->current_time = priv->shown_time;
@@ -1246,7 +1285,6 @@ _elm_calendar_weekdays_names_set(Eo *obj, Elm_Calendar_Data *sd, const char **we
1246 { 1285 {
1247 eina_stringshare_replace(&sd->weekdays[i], weekdays[i]); 1286 eina_stringshare_replace(&sd->weekdays[i], weekdays[i]);
1248 } 1287 }
1249 sd->weekdays_set = EINA_TRUE;
1250 1288
1251 evas_object_smart_changed(obj); 1289 evas_object_smart_changed(obj);
1252} 1290}
diff --git a/src/lib/elm_widget_calendar.h b/src/lib/elm_widget_calendar.h
index e7d4d47e3..b48f22f29 100644
--- a/src/lib/elm_widget_calendar.h
+++ b/src/lib/elm_widget_calendar.h
@@ -58,7 +58,6 @@ struct _Elm_Calendar_Data
58 Eina_Bool selected : 1; 58 Eina_Bool selected : 1;
59 Eina_Bool double_spinners : 1; 59 Eina_Bool double_spinners : 1;
60 Eina_Bool filling : 1; 60 Eina_Bool filling : 1;
61 Eina_Bool weekdays_set : 1;
62}; 61};
63 62
64struct _Elm_Calendar_Mark 63struct _Elm_Calendar_Mark