void set_volume (cli_infos_t *infos, gchar *channel, gint volume) { xmmsc_result_t *res; xmmsv_t *val; GList *it, *channels = NULL; if (!channel) { /* get all channels */ res = xmmsc_playback_volume_get (infos->sync); xmmsc_result_wait (res); val = xmmsc_result_get_value (res); xmmsv_dict_foreach (val, dict_keys, &channels); xmmsc_result_unref (res); } else { channels = g_list_prepend (channels, g_strdup (channel)); } /* set volumes for channels in list */ for (it = g_list_first (channels); it != NULL; it = g_list_next (it)) { res = xmmsc_playback_volume_set (infos->sync, it->data, volume); xmmsc_result_wait (res); xmmsc_result_unref (res); /* free channel string */ g_free (it->data); } g_list_free (channels); cli_infos_loop_resume (infos); }
static void updater_subscribe_config (updater_t *updater) { xmmsc_result_t *res; const gchar *default_directory; g_return_if_fail (updater); g_return_if_fail (updater->conn); default_directory = g_get_user_special_dir (G_USER_DIRECTORY_MUSIC); if (!default_directory) { default_directory = ""; } res = xmmsc_config_register_value (updater->conn, "mlibupdater.watch_dirs", default_directory); xmmsc_result_notifier_set (res, updater_config_register, updater); xmmsc_result_unref (res); res = xmmsc_broadcast_config_value_changed (updater->conn); xmmsc_result_notifier_set (res, updater_config_changed, updater); xmmsc_result_unref (res); }
static gboolean ol_player_xmms2_go_rel (int rel) { ol_log_func (); ol_debugf (" rel:%d\n", rel); if (!ol_player_xmms2_ensure_connection ()) return FALSE; xmmsc_result_t *result = xmmsc_playlist_set_next_rel (connection, rel); xmmsc_result_wait (result); xmmsv_t *return_value = xmmsc_result_get_value (result); if (xmmsv_is_error (return_value)) { ol_debug ("Error on setting playlist next"); return FALSE; } xmmsc_result_unref (result); result = xmmsc_playback_tickle (connection); xmmsc_result_wait (result); if (xmmsc_result_iserror (result)) { ol_debug ("Error on tickle playback"); return FALSE; } xmmsc_result_unref (result); return TRUE; }
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); }
int main (int argc, char **argv) { GIOChannel *gio; GMainLoop *ml; gchar *path; gchar *tmp; xmmsc_connection_t *conn; xmmsc_result_t *res; xmonitor_t *mon; gint fd; conn = xmmsc_init ("xmms-medialib-updater"); path = getenv ("XMMS_PATH"); if (!xmmsc_connect (conn, path)) { ERR ("Could not connect to xmms2d %s", xmmsc_get_last_error (conn)); return EXIT_FAILURE; } ml = g_main_loop_new (NULL, FALSE); xmmsc_mainloop_gmain_init (conn); xmmsc_disconnect_callback_set (conn, quit, ml); mon = g_new0 (xmonitor_t, 1); fd = monitor_init (mon); mon->conn = conn; if (fd == -1) { ERR ("Couldn't initalize monitor"); return EXIT_FAILURE; } tmp = getenv("XMMS_DEBUG"); if (!tmp) { g_log_set_handler (NULL, G_LOG_LEVEL_MESSAGE | G_LOG_FLAG_RECURSION, message_handler, NULL); } gio = g_io_channel_unix_new (fd); g_io_add_watch (gio, G_IO_IN, s_callback, mon); res = xmmsc_configval_register (conn, "mlibupdater.watch_dirs", ""); xmmsc_result_notifier_set (res, handle_configval, mon); xmmsc_result_unref (res); res = xmmsc_broadcast_configval_changed (conn); xmmsc_result_notifier_set (res, handle_config_changed, mon); xmmsc_result_unref (res); g_main_loop_run (ml); return EXIT_SUCCESS; }
static gboolean ol_player_xmms2_seek (int pos_ms) { ol_log_func (); if (!ol_player_xmms2_ensure_connection ()) return FALSE; #if XMMS_IPC_PROTOCOL_VERSION >= 16 xmmsc_result_unref (xmmsc_playback_seek_ms (connection, pos_ms, XMMS_PLAYBACK_SEEK_SET)); #else xmmsc_result_unref (xmmsc_playback_seek_ms (connection, pos_ms)); #endif return TRUE; }
void remove_cached_list (xmmsc_result_t *matching, cli_infos_t *infos) { /* FIXME: w00t at code copy-paste, please modularize */ xmmsc_result_t *rmres; guint plid, id; gint plsize; GArray *playlist; gint i; const gchar *err; xmmsv_t *val; val = xmmsc_result_get_value (matching); plsize = infos->cache->active_playlist->len; playlist = infos->cache->active_playlist; if (xmmsv_get_error (val, &err) || !xmmsv_is_list (val)) { g_printf (_("Error retrieving the media matching the pattern!\n")); } else { xmmsv_list_iter_t *it; xmmsv_get_list_iter (val, &it); /* Loop on the playlist (backward, easier to remove) */ for (i = plsize - 1; i >= 0; i--) { plid = g_array_index (playlist, guint, i); /* Loop on the matched media */ for (xmmsv_list_iter_first (it); xmmsv_list_iter_valid (it); xmmsv_list_iter_next (it)) { xmmsv_t *entry; xmmsv_list_iter_entry (it, &entry); /* If both match, remove! */ if (xmmsv_get_uint (entry, &id) && plid == id) { rmres = xmmsc_playlist_remove_entry (infos->sync, NULL, i); xmmsc_result_wait (rmres); xmmsc_result_unref (rmres); break; } } } } cli_infos_loop_resume (infos); xmmsc_result_unref (matching); }
void cmd_playlists_list (xmmsc_connection_t *conn, gint argc, gchar **argv) { const gchar *active_name; xmmsc_result_t *res, *active_res; xmmsv_t *val, *active_val; xmmsv_list_iter_t *it; active_res = xmmsc_playlist_current_active (conn); xmmsc_result_wait (active_res); active_val = xmmsc_result_get_value (active_res); if (xmmsv_is_error (active_val) || !xmmsv_get_string (active_val, &active_name)) { active_name = NULL; } res = xmmsc_playlist_list (conn); 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)) { xmmsv_t *valstr; const gchar *name; xmmsv_list_iter_entry (it, &valstr); if (!xmmsv_get_string (valstr, &name)) { print_error ("Broken resultset"); } /* Hide all lists that start with _ */ if (name[0] != '_') { if (active_name != NULL && strcmp (active_name, name) == 0) { print_info ("->%s", name); } else { print_info (" %s", name); } } xmmsv_list_iter_next (it); } xmmsc_result_unref (res); xmmsc_result_unref (active_res); }
static void pos_move_cb (gint curr, void *userdata) { xmmsc_result_t *movres; pl_pos_udata_t *pack = (pl_pos_udata_t *) userdata; /* Entries are moved in descending order, pack->inc is used as * offset both for forward and backward moves, and reset * inbetween. */ if (curr < pack->pos) { /* moving forward */ if (pack->inc >= 0) { pack->inc = -1; /* start inc at -1, decrement */ } movres = xmmsc_playlist_move_entry (pack->infos->sync, pack->playlist, curr, pack->pos + pack->inc); pack->inc--; } else { /* moving backward */ movres = xmmsc_playlist_move_entry (pack->infos->sync, pack->playlist, curr + pack->inc, pack->pos); pack->inc++; } xmmsc_result_wait (movres); xmmsc_result_unref (movres); }
void cmd_insertid (xmmsc_connection_t *conn, gint argc, gchar **argv) { gchar *playlist = NULL; guint pos, mlib_id; char *endptr; xmmsc_result_t *res; if (argc < 4) { print_error ("Need a position and a medialib id"); } pos = strtol (argv[2], &endptr, 10); if (*endptr == '\0') { mlib_id = strtol (argv[3], NULL, 10); /* No playlist name */ } else { playlist = argv[2]; /* extract playlist name */ pos = strtol (argv[3], NULL, 10); mlib_id = strtol (argv[4], NULL, 10); } res = xmmsc_playlist_insert_id (conn, playlist, pos, mlib_id); xmmsc_result_wait (res); if (xmmsc_result_iserror (res)) { print_error ("Unable to insert %u at position %u: %s", mlib_id, pos, xmmsc_result_get_error (res)); } print_info ("Inserted %u at position %u", mlib_id, pos); xmmsc_result_unref (res); }
static void c_free (RbResult *res) { xmmsc_result_unref (res->real); free (res); }
void cmd_sort (xmmsc_connection_t *conn, gint argc, gchar **argv) { gchar *playlist; xmmsv_t *sortby; xmmsc_result_t *res; if (argc < 3) { print_error ("Sort needs a property to sort on"); } else if (argc == 3) { playlist = NULL; sortby = xmmsv_make_stringlist (&argv[2], argc - 2); } else { playlist = argv[2]; sortby = xmmsv_make_stringlist (&argv[3], argc - 3); } res = xmmsc_playlist_sort (conn, playlist, sortby); xmmsc_result_wait (res); if (xmmsc_result_iserror (res)) { print_error ("%s", xmmsc_result_get_error (res)); } xmmsc_result_unref (res); xmmsv_unref (sortby); }
static gboolean ol_player_xmms2_get_music_length (int *len) { /* ol_log_func (); */ ol_assert_ret (len != NULL, FALSE); if (!ol_player_xmms2_ensure_connection ()) return FALSE; *len = 0; int32_t id = ol_player_xmms2_get_currend_id (); if (id > 0) { xmmsc_result_t *result = xmmsc_medialib_get_info (connection, id); xmmsc_result_wait (result); xmmsv_t *return_value = xmmsc_result_get_value (result); if (xmmsv_is_error (return_value)) { ol_error ("Get music info from XMMS2 failed."); } else { xmmsv_t *dict = xmmsv_propdict_to_dict (return_value, NULL); *len = ol_player_xmms2_get_dict_int (return_value, "duration"); xmmsv_unref (dict); } xmmsc_result_unref (result); } return TRUE; }
static int32_t ol_player_xmms2_get_currend_id () { /* ol_log_func (); */ if (!ol_player_xmms2_ensure_connection ()) return 0; int32_t ret = 0; xmmsc_result_t *result = xmmsc_playback_current_id (connection); xmmsc_result_wait (result); xmmsv_t *return_value = xmmsc_result_get_value (result); if (xmmsv_is_error (return_value)) { ol_error ("Error on getting current id"); ret = 0; } else { if (!xmmsv_get_int (return_value, &ret)) { ol_error ("Get id from result failed"); ret = 0; } } xmmsc_result_unref (result); return ret; }
void list_plugins (cli_infos_t *infos, xmmsc_result_t *res) { const gchar *name, *desc, *err; xmmsv_t *val; val = xmmsc_result_get_value (res); if (!xmmsv_get_error (val, &err)) { xmmsv_list_iter_t *it; xmmsv_get_list_iter (val, &it); for (xmmsv_list_iter_first (it); xmmsv_list_iter_valid (it); xmmsv_list_iter_next (it)) { xmmsv_t *elem; xmmsv_list_iter_entry (it, &elem); xmmsv_dict_entry_get_string (elem, "shortname", &name); xmmsv_dict_entry_get_string (elem, "description", &desc); g_printf ("%s - %s\n", name, desc); } } else { g_printf (_("Server error: %s\n"), err); } xmmsc_result_unref (res); cli_infos_loop_resume (infos); }
static void do_watch_dir (xmonitor_t *mon, const gchar *dirs) { xmmsc_result_t *res; GList *n; DBG ("We are going to watch '%s'", dirs); for (n = mon->dir_list; n; n = g_list_next (n)) { monitor_del_dir (mon, n->data); g_free (n->data); } if (mon->dir_list) { g_list_free (mon->dir_list); mon->dir_list = NULL; } if (strlen (dirs) < 1) { mon->watch_dir = NULL; return; } else { mon->watch_dir = g_strdup (dirs); } /* Make sure that nothing changed while we where away! */ res = xmmsc_medialib_path_import (mon->conn, mon->watch_dir); xmmsc_result_notifier_set (res, handle_addpath, mon); xmmsc_result_unref (res); }
void cmd_move (xmmsc_connection_t *conn, gint argc, gchar **argv) { xmmsc_result_t *res; guint cur_pos, new_pos, arg_start; gchar *playlist; if (argc < 4) { print_error ("You'll need to specifiy current and new position"); } if (argc == 4) { playlist = NULL; arg_start = 2; } else { playlist = argv[2]; arg_start = 3; } cur_pos = strtol (argv[arg_start], NULL, 10); new_pos = strtol (argv[arg_start + 1], NULL, 10); res = xmmsc_playlist_move_entry (conn, playlist, cur_pos, new_pos); xmmsc_result_wait (res); if (xmmsc_result_iserror (res)) { print_error ("Unable to move playlist entry: %s", xmmsc_result_get_error (res)); } xmmsc_result_unref (res); print_info ("Moved %u to %u", cur_pos, new_pos); }
void collection_print_config (xmmsc_result_t *res, cli_infos_t *infos, gchar *attrname) { xmmsv_coll_t *coll; gchar *attrvalue; xmmsv_t *val; val = xmmsc_result_get_value (res); if (xmmsv_get_coll (val, &coll)) { if (attrname == NULL) { xmmsc_coll_attribute_foreach (coll, coll_print_attributes, NULL); } else { if (xmmsc_coll_attribute_get (coll, attrname, &attrvalue)) { coll_print_attributes (attrname, attrvalue, NULL); } else { g_printf (_("Invalid attribute!\n")); } } } else { g_printf (_("Invalid collection!\n")); } cli_infos_loop_resume (infos); xmmsc_result_unref (res); }
static int handle_remove_from_mlib (xmmsv_t *v, void *userdata) { xmonitor_t *mon = userdata; xmmsc_result_t *res2; xmmsv_list_iter_t *it; for (xmmsv_get_list_iter (v, &it); xmmsv_list_iter_valid (it); xmmsv_list_iter_next (it)) { guint32 id; xmmsv_t *elem; if (!xmmsv_list_iter_entry (it, &elem) || !xmmsv_get_uint (elem, &id)) { ERR ("Failed to get entry id from hash!"); continue; } if (id == 0) { DBG ("Entry not in db!"); continue; } DBG ("Removing %d", id); res2 = xmmsc_medialib_remove_entry (mon->conn, id); xmmsc_result_unref (res2); } return FALSE; }
void cmd_addid (xmmsc_connection_t *conn, gint argc, gchar **argv) { gint i; gchar *playlist = NULL; xmmsc_result_t *res; if (argc < 3) { print_error ("Need a medialib id to add"); } for (i = 2; argv[i]; i++) { guint id = strtoul (argv[i], NULL, 10); if (id) { res = xmmsc_playlist_add_id (conn, playlist, id); xmmsc_result_wait (res); if (xmmsc_result_iserror (res)) { print_error ("Couldn't add %d to playlist: %s", id, xmmsc_result_get_error (res)); } xmmsc_result_unref (res); print_info ("Added medialib id %d to playlist", id); } else if (i == 2) { /* First argument is the playlist name */ playlist = argv[i]; } } }
static void updater_remove_directory (updater_t *updater, GFile *file) { xmmsc_result_t *res; xmmsv_t *univ, *coll; gchar *path, *pattern, *encoded; path = g_file_get_path (file); encoded = xmmsv_encode_url (path); g_free (path); pattern = g_strdup_printf ("file://%s/*", encoded); g_free (encoded); univ = xmmsv_new_coll (XMMS_COLLECTION_TYPE_UNIVERSE); coll = xmmsv_new_coll (XMMS_COLLECTION_TYPE_MATCH); xmmsv_coll_add_operand (coll, univ); xmmsv_coll_attribute_set_string (coll, "field", "url"); xmmsv_coll_attribute_set_string (coll, "value", pattern); xmmsv_coll_attribute_set_string (coll, "case-sensitive", "true"); g_debug ("remove '%s' from mlib", pattern); res = xmmsc_coll_query_ids (updater->conn, coll, NULL, 0, 0); xmmsc_result_notifier_set (res, updater_remove_directory_by_id, updater); xmmsc_result_unref (res); xmmsv_unref (coll); xmmsv_unref (univ); g_free (pattern); }
static int updater_rehash_file_by_id (xmmsv_t *value, void *udata) { xmmsc_result_t *res; updater_t *updater; int mid; updater = (updater_t *) udata; g_return_val_if_fail (updater, FALSE); if (!xmmsv_get_int (value, &mid)) { return FALSE; } if (!mid) { g_warning ("Couldn't find requested medialib entry."); return FALSE; } res = xmmsc_medialib_rehash (updater->conn, mid); xmmsc_result_unref (res); return FALSE; }
static void print_collections_list (xmmsc_result_t *res, cli_infos_t *infos, gchar *mark, gboolean all) { const gchar *s, *err; xmmsv_t *val; val = xmmsc_result_get_value (res); if (!xmmsv_get_error (val, &err)) { xmmsv_list_iter_t *it; xmmsv_get_list_iter (val, &it); while (xmmsv_list_iter_valid (it)) { xmmsv_t *entry; xmmsv_list_iter_entry (it, &entry); /* Skip hidden playlists if all is FALSE*/ if (xmmsv_get_string (entry, &s) && ((*s != '_') || all)) { /* Highlight active playlist */ if (mark && strcmp (s, mark) == 0) { g_printf ("* %s\n", s); } else { g_printf (" %s\n", s); } } xmmsv_list_iter_next (it); } } else { g_printf (_("Server error: %s\n"), err); } cli_infos_loop_resume (infos); xmmsc_result_unref (res); }
static int updater_remove_file_by_id (xmmsv_t *value, void *udata) { xmmsc_result_t *res; updater_t *updater; int mid; updater = (updater_t *) udata; g_return_val_if_fail (updater, FALSE); if (!xmmsv_get_int (value, &mid)) { g_error ("couldn't find this one!"); return FALSE; } if (!mid) { g_debug ("entry not in medialib"); return FALSE; } res = xmmsc_medialib_remove_entry (updater->conn, mid); xmmsc_result_unref (res); return FALSE; }
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); } }
void cmd_addpls (xmmsc_connection_t *conn, gint argc, gchar **argv) { gchar *playlist; xmmsc_result_t *res, *res2; xmmsv_t *val; xmmsv_coll_t *coll; gchar *url; if (argc < 3) { print_error ("Supply path to playlist file"); } if (argc == 3) { playlist = NULL; url = format_url (argv[2], G_FILE_TEST_IS_REGULAR); } else { playlist = argv[2]; url = format_url (argv[3], G_FILE_TEST_IS_REGULAR); } res = xmmsc_coll_idlist_from_playlist_file (conn, url); g_free (url); xmmsc_result_wait (res); val = xmmsc_result_get_value (res); if (xmmsv_is_error (val)) { print_error ("%s", xmmsv_get_error_old (val)); } if (!xmmsv_get_coll (val, &coll)) { print_error ("Couldn't get collection from result!"); } res2 = xmmsc_playlist_add_idlist (conn, playlist, coll); xmmsc_result_wait (res2); if (xmmsc_result_iserror (res2)) { print_error ("%s", xmmsc_result_get_error (res2)); } print_info ("Playlist with %d entries added", xmmsv_coll_idlist_get_size (coll)); xmmsc_result_unref (res); xmmsc_result_unref (res2); }
void Client::quit() { if( connected_ ) { xmmsc_result_t* res = xmmsc_quit( conn_ ); xmmsc_result_unref( res ); connected_ = false; } }
void print_stats (cli_infos_t *infos, xmmsc_result_t *res) { print_server_stats (res); cli_infos_loop_resume (infos); xmmsc_result_unref (res); }
void add_list (xmmsc_result_t *matching, cli_infos_t *infos, gchar *playlist, gint pos) { /* FIXME: w00t at code copy-paste, please modularize */ xmmsc_result_t *insres; guint id; gint offset; const gchar *err; xmmsv_t *val; val = xmmsc_result_get_value (matching); offset = 0; if (xmmsv_get_error (val, &err) || !xmmsv_is_list (val)) { g_printf (_("Error retrieving the media matching the pattern!\n")); } else { xmmsv_list_iter_t *it; xmmsv_get_list_iter (val, &it); /* Loop on the matched media */ for (xmmsv_list_iter_first (it); xmmsv_list_iter_valid (it); xmmsv_list_iter_next (it)) { xmmsv_t *entry; xmmsv_list_iter_entry (it, &entry); if (xmmsv_get_uint (entry, &id)) { insres = xmmsc_playlist_insert_id (infos->sync, playlist, pos + offset, id); xmmsc_result_wait (insres); xmmsc_result_unref (insres); offset++; } } } cli_infos_loop_resume (infos); xmmsc_result_unref (matching); }
/* Apply operation to an idlist */ void apply_ids (cli_infos_t *infos, xmmsc_result_t *res, idlist_command_t cmd) { const gchar *err; xmmsc_result_t *cmdres; xmmsv_t *val; val = xmmsc_result_get_value (res); if (!xmmsv_get_error (val, &err)) { xmmsv_list_iter_t *it; xmmsv_get_list_iter (val, &it); for (xmmsv_list_iter_first (it); xmmsv_list_iter_valid (it); xmmsv_list_iter_next (it)) { xmmsv_t *entry; guint id; xmmsv_list_iter_entry (it, &entry); if (xmmsv_get_uint (entry, &id)) { switch (cmd) { case IDLIST_CMD_REHASH: cmdres = xmmsc_medialib_rehash (infos->sync, id); break; case IDLIST_CMD_REMOVE: cmdres = xmmsc_medialib_remove_entry (infos->sync, id); break; default: break; } xmmsc_result_wait (cmdres); xmmsc_result_unref (cmdres); } } } else { g_printf (_("Server error: %s\n"), err); } cli_infos_loop_resume (infos); xmmsc_result_unref (res); }