[totem] Set the user agent and referrer on the existing source



commit b99361abb4c9171bde8725b672f4695c8eb6413b
Author: Christian Persch <chpe gnome org>
Date:   Thu Oct 22 13:07:28 2009 +0200

    Set the user agent and referrer on the existing source
    
    When changing the user agent or the referrer while a source already
    exists, change them on the existing source.

 src/backend/bacon-video-widget-gst-0.10.c |   36 ++++++++++++++++++++---------
 1 files changed, 25 insertions(+), 11 deletions(-)
---
diff --git a/src/backend/bacon-video-widget-gst-0.10.c b/src/backend/bacon-video-widget-gst-0.10.c
index ad4c19b..21c7b0b 100644
--- a/src/backend/bacon-video-widget-gst-0.10.c
+++ b/src/backend/bacon-video-widget-gst-0.10.c
@@ -156,6 +156,7 @@ struct BaconVideoWidgetPrivate
   BvwAspectRatio               ratio_type;
 
   GstElement                  *play;
+  GstElement                  *source;
   GstXOverlay                 *xoverlay;      /* protect with lock */
   GstColorBalance             *balance;       /* protect with lock */
   GstNavigation               *navigation;    /* protect with lock */
@@ -2050,13 +2051,11 @@ bvw_set_user_agent_on_element (BaconVideoWidget * bvw, GstElement * element)
 {
   BaconVideoWidgetPrivate *priv = bvw->priv;
 
-  if (priv->user_agent == NULL)
+  if (g_object_class_find_property (G_OBJECT_GET_CLASS (element), "user-agent") == NULL)
     return;
 
-  if (g_object_class_find_property (G_OBJECT_GET_CLASS (element), "user-agent")) {
-    GST_DEBUG ("Setting HTTP user-agent to '%s'", priv->user_agent);
-    g_object_set (element, "user-agent", priv->user_agent, NULL);
-  }
+  GST_DEBUG ("Setting HTTP user-agent to '%s'", priv->user_agent ? priv->user_agent : "(default)");
+  g_object_set (element, "user-agent", priv->user_agent, NULL);
 }
 
 static void
@@ -2094,6 +2093,7 @@ bvw_set_referrer_on_element (BaconVideoWidget * bvw, GstElement * element)
 static void
 playbin_source_notify_cb (GObject *play, GParamSpec *p, BaconVideoWidget *bvw)
 {
+  BaconVideoWidgetPrivate *priv = bvw->priv;
   GstElement *source = NULL;
 
   /* CHECKME: do we really need these taglist frees here (tpm)? */
@@ -2111,6 +2111,12 @@ playbin_source_notify_cb (GObject *play, GParamSpec *p, BaconVideoWidget *bvw)
   }
 
   g_object_get (play, "source", &source, NULL);
+
+  if (priv->source != NULL) {
+    g_object_unref (priv->source);
+  }
+
+  priv->source = source;
   if (source == NULL)
     return;
     
@@ -2118,7 +2124,6 @@ playbin_source_notify_cb (GObject *play, GParamSpec *p, BaconVideoWidget *bvw)
   bvw_set_device_on_element (bvw, source);
   bvw_set_user_agent_on_element (bvw, source);
   bvw_set_referrer_on_element (bvw, source);
-  g_object_unref (source);
 }
 
 static gboolean
@@ -2317,6 +2322,11 @@ bacon_video_widget_finalize (GObject * object)
     bvw->priv->vis_plugins_list = NULL;
   }
 
+  if (bvw->priv->source != NULL) {
+    g_object_unref (bvw->priv->source);
+    bvw->priv->source = NULL;
+  }
+
   if (bvw->priv->play != NULL && GST_IS_ELEMENT (bvw->priv->play)) {
     gst_element_set_state (bvw->priv->play, GST_STATE_NULL);
     gst_object_unref (bvw->priv->play);
@@ -3948,9 +3958,11 @@ bacon_video_widget_set_user_agent (BaconVideoWidget *bvw,
   g_free (priv->user_agent);
   priv->user_agent = g_strdup (user_agent);
 
-  g_object_notify (G_OBJECT (bvw), "user-agent");
+  if (priv->source) {
+    bvw_set_user_agent_on_element (bvw, priv->source);
+  }
 
-  /* FIXME: set the new UA on the source element if it already exists */
+  g_object_notify (G_OBJECT (bvw), "user-agent");
 }
 
 /**
@@ -3980,10 +3992,12 @@ bacon_video_widget_set_referrer (BaconVideoWidget *bvw,
   /* Referrer URIs must not have a fragment */
   if ((frag = strchr (priv->referrer, '#')) != NULL)
     *frag = '\0';
-  
-  g_object_notify (G_OBJECT (bvw), "referrer");
 
-  /* FIXME: set the new referrer on the source element if it already exists */
+  if (priv->source) {
+    bvw_set_referrer_on_element (bvw, priv->source);
+  }
+
+  g_object_notify (G_OBJECT (bvw), "referrer");
 }
 
 /**



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