1 /*****************************************************************************
2 * dbus-tracklist.c : dbus control module (mpris v1.0) - /TrackList object
3 *****************************************************************************
4 * Copyright © 2006-2008 Rafaël Carré
5 * Copyright © 2007-2010 Mirsal Ennaime
6 * Copyright © 2009-2010 The VideoLAN team
9 * Authors: Mirsal ENNAIME <mirsal dot ennaime at gmail dot com>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
24 *****************************************************************************/
30 #include <vlc_common.h>
31 #include <vlc_playlist.h>
35 #include "dbus_tracklist.h"
36 #include "dbus_common.h"
39 const char* psz_tracklist_introspection_xml =
40 "<!DOCTYPE node PUBLIC \"-//freedesktop//DTD D-BUS Object Introspection 1.0//EN\"\n"
41 "\"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd\">\n"
43 " <interface name=\"org.freedesktop.DBus.Introspectable\">\n"
44 " <method name=\"Introspect\">\n"
45 " <arg name=\"data\" direction=\"out\" type=\"s\"/>\n"
48 " <interface name=\"org.freedesktop.MediaPlayer\">\n"
49 " <method name=\"AddTrack\">\n"
50 " <arg type=\"s\" direction=\"in\" />\n"
51 " <arg type=\"b\" direction=\"in\" />\n"
52 " <arg type=\"i\" direction=\"out\" />\n"
54 " <method name=\"DelTrack\">\n"
55 " <arg type=\"i\" direction=\"in\" />\n"
57 " <method name=\"GetMetadata\">\n"
58 " <arg type=\"i\" direction=\"in\" />\n"
59 " <arg type=\"a{sv}\" direction=\"out\" />\n"
61 " <method name=\"GetCurrentTrack\">\n"
62 " <arg type=\"i\" direction=\"out\" />\n"
64 " <method name=\"GetLength\">\n"
65 " <arg type=#include <vlc_common.h>\"i\" direction=\"out\" />\n"
67 " <method name=\"SetLoop\">\n"
68 " <arg type=\"b\" direction=\"in\" />\n"
70 " <method name=\"SetRandom\">\n"
71 " <arg type=\"b\" direction=\"in\" />\n"
73 " <signal name=\"TrackListChange\">\n"
74 " <arg type=\"i\" />\n"
80 DBUS_METHOD( AddTrack )
81 { /* add the string to the playlist, and play it if the boolean is true */
86 dbus_error_init( &error );
91 dbus_message_get_args( p_from, &error,
92 DBUS_TYPE_STRING, &psz_mrl,
93 DBUS_TYPE_BOOLEAN, &b_play,
96 if( dbus_error_is_set( &error ) )
98 msg_Err( (vlc_object_t*) p_this, "D-Bus message reading : %s",
100 dbus_error_free( &error );
101 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
104 playlist_Add( PL, psz_mrl, NULL, PLAYLIST_APPEND |
105 ( ( b_play == TRUE ) ? PLAYLIST_GO : 0 ) ,
106 PLAYLIST_END, true, false );
108 dbus_int32_t i_success = 0;
109 ADD_INT32( &i_success );
114 DBUS_METHOD( GetCurrentTrack )
119 playlist_t *p_playlist = PL;
122 dbus_int32_t i_position = PL->i_current_index;
125 ADD_INT32( &i_position );
129 DBUS_METHOD( GetMetadata )
134 dbus_error_init( &error );
136 dbus_int32_t i_position;
137 playlist_t *p_playlist = PL;
139 dbus_message_get_args( p_from, &error,
140 DBUS_TYPE_INT32, &i_position,
143 if( dbus_error_is_set( &error ) )
145 msg_Err( (vlc_object_t*) p_this, "D-Bus message reading : %s",
147 dbus_error_free( &error );
148 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
152 if( i_position < p_playlist->current.i_size )
154 GetInputMeta( p_playlist->current.p_elems[i_position]->p_input, &args );
161 DBUS_METHOD( GetLength )
165 playlist_t *p_playlist = PL;
168 dbus_int32_t i_elements = PL->current.i_size;
171 ADD_INT32( &i_elements );
175 DBUS_METHOD( DelTrack )
180 dbus_error_init( &error );
182 dbus_int32_t i_position;
183 playlist_t *p_playlist = PL;
185 dbus_message_get_args( p_from, &error,
186 DBUS_TYPE_INT32, &i_position,
189 if( dbus_error_is_set( &error ) )
191 msg_Err( (vlc_object_t*) p_this, "D-Bus message reading : %s",
193 dbus_error_free( &error );
194 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
198 if( i_position < p_playlist->current.i_size )
200 playlist_DeleteFromInput( p_playlist,
201 p_playlist->current.p_elems[i_position]->p_input,
209 DBUS_METHOD( SetLoop )
217 dbus_error_init( &error );
218 dbus_message_get_args( p_from, &error,
219 DBUS_TYPE_BOOLEAN, &b_loop,
222 if( dbus_error_is_set( &error ) )
224 msg_Err( (vlc_object_t*) p_this, "D-Bus message reading : %s",
226 dbus_error_free( &error );
227 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
230 var_SetBool( PL, "loop", ( b_loop == TRUE ) );
235 DBUS_METHOD( SetRandom )
241 dbus_bool_t b_random;
243 dbus_error_init( &error );
244 dbus_message_get_args( p_from, &error,
245 DBUS_TYPE_BOOLEAN, &b_random,
248 if( dbus_error_is_set( &error ) )
250 msg_Err( (vlc_object_t*) p_this, "D-Bus message reading : %s",
252 dbus_error_free( &error );
253 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
256 var_SetBool( PL, "random", ( b_random == TRUE ) );
261 /******************************************************************************
262 * TrackListChange: tracklist order / length change signal
263 *****************************************************************************/
264 DBUS_SIGNAL( TrackListChangeSignal )
265 { /* emit the new tracklist lengh */
266 SIGNAL_INIT( DBUS_MPRIS_TRACKLIST_INTERFACE,
267 DBUS_MPRIS_TRACKLIST_PATH,
272 playlist_t *p_playlist = ((intf_thread_t*)p_data)->p_sys->p_playlist;
274 dbus_int32_t i_elements = p_playlist->current.i_size;
277 ADD_INT32( &i_elements );
281 DBUS_METHOD( handle_introspect_tracklist )
286 ADD_STRING( &psz_tracklist_introspection_xml );
290 #define METHOD_FUNC( interface, method, function ) \
291 else if( dbus_message_is_method_call( p_from, interface, method ) )\
292 return function( p_conn, p_from, p_this )
295 handle_tracklist ( DBusConnection *p_conn, DBusMessage *p_from, void *p_this )
297 if( dbus_message_is_method_call( p_from,
298 DBUS_INTERFACE_INTROSPECTABLE, "Introspect" ) )
299 return handle_introspect_tracklist( p_conn, p_from, p_this );
301 /* here D-Bus method names are associated to an handler */
303 METHOD_FUNC( DBUS_MPRIS_TRACKLIST_INTERFACE, "GetMetadata", GetMetadata );
304 METHOD_FUNC( DBUS_MPRIS_TRACKLIST_INTERFACE, "GetCurrentTrack", GetCurrentTrack );
305 METHOD_FUNC( DBUS_MPRIS_TRACKLIST_INTERFACE, "GetLength", GetLength );
306 METHOD_FUNC( DBUS_MPRIS_TRACKLIST_INTERFACE, "AddTrack", AddTrack );
307 METHOD_FUNC( DBUS_MPRIS_TRACKLIST_INTERFACE, "DelTrack", DelTrack );
308 METHOD_FUNC( DBUS_MPRIS_TRACKLIST_INTERFACE, "SetLoop", SetLoop );
309 METHOD_FUNC( DBUS_MPRIS_TRACKLIST_INTERFACE, "SetRandom", SetRandom );
311 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
314 /*****************************************************************************
315 * TrackListChangeEmit: Emits the TrackListChange signal
316 *****************************************************************************/
317 /* FIXME: It is not called on tracklist reordering */
318 int TrackListChangeEmit( intf_thread_t *p_intf, int signal, int i_node )
320 // "playlist-item-append"
321 if( signal == SIGNAL_PLAYLIST_ITEM_APPEND )
323 /* don't signal when items are added/removed in p_category */
324 playlist_t *p_playlist = p_intf->p_sys->p_playlist;
326 playlist_item_t *p_item = playlist_ItemGetById( p_playlist, i_node );
328 while( p_item->p_parent )
329 p_item = p_item->p_parent;
330 if( p_item == p_playlist->p_root_category )
338 if( p_intf->p_sys->b_dead )
341 UpdateCaps( p_intf );
342 TrackListChangeSignal( p_intf->p_sys->p_conn, p_intf );