~ubuntu-branches/ubuntu/oneiric/cairo-dock-plug-ins/oneiric-updates

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Matthieu Baerts (matttbe), Matthieu Baerts (matttbe), Iain Lane
  • Date: 2011-10-09 00:19:16 UTC
  • mfrom: (1.1.15 upstream)
  • Revision ID: james.westby@ubuntu.com-20111009001916-9czstskx2t6l0b3x
Tags: 2.4.0~2-0ubuntu1
[ Matthieu Baerts (matttbe) ]
* New upstream bug fix release. (LP: #859984)
* Upstream (short) ChangeLog (2.4.0~0beta2 -> 2.4.0~1):
 - Powermanager: correctly release the reference on the device object
 - logout: now works if there is no session-manager
 - Status-Notifier: fixed a small bug
    (wrong callback in cairo_dock_stop_watching_dbus_name_owner)
 - Folders: fixed the positionning of the new icon
    and the dialog when dropping a folder inside the dock
    and fixed the icon-rendering
 - Dustbin: use the default theme if no icon is found
 - Impulse: the default context seems to be ok and not an error
 - Status-Notifier: On Ubuntu Oneiric (with indicator-0.4)
    the ApplicationAdded signal has changed and has a new parameter
 - Disable MeMenu on Oneiric (no longer available with indicator-0.4)
 - CMakeLists.txt: Improved output messages
 - Slide view: fixed a small offset in vertical view
 - musicPlayer:
  + split MPRIS 1.0 and 2.0 to help debugging and finding the right
     name of the bug.
  + 'rhythmbox-client' tool is no longer available: used MPRIS
  + Disable Amazon service (it no longer work)
  + Cover: fixed corrupted icons: some players (e.g. the latest version
     of RB) copy covers on their cache forlder but it takes a few time.
  + Fixed the update the icon and its name if the player is stopped.
  + Prevent a crash if the name given by MPRIS is NULL
 - Powermanager: try to prevent to have a few dialogues at the same time
 - PowerManager and AlsaMixer: hidden gnome2 or 3 apps if not available
 - Messaging-Menu: Updated for Natty and Oneiric
    (dbus-menu gives us GVariant instead of GValue objects)
 - Alsamixer: fixed a small bug on reload
 - Dbus: Bash interface: Fixed a typo with emblem positions
 - Sys-monitor: fixed a bug which prevented from getting
    the CPU temperature in some cases
 - Compiz (0.9): type filter: replaced type=utility by type=Utility
 - Updated the version of all applets that have gauges
   in order to use the right directory
 - Wifi: Fixed the status if we are not connected
 - Dbus: removed a conflict with the Help applet
 - Messaging-Menu: updated applet-menu.c => Memory leaks on pixbufs
 - Dbus: Fixed a crash when changing dock theme if a 'third-party' applet
    is running
 - Netspeed: in /proc/net/dev, there are 8 values to drop after the card id
    except if there is whitespaces just after this ':' character
    and fixed order and value for ON_ICON display
 - dock-rendering/toto: removed a useless file
 - Clipper: fixed the loading of the remembered items
    (they had the wrong type) and fixed a bug if we reduce the list of items
 - Folders, dustbin, Network-Monitor: tried to not use cast if it's possible
 - Code cleaned and re-organised a few functions
   (e.g. emblem references has been renamed)
 - Removed useless files: powermanager-dbus*
 - Updating translations
 - Fixed a few warnings at the compilation
 - Removed a few useless output messages
 - Fixed these LP bugs:
  + Empty trash from the trashcan does not delete files
     from usb harddisks: LP: #658681
  + Switcher applet doesn't respect desktop numbers LP: #626782
* Upstream (short) ChangeLog (2.4.0~1 -> 2.4.0~2):
 - Messaging-Menu: fixed a wrong g_object_unref (double free)
    and a small memory leak
 - Folders: fixed a tiny warning at the compilation (32bits)
 - switcher: removed an unnecessary config parameter
 - Folders: file size: used English instead of French translation.
 - Indicator applet: Forced a cast to remove an annoying warning
    due to clumsy dbusmenu_gtkmenu_new() declaration
 - Fixed the detection of the screensaver
 - Fixed tiny warnings at the compilation (with CAIRO_CONTAINER)
* debian/control:
 - Updated the version of cairo-dock-[core;data;dev].
 - Added gvfs as 'Suggests' for cairo-dock-plug-ins-integration
    (Used for managing files)
 - Removed 'libthunar-vfs-1-dev' (libthunar-vfs is no longer installed
    by default since XFCE 4.8 and it is replaced by gvfs)
 - Removed 'indicator-me' (no longer available
    and the installation of Cairo-Dock produces an error)
 - Moved 'indicator-messages' to 'Recommends'
* debian/rules:
 - Updated the name of CMake extras flags
* debian/cairo-dock-plug-ins-data.lintian-overrides:
 - Deleted (now useless)
* debian/cairo-dock-plug-ins.lintian-overrides:
 - Cairo-Dock Plug-Ins are not linked to gldi
 - shlib-without-versioned-soname: forwarded to upstream.
* debian/cairo-dock-plug-ins-integration.lintian-overrides:
 - Cairo-Dock Plug-Ins are not linked to gldi
 - ldconfig and shlibs are not needed
* debian/cairo-dock-plug-ins.install:
 - Fixed lintian errors: package-installs-python-bytecode
* debian/control: Fixed lintian warnings:
 - python-script-but-no-python-dep
 - description-synopsis-starts-with-article
* debian/changelog:
 - Fixed lintian warning: old-fsf-address-in-copyright-file
* debian/patches/01-switcher-force-compact-view.patch: 
 - Forced the compact view because the other doesn't work

[ Iain Lane ]
* Fix Mono/CLI build to be ~policy compliant and use correct compiler

Show diffs side-by-side

added added

removed removed

Lines of Context:
93
93
76 <arg type="i" />
94
94
77 </signal>
95
95
78 </interface>
96
 
79 </node>
 
96
79 </node> 
97
97
 
98
98
service : org.mpris.audacious
99
99
interface : org.freedesktop.MediaPlayer
108
108
        GetStatus(int[4]: status:play=0,pause,stop shuffle=random no_playlist_advance repeat=loop)
109
109
        GetMetadata(hash: length title artist album genre codec quality track-number location)
110
110
        PositionGet(int=time_in_second)
111
 
 
 
111
        
112
112
        TrackChange(hash: idem)
113
113
        StatusChange(int[4])
114
114
 
146
146
                        myData.cArtist = g_strdup (str);
147
147
        }
