/dev/tomkiewicz/e2ee: 4825e8b34919: E2EE: implement PURPLE_STOCK...
Tomasz Wasilczyk
twasilczyk at pidgin.im
Mon Oct 7 08:00:32 EDT 2013
Changeset: 4825e8b34919f111e890c140cdb557cfb37098e7
Author: Tomasz Wasilczyk <twasilczyk at pidgin.im>
Date: 2013-10-07 14:00 +0200
Branch: default
URL: https://hg.pidgin.im/dev/tomkiewicz/e2ee/rev/4825e8b34919
Description:
E2EE: implement PURPLE_STOCK_IMAGE_PROTOCOL
diffstat:
libpurple/imgstore.h | 1 +
pidgin/gtkconv.c | 41 +++++++++++++++++++++++------------------
pidgin/gtkinternal.h | 36 ++++++++++++++++++++++++++++++++++++
pidgin/gtkwebview.c | 52 ++++++++++++++++++++++++++++++++++++++++++++--------
4 files changed, 104 insertions(+), 26 deletions(-)
diffs (238 lines):
diff --git a/libpurple/imgstore.h b/libpurple/imgstore.h
--- a/libpurple/imgstore.h
+++ b/libpurple/imgstore.h
@@ -31,6 +31,7 @@
#include <glib.h>
#define PURPLE_STORED_IMAGE_PROTOCOL "purple-image:"
+#define PURPLE_STOCK_IMAGE_PROTOCOL "purple-stock-image:"
/** A reference-counted immutable wrapper around an image's data and its
* filename.
diff --git a/pidgin/gtkconv.c b/pidgin/gtkconv.c
--- a/pidgin/gtkconv.c
+++ b/pidgin/gtkconv.c
@@ -50,6 +50,7 @@
#include "util.h"
#include "version.h"
+#include "gtkinternal.h"
#include "gtkdnd-hints.h"
#include "gtkblist.h"
#include "gtkconv.h"
@@ -218,7 +219,6 @@ static void focus_out_from_menubar(GtkWi
static void pidgin_conv_tab_pack(PidginWindow *win, PidginConversation *gtkconv);
static gboolean infopane_press_cb(GtkWidget *widget, GdkEventButton *e, PidginConversation *conv);
static void hide_conv(PidginConversation *gtkconv, gboolean closetimer);
-static GdkPixbuf * e2ee_stock_icon_get(const gchar *stock_name);
static void pidgin_conv_set_position_size(PidginWindow *win, int x, int y,
int width, int height);
@@ -3949,6 +3949,14 @@ send_to_item_leave_notify_cb(GtkWidget *
return FALSE;
}
+static GtkWidget *
+e2ee_state_to_gtkimage(PurpleE2eeState *state)
+{
+ return gtk_image_new_from_pixbuf(pidgin_pixbuf_from_imgstore(
+ _pidgin_e2ee_stock_icon_get(
+ purple_e2ee_state_get_stock_icon(state))));
+}
+
static void
create_sendto_item(GtkWidget *menu, GtkSizeGroup *sg, GSList **group,
PurpleBuddy *buddy, PurpleAccount *account, const char *name,
@@ -3982,11 +3990,9 @@ create_sendto_item(GtkWidget *menu, GtkS
PURPLE_CONV_TYPE_IM, buddy->name, buddy->account);
if (conv)
state = purple_conversation_get_e2ee_state(conv);
- if (state) {
- e2ee_image = gtk_image_new_from_pixbuf(
- e2ee_stock_icon_get(
- purple_e2ee_state_get_stock_icon(state)));
- } else
+ if (state)
+ e2ee_image = e2ee_state_to_gtkimage(state);
+ else
e2ee_image = gtk_image_new();
}
@@ -4157,23 +4163,23 @@ generate_send_to_items(PidginWindow *win
update_send_to_selection(win);
}
-static GdkPixbuf *
-e2ee_stock_icon_get(const gchar *stock_name)
+PurpleStoredImage *
+_pidgin_e2ee_stock_icon_get(const gchar *stock_name)
{
gchar filename[100], *path;
- GdkPixbuf *pixbuf;
-
- if (g_hash_table_lookup_extended(e2ee_stock, stock_name, NULL, (gpointer*)&pixbuf))
- return pixbuf;
+ PurpleStoredImage *image;
+
+ if (g_hash_table_lookup_extended(e2ee_stock, stock_name, NULL, (gpointer*)&image))
+ return image;
g_snprintf(filename, sizeof(filename), "%s.png", stock_name);
path = g_build_filename(DATADIR, "pixmaps", "pidgin", "e2ee", "16",
filename, NULL);
- pixbuf = pidgin_pixbuf_new_from_file(path);
+ image = purple_imgstore_new_from_file(path);
g_free(path);
- g_hash_table_insert(e2ee_stock, g_strdup(stock_name), pixbuf);
- return pixbuf;
+ g_hash_table_insert(e2ee_stock, g_strdup(stock_name), image);
+ return image;
}
static void
@@ -4214,8 +4220,7 @@ generate_e2ee_controls(PidginWindow *win
gtk_menu_item_set_submenu(GTK_MENU_ITEM(win->menu.e2ee), menu);
gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(win->menu.e2ee),
- gtk_image_new_from_pixbuf(e2ee_stock_icon_get(
- purple_e2ee_state_get_stock_icon(state))));
+ e2ee_state_to_gtkimage(state));
gtk_widget_set_tooltip_text(win->menu.e2ee,
purple_e2ee_state_get_name(state));
@@ -8674,7 +8679,7 @@ pidgin_conversations_init(void)
void *blist_handle = purple_blist_get_handle();
char *theme_dir;
- e2ee_stock = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_object_unref);
+ e2ee_stock = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, (GDestroyNotify)purple_imgstore_unref);
/* Conversations */
purple_prefs_add_none(PIDGIN_PREFS_ROOT "/conversations");
diff --git a/pidgin/gtkinternal.h b/pidgin/gtkinternal.h
new file mode 100644
--- /dev/null
+++ b/pidgin/gtkinternal.h
@@ -0,0 +1,36 @@
+/**
+ * @file gtkinternal.h Internal definitions and includes for Pidgin
+ * @ingroup pidgin
+ */
+
+/* pidgin
+ *
+ * Pidgin is the legal property of its developers, whose names are too numerous
+ * to list here. Please refer to the COPYRIGHT file distributed with this
+ * source distribution.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
+ */
+#ifndef _PIDGIN_INTERNAL_H_
+#define _PIDGIN_INTERNAL_H_
+
+G_BEGIN_DECLS
+
+PurpleStoredImage *
+_pidgin_e2ee_stock_icon_get(const gchar *stock_name);
+
+G_END_DECLS
+
+#endif /* _PIDGIN_INTERNAL_H_ */
diff --git a/pidgin/gtkwebview.c b/pidgin/gtkwebview.c
--- a/pidgin/gtkwebview.c
+++ b/pidgin/gtkwebview.c
@@ -34,6 +34,7 @@
#include "gtkwebview.h"
#include "gtkwebviewtoolbar.h"
+#include "gtkinternal.h"
#include "gtk3compat.h"
#define MAX_FONT_SIZE 7
@@ -687,12 +688,12 @@ webview_resource_loading(WebKitWebView *
gpointer user_data)
{
const gchar *uri;
+ PurpleStoredImage *img = NULL;
+ const char *filename;
uri = webkit_network_request_get_uri(request);
if (purple_str_has_prefix(uri, PURPLE_STORED_IMAGE_PROTOCOL)) {
int id;
- PurpleStoredImage *img;
- const char *filename;
uri += sizeof(PURPLE_STORED_IMAGE_PROTOCOL) - 1;
id = strtoul(uri, NULL, 10);
@@ -700,17 +701,52 @@ webview_resource_loading(WebKitWebView *
img = purple_imgstore_find_by_id(id);
if (!img)
return;
-
+ } else if (purple_str_has_prefix(uri, PURPLE_STOCK_IMAGE_PROTOCOL)) {
+ gchar *p_uri, *found;
+ const gchar *domain, *stock_name;
+
+ uri += sizeof(PURPLE_STOCK_IMAGE_PROTOCOL) - 1;
+
+ p_uri = g_strdup(uri);
+ found = strchr(p_uri, '/');
+ if (!found) {
+ purple_debug_warning("webview", "Invalid purple stock "
+ "image uri: %s", uri);
+ return;
+ }
+
+ found[0] = '\0';
+ domain = p_uri;
+ stock_name = found + 1;
+
+ if (g_strcmp0(domain, "e2ee") == 0) {
+ img = _pidgin_e2ee_stock_icon_get(stock_name);
+ if (!img)
+ return;
+ } else {
+ purple_debug_warning("webview", "Invalid purple stock "
+ "image domain: %s", domain);
+ return;
+ }
+ } else
+ return;
+
+ if (img != NULL) {
filename = purple_imgstore_get_filename(img);
if (filename && g_path_is_absolute(filename)) {
- char *tmp = g_strdup_printf("file://%s", filename);
+ gchar *tmp = g_strdup_printf("file://%s", filename);
webkit_network_request_set_uri(request, tmp);
g_free(tmp);
} else {
- char *b64 = purple_base64_encode(purple_imgstore_get_data(img),
- purple_imgstore_get_size(img));
- const char *type = purple_imgstore_get_extension(img);
- char *tmp = g_strdup_printf("data:image/%s;base64,%s", type, b64);
+ gchar *b64, *tmp;
+ 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);
g_free(b64);
g_free(tmp);
More information about the Commits
mailing list