/pidgin/main: 65ced7f8beaa: Fix regression: saving small WebView...

Tomasz Wasilczyk twasilczyk at pidgin.im
Sat Apr 5 20:31:01 EDT 2014


Changeset: 65ced7f8beaaa5ec444add8ae3813a5ac3d0a361
Author:	 Tomasz Wasilczyk <twasilczyk at pidgin.im>
Date:	 2014-04-06 02:30 +0200
Branch:	 default
URL: https://hg.pidgin.im/pidgin/main/rev/65ced7f8beaa

Description:

Fix regression: saving small WebView images as a custom smileys

diffstat:

 pidgin/gtksmiley-manager.c |  27 +++++++++++++++++++++++++--
 pidgin/gtksmiley-manager.h |  14 +++++++++++++-
 pidgin/gtkwebview.c        |  36 ++++++++++++++++++++++++++++--------
 3 files changed, 66 insertions(+), 11 deletions(-)

diffs (177 lines):

diff --git a/pidgin/gtksmiley-manager.c b/pidgin/gtksmiley-manager.c
--- a/pidgin/gtksmiley-manager.c
+++ b/pidgin/gtksmiley-manager.c
@@ -149,6 +149,13 @@ edit_dialog_set_image(SmileyEditDialog *
 }
 
 static void
