pidgin/pidgin

Parents c568fcefdb82
Children 8b5b33f733d6
Imgupload: use our own insert image callback for hooked conversations
--- a/libpurple/marshallers.list Mon May 19 11:18:48 2014 +0200
+++ b/libpurple/marshallers.list Mon May 19 14:23:16 2014 +0200
@@ -6,3 +6,4 @@
VOID:ENUM,STRING,STRING,BOOLEAN
VOID:FLAGS,FLAGS
VOID:STRING,STRING,OBJECT,OBJECT
+BOOLEAN:OBJECT
--- a/pidgin/gtkwebview.c Mon May 19 11:18:48 2014 +0200
+++ b/pidgin/gtkwebview.c Mon May 19 14:23:16 2014 +0200
@@ -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 @@
UPDATE_FORMAT,
CHANGED,
HTML_APPENDED,
+ INSERT_IMAGE,
LAST_SIGNAL
};
static guint signals[LAST_SIGNAL] = { 0 };
@@ -1308,6 +1310,20 @@
#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 @@
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 @@
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));
--- a/pidgin/gtkwebview.h Mon May 19 11:18:48 2014 +0200
+++ b/pidgin/gtkwebview.h Mon May 19 14:23:16 2014 +0200
@@ -102,6 +102,7 @@
void (*update_format)(PidginWebView *);
void (*changed)(PidginWebView *);
void (*html_appended)(PidginWebView *, WebKitDOMRange *);
+ gboolean (*insert_image)(PidginWebView *, PurpleImage *);
};
G_BEGIN_DECLS
--- a/pidgin/plugins/imgupload.c Mon May 19 11:18:48 2014 +0200
+++ b/pidgin/plugins/imgupload.c Mon May 19 14:23:16 2014 +0200
@@ -47,6 +47,43 @@
* 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 @@
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 @@
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 @@
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();