[totem/wip/hadess/save-file-fixes: 10/11] grilo: Ensure bookmarks plugin is available on startup



commit fcb2a202991997d07b728bddb90323a121080ccd
Author: Bastien Nocera <hadess hadess net>
Date:   Wed Feb 6 15:54:37 2019 +0100

    grilo: Ensure bookmarks plugin is available on startup
    
    Rework the grilo plugins loading code to make sure that the bookmarks
    plugin and offline metadata plugins are available when the UI is opened
    without going through the content selection view, directly into the
    player.

 src/totem-grilo.c | 65 +++++++++++++++++++++++++++++++++++++++----------------
 1 file changed, 46 insertions(+), 19 deletions(-)
---
diff --git a/src/totem-grilo.c b/src/totem-grilo.c
index 01adeab2c..8cfe00415 100644
--- a/src/totem-grilo.c
+++ b/src/totem-grilo.c
@@ -64,7 +64,7 @@ struct _TotemGriloPrivate {
        Totem *totem;
        GtkWindow *main_window;
 
-       gboolean plugins_loaded;
+       gboolean plugins_activated;
 
        GrlSource *local_metadata_src;
        GrlSource *title_parsing_src;
@@ -1249,6 +1249,22 @@ source_added_cb (GrlRegistry *registry,
        GrlSupportedOps ops;
        const char *id;
 
+       self = TOTEM_GRILO (user_data);
+       id = grl_source_get_id (source);
+
+       /* Metadata */
+       if (g_str_equal (id, "grl-video-title-parsing"))
+               self->priv->title_parsing_src = source;
+       else if (g_str_equal (id, "grl-local-metadata"))
+               self->priv->local_metadata_src = source;
+       else if (g_str_equal (id, "grl-metadata-store"))
+               self->priv->metadata_store_src = source;
+       else if (g_str_equal (id, "grl-bookmarks"))
+               self->priv->bookmarks_src = source;
+
+       if (self->priv->plugins_activated == FALSE)
+               return;
+
        if (source_is_blacklisted (source) ||
            source_is_forbidden (source) ||
            !(grl_source_get_supported_media (source) & GRL_MEDIA_TYPE_VIDEO)) {
@@ -1258,9 +1274,6 @@ source_added_cb (GrlRegistry *registry,
                return;
        }
 
-       self = TOTEM_GRILO (user_data);
-       id = grl_source_get_id (source);
-
        /* The filesystem plugin */
        if (g_str_equal (id, "grl-filesystem") &&
            self->priv->fs_plugin_configured == FALSE) {
@@ -1273,16 +1286,6 @@ source_added_cb (GrlRegistry *registry,
        else
                name = grl_source_get_name (source);
 
-       /* Metadata */
-       if (g_str_equal (id, "grl-video-title-parsing"))
-               self->priv->title_parsing_src = source;
-       else if (g_str_equal (id, "grl-local-metadata"))
-               self->priv->local_metadata_src = source;
-       else if (g_str_equal (id, "grl-metadata-store"))
-               self->priv->metadata_store_src = source;
-       else if (g_str_equal (id, "grl-bookmarks"))
-               self->priv->bookmarks_src = source;
-
        ops = grl_source_supported_operations (source);
        if (ops & GRL_OP_BROWSE) {
                gboolean monitor = FALSE;
@@ -1410,6 +1413,12 @@ load_grilo_plugins (TotemGrilo *self)
        GSettings *settings;
        char **configs;
        guint i;
+       const char *required_plugins[] = {
+               "grl-lua-factory",
+               "grl-local-metadata",
+               "grl-metadata-store",
+               "grl-bookmarks"
+       };
 
        registry = grl_registry_get_default ();
 
@@ -1433,9 +1442,17 @@ load_grilo_plugins (TotemGrilo *self)
        g_signal_connect (registry, "source-removed",
                          G_CALLBACK (source_removed_cb), self);
 
-       if (grl_registry_load_all_plugins (registry, TRUE, &error) == FALSE) {
+       if (grl_registry_load_all_plugins (registry, FALSE, &error) == FALSE) {
                g_warning ("Failed to load grilo plugins: %s", error->message);
                g_error_free (error);
+               return;
+       }
+
+       for (i = 0; i < G_N_ELEMENTS(required_plugins); i++) {
+               if (!grl_registry_activate_plugin_by_id (registry, required_plugins[i], &error)) {
+                       g_warning ("Failed to load %s plugin: %s", required_plugins[i], error->message);
+                       g_clear_error (&error);
+               }
        }
 }
 
@@ -2496,17 +2513,26 @@ totem_grilo_finalize (GObject *object)
 void
 totem_grilo_start (TotemGrilo *self)
 {
+       GError *error = NULL;
+       GrlRegistry *registry;
+
        g_debug ("TotemGrilo: Resuming videos thumbnailing");
 
        totem_grilo_resume_icon_thumbnailing ();
 
-       if (self->priv->plugins_loaded)
+       if (self->priv->plugins_activated)
                return;
 
-       g_debug ("TotemGrilo: Loading plugins");
+       g_debug ("TotemGrilo: Activating plugins");
 
-       load_grilo_plugins (self);
-       self->priv->plugins_loaded = TRUE;
+       registry = grl_registry_get_default ();
+       self->priv->plugins_activated = TRUE;
+
+       /* Load the others */
+       if (grl_registry_load_all_plugins (registry, TRUE, &error) == FALSE) {
+               g_warning ("Failed to activate grilo plugins: %s", error->message);
+               g_error_free (error);
+       }
 }
 
 void
@@ -2526,6 +2552,7 @@ totem_grilo_constructed (GObject *object)
        setup_ui (self);
        grl_init (0, NULL);
        setup_config (self);
+       load_grilo_plugins (self);
 }
 
 gboolean


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