Show temporary contact dialog for unknown contacts
authorArtem Garmash <artemgarmash@gmail.com>
Mon, 21 Dec 2009 22:43:35 +0000 (00:43 +0200)
committerArtem Garmash <artem.garmash@nokia.com>
Sun, 27 Jun 2010 19:13:41 +0000 (22:13 +0300)
src/el-home-applet.c

index e9a69de..7994155 100644 (file)
@@ -33,6 +33,8 @@
 #include <libosso-abook/osso-abook-waitable.h>
 #include <libosso-abook/osso-abook-contact.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>
 
 #define EL_HOME_APPLET_GET_PRIVATE(obj) ( \
         G_TYPE_INSTANCE_GET_PRIVATE (obj, \
@@ -95,6 +97,8 @@ struct _ELHomeAppletPrivate
         OssoABookRoster *aggregator;
         OssoABookWaitableClosure *aggregator_ready_closure;
         gchar *contact_id;
+        gchar *remote_id;
+        gchar *local_id;
 };
 
 HD_DEFINE_PLUGIN_MODULE (ELHomeApplet, el_home_applet, HD_TYPE_HOME_PLUGIN_ITEM);
@@ -437,6 +441,19 @@ dispose (GObject *self)
                 g_free (priv->message);
                 priv->message = NULL;
         }
+        if (priv->contact_id) {
+                g_free (priv->contact_id);
+                priv->contact_id = NULL;
+        }
+        if (priv->remote_id) {
+                g_free (priv->remote_id);
+                priv->remote_id = NULL;
+        }
+        if (priv->local_id) {
+                g_free (priv->local_id);
+                priv->local_id = NULL;
+        }
+
         if (priv->font_desc) {
                 pango_font_description_free (priv->font_desc);
                 priv->font_desc = NULL;
@@ -493,6 +510,9 @@ resolve_contact (ELHomeApplet *self)
                         }
                 }
         }
+        else {
+                /* TODO: use priv->remote_id and priv->local_id to lookup contact*/
+        }
 }
 
 static gchar*
@@ -537,6 +557,14 @@ show_event (ELHomeApplet *self, RTComElIter *it)
                 g_free (priv->contact_id);
                 priv->contact_id = NULL;
         }
+        if (priv->local_id) {
+                g_free (priv->local_id);
+                priv->local_id = NULL;
+        }
+        if (priv->remote_id) {
+                g_free (priv->remote_id);
+                priv->remote_id = NULL;
+        }
 
         if (it && rtcom_el_iter_first (it)) {
                 rtcom_el_iter_dup_string (it, "free-text", &priv->message);
@@ -548,9 +576,12 @@ show_event (ELHomeApplet *self, RTComElIter *it)
                         if (rtcom_el_iter_get_int (it, "start-time", (gint*)&received_t))
                                 received = format_time (received_t);
 
+                        rtcom_el_iter_dup_string (it, "remote-id", &priv->remote_id);
                         if (!rtcom_el_iter_dup_string (it, "remote-name", &remote))
-                                rtcom_el_iter_dup_string (it, "remote-id", &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);
                         service = rtcom_el_iter_get_service (it);
                         if (!g_strcmp0 (service, "RTCOM_EL_SERVICE_SMS"))
@@ -805,25 +836,57 @@ button_press_event_cb (GtkWidget      *widget,
         return TRUE;
 }
 
-static gboolean
-start_starter (OssoABookAggregator *aggregator, const gchar *contact_id)
+static GtkWidget*
+create_contact_starter_dialog (OssoABookAggregator *aggregator, const gchar *contact_id)
 {
+        GtkWidget *dialog = NULL;
         GList *contacts = osso_abook_aggregator_lookup (aggregator, contact_id);
         if (contacts && contacts->data) {
                 GtkWidget *starter =
                         osso_abook_touch_contact_starter_new_with_contact
                         (NULL,
                          OSSO_ABOOK_CONTACT (contacts->data));
-                GtkWidget *dlg = osso_abook_touch_contact_starter_dialog_new
+                dialog = osso_abook_touch_contact_starter_dialog_new
                         (NULL,
                          OSSO_ABOOK_TOUCH_CONTACT_STARTER (starter));
                 gtk_widget_show_all (starter);
-                gtk_widget_show (dlg);
+        }
+
+        g_list_free (contacts);
 
-                return TRUE;
+        return dialog;
+}
+
+static GtkWidget*
+create_temporary_contact_dialog (const gchar *remote_id,
+                                 const gchar *account_id)
+{
+        GtkWidget *dialog = NULL;
+        const gchar *vcard = NULL;
+
+        if (account_id) {
+            vcard = osso_abook_account_manager_get_vcard_field (NULL, account_id);
         }
-        return FALSE;
+
+        if (vcard) {
+                EVCardAttribute *attribute = e_vcard_attribute_new (NULL, vcard);
+
+                e_vcard_attribute_add_value (attribute, remote_id);
+                dialog = osso_abook_temporary_contact_dialog_new
+                        (NULL,
+                         NULL, /*EBook            *book,*/
+                         attribute,
+                         NULL /*McAccount        *account*/);
+                g_signal_connect (dialog,
+                                  "response",
+                                  G_CALLBACK (gtk_widget_destroy),
+                                  NULL);
+                e_vcard_attribute_free (attribute);
+        }
+
+        return dialog;
 }
+
 static gboolean
 button_release_event_cb (GtkWidget      *widget,
                          GdkEventButton *event,
@@ -849,11 +912,19 @@ button_release_event_cb (GtkWidget      *widget,
                 gtk_widget_queue_draw (widget);
         }
         if (priv->active_header) {
+                GtkWidget *dialog = NULL;
                 priv->active_header = FALSE;
-                if (!start_starter (OSSO_ABOOK_AGGREGATOR (priv->aggregator),
-                                    priv->contact_id)) {
-                        /* TODO: start temp contact dlg */
-                }
+                dialog = create_contact_starter_dialog (OSSO_ABOOK_AGGREGATOR (priv->aggregator),
+                                                        priv->contact_id);
+                if (!dialog &&
+                    priv->remote_id &&
+                    priv->local_id)
+                        dialog = create_temporary_contact_dialog (priv->remote_id,
+                                                                  priv->local_id);
+
+                if (dialog)
+                        gtk_widget_show (dialog);
+
                 gtk_widget_queue_draw (widget);
         }