Ensure hildon-home will not start in safe mode
[conv-inbox] / src / el-home-applet.c
index 911f857..930b474 100644 (file)
 
 #include "config.h"
 #include "el-home-applet.h"
-
+#include <libintl.h>
 #include <hildon/hildon.h>
 #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>
 #include <libosso-abook/osso-abook-waitable.h>
 #include <libosso-abook/osso-abook-presence.h>
-#include <libosso-abook/osso-abook-avatar.h>
 #include <libosso-abook/osso-abook-touch-contact-starter.h>
 #include <libosso-abook/osso-abook-temporary-contact-dialog.h>
 #include <libosso-abook/osso-abook-account-manager.h>
@@ -104,9 +104,12 @@ struct _ELHomeAppletPrivate
         GtkWidget *icon;
         GtkWidget *unread;
         GtkWidget *received;
-        GtkWidget *empty;
         GtkWidget *cut_message;
-        GtkWidget *avatar;
+
+        /* empty view*/
+        GtkWidget *empty;
+        GtkWidget *sms_total;
+        GtkWidget *chat_total;
 
         gchar *message;
         gint event_id;
@@ -141,6 +144,10 @@ struct _ELHomeAppletPrivate
         gchar *local_id;
         gchar *group_uid;
         OssoABookContact *contact;
+
+        gboolean time_fmt_24h;
+
+        guint init_timer;
 };
 
 HD_DEFINE_PLUGIN_MODULE (ELHomeApplet, el_home_applet, HD_TYPE_HOME_PLUGIN_ITEM);
@@ -149,8 +156,8 @@ const gchar* g_module_check_init (GModule *module);
 const gchar*
 g_module_check_init (GModule *module)
 {
-       g_module_make_resident (module);
-       return NULL;
+        g_module_make_resident (module);
+        return NULL;
 }
 
 static void
@@ -612,7 +619,6 @@ update_presence_pixbuf (ELHomeApplet *self,
                 g_object_unref (priv->presence_pixbuf);
                 priv->presence_pixbuf = NULL;
         }
-        g_warning ("presence %s", icon_name);
 
         if (icon_name)
                 priv->presence_pixbuf = gtk_icon_theme_load_icon
@@ -639,6 +645,18 @@ presence_updated (OssoABookPresence *presence,
         update_presence_pixbuf (self, presence);
 }
 
+static void
+show_contact (ELHomeApplet *self)
+{
+        ELHomeAppletPrivate *priv = self->priv;
+
+        g_return_if_fail (priv->contact);
+
+        gtk_label_set_text (GTK_LABEL (priv->sender),
+                            osso_abook_contact_get_display_name (priv->contact));
+        resize_sender (priv);
+        gtk_widget_queue_draw (GTK_WIDGET (self));
+}
 
 static void
 resolve_contact (ELHomeApplet *self)
@@ -674,26 +692,19 @@ resolve_contact (ELHomeApplet *self)
 
         if (contacts && contacts->data) {
                 priv->contact = g_object_ref (OSSO_ABOOK_CONTACT (contacts->data));
-                gtk_label_set_text (GTK_LABEL (priv->sender),
-                                    osso_abook_contact_get_display_name (priv->contact));
-
+                g_signal_connect (priv->contact,
+                                  "notify::presence-status",
+                                  G_CALLBACK (presence_updated),
+                                  self);
                 priv->avatar_pixbuf = osso_abook_avatar_get_image_scaled
                         (OSSO_ABOOK_AVATAR (priv->contact),
                          HILDON_ICON_PIXEL_SIZE_THUMB,
                          HILDON_ICON_PIXEL_SIZE_THUMB,
                          TRUE);
-
                 update_presence_pixbuf (self,
                                         OSSO_ABOOK_PRESENCE (priv->contact));
-                g_signal_connect (priv->contact,
-                                  "notify::presence-status",
-                                  G_CALLBACK (presence_updated),
-                                  self);
-
-                resize_sender (priv);
-                gtk_widget_queue_draw (GTK_WIDGET (self));
+                show_contact (self);
         }
