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 */
43 #ifdef HAVE_SYS_STAT_H
44 # include <sys/stat.h>
46 #if (!defined( WIN32 ) || defined(__MINGW32__))
47 /* Mingw has its own version of dirent */
52 #define CDDA_MRL "cddax://"
54 #define CDDA_MRL "cdda://"
58 #define VCD_MRL "vcdx://"
60 #define VCD_MRL "vcdx://"
63 #define SEARCH_CHAIN_SIZE 20
64 #define OPEN_CHAIN_SIZE 50
66 /*****************************************************************************
68 *****************************************************************************/
69 static int Open ( vlc_object_t * );
70 static void Close ( vlc_object_t * );
72 static void Run ( intf_thread_t * );
73 static void PlayPause ( intf_thread_t * );
74 static void Eject ( intf_thread_t * );
76 static int HandleKey ( intf_thread_t *, int );
77 static void Redraw ( intf_thread_t *, time_t * );
78 static void SearchPlaylist ( intf_thread_t *, char * );
79 static void ManageSlider ( intf_thread_t * );
80 static void ReadDir ( intf_thread_t * );
82 /*****************************************************************************
84 *****************************************************************************/
86 #define BROWSE_TEXT N_("Filebrowser starting point")
87 #define BROWSE_LONGTEXT N_( \
88 "This option allows you to specify directory the ncurses filebrowser" \
89 "will show you initially.")
92 set_description( _("ncurses interface") );
93 set_capability( "interface", 10 );
94 set_callbacks( Open, Close );
95 add_shortcut( "curses" );
96 add_directory( "browse-dir", NULL, NULL, BROWSE_TEXT, BROWSE_LONGTEXT, VLC_FALSE );
99 /*****************************************************************************
100 * intf_sys_t: description and status of ncurses interface
101 *****************************************************************************/
120 playlist_t *p_playlist;
121 input_thread_t *p_input;
131 int i_box_lines_total;
134 int i_box_plidx; /* Playlist index */
135 int b_box_plidx_follow;
136 int i_box_bidx; /* browser index */
140 msg_subscription_t* p_sub; /* message bank subscription */
142 char *psz_search_chain; /* for playlist searching */
143 char *psz_old_search; /* for searching next */
146 char *psz_open_chain;
148 char *psz_current_dir;
150 struct dir_entry_t **pp_dir_entries;
153 static void DrawBox( WINDOW *win, int y, int x, int h, int w, char *title );
154 static void DrawLine( WINDOW *win, int y, int x, int w );
155 static void DrawEmptyLine( WINDOW *win, int y, int x, int w );
157 /*****************************************************************************
158 * Open: initialize and create window
159 *****************************************************************************/
160 static int Open( vlc_object_t *p_this )
162 intf_thread_t *p_intf = (intf_thread_t *)p_this;
166 /* Allocate instance and initialize some members */
167 p_sys = p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
168 p_sys->p_playlist = NULL;
169 p_sys->p_input = NULL;
170 p_sys->f_slider = 0.0;
171 p_sys->f_slider_old = 0.0;
172 p_sys->i_box_type = BOX_PLAYLIST;
173 p_sys->i_box_lines = 0;
174 p_sys->i_box_start= 0;
175 p_sys->i_box_lines_total = 0;
176 p_sys->b_box_plidx_follow = VLC_TRUE;
177 p_sys->b_box_cleared = VLC_FALSE;
178 p_sys->i_box_plidx = 0;
179 p_sys->i_box_bidx = 0;
180 p_sys->p_sub = msg_Subscribe( p_intf );
182 /* Initialize the curses library */
183 p_sys->w = initscr();
184 keypad( p_sys->w, TRUE );
185 /* Don't do NL -> CR/NL */
187 /* Take input chars one at a time */
197 /* exported function */
198 p_intf->pf_run = Run;
202 var_Set( p_intf->p_vlc, "verbose", val );
204 /* Initialize search chain */
205 p_sys->psz_search_chain = (char *)malloc( SEARCH_CHAIN_SIZE + 1 );
206 p_sys->psz_old_search = NULL;
207 p_sys->i_before_search = 0;
209 /* Initialize open chain */
210 p_sys->psz_open_chain = (char *)malloc( OPEN_CHAIN_SIZE + 1 );
212 /* Initialize browser options */
213 var_Create( p_intf, "browse-dir", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
214 var_Get( p_intf, "browse-dir", &val);
216 if( val.psz_string && *val.psz_string )
218 p_sys->psz_current_dir = strdup( val.psz_string);
219 free( val.psz_string );
223 p_sys->psz_current_dir = strdup( p_intf->p_vlc->psz_homedir );
226 p_sys->i_dir_entries = 0;
227 p_sys->pp_dir_entries = NULL;
233 /*****************************************************************************
234 * Close: destroy interface window
235 *****************************************************************************/
236 static void Close( vlc_object_t *p_this )
238 intf_thread_t *p_intf = (intf_thread_t *)p_this;
239 intf_sys_t *p_sys = p_intf->p_sys;
242 for( i = 0; i < p_sys->i_dir_entries; i++ )
244 struct dir_entry_t *p_dir_entry = p_sys->pp_dir_entries[i];
245 if( p_dir_entry->psz_path ) free( p_dir_entry->psz_path );
246 REMOVE_ELEM( p_sys->pp_dir_entries, p_sys->i_dir_entries, i );
247 if( p_dir_entry ) free( p_dir_entry );
249 p_sys->pp_dir_entries = NULL;
251 if( p_sys->psz_current_dir ) free( p_sys->psz_current_dir );
252 if( p_sys->psz_search_chain ) free( p_sys->psz_search_chain );
253 if( p_sys->psz_old_search ) free( p_sys->psz_old_search );
254 if( p_sys->psz_open_chain ) free( p_sys->psz_open_chain );
258 vlc_object_release( p_sys->p_input );
260 if( p_sys->p_playlist )
262 vlc_object_release( p_sys->p_playlist );
265 /* Close the ncurses interface */
268 msg_Unsubscribe( p_intf, p_sys->p_sub );
270 /* Destroy structure */
274 /*****************************************************************************
275 * Run: ncurses thread
276 *****************************************************************************/
277 static void Run( intf_thread_t *p_intf )
279 intf_sys_t *p_sys = p_intf->p_sys;
282 time_t t_last_refresh;
285 * force drawing the interface for the first time
287 t_last_refresh = ( time( 0 ) - 1);
289 while( !p_intf->b_die )
291 msleep( INTF_IDLE_SLEEP );
293 /* Update the input */
294 if( p_sys->p_playlist == NULL )
296 p_sys->p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
298 if( p_sys->p_playlist )
300 vlc_mutex_lock( &p_sys->p_playlist->object_lock );
301 if( p_sys->p_input == NULL )
303 p_sys->p_input = p_sys->p_playlist->p_input;
306 if( !p_sys->p_input->b_dead )
308 vlc_object_yield( p_sys->p_input );
312 else if( p_sys->p_input->b_dead )
314 vlc_object_release( p_sys->p_input );
315 p_sys->p_input = NULL;
316 p_sys->f_slider = p_sys->f_slider_old = 0.0;
317 p_sys->b_box_cleared = VLC_FALSE;
319 vlc_mutex_unlock( &p_sys->p_playlist->object_lock );
322 if( p_sys->b_box_plidx_follow && p_sys->p_playlist->i_index >= 0 )
324 p_sys->i_box_plidx = p_sys->p_playlist->i_index;
327 while( ( i_key = getch()) != -1 )
330 * HandleKey returns 1 if the screen needs to be redrawn
332 if ( HandleKey( p_intf, i_key ) )
334 Redraw( p_intf, &t_last_refresh );
338 if( p_sys->f_slider > 0.0001 && !p_sys->b_box_cleared )
341 Redraw( p_intf, &t_last_refresh );
342 p_sys->b_box_cleared = VLC_TRUE;
346 * redraw the screen every second
348 if ( (time(0) - t_last_refresh) >= 1 )
350 ManageSlider ( p_intf );
351 Redraw( p_intf, &t_last_refresh );
356 /* following functions are local */
358 static int HandleKey( intf_thread_t *p_intf, int i_key )
360 intf_sys_t *p_sys = p_intf->p_sys;
363 if( p_sys->i_box_type == BOX_PLAYLIST && p_sys->p_playlist )
365 int b_ret = VLC_TRUE;
370 /* Playlist Settings */
372 var_Get( p_sys->p_playlist, "random", &val );
373 val.b_bool = !val.b_bool;
374 var_Set( p_sys->p_playlist, "random", val );
377 var_Get( p_sys->p_playlist, "loop", &val );
378 val.b_bool = !val.b_bool;
379 var_Set( p_sys->p_playlist, "loop", val );
382 var_Get( p_sys->p_playlist, "repeat", &val );
383 val.b_bool = !val.b_bool;
384 var_Set( p_sys->p_playlist, "repeat", val );
389 playlist_Sort( p_sys->p_playlist, SORT_TITLE, ORDER_NORMAL );
392 playlist_Sort( p_sys->p_playlist, SORT_TITLE, ORDER_REVERSE );
395 /* Playlist navigation */
397 p_sys->i_box_plidx = 0;
400 p_sys->i_box_plidx = p_sys->p_playlist->i_size - 1;
403 p_sys->i_box_plidx--;
406 p_sys->i_box_plidx++;
409 p_sys->i_box_plidx -= p_sys->i_box_lines;
412 p_sys->i_box_plidx += p_sys->i_box_lines;
418 int i_item = p_sys->p_playlist->i_index;
420 playlist_Delete( p_sys->p_playlist, p_sys->i_box_plidx );
421 if( i_item < p_sys->p_playlist->i_size && i_item != p_sys->p_playlist->i_index )
423 playlist_Goto( p_sys->p_playlist, i_item );
430 playlist_Goto( p_sys->p_playlist, p_sys->i_box_plidx );
439 if( p_sys->i_box_plidx >= p_sys->p_playlist->i_size ) p_sys->i_box_plidx = p_sys->p_playlist->i_size - 1;
440 if( p_sys->i_box_plidx < 0 ) p_sys->i_box_plidx = 0;
441 if( p_sys->i_box_plidx == p_sys->p_playlist->i_index )
442 p_sys->b_box_plidx_follow = VLC_TRUE;
444 p_sys->b_box_plidx_follow = VLC_FALSE;
448 if( p_sys->i_box_type == BOX_BROWSE )
450 vlc_bool_t b_ret = VLC_TRUE;
451 /* Browser navigation */
455 p_sys->i_box_bidx = 0;
458 p_sys->i_box_bidx = p_sys->i_dir_entries - 1;
467 p_sys->i_box_bidx -= p_sys->i_box_lines;
470 p_sys->i_box_bidx += p_sys->i_box_lines;
475 if( p_sys->pp_dir_entries[p_sys->i_box_bidx]->b_file )
477 int i_size_entry = strlen( p_sys->psz_current_dir ) +
478 strlen( p_sys->pp_dir_entries[p_sys->i_box_bidx]->psz_path ) + 2;
479 char *psz_uri = (char *)malloc( sizeof(char)*i_size_entry);
481 sprintf( psz_uri, "%s/%s", p_sys->psz_current_dir, p_sys->pp_dir_entries[p_sys->i_box_bidx]->psz_path );
482 playlist_Add( p_sys->p_playlist, psz_uri,
484 PLAYLIST_APPEND, PLAYLIST_END );
485 p_sys->i_box_type = BOX_PLAYLIST;
490 int i_size_entry = strlen( p_sys->psz_current_dir ) +
491 strlen( p_sys->pp_dir_entries[p_sys->i_box_bidx]->psz_path ) + 2;
492 char *psz_uri = (char *)malloc( sizeof(char)*i_size_entry);
494 sprintf( psz_uri, "%s/%s", p_sys->psz_current_dir, p_sys->pp_dir_entries[p_sys->i_box_bidx]->psz_path );
496 p_sys->psz_current_dir = strdup( psz_uri );
507 if( p_sys->i_box_bidx >= p_sys->i_dir_entries ) p_sys->i_box_bidx = p_sys->i_dir_entries - 1;
508 if( p_sys->i_box_bidx < 0 ) p_sys->i_box_bidx = 0;
512 else if( p_sys->i_box_type == BOX_HELP || p_sys->i_box_type == BOX_INFO )
517 p_sys->i_box_start = 0;
520 p_sys->i_box_start = p_sys->i_box_lines_total - 1;
523 if( p_sys->i_box_start > 0 ) p_sys->i_box_start--;
526 if( p_sys->i_box_start < p_sys->i_box_lines_total - 1 )
528 p_sys->i_box_start++;
532 p_sys->i_box_start -= p_sys->i_box_lines;
533 if( p_sys->i_box_start < 0 ) p_sys->i_box_start = 0;
536 p_sys->i_box_start += p_sys->i_box_lines;
537 if( p_sys->i_box_start >= p_sys->i_box_lines_total )
539 p_sys->i_box_start = p_sys->i_box_lines_total - 1;
546 else if( p_sys->i_box_type == BOX_NONE )
552 ManageSlider ( p_intf );
555 p_sys->f_slider = 99.9;
556 ManageSlider ( p_intf );
559 p_sys->f_slider += 5.0;
560 if( p_sys->f_slider >= 99.0 ) p_sys->f_slider = 99.0;
561 ManageSlider ( p_intf );
564 p_sys->f_slider -= 5.0;
565 if( p_sys->f_slider < 0.0 ) p_sys->f_slider = 0.0;
566 ManageSlider ( p_intf );
573 else if( p_sys->i_box_type == BOX_SEARCH && p_sys->psz_search_chain )
576 i_chain_len = strlen( p_sys->psz_search_chain );
584 if( i_chain_len > 0 )
586 p_sys->psz_old_search = strdup( p_sys->psz_search_chain );
588 else if( p_sys->psz_old_search )
590 SearchPlaylist( p_intf, p_sys->psz_old_search );
592 p_sys->i_box_type = BOX_PLAYLIST;
594 case 0x1b: /* Esc. */
595 p_sys->i_box_plidx = p_sys->i_before_search;
596 p_sys->i_box_type = BOX_PLAYLIST;
599 if( i_chain_len > 0 )
601 p_sys->psz_search_chain[ i_chain_len - 1 ] = '\0';
605 if( i_chain_len < SEARCH_CHAIN_SIZE )
607 p_sys->psz_search_chain[ i_chain_len++ ] = i_key;
608 p_sys->psz_search_chain[ i_chain_len ] = 0;
612 if( p_sys->psz_old_search )
614 free( p_sys->psz_old_search );
615 p_sys->psz_old_search = NULL;
617 SearchPlaylist( p_intf, p_sys->psz_search_chain );
620 else if( p_sys->i_box_type == BOX_OPEN && p_sys->psz_open_chain )
623 i_chain_len = strlen( p_sys->psz_open_chain );
624 playlist_t *p_playlist = p_sys->p_playlist;
633 if( p_playlist && i_chain_len > 0 )
635 playlist_Add( p_playlist, p_sys->psz_open_chain,
636 p_sys->psz_open_chain,
637 PLAYLIST_GO|PLAYLIST_APPEND, PLAYLIST_END );
638 p_sys->b_box_plidx_follow = VLC_TRUE;
640 p_sys->i_box_type = BOX_PLAYLIST;
642 case 0x1b: /* Esc. */
643 p_sys->i_box_type = BOX_PLAYLIST;
646 if( i_chain_len > 0 )
648 p_sys->psz_open_chain[ i_chain_len - 1 ] = '\0';
652 if( i_chain_len < OPEN_CHAIN_SIZE )
654 p_sys->psz_open_chain[ i_chain_len++ ] = i_key;
655 p_sys->psz_open_chain[ i_chain_len ] = 0;
669 p_intf->p_vlc->b_die = VLC_TRUE;
674 if( p_sys->i_box_type == BOX_INFO )
675 p_sys->i_box_type = BOX_NONE;
677 p_sys->i_box_type = BOX_INFO;
678 p_sys->i_box_lines_total = 0;
681 if( p_sys->i_box_type == BOX_LOG )
682 p_sys->i_box_type = BOX_NONE;
684 p_sys->i_box_type = BOX_LOG;
687 if( p_sys->i_box_type == BOX_PLAYLIST )
688 p_sys->i_box_type = BOX_NONE;
690 p_sys->i_box_type = BOX_PLAYLIST;
693 if( p_sys->i_box_type == BOX_BROWSE )
694 p_sys->i_box_type = BOX_NONE;
696 p_sys->i_box_type = BOX_BROWSE;
700 if( p_sys->i_box_type == BOX_HELP )
701 p_sys->i_box_type = BOX_NONE;
703 p_sys->i_box_type = BOX_HELP;
704 p_sys->i_box_lines_total = 0;
707 if( p_sys->i_box_type != BOX_SEARCH )
709 if( p_sys->psz_search_chain == NULL )
713 p_sys->psz_search_chain[0] = '\0';
714 p_sys->b_box_plidx_follow = VLC_FALSE;
715 p_sys->i_before_search = p_sys->i_box_plidx;
716 p_sys->i_box_type = BOX_SEARCH;
720 if( p_sys->i_box_type != BOX_OPEN )
722 if( p_sys->psz_open_chain == NULL )
726 p_sys->psz_open_chain[0] = '\0';
727 p_sys->i_box_type = BOX_OPEN;
733 p_sys->f_slider += 1.0;
734 if( p_sys->f_slider > 99.9 ) p_sys->f_slider = 99.9;
735 ManageSlider ( p_intf );
739 p_sys->f_slider -= 1.0;
740 if( p_sys->f_slider < 0.0 ) p_sys->f_slider = 0.0;
741 ManageSlider ( p_intf );
747 vout_thread_t *p_vout;
748 if( p_intf->p_sys->p_input )
750 p_vout = vlc_object_find( p_intf->p_sys->p_input,
751 VLC_OBJECT_VOUT, FIND_CHILD );
754 p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
755 vlc_object_release( p_vout );
766 if( p_intf->p_sys->p_playlist )
768 playlist_Stop( p_intf->p_sys->p_playlist );
779 val.b_bool = VLC_TRUE;
780 var_Set( p_sys->p_input, "prev-title", val );
787 val.b_bool = VLC_TRUE;
788 var_Set( p_sys->p_input, "next-title", val );
795 val.b_bool = VLC_TRUE;
796 var_Set( p_sys->p_input, "prev-chapter", val );
803 val.b_bool = VLC_TRUE;
804 var_Set( p_sys->p_input, "next-chapter", val );
809 if( p_intf->p_sys->p_playlist )
811 playlist_Prev( p_intf->p_sys->p_playlist );
817 if( p_intf->p_sys->p_playlist )
819 playlist_Next( p_intf->p_sys->p_playlist );
825 aout_VolumeUp( p_intf, 1, NULL );
830 aout_VolumeDown( p_intf, 1, NULL );
835 * ^l should clear and redraw the screen
846 static void ManageSlider ( intf_thread_t *p_intf )
848 intf_sys_t *p_sys = p_intf->p_sys;
849 input_thread_t *p_input = p_sys->p_input;
852 if( p_input == NULL )
856 var_Get( p_input, "state", &val );
857 if( val.i_int != PLAYING_S )
862 var_Get( p_input, "position", &val );
863 if( p_sys->f_slider == p_sys->f_slider_old )
866 p_sys->f_slider_old = 100 * val.f_float;
870 p_sys->f_slider_old = p_sys->f_slider;
872 val.f_float = p_sys->f_slider / 100.0;
873 var_Set( p_input, "position", val );
877 static void SearchPlaylist( intf_thread_t *p_intf, char *psz_searchstring )
883 intf_sys_t *p_sys = p_intf->p_sys;
884 playlist_t *p_playlist = p_sys->p_playlist;
886 if( p_sys->i_before_search >= 0 )
887 i_first = p_sys->i_before_search;
889 if( ( ! psz_searchstring ) || strlen( psz_searchstring ) <= 0 )
891 p_sys->i_box_plidx = p_sys->i_before_search;
895 for( i_current = i_first + 1; i_current < p_playlist->i_size;
898 if( strcasestr( p_playlist->pp_items[i_current]->input.psz_name,
899 psz_searchstring ) != NULL
900 || strcasestr( p_playlist->pp_items[i_current]->input.psz_uri,
901 psz_searchstring ) != NULL )
910 for( i_current = 0; i_current < i_first; i_current++ )
912 if( strcasestr( p_playlist->pp_items[i_current]->input.psz_name,
913 psz_searchstring ) != NULL
914 || strcasestr( p_playlist->pp_items[i_current]->input.psz_uri,
915 psz_searchstring ) != NULL )
924 if( i_item < 0 || i_item >= p_playlist->i_size ) return;
926 p_sys->i_box_plidx = i_item;
930 static void mvnprintw( int y, int x, int w, const char *p_fmt, ... )
936 va_start ( vl_args, p_fmt );
937 vasprintf ( &p_buf, p_fmt, vl_args );
946 if( ( i_len = strlen( p_buf ) ) > w )
948 int i_cut = i_len - w;
949 int x1 = i_len/2 - i_cut/2;
954 memmove( &p_buf[x1], &p_buf[x2], i_len - x2 );
963 mvprintw( y, x, "%s", p_buf );
967 mvprintw( y, x, "%s", p_buf );
968 mvhline( y, x + i_len, ' ', w - i_len );
972 static void MainBoxWrite( intf_thread_t *p_intf, int l, int x, const char *p_fmt, ... )
974 intf_sys_t *p_sys = p_intf->p_sys;
979 if( l < p_sys->i_box_start || l - p_sys->i_box_start >= p_sys->i_box_lines )
984 va_start ( vl_args, p_fmt );
985 vasprintf ( &p_buf, p_fmt, vl_args );
993 mvnprintw( p_sys->i_box_y + l - p_sys->i_box_start, x, COLS - x - 1, "%s", p_buf );
996 static void Redraw ( intf_thread_t *p_intf, time_t *t_last_refresh )
998 intf_sys_t *p_sys = p_intf->p_sys;
999 input_thread_t *p_input = p_sys->p_input;
1007 attrset ( A_REVERSE );
1008 mvnprintw( y, 0, COLS, "VLC media player" " (ncurses interface) [ h for help ]" );
1009 attroff ( A_REVERSE );
1013 if( p_input && !p_input->b_dead )
1015 char buf1[MSTRTIME_MAX_SIZE];
1016 char buf2[MSTRTIME_MAX_SIZE];
1018 vlc_value_t val_list;
1021 mvnprintw( y++, 0, COLS, " Source : %s",
1022 p_input->input.p_item->psz_uri );
1025 var_Get( p_input, "state", &val );
1026 if( val.i_int == PLAYING_S )
1028 mvnprintw( y++, 0, COLS, " State : Playing" );
1030 else if( val.i_int == PAUSE_S )
1032 mvnprintw( y++, 0, COLS, " State : Paused" );
1038 if( val.i_int != INIT_S && val.i_int != END_S )
1040 audio_volume_t i_volume;
1043 var_Get( p_input, "time", &val );
1044 msecstotimestr( buf1, val.i_time / 1000 );
1046 var_Get( p_input, "length", &val );
1047 msecstotimestr( buf2, val.i_time / 1000 );
1049 mvnprintw( y++, 0, COLS, " Position : %s/%s (%.2f%%)", buf1, buf2, p_sys->f_slider );
1052 aout_VolumeGet( p_intf, &i_volume );
1053 mvnprintw( y++, 0, COLS, " Volume : %i%%", i_volume*200/AOUT_VOLUME_MAX );
1056 if( !var_Get( p_input, "title", &val ) )
1058 var_Change( p_input, "title", VLC_VAR_GETCHOICES, &val_list, NULL );
1059 if( val_list.p_list->i_count > 0 )
1061 mvnprintw( y++, 0, COLS, " Title : %d/%d", val.i_int, val_list.p_list->i_count );
1063 var_Change( p_input, "title", VLC_VAR_FREELIST, &val_list, NULL );
1067 if( !var_Get( p_input, "chapter", &val ) )
1069 var_Change( p_input, "chapter", VLC_VAR_GETCHOICES, &val_list, NULL );
1070 if( val_list.p_list->i_count > 0 )
1072 mvnprintw( y++, 0, COLS, " Chapter : %d/%d", val.i_int, val_list.p_list->i_count );
1074 var_Change( p_input, "chapter", VLC_VAR_FREELIST, &val_list, NULL );
1084 mvnprintw( y++, 0, COLS, "Source: <no current item>" );
1085 DrawEmptyLine( p_sys->w, y++, 0, COLS );
1086 DrawEmptyLine( p_sys->w, y++, 0, COLS );
1087 DrawEmptyLine( p_sys->w, y++, 0, COLS );
1090 DrawBox( p_sys->w, y, 0, 3, COLS, "" );
1091 DrawEmptyLine( p_sys->w, y+1, 1, COLS-2);
1092 DrawLine( p_sys->w, y+1, 1, (int)(p_intf->p_sys->f_slider/100.0 * (COLS -2)) );
1095 p_sys->i_box_y = y + 1;
1096 p_sys->i_box_lines = LINES - y - 2;
1101 if( p_sys->i_box_type == BOX_HELP )
1105 DrawBox( p_sys->w, y++, 0, h, COLS, " Help " );
1107 MainBoxWrite( p_intf, l++, 1, "[Display]" );
1108 MainBoxWrite( p_intf, l++, 1, " h,H Show/Hide help box" );
1109 MainBoxWrite( p_intf, l++, 1, " i Show/Hide info box" );
1110 MainBoxWrite( p_intf, l++, 1, " L Show/Hide messages box" );
1111 MainBoxWrite( p_intf, l++, 1, " P Show/Hide playlist box" );
1112 MainBoxWrite( p_intf, l++, 1, " B Show/Hide filebrowser" );
1113 MainBoxWrite( p_intf, l++, 1, "" );
1115 MainBoxWrite( p_intf, l++, 1, "[Global]" );
1116 MainBoxWrite( p_intf, l++, 1, " q, Q Quit" );
1117 MainBoxWrite( p_intf, l++, 1, " s Stop" );
1118 MainBoxWrite( p_intf, l++, 1, " <space> Pause/Play" );
1119 MainBoxWrite( p_intf, l++, 1, " f Toggle Fullscreen" );
1120 MainBoxWrite( p_intf, l++, 1, " n, p Next/Previous playlist item" );
1121 MainBoxWrite( p_intf, l++, 1, " [, ] Next/Previous title" );
1122 MainBoxWrite( p_intf, l++, 1, " <, > Next/Previous chapter" );
1123 MainBoxWrite( p_intf, l++, 1, " <right> Seek +1%%" );
1124 MainBoxWrite( p_intf, l++, 1, " <left> Seek -1%%" );
1125 MainBoxWrite( p_intf, l++, 1, " a Volume Up" );
1126 MainBoxWrite( p_intf, l++, 1, " z Volume Down" );
1127 MainBoxWrite( p_intf, l++, 1, "" );
1129 MainBoxWrite( p_intf, l++, 1, "[Playlist]" );
1130 MainBoxWrite( p_intf, l++, 1, " r Random" );
1131 MainBoxWrite( p_intf, l++, 1, " l Loop Playlist" );
1132 MainBoxWrite( p_intf, l++, 1, " R Repeat item" );
1133 MainBoxWrite( p_intf, l++, 1, " o Order Playlist by title" );
1134 MainBoxWrite( p_intf, l++, 1, " O Reverse order Playlist by title" );
1135 MainBoxWrite( p_intf, l++, 1, " / Look for an item" );
1136 MainBoxWrite( p_intf, l++, 1, " A Add an entry" );
1137 MainBoxWrite( p_intf, l++, 1, " D, <del> Delete an entry" );
1138 MainBoxWrite( p_intf, l++, 1, " <backspace> Delete an entry" );
1139 MainBoxWrite( p_intf, l++, 1, "" );
1141 MainBoxWrite( p_intf, l++, 1, "[Boxes]" );
1142 MainBoxWrite( p_intf, l++, 1, " <up>,<down> Navigate through the box line by line" );
1143 MainBoxWrite( p_intf, l++, 1, " <pgup>,<pgdown> Navigate through the box page by page" );
1144 MainBoxWrite( p_intf, l++, 1, "" );
1146 MainBoxWrite( p_intf, l++, 1, "[Player]" );
1147 MainBoxWrite( p_intf, l++, 1, " <up>,<down> Seek +/-5%%" );
1148 MainBoxWrite( p_intf, l++, 1, "" );
1150 MainBoxWrite( p_intf, l++, 1, "[Miscellaneous]" );
1151 MainBoxWrite( p_intf, l++, 1, " Ctrl-l Refresh the screen" );
1153 p_sys->i_box_lines_total = l;
1154 if( p_sys->i_box_start >= p_sys->i_box_lines_total )
1156 p_sys->i_box_start = p_sys->i_box_lines_total - 1;
1159 if( l - p_sys->i_box_start < p_sys->i_box_lines )
1161 y += l - p_sys->i_box_start;
1165 y += p_sys->i_box_lines;
1168 else if( p_sys->i_box_type == BOX_INFO )
1172 DrawBox( p_sys->w, y++, 0, h, COLS, " Information " );
1177 vlc_mutex_lock( &p_input->input.p_item->lock );
1178 for ( i = 0; i < p_input->input.p_item->i_categories; i++ )
1180 info_category_t *p_category = p_input->input.p_item->pp_categories[i];
1181 if( y >= y_end ) break;
1182 MainBoxWrite( p_intf, l++, 1, " [%s]", p_category->psz_name );
1183 for ( j = 0; j < p_category->i_infos; j++ )
1185 info_t *p_info = p_category->pp_infos[j];
1186 if( y >= y_end ) break;
1187 MainBoxWrite( p_intf, l++, 1, " %s: %s", p_info->psz_name, p_info->psz_value );
1190 vlc_mutex_unlock( &p_input->input.p_item->lock );
1194 MainBoxWrite( p_intf, l++, 1, "No item currently playing" );
1196 p_sys->i_box_lines_total = l;
1197 if( p_sys->i_box_start >= p_sys->i_box_lines_total )
1199 p_sys->i_box_start = p_sys->i_box_lines_total - 1;
1202 if( l - p_sys->i_box_start < p_sys->i_box_lines )
1204 y += l - p_sys->i_box_start;
1208 y += p_sys->i_box_lines;
1211 else if( p_sys->i_box_type == BOX_LOG )
1217 DrawBox( p_sys->w, y++, 0, h, COLS, " Logs " );
1219 i_start = p_intf->p_sys->p_sub->i_start;
1221 vlc_mutex_lock( p_intf->p_sys->p_sub->p_lock );
1222 i_stop = *p_intf->p_sys->p_sub->pi_stop;
1223 vlc_mutex_unlock( p_intf->p_sys->p_sub->p_lock );
1227 static const char *ppsz_type[4] = { "", "error", "warning", "debug" };
1228 if( i_line >= h - 2 )
1234 if( i_stop < 0 ) i_stop += VLC_MSG_QSIZE;
1235 if( i_stop == i_start )
1239 mvnprintw( y + h-2-i_line, 1, COLS - 2, " [%s] %s",
1240 ppsz_type[p_sys->p_sub->p_msg[i_stop].i_type],
1241 p_sys->p_sub->p_msg[i_stop].psz_msg );
1244 vlc_mutex_lock( p_intf->p_sys->p_sub->p_lock );
1245 p_intf->p_sys->p_sub->i_start = i_stop;
1246 vlc_mutex_unlock( p_intf->p_sys->p_sub->p_lock );
1249 else if( p_sys->i_box_type == BOX_BROWSE )
1252 int i_start, i_stop;
1254 DrawBox( p_sys->w, y++, 0, h, COLS, " Browse " );
1256 if( p_sys->i_box_bidx >= p_sys->i_dir_entries ) p_sys->i_box_plidx = p_sys->i_dir_entries - 1;
1257 if( p_sys->i_box_bidx < 0 ) p_sys->i_box_bidx = 0;
1259 if( p_sys->i_box_bidx < (h - 2)/2 )
1264 else if( p_sys->i_dir_entries - p_sys->i_box_bidx > (h - 2)/2 )
1266 i_start = p_sys->i_box_bidx - (h - 2)/2;
1267 i_stop = i_start + h - 2;
1271 i_stop = p_sys->i_dir_entries;
1272 i_start = p_sys->i_dir_entries - (h - 2);
1278 if( i_stop > p_sys->i_dir_entries )
1280 i_stop = p_sys->i_dir_entries;
1283 for( i_item = i_start; i_item < i_stop; i_item++ )
1285 vlc_bool_t b_selected = ( p_sys->i_box_bidx == i_item );
1287 if( y >= y_end ) break;
1290 attrset( A_REVERSE );
1292 mvnprintw( y++, 1, COLS - 2, "%c %s", p_sys->pp_dir_entries[i_item]->b_file == VLC_TRUE ? '-' : '+',
1293 p_sys->pp_dir_entries[i_item]->psz_path );
1296 attroff ( A_REVERSE );
1301 else if( ( p_sys->i_box_type == BOX_PLAYLIST ||
1302 p_sys->i_box_type == BOX_SEARCH ||
1303 p_sys->i_box_type == BOX_OPEN ) && p_sys->p_playlist )
1306 playlist_t *p_playlist = p_sys->p_playlist;
1307 int i_start, i_stop;
1309 DrawBox( p_sys->w, y++, 0, h, COLS, " Playlist " );
1311 if( p_sys->i_box_plidx >= p_playlist->i_size ) p_sys->i_box_plidx = p_playlist->i_size - 1;
1312 if( p_sys->i_box_plidx < 0 ) p_sys->i_box_plidx = 0;
1314 if( p_sys->i_box_plidx < (h - 2)/2 )
1319 else if( p_playlist->i_size - p_sys->i_box_plidx > (h - 2)/2 )
1321 i_start = p_sys->i_box_plidx - (h - 2)/2;
1322 i_stop = i_start + h - 2;
1326 i_stop = p_playlist->i_size;
1327 i_start = p_playlist->i_size - (h - 2);
1333 if( i_stop > p_playlist->i_size )
1335 i_stop = p_playlist->i_size;
1338 for( i_item = i_start; i_item < i_stop; i_item++ )
1340 vlc_bool_t b_selected = ( p_sys->i_box_plidx == i_item );
1341 int c = p_playlist->i_index == i_item ? '>' : ' ';
1343 if( y >= y_end ) break;
1346 attrset( A_REVERSE );
1348 if( !strcmp( p_playlist->pp_items[i_item]->input.psz_name,
1349 p_playlist->pp_items[i_item]->input.psz_uri ) )
1351 mvnprintw( y++, 1, COLS - 2, "%c %d - '%s'",
1354 p_playlist->pp_items[i_item]->input.psz_uri );
1358 mvnprintw( y++, 1, COLS - 2, "%c %d - '%s' (%s)",
1361 p_playlist->pp_items[i_item]->input.psz_uri,
1362 p_playlist->pp_items[i_item]->input.psz_name );
1366 attroff ( A_REVERSE );
1374 if( p_sys->i_box_type == BOX_SEARCH )
1376 DrawEmptyLine( p_sys->w, 7, 1, COLS-2 );
1377 if( p_sys->psz_search_chain )
1379 if( strlen( p_sys->psz_search_chain ) == 0 &&
1380 p_sys->psz_old_search != NULL )
1382 /* Searching next entry */
1383 mvnprintw( 7, 1, COLS-2, "Find: %s", p_sys->psz_old_search );
1387 mvnprintw( 7, 1, COLS-2, "Find: %s", p_sys->psz_search_chain );
1391 if( p_sys->i_box_type == BOX_OPEN )
1393 if( p_sys->psz_open_chain )
1395 DrawEmptyLine( p_sys->w, 7, 1, COLS-2 );
1396 mvnprintw( 7, 1, COLS-2, "Open: %s", p_sys->psz_open_chain );
1402 DrawEmptyLine( p_sys->w, y++, 1, COLS - 2 );
1407 *t_last_refresh = time( 0 );
1410 static void Eject ( intf_thread_t *p_intf )
1412 char *psz_device = NULL, *psz_parser, *psz_name;
1415 * Get the active input
1416 * Determine whether we can eject a media, ie it's a DVD, VCD or CD-DA
1417 * If it's neither of these, then return
1420 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1423 if( p_playlist == NULL )
1428 vlc_mutex_lock( &p_playlist->object_lock );
1430 if( p_playlist->i_index < 0 )
1432 vlc_mutex_unlock( &p_playlist->object_lock );
1433 vlc_object_release( p_playlist );
1437 psz_name = p_playlist->pp_items[ p_playlist->i_index ]->input.psz_name;
1441 if( !strncmp(psz_name, "dvd://", 4) )
1443 switch( psz_name[strlen("dvd://")] )
1447 psz_device = config_GetPsz( p_intf, "dvd" );
1450 /* Omit the first MRL-selector characters */
1451 psz_device = strdup( psz_name + strlen("dvd://" ) );
1455 else if( !strncmp(psz_name, VCD_MRL, strlen(VCD_MRL)) )
1457 switch( psz_name[strlen(VCD_MRL)] )
1461 psz_device = config_GetPsz( p_intf, VCD_MRL );
1464 /* Omit the beginning MRL-selector characters */
1465 psz_device = strdup( psz_name + strlen(VCD_MRL) );
1469 else if( !strncmp(psz_name, CDDA_MRL, strlen(CDDA_MRL) ) )
1471 switch( psz_name[strlen(CDDA_MRL)] )
1475 psz_device = config_GetPsz( p_intf, "cd-audio" );
1478 /* Omit the beginning MRL-selector characters */
1479 psz_device = strdup( psz_name + strlen(CDDA_MRL) );
1485 psz_device = strdup( psz_name );
1489 vlc_mutex_unlock( &p_playlist->object_lock );
1490 vlc_object_release( p_playlist );
1492 if( psz_device == NULL )
1497 /* Remove what we have after @ */
1498 psz_parser = psz_device;
1499 for( psz_parser = psz_device ; *psz_parser ; psz_parser++ )
1501 if( *psz_parser == '@' )
1508 /* If there's a stream playing, we aren't allowed to eject ! */
1509 if( p_intf->p_sys->p_input == NULL )
1511 msg_Dbg( p_intf, "ejecting %s", psz_device );
1513 intf_Eject( p_intf, psz_device );
1520 static void ReadDir( intf_thread_t *p_intf )
1522 intf_sys_t *p_sys = p_intf->p_sys;
1523 DIR * p_current_dir;
1524 struct dirent * p_dir_content;
1527 if( p_sys->psz_current_dir && *p_sys->psz_current_dir )
1530 p_current_dir = opendir( p_sys->psz_current_dir );
1532 if( p_current_dir == NULL )
1534 /* something went bad, get out of here ! */
1536 msg_Warn( p_intf, "cannot open directory `%s' (%s)",
1537 p_sys->psz_current_dir, strerror(errno));
1539 msg_Warn( p_intf, "cannot open directory `%s'", p_sys->psz_current_dir );
1544 /* Clean the old shit */
1545 for( i = 0; i < p_sys->i_dir_entries; i++ )
1547 struct dir_entry_t *p_dir_entry = p_sys->pp_dir_entries[i];
1548 free( p_dir_entry->psz_path );
1549 REMOVE_ELEM( p_sys->pp_dir_entries, p_sys->i_dir_entries, i );
1550 free( p_dir_entry );
1552 p_sys->pp_dir_entries = NULL;
1553 p_sys->i_dir_entries = 0;
1555 /* get the first directory entry */
1556 p_dir_content = readdir( p_current_dir );
1558 /* while we still have entries in the directory */
1559 while( p_dir_content != NULL )
1561 struct dir_entry_t *p_dir_entry;
1562 int i_size_entry = strlen( p_sys->psz_current_dir ) +
1563 strlen( p_dir_content->d_name ) + 2;
1564 char *psz_uri = (char *)malloc( sizeof(char)*i_size_entry);
1566 sprintf( psz_uri, "%s/%s", p_sys->psz_current_dir, p_dir_content->d_name );
1568 if( ( p_dir_entry = malloc( sizeof( struct dir_entry_t) ) ) == NULL )
1574 #if defined( S_ISDIR )
1575 struct stat stat_data;
1576 stat( psz_uri, &stat_data );
1577 if( S_ISDIR(stat_data.st_mode) )
1578 #elif defined( DT_DIR )
1579 if( p_dir_content->d_type & DT_DIR )
1584 p_dir_entry->psz_path = strdup( p_dir_content->d_name );
1585 p_dir_entry->b_file = VLC_FALSE;
1586 INSERT_ELEM( p_sys->pp_dir_entries, p_sys->i_dir_entries,
1587 p_sys->i_dir_entries, p_dir_entry );
1591 p_dir_entry->psz_path = strdup( p_dir_content->d_name );
1592 p_dir_entry->b_file = VLC_TRUE;
1593 INSERT_ELEM( p_sys->pp_dir_entries, p_sys->i_dir_entries,
1594 p_sys->i_dir_entries, p_dir_entry );
1597 /* Read next entry */
1598 p_dir_content = readdir( p_current_dir );
1600 closedir( p_current_dir );
1605 msg_Dbg( p_intf, "no current dir set" );
1610 static void PlayPause( intf_thread_t *p_intf )
1612 input_thread_t *p_input = p_intf->p_sys->p_input;
1617 var_Get( p_input, "state", &val );
1618 if( val.i_int != PAUSE_S )
1620 val.i_int = PAUSE_S;
1624 val.i_int = PLAYING_S;
1626 var_Set( p_input, "state", val );
1628 else if( p_intf->p_sys->p_playlist )
1630 playlist_Play( p_intf->p_sys->p_playlist );
1634 /****************************************************************************
1636 ****************************************************************************/
1637 static void DrawBox( WINDOW *win, int y, int x, int h, int w, char *title )
1642 if( w > 3 && h > 2 )
1644 if( title == NULL ) title = "";
1645 i_len = strlen( title );
1647 if( i_len > w - 2 ) i_len = w - 2;
1649 mvwaddch( win, y, x, ACS_ULCORNER );
1650 mvwhline( win, y, x+1, ACS_HLINE, ( w-i_len-2)/2 );
1651 mvwprintw( win,y, x+1+(w-i_len-2)/2, "%s", title );
1652 mvwhline( win, y, x+(w-i_len)/2+i_len, ACS_HLINE, w - 1 - ((w-i_len)/2+i_len) );
1653 mvwaddch( win, y, x+w-1,ACS_URCORNER );
1655 for( i = 0; i < h-2; i++ )
1657 mvwaddch( win, y+i+1, x, ACS_VLINE );
1658 mvwaddch( win, y+i+1, x+w-1, ACS_VLINE );
1661 mvwaddch( win, y+h-1, x, ACS_LLCORNER );
1662 mvwhline( win, y+h-1, x+1, ACS_HLINE, w - 2 );
1663 mvwaddch( win, y+h-1, x+w-1, ACS_LRCORNER );
1667 static void DrawEmptyLine( WINDOW *win, int y, int x, int w )
1671 mvhline( y, x, ' ', w );
1675 static void DrawLine( WINDOW *win, int y, int x, int w )
1679 attrset( A_REVERSE );
1680 mvhline( y, x, ' ', w );
1681 attroff ( A_REVERSE );