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 );
962 DrawBox( p_sys->w, y, 0, 3, COLS, "" );
963 DrawEmptyLine( p_sys->w, y+1, 1, COLS-2);
964 DrawLine( p_sys->w, y+1, 1, (int)(p_intf->p_sys->f_slider/100.0 * (COLS -2)) );
967 p_sys->i_box_y = y + 1;
968 p_sys->i_box_lines = LINES - y - 2;
973 if( p_sys->i_box_type == BOX_HELP )
977 DrawBox( p_sys->w, y++, 0, h, COLS, " Help " );
979 MainBoxWrite( p_intf, l++, 1, "[Display]" );
980 MainBoxWrite( p_intf, l++, 1, " h,H Show/Hide help box" );
981 MainBoxWrite( p_intf, l++, 1, " i Show/Hide info box" );
982 MainBoxWrite( p_intf, l++, 1, " l Show/Hide messages box" );
983 MainBoxWrite( p_intf, l++, 1, " P Show/Hide playlist box" );
984 MainBoxWrite( p_intf, l++, 1, "" );
986 MainBoxWrite( p_intf, l++, 1, "[Global]" );
987 MainBoxWrite( p_intf, l++, 1, " q, Q Quit" );
988 MainBoxWrite( p_intf, l++, 1, " s Stop" );
989 MainBoxWrite( p_intf, l++, 1, " <space> Pause/Play" );
990 MainBoxWrite( p_intf, l++, 1, " f Toggle Fullscreen" );
991 MainBoxWrite( p_intf, l++, 1, " n, p Next/Previous playlist item" );
992 MainBoxWrite( p_intf, l++, 1, " [, ] Next/Previous title" );
993 MainBoxWrite( p_intf, l++, 1, " <, > Next/Previous chapter" );
994 MainBoxWrite( p_intf, l++, 1, " <right> Seek +1%%" );
995 MainBoxWrite( p_intf, l++, 1, " <left> Seek -1%%" );
996 MainBoxWrite( p_intf, l++, 1, " a Volume Up" );
997 MainBoxWrite( p_intf, l++, 1, " z Volume Down" );
998 MainBoxWrite( p_intf, l++, 1, "" );
1000 MainBoxWrite( p_intf, l++, 1, "[Playlist]" );
1001 MainBoxWrite( p_intf, l++, 1, " r Random" );
1002 MainBoxWrite( p_intf, l++, 1, " l Loop Playlist" );
1003 MainBoxWrite( p_intf, l++, 1, " R Repeat item" );
1004 MainBoxWrite( p_intf, l++, 1, " o Order Playlist by title" );
1005 MainBoxWrite( p_intf, l++, 1, " O Reverse order Playlist by title" );
1006 MainBoxWrite( p_intf, l++, 1, " / Look for an item" );
1007 MainBoxWrite( p_intf, l++, 1, " A Add an entry" );
1008 MainBoxWrite( p_intf, l++, 1, " D, <del> Delete an entry" );
1009 MainBoxWrite( p_intf, l++, 1, " <backspace> Delete an entry" );
1010 MainBoxWrite( p_intf, l++, 1, "" );
1012 MainBoxWrite( p_intf, l++, 1, "[Boxes]" );
1013 MainBoxWrite( p_intf, l++, 1, " <up>,<down> Navigate through the box line by line" );
1014 MainBoxWrite( p_intf, l++, 1, " <pgup>,<pgdown> Navigate through the box page by page" );
1015 MainBoxWrite( p_intf, l++, 1, "" );
1017 MainBoxWrite( p_intf, l++, 1, "[Player]" );
1018 MainBoxWrite( p_intf, l++, 1, " <up>,<down> Seek +/-5%%" );
1019 MainBoxWrite( p_intf, l++, 1, "" );
1021 MainBoxWrite( p_intf, l++, 1, "[Miscellaneous]" );
1022 MainBoxWrite( p_intf, l++, 1, " Ctrl-l Refresh the screen" );
1024 p_sys->i_box_lines_total = l;
1025 if( p_sys->i_box_start >= p_sys->i_box_lines_total )
1027 p_sys->i_box_start = p_sys->i_box_lines_total - 1;
1030 if( l - p_sys->i_box_start < p_sys->i_box_lines )
1032 y += l - p_sys->i_box_start;
1036 y += p_sys->i_box_lines;
1039 else if( p_sys->i_box_type == BOX_INFO )
1043 DrawBox( p_sys->w, y++, 0, h, COLS, " Information " );
1048 vlc_mutex_lock( &p_input->p_item->lock );
1049 for ( i = 0; i < p_input->p_item->i_categories; i++ )
1051 info_category_t *p_category = p_input->p_item->pp_categories[i];
1052 if( y >= y_end ) break;
1053 MainBoxWrite( p_intf, l++, 1, " [%s]", p_category->psz_name );
1054 for ( j = 0; j < p_category->i_infos; j++ )
1056 info_t *p_info = p_category->pp_infos[j];
1057 if( y >= y_end ) break;
1058 MainBoxWrite( p_intf, l++, 1, " %s: %s", p_info->psz_name, p_info->psz_value );
1061 vlc_mutex_unlock( &p_input->p_item->lock );
1065 MainBoxWrite( p_intf, l++, 1, "No item currently playing" );
1067 p_sys->i_box_lines_total = l;
1068 if( p_sys->i_box_start >= p_sys->i_box_lines_total )
1070 p_sys->i_box_start = p_sys->i_box_lines_total - 1;
1073 if( l - p_sys->i_box_start < p_sys->i_box_lines )
1075 y += l - p_sys->i_box_start;
1079 y += p_sys->i_box_lines;
1082 else if( p_sys->i_box_type == BOX_LOG )
1088 DrawBox( p_sys->w, y++, 0, h, COLS, " Logs " );
1090 i_start = p_intf->p_sys->p_sub->i_start;
1092 vlc_mutex_lock( p_intf->p_sys->p_sub->p_lock );
1093 i_stop = *p_intf->p_sys->p_sub->pi_stop;
1094 vlc_mutex_unlock( p_intf->p_sys->p_sub->p_lock );
1098 static const char *ppsz_type[4] = { "", "error", "warning", "debug" };
1099 if( i_line >= h - 2 )
1105 if( i_stop < 0 ) i_stop += VLC_MSG_QSIZE;
1106 if( i_stop == i_start )
1110 mvnprintw( y + h-2-i_line, 1, COLS - 2, " [%s] %s",
1111 ppsz_type[p_sys->p_sub->p_msg[i_stop].i_type],
1112 p_sys->p_sub->p_msg[i_stop].psz_msg );
1115 vlc_mutex_lock( p_intf->p_sys->p_sub->p_lock );
1116 p_intf->p_sys->p_sub->i_start = i_stop;
1117 vlc_mutex_unlock( p_intf->p_sys->p_sub->p_lock );
1120 else if( ( p_sys->i_box_type == BOX_PLAYLIST ||
1121 p_sys->i_box_type == BOX_SEARCH ||
1122 p_sys->i_box_type == BOX_OPEN ) && p_sys->p_playlist )
1125 playlist_t *p_playlist = p_sys->p_playlist;
1126 int i_start, i_stop;
1128 DrawBox( p_sys->w, y++, 0, h, COLS, " Playlist " );
1130 if( p_sys->i_box_plidx >= p_playlist->i_size ) p_sys->i_box_plidx = p_playlist->i_size - 1;
1131 if( p_sys->i_box_plidx < 0 ) p_sys->i_box_plidx = 0;
1133 if( p_sys->i_box_plidx < (h - 2)/2 )
1138 else if( p_playlist->i_size - p_sys->i_box_plidx > (h - 2)/2 )
1140 i_start = p_sys->i_box_plidx - (h - 2)/2;
1141 i_stop = i_start + h - 2;
1145 i_stop = p_playlist->i_size;
1146 i_start = p_playlist->i_size - (h - 2);
1152 if( i_stop > p_playlist->i_size )
1154 i_stop = p_playlist->i_size;
1157 for( i_item = i_start; i_item < i_stop; i_item++ )
1159 vlc_bool_t b_selected = ( p_sys->i_box_plidx == i_item );
1160 int c = p_playlist->i_index == i_item ? '>' : ' ';
1162 if( y >= y_end ) break;
1165 attrset( A_REVERSE );
1167 if( !strcmp( p_playlist->pp_items[i_item]->input.psz_name,
1168 p_playlist->pp_items[i_item]->input.psz_uri ) )
1170 mvnprintw( y++, 1, COLS - 2, "%c %d - '%s'",
1173 p_playlist->pp_items[i_item]->input.psz_uri );
1177 mvnprintw( y++, 1, COLS - 2, "%c %d - '%s' (%s)",
1180 p_playlist->pp_items[i_item]->input.psz_uri,
1181 p_playlist->pp_items[i_item]->input.psz_name );
1185 attroff ( A_REVERSE );
1193 if( p_sys->i_box_type == BOX_SEARCH )
1195 DrawEmptyLine( p_sys->w, 6, 1, COLS-2 );
1196 if( p_sys->psz_search_chain )
1198 if( strlen( p_sys->psz_search_chain ) == 0 &&
1199 p_sys->psz_old_search != NULL )
1201 /* Searching next entry */
1202 mvnprintw( 6, 1, COLS-2, "Find: %s", p_sys->psz_old_search );
1206 mvnprintw( 6, 1, COLS-2, "Find: %s", p_sys->psz_search_chain );
1210 if( p_sys->i_box_type == BOX_OPEN )
1212 DrawEmptyLine( p_sys->w, 6, 1, COLS-2 );
1213 if( p_sys->psz_open_chain )
1215 mvnprintw( 6, 1, COLS-2, "Open: %s", p_sys->psz_open_chain );
1221 DrawEmptyLine( p_sys->w, y++, 1, COLS - 2 );
1226 *t_last_refresh = time( 0 );
1229 static void Eject ( intf_thread_t *p_intf )
1231 char *psz_device = NULL, *psz_parser, *psz_name;
1234 * Get the active input
1235 * Determine whether we can eject a media, ie it's a DVD, VCD or CD-DA
1236 * If it's neither of these, then return
1239 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1242 if( p_playlist == NULL )
1247 vlc_mutex_lock( &p_playlist->object_lock );
1249 if( p_playlist->i_index < 0 )
1251 vlc_mutex_unlock( &p_playlist->object_lock );
1252 vlc_object_release( p_playlist );
1256 psz_name = p_playlist->pp_items[ p_playlist->i_index ]->input.psz_name;
1260 if( !strncmp(psz_name, "dvd://", 4) )
1262 switch( psz_name[strlen("dvd://")] )
1266 psz_device = config_GetPsz( p_intf, "dvd" );
1269 /* Omit the first MRL-selector characters */
1270 psz_device = strdup( psz_name + strlen("dvd://" ) );
1274 else if( !strncmp(psz_name, VCD_MRL, strlen(VCD_MRL)) )
1276 switch( psz_name[strlen(VCD_MRL)] )
1280 psz_device = config_GetPsz( p_intf, VCD_MRL );
1283 /* Omit the beginning MRL-selector characters */
1284 psz_device = strdup( psz_name + strlen(VCD_MRL) );
1288 else if( !strncmp(psz_name, CDDA_MRL, strlen(CDDA_MRL) ) )
1290 switch( psz_name[strlen(CDDA_MRL)] )
1294 psz_device = config_GetPsz( p_intf, "cd-audio" );
1297 /* Omit the beginning MRL-selector characters */
1298 psz_device = strdup( psz_name + strlen(CDDA_MRL) );
1304 psz_device = strdup( psz_name );
1308 vlc_mutex_unlock( &p_playlist->object_lock );
1309 vlc_object_release( p_playlist );
1311 if( psz_device == NULL )
1316 /* Remove what we have after @ */
1317 psz_parser = psz_device;
1318 for( psz_parser = psz_device ; *psz_parser ; psz_parser++ )
1320 if( *psz_parser == '@' )
1327 /* If there's a stream playing, we aren't allowed to eject ! */
1328 if( p_intf->p_sys->p_input == NULL )
1330 msg_Dbg( p_intf, "ejecting %s", psz_device );
1332 intf_Eject( p_intf, psz_device );
1339 static void PlayPause ( intf_thread_t *p_intf )
1341 input_thread_t *p_input = p_intf->p_sys->p_input;
1346 var_Get( p_input, "state", &val );
1347 if( val.i_int != PAUSE_S )
1349 val.i_int = PAUSE_S;
1353 val.i_int = PLAYING_S;
1355 var_Set( p_input, "state", val );
1357 else if( p_intf->p_sys->p_playlist )
1359 playlist_Play( p_intf->p_sys->p_playlist );
1363 /****************************************************************************
1365 ****************************************************************************/
1366 static void DrawBox( WINDOW *win, int y, int x, int h, int w, char *title )
1371 if( w > 3 && h > 2 )
1373 if( title == NULL ) title = "";
1374 i_len = strlen( title );
1376 if( i_len > w - 2 ) i_len = w - 2;
1378 mvwaddch( win, y, x, ACS_ULCORNER );
1379 mvwhline( win, y, x+1, ACS_HLINE, ( w-i_len-2)/2 );
1380 mvwprintw( win,y, x+1+(w-i_len-2)/2, "%s", title );
1381 mvwhline( win, y, x+(w-i_len)/2+i_len, ACS_HLINE, w - 1 - ((w-i_len)/2+i_len) );
1382 mvwaddch( win, y, x+w-1,ACS_URCORNER );
1384 for( i = 0; i < h-2; i++ )
1386 mvwaddch( win, y+i+1, x, ACS_VLINE );
1387 mvwaddch( win, y+i+1, x+w-1, ACS_VLINE );
1390 mvwaddch( win, y+h-1, x, ACS_LLCORNER );
1391 mvwhline( win, y+h-1, x+1, ACS_HLINE, w - 2 );
1392 mvwaddch( win, y+h-1, x+w-1, ACS_LRCORNER );
1396 static void DrawEmptyLine( WINDOW *win, int y, int x, int w )
1400 mvhline( y, x, ' ', w );
1404 static void DrawLine( WINDOW *win, int y, int x, int w )
1408 attrset( A_REVERSE );
1409 mvhline( y, x, ' ', w );
1410 attroff ( A_REVERSE );