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 at mirsal fr>
10 * Rafaël Carré <funman at videolanorg>
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
25 *****************************************************************************/
31 #include <vlc_common.h>
32 #include <vlc_playlist.h>
36 #include "dbus_tracklist.h"
37 #include "dbus_common.h"
39 DBUS_METHOD( AddTrack )
40 { /* add the string to the playlist, and play it if the boolean is true */
44 dbus_error_init( &error );
46 char *psz_mrl, *psz_aftertrack;
49 dbus_message_get_args( p_from, &error,
50 DBUS_TYPE_STRING, &psz_mrl,
51 DBUS_TYPE_OBJECT_PATH, &psz_aftertrack,
52 DBUS_TYPE_BOOLEAN, &b_play,
55 if( dbus_error_is_set( &error ) )
57 msg_Err( (vlc_object_t*) p_this, "D-Bus message reading : %s",
59 dbus_error_free( &error );
60 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
63 #warning psz_aftertrack is not used
64 playlist_Add( PL, psz_mrl, NULL, PLAYLIST_APPEND |
65 ( ( b_play == TRUE ) ? PLAYLIST_GO : 0 ) ,
66 PLAYLIST_END, true, false );
71 DBUS_METHOD( GetCurrentTrack )
76 playlist_t *p_playlist = PL;
79 dbus_int32_t i_position = PL->i_current_index;
82 ADD_INT32( &i_position );
86 DBUS_METHOD( GetMetadata )
91 dbus_error_init( &error );
93 dbus_int32_t i_position;
94 playlist_t *p_playlist = PL;
96 dbus_message_get_args( p_from, &error,
97 DBUS_TYPE_INT32, &i_position,
100 if( dbus_error_is_set( &error ) )
102 msg_Err( (vlc_object_t*) p_this, "D-Bus message reading : %s",
104 dbus_error_free( &error );
105 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
109 if( i_position < p_playlist->current.i_size )
111 GetInputMeta( p_playlist->current.p_elems[i_position]->p_input, &args );
118 DBUS_METHOD( GetLength )
122 playlist_t *p_playlist = PL;
125 dbus_int32_t i_elements = PL->current.i_size;
128 ADD_INT32( &i_elements );
132 DBUS_METHOD( DelTrack )
137 dbus_error_init( &error );
139 dbus_int32_t i_position;
140 playlist_t *p_playlist = PL;
142 dbus_message_get_args( p_from, &error,
143 DBUS_TYPE_INT32, &i_position,
146 if( dbus_error_is_set( &error ) )
148 msg_Err( (vlc_object_t*) p_this, "D-Bus message reading : %s",
150 dbus_error_free( &error );
151 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
155 if( i_position < p_playlist->current.i_size )
157 playlist_DeleteFromInput( p_playlist,
158 p_playlist->current.p_elems[i_position]->p_input,
166 DBUS_METHOD( SetLoop )
174 dbus_error_init( &error );
175 dbus_message_get_args( p_from, &error,
176 DBUS_TYPE_BOOLEAN, &b_loop,
179 if( dbus_error_is_set( &error ) )
181 msg_Err( (vlc_object_t*) p_this, "D-Bus message reading : %s",
183 dbus_error_free( &error );
184 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
187 var_SetBool( PL, "loop", ( b_loop == TRUE ) );
192 DBUS_METHOD( SetRandom )
198 dbus_bool_t b_random;
200 dbus_error_init( &error );
201 dbus_message_get_args( p_from, &error,
202 DBUS_TYPE_BOOLEAN, &b_random,
205 if( dbus_error_is_set( &error ) )
207 msg_Err( (vlc_object_t*) p_this, "D-Bus message reading : %s",
209 dbus_error_free( &error );
210 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
213 var_SetBool( PL, "random", ( b_random == TRUE ) );
218 /******************************************************************************
219 * TrackListChange: tracklist order / length change signal
220 *****************************************************************************/
221 DBUS_SIGNAL( TrackListChangeSignal )
222 { /* emit the new tracklist lengh */
223 SIGNAL_INIT( DBUS_MPRIS_TRACKLIST_INTERFACE,
224 DBUS_MPRIS_TRACKLIST_PATH,
229 playlist_t *p_playlist = ((intf_thread_t*)p_data)->p_sys->p_playlist;
231 dbus_int32_t i_elements = p_playlist->current.i_size;
234 ADD_INT32( &i_elements );
238 #define METHOD_FUNC( interface, method, function ) \
239 else if( dbus_message_is_method_call( p_from, interface, method ) )\
240 return function( p_conn, p_from, p_this )
243 handle_tracklist ( DBusConnection *p_conn, DBusMessage *p_from, void *p_this )
247 /* METHOD_FUNC( DBUS_INTERFACE_PROPERTIES, "Get", GetProperty );
248 METHOD_FUNC( DBUS_INTERFACE_PROPERTIES, "Set", SetProperty );
249 METHOD_FUNC( DBUS_INTERFACE_PROPERTIES, "GetAll", GetAllProperties ); */
251 /* here D-Bus method names are associated to an handler */
253 METHOD_FUNC( DBUS_MPRIS_TRACKLIST_INTERFACE, "GetMetadata", GetMetadata );
254 METHOD_FUNC( DBUS_MPRIS_TRACKLIST_INTERFACE, "GetCurrentTrack", GetCurrentTrack );
255 METHOD_FUNC( DBUS_MPRIS_TRACKLIST_INTERFACE, "GetLength", GetLength );
256 METHOD_FUNC( DBUS_MPRIS_TRACKLIST_INTERFACE, "AddTrack", AddTrack );
257 METHOD_FUNC( DBUS_MPRIS_TRACKLIST_INTERFACE, "DelTrack", DelTrack );
258 METHOD_FUNC( DBUS_MPRIS_TRACKLIST_INTERFACE, "SetLoop", SetLoop );
259 METHOD_FUNC( DBUS_MPRIS_TRACKLIST_INTERFACE, "SetRandom", SetRandom );
261 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
264 /*****************************************************************************
265 * TrackListChangeEmit: Emits the TrackListChange signal
266 *****************************************************************************/
267 /* FIXME: It is not called on tracklist reordering */
268 int TrackListChangeEmit( intf_thread_t *p_intf, int signal, int i_node )
270 // "playlist-item-append"
271 if( signal == SIGNAL_PLAYLIST_ITEM_APPEND )
273 /* don't signal when items are added/removed in p_category */
274 playlist_t *p_playlist = p_intf->p_sys->p_playlist;
276 playlist_item_t *p_item = playlist_ItemGetById( p_playlist, i_node );
278 while( p_item->p_parent )
279 p_item = p_item->p_parent;
280 if( p_item == p_playlist->p_root_category )
288 if( p_intf->p_sys->b_dead )
291 TrackListChangeSignal( p_intf->p_sys->p_conn, p_intf );