274
272
// Definition du backend. //
275
273
////////////////////////////
277
/* Fonction de connexion au bus de audacious.
279
static gboolean _cd_audacious_dbus_connect_to_bus (void)
281
if (cairo_dock_dbus_is_enabled ())
283
myData.dbus_enable = cd_musicplayer_dbus_connect_to_bus (); // cree le proxy.
285
myData.dbus_enable_shell = musicplayer_dbus_connect_to_bus_Shell (); // cree le proxy pour la 2eme interface car AU en a 2.
287
dbus_g_proxy_add_signal(myData.dbus_proxy_player, "StatusChange",
288
MP_DBUS_TYPE_PLAYER_STATUS_MPRIS,
290
dbus_g_proxy_connect_signal(myData.dbus_proxy_player, "StatusChange",
291
G_CALLBACK(onChangePlaying_mpris), NULL, NULL);
293
dbus_g_proxy_add_signal(myData.dbus_proxy_player, "TrackChange",
294
MP_DBUS_TYPE_SONG_METADATA,
296
dbus_g_proxy_connect_signal(myData.dbus_proxy_player, "TrackChange",
297
G_CALLBACK(onChangeSong), NULL, NULL); // pas de TrackListChange, donc on fera tout dedans.
304
/* Permet de libérer la mémoire prise par le backend.
306
static void cd_audacious_free_data (void)
308
if (myData.dbus_proxy_player != NULL)
310
dbus_g_proxy_disconnect_signal(myData.dbus_proxy_player, "StatusChange",
311
G_CALLBACK(onChangePlaying_mpris), NULL);
313
dbus_g_proxy_disconnect_signal(myData.dbus_proxy_player, "TrackChange",
314
G_CALLBACK(onChangeSong), NULL);
317
musicplayer_dbus_disconnect_from_bus();
318
musicplayer_dbus_disconnect_from_bus_Shell();
322
275
/* Controle du lecteur (permet d'effectuer les actions de bases sur le lecteur).
324
277
static void cd_audacious_control (MyPlayerControl pControl, const char* song)
326
279
const gchar *cCommand = NULL;
328
281
switch (pControl) {
329
282
case PLAYER_PREVIOUS :
330
283
cCommand = "Prev";
333
286
case PLAYER_STOP :
334
287
cCommand = "Stop";
337
290
case PLAYER_PLAY_PAUSE :
338
291
if (myData.iPlayingStatus != PLAYER_PLAYING)
339
292
cCommand = "Play";
407
360
/* Recupere le temps ecoule chaque seconde (pas de signal pour ca).
409
static void cd_audacious_read_data (void)
362
static void cd_audacious_get_data (void)
411
if (myData.dbus_enable)
364
if (myData.iPlayingStatus == PLAYER_PLAYING)
413
if (myData.bIsRunning)
415
if (myData.iPlayingStatus == PLAYER_PLAYING)
417
///_audacious_get_time_elapsed ();
418
cd_mpris_get_time_elapsed ();
419
if (myData.iCurrentTime < 0)
420
myData.iPlayingStatus = PLAYER_STOPPED;
422
else if (myData.iPlayingStatus != PLAYER_PAUSED) // en pause le temps reste constant.
423
myData.iCurrentTime = 0;
427
myData.iCurrentTime = 0;
429
cd_message (" myData.iCurrentTime <- %d", myData.iCurrentTime);
366
cd_mpris_get_time_elapsed ();
367
if (myData.iCurrentTime < 0)
368
myData.iPlayingStatus = PLAYER_STOPPED;
370
else if (myData.iPlayingStatus != PLAYER_PAUSED) // en pause le temps reste constant.
371
myData.iCurrentTime = 0;
433
374
/* Initialise le backend de AU.
435
static void cd_audacious_configure (void)
376
static void cd_audacious_start (void)
437
myData.DBus_commands.service = "org.mpris.audacious";
438
myData.DBus_commands.path = "/Player";
439
myData.DBus_commands.path2 = "/TrackList";
440
myData.DBus_commands.interface = "org.freedesktop.MediaPlayer";
441
myData.DBus_commands.interface2 = "org.freedesktop.MediaPlayer";
378
// register to the signals
379
dbus_g_proxy_add_signal(myData.dbus_proxy_player, "StatusChange",
380
MP_DBUS_TYPE_PLAYER_STATUS_MPRIS,
382
dbus_g_proxy_connect_signal(myData.dbus_proxy_player, "StatusChange",
383
G_CALLBACK(onChangePlaying_mpris), NULL, NULL);
443
myData.dbus_enable = _cd_audacious_dbus_connect_to_bus (); // se connecte au bus et aux signaux de AU.
444
if (myData.dbus_enable)
446
cd_musicplayer_dbus_detect_player (); // on teste la presence de AU sur le bus <=> s'il est ouvert ou pas.
447
if(myData.bIsRunning) // player en cours d'execution, on recupere son etat.
449
cd_debug ("MP : AU is running\n");
450
///_audacious_getPlaying_mpris ();
451
cd_mpris_getPlaying ();
452
cd_audacious_getSongInfos ();
453
cd_musicplayer_update_icon (TRUE);
455
else // player eteint.
457
cd_musicplayer_set_surface (PLAYER_NONE);
460
else // sinon on signale par l'icone appropriee que le bus n'est pas accessible.
462
cd_musicplayer_set_surface (PLAYER_BROKEN);
385
dbus_g_proxy_add_signal(myData.dbus_proxy_player, "TrackChange",
386
MP_DBUS_TYPE_SONG_METADATA,
388
dbus_g_proxy_connect_signal(myData.dbus_proxy_player, "TrackChange",
389
G_CALLBACK(onChangeSong), NULL, NULL); // pas de TrackListChange, donc on fera tout dedans.
391
// get the current state.
392
cd_mpris_getPlaying (); ///_audacious_getPlaying_mpris ();
393
cd_audacious_getSongInfos ();
394
cd_musicplayer_update_icon (TRUE);
466
397
/* On enregistre notre lecteur.
468
399
void cd_musicplayer_register_audacious_handler (void)
470
MusicPlayerHandeler *pAudacious = g_new0 (MusicPlayerHandeler, 1);
471
pAudacious->read_data = cd_audacious_read_data; // recupere le temps ecoule car on n'a pas de signal pour ca.
472
pAudacious->free_data = cd_audacious_free_data;
473
pAudacious->configure = cd_audacious_configure; // renseigne les proprietes DBus et se connecte au bus.
474
pAudacious->control = cd_audacious_control;
475
pAudacious->get_cover = NULL;
476
pAudacious->cCoverDir = NULL; /// a confirmer...
401
MusicPlayerHandler *pHandler = g_new0 (MusicPlayerHandler, 1);
402
pHandler->name = "Audacious";
403
pHandler->get_data = cd_audacious_get_data;
404
pHandler->stop = NULL;
405
pHandler->start = cd_audacious_start;
406
pHandler->control = cd_audacious_control;
407
pHandler->get_cover = NULL;
408
pHandler->cCoverDir = NULL;
478
gchar *cResult = cairo_dock_launch_command_sync ("which audacious2");
410
// TODO: to check because I think that the class was audacious2 before and not audacious...
411
/*gchar *cResult = cairo_dock_launch_command_sync ("which audacious2");
479
412
if (cResult != NULL && *cResult == '/')
481
414
cd_debug ("MusicPlayer: Audacious2");
482
pAudacious->appclass = "audacious2";
483
pAudacious->launch = "audacious2";
415
pHandler->appclass = "audacious2";
416
pHandler->launch = "audacious2";
487
420
cd_debug ("MusicPlayer: Audacious (without 2)");
488
pAudacious->appclass = "audacious"; // now it's without this '2'
489
pAudacious->launch = "audacious";
421
pHandler->appclass = "audacious"; // now it's without this '2'
422
pHandler->launch = "audacious";
492
pAudacious->name = "Audacious";
493
pAudacious->cMprisService = "org.mpris.audacious";
494
pAudacious->iPlayer = MP_AUDACIOUS;
495
pAudacious->bSeparateAcquisition = FALSE; // inutile de threader.
496
pAudacious->iPlayerControls = PLAYER_PREVIOUS | PLAYER_PLAY_PAUSE | PLAYER_NEXT | PLAYER_STOP | PLAYER_JUMPBOX | PLAYER_SHUFFLE | PLAYER_REPEAT | PLAYER_ENQUEUE;
497
pAudacious->iLevel = PLAYER_GOOD; // n'a besoin d'une boucle que pour afficher le temps ecoule.
499
cd_musicplayer_register_my_handler(pAudacious, "audacious");
425
pHandler->appclass = "audacious"; // desktop file is audasious2.desktop, and command is audacious2, but audacious also exists, and the class is Audacious ... this is really not serious.
426
pHandler->launch = "audacious";
427
pHandler->cMprisService = "org.mpris.audacious";
428
pHandler->bSeparateAcquisition = FALSE;
429
pHandler->iPlayerControls = PLAYER_PREVIOUS | PLAYER_PLAY_PAUSE | PLAYER_NEXT | PLAYER_STOP | PLAYER_JUMPBOX | PLAYER_SHUFFLE | PLAYER_REPEAT | PLAYER_ENQUEUE;
430
pHandler->iLevel = PLAYER_GOOD;
432
pHandler->cMprisService = "org.mpris.audacious";
433
pHandler->path = "/Player";
434
pHandler->interface = "org.freedesktop.MediaPlayer";
435
pHandler->path2 = "/TrackList";
436
pHandler->interface2 = "org.freedesktop.MediaPlayer";
438
cd_musicplayer_register_my_handler(pHandler);