/pidgin/main: 48c6ee645ca1: Imgstore vs PurpleImage: rip and fix

Tomasz Wasilczyk twasilczyk at pidgin.im
Thu Apr 10 17:09:55 EDT 2014


Changeset: 48c6ee645ca11f91f1660c7687456bc015fd8e8a
Author:	 Tomasz Wasilczyk <twasilczyk at pidgin.im>
Date:	 2014-04-10 23:09 +0200
Branch:	 default
URL: https://hg.pidgin.im/pidgin/main/rev/48c6ee645ca1

Description:

Imgstore vs PurpleImage: rip and fix

diffstat:

 libpurple/plugins/perl/perl-common.c    |   2 -
 libpurple/protocols/bonjour/bonjour.c   |   4 +-
 libpurple/protocols/bonjour/bonjour.h   |   1 +
 libpurple/protocols/gg/avatar.h         |   2 +
 libpurple/protocols/jabber/jabber.h     |   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/libymsg.h     |   2 +
 libpurple/smiley-custom.c               |  28 +++++++++++-------------
 libpurple/smiley-custom.h               |   2 +-
 libpurple/smiley-remote.c               |  10 ++++----
 libpurple/smiley-remote.h               |   1 -
 libpurple/smiley.c                      |  11 ++++-----
 libpurple/smiley.h                      |   6 ++--
 libpurple/xfer.c                        |   1 +
 pidgin/gtkconv.c                        |   4 +-
 pidgin/gtkinternal.h                    |   2 +-
 pidgin/gtksmiley-manager.c              |  38 ++++++++++++++++----------------
 pidgin/gtksmiley-manager.h              |   2 +-
 pidgin/gtkutils.c                       |  23 +++++++++++++------
 pidgin/gtkutils.h                       |  16 ++++++++++---
 pidgin/gtkwebview.c                     |  10 ++++++--
 pidgin/gtkwebview.h                     |   7 +++--
 pidgin/gtkwebviewtoolbar.c              |  10 ++++----
 26 files changed, 110 insertions(+), 81 deletions(-)

diffs (truncated from 718 to 300 lines):

