diff --git a/src/screen_browser.c b/src/screen_browser.c
index 49827647d6e8f0898032fbad629c3b69b6e3a6e9..c38ae9ea81490f539723a4e7e6dd2e8da0fc76d8 100644 (file)
--- a/src/screen_browser.c
+++ b/src/screen_browser.c
/* ncmpc (Ncurses MPD Client)
- * (c) 2004-2010 The Music Player Daemon Project
+ * (c) 2004-2017 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"
#define HIGHLIGHT (0x01)
#endif
-static const char playlist_format[] = "*%s*";
-
#ifndef NCMPC_MINI
/* sync highlight flags with playlist */
screen_browser_sync_highlights(struct filelist *fl,
const struct mpdclient_playlist *playlist)
{
- guint i;
-
- for (i = 0; i < filelist_length(fl); ++i) {
+ for (unsigned i = 0; i < filelist_length(fl); ++i) {
struct filelist_entry *entry = filelist_get(fl, i);
const struct mpd_entity *entity = entry->entity;
{
const struct filelist *fl = (const struct filelist *) data;
static char buf[BUFSIZE];
- const struct filelist_entry *entry;
- const struct mpd_entity *entity;
assert(fl != NULL);
assert(idx < filelist_length(fl));
- entry = filelist_get(fl, idx);
+ const struct filelist_entry *entry = filelist_get(fl, idx);
assert(entry != NULL);
- entity = entry->entity;
+ const struct mpd_entity *entity = entry->entity;
if( entity == NULL )
return "..";
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;
}
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;
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)) {
browser_handle_enter(struct screen_browser *browser, struct mpdclient *c)
{
struct filelist_entry *entry = browser_get_selected_entry(browser);
- struct mpd_entity *entity;
-
if (entry == NULL)
return false;
- entity = entry->entity;
+ struct mpd_entity *entity = entry->entity;
if (entity == NULL)
return false;
static bool
browser_select_entry(struct mpdclient *c, struct filelist_entry *entry,
- G_GNUC_UNUSED gboolean toggle)
+ gcc_unused gboolean toggle)
{
assert(entry != NULL);
assert(entry->entity != NULL);
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);
}
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 {
browser_handle_select(struct screen_browser *browser, struct mpdclient *c)
{
struct list_window_range range;
- struct filelist_entry *entry;
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);
-
+ struct filelist_entry *entry = browser_get_index(browser, i);
if (entry != NULL && entry->entity != NULL)
success = browser_select_entry(c, entry, TRUE);
}
browser_handle_add(struct screen_browser *browser, struct mpdclient *c)
{
struct list_window_range range;
- struct filelist_entry *entry;
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);
-
+ struct filelist_entry *entry = browser_get_index(browser, i);
if (entry != NULL && entry->entity != NULL)
success = browser_select_entry(c, entry, FALSE) ||
success;
static void
browser_handle_select_all(struct screen_browser *browser, struct mpdclient *c)
{
- guint i;
-
if (browser->filelist == NULL)
return;
- for (i = 0; i < filelist_length(browser->filelist); ++i) {
+ for (unsigned i = 0; i < filelist_length(browser->filelist); ++i) {
struct filelist_entry *entry = filelist_get(browser->filelist, i);
if (entry != NULL && entry->entity != NULL)
@@ -388,14 +378,12 @@ browser_handle_mouse_event(struct screen_browser *browser, struct mpdclient *c)
static void
screen_browser_paint_callback(WINDOW *w, unsigned i, unsigned y,
- unsigned width, bool selected, void *data);
+ unsigned width, bool selected, const void *data);
bool
browser_cmd(struct screen_browser *browser,
struct mpdclient *c, command_t cmd)
{
- const struct mpd_song *song;
-
if (browser->filelist == NULL)
return false;
return true;
switch (cmd) {
+#if defined(ENABLE_SONG_SCREEN) || defined(ENABLE_LYRICS_SCREEN)
+ const struct mpd_song *song;
+#endif
+
case CMD_LIST_FIND:
case CMD_LIST_RFIND:
case CMD_LIST_FIND_NEXT:
browser->filelist);
return true;
case CMD_LIST_JUMP:
- screen_jump(browser->lw, browser_lw_callback,
- screen_browser_paint_callback, browser->filelist);
+ screen_jump(browser->lw,
+ browser_lw_callback, browser->filelist,
+ screen_browser_paint_callback, browser);
return true;
#ifdef HAVE_GETMOUSE
return false;
switch (cmd) {
+ const struct mpd_song *song;
+
case CMD_PLAY:
browser_handle_enter(browser, c);
return true;
static void
screen_browser_paint_callback(WINDOW *w, unsigned i,
unsigned y, unsigned width,
- bool selected, void *data)
+ bool selected, const 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;
+ const struct screen_browser *browser = (const struct screen_browser *) data;
- assert(fl != NULL);
- assert(i < filelist_length(fl));
+ assert(browser != NULL);
+ assert(browser->filelist != NULL);
+ assert(i < filelist_length(browser->filelist));
- entry = filelist_get(fl, i);
+ const struct filelist_entry *entry = filelist_get(browser->filelist, i);
assert(entry != NULL);
- entity = entry->entity;
+ const struct mpd_entity *entity = entry->entity;
if (entity == NULL) {
screen_browser_paint_directory(w, width, selected, "..");
return;
}
#ifndef NCMPC_MINI
- highlight = (entry->flags & HIGHLIGHT) != 0;
+ const bool highlight = (entry->flags & HIGHLIGHT) != 0;
#else
- highlight = false;
+ const bool highlight = false;
#endif
switch (mpd_entity_get_type(entity)) {
+ const struct mpd_directory *directory;
+ const struct mpd_playlist *playlist;
+ char *p;
+
case MPD_ENTITY_TYPE_DIRECTORY:
directory = mpd_entity_get_directory(entity);
p = utf8_to_locale(g_basename(mpd_directory_get_path(directory)));
case MPD_ENTITY_TYPE_SONG:
paint_song_row(w, y, width, selected, highlight,
- mpd_entity_get_song(entity), NULL);
+ mpd_entity_get_song(entity), NULL, browser->song_format);
break;
case MPD_ENTITY_TYPE_PLAYLIST:
screen_browser_paint(const struct screen_browser *browser)
{
list_window_paint2(browser->lw, screen_browser_paint_callback,
- browser->filelist);
+ browser);
}