[balsa/wip/gtk4: 230/351] face headers: add API to get the pixbufs
- From: Peter Bloomfield <peterb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [balsa/wip/gtk4: 230/351] face headers: add API to get the pixbufs
- Date: Wed, 23 May 2018 21:36:18 +0000 (UTC)
commit 25cef0f0c0b3ab1a872a30da6f90b535b77ccd3e
Author: Peter Bloomfield <PeterBloomfield bellsouth net>
Date: Mon Mar 19 12:55:14 2018 -0400
face headers: add API to get the pixbufs
The Face and X-Face headers define small images; on screen, we show them
in GtkImages, but to print them we need the actual GdkPixbufs.
libbalsa/libbalsa.c | 56 ++++++++++++++++++++++++++++++--------
libbalsa/libbalsa.h | 4 +++
src/balsa-print-object-header.c | 19 +++++++------
3 files changed, 58 insertions(+), 21 deletions(-)
---
diff --git a/libbalsa/libbalsa.c b/libbalsa/libbalsa.c
index 25683a1..70608b3 100644
--- a/libbalsa/libbalsa.c
+++ b/libbalsa/libbalsa.c
@@ -815,14 +815,14 @@ libbalsa_get_header_from_path(const gchar * header, const gchar * path,
return content;
}
-GtkWidget *
-libbalsa_get_image_from_face_header(const gchar * content, GError ** err)
+GdkPixbuf *
+libbalsa_get_pixbuf_from_face_header(const gchar * content, GError ** err)
{
GMimeStream *stream;
GMimeStream *stream_filter;
GMimeFilter *filter;
GByteArray *array;
- GtkWidget *image = NULL;
+ GdkPixbuf *pixbuf = NULL;
stream = g_mime_stream_mem_new();
stream_filter = g_mime_stream_filter_new(stream);
@@ -846,25 +846,42 @@ libbalsa_get_image_from_face_header(const gchar * content, GError ** err)
gdk_pixbuf_loader_close(loader, *err ? NULL : err);
if (!*err)
- image = gtk_image_new_from_pixbuf(gdk_pixbuf_loader_get_pixbuf
- (loader));
+ pixbuf = gdk_pixbuf_loader_get_pixbuf (loader);
g_object_unref(loader);
}
g_object_unref(stream);
+ return pixbuf;
+}
+
+GtkWidget *
+libbalsa_get_image_from_face_header(const gchar * content, GError ** err)
+{
+ GdkPixbuf *pixbuf;
+ GtkWidget *image;
+
+ pixbuf = libbalsa_get_pixbuf_from_face_header(content, err);
+
+ if (pixbuf != NULL) {
+ image = gtk_image_new_from_pixbuf(pixbuf);
+ g_object_unref(pixbuf);
+ } else {
+ image = NULL;
+ }
+
return image;
}
#if HAVE_COMPFACE
GtkWidget *
-libbalsa_get_image_from_x_face_header(const gchar * content, GError ** err)
+libbalsa_get_pixbuf_from_x_face_header(const gchar * content, GError ** err)
{
gchar buf[2048];
GdkPixbuf *pixbuf;
guchar *pixels;
gint lines;
const gchar *p;
- GtkWidget *image = NULL;
+ GdkPixbuf *pixbuf = NULL;
strncpy(buf, content, sizeof buf - 1);
@@ -872,11 +889,11 @@ libbalsa_get_image_from_x_face_header(const gchar * content, GError ** err)
case -1:
g_set_error(err, LIBBALSA_IMAGE_ERROR, LIBBALSA_IMAGE_ERROR_FORMAT,
_("Invalid input format"));
- return image;
+ return NULL;
case -2:
g_set_error(err, LIBBALSA_IMAGE_ERROR, LIBBALSA_IMAGE_ERROR_BUFFER,
_("Internal buffer overrun"));
- return image;
+ return NULL;
}
pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, FALSE, 8, 48, 48);
@@ -894,7 +911,7 @@ libbalsa_get_image_from_x_face_header(const gchar * content, GError ** err)
/* Translators: please do not translate Face. */
_("Bad X-Face data"));
g_object_unref(pixbuf);
- return image;
+ return NULL;
}
for (j = 0, q = pixels; j < 3; j++)
for (k = 15; k >= 0; --k){
@@ -907,8 +924,23 @@ libbalsa_get_image_from_x_face_header(const gchar * content, GError ** err)
pixels += gdk_pixbuf_get_rowstride(pixbuf);
}
- image = gtk_image_new_from_pixbuf(pixbuf);
- g_object_unref(pixbuf);
+ return pixbuf;
+}
+
+GtkWidget *
+libbalsa_get_image_from_x_face_header(const gchar * content, GError ** err)
+{
+ GdkPixbuf *pixbuf;
+ GtkWidget *image;
+
+ pixbuf = libbalsa_get_pixbuf_from_x_face_header(content, err);
+
+ if (pixbuf != NULL) {
+ image = gtk_image_new_from_pixbuf(pixbuf);
+ g_object_unref(pixbuf);
+ } else {
+ image = NULL;
+ }
return image;
}
diff --git a/libbalsa/libbalsa.h b/libbalsa/libbalsa.h
index 9fbdc5e..ffaffb7 100644
--- a/libbalsa/libbalsa.h
+++ b/libbalsa/libbalsa.h
@@ -173,9 +173,13 @@ extern void (*libbalsa_progress_set_activity) (gboolean set,
gchar *libbalsa_get_header_from_path(const gchar * header,
const gchar * path, gsize * size,
GError ** err);
+GdkPixbuf *libbalsa_get_pixbuf_from_face_header(const gchar * content,
+ GError ** err);
GtkWidget *libbalsa_get_image_from_face_header(const gchar * content,
GError ** err);
#if HAVE_COMPFACE
+GdkPixbuf *libbalsa_get_pixbuf_from_x_face_header(const gchar * content,
+ GError ** err);
GtkWidget *libbalsa_get_image_from_x_face_header(const gchar * content,
GError ** err);
#endif /* HAVE_COMPFACE */
diff --git a/src/balsa-print-object-header.c b/src/balsa-print-object-header.c
index 7ade7ec..4864d9e 100644
--- a/src/balsa-print-object-header.c
+++ b/src/balsa-print-object-header.c
@@ -196,21 +196,22 @@ balsa_print_object_header_new_real(GList * list,
/* check for face and x-face */
if (!face) {
GError *err = NULL;
- GtkWidget * f_widget = NULL;
+ GdkPixbuf *f_pixbuf = NULL;
- if (!g_ascii_strcasecmp("Face", pair[0]))
- f_widget = libbalsa_get_image_from_face_header(pair[1], &err);
+ if (g_ascii_strcasecmp("Face", pair[0]) == 0)
+ f_pixbuf = libbalsa_get_pixbuf_from_face_header(pair[1], &err);
#if HAVE_COMPFACE
- else if (!g_ascii_strcasecmp("X-Face", pair[0]))
- f_widget = libbalsa_get_image_from_x_face_header(pair[1], &err);
+ else if (g_ascii_strcasecmp("X-Face", pair[0]) == 0)
+ f_pixbuf = libbalsa_get_pixbuf_from_x_face_header(pair[1], &err);
#endif /* HAVE_COMPFACE */
- if (err)
+ if (err != NULL)
+ /* FIXME report something? */
g_error_free(err);
- if (f_widget) {
- face = gtk_image_get_surface(GTK_IMAGE(f_widget));
+ if (f_pixbuf != NULL) {
+ face = gdk_cairo_surface_create_from_pixbuf(f_pixbuf, 0, NULL);
cairo_surface_reference(face);
- gtk_widget_destroy(f_widget);
+ g_object_unref(f_pixbuf);
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]