summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: c17ac1e)
raw | patch | inline | side by side (parent: c17ac1e)
author | Romain Bignon <romain@peerfuse.org> | |
Sun, 14 Jun 2009 15:24:08 +0000 (17:24 +0200) | ||
committer | Max 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]
display the songs time in playlist.
It isn't displayed with NCMPC_MINI.
[mk: unbreak wide-cursor=no]
13 files changed:
diff --git a/src/list_window.c b/src/list_window.c
index 7bdee1a4e67bc4fc46b2dbab8c22dac4c586f29b..9421db3744e9b472a43fcbf8e1a72b1c48baa29b 100644 (file)
--- a/src/list_window.c
+++ b/src/list_window.c
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;
}
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) {
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);
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)
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)
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 20ebfc869323f9f9a33ae9b34f04f811eb7b48cb..e99c45f475f8d24aade1be73544c7ca6860cd66b 100644 (file)
--- a/src/list_window.h
+++ b/src/list_window.h
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 40a0ed750ed128a34c62422a8409a576bd0f86fd..be32dacb4ba7f0c7e20ef25d6f686f193c9cd335 100644 (file)
--- a/src/screen_artist.c
+++ b/src/screen_artist.c
/* 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 29dd4bfa49f3865f524e6ae98e55a6fd1aac8853..152ee9a1c4baadcbfd59374cbbd834f8e01dac1e 100644 (file)
--- a/src/screen_browser.c
+++ b/src/screen_browser.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 112ed9f9a3d7fcd2cd1bfe88b0a08aff455dbcb2..3954c8d3f3f52246b5e143782e73bfc77f7670e9 100644 (file)
--- a/src/screen_browser.h
+++ b/src/screen_browser.h
/* 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
#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 467b7b789add6b7465109345a10015d9f376f2e7..81b479fefbce01b26e879b237ae081edcc0202eb 100644 (file)
--- a/src/screen_help.c
+++ b/src/screen_help.c
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 94e038875d3851ce66b33f572ab9d18615524bf4..d1dce2314feb85b837e3e1a9173b4fdfb9798b88 100644 (file)
--- a/src/screen_keydef.c
+++ b/src/screen_keydef.c
}
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 a22fc925a0448285e0154318ae686100eef545d3..9b6fa87bc80e4a61f47bf3a40ee41e2e2d330a11 100644 (file)
--- a/src/screen_outputs.c
+++ b/src/screen_outputs.c
/* 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
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 4b03c5d3f55637ac88858d4ff63bef8ff9f6be1a..23ba656e16a4613c64de169305aa23c2f541d159 100644 (file)
--- a/src/screen_play.c
+++ b/src/screen_play.c
}
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
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 3d9092ab3757d8346a0c72e31ac3b5991e755f1f..00d1388ceb6f425067495c1fda3d2bd9dcd0cffc 100644 (file)
--- a/src/screen_search.c
+++ b/src/screen_search.c
/* 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
/* 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 29c0f2df7a140d554241df6ddcb1b88f9cbb5b4b..87a78915cb220f7d33b9a1ba0078c77b389437c7 100644 (file)
--- a/src/screen_song.c
+++ b/src/screen_song.c
/* 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
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 1222f27cf115464826915c0f7aef8306e9c250d5..6f642e8498bb570c356df2bb855fd03d48291e28 100644 (file)
--- a/src/screen_text.c
+++ b/src/screen_text.c
/* 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
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 4841731c937278babdc99a42b82c4731c57dc99a..a64b858df59532267dd38a07243b82dcfd7dc266 100644 (file)
--- a/src/screen_text.h
+++ b/src/screen_text.h
/* 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
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)