/pidgin/main: cc375b914104: imgstore: remove refs from gg prpl

Tomasz Wasilczyk twasilczyk at pidgin.im
Thu Apr 10 18:40:28 EDT 2014


Changeset: cc375b914104116332a849c79d162834318184e0
Author:	 Tomasz Wasilczyk <twasilczyk at pidgin.im>
Date:	 2014-04-11 00:40 +0200
Branch:	 default
URL: https://hg.pidgin.im/pidgin/main/rev/cc375b914104

Description:

imgstore: remove refs from gg prpl

diffstat:

 libpurple/image.c                     |   7 ++++
 libpurple/image.h                     |   3 +
 libpurple/protocols/gg/Makefile.am    |   4 +-
 libpurple/protocols/gg/Makefile.mingw |   2 +-
 libpurple/protocols/gg/avatar.c       |  14 ++++---
 libpurple/protocols/gg/avatar.h       |   4 +-
 libpurple/protocols/gg/gg.h           |   2 +-
 libpurple/protocols/gg/image.c        |  58 ++++++++++++++++++----------------
 libpurple/protocols/gg/image.h        |   4 +-
 libpurple/protocols/gg/message-prpl.c |  13 ++++---
 10 files changed, 64 insertions(+), 47 deletions(-)

diffs (truncated from 357 to 300 lines):

diff --git a/libpurple/image.c b/libpurple/image.c
--- a/libpurple/image.c
+++ b/libpurple/image.c
@@ -372,6 +372,13 @@ purple_image_generate_filename(PurpleIma
 	return priv->gen_filename;
 }
 