+edit_dialog_set_shortcut(SmileyEditDialog *edit_dialog,
+	const gchar *shortcut)
+{
+	gtk_entry_set_text(edit_dialog->shortcut, shortcut ? shortcut : "");
+}
+
+static void
 edit_dialog_image_choosen(const char *filename, gpointer _edit_dialog)
 {
 	PurpleStoredImage *image;
@@ -319,7 +326,8 @@ edit_dialog_show(SmileyManager *manager,
 
 	edit_dialog->window = GTK_DIALOG(gtk_dialog_new_with_buttons(
 		smiley ? _("Edit Smiley") : _("Add Smiley"),
-		GTK_WINDOW(manager->window), GTK_DIALOG_DESTROY_WITH_PARENT,
+		manager ? GTK_WINDOW(manager->window) : NULL,
+		GTK_DIALOG_DESTROY_WITH_PARENT,
 		GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
 		smiley ? GTK_STOCK_SAVE : GTK_STOCK_ADD, GTK_RESPONSE_ACCEPT,
 		NULL));
@@ -444,6 +452,22 @@ edit_dialog_show(SmileyManager *manager,
 	return edit_dialog;
 }
 
+void
+pidgin_smiley_manager_add(PurpleStoredImage *image, const gchar *shortcut)
+{
+	SmileyEditDialog *edit_dialog;
+
+	g_return_if_fail(image != NULL);
+
+	purple_imgstore_ref(image);
+
+	edit_dialog = edit_dialog_show(NULL, NULL);
+	edit_dialog_set_shortcut(edit_dialog, shortcut);
+	if (!edit_dialog_set_image(edit_dialog, image))
+		gtk_widget_destroy(GTK_WIDGET(edit_dialog->window));
+}
+
+
 /*******************************************************************************
  * Custom smiley list Drag-and-drop support.
  ******************************************************************************/
@@ -709,7 +733,6 @@ manager_list_create(SmileyManager *manag
  * Custom smiley manager window.
  ******************************************************************************/
 
-
 static void
 manager_select_cb(GtkWidget *widget, gint resp, SmileyManager *manager)
 {
diff --git a/pidgin/gtksmiley-manager.h b/pidgin/gtksmiley-manager.h
--- a/pidgin/gtksmiley-manager.h
+++ b/pidgin/gtksmiley-manager.h
@@ -41,7 +41,19 @@ G_BEGIN_DECLS
  * Creates and shows the smiley manager window, or requests focus for it,
  * if it's already opened.
  */
-void pidgin_smiley_manager_show(void);
+void
+pidgin_smiley_manager_show(void);
+
+/**
+ * pidgin_smiley_manager_add:
+ * @image: the image for a new smiley.
+ * @shortcut: the textual representation, may be %NULL.
+ *
+ * Creates and shows the new dialog for adding a new custom smiley with
+ * provided image.
+ */
+void
+pidgin_smiley_manager_add(PurpleStoredImage *image, const gchar *shortcut);
 
 G_END_DECLS
 
diff --git a/pidgin/gtkwebview.c b/pidgin/gtkwebview.c
--- a/pidgin/gtkwebview.c
+++ b/pidgin/gtkwebview.c
@@ -24,10 +24,12 @@
 #include "debug.h"
 #include "glibcompat.h"
 #include "pidgin.h"
+#include "pidginstock.h"
 
 #include <gdk/gdkkeysyms.h>
 
 #include "gtkutils.h"
+#include "gtksmiley-manager.h"
 #include "gtkwebview.h"
 #include "gtkwebviewtoolbar.h"
 
@@ -594,7 +596,7 @@ webview_image_saved(GtkWidget *dialog, g
 static void
 webview_image_save(GtkWidget *item, WebKitDOMHTMLImageElement *image_node)
 {
-	const gchar *src = webkit_dom_html_image_element_get_src(image_node);
+	const gchar *src;
 	WebKitWebView *webview;
 	PurpleStoredImage *image;
 	GtkFileChooserDialog *dialog;
@@ -604,6 +606,7 @@ webview_image_save(GtkWidget *item, WebK
 	webview = g_object_get_data(G_OBJECT(image_node), "pidgin-gtkwebview");
 	g_return_if_fail(webview != NULL);
 
+	src = webkit_dom_html_image_element_get_src(image_node); /* XXX: a leak or not? */
 	image = webview_resource_get_loaded(webview, src);
 	g_return_if_fail(image != NULL);
 
@@ -635,6 +638,24 @@ webview_image_save(GtkWidget *item, WebK
 }
 
 static void
+webview_image_add_smiley(GtkWidget *item, WebKitDOMHTMLImageElement *image_node)
+{
+	const gchar *src;
+	WebKitWebView *webview;
+	PurpleStoredImage *image;
+
+	src = webkit_dom_html_image_element_get_src(image_node);
+	webview = g_object_get_data(G_OBJECT(image_node), "pidgin-gtkwebview");
+	g_return_if_fail(webview != NULL);
+
+	image = webview_resource_get_loaded(webview, src);
+	g_return_if_fail(image != NULL);
+
+	pidgin_smiley_manager_add(image,
+		webkit_dom_html_image_element_get_alt(image_node));
+}
+
+static void
 do_popup_menu(WebKitWebView *webview, int button, int time, int context,
               WebKitDOMNode *node, const char *uri)
 {
@@ -707,8 +728,7 @@ do_popup_menu(WebKitWebView *webview, in
 		gtk_widget_show(menu_item);
 		gtk_menu_shell_append(GTK_MENU_SHELL(menu), menu_item);
 
-#if 0
-		/* TODO */
+		/* TODO: check, if it's not *our* custom smiley (use css) */
 		if (width <= 96 && height <= 96) {
 			menu_item = gtk_image_menu_item_new_with_mnemonic(
 				_("_Add Custom Smiley..."));
@@ -716,12 +736,12 @@ do_popup_menu(WebKitWebView *webview, in
 				GTK_IMAGE_MENU_ITEM(menu_item),
 				gtk_image_new_from_stock(GTK_STOCK_ADD,
 					GTK_ICON_SIZE_MENU));
-			g_signal_connect(G_OBJECT(item), "activate",
-				G_CALLBACK(), save);
+			g_signal_connect_object(G_OBJECT(menu_item), "activate",
+				G_CALLBACK(webview_image_add_smiley),
+				image_node, 0);
 			gtk_widget_show(menu_item);
 			gtk_menu_shell_append(GTK_MENU_SHELL(menu), menu_item);
 		}
-#endif
 
 		show_clipboard = FALSE;
 	}
@@ -787,8 +807,8 @@ do_popup_menu(WebKitWebView *webview, in
 
 		pidgin_separator(menu);
 
-		inspect = pidgin_new_item_from_stock(menu, _("Inspect _Element"), NULL,
-		                                     NULL, NULL, 0, 0, NULL);
+		inspect = pidgin_new_item_from_stock(menu, _("Inspect _Element"),
+			PIDGIN_STOCK_DEBUG, NULL, NULL, 0, 0, NULL);
 		g_signal_connect_data(G_OBJECT(inspect), "activate",
 		                      G_CALLBACK(webview_inspector_inspect_element),
 		                      data, (GClosureNotify)g_free, 0);



More information about the Commits mailing list