#include <libnotify/notify.h>
#include <vlc/vlc.h>
-#include <vlc/intf.h>
+#include <vlc_interface.h>
+#include <vlc_playlist.h>
#include <vlc_meta.h>
/*****************************************************************************
static int Notify( vlc_object_t *, const char * );
#define MAX_LENGTH 256
+struct intf_sys_t
+{
+ vlc_mutex_t lock;
+};
+
/*****************************************************************************
* Module descriptor
****************************************************************************/
*****************************************************************************/
static int Open( vlc_object_t *p_this )
{
- intf_thread_t *p_intf = (intf_thread_t *)p_this;
- playlist_t *p_playlist;
+ intf_thread_t *p_intf = (intf_thread_t *)p_this;
+ playlist_t *p_playlist;
+ intf_sys_t *p_sys = malloc( sizeof( intf_sys_t ) );
+
+ if( !p_sys )
+ {
+ msg_Err( p_intf, "Out of memory" );
+ return VLC_ENOMEM;
+ }
if( !notify_init( APPLICATION_NAME ) )
{
return VLC_EGENERIC;
}
+ vlc_mutex_init( p_this, &p_sys->lock );
+
+ p_intf->p_sys = p_sys;
+
p_playlist = pl_Yield( p_intf );
var_AddCallback( p_playlist, "playlist-current", ItemChange, p_intf );
pl_Release( p_intf );
*****************************************************************************/
static void Close( vlc_object_t *p_this )
{
+ intf_thread_t *p_intf = ( intf_thread_t* ) p_this;
+ intf_sys_t *p_sys = p_intf->p_sys;
+
playlist_t *p_playlist = pl_Yield( p_this );
var_DelCallback( p_playlist, "playlist-current", ItemChange, p_this );
pl_Release( p_this );
+ vlc_mutex_destroy( &p_sys->lock );
+ free( p_sys );
notify_uninit();
}
static int ItemChange( vlc_object_t *p_this, const char *psz_var,
vlc_value_t oldval, vlc_value_t newval, void *param )
{
- char psz_tmp[MAX_LENGTH];
- char *psz_title = NULL;
- char *psz_artist = NULL;
- char *psz_album = NULL;
- input_thread_t *p_input=NULL;
- playlist_t * p_playlist = pl_Yield( p_this );
+ char psz_tmp[MAX_LENGTH];
+ char *psz_title = NULL;
+ char *psz_artist = NULL;
+ char *psz_album = NULL;
+ input_thread_t *p_input = NULL;
+ playlist_t * p_playlist = pl_Yield( p_this );
+ intf_thread_t *p_intf = ( intf_thread_t* ) param;
+ intf_sys_t *p_sys = p_intf->p_sys;
p_input = p_playlist->p_input;
vlc_object_release( p_playlist );
if( !p_input ) return VLC_SUCCESS;
vlc_object_yield( p_input );
- if( p_input->b_dead || !p_input->input.p_item->psz_name )
+ if( p_input->b_dead || !input_GetItem(p_input)->psz_name )
{
/* Not playing anything ... */
vlc_object_release( p_input );
}
/* Playing something ... */
- psz_artist = p_input->input.p_item->p_meta->psz_artist ?
- strdup( p_input->input.p_item->p_meta->psz_artist ) :
+ psz_artist = input_GetItem(p_input)->p_meta->psz_artist ?
+ strdup( input_GetItem(p_input)->p_meta->psz_artist ) :
strdup( _("no artist") );
- psz_album = p_input->input.p_item->p_meta->psz_album ?
- strdup( p_input->input.p_item->p_meta->psz_album ) :
+ psz_album = input_GetItem(p_input)->p_meta->psz_album ?
+ strdup( input_GetItem(p_input)->p_meta->psz_album ) :
strdup( _("no album") );
- psz_title = strdup( p_input->input.p_item->psz_name );
+ psz_title = strdup( input_GetItem(p_input)->psz_name );
+
+ vlc_object_release( p_input );
+
if( psz_title == NULL ) psz_title = strdup( N_("(no title)") );
snprintf( psz_tmp, MAX_LENGTH, "<b>%s</b>\n%s - %s",
psz_title, psz_artist, psz_album );
free( psz_artist );
free( psz_album );
+ vlc_mutex_lock( &p_sys->lock );
+
Notify( p_this, psz_tmp );
- vlc_object_release( p_input );
+ vlc_mutex_unlock( &p_sys->lock );
+
return VLC_SUCCESS;
}