Modified webpage: now tinymail repository is in gitorious.
[modest] / src / modest-datetime-formatter.c
index 22acacf..b04ec34 100644 (file)
@@ -37,6 +37,8 @@
 #include "modest-text-utils.h"
 #ifdef MODEST_USE_LIBTIME
 #include <clockd/libtime.h>
+#include <libosso.h>
+#include <modest-platform.h>
 #endif
 
 typedef enum {
@@ -61,6 +63,14 @@ struct _ModestDatetimeFormatterPrivate {
 #endif
 };
 
+/* We need this very nasty stuff because the call to
+   osso_time_set_notification_cb cannot be reverted and thus the
+   handler will be called always even though we try to set another
+   one */
+#ifdef MODEST_USE_LIBTIME
+static ModestDatetimeFormatter *global_self = NULL;
+#endif
+
 #define MODEST_DATETIME_FORMATTER_GET_PRIVATE(o)     (G_TYPE_INSTANCE_GET_PRIVATE ((o), \
                                                                                   MODEST_TYPE_DATETIME_FORMATTER, \
                                                                                   ModestDatetimeFormatterPrivate))
@@ -159,6 +169,17 @@ clock_format_changed (GConfClient *gconf,
 }
 #endif
 
+#ifdef MODEST_USE_LIBTIME
+static void
+time_changed_cb (gpointer userdata)
+{
+       if (global_self) {
+               time_get_synced ();
+               g_signal_emit (global_self, signals[FORMAT_CHANGED_SIGNAL], 0);
+       }
+}
+#endif
+
 static void
 init_format (ModestDatetimeFormatter *obj)
 {
@@ -184,8 +205,18 @@ init_format (ModestDatetimeFormatter *obj)
                g_warning ("Error listening to time format in gconf %s", err->message);
                g_error_free (err);
        }
+
        update_format (obj);
 #endif
+
+#ifdef MODEST_USE_LIBTIME
+       if (OSSO_OK == osso_time_set_notification_cb (modest_platform_get_osso_context (),
+                                                     time_changed_cb,
+                                                     NULL))
+               global_self = obj;
+       time_get_synced ();
+#endif
+
 }
 
 static void
@@ -208,6 +239,13 @@ modest_datetime_formatter_finalize   (GObject *obj)
        priv->gconf_handler = 0;
        gconf_client_remove_dir (gconf, HILDON2_GCONF_FORMAT_DIR,
                                 NULL);
+
+       /* Disconnect notification */
+#ifdef MODEST_USE_LIBTIME
+       if (OSSO_OK != osso_time_set_notification_cb (modest_platform_get_osso_context (),
+                                                     NULL, NULL))
+               global_self = NULL;
+#endif
 #endif
        G_OBJECT_CLASS (parent_class)->finalize (obj);
 }
@@ -234,7 +272,7 @@ modest_datetime_formatter_format_date (ModestDatetimeFormatter *self,
        switch (priv->current_format) {
        case DATETIME_FORMAT_12H:
        case DATETIME_FORMAT_24H:
-               format_string = _HL("wdgt_va_date");
+               format_string = _HL_DATE;
                break;
        case DATETIME_FORMAT_LOCALE:
                format_string = "%x";
@@ -270,10 +308,10 @@ modest_datetime_formatter_format_time (ModestDatetimeFormatter *self,
 
        switch (priv->current_format) {
        case DATETIME_FORMAT_12H:
-               format_string = is_pm?_HL("wdgt_va_12h_time_pm"):_HL("wdgt_va_12h_time_am");
+               format_string = is_pm?_HL_12H_TIME_PM:_HL_12H_TIME_AM;
                break;
        case DATETIME_FORMAT_24H:
-               format_string = _HL("wdgt_va_24h_time");
+               format_string = _HL_24H_TIME;
                break;
        case DATETIME_FORMAT_LOCALE:
                format_string = "%X";