Re: [patch] part popups, simplified attachment navigation



Am 12.06.04 17:24 schrieb(en) Steffen Klemer:
yes, we should - does gdk-pixbuff support this or will this be the step

It's possible with GdkPixbuf built-in methods - a very quick 10-minutes hack (also changing the attachments button callback from clicked to pressed) is below. It still has two drawbacks: the maximum image witdth is assumed to be the width of the content container minus the borders, which is too large for embedded messages, and it does not honor resizes. Therefore, it should only be used to demonstrate what I'm thinking of...


Cheers, Albrecht.


-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Albrecht Dreß - Johanna-Kirchner-Straße 13 - D-53123 Bonn (Germany) Phone (+49) 228 6199571 - mailto:albrecht dress arcor de _________________________________________________________________________

--- balsa-message.c.1	2004-06-13 13:12:27.000000000 +0200
+++ balsa-message.c	2004-06-13 13:43:26.000000000 +0200
@@ -429,7 +429,7 @@
 			  gtk_image_new_from_stock("gnome-stock-attach", 
 						   GTK_ICON_SIZE_LARGE_TOOLBAR));
 	gtk_box_pack_start(GTK_BOX(vbox), button, FALSE, FALSE, 0);
-	g_signal_connect(button, "clicked", 
+	g_signal_connect(button, "pressed", 
 			 G_CALLBACK(balsa_headers_attachments_popup), bm);
 	g_object_set_data(G_OBJECT(widget), BALSA_MESSAGE_ATTACHMENTS,
 			  ebox);
@@ -1428,12 +1428,42 @@
 static void
 part_info_init_image(BalsaMessage * bm, BalsaPartInfo * info)
 {
+    GdkPixbuf *pixbuf;
     GtkWidget *image;
     GtkWidget *evbox;
+    GError * load_err = NULL;
 
     libbalsa_message_body_save_temporary(info->body);
+    pixbuf = gdk_pixbuf_new_from_file (info->body->temp_filename, &load_err);
+    if (!pixbuf) {
+	if (load_err) {
+            balsa_information(LIBBALSA_INFORMATION_ERROR,
+			      _("Error loading attached image: %s\n"),
+			      load_err->message);
+	    g_error_free(load_err);
+	}
+	part_info_init_unknown(bm, info);
+	return;
+    }
+
     evbox = gtk_event_box_new();
-    image = gtk_image_new_from_file(info->body->temp_filename);
+    if (gdk_pixbuf_get_width(pixbuf) >
+	bm->content->allocation.width + 2 * BIG_PADDING) {
+	GdkPixbuf * scaled_pixbuf;
+	gint dst_w, dst_h;
+
+	dst_w = bm->content->allocation.width - 2 * BIG_PADDING;
+	if (dst_w < 32)
+	    dst_w = 32;   /* paranoia check */
+	dst_h = (gfloat)dst_w / (gfloat)gdk_pixbuf_get_width(pixbuf) *
+	    gdk_pixbuf_get_height(pixbuf) + 0.5;
+	scaled_pixbuf = gdk_pixbuf_scale_simple(pixbuf, dst_w, dst_h,
+						GDK_INTERP_BILINEAR);
+	g_object_unref(pixbuf);
+	pixbuf = scaled_pixbuf;
+    }
+    image = gtk_image_new_from_pixbuf(pixbuf);
+    g_object_unref(pixbuf);
     gtk_widget_show(image);
     gtk_container_add(GTK_CONTAINER(evbox), image);
     info->widget = evbox;

Attachment: signature.asc
Description: PGP signature



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