[empathy/gnome-2-34] Display an avatar on the block contact dialog



commit 462020737d41b5997b64b76b1991b79fd13eb734
Author: Emilio Pozuelo Monfort <emilio pozuelo collabora co uk>
Date:   Thu Mar 17 20:12:14 2011 +0000

    Display an avatar on the block contact dialog
    
    https://bugzilla.gnome.org/show_bug.cgi?id=645069

 libempathy-gtk/empathy-individual-dialogs.c |    8 ++
 libempathy-gtk/empathy-individual-dialogs.h |    1 +
 libempathy-gtk/empathy-individual-view.c    |  112 +++++++++++++++++---------
 3 files changed, 82 insertions(+), 39 deletions(-)
---
diff --git a/libempathy-gtk/empathy-individual-dialogs.c b/libempathy-gtk/empathy-individual-dialogs.c
index 2d3c688..bfca2e8 100644
--- a/libempathy-gtk/empathy-individual-dialogs.c
+++ b/libempathy-gtk/empathy-individual-dialogs.c
@@ -179,6 +179,7 @@ contact_pretty_name (TpContact *contact)
 gboolean
 empathy_block_individual_dialog_show (GtkWindow *parent,
     FolksIndividual *individual,
+    GdkPixbuf *avatar,
     gboolean *abusive)
 {
   EmpathyIndividualManager *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);
 
diff --git a/libempathy-gtk/empathy-individual-dialogs.h b/libempathy-gtk/empathy-individual-dialogs.h
index 1444d5a..e071056 100644
--- a/libempathy-gtk/empathy-individual-dialogs.h
+++ b/libempathy-gtk/empathy-individual-dialogs.h
@@ -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
diff --git a/libempathy-gtk/empathy-individual-view.c b/libempathy-gtk/empathy-individual-view.c
index b121801..90a9fc6 100644
--- a/libempathy-gtk/empathy-individual-view.c
+++ b/libempathy-gtk/empathy-individual-view.c
@@ -2237,7 +2237,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;
@@ -2245,6 +2246,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;
@@ -2292,7 +2300,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 ();
@@ -2362,55 +2370,81 @@ 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;
+  EmpathyIndividualManager *manager;
+  GdkPixbuf *avatar;
+  gchar *text;
+  GtkWindow *parent;
+  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;
-      gboolean can_block;
-      int res;
+      DEBUG ("Could not get avatar: %s", error->message);
+      g_error_free (error);
+    }
 
-      manager = empathy_individual_manager_dup_singleton ();
-      can_block = empathy_individual_manager_supports_blocking (manager,
-          individual);
+  /* We couldn't retrieve the avatar, but that isn't a fatal error,
+   * so we still display the remove dialog. */
 
-      parent = empathy_get_toplevel_window (GTK_WIDGET (view));
-      text =
-          g_strdup_printf (
-          _("Are you sure you want to remove '%s' from your contacts?"),
-          folks_alias_details_get_alias (FOLKS_ALIAS_DETAILS (individual)));
-      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);
 
-          if (res == REMOVE_DIALOG_RESPONSE_DELETE_AND_BLOCK)
-            {
-              if (!empathy_block_individual_dialog_show (parent, individual,
-                    &abusive))
-                goto finally;
+  parent = empathy_get_toplevel_window (GTK_WIDGET (view));
+  text =
+      g_strdup_printf (
+      _("Are you sure you want to remove '%s' from your contacts?"),
+      folks_alias_details_get_alias (FOLKS_ALIAS_DETAILS (individual)));
 
-              empathy_individual_manager_set_blocked (manager, individual,
-                  TRUE, abusive);
-            }
+  res = individual_view_remove_dialog_show (parent, _("Removing contact"),
+      text, can_block, avatar);
+
+  if (res == REMOVE_DIALOG_RESPONSE_DELETE ||
+      res == REMOVE_DIALOG_RESPONSE_DELETE_AND_BLOCK)
+    {
+      gboolean 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 (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);
     }
 }
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]