diff --git a/src/screen_browser.c b/src/screen_browser.c
index 994ea2dd5f61150ec95bcd758785897fc86d14e7..04673f4e85a7e5632525a3cf19820fcab1d80ad6 100644 (file)
--- a/src/screen_browser.c
+++ b/src/screen_browser.c
/* 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
* 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 "strfsong.h"
#include "mpdclient.h"
#include "filelist.h"
+#include "colors.h"
+#include "paint.h"
+#include "song_paint.h"
#include <mpd/client.h>
#define HIGHLIGHT (0x01)
#endif
-static const char playlist_format[] = "*%s*";
-
#ifndef NCMPC_MINI
/* sync highlight flags with playlist */
/* 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];
@@ -87,21 +89,15 @@ 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 "[..]";
+ return "..";
if (mpd_entity_get_type(entity) == MPD_ENTITY_TYPE_DIRECTORY) {
const struct mpd_directory *dir =
mpd_entity_get_directory(entity);
char *directory = utf8_to_locale(g_basename(mpd_directory_get_path(dir)));
-
- g_snprintf(buf, BUFSIZE, "[%s]", directory);
+ g_strlcpy(buf, directory, sizeof(buf));
g_free(directory);
return buf;
} else if (mpd_entity_get_type(entity) == MPD_ENTITY_TYPE_SONG) {
@@ -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;
}
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;
}
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;
{
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) {
{
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;
@@ -384,6 +388,10 @@ browser_handle_mouse_event(struct screen_browser *browser, struct mpdclient *c)
}
#endif
+static void
+screen_browser_paint_callback(WINDOW *w, unsigned i, unsigned y,
+ unsigned width, bool selected, void *data);
+
bool
browser_cmd(struct screen_browser *browser,
struct mpdclient *c, command_t cmd)
browser->filelist);
return true;
case CMD_LIST_JUMP:
- screen_jump(browser->lw, browser_lw_callback, browser->filelist);
+ screen_jump(browser->lw, browser_lw_callback,
+ screen_browser_paint_callback, browser->filelist);
return true;
#ifdef HAVE_GETMOUSE
return false;
}
+void
+screen_browser_paint_directory(WINDOW *w, unsigned width,
+ bool selected, const char *name)
+{
+ row_color(w, COLOR_DIRECTORY, selected);
+
+ waddch(w, '[');
+ waddstr(w, name);
+ waddch(w, ']');
+
+ /* erase the unused space after the text */
+ row_clear_to_eol(w, width, selected);
+}
+
+static void
+screen_browser_paint_playlist(WINDOW *w, unsigned width,
+ bool selected, const char *name)
+{
+ row_paint_text(w, width, COLOR_PLAYLIST, selected, name);
+}
+
+static void
+screen_browser_paint_callback(WINDOW *w, unsigned i,
+ unsigned y, unsigned width,
+ bool selected, void *data)
+{
+ const struct filelist *fl = (const struct filelist *) data;
+ const struct filelist_entry *entry;
+ const struct mpd_entity *entity;
+ bool highlight;
+ const struct mpd_directory *directory;
+ const struct mpd_playlist *playlist;
+ char *p;
+
+ assert(fl != NULL);
+ assert(i < filelist_length(fl));
+
+ entry = filelist_get(fl, i);
+ assert(entry != NULL);
+
+ entity = entry->entity;
+ if (entity == NULL) {
+ screen_browser_paint_directory(w, width, selected, "..");
+ return;
+ }
+
+#ifndef NCMPC_MINI
+ highlight = (entry->flags & HIGHLIGHT) != 0;
+#else
+ highlight = false;
+#endif
+
+ switch (mpd_entity_get_type(entity)) {
+ case MPD_ENTITY_TYPE_DIRECTORY:
+ directory = mpd_entity_get_directory(entity);
+ p = utf8_to_locale(g_basename(mpd_directory_get_path(directory)));
+ screen_browser_paint_directory(w, width, selected, p);
+ g_free(p);
+ break;
+
+ case MPD_ENTITY_TYPE_SONG:
+ paint_song_row(w, y, width, selected, highlight,
+ mpd_entity_get_song(entity), NULL);
+ break;
+
+ case MPD_ENTITY_TYPE_PLAYLIST:
+ playlist = mpd_entity_get_playlist(entity);
+ p = utf8_to_locale(g_basename(mpd_playlist_get_path(playlist)));
+ screen_browser_paint_playlist(w, width, selected, p);
+ g_free(p);
+ break;
+
+ default:
+ row_paint_text(w, width, highlight ? COLOR_LIST_BOLD : COLOR_LIST,
+ selected, "<unknown>");
+ }
+}
+
void
screen_browser_paint(const struct screen_browser *browser)
{
- list_window_paint(browser->lw, browser_lw_callback, browser->filelist);
+ list_window_paint2(browser->lw, screen_browser_paint_callback,
+ browser->filelist);
}