Code

display songs time in playlist
authorRomain Bignon <romain@peerfuse.org>
Sun, 14 Jun 2009 15:24:08 +0000 (17:24 +0200)
committerMax Kellermann <max@duempel.org>
Sun, 14 Jun 2009 15:24:08 +0000 (17:24 +0200)
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]

13 files changed:
src/list_window.c
src/list_window.h
src/screen_artist.c
src/screen_browser.c
src/screen_browser.h
src/screen_help.c
src/screen_keydef.c
src/screen_outputs.c
src/screen_play.c
src/screen_search.c
src/screen_song.c
src/screen_text.c
src/screen_text.h

index 7bdee1a4e67bc4fc46b2dbab8c22dac4c586f29b..9421db3744e9b472a43fcbf8e1a72b1c48baa29b 100644 (file)
@@ -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
index 20ebfc869323f9f9a33ae9b34f04f811eb7b48cb..e99c45f475f8d24aade1be73544c7ca6860cd66b 100644 (file)
@@ -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 {
index 40a0ed750ed128a34c62422a8409a576bd0f86fd..be32dacb4ba7f0c7e20ef25d6f686f193c9cd335 100644 (file)
@@ -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];
index 29dd4bfa49f3865f524e6ae98e55a6fd1aac8853..152ee9a1c4baadcbfd59374cbbd834f8e01dac1e 100644 (file)
@@ -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;
index 112ed9f9a3d7fcd2cd1bfe88b0a08aff455dbcb2..3954c8d3f3f52246b5e143782e73bfc77f7670e9 100644 (file)
@@ -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,
index 467b7b789add6b7465109345a10015d9f376f2e7..81b479fefbce01b26e879b237ae081edcc0202eb 100644 (file)
@@ -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];
 
index 94e038875d3851ce66b33f572ab9d18615524bf4..d1dce2314feb85b837e3e1a9173b4fdfb9798b88 100644 (file)
@@ -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];
 
index a22fc925a0448285e0154318ae686100eef545d3..9b6fa87bc80e4a61f47bf3a40ee41e2e2d330a11 100644 (file)
@@ -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;
 
index 4b03c5d3f55637ac88858d4ff63bef8ff9f6be1a..23ba656e16a4613c64de169305aa23c2f541d159 100644 (file)
@@ -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;
index 3d9092ab3757d8346a0c72e31ac3b5991e755f1f..00d1388ceb6f425067495c1fda3d2bd9dcd0cffc 100644 (file)
@@ -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[] = {
index 29c0f2df7a140d554241df6ddcb1b88f9cbb5b4b..87a78915cb220f7d33b9a1ba0078c77b389437c7 100644 (file)
@@ -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;
index 1222f27cf115464826915c0f7aef8306e9c250d5..6f642e8498bb570c356df2bb855fd03d48291e28 100644 (file)
@@ -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];
index 4841731c937278babdc99a42b82c4731c57dc99a..a64b858df59532267dd38a07243b82dcfd7dc266 100644 (file)
@@ -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)