/pidgin/main: 8d99745b6214: imgstore: rip from Pidgin (mostly gt...
Tomasz Wasilczyk
twasilczyk at pidgin.im
Thu Apr 10 17:35:51 EDT 2014
Changeset: 8d99745b6214b924f0a45b8f71c628336949481c
Author: Tomasz Wasilczyk <twasilczyk at pidgin.im>
Date: 2014-04-10 23:35 +0200
Branch: default
URL: https://hg.pidgin.im/pidgin/main/rev/8d99745b6214
Description:
imgstore: rip from Pidgin (mostly gtkwebview)
diffstat:
pidgin/gtkaccount.c | 6 ++--
pidgin/gtkconv.c | 4 +-
pidgin/gtkrequest.c | 2 +-
pidgin/gtkutils.c | 5 ---
pidgin/gtkutils.h | 7 ----
pidgin/gtkwebview.c | 78 ++++++++++++++++++++++++----------------------------
6 files changed, 42 insertions(+), 60 deletions(-)
diffs (287 lines):
diff --git a/pidgin/gtkaccount.c b/pidgin/gtkaccount.c
--- a/pidgin/gtkaccount.c
+++ b/pidgin/gtkaccount.c
@@ -194,7 +194,7 @@ set_dialog_icon(AccountPrefsDialog *dial
}
if (dialog->icon_img != NULL) {
- pixbuf = pidgin_pixbuf_from_imgstore(dialog->icon_img);
+ pixbuf = pidgin_pixbuf_from_image(dialog->icon_img);
}
if (pixbuf && dialog->prpl_info &&
@@ -2290,8 +2290,8 @@ set_account(GtkListStore *store, GtkTree
if (img != NULL) {
GdkPixbuf *buddyicon_pixbuf;
- buddyicon_pixbuf = pidgin_pixbuf_from_imgstore(img);
- purple_imgstore_unref(img);
+ buddyicon_pixbuf = pidgin_pixbuf_from_image(img);
+ g_object_unref(img);
if (buddyicon_pixbuf != NULL) {
buddyicon = gdk_pixbuf_scale_simple(buddyicon_pixbuf, 22, 22, GDK_INTERP_HYPER);
diff --git a/pidgin/gtkconv.c b/pidgin/gtkconv.c
--- a/pidgin/gtkconv.c
+++ b/pidgin/gtkconv.c
@@ -3939,14 +3939,14 @@ send_to_item_leave_notify_cb(GtkWidget *
static GtkWidget *
e2ee_state_to_gtkimage(PurpleE2eeState *state)
{
- PurpleStoredImage *img;
+ PurpleImage *img;
img = _pidgin_e2ee_stock_icon_get(
purple_e2ee_state_get_stock_icon(state));
if (!img)
return NULL;
- return gtk_image_new_from_pixbuf(pidgin_pixbuf_from_imgstore(img));
+ return gtk_image_new_from_pixbuf(pidgin_pixbuf_from_image(img));
}
static void
diff --git a/pidgin/gtkrequest.c b/pidgin/gtkrequest.c
--- a/pidgin/gtkrequest.c
+++ b/pidgin/gtkrequest.c
@@ -1616,7 +1616,7 @@ static GdkPixbuf*
PIDGIN_PRPL_ICON_SMALL);
}
} else if (g_strcmp0(domain, "e2ee") == 0) {
- image = pidgin_pixbuf_from_imgstore(
+ image = pidgin_pixbuf_from_image(
_pidgin_e2ee_stock_icon_get(id));
} else {
purple_debug_error("gtkrequest", "Unknown domain: %s", domain);
diff --git a/pidgin/gtkutils.c b/pidgin/gtkutils.c
--- a/pidgin/gtkutils.c
+++ b/pidgin/gtkutils.c
@@ -3100,11 +3100,6 @@ GdkPixbufAnimation *pidgin_pixbuf_anim_f
return GDK_PIXBUF_ANIMATION(pidgin_pixbuf_from_data_helper(buf, count, TRUE));
}
-GdkPixbuf *pidgin_pixbuf_from_imgstore(PurpleImage *image)
-{
- return pidgin_pixbuf_from_image(image); /* TODO: remove it */
-}
-
GdkPixbuf *
pidgin_pixbuf_from_image(PurpleImage *image)
{
diff --git a/pidgin/gtkutils.h b/pidgin/gtkutils.h
--- a/pidgin/gtkutils.h
+++ b/pidgin/gtkutils.h
@@ -858,13 +858,6 @@ GdkPixbuf *pidgin_pixbuf_from_data(const
GdkPixbufAnimation *pidgin_pixbuf_anim_from_data(const guchar *buf, gsize count);
/**
- * pidgin_pixbuf_from_imgstore:
- *
- * TODO: remove it!
- */
-GdkPixbuf *pidgin_pixbuf_from_imgstore(PurpleImage *image);
-
-/**
* pidgin_pixbuf_from_image:
* @image: a PurpleImage.
*
diff --git a/pidgin/gtkwebview.c b/pidgin/gtkwebview.c
--- a/pidgin/gtkwebview.c
+++ b/pidgin/gtkwebview.c
@@ -23,6 +23,7 @@
#include "internal.h"
#include "debug.h"
#include "glibcompat.h"
+#include "image-store.h"
#include "pidgin.h"
#include "pidginstock.h"
@@ -36,8 +37,6 @@
#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 */
@@ -140,24 +139,24 @@ webview_resource_loading(WebKitWebView *
gpointer user_data)
{
const gchar *uri;
- PurpleStoredImage *img = NULL;
- const char *filename;
+ PurpleImage *img = NULL;
+ const gchar *path;
uri = webkit_network_request_get_uri(request);
- if (purple_str_has_prefix(uri, PURPLE_STORED_IMAGE_PROTOCOL)) {
- int id;
+ if (purple_str_has_prefix(uri, PURPLE_IMAGE_STORE_PROTOCOL)) {
+ guint id;
- uri += sizeof(PURPLE_STORED_IMAGE_PROTOCOL) - 1;
+ uri += sizeof(PURPLE_IMAGE_STORE_PROTOCOL) - 1;
id = strtoul(uri, NULL, 10);
- img = purple_imgstore_find_by_id(id);
+ img = purple_image_store_get(id);
if (!img)
return;
- } else if (purple_str_has_prefix(uri, PURPLE_STOCK_IMAGE_PROTOCOL)) {
+ } else if (purple_str_has_prefix(uri, PURPLE_IMAGE_STORE_STOCK_PROTOCOL)) {
gchar *p_uri, *found;
const gchar *domain, *stock_name;
- uri += sizeof(PURPLE_STOCK_IMAGE_PROTOCOL) - 1;
+ uri += sizeof(PURPLE_IMAGE_STORE_STOCK_PROTOCOL) - 1;
p_uri = g_strdup(uri);
found = strchr(p_uri, '/');
@@ -184,24 +183,23 @@ webview_resource_loading(WebKitWebView *
return;
if (img != NULL) {
- filename = purple_imgstore_get_filename(img);
- if (filename && g_path_is_absolute(filename)) {
- gchar *tmp = g_filename_to_uri(filename, NULL, NULL);
- webkit_network_request_set_uri(request, tmp);
- g_free(tmp);
+ path = purple_image_get_path(img);
+ if (path) {
+ gchar *uri = g_filename_to_uri(path, NULL, NULL);
+ webkit_network_request_set_uri(request, uri);
+ g_free(uri);
} else {
- gchar *b64, *tmp;
+ gchar *b64, *src;
const gchar *type;
b64 = purple_base64_encode(
- purple_imgstore_get_data(img),
- purple_imgstore_get_size(img));
- type = purple_imgstore_get_extension(img);
- tmp = g_strdup_printf("data:image/%s;base64,%s",
- type, b64);
- webkit_network_request_set_uri(request, tmp);
+ purple_image_get_data(img),
+ purple_image_get_size(img));
+ type = purple_image_get_mimetype(img);
+ src = g_strdup_printf("data:%s;base64,%s", type, b64);
g_free(b64);
- g_free(tmp);
+ webkit_network_request_set_uri(request, src);
+ g_free(src);
}
}
}
@@ -213,7 +211,7 @@ webview_resource_loaded(WebKitWebView *w
PidginWebViewPriv *priv = PIDGIN_WEBVIEW_GET_PRIVATE(web_view);
const gchar *uri;
GString *data;
- PurpleStoredImage *image;
+ PurpleImage *image;
if (!purple_str_has_caseprefix(
webkit_web_resource_get_mime_type(web_resource), "image/"))
@@ -230,15 +228,15 @@ webview_resource_loaded(WebKitWebView *w
return;
/* TODO: we could avoid copying data, if uri is a
- * PURPLE_STORED_IMAGE_PROTOCOL or PURPLE_STOCK_IMAGE_PROTOCOL */
- image = purple_imgstore_new(g_memdup(data->str, data->len),
- data->len, NULL);
+ * PURPLE_IMAGE_STORE_PROTOCOL */
+ image = purple_image_new_from_data(
+ g_memdup(data->str, data->len), data->len);
g_return_if_fail(image != NULL);
g_hash_table_insert(priv->loaded_images, g_strdup(uri), image);
}
-static PurpleStoredImage *
+static PurpleImage *
webview_resource_get_loaded(WebKitWebView *web_view, const gchar *uri)
{
PidginWebViewPriv *priv = PIDGIN_WEBVIEW_GET_PRIVATE(web_view);
@@ -570,9 +568,8 @@ get_unicode_menu(WebKitWebView *webview)
static void
webview_image_saved(GtkWidget *dialog, gint response, gpointer _unused)
{
- PurpleStoredImage *image;
+ PurpleImage *image;
gchar *filename;
- GError *error = NULL;
if (response != GTK_RESPONSE_ACCEPT) {
gtk_widget_destroy(dialog);
@@ -586,11 +583,8 @@ webview_image_saved(GtkWidget *dialog, g
g_return_if_fail(filename != NULL);
g_return_if_fail(filename[0] != '\0');
- g_file_set_contents(filename, purple_imgstore_get_data(image),
- purple_imgstore_get_size(image), &error);
- if (error) {
- purple_debug_error("gtkwebview", "Failed saving image: %s",
- error->message);
+ if (!purple_image_save(image, filename)) {
+ purple_debug_error("gtkwebview", "Failed saving image");
/* TODO: we should display a notification here */
}
@@ -603,7 +597,7 @@ webview_image_save(GtkWidget *item, WebK
{
const gchar *src;
WebKitWebView *webview;
- PurpleStoredImage *image;
+ PurpleImage *image;
GtkFileChooserDialog *dialog;
gchar *filename;
GtkWidget *parent;
@@ -628,16 +622,16 @@ webview_image_save(GtkWidget *item, WebK
/* TODO: use image's file name, if there is one */
filename = g_strdup_printf(_("image.%s"),
- purple_imgstore_get_extension(image));
+ purple_image_get_extension(image));
gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(dialog), filename);
g_free(filename);
g_signal_connect(G_OBJECT(dialog), "response",
G_CALLBACK(webview_image_saved), NULL);
- purple_imgstore_ref(image);
+ g_object_ref(image);
g_object_set_data_full(G_OBJECT(dialog), "pidgin-gtkwebview-image",
- image, (GDestroyNotify)purple_imgstore_unref);
+ image, g_object_unref);
gtk_widget_show(GTK_WIDGET(dialog));
}
@@ -647,7 +641,7 @@ webview_image_add_smiley(GtkWidget *item
{
const gchar *src;
WebKitWebView *webview;
- PurpleStoredImage *image;
+ PurpleImage *image;
src = webkit_dom_html_image_element_get_src(image_node);
webview = g_object_get_data(G_OBJECT(image_node), "pidgin-gtkwebview");
@@ -1307,7 +1301,7 @@ pidgin_webview_init(PidginWebView *webvi
G_CALLBACK(webview_inspector_show), webview);
priv->loaded_images = g_hash_table_new_full(g_str_hash, g_str_equal,
- g_free, (GDestroyNotify)purple_imgstore_unref);
+ g_free, g_object_unref);
}
GType
@@ -2069,7 +2063,7 @@ pidgin_webview_insert_image(PidginWebVie
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
+ img = g_strdup_printf("<img src='" PURPLE_IMAGE_STORE_PROTOCOL
"%u'/>", id);
priv->edit.block_changed = TRUE;
More information about the Commits
mailing list