X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;ds=sidebyside;f=modules%2Fmisc%2Fnotify%2Ftelepathy.c;h=4f538c858116f34c24b455d1b13d5364d389473b;hb=9ad71b062b647f667e6a279bf9e8672c312b47c8;hp=f37f0059fdf82b9bb5fcdc66334eb615f7803250;hpb=7890152736deba5a938e9eb1fd3fd6dd1c00dae1;p=vlc diff --git a/modules/misc/notify/telepathy.c b/modules/misc/notify/telepathy.c index f37f0059fd..4f538c8581 100644 --- a/modules/misc/notify/telepathy.c +++ b/modules/misc/notify/telepathy.c @@ -1,7 +1,7 @@ /***************************************************************************** * telepathy.c : changes Telepathy Presence information using MissionControl ***************************************************************************** - * Copyright © 2007 the VideoLAN team + * Copyright © 2007-2009 the VideoLAN team * $Id$ * * Author: Rafaël Carré @@ -25,11 +25,16 @@ * Preamble *****************************************************************************/ -#include +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include +#include #include -#include #include #include + #include /***************************************************************************** @@ -51,6 +56,8 @@ static void Close ( vlc_object_t * ); static int ItemChange( vlc_object_t *, const char *, vlc_value_t, vlc_value_t, void * ); +static int StateChange( vlc_object_t *, const char *, + vlc_value_t, vlc_value_t, void * ); static int SendToTelepathy( intf_thread_t *, const char * ); /***************************************************************************** @@ -67,18 +74,18 @@ static int SendToTelepathy( intf_thread_t *, const char * ); "$I Video Title, $L Time Remaining, $N Name, $O Audio language, $P Position, " \ "$R Rate, $S Sample rate, $T Time elapsed, $U Publisher, $V Volume") -vlc_module_begin(); - set_category( CAT_INTERFACE ); - set_subcategory( SUBCAT_INTERFACE_CONTROL ); - set_shortname( "Telepathy" ); - set_description( _("Telepathy \"Now Playing\" using MissionControl") ); +vlc_module_begin () + set_category( CAT_INTERFACE ) + set_subcategory( SUBCAT_INTERFACE_CONTROL ) + set_shortname( "Telepathy" ) + set_description( N_("Telepathy \"Now Playing\" (MissionControl)") ) add_string( "telepathy-format", FORMAT_DEFAULT, NULL, - FORMAT_TEXT, FORMAT_LONGTEXT, VLC_FALSE ); + FORMAT_TEXT, FORMAT_LONGTEXT, false ) - set_capability( "interface", 0 ); - set_callbacks( Open, Close ); -vlc_module_end(); + set_capability( "interface", 0 ) + set_callbacks( Open, Close ) +vlc_module_end () /***************************************************************************** * Open: initialize and create stuff @@ -87,15 +94,16 @@ static int Open( vlc_object_t *p_this ) { intf_thread_t *p_intf = (intf_thread_t *)p_this; playlist_t *p_playlist; - DBusConnection *p_conn; DBusError error; - MALLOC_ERR( p_intf->p_sys, intf_sys_t ); + p_intf->p_sys = malloc( sizeof( intf_sys_t ) ); + if( !p_intf->p_sys ) + return VLC_ENOMEM; /* connect to the session bus */ dbus_error_init( &error ); - p_conn = dbus_bus_get( DBUS_BUS_SESSION, &error ); - if( !p_conn ) + p_intf->p_sys->p_conn = dbus_bus_get( DBUS_BUS_SESSION, &error ); + if( !p_intf->p_sys->p_conn ) { msg_Err( p_this, "Failed to connect to the DBus session daemon: %s", error.message ); @@ -103,9 +111,8 @@ static int Open( vlc_object_t *p_this ) free( p_intf->p_sys ); return VLC_EGENERIC; } - p_intf->p_sys->p_conn = p_conn; - p_intf->p_sys->psz_format = config_GetPsz( p_intf, "telepathy-format" ); + p_intf->p_sys->psz_format = var_InheritString( p_intf, "telepathy-format" ); if( !p_intf->p_sys->psz_format ) { msg_Dbg( p_intf, "no format provided" ); @@ -115,10 +122,9 @@ static int Open( vlc_object_t *p_this ) p_intf->p_sys->i_id = -1; - p_playlist = pl_Yield( p_intf ); + p_playlist = pl_Get( p_intf ); var_AddCallback( p_playlist, "item-change", ItemChange, p_intf ); - var_AddCallback( p_playlist, "playlist-current", ItemChange, p_intf ); - pl_Release( p_intf ); + var_AddCallback( p_playlist, "item-current", ItemChange, p_intf ); return VLC_SUCCESS; } @@ -129,7 +135,16 @@ static int Open( vlc_object_t *p_this ) static void Close( vlc_object_t *p_this ) { intf_thread_t *p_intf = (intf_thread_t *)p_this; - playlist_t *p_playlist = pl_Yield( p_this ); + playlist_t *p_playlist = pl_Get( p_this ); + input_thread_t *p_input = NULL; + + var_DelCallback( p_playlist, "item-change", ItemChange, p_intf ); + var_DelCallback( p_playlist, "item-current", ItemChange, p_intf ); + if( (p_input = playlist_CurrentInput( p_playlist )) ) + { + var_DelCallback( p_input, "state", StateChange, p_intf ); + vlc_object_release( p_input ); + } /* Clears the Presence message ... else it looks like we're still playing * something although VLC (or the Telepathy plugin) is closed */ @@ -137,10 +152,6 @@ static void Close( vlc_object_t *p_this ) /* Do not check for VLC_ENOMEM as we're closing */ SendToTelepathy( p_intf, "" ); - var_DelCallback( p_playlist, "item-change", ItemChange, p_intf ); - var_DelCallback( p_playlist, "playlist-current", ItemChange, p_intf ); - pl_Release( p_this ); - /* we won't use the DBus connection anymore */ dbus_connection_unref( p_intf->p_sys->p_conn ); @@ -155,19 +166,24 @@ static void Close( vlc_object_t *p_this ) static int ItemChange( vlc_object_t *p_this, const char *psz_var, vlc_value_t oldval, vlc_value_t newval, void *param ) { + VLC_UNUSED(oldval); intf_thread_t *p_intf = (intf_thread_t *)param; + playlist_t* p_playlist = (playlist_t*) p_this; char *psz_buf = NULL; input_thread_t *p_input; + input_item_t *p_item = newval.p_address; + bool b_is_item_current = !strcmp( "item-current", psz_var ); /* Don't update Telepathy presence each time an item has been preparsed */ - if( !strncmp( "playlist-current", psz_var, 16 ) ) + if( b_is_item_current ) { /* stores the current input item id */ - p_intf->p_sys->i_id = newval.i_int; + p_intf->p_sys->i_id = p_item->i_id; p_intf->p_sys->i_item_changes = 0; } else { - if( newval.i_int != p_intf->p_sys->i_id ) /* "item-change" */ + + if( p_item->i_id != p_intf->p_sys->i_id ) /* "item-change" */ return VLC_SUCCESS; /* Some variable bitrate inputs call "item-change callbacks each time * their length is updated, that is several times per second. @@ -177,14 +193,9 @@ static int ItemChange( vlc_object_t *p_this, const char *psz_var, p_intf->p_sys->i_item_changes++; } - - playlist_t *p_playlist = pl_Yield( p_this ); - - p_input = p_playlist->p_input; - pl_Release( p_this ); + p_input = playlist_CurrentInput( p_playlist ); if( !p_input ) return VLC_SUCCESS; - vlc_object_yield( p_input ); if( p_input->b_dead || !input_GetItem(p_input)->psz_name ) { @@ -193,28 +204,44 @@ static int ItemChange( vlc_object_t *p_this, const char *psz_var, switch( SendToTelepathy( p_intf, "" ) ) { case VLC_ENOMEM: - Close( p_this ); return VLC_ENOMEM; default: return VLC_SUCCESS; } } + if( b_is_item_current ) + var_AddCallback( p_input, "state", StateChange, p_intf ); + /* We format the string to be displayed */ - psz_buf = str_format_meta( p_this, p_intf->p_sys->psz_format ); + psz_buf = str_format_meta( (vlc_object_t*) p_intf, + p_intf->p_sys->psz_format ); + /* We don't need the input anymore */ vlc_object_release( p_input ); if( SendToTelepathy( p_intf, psz_buf ) == VLC_ENOMEM ) { free( psz_buf ); - Close( p_this ); return VLC_ENOMEM; } free( psz_buf ); return VLC_SUCCESS; } +/***************************************************************************** + * StateChange: State change callback + *****************************************************************************/ +static int StateChange( vlc_object_t *p_this, const char *psz_var, + vlc_value_t oldval, vlc_value_t newval, void *param ) +{ + VLC_UNUSED(p_this); VLC_UNUSED(psz_var); VLC_UNUSED(oldval); + intf_thread_t *p_intf = (intf_thread_t *)param; + if( newval.i_int >= END_S ) + return SendToTelepathy( p_intf, "" ); + return VLC_SUCCESS; +} + /***************************************************************************** * SendToTelepathy *****************************************************************************/