pidgin: 36826042: Fixup Insert Image functionality.

qulogic at pidgin.im qulogic at pidgin.im
Tue Jun 5 03:33:46 EDT 2012


----------------------------------------------------------------------
Revision: 368260424b2dfd8d1fbdaea9a0c5d7b392d83514
Parent:   2df0f0e888994332d6cfa29ef7ed749b6a31c57d
Author:   qulogic at pidgin.im
Date:     06/05/12 02:17:48
Branch:   im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/368260424b2dfd8d1fbdaea9a0c5d7b392d83514

Changelog: 

Fixup Insert Image functionality.

Changes against parent 2df0f0e888994332d6cfa29ef7ed749b6a31c57d

  patched  pidgin/gtkwebview.c
  patched  pidgin/gtkwebview.h
  patched  pidgin/gtkwebviewtoolbar.c

-------------- next part --------------
============================================================
--- pidgin/gtkwebview.c	3ac28ffe548876e548fef2376510f7e2d6596723
+++ pidgin/gtkwebview.c	b0b223455d4bc90afbda18921ecd75bf7d4da610
@@ -1052,3 +1052,19 @@ gtk_webview_insert_link(GtkWebView *webv
 	g_free(link);
 }
 
+void
+gtk_webview_insert_image(GtkWebView *webview, int id)
+{
+	GtkWebViewPriv *priv = GTK_WEBVIEW_GET_PRIVATE(webview);
+	WebKitDOMDocument *dom;
+	char *img;
+
+	dom = webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(webview));
+	img = g_strdup_printf("<img src='%s'/>", get_image_src_from_id(priv, id));
+
+	priv->edit.block_changed = TRUE;
+	webkit_dom_document_exec_command(dom, "insertHTML", FALSE, img);
+	priv->edit.block_changed = FALSE;
+	g_free(img);
+}
+
============================================================
--- pidgin/gtkwebview.h	f846c6555ec930a3ba87a1f15ab90b0737371c65
+++ pidgin/gtkwebview.h	a45485c62f7361f6ba6ebc13fc399039536da7ed
@@ -429,6 +429,14 @@ void gtk_webview_insert_link(GtkWebView 
  */
 void gtk_webview_insert_link(GtkWebView *webview, const char *url, const char *desc);
 
+/**
+ * Inserts an image at the current location or selection in a GtkWebView.
+ *
+ * @param webview The GtkWebView
+ * @param id      The PurpleStoredImage id
+ */
+void gtk_webview_insert_image(GtkWebView *webview, int id);
+
 G_END_DECLS
 
 #endif /* _PIDGIN_WEBVIEW_H_ */
============================================================
--- pidgin/gtkwebviewtoolbar.c	e3bbb326145a4113151d356ccbfc933302521eb2
+++ pidgin/gtkwebviewtoolbar.c	b77c6c92b5d1abebcfc075c28863e6cb6a2d3dae
@@ -540,27 +540,22 @@ do_insert_image_cb(GtkWidget *widget, in
 static void
 do_insert_image_cb(GtkWidget *widget, int response, GtkWebViewToolbar *toolbar)
 {
-#if 0
 	GtkWebViewToolbarPriv *priv = GTK_WEBVIEWTOOLBAR_GET_PRIVATE(toolbar);
-	gchar *filename, *name, *buf;
+	gchar *filename = NULL, *name, *buf;
 	char *filedata;
 	size_t size;
 	GError *error = NULL;
 	int id;
-	GtkTextIter iter;
-	GtkTextMark *ins;
 
-	if (response != GTK_RESPONSE_ACCEPT)
-		return;
+	if (response == GTK_RESPONSE_ACCEPT)
+		filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(widget));
 
-	filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(widget));
+	/* The following triggers a callback that closes the widget */
+	gtk_action_activate(priv->image);
 
 	if (filename == NULL)
 		return;
 
-	/* The following triggers a callback that closes the widget */
-	gtk_action_activate(priv->image);
-
 	if (!g_file_get_contents(filename, &filedata, &size, &error)) {
 		purple_notify_error(NULL, NULL, error->message, NULL);
 
@@ -586,12 +581,8 @@ do_insert_image_cb(GtkWidget *widget, in
 
 	g_free(filename);
 
-	ins = gtk_text_buffer_get_insert(gtk_text_view_get_buffer(GTK_TEXT_VIEW(toolbar->webview)));
-	gtk_text_buffer_get_iter_at_mark(gtk_text_view_get_buffer(GTK_TEXT_VIEW(toolbar->webview)),
-									 &iter, ins);
-	gtk_webview_insert_image_at_iter(GTK_WEBVIEW(toolbar->webview), id, &iter);
+	gtk_webview_insert_image(GTK_WEBVIEW(toolbar->webview), id);
 	purple_imgstore_unref_by_id(id);
-#endif
 }
 
 static void
@@ -600,14 +591,14 @@ insert_image_cb(GtkAction *action, GtkWe
 	GtkWebViewToolbarPriv *priv = GTK_WEBVIEWTOOLBAR_GET_PRIVATE(toolbar);
 	GtkWidget *window;
 
-	if (priv->image_dialog) {
+	if (!priv->image_dialog) {
 		window = gtk_file_chooser_dialog_new(_("Insert Image"), NULL,
 		                                     GTK_FILE_CHOOSER_ACTION_OPEN,
 		                                     GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
 		                                     GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
 		                                     NULL);
 		gtk_dialog_set_default_response(GTK_DIALOG(window), GTK_RESPONSE_ACCEPT);
-		g_signal_connect(G_OBJECT(GTK_FILE_CHOOSER(window)), "response",
+		g_signal_connect(G_OBJECT(window), "response",
 		                 G_CALLBACK(do_insert_image_cb), toolbar);
 
 		gtk_widget_show(window);


More information about the Commits mailing list