/pidgin/main: 2ebcb105e606: Rename two functions.

Mark Doliner mark at kingant.net
Tue Jan 22 03:05:42 EST 2013


Changeset: 2ebcb105e606f08f0606e46b2e430ade312ae01e
Author:	 Mark Doliner <mark at kingant.net>
Date:	 2013-01-22 00:05 -0800
Branch:	 default
URL: http://hg.pidgin.im/pidgin/main/rev/2ebcb105e606

Description:

Rename two functions.

purple_imgstore_add --> purple_imgstore_new
purple_imgstore_add_with_id --> purple_imgstore_new_with_id

The first function was really misnamed... it doesn't actually add the
function to anything.  The second function was more accurate, in that
it adds the image to a hash table.  But it also allocates a new image,
so I thought it was better to be consistent, to make it more clear
that these functions are similar.

diffstat:

 ChangeLog.API                             |   2 ++
 libpurple/buddyicon.c                     |   2 +-
 libpurple/ft.c                            |   2 +-
 libpurple/imgstore.c                      |  11 ++++++-----
 libpurple/imgstore.h                      |  24 ++++++++++++------------
 libpurple/plugins/perl/common/ImgStore.xs |   4 ++--
 libpurple/protocols/gg/image.c            |   2 +-
 libpurple/protocols/jabber/buddy.c        |   2 +-
 libpurple/protocols/msn/msn.c             |   2 +-
 libpurple/protocols/msn/switchboard.c     |   2 +-
 libpurple/protocols/mxit/formcmds.c       |   4 ++--
 libpurple/protocols/mxit/markup.c         |   2 +-
 libpurple/protocols/mxit/protocol.c       |   2 +-
 libpurple/protocols/mxit/splashscreen.c   |   2 +-
 libpurple/protocols/oscar/odc.c           |   2 +-
 libpurple/protocols/sametime/sametime.c   |   2 +-
 libpurple/protocols/silc/ops.c            |   2 +-
 libpurple/protocols/yahoo/yahoo_profile.c |   2 +-
 libpurple/smiley.c                        |   2 +-
 pidgin/gtkaccount.c                       |   2 +-
 pidgin/gtkimhtml.c                        |   2 +-
 pidgin/gtkimhtmltoolbar.c                 |   2 +-
 pidgin/gtkutils.c                         |   2 +-
 pidgin/gtkwebviewtoolbar.c                |   2 +-
 24 files changed, 43 insertions(+), 40 deletions(-)

diffs (truncated from 397 to 300 lines):

diff --git a/ChangeLog.API b/ChangeLog.API
--- a/ChangeLog.API
+++ b/ChangeLog.API
@@ -89,6 +89,8 @@ version 3.0.0 (??/??/????):
 		* purple_conversation_get_gc renamed to
 		  purple_conversation_get_connection
 		* purple_dnsquery_a now takes a PurpleAccount as the first parameter
+		* purple_imgstore_add renamed to purple_imgstore_new
+		* purple_imgstore_add_with_id renamed to purple_imgstore_new_with_id
 		* purple_network_listen now takes the protocol family as the second
 		  parameter
 		* purple_network_listen now takes a boolean indicating external port
diff --git a/libpurple/buddyicon.c b/libpurple/buddyicon.c
--- a/libpurple/buddyicon.c
+++ b/libpurple/buddyicon.c
@@ -270,7 +270,7 @@ purple_buddy_icon_data_new(guchar *icon_
 		return purple_imgstore_ref(img);
 	}
 
-	img = purple_imgstore_add(icon_data, icon_len, file);
+	img = purple_imgstore_new(icon_data, icon_len, file);
 
 	/* This will take ownership of file and g_free it either now or later. */
 	g_hash_table_insert(icon_data_cache, file, img);
