diff options
author | Kalle Wallin <kaw@linux.se> | 2004-04-19 22:06:41 +0000 |
---|---|---|
committer | Kalle Wallin <kaw@linux.se> | 2004-04-19 22:06:41 +0000 |
commit | bf28b56f26bb5753c706e2e249265f95b500fd78 (patch) | |
tree | 7dbc577ad0ab0b293ab0ff00b86ee93ab80bae4d /screen_file.c | |
parent | 2a803438b5efaee06de58af19a7cb501904d2901 (diff) | |
download | mpd-bf28b56f26bb5753c706e2e249265f95b500fd78.tar.gz mpd-bf28b56f26bb5753c706e2e249265f95b500fd78.tar.xz mpd-bf28b56f26bb5753c706e2e249265f95b500fd78.zip |
Major cleanup. The goal of this is to simplify addition of "screens".
git-svn-id: https://svn.musicpd.org/ncmpc/trunk@832 09075e82-0dd4-0310-85a5-a0d7c8717e4f
Diffstat (limited to 'screen_file.c')
-rw-r--r-- | screen_file.c | 197 |
1 files changed, 127 insertions, 70 deletions
diff --git a/screen_file.c b/screen_file.c index cb1500588..a0b9ee3f7 100644 --- a/screen_file.c +++ b/screen_file.c @@ -1,3 +1,21 @@ +/* + * (c) 2004 by Kalle Wallin (kaw@linux.se) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + #include <ctype.h> #include <stdlib.h> #include <string.h> @@ -14,9 +32,13 @@ #include "screen_file.h" #define BUFSIZE 1024 +#define TITLESIZE 256 #define USE_OLD_LAYOUT +static list_window_t *lw; +static mpd_client_t *mpc = NULL; + static char * list_callback(int index, int *highlight, void *data) { @@ -84,7 +106,6 @@ list_callback(int index, int *highlight, void *data) static int change_directory(screen_t *screen, mpd_client_t *c, filelist_entry_t *entry) { - list_window_t *w = screen->filelist; mpd_InfoEntity *entity = entry->entity; if( entity==NULL ) @@ -111,7 +132,7 @@ change_directory(screen_t *screen, mpd_client_t *c, filelist_entry_t *entry) return -1; mpc_update_filelist(c); - list_window_reset(w); + list_window_reset(lw); return 0; } @@ -133,7 +154,6 @@ load_playlist(screen_t *screen, mpd_client_t *c, filelist_entry_t *entry) static int handle_delete(screen_t *screen, mpd_client_t *c) { - list_window_t *lw = screen->filelist; filelist_entry_t *entry; mpd_InfoEntity *entity; mpd_PlaylistFile *plf; @@ -184,11 +204,10 @@ handle_delete(screen_t *screen, mpd_client_t *c) static int handle_play_cmd(screen_t *screen, mpd_client_t *c) { - list_window_t *w = screen->filelist; filelist_entry_t *entry; mpd_InfoEntity *entity; - entry = ( filelist_entry_t *) g_list_nth_data(c->filelist, w->selected); + entry = ( filelist_entry_t *) g_list_nth_data(c->filelist, lw->selected); if( entry==NULL ) return -1; @@ -253,10 +272,9 @@ add_directory(mpd_client_t *c, char *dir) static int handle_select(screen_t *screen, mpd_client_t *c) { - list_window_t *w = screen->filelist; filelist_entry_t *entry; - entry = ( filelist_entry_t *) g_list_nth_data(c->filelist, w->selected); + entry = ( filelist_entry_t *) g_list_nth_data(c->filelist, lw->selected); if( entry==NULL || entry->entity==NULL) return -1; @@ -306,54 +324,41 @@ handle_select(screen_t *screen, mpd_client_t *c) return 0; } -void -file_clear_highlights(mpd_client_t *c) +static void +file_init(WINDOW *w, int cols, int rows) { - GList *list = g_list_first(c->filelist); - - while( list ) - { - filelist_entry_t *entry = list->data; - - entry->selected = 0; - list = list->next; - } + lw = list_window_init(w, cols, rows); } -void -file_clear_highlight(mpd_client_t *c, mpd_Song *song) +static void +file_exit(void) { - GList *list = g_list_first(c->filelist); - - if( !song ) - return; + list_window_free(lw); +} - while( list ) +static void +file_open(screen_t *screen, mpd_client_t *c) +{ + if( c->filelist == NULL ) { - filelist_entry_t *entry = list->data; - mpd_InfoEntity *entity = entry->entity; - - if( entity && entity->type==MPD_INFO_ENTITY_TYPE_SONG ) - { - mpd_Song *song2 = entity->info.song; - - if( strcmp(song->file, song2->file) == 0 ) - { - entry->selected = 0; - } - } - list = list->next; + mpc_update_filelist(c); } + mpc = c; } -char * -file_get_header(mpd_client_t *c) +static void +file_close(void) { - static char buf[BUFSIZE]; +} + +static char * +file_title(void) +{ + static char buf[TITLESIZE]; char *tmp; - tmp = utf8_to_locale(basename(c->cwd)); - snprintf(buf, BUFSIZE, + tmp = utf8_to_locale(basename(mpc->cwd)); + snprintf(buf, TITLESIZE, TOP_HEADER_FILE ": %s ", tmp ); @@ -362,32 +367,16 @@ file_get_header(mpd_client_t *c) return buf; } -void -file_open(screen_t *screen, mpd_client_t *c) -{ - if( c->filelist == NULL ) - { - mpc_update_filelist(c); - } -} - -void -file_close(screen_t *screen, mpd_client_t *c) -{ -} - -void +static void file_paint(screen_t *screen, mpd_client_t *c) { - list_window_t *w = screen->filelist; - - w->clear = 1; + lw->clear = 1; - list_window_paint(screen->filelist, list_callback, (void *) c); - wnoutrefresh(screen->filelist->w); + list_window_paint(lw, list_callback, (void *) c); + wnoutrefresh(lw->w); } -void +static void file_update(screen_t *screen, mpd_client_t *c) { if( c->filelist_updated ) @@ -396,12 +385,12 @@ file_update(screen_t *screen, mpd_client_t *c) c->filelist_updated = 0; return; } - list_window_paint(screen->filelist, list_callback, (void *) c); - wnoutrefresh(screen->filelist->w); + list_window_paint(lw, list_callback, (void *) c); + wnoutrefresh(lw->w); } -int +static int file_cmd(screen_t *screen, mpd_client_t *c, command_t cmd) { switch(cmd) @@ -421,7 +410,7 @@ file_cmd(screen_t *screen, mpd_client_t *c, command_t cmd) break; case CMD_SCREEN_UPDATE: mpc_update_filelist(c); - list_window_check_selected(screen->filelist, c->filelist_length); + list_window_check_selected(lw, c->filelist_length); screen_status_printf("Screen updated!"); return 1; case CMD_LIST_FIND: @@ -429,10 +418,78 @@ file_cmd(screen_t *screen, mpd_client_t *c, command_t cmd) case CMD_LIST_FIND_NEXT: case CMD_LIST_RFIND_NEXT: return screen_find(screen, c, - screen->filelist, c->filelist_length, + lw, c->filelist_length, cmd, list_callback); default: break; } - return list_window_cmd(screen->filelist, c->filelist_length, cmd); + return list_window_cmd(lw, c->filelist_length, cmd); +} + + +list_window_t * +get_filelist_window() +{ + return lw; } + + +void +file_clear_highlights(mpd_client_t *c) +{ + GList *list = g_list_first(c->filelist); + + while( list ) + { + filelist_entry_t *entry = list->data; + + entry->selected = 0; + list = list->next; + } +} + +void +file_clear_highlight(mpd_client_t *c, mpd_Song *song) +{ + GList *list = g_list_first(c->filelist); + + if( !song ) + return; + + while( list ) + { + filelist_entry_t *entry = list->data; + mpd_InfoEntity *entity = entry->entity; + + if( entity && entity->type==MPD_INFO_ENTITY_TYPE_SONG ) + { + mpd_Song *song2 = entity->info.song; + + if( strcmp(song->file, song2->file) == 0 ) + { + entry->selected = 0; + } + } + list = list->next; + } +} + +screen_functions_t * +get_screen_file(void) +{ + static screen_functions_t functions; + + memset(&functions, 0, sizeof(screen_functions_t)); + functions.init = file_init; + functions.exit = file_exit; + functions.open = file_open; + functions.close = file_close; + functions.paint = file_paint; + functions.update = file_update; + functions.cmd = file_cmd; + functions.get_lw = get_filelist_window; + functions.get_title = file_title; + + return &functions; +} + |