Open conversation on message click
[conv-inbox] / src / el-home-applet.c
index 3d58568..4f7858e 100644 (file)
@@ -36,6 +36,8 @@
 #include <libosso-abook/osso-abook-temporary-contact-dialog.h>
 #include <libosso-abook/osso-abook-account-manager.h>
 
+#include <telepathy-glib/interfaces.h>
+
 #define EL_HOME_APPLET_GET_PRIVATE(obj) ( \
         G_TYPE_INSTANCE_GET_PRIVATE (obj, \
                 EL_TYPE_HOME_APPLET, ELHomeAppletPrivate))
 #define SCROLL_STEP 1 /* pixel */
 #define TEXT_Y_OFFSET (HEADER_HEIGHT + HILDON_MARGIN_HALF)
 
+#define NOTIFICATION_UI_DBUS_NAME     "org.freedesktop.Telepathy.Client.NotificationUI"
+#define NOTIFICATION_UI_DBUS_PATH     "/org/freedesktop/Telepathy/Client/NotificationUI"
+#define NOTIFICATION_UI_DBUS_IFACE    "com.nokia.RtcomNotificationUi"
+
 struct _ELHomeAppletPrivate
 {
         RTComEl *eventlogger;
@@ -644,30 +650,39 @@ show_event (ELHomeApplet *self, RTComElIter *it)
         g_warning (G_STRFUNC);
         gchar *remote = NULL;
         gchar *received = NULL;
-        const gchar *icon_name = NULL;
+        /* const gchar *icon_name = NULL; */
 
         if (it && rtcom_el_iter_first (it)) {
                 rtcom_el_iter_dup_string (it, "free-text", &priv->message);
                 if (priv->message) {
-                        const gchar *service;
+                        /* const gchar *service; */
                         time_t received_t;
 
                         rtcom_el_iter_get_int (it, "id", &priv->event_id);
                         if (rtcom_el_iter_get_int (it, "start-time", (gint*)&received_t))
                                 received = format_time (received_t);
 
-                        rtcom_el_iter_dup_string (it, "remote-uid", &priv->remote_id);
-                        if (!rtcom_el_iter_dup_string (it, "remote-name", &remote))
-                                remote = g_strdup (priv->remote_id);
-
-                        rtcom_el_iter_dup_string (it, "remote-ebook-uid", &priv->contact_id);
-                        rtcom_el_iter_dup_string (it, "local-uid", &priv->local_id);
-                        g_warning ("abook uid %s", priv->contact_id);
+                        if (rtcom_el_iter_dup_string (it, "remote-uid", &priv->remote_id)) {
+                                if (priv->remote_id && priv->remote_id[0])  {
+                                        if (!rtcom_el_iter_dup_string (it, "remote-name", &remote))
+                                                remote = g_strdup (priv->remote_id);
+
+                                        rtcom_el_iter_dup_string (it, "remote-ebook-uid", &priv->contact_id);
+                                        rtcom_el_iter_dup_string (it, "local-uid", &priv->local_id);
+                                        g_warning ("abook uid %s", priv->contact_id);
+                                }
+                                else if (priv->remote_id) {
+                                        g_free (priv->remote_id);
+                                        priv->remote_id = NULL;
+                                }
+                        }
+#if 0
                         service = rtcom_el_iter_get_service (it);
                         if (!g_strcmp0 (service, "RTCOM_EL_SERVICE_SMS"))
                                 icon_name = "chat_unread_sms";
                         else if (!g_strcmp0 (service, "RTCOM_EL_SERVICE_CHAT"))
                                 icon_name = "chat_unread_chat";
+#endif
                 }
         }
         else {
@@ -824,6 +839,72 @@ read_event (ELHomeApplet *self)
 }
 
 static void
+remove_notification (ELHomeApplet *self)
+{
+        ELHomeAppletPrivate *priv = self->priv;
+
+        DBusGConnection* conn;
+        GError *error;
+        DBusGProxy *proxy;
+        GPtrArray *conv_structs;
+        GType conv_structs_type;
+        GValueArray *account_info;
+        GValue value = {0, };
+        DBusGProxyCall *call;
+
+        if (!(priv->remote_id && priv->local_id))
+                return;
+
+        conn = hd_home_plugin_item_get_dbus_g_connection (HD_HOME_PLUGIN_ITEM (self),
+                                                          DBUS_BUS_SESSION,
+                                                          &error);
+        if (!conn) {
+                g_error ("Failed get dbus g connection %s", error->message);
+                g_error_free (error);
+                return;
+        }
+
+        proxy = dbus_g_proxy_new_for_name (conn,
+                                           NOTIFICATION_UI_DBUS_NAME,
+                                           NOTIFICATION_UI_DBUS_PATH,
+                                           NOTIFICATION_UI_DBUS_IFACE);
+
+        conv_structs = g_ptr_array_sized_new (1);
+        account_info = g_value_array_new (2);
+
+        g_value_init (&value, G_TYPE_STRING);
+        g_value_set_string (&value, priv->local_id);
+        g_value_array_append (account_info, &value);
+        g_value_unset (&value);
+
+        g_value_init (&value, G_TYPE_STRING);
+        g_value_set_string (&value, priv->remote_id);
+        g_value_array_append (account_info, &value);
+        g_value_unset (&value);
+
+        g_ptr_array_add (conv_structs, account_info);
+
+        conv_structs_type = dbus_g_type_get_collection
+                ("GPtrArray",
+                 dbus_g_type_get_struct ("GValueArray",
+                                         G_TYPE_STRING,
+                                         G_TYPE_STRING,
+                                         G_TYPE_INVALID));
+
+        call = dbus_g_proxy_begin_call (proxy,
+                                        "ClearConversationNotifications",
+                                        NULL, NULL, NULL,
+                                        conv_structs_type,
+                                        conv_structs,
+                                        G_TYPE_INVALID);
+
+        g_value_array_free (account_info);
+        g_ptr_array_free (conv_structs, TRUE);
+
+        g_object_unref (proxy);
+}
+
+static void
 mark_as_read (ELHomeApplet *self)
 {
         ELHomeAppletPrivate *priv = self->priv;
@@ -833,9 +914,39 @@ mark_as_read (ELHomeApplet *self)
                                          priv->event_id,
                                          TRUE,
                                          NULL);
+                remove_notification (self);
         }
 }
 
