[evolution-patches] (Addressbook) Fix for bug 274509 (Revised)



Hi,

I have attached the patch which resizes while syncing from bbdb as well
as vcard control and it also does the resize while migrating from older version.

-Srini
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/evolution/plugins/bbdb/ChangeLog,v
retrieving revision 1.17
diff -u -p -r1.17 ChangeLog
--- ChangeLog	28 Jul 2005 09:41:23 -0000	1.17
+++ ChangeLog	22 Aug 2005 10:54:31 -0000
@@ -1,3 +1,8 @@
+2005-08-22  Srinivasa Ragavan <sragavan novell com>
+
+	* gaimbuddies.c	(bbdb_merge_buddy_to_contact): Added code to 
+	resize image when automatic sync of images
+
 2005-07-28  Vivek Jain  <jvivek novell com>
 	
 	* bbdb.c:(bbdb_handle_reply):check for NULL
Index: gaimbuddies.c
===================================================================
RCS file: /cvs/gnome/evolution/plugins/bbdb/gaimbuddies.c,v
retrieving revision 1.5
diff -u -p -r1.5 gaimbuddies.c
--- gaimbuddies.c	17 Jun 2005 15:20:30 -0000	1.5
+++ gaimbuddies.c	22 Aug 2005 10:54:32 -0000
@@ -254,9 +254,45 @@ bbdb_merge_buddy_to_contact (EBook *book
 				g_list_free (ims);
 				return dirty;
 			}
-
-			e_contact_set (c, E_CONTACT_PHOTO, (gpointer) photo);
-			dirty = TRUE;
+			
+			if (photo) {
+				GdkPixbuf *pixbuf, *new;
+				GdkPixbufLoader *loader = gdk_pixbuf_loader_new();
+				
+				gdk_pixbuf_loader_write (loader, photo->data, photo->length, NULL);
+				gdk_pixbuf_loader_close (loader, NULL);
+					
+				pixbuf = gdk_pixbuf_loader_get_pixbuf (loader);
+				if (pixbuf) {
+					int width, height;
+					
+					g_object_ref (pixbuf);
+					height = gdk_pixbuf_get_height (pixbuf);
+					width = gdk_pixbuf_get_width (pixbuf);
+		
+					if (height > 96 || width > 96)  {
+						if ( width > height) {
+							height = height * 96 / width;
+							width = 96;
+						} else {
+							width = width *96 / height;
+							height = 96;
+						}
+		        		       	new = gdk_pixbuf_scale_simple (pixbuf, width, height, GDK_INTERP_BILINEAR);
+						if (new) {
+							g_free(photo->data);
+			        	       		gdk_pixbuf_save_to_buffer (new, &photo->data, &photo->length, "jpeg", NULL, "quality", "100", NULL);
+							g_object_unref (new);
+							e_contact_set (c, E_CONTACT_PHOTO, photo);
+							dirty = TRUE;
+						}
+					}
+					g_object_unref (pixbuf);
+				}
+				g_object_unref (loader);
+				g_free (photo->data);
+				g_free(photo);
+			}	
 		}
 	}
 
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/evolution/addressbook/ChangeLog,v
retrieving revision 1.1988
diff -u -p -r1.1988 ChangeLog
--- ChangeLog	22 Aug 2005 10:37:17 -0000	1.1988
+++ ChangeLog	22 Aug 2005 11:33:30 -0000
@@ -1,3 +1,11 @@
+2005-08-22  Srinivasa Ragavan <sragavan novell com>
+
+	* gui/widgets/eab-vcard-control.c (book_open_cb): Added code to
+	resize image while adding contacts from vcard control.
+	
+	* gui/components/addressbook-migrate.c (migrate_contacts): Added code
+	to resize image while migrating from old evolution.
+	
 2005-08-22  Sushma Rai  <rsushma novell com>
 
 	* gui/widgets/eab-contact-display.c 
