/pidgin/main: 3ade2f38ec3a: imgstore: unref sametime
Tomasz Wasilczyk
twasilczyk at pidgin.im
Fri Apr 11 18:07:08 EDT 2014
Changeset: 3ade2f38ec3a74ab0770ca54c0889f16b5103e02
Author: Tomasz Wasilczyk <twasilczyk at pidgin.im>
Date: 2014-04-12 00:07 +0200
Branch: default
URL: https://hg.pidgin.im/pidgin/main/rev/3ade2f38ec3a
Description:
imgstore: unref sametime
diffstat:
libpurple/protocols/sametime/sametime.c | 107 +++++++++++--------------------
1 files changed, 37 insertions(+), 70 deletions(-)
diffs (199 lines):
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
@@ -36,8 +36,8 @@
#include "circularbuffer.h"
#include "conversation.h"
#include "debug.h"
+#include "image-store.h"
#include "xfer.h"
-#include "imgstore.h"
#include "mime.h"
#include "notify.h"
#include "plugin.h"
@@ -2715,15 +2715,13 @@ static void im_recv_mime(struct mwConver
const char *data) {
GHashTable *img_by_cid;
- GList *images;
GString *str;
PurpleMimeDocument *doc;
GList *parts;
- img_by_cid = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
- images = NULL;
+ img_by_cid = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_object_unref);
/* don't want the contained string to ever be NULL */
str = g_string_new("");
@@ -2748,7 +2746,7 @@ static void im_recv_mime(struct mwConver
guchar *d_dat;
gsize d_len;
char *cid;
- int img;
+ PurpleImage *image;
/* obtain and unencode the data */
purple_mime_part_get_data_decoded(part, &d_dat, &d_len);
@@ -2758,22 +2756,11 @@ static void im_recv_mime(struct mwConver
cid = make_cid(cid);
/* add image to the purple image store */
- /* 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. */
- img = purple_imgstore_new_with_id(d_dat, d_len, cid);
+ image = purple_image_new_from_data(d_dat, d_len);
+ purple_image_set_friendly_filename(image, cid);
/* map the cid to the image store identifier */
- g_hash_table_insert(img_by_cid, cid, GINT_TO_POINTER(img));
-
- /* recall the image for dereferencing later */
- images = g_list_append(images, GINT_TO_POINTER(img));
-
+ g_hash_table_insert(img_by_cid, cid, image);
} else if(purple_str_has_prefix(type, "text")) {
/* concatenate all the text parts together */
@@ -2819,7 +2806,8 @@ static void im_recv_mime(struct mwConver
if(align) g_string_append_printf(atstr, " align=\"%s\"", align);
if(border) g_string_append_printf(atstr, " border=\"%s\"", border);
- mov = g_snprintf(start, len, "<img%s src=\"" PURPLE_STORED_IMAGE_PROTOCOL "%i\"", atstr->str, img);
+ mov = g_snprintf(start, len, "<img src=\"" PURPLE_IMAGE_STORE_PROTOCOL
+ "%u\"%s", img, atstr->str);
while(mov < len) start[mov++] = ' ';
g_string_free(atstr, TRUE);
@@ -2836,12 +2824,6 @@ static void im_recv_mime(struct mwConver
/* clean up the cid table */
g_hash_table_destroy(img_by_cid);
-
- /* dereference all the imgages */
- while(images) {
- purple_imgstore_unref_by_id(GPOINTER_TO_INT(images->data));
- images = g_list_delete_link(images, images);
- }
}
@@ -3798,40 +3780,26 @@ static char *im_mime_content_type(void)
mw_rand() & 0xfff, mw_rand() & 0xffff);
}
-
-/** determine content type from extension. Not so happy about this,
- but I don't want to actually write image type detection */
-static char *im_mime_img_content_type(PurpleStoredImage *img) {
- const char *fn = purple_imgstore_get_filename(img);
- const char *ct = NULL;
-
- ct = strrchr(fn, '.');
- if(! ct) {
- ct = "image";
-
- } else if(! strcmp(".png", ct)) {
- ct = "image/png";
-
- } else if(! strcmp(".jpg", ct)) {
- ct = "image/jpeg";
-
- } else if(! strcmp(".jpeg", ct)) {
- ct = "image/jpeg";
-
- } else if(! strcmp(".gif", ct)) {
- ct = "image/gif";
-
- } else {
- ct = "image";
- }
-
- return g_strdup_printf("%s; name=\"%s\"", ct, fn);
-}
-
-
-static char *im_mime_img_content_disp(PurpleStoredImage *img) {
- const char *fn = purple_imgstore_get_filename(img);
- return g_strdup_printf("attachment; filename=\"%s\"", fn);
+/** determine content type from contents */
+static gchar *
+im_mime_img_content_type(PurpleImage *img)
+{
+ const gchar *mimetype;
+
+ mimetype = purple_image_get_mimetype(img);
+
+ if (!mimetype)
+ mimetype = "image";
+
+ return g_strdup_printf("%s; name=\"%s\"", mimetype,
+ purple_image_get_friendly_filename(img));
+}
+
+
+static char *
+im_mime_img_content_disp(PurpleImage *img) {
+ return g_strdup_printf("attachment; filename=\"%s\"",
+ purple_image_get_friendly_filename(img));
}
@@ -3860,23 +3828,22 @@ static char *im_mime_convert(PurpleConne
tmp = (char *) message;
while(*tmp && purple_markup_find_tag("img", tmp, (const char **) &start,
(const char **) &end, &attr)) {
- char *id;
- PurpleStoredImage *img = NULL;
+ gchar *uri;
+ PurpleImage *img = NULL;
gsize len = (start - tmp);
/* append the in-between-tags text */
if(len) g_string_append_len(str, tmp, len);
- /* find the imgstore data by the id tag */
- id = g_datalist_get_data(&attr, "id");
- if(id && *id)
- img = purple_imgstore_find_by_id(atoi(id));
+ uri = g_datalist_get_data(&attr, "src");
+ if (uri)
+ img = purple_image_store_get_from_uri(uri);
if(img) {
char *cid;
gpointer data;
- size_t size;
+ gsize size;
part = purple_mime_part_new(doc);
@@ -3897,8 +3864,8 @@ static char *im_mime_convert(PurpleConne
/* obtain and base64 encode the image data, and put it in the
mime part */
- size = purple_imgstore_get_size(img);
- data = purple_base64_encode(purple_imgstore_get_data(img), (gsize) size);
+ size = purple_image_get_size(img);
+ data = purple_base64_encode(purple_image_get_data(img), size);
purple_mime_part_set_data(part, data);
g_free(data);
@@ -3908,7 +3875,7 @@ static char *im_mime_convert(PurpleConne
} else {
/* append the literal image tag, since we couldn't find a
- relative imgstore object */
+ relative PurpleImage object */
gsize len = (end - start) + 1;
g_string_append_len(str, start, len);
}
More information about the Commits
mailing list