[totem/gnome-2-28] Make user agent a property on BaconVideoWidget



commit 2446c5e9c4398ce7a27ba05bee3cd359315f61eb
Author: Christian Persch <chpe gnome org>
Date:   Thu Oct 22 12:33:08 2009 +0200

    Make user agent a property on BaconVideoWidget
    
    Instead of transporting the value via environment variable, add a
    gobject property for it.

 browser-plugin/totem-plugin-viewer.c      |   24 ++++--------
 src/backend/bacon-video-widget-gst-0.10.c |   60 ++++++++++++++++++++++++++--
 src/backend/bacon-video-widget.h          |    3 +
 3 files changed, 66 insertions(+), 21 deletions(-)
---
diff --git a/browser-plugin/totem-plugin-viewer.c b/browser-plugin/totem-plugin-viewer.c
index 1fcb5f5..6d02d07 100644
--- a/browser-plugin/totem-plugin-viewer.c
+++ b/browser-plugin/totem-plugin-viewer.c
@@ -110,6 +110,7 @@ typedef struct _TotemEmbedded {
 	TotemStatusbar *statusbar;
 	TotemScrsaver *scrsaver;
 	int width, height;
+        char *user_agent;
 	const char *mimetype;
 	char *base_uri;
 	char *current_uri;
@@ -1742,14 +1743,12 @@ totem_embedded_construct (TotemEmbedded *emb,
 					       (-1, -1, type, &err));
 	}
 
-	/* FIXME! */
-	if (emb->bvw == NULL) {
-		/* FIXME! */
-		/* FIXME construct and show error message */
-		totem_embedded_error_and_exit (_("The Totem plugin could not be started."), err != NULL ? err->message : _("No reason."), emb);
-
-		if (err != NULL)
-			g_error_free (err);
+	/* FIXME: check the UA strings of the legacy plugins themselves */
+	/* FIXME: at least hxplayer seems to send different UAs depending on the protocol!? */
+	if (emb->user_agent != NULL) {
+                bacon_video_widget_set_user_agent (emb->bvw, emb->user_agent);
+		g_free (emb->user_agent);
+		emb->user_agent = NULL;
 	}
 
 	/* Fullscreen setup */
@@ -2267,14 +2266,6 @@ int main (int argc, char **argv)
 		exit (1);
 	}
 
-	/* FIXME: check the UA strings of the legacy plugins themselves */
-	/* FIXME: at least hxplayer seems to send different UAs depending on the protocol!? */
-	if (arg_user_agent != NULL) {
-		g_setenv ("BACON_VIDEO_WIDGET_HTTP_USER_AGENT", arg_user_agent, TRUE);
-		g_free (arg_user_agent);
-		arg_user_agent = NULL;
-	}
-
 	bacon_video_widget_init_backend (NULL, NULL);
 
 	dbus_g_object_type_install_info (TOTEM_TYPE_EMBEDDED,
@@ -2322,6 +2313,7 @@ int main (int argc, char **argv)
 	emb->autostart = !arg_no_autostart;
 	emb->audioonly = arg_audioonly;
 	emb->type = arg_plugin_type;
+        emb->user_agent = arg_user_agent;
 
 	/* FIXME: register this BEFORE requesting the service name? */
 	dbus_g_connection_register_g_object
diff --git a/src/backend/bacon-video-widget-gst-0.10.c b/src/backend/bacon-video-widget-gst-0.10.c
index 02b61ce..8dbd7fc 100644
--- a/src/backend/bacon-video-widget-gst-0.10.c
+++ b/src/backend/bacon-video-widget-gst-0.10.c
@@ -123,6 +123,7 @@ enum
   PROP_SEEKABLE,
   PROP_SHOW_CURSOR,
   PROP_SHOW_VISUALS,
+  PROP_USER_AGENT,
   PROP_VOLUME
 };
 
@@ -146,6 +147,8 @@ typedef enum {
 
 struct BaconVideoWidgetPrivate
 {
+  char                        *user_agent;
+
   char                        *mrl;
   BvwAspectRatio               ratio_type;
 
@@ -1058,6 +1061,16 @@ bacon_video_widget_class_init (BaconVideoWidgetClass * klass)
                                                          NULL, FALSE,
                                                          G_PARAM_WRITABLE));
 
