1 /*****************************************************************************
2 * ncurses.c : NCurses plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2001-2004 VideoLAN
7 * Authors: Sam Hocevar <sam@zoy.org>
8 * Laurent Aimar <fenrir@via.ecp.fr>
9 * Yoann Peronneau <yoann@videolan.org>
10 * Derk-Jan Hartman <hartman at videolan dot org>
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
25 *****************************************************************************/
27 /*****************************************************************************
29 *****************************************************************************/
30 #include <stdlib.h> /* malloc(), free() */
32 #include <errno.h> /* ENOMEM */
44 #define CDDA_MRL "cddax://"
46 #define CDDA_MRL "cdda://"
50 #define VCD_MRL "vcdx://"
52 #define VCD_MRL "vcdx://"
55 #define SEARCH_CHAIN_SIZE 20
56 #define OPEN_CHAIN_SIZE 50
58 /*****************************************************************************
60 *****************************************************************************/
61 static int Open ( vlc_object_t * );
62 static void Close ( vlc_object_t * );
64 static void Run ( intf_thread_t * );
65 static void PlayPause ( intf_thread_t * );
66 static void Eject ( intf_thread_t * );
68 static int HandleKey ( intf_thread_t *, int );
69 static void Redraw ( intf_thread_t *, time_t * );
70 static void SearchPlaylist ( intf_thread_t *, char * );
71 static void ManageSlider ( intf_thread_t * );
73 /*****************************************************************************
75 *****************************************************************************/
77 set_description( _("ncurses interface") );
78 set_capability( "interface", 10 );
79 set_callbacks( Open, Close );
80 add_shortcut( "curses" );
83 /*****************************************************************************
84 * intf_sys_t: description and status of ncurses interface
85 *****************************************************************************/
98 playlist_t *p_playlist;
99 input_thread_t *p_input;
109 int i_box_lines_total;
112 int i_box_plidx; /* Playlist index */
113 int b_box_plidx_follow;
117 msg_subscription_t* p_sub; /* message bank subscription */
119 char *psz_search_chain; /* for playlist searching */
120 char *psz_old_search; /* for searching next */
123 char *psz_open_chain;
126 static void DrawBox( WINDOW *win, int y, int x, int h, int w, char *title );
127 static void DrawLine( WINDOW *win, int y, int x, int w );
128 static void DrawEmptyLine( WINDOW *win, int y, int x, int w );
130 /*****************************************************************************
131 * Open: initialize and create window
132 *****************************************************************************/
133 static int Open( vlc_object_t *p_this )
135 intf_thread_t *p_intf = (intf_thread_t *)p_this;
139 /* Allocate instance and initialize some members */
140 p_sys = p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
141 p_sys->p_playlist = NULL;
142 p_sys->p_input = NULL;
143 p_sys->f_slider = 0.0;
144 p_sys->f_slider_old = 0.0;
145 p_sys->i_box_type = BOX_PLAYLIST;
146 p_sys->i_box_lines = 0;
147 p_sys->i_box_start= 0;
148 p_sys->i_box_lines_total = 0;
149 p_sys->b_box_plidx_follow = VLC_TRUE;
150 p_sys->b_box_cleared = VLC_FALSE;
151 p_sys->i_box_plidx = 0;
152 p_sys->p_sub = msg_Subscribe( p_intf );
154 /* Initialize the curses library */
155 p_sys->w = initscr();
156 keypad( p_sys->w, TRUE );
157 /* Don't do NL -> CR/NL */
159 /* Take input chars one at a time */
169 /* exported function */
170 p_intf->pf_run = Run;
174 var_Set( p_intf->p_vlc, "verbose", val );
176 /* Initialize search chain */
177 p_sys->psz_search_chain = (char *)malloc( SEARCH_CHAIN_SIZE + 1 );
178 p_sys->psz_old_search = NULL;
179 p_sys->i_before_search = 0;
181 /* Initialize open chain */
182 p_sys->psz_open_chain = (char *)malloc( OPEN_CHAIN_SIZE + 1 );
187 /*****************************************************************************
188 * Close: destroy interface window
189 *****************************************************************************/
190 static void Close( vlc_object_t *p_this )
192 intf_thread_t *p_intf = (intf_thread_t *)p_this;
193 intf_sys_t *p_sys = p_intf->p_sys;
195 if( p_sys->psz_search_chain ) free( p_sys->psz_search_chain );
196 if( p_sys->psz_old_search ) free( p_sys->psz_old_search );
197 if( p_sys->psz_open_chain ) free( p_sys->psz_open_chain );
201 vlc_object_release( p_sys->p_input );
203 if( p_sys->p_playlist )
205 vlc_object_release( p_sys->p_playlist );
208 /* Close the ncurses interface */
211 msg_Unsubscribe( p_intf, p_sys->p_sub );
213 /* Destroy structure */
217 /*****************************************************************************
218 * Run: ncurses thread
219 *****************************************************************************/
220 static void Run( intf_thread_t *p_intf )
222 intf_sys_t *p_sys = p_intf->p_sys;
225 time_t t_last_refresh;
228 * force drawing the interface for the first time
230 t_last_refresh = ( time( 0 ) - 1);
232 while( !p_intf->b_die )
234 msleep( INTF_IDLE_SLEEP );
236 /* Update the input */
237 if( p_sys->p_playlist == NULL )
239 p_sys->p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
241 if( p_sys->p_playlist )
243 vlc_mutex_lock( &p_sys->p_playlist->object_lock );
244 if( p_sys->p_input == NULL )
246 p_sys->p_input = p_sys->p_playlist->p_input;
249 if( !p_sys->p_input->b_dead )
251 vlc_object_yield( p_sys->p_input );
255 else if( p_sys->p_input->b_dead )
257 vlc_object_release( p_sys->p_input );
258 p_sys->p_input = NULL;
259 p_sys->f_slider = p_sys->f_slider_old = 0.0;
260 p_sys->b_box_cleared = VLC_FALSE;
262 vlc_mutex_unlock( &p_sys->p_playlist->object_lock );
265 if( p_sys->b_box_plidx_follow && p_sys->p_playlist->i_index >= 0 )
267 p_sys->i_box_plidx = p_sys->p_playlist->i_index;
271 while( ( i_key = getch()) != -1 )
274 * HandleKey returns 1 if the screen needs to be redrawn
276 if ( HandleKey( p_intf, i_key ) )
278 Redraw( p_intf, &t_last_refresh );
282 if( p_sys->f_slider > 0.0001 && !p_sys->b_box_cleared )
285 Redraw( p_intf, &t_last_refresh );
286 p_sys->b_box_cleared = VLC_TRUE;
290 * redraw the screen every second
292 if ( (time(0) - t_last_refresh) >= 1 )
294 ManageSlider ( p_intf );
295 Redraw( p_intf, &t_last_refresh );
300 /* following functions are local */
302 static int HandleKey( intf_thread_t *p_intf, int i_key )
304 intf_sys_t *p_sys = p_intf->p_sys;
307 if( p_sys->i_box_type == BOX_PLAYLIST && p_sys->p_playlist )
309 int b_ret = VLC_TRUE;
314 /* Playlist Settings */
316 var_Get( p_sys->p_playlist, "random", &val );
317 val.b_bool = !val.b_bool;
318 var_Set( p_sys->p_playlist, "random", val );
321 var_Get( p_sys->p_playlist, "loop", &val );
322 val.b_bool = !val.b_bool;
323 var_Set( p_sys->p_playlist, "loop", val );
326 var_Get( p_sys->p_playlist, "repeat", &val );
327 val.b_bool = !val.b_bool;
328 var_Set( p_sys->p_playlist, "repeat", val );
333 playlist_Sort( p_sys->p_playlist, SORT_TITLE, ORDER_NORMAL );
336 playlist_Sort( p_sys->p_playlist, SORT_TITLE, ORDER_REVERSE );
339 /* Playlist navigation */
341 p_sys->i_box_plidx = 0;
344 p_sys->i_box_plidx = p_sys->p_playlist->i_size - 1;
347 p_sys->i_box_plidx--;
350 p_sys->i_box_plidx++;
353 p_sys->i_box_plidx -= p_sys->i_box_lines;
356 p_sys->i_box_plidx += p_sys->i_box_lines;
362 int i_item = p_sys->p_playlist->i_index;
364 playlist_Delete( p_sys->p_playlist, p_sys->i_box_plidx );
365 if( i_item < p_sys->p_playlist->i_size && i_item != p_sys->p_playlist->i_index )
367 playlist_Goto( p_sys->p_playlist, i_item );
374 playlist_Goto( p_sys->p_playlist, p_sys->i_box_plidx );
383 if( p_sys->i_box_plidx >= p_sys->p_playlist->i_size ) p_sys->i_box_plidx = p_sys->p_playlist->i_size - 1;
384 if( p_sys->i_box_plidx < 0 ) p_sys->i_box_plidx = 0;
385 if( p_sys->i_box_plidx == p_sys->p_playlist->i_index )
386 p_sys->b_box_plidx_follow = VLC_TRUE;
388 p_sys->b_box_plidx_follow = VLC_FALSE;
392 else if( p_sys->i_box_type == BOX_HELP || p_sys->i_box_type == BOX_INFO )
397 p_sys->i_box_start = 0;
400 p_sys->i_box_start = p_sys->i_box_lines_total - 1;
403 if( p_sys->i_box_start > 0 ) p_sys->i_box_start--;
406 if( p_sys->i_box_start < p_sys->i_box_lines_total - 1 )
408 p_sys->i_box_start++;
412 p_sys->i_box_start -= p_sys->i_box_lines;
413 if( p_sys->i_box_start < 0 ) p_sys->i_box_start = 0;
416 p_sys->i_box_start += p_sys->i_box_lines;
417 if( p_sys->i_box_start >= p_sys->i_box_lines_total )
419 p_sys->i_box_start = p_sys->i_box_lines_total - 1;
426 else if( p_sys->i_box_type == BOX_NONE )
432 ManageSlider ( p_intf );
435 p_sys->f_slider = 99.9;
436 ManageSlider ( p_intf );
439 p_sys->f_slider += 5.0;
440 if( p_sys->f_slider >= 99.0 ) p_sys->f_slider = 99.0;
441 ManageSlider ( p_intf );
444 p_sys->f_slider -= 5.0;
445 if( p_sys->f_slider < 0.0 ) p_sys->f_slider = 0.0;
446 ManageSlider ( p_intf );
453 else if( p_sys->i_box_type == BOX_SEARCH && p_sys->psz_search_chain )
456 i_chain_len = strlen( p_sys->psz_search_chain );
464 if( i_chain_len > 0 )
466 p_sys->psz_old_search = strdup( p_sys->psz_search_chain );
468 else if( p_sys->psz_old_search )
470 SearchPlaylist( p_intf, p_sys->psz_old_search );
472 p_sys->i_box_type = BOX_PLAYLIST;
474 case 0x1b: /* Esc. */
475 p_sys->i_box_plidx = p_sys->i_before_search;
476 p_sys->i_box_type = BOX_PLAYLIST;
479 if( i_chain_len > 0 )
481 p_sys->psz_search_chain[ i_chain_len - 1 ] = '\0';
485 if( i_chain_len < SEARCH_CHAIN_SIZE )
487 p_sys->psz_search_chain[ i_chain_len++ ] = i_key;
488 p_sys->psz_search_chain[ i_chain_len ] = 0;
492 if( p_sys->psz_old_search )
494 free( p_sys->psz_old_search );
495 p_sys->psz_old_search = NULL;
497 SearchPlaylist( p_intf, p_sys->psz_search_chain );
500 else if( p_sys->i_box_type == BOX_OPEN && p_sys->psz_open_chain )
503 i_chain_len = strlen( p_sys->psz_open_chain );
504 playlist_t *p_playlist = p_sys->p_playlist;
513 if( p_playlist && i_chain_len > 0 )
515 playlist_Add( p_playlist, p_sys->psz_open_chain,
516 p_sys->psz_open_chain,
517 PLAYLIST_GO|PLAYLIST_APPEND, PLAYLIST_END );
518 p_sys->b_box_plidx_follow = VLC_TRUE;
520 p_sys->i_box_type = BOX_PLAYLIST;
522 case 0x1b: /* Esc. */
523 p_sys->i_box_type = BOX_PLAYLIST;
526 if( i_chain_len > 0 )
528 p_sys->psz_open_chain[ i_chain_len - 1 ] = '\0';
532 if( i_chain_len < OPEN_CHAIN_SIZE )
534 p_sys->psz_open_chain[ i_chain_len++ ] = i_key;
535 p_sys->psz_open_chain[ i_chain_len ] = 0;
549 p_intf->p_vlc->b_die = VLC_TRUE;
554 if( p_sys->i_box_type == BOX_INFO )
555 p_sys->i_box_type = BOX_NONE;
557 p_sys->i_box_type = BOX_INFO;
558 p_sys->i_box_lines_total = 0;
561 if( p_sys->i_box_type == BOX_LOG )
562 p_sys->i_box_type = BOX_NONE;
564 p_sys->i_box_type = BOX_LOG;
567 if( p_sys->i_box_type == BOX_PLAYLIST )
568 p_sys->i_box_type = BOX_NONE;
570 p_sys->i_box_type = BOX_PLAYLIST;
574 if( p_sys->i_box_type == BOX_HELP )
575 p_sys->i_box_type = BOX_NONE;
577 p_sys->i_box_type = BOX_HELP;
578 p_sys->i_box_lines_total = 0;
581 if( p_sys->i_box_type != BOX_SEARCH )
583 if( p_sys->psz_search_chain == NULL )
587 p_sys->psz_search_chain[0] = '\0';
588 p_sys->b_box_plidx_follow = VLC_FALSE;
589 p_sys->i_before_search = p_sys->i_box_plidx;
590 p_sys->i_box_type = BOX_SEARCH;
594 if( p_sys->i_box_type != BOX_OPEN )
596 if( p_sys->psz_open_chain == NULL )
600 p_sys->psz_open_chain[0] = '\0';
601 p_sys->i_box_type = BOX_OPEN;
607 p_sys->f_slider += 1.0;
608 if( p_sys->f_slider > 99.9 ) p_sys->f_slider = 99.9;
609 ManageSlider ( p_intf );
613 p_sys->f_slider -= 1.0;
614 if( p_sys->f_slider < 0.0 ) p_sys->f_slider = 0.0;
615 ManageSlider ( p_intf );
621 vout_thread_t *p_vout;
622 if( p_intf->p_sys->p_input )
624 p_vout = vlc_object_find( p_intf->p_sys->p_input,
625 VLC_OBJECT_VOUT, FIND_CHILD );
628 p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
629 vlc_object_release( p_vout );
640 if( p_intf->p_sys->p_playlist )
642 playlist_Stop( p_intf->p_sys->p_playlist );
653 val.b_bool = VLC_TRUE;
654 var_Set( p_sys->p_input, "prev-title", val );
661 val.b_bool = VLC_TRUE;
662 var_Set( p_sys->p_input, "next-title", val );
669 val.b_bool = VLC_TRUE;
670 var_Set( p_sys->p_input, "prev-chapter", val );
677 val.b_bool = VLC_TRUE;
678 var_Set( p_sys->p_input, "next-chapter", val );
683 if( p_intf->p_sys->p_playlist )
685 playlist_Prev( p_intf->p_sys->p_playlist );
691 if( p_intf->p_sys->p_playlist )
693 playlist_Next( p_intf->p_sys->p_playlist );
699 aout_VolumeUp( p_intf, 1, NULL );
704 aout_VolumeDown( p_intf, 1, NULL );
709 * ^l should clear and redraw the screen
720 static void ManageSlider ( intf_thread_t *p_intf )
722 intf_sys_t *p_sys = p_intf->p_sys;
723 input_thread_t *p_input = p_sys->p_input;
726 if( p_input == NULL )
730 var_Get( p_input, "state", &val );
731 if( val.i_int != PLAYING_S )
736 var_Get( p_input, "position", &val );
737 if( p_sys->f_slider == p_sys->f_slider_old )
740 p_sys->f_slider_old = 100 * val.f_float;
744 p_sys->f_slider_old = p_sys->f_slider;
746 val.f_float = p_sys->f_slider / 100.0;
747 var_Set( p_input, "position", val );
751 static void SearchPlaylist( intf_thread_t *p_intf, char *psz_searchstring )
757 intf_sys_t *p_sys = p_intf->p_sys;
758 playlist_t *p_playlist = p_sys->p_playlist;
760 if( p_sys->i_before_search >= 0 )
761 i_first = p_sys->i_before_search;
763 if( ( ! psz_searchstring ) || strlen( psz_searchstring ) <= 0 )
765 p_sys->i_box_plidx = p_sys->i_before_search;
769 for( i_current = i_first + 1; i_current < p_playlist->i_size;
772 if( strcasestr( p_playlist->pp_items[i_current]->input.psz_name,
773 psz_searchstring ) != NULL
774 || strcasestr( p_playlist->pp_items[i_current]->input.psz_uri,
775 psz_searchstring ) != NULL )
784 for( i_current = 0; i_current < i_first; i_current++ )
786 if( strcasestr( p_playlist->pp_items[i_current]->input.psz_name,
787 psz_searchstring ) != NULL
788 || strcasestr( p_playlist->pp_items[i_current]->input.psz_uri,
789 psz_searchstring ) != NULL )
798 if( i_item < 0 || i_item >= p_playlist->i_size ) return;
800 p_sys->i_box_plidx = i_item;
804 static void mvnprintw( int y, int x, int w, const char *p_fmt, ... )
810 va_start ( vl_args, p_fmt );
811 vasprintf ( &p_buf, p_fmt, vl_args );
820 if( ( i_len = strlen( p_buf ) ) > w )
822 int i_cut = i_len - w;
823 int x1 = i_len/2 - i_cut/2;
828 memmove( &p_buf[x1], &p_buf[x2], i_len - x2 );
837 mvprintw( y, x, "%s", p_buf );
841 mvprintw( y, x, "%s", p_buf );
842 mvhline( y, x + i_len, ' ', w - i_len );
846 static void MainBoxWrite( intf_thread_t *p_intf, int l, int x, const char *p_fmt, ... )
848 intf_sys_t *p_sys = p_intf->p_sys;
853 if( l < p_sys->i_box_start || l - p_sys->i_box_start >= p_sys->i_box_lines )
858 va_start ( vl_args, p_fmt );
859 vasprintf ( &p_buf, p_fmt, vl_args );
867 mvnprintw( p_sys->i_box_y + l - p_sys->i_box_start, x, COLS - x - 1, "%s", p_buf );
870 static void Redraw ( intf_thread_t *p_intf, time_t *t_last_refresh )
872 intf_sys_t *p_sys = p_intf->p_sys;
873 input_thread_t *p_input = p_sys->p_input;
881 attrset ( A_REVERSE );
882 mvnprintw( y, 0, COLS, "VLC media player" " (ncurses interface) [ h for help ]" );
883 attroff ( A_REVERSE );
887 if( p_input && !p_input->b_dead )
889 char buf1[MSTRTIME_MAX_SIZE];
890 char buf2[MSTRTIME_MAX_SIZE];
892 vlc_value_t val_list;
895 mvnprintw( y++, 0, COLS, " Source : %s", p_input->psz_source );
898 var_Get( p_input, "state", &val );
899 if( val.i_int == PLAYING_S )
901 mvnprintw( y++, 0, COLS, " State : Playing" );
903 else if( val.i_int == PAUSE_S )
905 mvnprintw( y++, 0, COLS, " State : Paused" );
911 if( val.i_int != INIT_S && val.i_int != END_S )
913 audio_volume_t i_volume;
916 var_Get( p_input, "time", &val );
917 msecstotimestr( buf1, val.i_time / 1000 );
919 var_Get( p_input, "length", &val );
920 msecstotimestr( buf2, val.i_time / 1000 );
922 mvnprintw( y++, 0, COLS, " Position : %s/%s (%.2f%%)", buf1, buf2, p_sys->f_slider );
925 aout_VolumeGet( p_intf, &i_volume );
926 mvnprintw( y++, 0, COLS, " Volume : %i%%", i_volume*200/AOUT_VOLUME_MAX );
929 if( !var_Get( p_input, "title", &val ) )
931 var_Change( p_input, "title", VLC_VAR_GETCHOICES, &val_list, NULL );
932 if( val_list.p_list->i_count > 0 )
934 mvnprintw( y++, 0, COLS, " Title : %d/%d", val.i_int, val_list.p_list->i_count );
936 var_Change( p_input, "title", VLC_VAR_FREELIST, &val_list, NULL );
940 if( !var_Get( p_input, "chapter", &val ) )
942 var_Change( p_input, "chapter", VLC_VAR_GETCHOICES, &val_list, NULL );
943 if( val_list.p_list->i_count > 0 )
945 mvnprintw( y++, 0, COLS, " Chapter : %d/%d", val.i_int, val_list.p_list->i_count );
947 var_Change( p_input, "chapter", VLC_VAR_FREELIST, &val_list, NULL );
957 mvnprintw( y++, 0, COLS, "Source: <no current item>" );
958 DrawEmptyLine( p_sys->w, y++, 0, COLS );
959 DrawEmptyLine( p_sys->w, y++, 0, COLS );
960 DrawEmptyLine( p_sys->w, y++, 0, COLS );
963 DrawBox( p_sys->w, y, 0, 3, COLS, "" );
964 DrawEmptyLine( p_sys->w, y+1, 1, COLS-2);
965 DrawLine( p_sys->w, y+1, 1, (int)(p_intf->p_sys->f_slider/100.0 * (COLS -2)) );
968 p_sys->i_box_y = y + 1;
969 p_sys->i_box_lines = LINES - y - 2;
974 if( p_sys->i_box_type == BOX_HELP )
978 DrawBox( p_sys->w, y++, 0, h, COLS, " Help " );
980 MainBoxWrite( p_intf, l++, 1, "[Display]" );
981 MainBoxWrite( p_intf, l++, 1, " h,H Show/Hide help box" );
982 MainBoxWrite( p_intf, l++, 1, " i Show/Hide info box" );
983 MainBoxWrite( p_intf, l++, 1, " l Show/Hide messages box" );
984 MainBoxWrite( p_intf, l++, 1, " P Show/Hide playlist box" );
985 MainBoxWrite( p_intf, l++, 1, "" );
987 MainBoxWrite( p_intf, l++, 1, "[Global]" );
988 MainBoxWrite( p_intf, l++, 1, " q, Q Quit" );
989 MainBoxWrite( p_intf, l++, 1, " s Stop" );
990 MainBoxWrite( p_intf, l++, 1, " <space> Pause/Play" );
991 MainBoxWrite( p_intf, l++, 1, " f Toggle Fullscreen" );
992 MainBoxWrite( p_intf, l++, 1, " n, p Next/Previous playlist item" );
993 MainBoxWrite( p_intf, l++, 1, " [, ] Next/Previous title" );
994 MainBoxWrite( p_intf, l++, 1, " <, > Next/Previous chapter" );
995 MainBoxWrite( p_intf, l++, 1, " <right> Seek +1%%" );
996 MainBoxWrite( p_intf, l++, 1, " <left> Seek -1%%" );
997 MainBoxWrite( p_intf, l++, 1, " a Volume Up" );
998 MainBoxWrite( p_intf, l++, 1, " z Volume Down" );
999 MainBoxWrite( p_intf, l++, 1, "" );
1001 MainBoxWrite( p_intf, l++, 1, "[Playlist]" );
1002 MainBoxWrite( p_intf, l++, 1, " r Random" );
1003 MainBoxWrite( p_intf, l++, 1, " l Loop Playlist" );
1004 MainBoxWrite( p_intf, l++, 1, " R Repeat item" );
1005 MainBoxWrite( p_intf, l++, 1, " o Order Playlist by title" );
1006 MainBoxWrite( p_intf, l++, 1, " O Reverse order Playlist by title" );
1007 MainBoxWrite( p_intf, l++, 1, " / Look for an item" );
1008 MainBoxWrite( p_intf, l++, 1, " A Add an entry" );
1009 MainBoxWrite( p_intf, l++, 1, " D, <del> Delete an entry" );
1010 MainBoxWrite( p_intf, l++, 1, " <backspace> Delete an entry" );
1011 MainBoxWrite( p_intf, l++, 1, "" );
1013 MainBoxWrite( p_intf, l++, 1, "[Boxes]" );
1014 MainBoxWrite( p_intf, l++, 1, " <up>,<down> Navigate through the box line by line" );
1015 MainBoxWrite( p_intf, l++, 1, " <pgup>,<pgdown> Navigate through the box page by page" );
1016 MainBoxWrite( p_intf, l++, 1, "" );
1018 MainBoxWrite( p_intf, l++, 1, "[Player]" );
1019 MainBoxWrite( p_intf, l++, 1, " <up>,<down> Seek +/-5%%" );
1020 MainBoxWrite( p_intf, l++, 1, "" );
1022 MainBoxWrite( p_intf, l++, 1, "[Miscellaneous]" );
1023 MainBoxWrite( p_intf, l++, 1, " Ctrl-l Refresh the screen" );
1025 p_sys->i_box_lines_total = l;
1026 if( p_sys->i_box_start >= p_sys->i_box_lines_total )
1028 p_sys->i_box_start = p_sys->i_box_lines_total - 1;
1031 if( l - p_sys->i_box_start < p_sys->i_box_lines )
1033 y += l - p_sys->i_box_start;
1037 y += p_sys->i_box_lines;
1040 else if( p_sys->i_box_type == BOX_INFO )
1044 DrawBox( p_sys->w, y++, 0, h, COLS, " Information " );
1049 vlc_mutex_lock( &p_input->p_item->lock );
1050 for ( i = 0; i < p_input->p_item->i_categories; i++ )
1052 info_category_t *p_category = p_input->p_item->pp_categories[i];
1053 if( y >= y_end ) break;
1054 MainBoxWrite( p_intf, l++, 1, " [%s]", p_category->psz_name );
1055 for ( j = 0; j < p_category->i_infos; j++ )
1057 info_t *p_info = p_category->pp_infos[j];
1058 if( y >= y_end ) break;
1059 MainBoxWrite( p_intf, l++, 1, " %s: %s", p_info->psz_name, p_info->psz_value );
1062 vlc_mutex_unlock( &p_input->p_item->lock );
1066 MainBoxWrite( p_intf, l++, 1, "No item currently playing" );
1068 p_sys->i_box_lines_total = l;
1069 if( p_sys->i_box_start >= p_sys->i_box_lines_total )
1071 p_sys->i_box_start = p_sys->i_box_lines_total - 1;
1074 if( l - p_sys->i_box_start < p_sys->i_box_lines )
1076 y += l - p_sys->i_box_start;
1080 y += p_sys->i_box_lines;
1083 else if( p_sys->i_box_type == BOX_LOG )
1089 DrawBox( p_sys->w, y++, 0, h, COLS, " Logs " );
1091 i_start = p_intf->p_sys->p_sub->i_start;
1093 vlc_mutex_lock( p_intf->p_sys->p_sub->p_lock );
1094 i_stop = *p_intf->p_sys->p_sub->pi_stop;
1095 vlc_mutex_unlock( p_intf->p_sys->p_sub->p_lock );
1099 static const char *ppsz_type[4] = { "", "error", "warning", "debug" };
1100 if( i_line >= h - 2 )
1106 if( i_stop < 0 ) i_stop += VLC_MSG_QSIZE;
1107 if( i_stop == i_start )
1111 mvnprintw( y + h-2-i_line, 1, COLS - 2, " [%s] %s",
1112 ppsz_type[p_sys->p_sub->p_msg[i_stop].i_type],
1113 p_sys->p_sub->p_msg[i_stop].psz_msg );
1116 vlc_mutex_lock( p_intf->p_sys->p_sub->p_lock );
1117 p_intf->p_sys->p_sub->i_start = i_stop;
1118 vlc_mutex_unlock( p_intf->p_sys->p_sub->p_lock );
1121 else if( ( p_sys->i_box_type == BOX_PLAYLIST ||
1122 p_sys->i_box_type == BOX_SEARCH ||
1123 p_sys->i_box_type == BOX_OPEN ) && p_sys->p_playlist )
1126 playlist_t *p_playlist = p_sys->p_playlist;
1127 int i_start, i_stop;
1129 DrawBox( p_sys->w, y++, 0, h, COLS, " Playlist " );
1131 if( p_sys->i_box_plidx >= p_playlist->i_size ) p_sys->i_box_plidx = p_playlist->i_size - 1;
1132 if( p_sys->i_box_plidx < 0 ) p_sys->i_box_plidx = 0;
1134 if( p_sys->i_box_plidx < (h - 2)/2 )
1139 else if( p_playlist->i_size - p_sys->i_box_plidx > (h - 2)/2 )
1141 i_start = p_sys->i_box_plidx - (h - 2)/2;
1142 i_stop = i_start + h - 2;
1146 i_stop = p_playlist->i_size;
1147 i_start = p_playlist->i_size - (h - 2);
1153 if( i_stop > p_playlist->i_size )
1155 i_stop = p_playlist->i_size;
1158 for( i_item = i_start; i_item < i_stop; i_item++ )
1160 vlc_bool_t b_selected = ( p_sys->i_box_plidx == i_item );
1161 int c = p_playlist->i_index == i_item ? '>' : ' ';
1163 if( y >= y_end ) break;
1166 attrset( A_REVERSE );
1168 if( !strcmp( p_playlist->pp_items[i_item]->input.psz_name,
1169 p_playlist->pp_items[i_item]->input.psz_uri ) )
1171 mvnprintw( y++, 1, COLS - 2, "%c %d - '%s'",
1174 p_playlist->pp_items[i_item]->input.psz_uri );
1178 mvnprintw( y++, 1, COLS - 2, "%c %d - '%s' (%s)",
1181 p_playlist->pp_items[i_item]->input.psz_uri,
1182 p_playlist->pp_items[i_item]->input.psz_name );
1186 attroff ( A_REVERSE );
1194 if( p_sys->i_box_type == BOX_SEARCH )
1196 DrawEmptyLine( p_sys->w, 7, 1, COLS-2 );
1197 if( p_sys->psz_search_chain )
1199 if( strlen( p_sys->psz_search_chain ) == 0 &&
1200 p_sys->psz_old_search != NULL )
1202 /* Searching next entry */
1203 mvnprintw( 7, 1, COLS-2, "Find: %s", p_sys->psz_old_search );
1207 mvnprintw( 7, 1, COLS-2, "Find: %s", p_sys->psz_search_chain );
1211 if( p_sys->i_box_type == BOX_OPEN )
1213 if( p_sys->psz_open_chain )
1215 DrawEmptyLine( p_sys->w, 7, 1, COLS-2 );
1216 mvnprintw( 7, 1, COLS-2, "Open: %s", p_sys->psz_open_chain );
1222 DrawEmptyLine( p_sys->w, y++, 1, COLS - 2 );
1227 *t_last_refresh = time( 0 );
1230 static void Eject ( intf_thread_t *p_intf )
1232 char *psz_device = NULL, *psz_parser, *psz_name;
1235 * Get the active input
1236 * Determine whether we can eject a media, ie it's a DVD, VCD or CD-DA
1237 * If it's neither of these, then return
1240 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1243 if( p_playlist == NULL )
1248 vlc_mutex_lock( &p_playlist->object_lock );
1250 if( p_playlist->i_index < 0 )
1252 vlc_mutex_unlock( &p_playlist->object_lock );
1253 vlc_object_release( p_playlist );
1257 psz_name = p_playlist->pp_items[ p_playlist->i_index ]->input.psz_name;
1261 if( !strncmp(psz_name, "dvd://", 4) )
1263 switch( psz_name[strlen("dvd://")] )
1267 psz_device = config_GetPsz( p_intf, "dvd" );
1270 /* Omit the first MRL-selector characters */
1271 psz_device = strdup( psz_name + strlen("dvd://" ) );
1275 else if( !strncmp(psz_name, VCD_MRL, strlen(VCD_MRL)) )
1277 switch( psz_name[strlen(VCD_MRL)] )
1281 psz_device = config_GetPsz( p_intf, VCD_MRL );
1284 /* Omit the beginning MRL-selector characters */
1285 psz_device = strdup( psz_name + strlen(VCD_MRL) );
1289 else if( !strncmp(psz_name, CDDA_MRL, strlen(CDDA_MRL) ) )
1291 switch( psz_name[strlen(CDDA_MRL)] )
1295 psz_device = config_GetPsz( p_intf, "cd-audio" );
1298 /* Omit the beginning MRL-selector characters */
1299 psz_device = strdup( psz_name + strlen(CDDA_MRL) );
1305 psz_device = strdup( psz_name );
1309 vlc_mutex_unlock( &p_playlist->object_lock );
1310 vlc_object_release( p_playlist );
1312 if( psz_device == NULL )
1317 /* Remove what we have after @ */
1318 psz_parser = psz_device;
1319 for( psz_parser = psz_device ; *psz_parser ; psz_parser++ )
1321 if( *psz_parser == '@' )
1328 /* If there's a stream playing, we aren't allowed to eject ! */
1329 if( p_intf->p_sys->p_input == NULL )
1331 msg_Dbg( p_intf, "ejecting %s", psz_device );
1333 intf_Eject( p_intf, psz_device );
1340 static void PlayPause ( intf_thread_t *p_intf )
1342 input_thread_t *p_input = p_intf->p_sys->p_input;
1347 var_Get( p_input, "state", &val );
1348 if( val.i_int != PAUSE_S )
1350 val.i_int = PAUSE_S;
1354 val.i_int = PLAYING_S;
1356 var_Set( p_input, "state", val );
1358 else if( p_intf->p_sys->p_playlist )
1360 playlist_Play( p_intf->p_sys->p_playlist );
1364 /****************************************************************************
1366 ****************************************************************************/
1367 static void DrawBox( WINDOW *win, int y, int x, int h, int w, char *title )
1372 if( w > 3 && h > 2 )
1374 if( title == NULL ) title = "";
1375 i_len = strlen( title );
1377 if( i_len > w - 2 ) i_len = w - 2;
1379 mvwaddch( win, y, x, ACS_ULCORNER );
1380 mvwhline( win, y, x+1, ACS_HLINE, ( w-i_len-2)/2 );
1381 mvwprintw( win,y, x+1+(w-i_len-2)/2, "%s", title );
1382 mvwhline( win, y, x+(w-i_len)/2+i_len, ACS_HLINE, w - 1 - ((w-i_len)/2+i_len) );
1383 mvwaddch( win, y, x+w-1,ACS_URCORNER );
1385 for( i = 0; i < h-2; i++ )
1387 mvwaddch( win, y+i+1, x, ACS_VLINE );
1388 mvwaddch( win, y+i+1, x+w-1, ACS_VLINE );
1391 mvwaddch( win, y+h-1, x, ACS_LLCORNER );
1392 mvwhline( win, y+h-1, x+1, ACS_HLINE, w - 2 );
1393 mvwaddch( win, y+h-1, x+w-1, ACS_LRCORNER );
1397 static void DrawEmptyLine( WINDOW *win, int y, int x, int w )
1401 mvhline( y, x, ' ', w );
1405 static void DrawLine( WINDOW *win, int y, int x, int w )
1409 attrset( A_REVERSE );
1410 mvhline( y, x, ' ', w );
1411 attroff ( A_REVERSE );