Code

colors: Allow using 256 colors
[ncmpc.git] / src / screen_artist.c
index 3278f8fbf63926b98432dbb97388e6d58133ff14..d6011a7bc13d078cb1c2feffa96efcf580c08f67 100644 (file)
@@ -60,8 +60,7 @@ compare_utf8(gconstpointer s1, gconstpointer s2)
 
 /* list_window callback */
 static const char *
-screen_artist_lw_callback(unsigned idx, G_GNUC_UNUSED bool *highlight,
-                         G_GNUC_UNUSED char** sc, G_GNUC_UNUSED void *data)
+screen_artist_lw_callback(unsigned idx, void *data)
 {
        GPtrArray *list = data;
        static char buf[BUFSIZE];
@@ -216,27 +215,27 @@ load_song_list(struct mpdclient *c)
        assert(album != NULL);
        assert(browser.filelist == NULL);
 
-       mpd_search_db_songs(connection, true);
-       mpd_search_add_tag_constraint(connection, MPD_OPERATOR_DEFAULT,
-                                     MPD_TAG_ARTIST, artist);
-       if (album[0] != 0)
-               mpd_search_add_tag_constraint(connection, MPD_OPERATOR_DEFAULT,
-                                             MPD_TAG_ALBUM, album);
-       mpd_search_commit(connection);
-
        browser.filelist = filelist_new();
        /* add a dummy entry for ".." */
        filelist_append(browser.filelist, NULL);
 
-       filelist_recv(browser.filelist, connection);
+       if (connection != NULL) {
+               mpd_search_db_songs(connection, true);
+               mpd_search_add_tag_constraint(connection, MPD_OPERATOR_DEFAULT,
+                                             MPD_TAG_ARTIST, artist);
+               if (album[0] != 0)
+                       mpd_search_add_tag_constraint(connection, MPD_OPERATOR_DEFAULT,
+                                                     MPD_TAG_ALBUM, album);
+               mpd_search_commit(connection);
 
-       if (!mpd_response_finish(connection))
-               mpdclient_handle_error(c);
+               filelist_recv(browser.filelist, connection);
+
+               if (!mpd_response_finish(connection))
+                       mpdclient_handle_error(c);
+       }
 
-#ifndef NCMPC_MINI
        /* fix highlights */
        screen_browser_sync_highlights(browser.filelist, &c->playlist);
-#endif
        list_window_set_length(browser.lw, filelist_length(browser.filelist));
 }
 
@@ -339,8 +338,7 @@ static void
 screen_artist_paint(void)
 {
        if (browser.filelist) {
-               list_window_paint(browser.lw, browser_lw_callback,
-                                 browser.filelist);
+               screen_browser_paint(&browser);
        } else if (album_list != NULL)
                list_window_paint(browser.lw, screen_artist_lw_callback,
                                  album_list);
@@ -396,14 +394,12 @@ screen_artist_update(struct mpdclient *c)
                /* the db has changed -> update the list */
                reload_lists(c);
 
-#ifndef NCMPC_MINI
-       if (c->events & (MPD_IDLE_DATABASE | MPD_IDLE_PLAYLIST))
+       if (c->events & (MPD_IDLE_DATABASE | MPD_IDLE_QUEUE))
                screen_browser_sync_highlights(browser.filelist, &c->playlist);
-#endif
 
        if (c->events & (MPD_IDLE_DATABASE
 #ifndef NCMPC_MINI
-                        | MPD_IDLE_PLAYLIST
+                        | MPD_IDLE_QUEUE
 #endif
                         ))
                artist_repaint();
@@ -418,6 +414,9 @@ add_query(struct mpdclient *c, enum mpd_tag_type table, char *_filter)
 
        assert(filter != NULL);
 
+       if (connection == NULL)
+               return;
+
        str = utf8_to_locale(_filter);
        if (table == MPD_TAG_ALBUM)
                screen_status_printf("Adding album %s...", str);
@@ -472,6 +471,7 @@ 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;
        int idx;
@@ -615,8 +615,8 @@ screen_artist_cmd(struct mpdclient *c, command_t cmd)
                        if (browser.lw->selected >= artist_list->len)
                                return true;
 
-                       for (unsigned i = browser.lw->selected_start;
-                            i <= browser.lw->selected_end; ++i) {
+                       list_window_get_range(browser.lw, &range);
+                       for (unsigned i = range.start; i < range.end; ++i) {
                                selected = g_ptr_array_index(artist_list, i);
                                add_query(c, MPD_TAG_ARTIST, selected);
                                cmd = CMD_LIST_NEXT; /* continue and select next item... */
@@ -624,8 +624,8 @@ screen_artist_cmd(struct mpdclient *c, command_t cmd)
                        break;
 
                case LIST_ALBUMS:
-                       for (unsigned i = browser.lw->selected_start;
-                            i <= browser.lw->selected_end; ++i) {
+                       list_window_get_range(browser.lw, &range);
+                       for (unsigned i = range.start; i < range.end; ++i) {
                                if(i == album_list->len + 1)
                                        add_query(c, MPD_TAG_ARTIST, artist);
                                else if (i > 0)
@@ -674,13 +674,13 @@ screen_artist_cmd(struct mpdclient *c, command_t cmd)
                switch (mode) {
                case LIST_ARTISTS:
                        screen_jump(browser.lw, screen_artist_lw_callback,
-                                   artist_list);
+                                   NULL, artist_list);
                        artist_repaint();
                        return true;
 
                case LIST_ALBUMS:
                        screen_jump(browser.lw, screen_artist_lw_callback,
-                                   album_list);
+                                   NULL, album_list);
                        artist_repaint();
                        return true;