Code

Imported ncmpc (mpc-ncures).
[ncmpc.git] / screen_play.c
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;
56  
57   w->clear = 1;
58   
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   char buf[256];
88   mpd_Song *song;
90   switch(cmd)
91     {
92     case CMD_DELETE:
93       song = mpc_playlist_get_song(c, screen->playlist->selected);
94       file_clear_highlight(c, song);
95       mpd_sendDeleteCommand(c->connection, screen->playlist->selected);
96       mpd_finishCommand(c->connection);
97       snprintf(buf, 256,
98                "Removed \'%s\' from playlist!",
99                mpc_get_song_name(song));               
100       screen_status_message(c, buf);
101       break;
102     case CMD_LIST_PREVIOUS:
103       list_window_previous(screen->playlist);
104       screen->playlist->repaint=1;
105       break;
106     case CMD_LIST_NEXT:
107       list_window_next(screen->playlist, c->playlist_length);
108       screen->playlist->repaint=1;
109       break;
110     case CMD_LIST_FIRST:
111       list_window_first(screen->playlist);
112       screen->playlist->repaint  = 1;
113       break;
114     case CMD_LIST_LAST:
115       list_window_last(screen->playlist, c->playlist_length);
116       screen->playlist->repaint  = 1;
117     case CMD_LIST_NEXT_PAGE:
118       list_window_next_page(screen->playlist, c->playlist_length);
119       screen->playlist->repaint  = 1;
120       break;
121     case CMD_LIST_PREVIOUS_PAGE:
122       list_window_previous_page(screen->playlist);
123       screen->playlist->repaint  = 1;
124       break;
125     default:
126       return 0;
127     }
128   return 1;