[epiphany/peas: 6/6] ephy-window: update for new extension manager



commit 6089af9ddf75d02cb645beedad125f3b4803b4c8
Author: Diego Escalante Urrelo <descalante igalia com>
Date:   Sat Apr 2 14:26:27 2011 -0500

    ephy-window: update for new extension manager

 data/ui/epiphany-ui.xml |    4 ++-
 src/ephy-window.c       |   78 +++++++++++++++++++++++++++++++++++++---------
 src/window-commands.c   |   29 +++++++++++++++++
 src/window-commands.h   |    3 ++
 4 files changed, 97 insertions(+), 17 deletions(-)
---
diff --git a/data/ui/epiphany-ui.xml b/data/ui/epiphany-ui.xml
index 5d1ffbf..f7589c5 100644
--- a/data/ui/epiphany-ui.xml
+++ b/data/ui/epiphany-ui.xml
@@ -84,7 +84,9 @@
 			<separator name="BookmarksSep1"/>
 		</menu>
 
-		<menu name="ToolsMenu" action="Tools"/>
+		<menu name="ToolsMenu" action="Tools">
+			<menuitem name="ToolsExtensionsManager"	action="ToolsExtensionsManager"/>
+		</menu>
 
 		<menu name="TabsMenu" action="Tabs">
 			<menuitem name="TabsPreviousMenu" action="TabsPrevious"/>
diff --git a/src/ephy-window.c b/src/ephy-window.c
index 55614e8..6a59e18 100644
--- a/src/ephy-window.c
+++ b/src/ephy-window.c
@@ -44,9 +44,12 @@
 #include "ephy-toolbar.h"
 #include "popup-commands.h"
 #include "ephy-encoding-menu.h"
+#include "ephy-extension.h"
+#include "ephy-extensions-manager.h"
+#include "ephy-session.h"
+#include "ephy-lockdown.h"
 #include "ephy-tabs-menu.h"
 #include "ephy-stock-icons.h"
-#include "ephy-extension.h"
 #include "ephy-bookmarks-ui.h"
 #include "ephy-link.h"
 #include "ephy-gui.h"
@@ -239,6 +242,11 @@ static const GtkActionEntry ephy_menu_entries [] = {
 	  N_("Open the history window"),
 	  G_CALLBACK (window_cmd_go_history) },
 
