diff --git a/src/screen_queue.c b/src/screen_queue.c
index 863c3dd5f38442e6e432a58d90d8038321869acb..7c1041cadfe28268e5210b95c97c09c4a4c6c031 100644 (file)
--- a/src/screen_queue.c
+++ b/src/screen_queue.c
#include "screen_queue.h"
#include "screen_interface.h"
#include "screen_file.h"
-#include "screen_message.h"
+#include "screen_status.h"
#include "screen_find.h"
#include "config.h"
#include "i18n.h"
#include "screen_utils.h"
#include "screen_song.h"
#include "screen_lyrics.h"
+#include "Compiler.h"
#ifndef NCMPC_MINI
#include "hscroll.h"
static void
screen_queue_restore_selection(void)
{
- const struct mpd_song *song;
- int pos;
-
list_window_set_length(lw, playlist_length(playlist));
if (selected_song_id < 0)
/* there was no selection */
return;
- song = screen_queue_selected_song();
+ const struct mpd_song *song = screen_queue_selected_song();
if (song != NULL &&
mpd_song_get_id(song) == (unsigned)selected_song_id)
/* selection is still valid */
return;
- pos = playlist_get_index_from_id(playlist, selected_song_id);
+ int pos = playlist_get_index_from_id(playlist, selected_song_id);
if (pos >= 0)
list_window_set_cursor(lw, pos);
}
static const char *
-screen_queue_lw_callback(unsigned idx, G_GNUC_UNUSED void *data)
+screen_queue_lw_callback(unsigned idx, gcc_unused void *data)
{
static char songname[MAX_SONG_LENGTH];
- struct mpd_song *song;
assert(playlist != NULL);
assert(idx < playlist_length(playlist));
- song = playlist_get(playlist, idx);
+ struct mpd_song *song = playlist_get(playlist, idx);
strfsong(songname, MAX_SONG_LENGTH, options.list_format, song);
static void
center_playing_item(const struct mpd_status *status, bool center_cursor)
{
- int idx;
-
if (status == NULL ||
(mpd_status_get_state(status) != MPD_STATE_PLAY &&
mpd_status_get_state(status) != MPD_STATE_PAUSE))
return;
/* try to center the song that are playing */
- idx = mpd_status_get_song_pos(status);
+ int idx = mpd_status_get_song_pos(status);
if (idx < 0)
return;
list_window_fetch_cursor(lw);
}
-G_GNUC_PURE
+gcc_pure
static int
get_current_song_id(const struct mpd_status *status)
{
#ifndef NCMPC_MINI
static void
-save_pre_completion_cb(GCompletion *gcmp, G_GNUC_UNUSED gchar *line,
+save_pre_completion_cb(GCompletion *gcmp, gcc_unused gchar *line,
void *data)
{
completion_callback_data_t *tmp = (completion_callback_data_t *)data;
}
static void
-save_post_completion_cb(G_GNUC_UNUSED GCompletion *gcmp,
- G_GNUC_UNUSED gchar *line, GList *items,
- G_GNUC_UNUSED void *data)
+save_post_completion_cb(gcc_unused GCompletion *gcmp,
+ gcc_unused gchar *line, GList *items,
+ gcc_unused void *data)
{
if (g_list_length(items) >= 1)
screen_display_completion_list(items);
playlist_save(struct mpdclient *c, char *name, char *defaultname)
{
struct mpd_connection *connection;
- gchar *filename, *filename_utf8;
-#ifndef NCMPC_MINI
- GCompletion *gcmp;
- GList *list = NULL;
- completion_callback_data_t data;
-#endif
+ gchar *filename;
#ifdef NCMPC_MINI
(void)defaultname;
#ifndef NCMPC_MINI
if (name == NULL) {
/* initialize completion support */
- gcmp = g_completion_new(NULL);
+ GCompletion *gcmp = g_completion_new(NULL);
g_completion_set_compare(gcmp, completion_strncmp);
- data.list = &list;
- data.dir_list = NULL;
- data.c = c;
+ GList *list = NULL;
+ completion_callback_data_t data = {
+ .list = &list,
+ .dir_list = NULL,
+ .c = c,
+ };
wrln_completion_callback_data = &data;
wrln_pre_completion_callback = save_pre_completion_cb;
wrln_post_completion_callback = save_post_completion_cb;
/* query the user for a filename */
- filename = screen_readln(_("Save playlist as"),
+ filename = screen_readln(_("Save queue as"),
defaultname,
NULL,
gcmp);
filename=g_strstrip(filename);
} else
#endif
- filename=g_strdup(name);
+ filename=g_strdup(name);
if (filename == NULL)
return -1;
return -1;
}
- filename_utf8 = locale_to_utf8(filename);
+ char *filename_utf8 = locale_to_utf8(filename);
if (!mpd_run_save(connection, filename_utf8)) {
if (mpd_connection_get_error(connection) == MPD_ERROR_SERVER &&
mpd_connection_get_server_error(connection) == MPD_SERVER_ERROR_EXIST &&
mpd_connection_clear_error(connection)) {
- char *buf;
- int key;
-
- buf = g_strdup_printf(_("Replace %s [%s/%s] ? "),
- filename, YES, NO);
- key = tolower(screen_getch(buf));
+ char *buf = g_strdup_printf(_("Replace %s [%s/%s] ? "),
+ filename, YES, NO);
+ bool replace = screen_get_yesno(buf, false);
g_free(buf);
- if (key != YES[0]) {
+ if (!replace) {
g_free(filename_utf8);
g_free(filename);
screen_status_printf(_("Aborted"));
static int
handle_add_to_playlist(struct mpdclient *c)
{
- gchar *path;
- GCompletion *gcmp;
#ifndef NCMPC_MINI
+ /* initialize completion support */
+ GCompletion *gcmp = g_completion_new(NULL);
+ g_completion_set_compare(gcmp, completion_strncmp);
+
GList *list = NULL;
GList *dir_list = NULL;
- completion_callback_data_t data;
+ completion_callback_data_t data = {
+ .list = &list,
+ .dir_list = &dir_list,
+ .c = c,
+ };
- /* initialize completion support */
- gcmp = g_completion_new(NULL);
- g_completion_set_compare(gcmp, completion_strncmp);
- data.list = &list;
- data.dir_list = &dir_list;
- data.c = c;
wrln_completion_callback_data = &data;
wrln_pre_completion_callback = add_pre_completion_cb;
wrln_post_completion_callback = add_post_completion_cb;
#else
- gcmp = NULL;
+ GCompletion *gcmp = NULL;
#endif
/* get path */
- path = screen_readln(_("Add"),
- NULL,
- NULL,
- gcmp);
+ char *path = screen_readln(_("Add"),
+ NULL,
+ NULL,
+ gcmp);
/* destroy completion data */
#ifndef NCMPC_MINI
screen_queue_title(char *str, size_t size)
{
if (options.host == NULL)
- return _("Playlist");
+ return _("Queue");
- g_snprintf(str, size, _("Playlist on %s"), options.host);
+ g_snprintf(str, size, _("Queue on %s"), options.host);
return str;
}
static void
screen_queue_paint_callback(WINDOW *w, unsigned i,
unsigned y, unsigned width,
- bool selected, G_GNUC_UNUSED void *data)
+ bool selected, gcc_unused const void *data)
{
- const struct mpd_song *song;
- struct hscroll *row_hscroll;
-
assert(playlist != NULL);
assert(i < playlist_length(playlist));
- song = playlist_get(playlist, i);
+ const struct mpd_song *song = playlist_get(playlist, i);
-#ifdef NCMPC_MINI
- row_hscroll = NULL;
-#else
+ struct hscroll *row_hscroll = NULL;
+#ifndef NCMPC_MINI
row_hscroll = selected && options.scroll && lw->selected == i
? &hscroll : NULL;
#endif
paint_song_row(w, y, width, selected,
(int)mpd_song_get_id(song) == current_song_id,
- song, row_hscroll);
+ song, row_hscroll, options.list_format);
}
static void
screen_queue_restore_selection();
else
/* the queue size may have changed, even if we havn't
- revceived the QUEUE idle event yet */
+ received the QUEUE idle event yet */
list_window_set_length(lw, playlist_length(playlist));
if (((c->events & MPD_IDLE_PLAYER) != 0 &&
static bool
handle_mouse_event(struct mpdclient *c)
{
- int row;
unsigned long bstate;
- unsigned old_selected;
-
+ int row;
if (screen_get_mouse_event(c, &bstate, &row) ||
list_window_mouse(lw, bstate, row)) {
screen_queue_repaint();
return true;
}
- old_selected = lw->selected;
+ const unsigned old_selected = lw->selected;
list_window_set_cursor(lw, lw->start + row);
if (bstate & BUTTON1_CLICKED) {
{
struct mpd_connection *connection;
static command_t cached_cmd = CMD_NONE;
- command_t prev_cmd = cached_cmd;
- struct list_window_range range;
- const struct mpd_song *song;
+ const command_t prev_cmd = cached_cmd;
cached_cmd = cmd;
lw->hide_cursor = false;
screen_queue_repaint();
return true;
case CMD_LIST_JUMP:
- screen_jump(lw, screen_queue_lw_callback, NULL, NULL);
+ screen_jump(lw, screen_queue_lw_callback, NULL, NULL, NULL);
screen_queue_save_selection();
screen_queue_repaint();
return true;
break;
#endif
case CMD_SCREEN_SWAP:
- screen_swap(c, playlist_get(&c->playlist, lw->selected));
+ if (playlist_length(&c->playlist) > 0)
+ screen_swap(c, playlist_get(&c->playlist, lw->selected));
+ else
+ screen_swap(c, NULL);
return true;
default:
return false;
switch(cmd) {
+ const struct mpd_song *song;
+ struct list_window_range range;
+
case CMD_PLAY:
song = screen_queue_selected_song();
if (song == NULL)
return true;
if (mpd_run_shuffle_range(connection, range.start, range.end))
- screen_status_message(_("Shuffled playlist"));
+ screen_status_message(_("Shuffled queue"));
else
mpdclient_handle_error(c);
return true;
if (!mpdclient_cmd_move(c, range.end - 1, range.start - 1))
return true;
- list_window_move_cursor(lw, lw->selected - 1);
+ lw->selected--;
+ lw->range_base--;
+
+ if (lw->range_selection)
+ list_window_scroll_to(lw, lw->range_base);
+ list_window_scroll_to(lw, lw->selected);
screen_queue_save_selection();
return true;
if (!mpdclient_cmd_move(c, range.start, range.end))
return true;
- list_window_move_cursor(lw, lw->selected + 1);
+ lw->selected++;
+ lw->range_base++;
+
+ if (lw->range_selection)
+ list_window_scroll_to(lw, lw->range_base);
+ list_window_scroll_to(lw, lw->selected);
screen_queue_save_selection();
return true;