[gnome-calendar] week-view: take into account GNOME time format
- From: Erick Pérez Castellanos <erickpc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-calendar] week-view: take into account GNOME time format
- Date: Thu, 4 Dec 2014 22:43:09 +0000 (UTC)
commit 184854e318f728ce3c07a8a4d43bf849315dfb9d
Author: Erick Pérez Castellanos <erick red gmail com>
Date: Tue Nov 18 12:31:50 2014 -0500
week-view: take into account GNOME time format
Bug: https://bugzilla.gnome.org/show_bug.cgi?id=703321
src/gcal-week-view.c | 54 +++++++++++++++++++++++++++++++++++++++++--------
src/gcal-week-view.h | 3 ++
src/gcal-window.c | 12 +++++++++++
3 files changed, 60 insertions(+), 9 deletions(-)
---
diff --git a/src/gcal-week-view.c b/src/gcal-week-view.c
index 30e1311..bdff20a 100644
--- a/src/gcal-week-view.c
+++ b/src/gcal-week-view.c
@@ -74,6 +74,11 @@ typedef struct
* 0 for Sunday, 1 for Monday and so on */
gint first_weekday;
+ /**
+ * clock format from GNOME desktop settings
+ */
+ gboolean use_24h_format;
+
/* property */
icaltimetype *date;
GcalManager *manager; /* weak referenced */
@@ -408,16 +413,24 @@ draw_grid_window (GcalWeekView *view,
for (i = 0; i < 24; i++)
{
gchar *hours;
- hours = g_strdup_printf ("%d %s",
- i % 12,
- i < 12 ? _("AM") : _("PM"));
-
- if (i == 0)
- pango_layout_set_text (layout, _("Midnight"), -1);
- else if (i == 12)
- pango_layout_set_text (layout, _("Noon"), -1);
+ if (priv->use_24h_format)
+ {
+ hours = g_strdup_printf ("%02d:00", i);
+ pango_layout_set_text (layout, hours, -1);
+ }
else
- pango_layout_set_text (layout, hours, -1);
+ {
+ hours = g_strdup_printf ("%02d:00 %s",
+ i % 12,
+ i < 12 ? _("AM") : _("PM"));
+
+ if (i == 0)
+ pango_layout_set_text (layout, _("Midnight"), -1);
+ else if (i == 12)
+ pango_layout_set_text (layout, _("Noon"), -1);
+ else
+ pango_layout_set_text (layout, hours, -1);
+ }
cairo_move_to (cr, padding.left, padding.top + (height / 24) * i);
pango_cairo_show_layout (cr, layout);
@@ -468,6 +481,7 @@ get_sidebar_width (GtkWidget *widget)
PangoFontDescription *font_desc;
gint mid_width;
gint noon_width;
+ gint hours_width;
gint sidebar_width;
context = gtk_widget_get_style_context (widget);
@@ -489,7 +503,12 @@ get_sidebar_width (GtkWidget *widget)
pango_layout_set_text (layout, _("Noon"), -1);
pango_layout_get_pixel_size (layout, &noon_width, NULL);
+
+ pango_layout_set_text (layout, _("00:00 PM"), -1);
+ pango_layout_get_pixel_size (layout, &hours_width, NULL);
+
sidebar_width = noon_width > mid_width ? noon_width : mid_width;
+ sidebar_width = sidebar_width > hours_width ? 0 : hours_width;
sidebar_width += padding.left + padding.right;
pango_font_description_free (font_desc);
@@ -1450,3 +1469,20 @@ gcal_week_view_set_first_weekday (GcalWeekView *view,
priv = gcal_week_view_get_instance_private (view);
priv->first_weekday = day_nr;
}
+
+/**
+ * gcal_week_view_set_use_24h_format:
+ * @view:
+ * @use_24h:
+ *
+ * Whether the view will show time using 24h or 12h format
+ **/
+void
+gcal_week_view_set_use_24h_format (GcalWeekView *view,
+ gboolean use_24h)
+{
+ GcalWeekViewPrivate *priv;
+
+ priv = gcal_week_view_get_instance_private (view);
+ priv->use_24h_format = use_24h;
+}
diff --git a/src/gcal-week-view.h b/src/gcal-week-view.h
index af9cdef..010824a 100644
--- a/src/gcal-week-view.h
+++ b/src/gcal-week-view.h
@@ -53,6 +53,9 @@ GtkWidget* gcal_week_view_new (GcalManager *manager);
void gcal_week_view_set_first_weekday (GcalWeekView *view,
gint day_nr);
+void gcal_week_view_set_use_24h_format (GcalWeekView *view,
+ gboolean use_24h);
+
G_END_DECLS
#endif /* __GCAL_WEEK_VIEW_H__ */
diff --git a/src/gcal-window.c b/src/gcal-window.c
index b4e4678..925fb66 100644
--- a/src/gcal-window.c
+++ b/src/gcal-window.c
@@ -1026,6 +1026,9 @@ gcal_window_constructed (GObject *object)
GtkBuilder *builder;
GMenuModel *winmenu;
+ GSettings *helper_settings;
+ gchar *clock_format;
+ gboolean use_24h_format;
gint i;
if (G_OBJECT_CLASS (gcal_window_parent_class)->constructed != NULL)
@@ -1033,6 +1036,12 @@ gcal_window_constructed (GObject *object)
priv = gcal_window_get_instance_private (GCAL_WINDOW (object));
+ helper_settings = g_settings_new ("org.gnome.desktop.interface");
+ clock_format = g_settings_get_string (helper_settings, "clock-format");
+ use_24h_format = (g_strcmp0 (clock_format, "24h") == 0);
+ g_free (clock_format);
+ g_object_unref (helper_settings);
+
/* ui construction */
priv->main_box = gtk_grid_new ();
gtk_orientable_set_orientation (GTK_ORIENTABLE (priv->main_box),
@@ -1142,6 +1151,9 @@ gcal_window_constructed (GObject *object)
gcal_week_view_set_first_weekday (
GCAL_WEEK_VIEW (priv->views[GCAL_WINDOW_VIEW_WEEK]),
get_first_weekday ());
+ gcal_week_view_set_use_24h_format (
+ GCAL_WEEK_VIEW (priv->views[GCAL_WINDOW_VIEW_WEEK]),
+ use_24h_format);
gtk_stack_add_titled (GTK_STACK (priv->views_stack),
priv->views[GCAL_WINDOW_VIEW_WEEK],
"week", _("Week"));
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]