changeset 10953:e8e535ad720b

[gaim-migrate @ 12753] sf patch #1211718, from Richard Laager "Set Extension for Saving Buddy Icons" committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Tue, 31 May 2005 23:48:54 +0000
parents 98225b573c9d
children ec90b7d126be
files ChangeLog src/buddyicon.c src/buddyicon.h src/gtkconv.c
diffstat 4 files changed, 43 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Tue May 31 23:40:57 2005 +0000
+++ b/ChangeLog	Tue May 31 23:48:54 2005 +0000
@@ -34,6 +34,8 @@
 	* Full message background colors are now supported
 	* Smooth scrolling when receiving a new message
 	* Themeable mouse-over hyperlink coloring
+	* Attempt to detect the file type of a buddy icon when saving
+	  (Richard Laager)
 
 	Bug fixes:
 	* People using input methods can now use Enter again.
--- a/src/buddyicon.c	Tue May 31 23:40:57 2005 +0000
+++ b/src/buddyicon.c	Tue May 31 23:48:54 2005 +0000
@@ -331,6 +331,32 @@
 	return icon->data;
 }
 
+const char *
+gaim_buddy_icon_get_type(const GaimBuddyIcon *icon)
+{
+	const void *data;
+	size_t len;
+
+	g_return_val_if_fail(icon != NULL, NULL);
+
+	data = gaim_buddy_icon_get_data(icon, &len);
+
+	/* TODO: Find a way to do this with GDK */
+	if (len >= 4)
+	{
+		if (!strncmp(data, "BM", 2))
+			return "bmp";
+		else if (!strncmp(data, "GIF8", 4))
+			return "gif";
+		else if (!strncmp(data, "\xff\xd8\xff\xe0", 4))
+			return "jpg";
+		else if (!strncmp(data, "\x89PNG", 4))
+			return "png";
+	}
+
+	return NULL;
+}
+
 void
 gaim_buddy_icons_set_for_user(GaimAccount *account, const char *username,
 							  void *icon_data, size_t icon_len)
--- a/src/buddyicon.h	Tue May 31 23:40:57 2005 +0000
+++ b/src/buddyicon.h	Tue May 31 23:48:54 2005 +0000
@@ -158,6 +158,15 @@
  */
 const void *gaim_buddy_icon_get_data(const GaimBuddyIcon *icon, size_t *len);
 
+/**
+ * Returns an extension corresponding to the buddy icon's file type.
+ *
+ * @param icon The buddy icon.
+ *
+ * @return The icon's extension.
+ */
+const char *gaim_buddy_icon_get_type(const GaimBuddyIcon *icon);
+
 /*@}*/
 
 /**************************************************************************/
--- a/src/gtkconv.c	Tue May 31 23:40:57 2005 +0000
+++ b/src/gtkconv.c	Tue May 31 23:48:54 2005 +0000
@@ -2543,15 +2543,16 @@
 icon_menu_save_cb(GtkWidget *widget, GaimGtkConversation *gtkconv)
 {
 	GaimConversation *conv = gtkconv->active_conv;
+	const gchar *ext;
 	gchar *buf;
 
 	g_return_if_fail(conv != NULL);
 
-	/*
-	 * XXX - The file extension needs to be set to something that doesn't suck...
-	 * Maybe do what gtkimhtml.c does when saving an image?
-	 */
-	buf = g_strdup_printf("%s.icon", gaim_normalize(conv->account, conv->name));
+	ext = gaim_buddy_icon_get_type(gaim_conv_im_get_icon(GAIM_CONV_IM(conv)));
+	if (ext == NULL)
+		ext = "icon";
+
+	buf = g_strdup_printf("%s.%s", gaim_normalize(conv->account, conv->name), ext);
 
 	gaim_request_file(conv, _("Save Icon"), buf, TRUE,
 					 G_CALLBACK(saveicon_writefile_cb), NULL, conv);