+static void
+open_conversation (ELHomeApplet *self)
+{
+        ELHomeAppletPrivate *priv = self->priv;
+        McAccount *account;
+        McAccountChannelrequestData request;
+
+        if (!(priv->remote_id && priv->local_id))
+                return;
+
+        account = osso_abook_account_manager_lookup_by_name (NULL,
+                                                             priv->local_id);
+        if (!account)
+                return;
+
+        MC_ACCOUNT_CRD_INIT (&request);
+        MC_ACCOUNT_CRD_SET (&request, channel_type, TP_IFACE_QUARK_CHANNEL_TYPE_TEXT);
+        MC_ACCOUNT_CRD_SET (&request, target_handle_type, TP_HANDLE_TYPE_CONTACT);
+        MC_ACCOUNT_CRD_SET (&request, target_id, priv->remote_id);
+
+        mc_account_channelrequest (
+                account,
+                &request,
+                time (NULL),
+                NULL, /* handler */
+                MC_ACCOUNT_CR_FLAG_USE_EXISTING,
+                NULL, NULL, NULL, NULL);
+}
+
 static gboolean
 read_new_event (ELHomeApplet *self)
 {
@@ -990,7 +1101,8 @@ button_release_event_cb (GtkWidget      *widget,
                 }
                 else {
 #ifndef DEBUG_LAYOUT
-                        mark_as_read (self);
+                        /* mark_as_read (self); */
+                        open_conversation (self);
 #endif
                 }