summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 4935255)
raw | patch | inline | side by side (parent: 4935255)
author | Max Kellermann <max@duempel.org> | |
Wed, 1 Oct 2008 07:38:45 +0000 (09:38 +0200) | ||
committer | Max Kellermann <max@duempel.org> | |
Wed, 1 Oct 2008 07:38:45 +0000 (09:38 +0200) |
"metalist" can have different meanings, depending on the mode.
Replace it with two separate variables "artist_list" and "album_list".
This way, we can optimize screen updates later.
Replace it with two separate variables "artist_list" and "album_list".
This way, we can optimize screen updates later.
src/screen_artist.c | patch | blob | history |
diff --git a/src/screen_artist.c b/src/screen_artist.c
index 1d17f75f284ce1ee665486db88423089cf911ab6..ba48ce837196d40775eedb6ddc44f3e3ad2b8c4f 100644 (file)
--- a/src/screen_artist.c
+++ b/src/screen_artist.c
typedef enum { LIST_ARTISTS, LIST_ALBUMS, LIST_SONGS } artist_mode_t;
static artist_mode_t mode = LIST_ARTISTS;
+static GPtrArray *artist_list, *album_list;
static char *artist = NULL;
static char *album = NULL;
-static GPtrArray *metalist = NULL;
static struct screen_browser browser;
static const char *
artist_lw_callback(unsigned idx, mpd_unused int *highlight, mpd_unused void *data)
{
+ GPtrArray *list = data;
static char buf[BUFSIZE];
char *str, *str_utf8;
if (mode == LIST_ALBUMS) {
if (idx == 0)
return "[..]";
- else if (idx == metalist->len + 1) {
+ else if (idx == list->len + 1) {
str = utf8_to_locale(_("All tracks"));
g_snprintf(buf, BUFSIZE, "[%s]", str);
g_free(str);
@@ -79,10 +80,10 @@ artist_lw_callback(unsigned idx, mpd_unused int *highlight, mpd_unused void *dat
--idx;
}
- if (idx >= metalist->len)
+ if (idx >= list->len)
return NULL;
- str_utf8 = g_ptr_array_index(metalist, idx);
+ str_utf8 = g_ptr_array_index(list, idx);
assert(str_utf8 != NULL);
str = utf8_to_locale(str_utf8);
static void
free_lists(struct mpdclient *c)
{
- if (metalist != NULL) {
- string_array_free(metalist);
- metalist = NULL;
+ if (artist_list != NULL) {
+ string_array_free(artist_list);
+ artist_list = NULL;
+ }
+
+ if (album_list != NULL) {
+ string_array_free(album_list);
+ album_list = NULL;
}
if (browser.filelist) {
assert(mode == LIST_ARTISTS);
assert(artist == NULL);
assert(album == NULL);
- assert(metalist == NULL);
+ assert(artist_list == NULL);
+ assert(album_list == NULL);
assert(browser.filelist == NULL);
list = mpdclient_get_artists_utf8(c);
/* sort list */
list = g_list_sort(list, compare_utf8);
- metalist = g_list_to_ptr_array(list);
+ artist_list = g_list_to_ptr_array(list);
}
static void
assert(mode == LIST_ALBUMS);
assert(artist != NULL);
assert(album == NULL);
- assert(metalist == NULL);
+ assert(album_list == NULL);
assert(browser.filelist == NULL);
list = mpdclient_get_albums_utf8(c, artist);
/* sort list */
list = g_list_sort(list, compare_utf8);
- metalist = g_list_to_ptr_array(list);
+ album_list = g_list_to_ptr_array(list);
}
static void
{
static gboolean callback_installed = FALSE;
- if (metalist == NULL && browser.filelist == NULL)
+ if (artist_list == NULL && album_list == NULL &&
+ browser.filelist == NULL)
reload_lists(c);
if (!callback_installed) {
mpdclient_install_browse_callback(c, browse_callback);
if (browser.filelist) {
list_window_paint(browser.lw, browser_lw_callback,
browser.filelist);
- } else if (metalist) {
- list_window_paint(browser.lw, artist_lw_callback, metalist);
- } else {
+ } else if (album_list != NULL)
+ list_window_paint(browser.lw, artist_lw_callback, album_list);
+ else if (artist_list != NULL)
+ list_window_paint(browser.lw, artist_lw_callback, artist_list);
+ else {
wmove(browser.lw->w, 0, 0);
wclrtobot(browser.lw->w);
}
static unsigned
metalist_length(void)
{
- assert(metalist != NULL);
+ assert(mode != LIST_ARTISTS || artist_list != NULL);
+ assert(mode != LIST_ALBUMS || album_list != NULL);
return mode == LIST_ALBUMS
- ? metalist->len + 2
- : metalist->len;
+ ? album_list->len + 2
+ : artist_list->len;
}
static int
case CMD_PLAY:
switch (mode) {
case LIST_ARTISTS:
- selected = g_ptr_array_index(metalist,
+ selected = g_ptr_array_index(artist_list,
browser.lw->selected);
open_album_list(c, g_strdup(selected));
list_window_push_state(browser.lw_state, browser.lw);
- list_window_paint(browser.lw, artist_lw_callback, metalist);
- wrefresh(browser.lw->w);
+ artist_repaint();
break;
case LIST_ALBUMS:
list_window_reset(browser.lw);
/* restore previous list window state */
list_window_pop_state(browser.lw_state, browser.lw);
- } else if (browser.lw->selected == metalist->len + 1) {
+ } else if (browser.lw->selected == album_list->len + 1) {
/* handle "show all" */
open_song_list(c, g_strdup(artist), g_strdup("\0"));
list_window_push_state(browser.lw_state, browser.lw);
} else {
/* select album */
- selected = g_ptr_array_index(metalist,
+ selected = g_ptr_array_index(album_list,
browser.lw->selected - 1);
open_song_list(c, g_strdup(artist), g_strdup(selected));
list_window_push_state(browser.lw_state, browser.lw);
list_window_pop_state(browser.lw_state,
browser.lw);
- list_window_paint(browser.lw, artist_lw_callback, metalist);
- wrefresh(browser.lw->w);
+ artist_repaint();
} else
browser_handle_enter(&browser, c);
break;
case CMD_ADD:
switch(mode) {
case LIST_ARTISTS:
- selected = g_ptr_array_index(metalist,
+ selected = g_ptr_array_index(artist_list,
browser.lw->selected);
add_query(c, MPD_TABLE_ARTIST, selected);
cmd = CMD_LIST_NEXT; /* continue and select next item... */
break;
case LIST_ALBUMS:
- if (browser.lw->selected == metalist->len + 1)
+ if (browser.lw->selected == album_list->len + 1)
add_query(c, MPD_TABLE_ARTIST, artist);
else if (browser.lw->selected > 0) {
- selected = g_ptr_array_index(metalist,
+ selected = g_ptr_array_index(album_list,
browser.lw->selected - 1);
add_query(c, MPD_TABLE_ALBUM, selected);
cmd = CMD_LIST_NEXT; /* continue and select next item... */
case CMD_LIST_RFIND:
case CMD_LIST_FIND_NEXT:
case CMD_LIST_RFIND_NEXT:
- if (browser.filelist)
+ switch (mode) {
+ case LIST_ARTISTS:
+ screen_find(screen,
+ browser.lw, artist_list->len,
+ cmd, artist_lw_callback, artist_list);
+ break;
+
+ case LIST_ALBUMS:
+ screen_find(screen,
+ browser.lw, album_list->len + 2,
+ cmd, artist_lw_callback, album_list);
+ break;
+
+ case LIST_SONGS:
screen_find(screen,
- browser.lw, filelist_length(browser.filelist),
+ browser.lw,
+ filelist_length(browser.filelist),
cmd, browser_lw_callback,
browser.filelist);
- else if (metalist)
- screen_find(screen,
- browser.lw, metalist_length(),
- cmd, artist_lw_callback, metalist);
- else
- return 1;
+ break;
+ }
artist_repaint();
return 1;