]> git.0d.be Git - empathy.git/blobdiff - libempathy-gtk/empathy-avatar-image.c
Move should_create_salut_account to local-xmpp-assistant-widget
[empathy.git] / libempathy-gtk / empathy-avatar-image.c
index 5a5f0aafbfe13451cc8f9ac15cb9ecb641cddf71..3fb79692c333405f94361e80156dfa08b4263240 100644 (file)
@@ -1,7 +1,7 @@
 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
 /*
  * Copyright (C) 2006-2007 Imendio AB
- * Copyright (C) 2007 Collabora Ltd.
+ * Copyright (C) 2007-2008 Collabora Ltd.
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License as
  *
  * You should have received a copy of the GNU General Public
  * License along with this program; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
+ * Boston, MA  02110-1301  USA
  *
  * Authors: Xavier Claessens <xclaesse@gmail.com>
  */
 
 #include "config.h"
 
-#include <glib/gi18n.h>
+#include <glib/gi18n-lib.h>
 #include <gdk/gdkkeysyms.h>
 #include <gdk/gdk.h>
 #include <gtk/gtk.h>
 #include <gdk/gdkx.h>
 
-#include <libempathy/empathy-debug.h>
-
+#include <libempathy/empathy-utils.h>
 #include "empathy-avatar-image.h"
 #include "empathy-ui-utils.h"
 
-#define DEBUG_DOMAIN "AvatarImage"
+/**
+ * SECTION:empathy-avatar-image
+ * @title: EmpathyAvatarImage
+ * @short_description: A widget to display an avatar
+ * @include: libempathy-gtk/empathy-avatar-image.h
+ *
+ * #EmpathyAvatarImage is a widget which displays an avatar.
+ */
 
-#define GET_PRIV(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), EMPATHY_TYPE_AVATAR_IMAGE, EmpathyAvatarImagePriv))
+/**
+ * EmpathyAvatarImage:
+ * @parent: parent object
+ *
+ * Widget which displays an avatar.
+ */
 
 #define MAX_SMALL 64
 #define MAX_LARGE 400
 
