empathy r1669 - trunk/libempathy-gtk
- From: xclaesse svn gnome org
- To: svn-commits-list gnome org
- Subject: empathy r1669 - trunk/libempathy-gtk
- Date: Tue, 11 Nov 2008 15:25:40 +0000 (UTC)
Author: xclaesse
Date: Tue Nov 11 15:25:40 2008
New Revision: 1669
URL: http://svn.gnome.org/viewvc/empathy?rev=1669&view=rev
Log:
Don't automatically resize and png-ify avatars.
Modified:
trunk/libempathy-gtk/empathy-avatar-chooser.c
trunk/libempathy-gtk/empathy-avatar-image.c
trunk/libempathy-gtk/empathy-ui-utils.c
trunk/libempathy-gtk/empathy-ui-utils.h
Modified: trunk/libempathy-gtk/empathy-avatar-chooser.c
==============================================================================
--- trunk/libempathy-gtk/empathy-avatar-chooser.c (original)
+++ trunk/libempathy-gtk/empathy-avatar-chooser.c Tue Nov 11 15:25:40 2008
@@ -166,39 +166,30 @@
}
static void
-avatar_chooser_set_pixbuf (EmpathyAvatarChooser *chooser,
- GdkPixbuf *pixbuf)
+avatar_chooser_set_image (EmpathyAvatarChooser *chooser,
+ GdkPixbuf *pixbuf,
+ gchar *image_data,
+ gsize image_data_size,
+ gchar *mime_type)
{
EmpathyAvatarChooserPriv *priv = GET_PRIV (chooser);
GtkWidget *image;
GdkPixbuf *pixbuf_view = NULL;
- GdkPixbuf *pixbuf_save = NULL;
- GError *error = NULL;
g_free (priv->image_data);
+ g_free (priv->mime_type);
+
priv->image_data = NULL;
priv->image_data_size = 0;
- g_free (priv->mime_type);
priv->mime_type = NULL;
if (pixbuf) {
- pixbuf_view = empathy_pixbuf_scale_down_if_necessary (pixbuf, AVATAR_SIZE_VIEW);
- pixbuf_save = empathy_pixbuf_scale_down_if_necessary (pixbuf, AVATAR_SIZE_SAVE);
+ priv->image_data = image_data;
+ priv->image_data_size = image_data_size;
+ priv->mime_type = mime_type;
- if (!gdk_pixbuf_save_to_buffer (pixbuf_save,
- &priv->image_data,
- &priv->image_data_size,
- "png",
- &error, NULL)) {
- DEBUG ("Failed to save pixbuf: %s",
- error ? error->message : "No error given");
- g_clear_error (&error);
- } else {
- priv->mime_type = "image/png";
- }
+ pixbuf_view = empathy_pixbuf_scale_down_if_necessary (pixbuf, AVATAR_SIZE_VIEW);
image = gtk_image_new_from_pixbuf (pixbuf_view);
-
- g_object_unref (pixbuf_save);
g_object_unref (pixbuf_view);
} else {
image = gtk_image_new_from_icon_name ("stock_person",
@@ -210,22 +201,30 @@
}
static void
+avatar_chooser_clear_image (EmpathyAvatarChooser *chooser)
+{
+ avatar_chooser_set_image (chooser, NULL, NULL, 0, NULL);
+}
+
+static void
avatar_chooser_set_image_from_file (EmpathyAvatarChooser *chooser,
const gchar *filename)
{
- GdkPixbuf *pixbuf;
- GError *error = NULL;
+ gchar *image_data = NULL;
+ gsize image_size = 0;
+ GError *error = NULL;
- if (!(pixbuf = gdk_pixbuf_new_from_file (filename, &error))) {
- DEBUG ("Failed to load pixbuf from file: %s",
+ if (!g_file_get_contents (filename, &image_data, &image_size, &error)) {
+ DEBUG ("Failed to load image from '%s': %s", filename,
error ? error->message : "No error given");
+
+ avatar_chooser_clear_image (chooser);
+
g_clear_error (&error);
+ return;
}
- avatar_chooser_set_pixbuf (chooser, pixbuf);
- if (pixbuf) {
- g_object_unref (pixbuf);
- }
+ avatar_chooser_set_image_from_data (chooser, image_data, image_size);
}
static void
@@ -233,10 +232,11 @@
gchar *data,
gsize size)
{
- GdkPixbuf *pixbuf;
+ GdkPixbuf *pixbuf;
+ gchar *mime_type = NULL;
- pixbuf = empathy_pixbuf_from_data (data, size);
- avatar_chooser_set_pixbuf (chooser, pixbuf);
+ pixbuf = empathy_pixbuf_from_data (data, size, &mime_type);
+ avatar_chooser_set_image (chooser, pixbuf, data, size, mime_type);
if (pixbuf) {
g_object_unref (pixbuf);
}
@@ -553,9 +553,12 @@
{
g_return_if_fail (EMPATHY_IS_AVATAR_CHOOSER (chooser));
- avatar_chooser_set_image_from_data (chooser,
- avatar ? avatar->data : NULL,
- avatar ? avatar->len : 0);
+ if (avatar != NULL) {
+ gchar *data = g_memdup (avatar->data, avatar->len);
+ avatar_chooser_set_image_from_data (chooser, data, avatar->len);
+ } else {
+ avatar_chooser_clear_image (chooser);
+ }
}
void
Modified: trunk/libempathy-gtk/empathy-avatar-image.c
==============================================================================
--- trunk/libempathy-gtk/empathy-avatar-image.c (original)
+++ trunk/libempathy-gtk/empathy-avatar-image.c Tue Nov 11 15:25:40 2008
@@ -276,7 +276,7 @@
}
if (avatar) {
- priv->pixbuf = empathy_pixbuf_from_data (avatar->data, avatar->len);
+ priv->pixbuf = empathy_pixbuf_from_data (avatar->data, avatar->len, NULL);
}
if (!priv->pixbuf) {
Modified: trunk/libempathy-gtk/empathy-ui-utils.c
==============================================================================
--- trunk/libempathy-gtk/empathy-ui-utils.c (original)
+++ trunk/libempathy-gtk/empathy-ui-utils.c Tue Nov 11 15:25:40 2008
@@ -245,11 +245,14 @@
}
GdkPixbuf *
-empathy_pixbuf_from_data (gchar *data,
- gsize data_size)
+empathy_pixbuf_from_data (gchar *data,
+ gsize data_size,
+ gchar **mime_type)
{
GdkPixbufLoader *loader;
+ GdkPixbufFormat *format;
GdkPixbuf *pixbuf = NULL;
+ gchar **mime_types;
GError *error = NULL;
if (!data) {
@@ -260,23 +263,34 @@
if (!gdk_pixbuf_loader_write (loader, data, data_size, &error)) {
DEBUG ("Failed to write to pixbuf loader: %s",
error ? error->message : "No error given");
- g_clear_error (&error);
- g_object_unref (loader);
- return NULL;
+ goto out;
}
if (!gdk_pixbuf_loader_close (loader, &error)) {
DEBUG ("Failed to close pixbuf loader: %s",
error ? error->message : "No error given");
- g_clear_error (&error);
- g_object_unref (loader);
- return NULL;
+ goto out;
}
pixbuf = gdk_pixbuf_loader_get_pixbuf (loader);
if (pixbuf) {
g_object_ref (pixbuf);
+
+ if (mime_type != NULL) {
+ format = gdk_pixbuf_loader_get_format (loader);
+ mime_types = gdk_pixbuf_format_get_mime_types (format);
+
+ *mime_type = g_strdup (*mime_types);
+ if (*(mime_types + 1) != NULL) {
+ DEBUG ("Loader supports more than one mime "
+ "type! Picking the first one, %s",
+ *mime_type);
+ }
+ g_strfreev (mime_types);
+ }
}
+out:
+ g_clear_error (&error);
g_object_unref (loader);
return pixbuf;
Modified: trunk/libempathy-gtk/empathy-ui-utils.h
==============================================================================
--- trunk/libempathy-gtk/empathy-ui-utils.h (original)
+++ trunk/libempathy-gtk/empathy-ui-utils.h Tue Nov 11 15:25:40 2008
@@ -69,7 +69,8 @@
const gchar * empathy_icon_name_for_presence (McPresence presence);
const gchar * empathy_icon_name_for_contact (EmpathyContact *contact);
GdkPixbuf * empathy_pixbuf_from_data (gchar *data,
- gsize data_size);
+ gsize data_size,
+ gchar **mime_type);
GdkPixbuf * empathy_pixbuf_from_avatar_scaled (EmpathyAvatar *avatar,
gint width,
gint height);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]