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 wnoutrefresh(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 wnoutrefresh(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_SAVE_PLAYLIST:
96 screen_status_printf("Sorry, playlist saving not implemented yet!");
97 return 1;
98 case CMD_LIST_FIND:
99 case CMD_LIST_RFIND:
100 case CMD_LIST_FIND_NEXT:
101 case CMD_LIST_RFIND_NEXT:
102 return screen_find(screen, c,
103 screen->playlist, c->playlist_length,
104 cmd, list_callback);
105 default:
106 break;
107 }
108 return list_window_cmd(screen->playlist, c->playlist_length, cmd) ;
109 }