Code

Implement a search-format configuration option (Mantis #4007)
authorSimon Arlott <sa.me.uk>
Mon, 19 May 2014 23:52:28 +0000 (00:52 +0100)
committerMax Kellermann <max@duempel.org>
Wed, 28 May 2014 16:13:40 +0000 (18:13 +0200)
This configures the song format for the search window,
and defaults to the value of list-format if not specified.

20 files changed:
NEWS
doc/config.sample
doc/ncmpc.1
src/conf.c
src/list_window.c
src/list_window.h
src/mpdclient.c
src/mpdclient.h
src/options.c
src/options.h
src/screen_artist.c
src/screen_browser.c
src/screen_browser.h
src/screen_file.c
src/screen_help.c
src/screen_outputs.c
src/screen_queue.c
src/screen_search.c
src/song_paint.c
src/song_paint.h

diff --git a/NEWS b/NEWS
index a9b594449689ade614296504c43ff760482f6c0b..d6ebaba8b66f20532de703dfe7ce8b85ecc540f3 100644 (file)
--- 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)
index 986452f2df5580e5089166a266bf3c3302cebf99..1b40092e01e4461fcad9b219c81c8430ff08f0bc 100644 (file)
@@ -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%"
 
index b7fd7ce9be4d46805e013a1853396dc7dcab2d6c..69e591945f23b03c9ecb698781eeb9d5df3b9e0a 100644 (file)
@@ -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
index 83c11c5f194b6359ffdd16a202355b64e98914e8..5d8ec5e8bcbd9937ee64067948c08be6de20c65c 100644 (file)
@@ -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);
index 387b7766b4f2d1fdfa3ad6855b049a5cd3ae6a06..c2a4b012f51a76d12ae18fdec3a095b221bfbc8b 100644 (file)
@@ -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);
index 495657b3cb93f9fcd4972bcae61e6dff83021116..2e1f76956ff1f24dfcebd0b7a94578248f806f9d 100644 (file)
@@ -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
index 9baf70bc7134fa8d2125f4ff463660052eb3ff82..1e01486a27c8c65bffcfaead13f95a08612a7eaa 100644 (file)
 
 #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);
        }
 
index 8dab0936856b06d448e9d363558c01b9e91f5ef1..01294dbb48a1b8b3887a4e95a48f3506b46deaf0 100644 (file)
@@ -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
index 0a453e23a51ea403885a878782208ddac6b70506..370215ef7cb0f8dd9bbc83c97a08c2b706768467 100644 (file)
@@ -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
index 74dfd4284657a31d3066742ea040c69b6b17d823..8b42b6d42f9eee306c97b848c207dead4bb7fd74 100644 (file)
@@ -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;
index 077fca52bd61ccf442e88d1cafba8229feb347ad..3ffc931137719459e8c9f4fe75031ce18993f5ff 100644 (file)
@@ -28,6 +28,7 @@
 #include "mpdclient.h"
 #include "screen_browser.h"
 #include "filelist.h"
+#include "options.h"
 
 #include <assert.h>
 #include <string.h>
@@ -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;
 
index 0835241ed2c9f46852c257620f70d1baa51bd14d..ff209db2bfb46146dca776b051235053a2349304 100644 (file)
@@ -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);
 }
index ad840dd1bad7cfbf74593ed485523f177a1bde9a..8346084f3148d7a660e77643d1c2b3c51075d3c4 100644 (file)
@@ -36,6 +36,7 @@ struct screen_browser {
        struct list_window *lw;
 
        struct filelist *filelist;
+       const char *song_format;
 };
 
 #ifndef NCMPC_MINI
index 175e7866ab2ea1e0285d62c762a7e58a81c504dd..124108bb770a55f482764ba59d860f302b7063f5 100644 (file)
@@ -30,6 +30,7 @@
 #include "filelist.h"
 #include "screen_utils.h"
 #include "screen_client.h"
+#include "options.h"
 
 #include <mpd/client.h>
 
@@ -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
index da2d3e9773465ecc820429a5056cac5fc73b9951..d2d96d1ffbaae92369fed69babe4ff4f2a08f870 100644 (file)
@@ -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];
 
index e80d7bae50962af4320fcc6dc8182b4fdd342933..2aa60e1ab44c4fddabf2bb3d13dd0cc67f94e843 100644 (file)
@@ -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;
 
index 0d08bbcb63ce67f3eb8a5dec83681fbc1b74a77a..7fd73aa7080c2e1531507b0debe3a2d86217d11e 100644 (file)
@@ -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
index 0d39ddb151e76c6b7b7a32fd8b520d8bef778ac7..deab64ab05ba96bc5ea35e181834724f646fd2a9 100644 (file)
@@ -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));
 }
 
index f3f3918c02a7909e1f584ae5a40e77a6599486aa..c3ae757bda89a7bad7ac57e457cd5e274cd0b43b 100644 (file)
 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);
 
index 808109517530240f32a8d5c512dd3429a5e95a19..41080a1c3f9298e1dbe8dddd3a380211de85ecef 100644 (file)
@@ -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