From: Romain Bignon Date: Sun, 14 Jun 2009 15:24:08 +0000 (+0200) Subject: display songs time in playlist X-Git-Tag: release-0.15~48 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=850ad87b588dd6cbb96e5558ee671f2c95cc839d;p=ncmpc.git display songs time in playlist Add the way to display a second column in a list window, and use it to display the songs time in playlist. It isn't displayed with NCMPC_MINI. [mk: unbreak wide-cursor=no] --- diff --git a/src/list_window.c b/src/list_window.c index 7bdee1a..9421db3 100644 --- a/src/list_window.c +++ b/src/list_window.c @@ -323,7 +323,7 @@ list_window_paint(struct list_window *lw, lw->start = 0; else { - while ( start > 0 && callback(start + lw->rows - 1, &highlight, callback_data) == NULL) + while ( start > 0 && callback(start + lw->rows - 1, &highlight, NULL, callback_data) == NULL) start--; lw->start = start; } @@ -331,9 +331,10 @@ list_window_paint(struct list_window *lw, for (i = 0; i < lw->rows; i++) { const char *label; + char *second_column = NULL; highlight = false; - label = callback(lw->start + i, &highlight, callback_data); + label = callback(lw->start + i, &highlight, &second_column, callback_data); wmove(lw->w, i, 0); if (label) { @@ -353,6 +354,19 @@ list_window_paint(struct list_window *lw, if (fill && len < lw->cols) whline(lw->w, ' ', lw->cols-len); + if(second_column) + { + unsigned sc_len = utf8_width(second_column) + 1; + if(lw->cols > sc_len) + { + wmove(lw->w, i, lw->cols - sc_len); + waddstr(lw->w, " "); + wmove(lw->w, i, lw->cols - sc_len + 1); + waddstr(lw->w, second_column); + } + g_free(second_column); + } + if (selected) wattroff(lw->w, A_REVERSE); @@ -376,7 +390,7 @@ list_window_find(struct list_window *lw, const char *label; do { - while ((label = callback(i,&h,callback_data))) { + while ((label = callback(i,&h,NULL,callback_data))) { if (str && label && match_line(label, str)) { lw->selected = i; if(!lw->range_selection || i > lw->selected_end) @@ -419,7 +433,7 @@ list_window_rfind(struct list_window *lw, return false; do { - while (i >= 0 && (label = callback(i,&h,callback_data))) { + while (i >= 0 && (label = callback(i,&h,NULL,callback_data))) { if( str && label && match_line(label, str) ) { lw->selected = i; if(!lw->range_selection || i > (int)lw->selected_end) @@ -453,7 +467,7 @@ list_window_jump(struct list_window *lw, unsigned i = 0; const char *label; - while ((label = callback(i,&h,callback_data))) { + while ((label = callback(i,&h,NULL,callback_data))) { if (label && label[0] == '[') label++; #ifndef NCMPC_MINI diff --git a/src/list_window.h b/src/list_window.h index 20ebfc8..e99c45f 100644 --- a/src/list_window.h +++ b/src/list_window.h @@ -34,6 +34,7 @@ typedef const char *(*list_window_callback_fn_t)(unsigned index, bool *highlight, + char **second_column, void *data); typedef struct list_window { diff --git a/src/screen_artist.c b/src/screen_artist.c index 40a0ed7..be32dac 100644 --- a/src/screen_artist.c +++ b/src/screen_artist.c @@ -61,7 +61,7 @@ compare_utf8(gconstpointer s1, gconstpointer s2) /* list_window callback */ static const char * artist_lw_callback(unsigned idx, G_GNUC_UNUSED bool *highlight, - G_GNUC_UNUSED void *data) + G_GNUC_UNUSED char** sc, G_GNUC_UNUSED void *data) { GPtrArray *list = data; static char buf[BUFSIZE]; diff --git a/src/screen_browser.c b/src/screen_browser.c index 29dd4bf..152ee9a 100644 --- a/src/screen_browser.c +++ b/src/screen_browser.c @@ -117,7 +117,7 @@ browser_playlist_changed(struct screen_browser *browser, mpdclient_t *c, /* list_window callback */ const char * -browser_lw_callback(unsigned idx, bool *highlight, void *data) +browser_lw_callback(unsigned idx, bool *highlight, G_GNUC_UNUSED char **second_column, void *data) { static char buf[BUFSIZE]; mpdclient_filelist_t *fl = (mpdclient_filelist_t *) data; diff --git a/src/screen_browser.h b/src/screen_browser.h index 112ed9f..3954c8d 100644 --- a/src/screen_browser.h +++ b/src/screen_browser.h @@ -1,7 +1,7 @@ /* 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 @@ -46,7 +46,7 @@ browser_playlist_changed(struct screen_browser *browser, mpdclient_t *c, #endif -const char *browser_lw_callback(unsigned index, bool *highlight, void *filelist); +const char *browser_lw_callback(unsigned index, bool *highlight, char** second_column, void *filelist); bool browser_change_directory(struct screen_browser *browser, mpdclient_t *c, diff --git a/src/screen_help.c b/src/screen_help.c index 467b7b7..81b479f 100644 --- a/src/screen_help.c +++ b/src/screen_help.c @@ -185,7 +185,7 @@ static help_text_row_t help_text[] = { static list_window_t *lw; static const char * -list_callback(unsigned idx, bool *highlight, G_GNUC_UNUSED void *data) +list_callback(unsigned idx, bool *highlight, G_GNUC_UNUSED char** second_column, G_GNUC_UNUSED void *data) { static char buf[512]; diff --git a/src/screen_keydef.c b/src/screen_keydef.c index 94e0388..d1dce23 100644 --- a/src/screen_keydef.c +++ b/src/screen_keydef.c @@ -188,7 +188,7 @@ assign_new_key(WINDOW *w, int cmd_index, int key_index) } static const char * -list_callback(unsigned idx, bool *highlight, G_GNUC_UNUSED void *data) +list_callback(unsigned idx, bool *highlight, G_GNUC_UNUSED char** sc, G_GNUC_UNUSED void *data) { static char buf[BUFSIZE]; diff --git a/src/screen_outputs.c b/src/screen_outputs.c index a22fc92..9b6fa87 100644 --- a/src/screen_outputs.c +++ b/src/screen_outputs.c @@ -1,7 +1,7 @@ /* 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 @@ -104,7 +104,7 @@ fill_outputs_list(mpdclient_t *c) static const char * outputs_list_callback(unsigned int output_index, bool *highlight, - G_GNUC_UNUSED void *data) + G_GNUC_UNUSED char **sc, G_GNUC_UNUSED void *data) { mpd_OutputEntity *output; diff --git a/src/screen_play.c b/src/screen_play.c index 4b03c5d..23ba656 100644 --- a/src/screen_play.c +++ b/src/screen_play.c @@ -97,7 +97,7 @@ playlist_changed_callback(mpdclient_t *c, int event, gpointer data) } static const char * -list_callback(unsigned idx, bool *highlight, G_GNUC_UNUSED void *data) +list_callback(unsigned idx, bool *highlight, char **second_column, G_GNUC_UNUSED void *data) { static char songname[MAX_SONG_LENGTH]; #ifndef NCMPC_MINI @@ -115,22 +115,31 @@ list_callback(unsigned idx, bool *highlight, G_GNUC_UNUSED void *data) strfsong(songname, MAX_SONG_LENGTH, options.list_format, song); #ifndef NCMPC_MINI - if (options.scroll && (unsigned)song->pos == lw->selected && - utf8_width(songname) > (unsigned)COLS) { - static unsigned current_song; - char *tmp; + if(second_column) + *second_column = g_strdup_printf("%d:%02d", song->time/60, song->time%60); - if (current_song != lw->selected) { - st.offset = 0; - current_song = lw->selected; - } + if ((unsigned)song->pos == lw->selected) + { + if (options.scroll && utf8_width(songname) > (unsigned)COLS) + { + static unsigned current_song; + char *tmp; + + if (current_song != lw->selected) { + st.offset = 0; + current_song = lw->selected; + } - tmp = strscroll(songname, options.scroll_sep, - MAX_SONG_LENGTH, &st); - g_strlcpy(songname, tmp, MAX_SONG_LENGTH); - g_free(tmp); - } else if ((unsigned)song->pos == lw->selected) - st.offset = 0; + tmp = strscroll(songname, options.scroll_sep, + MAX_SONG_LENGTH, &st); + g_strlcpy(songname, tmp, MAX_SONG_LENGTH); + g_free(tmp); + } + else + st.offset = 0; + } +#else + (void)second_column; #endif return songname; diff --git a/src/screen_search.c b/src/screen_search.c index 3d9092a..00d1388 100644 --- a/src/screen_search.c +++ b/src/screen_search.c @@ -1,7 +1,7 @@ /* 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 @@ -89,7 +89,7 @@ static struct screen_browser browser; /* search info */ static const char * lw_search_help_callback(unsigned idx, G_GNUC_UNUSED bool *highlight, - G_GNUC_UNUSED void *data) + G_GNUC_UNUSED char** sc, G_GNUC_UNUSED void *data) { unsigned text_rows; static const char *text[] = { diff --git a/src/screen_song.c b/src/screen_song.c index 29c0f2d..87a7891 100644 --- a/src/screen_song.c +++ b/src/screen_song.c @@ -1,7 +1,7 @@ /* 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 @@ -69,7 +69,7 @@ screen_song_repaint(void) static const char * screen_song_list_callback(unsigned idx, G_GNUC_UNUSED bool *highlight, - G_GNUC_UNUSED void *data) + G_GNUC_UNUSED char** sc, G_GNUC_UNUSED void *data) { static char buffer[256]; char *value; diff --git a/src/screen_text.c b/src/screen_text.c index 1222f27..6f642e8 100644 --- a/src/screen_text.c +++ b/src/screen_text.c @@ -1,7 +1,7 @@ /* 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 @@ -78,7 +78,7 @@ screen_text_set(struct screen_text *text, const GString *str) const char * screen_text_list_callback(unsigned idx, G_GNUC_UNUSED bool *highlight, - void *data) + G_GNUC_UNUSED char** sc, void *data) { const struct screen_text *text = data; static char buffer[256]; diff --git a/src/screen_text.h b/src/screen_text.h index 4841731..a64b858 100644 --- a/src/screen_text.h +++ b/src/screen_text.h @@ -1,7 +1,7 @@ /* 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 @@ -70,7 +70,7 @@ void screen_text_set(struct screen_text *text, const GString *str); const char * -screen_text_list_callback(unsigned idx, bool *highlight, void *data); +screen_text_list_callback(unsigned idx, bool *highlight, char** sc, void *data); static inline void screen_text_paint(struct screen_text *text)