+  /**
+   * BaconVideoWidget:user-agent:
+   *
+   * The HTTP user agent string to use.
+   **/
+  g_object_class_install_property (object_class, PROP_USER_AGENT,
+                                   g_param_spec_string ("user-agent", NULL, NULL,
+                                                        NULL,
+                                                        G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+
   /* Signals */
   /**
    * BaconVideoWidget::error:
@@ -2021,15 +2034,14 @@ bvw_set_device_on_element (BaconVideoWidget * bvw, GstElement * element)
 static void
 bvw_set_user_agent_on_element (BaconVideoWidget * bvw, GstElement * element)
 {
-  const char *ua;
+  BaconVideoWidgetPrivate *priv = bvw->priv;
 
-  ua = g_getenv ("BACON_VIDEO_WIDGET_HTTP_USER_AGENT");
-  if (ua == NULL)
+  if (priv->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'", ua);
-    g_object_set (element, "user-agent", ua, NULL);
+    GST_DEBUG ("Setting HTTP user-agent to '%s'", priv->user_agent);
+    g_object_set (element, "user-agent", priv->user_agent, NULL);
   }
 }
 
@@ -2233,6 +2245,9 @@ bacon_video_widget_finalize (GObject * object)
     bvw->priv->bus = NULL;
   }
 
+  g_free (bvw->priv->user_agent);
+  bvw->priv->user_agent = NULL;
+
   g_free (bvw->priv->media_device);
   bvw->priv->media_device = NULL;
 
@@ -2316,6 +2331,10 @@ bacon_video_widget_set_property (GObject * object, guint property_id,
       bacon_video_widget_set_show_visuals (bvw,
       g_value_get_boolean (value));
       break;
+    case PROP_USER_AGENT:
+      bacon_video_widget_set_user_agent (bvw,
+      g_value_get_string (value));
+      break;
     case PROP_VOLUME:
       bacon_video_widget_set_volume (bvw, g_value_get_double (value));
       break;
@@ -2357,6 +2376,9 @@ bacon_video_widget_get_property (GObject * object, guint property_id,
       g_value_set_boolean (value,
       bacon_video_widget_get_show_cursor (bvw));
       break;
+    case PROP_USER_AGENT:
+      g_value_set_string (value, bvw->priv->user_agent);
+      break;
     case PROP_VOLUME:
       g_value_set_double (value, bvw->priv->volume);
       break;
@@ -3842,6 +3864,34 @@ bacon_video_widget_set_subtitle_encoding (BaconVideoWidget *bvw,
 }
 
 /**
+ * bacon_video_widget_set_user_agent:
+ * @bvw: a #BaconVideoWidget
+ * @user_agent: a HTTP user agent string, or %NULL to use the default
+ *
+ * Sets the HTTP user agent string to use when fetching HTTP ressources.
+ **/
+void
+bacon_video_widget_set_user_agent (BaconVideoWidget *bvw,
+                                   const char *user_agent)
+{
+  BaconVideoWidgetPrivate *priv;
+
+  g_return_if_fail (BACON_IS_VIDEO_WIDGET (bvw));
+
+  priv = bvw->priv;
+
+  if (g_strcmp0 (user_agent, priv->user_agent) == 0)
+    return;
+
+  g_free (priv->user_agent);
+  priv->user_agent = g_strdup (user_agent);
+
+  g_object_notify (G_OBJECT (bvw), "user-agent");
+
+  /* FIXME: set the new UA on the source element if it already exists */
+}
+
+/**
  * bacon_video_widget_can_set_volume:
  * @bvw: a #BaconVideoWidget
  *
diff --git a/src/backend/bacon-video-widget.h b/src/backend/bacon-video-widget.h
index d4ffd0c..b2ad057 100644
--- a/src/backend/bacon-video-widget.h
+++ b/src/backend/bacon-video-widget.h
@@ -232,6 +232,9 @@ void bacon_video_widget_set_subtitle_font	 (BaconVideoWidget *bvw,
 void bacon_video_widget_set_subtitle_encoding	 (BaconVideoWidget *bvw,
 						  const char *encoding);
 
+void bacon_video_widget_set_user_agent           (BaconVideoWidget *bvw,
+                                                  const char *user_agent);
+
 /* Metadata */
 /**
  * BvwMetadataType:



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