Code

screen_browser: moved paint_song() to song_paint.c
authorMax Kellermann <max@duempel.org>
Sun, 11 Oct 2009 16:20:49 +0000 (18:20 +0200)
committerMax Kellermann <max@duempel.org>
Sun, 11 Oct 2009 16:20:49 +0000 (18:20 +0200)
Makefile.am
src/screen_browser.c
src/song_paint.c [new file with mode: 0644]
src/song_paint.h [new file with mode: 0644]

index 8ad132b2b2f8b1dbbbe2cb7613ca2f507674a506..966253bff457c1d28901fb274c9c8cdab3a8396e 100644 (file)
@@ -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 \
index 922e4de52fe2e8d2b316a15934d3f068fb4fc74a..6070e6902ee94dcfe7097c880803ec7e8dcf98fe 100644 (file)
@@ -32,7 +32,7 @@
 #include "filelist.h"
 #include "colors.h"
 #include "paint.h"
-#include "utils.h"
+#include "song_paint.h"
 
 #include <mpd/client.h>
 
@@ -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 (file)
index 0000000..5b7966b
--- /dev/null
@@ -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 <mpd/client.h>
+
+#include <glib.h>
+
+#include <string.h>
+
+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 (file)
index 0000000..c4581aa
--- /dev/null
@@ -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 <stdbool.h>
+
+#ifdef HAVE_NCURSESW_NCURSES_H
+#include <ncursesw/ncurses.h>
+#else
+#include <ncurses.h>
+#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