diff --git a/libpurple/ft.c b/libpurple/ft.c
--- a/libpurple/ft.c
+++ b/libpurple/ft.c
@@ -303,7 +303,7 @@ purple_xfer_conversation_write_internal(
 	if (print_thumbnail && thumbnail_data) {
 		gchar *message_with_img;
 		gpointer data = g_memdup(thumbnail_data, size);
-		int id = purple_imgstore_add_with_id(data, size, NULL);
+		int id = purple_imgstore_new_with_id(data, size, NULL);
 
 		message_with_img =
 			g_strdup_printf("<img src='" PURPLE_STORED_IMAGE_PROTOCOL "%d'> %s",
diff --git a/libpurple/imgstore.c b/libpurple/imgstore.c
--- a/libpurple/imgstore.c
+++ b/libpurple/imgstore.c
@@ -36,7 +36,7 @@ static GHashTable *imgstore;
 static unsigned int nextid = 0;
 
 /*
- * NOTE: purple_imgstore_add() creates these without zeroing the memory, so
+ * NOTE: purple_imgstore_new() creates these without zeroing the memory, so
  * NOTE: make sure to update that function when adding members.
  */
 struct _PurpleStoredImage
@@ -49,7 +49,7 @@ struct _PurpleStoredImage
 };
 
 PurpleStoredImage *
-purple_imgstore_add(gpointer data, size_t size, const char *filename)
+purple_imgstore_new(gpointer data, size_t size, const char *filename)
 {
 	PurpleStoredImage *img;
 
@@ -82,13 +82,13 @@ purple_imgstore_new_from_file(const char
 		g_error_free(err);
 		return NULL;
 	}
-	return purple_imgstore_add(data, len, path);
+	return purple_imgstore_new(data, len, path);
 }
 
 int
-purple_imgstore_add_with_id(gpointer data, size_t size, const char *filename)
+purple_imgstore_new_with_id(gpointer data, size_t size, const char *filename)
 {
-	PurpleStoredImage *img = purple_imgstore_add(data, size, filename);
+	PurpleStoredImage *img = purple_imgstore_new(data, size, filename);
 	if (!img) {
 		return 0;
 	}
@@ -219,6 +219,7 @@ purple_imgstore_init()
 	                       purple_value_new(PURPLE_TYPE_SUBTYPE,
 	                                        PURPLE_SUBTYPE_STORED_IMAGE));
 
+	// Use _new_full and free the objects when done.
 	imgstore = g_hash_table_new(g_int_hash, g_int_equal);
 }
 
diff --git a/libpurple/imgstore.h b/libpurple/imgstore.h
--- a/libpurple/imgstore.h
+++ b/libpurple/imgstore.h
@@ -42,9 +42,9 @@ G_BEGIN_DECLS
 /**
  * Create a new PurpleStoredImage.
  *
- * Despite the name of this function, the image is NOT added to the image
- * store and no ID is assigned.  If you need to reference the image by an
- * ID, use purple_imgstore_add_with_id() instead.
+ * The image is not added to the image store and no ID is assigned.  If you
+ * need to reference the image by an ID, use purple_imgstore_new_with_id()
+ * instead.
  *
  * The caller owns a reference to this image and must dereference it with
  * purple_imgstore_unref() for it to be freed.
@@ -62,18 +62,18 @@ G_BEGIN_DECLS
  *                  disk, make sure the filename is appropriately escaped.
  *                  You may wish to use purple_escape_filename().
  *
- * @return The stored image, or NULL if the image was not added (because of
+ * @return The image, or NULL if the image could not be created (because of
  *         empty data or size).
  */
 PurpleStoredImage *
-purple_imgstore_add(gpointer data, size_t size, const char *filename);
+purple_imgstore_new(gpointer data, size_t size, const char *filename);
 
 /**
- * Create a PurpleStoredImage using purple_imgstore_add() by reading the
+ * Create a PurpleStoredImage using purple_imgstore_new() by reading the
  * given filename from disk.
  *
  * The image is not added to the image store and no ID is assigned.  If you
- * need to reference the image by an ID, use purple_imgstore_add_with_id()
+ * need to reference the image by an ID, use purple_imgstore_new_with_id()
  * instead.
  *
  * Make sure the filename is appropriately escaped.  You may wish to use
@@ -83,16 +83,16 @@ purple_imgstore_add(gpointer data, size_
  * The caller owns a reference to this image and must dereference it with
  * purple_imgstore_unref() for it to be freed.
  *
- * @param path  The path to the image.
+ * @param path The path to the image.
  *
- * @return The stored image, or NULL if the image was not added (because of
+ * @return The image, or NULL if the image could not be created (because of
  *         empty data or size).
  */
 PurpleStoredImage *
 purple_imgstore_new_from_file(const char *path);
 
 /**
- * Create a PurpleStoredImage using purple_imgstore_add() and add the
+ * Create a PurpleStoredImage using purple_imgstore_new() and add the
  * image to the image store.  A unique ID will be assigned to the image.
  *
  * The caller owns a reference to the image and must dereference it with
@@ -114,9 +114,9 @@ purple_imgstore_new_from_file(const char
  *
  * @return ID for the image.  This is a unique number that can be used
  *         within libpurple to reference the image.  0 is returned if the
- *         image was not added (because of empty data or size).
+ *         image could not be created (because of empty data or size).
  */
-int purple_imgstore_add_with_id(gpointer data, size_t size, const char *filename);
+int purple_imgstore_new_with_id(gpointer data, size_t size, const char *filename);
 
 /**
  * Retrieve an image from the store. The caller does not own a
diff --git a/libpurple/plugins/perl/common/ImgStore.xs b/libpurple/plugins/perl/common/ImgStore.xs
--- a/libpurple/plugins/perl/common/ImgStore.xs
+++ b/libpurple/plugins/perl/common/ImgStore.xs
@@ -4,13 +4,13 @@ MODULE = Purple::ImgStore  PACKAGE = Pur
 PROTOTYPES: ENABLE
 
 Purple::StoredImage
-purple_imgstore_add(data, size, filename)
+purple_imgstore_new(data, size, filename)
 	void *data
 	size_t size
 	const char *filename
 
 int
-purple_imgstore_add_with_id(data, size, filename)
+purple_imgstore_new_with_id(data, size, filename)
 	void *data
 	size_t size
 	const char *filename
diff --git a/libpurple/protocols/gg/image.c b/libpurple/protocols/gg/image.c
--- a/libpurple/protocols/gg/image.c
+++ b/libpurple/protocols/gg/image.c
@@ -177,7 +177,7 @@ void ggp_image_recv(PurpleConnection *gc
 	gchar *imgtag_replace;
 	GList *pending_messages_it;
 	
-	stored_id = purple_imgstore_add_with_id(
+	stored_id = purple_imgstore_new_with_id(
 		g_memdup(image_reply->image, image_reply->size),
 		image_reply->size,
 		image_reply->filename);
diff --git a/libpurple/protocols/jabber/buddy.c b/libpurple/protocols/jabber/buddy.c
--- a/libpurple/protocols/jabber/buddy.c
+++ b/libpurple/protocols/jabber/buddy.c
@@ -1203,7 +1203,7 @@ static void jabber_vcard_parse(JabberStr
 						char *img_text;
 						char *hash;
 
-						jbi->vcard_imgids = g_slist_prepend(jbi->vcard_imgids, GINT_TO_POINTER(purple_imgstore_add_with_id(g_memdup(data, size), size, "logo.png")));
+						jbi->vcard_imgids = g_slist_prepend(jbi->vcard_imgids, GINT_TO_POINTER(purple_imgstore_new_with_id(g_memdup(data, size), size, "logo.png")));
 						img_text = g_strdup_printf("<img src='" PURPLE_STORED_IMAGE_PROTOCOL "%d'>",
 						                           GPOINTER_TO_INT(jbi->vcard_imgids->data));
 
diff --git a/libpurple/protocols/msn/msn.c b/libpurple/protocols/msn/msn.c
--- a/libpurple/protocols/msn/msn.c
+++ b/libpurple/protocols/msn/msn.c
@@ -2783,7 +2783,7 @@ msn_got_photo(PurpleUtilFetchUrlData *ur
 		{
 			char buf[1024];
 			purple_debug_info("msn", "%s is %" G_GSIZE_FORMAT " bytes\n", photo_url_text, len);
-			id = purple_imgstore_add_with_id(g_memdup(url_text, len), len, NULL);
+			id = purple_imgstore_new_with_id(g_memdup(url_text, len), len, NULL);
 			g_snprintf(buf, sizeof(buf), "<img id=\"%d\"><br>", id);
 			purple_notify_user_info_prepend_pair_html(user_info, NULL, buf);
 		}
diff --git a/libpurple/protocols/msn/switchboard.c b/libpurple/protocols/msn/switchboard.c
--- a/libpurple/protocols/msn/switchboard.c
+++ b/libpurple/protocols/msn/switchboard.c
@@ -827,7 +827,7 @@ msn_switchboard_show_ink(MsnSwitchBoard 
 		return;
 	}
 
-	imgid = purple_imgstore_add_with_id(image_data, image_len, NULL);
+	imgid = purple_imgstore_new_with_id(image_data, image_len, NULL);
 	image_msg = g_strdup_printf("<IMG SRC='" PURPLE_STORED_IMAGE_PROTOCOL "%d'>",
 	                            imgid);
 
diff --git a/libpurple/protocols/mxit/formcmds.c b/libpurple/protocols/mxit/formcmds.c
--- a/libpurple/protocols/mxit/formcmds.c
+++ b/libpurple/protocols/mxit/formcmds.c
@@ -107,7 +107,7 @@ static void mxit_cb_ii_returned(PurpleUt
 	}
 
 	/* we now have the inline image, store a copy in the imagestore */
-	id = purple_imgstore_add_with_id(g_memdup(url_text, len), len, NULL);
+	id = purple_imgstore_new_with_id(g_memdup(url_text, len), len, NULL);
 
 	/* map the inline image id to purple image id */
 	intptr = g_malloc(sizeof(int));
@@ -335,7 +335,7 @@ static void command_image(struct RXMsgDa
 	if (img) {
 		rawimg = purple_base64_decode(img, &rawimglen);
 		//purple_util_write_data_to_file_absolute("/tmp/mxitinline.png", (char*) rawimg, rawimglen);
-		imgid = purple_imgstore_add_with_id(rawimg, rawimglen, NULL);
+		imgid = purple_imgstore_new_with_id(rawimg, rawimglen, NULL);
 		g_string_append_printf(msg,
 		                       "<img src=\"" PURPLE_STORED_IMAGE_PROTOCOL "%i\">",
 		                       imgid);
diff --git a/libpurple/protocols/mxit/markup.c b/libpurple/protocols/mxit/markup.c
--- a/libpurple/protocols/mxit/markup.c
+++ b/libpurple/protocols/mxit/markup.c
@@ -596,7 +596,7 @@ static void emoticon_returned( PurpleUti
 	}
 
 	/* we now have the emoticon, store it in the imagestore */
-	id = purple_imgstore_add_with_id( em_data, em_size, NULL );
+	id = purple_imgstore_new_with_id( em_data, em_size, NULL );
 
 	/* map the mxit emoticon id to purple image id */
 	intptr = g_malloc( sizeof( int ) );
diff --git a/libpurple/protocols/mxit/protocol.c b/libpurple/protocols/mxit/protocol.c
--- a/libpurple/protocols/mxit/protocol.c
+++ b/libpurple/protocols/mxit/protocol.c
@@ -2182,7 +2182,7 @@ static void mxit_parse_cmd_media( struct
 					contact = get_mxit_invite_contact( session, chunk.mxitid );
 					if ( contact ) {
 						/* this is an invite (add image to the internal image store) */
-						contact->imgid = purple_imgstore_add_with_id( g_memdup( chunk.data, chunk.length ), chunk.length, NULL );
+						contact->imgid = purple_imgstore_new_with_id( g_memdup( chunk.data, chunk.length ), chunk.length, NULL );
 						/* show the profile */
 						mxit_show_profile( session, chunk.mxitid, contact->profile );
 					}
diff --git a/libpurple/protocols/mxit/splashscreen.c b/libpurple/protocols/mxit/splashscreen.c
--- a/libpurple/protocols/mxit/splashscreen.c
+++ b/libpurple/protocols/mxit/splashscreen.c
@@ -184,7 +184,7 @@ void splash_display(struct MXitSession* 
 		char buf[128];
 
 		/* Add splash-image to imagestore */
-		imgid = purple_imgstore_add_with_id(g_memdup(imgdata, imglen), imglen, NULL);
+		imgid = purple_imgstore_new_with_id(g_memdup(imgdata, imglen), imglen, NULL);
 
 		/* Generate and display message */
 		g_snprintf(buf, sizeof(buf),
diff --git a/libpurple/protocols/oscar/odc.c b/libpurple/protocols/oscar/odc.c
--- a/libpurple/protocols/oscar/odc.c
+++ b/libpurple/protocols/oscar/odc.c
@@ -356,7 +356,7 @@ peer_odc_handle_payload(PeerConnection *
 
 			if ((embedded_data != NULL) && (embedded_data->size == size))
 			{
-				imgid = purple_imgstore_add_with_id(g_memdup(embedded_data->data, size), size, src);
+				imgid = purple_imgstore_new_with_id(g_memdup(embedded_data->data, size), size, src);
 
 				/* Record the image number */
 				images = g_slist_append(images, GINT_TO_POINTER(imgid));
diff --git a/libpurple/protocols/sametime/sametime.c b/libpurple/protocols/sametime/sametime.c
--- a/libpurple/protocols/sametime/sametime.c
+++ b/libpurple/protocols/sametime/sametime.c
@@ -2780,7 +2780,7 @@ static void im_recv_mime(struct mwConver
       cid = make_cid(cid);
 
       /* add image to the purple image store */
-      img = purple_imgstore_add_with_id(d_dat, d_len, cid);
+      img = purple_imgstore_new_with_id(d_dat, d_len, cid);
 
       /* map the cid to the image store identifier */



More information about the Commits mailing list