[totem] main: Add a way to insert new items in the recent view



commit f226aac616d22da1d30945c38ba82377e4c734c6
Author: Bastien Nocera <hadess hadess net>
Date:   Fri Feb 14 16:36:02 2014 +0100

    main: Add a way to insert new items in the recent view
    
    By adding them to the bookmarks source.

 configure.ac      |    2 +-
 src/totem-grilo.c |   62 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 src/totem-grilo.h |    3 ++
 3 files changed, 66 insertions(+), 1 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 43f4a97..70fb09a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -235,7 +235,7 @@ AM_CONDITIONAL([ENABLE_PYTHON],[test "x$enable_python" = "xyes"])
 # Player requirements
 #================================================================
 
-PKG_CHECK_MODULES(PLAYER, $BACKEND_MODULES glib-2.0 >= $GLIB_REQS gio-2.0 >= $GIO_REQS gtk+-3.0 >= $GTK_REQS 
gdk-x11-3.0 >= $GTK_REQS gmodule-2.0 totem-plparser >= $TOTEM_PLPARSER_REQS libpeas-1.0 >= $PEAS_REQS 
libpeas-gtk-1.0 >= $PEAS_REQS $PYTHON_MODULES grilo-0.2 >= $GRILO_REQS)
+PKG_CHECK_MODULES(PLAYER, $BACKEND_MODULES glib-2.0 >= $GLIB_REQS gio-2.0 >= $GIO_REQS gtk+-3.0 >= $GTK_REQS 
gdk-x11-3.0 >= $GTK_REQS gmodule-2.0 totem-plparser >= $TOTEM_PLPARSER_REQS libpeas-1.0 >= $PEAS_REQS 
libpeas-gtk-1.0 >= $PEAS_REQS $PYTHON_MODULES grilo-0.2 >= $GRILO_REQS grilo-pls-0.2 >= $GRILO_REQS)
 PKG_CHECK_MODULES(LIBPLAYER, glib-2.0 >= $GLIB_REQS gio-2.0 >= $GIO_REQS gtk+-3.0 >= $GTK_REQS gdk-x11-3.0 
= $GTK_REQS clutter-gtk-1.0)
 PKG_CHECK_MODULES(HELPER, gstreamer-1.0 gstreamer-tag-1.0)
 PKG_CHECK_MODULES(TIME_HELPER, glib-2.0)
diff --git a/src/totem-grilo.c b/src/totem-grilo.c
index e13859f..7bf6917 100644
--- a/src/totem-grilo.c
+++ b/src/totem-grilo.c
@@ -34,6 +34,7 @@
 #include <glib-object.h>
 #include <glib/gi18n-lib.h>
 #include <grilo.h>
+#include <pls/grl-pls.h>
 
 #include <totem-interface.h>
 #include <totem-dirs.h>
@@ -60,6 +61,7 @@ struct _TotemGriloPrivate {
 
        GrlSource *local_metadata_src;
        GrlSource *metadata_store_src;
+       GrlSource *bookmarks_src;
        gboolean fs_plugin_configured;
 
        TotemGriloPage current_page;
@@ -541,6 +543,19 @@ add_local_metadata (TotemGrilo *self,
        if (!source_is_recent (source))
                return;
 
+       /* Avoid trying to get metadata for web radios */
+       if (source == self->priv->bookmarks_src) {
+               char *scheme;
+
+               scheme = g_uri_parse_scheme (grl_media_get_url (media));
+               if (g_strcmp0 (scheme, "http") == 0 ||
+                   g_strcmp0 (scheme, "https") == 0) {
+                       g_free (scheme);
+                       return;
+               }
+               g_free (scheme);
+       }
+
        options = grl_operation_options_new (NULL);
        grl_operation_options_set_flags (options, GRL_RESOLVE_FULL);
        grl_source_resolve_sync (self->priv->local_metadata_src,
@@ -1202,6 +1217,8 @@ source_added_cb (GrlRegistry *registry,
                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) {
@@ -2280,6 +2297,51 @@ totem_grilo_get_current_page (TotemGrilo *self)
        return self->priv->current_page;
 }
 
+gboolean
+totem_grilo_add_item_to_recent (TotemGrilo *self,
+                               const char *uri,
+                               gboolean    is_web)
+{
+       GrlMedia *media;
+       GFile *file;
+
+       g_return_val_if_fail (TOTEM_IS_GRILO (self), FALSE);
+
+       file = g_file_new_for_uri (uri);
+
+       if (is_web) {
+               char *basename;
+
+               media = grl_media_video_new ();
+
+               basename = g_file_get_basename (file);
+               grl_media_set_title (media, basename);
+               g_free (basename);
+
+               grl_media_set_url (media, uri);
+       } else {
+               GrlOperationOptions *options;
+
+               options = grl_operation_options_new (NULL);
+               media = grl_pls_file_to_media (NULL,
+                                              file,
+                                              NULL,
+                                              FALSE,
+                                              options);
+               g_object_unref (options);
+       }
+
+       g_object_unref (file);
+
+       /* This should be quick, just adding the item to the DB */
+       grl_source_store_sync (self->priv->bookmarks_src,
+                              NULL,
+                              media,
+                              GRL_WRITE_NORMAL,
+                              NULL);
+       return TRUE;
+}
+
 static void
 totem_grilo_set_property (GObject         *object,
                           guint            prop_id,
diff --git a/src/totem-grilo.h b/src/totem-grilo.h
index ab0f961..2bfe99d 100644
--- a/src/totem-grilo.h
+++ b/src/totem-grilo.h
@@ -70,6 +70,9 @@ gboolean        totem_grilo_get_show_back_button  (TotemGrilo  *self);
 void            totem_grilo_set_current_page      (TotemGrilo     *self,
                                                    TotemGriloPage  page);
 TotemGriloPage  totem_grilo_get_current_page      (TotemGrilo     *self);
+gboolean        totem_grilo_add_item_to_recent    (TotemGrilo     *self,
+                                                   const char     *uri,
+                                                   gboolean        is_web);
 
 G_END_DECLS
 


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