Beispiel #1
0
/*
 * report back items in the playlist
 */
int
hgd_cmd_playlist(struct hgd_session *sess, char **args)
{
	char			*resp;
	struct hgd_playlist	 list;
	unsigned int		 i, num_votes;

	/* shhh */
	args = args;

	if (hgd_get_playlist(&list) == HGD_FAIL) {
		hgd_sock_send_line(sess->sock_fd, sess->ssl, "err|sql");
		return (HGD_FAIL);
	}

	/* and respond to client */
	xasprintf(&resp, "ok|%d", list.n_items);
	hgd_sock_send_line(sess->sock_fd, sess->ssl, resp);
	free(resp);

	num_votes = hgd_get_num_votes();


	for (i = 0; i < list.n_items; i++) {
		xasprintf(&resp, "%d|%s|%s|%s|%s|%s|%s|%d|%d|%d|%d|%d|%d",
		    list.items[i]->id,
		    list.items[i]->filename + strlen(HGD_UNIQ_FILE_PFX),
		    list.items[i]->tags.artist,
		    list.items[i]->tags.title,
		    list.items[i]->user,
		    list.items[i]->tags.album,
		    list.items[i]->tags.genre,
		    list.items[i]->tags.duration,
		    list.items[i]->tags.bitrate,
		    list.items[i]->tags.samplerate,
		    list.items[i]->tags.channels,
		    list.items[i]->tags.year,
		    (i == 0 ? (req_votes - num_votes) : req_votes)
		);
		hgd_sock_send_line(sess->sock_fd, sess->ssl, resp);
		DPRINTF(HGD_D_DEBUG, "%s\n", resp);
		free(resp);
	}

	hgd_free_playlist(&list);

	return (HGD_OK);
}
Beispiel #2
0
int
hgd_update_playlist_win(struct ui *u)
{
	ITEM			**items = NULL;
	int			  i, ret = HGD_FAIL;
	char			 *item_str;
	struct hgd_playlist	 *playlist = NULL;
	char			 *track_str;

	DPRINTF(HGD_D_INFO, "Update playlist window");

	hgd_set_statusbar_text(u, "Connected >>> Fetching playlist");

	if (sock_fd == -1) {
		ret = HGD_OK;
		goto clean;
	}

	wclear(u->content_wins[HGD_WIN_PLAYLIST]);
	hgd_unpost_and_free_content_menu(u, HGD_WIN_PLAYLIST);

	/* and now populate the menu */
	if (hgd_cli_get_playlist(&playlist) != HGD_OK) {
		goto clean;
	}

	if (playlist->n_items == 0) {
		ret = HGD_OK;
		mvwprintw(u->content_wins[HGD_WIN_PLAYLIST], 0, 0, "Playlist Empty - Saddest of times!");
		goto clean;
	}

	items = xcalloc(playlist->n_items + 1, sizeof(ITEM *));
	for (i = 0; i < playlist->n_items; i++) {

		DPRINTF(HGD_D_DEBUG, "Adding item \"%s\"",
		    playlist->items[i]->tags.title);

		if ((strcmp(playlist->items[i]->tags.artist, "")) ||
		    (strcmp(playlist->items[i]->tags.title, ""))) {

			xasprintf(&track_str, "#%03d from %-8s: '%s' by '%s'",
			    playlist->items[i]->id,
			    playlist->items[i]->user,
			    playlist->items[i]->tags.title,
			    playlist->items[i]->tags.artist);
		} else  {
			xasprintf(&track_str, "#%03d from %-8s: '%s'",
			    playlist->items[i]->id,
			    playlist->items[i]->user,
			    playlist->items[i]->filename);
		}

		hgd_prepare_item_string(&item_str, track_str);
		free(track_str);

		items[i] = new_item(item_str, NULL);
		if (items[i] == NULL)
			DPRINTF(HGD_D_WARN, "Could not make new item: %s", SERROR);
	}

	u->content_menus[HGD_WIN_PLAYLIST] = new_menu(items);
	if (u->content_menus[HGD_WIN_PLAYLIST] == NULL) {
			DPRINTF(HGD_D_ERROR, "Could not make menu");
			goto clean;
	}

	set_menu_win(u->content_menus[HGD_WIN_PLAYLIST],
	    u->content_wins[HGD_WIN_PLAYLIST]);
	set_menu_mark(u->content_menus[HGD_WIN_PLAYLIST], "");
	set_menu_format(u->content_menus[HGD_WIN_PLAYLIST], LINES - 2, 1);
	set_menu_fore(u->content_menus[HGD_WIN_PLAYLIST],
	    COLOR_PAIR(HGD_CPAIR_SELECTED));

	if ((post_menu(u->content_menus[HGD_WIN_PLAYLIST])) != E_OK) {
		DPRINTF(HGD_D_ERROR, "Could not post menu");
		goto clean;
	}

	hgd_set_standard_statusbar_text(u);

	ret = HGD_OK;
clean:
	if (playlist)
		hgd_free_playlist(playlist);
#if 0
	if (items)
		free(items);
#endif
	if (playlist)
		free(playlist);

	return (ret);
}