/pidgin/main: 419c033e46b9: Enable WebKit inspector for all widg...

Tomasz Wasilczyk tomkiewicz at cpw.pidgin.im
Fri Aug 16 07:41:13 EDT 2013


Changeset: 419c033e46b9fa52ef327f04c458ee31ffc25ae2
Author:	 Tomasz Wasilczyk <tomkiewicz at cpw.pidgin.im>
Date:	 2013-08-16 13:41 +0200
Branch:	 default
URL: https://hg.pidgin.im/pidgin/main/rev/419c033e46b9

Description:

Enable WebKit inspector for all widgets, not only conversation

diffstat:

 pidgin/gtkwebview.c     |   63 +++++++++++++++++++++--
 pidgin/plugins/webkit.c |  127 ++---------------------------------------------
 2 files changed, 63 insertions(+), 127 deletions(-)

diffs (296 lines):

diff --git a/pidgin/gtkwebview.c b/pidgin/gtkwebview.c
--- a/pidgin/gtkwebview.c
+++ b/pidgin/gtkwebview.c
@@ -131,6 +131,10 @@ typedef struct _GtkWebViewPriv {
 	char *protocol_name;
 	GHashTable *smiley_data;
 	GtkSmileyTree *default_smilies;
+
+	/* WebKit inspector */
+	WebKitWebView *inspector_view;
+	GtkWindow *inspector_win;
 } GtkWebViewPriv;
 
 /******************************************************************************
@@ -837,11 +841,41 @@ webview_load_finished(WebKitWebView *web
 }
 
 static void
-webview_show_inspector_cb(GtkWidget *item, GtkWebViewInspectData *data)
+webview_inspector_inspect_element(GtkWidget *item, GtkWebViewInspectData *data)
 {
 	webkit_web_inspector_inspect_node(data->inspector, data->node);
 }
 
+static WebKitWebView *
+webview_inspector_create(WebKitWebInspector *inspector,
+	WebKitWebView *webview, gpointer _unused)
+{
+	GtkWebViewPriv *priv = GTK_WEBVIEW_GET_PRIVATE(webview);
+
+	if (priv->inspector_view != NULL)
+		return priv->inspector_view;
+
+	priv->inspector_win = GTK_WINDOW(gtk_window_new(GTK_WINDOW_TOPLEVEL));
+	gtk_window_set_title(priv->inspector_win, _("WebKit inspector"));
+	gtk_window_set_default_size(priv->inspector_win, 600, 400);
+
+	priv->inspector_view = WEBKIT_WEB_VIEW(webkit_web_view_new());
+	gtk_container_add(GTK_CONTAINER(priv->inspector_win),
+		GTK_WIDGET(priv->inspector_view));
+
+	return priv->inspector_view;
+}
+
+static gboolean
+webview_inspector_show(WebKitWebInspector *inspector, GtkWidget *webview)
+{
+	GtkWebViewPriv *priv = GTK_WEBVIEW_GET_PRIVATE(webview);
+
+	gtk_widget_show_all(GTK_WIDGET(priv->inspector_win));
+
+	return TRUE;
+}
+
 static GtkWebViewProtocol *
 webview_find_protocol(const char *url, gboolean reverse)
 {
@@ -997,8 +1031,6 @@ do_popup_menu(WebKitWebView *webview, in
 {
 	GtkWidget *menu;
 	GtkWidget *cut, *copy, *paste, *delete, *select;
-	WebKitWebSettings *settings;
-	gboolean inspector;
 
 	menu = gtk_menu_new();
 	g_signal_connect(menu, "selection-done",
@@ -1077,12 +1109,16 @@ do_popup_menu(WebKitWebView *webview, in
 			webkit_web_view_can_cut_clipboard(webview));
 	}
 
-	settings = webkit_web_view_get_settings(webview);
-	g_object_get(G_OBJECT(settings), "enable-developer-extras", &inspector, NULL);
-	if (inspector) {
+	if (purple_prefs_get_bool(PIDGIN_PREFS_ROOT
+		"/webview/inspector_enabled"))
+	{
+		WebKitWebSettings *settings;
 		GtkWidget *inspect;
 		GtkWebViewInspectData *data;
 
+		settings = webkit_web_view_get_settings(webview);
+		g_object_set(G_OBJECT(settings), "enable-developer-extras", TRUE, NULL);
+
 		data = g_new0(GtkWebViewInspectData, 1);
 		data->inspector = webkit_web_view_get_inspector(webview);
 		data->node = node;
@@ -1092,7 +1128,7 @@ do_popup_menu(WebKitWebView *webview, in
 		inspect = pidgin_new_item_from_stock(menu, _("Inspect _Element"), NULL,
 		                                     NULL, NULL, 0, 0, NULL);
 		g_signal_connect_data(G_OBJECT(inspect), "activate",
-		                      G_CALLBACK(webview_show_inspector_cb),
+		                      G_CALLBACK(webview_inspector_inspect_element),
 		                      data, (GClosureNotify)g_free, 0);
 	}
 
@@ -1391,6 +1427,9 @@ gtk_webview_finalize(GObject *webview)
 	GtkWebViewPriv *priv = GTK_WEBVIEW_GET_PRIVATE(webview);
 	gpointer temp;
 
+	if (priv->inspector_win != NULL)
+		gtk_widget_destroy(GTK_WIDGET(priv->inspector_win));
+
 	if (priv->loader)
 		g_source_remove(priv->loader);
 
@@ -1492,12 +1531,16 @@ gtk_webview_class_init(GtkWebViewClass *
 	binding_set = gtk_binding_set_by_class(klass);
 	gtk_binding_entry_add_signal(binding_set, GDK_KEY_r, GDK_CONTROL_MASK,
 	                             "format-cleared", 0);
+
+	purple_prefs_add_none(PIDGIN_PREFS_ROOT "/webview");
+	purple_prefs_add_bool(PIDGIN_PREFS_ROOT "/webview/inspector_enabled", FALSE);
 }
 
 static void
 gtk_webview_init(GtkWebView *webview, gpointer userdata)
 {
 	GtkWebViewPriv *priv = GTK_WEBVIEW_GET_PRIVATE(webview);
+	WebKitWebInspector *inspector;
 
 	priv->load_queue = g_queue_new();
 
@@ -1522,6 +1565,12 @@ gtk_webview_init(GtkWebView *webview, gp
 
 	g_signal_connect(G_OBJECT(webview), "resource-request-starting",
 	                 G_CALLBACK(webview_resource_loading), NULL);
+
+	inspector = webkit_web_view_get_inspector(WEBKIT_WEB_VIEW(webview));
+	g_signal_connect(G_OBJECT(inspector), "inspect-web-view",
+		G_CALLBACK(webview_inspector_create), NULL);
+	g_signal_connect(G_OBJECT(inspector), "show-window",
+		G_CALLBACK(webview_inspector_show), webview);
 }
 
 GType
diff --git a/pidgin/plugins/webkit.c b/pidgin/plugins/webkit.c
--- a/pidgin/plugins/webkit.c
+++ b/pidgin/plugins/webkit.c
@@ -21,115 +21,15 @@
 
 #include "version.h"
 
-#include "pidgin.h"
-
-#include "gtkconv.h"
 #include "gtkplugin.h"
-#include "gtkwebview.h"
-
-static WebKitWebView *
-create_gtk_window_around_it(WebKitWebInspector *inspector,
-                            WebKitWebView      *webview,
-                            PidginConversation *gtkconv)
-{
-	GtkWidget *win;
-	GtkWidget *view;
-	char *title;
-
-	win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
-	title = g_strdup_printf(_("%s - Inspector"),
-	                        gtk_label_get_text(GTK_LABEL(gtkconv->tab_label)));
-	gtk_window_set_title(GTK_WINDOW(win), title);
-	g_free(title);
-	gtk_window_set_default_size(GTK_WINDOW(win), 600, 400);
-	g_signal_connect_swapped(G_OBJECT(gtkconv->tab_cont), "destroy", G_CALLBACK(gtk_widget_destroy), win);
-
-	view = webkit_web_view_new();
-	gtk_container_add(GTK_CONTAINER(win), view);
-	g_object_set_data(G_OBJECT(webview), "inspector-window", win);
-
-	return WEBKIT_WEB_VIEW(view);
-}
-
-static gboolean
-show_inspector_window(WebKitWebInspector *inspector,
-                      GtkWidget          *webview)
-{
-	GtkWidget *win;
-
-	win = g_object_get_data(G_OBJECT(webview), "inspector-window");
-
-	gtk_widget_show_all(win);
-
-	return TRUE;
-}
-
-static void
-setup_inspector(PidginConversation *gtkconv)
-{
-	GtkWidget *webview = gtkconv->webview;
-	WebKitWebSettings *settings;
-	WebKitWebInspector *inspector;
-
-	settings = webkit_web_view_get_settings(WEBKIT_WEB_VIEW(webview));
-	inspector = webkit_web_view_get_inspector(WEBKIT_WEB_VIEW(webview));
-
-	g_object_set(G_OBJECT(settings), "enable-developer-extras", TRUE, NULL);
-
-	g_signal_connect(G_OBJECT(inspector), "inspect-web-view",
-	                 G_CALLBACK(create_gtk_window_around_it), gtkconv);
-	g_signal_connect(G_OBJECT(inspector), "show-window",
-	                 G_CALLBACK(show_inspector_window), webview);
-}
-
-static void
-remove_inspector(PidginConversation *gtkconv)
-{
-	GtkWidget *webview = gtkconv->webview;
-	GtkWidget *win;
-	WebKitWebSettings *settings;
-
-	win = g_object_get_data(G_OBJECT(webview), "inspector-window");
-	if (win != NULL)
-		gtk_widget_destroy(win);
-	g_object_set_data(G_OBJECT(webview), "inspector-window", NULL);
-
-	settings = webkit_web_view_get_settings(WEBKIT_WEB_VIEW(webview));
-
-	g_object_set(G_OBJECT(settings), "enable-developer-extras", FALSE, NULL);
-}
-
-static void
-conversation_displayed_cb(PidginConversation *gtkconv)
-{
-	GtkWidget *inspect = NULL;
-
-	inspect = g_object_get_data(G_OBJECT(gtkconv->webview),
-	                            "inspector-window");
-	if (inspect == NULL) {
-		setup_inspector(gtkconv);
-	}
-}
 
 static gboolean
 plugin_load(PurplePlugin *plugin)
 {
-	GList *convs = purple_get_conversations();
-	void *gtk_conv_handle = pidgin_conversations_get_handle();
+	purple_prefs_add_none(PIDGIN_PREFS_ROOT "/webview");
+	purple_prefs_add_bool(PIDGIN_PREFS_ROOT "/webview/inspector_enabled", FALSE);
 
-	purple_signal_connect(gtk_conv_handle, "conversation-displayed", plugin,
-	                      PURPLE_CALLBACK(conversation_displayed_cb), NULL);
-
-	while (convs) {
-		PurpleConversation *conv = (PurpleConversation *)convs->data;
-
-		/* Setup WebKit Inspector */
-		if (PIDGIN_IS_PIDGIN_CONVERSATION(conv)) {
-			setup_inspector(PIDGIN_CONVERSATION(conv));
-		}
-
-		convs = convs->next;
-	}
+	purple_prefs_set_bool(PIDGIN_PREFS_ROOT "/webview/inspector_enabled", TRUE);
 
 	return TRUE;
 }