148
148
        cd_message ("  cArtist <- %s", myData.cArtist);
149
 
 
 
149
        
150
150
        g_free (myData.cAlbum);
151
151
        myData.cAlbum = NULL;
152
152
        value = (GValue *) g_hash_table_lookup(data_list, "album");
157
157
                        myData.cAlbum = g_strdup (str);
158
158
        }
159
159
        cd_message ("  cAlbum <- %s", myData.cAlbum);
160
 
 
 
160
        
161
161
        g_free (myData.cTitle);
162
162
        myData.cTitle = NULL;
163
163
        value = (GValue *) g_hash_table_lookup(data_list, "title");
168
168
                        myData.cTitle = g_strdup (str);
169
169
        }
170
170
        cd_message ("  cTitle <- %s", myData.cTitle);
171
 
 
 
171
        
172
172
        value = (GValue *) g_hash_table_lookup(data_list, "tracknumber");
173
173
        if (value == NULL)
174
174
                value = (GValue *) g_hash_table_lookup(data_list, "track-number");  // old parameter.
177
177
        else
178
178
                myData.iTrackNumber = 0.;
179
179
        cd_message ("  iTrackNumber <- %d", myData.iTrackNumber);
180
 
 
 
180
        
181
181
        value = (GValue *) g_hash_table_lookup(data_list, "mtime");
182
182
        if (value == NULL)
183
183
                value = (GValue *) g_hash_table_lookup(data_list, "length");  // old parameter.
184
184
        if (value != NULL && G_VALUE_HOLDS_INT(value)) myData.iSongLength = g_value_get_int(value) / 1000;
185
185
        else myData.iSongLength = 0;
186
186
        cd_message ("  iSongLength <- %ds", myData.iSongLength);
187
 
 
 
187
        
188
188
        g_free (myData.cPlayingUri);
189
189
        value = (GValue *) g_hash_table_lookup(data_list, "location");
190
190
        if (value != NULL && G_VALUE_HOLDS_STRING(value)) myData.cPlayingUri = g_strdup (g_value_get_string(value));
191
191
        else myData.cPlayingUri = NULL;
192
192
        cd_message ("  cUri <- %s", myData.cPlayingUri);
193
 
 
 
193
        
194
194
        cd_musicplayer_get_cover_path (NULL, TRUE);
195
195
}
196
196
 
