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>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
23 *****************************************************************************/
25 /*****************************************************************************
27 *****************************************************************************/
28 #include <stdlib.h> /* malloc(), free() */
30 #include <errno.h> /* ENOMEM */
41 #define CDDA_MRL "cddax://"
43 #define CDDA_MRL "cdda://"
47 #define VCD_MRL "vcdx://"
49 #define VCD_MRL "vcdx://"
52 #define SEARCH_CHAIN_SIZE 20
53 #define OPEN_CHAIN_SIZE 50
55 /*****************************************************************************
57 *****************************************************************************/
58 static int Open ( vlc_object_t * );
59 static void Close ( vlc_object_t * );
61 static void Run ( intf_thread_t * );
62 static void PlayPause ( intf_thread_t * );
63 static void Eject ( intf_thread_t * );
65 static int HandleKey ( intf_thread_t *, int );
66 static void Redraw ( intf_thread_t *, time_t * );
67 static void SearchPlaylist ( intf_thread_t *, char * );
68 static void ManageSlider ( intf_thread_t * );
70 /*****************************************************************************
72 *****************************************************************************/
74 set_description( _("ncurses interface") );
75 set_capability( "interface", 10 );
76 set_callbacks( Open, Close );
77 add_shortcut( "curses" );
80 /*****************************************************************************
81 * intf_sys_t: description and status of ncurses interface
82 *****************************************************************************/
95 playlist_t *p_playlist;
96 input_thread_t *p_input;
106 int i_box_lines_total;
109 int i_box_plidx; /* Playlist index */
110 int b_box_plidx_follow;
114 msg_subscription_t* p_sub; /* message bank subscription */
116 char *psz_search_chain; /* for playlist searching */
117 char *psz_old_search; /* for searching next */
120 char *psz_open_chain;
123 static void DrawBox( WINDOW *win, int y, int x, int h, int w, char *title );
124 static void DrawLine( WINDOW *win, int y, int x, int w );
125 static void DrawEmptyLine( WINDOW *win, int y, int x, int w );
127 /*****************************************************************************
128 * Open: initialize and create window
129 *****************************************************************************/
130 static int Open( vlc_object_t *p_this )
132 intf_thread_t *p_intf = (intf_thread_t *)p_this;
136 /* Allocate instance and initialize some members */
137 p_sys = p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
138 p_sys->p_playlist = NULL;
139 p_sys->p_input = NULL;
140 p_sys->f_slider = 0.0;
141 p_sys->f_slider_old = 0.0;
142 p_sys->i_box_type = BOX_PLAYLIST;
143 p_sys->i_box_lines = 0;
144 p_sys->i_box_start= 0;
145 p_sys->i_box_lines_total = 0;
146 p_sys->b_box_plidx_follow = VLC_TRUE;
147 p_sys->b_box_cleared = VLC_FALSE;
148 p_sys->i_box_plidx = 0;
149 p_sys->p_sub = msg_Subscribe( p_intf );
151 /* Initialize the curses library */
152 p_sys->w = initscr();
153 keypad( p_sys->w, TRUE );
154 /* Don't do NL -> CR/NL */
156 /* Take input chars one at a time */
166 /* exported function */
167 p_intf->pf_run = Run;
171 var_Set( p_intf->p_vlc, "verbose", val );
173 /* Initialize search chain */
174 p_sys->psz_search_chain = (char *)malloc( SEARCH_CHAIN_SIZE + 1 );
175 p_sys->psz_old_search = NULL;
176 p_sys->i_before_search = 0;
178 /* Initialize open chain */
179 p_sys->psz_open_chain = (char *)malloc( OPEN_CHAIN_SIZE + 1 );
184 /*****************************************************************************
185 * Close: destroy interface window
186 *****************************************************************************/
187 static void Close( vlc_object_t *p_this )
189 intf_thread_t *p_intf = (intf_thread_t *)p_this;
190 intf_sys_t *p_sys = p_intf->p_sys;
192 if( p_sys->psz_search_chain ) free( p_sys->psz_search_chain );
193 if( p_sys->psz_old_search ) free( p_sys->psz_old_search );
194 if( p_sys->psz_open_chain ) free( p_sys->psz_open_chain );
198 vlc_object_release( p_sys->p_input );
200 if( p_sys->p_playlist )
202 vlc_object_release( p_sys->p_playlist );
205 /* Close the ncurses interface */
208 msg_Unsubscribe( p_intf, p_sys->p_sub );
210 /* Destroy structure */
214 /*****************************************************************************
215 * Run: ncurses thread
216 *****************************************************************************/
217 static void Run( intf_thread_t *p_intf )
219 intf_sys_t *p_sys = p_intf->p_sys;
222 time_t t_last_refresh;
225 * force drawing the interface for the first time
227 t_last_refresh = ( time( 0 ) - 1);
229 while( !p_intf->b_die )
231 msleep( INTF_IDLE_SLEEP );
233 /* Update the input */
234 if( p_sys->p_playlist == NULL )
236 p_sys->p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
238 if( p_sys->p_playlist )
240 vlc_mutex_lock( &p_sys->p_playlist->object_lock );
241 if( p_sys->p_input == NULL )
243 p_sys->p_input = p_sys->p_playlist->p_input;
246 if( !p_sys->p_input->b_dead )
248 vlc_object_yield( p_sys->p_input );
252 else if( p_sys->p_input->b_dead )
254 vlc_object_release( p_sys->p_input );
255 p_sys->p_input = NULL;
256 p_sys->f_slider = p_sys->f_slider_old = 0.0;
257 p_sys->b_box_cleared = VLC_FALSE;
259 vlc_mutex_unlock( &p_sys->p_playlist->object_lock );
262 if( p_sys->b_box_plidx_follow && p_sys->p_playlist->i_index >= 0 )
264 p_sys->i_box_plidx = p_sys->p_playlist->i_index;
268 while( ( i_key = getch()) != -1 )
271 * HandleKey returns 1 if the screen needs to be redrawn
273 if ( HandleKey( p_intf, i_key ) )
275 Redraw( p_intf, &t_last_refresh );
279 if( p_sys->f_slider > 0.0001 && !p_sys->b_box_cleared )
282 Redraw( p_intf, &t_last_refresh );
283 p_sys->b_box_cleared = VLC_TRUE;
287 * redraw the screen every second
289 if ( (time(0) - t_last_refresh) >= 1 )
291 ManageSlider ( p_intf );
292 Redraw( p_intf, &t_last_refresh );
297 /* following functions are local */
299 static int HandleKey( intf_thread_t *p_intf, int i_key )
301 intf_sys_t *p_sys = p_intf->p_sys;
304 if( p_sys->i_box_type == BOX_PLAYLIST && p_sys->p_playlist )
306 int b_ret = VLC_TRUE;
312 playlist_Sort( p_sys->p_playlist, SORT_RANDOM, ORDER_NORMAL );
315 playlist_Sort( p_sys->p_playlist, SORT_TITLE, ORDER_NORMAL );
318 playlist_Sort( p_sys->p_playlist, SORT_TITLE, ORDER_REVERSE );
321 /* Playlist navigation */
323 p_sys->i_box_plidx = 0;
326 p_sys->i_box_plidx = p_sys->p_playlist->i_size - 1;
329 p_sys->i_box_plidx--;
332 p_sys->i_box_plidx++;
335 p_sys->i_box_plidx -= p_sys->i_box_lines;
338 p_sys->i_box_plidx += p_sys->i_box_lines;
343 int i_item = p_sys->p_playlist->i_index;
345 playlist_Delete( p_sys->p_playlist, p_sys->i_box_plidx );
346 if( i_item < p_sys->p_playlist->i_size && i_item != p_sys->p_playlist->i_index )
348 playlist_Goto( p_sys->p_playlist, i_item );
355 playlist_Goto( p_sys->p_playlist, p_sys->i_box_plidx );
364 if( p_sys->i_box_plidx >= p_sys->p_playlist->i_size ) p_sys->i_box_plidx = p_sys->p_playlist->i_size - 1;
365 if( p_sys->i_box_plidx < 0 ) p_sys->i_box_plidx = 0;
366 if( p_sys->i_box_plidx == p_sys->p_playlist->i_index )
367 p_sys->b_box_plidx_follow = VLC_TRUE;
369 p_sys->b_box_plidx_follow = VLC_FALSE;
373 else if( p_sys->i_box_type == BOX_HELP || p_sys->i_box_type == BOX_INFO )
378 p_sys->i_box_start = 0;
381 p_sys->i_box_start = p_sys->i_box_lines_total - 1;
384 if( p_sys->i_box_start > 0 ) p_sys->i_box_start--;
387 if( p_sys->i_box_start < p_sys->i_box_lines_total - 1 )
389 p_sys->i_box_start++;
393 p_sys->i_box_start -= p_sys->i_box_lines;
394 if( p_sys->i_box_start < 0 ) p_sys->i_box_start = 0;
397 p_sys->i_box_start += p_sys->i_box_lines;
398 if( p_sys->i_box_start >= p_sys->i_box_lines_total )
400 p_sys->i_box_start = p_sys->i_box_lines_total - 1;
407 else if( p_sys->i_box_type == BOX_NONE )
413 ManageSlider ( p_intf );
416 p_sys->f_slider = 99.9;
417 ManageSlider ( p_intf );
420 p_sys->f_slider += 5.0;
421 if( p_sys->f_slider >= 99.0 ) p_sys->f_slider = 99.0;
422 ManageSlider ( p_intf );
425 p_sys->f_slider -= 5.0;
426 if( p_sys->f_slider < 0.0 ) p_sys->f_slider = 0.0;
427 ManageSlider ( p_intf );
434 else if( p_sys->i_box_type == BOX_SEARCH && p_sys->psz_search_chain )
437 i_chain_len = strlen( p_sys->psz_search_chain );
445 if( i_chain_len > 0 )
447 p_sys->psz_old_search = strdup( p_sys->psz_search_chain );
449 else if( p_sys->psz_old_search )
451 SearchPlaylist( p_intf, p_sys->psz_old_search );
453 p_sys->i_box_type = BOX_PLAYLIST;
455 case 0x1b: /* Esc. */
456 p_sys->i_box_plidx = p_sys->i_before_search;
457 p_sys->i_box_type = BOX_PLAYLIST;
460 if( i_chain_len > 0 )
462 p_sys->psz_search_chain[ i_chain_len - 1 ] = '\0';
466 if( i_chain_len < SEARCH_CHAIN_SIZE )
468 p_sys->psz_search_chain[ i_chain_len++ ] = i_key;
469 p_sys->psz_search_chain[ i_chain_len ] = 0;
473 if( p_sys->psz_old_search )
475 free( p_sys->psz_old_search );
476 p_sys->psz_old_search = NULL;
478 SearchPlaylist( p_intf, p_sys->psz_search_chain );
481 else if( p_sys->i_box_type == BOX_OPEN && p_sys->psz_open_chain )
484 i_chain_len = strlen( p_sys->psz_open_chain );
485 playlist_t *p_playlist = p_sys->p_playlist;
496 playlist_Add( p_playlist, p_sys->psz_open_chain,
497 p_sys->psz_open_chain,
498 PLAYLIST_GO|PLAYLIST_APPEND, PLAYLIST_END );
499 p_sys->b_box_plidx_follow = VLC_TRUE;
501 p_sys->i_box_type = BOX_PLAYLIST;
503 case 0x1b: /* Esc. */
504 p_sys->i_box_type = BOX_PLAYLIST;
507 if( i_chain_len > 0 )
509 p_sys->psz_open_chain[ i_chain_len - 1 ] = '\0';
513 if( i_chain_len < OPEN_CHAIN_SIZE )
515 p_sys->psz_open_chain[ i_chain_len++ ] = i_key;
516 p_sys->psz_open_chain[ i_chain_len ] = 0;
535 if( p_sys->i_box_type == BOX_INFO )
536 p_sys->i_box_type = BOX_NONE;
538 p_sys->i_box_type = BOX_INFO;
539 p_sys->i_box_lines_total = 0;
542 if( p_sys->i_box_type == BOX_LOG )
543 p_sys->i_box_type = BOX_NONE;
545 p_sys->i_box_type = BOX_LOG;
548 if( p_sys->i_box_type == BOX_PLAYLIST )
549 p_sys->i_box_type = BOX_NONE;
551 p_sys->i_box_type = BOX_PLAYLIST;
555 if( p_sys->i_box_type == BOX_HELP )
556 p_sys->i_box_type = BOX_NONE;
558 p_sys->i_box_type = BOX_HELP;
559 p_sys->i_box_lines_total = 0;
562 if( p_sys->i_box_type != BOX_SEARCH )
564 if( p_sys->psz_search_chain == NULL )
568 p_sys->psz_search_chain[0] = '\0';
569 p_sys->b_box_plidx_follow = VLC_FALSE;
570 p_sys->i_before_search = p_sys->i_box_plidx;
571 p_sys->i_box_type = BOX_SEARCH;
574 case 0x0f: /* '^o': open */
575 if( p_sys->i_box_type != BOX_OPEN )
577 if( p_sys->psz_open_chain == NULL )
581 p_sys->psz_open_chain[0] = '\0';
582 p_sys->i_box_type = BOX_OPEN;
588 p_sys->f_slider += 1.0;
589 if( p_sys->f_slider > 99.9 ) p_sys->f_slider = 99.9;
590 ManageSlider ( p_intf );
594 p_sys->f_slider -= 1.0;
595 if( p_sys->f_slider < 0.0 ) p_sys->f_slider = 0.0;
596 ManageSlider ( p_intf );
602 vout_thread_t *p_vout;
603 if( p_intf->p_sys->p_input )
605 p_vout = vlc_object_find( p_intf->p_sys->p_input,
606 VLC_OBJECT_VOUT, FIND_CHILD );
609 p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
610 vlc_object_release( p_vout );
621 if( p_intf->p_sys->p_playlist )
623 playlist_Stop( p_intf->p_sys->p_playlist );
634 val.b_bool = VLC_TRUE;
635 var_Set( p_sys->p_input, "prev-title", val );
642 val.b_bool = VLC_TRUE;
643 var_Set( p_sys->p_input, "next-title", val );
650 val.b_bool = VLC_TRUE;
651 var_Set( p_sys->p_input, "prev-chapter", val );
658 val.b_bool = VLC_TRUE;
659 var_Set( p_sys->p_input, "next-chapter", val );
664 if( p_intf->p_sys->p_playlist )
666 playlist_Prev( p_intf->p_sys->p_playlist );
671 if( p_intf->p_sys->p_playlist )
673 playlist_Next( p_intf->p_sys->p_playlist );
679 * ^l should clear and redraw the screen
690 static void ManageSlider ( intf_thread_t *p_intf )
692 intf_sys_t *p_sys = p_intf->p_sys;
693 input_thread_t *p_input = p_sys->p_input;
696 if( p_input == NULL )
700 var_Get( p_input, "state", &val );
701 if( val.i_int != PLAYING_S )
706 var_Get( p_input, "position", &val );
707 if( p_sys->f_slider == p_sys->f_slider_old )
710 p_sys->f_slider_old = 100 * val.f_float;
714 p_sys->f_slider_old = p_sys->f_slider;
716 val.f_float = p_sys->f_slider / 100.0;
717 var_Set( p_input, "position", val );
721 static void SearchPlaylist( intf_thread_t *p_intf, char *psz_searchstring )
727 intf_sys_t *p_sys = p_intf->p_sys;
728 playlist_t *p_playlist = p_sys->p_playlist;
730 if( p_sys->i_before_search >= 0 )
731 i_first = p_sys->i_before_search;
733 if( ( ! psz_searchstring ) || strlen( psz_searchstring ) <= 0 )
735 p_sys->i_box_plidx = p_sys->i_before_search;
739 for( i_current = i_first + 1; i_current < p_playlist->i_size;
742 if( strcasestr( p_playlist->pp_items[i_current]->input.psz_name,
743 psz_searchstring ) != NULL
744 || strcasestr( p_playlist->pp_items[i_current]->input.psz_uri,
745 psz_searchstring ) != NULL )
754 for( i_current = 0; i_current < i_first; i_current++ )
756 if( strcasestr( p_playlist->pp_items[i_current]->input.psz_name,
757 psz_searchstring ) != NULL
758 || strcasestr( p_playlist->pp_items[i_current]->input.psz_uri,
759 psz_searchstring ) != NULL )
768 if( i_item < 0 || i_item >= p_playlist->i_size ) return;
770 p_sys->i_box_plidx = i_item;
774 static void mvnprintw( int y, int x, int w, const char *p_fmt, ... )
780 va_start ( vl_args, p_fmt );
781 vasprintf ( &p_buf, p_fmt, vl_args );
790 if( ( i_len = strlen( p_buf ) ) > w )
792 int i_cut = i_len - w;
793 int x1 = i_len/2 - i_cut/2;
798 memmove( &p_buf[x1], &p_buf[x2], i_len - x2 );
807 mvprintw( y, x, "%s", p_buf );
811 mvprintw( y, x, "%s", p_buf );
812 mvhline( y, x + i_len, ' ', w - i_len );
816 static void MainBoxWrite( intf_thread_t *p_intf, int l, int x, const char *p_fmt, ... )
818 intf_sys_t *p_sys = p_intf->p_sys;
823 if( l < p_sys->i_box_start || l - p_sys->i_box_start >= p_sys->i_box_lines )
828 va_start ( vl_args, p_fmt );
829 vasprintf ( &p_buf, p_fmt, vl_args );
837 mvnprintw( p_sys->i_box_y + l - p_sys->i_box_start, x, COLS - x - 1, "%s", p_buf );
840 static void Redraw ( intf_thread_t *p_intf, time_t *t_last_refresh )
842 intf_sys_t *p_sys = p_intf->p_sys;
843 input_thread_t *p_input = p_sys->p_input;
851 attrset ( A_REVERSE );
852 mvnprintw( y, 0, COLS, VOUT_TITLE " (ncurses interface) [ h for help ]" );
853 attroff ( A_REVERSE );
857 if( p_input && !p_input->b_dead )
859 char buf1[MSTRTIME_MAX_SIZE];
860 char buf2[MSTRTIME_MAX_SIZE];
862 vlc_value_t val_list;
865 mvnprintw( y++, 0, COLS, " Source : %s", p_input->psz_source );
868 var_Get( p_input, "state", &val );
869 if( val.i_int == PLAYING_S )
871 mvnprintw( y++, 0, COLS, " State : Playing" );
873 else if( val.i_int == PAUSE_S )
875 mvnprintw( y++, 0, COLS, " State : Paused" );
881 if( val.i_int != INIT_S && val.i_int != END_S )
884 var_Get( p_input, "time", &val );
885 msecstotimestr( buf1, val.i_time / 1000 );
887 var_Get( p_input, "length", &val );
888 msecstotimestr( buf2, val.i_time / 1000 );
890 mvnprintw( y++, 0, COLS, " Position : %s/%s (%.2f%%)", buf1, buf2, p_sys->f_slider );
893 if( !var_Get( p_input, "title", &val ) )
895 var_Change( p_input, "title", VLC_VAR_GETCHOICES, &val_list, NULL );
896 if( val_list.p_list->i_count > 0 )
898 mvnprintw( y++, 0, COLS, " Title : %d/%d", val.i_int, val_list.p_list->i_count );
900 var_Change( p_input, "title", VLC_VAR_FREELIST, &val_list, NULL );
904 if( !var_Get( p_input, "chapter", &val ) )
906 var_Change( p_input, "chapter", VLC_VAR_GETCHOICES, &val_list, NULL );
907 if( val_list.p_list->i_count > 0 )
909 mvnprintw( y++, 0, COLS, " Chapter : %d/%d", val.i_int, val_list.p_list->i_count );
911 var_Change( p_input, "chapter", VLC_VAR_FREELIST, &val_list, NULL );
921 mvnprintw( y++, 0, COLS, "Source: <no current item>" );
922 DrawEmptyLine( p_sys->w, y++, 0, COLS );
923 DrawEmptyLine( p_sys->w, y++, 0, COLS );
926 DrawBox( p_sys->w, y, 0, 3, COLS, "" );
927 DrawEmptyLine( p_sys->w, y+1, 1, COLS-2);
928 DrawLine( p_sys->w, y+1, 1, (int)(p_intf->p_sys->f_slider/100.0 * (COLS -2)) );
931 p_sys->i_box_y = y + 1;
932 p_sys->i_box_lines = LINES - y - 2;
937 if( p_sys->i_box_type == BOX_HELP )
941 DrawBox( p_sys->w, y++, 0, h, COLS, " Help " );
943 MainBoxWrite( p_intf, l++, 1, "[Display]" );
944 MainBoxWrite( p_intf, l++, 1, " h,H Show/Hide help box" );
945 MainBoxWrite( p_intf, l++, 1, " i Show/Hide informations box" );
946 MainBoxWrite( p_intf, l++, 1, " l Show/Hide logs box" );
947 MainBoxWrite( p_intf, l++, 1, " P Show/Hide playlist box" );
948 MainBoxWrite( p_intf, l++, 1, "" );
950 MainBoxWrite( p_intf, l++, 1, "[Global]" );
951 MainBoxWrite( p_intf, l++, 1, " q, Q Quit" );
952 MainBoxWrite( p_intf, l++, 1, " s Stop" );
953 MainBoxWrite( p_intf, l++, 1, " <space> Pause/Play" );
954 MainBoxWrite( p_intf, l++, 1, " n, p Next/Previous item" );
955 MainBoxWrite( p_intf, l++, 1, " [, ] Next/Previous title" );
956 MainBoxWrite( p_intf, l++, 1, " <, > Next/Previous title" );
957 MainBoxWrite( p_intf, l++, 1, " <right> Seek +1%%" );
958 MainBoxWrite( p_intf, l++, 1, " <left> Seek -1%%" );
959 MainBoxWrite( p_intf, l++, 1, "" );
961 MainBoxWrite( p_intf, l++, 1, "[Playlist]" );
962 MainBoxWrite( p_intf, l++, 1, " r Randomize playlist" );
963 MainBoxWrite( p_intf, l++, 1, " o Order Playlist" );
964 MainBoxWrite( p_intf, l++, 1, " O Reverse order Playlist" );
965 MainBoxWrite( p_intf, l++, 1, " / Look for an item" );
966 MainBoxWrite( p_intf, l++, 1, " Ctrl-o Add an entry" );
967 MainBoxWrite( p_intf, l++, 1, " <del> Delete an entry" );
968 MainBoxWrite( p_intf, l++, 1, " <backspace> Delete an entry" );
969 MainBoxWrite( p_intf, l++, 1, "" );
971 MainBoxWrite( p_intf, l++, 1, "[Boxes]" );
972 MainBoxWrite( p_intf, l++, 1, " <up>,<down> Navigate through the box line by line" );
973 MainBoxWrite( p_intf, l++, 1, " <pgup>,<pgdown> Navigate through the box page by page" );
974 MainBoxWrite( p_intf, l++, 1, "" );
976 MainBoxWrite( p_intf, l++, 1, "[Player]" );
977 MainBoxWrite( p_intf, l++, 1, " <up>,<down> Seek +/-5%%" );
978 MainBoxWrite( p_intf, l++, 1, "" );
980 MainBoxWrite( p_intf, l++, 1, "[Miscellaneous]" );
981 MainBoxWrite( p_intf, l++, 1, " Ctrl-l Refresh the screen" );
983 p_sys->i_box_lines_total = l;
984 if( p_sys->i_box_start >= p_sys->i_box_lines_total )
986 p_sys->i_box_start = p_sys->i_box_lines_total - 1;
989 if( l - p_sys->i_box_start < p_sys->i_box_lines )
991 y += l - p_sys->i_box_start;
995 y += p_sys->i_box_lines;
998 else if( p_sys->i_box_type == BOX_INFO )
1002 DrawBox( p_sys->w, y++, 0, h, COLS, " Information " );
1008 vlc_mutex_lock( &p_input->stream.stream_lock );
1009 for ( i = 0; i < p_input->p_item->i_categories; i++ )
1011 info_category_t *p_category = p_input->p_item->pp_categories[i];
1012 if( y >= y_end ) break;
1013 MainBoxWrite( p_intf, l++, 1, " [%s]", p_category->psz_name );
1014 for ( j = 0; j < p_category->i_infos; j++ )
1016 info_t *p_info = p_category->pp_infos[j];
1017 if( y >= y_end ) break;
1018 MainBoxWrite( p_intf, l++, 1, " %s: %s", p_info->psz_name, p_info->psz_value );
1021 vlc_mutex_unlock( &p_input->p_item->lock );
1025 MainBoxWrite( p_intf, l++, 1, "No item currently playing" );
1027 p_sys->i_box_lines_total = l;
1028 if( p_sys->i_box_start >= p_sys->i_box_lines_total )
1030 p_sys->i_box_start = p_sys->i_box_lines_total - 1;
1033 if( l - p_sys->i_box_start < p_sys->i_box_lines )
1035 y += l - p_sys->i_box_start;
1039 y += p_sys->i_box_lines;
1042 else if( p_sys->i_box_type == BOX_LOG )
1048 DrawBox( p_sys->w, y++, 0, h, COLS, " Logs " );
1050 i_start = p_intf->p_sys->p_sub->i_start;
1052 vlc_mutex_lock( p_intf->p_sys->p_sub->p_lock );
1053 i_stop = *p_intf->p_sys->p_sub->pi_stop;
1054 vlc_mutex_unlock( p_intf->p_sys->p_sub->p_lock );
1058 static const char *ppsz_type[4] = { "", "error", "warning", "debug" };
1059 if( i_line >= h - 2 )
1065 if( i_stop < 0 ) i_stop += VLC_MSG_QSIZE;
1066 if( i_stop == i_start )
1070 mvnprintw( y + h-2-i_line, 1, COLS - 2, " [%s] %s",
1071 ppsz_type[p_sys->p_sub->p_msg[i_stop].i_type],
1072 p_sys->p_sub->p_msg[i_stop].psz_msg );
1075 vlc_mutex_lock( p_intf->p_sys->p_sub->p_lock );
1076 p_intf->p_sys->p_sub->i_start = i_stop;
1077 vlc_mutex_unlock( p_intf->p_sys->p_sub->p_lock );
1080 else if( ( p_sys->i_box_type == BOX_PLAYLIST ||
1081 p_sys->i_box_type == BOX_SEARCH ||
1082 p_sys->i_box_type == BOX_OPEN ) && p_sys->p_playlist )
1085 playlist_t *p_playlist = p_sys->p_playlist;
1086 int i_start, i_stop;
1088 DrawBox( p_sys->w, y++, 0, h, COLS, " Playlist " );
1090 if( p_sys->i_box_plidx >= p_playlist->i_size ) p_sys->i_box_plidx = p_playlist->i_size - 1;
1091 if( p_sys->i_box_plidx < 0 ) p_sys->i_box_plidx = 0;
1093 if( p_sys->i_box_plidx < (h - 2)/2 )
1098 else if( p_playlist->i_size - p_sys->i_box_plidx > (h - 2)/2 )
1100 i_start = p_sys->i_box_plidx - (h - 2)/2;
1101 i_stop = i_start + h - 2;
1105 i_stop = p_playlist->i_size;
1106 i_start = p_playlist->i_size - (h - 2);
1112 if( i_stop > p_playlist->i_size )
1114 i_stop = p_playlist->i_size;
1117 for( i_item = i_start; i_item < i_stop; i_item++ )
1119 vlc_bool_t b_selected = ( p_sys->i_box_plidx == i_item );
1120 int c = p_playlist->i_index == i_item ? '>' : ' ';
1122 if( y >= y_end ) break;
1125 attrset( A_REVERSE );
1127 if( !strcmp( p_playlist->pp_items[i_item]->input.psz_name,
1128 p_playlist->pp_items[i_item]->input.psz_uri ) )
1130 mvnprintw( y++, 1, COLS - 2, "%c %d - '%s'",
1133 p_playlist->pp_items[i_item]->input.psz_uri );
1137 mvnprintw( y++, 1, COLS - 2, "%c %d - '%s' (%s)",
1140 p_playlist->pp_items[i_item]->input.psz_uri,
1141 p_playlist->pp_items[i_item]->input.psz_name );
1145 attroff ( A_REVERSE );
1153 if( p_sys->i_box_type == BOX_SEARCH )
1155 DrawEmptyLine( p_sys->w, 6, 1, COLS-2 );
1156 if( p_sys->psz_search_chain )
1158 if( strlen( p_sys->psz_search_chain ) == 0 &&
1159 p_sys->psz_old_search != NULL )
1161 /* Searching next entry */
1162 mvnprintw( 6, 1, COLS-2, "Find: %s", p_sys->psz_old_search );
1166 mvnprintw( 6, 1, COLS-2, "Find: %s", p_sys->psz_search_chain );
1170 if( p_sys->i_box_type == BOX_OPEN )
1172 DrawEmptyLine( p_sys->w, 6, 1, COLS-2 );
1173 if( p_sys->psz_open_chain )
1175 mvnprintw( 6, 1, COLS-2, "Open: %s", p_sys->psz_open_chain );
1181 DrawEmptyLine( p_sys->w, y++, 1, COLS - 2 );
1186 *t_last_refresh = time( 0 );
1189 static void Eject ( intf_thread_t *p_intf )
1191 char *psz_device = NULL, *psz_parser, *psz_name;
1194 * Get the active input
1195 * Determine whether we can eject a media, ie it's a DVD, VCD or CD-DA
1196 * If it's neither of these, then return
1199 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1202 if( p_playlist == NULL )
1207 vlc_mutex_lock( &p_playlist->object_lock );
1209 if( p_playlist->i_index < 0 )
1211 vlc_mutex_unlock( &p_playlist->object_lock );
1212 vlc_object_release( p_playlist );
1216 psz_name = p_playlist->pp_items[ p_playlist->i_index ]->input.psz_name;
1220 if( !strncmp(psz_name, "dvd://", 4) )
1222 switch( psz_name[strlen("dvd://")] )
1226 psz_device = config_GetPsz( p_intf, "dvd" );
1229 /* Omit the first MRL-selector characters */
1230 psz_device = strdup( psz_name + strlen("dvd://" ) );
1234 else if( !strncmp(psz_name, VCD_MRL, strlen(VCD_MRL)) )
1236 switch( psz_name[strlen(VCD_MRL)] )
1240 psz_device = config_GetPsz( p_intf, VCD_MRL );
1243 /* Omit the beginning MRL-selector characters */
1244 psz_device = strdup( psz_name + strlen(VCD_MRL) );
1248 else if( !strncmp(psz_name, CDDA_MRL, strlen(CDDA_MRL) ) )
1250 switch( psz_name[strlen(CDDA_MRL)] )
1254 psz_device = config_GetPsz( p_intf, "cd-audio" );
1257 /* Omit the beginning MRL-selector characters */
1258 psz_device = strdup( psz_name + strlen(CDDA_MRL) );
1264 psz_device = strdup( psz_name );
1268 vlc_mutex_unlock( &p_playlist->object_lock );
1269 vlc_object_release( p_playlist );
1271 if( psz_device == NULL )
1276 /* Remove what we have after @ */
1277 psz_parser = psz_device;
1278 for( psz_parser = psz_device ; *psz_parser ; psz_parser++ )
1280 if( *psz_parser == '@' )
1287 /* If there's a stream playing, we aren't allowed to eject ! */
1288 if( p_intf->p_sys->p_input == NULL )
1290 msg_Dbg( p_intf, "ejecting %s", psz_device );
1292 intf_Eject( p_intf, psz_device );
1299 static void PlayPause ( intf_thread_t *p_intf )
1301 input_thread_t *p_input = p_intf->p_sys->p_input;
1306 var_Get( p_input, "state", &val );
1307 if( val.i_int != PAUSE_S )
1309 val.i_int = PAUSE_S;
1313 val.i_int = PLAYING_S;
1315 var_Set( p_input, "state", val );
1317 else if( p_intf->p_sys->p_playlist )
1319 playlist_Play( p_intf->p_sys->p_playlist );
1323 /****************************************************************************
1325 ****************************************************************************/
1326 static void DrawBox( WINDOW *win, int y, int x, int h, int w, char *title )
1331 if( w > 3 && h > 2 )
1333 if( title == NULL ) title = "";
1334 i_len = strlen( title );
1336 if( i_len > w - 2 ) i_len = w - 2;
1338 mvwaddch( win, y, x, ACS_ULCORNER );
1339 mvwhline( win, y, x+1, ACS_HLINE, ( w-i_len-2)/2 );
1340 mvwprintw( win,y, x+1+(w-i_len-2)/2, "%s", title );
1341 mvwhline( win, y, x+(w-i_len)/2+i_len, ACS_HLINE, w - 1 - ((w-i_len)/2+i_len) );
1342 mvwaddch( win, y, x+w-1,ACS_URCORNER );
1344 for( i = 0; i < h-2; i++ )
1346 mvwaddch( win, y+i+1, x, ACS_VLINE );
1347 mvwaddch( win, y+i+1, x+w-1, ACS_VLINE );
1350 mvwaddch( win, y+h-1, x, ACS_LLCORNER );
1351 mvwhline( win, y+h-1, x+1, ACS_HLINE, w - 2 );
1352 mvwaddch( win, y+h-1, x+w-1, ACS_LRCORNER );
1356 static void DrawEmptyLine( WINDOW *win, int y, int x, int w )
1360 mvhline( y, x, ' ', w );
1364 static void DrawLine( WINDOW *win, int y, int x, int w )
1368 attrset( A_REVERSE );
1369 mvhline( y, x, ' ', w );
1370 attroff ( A_REVERSE );