void cli_cache_refresh (cli_infos_t *infos) { xmmsc_result_t *res; res = xmmsc_playlist_current_pos (infos->conn, XMMS_ACTIVE_PLAYLIST); xmmsc_result_wait (res); refresh_currpos (xmmsc_result_get_value (res), infos->cache); xmmsc_result_unref (res); res = xmmsc_playback_current_id (infos->conn); xmmsc_result_wait (res); refresh_currid (xmmsc_result_get_value (res), infos->cache); xmmsc_result_unref (res); res = xmmsc_playback_status (infos->conn); xmmsc_result_wait (res); refresh_playback_status (xmmsc_result_get_value (res), infos->cache); xmmsc_result_unref (res); res = xmmsc_playlist_list_entries (infos->conn, XMMS_ACTIVE_PLAYLIST); xmmsc_result_wait (res); refresh_active_playlist (xmmsc_result_get_value (res), infos->cache); xmmsc_result_unref (res); res = xmmsc_playlist_current_active (infos->conn); xmmsc_result_wait (res); refresh_active_playlist_name (xmmsc_result_get_value (res), infos->cache); xmmsc_result_unref (res); }
static gint update_active_playlist (xmmsv_t *val, void *udata) { cli_infos_t *infos = (cli_infos_t *) udata; cli_cache_t *cache = infos->cache; xmmsc_result_t *refres; gint pos, newpos, type; gint id; const gchar *name; xmmsv_dict_entry_get_int (val, "type", &type); xmmsv_dict_entry_get_int (val, "position", &pos); xmmsv_dict_entry_get_int (val, "id", &id); xmmsv_dict_entry_get_string (val, "name", &name); /* Active playlist not changed, nevermind */ if (strcmp (name, cache->active_playlist_name) != 0) { return TRUE; } /* Apply changes to the cached playlist */ switch (type) { case XMMS_PLAYLIST_CHANGED_ADD: g_array_append_val (cache->active_playlist, id); break; case XMMS_PLAYLIST_CHANGED_INSERT: g_array_insert_val (cache->active_playlist, pos, id); break; case XMMS_PLAYLIST_CHANGED_MOVE: xmmsv_dict_entry_get_int (val, "newposition", &newpos); g_array_remove_index (cache->active_playlist, pos); g_array_insert_val (cache->active_playlist, newpos, id); break; case XMMS_PLAYLIST_CHANGED_REMOVE: g_array_remove_index (cache->active_playlist, pos); break; case XMMS_PLAYLIST_CHANGED_SHUFFLE: case XMMS_PLAYLIST_CHANGED_SORT: case XMMS_PLAYLIST_CHANGED_CLEAR: /* Oops, reload the whole playlist */ refres = xmmsc_playlist_list_entries (infos->conn, XMMS_ACTIVE_PLAYLIST); xmmsc_result_notifier_set (refres, &refresh_active_playlist, infos->cache); xmmsc_result_unref (refres); freshness_requested (&cache->freshness_active_playlist); break; } return TRUE; }
static gint reload_active_playlist (xmmsv_t *val, void *udata) { cli_infos_t *infos = (cli_infos_t *) udata; xmmsc_result_t *refres; const gchar *buf; /* FIXME: Also listen to playlist renames, in case the active PL is renamed! */ /* Refresh playlist name */ if (xmmsv_get_string (val, &buf)) { g_free (infos->cache->active_playlist_name); infos->cache->active_playlist_name = g_strdup (buf); } /* Get all the entries again */ refres = xmmsc_playlist_list_entries (infos->conn, XMMS_ACTIVE_PLAYLIST); xmmsc_result_notifier_set (refres, &refresh_active_playlist, infos->cache); xmmsc_result_unref (refres); freshness_requested (&infos->cache->freshness_active_playlist); return TRUE; }
void move_entries (xmmsc_result_t *matching, cli_infos_t *infos, gchar *playlist, gint pos) { xmmsc_result_t *movres, *lisres; guint id, curr; gint inc; gboolean up; GTree *list; xmmsv_t *lisval; const gchar *err; lisres = xmmsc_playlist_list_entries (infos->sync, playlist); xmmsc_result_wait (lisres); lisval = xmmsc_result_get_value (lisres); if (xmmsv_get_error (lisval, &err) || !xmmsv_is_list (lisval)) { g_printf (_("Error retrieving playlist entries\n")); } else { xmmsv_list_iter_t *it; xmmsv_t *entry; /* store matching mediaids in a tree (faster lookup) */ list = matching_ids_tree (matching); /* move matched playlist items */ curr = 0; inc = 0; up = TRUE; xmmsv_get_list_iter (lisval, &it); for (xmmsv_list_iter_first (it); xmmsv_list_iter_valid (it); xmmsv_list_iter_next (it)) { xmmsv_list_iter_entry (it, &entry); if (curr == pos) { up = FALSE; } if (xmmsv_get_uint (entry, &id) && g_tree_lookup (list, &id) != NULL) { if (up) { /* moving forward */ movres = xmmsc_playlist_move_entry (infos->sync, playlist, curr - inc, pos - 1); } else { /* moving backward */ movres = xmmsc_playlist_move_entry (infos->sync, playlist, curr, pos + inc); } xmmsc_result_wait (movres); xmmsc_result_unref (movres); inc++; } curr++; } g_tree_destroy (list); } finish: cli_infos_loop_resume (infos); xmmsc_result_unref (matching); xmmsc_result_unref (lisres); }
void cmd_list (xmmsc_connection_t *conn, gint argc, gchar **argv) { gchar *playlist = NULL; xmmsc_result_t *res; xmmsv_t *val; xmmsv_list_iter_t *it; gulong total_playtime = 0; gint p = 0; guint pos = 0; if (argc > 2) { playlist = argv[2]; } res = xmmsc_playlist_current_pos (conn, playlist); xmmsc_result_wait (res); val = xmmsc_result_get_value (res); if (!xmmsv_is_error (val)) { if (!xmmsv_dict_entry_get_int (val, "position", &p)) { print_error ("Broken resultset"); } xmmsc_result_unref (res); } res = xmmsc_playlist_list_entries (conn, playlist); xmmsc_result_wait (res); val = xmmsc_result_get_value (res); if (xmmsv_is_error (val)) { print_error ("%s", xmmsv_get_error_old (val)); } xmmsv_get_list_iter (val, &it); while (xmmsv_list_iter_valid (it)) { xmmsc_result_t *info_res; xmmsv_t *val_id, *propdict, *info_val; gchar line[80]; gint playtime = 0; guint ui; xmmsv_list_iter_entry (it, &val_id); if (!xmmsv_get_uint (val_id, &ui)) { print_error ("Broken resultset"); } info_res = xmmsc_medialib_get_info (conn, ui); xmmsc_result_wait (info_res); propdict = xmmsc_result_get_value (info_res); info_val = xmmsv_propdict_to_dict (propdict, NULL); if (xmmsv_is_error (info_val)) { print_error ("%s", xmmsv_get_error_old (info_val)); } if (xmmsv_dict_entry_get_int (info_val, "duration", &playtime)) { total_playtime += playtime; } if (val_has_key (info_val, "channel")) { if (val_has_key (info_val, "title")) { xmmsc_entry_format (line, sizeof (line), "[stream] ${title}", info_val); } else { xmmsc_entry_format (line, sizeof (line), "${channel}", info_val); } } else if (!val_has_key (info_val, "title")) { const gchar *url; gchar dur[10]; xmmsc_entry_format (dur, sizeof (dur), "(${minutes}:${seconds})", info_val); if (xmmsv_dict_entry_get_string (info_val, "url", &url)) { gchar *filename = g_path_get_basename (url); if (filename) { g_snprintf (line, sizeof (line), "%s %s", filename, dur); g_free (filename); } else { g_snprintf (line, sizeof (line), "%s %s", url, dur); } } } else { xmmsc_entry_format (line, sizeof (line), listformat, info_val); } if (p == pos) { print_info ("->[%d/%d] %s", pos, ui, line); } else { print_info (" [%d/%d] %s", pos, ui, line); } pos++; xmmsc_result_unref (info_res); xmmsv_unref (info_val); xmmsv_list_iter_next (it); } xmmsc_result_unref (res); /* rounding */ total_playtime += 500; print_info ("\nTotal playtime: %d:%02d:%02d", total_playtime / 3600000, (total_playtime / 60000) % 60, (total_playtime / 1000) % 60); }