[gnome-calendar/search-improvements] search-view: respect system time format
- From: Georges Basile Stavracas Neto <gbsneto src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-calendar/search-improvements] search-view: respect system time format
- Date: Wed, 7 Jan 2015 03:42:31 +0000 (UTC)
commit ff03e923c2db46d414e068c4eb96cb4b78033fb3
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date: Wed Jan 7 01:42:18 2015 -0200
search-view: respect system time format
src/gcal-search-view.c | 33 +++++++++++++++++++++++++++++++--
src/gcal-search-view.h | 3 +++
src/gcal-window.c | 1 +
3 files changed, 35 insertions(+), 2 deletions(-)
---
diff --git a/src/gcal-search-view.c b/src/gcal-search-view.c
index a5e432a..c3dce46 100644
--- a/src/gcal-search-view.c
+++ b/src/gcal-search-view.c
@@ -50,6 +50,7 @@ typedef struct
/* property */
icaltimetype *date;
GcalManager *manager; /* weak reference */
+ gboolean format_24h;
} GcalSearchViewPrivate;
enum
@@ -202,7 +203,11 @@ make_row_for_event_data (GcalSearchView *view,
/* show 'all day' instead of 00:00 */
if (comp_dt.value->is_date == 0)
{
- text = g_date_time_format (datetime, priv->time_mask);
+ if (priv->format_24h)
+ text = g_strdup_printf ("%.2d:%.2d", comp_dt.value->hour, comp_dt.value->minute);
+ else
+ text = g_strdup_printf (_("%.2d:%.2d %s"), comp_dt.value->hour % 12, comp_dt.value->minute,
+ comp_dt.value->hour < 12 ? _("AM") : _("PM"));
time_label = gtk_label_new (text);
g_free (text);
}
@@ -211,7 +216,7 @@ make_row_for_event_data (GcalSearchView *view,
time_label = gtk_label_new (_("All day"));
}
- gtk_label_set_width_chars (GTK_LABEL (date_label), 14);
+ gtk_label_set_width_chars (GTK_LABEL (time_label), 14);
gtk_style_context_add_class (gtk_widget_get_style_context (time_label), "dim-label");
/* name label */
@@ -673,3 +678,27 @@ gcal_search_view_new (GcalManager *manager)
{
return g_object_new (GCAL_TYPE_SEARCH_VIEW, "manager", manager, NULL);
}
+
+/**
+ * gcal_search_view_set_time_format:
+ * @view: a #GcalSearchView instance.
+ * @format_24h: whether is 24h or not.
+ *
+ * Setup time format, instead of accessing DConf
+ * again.
+ *
+ */
+void
+gcal_search_view_set_time_format (GcalSearchView *view,
+ gboolean format_24h)
+{
+ GcalSearchViewPrivate *priv;
+
+ priv = gcal_search_view_get_instance_private (view);
+ priv->format_24h = format_24h;
+
+ if (format_24h)
+ priv->time_mask = "%H:%M";
+ else
+ priv->time_mask = "%I:%M %p";
+}
diff --git a/src/gcal-search-view.h b/src/gcal-search-view.h
index ffffde3..798dc09 100644
--- a/src/gcal-search-view.h
+++ b/src/gcal-search-view.h
@@ -52,6 +52,9 @@ struct _GcalSearchViewClass
GType gcal_search_view_get_type (void);
+void gcal_search_view_set_time_format (GcalSearchView *view,
+ gboolean format_24h);
+
GtkWidget* gcal_search_view_new (GcalManager *manager);
G_END_DECLS
diff --git a/src/gcal-window.c b/src/gcal-window.c
index 1a2bd3d..8c2d998 100644
--- a/src/gcal-window.c
+++ b/src/gcal-window.c
@@ -1346,6 +1346,7 @@ gcal_window_constructed (GObject *object)
priv->views[GCAL_WINDOW_VIEW_SEARCH] =
gcal_search_view_new (priv->manager);
g_object_ref_sink (priv->views[GCAL_WINDOW_VIEW_SEARCH]);
+ gcal_search_view_set_time_format (GCAL_SEARCH_VIEW (priv->views[GCAL_WINDOW_VIEW_SEARCH]), use_24h_format);
g_object_bind_property (GCAL_WINDOW (object), "active-date",
priv->views[GCAL_WINDOW_VIEW_SEARCH],
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]