diff options
author | Max Kellermann <max@duempel.org> | 2008-09-18 23:35:11 +0200 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2008-09-18 23:35:11 +0200 |
commit | 4f7926a989e2428a4701de3410e80997867ff63b (patch) | |
tree | 425cc5381efbbe850c7479008bb8cd2d1c4209a9 | |
parent | b7d7beeed8cab78bcc7c3df2f63a93bf682f84ca (diff) | |
download | mpd-4f7926a989e2428a4701de3410e80997867ff63b.tar.gz mpd-4f7926a989e2428a4701de3410e80997867ff63b.tar.xz mpd-4f7926a989e2428a4701de3410e80997867ff63b.zip |
screen_browser: added struct screen_browser
We are going to separate the browser functions from screen_file.c.
Move all variables which are going to be needed by this code.
-rw-r--r-- | src/screen_artist.c | 170 | ||||
-rw-r--r-- | src/screen_browser.h | 6 | ||||
-rw-r--r-- | src/screen_file.c | 114 | ||||
-rw-r--r-- | src/screen_search.c | 103 |
4 files changed, 208 insertions, 185 deletions
diff --git a/src/screen_artist.c b/src/screen_artist.c index 2f7796677..8e9732b8b 100644 --- a/src/screen_artist.c +++ b/src/screen_artist.c @@ -46,11 +46,10 @@ typedef enum { LIST_ARTISTS, LIST_ALBUMS, LIST_SONGS } artist_mode_t; static artist_mode_t mode = LIST_ARTISTS; static char *artist = NULL; static char *album = NULL; -static list_window_t *lw = NULL; -static mpdclient_filelist_t *filelist = NULL; static unsigned metalist_length = 0; static GList *metalist = NULL; -static list_window_state_t *lw_state = NULL; + +static struct screen_browser browser; static gint compare_utf8(gconstpointer s1, gconstpointer s2) @@ -87,16 +86,16 @@ artist_lw_callback(unsigned idx, mpd_unused int *highlight, mpd_unused void *dat static void playlist_changed_callback(mpdclient_t *c, int event, mpd_unused gpointer data) { - if (filelist == NULL) + if (browser.filelist == NULL) return; D("screen_artist.c> playlist_callback() [%d]\n", event); switch(event) { case PLAYLIST_EVENT_CLEAR: - clear_highlights(filelist); + clear_highlights(browser.filelist); break; default: - sync_highlights(c, filelist); + sync_highlights(c, browser.filelist); break; } } @@ -112,10 +111,10 @@ update_metalist(mpdclient_t *c, char *m_artist, char *m_album) if (metalist) metalist = string_list_free(metalist); - if (filelist) { + if (browser.filelist) { mpdclient_remove_playlist_callback(c, playlist_changed_callback); - mpdclient_filelist_free(filelist); - filelist = NULL; + mpdclient_filelist_free(browser.filelist); + browser.filelist = NULL; } if (m_album) { @@ -126,22 +125,23 @@ update_metalist(mpdclient_t *c, char *m_artist, char *m_album) album = m_album; if (album[0] == 0) { album = g_strdup(_("All tracks")); - filelist = mpdclient_filelist_search_utf8(c, - TRUE, - MPD_TABLE_ARTIST, - artist); + browser.filelist = + mpdclient_filelist_search_utf8(c, TRUE, + MPD_TABLE_ARTIST, + artist); } else - filelist = mpdclient_filelist_search_utf8(c, - TRUE, - MPD_TABLE_ALBUM, - album); + browser.filelist = + mpdclient_filelist_search_utf8(c, TRUE, + MPD_TABLE_ALBUM, + album); /* add a dummy entry for ".." */ entry = g_malloc0(sizeof(filelist_entry_t)); entry->entity = NULL; - filelist->list = g_list_insert(filelist->list, entry, 0); - filelist->length++; + browser.filelist->list = g_list_insert(browser.filelist->list, + entry, 0); + browser.filelist->length++; /* install playlist callback and fix highlights */ - sync_highlights(c, filelist); + sync_highlights(c, browser.filelist); mpdclient_install_playlist_callback(c, playlist_changed_callback); mode = LIST_SONGS; } else if (m_artist) { @@ -165,7 +165,7 @@ update_metalist(mpdclient_t *c, char *m_artist, char *m_album) mode = LIST_ARTISTS; } metalist_length = g_list_length(metalist); - lw->clear = TRUE; + browser.lw->clear = TRUE; } /* db updated */ @@ -175,8 +175,8 @@ browse_callback(mpdclient_t *c, int event, mpd_unused gpointer data) switch(event) { case BROWSE_DB_UPDATED: D("screen_artist.c> browse_callback() [BROWSE_DB_UPDATED]\n"); - lw->clear = 1; - lw->repaint = 1; + browser.lw->clear = 1; + browser.lw->repaint = 1; update_metalist(c, g_strdup(artist), g_strdup(album)); break; default: @@ -187,8 +187,8 @@ browse_callback(mpdclient_t *c, int event, mpd_unused gpointer data) static void init(WINDOW *w, int cols, int rows) { - lw = list_window_init(w, cols, rows); - lw_state = list_window_init_state(); + browser.lw = list_window_init(w, cols, rows); + browser.lw_state = list_window_init_state(); artist = NULL; album = NULL; } @@ -196,16 +196,16 @@ init(WINDOW *w, int cols, int rows) static void quit(void) { - if (filelist) - mpdclient_filelist_free(filelist); + if (browser.filelist) + mpdclient_filelist_free(browser.filelist); if (metalist) string_list_free(metalist); g_free(artist); g_free(album); artist = NULL; album = NULL; - list_window_free(lw); - list_window_free_state(lw_state); + list_window_free(browser.lw); + list_window_free_state(browser.lw_state); } static void @@ -213,7 +213,7 @@ open(mpd_unused screen_t *screen, mpdclient_t *c) { static gboolean callback_installed = FALSE; - if (metalist == NULL && filelist == NULL) + if (metalist == NULL && browser.filelist == NULL) update_metalist(c, NULL, NULL); if (!callback_installed) { mpdclient_install_browse_callback(c, browse_callback); @@ -224,38 +224,40 @@ open(mpd_unused screen_t *screen, mpdclient_t *c) static void resize(int cols, int rows) { - lw->cols = cols; - lw->rows = rows; + browser.lw->cols = cols; + browser.lw->rows = rows; } static void paint(mpd_unused screen_t *screen, mpd_unused mpdclient_t *c) { - lw->clear = 1; + browser.lw->clear = 1; - if (filelist) { - list_window_paint(lw, browse_lw_callback, (void *) filelist); - filelist->updated = FALSE; + if (browser.filelist) { + list_window_paint(browser.lw, browse_lw_callback, + browser.filelist); + browser.filelist->updated = FALSE; } else if (metalist) { - list_window_paint(lw, artist_lw_callback, (void *) metalist); + list_window_paint(browser.lw, artist_lw_callback, metalist); } else { - wmove(lw->w, 0, 0); - wclrtobot(lw->w); + wmove(browser.lw->w, 0, 0); + wclrtobot(browser.lw->w); } - wnoutrefresh(lw->w); + wnoutrefresh(browser.lw->w); } static void update(screen_t *screen, mpdclient_t *c) { - if (filelist && !filelist->updated) - list_window_paint(lw, browse_lw_callback, (void *) filelist); + if (browser.filelist && !browser.filelist->updated) + list_window_paint(browser.lw, browse_lw_callback, + browser.filelist); else if (metalist) - list_window_paint(lw, artist_lw_callback, (void *) metalist); + list_window_paint(browser.lw, artist_lw_callback, metalist); else paint(screen, c); - wnoutrefresh(lw->w); + wnoutrefresh(browser.lw->w); } static const char * @@ -309,41 +311,45 @@ artist_cmd(screen_t *screen, mpdclient_t *c, command_t cmd) case CMD_PLAY: switch (mode) { case LIST_ARTISTS: - selected = (char *) g_list_nth_data(metalist, lw->selected); + selected = (char *) g_list_nth_data(metalist, + browser.lw->selected); update_metalist(c, g_strdup(selected), NULL); - list_window_push_state(lw_state,lw); + list_window_push_state(browser.lw_state, browser.lw); break; case LIST_ALBUMS: - if (lw->selected == 0) { + if (browser.lw->selected == 0) { /* handle ".." */ update_metalist(c, NULL, NULL); - list_window_reset(lw); + list_window_reset(browser.lw); /* restore previous list window state */ - list_window_pop_state(lw_state,lw); - } else if (lw->selected == metalist_length - 1) { + list_window_pop_state(browser.lw_state, browser.lw); + } else if (browser.lw->selected == metalist_length - 1) { /* handle "show all" */ update_metalist(c, g_strdup(artist), g_strdup("\0")); - list_window_push_state(lw_state,lw); + list_window_push_state(browser.lw_state, browser.lw); } else { /* select album */ - selected = (char *) g_list_nth_data(metalist, lw->selected); + selected = g_list_nth_data(metalist, + browser.lw->selected); update_metalist(c, g_strdup(artist), g_strdup(selected)); - list_window_push_state(lw_state,lw); + list_window_push_state(browser.lw_state, browser.lw); } break; case LIST_SONGS: - if (lw->selected == 0) { + if (browser.lw->selected == 0) { /* handle ".." */ update_metalist(c, g_strdup(artist), NULL); - list_window_reset(lw); + list_window_reset(browser.lw); /* restore previous list window state */ - list_window_pop_state(lw_state,lw); + list_window_pop_state(browser.lw_state, + browser.lw); } else - browse_handle_enter(screen, c, lw, filelist); + browse_handle_enter(screen, c, browser.lw, + browser.filelist); break; } return 1; @@ -358,16 +364,16 @@ artist_cmd(screen_t *screen, mpdclient_t *c, command_t cmd) case LIST_ALBUMS: update_metalist(c, NULL, NULL); - list_window_reset(lw); + list_window_reset(browser.lw); /* restore previous list window state */ - list_window_pop_state(lw_state,lw); + list_window_pop_state(browser.lw_state, browser.lw); break; case LIST_SONGS: update_metalist(c, g_strdup(artist), NULL); - list_window_reset(lw); + list_window_reset(browser.lw); /* restore previous list window state */ - list_window_pop_state(lw_state,lw); + list_window_pop_state(browser.lw_state, browser.lw); break; } break; @@ -380,9 +386,9 @@ artist_cmd(screen_t *screen, mpdclient_t *c, command_t cmd) case LIST_ALBUMS: case LIST_SONGS: update_metalist(c, NULL, NULL); - list_window_reset(lw); + list_window_reset(browser.lw); /* restore first list window state (pop while returning true) */ - while(list_window_pop_state(lw_state,lw)); + while(list_window_pop_state(browser.lw_state, browser.lw)); break; } break; @@ -390,23 +396,27 @@ artist_cmd(screen_t *screen, mpdclient_t *c, command_t cmd) case CMD_SELECT: switch(mode) { case LIST_ARTISTS: - selected = (char *) g_list_nth_data(metalist, lw->selected); + selected = g_list_nth_data(metalist, + browser.lw->selected); add_query(c, MPD_TABLE_ARTIST, selected); cmd = CMD_LIST_NEXT; /* continue and select next item... */ break; case LIST_ALBUMS: - if (lw->selected && lw->selected == metalist_length - 1) + if (browser.lw->selected && + browser.lw->selected == metalist_length - 1) add_query(c, MPD_TABLE_ARTIST, artist); - else if (lw->selected > 0) { - selected = (char *) g_list_nth_data(metalist, lw->selected); + else if (browser.lw->selected > 0) { + selected = g_list_nth_data(metalist, + browser.lw->selected); add_query(c, MPD_TABLE_ALBUM, selected); cmd = CMD_LIST_NEXT; /* continue and select next item... */ } break; case LIST_SONGS: - if (browse_handle_select(screen, c, lw, filelist) == 0) + if (browse_handle_select(screen, c, browser.lw, + browser.filelist) == 0) /* continue and select next item... */ cmd = CMD_LIST_NEXT; break; @@ -416,8 +426,8 @@ artist_cmd(screen_t *screen, mpdclient_t *c, command_t cmd) /* continue and update... */ case CMD_SCREEN_UPDATE: screen->painted = 0; - lw->clear = 1; - lw->repaint = 1; + browser.lw->clear = 1; + browser.lw->repaint = 1; update_metalist(c, g_strdup(artist), g_strdup(album)); screen_status_printf(_("Screen updated!")); return 0; @@ -426,28 +436,30 @@ artist_cmd(screen_t *screen, mpdclient_t *c, command_t cmd) case CMD_LIST_RFIND: case CMD_LIST_FIND_NEXT: case CMD_LIST_RFIND_NEXT: - if (filelist) + if (browser.filelist) return screen_find(screen, - lw, filelist->length, - cmd, browse_lw_callback, (void *) filelist); + browser.lw, browser.filelist->length, + cmd, browse_lw_callback, + browser.filelist); else if (metalist) return screen_find(screen, - lw, metalist_length, - cmd, artist_lw_callback, (void *) metalist); + browser.lw, metalist_length, + cmd, artist_lw_callback, metalist); else return 1; case CMD_MOUSE_EVENT: - return browse_handle_mouse_event(screen,c,lw,filelist); + return browse_handle_mouse_event(screen, c,browser.lw, + browser.filelist); default: break; } - if (filelist) - return list_window_cmd(lw, filelist->length, cmd); + if (browser.filelist) + return list_window_cmd(browser.lw, browser.filelist->length, cmd); else if (metalist) - return list_window_cmd(lw, metalist_length, cmd); + return list_window_cmd(browser.lw, metalist_length, cmd); return 0; } diff --git a/src/screen_browser.h b/src/screen_browser.h index 0726d0b35..3ebcff20a 100644 --- a/src/screen_browser.h +++ b/src/screen_browser.h @@ -1,3 +1,9 @@ +struct screen_browser { + struct list_window *lw; + struct list_window_state *lw_state; + + mpdclient_filelist_t *filelist; +}; void clear_highlights(mpdclient_filelist_t *filelist); void sync_highlights(mpdclient_t *c, mpdclient_filelist_t *filelist); diff --git a/src/screen_file.c b/src/screen_file.c index 5b66d6f52..36e04b590 100644 --- a/src/screen_file.c +++ b/src/screen_file.c @@ -44,11 +44,7 @@ #define HIGHLIGHT (0x01) - -static list_window_t *lw = NULL; -static list_window_state_t *lw_state = NULL; -static mpdclient_filelist_t *filelist = NULL; - +static struct screen_browser browser; /* clear the highlight flag for all items in the filelist */ void @@ -119,9 +115,9 @@ file_changed_callback(mpdclient_t *c, mpd_unused int event, mpd_unused gpointer data) { D("screen_file.c> filelist_callback() [%d]\n", event); - filelist = mpdclient_filelist_update(c, filelist); - sync_highlights(c, filelist); - list_window_check_selected(lw, filelist->length); + browser.filelist = mpdclient_filelist_update(c, browser.filelist); + sync_highlights(c, browser.filelist); + list_window_check_selected(browser.lw, browser.filelist->length); } /* the playlist have been updated -> fix highlights */ @@ -131,18 +127,18 @@ playlist_changed_callback(mpdclient_t *c, int event, gpointer data) D("screen_file.c> playlist_callback() [%d]\n", event); switch(event) { case PLAYLIST_EVENT_CLEAR: - clear_highlights(filelist); + clear_highlights(browser.filelist); break; case PLAYLIST_EVENT_ADD: - set_highlight(filelist, (mpd_Song *) data, 1); + set_highlight(browser.filelist, (mpd_Song *) data, 1); break; case PLAYLIST_EVENT_DELETE: - set_highlight(filelist, (mpd_Song *) data, 0); + set_highlight(browser.filelist, (mpd_Song *) data, 0); break; case PLAYLIST_EVENT_MOVE: break; default: - sync_highlights(c, filelist); + sync_highlights(c, browser.filelist); break; } } @@ -209,33 +205,33 @@ change_directory(mpd_unused screen_t *screen, mpdclient_t *c, if( entity==NULL ) { if( entry || 0==strcmp(new_path, "..") ) { /* return to parent */ - char *parent = g_path_get_dirname(filelist->path); + char *parent = g_path_get_dirname(browser.filelist->path); if( strcmp(parent, ".") == 0 ) parent[0] = '\0'; path = g_strdup(parent); - list_window_reset(lw); + list_window_reset(browser.lw); /* restore previous list window state */ - list_window_pop_state(lw_state,lw); + list_window_pop_state(browser.lw_state,browser.lw); } else { /* entry==NULL, then new_path ("" is root) */ path = g_strdup(new_path); - list_window_reset(lw); + list_window_reset(browser.lw); /* restore first list window state (pop while returning true) */ - while(list_window_pop_state(lw_state,lw)); + while(list_window_pop_state(browser.lw_state,browser.lw)); } } else if( entity->type==MPD_INFO_ENTITY_TYPE_DIRECTORY) { /* enter sub */ mpd_Directory *dir = entity->info.directory; path = utf8_to_locale(dir->path); /* save current list window state */ - list_window_push_state(lw_state,lw); + list_window_push_state(browser.lw_state,browser.lw); } else return -1; - mpdclient_filelist_free(filelist); - filelist = mpdclient_filelist_get(c, path); - sync_highlights(c, filelist); - list_window_check_selected(lw, filelist->length); + mpdclient_filelist_free(browser.filelist); + browser.filelist = mpdclient_filelist_get(c, path); + sync_highlights(c, browser.filelist); + list_window_check_selected(browser.lw, browser.filelist->length); g_free(path); return 0; } @@ -260,8 +256,7 @@ handle_save(screen_t *screen, mpdclient_t *c) filelist_entry_t *entry; char *defaultname = NULL; - - entry=( filelist_entry_t *) g_list_nth_data(filelist->list,lw->selected); + entry = g_list_nth_data(browser.filelist->list, browser.lw->selected); if( entry && entry->entity ) { mpd_InfoEntity *entity = entry->entity; if( entity->type==MPD_INFO_ENTITY_TYPE_PLAYLISTFILE ) { @@ -282,7 +277,7 @@ handle_delete(screen_t *screen, mpdclient_t *c) char *str, *buf; int key; - entry=( filelist_entry_t *) g_list_nth_data(filelist->list,lw->selected); + entry = g_list_nth_data(browser.filelist->list,browser. lw->selected); if( entry==NULL || entry->entity==NULL ) return -1; @@ -560,31 +555,31 @@ browse_handle_select_all (screen_t *screen, static void browse_init(WINDOW *w, int cols, int rows) { - lw = list_window_init(w, cols, rows); - lw_state = list_window_init_state(); + browser.lw = list_window_init(w, cols, rows); + browser.lw_state = list_window_init_state(); } static void browse_resize(int cols, int rows) { - lw->cols = cols; - lw->rows = rows; + browser.lw->cols = cols; + browser.lw->rows = rows; } static void browse_exit(void) { - if( filelist ) - mpdclient_filelist_free(filelist); - list_window_free(lw); - list_window_free_state(lw_state); + if (browser.filelist) + mpdclient_filelist_free(browser.filelist); + list_window_free(browser.lw); + list_window_free_state(browser.lw_state); } static void browse_open(mpd_unused screen_t *screen, mpd_unused mpdclient_t *c) { - if( filelist == NULL ) { - filelist = mpdclient_filelist_get(c, ""); + if (browser.filelist == NULL) { + browser.filelist = mpdclient_filelist_get(c, ""); mpdclient_install_playlist_callback(c, playlist_changed_callback); mpdclient_install_browse_callback(c, file_changed_callback); } @@ -596,7 +591,7 @@ browse_title(char *str, size_t size) char *pathcopy; char *parentdir; - pathcopy = strdup(filelist->path); + pathcopy = strdup(browser.filelist->path); parentdir = dirname(pathcopy); parentdir = basename(parentdir); @@ -607,7 +602,7 @@ browse_title(char *str, size_t size) g_snprintf(str, size, _("Browse: %s%s%s"), parentdir ? parentdir : "", parentdir ? "/" : "", - basename(filelist->path)); + basename(browser.filelist->path)); free(pathcopy); return str; } @@ -615,23 +610,23 @@ browse_title(char *str, size_t size) static void browse_paint(mpd_unused screen_t *screen, mpd_unused mpdclient_t *c) { - lw->clear = 1; + browser.lw->clear = 1; - list_window_paint(lw, browse_lw_callback, (void *) filelist); - wnoutrefresh(lw->w); + list_window_paint(browser.lw, browse_lw_callback, browser.filelist); + wnoutrefresh(browser.lw->w); } static void browse_update(screen_t *screen, mpdclient_t *c) { - if( filelist->updated ) { + if (browser.filelist->updated) { browse_paint(screen, c); - filelist->updated = FALSE; + browser.filelist->updated = FALSE; return; } - list_window_paint(lw, browse_lw_callback, (void *) filelist); - wnoutrefresh(lw->w); + list_window_paint(browser.lw, browse_lw_callback, browser.filelist); + wnoutrefresh(browser.lw->w); } @@ -675,7 +670,8 @@ browse_cmd(screen_t *screen, mpdclient_t *c, command_t cmd) { switch(cmd) { case CMD_PLAY: - browse_handle_enter(screen, c, lw, filelist); + browse_handle_enter(screen, c, browser.lw, + browser.filelist); return 1; case CMD_GO_ROOT_DIRECTORY: return change_directory(screen, c, NULL, ""); @@ -684,7 +680,8 @@ browse_cmd(screen_t *screen, mpdclient_t *c, command_t cmd) return change_directory(screen, c, NULL, ".."); break; case CMD_SELECT: - if (browse_handle_select(screen, c, lw, filelist) == 0) { + if (browse_handle_select(screen, c, browser.lw, + browser.filelist) == 0) { /* continue and select next item... */ cmd = CMD_LIST_NEXT; } @@ -697,10 +694,11 @@ browse_cmd(screen_t *screen, mpdclient_t *c, command_t cmd) break; case CMD_SCREEN_UPDATE: screen->painted = 0; - lw->clear = 1; - lw->repaint = 1; - filelist = mpdclient_filelist_update(c, filelist); - list_window_check_selected(lw, filelist->length); + browser.lw->clear = 1; + browser.lw->repaint = 1; + browser.filelist = mpdclient_filelist_update(c, browser.filelist); + list_window_check_selected(browser.lw, + browser.filelist->length); screen_status_printf(_("Screen updated!")); return 1; case CMD_DB_UPDATE: @@ -708,10 +706,10 @@ browse_cmd(screen_t *screen, mpdclient_t *c, command_t cmd) return 1; if (!c->status->updatingDb) { - if (mpdclient_cmd_db_update_utf8(c,filelist->path) == 0) { - if (strcmp(filelist->path, "")) + if (mpdclient_cmd_db_update_utf8(c, browser.filelist->path) == 0) { + if (strcmp(browser.filelist->path, "")) screen_status_printf(_("Database update of %s started!"), - filelist->path); + browser.filelist->path); else screen_status_printf(_("Database update started!")); @@ -727,15 +725,17 @@ browse_cmd(screen_t *screen, mpdclient_t *c, command_t cmd) case CMD_LIST_FIND_NEXT: case CMD_LIST_RFIND_NEXT: return screen_find(screen, - lw, filelist->length, - cmd, browse_lw_callback, (void *) filelist); + browser.lw, browser.filelist->length, + cmd, browse_lw_callback, + browser.filelist); case CMD_MOUSE_EVENT: - return browse_handle_mouse_event(screen,c,lw,filelist); + return browse_handle_mouse_event(screen,c, browser.lw, + browser.filelist); default: break; } - return list_window_cmd(lw, filelist->length, cmd); + return list_window_cmd(browser.lw, browser.filelist->length, cmd); } const struct screen_functions screen_browse = { diff --git a/src/screen_search.c b/src/screen_search.c index 8a7f9b1df..02ba2d1c6 100644 --- a/src/screen_search.c +++ b/src/screen_search.c @@ -105,12 +105,12 @@ static search_type_t mode[] = { { 0, NULL } }; -static list_window_t *lw = NULL; -static mpdclient_filelist_t *filelist = NULL; static GList *search_history = NULL; static gchar *pattern = NULL; static gboolean advanced_search_mode = FALSE; +static struct screen_browser browser; + /* search info */ static const char * @@ -144,15 +144,15 @@ lw_search_help_callback(unsigned idx, mpd_unused int *highlight, static void playlist_changed_callback(mpdclient_t *c, int event, mpd_unused gpointer data) { - if (filelist == NULL) + if (browser.filelist == NULL) return; D("screen_search.c> playlist_callback() [%d]\n", event); switch(event) { case PLAYLIST_EVENT_CLEAR: - clear_highlights(filelist); + clear_highlights(browser.filelist); break; default: - sync_highlights(c, filelist); + sync_highlights(c, browser.filelist); break; } } @@ -175,10 +175,10 @@ static void search_clear(mpd_unused screen_t *screen, mpdclient_t *c, gboolean clear_pattern) { - if (filelist) { + if (browser.filelist) { mpdclient_remove_playlist_callback(c, playlist_changed_callback); - mpdclient_filelist_free(filelist); - filelist = NULL; + mpdclient_filelist_free(browser.filelist); + browser.filelist = NULL; } if (clear_pattern && pattern) { g_free(pattern); @@ -334,21 +334,21 @@ search_new(screen_t *screen, mpdclient_t *c) } if (pattern == NULL) { - list_window_reset(lw); + list_window_reset(browser.lw); return; } if (!MPD_VERSION_LT(c, 0, 12, 0)) - filelist = search_advanced_query(pattern, c); + browser.filelist = search_advanced_query(pattern, c); - if (!advanced_search_mode && filelist == NULL) - filelist = filelist_search(c, FALSE, - mode[options.search_mode].table, - pattern); + if (!advanced_search_mode && browser.filelist == NULL) + browser.filelist = filelist_search(c, FALSE, + mode[options.search_mode].table, + pattern); - sync_highlights(c, filelist); + sync_highlights(c, browser.filelist); mpdclient_install_playlist_callback(c, playlist_changed_callback); - list_window_check_selected(lw, filelist->length); + list_window_check_selected(browser.lw, browser.filelist->length); } @@ -356,7 +356,7 @@ search_new(screen_t *screen, mpdclient_t *c) static void init(WINDOW *w, int cols, int rows) { - lw = list_window_init(w, cols, rows); + browser.lw = list_window_init(w, cols, rows); } static void @@ -364,9 +364,9 @@ quit(void) { if (search_history) string_list_free(search_history); - if (filelist) - mpdclient_filelist_free(filelist); - list_window_free(lw); + if (browser.filelist) + mpdclient_filelist_free(browser.filelist); + list_window_free(browser.lw); if (pattern) { g_free(pattern); @@ -388,41 +388,41 @@ open(mpd_unused screen_t *screen, mpd_unused mpdclient_t *c) static void resize(int cols, int rows) { - lw->cols = cols; - lw->rows = rows; + browser.lw->cols = cols; + browser.lw->rows = rows; } static void paint(mpd_unused screen_t *screen, mpdclient_t *c) { - lw->clear = 1; + browser.lw->clear = 1; - if (filelist) { - lw->flags = 0; - list_window_paint(lw, browse_lw_callback, (void *) filelist); - filelist->updated = FALSE; + if (browser.filelist) { + browser.lw->flags = 0; + list_window_paint(browser.lw, browse_lw_callback, browser.filelist); + browser.filelist->updated = FALSE; } else { - lw->flags = LW_HIDE_CURSOR; - list_window_paint(lw, lw_search_help_callback, NULL); + browser.lw->flags = LW_HIDE_CURSOR; + list_window_paint(browser.lw, lw_search_help_callback, NULL); if( !MPD_VERSION_LT(c, 0, 12, 0) ) g_strdup_printf("Advanced search disabled (MPD version < 0.12.0"); // wmove(lw->w, 0, 0); //wclrtobot(lw->w); } - wnoutrefresh(lw->w); + wnoutrefresh(browser.lw->w); } static void update(screen_t *screen, mpdclient_t *c) { - if (filelist==NULL || filelist->updated) { + if (browser.filelist == NULL || browser.filelist->updated) { paint(screen, c); return; } - list_window_paint(lw, browse_lw_callback, (void *) filelist); - wnoutrefresh(lw->w); + list_window_paint(browser.lw, browse_lw_callback, browser.filelist); + wnoutrefresh(browser.lw->w); } static const char * @@ -448,19 +448,21 @@ search_cmd(screen_t *screen, mpdclient_t *c, command_t cmd) { switch (cmd) { case CMD_PLAY: - browse_handle_enter(screen, c, lw, filelist); + browse_handle_enter(screen, c, browser.lw, browser.filelist); return 1; case CMD_SELECT: - if (browse_handle_select(screen, c, lw, filelist) == 0) { + if (browse_handle_select(screen, c, browser.lw, + browser.filelist) == 0) { /* continue and select next item... */ cmd = CMD_LIST_NEXT; } /* call list_window_cmd to go to the next item */ - return list_window_cmd(lw, filelist->length, cmd); + return list_window_cmd(browser.lw, browser.filelist->length, cmd); case CMD_SELECT_ALL: - browse_handle_select_all (screen, c, lw, filelist); + browse_handle_select_all(screen, c, browser.lw, + browser.filelist); paint (screen, c); return 0; @@ -474,11 +476,11 @@ search_cmd(screen_t *screen, mpdclient_t *c, command_t cmd) case CMD_SCREEN_UPDATE: if (pattern) { search_clear(screen, c, FALSE); - filelist = filelist_search(c, - FALSE, - mode[options.search_mode].table, - pattern); - sync_highlights(c, filelist); + browser.filelist = filelist_search(c, + FALSE, + mode[options.search_mode].table, + pattern); + sync_highlights(c, browser.filelist); } return 1; @@ -488,26 +490,29 @@ search_cmd(screen_t *screen, mpdclient_t *c, command_t cmd) case CMD_CLEAR: search_clear(screen, c, TRUE); - list_window_reset(lw); + list_window_reset(browser.lw); return 1; case CMD_LIST_FIND: case CMD_LIST_RFIND: case CMD_LIST_FIND_NEXT: case CMD_LIST_RFIND_NEXT: - if (filelist) + if (browser.filelist) return screen_find(screen, - lw, filelist->length, - cmd, browse_lw_callback, (void *) filelist); + browser.lw, browser.filelist->length, + cmd, browse_lw_callback, + browser.filelist); else return 1; case CMD_MOUSE_EVENT: - return browse_handle_mouse_event(screen,c,lw,filelist); + return browse_handle_mouse_event(screen, c, browser.lw, + browser.filelist); default: - if (filelist) - return list_window_cmd(lw, filelist->length, cmd); + if (browser.filelist) + return list_window_cmd(browser.lw, + browser.filelist->length, cmd); } return 0; |