]> git.0d.be Git - empathy.git/commitdiff
Display an avatar on the block contact dialog
authorEmilio Pozuelo Monfort <emilio.pozuelo@collabora.co.uk>
Fri, 18 Mar 2011 11:14:51 +0000 (11:14 +0000)
committerEmilio Pozuelo Monfort <emilio.pozuelo@collabora.co.uk>
Fri, 18 Mar 2011 11:14:51 +0000 (11:14 +0000)
https://bugzilla.gnome.org/show_bug.cgi?id=645069

libempathy-gtk/empathy-individual-dialogs.c
libempathy-gtk/empathy-individual-dialogs.h
libempathy-gtk/empathy-individual-view.c

index b5f41db13e82d0332f526f2fdc516bb7c1745f0d..2e88a742b557c91b5cb47213e03913859786ea3a 100644 (file)
@@ -179,6 +179,7 @@ contact_pretty_name (TpContact *contact)
 gboolean
 empathy_block_individual_dialog_show (GtkWindow *parent,
     FolksIndividual *individual,
+    GdkPixbuf *avatar,
     gboolean *abusive)
 {
   EmpathyContactManager *contact_manager =
@@ -198,6 +199,13 @@ empathy_block_individual_dialog_show (GtkWindow *parent,
       _("Block %s?"),
       folks_alias_details_get_alias (FOLKS_ALIAS_DETAILS (individual)));
 
+  if (avatar != NULL)
+    {
+      GtkWidget *image = gtk_image_new_from_pixbuf (avatar);
+      gtk_message_dialog_set_image (GTK_MESSAGE_DIALOG (dialog), image);
+      gtk_widget_show (image);
+    }
+
   /* build a list of personas that support blocking */
   personas = folks_individual_get_personas (individual);
 
index 1444d5ac816916dbb609e9db6dd8cd2b6c441bc2..e071056768c9c7375736393e22b3e418b4a2f735 100644 (file)
@@ -34,6 +34,7 @@ void empathy_new_individual_dialog_show_with_individual (GtkWindow *parent,
     FolksIndividual *individual);
 gboolean empathy_block_individual_dialog_show (GtkWindow *parent,
     FolksIndividual *individual,
+    GdkPixbuf *avatar,
     gboolean *abusive);
 
 G_END_DECLS
index 5cd2afacbd4805e21ad43b94a9e222db022465b7..634c391a8d76b238ebaeaf81581ee5f7cc25463f 100644 (file)
@@ -2275,7 +2275,8 @@ static int
 individual_view_remove_dialog_show (GtkWindow *parent,
     const gchar *message,
     const gchar *secondary_text,
-    gboolean block_button)
+    gboolean block_button,
+    GdkPixbuf *avatar)
 {
   GtkWidget *dialog;
   gboolean res;
@@ -2283,6 +2284,13 @@ individual_view_remove_dialog_show (GtkWindow *parent,
   dialog = gtk_message_dialog_new (parent, GTK_DIALOG_MODAL,
       GTK_MESSAGE_QUESTION, GTK_BUTTONS_NONE, "%s", message);
 
+  if (avatar != NULL)
+    {
+      GtkWidget *image = gtk_image_new_from_pixbuf (avatar);
+      gtk_message_dialog_set_image (GTK_MESSAGE_DIALOG (dialog), image);
+      gtk_widget_show (image);
+    }
+
   if (block_button)
     {
       GtkWidget *button;
@@ -2329,7 +2337,7 @@ individual_view_group_remove_activate_cb (GtkMenuItem *menuitem,
           group);
       parent = empathy_get_toplevel_window (GTK_WIDGET (view));
       if (individual_view_remove_dialog_show (parent, _("Removing group"),
-              text, FALSE) == REMOVE_DIALOG_RESPONSE_DELETE)
+              text, FALSE, NULL) == REMOVE_DIALOG_RESPONSE_DELETE)
         {
           EmpathyIndividualManager *manager =
               empathy_individual_manager_dup_singleton ();
@@ -2399,89 +2407,115 @@ empathy_individual_view_get_group_menu (EmpathyIndividualView *view)
 }
 
 static void
-individual_view_remove_activate_cb (GtkMenuItem *menuitem,
-    EmpathyIndividualView *view)
+got_avatar (GObject *source_object,
+    GAsyncResult *result,
+    gpointer user_data)
 {
-  FolksIndividual *individual;
+  FolksIndividual *individual = FOLKS_INDIVIDUAL (source_object);
+  EmpathyIndividualView *view = user_data;
+  GdkPixbuf *avatar;
+  EmpathyIndividualManager *manager;
+  gchar *text;
+  GtkWindow *parent;
+  GList *l, *personas;
+  guint persona_count = 0;
+  gboolean can_block;
+  GError *error = NULL;
+  gint res;
 
-  individual = empathy_individual_view_dup_selected (view);
+  avatar = empathy_pixbuf_avatar_from_individual_scaled_finish (individual,
+      result, &error);
 
-  if (individual != NULL)
+  if (error != NULL)
     {
-      EmpathyIndividualManager *manager;
-      gchar *text;
-      GtkWindow *parent;
-      GList *l, *personas;
-      guint persona_count = 0;
-      gboolean can_block;
-      int res;
+      DEBUG ("Could not get avatar: %s", error->message);
+      g_error_free (error);
+    }
 
-      personas = folks_individual_get_personas (individual);
+  /* We couldn't retrieve the avatar, but that isn't a fatal error,
+   * so we still display the remove dialog. */
 
-      /* If we have more than one TpfPersona, display a different message
-       * ensuring the user knows that *all* of the meta-contacts' personas will
-       * be removed. */
-      for (l = personas; l != NULL; l = l->next)
-        {
-          if (!empathy_folks_persona_is_interesting (FOLKS_PERSONA (l->data)))
-            continue;
+  personas = folks_individual_get_personas (individual);
 
-          persona_count++;
-          if (persona_count >= 2)
-            break;
-        }
+  /* If we have more than one TpfPersona, display a different message
+   * ensuring the user knows that *all* of the meta-contacts' personas will
+   * be removed. */
+  for (l = personas; l != NULL; l = l->next)
+    {
+      if (!empathy_folks_persona_is_interesting (FOLKS_PERSONA (l->data)))
+        continue;
 
-      if (persona_count < 2)
-        {
-          /* Not a meta-contact */
-          text =
-              g_strdup_printf (
-                  _("Do you really want to remove the contact '%s'?"),
-                  folks_alias_details_get_alias (
-                      FOLKS_ALIAS_DETAILS (individual)));
-        }
-      else
-        {
-          /* Meta-contact */
-          text =
-              g_strdup_printf (
-                  _("Do you really want to remove the linked contact '%s'? "
-                    "Note that this will remove all the contacts which make up "
-                    "this linked contact."),
-                  folks_alias_details_get_alias (
-                      FOLKS_ALIAS_DETAILS (individual)));
-        }
+      persona_count++;
+      if (persona_count >= 2)
+        break;
+    }
 
+  if (persona_count < 2)
+    {
+      /* Not a meta-contact */
+      text =
+          g_strdup_printf (
+              _("Do you really want to remove the contact '%s'?"),
+              folks_alias_details_get_alias (
+                  FOLKS_ALIAS_DETAILS (individual)));
+    }
+  else
+    {
+      /* Meta-contact */
+      text =
+          g_strdup_printf (
+              _("Do you really want to remove the linked contact '%s'? "
+                "Note that this will remove all the contacts which make up "
+                "this linked contact."),
+              folks_alias_details_get_alias (
+                  FOLKS_ALIAS_DETAILS (individual)));
+    }
 
-      manager = empathy_individual_manager_dup_singleton ();
-      can_block = empathy_individual_manager_supports_blocking (manager,
-          individual);
-      parent = empathy_get_toplevel_window (GTK_WIDGET (view));
-      res = individual_view_remove_dialog_show (parent, _("Removing contact"),
-              text, can_block);
 
-      if (res == REMOVE_DIALOG_RESPONSE_DELETE ||
-          res == REMOVE_DIALOG_RESPONSE_DELETE_AND_BLOCK)
-        {
-          gboolean abusive;
+  manager = empathy_individual_manager_dup_singleton ();
+  can_block = empathy_individual_manager_supports_blocking (manager,
+      individual);
+  parent = empathy_get_toplevel_window (GTK_WIDGET (view));
+  res = individual_view_remove_dialog_show (parent, _("Removing contact"),
+          text, can_block, avatar);
 
-          if (res == REMOVE_DIALOG_RESPONSE_DELETE_AND_BLOCK)
-            {
-              if (!empathy_block_individual_dialog_show (parent, individual,
-                    &abusive))
-                goto finally;
+  if (res == REMOVE_DIALOG_RESPONSE_DELETE ||
+      res == REMOVE_DIALOG_RESPONSE_DELETE_AND_BLOCK)
+    {
+      gboolean abusive;
 
-              empathy_individual_manager_set_blocked (manager, individual,
-                  TRUE, abusive);
-            }
+      if (res == REMOVE_DIALOG_RESPONSE_DELETE_AND_BLOCK)
+        {
+          if (!empathy_block_individual_dialog_show (parent, individual,
+                avatar, &abusive))
+            goto finally;
 
-          empathy_individual_manager_remove (manager, individual, "");
+          empathy_individual_manager_set_blocked (manager, individual,
+              TRUE, abusive);
         }
 
-finally:
-      g_free (text);
+      empathy_individual_manager_remove (manager, individual, "");
+    }
+
+ finally:
+  g_free (text);
+  g_object_unref (individual);
+  g_object_unref (manager);
+}
+
+static void
+individual_view_remove_activate_cb (GtkMenuItem *menuitem,
+    EmpathyIndividualView *view)
+{
+  FolksIndividual *individual;
+
+  individual = empathy_individual_view_dup_selected (view);
+
+  if (individual != NULL)
+    {
+      empathy_pixbuf_avatar_from_individual_scaled_async (individual,
+          48, 48, NULL, got_avatar, view);
       g_object_unref (individual);
-      g_object_unref (manager);
     }
 }