[totem] main: Use a signal to get the user-agent for specific sites
- From: Bastien Nocera <hadess src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [totem] main: Use a signal to get the user-agent for specific sites
- Date: Sat, 21 Apr 2012 20:45:42 +0000 (UTC)
commit 56b360ecc090dac8403922d1c80e4911f2dc3959
Author: Bastien Nocera <hadess hadess net>
Date: Sat Apr 21 21:04:28 2012 +0100
main: Use a signal to get the user-agent for specific sites
Instead of hard-coding hacks in the Totem core itself.
https://bugzilla.gnome.org/show_bug.cgi?id=674469
src/totem-object.c | 47 ++++++++++++++++++++++++++++++++++++-----
src/totem.h | 2 +
src/totemobject-marshal.list | 1 +
3 files changed, 44 insertions(+), 6 deletions(-)
---
diff --git a/src/totem-object.c b/src/totem-object.c
index b012570..5879266 100644
--- a/src/totem-object.c
+++ b/src/totem-object.c
@@ -121,6 +121,7 @@ enum {
FILE_OPENED,
FILE_CLOSED,
METADATA_UPDATED,
+ GET_USER_AGENT,
LAST_SIGNAL
};
@@ -194,6 +195,22 @@ bail:
return FALSE;
}
+static gboolean
+accumulator_first_non_null_wins (GSignalInvocationHint *ihint,
+ GValue *return_accu,
+ const GValue *handler_return,
+ gpointer data)
+{
+ const gchar *str;
+
+ str = g_value_get_string (handler_return);
+ if (str == NULL)
+ return TRUE;
+ g_value_set_string (return_accu, str);
+
+ return FALSE;
+}
+
static void
totem_object_class_init (TotemObjectClass *klass)
{
@@ -335,6 +352,25 @@ totem_object_class_init (TotemObjectClass *klass)
NULL, NULL,
totemobject_marshal_VOID__STRING_STRING_STRING_UINT,
G_TYPE_NONE, 4, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_UINT);
+
+ /**
+ * TotemObject::get-user-agent:
+ * @totem: the #TotemObject which received the signal
+ * @mrl: the MRL of the opened stream
+ *
+ * The #TotemObject::get-user-agent signal is emitted before opening a stream, so that plugins
+ * have the opportunity to return the user-agent to be set.
+ *
+ * Return value: allocated string representing the user-agent to use for @mrl
+ */
+ totem_table_signals[GET_USER_AGENT] =
+ g_signal_new ("get-user-agent",
+ G_TYPE_FROM_CLASS (object_class),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (TotemObjectClass, get_user_agent),
+ accumulator_first_non_null_wins, NULL,
+ totemobject_marshal_STRING__STRING,
+ G_TYPE_STRING, 1, G_TYPE_STRING);
}
static void
@@ -1634,6 +1670,7 @@ totem_action_set_mrl_with_warning (TotemObject *totem,
} else {
gboolean caps;
gdouble volume;
+ char *user_agent;
char *autoload_sub = NULL;
GError *err = NULL;
@@ -1642,12 +1679,10 @@ totem_action_set_mrl_with_warning (TotemObject *totem,
if (subtitle == NULL && totem->autoload_subs != FALSE)
autoload_sub = totem_uri_get_subtitle_uri (mrl);
- /* HACK: Bad bad Apple */
- if (g_str_has_prefix (mrl, "http://movies.apple.com")
- || g_str_has_prefix (mrl, "http://trailers.apple.com"))
- bacon_video_widget_set_user_agent (totem->bvw, "Quicktime/7.2.0");
- else
- bacon_video_widget_set_user_agent (totem->bvw, NULL);
+ user_agent = NULL;
+ g_signal_emit (G_OBJECT (totem), totem_table_signals[GET_USER_AGENT], 0, mrl, &user_agent);
+ bacon_video_widget_set_user_agent (totem->bvw, user_agent);
+ g_free (user_agent);
totem_gdk_window_set_waiting_cursor (gtk_widget_get_window (totem->win));
totem_try_restore_position (totem, mrl);
diff --git a/src/totem.h b/src/totem.h
index 03cc4bd..46de8ab 100644
--- a/src/totem.h
+++ b/src/totem.h
@@ -171,6 +171,8 @@ typedef struct {
const char *title,
const char *album,
guint track_num);
+ char * (*get_user_agent) (TotemObject *totem,
+ const char *mrl);
} TotemObjectClass;
GType totem_object_get_type (void);
diff --git a/src/totemobject-marshal.list b/src/totemobject-marshal.list
index bb10a86..cd46d39 100644
--- a/src/totemobject-marshal.list
+++ b/src/totemobject-marshal.list
@@ -1 +1,2 @@
VOID:STRING,STRING,STRING,UINT
+STRING:STRING
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]