-
 }
 
 static void
@@ -709,12 +720,10 @@ contacts_added (OssoABookRoster  *roster,
 }
 
 static void
-reset_contact (ELHomeApplet *self)
+reset_contact (ELHomeApplet *self, gboolean resize)
 {
         ELHomeAppletPrivate *priv = self->priv;
 
-        gtk_widget_hide (priv->icon);
-
         if (priv->avatar_pixbuf) {
                 g_object_unref (priv->avatar_pixbuf);
                 priv->avatar_pixbuf = NULL;
@@ -733,7 +742,8 @@ reset_contact (ELHomeApplet *self)
                 priv->contact = NULL;
         }
 
-        resize_sender (priv);
+        if (resize)
+                resize_sender (priv);
 }
 
 static void
@@ -750,13 +760,13 @@ contacts_removed (OssoABookRoster *roster,
 
                 for (contact_id = ids; *contact_id; contact_id++) {
                         if (strcmp (*contact_id, priv->contact_id) == 0) {
-                                reset_contact (self);
+                                reset_contact (self, TRUE);
 
                                 gtk_widget_queue_draw (GTK_WIDGET (self));
                                 return;
                         }
                         if (strcmp (*contact_id, uid) == 0) {
-                                reset_contact (self);
+                                reset_contact (self, TRUE);
                                 resolve_contact (self);
                                 gtk_widget_queue_draw (GTK_WIDGET (self));
                                 return;
@@ -766,11 +776,34 @@ contacts_removed (OssoABookRoster *roster,
 }
 
 static void
-clean_state (ELHomeApplet *self)
+clean_contact (ELHomeApplet *self, gboolean resize)
 {
         ELHomeAppletPrivate *priv = self->priv;
 
-        reset_contact (self);
+        reset_contact (self, resize);
+
+        if (priv->aggregator) {
+                if (priv->aggregator_ready_closure){
+                        osso_abook_waitable_cancel (OSSO_ABOOK_WAITABLE (priv->aggregator),
+                                                    priv->aggregator_ready_closure);
+                        priv->aggregator_ready_closure = NULL;
+                }
+                g_signal_handlers_disconnect_by_func (priv->aggregator,
+                                                      contacts_added,
+                                                      self);
+                g_signal_handlers_disconnect_by_func (priv->aggregator,
+                                                      contacts_removed,
+                                                      self);
+                osso_abook_roster_stop (priv->aggregator);
+                g_object_unref (priv->aggregator);
+                priv->aggregator = NULL;
+        }
+}
+
+static void
+clean_state (ELHomeApplet *self)
+{
+        ELHomeAppletPrivate *priv = self->priv;
 
         if (priv->message) {
                 g_free (priv->message);
@@ -793,23 +826,6 @@ clean_state (ELHomeApplet *self)
                 g_free (priv->group_uid);
                 priv->group_uid = NULL;
         }
-
-        if (priv->aggregator) {
-                if (priv->aggregator_ready_closure){
-                        osso_abook_waitable_cancel (OSSO_ABOOK_WAITABLE (priv->aggregator),
-                                                    priv->aggregator_ready_closure);
-                        priv->aggregator_ready_closure = NULL;
-                }
-                g_signal_handlers_disconnect_by_func (priv->aggregator,
-                                                      contacts_added,
-                                                      self);
-                g_signal_handlers_disconnect_by_func (priv->aggregator,
-                                                      contacts_removed,
-                                                      self);
-                osso_abook_roster_stop (priv->aggregator);
-                g_object_unref (priv->aggregator);
-                priv->aggregator = NULL;
-        }
 }
 
 static void
@@ -817,6 +833,11 @@ dispose (GObject *self)
 {
         ELHomeAppletPrivate *priv = EL_HOME_APPLET(self)->priv;
 
+        if (priv->init_timer) {
+                g_source_remove (priv->init_timer);
+                priv->init_timer = 0;
+        }
+
         stop_scroll_anim (priv);
         if (priv->idle_id) {
                 g_source_remove (priv->idle_id);
@@ -832,6 +853,7 @@ dispose (GObject *self)
         }
 
         clean_state (EL_HOME_APPLET (self));
+        clean_contact (EL_HOME_APPLET (self), FALSE);
 
         G_OBJECT_CLASS (el_home_applet_parent_class)->dispose (self);
 }
@@ -875,7 +897,7 @@ start_aggregator (ELHomeApplet *self)
         ELHomeAppletPrivate *priv = self->priv;
         EBookQuery *query = NULL;
         GError *error = NULL;
-        g_warning ("%s rid %s lid %s", G_STRFUNC, priv->remote_id, priv->local_id);
+
         if (priv->local_id && priv->remote_id) {
                 const gchar *vcard = osso_abook_account_manager_get_vcard_field
                         (NULL, priv->local_id);
@@ -886,7 +908,7 @@ start_aggregator (ELHomeApplet *self)
                 else
                         query = e_book_query_any_field_contains (priv->remote_id);
         }
-        g_warning ("%s query %p", G_STRFUNC, query);
+
         if (query) {
                 priv->aggregator = osso_abook_aggregator_new_with_query (NULL,
                                                                          query,
@@ -902,7 +924,6 @@ start_aggregator (ELHomeApplet *self)
         }
 
         if (priv->aggregator) {
-                g_warning ("%s start aggr", G_STRFUNC);
                 priv->aggregator_ready_closure = osso_abook_waitable_call_when_ready
                         (OSSO_ABOOK_WAITABLE (priv->aggregator),
                          aggregator_ready_cb,
@@ -913,25 +934,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;
 }
@@ -962,7 +998,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]) {
@@ -986,8 +1022,6 @@ show_event (ELHomeApplet *self, RTComElIter *it)
                 priv->event_id = -1;
         }
 
-        gtk_widget_hide (priv->avatar);
-
         if (priv->message) {
                 gtk_widget_hide (priv->empty);
         }
@@ -1033,7 +1067,7 @@ make_query (RTComEl *el, gint event_id)
                 rtcom_el_query_prepare (query,
                                         "is-read", FALSE, RTCOM_EL_OP_EQUAL,
                                         "service", conv_services, RTCOM_EL_OP_IN_STRV,
-                                        /* "event-type", conv_event_types, RTCOM_EL_OP_IN_STRV, */
+                                        "event-type", conv_event_types, RTCOM_EL_OP_IN_STRV,
                                         NULL);
         }
         it = rtcom_el_get_events (el, query);
@@ -1093,43 +1127,75 @@ query_unread_events (RTComEl *el)
         return count;
 }
 
-static gint
-query_read_events (RTComEl *el, const gchar *service)
+static gboolean
+query_read_events (RTComEl *el, const gchar *service, gint *events, gint *conversations)
 {
         sqlite3 *db;
         sqlite3_stmt *stmt;
         int ret;
-        gint count = -1;
+        gboolean result = TRUE;
 
         g_object_get (el, "db", &db, NULL);
 
         if (sqlite3_prepare_v2 (db,
-                                "SELECT SUM(total_events) FROM GroupCache, Services "
+                                "SELECT SUM(total_events), COUNT(group_uid) FROM GroupCache, Services "
                                 "WHERE GroupCache.service_id=Services.id AND Services.name=?;",
                                 -1,
                                 &stmt,
                                 NULL) != SQLITE_OK) {
                 g_error ("%s: can't compile SQL", G_STRFUNC);
-                return -1;
+                return FALSE;
         }
         if (sqlite3_bind_text (stmt, 1, service, -1, SQLITE_STATIC) != SQLITE_OK)  {
                 g_error ("Failed to bind %s to SQL stmt", service);
+                result = FALSE;
                 goto DONE;
         }
 
         while (SQLITE_BUSY == (ret = sqlite3_step (stmt)));
 
         if (ret == SQLITE_ROW) {
-                count = sqlite3_column_int (stmt, 0);
+                *events = sqlite3_column_int (stmt, 0);
+                *conversations = sqlite3_column_int (stmt, 1);
         }
         else {
                 g_error ("%s: error while executing SQL", G_STRFUNC);
+                result = FALSE;
+                goto DONE;
         }
 
  DONE:
         sqlite3_finalize (stmt);
 
-        return count;
+        return result;
+}
+
+static void
+am_ready (OssoABookAccountManager *manager,
+          const GError            *error,
+          gpointer                 user_data)
+{
+        ELHomeApplet *self = EL_HOME_APPLET (user_data);
+        ELHomeAppletPrivate *priv = self->priv;
+
+        if (!error &&
+            priv->local_id &&
+            !GTK_WIDGET_VISIBLE (priv->icon)) {
+                McAccount *account;
+
+                account = osso_abook_account_manager_lookup_by_name (NULL,
+                                                                     priv->local_id);
+                if (account) {
+                        McProfile *profile = mc_profile_lookup (mc_account_compat_get_profile (account));
+                        const gchar *icon_name = mc_profile_get_icon_name (profile);
+                        if (icon_name) {
+                                gtk_image_set_from_icon_name (GTK_IMAGE (priv->icon),
+                                                              icon_name,
+                                                              HILDON_ICON_SIZE_XSMALL);
+                                gtk_widget_show (priv->icon);
+                        }
+                }
+        }
 }
 
 static void
@@ -1138,6 +1204,11 @@ read_event (ELHomeApplet *self)
         ELHomeAppletPrivate *priv = self->priv;
         RTComElIter *it = NULL;
         const gchar *icon_name = NULL;
+        gchar *remote_id;
+        gchar *local_id;
+
+        remote_id = g_strdup (priv->remote_id);
+        local_id = g_strdup (priv->local_id);
 
         clean_state (self);
 
@@ -1147,40 +1218,82 @@ read_event (ELHomeApplet *self)
         if (it) g_object_unref (it);
 
         if (priv->event_id >= 0) {
-                start_aggregator (self);
+                gboolean new_account = g_strcmp0 (priv->local_id, local_id);
 
-                if (g_strcmp0 (priv->local_id, "ring/tel/ring") == 0) {
-                        icon_name = "general_sms";
+                if (g_strcmp0 (priv->remote_id, remote_id) ||
+                    new_account ||
+                    !priv->contact) {
+                        clean_contact (self, TRUE);
+                        start_aggregator (self);
                 }
-                else{
-                        McAccount *account;
-                        account = osso_abook_account_manager_lookup_by_name (NULL,
-                                                                             priv->local_id);
-                        if (account) {
-                                McProfile *profile = mc_profile_lookup (mc_account_compat_get_profile (account));
-                                icon_name = mc_profile_get_icon_name (profile);
-                        }
+                else if (priv->contact) {
+                        show_contact (self);
                 }
 
-                if (icon_name) {
-                        gtk_image_set_from_icon_name (GTK_IMAGE (priv->icon),
-                                                      icon_name,
-                                                      HILDON_ICON_SIZE_XSMALL);
-                        gtk_widget_show (priv->icon);
+                if (new_account) {
+                        if (g_strcmp0 (priv->local_id, "ring/tel/ring") == 0) {
+                                icon_name = "general_sms";
+                        }
+                        else {
+                                McAccount *account;
+                                OssoABookAccountManager *am = osso_abook_account_manager_get_default ();
+                                if (!osso_abook_waitable_is_ready (OSSO_ABOOK_WAITABLE (am), NULL)) {
+                                        osso_abook_account_manager_call_when_ready  (am,
+                                                                                     am_ready,
+                                                                                     self,
+                                                                                     NULL);
+                                }
+                                else {
+                                        account = osso_abook_account_manager_lookup_by_name (NULL,
+                                                                                             priv->local_id);
+                                        if (account) {
+                                                McProfile *profile = mc_profile_lookup (mc_account_compat_get_profile (account));
+                                                icon_name = mc_profile_get_icon_name (profile);
+                                        }
+                                }
+                        }
+
+                        if (icon_name) {
+                                gtk_image_set_from_icon_name (GTK_IMAGE (priv->icon),
+                                                              icon_name,
+                                                              HILDON_ICON_SIZE_XSMALL);
+                                gtk_widget_show (priv->icon);
+                        }
+                        else
+                                gtk_widget_hide (priv->icon);
                 }
         }
         else {
-                gint n_sms_events = query_read_events (priv->eventlogger,
-                                                       "RTCOM_EL_SERVICE_SMS");
-                gint n_chat_events = query_read_events (priv->eventlogger,
-                                                        "RTCOM_EL_SERVICE_CHAT");
-                gchar *empty_text = g_strdup_printf ("SMSes %d, Chats %d",
-                                                     n_sms_events,
-                                                     n_chat_events);
-                gtk_label_set_text (GTK_LABEL (priv->empty),
-                                    empty_text);
-                g_free (empty_text);
+                gchar *text;
+                gint n_sms_events = 0, n_sms_convs = 0;
+                gint n_chat_events = 0, n_chat_convs = 0;
+                const gchar *fmt = "%d <span size=\"small\">(%d)</span>";
+
+                query_read_events (priv->eventlogger,
+                                   "RTCOM_EL_SERVICE_SMS",
+                                   &n_sms_events, &n_sms_convs);
+                query_read_events (priv->eventlogger,
+                                   "RTCOM_EL_SERVICE_CHAT",
+                                   &n_chat_events, &n_chat_convs);
+
+                text = g_strdup_printf (fmt, n_sms_convs, n_sms_events);
+                gtk_label_set_markup (GTK_LABEL (priv->sms_total), text);
+                g_free (text);
+
+                text = g_strdup_printf (fmt, n_chat_convs, n_chat_events);
+                gtk_label_set_markup (GTK_LABEL (priv->chat_total), text);
+                g_free (text);
+
+                gtk_label_set_text (GTK_LABEL (priv->sender),
+                                    dgettext ("rtcom-messaging-ui",
+                                              "messaging_ap_conversations"));
+
+                clean_contact (self, TRUE);
+                gtk_widget_hide (priv->icon);
         }
+
+        g_free (local_id);
+        g_free (remote_id);
 }
 
 static void
@@ -1358,10 +1471,13 @@ read_new_event (ELHomeApplet *self)
 {
         ELHomeAppletPrivate *priv = self->priv;
 
-        g_warning ("read_new_event");
-
         read_event (self);
-        priv->unread_count = query_unread_events (priv->eventlogger);
+
+        if (priv->event_id >= 0)
+                priv->unread_count = query_unread_events (priv->eventlogger);
+        else
+                priv->unread_count = 0;
+
         update_unread_label (self);
 
         priv->idle_id = 0;
@@ -1373,7 +1489,7 @@ static void
 add_new_idle (ELHomeApplet *self)
 {
         ELHomeAppletPrivate *priv = self->priv;
-        g_warning ("add_new_idle");
+
         if (priv->idle_id)
                 g_source_remove (priv->idle_id);
         priv->idle_id = g_idle_add ((GSourceFunc)read_new_event,
@@ -1390,21 +1506,40 @@ new_event_cb (RTComEl      *backend,
               const gchar  *service,
               ELHomeApplet *self)
 {
-        g_warning ("%s %s %s %s", local_uid, remote_uid, remote_ebook_uid, service);
-#if 0
-        const gchar** conv_service = conv_services;
-                g_warning ("%s", service);
-        do {
-                g_warning ("%s", *conv_service);
-                if (!g_strcmp0 (*conv_service, service)) {
-                        add_new_idle (self);
-                        return;
+        if (service && service[0] != '\0') {
+                const gchar** conv_service = conv_services;
+                do {
+                        if (!g_strcmp0 (*conv_service, service)) {
+                                add_new_idle (self);
+                                return;
+                        }
                 }
+                while(*++conv_service);
         }
-        while(*++conv_service);
-#else
+        else
+                add_new_idle (self);
+}
+
+static void
+all_deleted_cb (RTComEl      *backend,
+                const gchar  *service,
+                ELHomeApplet *self)
+{
+        new_event_cb (backend,
+                      0,
+                      NULL,
+                      NULL,
+                      NULL,
+                      NULL,
+                      service,
+                      self);
+}
+
+static void
+refresh_hint_cb (RTComEl     *backend,
+                 ELHomeApplet *self)
+{
         add_new_idle (self);
-#endif
 }
 
 static gboolean
@@ -1554,9 +1689,7 @@ button_release_event_cb (GtkWidget      *widget,
                                                               self);
                 }
                 else
-#ifndef DEBUG_LAYOUT
                         mark_as_read (self);
-#endif
                 break;
         default:;
         }
@@ -1589,19 +1722,82 @@ leave_notify_event_cb (GtkWidget        *widget,
         return FALSE;
 }
 
+static gboolean
+init_eventlogger (ELHomeApplet *self)
+{
+        ELHomeAppletPrivate *priv = self->priv;
+
+        priv->eventlogger = rtcom_el_new ();
+
+        /* check that db is initialized */
+        gpointer *db = NULL;
+        g_object_get (priv->eventlogger, "db", &db, NULL);
+        if (!db) {
+                static int trial = 0;
+
+                g_object_unref (priv->eventlogger);
+                priv->eventlogger = NULL;
+
+                if (trial == 0) {
+                        trial++;
+                        priv->init_timer = g_timeout_add_seconds (5,
+                                                                  (GSourceFunc)init_eventlogger,
+                                                                  self);
+                        return TRUE; /* return value doesn't matter */
+                }
+                else if (trial < 5) {
+                        trial++;
+                        return TRUE;
+                }
+                else {
+                        g_error ("Failed to init eventlogger");
+                        return FALSE;
+                }
+        }
+
+        g_signal_connect (priv->eventlogger,
+                          "new-event",
+                          G_CALLBACK (new_event_cb),
+                          self);
+        g_signal_connect (priv->eventlogger,
+                          "event-updated",
+                          G_CALLBACK (new_event_cb),
+                          self);
+        g_signal_connect (priv->eventlogger,
+                          "event-deleted",
+                          G_CALLBACK (new_event_cb),
+                          self);
+        g_signal_connect (priv->eventlogger,
+                          "all-deleted",
+                          G_CALLBACK (all_deleted_cb),
+                          self);
+        g_signal_connect (priv->eventlogger,
+                          "refresh-hint",
+                          G_CALLBACK (refresh_hint_cb),
+                          self);
+
+        add_new_idle (self);
+
+        priv->init_timer = 0;
+
+        return FALSE;
+}
+
 static void
 el_home_applet_init (ELHomeApplet *self)
 {
         ELHomeAppletPrivate *priv;
         GtkWidget *event_box;
         GtkWidget *hbox, *vbox, *align, *footer;
+        GtkWidget *w;
+        GConfClient *gconf;
 
         self->priv = EL_HOME_APPLET_GET_PRIVATE (self);
         priv = self->priv;
 
         gtk_widget_set_app_paintable (GTK_WIDGET (self), TRUE);
 
-        priv->unread = gtk_label_new ("12");
+        priv->unread = gtk_label_new (NULL);
         gtk_misc_set_alignment (GTK_MISC (priv->unread),
                                 0.0f,
                                 0.5f);
@@ -1612,12 +1808,7 @@ el_home_applet_init (ELHomeApplet *self)
                                 0.5f,
                                 0.5f);
 
-        priv->avatar = gtk_image_new ();
-        gtk_misc_set_alignment (GTK_MISC (priv->avatar),
-                                0.5f,
-                                0.5f);
-
-        priv->sender = gtk_label_new ("asdf asdf asdf asdf asdf");
+        priv->sender = gtk_label_new (NULL);
         gtk_misc_set_alignment (GTK_MISC (priv->sender),
                                 0.5f,
                                 0.55f);
@@ -1629,14 +1820,36 @@ el_home_applet_init (ELHomeApplet *self)
                                      C_WIDTH,
                                      HILDON_ICON_PIXEL_SIZE_THUMB);
 
-        priv->message = g_strdup ("One two three four five six seven eight nine ten");
-
-        /* TODO: l10n */
-        priv->empty = gtk_label_new ("No new messages");
-        gtk_widget_set_name (priv->empty, "hildon-shadow-label");
+        /* construt empty table */
+        priv->empty = gtk_fixed_new ();
+
+        w = gtk_image_new_from_icon_name ("general_sms", HILDON_ICON_SIZE_FINGER);
+        gtk_fixed_put (GTK_FIXED (priv->empty), w,
+                       4*HILDON_MARGIN_DOUBLE,
+                       2*HILDON_MARGIN_DOUBLE);
+
+        w = gtk_image_new_from_icon_name ("general_chat", HILDON_ICON_SIZE_FINGER);
+        gtk_fixed_put (GTK_FIXED (priv->empty), w,
+                       4*HILDON_MARGIN_DOUBLE,
+                       3*HILDON_MARGIN_DOUBLE + HILDON_ICON_PIXEL_SIZE_FINGER);
+
+        priv->sms_total = gtk_label_new (NULL);
+        gtk_widget_set_name (priv->sms_total, "hildon-shadow-label");
+        gtk_fixed_put (GTK_FIXED (priv->empty), priv->sms_total,
+                       5*HILDON_MARGIN_DOUBLE  + HILDON_ICON_PIXEL_SIZE_FINGER,
+                       2*HILDON_MARGIN_DOUBLE + HILDON_MARGIN_HALF);
+
+        priv->chat_total = gtk_label_new (NULL);
+        gtk_widget_set_name (priv->chat_total, "hildon-shadow-label");
+        gtk_fixed_put (GTK_FIXED (priv->empty), priv->chat_total,
+                       5*HILDON_MARGIN_DOUBLE  + HILDON_ICON_PIXEL_SIZE_FINGER,
+                       3*HILDON_MARGIN_DOUBLE + HILDON_MARGIN_HALF + HILDON_ICON_PIXEL_SIZE_FINGER);
+
+        gtk_widget_show_all (GTK_WIDGET (priv->empty));
+        gtk_widget_hide (GTK_WIDGET (priv->empty));
         GTK_WIDGET_SET_FLAGS (priv->empty, GTK_NO_SHOW_ALL);
 
-        priv->received = gtk_label_new ("aewf aewf aewf awef");
+        priv->received = gtk_label_new (NULL);
         gtk_misc_set_alignment (GTK_MISC (priv->received),
                                 1.0f,
                                 0.5f);
@@ -1704,21 +1917,16 @@ el_home_applet_init (ELHomeApplet *self)
 
         gtk_widget_show_all (GTK_WIDGET (event_box));
 
-#ifndef DEBUG_LAYOUT
-        priv->eventlogger = rtcom_el_new ();
-        g_signal_connect (priv->eventlogger,
-                          "new-event",
-                          G_CALLBACK (new_event_cb),
-                          self);
-        g_signal_connect (priv->eventlogger,
-                          "event-updated",
-                          G_CALLBACK (new_event_cb),
-                          self);
 
         osso_abook_init_with_name (PACKAGE, NULL);
 
-        add_new_idle (self);
-#endif
+        gconf = gconf_client_get_default ();
+        priv->time_fmt_24h = gconf_client_get_bool (gconf,
+                                                    "/apps/clock/time-format",
+                                                    NULL);
+        g_object_unref (gconf);
+
+        init_eventlogger (self);
 }
 
 static void
@@ -1734,4 +1942,3 @@ el_home_applet_class_init (ELHomeAppletClass *klass)
 
         g_type_class_add_private (klass, sizeof (ELHomeAppletPrivate));
 }
-