pidgin: f2299a6f: Add a WebKit Development plugin, that al...

qulogic at pidgin.im qulogic at pidgin.im
Fri Sep 16 02:15:52 EDT 2011


----------------------------------------------------------------------
Revision: f2299a6fb7c17874bba50dc4014e3b272d27f6d2
Parent:   7e29431f81d1d408673b3b76f805d1202989cb03
Author:   qulogic at pidgin.im
Date:     09/16/11 02:10:04
Branch:   im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/f2299a6fb7c17874bba50dc4014e3b272d27f6d2

Changelog: 

Add a WebKit Development plugin, that allows opening the builtin
inspector on a view. To use, activate the plugin, right-click a view,
and select 'Inspect Element'.

Changes against parent 7e29431f81d1d408673b3b76f805d1202989cb03

  added    pidgin/plugins/webkit.c
  patched  pidgin/plugins/Makefile.am

-------------- next part --------------
============================================================
--- pidgin/plugins/Makefile.am	dc4b68aa1cbb0a86f9f738b41ab7b81a22a26703
+++ pidgin/plugins/Makefile.am	a2eb4b97dd42747393d29b85283d07b4863dfcf3
@@ -43,6 +43,7 @@ vvconfig_la_LDFLAGS         = -module -a
 spellchk_la_LDFLAGS         = -module -avoid-version
 themeedit_la_LDFLAGS        = -module -avoid-version
 vvconfig_la_LDFLAGS         = -module -avoid-version
+webkit_la_LDFLAGS           = -module -avoid-version
 xmppconsole_la_LDFLAGS      = -module -avoid-version
 
 if PLUGINS
@@ -58,7 +59,8 @@ plugin_LTLIBRARIES = \
 	relnot.la           \
 	sendbutton.la       \
 	spellchk.la         \
-	themeedit.la         \
+	themeedit.la        \
+	webkit.la           \
 	xmppconsole.la
 
 if USE_VV
@@ -82,6 +84,7 @@ themeedit_la_SOURCES        = themeedit.
 sendbutton_la_SOURCES       = sendbutton.c
 spellchk_la_SOURCES         = spellchk.c
 themeedit_la_SOURCES        = themeedit.c themeedit-icon.c themeedit-icon.h
+webkit_la_SOURCES           = webkit.c
 xmppconsole_la_SOURCES      = xmppconsole.c
 
 convcolors_la_LIBADD        = $(GTK_LIBS)
@@ -97,6 +100,7 @@ themeedit_la_LIBADD         = $(GTK_LIBS
 sendbutton_la_LIBADD        = $(GTK_LIBS)
 spellchk_la_LIBADD          = $(GTK_LIBS)
 themeedit_la_LIBADD         = $(GTK_LIBS)
+webkit_la_LIBADD            = $(GTK_LIBS) $(WEBKIT_LIBS)
 xmppconsole_la_LIBADD       = $(GTK_LIBS)
 
 endif # PLUGINS
============================================================
--- /dev/null	
+++ pidgin/plugins/webkit.c	b0f6b8ff237fe25b64eb5291b46160a16fe47e99
@@ -0,0 +1,202 @@
+/*
+ * WebKit - Open the inspector on any WebKit views.
+ * Copyright (C) 2011 Elliott Sales de Andrade <qulogic at pidgin.im>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "internal.h"
+
+#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);
+
+	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;
+	WebKitWebInspector *inspector;
+
+	win = g_object_get_data(G_OBJECT(webview), "inspector-window");
+	gtk_widget_destroy(win);
+	g_object_set_data(G_OBJECT(webview), "inspector-window", NULL);
+
+	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", 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_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;
+	}
+
+	return TRUE;
+}
+
+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;
+	}
+
+	return TRUE;
+}
+
+static PurplePluginInfo info =
+{
+	PURPLE_PLUGIN_MAGIC,
+	PURPLE_MAJOR_VERSION,                           /**< major version */
+	PURPLE_MINOR_VERSION,                           /**< minor version */
+	PURPLE_PLUGIN_STANDARD,                         /**< type */
+	PIDGIN_PLUGIN_TYPE,                             /**< ui_requirement */
+	0,                                              /**< flags */
+	NULL,                                           /**< dependencies */
+	PURPLE_PRIORITY_DEFAULT,                        /**< priority */
+
+	"gtkwebkit-inspect",                            /**< id */
+	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 */
+	"Elliott Sales de Andrade <qulogic at pidgin.im>", /**< author */
+	PURPLE_WEBSITE,                                 /**< homepage */
+	plugin_load,                                    /**< load */
+	plugin_unload,                                  /**< unload */
+	NULL,                                           /**< destroy */
+	NULL,                                           /**< ui_info */
+	NULL,                                           /**< extra_info */
+	NULL,                                           /**< prefs_info */
+	NULL,                                           /**< actions */
+
+	/* padding */
+	NULL,
+	NULL,
+	NULL,
+	NULL
+};
+
+static void
+init_plugin(PurplePlugin *plugin)
+{
+}
+
+PURPLE_INIT_PLUGIN(webkit-devel, init_plugin, info)
+


More information about the Commits mailing list