From 4345c919f9d9c184f2369e630089323d5fdf7691 Mon Sep 17 00:00:00 2001 From: Simon Arlott Date: Tue, 20 May 2014 00:52:28 +0100 Subject: [PATCH] Implement a search-format configuration option (Mantis #4007) This configures the song format for the search window, and defaults to the value of list-format if not specified. --- NEWS | 1 + doc/config.sample | 3 +++ doc/ncmpc.1 | 3 +++ src/conf.c | 5 +++++ src/list_window.c | 2 +- src/list_window.h | 4 ++-- src/mpdclient.c | 9 +++++---- src/mpdclient.h | 6 ++++-- src/options.c | 2 ++ src/options.h | 1 + src/screen_artist.c | 10 ++++++---- src/screen_browser.c | 17 +++++++++-------- src/screen_browser.h | 1 + src/screen_file.c | 2 ++ src/screen_help.c | 2 +- src/screen_outputs.c | 2 +- src/screen_queue.c | 4 ++-- src/screen_search.c | 5 +++++ src/song_paint.c | 4 ++-- src/song_paint.h | 3 ++- 20 files changed, 58 insertions(+), 28 deletions(-) diff --git a/NEWS b/NEWS index a9b5944..d6ebaba 100644 --- a/NEWS +++ b/NEWS @@ -3,6 +3,7 @@ ncmpc 0.22 - not yet released * remove useless "Connected to ..." message * require libmpdclient 2.3, MPD 0.16 * patched color line-flags +* configuration option "search-format" ncmpc 0.21 - (2013-04-11) diff --git a/doc/config.sample b/doc/config.sample index 986452f..1b40092 100644 --- a/doc/config.sample +++ b/doc/config.sample @@ -79,6 +79,9 @@ ## The format used to display songs in the main window. #list-format = "%name%|[%artist% - ]%title%|%file%" +## The format used to display songs in the search window. +#search-format = "%name%|[%artist% - ]%title%|%file%" + ## The format used to display songs on the status line. #status-format = "[%artist% - ]%title%|%shortfile%" diff --git a/doc/ncmpc.1 b/doc/ncmpc.1 index b7fd7ce..69e5919 100644 --- a/doc/ncmpc.1 +++ b/doc/ncmpc.1 @@ -167,6 +167,9 @@ the separator to show at the end of the scrolling title. .B list\-format = SONG FORMAT The format used to display songs in the main window. .TP +.B search\-format = SONG FORMAT +The format used to display songs in the search window. Default is to use list\-format. +.TP .B status\-format = SONG FORMAT The format used to display songs on the status line. .TP diff --git a/src/conf.c b/src/conf.c index 83c11c5..5d8ec5e 100644 --- a/src/conf.c +++ b/src/conf.c @@ -48,6 +48,7 @@ #define CONF_COLOR "color" #define CONF_COLOR_DEFINITION "colordef" #define CONF_LIST_FORMAT "list-format" +#define CONF_SEARCH_FORMAT "search-format" #define CONF_STATUS_FORMAT "status-format" #define CONF_XTERM_TITLE_FORMAT "xterm-title-format" #define CONF_LIST_WRAP "wrap-around" @@ -435,6 +436,10 @@ parse_line(char *line) else if (!strcasecmp(CONF_LIST_FORMAT, name)) { g_free(options.list_format); options.list_format = get_format(value); + /* search format string */ + } else if (!strcasecmp(CONF_SEARCH_FORMAT, name)) { + g_free(options.search_format); + options.search_format = get_format(value); /* status format string */ } else if (!strcasecmp(CONF_STATUS_FORMAT, name)) { g_free(options.status_format); diff --git a/src/list_window.c b/src/list_window.c index 387b776..c2a4b01 100644 --- a/src/list_window.c +++ b/src/list_window.c @@ -380,7 +380,7 @@ list_window_paint(const struct list_window *lw, void list_window_paint2(const struct list_window *lw, list_window_paint_callback_t paint_callback, - void *callback_data) + const void *callback_data) { bool show_cursor = !lw->hide_cursor && (!options.hardware_cursor || lw->range_selection); diff --git a/src/list_window.h b/src/list_window.h index 495657b..2e1f769 100644 --- a/src/list_window.h +++ b/src/list_window.h @@ -35,7 +35,7 @@ typedef void (*list_window_paint_callback_t)(WINDOW *w, unsigned i, unsigned y, unsigned width, bool selected, - void *data); + const void *data); struct list_window { WINDOW *w; @@ -94,7 +94,7 @@ void list_window_paint(const struct list_window *lw, void list_window_paint2(const struct list_window *lw, list_window_paint_callback_t paint_callback, - void *callback_data); + const void *callback_data); /* perform basic list window commands (movement) */ bool diff --git a/src/mpdclient.c b/src/mpdclient.c index 9baf70b..1e01486 100644 --- a/src/mpdclient.c +++ b/src/mpdclient.c @@ -35,10 +35,11 @@ #define BUFSIZE 1024 -/* sort by list-format */ +/* sort by song format */ gint compare_filelistentry_format(gconstpointer filelist_entry1, - gconstpointer filelist_entry2) + gconstpointer filelist_entry2, + const char *song_format) { const struct mpd_entity *e1 = ((const struct filelist_entry *)filelist_entry1)->entity; @@ -50,8 +51,8 @@ compare_filelistentry_format(gconstpointer filelist_entry1, mpd_entity_get_type(e1) == MPD_ENTITY_TYPE_SONG && mpd_entity_get_type(e2) == MPD_ENTITY_TYPE_SONG) { char key1[BUFSIZE], key2[BUFSIZE]; - strfsong(key1, BUFSIZE, options.list_format, mpd_entity_get_song(e1)); - strfsong(key2, BUFSIZE, options.list_format, mpd_entity_get_song(e2)); + strfsong(key1, BUFSIZE, song_format, mpd_entity_get_song(e1)); + strfsong(key2, BUFSIZE, song_format, mpd_entity_get_song(e2)); n = strcmp(key1,key2); } diff --git a/src/mpdclient.h b/src/mpdclient.h index 8dab093..01294db 100644 --- a/src/mpdclient.h +++ b/src/mpdclient.h @@ -197,8 +197,10 @@ mpdclient_playlist_update_changes(struct mpdclient *c); bool mpdclient_filelist_add_all(struct mpdclient *c, struct filelist *fl); -/* sort by list-format */ +/* sort by song format */ gcc_pure -gint compare_filelistentry_format(gconstpointer filelist_entry1, gconstpointer filelist_entry2); +gint compare_filelistentry_format(gconstpointer filelist_entry1, + gconstpointer filelist_entry2, + const char *song_format); #endif diff --git a/src/options.c b/src/options.c index 0a453e2..370215e 100644 --- a/src/options.c +++ b/src/options.c @@ -378,6 +378,7 @@ options_init(void) { /* default option values */ options.list_format = g_strdup(DEFAULT_LIST_FORMAT); + options.search_format = NULL; options.status_format = g_strdup(DEFAULT_STATUS_FORMAT); options.screen_list = g_strsplit_set(DEFAULT_SCREEN_LIST, " ", 0); #ifndef NCMPC_MINI @@ -397,6 +398,7 @@ options_deinit(void) g_free(options.config_file); g_free(options.key_file); g_free(options.list_format); + g_free(options.search_format); g_free(options.status_format); g_strfreev(options.screen_list); #ifndef NCMPC_MINI diff --git a/src/options.h b/src/options.h index 74dfd42..8b42b6d 100644 --- a/src/options.h +++ b/src/options.h @@ -32,6 +32,7 @@ typedef struct { char *config_file; char *key_file; char *list_format; + char *search_format; char *status_format; #ifndef NCMPC_MINI char *xterm_title_format; diff --git a/src/screen_artist.c b/src/screen_artist.c index 077fca5..3ffc931 100644 --- a/src/screen_artist.c +++ b/src/screen_artist.c @@ -28,6 +28,7 @@ #include "mpdclient.h" #include "screen_browser.h" #include "filelist.h" +#include "options.h" #include #include @@ -301,6 +302,7 @@ static void screen_artist_init(WINDOW *w, int cols, int rows) { browser.lw = list_window_init(w, cols, rows); + browser.song_format = options.list_format; artist = NULL; album = NULL; } @@ -332,9 +334,9 @@ screen_artist_resize(int cols, int rows) static void paint_artist_callback(WINDOW *w, unsigned i, gcc_unused unsigned y, unsigned width, - bool selected, void *data) + bool selected, const void *data) { - GPtrArray *list = data; + const GPtrArray *list = data; char *p = utf8_to_locale(g_ptr_array_index(list, i)); screen_browser_paint_directory(w, width, selected, p); @@ -350,9 +352,9 @@ paint_artist_callback(WINDOW *w, unsigned i, static void paint_album_callback(WINDOW *w, unsigned i, gcc_unused unsigned y, unsigned width, - bool selected, void *data) + bool selected, const void *data) { - GPtrArray *list = data; + const GPtrArray *list = data; const char *p; char *q = NULL; diff --git a/src/screen_browser.c b/src/screen_browser.c index 0835241..ff209db 100644 --- a/src/screen_browser.c +++ b/src/screen_browser.c @@ -378,7 +378,7 @@ browser_handle_mouse_event(struct screen_browser *browser, struct mpdclient *c) static void screen_browser_paint_callback(WINDOW *w, unsigned i, unsigned y, - unsigned width, bool selected, void *data); + unsigned width, bool selected, const void *data); bool browser_cmd(struct screen_browser *browser, @@ -503,14 +503,15 @@ screen_browser_paint_playlist(WINDOW *w, unsigned width, static void screen_browser_paint_callback(WINDOW *w, unsigned i, unsigned y, unsigned width, - bool selected, void *data) + bool selected, const void *data) { - const struct filelist *fl = (const struct filelist *) data; + const struct screen_browser *browser = (const struct screen_browser *) data; - assert(fl != NULL); - assert(i < filelist_length(fl)); + assert(browser != NULL); + assert(browser->filelist != NULL); + assert(i < filelist_length(browser->filelist)); - const struct filelist_entry *entry = filelist_get(fl, i); + const struct filelist_entry *entry = filelist_get(browser->filelist, i); assert(entry != NULL); const struct mpd_entity *entity = entry->entity; @@ -539,7 +540,7 @@ screen_browser_paint_callback(WINDOW *w, unsigned i, case MPD_ENTITY_TYPE_SONG: paint_song_row(w, y, width, selected, highlight, - mpd_entity_get_song(entity), NULL); + mpd_entity_get_song(entity), NULL, browser->song_format); break; case MPD_ENTITY_TYPE_PLAYLIST: @@ -559,5 +560,5 @@ void screen_browser_paint(const struct screen_browser *browser) { list_window_paint2(browser->lw, screen_browser_paint_callback, - browser->filelist); + browser); } diff --git a/src/screen_browser.h b/src/screen_browser.h index ad840dd..8346084 100644 --- a/src/screen_browser.h +++ b/src/screen_browser.h @@ -36,6 +36,7 @@ struct screen_browser { struct list_window *lw; struct filelist *filelist; + const char *song_format; }; #ifndef NCMPC_MINI diff --git a/src/screen_file.c b/src/screen_file.c index 175e786..124108b 100644 --- a/src/screen_file.c +++ b/src/screen_file.c @@ -30,6 +30,7 @@ #include "filelist.h" #include "screen_utils.h" #include "screen_client.h" +#include "options.h" #include @@ -249,6 +250,7 @@ screen_file_init(WINDOW *w, int cols, int rows) current_path = g_strdup(""); browser.lw = list_window_init(w, cols, rows); + browser.song_format = options.list_format; } static void diff --git a/src/screen_help.c b/src/screen_help.c index da2d3e9..d2d96d1 100644 --- a/src/screen_help.c +++ b/src/screen_help.c @@ -245,7 +245,7 @@ static void screen_help_paint_callback(WINDOW *w, unsigned i, unsigned y, unsigned width, gcc_unused bool selected, - gcc_unused void *data) + gcc_unused const void *data) { const struct help_text_row *row = &help_text[i]; diff --git a/src/screen_outputs.c b/src/screen_outputs.c index e80d7ba..2aa60e1 100644 --- a/src/screen_outputs.c +++ b/src/screen_outputs.c @@ -174,7 +174,7 @@ outputs_title(gcc_unused char *str, gcc_unused size_t size) static void screen_outputs_paint_callback(WINDOW *w, unsigned i, gcc_unused unsigned y, unsigned width, - bool selected, gcc_unused void *data) + bool selected, gcc_unused const void *data) { const struct mpd_output *output; diff --git a/src/screen_queue.c b/src/screen_queue.c index 0d08bbc..7fd73aa 100644 --- a/src/screen_queue.c +++ b/src/screen_queue.c @@ -504,7 +504,7 @@ screen_queue_title(char *str, size_t size) static void screen_queue_paint_callback(WINDOW *w, unsigned i, unsigned y, unsigned width, - bool selected, gcc_unused void *data) + bool selected, gcc_unused const void *data) { assert(playlist != NULL); assert(i < playlist_length(playlist)); @@ -519,7 +519,7 @@ screen_queue_paint_callback(WINDOW *w, unsigned i, paint_song_row(w, y, width, selected, (int)mpd_song_get_id(song) == current_song_id, - song, row_hscroll); + song, row_hscroll, options.list_format); } static void diff --git a/src/screen_search.c b/src/screen_search.c index 0d39ddb..deab64a 100644 --- a/src/screen_search.c +++ b/src/screen_search.c @@ -352,6 +352,11 @@ static void screen_search_init(WINDOW *w, int cols, int rows) { browser.lw = list_window_init(w, cols, rows); + if (options.search_format != NULL) { + browser.song_format = options.search_format; + } else { + browser.song_format = options.list_format; + } list_window_set_length(browser.lw, G_N_ELEMENTS(help_text)); } diff --git a/src/song_paint.c b/src/song_paint.c index f3f3918..c3ae757 100644 --- a/src/song_paint.c +++ b/src/song_paint.c @@ -34,11 +34,11 @@ void paint_song_row(WINDOW *w, gcc_unused unsigned y, unsigned width, bool selected, bool highlight, const struct mpd_song *song, - gcc_unused struct hscroll *hscroll) + gcc_unused struct hscroll *hscroll, const char *format) { char buffer[width * 4]; - strfsong(buffer, sizeof(buffer), options.list_format, song); + strfsong(buffer, sizeof(buffer), format, song); row_paint_text(w, width, highlight ? COLOR_LIST_BOLD : COLOR_LIST, selected, buffer); diff --git a/src/song_paint.h b/src/song_paint.h index 8081095..41080a1 100644 --- a/src/song_paint.h +++ b/src/song_paint.h @@ -39,10 +39,11 @@ struct hscroll; * @param highlight true if the row is highlighted * @param song the song object * @param hscroll an optional hscroll object + * @param format the song format */ void paint_song_row(WINDOW *w, unsigned y, unsigned width, bool selected, bool highlight, const struct mpd_song *song, - struct hscroll *hscroll); + struct hscroll *hscroll, const char *format); #endif -- 2.30.2