~vcs-imports/pidgin-musictracker/trunk

« back to all changes in this revision

Viewing changes to src/mpris.c

  • Committer: jon.turney at org
  • Date: 2010-03-01 00:28:25 UTC
  • Revision ID: svn-v4:dccc4ef9-3752-0410-9079-47cdceed9760:trunk:446

The code for handling dbus proxy objects doesn't seem to be quite
right, and leaks them for some people, so rewrite it to use static
proxy object.

Also refactor the various player dbus interface code so they use a
common DBUS bus object

Hopefully this addresses issue 88 and issue 148

Show diffs side-by-side

added added

removed removed

Lines of Context:
48
48
#include <dbus/dbus-glib.h>
49
49
 
50
50
#include "musictracker.h"
 
51
#include "utils.h"
51
52
 
52
53
#define DBUS_MPRIS_NAMESPACE            "org.mpris."
53
54
#define DBUS_MPRIS_PLAYER               "org.freedesktop.MediaPlayer"
63
64
#define mpris_error(fmt, ...)   purple_debug(PURPLE_DEBUG_ERROR, "MPRIS", \
64
65
                                        fmt, ## __VA_ARGS__);
65
66
 
66
 
static DBusGConnection *bus = NULL;
67
 
 
68
67
#define MPRIS_HINT_STATUSCHANGE 1
69
68
#define MPRIS_HINT_METADATA_METHOD_CASE 2
70
69
 
168
167
 
169
168
static void mpris_connect_dbus_signals(pidginmpris_t *player)
170
169
{
171
 
        player->proxy = dbus_g_proxy_new_for_name(bus,
 
170
        player->proxy = dbus_g_proxy_new_for_name(connection,
172
171
                        player->service_name, DBUS_MPRIS_PLAYER_PATH, DBUS_MPRIS_PLAYER);
173
172
 
174
173
        dbus_g_proxy_add_signal(player->proxy, DBUS_MPRIS_TRACK_SIGNAL,
194
193
 
195
194
static gboolean mpris_app_running(pidginmpris_t *player)
196
195
{
197
 
        DBusGProxy *proxy = dbus_g_proxy_new_for_name_owner(bus, 
 
196
        DBusGProxy *proxy = dbus_g_proxy_new_for_name_owner(connection,
198
197
                        player->service_name, DBUS_MPRIS_PLAYER_PATH, DBUS_MPRIS_PLAYER, NULL);
199
198
        
200
199
        if(!proxy)
234
233
  mpris_status_signal_int_cb(NULL, -1, &(player->ti));
235
234
 
236
235
  /* Try to discover how this player likes to be known */
237
 
  DBusGProxy *proxy = dbus_g_proxy_new_for_name(bus, player->service_name, "/", DBUS_MPRIS_PLAYER);
 
236
  DBusGProxy *proxy = dbus_g_proxy_new_for_name(connection, player->service_name, "/", DBUS_MPRIS_PLAYER);
238
237
  if (proxy)
239
238
    {
240
239
      GError *error = 0;
286
285
    }
287
286
}
288
287
 
289
 
static gboolean
290
 
load_plugin(void)
291
 
{
292
 
        if (!players)
293
 
          players = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, player_delete);
294
 
 
295
 
        /* initialize dbus connection */
296
 
        GError *error = 0;
297
 
        bus = dbus_g_bus_get(DBUS_BUS_SESSION, &error);
298
 
        if (!bus) {
299
 
                mpris_error("failed to connect to the dbus daemon: %s\n", error->message);
300
 
                g_error_free (error);
301
 
                return FALSE;
302
 
        }
303
 
 
304
 
        return TRUE;
305
 
}
306
 
 
307
288
static void
308
289
mpris_check_player(gpointer key, gpointer value, gpointer user_data)
309
290
419
400
void
420
401
get_mpris_info(struct TrackInfo* ti)
421
402
{
422
 
  if (!bus)
423
 
    if (!load_plugin())
424
 
      return;
 
403
  if (!connection)
 
404
    {
 
405
      if (!dbus_g_init_connection())
 
406
        return;
 
407
    }
 
408
 
 
409
  if (!players)
 
410
    {
 
411
      players = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, player_delete);
 
412
    }
425
413
 
426
414
  /* Look for "org.mpris.*" service names on the bus */
427
415
  GError *error = 0;
428
 
  DBusGProxy *proxy = dbus_g_proxy_new_for_name(bus, "org.freedesktop.DBus", "/", "org.freedesktop.DBus");
 
416
 
 
417
  static DBusGProxy *proxy = 0;
 
418
  if (!proxy)
 
419
    {
 
420
      proxy = dbus_g_proxy_new_for_name(connection, "org.freedesktop.DBus", "/", "org.freedesktop.DBus");
 
421
    }
 
422
  
429
423
  if (proxy)
430
424
    {
431
425
      char **v;