diff options
-rw-r--r-- | a11y/ChangeLog | 7 | ||||
-rw-r--r-- | a11y/widgets/ea-calendar-item.c | 18 | ||||
-rw-r--r-- | calendar/ChangeLog | 7 | ||||
-rw-r--r-- | calendar/gui/weekday-picker.c | 17 | ||||
-rw-r--r-- | e-util/ChangeLog | 8 | ||||
-rw-r--r-- | e-util/e-util.c | 94 | ||||
-rw-r--r-- | e-util/e-util.h | 4 | ||||
-rw-r--r-- | widgets/misc/ChangeLog | 8 | ||||
-rw-r--r-- | widgets/misc/e-calendar-item.c | 34 | ||||
-rw-r--r-- | widgets/misc/e-calendar-item.h | 3 |
10 files changed, 147 insertions, 53 deletions
diff --git a/a11y/ChangeLog b/a11y/ChangeLog index 67025af0f6..15c5ffe546 100644 --- a/a11y/ChangeLog +++ b/a11y/ChangeLog @@ -1,3 +1,10 @@ +2007-12-03 Matthew Barnes <mbarnes@redhat.com> + + ** Fixes part of bug #392747 + + * widgets/ea-calendar-item.c (ea_calendar_item_get_column_label): + Get the column label via e_get_weekday_name(). + 2007-10-29 Kjartan Maraas <kmaraas@gnome.org> * addressbook/ea-addressbook.c: diff --git a/a11y/widgets/ea-calendar-item.c b/a11y/widgets/ea-calendar-item.c index 585eba796d..00cba1b477 100644 --- a/a11y/widgets/ea-calendar-item.c +++ b/a11y/widgets/ea-calendar-item.c @@ -1119,8 +1119,7 @@ ea_calendar_item_get_column_label (EaCalendarItem *ea_calitem, gint column, AtkGObjectAccessible *atk_gobj; GObject *g_obj; ECalendarItem *calitem; - gchar *week_char; - gint char_size; + const gchar *abbr_name; g_return_val_if_fail (ea_calitem, FALSE); @@ -1129,17 +1128,12 @@ ea_calendar_item_get_column_label (EaCalendarItem *ea_calitem, gint column, if (!g_obj) return FALSE; + /* Columns are 0 = Monday ... 6 = Sunday */ calitem = E_CALENDAR_ITEM (g_obj); - week_char = g_utf8_offset_to_pointer (calitem->days, column); - char_size = strlen (calitem->days) - - strlen (g_utf8_find_next_char (calitem->days, NULL)); - - if (week_char && char_size < buffer_size) { - memcpy (buffer, week_char, char_size); - buffer[char_size] = '\0'; - return TRUE; - } - return FALSE; + abbr_name = e_get_weekday_name (column + 1, TRUE); + g_strlcpy (buffer, abbr_name, buffer_size); + + return TRUE; } /* the coordinate the e-calendar canvas coord */ diff --git a/calendar/ChangeLog b/calendar/ChangeLog index d6ba17a3ef..db0a0582e9 100644 --- a/calendar/ChangeLog +++ b/calendar/ChangeLog @@ -1,3 +1,10 @@ +2007-12-03 Matthew Barnes <mbarnes@redhat.com> + + ** Fixes part of bug #392747 + + * gui/weekday-picker.c (get_day_text): + Convert the day_index to GDateWeekday and call e_get_weekday_name(). + 2007-11-30 Milan Crha <mcrha@redhat.com> ** Fix for bug #325730 diff --git a/calendar/gui/weekday-picker.c b/calendar/gui/weekday-picker.c index 166c5d5b26..709255f374 100644 --- a/calendar/gui/weekday-picker.c +++ b/calendar/gui/weekday-picker.c @@ -28,6 +28,7 @@ #include <glib/gi18n.h> #include <libgnomecanvas/gnome-canvas-rect-ellipse.h> #include <libgnomecanvas/gnome-canvas-text.h> +#include <e-util/e-util.h> #include "weekday-picker.h" @@ -315,20 +316,12 @@ colorize_items (WeekdayPicker *wp) static char * get_day_text (int day_index) { - /* The first letter of each day of the week starting with Sunday */ - const char *str = _("SMTWTFS"); - char *day; - int char_size = 0; + GDateWeekday weekday; - day = g_utf8_offset_to_pointer (str, day_index); + /* Convert from tm_wday to GDateWeekday. */ + weekday = (day_index == 0) ? G_DATE_SUNDAY : day_index; - /* we use strlen because we actually want to count bytes */ - if (day_index == 6) - char_size = strlen (day); - else - char_size = strlen (day) - strlen (g_utf8_find_next_char (day, NULL)); - - return g_strndup (day, char_size); + return g_strdup (e_get_weekday_name (weekday, TRUE)); } static void diff --git a/e-util/ChangeLog b/e-util/ChangeLog index d44416e18e..0c5834debc 100644 --- a/e-util/ChangeLog +++ b/e-util/ChangeLog @@ -1,3 +1,11 @@ +2007-12-03 Matthew Barnes <mbarnes@redhat.com> + + ** Fixes part of bug #392747 + + * e-utils.c (e_get_month_name), (e_get_weekday_name): + New functions cache localized month and weekday names (respectively) + for easier retrieval than resorting to strftime(). + 2007-11-13 Ondrej Jirman <megous@megous.com> ** Fix for bug #494320 diff --git a/e-util/e-util.c b/e-util/e-util.c index 2515e78eb2..625c617a8b 100644 --- a/e-util/e-util.c +++ b/e-util/e-util.c @@ -547,6 +547,100 @@ e_utf8_strftime_fix_am_pm (gchar *str, gsize max, const gchar *fmt, } /** + * e_get_month_name: + * @month: month index + * @abbreviated: if %TRUE, abbreviate the month name + * + * Returns the localized name for @month. If @abbreviated is %TRUE, + * returns the locale's abbreviated month name. + * + * Returns: localized month name + **/ +const gchar * +e_get_month_name (GDateMonth month, + gboolean abbreviated) +{ + /* Make the indices correspond to the enum values. */ + static const gchar *abbr_names[G_DATE_DECEMBER + 1]; + static const gchar *full_names[G_DATE_DECEMBER + 1]; + static gboolean first_time = TRUE; + + g_return_val_if_fail (month >= G_DATE_JANUARY, NULL); + g_return_val_if_fail (month <= G_DATE_DECEMBER, NULL); + + if (G_UNLIKELY (first_time)) { + gchar buffer[256]; + GDateMonth ii; + GDate date; + + memset (abbr_names, 0, sizeof (abbr_names)); + memset (full_names, 0, sizeof (full_names)); + + /* First Julian day was in January. */ + g_date_set_julian (&date, 1); + + for (ii = G_DATE_JANUARY; ii <= G_DATE_DECEMBER; ii++) { + g_date_strftime (buffer, sizeof (buffer), "%b", &date); + abbr_names[ii] = g_intern_string (buffer); + g_date_strftime (buffer, sizeof (buffer), "%B", &date); + full_names[ii] = g_intern_string (buffer); + g_date_add_months (&date, 1); + } + + first_time = FALSE; + } + + return abbreviated ? abbr_names[month] : full_names[month]; +} + +/** + * e_get_weekday_name: + * @weekday: weekday index + * @abbreviated: if %TRUE, abbreviate the weekday name + * + * Returns the localized name for @weekday. If @abbreviated is %TRUE, + * returns the locale's abbreviated weekday name. + * + * Returns: localized weekday name + **/ +const gchar * +e_get_weekday_name (GDateWeekday weekday, + gboolean abbreviated) +{ + /* Make the indices correspond to the enum values. */ + static const gchar *abbr_names[G_DATE_SUNDAY + 1]; + static const gchar *full_names[G_DATE_SUNDAY + 1]; + static gboolean first_time = TRUE; + + g_return_val_if_fail (weekday >= G_DATE_MONDAY, NULL); + g_return_val_if_fail (weekday <= G_DATE_SUNDAY, NULL); + + if (G_UNLIKELY (first_time)) { + gchar buffer[256]; + GDateWeekday ii; + GDate date; + + memset (abbr_names, 0, sizeof (abbr_names)); + memset (full_names, 0, sizeof (full_names)); + + /* First Julian day was a Monday. */ + g_date_set_julian (&date, 1); + + for (ii = G_DATE_MONDAY; ii <= G_DATE_SUNDAY; ii++) { + g_date_strftime (buffer, sizeof (buffer), "%a", &date); + abbr_names[ii] = g_intern_string (buffer); + g_date_strftime (buffer, sizeof (buffer), "%A", &date); + full_names[ii] = g_intern_string (buffer); + g_date_add_days (&date, 1); + } + + first_time = FALSE; + } + + return abbreviated ? abbr_names[weekday] : full_names[weekday]; +} + +/** * e_flexible_strtod: * @nptr: the string to convert to a numeric value. * @endptr: if non-NULL, it returns the character after diff --git a/e-util/e-util.h b/e-util/e-util.h index c2983f454f..e3774c5852 100644 --- a/e-util/e-util.h +++ b/e-util/e-util.h @@ -82,6 +82,10 @@ gsize e_utf8_strftime_fix_am_pm (gchar *str, gsize max, const gchar *fmt, const struct tm *tm); +const gchar * e_get_month_name (GDateMonth month, + gboolean abbreviated); +const gchar * e_get_weekday_name (GDateWeekday weekday, + gboolean abbreviated); /* String to/from double conversion functions */ gdouble e_flexible_strtod (const gchar *nptr, diff --git a/widgets/misc/ChangeLog b/widgets/misc/ChangeLog index 93934b2bbc..a4b449c7d9 100644 --- a/widgets/misc/ChangeLog +++ b/widgets/misc/ChangeLog @@ -1,3 +1,11 @@ +2007-12-03 Matthew Barnes <mbarnes@redhat.com> + + ** Fixes part of bug #392747 + + * e-calendar-item.h (struct _ECalendarItem): + * e-calendar-item.c (e_calendar_item_init), (e_calendar_item_draw): + Lose the local weekday name cache and just call e_get_weekday_name(). + 2007-12-01 Matthew Barnes <mbarnes@redhat.com> ** Fixes part of bug #495123 diff --git a/widgets/misc/e-calendar-item.c b/widgets/misc/e-calendar-item.c index 7cbfc2f958..f023e89850 100644 --- a/widgets/misc/e-calendar-item.c +++ b/widgets/misc/e-calendar-item.c @@ -411,10 +411,6 @@ e_calendar_item_init (ECalendarItem *calitem) calitem->time_callback_data = NULL; calitem->time_callback_destroy = NULL; - /* Translators: These are the first characters of each day of the - week, 'M' for 'Monday', 'T' for Tuesday etc. */ - calitem->days = _("MTWTFSS"); - calitem->signal_emission_idle_id = 0; } @@ -964,18 +960,11 @@ e_calendar_item_draw (GnomeCanvasItem *canvas_item, static void layout_set_day_text (ECalendarItem *calitem, PangoLayout *layout, int day_index) { - char *day; - int char_size = 0; - - day = g_utf8_offset_to_pointer (calitem->days, day_index); - - /* we use strlen because we actually want to count bytes */ - if (day_index == 6) - char_size = strlen (day); - else - char_size = strlen (day) - strlen (g_utf8_find_next_char (day, NULL)); + const gchar *abbr_name; - pango_layout_set_text (layout, day, char_size); + /* day_index: 0 = Monday ... 6 = Sunday */ + abbr_name = e_get_weekday_name (day_index + 1, TRUE); + pango_layout_set_text (layout, abbr_name, -1); } static void @@ -1611,18 +1600,11 @@ e_calendar_item_draw (GnomeCanvasItem *canvas_item, static void layout_set_day_text (ECalendarItem *calitem, PangoLayout *layout, int day_index) { - char *day; - int char_size = 0; - - day = g_utf8_offset_to_pointer (calitem->days, day_index); - - /* we use strlen because we actually want to count bytes */ - if (day_index == 6) - char_size = strlen (day); - else - char_size = strlen (day) - strlen (g_utf8_find_next_char (day, NULL)); + const gchar *abbr_name; - pango_layout_set_text (layout, day, char_size); + /* day_index: 0 = Monday ... 6 = Sunday */ + abbr_name = e_get_weekday_name (day_index + 1, TRUE); + pango_layout_set_text (layout, abbr_name, -1); } static void diff --git a/widgets/misc/e-calendar-item.h b/widgets/misc/e-calendar-item.h index efd6d60a73..c78d9d14ec 100644 --- a/widgets/misc/e-calendar-item.h +++ b/widgets/misc/e-calendar-item.h @@ -216,9 +216,6 @@ struct _ECalendarItem gint selection_real_start_month_offset; gint selection_real_start_day; - /* The first character of each day of the week, e.g. 'MTWTFSS'. */ - gchar *days; - /* Widths of the day characters. */ gint day_widths[7]; |