200
200
{
201
201
        GHashTable *data_list = NULL;
202
202
        const gchar *data;
203
 
 
 
203
                
204
204
        if(dbus_g_proxy_call (myData.dbus_proxy_player, "GetMetadata", NULL,
205
205
                G_TYPE_INVALID,
206
206
                MP_DBUS_TYPE_SONG_METADATA,
239
239
{
240
240
        CD_APPLET_ENTER;
241
241
        cd_debug ("MP : %s ()\n", __func__);
242
 
 
 
242
        
243
243
        if (metadata != NULL)
244
244
        {
245
245
                _extract_metadata (metadata);
246
246
                myData.iTrackListIndex = cairo_dock_dbus_get_integer (myData.dbus_proxy_shell, "GetCurrentTrack");
247
247
                myData.iTrackListLength = cairo_dock_dbus_get_integer (myData.dbus_proxy_shell, "GetLength");
248
 
                myData.bIsRunning = TRUE;
 
248
                myData.iPlayingStatus = PLAYER_PLAYING;  // the current song has changed, means we are playing, so let's update the status now, for the coming update_icon().
249
249
        }
250
250
        else
251
251
        {
262
262
                myData.iSongLength = 0;
263
263
                myData.iTrackNumber = 0;
264
264
                myData.cover_exist = FALSE;
265
 
 
266
 
                cd_musicplayer_dbus_detect_player ();
267
265
        }
268
266
        cd_musicplayer_update_icon (TRUE);
269
267
        CD_APPLET_LEAVE ();
274
272
// Definition du backend. //
275
273
////////////////////////////
276
274
 
277
 
/* Fonction de connexion au bus de audacious.
278
 
 */
279
 
static gboolean _cd_audacious_dbus_connect_to_bus (void)
280
 
{
281
 
        if (cairo_dock_dbus_is_enabled ())
282
 
        {
283
 
                myData.dbus_enable = cd_musicplayer_dbus_connect_to_bus (); // cree le proxy.
284
 
 
285
 
                myData.dbus_enable_shell = musicplayer_dbus_connect_to_bus_Shell ();  // cree le proxy pour la 2eme interface car AU en a 2.
286
 
 
287
 
                dbus_g_proxy_add_signal(myData.dbus_proxy_player, "StatusChange",
288
 
                        MP_DBUS_TYPE_PLAYER_STATUS_MPRIS,
289
 
                        G_TYPE_INVALID);
290
 
                dbus_g_proxy_connect_signal(myData.dbus_proxy_player, "StatusChange",
291
 
                        G_CALLBACK(onChangePlaying_mpris), NULL, NULL);
292
 
 
293
 
                dbus_g_proxy_add_signal(myData.dbus_proxy_player, "TrackChange",
294
 
                        MP_DBUS_TYPE_SONG_METADATA,
295
 
                        G_TYPE_INVALID);
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.
298
 
 
299
 
                return TRUE;
300
 
        }
301
 
        return FALSE;
302
 
}
303
 
 
304
 
/* Permet de libérer la mémoire prise par le backend.
305
 
 */
306
 
static void cd_audacious_free_data (void)
307
 
{
308
 
        if (myData.dbus_proxy_player != NULL)
309
 
        {
310
 
                dbus_g_proxy_disconnect_signal(myData.dbus_proxy_player, "StatusChange",
311
 
                        G_CALLBACK(onChangePlaying_mpris), NULL);
312
 
 
313
 
                dbus_g_proxy_disconnect_signal(myData.dbus_proxy_player, "TrackChange",
314
 
                        G_CALLBACK(onChangeSong), NULL);
315
 
        }
316
 
 
317
 
        musicplayer_dbus_disconnect_from_bus();
318
 
        musicplayer_dbus_disconnect_from_bus_Shell();
319
 
}
320
 
 
321
 
 
322
275
/* Controle du lecteur (permet d'effectuer les actions de bases sur le lecteur).
323
276
 */
324
277
static void cd_audacious_control (MyPlayerControl pControl, const char* song)
325
278
{
326
279
        const gchar *cCommand = NULL;
327
 
 
 
280
                
328
281
        switch (pControl) {
329
282
                case PLAYER_PREVIOUS :
330
283
                        cCommand = "Prev";
331
284
                break;
332
 
 
 
285
                
333
286
                case PLAYER_STOP :
334
287
                        cCommand = "Stop";
335
288
                break;
336
 
 
 
289
                
337
290
                case PLAYER_PLAY_PAUSE :
338
291
                        if (myData.iPlayingStatus != PLAYER_PLAYING)
339
292
                                cCommand = "Play";
344
297
                case PLAYER_NEXT :
345
298
                        cCommand = "Next";
346
299
                break;
347
 
 
 
300
                
348
301
                case PLAYER_JUMPBOX :
349
302
                case PLAYER_SHUFFLE :
350
303
                case PLAYER_REPEAT :
351
304
                {
352
 
 
 
305
                        
353
306
                        DBusGProxy *dbus_proxy_atheme = cairo_dock_create_new_session_proxy (
354
307
                                "org.atheme.audacious",
355
308
                                "/org/atheme/audacious",
381
334
                                cd_warning ("org.atheme.audacious not valid !");
382
335
                }
383
336
                break;
384
 
 
 
337
                
385
338
                case PLAYER_ENQUEUE :
386
339
                        cd_debug ("enqueue %s\n", song);
387
340
                        dbus_g_proxy_call_no_reply (myData.dbus_proxy_shell, "AddTrack",
390
343
                                G_TYPE_BOOLEAN, FALSE,
391
344
                                G_TYPE_INVALID);
392
345
                break;
393
 
 
 
346
                
394
347
                default :
395
348
                        return;
396
349
                break;
397
350
        }
398
 
 
399
 
        if (cCommand != NULL)
 
351
        
 
352
        if (cCommand != NULL) 
400
353
        {
401
354
                cd_debug ("MP : Handler audacious : will use '%s'", cCommand);
402
355
                cairo_dock_dbus_call (myData.dbus_proxy_player, cCommand);
406
359
 
407
360
/* Recupere le temps ecoule chaque seconde (pas de signal pour ca).
408
361
 */
409
 
static void cd_audacious_read_data (void)
 
362
static void cd_audacious_get_data (void)
410
363
{
411
 
        if (myData.dbus_enable)
 
364
        if (myData.iPlayingStatus == PLAYER_PLAYING)
412
365
        {
413
 
                if (myData.bIsRunning)
414
 
                {
415
 
                        if (myData.iPlayingStatus == PLAYER_PLAYING)
416
 
                        {
417
 
                                ///_audacious_get_time_elapsed ();
418
 
                                cd_mpris_get_time_elapsed ();
419
 
                                if (myData.iCurrentTime < 0)
420
 
                                        myData.iPlayingStatus = PLAYER_STOPPED;
421
 
                        }
422
 
                        else if (myData.iPlayingStatus != PLAYER_PAUSED)  // en pause le temps reste constant.
423
 
                                myData.iCurrentTime = 0;
424
 
                }
425
 
                else
426
 
                {
427
 
                        myData.iCurrentTime = 0;
428
 
                }
429
 
                cd_message (" myData.iCurrentTime <- %d", myData.iCurrentTime);
 
366
                cd_mpris_get_time_elapsed ();
 
367
                if (myData.iCurrentTime < 0)
 
368
                        myData.iPlayingStatus = PLAYER_STOPPED;
430
369
        }
 
370
        else if (myData.iPlayingStatus != PLAYER_PAUSED)  // en pause le temps reste constant.
 
371
                myData.iCurrentTime = 0;
431
372
}
432
373
 
433
374
/* Initialise le backend de AU.
434
375
 */
435
 
static void cd_audacious_configure (void)
 
376
static void cd_audacious_start (void)
436
377
{
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,
 
381
                G_TYPE_INVALID);
 
382
        dbus_g_proxy_connect_signal(myData.dbus_proxy_player, "StatusChange",
 
383
                G_CALLBACK(onChangePlaying_mpris), NULL, NULL);
442
384
 
443
 
        myData.dbus_enable = _cd_audacious_dbus_connect_to_bus ();  // se connecte au bus et aux signaux de AU.
444
 
        if (myData.dbus_enable)
445
 
        {
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.
448
 
                {
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);
454
 
                }
455
 
                else  // player eteint.
456
 
                {
457
 
                        cd_musicplayer_set_surface (PLAYER_NONE);
458
 
                }
459
 
        }
460
 
        else  // sinon on signale par l'icone appropriee que le bus n'est pas accessible.
461
 
        {
462
 
                cd_musicplayer_set_surface (PLAYER_BROKEN);
463
 
        }
 
385
        dbus_g_proxy_add_signal(myData.dbus_proxy_player, "TrackChange",
 
386
                MP_DBUS_TYPE_SONG_METADATA,
 
387
                G_TYPE_INVALID);
 
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.
 
390
        
 
391
        // get the current state.
 
392
        cd_mpris_getPlaying ();  ///_audacious_getPlaying_mpris ();
 
393
        cd_audacious_getSongInfos ();
 
394
        cd_musicplayer_update_icon (TRUE);
464
395
}
465
396
 
466
397
/* On enregistre notre lecteur.
467
398
 */
468
399
void cd_musicplayer_register_audacious_handler (void)
469
400
{
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;
477
409
 
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 == '/')
480
413
        {
481
414
                cd_debug ("MusicPlayer: Audacious2");
482
 
                pAudacious->appclass = "audacious2";
483
 
                pAudacious->launch = "audacious2";
 
415
                pHandler->appclass = "audacious2";
 
416
                pHandler->launch = "audacious2";
484
417
        }
485
418
        else
486
419
        {
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";
490
423
        }
491
 
        g_free (cResult);
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.
498
 
 
499
 
        cd_musicplayer_register_my_handler(pAudacious, "audacious");
 
424
        g_free (cResult);*/
 
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;
 
431
        
 
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";
 
437
        
 
438
        cd_musicplayer_register_my_handler(pHandler);
500
439
}