~ubuntu-branches/ubuntu/saucy/cairo-dock-plug-ins/saucy

« back to all changes in this revision

Viewing changes to musicPlayer/src/applet-mpris2.c

Tags: upstream-3.0.0.0beta1
ImportĀ upstreamĀ versionĀ 3.0.0.0beta1

Show diffs side-by-side

added added

removed removed

Lines of Context:
144
144
        
145
145
        CD_APPLET_LEAVE ();
146
146
}
147
 
static void cd_mpris2_getPlaying_async (void)  // used by Audacious.
 
147
static void cd_mpris2_getPlaying_async (void)
148
148
{
149
149
        if (s_pGetStatusCall != NULL)
150
150
                return;
190
190
        }
191
191
}
192
192
 
 
193
/*static gboolean _can_control (void)
 
194
{
 
195
        return cairo_dock_dbus_get_property_as_int (myData.dbus_proxy_player, "org.mpris.MediaPlayer2.Player", "CanControl");
 
196
}*/
 
197
 
 
198
static double cd_mpris2_get_volume (void)
 
199
{
 
200
        return cairo_dock_dbus_get_property_as_double (myData.dbus_proxy_player, "org.mpris.MediaPlayer2.Player", "Volume");
 
201
}
 
202
 
193
203
static gboolean _extract_metadata (GHashTable *pMetadata)
194
204
{
195
205
        gboolean bTrackHasChanged = FALSE;
275
285
        {
276
286
                cCoverPath = g_value_get_string(v);
277
287
        }
278
 
        cd_musicplayer_get_cover_path (cCoverPath, TRUE); // did it at the end (we have to know the artist and the album if (cCoverPath == NULL))
 
288
        cd_musicplayer_set_cover_path (cCoverPath);  // do it at the end (we have to know the artist and the album if (cCoverPath == NULL))
279
289
 
280
290
        /// we miss iTrackListIndex and tracklist-length ...
281
291
        
334
344
                myData.cover_exist = FALSE;
335
345
        }
336
346
        
337
 
        cd_musicplayer_update_icon (TRUE);
 
347
        cd_musicplayer_update_icon ();
338
348
        cd_musicplayer_relaunch_handler ();
339
349
        
340
350
        CD_APPLET_LEAVE ();
366
376
        if (strcmp (cInterface, "org.mpris.MediaPlayer2.Player") == 0)
367
377
        {
368
378
                v = g_hash_table_lookup (pChangedProps, "PlaybackStatus");
369
 
                if (v != NULL && G_VALUE_HOLDS_STRING (v))
 
379
                if (v != NULL && G_VALUE_HOLDS_STRING (v))  // status has changed
370
380
                {
371
381
                        const gchar *cStatus = g_value_get_string (v);  // "Playing", "Paused" or "Stopped"
372
382
                        myData.iPlayingStatus = _extract_status (cStatus);
375
385
                        if (myData.iPlayingStatus == PLAYER_PLAYING)  // le handler est stoppe lorsque le lecteur ne joue rien.
376
386
                                cd_musicplayer_relaunch_handler ();
377
387
                        
378
 
                        if (! myData.cover_exist && (myData.cPlayingUri != NULL || myData.cTitle != NULL))
379
 
                        {
380
 
                                cd_musicplayer_set_surface (myData.iPlayingStatus);
381
 
                                cd_debug ("cover (%d), cPlayingUri (%s), cTitle (%s)", myData.cover_exist, myData.cPlayingUri, myData.cTitle);
382
 
                        }
383
 
                        else
384
 
                        {
385
 
                                CD_APPLET_REDRAW_MY_ICON;
386
 
                        }
 
388
                        cd_musicplayer_update_icon ();
387
389
                }
388
390
                
389
391
                v = g_hash_table_lookup (pChangedProps, "Metadata");
392
394
                        GHashTable *pMetadata = g_value_get_boxed (v);
393
395
                        gboolean bTrackHasChanged = _extract_metadata (pMetadata);
394
396
                        
395
 
                        if (bTrackHasChanged)
 
397
                        if (bTrackHasChanged)  // new song (song changed or started playing)
396
398
                        {
397
399
                                myData.iPlayingStatus = PLAYER_PLAYING;  // pour les lecteurs bugues comme Exaile qui envoit un statut "stop" au changement de musique sans envoyer de status "play" par la suite. On considere donc que si le lecteur joue une nouvelle musique, c'est qu'il est en "play".
398
 
                                cd_musicplayer_update_icon (TRUE);
 
400
                                cd_musicplayer_update_icon ();
399
401
                        }
400
 
                        else if (myData.iPlayingStatus == PLAYER_STOPPED)
401
 
                                cd_musicplayer_update_icon (TRUE); // Force the update of the icon if the player is now stopped.
402
402
                }
