Code

options.c: Read mpd host from environment if not specified.
[ncmpc.git] / src / screen_browser.c
index ef6614167d31f30a21c03f2834cedf40152b0a0b..04673f4e85a7e5632525a3cf19820fcab1d80ad6 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
@@ -17,6 +17,7 @@
  * 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"
@@ -44,8 +45,6 @@
 #define HIGHLIGHT  (0x01)
 #endif
 
-static const char playlist_format[] = "*%s*";
-
 #ifndef NCMPC_MINI
 
 /* sync highlight flags with playlist */
@@ -111,7 +110,7 @@ browser_lw_callback(unsigned idx, void *data)
                        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;
        }
@@ -144,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;
 
@@ -330,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;
@@ -484,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)
 {