Thu, 10 Apr 2014 23:09:48 +0200
Imgstore vs PurpleImage: rip and fix
--- a/libpurple/plugins/perl/perl-common.c Thu Apr 10 22:28:31 2014 +0200 +++ b/libpurple/plugins/perl/perl-common.c Thu Apr 10 23:09:48 2014 +0200 @@ -436,8 +436,6 @@ 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
--- a/libpurple/protocols/bonjour/bonjour.c Thu Apr 10 22:28:31 2014 +0200 +++ b/libpurple/protocols/bonjour/bonjour.c Thu Apr 10 23:09:48 2014 +0200 @@ -326,8 +326,8 @@ 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);
--- a/libpurple/protocols/bonjour/bonjour.h Thu Apr 10 22:28:31 2014 +0200 +++ b/libpurple/protocols/bonjour/bonjour.h Thu Apr 10 23:09:48 2014 +0200 @@ -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"
--- a/libpurple/protocols/gg/avatar.h Thu Apr 10 22:28:31 2014 +0200 +++ b/libpurple/protocols/gg/avatar.h Thu Apr 10 23:09:48 2014 +0200 @@ -33,6 +33,8 @@ #include <internal.h> #include <libgadu.h> +#include "imgstore.h" /* TODO: temp */ + typedef struct { guint timer;
--- a/libpurple/protocols/jabber/jabber.h Thu Apr 10 22:28:31 2014 +0200 +++ b/libpurple/protocols/jabber/jabber.h Thu Apr 10 23:09:48 2014 +0200 @@ -54,6 +54,8 @@ typedef struct _JabberStream JabberStream; +#include "imgstore.h" /* TODO: temp */ + #include <libxml/parser.h> #include <glib.h> #include "circularbuffer.h"
--- a/libpurple/protocols/mxit/mxit.h Thu Apr 10 22:28:31 2014 +0200 +++ b/libpurple/protocols/mxit/mxit.h Thu Apr 10 23:09:48 2014 +0200 @@ -30,6 +30,7 @@ #include "internal.h" #include "http.h" +#include "imgstore.h" /* TODO: temp */ #if defined( __APPLE__ ) /* apple architecture */
--- a/libpurple/protocols/oscar/oscar.h Thu Apr 10 22:28:31 2014 +0200 +++ b/libpurple/protocols/oscar/oscar.h Thu Apr 10 23:09:48 2014 +0200 @@ -37,6 +37,8 @@ #include "proxy.h" #include "sslconn.h" +#include "imgstore.h" /* TODO: temp */ + #include <stdio.h> #include <string.h> #include <fcntl.h>
--- a/libpurple/protocols/oscar/oscarcommon.h Thu Apr 10 22:28:31 2014 +0200 +++ b/libpurple/protocols/oscar/oscarcommon.h Thu Apr 10 23:09:48 2014 +0200 @@ -26,6 +26,8 @@ #include "internal.h" +#include "imgstore.h" /* TODO: temp */ + #include "accountopt.h" #include "prpl.h" #include "version.h"
--- a/libpurple/protocols/silc/silcpurple.h Thu Apr 10 22:28:31 2014 +0200 +++ b/libpurple/protocols/silc/silcpurple.h Thu Apr 10 23:09:48 2014 +0200 @@ -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))
--- a/libpurple/protocols/yahoo/libymsg.h Thu Apr 10 22:28:31 2014 +0200 +++ b/libpurple/protocols/yahoo/libymsg.h Thu Apr 10 23:09:48 2014 +0200 @@ -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
--- a/libpurple/smiley-custom.c Thu Apr 10 22:28:31 2014 +0200 +++ b/libpurple/smiley-custom.c Thu Apr 10 23:09:48 2014 +0200 @@ -160,13 +160,13 @@ } 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 @@ ******************************************************************************/ 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 @@ 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 @@ } 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);
--- a/libpurple/smiley-custom.h Thu Apr 10 22:28:31 2014 +0200 +++ b/libpurple/smiley-custom.h Thu Apr 10 23:09:48 2014 +0200 @@ -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:
--- a/libpurple/smiley-remote.c Thu Apr 10 22:28:31 2014 +0200 +++ b/libpurple/smiley-remote.c Thu Apr 10 23:09:48 2014 +0200 @@ -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 @@ 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 @@ 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 @@ 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); }
--- a/libpurple/smiley-remote.h Thu Apr 10 22:28:31 2014 +0200 +++ b/libpurple/smiley-remote.h Thu Apr 10 23:09:48 2014 +0200 @@ -40,7 +40,6 @@ #include <glib-object.h> -#include "imgstore.h" #include "util.h" typedef struct _PurpleRemoteSmiley PurpleRemoteSmiley;
--- a/libpurple/smiley.c Thu Apr 10 22:28:31 2014 +0200 +++ b/libpurple/smiley.c Thu Apr 10 23:09:48 2014 +0200 @@ -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 @@ 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 @@ 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 @@ return priv->image; } -PurpleStoredImage * +PurpleImage * purple_smiley_get_image(PurpleSmiley *smiley) { PurpleSmileyClass *klass; @@ -166,7 +165,7 @@ g_free(priv->path); if (priv->image) - purple_imgstore_unref(priv->image); + g_object_unref(priv->image); PURPLE_DBUS_UNREGISTER_POINTER(smiley);
--- a/libpurple/smiley.h Thu Apr 10 22:28:31 2014 +0200 +++ b/libpurple/smiley.h Thu Apr 10 23:09:48 2014 +0200 @@ -37,7 +37,7 @@ * may deal with special characters. */ -#include "imgstore.h" +#include "image.h" #include <glib-object.h> @@ -75,7 +75,7 @@ GObjectClass parent_class; /*< public >*/ - PurpleStoredImage * (*get_image)(PurpleSmiley *smiley); + PurpleImage * (*get_image)(PurpleSmiley *smiley); /*< private >*/ void (*purple_reserved1)(void); @@ -159,7 +159,7 @@ * * Returns: (transfer none): the image contents for a @smiley. */ -PurpleStoredImage * +PurpleImage * purple_smiley_get_image(PurpleSmiley *smiley); G_END_DECLS
--- a/libpurple/xfer.c Thu Apr 10 22:28:31 2014 +0200 +++ b/libpurple/xfer.c Thu Apr 10 23:09:48 2014 +0200 @@ -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
--- a/pidgin/gtkconv.c Thu Apr 10 22:28:31 2014 +0200 +++ b/pidgin/gtkconv.c Thu Apr 10 23:09:48 2014 +0200 @@ -4155,7 +4155,7 @@ update_send_to_selection(win); } -PurpleStoredImage * +PurpleImage * _pidgin_e2ee_stock_icon_get(const gchar *stock_name) { gchar filename[100], *path; @@ -4171,7 +4171,7 @@ 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);
--- a/pidgin/gtkinternal.h Thu Apr 10 22:28:31 2014 +0200 +++ b/pidgin/gtkinternal.h Thu Apr 10 23:09:48 2014 +0200 @@ -33,7 +33,7 @@ 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
--- a/pidgin/gtksmiley-manager.c Thu Apr 10 22:28:31 2014 +0200 +++ b/pidgin/gtksmiley-manager.c Thu Apr 10 23:09:48 2014 +0200 @@ -40,7 +40,7 @@ PurpleSmiley *smiley; gchar *filename; - PurpleStoredImage *new_image; + PurpleImage *new_image; GtkDialog *window; GtkImage *thumbnail; @@ -88,7 +88,7 @@ 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 @@ } 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 @@ /* 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 @@ 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 @@ 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 @@ 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 @@ } 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 @@ { SmileyManager *manager = _manager; SmileyEditDialog *edit_dialog; - PurpleStoredImage *image; + PurpleImage *image; const gchar *image_data; size_t image_size; @@ -490,8 +490,8 @@ 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 @@ 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 @@ 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");
--- a/pidgin/gtksmiley-manager.h Thu Apr 10 22:28:31 2014 +0200 +++ b/pidgin/gtksmiley-manager.h Thu Apr 10 23:09:48 2014 +0200 @@ -53,7 +53,7 @@ * provided image. */ void -pidgin_smiley_manager_add(PurpleStoredImage *image, const gchar *shortcut); +pidgin_smiley_manager_add(PurpleImage *image, const gchar *shortcut); G_END_DECLS
--- a/pidgin/gtkutils.c Thu Apr 10 22:28:31 2014 +0200 +++ b/pidgin/gtkutils.c Thu Apr 10 23:09:48 2014 +0200 @@ -1412,9 +1412,10 @@ 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 @@ } shortname = strrchr(data->filename, G_DIR_SEPARATOR); shortname = shortname ? shortname + 1 : data->filename; - id = purple_imgstore_new_with_id(filedata, size, shortname); - - pidgin_webview_insert_image(PIDGIN_WEBVIEW(gtkconv->entry), id); - purple_imgstore_unref_by_id(id); + img = purple_image_new_from_data(filedata, size); + + pidgin_webview_insert_image(PIDGIN_WEBVIEW(gtkconv->entry), img); + g_object_unref(img); break; } @@ -3099,10 +3100,16 @@ 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_data(purple_imgstore_get_data(image), - purple_imgstore_get_size(image)); + return pidgin_pixbuf_from_image(image); /* TODO: remove it */ +} + +GdkPixbuf * +pidgin_pixbuf_from_image(PurpleImage *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)
--- a/pidgin/gtkutils.h Thu Apr 10 22:28:31 2014 +0200 +++ b/pidgin/gtkutils.h Thu Apr 10 23:09:48 2014 +0200 @@ -859,13 +859,21 @@ /** * pidgin_pixbuf_from_imgstore: - * @image: A PurpleStoredImage. - * - * Create a GdkPixbuf from a PurpleStoredImage. * - * Returns: A GdkPixbuf created from the stored image. + * TODO: remove it! */ -GdkPixbuf *pidgin_pixbuf_from_imgstore(PurpleStoredImage *image); +GdkPixbuf *pidgin_pixbuf_from_imgstore(PurpleImage *image); + +/** + * pidgin_pixbuf_from_image: + * @image: a PurpleImage. + * + * Create a GdkPixbuf from a PurpleImage. + * + * Returns: a GdkPixbuf created from the @image. + */ +GdkPixbuf * +pidgin_pixbuf_from_image(PurpleImage *image); /** * pidgin_pixbuf_new_from_file:
--- a/pidgin/gtkwebview.c Thu Apr 10 22:28:31 2014 +0200 +++ b/pidgin/gtkwebview.c Thu Apr 10 23:09:48 2014 +0200 @@ -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 @@ } 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);
--- a/pidgin/gtkwebview.h Thu Apr 10 22:28:31 2014 +0200 +++ b/pidgin/gtkwebview.h Thu Apr 10 23:09:48 2014 +0200 @@ -576,12 +576,13 @@ /** * 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:
--- a/pidgin/gtkwebviewtoolbar.c Thu Apr 10 22:28:31 2014 +0200 +++ b/pidgin/gtkwebviewtoolbar.c Thu Apr 10 23:09:48 2014 +0200 @@ -612,7 +612,7 @@ 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 @@ 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 @@ 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); */ }