+#define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyAvatarImage)
 typedef struct {
        GtkWidget   *image;
        GtkWidget   *popup;
@@ -77,10 +89,10 @@ empathy_avatar_image_class_init (EmpathyAvatarImageClass *klass)
 static void
 empathy_avatar_image_init (EmpathyAvatarImage *avatar_image)
 {
-       EmpathyAvatarImagePriv *priv;
-
-       priv = GET_PRIV (avatar_image);
+       EmpathyAvatarImagePriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (avatar_image,
+               EMPATHY_TYPE_AVATAR_IMAGE, EmpathyAvatarImagePriv);
 
+       avatar_image->priv = priv;
        priv->image = gtk_image_new ();
        gtk_container_add (GTK_CONTAINER (avatar_image), priv->image);
        empathy_avatar_image_set (avatar_image, NULL);
@@ -120,8 +132,7 @@ avatar_image_filter_func (GdkXEvent  *gdkxevent,
 
        priv = GET_PRIV (data);
 
-       switch (xevent->type) {
-       case PropertyNotify:
+       if (xevent->type == PropertyNotify) {
                atom = gdk_x11_get_xatom_by_name ("_NET_CURRENT_DESKTOP");
                if (xevent->xproperty.atom == atom) {
                        if (priv->popup) {
@@ -129,7 +140,6 @@ avatar_image_filter_func (GdkXEvent  *gdkxevent,
                                priv->popup = NULL;
                        }
                }
-               break;
        }
 
        return GDK_FILTER_CONTINUE;
@@ -138,25 +148,24 @@ avatar_image_filter_func (GdkXEvent  *gdkxevent,
 static void
 avatar_image_add_filter (EmpathyAvatarImage *avatar_image)
 {
+       Display    *display;
        Window     window;
-       GdkWindow *gdkwindow;
        gint       mask;
+       XWindowAttributes attrs;
 
        mask = PropertyChangeMask;
 
-       window = GDK_ROOT_WINDOW ();
-       gdkwindow = gdk_xid_table_lookup (window);
+       window = gdk_x11_get_default_root_xwindow ();
+       display = gdk_x11_get_default_xdisplay ();
 
        gdk_error_trap_push ();
-       if (gdkwindow) {
-               XWindowAttributes attrs;
-               XGetWindowAttributes (gdk_display, window, &attrs);
-               mask |= attrs.your_event_mask;
-       }
 
-       XSelectInput (gdk_display, window, mask);
+       XGetWindowAttributes (display, window, &attrs);
+       mask |= attrs.your_event_mask;
+
+       XSelectInput (display, window, mask);
 
-       gdk_error_trap_pop ();
+       gdk_error_trap_pop_ignored ();
 
        gdk_window_add_filter (NULL, avatar_image_filter_func, avatar_image);
 }
@@ -178,6 +187,7 @@ avatar_image_button_press_event (GtkWidget *widget, GdkEventButton *event)
        gint                   popup_width, popup_height;
        gint                   width, height;
        GdkPixbuf             *pixbuf;
+       GtkAllocation          allocation;
 
        priv = GET_PRIV (widget);
 
@@ -193,8 +203,9 @@ avatar_image_button_press_event (GtkWidget *widget, GdkEventButton *event)
        popup_width = gdk_pixbuf_get_width (priv->pixbuf);
        popup_height = gdk_pixbuf_get_height (priv->pixbuf);
 
-       width = priv->image->allocation.width;
-       height = priv->image->allocation.height;
+       gtk_widget_get_allocation (priv->image, &allocation);
+       width = allocation.width;
+       height = allocation.height;
 
        /* Don't show a popup if the popup is smaller then the currently avatar
         * image.
@@ -220,7 +231,7 @@ avatar_image_button_press_event (GtkWidget *widget, GdkEventButton *event)
        gtk_image_set_from_pixbuf (GTK_IMAGE (image), pixbuf);
        g_object_unref (pixbuf);
 
-       gdk_window_get_origin (priv->image->window, &x, &y);
+       gdk_window_get_origin (gtk_widget_get_window (priv->image), &x, &y);
 
        x = x - (popup_width - width) / 2;
        y = y - (popup_height - height) / 2;
@@ -255,6 +266,13 @@ avatar_image_button_release_event (GtkWidget *widget, GdkEventButton *event)
        return TRUE;
 }
 
+/**
+ * empathy_avatar_image_new:
+ *
+ * Creates a new #EmpathyAvatarImage.
+ *
+ * Return value: a new #EmpathyAvatarImage
+ */
 GtkWidget *
 empathy_avatar_image_new (void)
 {
@@ -265,6 +283,13 @@ empathy_avatar_image_new (void)
        return GTK_WIDGET (avatar_image);
 }
 
+/**
+ * empathy_avatar_image_set:
+ * @avatar_image: an #EmpathyAvatarImage
+ * @avatar: the #EmpathyAvatar to set @avatar_image to
+ *
+ * Sets @avatar_image to display the avatar indicated by @avatar.
+ */
 void
 empathy_avatar_image_set (EmpathyAvatarImage *avatar_image,
                          EmpathyAvatar      *avatar)
@@ -280,13 +305,12 @@ empathy_avatar_image_set (EmpathyAvatarImage *avatar_image,
        }
 
        if (avatar) {
-               priv->pixbuf = empathy_pixbuf_from_data (avatar->data, avatar->len);
+               priv->pixbuf = empathy_pixbuf_from_data ((gchar *) avatar->data,
+                               avatar->len);
        }
 
        if (!priv->pixbuf) {
-               gtk_image_set_from_icon_name (GTK_IMAGE (priv->image),
-                                             "stock_person",
-                                             GTK_ICON_SIZE_DIALOG);
+               gtk_image_clear (GTK_IMAGE (priv->image));
                return;
        }