1 /*
2 * $Id: screen_play.c,v 1.6 2004/03/17 14:49:31 kalle Exp $
3 *
4 */
6 #include <stdlib.h>
7 #include <string.h>
8 #include <glib.h>
9 #include <ncurses.h>
11 #include "libmpdclient.h"
12 #include "mpc.h"
13 #include "command.h"
14 #include "screen.h"
15 #include "screen_file.h"
16 #include "screen_play.h"
19 #define BUFSIZE 256
21 static char *
22 list_callback(int index, int *highlight, void *data)
23 {
24 mpd_client_t *c = (mpd_client_t *) data;
25 mpd_Song *song;
27 *highlight = 0;
28 if( (song=mpc_playlist_get_song(c, index)) == NULL )
29 {
30 return NULL;
31 }
33 if( IS_PLAYING(c->status->state) && index==c->song_id )
34 {
35 *highlight = 1;
36 }
38 return mpc_get_song_name(song);
39 }
41 void
42 play_open(screen_t *screen, mpd_client_t *c)
43 {
45 }
47 void
48 play_close(screen_t *screen, mpd_client_t *c)
49 {
50 }
52 void
53 play_paint(screen_t *screen, mpd_client_t *c)
54 {
55 list_window_t *w = screen->playlist;
57 w->clear = 1;
59 list_window_paint(screen->playlist, list_callback, (void *) c);
60 wrefresh(screen->playlist->w);
61 }
63 void
64 play_update(screen_t *screen, mpd_client_t *c)
65 {
66 if( c->playlist_updated )
67 {
68 if( screen->playlist->selected >= c->playlist_length )
69 screen->playlist->selected = c->playlist_length-1;
70 if( screen->playlist->start >= c->playlist_length )
71 list_window_reset(screen->playlist);
73 play_paint(screen, c);
74 c->playlist_updated = 0;
75 }
76 else if( screen->playlist->repaint || 1)
77 {
78 list_window_paint(screen->playlist, list_callback, (void *) c);
79 wrefresh(screen->playlist->w);
80 screen->playlist->repaint = 0;
81 }
82 }
84 int
85 play_cmd(screen_t *screen, mpd_client_t *c, command_t cmd)
86 {
87 mpd_Song *song;
89 switch(cmd)
90 {
91 case CMD_DELETE:
92 song = mpc_playlist_get_song(c, screen->playlist->selected);
93 file_clear_highlight(c, song);
94 mpd_sendDeleteCommand(c->connection, screen->playlist->selected);
95 mpd_finishCommand(c->connection);
96 screen_status_printf("Removed \'%s\' from playlist!",
97 mpc_get_song_name(song));
98 break;
99 case CMD_LIST_PREVIOUS:
100 list_window_previous(screen->playlist);
101 screen->playlist->repaint=1;
102 break;
103 case CMD_LIST_NEXT:
104 list_window_next(screen->playlist, c->playlist_length);
105 screen->playlist->repaint=1;
106 break;
107 case CMD_LIST_FIRST:
108 list_window_first(screen->playlist);
109 screen->playlist->repaint = 1;
110 break;
111 case CMD_LIST_LAST:
112 list_window_last(screen->playlist, c->playlist_length);
113 screen->playlist->repaint = 1;
114 case CMD_LIST_NEXT_PAGE:
115 list_window_next_page(screen->playlist, c->playlist_length);
116 screen->playlist->repaint = 1;
117 break;
118 case CMD_LIST_PREVIOUS_PAGE:
119 list_window_previous_page(screen->playlist);
120 screen->playlist->repaint = 1;
121 break;
122 case CMD_LIST_FIND:
123 if( screen->findbuf )
124 {
125 free(screen->findbuf);
126 screen->findbuf=NULL;
127 }
128 /* fall throw... */
129 case CMD_LIST_FIND_NEXT:
130 if( !screen->findbuf )
131 screen->findbuf=screen_readln(screen->status_window.w, "/");
132 if( list_window_find(screen->playlist,
133 list_callback,
134 c,
135 screen->findbuf) == 0 )
136 {
137 screen->playlist->repaint = 1;
138 }
139 else
140 {
141 screen_status_printf("Unable to find \'%s\'", screen->findbuf);
142 beep();
143 }
144 break;
145 default:
146 return 0;
147 }
148 return 1;
149 }