diff options
author | Tomasz Wasilczyk <twasilczyk@pidgin.im> | 2014-04-10 23:09:48 +0200 |
---|---|---|
committer | Tomasz Wasilczyk <twasilczyk@pidgin.im> | 2014-04-10 23:09:48 +0200 |
commit | dc8f2be3591fa410d7aa8407aa6d24389252c2be (patch) | |
tree | 4307d7816926dbb59afbf0de6e63b3e3dafb3eac | |
parent | 7c72eff0f2c52ee17e9d34bde5631eac925987a0 (diff) | |
download | pidgin-dc8f2be3591fa410d7aa8407aa6d24389252c2be.tar.gz |
Imgstore vs PurpleImage: rip and fix
26 files changed, 109 insertions, 80 deletions
diff --git a/libpurple/plugins/perl/perl-common.c b/libpurple/plugins/perl/perl-common.c index 08769c0adb..50fdf255e9 100644 --- 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 type, void *arg) 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 index fb09e0a4b2..b6c86af2be 100644 --- a/libpurple/protocols/bonjour/bonjour.c +++ b/libpurple/protocols/bonjour/bonjour.c @@ -326,8 +326,8 @@ bonjour_convo_closed(PurpleConnection *connection, const char *who) 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 index 93cdb49083..35c81a85e1 100644 --- 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 index 5777ff1f3c..3e88354ed7 100644 --- 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 index d96b16cbad..bcc7c71ff0 100644 --- 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 index 615b6ad2b4..785d33e9c4 100644 --- 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 index ea74414ffb..f70b4407cb 100644 --- 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 index b211387d12..1d8f9c2170 100644 --- 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 index ddf57bf6d8..7310033b75 100644 --- 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 index 68fb9b5b1f..dc1d33aa25 100644 --- 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 index 91bb05884e..8784149ab8 100644 --- 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(PurpleStoredImage *img) ******************************************************************************/ 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(PurpleStoredImage *img, const gchar *shortcut) 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(PurpleStoredImage *img, const gchar *shortcut) } 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); - 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) { + file_path = g_build_filename(smileys_dir, file_name, NULL); + + 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 index d35647bbda..7c2183ed34 100644 --- 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 index 7389b5a56e..8b60346033 100644 --- 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(PurpleRemoteSmiley *smiley) 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(PurpleRemoteSmiley *smiley) 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 *obj) 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 index 78cf542cc5..0280c349fc 100644 --- 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 index 1a57d23c1c..7571d4c8aa 100644 --- 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 *smiley) 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(PurpleSmiley *smiley) 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 "); return NULL; @@ -131,7 +130,7 @@ purple_smiley_get_image_impl(PurpleSmiley *smiley) return priv->image; } -PurpleStoredImage * +PurpleImage * purple_smiley_get_image(PurpleSmiley *smiley) { PurpleSmileyClass *klass; @@ -166,7 +165,7 @@ purple_smiley_finalize(GObject *obj) g_free(priv->path); if (priv->image) - purple_imgstore_unref(priv->image); + g_object_unref(priv->image); PURPLE_DBUS_UNREGISTER_POINTER(smiley); diff --git a/libpurple/smiley.h b/libpurple/smiley.h index cae47da25f..210fe8bcb4 100644 --- a/libpurple/smiley.h +++ b/libpurple/smiley.h @@ -37,7 +37,7 @@ * may deal with special characters. */ -#include "imgstore.h" +#include "image.h" #include <glib-object.h> @@ -75,7 +75,7 @@ struct _PurpleSmileyClass GObjectClass parent_class; /*< public >*/ - PurpleStoredImage * (*get_image)(PurpleSmiley *smiley); + PurpleImage * (*get_image)(PurpleSmiley *smiley); /*< private >*/ void (*purple_reserved1)(void); @@ -159,7 +159,7 @@ purple_smiley_get_path(PurpleSmiley *smiley); * * Returns: (transfer none): the image contents for a @smiley. */ -PurpleStoredImage * +PurpleImage * purple_smiley_get_image(PurpleSmiley *smiley); G_END_DECLS diff --git a/libpurple/xfer.c b/libpurple/xfer.c index 1722cd03bd..cb780999d1 100644 --- a/libpurple/xfer.c +++ b/libpurple/xfer.c @@ -32,6 +32,7 @@ #include "request.h" #include "util.h" #include "debug.h" +#include "imgstore.h" /* TODO: temp */ #define FT_INITIAL_BUFFER_SIZE 4096 #define FT_MAX_BUFFER_SIZE 65535 diff --git a/pidgin/gtkconv.c b/pidgin/gtkconv.c index e7124d2839..adb6a38092 100644 --- a/pidgin/gtkconv.c +++ b/pidgin/gtkconv.c @@ -4155,7 +4155,7 @@ generate_send_to_items(PidginConvWindow *win) update_send_to_selection(win); } -PurpleStoredImage * +PurpleImage * _pidgin_e2ee_stock_icon_get(const gchar *stock_name) { gchar filename[100], *path; @@ -4171,7 +4171,7 @@ _pidgin_e2ee_stock_icon_get(const gchar *stock_name) g_snprintf(filename, sizeof(filename), "%s.png", stock_name); path = g_build_filename(DATADIR, "pixmaps", "pidgin", "e2ee", "16", filename, NULL); - image = purple_imgstore_new_from_file(path); + image = purple_image_new_from_file(path, FALSE); g_free(path); g_hash_table_insert(e2ee_stock, g_strdup(stock_name), image); diff --git a/pidgin/gtkinternal.h b/pidgin/gtkinternal.h index d11c547282..75035f28bd 100644 --- a/pidgin/gtkinternal.h +++ b/pidgin/gtkinternal.h @@ -33,7 +33,7 @@ G_BEGIN_DECLS static inline void _pidgin_widget_set_accessible_name(GtkWidget *widget, const gchar *name); -PurpleStoredImage * +PurpleImage * _pidgin_e2ee_stock_icon_get(const gchar *stock_name); G_END_DECLS diff --git a/pidgin/gtksmiley-manager.c b/pidgin/gtksmiley-manager.c index 8f01f25655..fc4e8e5faa 100644 --- a/pidgin/gtksmiley-manager.c +++ b/pidgin/gtksmiley-manager.c @@ -40,7 +40,7 @@ typedef struct PurpleSmiley *smiley; gchar *filename; - PurpleStoredImage *new_image; + PurpleImage *new_image; GtkDialog *window; GtkImage *thumbnail; @@ -88,7 +88,7 @@ edit_dialog_image_update_thumb(SmileyEditDialog *edit_dialog) GdkPixbuf *pixbuf = NULL; if (edit_dialog->new_image) { - pixbuf = pidgin_pixbuf_from_imgstore(edit_dialog->new_image); + pixbuf = pidgin_pixbuf_from_image(edit_dialog->new_image); } else if (edit_dialog->filename) { pixbuf = pidgin_pixbuf_new_from_file(edit_dialog->filename); if (!pixbuf) { @@ -117,13 +117,12 @@ edit_dialog_image_update_thumb(SmileyEditDialog *edit_dialog) } static gboolean -edit_dialog_set_image(SmileyEditDialog *edit_dialog, - PurpleStoredImage *image) +edit_dialog_set_image(SmileyEditDialog *edit_dialog, PurpleImage *image) { GdkPixbuf *tmp = NULL; if (edit_dialog->new_image) - purple_imgstore_unref(edit_dialog->new_image); + g_object_unref(edit_dialog->new_image); if (edit_dialog->smiley) { g_object_set_data(G_OBJECT(edit_dialog->smiley), @@ -132,11 +131,11 @@ edit_dialog_set_image(SmileyEditDialog *edit_dialog, /* check, if image is valid */ if (image) - tmp = pidgin_pixbuf_from_imgstore(image); + tmp = pidgin_pixbuf_from_image(image); if (tmp) g_object_unref(tmp); else { - purple_imgstore_unref(image); + g_object_unref(image); image = NULL; } @@ -158,13 +157,13 @@ edit_dialog_set_shortcut(SmileyEditDialog *edit_dialog, static void edit_dialog_image_choosen(const char *filename, gpointer _edit_dialog) { - PurpleStoredImage *image; + PurpleImage *image; SmileyEditDialog *edit_dialog = _edit_dialog; if (!filename) return; - image = purple_imgstore_new_from_file(filename); + image = purple_image_new_from_file(filename, TRUE); if (!image) return; @@ -207,7 +206,8 @@ edit_dialog_destroy(GtkWidget *window, gpointer _edit_dialog) g_object_unref(edit_dialog->smiley); } - purple_imgstore_unref(edit_dialog->new_image); + if (edit_dialog->new_image) + g_object_unref(edit_dialog->new_image); g_free(edit_dialog->filename); g_free(edit_dialog); @@ -251,8 +251,8 @@ edit_dialog_save(SmileyEditDialog *edit_dialog) if (edit_dialog->new_image == NULL) { /* We're reading the file and then writing it back - it's not * efficient, but it's also not really important here. */ - edit_dialog->new_image = purple_imgstore_new_from_file( - purple_smiley_get_path(edit_dialog->smiley)); + edit_dialog->new_image = purple_image_new_from_file( + purple_smiley_get_path(edit_dialog->smiley), TRUE); g_return_if_fail(edit_dialog->new_image); } @@ -453,13 +453,13 @@ edit_dialog_show(SmileyManager *manager, PurpleSmiley *smiley) } void -pidgin_smiley_manager_add(PurpleStoredImage *image, const gchar *shortcut) +pidgin_smiley_manager_add(PurpleImage *image, const gchar *shortcut) { SmileyEditDialog *edit_dialog; g_return_if_fail(image != NULL); - purple_imgstore_ref(image); + g_object_ref(image); edit_dialog = edit_dialog_show(NULL, NULL); edit_dialog_set_shortcut(edit_dialog, shortcut); @@ -478,7 +478,7 @@ smiley_list_dnd_url_got(PurpleHttpConnection *http_conn, { SmileyManager *manager = _manager; SmileyEditDialog *edit_dialog; - PurpleStoredImage *image; + PurpleImage *image; const gchar *image_data; size_t image_size; @@ -490,8 +490,8 @@ smiley_list_dnd_url_got(PurpleHttpConnection *http_conn, return; image_data = purple_http_response_get_data(response, &image_size); - image = purple_imgstore_new(g_memdup(image_data, image_size), - image_size, NULL); + image = purple_image_new_from_data(g_memdup(image_data, image_size), + image_size); if (!image) return; @@ -532,7 +532,7 @@ smiley_list_dnd_recv(GtkWidget *widget, GdkDragContext *dc, gint x, gint y, if (purple_str_has_caseprefix(content, "file://")) { SmileyEditDialog *edit_dialog; - PurpleStoredImage *image; + PurpleImage *image; gchar *filename; filename = g_filename_from_uri(content, NULL, NULL); @@ -543,7 +543,7 @@ smiley_list_dnd_recv(GtkWidget *widget, GdkDragContext *dc, gint x, gint y, return; } - image = purple_imgstore_new_from_file(filename); + image = purple_image_new_from_file(filename, TRUE); if (!image) { purple_debug_warning("gtksmiley-manager", "dropped file is not a valid image"); diff --git a/pidgin/gtksmiley-manager.h b/pidgin/gtksmiley-manager.h index 4c296d4d31..1e0507b6fc 100644 --- a/pidgin/gtksmiley-manager.h +++ b/pidgin/gtksmiley-manager.h @@ -53,7 +53,7 @@ pidgin_smiley_manager_show(void); * provided image. */ void -pidgin_smiley_manager_add(PurpleStoredImage *image, const gchar *shortcut); +pidgin_smiley_manager_add(PurpleImage *image, const gchar *shortcut); G_END_DECLS diff --git a/pidgin/gtkutils.c b/pidgin/gtkutils.c index 7769f2cadd..3c8ff61927 100644 --- a/pidgin/gtkutils.c +++ b/pidgin/gtkutils.c @@ -1412,9 +1412,10 @@ static void dnd_image_ok_callback(_DndData *data, int choice) GError *err = NULL; PurpleConversation *conv; PidginConversation *gtkconv; - int id; PurpleBuddy *buddy; PurpleContact *contact; + PurpleImage *img; + switch (choice) { case DND_BUDDY_ICON: if (g_stat(data->filename, &st)) { @@ -1459,10 +1460,10 @@ static void dnd_image_ok_callback(_DndData *data, int choice) } shortname = strrchr(data->filename, G_DIR_SEPARATOR); shortname = shortname ? shortname + 1 : data->filename; - id = purple_imgstore_new_with_id(filedata, size, shortname); + img = purple_image_new_from_data(filedata, size); - pidgin_webview_insert_image(PIDGIN_WEBVIEW(gtkconv->entry), id); - purple_imgstore_unref_by_id(id); + pidgin_webview_insert_image(PIDGIN_WEBVIEW(gtkconv->entry), img); + g_object_unref(img); break; } @@ -3099,10 +3100,16 @@ GdkPixbufAnimation *pidgin_pixbuf_anim_from_data(const guchar *buf, gsize count) return GDK_PIXBUF_ANIMATION(pidgin_pixbuf_from_data_helper(buf, count, TRUE)); } -GdkPixbuf *pidgin_pixbuf_from_imgstore(PurpleStoredImage *image) +GdkPixbuf *pidgin_pixbuf_from_imgstore(PurpleImage *image) +{ + return pidgin_pixbuf_from_image(image); /* TODO: remove it */ +} + +GdkPixbuf * +pidgin_pixbuf_from_image(PurpleImage *image) { - return pidgin_pixbuf_from_data(purple_imgstore_get_data(image), - purple_imgstore_get_size(image)); + return pidgin_pixbuf_from_data(purple_image_get_data(image), + purple_image_get_size(image)); } GdkPixbuf *pidgin_pixbuf_new_from_file(const gchar *filename) diff --git a/pidgin/gtkutils.h b/pidgin/gtkutils.h index 7e04300c5a..e68b1acdf0 100644 --- a/pidgin/gtkutils.h +++ b/pidgin/gtkutils.h @@ -859,13 +859,21 @@ GdkPixbufAnimation *pidgin_pixbuf_anim_from_data(const guchar *buf, gsize count) /** * pidgin_pixbuf_from_imgstore: - * @image: A PurpleStoredImage. * - * Create a GdkPixbuf from a PurpleStoredImage. + * TODO: remove it! + */ +GdkPixbuf *pidgin_pixbuf_from_imgstore(PurpleImage *image); + +/** + * pidgin_pixbuf_from_image: + * @image: a PurpleImage. * - * Returns: A GdkPixbuf created from the stored image. + * Create a GdkPixbuf from a PurpleImage. + * + * Returns: a GdkPixbuf created from the @image. */ -GdkPixbuf *pidgin_pixbuf_from_imgstore(PurpleStoredImage *image); +GdkPixbuf * +pidgin_pixbuf_from_image(PurpleImage *image); /** * pidgin_pixbuf_new_from_file: diff --git a/pidgin/gtkwebview.c b/pidgin/gtkwebview.c index 47e8dc5f0e..0f03066f1b 100644 --- a/pidgin/gtkwebview.c +++ b/pidgin/gtkwebview.c @@ -36,6 +36,8 @@ #include "gtkinternal.h" #include "gtk3compat.h" +#include "imgstore.h" /* TODO: temp */ + #define MAX_FONT_SIZE 7 #define MAX_SCROLL_TIME 0.4 /* seconds */ #define SCROLL_DELAY 33 /* milliseconds */ @@ -2055,18 +2057,20 @@ pidgin_webview_insert_link(PidginWebView *webview, const char *url, const char * } void -pidgin_webview_insert_image(PidginWebView *webview, int id) +pidgin_webview_insert_image(PidginWebView *webview, PurpleImage *image) { PidginWebViewPriv *priv; WebKitDOMDocument *dom; char *img; + guint id; g_return_if_fail(webview != NULL); + id = purple_image_store_add(image); priv = PIDGIN_WEBVIEW_GET_PRIVATE(webview); dom = webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(webview)); - img = g_strdup_printf("<img src='" PURPLE_STORED_IMAGE_PROTOCOL "%d'/>", - id); + img = g_strdup_printf("<img src='" PURPLE_STORED_IMAGE_PROTOCOL + "%u'/>", id); priv->edit.block_changed = TRUE; webkit_dom_document_exec_command(dom, "insertHTML", FALSE, img); diff --git a/pidgin/gtkwebview.h b/pidgin/gtkwebview.h index 0e85eb581c..583da102be 100644 --- a/pidgin/gtkwebview.h +++ b/pidgin/gtkwebview.h @@ -576,12 +576,13 @@ void pidgin_webview_insert_link(PidginWebView *webview, const char *url, const c /** * pidgin_webview_insert_image: - * @webview: The PidginWebView - * @id: The PurpleStoredImage id + * @webview: the PidginWebView. + * @image: the PurpleImage. * * Inserts an image at the current location or selection in a PidginWebView. */ -void pidgin_webview_insert_image(PidginWebView *webview, int id); +void +pidgin_webview_insert_image(PidginWebView *webview, PurpleImage *image); /** * pidgin_webview_get_protocol_name: diff --git a/pidgin/gtkwebviewtoolbar.c b/pidgin/gtkwebviewtoolbar.c index b126d6a9bd..1482aecb54 100644 --- a/pidgin/gtkwebviewtoolbar.c +++ b/pidgin/gtkwebviewtoolbar.c @@ -612,7 +612,7 @@ do_insert_image_cb(GtkWidget *widget, int response, PidginWebViewToolbar *toolba char *filedata; size_t size; GError *error = NULL; - int id; + PurpleImage *img; if (response == GTK_RESPONSE_ACCEPT) filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(widget)); @@ -634,9 +634,9 @@ do_insert_image_cb(GtkWidget *widget, int response, PidginWebViewToolbar *toolba name = strrchr(filename, G_DIR_SEPARATOR) + 1; - id = purple_imgstore_new_with_id(filedata, size, name); + img = purple_image_new_from_data(filedata, size); - if (id == 0) { + if (!img) { buf = g_strdup_printf(_("Failed to store image: %s\n"), filename); purple_notify_error(NULL, NULL, buf, NULL, NULL); @@ -648,9 +648,9 @@ do_insert_image_cb(GtkWidget *widget, int response, PidginWebViewToolbar *toolba g_free(filename); - pidgin_webview_insert_image(PIDGIN_WEBVIEW(toolbar->webview), id); + pidgin_webview_insert_image(PIDGIN_WEBVIEW(toolbar->webview), img); /* TODO: do it after passing an image to prpl, not before - * purple_imgstore_unref_by_id(id); + * g_object_unref(img); */ } |