gboolean get_dbusbird_info(struct TrackInfo* ti) { DBusGConnection *connection; DBusGProxy *proxy; GError *error = 0; char status[STRLEN]; connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error); if (connection == NULL) { trace("Failed to open connection to dbus: %s\n", error->message); g_error_free (error); return FALSE; } if (!dbus_g_running(connection, "org.mozilla.songbird")) { ti->status = STATUS_OFF; return TRUE; } proxy = dbus_g_proxy_new_for_name (connection, "org.mozilla.songbird", "/org/mozilla/songbird", "org.mozilla.songbird"); if (!dbusbird_dbus_string(proxy, "getStatus", status)) { return FALSE; } ti->player = "Songbird"; if (strcmp(status, "stopped") == 0) { ti->status = STATUS_OFF; return TRUE; } else if (strcmp(status, "playing") == 0) { ti->status = STATUS_NORMAL; } else { // paused ti->status = STATUS_PAUSED; } ti->currentSecs = 0; { char buf[STRLEN]; int hours, mins, secs; dbusbird_dbus_string(proxy, "getLength", buf); if (sscanf(buf, "%d:%d:%d", &hours, &mins, &secs)) { ti->totalSecs = hours * 3600 + mins*60 + secs; } } dbusbird_dbus_string(proxy, "getArtist", ti->artist); dbusbird_dbus_string(proxy, "getAlbum", ti->album); dbusbird_dbus_string(proxy, "getTitle", ti->track); return (ti->status != STATUS_OFF); }
void get_dbusbird_info(struct TrackInfo* ti) { static DBusGProxy *proxy = 0; char status[STRLEN]; ti->status = PLAYER_STATUS_CLOSED; if (!dbus_g_running("org.mozilla.songbird")) { return; } if (!proxy) { proxy = dbus_g_proxy_new_for_name (connection, "org.mozilla.songbird", "/org/mozilla/songbird", "org.mozilla.songbird"); } if (!dbusbird_dbus_string(proxy, "getStatus", status)) { return; } ti->player = "Songbird"; if (strcmp(status, "stopped") == 0) { ti->status = PLAYER_STATUS_STOPPED; return; } else if (strcmp(status, "playing") == 0) { ti->status = PLAYER_STATUS_PLAYING; } else { // paused ti->status = PLAYER_STATUS_PAUSED; } ti->currentSecs = 0; { char buf[STRLEN]; int hours, mins, secs; dbusbird_dbus_string(proxy, "getLength", buf); if (sscanf(buf, "%d:%d:%d", &hours, &mins, &secs) == 3) { ti->totalSecs = hours * 3600 + mins*60 + secs; } } dbusbird_dbus_string(proxy, "getArtist", ti->artist); dbusbird_dbus_string(proxy, "getAlbum", ti->album); dbusbird_dbus_string(proxy, "getTitle", ti->track); }