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 the directory the ncurses filebrowser " \
89 "will show you initially.")
92 set_description( _("ncurses interface") );
93 set_capability( "interface", 10 );
94 set_category( CAT_INTERFACE );
95 set_subcategory( SUBCAT_INTERFACE_GENERAL );
96 set_callbacks( Open, Close );
97 add_shortcut( "curses" );
98 add_directory( "browse-dir", NULL, NULL, BROWSE_TEXT, BROWSE_LONGTEXT, VLC_FALSE );
101 /*****************************************************************************
102 * intf_sys_t: description and status of ncurses interface
103 *****************************************************************************/
122 playlist_t *p_playlist;
123 input_thread_t *p_input;
133 int i_box_lines_total;
136 int i_box_plidx; /* Playlist index */
137 int b_box_plidx_follow;
138 int i_box_bidx; /* browser index */
142 msg_subscription_t* p_sub; /* message bank subscription */
144 char *psz_search_chain; /* for playlist searching */
145 char *psz_old_search; /* for searching next */
148 char *psz_open_chain;
150 char *psz_current_dir;
152 struct dir_entry_t **pp_dir_entries;
155 static void DrawBox( WINDOW *win, int y, int x, int h, int w, char *title );
156 static void DrawLine( WINDOW *win, int y, int x, int w );
157 static void DrawEmptyLine( WINDOW *win, int y, int x, int w );
159 /*****************************************************************************
160 * Open: initialize and create window
161 *****************************************************************************/
162 static int Open( vlc_object_t *p_this )
164 intf_thread_t *p_intf = (intf_thread_t *)p_this;
168 /* Allocate instance and initialize some members */
169 p_sys = p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
170 p_sys->p_playlist = NULL;
171 p_sys->p_input = NULL;
172 p_sys->f_slider = 0.0;
173 p_sys->f_slider_old = 0.0;
174 p_sys->i_box_type = BOX_PLAYLIST;
175 p_sys->i_box_lines = 0;
176 p_sys->i_box_start= 0;
177 p_sys->i_box_lines_total = 0;
178 p_sys->b_box_plidx_follow = VLC_TRUE;
179 p_sys->b_box_cleared = VLC_FALSE;
180 p_sys->i_box_plidx = 0;
181 p_sys->i_box_bidx = 0;
182 p_sys->p_sub = msg_Subscribe( p_intf );
184 /* Initialize the curses library */
185 p_sys->w = initscr();
186 keypad( p_sys->w, TRUE );
187 /* Don't do NL -> CR/NL */
189 /* Take input chars one at a time */
199 /* exported function */
200 p_intf->pf_run = Run;
204 var_Set( p_intf->p_vlc, "verbose", val );
206 /* Initialize search chain */
207 p_sys->psz_search_chain = (char *)malloc( SEARCH_CHAIN_SIZE + 1 );
208 p_sys->psz_old_search = NULL;
209 p_sys->i_before_search = 0;
211 /* Initialize open chain */
212 p_sys->psz_open_chain = (char *)malloc( OPEN_CHAIN_SIZE + 1 );
214 /* Initialize browser options */
215 var_Create( p_intf, "browse-dir", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
216 var_Get( p_intf, "browse-dir", &val);
218 if( val.psz_string && *val.psz_string )
220 p_sys->psz_current_dir = strdup( val.psz_string);
221 free( val.psz_string );
225 p_sys->psz_current_dir = strdup( p_intf->p_vlc->psz_homedir );
228 p_sys->i_dir_entries = 0;
229 p_sys->pp_dir_entries = NULL;
235 /*****************************************************************************
236 * Close: destroy interface window
237 *****************************************************************************/
238 static void Close( vlc_object_t *p_this )
240 intf_thread_t *p_intf = (intf_thread_t *)p_this;
241 intf_sys_t *p_sys = p_intf->p_sys;
244 for( i = 0; i < p_sys->i_dir_entries; i++ )
246 struct dir_entry_t *p_dir_entry = p_sys->pp_dir_entries[i];
247 if( p_dir_entry->psz_path ) free( p_dir_entry->psz_path );
248 REMOVE_ELEM( p_sys->pp_dir_entries, p_sys->i_dir_entries, i );
249 if( p_dir_entry ) free( p_dir_entry );
251 p_sys->pp_dir_entries = NULL;
253 if( p_sys->psz_current_dir ) free( p_sys->psz_current_dir );
254 if( p_sys->psz_search_chain ) free( p_sys->psz_search_chain );
255 if( p_sys->psz_old_search ) free( p_sys->psz_old_search );
256 if( p_sys->psz_open_chain ) free( p_sys->psz_open_chain );
260 vlc_object_release( p_sys->p_input );
262 if( p_sys->p_playlist )
264 vlc_object_release( p_sys->p_playlist );
267 /* Close the ncurses interface */
270 msg_Unsubscribe( p_intf, p_sys->p_sub );
272 /* Destroy structure */
276 /*****************************************************************************
277 * Run: ncurses thread
278 *****************************************************************************/
279 static void Run( intf_thread_t *p_intf )
281 intf_sys_t *p_sys = p_intf->p_sys;
284 time_t t_last_refresh;
287 * force drawing the interface for the first time
289 t_last_refresh = ( time( 0 ) - 1);
291 while( !p_intf->b_die )
293 msleep( INTF_IDLE_SLEEP );
295 /* Update the input */
296 if( p_sys->p_playlist == NULL )
298 p_sys->p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
300 if( p_sys->p_playlist )
302 vlc_mutex_lock( &p_sys->p_playlist->object_lock );
303 if( p_sys->p_input == NULL )
305 p_sys->p_input = p_sys->p_playlist->p_input;
308 if( !p_sys->p_input->b_dead )
310 vlc_object_yield( p_sys->p_input );
314 else if( p_sys->p_input->b_dead )
316 vlc_object_release( p_sys->p_input );
317 p_sys->p_input = NULL;
318 p_sys->f_slider = p_sys->f_slider_old = 0.0;
319 p_sys->b_box_cleared = VLC_FALSE;
321 vlc_mutex_unlock( &p_sys->p_playlist->object_lock );
324 if( p_sys->b_box_plidx_follow && p_sys->p_playlist->i_index >= 0 )
326 p_sys->i_box_plidx = p_sys->p_playlist->i_index;
329 while( ( i_key = getch()) != -1 )
332 * HandleKey returns 1 if the screen needs to be redrawn
334 if ( HandleKey( p_intf, i_key ) )
336 Redraw( p_intf, &t_last_refresh );
340 if( p_sys->f_slider > 0.0001 && !p_sys->b_box_cleared )
343 Redraw( p_intf, &t_last_refresh );
344 p_sys->b_box_cleared = VLC_TRUE;
348 * redraw the screen every second
350 if ( (time(0) - t_last_refresh) >= 1 )
352 ManageSlider ( p_intf );
353 Redraw( p_intf, &t_last_refresh );
358 /* following functions are local */
360 static int HandleKey( intf_thread_t *p_intf, int i_key )
362 intf_sys_t *p_sys = p_intf->p_sys;
365 if( p_sys->i_box_type == BOX_PLAYLIST && p_sys->p_playlist )
367 int b_ret = VLC_TRUE;
372 /* Playlist Settings */
374 var_Get( p_sys->p_playlist, "random", &val );
375 val.b_bool = !val.b_bool;
376 var_Set( p_sys->p_playlist, "random", val );
379 var_Get( p_sys->p_playlist, "loop", &val );
380 val.b_bool = !val.b_bool;
381 var_Set( p_sys->p_playlist, "loop", val );
384 var_Get( p_sys->p_playlist, "repeat", &val );
385 val.b_bool = !val.b_bool;
386 var_Set( p_sys->p_playlist, "repeat", val );
391 playlist_Sort( p_sys->p_playlist, SORT_TITLE, ORDER_NORMAL );
394 playlist_Sort( p_sys->p_playlist, SORT_TITLE, ORDER_REVERSE );
397 /* Playlist navigation */
399 p_sys->i_box_plidx = 0;
402 p_sys->i_box_plidx = p_sys->p_playlist->i_size - 1;
405 p_sys->i_box_plidx--;
408 p_sys->i_box_plidx++;
411 p_sys->i_box_plidx -= p_sys->i_box_lines;
414 p_sys->i_box_plidx += p_sys->i_box_lines;
420 int i_item = p_sys->p_playlist->i_index;
422 playlist_Delete( p_sys->p_playlist, p_sys->i_box_plidx );
423 if( i_item < p_sys->p_playlist->i_size && i_item != p_sys->p_playlist->i_index )
425 playlist_Goto( p_sys->p_playlist, i_item );
432 playlist_Goto( p_sys->p_playlist, p_sys->i_box_plidx );
441 if( p_sys->i_box_plidx >= p_sys->p_playlist->i_size ) p_sys->i_box_plidx = p_sys->p_playlist->i_size - 1;
442 if( p_sys->i_box_plidx < 0 ) p_sys->i_box_plidx = 0;
443 if( p_sys->i_box_plidx == p_sys->p_playlist->i_index )
444 p_sys->b_box_plidx_follow = VLC_TRUE;
446 p_sys->b_box_plidx_follow = VLC_FALSE;
450 if( p_sys->i_box_type == BOX_BROWSE )
452 vlc_bool_t b_ret = VLC_TRUE;
453 /* Browser navigation */
457 p_sys->i_box_bidx = 0;
460 p_sys->i_box_bidx = p_sys->i_dir_entries - 1;
469 p_sys->i_box_bidx -= p_sys->i_box_lines;
472 p_sys->i_box_bidx += p_sys->i_box_lines;
477 if( p_sys->pp_dir_entries[p_sys->i_box_bidx]->b_file )
479 int i_size_entry = strlen( p_sys->psz_current_dir ) +
480 strlen( p_sys->pp_dir_entries[p_sys->i_box_bidx]->psz_path ) + 2;
481 char *psz_uri = (char *)malloc( sizeof(char)*i_size_entry);
483 sprintf( psz_uri, "%s/%s", p_sys->psz_current_dir, p_sys->pp_dir_entries[p_sys->i_box_bidx]->psz_path );
484 playlist_Add( p_sys->p_playlist, psz_uri,
486 PLAYLIST_APPEND, PLAYLIST_END );
487 p_sys->i_box_type = BOX_PLAYLIST;
492 int i_size_entry = strlen( p_sys->psz_current_dir ) +
493 strlen( p_sys->pp_dir_entries[p_sys->i_box_bidx]->psz_path ) + 2;
494 char *psz_uri = (char *)malloc( sizeof(char)*i_size_entry);
496 sprintf( psz_uri, "%s/%s", p_sys->psz_current_dir, p_sys->pp_dir_entries[p_sys->i_box_bidx]->psz_path );
498 p_sys->psz_current_dir = strdup( psz_uri );
509 if( p_sys->i_box_bidx >= p_sys->i_dir_entries ) p_sys->i_box_bidx = p_sys->i_dir_entries - 1;
510 if( p_sys->i_box_bidx < 0 ) p_sys->i_box_bidx = 0;
514 else if( p_sys->i_box_type == BOX_HELP || p_sys->i_box_type == BOX_INFO )
519 p_sys->i_box_start = 0;
522 p_sys->i_box_start = p_sys->i_box_lines_total - 1;
525 if( p_sys->i_box_start > 0 ) p_sys->i_box_start--;
528 if( p_sys->i_box_start < p_sys->i_box_lines_total - 1 )
530 p_sys->i_box_start++;
534 p_sys->i_box_start -= p_sys->i_box_lines;
535 if( p_sys->i_box_start < 0 ) p_sys->i_box_start = 0;
538 p_sys->i_box_start += p_sys->i_box_lines;
539 if( p_sys->i_box_start >= p_sys->i_box_lines_total )
541 p_sys->i_box_start = p_sys->i_box_lines_total - 1;
548 else if( p_sys->i_box_type == BOX_NONE )
554 ManageSlider ( p_intf );
557 p_sys->f_slider = 99.9;
558 ManageSlider ( p_intf );
561 p_sys->f_slider += 5.0;
562 if( p_sys->f_slider >= 99.0 ) p_sys->f_slider = 99.0;
563 ManageSlider ( p_intf );
566 p_sys->f_slider -= 5.0;
567 if( p_sys->f_slider < 0.0 ) p_sys->f_slider = 0.0;
568 ManageSlider ( p_intf );
575 else if( p_sys->i_box_type == BOX_SEARCH && p_sys->psz_search_chain )
578 i_chain_len = strlen( p_sys->psz_search_chain );
586 if( i_chain_len > 0 )
588 p_sys->psz_old_search = strdup( p_sys->psz_search_chain );
590 else if( p_sys->psz_old_search )
592 SearchPlaylist( p_intf, p_sys->psz_old_search );
594 p_sys->i_box_type = BOX_PLAYLIST;
596 case 0x1b: /* Esc. */
597 p_sys->i_box_plidx = p_sys->i_before_search;
598 p_sys->i_box_type = BOX_PLAYLIST;
601 if( i_chain_len > 0 )
603 p_sys->psz_search_chain[ i_chain_len - 1 ] = '\0';
607 if( i_chain_len < SEARCH_CHAIN_SIZE )
609 p_sys->psz_search_chain[ i_chain_len++ ] = i_key;
610 p_sys->psz_search_chain[ i_chain_len ] = 0;
614 if( p_sys->psz_old_search )
616 free( p_sys->psz_old_search );
617 p_sys->psz_old_search = NULL;
619 SearchPlaylist( p_intf, p_sys->psz_search_chain );
622 else if( p_sys->i_box_type == BOX_OPEN && p_sys->psz_open_chain )
624 int i_chain_len = strlen( p_sys->psz_open_chain );
625 playlist_t *p_playlist = p_sys->p_playlist;
634 if( p_playlist && i_chain_len > 0 )
636 playlist_Add( p_playlist, p_sys->psz_open_chain,
637 p_sys->psz_open_chain,
638 PLAYLIST_GO|PLAYLIST_APPEND, PLAYLIST_END );
639 p_sys->b_box_plidx_follow = VLC_TRUE;
641 p_sys->i_box_type = BOX_PLAYLIST;
643 case 0x1b: /* Esc. */
644 p_sys->i_box_type = BOX_PLAYLIST;
647 if( i_chain_len > 0 )
649 p_sys->psz_open_chain[ i_chain_len - 1 ] = '\0';
653 if( i_chain_len < OPEN_CHAIN_SIZE )
655 p_sys->psz_open_chain[ i_chain_len++ ] = i_key;
656 p_sys->psz_open_chain[ i_chain_len ] = 0;
670 p_intf->p_vlc->b_die = VLC_TRUE;
675 if( p_sys->i_box_type == BOX_INFO )
676 p_sys->i_box_type = BOX_NONE;
678 p_sys->i_box_type = BOX_INFO;
679 p_sys->i_box_lines_total = 0;
682 if( p_sys->i_box_type == BOX_LOG )
683 p_sys->i_box_type = BOX_NONE;
685 p_sys->i_box_type = BOX_LOG;
688 if( p_sys->i_box_type == BOX_PLAYLIST )
689 p_sys->i_box_type = BOX_NONE;
691 p_sys->i_box_type = BOX_PLAYLIST;
694 if( p_sys->i_box_type == BOX_BROWSE )
695 p_sys->i_box_type = BOX_NONE;
697 p_sys->i_box_type = BOX_BROWSE;
701 if( p_sys->i_box_type == BOX_HELP )
702 p_sys->i_box_type = BOX_NONE;
704 p_sys->i_box_type = BOX_HELP;
705 p_sys->i_box_lines_total = 0;
708 if( p_sys->i_box_type != BOX_SEARCH )
710 if( p_sys->psz_search_chain == NULL )
714 p_sys->psz_search_chain[0] = '\0';
715 p_sys->b_box_plidx_follow = VLC_FALSE;
716 p_sys->i_before_search = p_sys->i_box_plidx;
717 p_sys->i_box_type = BOX_SEARCH;
721 if( p_sys->i_box_type != BOX_OPEN )
723 if( p_sys->psz_open_chain == NULL )
727 p_sys->psz_open_chain[0] = '\0';
728 p_sys->i_box_type = BOX_OPEN;
734 p_sys->f_slider += 1.0;
735 if( p_sys->f_slider > 99.9 ) p_sys->f_slider = 99.9;
736 ManageSlider ( p_intf );
740 p_sys->f_slider -= 1.0;
741 if( p_sys->f_slider < 0.0 ) p_sys->f_slider = 0.0;
742 ManageSlider ( p_intf );
748 vout_thread_t *p_vout;
749 if( p_intf->p_sys->p_input )
751 p_vout = vlc_object_find( p_intf->p_sys->p_input,
752 VLC_OBJECT_VOUT, FIND_CHILD );
755 p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
756 vlc_object_release( p_vout );
767 if( p_intf->p_sys->p_playlist )
769 playlist_Stop( p_intf->p_sys->p_playlist );
780 val.b_bool = VLC_TRUE;
781 var_Set( p_sys->p_input, "prev-title", val );
788 val.b_bool = VLC_TRUE;
789 var_Set( p_sys->p_input, "next-title", val );
796 val.b_bool = VLC_TRUE;
797 var_Set( p_sys->p_input, "prev-chapter", val );
804 val.b_bool = VLC_TRUE;
805 var_Set( p_sys->p_input, "next-chapter", val );
810 if( p_intf->p_sys->p_playlist )
812 playlist_Prev( p_intf->p_sys->p_playlist );
818 if( p_intf->p_sys->p_playlist )
820 playlist_Next( p_intf->p_sys->p_playlist );
826 aout_VolumeUp( p_intf, 1, NULL );
831 aout_VolumeDown( p_intf, 1, NULL );
836 * ^l should clear and redraw the screen
847 static void ManageSlider ( intf_thread_t *p_intf )
849 intf_sys_t *p_sys = p_intf->p_sys;
850 input_thread_t *p_input = p_sys->p_input;
853 if( p_input == NULL )
857 var_Get( p_input, "state", &val );
858 if( val.i_int != PLAYING_S )
863 var_Get( p_input, "position", &val );
864 if( p_sys->f_slider == p_sys->f_slider_old )
867 p_sys->f_slider_old = 100 * val.f_float;
871 p_sys->f_slider_old = p_sys->f_slider;
873 val.f_float = p_sys->f_slider / 100.0;
874 var_Set( p_input, "position", val );
878 static void SearchPlaylist( intf_thread_t *p_intf, char *psz_searchstring )
884 intf_sys_t *p_sys = p_intf->p_sys;
885 playlist_t *p_playlist = p_sys->p_playlist;
887 if( p_sys->i_before_search >= 0 )
888 i_first = p_sys->i_before_search;
890 if( ( ! psz_searchstring ) || strlen( psz_searchstring ) <= 0 )
892 p_sys->i_box_plidx = p_sys->i_before_search;
896 for( i_current = i_first + 1; i_current < p_playlist->i_size;
899 if( strcasestr( p_playlist->pp_items[i_current]->input.psz_name,
900 psz_searchstring ) != NULL
901 || strcasestr( p_playlist->pp_items[i_current]->input.psz_uri,
902 psz_searchstring ) != NULL )
911 for( i_current = 0; i_current < i_first; i_current++ )
913 if( strcasestr( p_playlist->pp_items[i_current]->input.psz_name,
914 psz_searchstring ) != NULL
915 || strcasestr( p_playlist->pp_items[i_current]->input.psz_uri,
916 psz_searchstring ) != NULL )
925 if( i_item < 0 || i_item >= p_playlist->i_size ) return;
927 p_sys->i_box_plidx = i_item;
931 static void mvnprintw( int y, int x, int w, const char *p_fmt, ... )
937 va_start ( vl_args, p_fmt );
938 vasprintf ( &p_buf, p_fmt, vl_args );
947 if( ( i_len = strlen( p_buf ) ) > w )
949 int i_cut = i_len - w;
950 int x1 = i_len/2 - i_cut/2;
955 memmove( &p_buf[x1], &p_buf[x2], i_len - x2 );
964 mvprintw( y, x, "%s", p_buf );
968 mvprintw( y, x, "%s", p_buf );
969 mvhline( y, x + i_len, ' ', w - i_len );
973 static void MainBoxWrite( intf_thread_t *p_intf, int l, int x, const char *p_fmt, ... )
975 intf_sys_t *p_sys = p_intf->p_sys;
980 if( l < p_sys->i_box_start || l - p_sys->i_box_start >= p_sys->i_box_lines )
985 va_start ( vl_args, p_fmt );
986 vasprintf ( &p_buf, p_fmt, vl_args );
994 mvnprintw( p_sys->i_box_y + l - p_sys->i_box_start, x, COLS - x - 1, "%s", p_buf );
997 static void Redraw ( intf_thread_t *p_intf, time_t *t_last_refresh )
999 intf_sys_t *p_sys = p_intf->p_sys;
1000 input_thread_t *p_input = p_sys->p_input;
1008 attrset ( A_REVERSE );
1009 mvnprintw( y, 0, COLS, "VLC media player" " (ncurses interface) [ h for help ]" );
1010 attroff ( A_REVERSE );
1014 if( p_input && !p_input->b_dead )
1016 char buf1[MSTRTIME_MAX_SIZE];
1017 char buf2[MSTRTIME_MAX_SIZE];
1019 vlc_value_t val_list;
1022 mvnprintw( y++, 0, COLS, " Source : %s",
1023 p_input->input.p_item->psz_uri );
1026 var_Get( p_input, "state", &val );
1027 if( val.i_int == PLAYING_S )
1029 mvnprintw( y++, 0, COLS, " State : Playing" );
1031 else if( val.i_int == PAUSE_S )
1033 mvnprintw( y++, 0, COLS, " State : Paused" );
1039 if( val.i_int != INIT_S && val.i_int != END_S )
1041 audio_volume_t i_volume;
1044 var_Get( p_input, "time", &val );
1045 msecstotimestr( buf1, val.i_time / 1000 );
1047 var_Get( p_input, "length", &val );
1048 msecstotimestr( buf2, val.i_time / 1000 );
1050 mvnprintw( y++, 0, COLS, " Position : %s/%s (%.2f%%)", buf1, buf2, p_sys->f_slider );
1053 aout_VolumeGet( p_intf, &i_volume );
1054 mvnprintw( y++, 0, COLS, " Volume : %i%%", i_volume*200/AOUT_VOLUME_MAX );
1057 if( !var_Get( p_input, "title", &val ) )
1059 var_Change( p_input, "title", VLC_VAR_GETCHOICES, &val_list, NULL );
1060 if( val_list.p_list->i_count > 0 )
1062 mvnprintw( y++, 0, COLS, " Title : %d/%d", val.i_int, val_list.p_list->i_count );
1064 var_Change( p_input, "title", VLC_VAR_FREELIST, &val_list, NULL );
1068 if( !var_Get( p_input, "chapter", &val ) )
1070 var_Change( p_input, "chapter", VLC_VAR_GETCHOICES, &val_list, NULL );
1071 if( val_list.p_list->i_count > 0 )
1073 mvnprintw( y++, 0, COLS, " Chapter : %d/%d", val.i_int, val_list.p_list->i_count );
1075 var_Change( p_input, "chapter", VLC_VAR_FREELIST, &val_list, NULL );
1085 mvnprintw( y++, 0, COLS, "Source: <no current item>" );
1086 DrawEmptyLine( p_sys->w, y++, 0, COLS );
1087 DrawEmptyLine( p_sys->w, y++, 0, COLS );
1088 DrawEmptyLine( p_sys->w, y++, 0, COLS );
1091 DrawBox( p_sys->w, y, 0, 3, COLS, "" );
1092 DrawEmptyLine( p_sys->w, y+1, 1, COLS-2);
1093 DrawLine( p_sys->w, y+1, 1, (int)(p_intf->p_sys->f_slider/100.0 * (COLS -2)) );
1096 p_sys->i_box_y = y + 1;
1097 p_sys->i_box_lines = LINES - y - 2;
1102 if( p_sys->i_box_type == BOX_HELP )
1106 DrawBox( p_sys->w, y++, 0, h, COLS, " Help " );
1108 MainBoxWrite( p_intf, l++, 1, "[Display]" );
1109 MainBoxWrite( p_intf, l++, 1, " h,H Show/Hide help box" );
1110 MainBoxWrite( p_intf, l++, 1, " i Show/Hide info box" );
1111 MainBoxWrite( p_intf, l++, 1, " L Show/Hide messages box" );
1112 MainBoxWrite( p_intf, l++, 1, " P Show/Hide playlist box" );
1113 MainBoxWrite( p_intf, l++, 1, " B Show/Hide filebrowser" );
1114 MainBoxWrite( p_intf, l++, 1, "" );
1116 MainBoxWrite( p_intf, l++, 1, "[Global]" );
1117 MainBoxWrite( p_intf, l++, 1, " q, Q Quit" );
1118 MainBoxWrite( p_intf, l++, 1, " s Stop" );
1119 MainBoxWrite( p_intf, l++, 1, " <space> Pause/Play" );
1120 MainBoxWrite( p_intf, l++, 1, " f Toggle Fullscreen" );
1121 MainBoxWrite( p_intf, l++, 1, " n, p Next/Previous playlist item" );
1122 MainBoxWrite( p_intf, l++, 1, " [, ] Next/Previous title" );
1123 MainBoxWrite( p_intf, l++, 1, " <, > Next/Previous chapter" );
1124 MainBoxWrite( p_intf, l++, 1, " <right> Seek +1%%" );
1125 MainBoxWrite( p_intf, l++, 1, " <left> Seek -1%%" );
1126 MainBoxWrite( p_intf, l++, 1, " a Volume Up" );
1127 MainBoxWrite( p_intf, l++, 1, " z Volume Down" );
1128 MainBoxWrite( p_intf, l++, 1, "" );
1130 MainBoxWrite( p_intf, l++, 1, "[Playlist]" );
1131 MainBoxWrite( p_intf, l++, 1, " r Random" );
1132 MainBoxWrite( p_intf, l++, 1, " l Loop Playlist" );
1133 MainBoxWrite( p_intf, l++, 1, " R Repeat item" );
1134 MainBoxWrite( p_intf, l++, 1, " o Order Playlist by title" );
1135 MainBoxWrite( p_intf, l++, 1, " O Reverse order Playlist by title" );
1136 MainBoxWrite( p_intf, l++, 1, " / Look for an item" );
1137 MainBoxWrite( p_intf, l++, 1, " A Add an entry" );
1138 MainBoxWrite( p_intf, l++, 1, " D, <del> Delete an entry" );
1139 MainBoxWrite( p_intf, l++, 1, " <backspace> Delete an entry" );
1140 MainBoxWrite( p_intf, l++, 1, "" );
1142 MainBoxWrite( p_intf, l++, 1, "[Boxes]" );
1143 MainBoxWrite( p_intf, l++, 1, " <up>,<down> Navigate through the box line by line" );
1144 MainBoxWrite( p_intf, l++, 1, " <pgup>,<pgdown> Navigate through the box page by page" );
1145 MainBoxWrite( p_intf, l++, 1, "" );
1147 MainBoxWrite( p_intf, l++, 1, "[Player]" );
1148 MainBoxWrite( p_intf, l++, 1, " <up>,<down> Seek +/-5%%" );
1149 MainBoxWrite( p_intf, l++, 1, "" );
1151 MainBoxWrite( p_intf, l++, 1, "[Miscellaneous]" );
1152 MainBoxWrite( p_intf, l++, 1, " Ctrl-l Refresh the screen" );
1154 p_sys->i_box_lines_total = l;
1155 if( p_sys->i_box_start >= p_sys->i_box_lines_total )
1157 p_sys->i_box_start = p_sys->i_box_lines_total - 1;
1160 if( l - p_sys->i_box_start < p_sys->i_box_lines )
1162 y += l - p_sys->i_box_start;
1166 y += p_sys->i_box_lines;
1169 else if( p_sys->i_box_type == BOX_INFO )
1173 DrawBox( p_sys->w, y++, 0, h, COLS, " Information " );
1178 vlc_mutex_lock( &p_input->input.p_item->lock );
1179 for ( i = 0; i < p_input->input.p_item->i_categories; i++ )
1181 info_category_t *p_category = p_input->input.p_item->pp_categories[i];
1182 if( y >= y_end ) break;
1183 MainBoxWrite( p_intf, l++, 1, " [%s]", p_category->psz_name );
1184 for ( j = 0; j < p_category->i_infos; j++ )
1186 info_t *p_info = p_category->pp_infos[j];
1187 if( y >= y_end ) break;
1188 MainBoxWrite( p_intf, l++, 1, " %s: %s", p_info->psz_name, p_info->psz_value );
1191 vlc_mutex_unlock( &p_input->input.p_item->lock );
1195 MainBoxWrite( p_intf, l++, 1, "No item currently playing" );
1197 p_sys->i_box_lines_total = l;
1198 if( p_sys->i_box_start >= p_sys->i_box_lines_total )
1200 p_sys->i_box_start = p_sys->i_box_lines_total - 1;
1203 if( l - p_sys->i_box_start < p_sys->i_box_lines )
1205 y += l - p_sys->i_box_start;
1209 y += p_sys->i_box_lines;
1212 else if( p_sys->i_box_type == BOX_LOG )
1218 DrawBox( p_sys->w, y++, 0, h, COLS, " Logs " );
1220 i_start = p_intf->p_sys->p_sub->i_start;
1222 vlc_mutex_lock( p_intf->p_sys->p_sub->p_lock );
1223 i_stop = *p_intf->p_sys->p_sub->pi_stop;
1224 vlc_mutex_unlock( p_intf->p_sys->p_sub->p_lock );
1228 static const char *ppsz_type[4] = { "", "error", "warning", "debug" };
1229 if( i_line >= h - 2 )
1235 if( i_stop < 0 ) i_stop += VLC_MSG_QSIZE;
1236 if( i_stop == i_start )
1240 mvnprintw( y + h-2-i_line, 1, COLS - 2, " [%s] %s",
1241 ppsz_type[p_sys->p_sub->p_msg[i_stop].i_type],
1242 p_sys->p_sub->p_msg[i_stop].psz_msg );
1245 vlc_mutex_lock( p_intf->p_sys->p_sub->p_lock );
1246 p_intf->p_sys->p_sub->i_start = i_stop;
1247 vlc_mutex_unlock( p_intf->p_sys->p_sub->p_lock );
1250 else if( p_sys->i_box_type == BOX_BROWSE )
1253 int i_start, i_stop;
1255 DrawBox( p_sys->w, y++, 0, h, COLS, " Browse " );
1257 if( p_sys->i_box_bidx >= p_sys->i_dir_entries ) p_sys->i_box_plidx = p_sys->i_dir_entries - 1;
1258 if( p_sys->i_box_bidx < 0 ) p_sys->i_box_bidx = 0;
1260 if( p_sys->i_box_bidx < (h - 2)/2 )
1265 else if( p_sys->i_dir_entries - p_sys->i_box_bidx > (h - 2)/2 )
1267 i_start = p_sys->i_box_bidx - (h - 2)/2;
1268 i_stop = i_start + h - 2;
1272 i_stop = p_sys->i_dir_entries;
1273 i_start = p_sys->i_dir_entries - (h - 2);
1279 if( i_stop > p_sys->i_dir_entries )
1281 i_stop = p_sys->i_dir_entries;
1284 for( i_item = i_start; i_item < i_stop; i_item++ )
1286 vlc_bool_t b_selected = ( p_sys->i_box_bidx == i_item );
1288 if( y >= y_end ) break;
1291 attrset( A_REVERSE );
1293 mvnprintw( y++, 1, COLS - 2, "%c %s", p_sys->pp_dir_entries[i_item]->b_file == VLC_TRUE ? '-' : '+',
1294 p_sys->pp_dir_entries[i_item]->psz_path );
1297 attroff ( A_REVERSE );
1302 else if( ( p_sys->i_box_type == BOX_PLAYLIST ||
1303 p_sys->i_box_type == BOX_SEARCH ||
1304 p_sys->i_box_type == BOX_OPEN ) && p_sys->p_playlist )
1307 playlist_t *p_playlist = p_sys->p_playlist;
1308 int i_start, i_stop;
1310 DrawBox( p_sys->w, y++, 0, h, COLS, " Playlist " );
1312 if( p_sys->i_box_plidx >= p_playlist->i_size ) p_sys->i_box_plidx = p_playlist->i_size - 1;
1313 if( p_sys->i_box_plidx < 0 ) p_sys->i_box_plidx = 0;
1315 if( p_sys->i_box_plidx < (h - 2)/2 )
1320 else if( p_playlist->i_size - p_sys->i_box_plidx > (h - 2)/2 )
1322 i_start = p_sys->i_box_plidx - (h - 2)/2;
1323 i_stop = i_start + h - 2;
1327 i_stop = p_playlist->i_size;
1328 i_start = p_playlist->i_size - (h - 2);
1334 if( i_stop > p_playlist->i_size )
1336 i_stop = p_playlist->i_size;
1339 for( i_item = i_start; i_item < i_stop; i_item++ )
1341 vlc_bool_t b_selected = ( p_sys->i_box_plidx == i_item );
1342 int c = p_playlist->i_index == i_item ? '>' : ' ';
1344 if( y >= y_end ) break;
1347 attrset( A_REVERSE );
1349 if( !strcmp( p_playlist->pp_items[i_item]->input.psz_name,
1350 p_playlist->pp_items[i_item]->input.psz_uri ) )
1352 mvnprintw( y++, 1, COLS - 2, "%c %d - '%s'",
1355 p_playlist->pp_items[i_item]->input.psz_uri );
1359 mvnprintw( y++, 1, COLS - 2, "%c %d - '%s' (%s)",
1362 p_playlist->pp_items[i_item]->input.psz_uri,
1363 p_playlist->pp_items[i_item]->input.psz_name );
1367 attroff ( A_REVERSE );
1375 if( p_sys->i_box_type == BOX_SEARCH )
1377 DrawEmptyLine( p_sys->w, 7, 1, COLS-2 );
1378 if( p_sys->psz_search_chain )
1380 if( strlen( p_sys->psz_search_chain ) == 0 &&
1381 p_sys->psz_old_search != NULL )
1383 /* Searching next entry */
1384 mvnprintw( 7, 1, COLS-2, "Find: %s", p_sys->psz_old_search );
1388 mvnprintw( 7, 1, COLS-2, "Find: %s", p_sys->psz_search_chain );
1392 if( p_sys->i_box_type == BOX_OPEN )
1394 if( p_sys->psz_open_chain )
1396 DrawEmptyLine( p_sys->w, 7, 1, COLS-2 );
1397 mvnprintw( 7, 1, COLS-2, "Open: %s", p_sys->psz_open_chain );
1403 DrawEmptyLine( p_sys->w, y++, 1, COLS - 2 );
1408 *t_last_refresh = time( 0 );
1411 static void Eject ( intf_thread_t *p_intf )
1413 char *psz_device = NULL, *psz_parser, *psz_name;
1416 * Get the active input
1417 * Determine whether we can eject a media, ie it's a DVD, VCD or CD-DA
1418 * If it's neither of these, then return
1421 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1424 if( p_playlist == NULL )
1429 vlc_mutex_lock( &p_playlist->object_lock );
1431 if( p_playlist->i_index < 0 )
1433 vlc_mutex_unlock( &p_playlist->object_lock );
1434 vlc_object_release( p_playlist );
1438 psz_name = p_playlist->pp_items[ p_playlist->i_index ]->input.psz_name;
1442 if( !strncmp(psz_name, "dvd://", 4) )
1444 switch( psz_name[strlen("dvd://")] )
1448 psz_device = config_GetPsz( p_intf, "dvd" );
1451 /* Omit the first MRL-selector characters */
1452 psz_device = strdup( psz_name + strlen("dvd://" ) );
1456 else if( !strncmp(psz_name, VCD_MRL, strlen(VCD_MRL)) )
1458 switch( psz_name[strlen(VCD_MRL)] )
1462 psz_device = config_GetPsz( p_intf, VCD_MRL );
1465 /* Omit the beginning MRL-selector characters */
1466 psz_device = strdup( psz_name + strlen(VCD_MRL) );
1470 else if( !strncmp(psz_name, CDDA_MRL, strlen(CDDA_MRL) ) )
1472 switch( psz_name[strlen(CDDA_MRL)] )
1476 psz_device = config_GetPsz( p_intf, "cd-audio" );
1479 /* Omit the beginning MRL-selector characters */
1480 psz_device = strdup( psz_name + strlen(CDDA_MRL) );
1486 psz_device = strdup( psz_name );
1490 vlc_mutex_unlock( &p_playlist->object_lock );
1491 vlc_object_release( p_playlist );
1493 if( psz_device == NULL )
1498 /* Remove what we have after @ */
1499 psz_parser = psz_device;
1500 for( psz_parser = psz_device ; *psz_parser ; psz_parser++ )
1502 if( *psz_parser == '@' )
1509 /* If there's a stream playing, we aren't allowed to eject ! */
1510 if( p_intf->p_sys->p_input == NULL )
1512 msg_Dbg( p_intf, "ejecting %s", psz_device );
1514 intf_Eject( p_intf, psz_device );
1521 static void ReadDir( intf_thread_t *p_intf )
1523 intf_sys_t *p_sys = p_intf->p_sys;
1524 DIR * p_current_dir;
1525 struct dirent * p_dir_content;
1528 if( p_sys->psz_current_dir && *p_sys->psz_current_dir )
1531 p_current_dir = opendir( p_sys->psz_current_dir );
1533 if( p_current_dir == NULL )
1535 /* something went bad, get out of here ! */
1537 msg_Warn( p_intf, "cannot open directory `%s' (%s)",
1538 p_sys->psz_current_dir, strerror(errno));
1540 msg_Warn( p_intf, "cannot open directory `%s'", p_sys->psz_current_dir );
1545 /* Clean the old shit */
1546 for( i = 0; i < p_sys->i_dir_entries; i++ )
1548 struct dir_entry_t *p_dir_entry = p_sys->pp_dir_entries[i];
1549 free( p_dir_entry->psz_path );
1550 REMOVE_ELEM( p_sys->pp_dir_entries, p_sys->i_dir_entries, i );
1551 free( p_dir_entry );
1553 p_sys->pp_dir_entries = NULL;
1554 p_sys->i_dir_entries = 0;
1556 /* get the first directory entry */
1557 p_dir_content = readdir( p_current_dir );
1559 /* while we still have entries in the directory */
1560 while( p_dir_content != NULL )
1562 #if defined( S_ISDIR )
1563 struct stat stat_data;
1565 struct dir_entry_t *p_dir_entry;
1566 int i_size_entry = strlen( p_sys->psz_current_dir ) +
1567 strlen( p_dir_content->d_name ) + 2;
1568 char *psz_uri = (char *)malloc( sizeof(char)*i_size_entry);
1570 sprintf( psz_uri, "%s/%s", p_sys->psz_current_dir,
1571 p_dir_content->d_name );
1573 if( !( p_dir_entry = malloc( sizeof( struct dir_entry_t) ) ) )
1579 #if defined( S_ISDIR )
1580 stat( psz_uri, &stat_data );
1581 if( S_ISDIR(stat_data.st_mode) )
1582 #elif defined( DT_DIR )
1583 if( p_dir_content->d_type & DT_DIR )
1588 p_dir_entry->psz_path = strdup( p_dir_content->d_name );
1589 p_dir_entry->b_file = VLC_FALSE;
1590 INSERT_ELEM( p_sys->pp_dir_entries, p_sys->i_dir_entries,
1591 p_sys->i_dir_entries, p_dir_entry );
1595 p_dir_entry->psz_path = strdup( p_dir_content->d_name );
1596 p_dir_entry->b_file = VLC_TRUE;
1597 INSERT_ELEM( p_sys->pp_dir_entries, p_sys->i_dir_entries,
1598 p_sys->i_dir_entries, p_dir_entry );
1602 /* Read next entry */
1603 p_dir_content = readdir( p_current_dir );
1605 closedir( p_current_dir );
1610 msg_Dbg( p_intf, "no current dir set" );
1615 static void PlayPause( intf_thread_t *p_intf )
1617 input_thread_t *p_input = p_intf->p_sys->p_input;
1622 var_Get( p_input, "state", &val );
1623 if( val.i_int != PAUSE_S )
1625 val.i_int = PAUSE_S;
1629 val.i_int = PLAYING_S;
1631 var_Set( p_input, "state", val );
1633 else if( p_intf->p_sys->p_playlist )
1635 playlist_Play( p_intf->p_sys->p_playlist );
1639 /****************************************************************************
1641 ****************************************************************************/
1642 static void DrawBox( WINDOW *win, int y, int x, int h, int w, char *title )
1647 if( w > 3 && h > 2 )
1649 if( title == NULL ) title = "";
1650 i_len = strlen( title );
1652 if( i_len > w - 2 ) i_len = w - 2;
1654 mvwaddch( win, y, x, ACS_ULCORNER );
1655 mvwhline( win, y, x+1, ACS_HLINE, ( w-i_len-2)/2 );
1656 mvwprintw( win,y, x+1+(w-i_len-2)/2, "%s", title );
1657 mvwhline( win, y, x+(w-i_len)/2+i_len, ACS_HLINE, w - 1 - ((w-i_len)/2+i_len) );
1658 mvwaddch( win, y, x+w-1,ACS_URCORNER );
1660 for( i = 0; i < h-2; i++ )
1662 mvwaddch( win, y+i+1, x, ACS_VLINE );
1663 mvwaddch( win, y+i+1, x+w-1, ACS_VLINE );
1666 mvwaddch( win, y+h-1, x, ACS_LLCORNER );
1667 mvwhline( win, y+h-1, x+1, ACS_HLINE, w - 2 );
1668 mvwaddch( win, y+h-1, x+w-1, ACS_LRCORNER );
1672 static void DrawEmptyLine( WINDOW *win, int y, int x, int w )
1676 mvhline( y, x, ' ', w );
1680 static void DrawLine( WINDOW *win, int y, int x, int w )
1684 attrset( A_REVERSE );
1685 mvhline( y, x, ' ', w );
1686 attroff ( A_REVERSE );