/dev/twasilczyk/imgupload: 965aaea4a59b: Imgupload: use our own ...

Tomasz Wasilczyk twasilczyk at pidgin.im
Mon May 19 08:23:25 EDT 2014


Changeset: 965aaea4a59bb10cce8a7d13b8040a73b5271959
Author:	 Tomasz Wasilczyk <twasilczyk at pidgin.im>
Date:	 2014-05-19 14:23 +0200
Branch:	 default
URL: https://hg.pidgin.im/dev/twasilczyk/imgupload/rev/965aaea4a59b

Description:

Imgupload: use our own insert image callback for hooked conversations

diffstat:

 libpurple/marshallers.list |   1 +
 pidgin/gtkwebview.c        |  27 +++++++++++++++++++++++++++
 pidgin/gtkwebview.h        |   1 +
 pidgin/plugins/imgupload.c |  44 ++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 73 insertions(+), 0 deletions(-)

diffs (162 lines):

diff --git a/libpurple/marshallers.list b/libpurple/marshallers.list
--- a/libpurple/marshallers.list
+++ b/libpurple/marshallers.list
@@ -6,3 +6,4 @@ VOID:ENUM,STRING,STRING
 VOID:ENUM,STRING,STRING,BOOLEAN
 VOID:FLAGS,FLAGS
 VOID:STRING,STRING,OBJECT,OBJECT
+BOOLEAN:OBJECT
diff --git a/pidgin/gtkwebview.c b/pidgin/gtkwebview.c
--- a/pidgin/gtkwebview.c
+++ b/pidgin/gtkwebview.c
@@ -24,6 +24,7 @@
 #include "debug.h"
 #include "glibcompat.h"
 #include "image-store.h"
+#include "marshallers.h"
 #include "pidgin.h"
 #include "pidginstock.h"
 
@@ -60,6 +61,7 @@ enum {
 	UPDATE_FORMAT,
 	CHANGED,
 	HTML_APPENDED,
+	INSERT_IMAGE,
 	LAST_SIGNAL
 };
 static guint signals[LAST_SIGNAL] = { 0 };
@@ -1308,6 +1310,20 @@ fill_spellcheck_dicts(void)
 
 #endif
 
+static gboolean
+pidgin_webview_insert_image_accu(GSignalInvocationHint *ihint,
+	GValue *return_accu, const GValue *handler_return, gpointer _unused)
+{
+	gboolean cancel;
+
+	cancel = g_value_get_boolean(handler_return);
+	if (!cancel)
+		return FALSE;
+
+	g_value_set_boolean(return_accu, TRUE);
+	return TRUE;
+}
+
 static void
 pidgin_webview_class_init(PidginWebViewClass *klass, gpointer userdata)
 {
@@ -1359,6 +1375,12 @@ pidgin_webview_class_init(PidginWebViewC
 	                                      g_cclosure_marshal_VOID__OBJECT,
 	                                      G_TYPE_NONE, 1, WEBKIT_TYPE_DOM_RANGE,
 	                                      NULL);
+	signals[INSERT_IMAGE] = g_signal_new("insert-image",
+		G_TYPE_FROM_CLASS(gobject_class), G_SIGNAL_RUN_LAST,
+		G_STRUCT_OFFSET(PidginWebViewClass, insert_image),
+		pidgin_webview_insert_image_accu, NULL,
+		purple_smarshal_BOOLEAN__OBJECT, G_TYPE_BOOLEAN, 1,
+		PURPLE_TYPE_IMAGE);
 
 	/* Class Methods */
 
@@ -2217,9 +2239,14 @@ pidgin_webview_insert_image(PidginWebVie
 	WebKitDOMDocument *dom;
 	char *img;
 	guint id;
+	gboolean cancel;
 
 	g_return_if_fail(webview != NULL);
 
+	g_signal_emit(webview, signals[INSERT_IMAGE], 0, image, &cancel);
+	if (cancel)
+		return;
+
 	id = purple_image_store_add(image);
 	priv = PIDGIN_WEBVIEW_GET_PRIVATE(webview);
 	dom = webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(webview));
diff --git a/pidgin/gtkwebview.h b/pidgin/gtkwebview.h
--- a/pidgin/gtkwebview.h
+++ b/pidgin/gtkwebview.h
@@ -102,6 +102,7 @@ struct _PidginWebViewClass
 	void (*update_format)(PidginWebView *);
 	void (*changed)(PidginWebView *);
 	void (*html_appended)(PidginWebView *, WebKitDOMRange *);
+	gboolean (*insert_image)(PidginWebView *, PurpleImage *);
 };
 
 G_BEGIN_DECLS