diff --git a/libpurple/plugins/perl/perl-common.c b/libpurple/plugins/perl/perl-common.c
--- a/libpurple/plugins/perl/perl-common.c
+++ b/libpurple/plugins/perl/perl-common.c
@@ -436,8 +436,6 @@ purple_perl_sv_from_purple_type(GType ty
 		stash = "Purple::XMLNode";
 	else if (type == PURPLE_TYPE_NOTIFY_USER_INFO)
  		stash = "Purple::NotifyUserInfo";
-	else if (type == PURPLE_TYPE_STORED_IMAGE)
- 		stash = "Purple::StoredImage";
 	else if (type == PURPLE_TYPE_CERTIFICATE_POOL)
  		stash = "Purple::Certificate::Pool";
 	else
diff --git a/libpurple/protocols/bonjour/bonjour.c b/libpurple/protocols/bonjour/bonjour.c
--- a/libpurple/protocols/bonjour/bonjour.c
+++ b/libpurple/protocols/bonjour/bonjour.c
@@ -326,8 +326,8 @@ bonjour_convo_closed(PurpleConnection *c
 	bb->conversation = NULL;
 }
 
-static
-void bonjour_set_buddy_icon(PurpleConnection *conn, PurpleStoredImage *img)
+static void
+bonjour_set_buddy_icon(PurpleConnection *conn, PurpleImage *img)
 {
 	BonjourData *bd = purple_connection_get_protocol_data(conn);
 	bonjour_dns_sd_update_buddy_icon(bd->dns_sd_data);
diff --git a/libpurple/protocols/bonjour/bonjour.h b/libpurple/protocols/bonjour/bonjour.h
--- a/libpurple/protocols/bonjour/bonjour.h
+++ b/libpurple/protocols/bonjour/bonjour.h
@@ -29,6 +29,7 @@
 #include "mdns_common.h"
 #include "internal.h"
 #include "jabber.h"
+#include "imgstore.h" /* TODO: temp */
 
 #define BONJOUR_GROUP_NAME _("Bonjour")
 #define BONJOUR_PROTOCOL_NAME "bonjour"
diff --git a/libpurple/protocols/gg/avatar.h b/libpurple/protocols/gg/avatar.h
--- a/libpurple/protocols/gg/avatar.h
+++ b/libpurple/protocols/gg/avatar.h
@@ -33,6 +33,8 @@
 #include <internal.h>
 #include <libgadu.h>
 
+#include "imgstore.h" /* TODO: temp */
+
 typedef struct
 {
 	guint timer;
diff --git a/libpurple/protocols/jabber/jabber.h b/libpurple/protocols/jabber/jabber.h
--- a/libpurple/protocols/jabber/jabber.h
+++ b/libpurple/protocols/jabber/jabber.h
@@ -54,6 +54,8 @@ typedef enum {
 
 typedef struct _JabberStream JabberStream;
 
+#include "imgstore.h" /* TODO: temp */
+
 #include <libxml/parser.h>
 #include <glib.h>
 #include "circularbuffer.h"
diff --git a/libpurple/protocols/mxit/mxit.h b/libpurple/protocols/mxit/mxit.h
--- a/libpurple/protocols/mxit/mxit.h
+++ b/libpurple/protocols/mxit/mxit.h
@@ -30,6 +30,7 @@
 #include "internal.h"
 #include "http.h"
 
+#include "imgstore.h" /* TODO: temp */
 
 #if defined( __APPLE__ )
 /* apple architecture */
diff --git a/libpurple/protocols/oscar/oscar.h b/libpurple/protocols/oscar/oscar.h
--- a/libpurple/protocols/oscar/oscar.h
+++ b/libpurple/protocols/oscar/oscar.h
@@ -37,6 +37,8 @@
 #include "proxy.h"
 #include "sslconn.h"
 
+#include "imgstore.h" /* TODO: temp */
+
 #include <stdio.h>
 #include <string.h>
 #include <fcntl.h>
diff --git a/libpurple/protocols/oscar/oscarcommon.h b/libpurple/protocols/oscar/oscarcommon.h
--- a/libpurple/protocols/oscar/oscarcommon.h
+++ b/libpurple/protocols/oscar/oscarcommon.h
@@ -26,6 +26,8 @@
 
 #include "internal.h"
 
+#include "imgstore.h" /* TODO: temp */
+
 #include "accountopt.h"
 #include "prpl.h"
 #include "version.h"
diff --git a/libpurple/protocols/silc/silcpurple.h b/libpurple/protocols/silc/silcpurple.h
--- a/libpurple/protocols/silc/silcpurple.h
+++ b/libpurple/protocols/silc/silcpurple.h
@@ -35,6 +35,8 @@
 #include "server.h"
 #include "util.h"
 
+#include "imgstore.h" /* TODO: temp */
+
 #undef SILC_VERSION
 #define SILC_VERSION(a, b, c) (((a) << 24) + ((b) << 16) + ((c) << 8))
 
diff --git a/libpurple/protocols/yahoo/libymsg.h b/libpurple/protocols/yahoo/libymsg.h
--- a/libpurple/protocols/yahoo/libymsg.h
+++ b/libpurple/protocols/yahoo/libymsg.h
@@ -31,6 +31,8 @@
 #include "prpl.h"
 #include "network.h"
 
+#include "imgstore.h" /* TODO: temp */
+
 #define YAHOO_PAGER_HOST_REQ_URL "http://vcs2.msg.yahoo.com/capacity"
 #define YAHOO_PAGER_HOST_FALLBACK "scsa.msg.yahoo.com"
 #define YAHOO_PAGER_PORT 5050
diff --git a/libpurple/smiley-custom.c b/libpurple/smiley-custom.c
--- a/libpurple/smiley-custom.c
+++ b/libpurple/smiley-custom.c
@@ -160,13 +160,13 @@ purple_smiley_custom_save(void)
 }
 
 static gchar *
-purple_smiley_custom_img_checksum(PurpleStoredImage *img)
+purple_smiley_custom_img_checksum(PurpleImage *img)
 {
-	g_return_val_if_fail(PURPLE_IS_STORED_IMAGE(img), NULL);
+	g_return_val_if_fail(PURPLE_IS_IMAGE(img), NULL);
 
 	return g_compute_checksum_for_data(G_CHECKSUM_SHA1,
-		purple_imgstore_get_data(img),
-		purple_imgstore_get_size(img));
+		purple_image_get_data(img),
+		purple_image_get_size(img));
 }
 
 
@@ -175,7 +175,7 @@ purple_smiley_custom_img_checksum(Purple
  ******************************************************************************/
 
 PurpleSmiley *
-purple_smiley_custom_add(PurpleStoredImage *img, const gchar *shortcut)
+purple_smiley_custom_add(PurpleImage *img, const gchar *shortcut)
 {
 	PurpleSmiley *existing_smiley, *smiley;
 	gchar *checksum, *file_path;
@@ -184,12 +184,12 @@ purple_smiley_custom_add(PurpleStoredIma
 	GError *error = NULL;
 	gboolean succ;
 
-	g_return_val_if_fail(PURPLE_IS_STORED_IMAGE(img), NULL);
+	g_return_val_if_fail(PURPLE_IS_IMAGE(img), NULL);
 
 	existing_smiley = purple_smiley_list_get_by_shortcut(
 		smileys_list, shortcut);
 
-	purple_imgstore_ref(img);
+	g_object_ref(img);
 
 	if (existing_smiley) {
 		disable_write = TRUE;
@@ -198,27 +198,25 @@ purple_smiley_custom_add(PurpleStoredIma
 	}
 
 	checksum = purple_smiley_custom_img_checksum(img);
-	file_ext = purple_imgstore_get_extension(img);
+	file_ext = purple_image_get_extension(img);
 	if (file_ext == NULL || g_strcmp0("icon", file_ext) == 0) {
 		purple_debug_warning("smiley-custom", "Invalid image type");
 		return NULL;
 	}
 
 	g_snprintf(file_name, sizeof(file_name), "%s.%s", checksum, file_ext);
+	g_free(checksum);
+
 	file_path = g_build_filename(smileys_dir, file_name, NULL);
 
-	g_file_set_contents(file_path, purple_imgstore_get_data(img),
-		purple_imgstore_get_size(img), &error);
-
-	g_free(checksum);
-	purple_imgstore_unref(img);
-
-	if (error) {
+	if (!purple_image_save(img, file_path)) {
 		purple_debug_error("smiley-custom", "Failed writing smiley "
 			"file %s: %s", file_path, error->message);
 		g_free(file_path);
+		g_object_unref(img);
 		return NULL;
 	}
+	g_object_unref(img);
 
 	smiley = purple_smiley_new(shortcut, file_path);
 	g_free(file_path);
diff --git a/libpurple/smiley-custom.h b/libpurple/smiley-custom.h
--- a/libpurple/smiley-custom.h
+++ b/libpurple/smiley-custom.h
@@ -49,7 +49,7 @@
  * Returns: a new #PurpleSmiley, or %NULL if error occured.
  */
 PurpleSmiley *
-purple_smiley_custom_add(PurpleStoredImage *image, const gchar *shortcut);
+purple_smiley_custom_add(PurpleImage *image, const gchar *shortcut);
 
 /**
  * purple_smiley_custom_remove:
diff --git a/libpurple/smiley-remote.c b/libpurple/smiley-remote.c
--- a/libpurple/smiley-remote.c
+++ b/libpurple/smiley-remote.c
@@ -31,7 +31,7 @@
 
 typedef struct {
 	GString *contents;
-	PurpleStoredImage *image; /* it's not the same as in parent */
+	PurpleImage *image; /* it's not the same as in parent */
 
 	gboolean has_failed;
 } PurpleRemoteSmileyPrivate;
@@ -94,8 +94,8 @@ purple_remote_smiley_close(PurpleRemoteS
 		return;
 	}
 
-	priv->image = purple_imgstore_new(priv->contents->str,
-		priv->contents->len, NULL);
+	priv->image = purple_image_new_from_data(priv->contents->str,
+		priv->contents->len);
 	g_return_if_fail(priv->image != NULL);
 	g_string_free(priv->contents, FALSE);
 	priv->contents = NULL;
@@ -121,7 +121,7 @@ purple_remote_smiley_failed(PurpleRemote
 	g_signal_emit(smiley, signals[SIG_FAILED], 0);
 }
 
-static PurpleStoredImage *
+static PurpleImage *
 purple_remote_smiley_get_image_impl(PurpleSmiley *smiley)
 {
 	PurpleRemoteSmileyPrivate *priv =
@@ -166,7 +166,7 @@ purple_remote_smiley_finalize(GObject *o
 	if (priv->contents)
 		g_string_free(priv->contents, TRUE);
 	if (priv->image)
-		purple_imgstore_unref(priv->image);
+		g_object_unref(priv->image);
 
 	G_OBJECT_CLASS(parent_class)->finalize(obj);
 }
diff --git a/libpurple/smiley-remote.h b/libpurple/smiley-remote.h
--- a/libpurple/smiley-remote.h
+++ b/libpurple/smiley-remote.h
@@ -40,7 +40,6 @@
 
 #include <glib-object.h>
 
-#include "imgstore.h"
 #include "util.h"
 
 typedef struct _PurpleRemoteSmiley PurpleRemoteSmiley;
diff --git a/libpurple/smiley.c b/libpurple/smiley.c
--- a/libpurple/smiley.c
+++ b/libpurple/smiley.c
@@ -23,7 +23,6 @@
 #include "glibcompat.h"
 #include "dbus-maybe.h"
 #include "debug.h"
-#include "imgstore.h"
 #include "smiley.h"
 #include "util.h"
 #include "xmlnode.h"
@@ -34,7 +33,7 @@
 typedef struct {
 	gchar *shortcut;
 	gchar *path;
-	PurpleStoredImage *image;
+	PurpleImage *image;
 	gboolean is_ready;
 } PurpleSmileyPrivate;
 
@@ -104,7 +103,7 @@ purple_smiley_get_path(PurpleSmiley *smi
 	return priv->path;
 }
 
-static PurpleStoredImage *
+static PurpleImage *
 purple_smiley_get_image_impl(PurpleSmiley *smiley)
 {
 	PurpleSmileyPrivate *priv = PURPLE_SMILEY_GET_PRIVATE(smiley);
@@ -123,7 +122,7 @@ purple_smiley_get_image_impl(PurpleSmile
 		return NULL;
 	}
 
-	priv->image = purple_imgstore_new_from_file(path);
+	priv->image = purple_image_new_from_file(path, TRUE);
 	if (!priv->image) {
 		purple_debug_error("smiley", "Couldn't load smiley data ");



More information about the Commits mailing list