+	/* Tools menu */
+	{ "ToolsExtensionsManager", NULL, N_("_Extensions"), "<control>Y",
+	  N_("Open the extensions manager"),
+	  G_CALLBACK (window_cmd_extensions_manager) },
+
 	/* Tabs menu */
 
 	{ "TabsPrevious", NULL, N_("_Previous Tab"), "<control>Page_Up",
@@ -448,6 +456,7 @@ struct _EphyWindowPrivate
 	guint idle_worker;
 	GtkWidget *entry;
 	GtkWidget *downloads_box;
+	PeasExtensionSet *extensions;
 
 	guint clear_progress_timeout_id;
 
@@ -2940,7 +2949,6 @@ notebook_page_added_cb (EphyNotebook *notebook,
 			EphyWindow *window)
 {
 	EphyWindowPrivate *priv = window->priv;
-	EphyExtension *manager;
 
 	LOG ("page-added   notebook %p embed %p position %u\n", notebook, embed, position);
 
@@ -2963,8 +2971,7 @@ notebook_page_added_cb (EphyNotebook *notebook,
 				 G_CALLBACK (embed_modal_alert_cb), window, G_CONNECT_AFTER);
 
 	/* Let the extensions attach themselves to the tab */
-	manager = EPHY_EXTENSION (ephy_shell_get_extensions_manager (ephy_shell));
-	ephy_extension_attach_tab (manager, window, embed);
+	peas_extension_set_call (priv->extensions, "attach_tab", window, embed);
 
         if (priv->present_on_insert)
         {
@@ -2980,7 +2987,6 @@ notebook_page_removed_cb (EphyNotebook *notebook,
 			  EphyWindow *window)
 {
 	EphyWindowPrivate *priv = window->priv;
-	EphyExtension *manager;
 
 	LOG ("page-removed notebook %p embed %p position %u\n", notebook, embed, position);
 
@@ -2988,9 +2994,8 @@ notebook_page_removed_cb (EphyNotebook *notebook,
 
 	g_return_if_fail (EPHY_IS_EMBED (embed));
 
-	/* Let the extensions remove themselves from the tab */
-	manager = EPHY_EXTENSION (ephy_shell_get_extensions_manager (ephy_shell));
-	ephy_extension_detach_tab (manager, window, embed);
+	peas_extension_set_call (priv->extensions, "detach_tab", window, embed);
+	peas_engine_garbage_collect (PEAS_ENGINE (ephy_shell_get_extensions_manager (ephy_shell)));
 
 #if 0
 	g_signal_handlers_disconnect_by_func (G_OBJECT (embed),
@@ -3214,16 +3219,18 @@ ephy_window_dispose (GObject *object)
 
 	LOG ("EphyWindow dispose %p", window);
 
+	peas_engine_garbage_collect (PEAS_ENGINE (ephy_shell_get_extensions_manager (ephy_shell)));
+
 	/* Only do these once */
 	if (window->priv->closing == FALSE)
 	{
-		EphyExtension *manager;
-
 		window->priv->closing = TRUE;
 
-		/* Let the extensions detach themselves from the window */
-		manager = EPHY_EXTENSION (ephy_shell_get_extensions_manager (ephy_shell));
-		ephy_extension_detach_window (manager, window);
+		peas_extension_set_call (priv->extensions, "detach_window", window);
+		g_object_unref (priv->extensions);
+		peas_engine_garbage_collect (PEAS_ENGINE (ephy_shell_get_extensions_manager (ephy_shell)));
+
+		ephy_session_detach_window (EPHY_SESSION (ephy_shell_get_session (ephy_shell)), window);
 		ephy_bookmarks_ui_detach_window (window);
 
 		g_signal_handlers_disconnect_by_func
@@ -3260,6 +3267,7 @@ ephy_window_dispose (GObject *object)
 
 		_ephy_window_set_context_event (window, NULL);
 	}
+	peas_engine_garbage_collect (PEAS_ENGINE (ephy_shell_get_extensions_manager (ephy_shell)));
 
 	destroy_fullscreen_popup (window);
 
@@ -3533,6 +3541,34 @@ cancel_handler (gpointer idptr)
 	g_source_remove (id);
 }
 
+static void
+extension_added_cb (PeasExtensionSet *extensions,
+		    PeasPluginInfo *info,
+		    PeasExtension *exten,
+		    EphyWindow *window)
+{
+	peas_extension_call (exten, "activate");
+	peas_extension_call (exten, "attach_window", window);
+	peas_extension_call (exten, "attach_tab", window->priv->active_embed);
+}
+
+static void
+extension_removed_cb (PeasExtensionSet *extensions,
+		      PeasPluginInfo *info,
+		      PeasExtension *exten,
+		      EphyWindow *window)
+{
+	peas_extension_call (exten, "detach_window", window);
+	peas_extension_call (exten, "deactivate");
+
+	/* Ensure update of ui manager, because we suspect it does something
+	 * with expected static strings in the type module (when unloaded the
+	 * strings don't exist anymore, and ui manager updates in an idle
+	 * func) */
+	gtk_ui_manager_ensure_update (window->priv->manager);
+}
+
+
 
 static void
 ephy_window_init (EphyWindow *window)
@@ -3556,7 +3592,6 @@ ephy_window_constructor (GType type,
 	GObject *object;
 	EphyWindow *window;
 	EphyWindowPrivate *priv;
-	EphyExtension *manager;
 	EphyEmbedSingle *single;
 	EggToolbarsModel *model;
 	GtkSettings *settings;
@@ -3672,8 +3707,19 @@ ephy_window_constructor (GType type,
 			  FALSE, FALSE, 0);
 
 	/* Once the window is sufficiently created let the extensions attach to it */
-	manager = EPHY_EXTENSION (ephy_shell_get_extensions_manager (ephy_shell));
-	ephy_extension_attach_window (manager, window);
+	priv->extensions = peas_extension_set_new (PEAS_ENGINE (ephy_shell_get_extensions_manager (ephy_shell)),
+						   EPHY_TYPE_EXTENSION,
+						   NULL);
+	peas_extension_set_call (priv->extensions, "attach_window", window);
+
+	g_signal_connect (priv->extensions, "extension-added",
+			  G_CALLBACK (extension_added_cb), window);
+	g_signal_connect (priv->extensions, "extension-removed",
+			  G_CALLBACK (extension_removed_cb), window);
+
+
+	ephy_session_attach_window (EPHY_SESSION (ephy_shell_get_session (ephy_shell)), window);
+	ephy_lockdown_attach_window (EPHY_LOCKDOWN (ephy_shell_get_lockdown (ephy_shell)), window);
 	ephy_bookmarks_ui_attach_window (window);
 
 	/* We only set the model now after attaching the extensions, so that
diff --git a/src/window-commands.c b/src/window-commands.c
index 3e4fdee..bfcd0ae 100644
--- a/src/window-commands.c
+++ b/src/window-commands.c
@@ -56,6 +56,7 @@
 #include <gio/gio.h>
 #include <gtk/gtk.h>
 #include <glib/gi18n.h>
+#include <libpeas-gtk/peas-gtk.h>
 #include <webkit/webkit.h>
 
 static void
@@ -1235,3 +1236,31 @@ window_cmd_browse_with_caret (GtkAction *action,
 	g_settings_set_boolean (EPHY_SETTINGS_MAIN,
 				EPHY_PREFS_ENABLE_CARET_BROWSING, active);
 }
+
+static void
+extensions_manager_delete_cb (GtkWidget *widget,
+			      GdkEvent *event,
+			      gpointer data)
+{
+	gtk_widget_destroy (widget);
+}
+
+void
+window_cmd_extensions_manager (GtkAction *action,
+			       EphyWindow *window)
+{
+	GtkWidget *manager;
+	GtkWidget *dialog;
+
+	manager = peas_gtk_plugin_manager_new (NULL);
+	dialog = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+
+	gtk_window_set_default_size (GTK_WINDOW (dialog), 500, 400);
+
+	gtk_container_add (GTK_CONTAINER (dialog), manager);
+
+	g_signal_connect (dialog, "delete-event",
+			  G_CALLBACK (extensions_manager_delete_cb), NULL);
+
+	gtk_widget_show_all (dialog);
+}
diff --git a/src/window-commands.h b/src/window-commands.h
index 5b37585..07a4779 100644
--- a/src/window-commands.h
+++ b/src/window-commands.h
@@ -159,3 +159,6 @@ void window_cmd_load_location   (GtkAction *action,
 void window_cmd_browse_with_caret (GtkAction *action,
 				   EphyWindow *window);
 
+void window_cmd_extensions_manager (GtkAction *action,
+				    EphyWindow *window);
+



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]