Disable extensions that are unavailable on the system

Extensions can be unavailable on a particular platform or a system
lacking a build-time requirement. Let's handle this more cleanly
and reflect it in the Extensions panel.
This commit is contained in:
Christian Dywan 2009-09-10 02:02:49 +02:00
parent e59b291709
commit 39e47ac3b7
4 changed files with 30 additions and 14 deletions

View file

@ -561,21 +561,25 @@ extension_test (void)
} }
#endif #endif
#endif
MidoriExtension* MidoriExtension*
extension_init (void) extension_init (void)
{ {
MidoriExtension* extension = g_object_new (MIDORI_TYPE_EXTENSION, MidoriExtension* extension = g_object_new (MIDORI_TYPE_EXTENSION,
"name", _("Advertisement blocker"), "name", _("Advertisement blocker"),
"description", _("Block advertisements according to a filter list"), "description", _("Block advertisements according to a filter list"),
#if WEBKIT_CHECK_VERSION (1, 1, 14)
"version", "0.1", "version", "0.1",
#endif
"authors", "Christian Dywan <christian@twotoasts.de>", "authors", "Christian Dywan <christian@twotoasts.de>",
NULL); NULL);
#if WEBKIT_CHECK_VERSION (1, 1, 14)
midori_extension_install_string_list (extension, "filters", NULL, G_MAXSIZE); midori_extension_install_string_list (extension, "filters", NULL, G_MAXSIZE);
g_signal_connect (extension, "activate", g_signal_connect (extension, "activate",
G_CALLBACK (adblock_activate_cb), NULL); G_CALLBACK (adblock_activate_cb), NULL);
#endif
return extension; return extension;
} }
#endif

View file

@ -604,20 +604,22 @@ static void tb_editor_activate_cb(MidoriExtension *extension, MidoriApp *app)
g_object_unref(browsers); g_object_unref(browsers);
} }
#endif
MidoriExtension *extension_init(void) MidoriExtension *extension_init(void)
{ {
MidoriExtension* extension = g_object_new(MIDORI_TYPE_EXTENSION, MidoriExtension* extension = g_object_new(MIDORI_TYPE_EXTENSION,
"name", _("Toolbar Editor"), "name", _("Toolbar Editor"),
"description", _("Easily edit the toolbar layout"), "description", _("Easily edit the toolbar layout"),
#if !HAVE_HILDON
"version", "0.1", "version", "0.1",
#endif
"authors", "Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de>", "authors", "Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de>",
NULL); NULL);
#if !HAVE_HILDON
g_signal_connect(extension, "activate", G_CALLBACK(tb_editor_activate_cb), NULL); g_signal_connect(extension, "activate", G_CALLBACK(tb_editor_activate_cb), NULL);
#endif
return extension; return extension;
} }
#endif

View file

@ -1300,10 +1300,10 @@ midori_load_extensions (gpointer data)
(gpointer) &extension_init)) (gpointer) &extension_init))
{ {
extension = extension_init (); extension = extension_init ();
/* FIXME: Validate the extension */
/* Signal that we want the extension to load and save */ /* Signal that we want the extension to load and save */
g_object_set_data_full (G_OBJECT (extension), "filename", g_object_set_data_full (G_OBJECT (extension), "filename",
g_strdup (filename), g_free); g_strdup (filename), g_free);
if (midori_extension_is_prepared (extension))
midori_extension_get_config_dir (extension); midori_extension_get_config_dir (extension);
} }
else else

View file

@ -221,7 +221,10 @@ midori_extensions_treeview_render_tick_cb (GtkTreeViewColumn* column,
gtk_tree_model_get (model, iter, 0, &extension, -1); gtk_tree_model_get (model, iter, 0, &extension, -1);
g_object_set (renderer, "active", midori_extension_is_active (extension), NULL); g_object_set (renderer,
"activatable", midori_extension_is_prepared (extension),
"active", midori_extension_is_active (extension),
NULL);
g_object_unref (extension); g_object_unref (extension);
} }
@ -244,12 +247,16 @@ midori_extensions_treeview_render_text_cb (GtkTreeViewColumn* column,
name = katze_object_get_string (extension, "name"); name = katze_object_get_string (extension, "name");
version = katze_object_get_string (extension, "version"); version = katze_object_get_string (extension, "version");
desc = katze_object_get_string (extension, "description"); desc = katze_object_get_string (extension, "description");
text = g_markup_printf_escaped ("<b>%s</b> %s\n%s", name, version, desc); text = g_markup_printf_escaped ("<b>%s</b> %s\n%s",
name, version && *version ? version : "", desc);
g_free (name); g_free (name);
g_free (version); g_free (version);
g_free (desc); g_free (desc);
g_object_set (renderer, "markup", text, NULL); g_object_set (renderer,
"markup", text,
"sensitive", midori_extension_is_prepared (extension),
NULL);
g_free (text); g_free (text);
g_object_unref (extension); g_object_unref (extension);
@ -272,7 +279,7 @@ midori_extensions_treeview_row_activated_cb (GtkTreeView* treeview,
gtk_tree_model_get (model, &iter, 0, &extension, -1); gtk_tree_model_get (model, &iter, 0, &extension, -1);
if (midori_extension_is_active (extension)) if (midori_extension_is_active (extension))
midori_extension_deactivate (extension); midori_extension_deactivate (extension);
else else if (midori_extension_is_prepared (extension))
g_signal_emit_by_name (extension, "activate", extensions->app); g_signal_emit_by_name (extension, "activate", extensions->app);
g_object_unref (extension); g_object_unref (extension);
@ -410,7 +417,7 @@ midori_extensions_button_release_event_cb (GtkWidget* widget,
if (katze_tree_view_get_selected_iter (GTK_TREE_VIEW (widget), &model, &iter)) if (katze_tree_view_get_selected_iter (GTK_TREE_VIEW (widget), &model, &iter))
{ {
MidoriExtension *extension; MidoriExtension* extension;
gtk_tree_model_get (model, &iter, 0, &extension, -1); gtk_tree_model_get (model, &iter, 0, &extension, -1);
@ -432,12 +439,12 @@ midori_extensions_cell_renderer_toggled_cb (GtkCellRendererToggle* renderer,
model = gtk_tree_view_get_model (GTK_TREE_VIEW (extensions->treeview)); model = gtk_tree_view_get_model (GTK_TREE_VIEW (extensions->treeview));
if (gtk_tree_model_get_iter_from_string (model, &iter, path)) if (gtk_tree_model_get_iter_from_string (model, &iter, path))
{ {
MidoriExtension *extension; MidoriExtension* extension;
gtk_tree_model_get (model, &iter, 0, &extension, -1); gtk_tree_model_get (model, &iter, 0, &extension, -1);
if (midori_extension_is_active (extension)) if (midori_extension_is_active (extension))
midori_extension_deactivate (extension); midori_extension_deactivate (extension);
else else if (midori_extension_is_prepared (extension))
g_signal_emit_by_name (extension, "activate", extensions->app); g_signal_emit_by_name (extension, "activate", extensions->app);
g_object_unref (extension); g_object_unref (extension);
@ -460,6 +467,9 @@ midori_extensions_tree_sort_func (GtkTreeModel* model,
name1 = katze_object_get_string (e1, "name"); name1 = katze_object_get_string (e1, "name");
name2 = katze_object_get_string (e2, "name"); name2 = katze_object_get_string (e2, "name");
g_object_unref (e1);
g_object_unref (e2);
result = g_strcmp0 (name1, name2); result = g_strcmp0 (name1, name2);
g_free (name1); g_free (name1);