1 #include <stdlib.h>
2 #include <string.h>
3 #include <glib.h>
4 #include <ncurses.h>
6 #include "libmpdclient.h"
7 #include "mpc.h"
8 #include "command.h"
9 #include "screen.h"
10 #include "screen_utils.h"
11 #include "screen_file.h"
12 #include "screen_play.h"
15 #define BUFSIZE 256
17 static char *
18 list_callback(int index, int *highlight, void *data)
19 {
20 mpd_client_t *c = (mpd_client_t *) data;
21 mpd_Song *song;
23 *highlight = 0;
24 if( (song=mpc_playlist_get_song(c, index)) == NULL )
25 {
26 return NULL;
27 }
29 if( IS_PLAYING(c->status->state) && index==c->song_id )
30 {
31 *highlight = 1;
32 }
34 return mpc_get_song_name(song);
35 }
37 void
38 play_open(screen_t *screen, mpd_client_t *c)
39 {
41 }
43 void
44 play_close(screen_t *screen, mpd_client_t *c)
45 {
46 }
48 void
49 play_paint(screen_t *screen, mpd_client_t *c)
50 {
51 list_window_t *w = screen->playlist;
53 w->clear = 1;
55 list_window_paint(screen->playlist, list_callback, (void *) c);
56 wrefresh(screen->playlist->w);
57 }
59 void
60 play_update(screen_t *screen, mpd_client_t *c)
61 {
62 if( c->playlist_updated )
63 {
64 if( screen->playlist->selected >= c->playlist_length )
65 screen->playlist->selected = c->playlist_length-1;
66 if( screen->playlist->start >= c->playlist_length )
67 list_window_reset(screen->playlist);
69 play_paint(screen, c);
70 c->playlist_updated = 0;
71 }
72 else if( screen->playlist->repaint || 1)
73 {
74 list_window_paint(screen->playlist, list_callback, (void *) c);
75 wrefresh(screen->playlist->w);
76 screen->playlist->repaint = 0;
77 }
78 }
80 int
81 play_cmd(screen_t *screen, mpd_client_t *c, command_t cmd)
82 {
83 mpd_Song *song;
85 switch(cmd)
86 {
87 case CMD_DELETE:
88 song = mpc_playlist_get_song(c, screen->playlist->selected);
89 file_clear_highlight(c, song);
90 mpd_sendDeleteCommand(c->connection, screen->playlist->selected);
91 mpd_finishCommand(c->connection);
92 screen_status_printf("Removed \'%s\' from playlist!",
93 mpc_get_song_name(song));
94 return 1;
95 case CMD_LIST_FIND:
96 if( screen->findbuf )
97 {
98 free(screen->findbuf);
99 screen->findbuf=NULL;
100 }
101 /* continue... */
102 case CMD_LIST_FIND_NEXT:
103 if( !screen->findbuf )
104 screen->findbuf=screen_readln(screen->status_window.w, "/");
105 if( list_window_find(screen->playlist,
106 list_callback,
107 c,
108 screen->findbuf) == 0 )
109 {
110 screen->playlist->repaint = 1;
111 }
112 else
113 {
114 screen_status_printf("Unable to find \'%s\'", screen->findbuf);
115 beep();
116 }
117 return 1;
118 default:
119 break;
120 }
121 return list_window_cmd(screen->playlist, c->playlist_length, cmd) ;
122 }