+void
+purple_image_set_friendly_filename(PurpleImage *image, const gchar *filename)
+{
+	/* TODO */
+	/* filter with g_path_get_basename() and purple_escape_filename() */
+}
+
 PurpleImage *
 purple_image_transfer_new(void)
 {
diff --git a/libpurple/image.h b/libpurple/image.h
--- a/libpurple/image.h
+++ b/libpurple/image.h
@@ -113,6 +113,9 @@ purple_image_get_mimetype(PurpleImage *i
 const gchar *
 purple_image_generate_filename(PurpleImage *image);
 
+void
+purple_image_set_friendly_filename(PurpleImage *image, const gchar *filename);
+
 PurpleImage *
 purple_image_transfer_new(void);
 
diff --git a/libpurple/protocols/gg/Makefile.am b/libpurple/protocols/gg/Makefile.am
--- a/libpurple/protocols/gg/Makefile.am
+++ b/libpurple/protocols/gg/Makefile.am
@@ -85,8 +85,8 @@ GGSOURCES = \
 	gg.h \
 	html.c \
 	html.h \
-	image.c \
-	image.h \
+	image-prpl.c \
+	image-prpl.h \
 	keymapper.c \
 	keymapper.h \
 	libgadu-events.c \
diff --git a/libpurple/protocols/gg/Makefile.mingw b/libpurple/protocols/gg/Makefile.mingw
--- a/libpurple/protocols/gg/Makefile.mingw
+++ b/libpurple/protocols/gg/Makefile.mingw
@@ -53,7 +53,7 @@ C_SRC =	\
 	edisc.c \
 	gg.c \
 	html.c \
-	image.c \
+	image-prpl.c \
 	keymapper.c \
 	libgadu-events.c \
 	libgaduw.c \
diff --git a/libpurple/protocols/gg/avatar.c b/libpurple/protocols/gg/avatar.c
--- a/libpurple/protocols/gg/avatar.c
+++ b/libpurple/protocols/gg/avatar.c
@@ -68,7 +68,7 @@ static void ggp_avatar_buddy_update_rece
 
 typedef struct
 {
-	PurpleStoredImage *img;
+	PurpleImage *img;
 } ggp_avatar_own_data;
 
 static void ggp_avatar_own_got_token(PurpleConnection *gc, const gchar *token,
@@ -317,7 +317,7 @@ static void ggp_avatar_buddy_update_rece
  * photo=<avatar content>
  */
 
-void ggp_avatar_own_set(PurpleConnection *gc, PurpleStoredImage *img)
+void ggp_avatar_own_set(PurpleConnection *gc, PurpleImage *img)
 {
 	ggp_avatar_own_data *own_data;
 
@@ -339,10 +339,12 @@ void ggp_avatar_own_set(PurpleConnection
 	ggp_oauth_request(gc, ggp_avatar_own_got_token, img, NULL, NULL);
 }
 
-static void ggp_avatar_own_got_token(PurpleConnection *gc, const gchar *token,
-	gpointer img)
+static void
+ggp_avatar_own_got_token(PurpleConnection *gc, const gchar *token,
+	gpointer _img)
 {
 	PurpleHttpRequest *req;
+	PurpleImage *img = _img;
 	ggp_avatar_own_data *own_data = ggp_avatar_get_avdata(gc)->own_data;
 	gchar *img_data, *img_data_e, *request_data;
 	PurpleAccount *account = purple_connection_get_account(gc);
@@ -355,8 +357,8 @@ static void ggp_avatar_own_got_token(Pur
 	}
 	own_data->img = NULL;
 
-	img_data = purple_base64_encode(purple_imgstore_get_data(img),
-		purple_imgstore_get_size(img));
+	img_data = purple_base64_encode(purple_image_get_data(img),
+		purple_image_get_size(img));
 	img_data_e = g_uri_escape_string(img_data, NULL, FALSE);
 	g_free(img_data);
 	request_data = g_strdup_printf("uin=%d&photo=%s", uin, img_data_e);
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,8 +33,6 @@
 #include <internal.h>
 #include <libgadu.h>
 
-#include "imgstore.h" /* TODO: temp */
-
 typedef struct
 {
 	guint timer;
@@ -50,6 +48,6 @@ void ggp_avatar_cleanup(PurpleConnection
 void ggp_avatar_buddy_update(PurpleConnection *gc, uin_t uin, time_t timestamp);
 void ggp_avatar_buddy_remove(PurpleConnection *gc, uin_t uin);
 
-void ggp_avatar_own_set(PurpleConnection *gc, PurpleStoredImage *img);
+void ggp_avatar_own_set(PurpleConnection *gc, PurpleImage *img);
 
 #endif /* _GGP_AVATAR_H */
diff --git a/libpurple/protocols/gg/gg.h b/libpurple/protocols/gg/gg.h
--- a/libpurple/protocols/gg/gg.h
+++ b/libpurple/protocols/gg/gg.h
@@ -38,7 +38,7 @@
 #include "search.h"
 #include "connection.h"
 
-#include "image.h"
+#include "image-prpl.h"
 #include "avatar.h"
 #include "roster.h"
 #include "multilogon.h"
diff --git a/libpurple/protocols/gg/image.c b/libpurple/protocols/gg/image-prpl.c
rename from libpurple/protocols/gg/image.c
rename to libpurple/protocols/gg/image-prpl.c
--- a/libpurple/protocols/gg/image.c
+++ b/libpurple/protocols/gg/image-prpl.c
@@ -27,7 +27,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA
  */
 
-#include "image.h"
+#include "image-prpl.h"
 
 #include <debug.h>
 #include <glibcompat.h>
@@ -35,6 +35,8 @@
 #include "gg.h"
 #include "utils.h"
 
+#include <image-store.h>
+
 struct _ggp_image_session_data
 {
 	GHashTable *got_images;
@@ -44,7 +46,7 @@ struct _ggp_image_session_data
 
 typedef struct
 {
-	int id;
+	guint id; /* TODO: store image ref, not id */
 	gchar *conv_name; /* TODO: callback */
 } ggp_image_sent;
 
@@ -59,16 +61,24 @@ typedef struct
 	gpointer user_data;
 } ggp_image_requested_listener;
 
+static void
+image_unref_by_id(guint id)
+{
+	/* TODO: store image ref, not id */
+	PurpleImage *img = purple_image_store_get(id);
+	g_object_unref(img);
+}
+
 static void ggp_image_got_free(gpointer data)
 {
-	int id = GPOINTER_TO_INT(data);
-	purple_imgstore_unref_by_id(id);
+	guint id = GPOINTER_TO_INT(data);
+	image_unref_by_id(id); /* TODO: store image ref, not id */
 }
 
 static void ggp_image_sent_free(gpointer data)
 {
 	ggp_image_sent *sent_image = (ggp_image_sent*)data;
-	purple_imgstore_unref_by_id(sent_image->id);
+	image_unref_by_id(sent_image->id);
 	g_free(sent_image->conv_name);
 	g_free(sent_image);
 }
@@ -121,11 +131,11 @@ void ggp_image_cleanup(PurpleConnection 
 }
 
 ggp_image_prepare_result ggp_image_prepare(PurpleConversation *conv,
-	const int stored_id, uint64_t *id)
+	const guint stored_id, uint64_t *id)
 {
 	PurpleConnection *gc = purple_conversation_get_connection(conv);
 	ggp_image_session_data *sdata = ggp_image_get_sdata(gc);
-	PurpleStoredImage *image = purple_imgstore_find_by_id(stored_id);
+	PurpleImage *image = purple_image_store_get(stored_id);
 	size_t image_size;
 	gconstpointer image_data;
 	uint32_t image_crc;
@@ -137,7 +147,7 @@ ggp_image_prepare_result ggp_image_prepa
 		return GGP_IMAGE_PREPARE_FAILURE;
 	}
 
-	image_size = purple_imgstore_get_size(image);
+	image_size = purple_image_get_size(image);
 
 	if (image_size > GGP_IMAGE_SIZE_MAX) {
 		purple_debug_warning("gg", "ggp_image_prepare: image "
@@ -145,8 +155,8 @@ ggp_image_prepare_result ggp_image_prepa
 		return GGP_IMAGE_PREPARE_TOO_BIG;
 	}
 
-	purple_imgstore_ref(image);
-	image_data = purple_imgstore_get_data(image);
+	g_object_ref(image);
+	image_data = purple_image_get_data(image);
 	image_crc = gg_crc32(0, image_data, image_size);
 
 	purple_debug_info("gg", "ggp_image_prepare: image prepared "
@@ -168,24 +178,18 @@ void ggp_image_recv(PurpleConnection *gc
 	const struct gg_event_image_reply *image_reply)
 {
 	ggp_image_session_data *sdata = ggp_image_get_sdata(gc);
-	int stored_id;
+	PurpleImage *img;
+	guint stored_id;
 	ggp_image_requested *req;
 	GList *it;
 	uint64_t id;
 
-	/* TODO: This PurpleStoredImage will be rendered within the IM window
-	 * and right-clicking the image will allow the user to save the image
-	 * to disk.  The default filename used in this dialog is the filename
-	 * that we pass to purple_imgstore_new_with_id(), so we should call
-	 * g_path_get_basename() and purple_escape_filename() on it before
-	 * passing it in.  This is easy, but it's not clear if there might be
-	 * other implications because this filename is used elsewhere within
-	 * this PRPL.
-	 */
-	stored_id = purple_imgstore_new_with_id(
+	img = purple_image_new_from_data(
 		g_memdup(image_reply->image, image_reply->size),
-		image_reply->size,
-		image_reply->filename);
+		image_reply->size);
+	purple_image_set_friendly_filename(img, image_reply->filename);
+	stored_id = purple_image_store_add(img);
+	g_object_unref(img);
 
 	id = ggp_image_params_to_id(image_reply->crc32, image_reply->size);
 
@@ -225,7 +229,7 @@ void ggp_image_send(PurpleConnection *gc
 	GGPInfo *accdata = purple_connection_get_protocol_data(gc);
 	ggp_image_session_data *sdata = ggp_image_get_sdata(gc);
 	ggp_image_sent *sent_image;
-	PurpleStoredImage *image;
+	PurpleImage *image;
 	PurpleConversation *conv;
 	uint64_t id;
 	gchar *gg_filename;
@@ -259,7 +263,7 @@ void ggp_image_send(PurpleConnection *gc
 		sent_image->id,
 		sent_image->conv_name);
 
-	image = purple_imgstore_find_by_id(sent_image->id);
+	image = purple_image_store_get(sent_image->id);
 
 	if (!image) {
 		purple_debug_error("gg", "ggp_image_send: requested image "
@@ -273,8 +277,8 @@ void ggp_image_send(PurpleConnection *gc
 	gg_filename = g_strdup_printf(GGP_IMAGE_ID_FORMAT, id);
 	gg_image_reply(accdata->session, image_request->sender,
 		gg_filename,
-		purple_imgstore_get_data(image),
-		purple_imgstore_get_size(image));
+		purple_image_get_data(image),
+		purple_image_get_size(image));
 	g_free(gg_filename);
 
 	conv = purple_conversations_find_with_account(
diff --git a/libpurple/protocols/gg/image.h b/libpurple/protocols/gg/image-prpl.h
rename from libpurple/protocols/gg/image.h
rename to libpurple/protocols/gg/image-prpl.h
--- a/libpurple/protocols/gg/image.h
+++ b/libpurple/protocols/gg/image-prpl.h
@@ -46,13 +46,13 @@ typedef enum
 } ggp_image_prepare_result;
 
 typedef void (*ggp_image_request_cb)(PurpleConnection *gc, uint64_t id,
-	int stored_id, gpointer user_data);



More information about the Commits mailing list