Code

screen_queue: rename "playlist" to "queue"
[ncmpc.git] / src / screen_browser.c
index edcd2d93bbbc9c820eac4701be8e1fcfb7fd46ef..936bd1f26ac5d360c69d0c55ceab80b598c5f318 100644 (file)
@@ -1,27 +1,28 @@
 /* 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
  * it under the terms of the GNU General Public License as published by
  * the Free Software Foundation; either version 2 of the License, or
  * (at your option) any later version.
-
+ *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
-
+ *
  * You should have received a copy of the GNU General Public License along
  * with this program; if not, write to the Free Software Foundation, Inc.,
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-*/
+ */
 
+#include "config.h"
 #include "screen_browser.h"
 #include "screen_file.h"
 #include "screen_song.h"
 #include "screen_lyrics.h"
-#include "screen_message.h"
+#include "screen_status.h"
 #include "screen_find.h"
 #include "screen.h"
 #include "i18n.h"
@@ -32,6 +33,7 @@
 #include "filelist.h"
 #include "colors.h"
 #include "paint.h"
+#include "song_paint.h"
 
 #include <mpd/client.h>
 
@@ -43,8 +45,6 @@
 #define HIGHLIGHT  (0x01)
 #endif
 
-static const char playlist_format[] = "*%s*";
-
 #ifndef NCMPC_MINI
 
 /* sync highlight flags with playlist */
