[totem] Try to mount GIO locations that are not mounted yet



commit 15a9e458ebd2d0a4b86898266651fcbb4744795a
Author: Sebastian Dröge <sebastian droege collabora co uk>
Date:   Thu Jul 16 17:02:00 2009 +0200

    Try to mount GIO locations that are not mounted yet
    
    This requires the giosrc element from gst-plugins-base 0.10.23.2.
    (Closes: #588079).

 ChangeLog                                 |    6 ++
 src/backend/bacon-video-widget-gst-0.10.c |   95 +++++++++++++++++++++++++++++
 2 files changed, 101 insertions(+), 0 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 004ea8f..e0d1734 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2009-07-16  Sebastian Dröge  <sebastian droege collabora co uk>
+	
+	* src/backend/bacon-video-widget-gst-0.10.c:
+	Try to mount GIO locations that are not mounted yet (Closes: #588079).
+	This requires the giosrc element from gst-plugins-base 0.10.23.2.
+
 2009-07-16  Robin Stocker  <robin nibor org>
 
 	* src/totem-object.c (drop_video_cb, drag_video_cb):
diff --git a/src/backend/bacon-video-widget-gst-0.10.c b/src/backend/bacon-video-widget-gst-0.10.c
index 583408e..329eccb 100644
--- a/src/backend/bacon-video-widget-gst-0.10.c
+++ b/src/backend/bacon-video-widget-gst-0.10.c
@@ -226,6 +226,10 @@ struct BaconVideoWidgetPrivate
   GList                       *missing_plugins;   /* GList of GstMessages */
   gboolean                     plugin_install_in_progress;
 
+  /* for mounting locations if necessary */
+  GCancellable                *mount_cancellable;
+  gboolean                     mount_in_progress;
+
   /* Bacon resize */
   BaconResize                 *bacon_resize;
 };
@@ -1214,6 +1218,9 @@ bacon_video_widget_init (BaconVideoWidget * bvw)
   bvw->priv->missing_plugins = NULL;
   bvw->priv->plugin_install_in_progress = FALSE;
 
+  bvw->priv->mount_cancellable = NULL;
+  bvw->priv->mount_in_progress = FALSE;
+
   bacon_video_widget_gst_missing_plugins_blacklist ();
 }
 
@@ -1307,6 +1314,45 @@ bvw_do_navigation_query (BaconVideoWidget * bvw, GstQuery *query)
 }
 
 static void
+mount_cb (GObject *obj, GAsyncResult *res, gpointer user_data)
+{
+  BaconVideoWidget * bvw = user_data;
+  gboolean ret;
+  const gchar *uri;
+  GError *error = NULL;
+
+  ret = g_file_mount_enclosing_volume_finish (G_FILE (obj), res, &error);
+
+  g_object_unref (bvw->priv->mount_cancellable);
+  bvw->priv->mount_cancellable = NULL;
+  bvw->priv->mount_in_progress = FALSE;
+
+  g_object_get (G_OBJECT (bvw->priv->play), "uri", &uri, NULL);
+
+  if (ret) {
+
+    GST_DEBUG ("Mounting location '%s' successful", GST_STR_NULL (uri));
+    bacon_video_widget_play (bvw, NULL);
+  } else {
+    GError *err = NULL;
+    GstMessage *msg;
+
+    GST_DEBUG ("Mounting location '%s' failed: %s", GST_STR_NULL (uri), error->message);
+
+    /* create a fake GStreamer error so we get a nice warning message */
+    err = g_error_new_literal (GST_RESOURCE_ERROR, GST_RESOURCE_ERROR_OPEN_READ, error->message);
+    msg = gst_message_new_error (GST_OBJECT (bvw->priv->play), err, error->message);
+    g_error_free (err);
+    g_error_free (error);
+    err = bvw_error_from_gst_error (bvw, msg);
+    gst_message_unref (msg);
+    g_signal_emit (bvw, bvw_signals[SIGNAL_ERROR], 0, err->message, FALSE, FALSE);
+    g_error_free (err);
+    bacon_video_widget_play (bvw, NULL);
+  }
+}
+
+static void
 bvw_handle_element_message (BaconVideoWidget *bvw, GstMessage *msg)
 {
   const gchar *type_name = NULL;
@@ -1350,6 +1396,46 @@ bvw_handle_element_message (BaconVideoWidget *bvw, GstMessage *msg)
     bvw->priv->missing_plugins =
       g_list_prepend (bvw->priv->missing_plugins, gst_message_ref (msg));
     goto done;
+  } else if (strcmp (type_name, "not-mounted") == 0) {
+    const GValue *val;
+    GFile *file;
+    GMountOperation *mount_op;
+    GtkWidget *toplevel;
+    const gchar *uri;
+
+    g_object_get (G_OBJECT (bvw->priv->play), "uri", &uri, NULL);
+
+    if (bvw->priv->mount_in_progress) {
+      g_cancellable_cancel (bvw->priv->mount_cancellable);
+      g_object_unref (bvw->priv->mount_cancellable);
+      bvw->priv->mount_cancellable = NULL;
+      bvw->priv->mount_in_progress = FALSE;
+    }
+
+    GST_DEBUG ("Trying to mount location '%s'", GST_STR_NULL (uri));
+    
+    toplevel = gtk_widget_get_toplevel (GTK_WIDGET (bvw));
+    if (toplevel == GTK_WIDGET (bvw) || !GTK_IS_WINDOW (toplevel))
+      toplevel = NULL;
+
+    val = gst_structure_get_value (msg->structure, "file");
+    if (val == NULL)
+      goto done;
+      
+    file = G_FILE (g_value_get_object (val));
+    if (file == NULL)
+      goto done;
+
+    bacon_video_widget_stop (bvw);
+
+    mount_op = gtk_mount_operation_new (toplevel ? GTK_WINDOW (toplevel) : NULL);
+    bvw->priv->mount_in_progress = TRUE;
+    bvw->priv->mount_cancellable = g_cancellable_new ();
+    g_file_mount_enclosing_volume (file, G_MOUNT_MOUNT_NONE,
+        mount_op, bvw->priv->mount_cancellable, mount_cb, bvw);
+
+    g_object_unref (mount_op);
+    goto done;
   } else {
     GstNavigationMessageType nav_msg_type =
         gst_navigation_message_get_type (msg);
@@ -2202,6 +2288,12 @@ bacon_video_widget_finalize (GObject * object)
     bvw->priv->cursor = NULL;
   }
 
+  if (bvw->priv->mount_cancellable) {
+    g_cancellable_cancel (bvw->priv->mount_cancellable);
+    g_object_unref (bvw->priv->mount_cancellable);
+    bvw->priv->mount_cancellable = NULL;
+  }
+
   g_mutex_free (bvw->priv->lock);
 
   G_OBJECT_CLASS (parent_class)->finalize (object);
@@ -3282,6 +3374,9 @@ bacon_video_widget_play (BaconVideoWidget * bvw, GError ** error)
   if (bvw->priv->plugin_install_in_progress && cur_state != GST_STATE_PAUSED) {
     GST_DEBUG ("plugin install in progress and nothing to play, doing nothing");
     return TRUE;
+  } else if (bvw->priv->mount_in_progress) {
+    GST_DEBUG ("Mounting in progress, doing nothing");
+    return TRUE;
   }
 
   GST_DEBUG ("play");



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