void coll_save (cli_infos_t *infos, xmmsv_coll_t *coll, xmmsc_coll_namespace_t ns, gchar *name, gboolean force) { xmmsc_result_t *res; xmmsv_t *val; gboolean save = TRUE; if (!force) { xmmsv_coll_t *exists; res = xmmsc_coll_get (infos->sync, name, ns); xmmsc_result_wait (res); val = xmmsc_result_get_value (res); if (xmmsv_get_coll (val, &exists)) { g_printf (_("Error: A collection already exists " "with the target name!\n")); save = FALSE; } xmmsc_result_unref (res); } if (save) { res = xmmsc_coll_save (infos->sync, coll, name, ns); xmmsc_result_wait (res); done (res, infos); } else { cli_infos_loop_resume (infos); } }
/* * call-seq: * xc.coll_save(coll, name, ns) -> result * * Save the collection _coll_ named _name_ under the namespace _ns_ to the * media library. */ static VALUE c_coll_save (VALUE self, VALUE coll, VALUE name, VALUE ns) { METHOD_HANDLER_HEADER /* FIXME: Check that we actually have a Collection object */ res = xmmsc_coll_save (xmms->real, FROM_XMMS_CLIENT_COLLECTION (coll), StringValuePtr (name), StringValuePtr (ns)); METHOD_HANDLER_FOOTER }
void configure_playlist (xmmsc_result_t *res, cli_infos_t *infos, gchar *playlist, gint history, gint upcoming, xmmsv_coll_type_t type, gchar *input) { xmmsc_result_t *saveres; xmmsv_coll_t *coll; xmmsv_coll_t *newcoll; xmmsv_t *val; gboolean copied = FALSE; val = xmmsc_result_get_value (res); if (xmmsv_get_coll (val, &coll)) { if (type >= 0 && xmmsv_coll_get_type (coll) != type) { newcoll = coll_copy_retype (coll, type); coll = newcoll; copied = TRUE; } if (history >= 0) { coll_int_attribute_set (coll, "history", history); } if (upcoming >= 0) { coll_int_attribute_set (coll, "upcoming", upcoming); } if (input) { /* Replace previous operand. */ newcoll = coll_make_reference (input, XMMS_COLLECTION_NS_COLLECTIONS); xmmsv_list_clear (xmmsv_coll_operands_get (coll)); xmmsv_coll_add_operand (coll, newcoll); xmmsv_coll_unref (newcoll); } saveres = xmmsc_coll_save (infos->sync, coll, playlist, XMMS_COLLECTION_NS_PLAYLISTS); xmmsc_result_wait (saveres); done (saveres, infos); } else { g_printf (_("Cannot find the playlist to configure!\n")); cli_infos_loop_resume (infos); } if (copied) { xmmsv_coll_unref (coll); } xmmsc_result_unref (res); }
/** * Create a new empty playlist. */ xmmsc_result_t * xmmsc_playlist_create (xmmsc_connection_t *c, const char *playlist) { xmmsc_result_t *res; xmmsv_coll_t *plcoll; x_check_conn (c, NULL); x_api_error_if (!playlist, "playlist name cannot be NULL", NULL); plcoll = xmmsv_coll_new (XMMS_COLLECTION_TYPE_IDLIST); res = xmmsc_coll_save (c, plcoll, playlist, XMMS_COLLECTION_NS_PLAYLISTS); xmmsv_coll_unref (plcoll); return res; }
void copy_playlist (xmmsc_result_t *res, cli_infos_t *infos, gchar *playlist) { xmmsc_result_t *saveres; xmmsv_coll_t *coll; xmmsv_t *val; val = xmmsc_result_get_value (res); if (xmmsv_get_coll (val, &coll)) { saveres = xmmsc_coll_save (infos->sync, coll, playlist, XMMS_COLLECTION_NS_PLAYLISTS); xmmsc_result_wait (saveres); done (saveres, infos); } else { g_printf (_("Cannot find the playlist to copy!\n")); cli_infos_loop_resume (infos); } xmmsc_result_unref (res); }
void cmd_playlist_type (xmmsc_connection_t *conn, gint argc, gchar **argv) { gchar *name; xmmsv_coll_type_t prevtype, newtype; xmmsc_result_t *res; xmmsv_t *val; xmmsv_coll_t *coll; /* Read playlist name */ if (argc < 4) { print_error ("usage: type_playlist [playlistname] [type] [options]"); } name = argv[3]; /* Retrieve the playlist operator */ res = xmmsc_coll_get (conn, name, XMMS_COLLECTION_NS_PLAYLISTS); 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_coll (val, &coll); prevtype = xmmsv_coll_get_type (coll); /* No type argument, simply display the current type */ if (argc < 5) { print_info (get_playlist_type_string (prevtype)); /* Type argument, set the new type */ } else { gint typelen; gint idlistsize; xmmsc_result_t *saveres; xmmsv_coll_t *newcoll; gint i; typelen = strlen (argv[4]); if (g_ascii_strncasecmp (argv[4], "list", typelen) == 0) { newtype = XMMS_COLLECTION_TYPE_IDLIST; } else if (g_ascii_strncasecmp (argv[4], "queue", typelen) == 0) { newtype = XMMS_COLLECTION_TYPE_QUEUE; } else if (g_ascii_strncasecmp (argv[4], "pshuffle", typelen) == 0) { newtype = XMMS_COLLECTION_TYPE_PARTYSHUFFLE; /* Setup operand for party shuffle (set operand) ! */ if (argc < 6) { print_error ("Give the source collection for the party shuffle"); } } else { print_error ("Invalid playlist type (valid types: list, queue, pshuffle)"); } /* Copy collection idlist, attributes and operand (if needed) */ newcoll = xmmsv_coll_new (newtype); idlistsize = xmmsv_coll_idlist_get_size (coll); for (i = 0; i < idlistsize; i++) { guint id; xmmsv_coll_idlist_get_index (coll, i, &id); xmmsv_coll_idlist_append (newcoll, id); } xmmsv_coll_attribute_foreach (coll, coll_copy_attributes, newcoll); if (newtype == XMMS_COLLECTION_TYPE_PARTYSHUFFLE) { playlist_setup_pshuffle (conn, newcoll, argv[5]); } /* Overwrite with new collection */ saveres = xmmsc_coll_save (conn, newcoll, name, XMMS_COLLECTION_NS_PLAYLISTS); xmmsc_result_wait (saveres); if (xmmsc_result_iserror (saveres)) { print_error ("Couldn't save %s : %s", name, xmmsc_result_get_error (saveres)); } xmmsv_coll_unref (newcoll); xmmsc_result_unref (saveres); } xmmsc_result_unref (res); }