Code

Implement a search-format configuration option (Mantis #4007)
[ncmpc.git] / src / screen_artist.c
index d488a7b9cb5a0090c280fefbfb34a749c3f9b304..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>
@@ -49,12 +50,10 @@ static gint
 compare_utf8(gconstpointer s1, gconstpointer s2)
 {
        const char *const*t1 = s1, *const*t2 = s2;
-       char *key1, *key2;
-       int n;
 
-       key1 = g_utf8_collate_key(*t1,-1);
-       key2 = g_utf8_collate_key(*t2,-1);
-       n = strcmp(key1,key2);
+       char *key1 = g_utf8_collate_key(*t1,-1);
+       char *key2 = g_utf8_collate_key(*t2,-1);
+       int n = strcmp(key1,key2);
        g_free(key1);
        g_free(key2);
        return n;
@@ -65,8 +64,6 @@ static const char *
 screen_artist_lw_callback(unsigned idx, void *data)
 {
        GPtrArray *list = data;
-       static char buf[BUFSIZE];
-       char *str, *str_utf8;
 
        if (mode == LIST_ALBUMS) {
                if (idx == 0)
@@ -79,10 +76,12 @@ screen_artist_lw_callback(unsigned idx, void *data)
 
        assert(idx < list->len);
 
-       str_utf8 = g_ptr_array_index(list, idx);
+       char *str_utf8 = g_ptr_array_index(list, idx);
        assert(str_utf8 != NULL);
 
-       str = utf8_to_locale(str_utf8);
+       char *str = utf8_to_locale(str_utf8);
+
+       static char buf[BUFSIZE];
        g_strlcpy(buf, str, sizeof(buf));
        g_free(str);
 
@@ -102,9 +101,7 @@ artist_repaint(void)
 static void
 string_array_free(GPtrArray *array)
 {
-       unsigned i;
-
-       for (i = 0; i < array->len; ++i) {
+       for (unsigned i = 0; i < array->len; ++i) {
                char *value = g_ptr_array_index(array, i);
                g_free(value);
        }
@@ -305,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;
 }
@@ -335,10 +333,10 @@ screen_artist_resize(int cols, int rows)
  */
 static void
 paint_artist_callback(WINDOW *w, unsigned i,
-                     G_GNUC_UNUSED unsigned y, unsigned width,
-                     bool selected, void *data)
+                     gcc_unused unsigned y, unsigned width,
+                     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);
@@ -353,10 +351,10 @@ paint_artist_callback(WINDOW *w, unsigned i,
  */
 static void
 paint_album_callback(WINDOW *w, unsigned i,
-                    G_GNUC_UNUSED unsigned y, unsigned width,
-                    bool selected, void *data)
+                    gcc_unused unsigned y, unsigned width,
+                    bool selected, const void *data)
 {
-       GPtrArray *list = data;
+       const GPtrArray *list = data;
        const char *p;
        char *q = NULL;
 
@@ -391,9 +389,9 @@ screen_artist_paint(void)
 static const char *
 screen_artist_get_title(char *str, size_t size)
 {
-       char *s1, *s2;
-
        switch(mode) {
+               char *s1, *s2;
+
        case LIST_ARTISTS:
                g_snprintf(str, size, _("All artists"));
                break;
@@ -453,15 +451,13 @@ add_query(struct mpdclient *c, enum mpd_tag_type table, const char *_filter,
          const char *_artist)
 {
        struct mpd_connection *connection = mpdclient_get_connection(c);
-       char *str;
-       struct filelist *addlist;
 
        assert(_filter != NULL);
 
        if (connection == NULL)
                return;
 
-       str = utf8_to_locale(_filter);
+       char *str = utf8_to_locale(_filter);
        if (table == MPD_TAG_ALBUM)
                screen_status_printf(_("Adding album %s..."), str);
        else
@@ -476,7 +472,7 @@ add_query(struct mpdclient *c, enum mpd_tag_type table, const char *_filter,
                                              MPD_TAG_ARTIST, _artist);
        mpd_search_commit(connection);
 
-       addlist = filelist_new_recv(connection);
+       struct filelist *addlist = filelist_new_recv(connection);
 
        if (mpdclient_finish_command(c))
                mpdclient_filelist_add_all(c, addlist);
@@ -516,13 +512,13 @@ string_array_find(GPtrArray *array, const char *value)
 static bool
 screen_artist_cmd(struct mpdclient *c, command_t cmd)
 {
-       struct list_window_range range;
-       char *selected;
-       char *old;
-       char *old_ptr;
-       int idx;
-
        switch(cmd) {
+               struct list_window_range range;
+               char *selected;
+               char *old;
+               char *old_ptr;
+               int idx;
+
        case CMD_PLAY:
                switch (mode) {
                case LIST_ARTISTS: