Пример #1
0
static void
avatar_chooser_update_preview_cb (GtkFileChooser       *file_chooser,
				  EmpathyAvatarChooser *chooser)
{
	gchar *filename;

	filename = gtk_file_chooser_get_preview_filename (file_chooser);

	if (filename) {
		GtkWidget *image;
		GdkPixbuf *pixbuf = NULL;
		GdkPixbuf *scaled_pixbuf;

		pixbuf = gdk_pixbuf_new_from_file (filename, NULL);

		image = gtk_file_chooser_get_preview_widget (file_chooser);

		if (pixbuf) {
			scaled_pixbuf = empathy_pixbuf_scale_down_if_necessary (pixbuf, AVATAR_SIZE_SAVE);
			gtk_image_set_from_pixbuf (GTK_IMAGE (image), scaled_pixbuf);
			g_object_unref (scaled_pixbuf);
			g_object_unref (pixbuf);
		} else {
			gtk_image_set_from_stock (GTK_IMAGE (image),
						  "gtk-dialog-question",
						  GTK_ICON_SIZE_DIALOG);
		}

		g_free (filename);
	}

	gtk_file_chooser_set_preview_widget_active (file_chooser, TRUE);
}
Пример #2
0
static void
avatar_chooser_set_image (EmpathyAvatarChooser *chooser,
			  EmpathyAvatar        *avatar,
			  GdkPixbuf            *pixbuf,
			  gboolean              set_locally)
{
	EmpathyAvatarChooserPriv *priv = GET_PRIV (chooser);
	GdkPixbuf                *pixbuf_view;
	GtkWidget                *image;

	g_assert (avatar != NULL);
	g_assert (pixbuf != NULL);

	if (set_locally) {
		EmpathyAvatar *conv;

		conv = avatar_chooser_maybe_convert_and_scale (chooser,
			pixbuf, avatar);
		empathy_avatar_unref (avatar);

		if (conv == NULL) {
			/* An error occured; don't change the avatar. */
			return;
		}

		avatar = conv;
	}

	if (priv->avatar != NULL) {
		empathy_avatar_unref (priv->avatar);
	}
	priv->avatar = avatar;

	pixbuf_view = empathy_pixbuf_scale_down_if_necessary (pixbuf, AVATAR_SIZE_VIEW);
	image = gtk_image_new_from_pixbuf (pixbuf_view);

	gtk_button_set_image (GTK_BUTTON (chooser), image);
	g_signal_emit (chooser, signals[CHANGED], 0);

	g_object_unref (pixbuf_view);
	g_object_unref (pixbuf);
}
Пример #3
0
/**
 * 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)
{
	EmpathyAvatarImagePriv *priv = GET_PRIV (avatar_image);
	GdkPixbuf              *scaled_pixbuf;

	g_return_if_fail (EMPATHY_IS_AVATAR_IMAGE (avatar_image));

	if (priv->pixbuf) {
		g_object_unref (priv->pixbuf);
		priv->pixbuf = NULL;
	}

	if (avatar) {
		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);
		return;
	}

	scaled_pixbuf = empathy_pixbuf_scale_down_if_necessary (priv->pixbuf, MAX_SMALL);
	gtk_image_set_from_pixbuf (GTK_IMAGE (priv->image), scaled_pixbuf);

	if (scaled_pixbuf != priv->pixbuf) {
		gtk_widget_set_tooltip_text (GTK_WIDGET (avatar_image),
					     _("Click to enlarge"));
	} else {
		gtk_widget_set_tooltip_text (GTK_WIDGET (avatar_image),
					     NULL);
	}

	g_object_unref (scaled_pixbuf);
}
Пример #4
0
static gboolean
avatar_image_button_press_event (GtkWidget *widget, GdkEventButton *event)
{
	EmpathyAvatarImagePriv *priv;
	GtkWidget             *popup;
	GtkWidget             *frame;
	GtkWidget             *image;
	gint                   x, y;
	gint                   popup_width, popup_height;
	gint                   width, height;
	GdkPixbuf             *pixbuf;

	priv = GET_PRIV (widget);

	if (priv->popup) {
		gtk_widget_destroy (priv->popup);
		priv->popup = NULL;
	}

	if (event->button != 1 || event->type != GDK_BUTTON_PRESS || !priv->pixbuf) {
		return FALSE;
	}

	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;

	/* Don't show a popup if the popup is smaller then the currently avatar
	 * image.
	 */
	if (popup_height <= height && popup_width <= width) {
		return TRUE;
	}

	pixbuf = empathy_pixbuf_scale_down_if_necessary (priv->pixbuf, MAX_LARGE);
	popup_width = gdk_pixbuf_get_width (pixbuf);
	popup_height = gdk_pixbuf_get_height (pixbuf);

	popup = gtk_window_new (GTK_WINDOW_POPUP);

	frame = gtk_frame_new (NULL);
	gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_OUT);

	gtk_container_add (GTK_CONTAINER (popup), frame);

	image = gtk_image_new ();
	gtk_container_add (GTK_CONTAINER (frame), image);

	gtk_image_set_from_pixbuf (GTK_IMAGE (image), pixbuf);
	g_object_unref (pixbuf);

	gdk_window_get_origin (priv->image->window, &x, &y);

	x = x - (popup_width - width) / 2;
	y = y - (popup_height - height) / 2;

	gtk_window_move (GTK_WINDOW (popup), x, y);

	priv->popup = popup;

	gtk_widget_show_all (popup);

	return TRUE;
}