@@ -137,18 +37,7 @@ plugin_load(PurplePlugin *plugin)
 static gboolean
 plugin_unload(PurplePlugin *plugin)
 {
-	GList *convs = purple_get_conversations();
-
-	while (convs) {
-		PurpleConversation *conv = (PurpleConversation *)convs->data;
-
-		/* Remove WebKit Inspector */
-		if (PIDGIN_IS_PIDGIN_CONVERSATION(conv)) {
-			remove_inspector(PIDGIN_CONVERSATION(conv));
-		}
-
-		convs = convs->next;
-	}
+	purple_prefs_set_bool(PIDGIN_PREFS_ROOT "/webview/inspector_enabled", FALSE);
 
 	return TRUE;
 }
@@ -168,10 +57,9 @@ static PurplePluginInfo info =
 	N_("WebKit Development"),                       /**< name */
 	DISPLAY_VERSION,                                /**< version */
 	N_("Enables WebKit Inspector."),                /**< summary */
-	N_("Enables WebKit's built-in inspector in a "
-	   "conversation window. This may be viewed "
-	   "by right-clicking a WebKit widget and "
-	   "selecting 'Inspect Element'."),             /**< description */
+	N_("Enables WebKit's built-in inspector. This "
+	   "may be viewed by right-clicking a WebKit "
+	   "widget and selecting 'Inspect Element'."),  /**< description */
 	"Elliott Sales de Andrade <qulogic at pidgin.im>", /**< author */
 	PURPLE_WEBSITE,                                 /**< homepage */
 	plugin_load,                                    /**< load */
@@ -195,4 +83,3 @@ init_plugin(PurplePlugin *plugin)
 }
 
 PURPLE_INIT_PLUGIN(webkit-devel, init_plugin, info)
-



More information about the Commits mailing list