1 /*****************************************************************************
2 * ncurses.c : NCurses plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2001-2004 the VideoLAN team
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 PlaylistRebuild( intf_thread_t * );
79 static void PlaylistAddNode( intf_thread_t *, playlist_item_t *, int, char *);
80 static void PlaylistDestroy( intf_thread_t * );
81 static int PlaylistChanged( vlc_object_t *, const char *, vlc_value_t,
82 vlc_value_t, void * );
83 static void FindIndex ( intf_thread_t * );
84 static void SearchPlaylist ( intf_thread_t *, char * );
85 static int SubSearchPlaylist( intf_thread_t *, char *, int, int );
86 static void ManageSlider ( intf_thread_t * );
87 static void ReadDir ( intf_thread_t * );
89 /*****************************************************************************
91 *****************************************************************************/
93 #define BROWSE_TEXT N_("Filebrowser starting point")
94 #define BROWSE_LONGTEXT N_( \
95 "This option allows you to specify the directory the ncurses filebrowser " \
96 "will show you initially.")
99 set_shortname( "Ncurses" );
100 set_description( _("Ncurses interface") );
101 set_capability( "interface", 10 );
102 set_category( CAT_INTERFACE );
103 set_subcategory( SUBCAT_INTERFACE_GENERAL );
104 set_callbacks( Open, Close );
105 add_shortcut( "curses" );
106 add_directory( "browse-dir", NULL, NULL, BROWSE_TEXT, BROWSE_LONGTEXT, VLC_FALSE );
109 /*****************************************************************************
110 * intf_sys_t: description and status of ncurses interface
111 *****************************************************************************/
130 playlist_item_t *p_item;
135 playlist_t *p_playlist;
136 input_thread_t *p_input;
146 int i_box_lines_total;
149 int i_box_plidx; /* Playlist index */
150 int b_box_plidx_follow;
151 playlist_item_t *p_plnode; /* Playlist node */
152 int i_box_bidx; /* browser index */
156 msg_subscription_t* p_sub; /* message bank subscription */
158 char *psz_search_chain; /* for playlist searching */
159 char *psz_old_search; /* for searching next */
162 char *psz_open_chain;
164 char *psz_current_dir;
166 struct dir_entry_t **pp_dir_entries;
168 int i_current_view; /* playlist view */
169 struct pl_item_t **pp_plist;
171 vlc_bool_t b_need_update; /* for playlist view */
174 static void DrawBox( WINDOW *win, int y, int x, int h, int w, char *title );
175 static void DrawLine( WINDOW *win, int y, int x, int w );
176 static void DrawEmptyLine( WINDOW *win, int y, int x, int w );
178 /*****************************************************************************
179 * Open: initialize and create window
180 *****************************************************************************/
181 static int Open( vlc_object_t *p_this )
183 intf_thread_t *p_intf = (intf_thread_t *)p_this;
187 /* Allocate instance and initialize some members */
188 p_sys = p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
189 p_sys->p_playlist = NULL;
190 p_sys->p_input = NULL;
191 p_sys->f_slider = 0.0;
192 p_sys->f_slider_old = 0.0;
193 p_sys->i_box_type = BOX_PLAYLIST;
194 p_sys->i_box_lines = 0;
195 p_sys->i_box_start= 0;
196 p_sys->i_box_lines_total = 0;
197 p_sys->b_box_plidx_follow = VLC_TRUE;
198 p_sys->b_box_cleared = VLC_FALSE;
199 p_sys->i_box_plidx = 0;
200 p_sys->p_plnode = NULL;
201 p_sys->i_box_bidx = 0;
202 p_sys->p_sub = msg_Subscribe( p_intf );
204 /* Initialize the curses library */
205 p_sys->w = initscr();
206 keypad( p_sys->w, TRUE );
207 /* Don't do NL -> CR/NL */
209 /* Take input chars one at a time */
219 /* exported function */
220 p_intf->pf_run = Run;
224 var_Set( p_intf->p_vlc, "verbose", val );
226 /* Set defaul playlist view */
227 p_sys->i_current_view = VIEW_CATEGORY;
228 p_sys->pp_plist = NULL;
229 p_sys->i_plist_entries = 0;
230 p_sys->b_need_update = VLC_FALSE;
232 /* Initialize search chain */
233 p_sys->psz_search_chain = (char *)malloc( SEARCH_CHAIN_SIZE + 1 );
234 p_sys->psz_old_search = NULL;
235 p_sys->i_before_search = 0;
237 /* Initialize open chain */
238 p_sys->psz_open_chain = (char *)malloc( OPEN_CHAIN_SIZE + 1 );
240 /* Initialize browser options */
241 var_Create( p_intf, "browse-dir", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
242 var_Get( p_intf, "browse-dir", &val);
244 if( val.psz_string && *val.psz_string )
246 p_sys->psz_current_dir = strdup( val.psz_string);
247 free( val.psz_string );
251 p_sys->psz_current_dir = strdup( p_intf->p_vlc->psz_homedir );
254 p_sys->i_dir_entries = 0;
255 p_sys->pp_dir_entries = NULL;
261 /*****************************************************************************
262 * Close: destroy interface window
263 *****************************************************************************/
264 static void Close( vlc_object_t *p_this )
266 intf_thread_t *p_intf = (intf_thread_t *)p_this;
267 intf_sys_t *p_sys = p_intf->p_sys;
270 var_DelCallback( p_sys->p_playlist, "intf-change", PlaylistChanged,
272 var_DelCallback( p_sys->p_playlist, "item-append", PlaylistChanged,
275 PlaylistDestroy( p_intf );
277 for( i = 0; i < p_sys->i_dir_entries; i++ )
279 struct dir_entry_t *p_dir_entry = p_sys->pp_dir_entries[i];
280 if( p_dir_entry->psz_path ) free( p_dir_entry->psz_path );
281 REMOVE_ELEM( p_sys->pp_dir_entries, p_sys->i_dir_entries, i );
282 if( p_dir_entry ) free( p_dir_entry );
284 p_sys->pp_dir_entries = NULL;
286 if( p_sys->psz_current_dir ) free( p_sys->psz_current_dir );
287 if( p_sys->psz_search_chain ) free( p_sys->psz_search_chain );
288 if( p_sys->psz_old_search ) free( p_sys->psz_old_search );
289 if( p_sys->psz_open_chain ) free( p_sys->psz_open_chain );
293 vlc_object_release( p_sys->p_input );
295 if( p_sys->p_playlist )
297 vlc_object_release( p_sys->p_playlist );
300 /* Close the ncurses interface */
303 msg_Unsubscribe( p_intf, p_sys->p_sub );
305 /* Destroy structure */
309 /*****************************************************************************
310 * Run: ncurses thread
311 *****************************************************************************/
312 static void Run( intf_thread_t *p_intf )
314 intf_sys_t *p_sys = p_intf->p_sys;
317 time_t t_last_refresh;
320 * force drawing the interface for the first time
322 t_last_refresh = ( time( 0 ) - 1);
324 while( !p_intf->b_die )
326 msleep( INTF_IDLE_SLEEP );
328 /* Update the input */
329 if( p_sys->p_playlist == NULL )
331 p_sys->p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
333 if( p_sys->p_playlist )
335 var_AddCallback( p_sys->p_playlist, "intf-change",
336 PlaylistChanged, p_intf );
337 var_AddCallback( p_sys->p_playlist, "item-append",
338 PlaylistChanged, p_intf );
341 if( p_sys->p_playlist )
343 vlc_mutex_lock( &p_sys->p_playlist->object_lock );
344 if( p_sys->p_input == NULL )
346 p_sys->p_input = p_sys->p_playlist->p_input;
349 if( !p_sys->p_input->b_dead )
351 vlc_object_yield( p_sys->p_input );
355 else if( p_sys->p_input->b_dead )
357 vlc_object_release( p_sys->p_input );
358 p_sys->p_input = NULL;
359 p_sys->f_slider = p_sys->f_slider_old = 0.0;
360 p_sys->b_box_cleared = VLC_FALSE;
362 vlc_mutex_unlock( &p_sys->p_playlist->object_lock );
365 if( p_sys->b_box_plidx_follow && p_sys->p_playlist->i_index >= 0 )
370 while( ( i_key = getch()) != -1 )
373 * HandleKey returns 1 if the screen needs to be redrawn
375 if( HandleKey( p_intf, i_key ) )
377 Redraw( p_intf, &t_last_refresh );
381 if( p_sys->f_slider > 0.0001 && !p_sys->b_box_cleared )
384 Redraw( p_intf, &t_last_refresh );
385 p_sys->b_box_cleared = VLC_TRUE;
389 * redraw the screen every second
391 if( (time(0) - t_last_refresh) >= 1 )
393 ManageSlider( p_intf );
394 Redraw( p_intf, &t_last_refresh );
399 /* following functions are local */
401 static int HandleKey( intf_thread_t *p_intf, int i_key )
403 intf_sys_t *p_sys = p_intf->p_sys;
406 if( p_sys->i_box_type == BOX_PLAYLIST && p_sys->p_playlist )
408 int b_ret = VLC_TRUE;
413 /* Playlist Settings */
415 var_Get( p_sys->p_playlist, "random", &val );
416 val.b_bool = !val.b_bool;
417 var_Set( p_sys->p_playlist, "random", val );
420 var_Get( p_sys->p_playlist, "loop", &val );
421 val.b_bool = !val.b_bool;
422 var_Set( p_sys->p_playlist, "loop", val );
425 var_Get( p_sys->p_playlist, "repeat", &val );
426 val.b_bool = !val.b_bool;
427 var_Set( p_sys->p_playlist, "repeat", val );
432 playlist_Sort( p_sys->p_playlist, SORT_TITLE, ORDER_NORMAL );
435 playlist_Sort( p_sys->p_playlist, SORT_TITLE, ORDER_REVERSE );
440 switch( p_sys->i_current_view )
443 p_sys->i_current_view = VIEW_ALL;
446 p_sys->i_current_view = VIEW_CATEGORY;
448 PlaylistRebuild( p_intf );
452 /* Playlist navigation */
454 p_sys->i_box_plidx = 0;
457 p_sys->i_box_plidx = p_sys->p_playlist->i_size - 1;
460 p_sys->i_box_plidx--;
463 p_sys->i_box_plidx++;
466 p_sys->i_box_plidx -= p_sys->i_box_lines;
469 p_sys->i_box_plidx += p_sys->i_box_lines;
475 int i_item = p_sys->p_playlist->i_index;
477 playlist_LockDelete( p_sys->p_playlist, p_sys->i_box_plidx );
478 if( i_item < p_sys->p_playlist->i_size &&
479 i_item != p_sys->p_playlist->i_index )
481 playlist_Goto( p_sys->p_playlist, i_item );
488 if( p_sys->i_current_view == VIEW_ALL )
490 playlist_Goto( p_sys->p_playlist, p_sys->i_box_plidx );
494 if( p_sys->pp_plist[p_sys->i_box_plidx]->p_item->i_children
497 playlist_Control( p_sys->p_playlist, PLAYLIST_ITEMPLAY,
498 p_sys->pp_plist[p_sys->i_box_plidx]->p_item );
502 playlist_Control( p_sys->p_playlist, PLAYLIST_VIEWPLAY,
503 p_sys->i_current_view,
504 p_sys->pp_plist[p_sys->i_box_plidx]->p_item,
508 p_sys->b_box_plidx_follow = VLC_TRUE;
517 int i_max = p_sys->i_plist_entries;
518 if( p_sys->i_current_view == VIEW_ALL )
519 i_max = p_sys->p_playlist->i_size;
520 if( p_sys->i_box_plidx >= i_max ) p_sys->i_box_plidx = i_max - 1;
521 if( p_sys->i_box_plidx < 0 ) p_sys->i_box_plidx = 0;
522 if( p_sys->i_current_view == VIEW_ALL )
524 if( p_sys->i_box_plidx == p_sys->p_playlist->i_index )
525 p_sys->b_box_plidx_follow = VLC_TRUE;
527 p_sys->b_box_plidx_follow = VLC_FALSE;
531 if( p_sys->pp_plist[p_sys->i_box_plidx]->p_item ==
532 p_sys->p_playlist->status.p_item )
533 p_sys->b_box_plidx_follow = VLC_TRUE;
535 p_sys->b_box_plidx_follow = VLC_FALSE;
540 if( p_sys->i_box_type == BOX_BROWSE )
542 vlc_bool_t b_ret = VLC_TRUE;
543 /* Browser navigation */
547 p_sys->i_box_bidx = 0;
550 p_sys->i_box_bidx = p_sys->i_dir_entries - 1;
559 p_sys->i_box_bidx -= p_sys->i_box_lines;
562 p_sys->i_box_bidx += p_sys->i_box_lines;
567 if( p_sys->pp_dir_entries[p_sys->i_box_bidx]->b_file )
569 int i_size_entry = strlen( p_sys->psz_current_dir ) +
570 strlen( p_sys->pp_dir_entries[p_sys->i_box_bidx]->psz_path ) + 2;
571 char *psz_uri = (char *)malloc( sizeof(char)*i_size_entry);
573 sprintf( psz_uri, "%s/%s", p_sys->psz_current_dir, p_sys->pp_dir_entries[p_sys->i_box_bidx]->psz_path );
574 playlist_Add( p_sys->p_playlist, psz_uri,
576 PLAYLIST_APPEND, PLAYLIST_END );
577 p_sys->i_box_type = BOX_PLAYLIST;
582 int i_size_entry = strlen( p_sys->psz_current_dir ) +
583 strlen( p_sys->pp_dir_entries[p_sys->i_box_bidx]->psz_path ) + 2;
584 char *psz_uri = (char *)malloc( sizeof(char)*i_size_entry);
586 sprintf( psz_uri, "%s/%s", p_sys->psz_current_dir, p_sys->pp_dir_entries[p_sys->i_box_bidx]->psz_path );
588 p_sys->psz_current_dir = strdup( psz_uri );
599 if( p_sys->i_box_bidx >= p_sys->i_dir_entries ) p_sys->i_box_bidx = p_sys->i_dir_entries - 1;
600 if( p_sys->i_box_bidx < 0 ) p_sys->i_box_bidx = 0;
604 else if( p_sys->i_box_type == BOX_HELP || p_sys->i_box_type == BOX_INFO )
609 p_sys->i_box_start = 0;
612 p_sys->i_box_start = p_sys->i_box_lines_total - 1;
615 if( p_sys->i_box_start > 0 ) p_sys->i_box_start--;
618 if( p_sys->i_box_start < p_sys->i_box_lines_total - 1 )
620 p_sys->i_box_start++;
624 p_sys->i_box_start -= p_sys->i_box_lines;
625 if( p_sys->i_box_start < 0 ) p_sys->i_box_start = 0;
628 p_sys->i_box_start += p_sys->i_box_lines;
629 if( p_sys->i_box_start >= p_sys->i_box_lines_total )
631 p_sys->i_box_start = p_sys->i_box_lines_total - 1;
638 else if( p_sys->i_box_type == BOX_NONE )
644 ManageSlider( p_intf );
647 p_sys->f_slider = 99.9;
648 ManageSlider( p_intf );
651 p_sys->f_slider += 5.0;
652 if( p_sys->f_slider >= 99.0 ) p_sys->f_slider = 99.0;
653 ManageSlider( p_intf );
656 p_sys->f_slider -= 5.0;
657 if( p_sys->f_slider < 0.0 ) p_sys->f_slider = 0.0;
658 ManageSlider( p_intf );
665 else if( p_sys->i_box_type == BOX_SEARCH && p_sys->psz_search_chain )
668 i_chain_len = strlen( p_sys->psz_search_chain );
676 if( i_chain_len > 0 )
678 p_sys->psz_old_search = strdup( p_sys->psz_search_chain );
680 else if( p_sys->psz_old_search )
682 SearchPlaylist( p_intf, p_sys->psz_old_search );
684 p_sys->i_box_type = BOX_PLAYLIST;
686 case 0x1b: /* Esc. */
687 p_sys->i_box_plidx = p_sys->i_before_search;
688 p_sys->i_box_type = BOX_PLAYLIST;
691 if( i_chain_len > 0 )
693 p_sys->psz_search_chain[ i_chain_len - 1 ] = '\0';
697 if( i_chain_len < SEARCH_CHAIN_SIZE )
699 p_sys->psz_search_chain[ i_chain_len++ ] = i_key;
700 p_sys->psz_search_chain[ i_chain_len ] = 0;
704 if( p_sys->psz_old_search )
706 free( p_sys->psz_old_search );
707 p_sys->psz_old_search = NULL;
709 SearchPlaylist( p_intf, p_sys->psz_search_chain );
712 else if( p_sys->i_box_type == BOX_OPEN && p_sys->psz_open_chain )
714 int i_chain_len = strlen( p_sys->psz_open_chain );
715 playlist_t *p_playlist = p_sys->p_playlist;
724 if( p_playlist && i_chain_len > 0 )
726 playlist_Add( p_playlist, p_sys->psz_open_chain,
727 p_sys->psz_open_chain,
728 PLAYLIST_GO|PLAYLIST_APPEND, PLAYLIST_END );
729 p_sys->b_box_plidx_follow = VLC_TRUE;
731 p_sys->i_box_type = BOX_PLAYLIST;
733 case 0x1b: /* Esc. */
734 p_sys->i_box_type = BOX_PLAYLIST;
737 if( i_chain_len > 0 )
739 p_sys->psz_open_chain[ i_chain_len - 1 ] = '\0';
743 if( i_chain_len < OPEN_CHAIN_SIZE )
745 p_sys->psz_open_chain[ i_chain_len++ ] = i_key;
746 p_sys->psz_open_chain[ i_chain_len ] = 0;
760 p_intf->p_vlc->b_die = VLC_TRUE;
765 if( p_sys->i_box_type == BOX_INFO )
766 p_sys->i_box_type = BOX_NONE;
768 p_sys->i_box_type = BOX_INFO;
769 p_sys->i_box_lines_total = 0;
772 if( p_sys->i_box_type == BOX_LOG )
773 p_sys->i_box_type = BOX_NONE;
775 p_sys->i_box_type = BOX_LOG;
778 if( p_sys->i_box_type == BOX_PLAYLIST )
779 p_sys->i_box_type = BOX_NONE;
781 p_sys->i_box_type = BOX_PLAYLIST;
784 if( p_sys->i_box_type == BOX_BROWSE )
785 p_sys->i_box_type = BOX_NONE;
787 p_sys->i_box_type = BOX_BROWSE;
791 if( p_sys->i_box_type == BOX_HELP )
792 p_sys->i_box_type = BOX_NONE;
794 p_sys->i_box_type = BOX_HELP;
795 p_sys->i_box_lines_total = 0;
798 if( p_sys->i_box_type != BOX_SEARCH )
800 if( p_sys->psz_search_chain == NULL )
804 p_sys->psz_search_chain[0] = '\0';
805 p_sys->b_box_plidx_follow = VLC_FALSE;
806 p_sys->i_before_search = p_sys->i_box_plidx;
807 p_sys->i_box_type = BOX_SEARCH;
811 if( p_sys->i_box_type != BOX_OPEN )
813 if( p_sys->psz_open_chain == NULL )
817 p_sys->psz_open_chain[0] = '\0';
818 p_sys->i_box_type = BOX_OPEN;
824 p_sys->f_slider += 1.0;
825 if( p_sys->f_slider > 99.9 ) p_sys->f_slider = 99.9;
826 ManageSlider( p_intf );
830 p_sys->f_slider -= 1.0;
831 if( p_sys->f_slider < 0.0 ) p_sys->f_slider = 0.0;
832 ManageSlider( p_intf );
838 if( p_intf->p_sys->p_input )
840 vout_thread_t *p_vout;
841 p_vout = vlc_object_find( p_intf->p_sys->p_input,
842 VLC_OBJECT_VOUT, FIND_CHILD );
845 var_Get( p_vout, "fullscreen", &val );
846 val.b_bool = !val.b_bool;
847 var_Set( p_vout, "fullscreen", val );
848 vlc_object_release( p_vout );
852 playlist_t *p_playlist;
853 p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
857 var_Get( p_playlist, "fullscreen", &val );
858 val.b_bool = !val.b_bool;
859 var_Set( p_playlist, "fullscreen", val );
860 vlc_object_release( p_playlist );
872 if( p_intf->p_sys->p_playlist )
874 playlist_Stop( p_intf->p_sys->p_playlist );
885 val.b_bool = VLC_TRUE;
886 var_Set( p_sys->p_input, "prev-title", val );
893 val.b_bool = VLC_TRUE;
894 var_Set( p_sys->p_input, "next-title", val );
901 val.b_bool = VLC_TRUE;
902 var_Set( p_sys->p_input, "prev-chapter", val );
909 val.b_bool = VLC_TRUE;
910 var_Set( p_sys->p_input, "next-chapter", val );
915 if( p_intf->p_sys->p_playlist )
917 playlist_Prev( p_intf->p_sys->p_playlist );
923 if( p_intf->p_sys->p_playlist )
925 playlist_Next( p_intf->p_sys->p_playlist );
931 aout_VolumeUp( p_intf, 1, NULL );
936 aout_VolumeDown( p_intf, 1, NULL );
941 * ^l should clear and redraw the screen
952 static void ManageSlider( intf_thread_t *p_intf )
954 intf_sys_t *p_sys = p_intf->p_sys;
955 input_thread_t *p_input = p_sys->p_input;
958 if( p_input == NULL )
962 var_Get( p_input, "state", &val );
963 if( val.i_int != PLAYING_S )
968 var_Get( p_input, "position", &val );
969 if( p_sys->f_slider == p_sys->f_slider_old )
972 p_sys->f_slider_old = 100 * val.f_float;
976 p_sys->f_slider_old = p_sys->f_slider;
978 val.f_float = p_sys->f_slider / 100.0;
979 var_Set( p_input, "position", val );
983 static void SearchPlaylist( intf_thread_t *p_intf, char *psz_searchstring )
988 intf_sys_t *p_sys = p_intf->p_sys;
989 playlist_t *p_playlist = p_sys->p_playlist;
991 if( p_sys->i_before_search >= 0 )
993 i_first = p_sys->i_before_search;
996 if( ( ! psz_searchstring ) || strlen( psz_searchstring ) <= 0 )
998 p_sys->i_box_plidx = p_sys->i_before_search;
1002 i_max = p_sys->i_current_view == VIEW_ALL ?
1003 p_playlist->i_size : p_sys->i_plist_entries;
1005 i_item = SubSearchPlaylist( p_intf, psz_searchstring, i_first + 1, i_max );
1008 i_item = SubSearchPlaylist( p_intf, psz_searchstring, 0, i_first );
1011 if( i_item < 0 || i_item >= i_max ) return;
1013 p_sys->i_box_plidx = i_item;
1016 static int SubSearchPlaylist( intf_thread_t *p_intf, char *psz_searchstring,
1017 int i_start, int i_stop )
1019 intf_sys_t *p_sys = p_intf->p_sys;
1020 playlist_t *p_playlist = p_sys->p_playlist;
1023 if( p_sys->i_current_view == VIEW_ALL )
1025 for( i = i_start + 1; i < i_stop; i++ )
1027 if( strcasestr( p_playlist->pp_items[i]->input.psz_name,
1028 psz_searchstring ) != NULL
1029 || strcasestr( p_playlist->pp_items[i]->input.psz_uri,
1030 psz_searchstring ) != NULL )
1039 for( i = i_start + 1; i < i_stop; i++ )
1041 if( strcasestr( p_sys->pp_plist[i]->psz_display,
1042 psz_searchstring ) != NULL )
1054 static void mvnprintw( int y, int x, int w, const char *p_fmt, ... )
1060 va_start( vl_args, p_fmt );
1061 vasprintf( &p_buf, p_fmt, vl_args );
1070 if( ( i_len = strlen( p_buf ) ) > w )
1072 int i_cut = i_len - w;
1073 int x1 = i_len/2 - i_cut/2;
1074 int x2 = x1 + i_cut;
1078 memmove( &p_buf[x1], &p_buf[x2], i_len - x2 );
1087 mvprintw( y, x, "%s", p_buf );
1091 mvprintw( y, x, "%s", p_buf );
1092 mvhline( y, x + i_len, ' ', w - i_len );
1096 static void MainBoxWrite( intf_thread_t *p_intf, int l, int x, const char *p_fmt, ... )
1098 intf_sys_t *p_sys = p_intf->p_sys;
1103 if( l < p_sys->i_box_start || l - p_sys->i_box_start >= p_sys->i_box_lines )
1108 va_start( vl_args, p_fmt );
1109 vasprintf( &p_buf, p_fmt, vl_args );
1117 mvnprintw( p_sys->i_box_y + l - p_sys->i_box_start, x, COLS - x - 1, "%s", p_buf );
1120 static void Redraw( intf_thread_t *p_intf, time_t *t_last_refresh )
1122 intf_sys_t *p_sys = p_intf->p_sys;
1123 input_thread_t *p_input = p_sys->p_input;
1131 attrset( A_REVERSE );
1132 mvnprintw( y, 0, COLS, "VLC media player" " (ncurses interface) [ h for help ]" );
1133 attroff( A_REVERSE );
1137 if( p_input && !p_input->b_dead )
1139 char buf1[MSTRTIME_MAX_SIZE];
1140 char buf2[MSTRTIME_MAX_SIZE];
1142 vlc_value_t val_list;
1145 mvnprintw( y++, 0, COLS, " Source : %s",
1146 p_input->input.p_item->psz_uri );
1149 var_Get( p_input, "state", &val );
1150 if( val.i_int == PLAYING_S )
1152 mvnprintw( y++, 0, COLS, " State : Playing" );
1154 else if( val.i_int == PAUSE_S )
1156 mvnprintw( y++, 0, COLS, " State : Paused" );
1162 if( val.i_int != INIT_S && val.i_int != END_S )
1164 audio_volume_t i_volume;
1167 var_Get( p_input, "time", &val );
1168 msecstotimestr( buf1, val.i_time / 1000 );
1170 var_Get( p_input, "length", &val );
1171 msecstotimestr( buf2, val.i_time / 1000 );
1173 mvnprintw( y++, 0, COLS, " Position : %s/%s (%.2f%%)", buf1, buf2, p_sys->f_slider );
1176 aout_VolumeGet( p_intf, &i_volume );
1177 mvnprintw( y++, 0, COLS, " Volume : %i%%", i_volume*200/AOUT_VOLUME_MAX );
1180 if( !var_Get( p_input, "title", &val ) )
1182 var_Change( p_input, "title", VLC_VAR_GETCHOICES, &val_list, NULL );
1183 if( val_list.p_list->i_count > 0 )
1185 mvnprintw( y++, 0, COLS, " Title : %d/%d", val.i_int, val_list.p_list->i_count );
1187 var_Change( p_input, "title", VLC_VAR_FREELIST, &val_list, NULL );
1191 if( !var_Get( p_input, "chapter", &val ) )
1193 var_Change( p_input, "chapter", VLC_VAR_GETCHOICES, &val_list, NULL );
1194 if( val_list.p_list->i_count > 0 )
1196 mvnprintw( y++, 0, COLS, " Chapter : %d/%d", val.i_int, val_list.p_list->i_count );
1198 var_Change( p_input, "chapter", VLC_VAR_FREELIST, &val_list, NULL );
1208 mvnprintw( y++, 0, COLS, "Source: <no current item>" );
1209 DrawEmptyLine( p_sys->w, y++, 0, COLS );
1210 DrawEmptyLine( p_sys->w, y++, 0, COLS );
1211 DrawEmptyLine( p_sys->w, y++, 0, COLS );
1214 DrawBox( p_sys->w, y, 0, 3, COLS, "" );
1215 DrawEmptyLine( p_sys->w, y+1, 1, COLS-2);
1216 DrawLine( p_sys->w, y+1, 1, (int)(p_intf->p_sys->f_slider/100.0 * (COLS -2)) );
1219 p_sys->i_box_y = y + 1;
1220 p_sys->i_box_lines = LINES - y - 2;
1225 if( p_sys->i_box_type == BOX_HELP )
1229 DrawBox( p_sys->w, y++, 0, h, COLS, " Help " );
1231 MainBoxWrite( p_intf, l++, 1, "[Display]" );
1232 MainBoxWrite( p_intf, l++, 1, " h,H Show/Hide help box" );
1233 MainBoxWrite( p_intf, l++, 1, " i Show/Hide info box" );
1234 MainBoxWrite( p_intf, l++, 1, " L Show/Hide messages box" );
1235 MainBoxWrite( p_intf, l++, 1, " P Show/Hide playlist box" );
1236 MainBoxWrite( p_intf, l++, 1, " B Show/Hide filebrowser" );
1237 MainBoxWrite( p_intf, l++, 1, "" );
1239 MainBoxWrite( p_intf, l++, 1, "[Global]" );
1240 MainBoxWrite( p_intf, l++, 1, " q, Q Quit" );
1241 MainBoxWrite( p_intf, l++, 1, " s Stop" );
1242 MainBoxWrite( p_intf, l++, 1, " <space> Pause/Play" );
1243 MainBoxWrite( p_intf, l++, 1, " f Toggle Fullscreen" );
1244 MainBoxWrite( p_intf, l++, 1, " n, p Next/Previous playlist item" );
1245 MainBoxWrite( p_intf, l++, 1, " [, ] Next/Previous title" );
1246 MainBoxWrite( p_intf, l++, 1, " <, > Next/Previous chapter" );
1247 MainBoxWrite( p_intf, l++, 1, " <right> Seek +1%%" );
1248 MainBoxWrite( p_intf, l++, 1, " <left> Seek -1%%" );
1249 MainBoxWrite( p_intf, l++, 1, " a Volume Up" );
1250 MainBoxWrite( p_intf, l++, 1, " z Volume Down" );
1251 MainBoxWrite( p_intf, l++, 1, "" );
1253 MainBoxWrite( p_intf, l++, 1, "[Playlist]" );
1254 MainBoxWrite( p_intf, l++, 1, " r Random" );
1255 MainBoxWrite( p_intf, l++, 1, " l Loop Playlist" );
1256 MainBoxWrite( p_intf, l++, 1, " R Repeat item" );
1257 MainBoxWrite( p_intf, l++, 1, " o Order Playlist by title" );
1258 MainBoxWrite( p_intf, l++, 1, " O Reverse order Playlist by title" );
1259 MainBoxWrite( p_intf, l++, 1, " / Look for an item" );
1260 MainBoxWrite( p_intf, l++, 1, " A Add an entry" );
1261 MainBoxWrite( p_intf, l++, 1, " D, <del> Delete an entry" );
1262 MainBoxWrite( p_intf, l++, 1, " <backspace> Delete an entry" );
1263 MainBoxWrite( p_intf, l++, 1, "" );
1265 MainBoxWrite( p_intf, l++, 1, "[Boxes]" );
1266 MainBoxWrite( p_intf, l++, 1, " <up>,<down> Navigate through the box line by line" );
1267 MainBoxWrite( p_intf, l++, 1, " <pgup>,<pgdown> Navigate through the box page by page" );
1268 MainBoxWrite( p_intf, l++, 1, "" );
1270 MainBoxWrite( p_intf, l++, 1, "[Player]" );
1271 MainBoxWrite( p_intf, l++, 1, " <up>,<down> Seek +/-5%%" );
1272 MainBoxWrite( p_intf, l++, 1, "" );
1274 MainBoxWrite( p_intf, l++, 1, "[Miscellaneous]" );
1275 MainBoxWrite( p_intf, l++, 1, " Ctrl-l Refresh the screen" );
1277 p_sys->i_box_lines_total = l;
1278 if( p_sys->i_box_start >= p_sys->i_box_lines_total )
1280 p_sys->i_box_start = p_sys->i_box_lines_total - 1;
1283 if( l - p_sys->i_box_start < p_sys->i_box_lines )
1285 y += l - p_sys->i_box_start;
1289 y += p_sys->i_box_lines;
1292 else if( p_sys->i_box_type == BOX_INFO )
1296 DrawBox( p_sys->w, y++, 0, h, COLS, " Information " );
1301 vlc_mutex_lock( &p_input->input.p_item->lock );
1302 for( i = 0; i < p_input->input.p_item->i_categories; i++ )
1304 info_category_t *p_category = p_input->input.p_item->pp_categories[i];
1305 if( y >= y_end ) break;
1306 MainBoxWrite( p_intf, l++, 1, " [%s]", p_category->psz_name );
1307 for( j = 0; j < p_category->i_infos; j++ )
1309 info_t *p_info = p_category->pp_infos[j];
1310 if( y >= y_end ) break;
1311 MainBoxWrite( p_intf, l++, 1, " %s: %s", p_info->psz_name, p_info->psz_value );
1314 vlc_mutex_unlock( &p_input->input.p_item->lock );
1318 MainBoxWrite( p_intf, l++, 1, "No item currently playing" );
1320 p_sys->i_box_lines_total = l;
1321 if( p_sys->i_box_start >= p_sys->i_box_lines_total )
1323 p_sys->i_box_start = p_sys->i_box_lines_total - 1;
1326 if( l - p_sys->i_box_start < p_sys->i_box_lines )
1328 y += l - p_sys->i_box_start;
1332 y += p_sys->i_box_lines;
1335 else if( p_sys->i_box_type == BOX_LOG )
1341 DrawBox( p_sys->w, y++, 0, h, COLS, " Logs " );
1343 i_start = p_intf->p_sys->p_sub->i_start;
1345 vlc_mutex_lock( p_intf->p_sys->p_sub->p_lock );
1346 i_stop = *p_intf->p_sys->p_sub->pi_stop;
1347 vlc_mutex_unlock( p_intf->p_sys->p_sub->p_lock );
1351 static const char *ppsz_type[4] = { "", "error", "warning", "debug" };
1352 if( i_line >= h - 2 )
1358 if( i_stop < 0 ) i_stop += VLC_MSG_QSIZE;
1359 if( i_stop == i_start )
1363 mvnprintw( y + h-2-i_line, 1, COLS - 2, " [%s] %s",
1364 ppsz_type[p_sys->p_sub->p_msg[i_stop].i_type],
1365 p_sys->p_sub->p_msg[i_stop].psz_msg );
1368 vlc_mutex_lock( p_intf->p_sys->p_sub->p_lock );
1369 p_intf->p_sys->p_sub->i_start = i_stop;
1370 vlc_mutex_unlock( p_intf->p_sys->p_sub->p_lock );
1373 else if( p_sys->i_box_type == BOX_BROWSE )
1375 /* Filebrowser box */
1376 int i_start, i_stop;
1378 DrawBox( p_sys->w, y++, 0, h, COLS, " Browse " );
1380 if( p_sys->i_box_bidx >= p_sys->i_dir_entries ) p_sys->i_box_plidx = p_sys->i_dir_entries - 1;
1381 if( p_sys->i_box_bidx < 0 ) p_sys->i_box_bidx = 0;
1383 if( p_sys->i_box_bidx < (h - 2)/2 )
1388 else if( p_sys->i_dir_entries - p_sys->i_box_bidx > (h - 2)/2 )
1390 i_start = p_sys->i_box_bidx - (h - 2)/2;
1391 i_stop = i_start + h - 2;
1395 i_stop = p_sys->i_dir_entries;
1396 i_start = p_sys->i_dir_entries - (h - 2);
1402 if( i_stop > p_sys->i_dir_entries )
1404 i_stop = p_sys->i_dir_entries;
1407 for( i_item = i_start; i_item < i_stop; i_item++ )
1409 vlc_bool_t b_selected = ( p_sys->i_box_bidx == i_item );
1411 if( y >= y_end ) break;
1414 attrset( A_REVERSE );
1416 mvnprintw( y++, 1, COLS - 2, "%c %s", p_sys->pp_dir_entries[i_item]->b_file == VLC_TRUE ? '-' : '+',
1417 p_sys->pp_dir_entries[i_item]->psz_path );
1420 attroff( A_REVERSE );
1425 else if( ( p_sys->i_box_type == BOX_PLAYLIST ||
1426 p_sys->i_box_type == BOX_SEARCH ||
1427 p_sys->i_box_type == BOX_OPEN ) && p_sys->p_playlist )
1430 playlist_t *p_playlist = p_sys->p_playlist;
1431 int i_start, i_stop, i_max = p_sys->i_plist_entries;
1435 switch( p_sys->i_current_view )
1438 psz_title = strdup( " Playlist (All, unsorted) " );
1439 i_max = p_playlist->i_size;
1442 psz_title = strdup( " Playlist (By category) " );
1445 psz_title = strdup( " Playlist (Manually added) " );
1448 DrawBox( p_sys->w, y++, 0, h, COLS, psz_title );
1450 if( p_sys->i_current_view != VIEW_ALL &&
1451 ( p_sys->b_need_update || p_sys->pp_plist == NULL ) )
1453 PlaylistRebuild( p_intf );
1455 if( p_sys->b_box_plidx_follow )
1457 FindIndex( p_intf );
1460 if( p_sys->i_box_plidx < 0 ) p_sys->i_box_plidx = 0;
1462 if( p_sys->i_box_plidx < (h - 2)/2 )
1467 else if( i_max - p_sys->i_box_plidx > (h - 2)/2 )
1469 i_start = p_sys->i_box_plidx - (h - 2)/2;
1470 i_stop = i_start + h - 2;
1475 i_start = i_max - (h - 2);
1481 if( i_stop > i_max )
1486 if( p_sys->i_current_view == VIEW_ALL )
1489 for( i_item = i_start; i_item < i_stop; i_item++ )
1491 vlc_bool_t b_selected = ( p_sys->i_box_plidx == i_item );
1492 int c = p_playlist->i_index == i_item ? '>' : ' ';
1494 if( y >= y_end ) break;
1497 attrset( A_REVERSE );
1499 if( !strcmp( p_playlist->pp_items[i_item]->input.psz_name,
1500 p_playlist->pp_items[i_item]->input.psz_uri ) )
1502 mvnprintw( y++, 1, COLS - 2, "%c %d - '%s'",
1505 p_playlist->pp_items[i_item]->input.psz_uri );
1509 mvnprintw( y++, 1, COLS - 2, "%c %d - '%s' (%s)",
1512 p_playlist->pp_items[i_item]->input.psz_uri,
1513 p_playlist->pp_items[i_item]->input.psz_name );
1517 attroff( A_REVERSE );
1525 for( i_item = i_start; i_item < i_stop; i_item++ )
1527 vlc_bool_t b_selected = ( p_sys->i_box_plidx == i_item );
1528 int c = ( p_playlist->status.p_item ==
1529 p_sys->pp_plist[i_item]->p_item ) ? '>' : ' ';
1531 if( y >= y_end ) break;
1534 attrset( A_REVERSE );
1536 mvnprintw( y++, 1, COLS - 2, "%c%s", c,
1537 p_sys->pp_plist[i_item]->psz_display );
1540 attroff( A_REVERSE );
1550 if( p_sys->i_box_type == BOX_SEARCH )
1552 DrawEmptyLine( p_sys->w, 7, 1, COLS-2 );
1553 if( p_sys->psz_search_chain )
1555 if( strlen( p_sys->psz_search_chain ) == 0 &&
1556 p_sys->psz_old_search != NULL )
1558 /* Searching next entry */
1559 mvnprintw( 7, 1, COLS-2, "Find: %s", p_sys->psz_old_search );
1563 mvnprintw( 7, 1, COLS-2, "Find: %s", p_sys->psz_search_chain );
1567 if( p_sys->i_box_type == BOX_OPEN )
1569 if( p_sys->psz_open_chain )
1571 DrawEmptyLine( p_sys->w, 7, 1, COLS-2 );
1572 mvnprintw( 7, 1, COLS-2, "Open: %s", p_sys->psz_open_chain );
1578 DrawEmptyLine( p_sys->w, y++, 1, COLS - 2 );
1583 *t_last_refresh = time( 0 );
1586 static void PlaylistRebuild( intf_thread_t *p_intf )
1588 intf_sys_t *p_sys = p_intf->p_sys;
1589 playlist_view_t *p_view;
1590 playlist_t *p_playlist = p_sys->p_playlist;
1592 if( p_playlist == NULL )
1597 vlc_mutex_lock( &p_playlist->object_lock );
1599 p_view = playlist_ViewFind( p_playlist, p_intf->p_sys->i_current_view );
1601 /* First clear the old one */
1602 PlaylistDestroy( p_intf );
1604 /* Build the new one */
1605 PlaylistAddNode( p_intf, p_view->p_root, 0, "" );
1607 p_sys->b_need_update = VLC_FALSE;
1609 vlc_mutex_unlock( &p_playlist->object_lock );
1612 static void PlaylistAddNode( intf_thread_t *p_intf, playlist_item_t *p_node,
1615 intf_sys_t *p_sys = p_intf->p_sys;
1616 playlist_item_t *p_child;
1620 psz_tmp = (char *)malloc( strlen( c ) + 4 );
1621 if( psz_tmp == NULL ) return;
1622 for( k = 0; k < p_node->i_children; k++ )
1624 struct pl_item_t *p_pl_item;
1628 p_child = p_node->pp_children[k];
1629 i_size = strlen( c ) + strlen( p_child->input.psz_name ) + 4;
1630 buff = (char *)malloc( sizeof( char ) * i_size );
1631 p_pl_item = (struct pl_item_t *)malloc( sizeof( struct pl_item_t ) );
1632 if( p_pl_item == NULL || buff == NULL ) return;
1636 sprintf( buff, "%s%c-%s", c, k == p_node->i_children - 1 ?
1637 '`' : '|', p_child->input.psz_name );
1641 sprintf( buff, " %s", p_child->input.psz_name );
1643 p_pl_item->psz_display = strdup( buff );
1644 p_pl_item->p_item = p_child;
1645 INSERT_ELEM( p_sys->pp_plist, p_sys->i_plist_entries,
1646 p_sys->i_plist_entries, p_pl_item );
1650 if( p_child->i_children > 0 )
1652 sprintf( psz_tmp, "%s%c ", c,
1653 k == p_node->i_children - 1 ? ' ' : '|' );
1654 PlaylistAddNode( p_intf, p_child, i,
1655 strlen( c ) ? psz_tmp : " " );
1661 static int PlaylistChanged( vlc_object_t *p_this, const char *psz_variable,
1662 vlc_value_t oval, vlc_value_t nval, void *param )
1664 intf_thread_t *p_intf = (intf_thread_t *)param;
1665 p_intf->p_sys->b_need_update = VLC_TRUE;
1669 static void FindIndex( intf_thread_t *p_intf )
1671 intf_sys_t *p_sys = p_intf->p_sys;
1674 if( p_sys->i_current_view == VIEW_ALL )
1676 p_sys->i_box_plidx = p_sys->p_playlist->i_index;
1678 else if( ( p_sys->i_box_plidx < p_sys->i_plist_entries &&
1679 p_sys->pp_plist[p_sys->i_box_plidx]->p_item !=
1680 p_sys->p_playlist->status.p_item ) )
1682 for( i = 0; i < p_sys->i_plist_entries; i++ )
1684 if( p_sys->pp_plist[i]->p_item ==
1685 p_sys->p_playlist->status.p_item )
1687 p_sys->i_box_plidx = i;
1694 static void PlaylistDestroy( intf_thread_t *p_intf )
1696 intf_sys_t *p_sys = p_intf->p_sys;
1699 for( i = 0; i < p_sys->i_plist_entries; i++ )
1701 struct pl_item_t *p_pl_item = p_sys->pp_plist[i];
1702 free( p_pl_item->psz_display );
1703 REMOVE_ELEM( p_sys->pp_plist, p_sys->i_plist_entries, i );
1706 p_sys->pp_plist = NULL;
1707 p_sys->i_plist_entries = 0;
1710 static void Eject( intf_thread_t *p_intf )
1712 char *psz_device = NULL, *psz_parser, *psz_name;
1715 * Get the active input
1716 * Determine whether we can eject a media, ie it's a DVD, VCD or CD-DA
1717 * If it's neither of these, then return
1720 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1723 if( p_playlist == NULL )
1728 vlc_mutex_lock( &p_playlist->object_lock );
1730 if( p_playlist->i_index < 0 )
1732 vlc_mutex_unlock( &p_playlist->object_lock );
1733 vlc_object_release( p_playlist );
1737 psz_name = p_playlist->pp_items[ p_playlist->i_index ]->input.psz_name;
1741 if( !strncmp(psz_name, "dvd://", 4) )
1743 switch( psz_name[strlen("dvd://")] )
1747 psz_device = config_GetPsz( p_intf, "dvd" );
1750 /* Omit the first MRL-selector characters */
1751 psz_device = strdup( psz_name + strlen("dvd://" ) );
1755 else if( !strncmp(psz_name, VCD_MRL, strlen(VCD_MRL)) )
1757 switch( psz_name[strlen(VCD_MRL)] )
1761 psz_device = config_GetPsz( p_intf, VCD_MRL );
1764 /* Omit the beginning MRL-selector characters */
1765 psz_device = strdup( psz_name + strlen(VCD_MRL) );
1769 else if( !strncmp(psz_name, CDDA_MRL, strlen(CDDA_MRL) ) )
1771 switch( psz_name[strlen(CDDA_MRL)] )
1775 psz_device = config_GetPsz( p_intf, "cd-audio" );
1778 /* Omit the beginning MRL-selector characters */
1779 psz_device = strdup( psz_name + strlen(CDDA_MRL) );
1785 psz_device = strdup( psz_name );
1789 vlc_mutex_unlock( &p_playlist->object_lock );
1790 vlc_object_release( p_playlist );
1792 if( psz_device == NULL )
1797 /* Remove what we have after @ */
1798 psz_parser = psz_device;
1799 for( psz_parser = psz_device ; *psz_parser ; psz_parser++ )
1801 if( *psz_parser == '@' )
1808 /* If there's a stream playing, we aren't allowed to eject ! */
1809 if( p_intf->p_sys->p_input == NULL )
1811 msg_Dbg( p_intf, "ejecting %s", psz_device );
1813 intf_Eject( p_intf, psz_device );
1820 static void ReadDir( intf_thread_t *p_intf )
1822 intf_sys_t *p_sys = p_intf->p_sys;
1823 DIR * p_current_dir;
1824 struct dirent * p_dir_content;
1827 if( p_sys->psz_current_dir && *p_sys->psz_current_dir )
1830 p_current_dir = opendir( p_sys->psz_current_dir );
1832 if( p_current_dir == NULL )
1834 /* something went bad, get out of here ! */
1836 msg_Warn( p_intf, "cannot open directory `%s' (%s)",
1837 p_sys->psz_current_dir, strerror(errno));
1839 msg_Warn( p_intf, "cannot open directory `%s'", p_sys->psz_current_dir );
1844 /* Clean the old shit */
1845 for( i = 0; i < p_sys->i_dir_entries; i++ )
1847 struct dir_entry_t *p_dir_entry = p_sys->pp_dir_entries[i];
1848 free( p_dir_entry->psz_path );
1849 REMOVE_ELEM( p_sys->pp_dir_entries, p_sys->i_dir_entries, i );
1850 free( p_dir_entry );
1852 p_sys->pp_dir_entries = NULL;
1853 p_sys->i_dir_entries = 0;
1855 /* get the first directory entry */
1856 p_dir_content = readdir( p_current_dir );
1858 /* while we still have entries in the directory */
1859 while( p_dir_content != NULL )
1861 #if defined( S_ISDIR )
1862 struct stat stat_data;
1864 struct dir_entry_t *p_dir_entry;
1865 int i_size_entry = strlen( p_sys->psz_current_dir ) +
1866 strlen( p_dir_content->d_name ) + 2;
1867 char *psz_uri = (char *)malloc( sizeof(char)*i_size_entry);
1869 sprintf( psz_uri, "%s/%s", p_sys->psz_current_dir,
1870 p_dir_content->d_name );
1872 if( !( p_dir_entry = malloc( sizeof( struct dir_entry_t) ) ) )
1878 #if defined( S_ISDIR )
1879 stat( psz_uri, &stat_data );
1880 if( S_ISDIR(stat_data.st_mode) )
1881 #elif defined( DT_DIR )
1882 if( p_dir_content->d_type & DT_DIR )
1887 p_dir_entry->psz_path = strdup( p_dir_content->d_name );
1888 p_dir_entry->b_file = VLC_FALSE;
1889 INSERT_ELEM( p_sys->pp_dir_entries, p_sys->i_dir_entries,
1890 p_sys->i_dir_entries, p_dir_entry );
1894 p_dir_entry->psz_path = strdup( p_dir_content->d_name );
1895 p_dir_entry->b_file = VLC_TRUE;
1896 INSERT_ELEM( p_sys->pp_dir_entries, p_sys->i_dir_entries,
1897 p_sys->i_dir_entries, p_dir_entry );
1901 /* Read next entry */
1902 p_dir_content = readdir( p_current_dir );
1904 closedir( p_current_dir );
1909 msg_Dbg( p_intf, "no current dir set" );
1914 static void PlayPause( intf_thread_t *p_intf )
1916 input_thread_t *p_input = p_intf->p_sys->p_input;
1921 var_Get( p_input, "state", &val );
1922 if( val.i_int != PAUSE_S )
1924 val.i_int = PAUSE_S;
1928 val.i_int = PLAYING_S;
1930 var_Set( p_input, "state", val );
1932 else if( p_intf->p_sys->p_playlist )
1934 playlist_Play( p_intf->p_sys->p_playlist );
1938 /****************************************************************************
1940 ****************************************************************************/
1941 static void DrawBox( WINDOW *win, int y, int x, int h, int w, char *title )
1946 if( w > 3 && h > 2 )
1948 if( title == NULL ) title = "";
1949 i_len = strlen( title );
1951 if( i_len > w - 2 ) i_len = w - 2;
1953 mvwaddch( win, y, x, ACS_ULCORNER );
1954 mvwhline( win, y, x+1, ACS_HLINE, ( w-i_len-2)/2 );
1955 mvwprintw( win,y, x+1+(w-i_len-2)/2, "%s", title );
1956 mvwhline( win, y, x+(w-i_len)/2+i_len, ACS_HLINE, w - 1 - ((w-i_len)/2+i_len) );
1957 mvwaddch( win, y, x+w-1,ACS_URCORNER );
1959 for( i = 0; i < h-2; i++ )
1961 mvwaddch( win, y+i+1, x, ACS_VLINE );
1962 mvwaddch( win, y+i+1, x+w-1, ACS_VLINE );
1965 mvwaddch( win, y+h-1, x, ACS_LLCORNER );
1966 mvwhline( win, y+h-1, x+1, ACS_HLINE, w - 2 );
1967 mvwaddch( win, y+h-1, x+w-1, ACS_LRCORNER );
1971 static void DrawEmptyLine( WINDOW *win, int y, int x, int w )
1975 mvhline( y, x, ' ', w );
1979 static void DrawLine( WINDOW *win, int y, int x, int w )
1983 attrset( A_REVERSE );
1984 mvhline( y, x, ' ', w );
1985 attroff( A_REVERSE );