/soc/2013/ankitkv/gobjectification: 07746c9a04bf: Merged default...

Ankit Vani a at nevitus.org
Fri Apr 11 06:54:32 EDT 2014


Changeset: 07746c9a04bf7cc6cacc7ac6abb0b1e9b1ee4c59
Author:	 Ankit Vani <a at nevitus.org>
Date:	 2014-04-11 16:23 +0530
Branch:	 soc.2013.gobjectification.plugins
URL: https://hg.pidgin.im/soc/2013/ankitkv/gobjectification/rev/07746c9a04bf

Description:

Merged default branch

diffstat:

 libpurple/Makefile.am                        |    4 +
 libpurple/Makefile.mingw                     |    2 +
 libpurple/buddyicon.c                        |  188 ++++----
 libpurple/buddyicon.h                        |   31 +-
 libpurple/ciphers/aescipher.c                |    2 +
 libpurple/conversation.c                     |    1 -
 libpurple/core.c                             |    8 +-
 libpurple/glibcompat.h                       |   32 +-
 libpurple/image-store.c                      |  180 ++++++++
 libpurple/image-store.h                      |   64 +++
 libpurple/image.c                            |  565 +++++++++++++++++++++++++++
 libpurple/image.h                            |  134 ++++++
 libpurple/imgstore.c                         |  183 +-------
 libpurple/imgstore.h                         |  242 +-----------
 libpurple/log.c                              |   14 +-
 libpurple/plugins/perl/Makefile.am           |    1 -
 libpurple/plugins/perl/common/BuddyIcon.xs   |    2 +-
 libpurple/plugins/perl/common/ImgStore.xs    |   53 --
 libpurple/plugins/perl/common/MANIFEST       |    1 -
 libpurple/plugins/perl/common/Makefile.mingw |    1 -
 libpurple/plugins/perl/common/Purple.xs      |    2 -
 libpurple/plugins/perl/common/module.h       |    4 -
 libpurple/plugins/perl/perl-common.c         |    2 -
 libpurple/protocol.c                         |    2 +-
 libpurple/protocol.h                         |    8 +-
 libpurple/protocols/bonjour/bonjour.c        |    4 +-
 libpurple/protocols/bonjour/mdns_common.c    |   20 +-
 libpurple/protocols/gg/Makefile.am           |    4 +-
 libpurple/protocols/gg/Makefile.mingw        |    2 +-
 libpurple/protocols/gg/avatar.c              |   14 +-
 libpurple/protocols/gg/avatar.h              |    2 +-
 libpurple/protocols/gg/gg.h                  |    2 +-
 libpurple/protocols/gg/image.c               |  106 +---
 libpurple/protocols/gg/image.h               |   31 +-
 libpurple/protocols/gg/message-prpl.c        |   44 +-
 libpurple/protocols/jabber/buddy.c           |   41 +-
 libpurple/protocols/jabber/buddy.h           |    2 +-
 libpurple/protocols/jabber/jabber.c          |   11 +-
 libpurple/protocols/jabber/message.c         |   41 +-
 libpurple/protocols/jabber/useravatar.c      |   24 +-
 libpurple/protocols/jabber/useravatar.h      |    4 +-
 libpurple/protocols/msn/msn.c                |    2 +-
 libpurple/protocols/mxit/mxit.h              |    1 +
 libpurple/protocols/oscar/oscar.h            |    2 +
 libpurple/protocols/oscar/oscarcommon.h      |    2 +
 libpurple/protocols/silc/silcpurple.h        |    2 +
 libpurple/protocols/yahoo/ymsg.h             |    2 +
 libpurple/smiley-custom.c                    |   28 +-
 libpurple/smiley-custom.h                    |    2 +-
 libpurple/smiley-list.c                      |   27 +-
 libpurple/smiley-parser.c                    |   70 ++-
 libpurple/smiley-parser.h                    |   39 +-
 libpurple/smiley-remote.c                    |   10 +-
 libpurple/smiley-remote.h                    |    1 -
 libpurple/smiley.c                           |   16 +-
 libpurple/smiley.h                           |    6 +-
 libpurple/tests/test_trie.c                  |   49 ++
 libpurple/theme.h                            |    1 -
 libpurple/trie.c                             |   68 +++
 libpurple/trie.h                             |   22 +-
 libpurple/util.h                             |   12 -
 libpurple/xfer.c                             |   16 +-
 pidgin/gtkaccount.c                          |   50 +-
 pidgin/gtkblist.c                            |   25 +-
 pidgin/gtkconv.c                             |  104 ++--
 pidgin/gtkinternal.h                         |    2 +-
 pidgin/gtkrequest.c                          |    2 +-
 pidgin/gtksmiley-manager.c                   |   38 +-
 pidgin/gtksmiley-manager.h                   |    2 +-
 pidgin/gtksmiley-theme.c                     |    6 +
 pidgin/gtkstatusbox.c                        |   58 +-
 pidgin/gtkstatusbox.h                        |    5 +-
 pidgin/gtkutils.c                            |   19 +-
 pidgin/gtkutils.h                            |   11 +-
 pidgin/gtkwebview.c                          |  135 ++++--
 pidgin/gtkwebview.h                          |   18 +-
 pidgin/gtkwebviewtoolbar.c                   |   57 +-
 pidgin/libpidgin.c                           |    2 +
 pidgin/plugins/perl/common/GtkStatusBox.xs   |    5 -
 po/POTFILES.in                               |    2 +-
 valgrind-suppressions                        |    8 +
 81 files changed, 1893 insertions(+), 1112 deletions(-)