Index: gui/component/addressbook-migrate.c
===================================================================
RCS file: /cvs/gnome/evolution/addressbook/gui/component/addressbook-migrate.c,v
retrieving revision 1.39
diff -u -p -r1.39 addressbook-migrate.c
--- gui/component/addressbook-migrate.c	15 Jul 2005 06:47:34 -0000	1.39
+++ gui/component/addressbook-migrate.c	22 Aug 2005 11:33:30 -0000
@@ -255,9 +255,50 @@ migrate_contacts (MigrationContext *cont
 		EContact *contact = l->data;
 		GError *e = NULL;
 		GList *attrs, *attr;
+		EContactPhoto *photo;
 
 		/* do some last minute massaging of the contact's attributes */
-
+	
+		/* Resize the photos to 96x96 if present. */
+		photo = e_contact_get (contact, E_CONTACT_PHOTO);
+		if (photo) {
+			GdkPixbuf *pixbuf, *new;
+			GdkPixbufLoader *loader = gdk_pixbuf_loader_new();
+				
+			gdk_pixbuf_loader_write (loader, photo->data, photo->length, NULL);
+			gdk_pixbuf_loader_close (loader, NULL);
+					
+			pixbuf = gdk_pixbuf_loader_get_pixbuf (loader);
+			if (pixbuf) {
+				int width, height;
+					
+				g_object_ref (pixbuf);
+				height = gdk_pixbuf_get_height (pixbuf);
+				width = gdk_pixbuf_get_width (pixbuf);
+		
+				if (height > 96 || width > 96)  {
+					if ( width > height) {
+						height = height * 96 / width;
+						width = 96;
+					} else {
+						width = width *96 / height;
+						height = 96;
+					}
+	        		       	new = gdk_pixbuf_scale_simple (pixbuf, width, height, GDK_INTERP_BILINEAR);
+					if (new) {
+						g_free(photo->data);
+		        	       		gdk_pixbuf_save_to_buffer (new, &photo->data, &photo->length, "jpeg", NULL, "quality", "100", NULL);
+						g_object_unref (new);
+						e_contact_set (contact, E_CONTACT_PHOTO, photo);
+					}
+				}
+				g_object_unref (pixbuf);
+			}
+			g_object_unref (loader);
+			g_free (photo->data);
+			g_free(photo);
+		}			
+		
 		attrs = e_vcard_get_attributes (E_VCARD (contact));
 		for (attr = attrs; attr;) {
 			EVCardAttribute *a = attr->data;
Index: gui/widgets/eab-vcard-control.c
===================================================================
RCS file: /cvs/gnome/evolution/addressbook/gui/widgets/eab-vcard-control.c,v
retrieving revision 1.9
diff -u -p -r1.9 eab-vcard-control.c
--- gui/widgets/eab-vcard-control.c	17 Jun 2005 15:20:26 -0000	1.9
+++ gui/widgets/eab-vcard-control.c	22 Aug 2005 11:33:30 -0000
@@ -38,7 +38,7 @@
 #include <addressbook/gui/component/addressbook.h>
 #include <addressbook/gui/widgets/eab-contact-display.h>
 #include <addressbook/util/eab-book-util.h>
-
+#include <gdk/gdkpixbuf.h>
 #include "eab-vcard-control.h"
 #include "eab-contact-merging.h"
 
@@ -187,7 +187,48 @@ book_open_cb (EBook *book, EBookStatus s
 		GList *p;
 		for (p = list; p; p = p->next) {
 			/* XXX argh, more passing of NULL's for callbacks */
-			eab_merging_book_add_contact (book, E_CONTACT (p->data), NULL, NULL);
+			EContact *contact = E_CONTACT(p->data);
+			EContactPhoto *photo;
+			photo = e_contact_get (contact, E_CONTACT_PHOTO);
+
+			if (photo) {
+				GdkPixbuf *pixbuf, *new;
+				GdkPixbufLoader *loader = gdk_pixbuf_loader_new();
+				
+				gdk_pixbuf_loader_write (loader, photo->data, photo->length, NULL);
+				gdk_pixbuf_loader_close (loader, NULL);
+					
+				pixbuf = gdk_pixbuf_loader_get_pixbuf (loader);
+				if (pixbuf) {
+					int width, height;
+					
+					g_object_ref (pixbuf);
+					height = gdk_pixbuf_get_height (pixbuf);
+					width = gdk_pixbuf_get_width (pixbuf);
+		
+					if (height > 96 || width > 96)  {
+						if ( width > height) {
+							height = height * 96 / width;
+							width = 96;
+						} else {
+							width = width *96 / height;
+							height = 96;
+						}
+		        		       	new = gdk_pixbuf_scale_simple (pixbuf, width, height, GDK_INTERP_BILINEAR);
+						if (new) {
+							g_free(photo->data);
+			        	       		gdk_pixbuf_save_to_buffer (new, &photo->data, &photo->length, "jpeg", NULL, "quality", "100", NULL);
+							g_object_unref (new);
+							e_contact_set (contact, E_CONTACT_PHOTO, photo);
+						}
+					}
+					g_object_unref (pixbuf);
+				}
+				g_object_unref (loader);
+				g_free (photo->data);
+				g_free(photo);
+			}			
+			eab_merging_book_add_contact (book, contact, NULL, NULL);
 		}
 	}
 	if (book)


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