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); }
gboolean get_quodlibet_info(struct TrackInfo* ti) { DBusGConnection *connection; DBusGProxy *player, *shell; GError *error = 0; char buf[100], status[100]; static gboolean connected = FALSE; 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, "net.sacredchao.QuodLibet")) { ti->status = STATUS_OFF; return TRUE; } player = dbus_g_proxy_new_for_name(connection, "net.sacredchao.QuodLibet", "/net/sacredchao/QuodLibet", "net.sacredchao.QuodLibet"); if (!connected) { dbus_g_proxy_add_signal(player, "Paused", G_TYPE_INVALID); dbus_g_proxy_connect_signal(player, "Paused", G_CALLBACK(cb_quodlibet_paused), (gpointer) STATUS_PAUSED, 0); dbus_g_proxy_add_signal(player, "Unpaused", G_TYPE_INVALID); dbus_g_proxy_connect_signal(player, "Unpaused", G_CALLBACK(cb_quodlibet_paused), (gpointer) STATUS_NORMAL, 0); connected = TRUE; } GHashTable *table; if (!dbus_g_proxy_call(player, "CurrentSong", &error, G_TYPE_INVALID, dbus_g_type_get_map("GHashTable", G_TYPE_STRING, G_TYPE_STRING), &table, G_TYPE_INVALID)) { ti->status = STATUS_OFF; return TRUE; } ti->status = g_state; quodlibet_hash_str(table, "artist", ti->artist); quodlibet_hash_str(table, "album", ti->album); quodlibet_hash_str(table, "title", ti->track); quodlibet_hash_str(table, "~#length", buf); sscanf(buf, "%d", &ti->totalSecs); g_hash_table_destroy(table); return TRUE; }
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); }
void get_audacious_info(struct TrackInfo* ti) { static DBusGProxy *proxy = 0; GError *error = 0; char *status = 0; int pos = 0; ti->status = PLAYER_STATUS_CLOSED; if (!dbus_g_running("org.atheme.audacious")) { return; } if (!proxy) { proxy = dbus_g_proxy_new_for_name (connection, "org.atheme.audacious", "/org/atheme/audacious", "org.atheme.audacious"); } if (!dbus_g_proxy_call_with_timeout(proxy, "Status", DBUS_TIMEOUT, &error, G_TYPE_INVALID, G_TYPE_STRING, &status, G_TYPE_INVALID)) { trace("Failed to make dbus call: %s", error->message); return; } ti->player = "Audacious"; if (strcmp(status, "stopped") == 0) { ti->status = PLAYER_STATUS_STOPPED; return; } else if (strcmp(status, "playing") == 0) { ti->status = PLAYER_STATUS_PLAYING; } else { ti->status = PLAYER_STATUS_PAUSED; } // Find the position in the playlist pos = audacious_dbus_uint(proxy, "Position"); ti->currentSecs = audacious_dbus_uint(proxy, "Time")/1000; ti->totalSecs = audacious_dbus_int(proxy, "SongLength", pos); audacious_dbus_string(proxy, "SongTuple", pos, "artist", ti->artist); audacious_dbus_string(proxy, "SongTuple", pos, "album", ti->album); audacious_dbus_string(proxy, "SongTuple", pos, "title", ti->track); }
void get_banshee_info(struct TrackInfo* ti) { GError *error = 0; int status; char szStatus[STRLEN]; if (dbus_g_running("org.gnome.Banshee")) { static DBusGProxy *proxy = 0; if (!proxy) { proxy = dbus_g_proxy_new_for_name (connection, "org.gnome.Banshee", "/org/gnome/Banshee/Player", "org.gnome.Banshee.Core"); } if (!dbus_g_proxy_call_with_timeout (proxy, "GetPlayingStatus", DBUS_TIMEOUT, &error, G_TYPE_INVALID, G_TYPE_INT, &status, G_TYPE_INVALID)) { trace("Failed to make dbus call: %s", error->message); return; } if (status == -1) { ti->status = PLAYER_STATUS_STOPPED; return; } else if (status == 1) ti->status = PLAYER_STATUS_PLAYING; else ti->status = PLAYER_STATUS_PAUSED; banshee_dbus_string(proxy, "GetPlayingArtist", ti->artist); banshee_dbus_string(proxy, "GetPlayingAlbum", ti->album); banshee_dbus_string(proxy, "GetPlayingTitle", ti->track); ti->totalSecs = banshee_dbus_int(proxy, "GetPlayingDuration"); ti->currentSecs = banshee_dbus_int(proxy, "GetPlayingPosition"); return; } else if (dbus_g_running("org.bansheeproject.Banshee")) { // provide for new interface in banshee 1.0 static DBusGProxy *proxy = 0; if (!proxy) { proxy = dbus_g_proxy_new_for_name (connection, "org.bansheeproject.Banshee", "/org/bansheeproject/Banshee/PlayerEngine", "org.bansheeproject.Banshee.PlayerEngine"); } banshee_dbus_string(proxy, "GetCurrentState", szStatus); if (strcmp(szStatus, "idle") == 0) { ti->status = PLAYER_STATUS_STOPPED; return; } else if (strcmp(szStatus, "playing") == 0) ti->status = PLAYER_STATUS_PLAYING; else ti->status = PLAYER_STATUS_PAUSED; GHashTable* table; if (!dbus_g_proxy_call_with_timeout (proxy, "GetCurrentTrack", DBUS_TIMEOUT, &error, G_TYPE_INVALID, dbus_g_type_get_map("GHashTable", G_TYPE_STRING, G_TYPE_VALUE), &table, G_TYPE_INVALID)) { trace("Failed to make dbus call: %s", error->message); return; } banshee_hash_str(table, "album", ti->album); banshee_hash_str(table, "artist", ti->artist); banshee_hash_str(table, "name", ti->track); g_hash_table_destroy(table); ti->totalSecs = banshee_dbus_uint(proxy, "GetLength") / 1000; ti->currentSecs = banshee_dbus_uint(proxy, "GetPosition") / 1000; return; } ti->status = PLAYER_STATUS_CLOSED; }
gboolean get_exaile_info(struct TrackInfo* ti) { DBusGConnection *connection; DBusGProxy *proxy; GError *error = 0; char buf[STRLEN], 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.exaile.DBusInterface")) { ti->status = STATUS_OFF; return TRUE; } proxy = dbus_g_proxy_new_for_name (connection, "org.exaile.DBusInterface", "/DBusInterfaceObject", "org.exaile.DBusInterface"); // We should be using "status" instead of "query" here, but its broken in // the current (0.2.6) Exaile version if (!exaile_dbus_query(proxy, "query", buf)) { trace("Failed to call Exaile dbus method. Assuming player is OFF"); ti->status = STATUS_OFF; return TRUE; } if (sscanf(buf, "status: %s", status) == 1) { if (!strcmp(status, "playing")) ti->status = STATUS_NORMAL; else ti->status = STATUS_PAUSED; } else { ti->status = STATUS_OFF; } if (ti->status != STATUS_OFF) { int mins, secs; exaile_dbus_query(proxy, "get_artist", ti->artist); exaile_dbus_query(proxy, "get_album", ti->album); exaile_dbus_query(proxy, "get_title", ti->track); exaile_dbus_query(proxy, "get_length", buf); if (sscanf(buf, "%d:%d", &mins, &secs)) { ti->totalSecs = mins*60 + secs; } error = 0; unsigned char percentage; if (!dbus_g_proxy_call_with_timeout(proxy, "current_position", DBUS_TIMEOUT, &error, G_TYPE_INVALID, G_TYPE_UCHAR, &percentage, G_TYPE_INVALID)) { trace("Failed to make dbus call: %s", error->message); } trace("exaile_dbus_query: 'current_position' => %d", percentage); ti->currentSecs = percentage*ti->totalSecs/100; } return TRUE; }