diffs (truncated from 5665 to 300 lines):

diff --git a/libpurple/Makefile.am b/libpurple/Makefile.am
--- a/libpurple/Makefile.am
+++ b/libpurple/Makefile.am
@@ -71,6 +71,8 @@ purple_coresources = \
 	eventloop.c \
 	http.c \
 	idle.c \
+	image.c \
+	image-store.c \
 	imgstore.c \
 	keyring.c \
 	log.c \
@@ -156,6 +158,8 @@ purple_coreheaders = \
 	eventloop.h \
 	http.h \
 	idle.h \
+	image.h \
+	image-store.h \
 	imgstore.h \
 	keyring.h \
 	log.h \
diff --git a/libpurple/Makefile.mingw b/libpurple/Makefile.mingw
--- a/libpurple/Makefile.mingw
+++ b/libpurple/Makefile.mingw
@@ -95,6 +95,8 @@ C_SRC =	\
 			eventloop.c \
 			http.c \
 			idle.c \
+			image.c \
+			image-store.c \
 			imgstore.c \
 			keyring.c \
 			log.c \
diff --git a/libpurple/buddyicon.c b/libpurple/buddyicon.c
--- a/libpurple/buddyicon.c
+++ b/libpurple/buddyicon.c
@@ -25,7 +25,7 @@
 #include "conversation.h"
 #include "dbus-maybe.h"
 #include "debug.h"
-#include "imgstore.h"
+#include "image.h"
 #include "util.h"
 
 /* NOTE: Instances of this struct are allocated without zeroing the memory, so
@@ -33,7 +33,7 @@
 struct _PurpleBuddyIcon
 {
 	PurpleAccount *account;    /* The account the user is on.          */
-	PurpleStoredImage *img;    /* The stored image containing
+	PurpleImage *img;          /* The image containing
 	                              the icon data.                       */
 	char *username;            /* The username the icon belongs to.    */
 	char *checksum;            /* The protocol checksum.               */
@@ -53,7 +53,7 @@ struct _PurpleBuddyIcon
 static GHashTable *account_cache = NULL;
 
 /*
- * This hash table contains a bunch of PurpleStoredImages that are
+ * This hash table contains a bunch of PurpleImages that are
  * shared across all accounts.
  *
  * Key is the filename for this image as constructed by
@@ -61,11 +61,10 @@ static GHashTable *account_cache = NULL;
  * sha-1 hash plus an appropriate file extension.  For example:
  *   "0f4972d17d1e70e751c43c90c948e72efbff9796.gif"
  *
- * The value is a PurpleStoredImage containing the icon data.  These
- * images are reference counted, and when the count reaches 0
- * imgstore.c emits the image-deleting signal and we remove the image
- * from the hash table (but it might still be saved on disk, if the
- * icon is being used by offline accounts or some such).
+ * The value is a PurpleImage containing the icon data.  These images are
+ * reference counted, and when the count reaches 0 we remove the image from
+ * the hash table (but it might still be saved on disk, if the icon is being
+ * used by offline accounts or some such).
  */
 static GHashTable *icon_data_cache = NULL;
 
