Code

*: use Compiler.h macros instead of glib.h
[ncmpc.git] / src / screen_queue.c
index fbcc18039a98d593e8cf6d153fb00c47f4c6a263..87cdc63ad0a517c86c144d1652bafc75bb610af8 100644 (file)
@@ -1,5 +1,5 @@
 /* ncmpc (Ncurses MPD Client)
- * (c) 2004-2009 The Music Player Daemon Project
+ * (c) 2004-2010 The Music Player Daemon Project
  * Project homepage: http://musicpd.org
  *
  * This program is free software; you can redistribute it and/or modify
@@ -20,7 +20,7 @@
 #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"
@@ -35,6 +35,7 @@
 #include "screen_utils.h"
 #include "screen_song.h"
 #include "screen_lyrics.h"
+#include "Compiler.h"
 
 #ifndef NCMPC_MINI
 #include "hscroll.h"
@@ -118,7 +119,7 @@ screen_queue_restore_selection(void)
 }
 
 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;
@@ -159,7 +160,7 @@ center_playing_item(const struct mpd_status *status, bool center_cursor)
        list_window_fetch_cursor(lw);
 }
 
-G_GNUC_PURE
+gcc_pure
 static int
 get_current_song_id(const struct mpd_status *status)
 {
@@ -187,7 +188,7 @@ screen_queue_song_change(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;
@@ -202,9 +203,9 @@ save_pre_completion_cb(GCompletion *gcmp, G_GNUC_UNUSED gchar *line,
 }
 
 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);
@@ -253,7 +254,7 @@ playlist_save(struct mpdclient *c, char *name, char *defaultname)
 
 
                /* query the user for a filename */
-               filename = screen_readln(_("Save playlist as"),
+               filename = screen_readln(_("Save queue as"),
                                         defaultname,
                                         NULL,
                                         gcmp);
@@ -268,7 +269,7 @@ playlist_save(struct mpdclient *c, char *name, char *defaultname)
                        filename=g_strstrip(filename);
        } else
 #endif
-                       filename=g_strdup(name);
+               filename=g_strdup(name);
 
        if (filename == NULL)
                return -1;
@@ -276,8 +277,10 @@ playlist_save(struct mpdclient *c, char *name, char *defaultname)
        /* send save command to mpd */
 
        connection = mpdclient_get_connection(c);
-       if (connection == NULL)
+       if (connection == NULL) {
+               g_free(filename);
                return -1;
+       }
 
        filename_utf8 = locale_to_utf8(filename);
        if (!mpd_run_save(connection, filename_utf8)) {
@@ -285,14 +288,14 @@ playlist_save(struct mpdclient *c, char *name, char *defaultname)
                    mpd_connection_get_server_error(connection) == MPD_SERVER_ERROR_EXIST &&
                    mpd_connection_clear_error(connection)) {
                        char *buf;
-                       int key;
+                       bool replace;
 
                        buf = g_strdup_printf(_("Replace %s [%s/%s] ? "),
                                              filename, YES, NO);
-                       key = tolower(screen_getch(buf));
+                       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"));
@@ -503,16 +506,16 @@ static const char *
 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 void *data)
 {
        const struct mpd_song *song;
        struct hscroll *row_hscroll;
@@ -550,6 +553,10 @@ screen_queue_update(struct mpdclient *c)
 {
        if (c->events & MPD_IDLE_QUEUE)
                screen_queue_restore_selection();
+       else
+               /* the queue size may have changed, even if we havn't
+                  received the QUEUE idle event yet */
+               list_window_set_length(lw, playlist_length(playlist));
 
        if (((c->events & MPD_IDLE_PLAYER) != 0 &&
             screen_queue_song_change(c->status)) ||
@@ -694,7 +701,10 @@ screen_queue_cmd(struct mpdclient *c, command_t cmd)
                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:
@@ -734,7 +744,7 @@ screen_queue_cmd(struct mpdclient *c, command_t cmd)
 
        case CMD_SHUFFLE:
                list_window_get_range(lw, &range);
-               if (range.end < range.start + 1)
+               if (range.end <= range.start + 1)
                        /* No range selection, shuffle all list. */
                        break;
 
@@ -743,7 +753,7 @@ screen_queue_cmd(struct mpdclient *c, command_t cmd)
                        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;
@@ -759,6 +769,10 @@ screen_queue_cmd(struct mpdclient *c, command_t cmd)
                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;
 
@@ -773,6 +787,10 @@ screen_queue_cmd(struct mpdclient *c, command_t cmd)
                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;