Code

utils: move format_duration_*() to time_format.c
[ncmpc.git] / src / song_paint.c
1 /* ncmpc (Ncurses MPD Client)
2  * (c) 2004-2017 The Music Player Daemon Project
3  * Project homepage: http://musicpd.org
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
20 #include "song_paint.h"
21 #include "paint.h"
22 #include "strfsong.h"
23 #include "time_format.h"
24 #include "hscroll.h"
25 #include "charset.h"
26 #include "config.h"
28 #include <mpd/client.h>
30 #include <glib.h>
32 #include <string.h>
34 void
35 paint_song_row(WINDOW *w, gcc_unused unsigned y, unsigned width,
36                bool selected, bool highlight, const struct mpd_song *song,
37                gcc_unused struct hscroll *hscroll, const char *format)
38 {
39         char buffer[width * 4];
41         strfsong(buffer, sizeof(buffer), format, song);
42         row_paint_text(w, width, highlight ? COLOR_LIST_BOLD : COLOR_LIST,
43                        selected, buffer);
45 #ifndef NCMPC_MINI
46         if (options.second_column && mpd_song_get_duration(song) > 0) {
47                 char duration[32];
48                 format_duration_short(duration, sizeof(duration),
49                                       mpd_song_get_duration(song));
50                 width -= strlen(duration) + 1;
51                 wmove(w, y, width);
52                 waddch(w, ' ');
53                 waddstr(w, duration);
54         }
56         if (hscroll != NULL && utf8_width(buffer) >= width) {
57                 hscroll_set(hscroll, 0, y, width, buffer);
58                 hscroll_draw(hscroll);
59         }
60 #endif
61 }