403
403
        }
404
 
        else /*if (strcmp (cInterface, "org.mpris.MediaPlayer2.TrackList") == 0)
 
404
        /*else if (strcmp (cInterface, "org.mpris.MediaPlayer2.TrackList") == 0)
405
405
        {
406
406
                
407
407
        }*/
 
408
        else
408
409
                cd_debug ("Another interface: %s", cInterface);
409
410
}
410
411
 
437
438
 */
438
439
static void cd_mpris2_control (MyPlayerControl pControl, const char* song)
439
440
{
 
441
        static GValue s_pValue = G_VALUE_INIT;
440
442
        gboolean bToggleValue;
441
443
        switch (pControl)
442
444
        {
466
468
                case PLAYER_SHUFFLE :
467
469
                        bToggleValue = cd_mpris2_is_shuffle ();
468
470
                        cd_debug ("SetRandom <- %d\n", !bToggleValue);
469
 
                        dbus_g_proxy_call_no_reply (myData.dbus_proxy_player, "Set",
470
 
                                G_TYPE_INVALID,
471
 
                                G_TYPE_STRING, "org.mpris.MediaPlayer2.Player",
472
 
                                G_TYPE_STRING, "Shuffle",
473
 
                                G_TYPE_BOOLEAN, !bToggleValue,
474
 
                                G_TYPE_INVALID);
 
471
                        g_value_init (&s_pValue, G_TYPE_BOOLEAN);
 
472
                        g_value_set_boolean (&s_pValue, !bToggleValue);
 
473
                        cairo_dock_dbus_set_property (myData.dbus_proxy_player, "org.mpris.MediaPlayer2.Player", "Shuffle", &s_pValue);
 
474
                        g_value_unset (&s_pValue);
475
475
                break;
476
476
                
477
477
                case PLAYER_REPEAT :
478
478
                        bToggleValue = cd_mpris2_is_loop ();
479
479
                        cd_debug ("SetLoop <- %d\n", !bToggleValue);
480
 
                        dbus_g_proxy_call_no_reply (myData.dbus_proxy_player, "Set",
481
 
                                G_TYPE_INVALID,
482
 
                                G_TYPE_STRING, "org.mpris.MediaPlayer2.Player",
483
 
                                G_TYPE_STRING, "LoopStatus",
484
 
                                G_TYPE_STRING, (bToggleValue ? "None" : "Playlist"),
485
 
                                G_TYPE_INVALID);
 
480
                        g_value_init (&s_pValue, G_TYPE_STRING);
 
481
                        g_value_set_static_string (&s_pValue, bToggleValue ? "None" : "Playlist");
 
482
                        cairo_dock_dbus_set_property (myData.dbus_proxy_player, "org.mpris.MediaPlayer2.Player", "LoopStatus", &s_pValue);
 
483
                        g_value_unset (&s_pValue);
486
484
                break;
487
485
                
488
486
                case PLAYER_ENQUEUE :
512
510
                }
513
511
                break;
514
512
                
 
513
                case PLAYER_VOLUME :
 
514
                {
 
515
                        double fVolume = cd_mpris2_get_volume ();  // [0, 1]
 
516
                        if (song && strcmp (song, "up") == 0)
 
517
                                fVolume += .05;
 
518
                        else
 
519
                                fVolume -= .05;
 
520
                        cd_debug ("volume <- %f\n", fVolume);
 
521
                        g_value_init (&s_pValue, G_TYPE_DOUBLE);
 
522
                        g_value_set_double (&s_pValue, fVolume);
 
523
                        cairo_dock_dbus_set_property (myData.dbus_proxy_player, "org.mpris.MediaPlayer2.Player", "Volume", &s_pValue);
 
524
                        g_value_unset (&s_pValue);
 
525
                }
 
526
                
515
527
                default :
516
528
                break;
517
529
        }
632
644
        
633
645
        pHandler->appclass = NULL;  // will be filled later.
634
646
        pHandler->launch = NULL;  // will be filled later.
635
 
        pHandler->iPlayerControls = PLAYER_PREVIOUS | PLAYER_PLAY_PAUSE | PLAYER_NEXT | PLAYER_STOP | PLAYER_SHUFFLE | PLAYER_REPEAT | PLAYER_ENQUEUE;
 
647
        pHandler->iPlayerControls = PLAYER_PREVIOUS | PLAYER_PLAY_PAUSE | PLAYER_NEXT | PLAYER_STOP | PLAYER_SHUFFLE | PLAYER_REPEAT | PLAYER_ENQUEUE | PLAYER_VOLUME;
636
648
        cd_musicplayer_register_my_handler (pHandler);
637
649
}