Use clock settings to show right time format.
authorArtem Garmash <artemgarmash@gmail.com>
Thu, 11 Feb 2010 16:32:18 +0000 (18:32 +0200)
committerArtem Garmash <artem.garmash@nokia.com>
Sun, 27 Jun 2010 19:13:46 +0000 (22:13 +0300)
Use hildon strings for date, time format.

src/el-home-applet.c

index d605662..2980851 100644 (file)
@@ -27,6 +27,7 @@
 #include <rtcom-eventlogger/eventlogger.h>
 #include <sqlite3.h>
 #include <string.h>
+#include <gconf/gconf-client.h>
 #include <libosso-abook/osso-abook-init.h>
 #include <libosso-abook/osso-abook-aggregator.h>
 #include <libosso-abook/osso-abook-contact.h>
@@ -143,6 +144,8 @@ struct _ELHomeAppletPrivate
         gchar *local_id;
         gchar *group_uid;
         OssoABookContact *contact;
+
+        gboolean time_fmt_24h;
 };
 
 HD_DEFINE_PLUGIN_MODULE (ELHomeApplet, el_home_applet, HD_TYPE_HOME_PLUGIN_ITEM);
@@ -921,25 +924,40 @@ start_aggregator (ELHomeApplet *self)
 }
 
 static gchar*
-format_time (time_t t)
+format_time (time_t t, gboolean time_fmt_24h)
 {
-        static const guint RESULT_SIZE = 32;
+        static const guint RESULT_SIZE = 64;
 
         time_t now;
         struct tm now_tm, t_tm;
-        const gchar *format = "%x %X";
+        const gchar *time_format;
         gchar *result = g_malloc0 (RESULT_SIZE);
 
         now = time (NULL);
         localtime_r (&now, &now_tm);
         localtime_r (&t, &t_tm);
 
+        if (time_fmt_24h)
+                time_format = "wdgt_va_24h_time";
+        else
+                time_format = now_tm.tm_hour > 11 ?
+                        "wdgt_va_12h_time_pm":
+                        "wdgt_va_12h_time_am";
+
         if ((now_tm.tm_year == t_tm.tm_year) &&
             (now_tm.tm_mon  == t_tm.tm_mon) &&
             (now_tm.tm_mday == t_tm.tm_mday))
-                format = "%X";
-
-        strftime (result, RESULT_SIZE, format, &t_tm);
+                strftime (result,
+                          RESULT_SIZE,
+                          dgettext ("hildon-libs", time_format),
+                          &t_tm);
+        else {
+                gchar *full_format = g_strdup_printf ("%s %s",
+                                                      dgettext ("hildon-libs", "wdgt_va_date"),
+                                                      dgettext ("hildon-libs", time_format));
+                strftime (result, RESULT_SIZE, full_format, &t_tm);
+                g_free (full_format);
+        }
 
         return result;
 }
@@ -970,7 +988,7 @@ show_event (ELHomeApplet *self, RTComElIter *it)
 
                         priv->event_id = g_value_get_int (g_value_array_get_nth (event, 0));
                         received_t = g_value_get_int (g_value_array_get_nth (event, 1));
-                        received = format_time (received_t);
+                        received = format_time (received_t, priv->time_fmt_24h);
                         priv->local_id = _VARR_DUP_STR (event, 2);
                         priv->remote_id = _VARR_DUP_STR (event, 3);
                         if (priv->remote_id && priv->remote_id[0]) {
@@ -1672,6 +1690,7 @@ el_home_applet_init (ELHomeApplet *self)
         GtkWidget *event_box;
         GtkWidget *hbox, *vbox, *align, *footer;
         GtkWidget *w;
+        GConfClient *gconf;
 
         self->priv = EL_HOME_APPLET_GET_PRIVATE (self);
         priv = self->priv;
@@ -1810,6 +1829,12 @@ el_home_applet_init (ELHomeApplet *self)
 
         osso_abook_init_with_name (PACKAGE, NULL);
 
+        gconf = gconf_client_get_default ();
+        priv->time_fmt_24h = gconf_client_get_bool (gconf,
+                                                    "/apps/clock/time-format",
+                                                    NULL);
+        g_object_unref (gconf);
+
         add_new_idle (self);
 }