From: Max Kellermann Date: Sun, 11 Oct 2009 16:20:49 +0000 (+0200) Subject: screen_browser: moved paint_song() to song_paint.c X-Git-Tag: release-0.16~113 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=03a24249b344f5f5553d12077a39679b1f374a3c;p=ncmpc.git screen_browser: moved paint_song() to song_paint.c --- diff --git a/Makefile.am b/Makefile.am index 8ad132b..966253b 100644 --- a/Makefile.am +++ b/Makefile.am @@ -34,6 +34,7 @@ ncmpc_headers = \ src/screen_utils.h \ src/screen_client.h \ src/list_window.h \ + src/song_paint.h \ src/colors.h \ src/paint.h \ src/hscroll.h \ @@ -93,6 +94,7 @@ src_ncmpc_SOURCES = \ src/screen_browser.c \ src/screen_file.c \ src/list_window.c \ + src/song_paint.c \ src/colors.c \ src/charset.c \ src/wreadln.c \ diff --git a/src/screen_browser.c b/src/screen_browser.c index 922e4de..6070e69 100644 --- a/src/screen_browser.c +++ b/src/screen_browser.c @@ -32,7 +32,7 @@ #include "filelist.h" #include "colors.h" #include "paint.h" -#include "utils.h" +#include "song_paint.h" #include @@ -498,29 +498,6 @@ screen_browser_paint_directory(WINDOW *w, unsigned width, row_clear_to_eol(w, width, selected); } -static void -screen_browser_paint_song(WINDOW *w, G_GNUC_UNUSED unsigned y, - 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); - -#ifndef NCMPC_MINI - if (mpd_song_get_duration(song) > 0) { - char duration[32]; - format_duration_short(duration, sizeof(duration), - mpd_song_get_duration(song)); - wmove(w, y, width - strlen(duration) - 1); - waddch(w, ' '); - waddstr(w, duration); - } -#endif -} - static void screen_browser_paint_playlist(WINDOW *w, unsigned width, bool selected, const char *name) @@ -573,8 +550,8 @@ screen_browser_paint_callback(WINDOW *w, unsigned i, break; case MPD_ENTITY_TYPE_SONG: - screen_browser_paint_song(w, y, width, selected, highlight, - mpd_entity_get_song(entity)); + paint_song_row(w, y, width, selected, highlight, + mpd_entity_get_song(entity)); break; case MPD_ENTITY_TYPE_PLAYLIST: diff --git a/src/song_paint.c b/src/song_paint.c new file mode 100644 index 0000000..5b7966b --- /dev/null +++ b/src/song_paint.c @@ -0,0 +1,52 @@ +/* ncmpc (Ncurses MPD Client) + * (c) 2004-2009 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 "song_paint.h" +#include "paint.h" +#include "strfsong.h" +#include "utils.h" +#include "config.h" + +#include + +#include + +#include + +void +paint_song_row(WINDOW *w, G_GNUC_UNUSED unsigned y, 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); + +#ifndef NCMPC_MINI + if (mpd_song_get_duration(song) > 0) { + char duration[32]; + format_duration_short(duration, sizeof(duration), + mpd_song_get_duration(song)); + wmove(w, y, width - strlen(duration) - 1); + waddch(w, ' '); + waddstr(w, duration); + } +#endif +} diff --git a/src/song_paint.h b/src/song_paint.h new file mode 100644 index 0000000..c4581aa --- /dev/null +++ b/src/song_paint.h @@ -0,0 +1,48 @@ +/* ncmpc (Ncurses MPD Client) + * (c) 2004-2009 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. +*/ + +#ifndef NCMPC_SONG_PAINT_H +#define NCMPC_SONG_PAINT_H + +#include + +#ifdef HAVE_NCURSESW_NCURSES_H +#include +#else +#include +#endif + +struct mpd_song; + +/** + * Paints a song into a list window row. The cursor must be set to + * the first character in the row prior to calling this function. + * + * @param w the ncurses window + * @param y the row number in the window + * @param width the width of the row + * @param selected true if the row is selected + * @param highlight true if the row is highlighted + * @param song the song object + */ +void +paint_song_row(WINDOW *w, unsigned y, unsigned width, + bool selected, bool highlight, const struct mpd_song *song); + +#endif