diff options
-rw-r--r-- | screen.c | 249 | ||||
-rw-r--r-- | screen.h | 34 | ||||
-rw-r--r-- | screen_file.c | 197 | ||||
-rw-r--r-- | screen_file.h | 11 | ||||
-rw-r--r-- | screen_help.c | 92 | ||||
-rw-r--r-- | screen_help.h | 9 | ||||
-rw-r--r-- | screen_play.c | 114 | ||||
-rw-r--r-- | screen_play.h | 9 | ||||
-rw-r--r-- | screen_search.c | 25 | ||||
-rw-r--r-- | screen_search.h | 8 |
10 files changed, 464 insertions, 284 deletions
@@ -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 <stdlib.h> #include <unistd.h> #include <stdarg.h> @@ -17,10 +35,15 @@ #include "screen_search.h" #include "screen_utils.h" +#ifdef ENABLE_KEYDEF_SCREEN +extern screen_functions_t *get_screen_keydef(void); +#endif + #define STATUS_MESSAGE_TIMEOUT 3 #define STATUS_LINE_MAX_SIZE 512 static screen_t *screen = NULL; +static screen_functions_t *mode_fn = NULL; static void switch_screen_mode(screen_mode_t new_mode, mpd_client_t *c) @@ -28,40 +51,38 @@ switch_screen_mode(screen_mode_t new_mode, mpd_client_t *c) if( new_mode == screen->mode ) return; - switch(screen->mode) + /* close the old mode */ + if( mode_fn && mode_fn->close ) + mode_fn->close(); + + /* get functions for the new mode */ + switch(new_mode) { case SCREEN_PLAY_WINDOW: - play_close(screen, c); + mode_fn = get_screen_playlist(); break; case SCREEN_FILE_WINDOW: - file_close(screen, c); - break; - case SCREEN_SEARCH_WINDOW: - search_close(screen, c); + mode_fn = get_screen_file(); break; case SCREEN_HELP_WINDOW: - help_close(screen, c); + mode_fn = get_screen_help(); + break; +#ifdef ENABLE_KEYDEF_SCREEN + case SCREEN_KEYDEF_WINDOW: + mode_fn = get_screen_keydef(); + break; +#endif + default: break; } screen->mode = new_mode; screen->painted = 0; - switch(screen->mode) - { - case SCREEN_PLAY_WINDOW: - play_open(screen, c); - break; - case SCREEN_FILE_WINDOW: - file_open(screen, c); - break; - case SCREEN_SEARCH_WINDOW: - search_open(screen, c); - break; - case SCREEN_HELP_WINDOW: - help_open(screen, c); - break; - } + /* open the new mode */ + if( mode_fn && mode_fn->open ) + mode_fn->open(screen, c); + } static void @@ -249,9 +270,22 @@ screen_exit(void) endwin(); if( screen ) { - screen->playlist = list_window_free(screen->playlist); - screen->filelist = list_window_free(screen->filelist); - screen->helplist = list_window_free(screen->helplist); + GList *list = g_list_first(screen->screen_list); + + /* close and exit all screens (playlist,browse,help...) */ + while( list ) + { + screen_functions_t *mode_fn = list->data; + + if( mode_fn && mode_fn->close ) + mode_fn->close(); + if( mode_fn && mode_fn->exit ) + mode_fn->exit(); + list->data = NULL; + list=list->next; + } + g_list_free(screen->screen_list); + g_free(screen->buf); g_free(screen->findbuf); g_free(screen); @@ -301,6 +335,8 @@ screen_status_printf(char *format, ...) int screen_init(void) { + GList *list; + /* initialize the curses library */ initscr(); if( has_colors() ) @@ -371,15 +407,6 @@ screen_init(void) screen->main_window.cols, 2, 0); - screen->playlist = list_window_init( screen->main_window.w, - screen->main_window.cols, - screen->main_window.rows ); - screen->filelist = list_window_init( screen->main_window.w, - screen->main_window.cols, - screen->main_window.rows ); - screen->helplist = list_window_init( screen->main_window.w, - screen->main_window.cols, - screen->main_window.rows ); // leaveok(screen->main_window.w, TRUE); temporary disabled keypad(screen->main_window.w, TRUE); @@ -413,36 +440,57 @@ screen_init(void) wbkgd(screen->status_window.w, STATUS_COLORS); } + /* initialize screens */ + screen->screen_list = NULL; + screen->screen_list = g_list_append(screen->screen_list, + (gpointer) get_screen_playlist()); + screen->screen_list = g_list_append(screen->screen_list, + (gpointer) get_screen_file()); + screen->screen_list = g_list_append(screen->screen_list, + (gpointer) get_screen_help()); +#ifdef ENABLE_KEYDEF_SCREEN + screen->screen_list = g_list_append(screen->screen_list, + (gpointer) get_screen_keydef()); +#endif + + list = screen->screen_list; + while( list ) + { + screen_functions_t *fn = list->data; + + if( fn && fn->init ) + fn->init(screen->main_window.w, + screen->main_window.cols, + screen->main_window.rows); + + list = list->next; + } + + mode_fn = get_screen_playlist(); + return 0; } void screen_paint(mpd_client_t *c) { - switch(screen->mode) - { - case SCREEN_PLAY_WINDOW: - paint_top_window(TOP_HEADER_PLAY, c->status->volume, 1); - play_paint(screen, c); - break; - case SCREEN_FILE_WINDOW: - paint_top_window(file_get_header(c), c->status->volume, 1); - file_paint(screen, c); - break; - case SCREEN_SEARCH_WINDOW: - paint_top_window(TOP_HEADER_SEARCH, c->status->volume, 1); - search_paint(screen, c); - break; - case SCREEN_HELP_WINDOW: - paint_top_window(TOP_HEADER_PLAY, c->status->volume, 1); - help_paint(screen, c); - break; - } - + /* paint the title/header window */ + if( mode_fn && mode_fn->get_title ) + paint_top_window(mode_fn->get_title(), c->status->volume, 1); + else + paint_top_window("", c->status->volume, 1); + + /* paint the main window */ + if( mode_fn && mode_fn->paint ) + mode_fn->paint(screen, c); + paint_progress_window(c); paint_status_window(c); screen->painted = 1; - wmove(screen->main_window.w, 0, 0); wnoutrefresh(screen->main_window.w); + wmove(screen->main_window.w, 0, 0); + wnoutrefresh(screen->main_window.w); + + /* tell curses to update */ doupdate(); } @@ -451,15 +499,18 @@ screen_update(mpd_client_t *c) { static int repeat = -1; static int random = -1; + static int crossfade = -1; list_window_t *lw = NULL; if( !screen->painted ) return screen_paint(c); + /* print a message if mpd status has changed */ if( repeat<0 ) { repeat = c->status->repeat; random = c->status->random; + crossfade = c->status->crossfade; } if( repeat != c->status->repeat ) screen_status_printf("Repeat is %s", @@ -467,40 +518,43 @@ screen_update(mpd_client_t *c) if( random != c->status->random ) screen_status_printf("Random is %s", c->status->random ? "On" : "Off"); - + if( crossfade != c->status->crossfade ) + screen_status_printf("Crossfade %d seconds", c->status->crossfade); + repeat = c->status->repeat; random = c->status->random; + crossfade = c->status->crossfade; - switch(screen->mode) - { - case SCREEN_PLAY_WINDOW: - if( screen->last_cmd==CMD_NONE && - time(NULL)-screen->input_timestamp <= SCREEN_WELCOME_TIME) - paint_top_window("", c->status->volume, 0); - else - paint_top_window(TOP_HEADER_PLAY, c->status->volume, 0); - play_update(screen, c); - lw = screen->playlist; - break; - case SCREEN_FILE_WINDOW: - paint_top_window(file_get_header(c), c->status->volume, 0); - file_update(screen, c); - lw = screen->filelist; - break; - case SCREEN_SEARCH_WINDOW: - paint_top_window(TOP_HEADER_SEARCH, c->status->volume, 0); - search_update(screen, c); - break; - case SCREEN_HELP_WINDOW: - paint_top_window(TOP_HEADER_HELP, c->status->volume, 0); - help_update(screen, c); - lw = screen->helplist; - break; - } + /* update title/header window */ + if( screen->last_cmd==CMD_NONE && + time(NULL)-screen->input_timestamp <= SCREEN_WELCOME_TIME) + paint_top_window("", c->status->volume, 0); + else if( mode_fn && mode_fn->get_title ) + paint_top_window(mode_fn->get_title(), c->status->volume, 0); + else + paint_top_window("", c->status->volume, 0); + + /* update the main window */ + if( mode_fn && mode_fn->paint ) + mode_fn->update(screen, c); + + if( mode_fn && mode_fn->get_lw ) + lw = mode_fn->get_lw(); + + /* update progress window */ paint_progress_window(c); + + /* update status window */ paint_status_window(c); - wmove(screen->main_window.w, LW_ROW(lw), 0); + + /* move the cursor to the selected row in the main window */ + if( lw ) + wmove(screen->main_window.w, LW_ROW(lw), 0); + else + wmove(screen->main_window.w, 0, 0); wnoutrefresh(screen->main_window.w); + + /* tell curses to update */ doupdate(); } @@ -512,30 +566,14 @@ screen_cmd(mpd_client_t *c, command_t cmd) screen->input_timestamp = time(NULL); screen->last_cmd = cmd; - switch(screen->mode) - { - case SCREEN_PLAY_WINDOW: - if( play_cmd(screen, c, cmd) ) - return; - break; - case SCREEN_FILE_WINDOW: - if( file_cmd(screen, c, cmd) ) - return; - break; - case SCREEN_SEARCH_WINDOW: - if( search_cmd(screen, c, cmd) ) - return; - break; - case SCREEN_HELP_WINDOW: - if( help_cmd(screen, c, cmd) ) - return; - break; - } + + if( mode_fn && mode_fn->cmd && mode_fn->cmd(screen, c, cmd) ) + return; switch(cmd) { case CMD_PLAY: - mpd_sendPlayCommand(c->connection, screen->playlist->selected); + mpd_sendPlayCommand(c->connection, play_get_selected()); mpd_finishCommand(c->connection); break; case CMD_PAUSE: @@ -634,6 +672,11 @@ screen_cmd(mpd_client_t *c, command_t cmd) case CMD_SCREEN_HELP: switch_screen_mode(SCREEN_HELP_WINDOW, c); break; +#ifdef ENABLE_KEYDEF_SCREEN + case CMD_SCREEN_KEYDEF: + switch_screen_mode(SCREEN_KEYDEF_WINDOW, c); + break; +#endif case CMD_QUIT: exit(EXIT_SUCCESS); default: @@ -32,17 +32,17 @@ #define IS_PAUSED(s) (s==MPD_STATUS_STATE_PAUSE) #define IS_STOPPED(s) (!(IS_PLAYING(s) | IS_PAUSED(s))) + typedef enum { SCREEN_PLAY_WINDOW = 0, SCREEN_FILE_WINDOW, SCREEN_HELP_WINDOW, + SCREEN_KEYDEF_WINDOW, SCREEN_SEARCH_WINDOW } screen_mode_t; - - typedef struct { WINDOW *w; @@ -59,14 +59,12 @@ typedef struct window_t progress_window; window_t status_window; + GList *screen_list; + time_t status_timestamp; time_t input_timestamp; command_t last_cmd; - list_window_t *playlist; - list_window_t *filelist; - list_window_t *helplist; - int cols, rows; screen_mode_t mode; @@ -81,6 +79,30 @@ typedef struct } screen_t; +typedef void (*screen_init_fn_t) (WINDOW *w, int cols, int rows); +typedef void (*screen_exit_fn_t) (void); +typedef void (*screen_open_fn_t) (screen_t *screen, mpd_client_t *c); +typedef void (*screen_close_fn_t) (void); +typedef void (*screen_paint_fn_t) (screen_t *screen, mpd_client_t *c); +typedef void (*screen_update_fn_t) (screen_t *screen, mpd_client_t *c); +typedef int (*screen_cmd_fn_t) (screen_t *scr, mpd_client_t *c, command_t cmd); +typedef char * (*screen_title_fn_t) (void); +typedef list_window_t * (*screen_get_lw_fn_t) (void); + +typedef struct +{ + screen_init_fn_t init; + screen_exit_fn_t exit; + screen_open_fn_t open; + screen_close_fn_t close; + screen_paint_fn_t paint; + screen_update_fn_t update; + screen_cmd_fn_t cmd; + screen_title_fn_t get_title; + screen_get_lw_fn_t get_lw; + +} screen_functions_t; + int screen_init(void); int screen_exit(void); 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; +} + diff --git a/screen_file.h b/screen_file.h index 2d5ab5ef9..1a48fc706 100644 --- a/screen_file.h +++ b/screen_file.h @@ -1,14 +1,7 @@ -char *file_get_header(mpd_client_t *c); - void file_clear_highlight(mpd_client_t *c, mpd_Song *song); void file_clear_highlights(mpd_client_t *c); -void file_open(screen_t *screen, mpd_client_t *c); -void file_close(screen_t *screen, mpd_client_t *c); - -void file_paint(screen_t *screen, mpd_client_t *c); -void file_update(screen_t *screen, mpd_client_t *c); - -int file_cmd(screen_t *screen, mpd_client_t *c, command_t cmd); +list_window_t *get_filelist_window(void); +screen_functions_t *get_screen_file(void); diff --git a/screen_help.c b/screen_help.c index c0661a67f..c19049717 100644 --- a/screen_help.c +++ b/screen_help.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 <stdlib.h> #include <string.h> #include <glib.h> @@ -46,6 +64,9 @@ static help_text_row_t help_text[] = { 0, CMD_SCREEN_HELP, NULL }, { 0, CMD_SCREEN_PLAY, NULL }, { 0, CMD_SCREEN_FILE, NULL }, +#ifdef ENABLE_KEYDEF_SCREEN + { 0, CMD_SCREEN_KEYDEF, NULL }, +#endif { 0, CMD_QUIT, NULL }, { 0, CMD_NONE, NULL }, { 0, CMD_NONE, NULL }, @@ -75,7 +96,7 @@ static help_text_row_t help_text[] = }; static int help_text_rows = -1; - +static list_window_t *lw = NULL; static char * @@ -117,51 +138,80 @@ list_callback(int index, int *highlight, void *data) return NULL; } +static void +help_init(WINDOW *w, int cols, int rows) +{ + lw = list_window_init(w, cols, rows); +} -void -help_open(screen_t *screen, mpd_client_t *c) +static void +help_exit(void) { + list_window_free(lw); } -void -help_close(screen_t *screen, mpd_client_t *c) + +static char * +help_title(void) { + return (TOP_HEADER_PREFIX "Help"); } -void +static void help_paint(screen_t *screen, mpd_client_t *c) { - list_window_t *w = screen->helplist; - - w->clear = 1; - list_window_paint(screen->helplist, list_callback, NULL); - wrefresh(screen->helplist->w); + lw->clear = 1; + list_window_paint(lw, list_callback, NULL); + wrefresh(lw->w); } -void +static void help_update(screen_t *screen, mpd_client_t *c) { - list_window_t *w = screen->helplist; - - if( w->repaint ) + if( lw->repaint ) { - list_window_paint(screen->helplist, list_callback, NULL); - wrefresh(screen->helplist->w); - w->repaint = 0; + list_window_paint(lw, list_callback, NULL); + wrefresh(lw->w); + lw->repaint = 0; } } -int +static int help_cmd(screen_t *screen, mpd_client_t *c, command_t cmd) { int retval; - retval = list_window_cmd(screen->helplist, help_text_rows, cmd); + retval = list_window_cmd(lw, help_text_rows, cmd); if( !retval ) return screen_find(screen, c, - screen->helplist, help_text_rows, + lw, help_text_rows, cmd, list_callback); return retval; } + +static list_window_t * +help_lw(void) +{ + return lw; +} + +screen_functions_t * +get_screen_help(void) +{ + static screen_functions_t functions; + + memset(&functions, 0, sizeof(screen_functions_t)); + functions.init = help_init; + functions.exit = help_exit; + functions.open = NULL; + functions.close = NULL; + functions.paint = help_paint; + functions.update = help_update; + functions.cmd = help_cmd; + functions.get_lw = help_lw; + functions.get_title = help_title; + + return &functions; +} diff --git a/screen_help.h b/screen_help.h index b6434dd99..ba2c57c8e 100644 --- a/screen_help.h +++ b/screen_help.h @@ -1,9 +1,2 @@ -void help_open(screen_t *screen, mpd_client_t *c); -void help_close(screen_t *screen, mpd_client_t *c); - -void help_paint(screen_t *screen, mpd_client_t *c); -void help_update(screen_t *screen, mpd_client_t *c); - -int help_cmd(screen_t *screen, mpd_client_t *c, command_t cmd); - +screen_functions_t *get_screen_help(void); diff --git a/screen_play.c b/screen_play.c index 95c2899fe..5669d3641 100644 --- a/screen_play.c +++ b/screen_play.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 <stdlib.h> #include <string.h> #include <glib.h> @@ -16,6 +34,8 @@ #define BUFSIZE 256 +static list_window_t *lw = NULL; + static char * list_callback(int index, int *highlight, void *data) { @@ -39,7 +59,6 @@ list_callback(int index, int *highlight, void *data) static int center_playing_item(screen_t *screen, mpd_client_t *c) { - list_window_t *lw = screen->playlist; int length = c->playlist_length; int offset = lw->selected-lw->start; @@ -99,35 +118,43 @@ handle_save_playlist(screen_t *screen, mpd_client_t *c) /* update the file list if it has been initalized */ if( c->filelist ) { + list_window_t *file_lw = get_filelist_window(); + mpc_update_filelist(c); - list_window_check_selected(screen->filelist, c->filelist_length); + list_window_check_selected(file_lw, c->filelist_length); } return 0; } -void -play_open(screen_t *screen, mpd_client_t *c) + +static void +play_init(WINDOW *w, int cols, int rows) { + lw = list_window_init(w, cols, rows); +} +static void +play_exit(void) +{ + list_window_free(lw); } -void -play_close(screen_t *screen, mpd_client_t *c) +static char * +play_title(void) { + return (TOP_HEADER_PREFIX "Playlist"); } -void +static void play_paint(screen_t *screen, mpd_client_t *c) -{ - list_window_t *w = screen->playlist; - - w->clear = 1; +{ + lw->clear = 1; - list_window_paint(screen->playlist, list_callback, (void *) c); - wnoutrefresh(screen->playlist->w); + list_window_paint(lw, list_callback, (void *) c); + wnoutrefresh(lw->w); } -void +static void play_update(screen_t *screen, mpd_client_t *c) { if( options.auto_center ) @@ -143,23 +170,23 @@ play_update(screen_t *screen, mpd_client_t *c) if( c->playlist_updated ) { - if( screen->playlist->selected >= c->playlist_length ) - screen->playlist->selected = c->playlist_length-1; - if( screen->playlist->start >= c->playlist_length ) - list_window_reset(screen->playlist); + if( lw->selected >= c->playlist_length ) + lw->selected = c->playlist_length-1; + if( lw->start >= c->playlist_length ) + list_window_reset(lw); play_paint(screen, c); c->playlist_updated = 0; } - else if( screen->playlist->repaint || 1) + else if( lw->repaint || 1) { - list_window_paint(screen->playlist, list_callback, (void *) c); - wnoutrefresh(screen->playlist->w); - screen->playlist->repaint = 0; + list_window_paint(lw, list_callback, (void *) c); + wnoutrefresh(lw->w); + lw->repaint = 0; } } -int +static int play_cmd(screen_t *screen, mpd_client_t *c, command_t cmd) { mpd_Song *song; @@ -167,11 +194,11 @@ play_cmd(screen_t *screen, mpd_client_t *c, command_t cmd) switch(cmd) { case CMD_DELETE: - song = mpc_playlist_get_song(c, screen->playlist->selected); + song = mpc_playlist_get_song(c, lw->selected); if( song ) { file_clear_highlight(c, song); - mpd_sendDeleteCommand(c->connection, screen->playlist->selected); + mpd_sendDeleteCommand(c->connection, lw->selected); mpd_finishCommand(c->connection); if( !mpc_error(c) ) { @@ -192,10 +219,43 @@ play_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->playlist, c->playlist_length, + lw, c->playlist_length, cmd, list_callback); default: break; } - return list_window_cmd(screen->playlist, c->playlist_length, cmd) ; + return list_window_cmd(lw, c->playlist_length, cmd) ; +} + + + +static list_window_t * +play_lw(void) +{ + return lw; +} + +int +play_get_selected(void) +{ + return lw->selected; +} + +screen_functions_t * +get_screen_playlist(void) +{ + static screen_functions_t functions; + + memset(&functions, 0, sizeof(screen_functions_t)); + functions.init = play_init; + functions.exit = play_exit; + functions.open = NULL; + functions.close = NULL; + functions.paint = play_paint; + functions.update = play_update; + functions.cmd = play_cmd; + functions.get_lw = play_lw; + functions.get_title = play_title; + + return &functions; } diff --git a/screen_play.h b/screen_play.h index c88f4c73a..f7c101856 100644 --- a/screen_play.h +++ b/screen_play.h @@ -1,10 +1,5 @@ +int play_get_selected(void); -void play_open(screen_t *screen, mpd_client_t *c); -void play_close(screen_t *screen, mpd_client_t *c); - -void play_paint(screen_t *screen, mpd_client_t *c); -void play_update(screen_t *screen, mpd_client_t *c); - -int play_cmd(screen_t *screen, mpd_client_t *c, command_t cmd); +screen_functions_t *get_screen_playlist(void); diff --git a/screen_search.c b/screen_search.c index cb975a882..6b6719e30 100644 --- a/screen_search.c +++ b/screen_search.c @@ -10,28 +10,3 @@ #include "screen.h" #include "screen_search.h" -void -search_open(screen_t *screen, mpd_client_t *c) -{ -} - -void -search_close(screen_t *screen, mpd_client_t *c) -{ -} - -void -search_paint(screen_t *screen, mpd_client_t *c) -{ -} - -void -search_update(screen_t *screen, mpd_client_t *c) -{ -} - -int -search_cmd(screen_t *screen, mpd_client_t *c, command_t cmd) -{ - return 0; -} diff --git a/screen_search.h b/screen_search.h index b2b7f5124..e69de29bb 100644 --- a/screen_search.h +++ b/screen_search.h @@ -1,8 +0,0 @@ - -void search_open(screen_t *screen, mpd_client_t *c); -void search_close(screen_t *screen, mpd_client_t *c); - -void search_paint(screen_t *screen, mpd_client_t *c); -void search_update(screen_t *screen, mpd_client_t *c); - -int search_cmd(screen_t *screen, mpd_client_t *c, command_t cmd); |