@@ -77,7 +76,7 @@ static GHashTable *icon_data_cache = NUL
  * time Pidgin starts.
  *
  * Key is the filename for this image as constructed by
- * purple_util_get_image_filename().  So it is the base16 encoded
+ * purple_image_generate_filename().  So it is the base16 encoded
  * sha-1 hash plus an appropriate file extension.  For example:
  *   "0f4972d17d1e70e751c43c90c948e72efbff9796.gif"
  *
@@ -140,34 +139,43 @@ unref_filename(const char *filename)
 	}
 }
 
+static const gchar *
+image_get_filename(PurpleImage *img)
+{
+	return g_object_get_data(G_OBJECT(img), "purple-buddyicon-filename");
+}
+
 static void
-purple_buddy_icon_data_cache(PurpleStoredImage *img)
+purple_buddy_icon_data_cache(PurpleImage *img)
 {
-	const char *dirname;
-	char *path;
+	const gchar *dirname, *filename;
+	gchar *path;
 
-	g_return_if_fail(img != NULL);
+	g_return_if_fail(PURPLE_IS_IMAGE(img));
 
 	if (!purple_buddy_icons_is_caching())
 		return;
 
 	dirname = purple_buddy_icons_get_cache_dir();
-	path = g_build_filename(dirname, purple_imgstore_get_filename(img), NULL);
+	filename = image_get_filename(img);
+	g_return_if_fail(filename != NULL);
+	path = g_build_filename(dirname, filename, NULL);
 
 	if (!g_file_test(dirname, G_FILE_TEST_IS_DIR))
 	{
-		purple_debug_info("buddyicon", "Creating icon cache directory.\n");
+		purple_debug_info("buddyicon", "creating icon cache directory");
 
 		if (g_mkdir(dirname, S_IRUSR | S_IWUSR | S_IXUSR) < 0)
 		{
 			purple_debug_error("buddyicon",
-			                   "Unable to create directory %s: %s\n",
-			                   dirname, g_strerror(errno));
+				"unable to create directory %s: %s",
+				dirname, g_strerror(errno));
+			return;
 		}
 	}
 
-	purple_util_write_data_to_file_absolute(path, purple_imgstore_get_data(img),
-											purple_imgstore_get_size(img));
+	if (!purple_image_save(img, path))
+		purple_debug_error("buddyicon", "failed to save icon %s", path);
 	g_free(path);
 }
 
@@ -218,51 +226,50 @@ value_equals(gpointer key, gpointer valu
 }
 
 static void
-image_deleting_cb(const PurpleStoredImage *img, gpointer data)
+image_deleting_cb(gpointer _filename)
 {
-	const char *filename = purple_imgstore_get_filename(img);
+	PurpleImage *img;
+	gchar *filename = _filename;
 
-	/* If there's no filename, it can't be one of our images. */
-	if (filename == NULL)
-		return;
+	img = g_hash_table_lookup(icon_data_cache, filename);
+	purple_buddy_icon_data_uncache_file(filename);
+	g_hash_table_remove(icon_data_cache, filename);
 
-	if (img == g_hash_table_lookup(icon_data_cache, filename))
-	{
-		purple_buddy_icon_data_uncache_file(filename);
-		g_hash_table_remove(icon_data_cache, filename);
+	/* We could make this O(1) by using another hash table, but
+	 * this is probably good enough. */
+	g_hash_table_foreach_remove(pointer_icon_cache, value_equals, (gpointer)img);
 
-		/* We could make this O(1) by using another hash table, but
-		 * this is probably good enough. */
-		g_hash_table_foreach_remove(pointer_icon_cache, value_equals, (gpointer)img);
-	}
+	g_free(filename);
 }
 