@@ -75,7 +75,7 @@ screen_browser_sync_highlights(struct filelist *fl,
 
 /* list_window callback */
 static const char *
-browser_lw_callback(unsigned idx, bool *highlight, G_GNUC_UNUSED char **second_column, void *data)
+browser_lw_callback(unsigned idx, void *data)
 {
        const struct filelist *fl = (const struct filelist *) data;
        static char buf[BUFSIZE];
@@ -89,11 +89,6 @@ browser_lw_callback(unsigned idx, bool *highlight, G_GNUC_UNUSED char **second_c
        assert(entry != NULL);
 
        entity = entry->entity;
-#ifndef NCMPC_MINI
-       *highlight = (entry->flags & HIGHLIGHT) != 0;
-#else
-       *highlight = false;
-#endif
 
        if( entity == NULL )
                return "..";
@@ -103,6 +98,7 @@ browser_lw_callback(unsigned idx, bool *highlight, G_GNUC_UNUSED char **second_c
                        mpd_entity_get_directory(entity);
                char *directory = utf8_to_locale(g_basename(mpd_directory_get_path(dir)));
                g_strlcpy(buf, directory, sizeof(buf));
+               g_free(directory);
                return buf;
        } else if (mpd_entity_get_type(entity) == MPD_ENTITY_TYPE_SONG) {
                const struct mpd_song *song = mpd_entity_get_song(entity);
@@ -114,7 +110,7 @@ browser_lw_callback(unsigned idx, bool *highlight, G_GNUC_UNUSED char **second_c
                        mpd_entity_get_playlist(entity);
                char *filename = utf8_to_locale(g_basename(mpd_playlist_get_path(playlist)));
 
-               g_snprintf(buf, BUFSIZE, playlist_format, filename);
+               g_strlcpy(buf, filename, sizeof(buf));
                g_free(filename);
                return buf;
        }
@@ -126,16 +122,20 @@ static bool
 load_playlist(struct mpdclient *c, const struct mpd_playlist *playlist)
 {
        struct mpd_connection *connection = mpdclient_get_connection(c);
-       char *filename = utf8_to_locale(mpd_playlist_get_path(playlist));
+
+       if (connection == NULL)
+               return false;
 
        if (mpd_run_load(connection, mpd_playlist_get_path(playlist))) {
+               char *filename = utf8_to_locale(mpd_playlist_get_path(playlist));
                screen_status_printf(_("Loading playlist %s..."),
                                     g_basename(filename));
+               g_free(filename);
+
                c->events |= MPD_IDLE_QUEUE;
        } else
                mpdclient_handle_error(c);
 
-       g_free(filename);
        return true;
 }
 
@@ -143,6 +143,9 @@ static bool
 enqueue_and_play(struct mpdclient *c, struct filelist_entry *entry)
 {
        struct mpd_connection *connection = mpdclient_get_connection(c);
+       if (connection == NULL)
+               return false;
+
        const struct mpd_song *song = mpd_entity_get_song(entry->entity);
        int id;
 
@@ -166,7 +169,7 @@ enqueue_and_play(struct mpdclient *c, struct filelist_entry *entry)
                entry->flags |= HIGHLIGHT;
 #endif
                strfsong(buf, BUFSIZE, options.list_format, song);
-               screen_status_printf(_("Adding \'%s\' to playlist"), buf);
+               screen_status_printf(_("Adding \'%s\' to queue"), buf);
        }
 
        if (!mpd_run_play_id(connection, id)) {
@@ -261,7 +264,7 @@ browser_select_entry(struct mpdclient *c, struct filelist_entry *entry,
                if (mpdclient_cmd_add_path(c, mpd_directory_get_path(dir))) {
                        char *tmp = utf8_to_locale(mpd_directory_get_path(dir));
 
-                       screen_status_printf(_("Adding \'%s\' to playlist"), tmp);
+                       screen_status_printf(_("Adding \'%s\' to queue"), tmp);
                        g_free(tmp);
                }
 
@@ -286,7 +289,7 @@ browser_select_entry(struct mpdclient *c, struct filelist_entry *entry,
                        char buf[BUFSIZE];
 
                        strfsong(buf, BUFSIZE, options.list_format, song);
-                       screen_status_printf(_("Adding \'%s\' to playlist"), buf);
+                       screen_status_printf(_("Adding \'%s\' to queue"), buf);
                }
 #ifndef NCMPC_MINI
        } else {
@@ -311,7 +314,7 @@ browser_handle_select(struct screen_browser *browser, struct mpdclient *c)
 {
        struct list_window_range range;
        struct filelist_entry *entry;
-       bool success;
+       bool success = false;
 
        list_window_get_range(browser->lw, &range);
        for (unsigned i = range.start; i < range.end; ++i) {
@@ -329,14 +332,15 @@ browser_handle_add(struct screen_browser *browser, struct mpdclient *c)
 {
        struct list_window_range range;
        struct filelist_entry *entry;
-       bool success;
+       bool success = false;
 
        list_window_get_range(browser->lw, &range);
        for (unsigned i = range.start; i < range.end; ++i) {
                entry = browser_get_index(browser, i);
 
                if (entry != NULL && entry->entity != NULL)
-                       success = browser_select_entry(c, entry, FALSE);
+                       success = browser_select_entry(c, entry, FALSE) ||
+                               success;
        }
 
        return range.end == range.start + 1 && success;
@@ -483,7 +487,7 @@ browser_cmd(struct screen_browser *browser,
        return false;
 }
 
-static void
+void
 screen_browser_paint_directory(WINDOW *w, unsigned width,
                               bool selected, const char *name)
 {
@@ -497,17 +501,6 @@ screen_browser_paint_directory(WINDOW *w, unsigned width,
        row_clear_to_eol(w, width, selected);
 }
 
-static void
-screen_browser_paint_song(WINDOW *w, unsigned width, bool selected,
-                         bool highlight, const struct mpd_song *song)
-{
-       char buffer[width * 4];
-
-       strfsong(buffer, sizeof(buffer), options.list_format, song);
-       row_paint_text(w, width, highlight ? COLOR_LIST_BOLD : COLOR_LIST,
-                      selected, buffer);
-}
-
 static void
 screen_browser_paint_playlist(WINDOW *w, unsigned width,
                              bool selected, const char *name)
@@ -517,7 +510,7 @@ screen_browser_paint_playlist(WINDOW *w, unsigned width,
 
 static void
 screen_browser_paint_callback(WINDOW *w, unsigned i,
-                             G_GNUC_UNUSED unsigned y, unsigned width,
+                             unsigned y, unsigned width,
                              bool selected, void *data)
 {
        const struct filelist *fl = (const struct filelist *) data;
@@ -546,11 +539,6 @@ screen_browser_paint_callback(WINDOW *w, unsigned i,
        highlight = false;
 #endif
 
-       if (highlight)
-               colors_use(w, COLOR_LIST_BOLD);
-       else
-               colors_use(w, COLOR_LIST);
-
        switch (mpd_entity_get_type(entity)) {
        case MPD_ENTITY_TYPE_DIRECTORY:
                directory = mpd_entity_get_directory(entity);
@@ -560,8 +548,8 @@ screen_browser_paint_callback(WINDOW *w, unsigned i,
                break;
 
        case MPD_ENTITY_TYPE_SONG:
-               screen_browser_paint_song(w, width, selected, highlight,
-                                         mpd_entity_get_song(entity));
+               paint_song_row(w, y, width, selected, highlight,
+                              mpd_entity_get_song(entity), NULL);
                break;
 
        case MPD_ENTITY_TYPE_PLAYLIST:
@@ -572,13 +560,9 @@ screen_browser_paint_callback(WINDOW *w, unsigned i,
                break;
 
        default:
-               waddstr(w, "<unknown>");
+               row_paint_text(w, width, highlight ? COLOR_LIST_BOLD : COLOR_LIST,
+                              selected, "<unknown>");
        }
-
-       whline(w, ' ', width);
-
-       if (selected)
-               wattroff(w, A_REVERSE);
 }
 
 void