From cbebda0db432638b08296c9b15309a25e8e32665 Mon Sep 17 00:00:00 2001 From: Christian Dywan Date: Thu, 7 Jan 2010 23:30:36 +0100 Subject: [PATCH] Remove Plugins panel, instead add Netscape plugins to Extensions Netscape Plugins cannot actually be activated or deactivated at the moment. --- midori/main.c | 54 ++++++- panels/midori-extensions.c | 2 +- panels/midori-plugins.c | 291 ------------------------------------- panels/midori-plugins.h | 43 ------ po/POTFILES.in | 1 - 5 files changed, 49 insertions(+), 342 deletions(-) delete mode 100644 panels/midori-plugins.c delete mode 100644 panels/midori-plugins.h diff --git a/midori/main.c b/midori/main.c index 0d992d90..21f0cc4e 100644 --- a/midori/main.c +++ b/midori/main.c @@ -21,7 +21,6 @@ #include "midori-console.h" #include "midori-extensions.h" #include "midori-history.h" -#include "midori-plugins.h" #include "midori-transfers.h" #include "sokoke.h" @@ -989,11 +988,6 @@ midori_app_add_browser_cb (MidoriApp* app, gtk_widget_show (addon); midori_panel_append_page (MIDORI_PANEL (panel), MIDORI_VIEWABLE (addon)); - /* Plugins */ - addon = g_object_new (MIDORI_TYPE_PLUGINS, "app", app, NULL); - gtk_widget_show (addon); - midori_panel_append_page (MIDORI_PANEL (panel), MIDORI_VIEWABLE (addon)); - /* Extensions */ addon = g_object_new (MIDORI_TYPE_EXTENSIONS, NULL); gtk_widget_show (addon); @@ -1339,6 +1333,52 @@ midori_load_cookie_jar (gpointer data) return FALSE; } +static gboolean +midori_load_netscape_plugins (gpointer data) +{ + MidoriApp* app = MIDORI_APP (data); + KatzeArray* extensions = katze_object_get_object (app, "extensions"); + /* FIXME: WebKit should have API to obtain the list of plugins. */ + /* FIXME: Monitor folders for newly added and removes files */ + GtkWidget* web_view = webkit_web_view_new (); + WebKitWebFrame* web_frame = webkit_web_view_get_main_frame (WEBKIT_WEB_VIEW (web_view)); + JSContextRef js_context = webkit_web_frame_get_global_context (web_frame); + /* This snippet joins the available plugins into a string like this: + URI1|title1,URI2|title2 + FIXME: Ensure separators contained in the string can't break it */ + gchar* value = sokoke_js_script_eval (js_context, + "function plugins (l) { var f = new Array (); for (i in l) " + "{ f.push (l[i].name + '|' + l[i].filename); } return f; }" + "plugins (navigator.plugins)", NULL); + gchar** items = g_strsplit (value, ",", 0); + guint i = 0; + + if (items != NULL) + while (items[i] != NULL) + { + gchar** parts = g_strsplit (items[i], "|", 2); + if (parts && *parts && !g_str_equal (parts[1], "undefined")) + { + MidoriExtension* extension; + gchar* desc = parts[1]; + gsize j = 0; + while (desc[j++]) + if (desc[j-1] == ';') + desc[j-1] = '\n'; + extension = g_object_new (MIDORI_TYPE_EXTENSION, + "name", parts[0], "description", desc, NULL); + g_object_set_data (G_OBJECT (extension), "static", (void*)0xdeadbeef); + katze_array_add_item (extensions, extension); + } + g_strfreev (parts); + i++; + } + g_strfreev (items); + g_object_unref (extensions); + + return FALSE; +} + static gboolean midori_load_extensions (gpointer data) { @@ -1417,6 +1457,8 @@ midori_load_extensions (gpointer data) } g_strfreev (active_extensions); + g_idle_add (midori_load_netscape_plugins, app); + return FALSE; } diff --git a/panels/midori-extensions.c b/panels/midori-extensions.c index 329a67e4..8f267585 100644 --- a/panels/midori-extensions.c +++ b/panels/midori-extensions.c @@ -227,7 +227,7 @@ midori_extensions_treeview_render_tick_cb (GtkTreeViewColumn* column, g_object_set (renderer, "activatable", midori_extension_is_prepared (extension), - "active", midori_extension_is_active (extension), + "active", midori_extension_is_active (extension) || g_object_get_data (G_OBJECT (extension), "static"), NULL); g_object_unref (extension); diff --git a/panels/midori-plugins.c b/panels/midori-plugins.c deleted file mode 100644 index 6d861b45..00000000 --- a/panels/midori-plugins.c +++ /dev/null @@ -1,291 +0,0 @@ -/* - Copyright (C) 2009 Christian Dywan - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - See the file COPYING for the full license text. -*/ - -#include "midori-plugins.h" - -#include "midori-app.h" -#include "midori-stock.h" -#include "midori-viewable.h" - -#include "sokoke.h" -#include -#include - -struct _MidoriPlugins -{ - GtkVBox parent_instance; - - GtkWidget* toolbar; - GtkWidget* treeview; - MidoriApp* app; -}; - -struct _MidoriPluginsClass -{ - GtkVBoxClass parent_class; -}; - -static void -midori_plugins_viewable_iface_init (MidoriViewableIface* iface); - -G_DEFINE_TYPE_WITH_CODE (MidoriPlugins, midori_plugins, GTK_TYPE_VBOX, - G_IMPLEMENT_INTERFACE (MIDORI_TYPE_VIEWABLE, - midori_plugins_viewable_iface_init)); - -enum -{ - PROP_0, - - PROP_APP -}; - -static void -midori_plugins_set_property (GObject* object, - guint prop_id, - const GValue* value, - GParamSpec* pspec); - -static void -midori_plugins_get_property (GObject* object, - guint prop_id, - GValue* value, - GParamSpec* pspec); - -static void -midori_plugins_class_init (MidoriPluginsClass* class) -{ - GObjectClass* gobject_class; - GParamFlags flags; - - gobject_class = G_OBJECT_CLASS (class); - gobject_class->set_property = midori_plugins_set_property; - gobject_class->get_property = midori_plugins_get_property; - - flags = G_PARAM_READWRITE | G_PARAM_CONSTRUCT; - - g_object_class_install_property (gobject_class, - PROP_APP, - g_param_spec_object ( - "app", - "App", - "The app", - MIDORI_TYPE_APP, - flags)); -} - -static const gchar* -midori_plugins_get_label (MidoriViewable* viewable) -{ - return _("Netscape plugins"); -} - -static const gchar* -midori_plugins_get_stock_id (MidoriViewable* viewable) -{ - return STOCK_PLUGINS; -} - -static GtkWidget* -midori_plugins_get_toolbar (MidoriViewable* plugins) -{ - if (!MIDORI_PLUGINS (plugins)->toolbar) - { - GtkWidget* toolbar; - GtkToolItem* toolitem; - - toolbar = gtk_toolbar_new (); - gtk_toolbar_set_style (GTK_TOOLBAR (toolbar), GTK_TOOLBAR_BOTH_HORIZ); - gtk_toolbar_set_icon_size (GTK_TOOLBAR (toolbar), GTK_ICON_SIZE_BUTTON); - toolitem = gtk_tool_item_new (); - gtk_toolbar_insert (GTK_TOOLBAR (toolbar), toolitem, -1); - gtk_widget_show (GTK_WIDGET (toolitem)); - - MIDORI_PLUGINS (plugins)->toolbar = toolbar; - } - - return MIDORI_PLUGINS (plugins)->toolbar; -} - -static void -midori_plugins_viewable_iface_init (MidoriViewableIface* iface) -{ - iface->get_stock_id = midori_plugins_get_stock_id; - iface->get_label = midori_plugins_get_label; - iface->get_toolbar = midori_plugins_get_toolbar; -} - -static void -midori_plugins_set_property (GObject* object, - guint prop_id, - const GValue* value, - GParamSpec* pspec) -{ - MidoriPlugins* plugins = MIDORI_PLUGINS (object); - - switch (prop_id) - { - case PROP_APP: - plugins->app = g_value_get_object (value); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static void -midori_plugins_get_property (GObject* object, - guint prop_id, - GValue* value, - GParamSpec* pspec) -{ - MidoriPlugins* plugins = MIDORI_PLUGINS (object); - - switch (prop_id) - { - case PROP_APP: - g_value_set_object (value, plugins->app); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static void -midori_plugins_treeview_render_icon_cb (GtkTreeViewColumn* column, - GtkCellRenderer* renderer, - GtkTreeModel* model, - GtkTreeIter* iter, - GtkWidget* treeview) -{ - g_object_set (renderer, "stock-id", GTK_STOCK_EXECUTE, NULL); -} - -static void -midori_plugins_treeview_render_text_cb (GtkTreeViewColumn* column, - GtkCellRenderer* renderer, - GtkTreeModel* model, - GtkTreeIter* iter, - GtkWidget* treeview) -{ - gchar* name; - gchar* text; - gchar* description; - - gtk_tree_model_get (model, iter, 0, &name, 1, &description, -1); - - text = g_strdup_printf ("%s\n%s", name, description); - g_free (name); - g_free (description); - g_object_set (renderer, "text", text, NULL); - g_free (text); -} - -static void -midori_plugins_add_item (MidoriPlugins* plugins, - const gchar* name, - const gchar* description) -{ - gchar* desc; - GtkTreeIter iter; - GtkTreeModel* model; - - desc = g_strdup (description); - if (desc) - { - gsize i, n; - - n = strlen (desc); - for (i = 0; i < n; i++) - if (desc[i] == ';') - desc[i] = '\n'; - } - model = gtk_tree_view_get_model (GTK_TREE_VIEW (plugins->treeview)); - gtk_list_store_append (GTK_LIST_STORE (model), &iter); - gtk_list_store_set (GTK_LIST_STORE (model), &iter, - 0, name, 1, desc, -1); - g_free (desc); -} - -static void -midori_plugins_init (MidoriPlugins* plugins) -{ - /* Create the treeview */ - GtkTreeViewColumn* column; - GtkCellRenderer* renderer_text; - GtkCellRenderer* renderer_pixbuf; - GtkListStore* liststore = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_STRING); - - plugins->treeview = gtk_tree_view_new_with_model (GTK_TREE_MODEL (liststore)); - gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (plugins->treeview), FALSE); - column = gtk_tree_view_column_new (); - renderer_pixbuf = gtk_cell_renderer_pixbuf_new (); - gtk_tree_view_column_pack_start (column, renderer_pixbuf, FALSE); - gtk_tree_view_column_set_cell_data_func (column, renderer_pixbuf, - (GtkTreeCellDataFunc)midori_plugins_treeview_render_icon_cb, - plugins->treeview, NULL); - renderer_text = gtk_cell_renderer_text_new (); - gtk_tree_view_column_pack_start (column, renderer_text, FALSE); - gtk_tree_view_column_set_cell_data_func (column, renderer_text, - (GtkTreeCellDataFunc)midori_plugins_treeview_render_text_cb, - plugins->treeview, NULL); - gtk_tree_view_append_column (GTK_TREE_VIEW (plugins->treeview), column); - g_object_unref (liststore); - gtk_widget_show (plugins->treeview); - gtk_box_pack_start (GTK_BOX (plugins), plugins->treeview, TRUE, TRUE, 0); - - if (1) - { - /* FIXME: WebKit should have API to obtain the list of plugins. */ - /* FIXME: Monitor folders for newly added and removes files */ - GtkWidget* web_view = webkit_web_view_new (); - WebKitWebFrame* web_frame = webkit_web_view_get_main_frame (WEBKIT_WEB_VIEW (web_view)); - JSContextRef js_context = webkit_web_frame_get_global_context (web_frame); - /* This snippet joins the available plugins into a string like this: - URI1|title1,URI2|title2 - FIXME: Ensure separators contained in the string can't break it */ - gchar* value = sokoke_js_script_eval (js_context, - "function plugins (l) { var f = new Array (); for (i in l) " - "{ f.push (l[i].name + '|' + l[i].filename); } return f; }" - "plugins (navigator.plugins)", NULL); - gchar** items = g_strsplit (value, ",", 0); - guint i = 0; - - if (items != NULL) - while (items[i] != NULL) - { - gchar** parts = g_strsplit (items[i], "|", 2); - if (parts && *parts && !g_str_equal (parts[1], "undefined")) - midori_plugins_add_item (plugins, *parts, parts[1]); - g_strfreev (parts); - i++; - } - g_strfreev (items); - } -} - -/** - * midori_plugins_new: - * - * Creates a new empty plugins. - * - * Return value: a new #MidoriPlugins - * - * Since: 0.1.3 - **/ -GtkWidget* -midori_plugins_new (void) -{ - MidoriPlugins* plugins = g_object_new (MIDORI_TYPE_PLUGINS, NULL); - - return GTK_WIDGET (plugins); -} diff --git a/panels/midori-plugins.h b/panels/midori-plugins.h deleted file mode 100644 index 00ee00c3..00000000 --- a/panels/midori-plugins.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - Copyright (C) 2009 Christian Dywan - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - See the file COPYING for the full license text. -*/ - -#ifndef __MIDORI_PLUGINS_H__ -#define __MIDORI_PLUGINS_H__ - -#include - -G_BEGIN_DECLS - -#define MIDORI_TYPE_PLUGINS \ - (midori_plugins_get_type ()) -#define MIDORI_PLUGINS(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST ((obj), MIDORI_TYPE_PLUGINS, MidoriPlugins)) -#define MIDORI_PLUGINS_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_CAST ((klass), MIDORI_TYPE_PLUGINS, MidoriPluginsClass)) -#define MIDORI_IS_PLUGINS(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MIDORI_TYPE_PLUGINS)) -#define MIDORI_IS_PLUGINS_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_TYPE ((klass), MIDORI_TYPE_PLUGINS)) -#define MIDORI_PLUGINS_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS ((obj), MIDORI_TYPE_PLUGINS, MidoriPluginsClass)) - -typedef struct _MidoriPlugins MidoriPlugins; -typedef struct _MidoriPluginsClass MidoriPluginsClass; - -GType -midori_plugins_get_type (void); - -GtkWidget* -midori_plugins_new (void); - -G_END_DECLS - -#endif /* __MIDORI_PLUGINS_H__ */ diff --git a/po/POTFILES.in b/po/POTFILES.in index 0fc4f33a..2bb0115b 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -17,7 +17,6 @@ panels/midori-bookmarks.c panels/midori-console.c panels/midori-extensions.c panels/midori-history.c -panels/midori-plugins.c panels/midori-transfers.c katze/katze-http-auth.c katze/katze-throbber.c