-static PurpleStoredImage *
+static PurpleImage *
 purple_buddy_icon_data_new(guchar *icon_data, size_t icon_len)
 {
-	char *file;
-	PurpleStoredImage *img;
+	PurpleImage *newimg, *oldimg;
+	const gchar *filename;
 
 	g_return_val_if_fail(icon_data != NULL, NULL);
 	g_return_val_if_fail(icon_len > 0, NULL);
 
-	file = purple_util_get_image_filename(icon_data, icon_len);
+	newimg = purple_image_new_from_data(icon_data, icon_len);
+	filename = purple_image_generate_filename(newimg);
 
-	img = g_hash_table_lookup(icon_data_cache, file);
-	if (img) {
-		g_free(file);
-		g_free(icon_data);
-		return purple_imgstore_ref(img);
+	oldimg = g_hash_table_lookup(icon_data_cache, filename);
+	if (oldimg) {
+		g_warn_if_fail(PURPLE_IS_IMAGE(oldimg));
+		g_object_unref(newimg);
+		g_object_ref(oldimg);
+		return oldimg;
 	}
 
-	img = purple_imgstore_new(icon_data, icon_len, file);
+	/* This will take ownership of file and free it as needed */
+	g_hash_table_insert(icon_data_cache, g_strdup(filename), newimg);
+	g_object_set_data_full(G_OBJECT(newimg), "purple-buddyicon-filename",
+		g_strdup(filename), image_deleting_cb);
 
-	/* This will take ownership of file and free it as needed */
-	g_hash_table_insert(icon_data_cache, file, img);
+	purple_buddy_icon_data_cache(newimg);
 
-	purple_buddy_icon_data_cache(img);
-
-	return img;
+	return newimg;
 }
 
 /*
@@ -356,7 +363,7 @@ purple_buddy_icon_unref(PurpleBuddyIcon 
 
 		g_free(icon->username);
 		g_free(icon->checksum);
-		purple_imgstore_unref(icon->img);
+		g_object_unref(icon->img);
 
 		PURPLE_DBUS_UNREGISTER_POINTER(icon);
 		g_slice_free(PurpleBuddyIcon, icon);
@@ -398,7 +405,8 @@ purple_buddy_icon_update(PurpleBuddyIcon
 		                                                 "buddy_icon"));
 		if (icon->img && purple_buddy_icons_is_caching())
 		{
-			const char *filename = purple_imgstore_get_filename(icon->img);
+			const char *filename = image_get_filename(icon->img);
+			g_warn_if_fail(filename != NULL);
 			purple_blist_node_set_string((PurpleBlistNode *)buddy,
 			                             "buddy_icon",
 			                             filename);
@@ -440,7 +448,7 @@ void
 purple_buddy_icon_set_data(PurpleBuddyIcon *icon, guchar *data,
                            size_t len, const char *checksum)
 {
-	PurpleStoredImage *old_img;
+	PurpleImage *old_img;
 
 	g_return_if_fail(icon != NULL);
 
@@ -460,7 +468,8 @@ purple_buddy_icon_set_data(PurpleBuddyIc
 
 	purple_buddy_icon_update(icon);
 
-	purple_imgstore_unref(old_img);
+	if (old_img)
+		g_object_unref(old_img);
 }
 
 PurpleAccount *
@@ -495,9 +504,9 @@ purple_buddy_icon_get_data(const PurpleB
 	if (icon->img)
 	{
 		if (len != NULL)
-			*len = purple_imgstore_get_size(icon->img);
+			*len = purple_image_get_size(icon->img);
 
-		return purple_imgstore_get_data(icon->img);
+		return purple_image_get_data(icon->img);
 	}
 
 	return NULL;
@@ -507,7 +516,7 @@ const char *
 purple_buddy_icon_get_extension(const PurpleBuddyIcon *icon)
 {
 	if (icon->img != NULL)
-		return purple_imgstore_get_extension(icon->img);
+		return purple_image_get_extension(icon->img);
 
 	return NULL;
 }
@@ -563,20 +572,19 @@ purple_buddy_icons_set_for_user(PurpleAc
 	}
 }
 
-char *purple_buddy_icon_get_full_path(PurpleBuddyIcon *icon)
+const gchar *
+purple_buddy_icon_get_full_path(PurpleBuddyIcon *icon)
 {
-	char *path;
+	const gchar *path;
 
 	g_return_val_if_fail(icon != NULL, NULL);
 
 	if (icon->img == NULL)
 		return NULL;
 
-	path = g_build_filename(purple_buddy_icons_get_cache_dir(),
-	                        purple_imgstore_get_filename(icon->img), NULL);
+	path = purple_image_get_path(icon->img);
 	if (!g_file_test(path, G_FILE_TEST_EXISTS))



More information about the Commits mailing list