diff --git a/pidgin/plugins/imgupload.c b/pidgin/plugins/imgupload.c
--- a/pidgin/plugins/imgupload.c
+++ b/pidgin/plugins/imgupload.c
@@ -47,6 +47,43 @@ imgup_conn_is_hooked(PurpleConnection *g
  * Plugin setup
  ******************************************************************************/
 
+static gboolean
+imgup_pidconv_insert_image(PidginWebView *webview, PurpleImage *image,
+	gpointer _gtkconv)
+{
+	PidginConversation *gtkconv = _gtkconv;
+	PurpleConversation *conv = gtkconv->active_conv;
+
+	if (!imgup_conn_is_hooked(purple_conversation_get_connection(conv)))
+		return FALSE;
+
+	purple_debug_fatal("imgupload", "not yet implemented");
+
+	return TRUE;
+}
+
+static void
+imgup_pidconv_init(PidginConversation *gtkconv)
+{
+	PidginWebView *webview;
+
+	webview = PIDGIN_WEBVIEW(gtkconv->entry);
+
+	g_signal_connect(G_OBJECT(webview), "insert-image",
+		G_CALLBACK(imgup_pidconv_insert_image), gtkconv);
+}
+
+static void
+imgup_pidconv_uninit(PidginConversation *gtkconv)
+{
+	PidginWebView *webview;
+
+	webview = PIDGIN_WEBVIEW(gtkconv->entry);
+
+	g_signal_handlers_disconnect_by_func(G_OBJECT(webview),
+		G_CALLBACK(imgup_pidconv_insert_image), gtkconv);
+}
+
 static void
 imgup_conv_init(PurpleConversation *conv)
 {
@@ -129,6 +166,8 @@ imgup_plugin_load(PurplePlugin *plugin)
 	for (; it; it = g_list_next(it)) {
 		PurpleConversation *conv = it->data;
 		imgup_conv_init(conv);
+		if (PIDGIN_IS_PIDGIN_CONVERSATION(conv))
+			imgup_pidconv_init(PIDGIN_CONVERSATION(conv));
 	}
 
 	purple_signal_connect(purple_connections_get_handle(),
@@ -137,6 +176,9 @@ imgup_plugin_load(PurplePlugin *plugin)
 	purple_signal_connect(purple_connections_get_handle(),
 		"signing-off", plugin,
 		PURPLE_CALLBACK(imgup_conn_uninit), NULL);
+	purple_signal_connect(pidgin_conversations_get_handle(),
+		"conversation-displayed", plugin,
+		PURPLE_CALLBACK(imgup_pidconv_init), NULL);
 
 	return TRUE;
 }
@@ -150,6 +192,8 @@ imgup_plugin_unload(PurplePlugin *plugin
 	for (; it; it = g_list_next(it)) {
 		PurpleConversation *conv = it->data;
 		imgup_conv_uninit(conv);
+		if (PIDGIN_IS_PIDGIN_CONVERSATION(conv))
+			imgup_pidconv_uninit(PIDGIN_CONVERSATION(conv));
 	}
 
 	it = purple_connections_get_all();



More information about the Commits mailing list