Commit b64a3e09 authored by Mirsal Ennaime's avatar Mirsal Ennaime

dbus: Use the AfterTrack parameter in the tracklist's Add method

parent d774b349
...@@ -36,16 +36,57 @@ ...@@ -36,16 +36,57 @@
#include "dbus_tracklist.h" #include "dbus_tracklist.h"
#include "dbus_common.h" #include "dbus_common.h"
/**
* Retrieves the position of an input item in the playlist, given its id
*
* This function must be called with the playlist locked
*
* @param playlist_t* p_playlist The playlist
* @param input_item_t* i_input_id An input item ID
*
* @return int The position of the input item or a VLC error constant
*/
static int getInputPosition( playlist_t* p_playlist, int i_input_id )
{
input_item_t* p_input = NULL;
assert( p_playlist );
assert( i_input_id >= 0 );
playlist_AssertLocked( p_playlist );
for( int i = 0; i < playlist_CurrentSize( p_playlist ); i++ )
{
p_input = p_playlist->current.p_elems[i]->p_input;
if( !p_input )
return VLC_EGENERIC;
if( p_input->i_id == i_input_id )
return i;
}
return VLC_ENOITEM;
}
DBUS_METHOD( AddTrack ) DBUS_METHOD( AddTrack )
{ /* add the string to the playlist, and play it if the boolean is true */ {
REPLY_INIT; REPLY_INIT;
DBusError error; DBusError error;
dbus_error_init( &error ); dbus_error_init( &error );
char *psz_mrl, *psz_aftertrack; char *psz_mrl, *psz_aftertrack;
playlist_t *p_playlist = PL;
dbus_bool_t b_play; dbus_bool_t b_play;
int i_input_id = -1;
int i_mode = PLAYLIST_APPEND;
int i_pos = PLAYLIST_END;
size_t i_append_len = sizeof( DBUS_MPRIS_APPEND );
size_t i_notrack_len = sizeof( DBUS_MPRIS_NOTRACK );
dbus_message_get_args( p_from, &error, dbus_message_get_args( p_from, &error,
DBUS_TYPE_STRING, &psz_mrl, DBUS_TYPE_STRING, &psz_mrl,
DBUS_TYPE_OBJECT_PATH, &psz_aftertrack, DBUS_TYPE_OBJECT_PATH, &psz_aftertrack,
...@@ -56,14 +97,43 @@ DBUS_METHOD( AddTrack ) ...@@ -56,14 +97,43 @@ DBUS_METHOD( AddTrack )
{ {
msg_Err( (vlc_object_t*) p_this, "D-Bus message reading : %s", msg_Err( (vlc_object_t*) p_this, "D-Bus message reading : %s",
error.message ); error.message );
dbus_error_free( &error ); dbus_error_free( &error );
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
} }
#warning psz_aftertrack is not used if( !strncmp( DBUS_MPRIS_APPEND, psz_aftertrack, i_append_len ) )
playlist_Add( PL, psz_mrl, NULL, PLAYLIST_APPEND | {
( ( b_play == TRUE ) ? PLAYLIST_GO : 0 ) , i_mode = PLAYLIST_APPEND;
PLAYLIST_END, true, false ); i_pos = PLAYLIST_END;
}
else if( !strncmp( DBUS_MPRIS_NOTRACK, psz_aftertrack, i_notrack_len ) )
{
i_mode = PLAYLIST_INSERT;
i_pos = 0;
}
else if( 1 == sscanf( psz_aftertrack, MPRIS_TRACKID_FORMAT, &i_input_id ) )
{
PL_LOCK;
int i_res = getInputPosition( p_playlist, i_input_id );
PL_UNLOCK;
if( i_res < 0 )
goto invalidTrackID;
i_mode = PLAYLIST_INSERT;
i_pos = i_res + 1;
}
else
{
invalidTrackID:
msg_Warn( (vlc_object_t *) p_this,
"AfterTrack: Invalid track ID \"%s\", appending instead",
psz_aftertrack );
}
i_mode |= ( TRUE == b_play ) ? PLAYLIST_GO : 0;
playlist_Add( PL, psz_mrl, NULL, i_mode, i_pos, true, false );
REPLY_SEND; REPLY_SEND;
} }
......
...@@ -34,6 +34,9 @@ ...@@ -34,6 +34,9 @@
#define DBUS_MPRIS_TRACKLIST_INTERFACE "org.mpris.MediaPlayer2.TrackList" #define DBUS_MPRIS_TRACKLIST_INTERFACE "org.mpris.MediaPlayer2.TrackList"
#define DBUS_MPRIS_TRACKLIST_PATH "/org/mpris/MediaPlayer2/TrackList" #define DBUS_MPRIS_TRACKLIST_PATH "/org/mpris/MediaPlayer2/TrackList"
#define DBUS_MPRIS_NOTRACK "/org/mpris/MediaPlayer2/TrackList/NoTrack"
#define DBUS_MPRIS_APPEND "/org/mpris/MediaPlayer2/TrackList/Append"
/* Handle incoming dbus messages */ /* Handle incoming dbus messages */
DBusHandlerResult handle_tracklist ( DBusConnection *p_conn, DBusHandlerResult handle_tracklist ( DBusConnection *p_conn,
DBusMessage *p_from, DBusMessage *p_from,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment