~ubuntu-branches/ubuntu/quantal/cairo-dock-plug-ins/quantal-201208191523

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Matthieu Baerts (matttbe)
  • Date: 2010-08-10 00:05:57 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20100810000557-pfxoz5w7hbyclcqh
Tags: 2.2.0~0beta4-0ubuntu1
* New Upstream Version (LP: #614625)
* Fixed a few bugs on LP:
 - LP: #483963: Dustbin applet does not display trashes on all volumes
 - LP: #485159: Some apps have problem with Systray
 - LP: #500677: ~/.xsession-errors is too much used by CD
 - LP: #500979: Shortcuts: the order gets messed up
 - LP: #521531: Mail: crashes on Maildir
 - LP: #519915: GTG: create a new applet to control GTG
 - LP: #526138: GMenu doesn't handle desktop file exec strings properly
 - LP: #531317: CMake: Added an error if the prefix of 'cairo-dock-plugins'
                 is not the same 'cairo-dock-core'
 - LP: #531319: CMake: check the version of 'cairo-dock' when building
                 'cairo-dock-plugins'
 - LP: #537115: Click at the position where icon lavel was, the icon
                 and dock still receive the event
 - LP: #537943: Terminal applet shortkey behaviour
 - LP: #538637: Trash applet doesn't create .trashinfo files on XFCE
 - More details on the 'ChangeLog' file
* debian/rules:
 - Autotools has been replaced by CMake
 - cdbs is now used.
* debian/copyright:
 - Updated with the new applets
* debian/control:
 - Autotools has been replaced by CMake
 - Added libcurl4-gnutls-dev, libindicator-dev, libdbusmenu-glib-dev
   libido-0.1-dev, libical-dev, libdbusmenu-gtk-dev as Build-deps
 - Bump Standard-Version to 3.9.1
 - Wget is required for dnd2share applet
 - Added the exact realease for 'cairo-dock-dev' in order to prevent any
    build error if this package is not already available (thx to didrocks)
* debian/cairo-dock-plug-ins*.install:
 - All sonames are now installed into lib32 or lib64 (lib*)

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
#include "applet-dbus.h"
29
29
#include "applet-draw.h"
30
30
#include "applet-cover.h"
 
31
#include "applet-mpris.h"
31
32
#include "applet-audacious.h"
32
33
 
33
34
#define MP_DBUS_TYPE_PLAYER_STATUS_MPRIS (dbus_g_type_get_struct ("GValueArray", G_TYPE_INT, G_TYPE_INT, G_TYPE_INT, G_TYPE_INT, G_TYPE_INVALID))
34
35
#define MP_DBUS_TYPE_PLAYER_STATUS G_TYPE_INT
35
36
 
36
 
gboolean bMpris = FALSE;
37
 
 
38
37
/*
39
38
<node name="/Player">
40
39
22 <interface name="org.freedesktop.MediaPlayer">
132
131
/////////////////////////////////
133
132
// Les Fonctions propres a AU. //
134
133
/////////////////////////////////
135
 
static inline void _extract_playing_status_mpris (GValueArray *status)
136
 
{
137
 
        cd_debug ("%s ()\n", __func__);
138
 
        int iStatus = -1;
139
 
        GValue *value = g_value_array_get_nth (status, 0);
140
 
        if (value != NULL && G_VALUE_HOLDS_INT(value))
141
 
                iStatus = g_value_get_int (value);
142
 
        else
143
 
                cd_warning ("value : %x doesn't hold an int\n", value);
144
 
        cd_debug (" => iStatus : %d\n", iStatus);
145
 
        
146
 
        switch (iStatus)
147
 
        {
148
 
                case 0:
149
 
                        myData.iPlayingStatus = PLAYER_PLAYING;
150
 
                break;
151
 
                case 1:
152
 
                        myData.iPlayingStatus = PLAYER_PAUSED;
153
 
                break;
154
 
                case 2:
155
 
                default:
156
 
                        myData.iPlayingStatus = PLAYER_STOPPED;
157
 
                break;
158
 
        }
159
 
}
160
 
static inline void _extract_playing_status (gint status)
161
 
{
162
 
        cd_debug ("%s ()\n", __func__);
163
 
        int iStatus = status;
164
 
        cd_debug (" => iStatus : %d\n", iStatus);
165
 
        
166
 
        switch (iStatus)
167
 
        {
168
 
                case 0:
169
 
                        myData.iPlayingStatus = PLAYER_PLAYING;
170
 
                break;
171
 
                case 1:
172
 
                        myData.iPlayingStatus = PLAYER_PAUSED;
173
 
                break;
174
 
                case 2:
175
 
                default:
176
 
                        myData.iPlayingStatus = PLAYER_STOPPED;
177
 
                break;
178
 
        }
179
 
}
180
 
 
181
 
 
182
 
/* Teste si Audacious joue de la musique ou non
183
 
 */
184
 
static void _audacious_getPlaying_mpris (void)
185
 
{
186
 
        cd_debug ("%s ()\n", __func__);
187
 
        GError *erreur = NULL;
188
 
        GValueArray *status;
189
 
        dbus_g_proxy_call (myData.dbus_proxy_player, "GetStatus", &erreur,  // Audacious's GetStatus() does not comply with MPRIS spec, it returns a single Int32
190
 
                G_TYPE_INVALID,
191
 
                MP_DBUS_TYPE_PLAYER_STATUS_MPRIS, &status,
192
 
                G_TYPE_INVALID);
193
 
        if (erreur != NULL)
194
 
        {
195
 
                cd_warning (erreur->message);
196
 
                g_error_free (erreur);
197
 
                myData.iPlayingStatus = PLAYER_NONE;
198
 
        }
199
 
        else
200
 
        {
201
 
                _extract_playing_status_mpris (status);
202
 
        }
203
 
}
204
 
static void _audacious_getPlaying (void)
205
 
{
206
 
        cd_debug ("%s ()\n", __func__);
207
 
        GError *erreur = NULL;
208
 
        gint status;
209
 
        dbus_g_proxy_call (myData.dbus_proxy_player, "GetStatus", &erreur,  // Audacious's GetStatus() does not comply with MPRIS spec, it returns a single Int32
210
 
                G_TYPE_INVALID,
211
 
                MP_DBUS_TYPE_PLAYER_STATUS, &status,
212
 
                G_TYPE_INVALID);
213
 
        if (erreur != NULL)
214
 
        {
215
 
                cd_warning (erreur->message);
216
 
                g_error_free (erreur);
217
 
                myData.iPlayingStatus = PLAYER_NONE;
218
 
        }
219
 
        else
220
 
        {
221
 
                _extract_playing_status (status);
222
 
        }
223
 
}
224
 
 
225
 
 
226
 
/* Renvoie le temps ecoule en secondes..
227
 
 */
228
 
static void _audacious_get_time_elapsed (void)
229
 
{
230
 
        myData.iCurrentTime = cairo_dock_dbus_get_integer (myData.dbus_proxy_player, "PositionGet") / 1000;
231
 
        //cd_debug ("myData.iCurrentTime <- %d\n", myData.iCurrentTime);
232
 
}
233
 
 
234
134
 
235
135
static inline void _extract_metadata (GHashTable *data_list)
236
136
{
269
169
        }
270
170
        cd_message ("  cTitle <- %s", myData.cTitle);
271
171
        
272
 
        value = (GValue *) g_hash_table_lookup(data_list, "track-number");
 
172
        value = (GValue *) g_hash_table_lookup(data_list, "tracknumber");
273
173
        if (value == NULL)
274
 
                value = (GValue *) g_hash_table_lookup(data_list, "tracknumber");
 
174
                value = (GValue *) g_hash_table_lookup(data_list, "track-number");  // old parameter.
275
175
        if (value != NULL && G_VALUE_HOLDS_INT(value))
276
176
                myData.iTrackNumber = g_value_get_int(value);
277
177
        else
278
 
                myData.iTrackNumber = cairo_dock_dbus_get_integer (myData.dbus_proxy_shell, "GetCurrentTrack");
 
178
                myData.iTrackNumber = 0.;
279
179
        cd_message ("  iTrackNumber <- %d", myData.iTrackNumber);
280
180
        
281
 
        value = (GValue *) g_hash_table_lookup(data_list, "length");
 
181
        value = (GValue *) g_hash_table_lookup(data_list, "mtime");
 
182
        if (value == NULL)
 
183
                value = (GValue *) g_hash_table_lookup(data_list, "length");  // old parameter.
282
184
        if (value != NULL && G_VALUE_HOLDS_INT(value)) myData.iSongLength = g_value_get_int(value) / 1000;
283
185
        else myData.iSongLength = 0;
284
186
        cd_message ("  iSongLength <- %ds", myData.iSongLength);
294
196
 
295
197
/* Recupere les infos de la chanson courante, y compris le chemin de la couverture (la telecharge au besoin).
296
198
 */
297
 
static void cd_audacious_getSongInfos ()
 
199
static void cd_audacious_getSongInfos (void)
298
200
{
299
201
        GHashTable *data_list = NULL;
300
202
        const gchar *data;
306
208
                G_TYPE_INVALID))
307
209
        {
308
210
                _extract_metadata (data_list);
309
 
                
 
211
                myData.iTrackListIndex = cairo_dock_dbus_get_integer (myData.dbus_proxy_shell, "GetCurrentTrack");
 
212
                myData.iTrackListLength = cairo_dock_dbus_get_integer (myData.dbus_proxy_shell, "GetLength");
310
213
                g_hash_table_destroy (data_list);
311
214
        }
312
215
        else
340
243
        if (metadata != NULL)
341
244
        {
342
245
                _extract_metadata (metadata);
 
246
                myData.iTrackListIndex = cairo_dock_dbus_get_integer (myData.dbus_proxy_shell, "GetCurrentTrack");
 
247
                myData.iTrackListLength = cairo_dock_dbus_get_integer (myData.dbus_proxy_shell, "GetLength");
343
248
                myData.bIsRunning = TRUE;
344
249
        }
345
250
        else
364
269
        CD_APPLET_LEAVE ();
365
270
}
366
271
 
367
 
/* Fonction executée à chaque changement play/pause
368
 
 */
369
 
static void onChangePlaying_mpris (DBusGProxy *player_proxy, GValueArray *status, gpointer data)
370
 
{
371
 
        CD_APPLET_ENTER;
372
 
        cd_debug ("MP : %s (%x)\n", __func__, status);
373
 
        myData.bIsRunning = TRUE;
374
 
        _extract_playing_status_mpris (status);
375
 
        
376
 
        if(! myData.cover_exist && (myData.cPlayingUri != NULL || myData.cTitle != NULL))
377
 
        {
378
 
                cd_musicplayer_set_surface (myData.iPlayingStatus);
379
 
        }
380
 
        else
381
 
        {
382
 
                CD_APPLET_REDRAW_MY_ICON;
383
 
        }
384
 
        CD_APPLET_LEAVE ();
385
 
}
386
 
static void onChangePlaying(DBusGProxy *player_proxy, gint status, gpointer data)
387
 
{
388
 
        CD_APPLET_ENTER;
389
 
        cd_debug ("MP : %s (%d)\n", __func__, status);
390
 
        myData.bIsRunning = TRUE;
391
 
        //_extract_playing_status (status);
392
 
        
393
 
        _audacious_getPlaying_mpris ();  // Audacious 2.1 is buggy, the signal marshaller doesn't comply with MPRIS but the "get" function does, so we use it to get the status when we receive the signal.
394
 
        
395
 
        if (myData.iPlayingStatus == PLAYER_PLAYING)
396
 
                cd_musicplayer_relaunch_handler ();
397
 
        if(! myData.cover_exist && myData.cPlayingUri != NULL)
398
 
        {
399
 
                cd_musicplayer_set_surface (myData.iPlayingStatus);
400
 
        }
401
 
        else
402
 
        {
403
 
                CD_APPLET_REDRAW_MY_ICON;
404
 
        }
405
 
        CD_APPLET_LEAVE ();
406
 
}
407
 
 
408
 
 
409
272
 
410
273
////////////////////////////
411
274
// Definition du backend. //
415
278
 */
416
279
static gboolean _cd_audacious_dbus_connect_to_bus (void)
417
280
{
418
 
        if (cairo_dock_bdus_is_enabled ())
 
281
        if (cairo_dock_dbus_is_enabled ())
419
282
        {
420
283
                myData.dbus_enable = cd_musicplayer_dbus_connect_to_bus (); // cree le proxy.
421
284
                
422
285
                myData.dbus_enable_shell = musicplayer_dbus_connect_to_bus_Shell ();  // cree le proxy pour la 2eme interface car AU en a 2.
423
286
                
424
 
                if (bMpris)
425
 
                {
426
 
                        dbus_g_proxy_add_signal(myData.dbus_proxy_player, "StatusChange",
427
 
                                MP_DBUS_TYPE_PLAYER_STATUS_MPRIS,
428
 
                                G_TYPE_INVALID);
429
 
                        dbus_g_proxy_connect_signal(myData.dbus_proxy_player, "StatusChange",
430
 
                                G_CALLBACK(onChangePlaying_mpris), NULL, NULL);
431
 
                }
432
 
                else  // buggy version (2.1), the signal marshaller is wrong, but is sent correctly.
433
 
                {
434
 
                        dbus_g_proxy_add_signal(myData.dbus_proxy_player, "StatusChange",
435
 
                                MP_DBUS_TYPE_PLAYER_STATUS,
436
 
                                G_TYPE_INVALID);
437
 
                        dbus_g_proxy_connect_signal(myData.dbus_proxy_player, "StatusChange",
438
 
                                G_CALLBACK(onChangePlaying), NULL, NULL);
439
 
                }
 
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);
440
292
                
441
293
                dbus_g_proxy_add_signal(myData.dbus_proxy_player, "TrackChange",
442
294
                        MP_DBUS_TYPE_SONG_METADATA,
443
295
                        G_TYPE_INVALID);
444
296
                dbus_g_proxy_connect_signal(myData.dbus_proxy_player, "TrackChange",
445
 
                        G_CALLBACK(onChangeSong), NULL, NULL);
 
297
                        G_CALLBACK(onChangeSong), NULL, NULL);  // pas de TrackListChange, donc on fera tout dedans.
446
298
                
447
299
                return TRUE;
448
300
        }
455
307
{
456
308
        if (myData.dbus_proxy_player != NULL)
457
309
        {
458
 
                if (bMpris)
459
 
                        dbus_g_proxy_disconnect_signal(myData.dbus_proxy_player, "StatusChange",
460
 
                                G_CALLBACK(onChangePlaying_mpris), NULL);
461
 
                else
462
 
                        dbus_g_proxy_disconnect_signal(myData.dbus_proxy_player, "StatusChange",
463
 
                                G_CALLBACK(onChangePlaying), NULL);
464
 
                        
 
310
                dbus_g_proxy_disconnect_signal(myData.dbus_proxy_player, "StatusChange",
 
311
                        G_CALLBACK(onChangePlaying_mpris), NULL);
 
312
                
465
313
                dbus_g_proxy_disconnect_signal(myData.dbus_proxy_player, "TrackChange",
466
314
                        G_CALLBACK(onChangeSong), NULL);
467
315
        }
501
349
                case PLAYER_SHUFFLE :
502
350
                case PLAYER_REPEAT :
503
351
                {
 
352
                        
504
353
                        DBusGProxy *dbus_proxy_atheme = cairo_dock_create_new_session_proxy (
505
354
                                "org.atheme.audacious",
506
355
                                "/org/atheme/audacious",
565
414
                {
566
415
                        if (myData.iPlayingStatus == PLAYER_PLAYING)
567
416
                        {
568
 
                                _audacious_get_time_elapsed ();
 
417
                                ///_audacious_get_time_elapsed ();
 
418
                                cd_mpris_get_time_elapsed ();
569
419
                                if (myData.iCurrentTime < 0)
570
420
                                        myData.iPlayingStatus = PLAYER_STOPPED;
571
421
                        }
597
447
                if(myData.bIsRunning)  // player en cours d'execution, on recupere son etat.
598
448
                {
599
449
                        cd_debug ("MP : AU is running\n");
600
 
                        _audacious_getPlaying_mpris ();
 
450
                        ///_audacious_getPlaying_mpris ();
 
451
                        cd_mpris_getPlaying ();
601
452
                        cd_audacious_getSongInfos ();
602
453
                        cd_musicplayer_update_icon (TRUE);
603
454
                }
624
475
        pAudacious->get_cover = NULL;
625
476
        pAudacious->cCoverDir = NULL;  /// a confirmer...
626
477
        
627
 
        pAudacious->appclass = "audacious";  // en fait Audacious.
 
478
        pAudacious->appclass = "audacious";  // les classes sont passees en minuscule par le dock.
628
479
        pAudacious->name = "Audacious";
629
480
        pAudacious->launch = "audacious2";
630
481
        pAudacious->cMprisService = "org.mpris.audacious";