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;
167 vlc_bool_t b_show_hidden_files;
169 int i_current_view; /* playlist view */
170 struct pl_item_t **pp_plist;
172 vlc_bool_t b_need_update; /* for playlist view */
175 static void DrawBox( WINDOW *win, int y, int x, int h, int w, char *title );
176 static void DrawLine( WINDOW *win, int y, int x, int w );
177 static void DrawEmptyLine( WINDOW *win, int y, int x, int w );
179 /*****************************************************************************
180 * Open: initialize and create window
181 *****************************************************************************/
182 static int Open( vlc_object_t *p_this )
184 intf_thread_t *p_intf = (intf_thread_t *)p_this;
188 /* Allocate instance and initialize some members */
189 p_sys = p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
190 p_sys->p_playlist = NULL;
191 p_sys->p_input = NULL;
192 p_sys->f_slider = 0.0;
193 p_sys->f_slider_old = 0.0;
194 p_sys->i_box_type = BOX_PLAYLIST;
195 p_sys->i_box_lines = 0;
196 p_sys->i_box_start= 0;
197 p_sys->i_box_lines_total = 0;
198 p_sys->b_box_plidx_follow = VLC_TRUE;
199 p_sys->b_box_cleared = VLC_FALSE;
200 p_sys->i_box_plidx = 0;
201 p_sys->p_plnode = NULL;
202 p_sys->i_box_bidx = 0;
203 p_sys->p_sub = msg_Subscribe( p_intf );
205 /* Initialize the curses library */
206 p_sys->w = initscr();
207 keypad( p_sys->w, TRUE );
208 /* Don't do NL -> CR/NL */
210 /* Take input chars one at a time */
220 /* exported function */
221 p_intf->pf_run = Run;
225 var_Set( p_intf->p_vlc, "verbose", val );
227 /* Set defaul playlist view */
228 p_sys->i_current_view = VIEW_CATEGORY;
229 p_sys->pp_plist = NULL;
230 p_sys->i_plist_entries = 0;
231 p_sys->b_need_update = VLC_FALSE;
233 /* Initialize search chain */
234 p_sys->psz_search_chain = (char *)malloc( SEARCH_CHAIN_SIZE + 1 );
235 p_sys->psz_old_search = NULL;
236 p_sys->i_before_search = 0;
238 /* Initialize open chain */
239 p_sys->psz_open_chain = (char *)malloc( OPEN_CHAIN_SIZE + 1 );
241 /* Initialize browser options */
242 var_Create( p_intf, "browse-dir", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
243 var_Get( p_intf, "browse-dir", &val);
245 if( val.psz_string && *val.psz_string )
247 p_sys->psz_current_dir = strdup( val.psz_string);
248 free( val.psz_string );
252 p_sys->psz_current_dir = strdup( p_intf->p_vlc->psz_homedir );
255 p_sys->i_dir_entries = 0;
256 p_sys->pp_dir_entries = NULL;
257 p_sys->b_show_hidden_files = VLC_FALSE;
263 /*****************************************************************************
264 * Close: destroy interface window
265 *****************************************************************************/
266 static void Close( vlc_object_t *p_this )
268 intf_thread_t *p_intf = (intf_thread_t *)p_this;
269 intf_sys_t *p_sys = p_intf->p_sys;
272 var_DelCallback( p_sys->p_playlist, "intf-change", PlaylistChanged,
274 var_DelCallback( p_sys->p_playlist, "item-append", PlaylistChanged,
277 PlaylistDestroy( p_intf );
279 for( i = 0; i < p_sys->i_dir_entries; i++ )
281 struct dir_entry_t *p_dir_entry = p_sys->pp_dir_entries[i];
282 if( p_dir_entry->psz_path ) free( p_dir_entry->psz_path );
283 REMOVE_ELEM( p_sys->pp_dir_entries, p_sys->i_dir_entries, i );
284 if( p_dir_entry ) free( p_dir_entry );
286 p_sys->pp_dir_entries = NULL;
288 if( p_sys->psz_current_dir ) free( p_sys->psz_current_dir );
289 if( p_sys->psz_search_chain ) free( p_sys->psz_search_chain );
290 if( p_sys->psz_old_search ) free( p_sys->psz_old_search );
291 if( p_sys->psz_open_chain ) free( p_sys->psz_open_chain );
295 vlc_object_release( p_sys->p_input );
297 if( p_sys->p_playlist )
299 vlc_object_release( p_sys->p_playlist );
302 /* Close the ncurses interface */
305 msg_Unsubscribe( p_intf, p_sys->p_sub );
307 /* Destroy structure */
311 /*****************************************************************************
312 * Run: ncurses thread
313 *****************************************************************************/
314 static void Run( intf_thread_t *p_intf )
316 intf_sys_t *p_sys = p_intf->p_sys;
319 time_t t_last_refresh;
322 * force drawing the interface for the first time
324 t_last_refresh = ( time( 0 ) - 1);
326 while( !p_intf->b_die )
328 msleep( INTF_IDLE_SLEEP );
330 /* Update the input */
331 if( p_sys->p_playlist == NULL )
333 p_sys->p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
335 if( p_sys->p_playlist )
337 var_AddCallback( p_sys->p_playlist, "intf-change",
338 PlaylistChanged, p_intf );
339 var_AddCallback( p_sys->p_playlist, "item-append",
340 PlaylistChanged, p_intf );
343 if( p_sys->p_playlist )
345 vlc_mutex_lock( &p_sys->p_playlist->object_lock );
346 if( p_sys->p_input == NULL )
348 p_sys->p_input = p_sys->p_playlist->p_input;
351 if( !p_sys->p_input->b_dead )
353 vlc_object_yield( p_sys->p_input );
357 else if( p_sys->p_input->b_dead )
359 vlc_object_release( p_sys->p_input );
360 p_sys->p_input = NULL;
361 p_sys->f_slider = p_sys->f_slider_old = 0.0;
362 p_sys->b_box_cleared = VLC_FALSE;
364 vlc_mutex_unlock( &p_sys->p_playlist->object_lock );
367 if( p_sys->b_box_plidx_follow && p_sys->p_playlist->i_index >= 0 )
372 while( ( i_key = getch()) != -1 )
375 * HandleKey returns 1 if the screen needs to be redrawn
377 if( HandleKey( p_intf, i_key ) )
379 Redraw( p_intf, &t_last_refresh );
383 if( p_sys->f_slider > 0.0001 && !p_sys->b_box_cleared )
386 Redraw( p_intf, &t_last_refresh );
387 p_sys->b_box_cleared = VLC_TRUE;
391 * redraw the screen every second
393 if( (time(0) - t_last_refresh) >= 1 )
395 ManageSlider( p_intf );
396 Redraw( p_intf, &t_last_refresh );
401 /* following functions are local */
403 static int HandleKey( intf_thread_t *p_intf, int i_key )
405 intf_sys_t *p_sys = p_intf->p_sys;
408 if( p_sys->i_box_type == BOX_PLAYLIST && p_sys->p_playlist )
410 int b_ret = VLC_TRUE;
415 /* Playlist Settings */
417 var_Get( p_sys->p_playlist, "random", &val );
418 val.b_bool = !val.b_bool;
419 var_Set( p_sys->p_playlist, "random", val );
422 var_Get( p_sys->p_playlist, "loop", &val );
423 val.b_bool = !val.b_bool;
424 var_Set( p_sys->p_playlist, "loop", val );
427 var_Get( p_sys->p_playlist, "repeat", &val );
428 val.b_bool = !val.b_bool;
429 var_Set( p_sys->p_playlist, "repeat", val );
434 playlist_Sort( p_sys->p_playlist, SORT_TITLE, ORDER_NORMAL );
437 playlist_Sort( p_sys->p_playlist, SORT_TITLE, ORDER_REVERSE );
442 switch( p_sys->i_current_view )
445 p_sys->i_current_view = VIEW_ALL;
448 p_sys->i_current_view = VIEW_CATEGORY;
450 PlaylistRebuild( p_intf );
454 /* Playlist navigation */
456 p_sys->i_box_plidx = 0;
459 p_sys->i_box_plidx = p_sys->p_playlist->i_size - 1;
462 p_sys->i_box_plidx--;
465 p_sys->i_box_plidx++;
468 p_sys->i_box_plidx -= p_sys->i_box_lines;
471 p_sys->i_box_plidx += p_sys->i_box_lines;
477 int i_item = p_sys->p_playlist->i_index;
479 playlist_LockDelete( p_sys->p_playlist, p_sys->i_box_plidx );
480 if( i_item < p_sys->p_playlist->i_size &&
481 i_item != p_sys->p_playlist->i_index )
483 playlist_Goto( p_sys->p_playlist, i_item );
490 if( p_sys->i_current_view == VIEW_ALL )
492 playlist_Goto( p_sys->p_playlist, p_sys->i_box_plidx );
496 if( p_sys->pp_plist[p_sys->i_box_plidx]->p_item->i_children
499 playlist_Control( p_sys->p_playlist, PLAYLIST_ITEMPLAY,
500 p_sys->pp_plist[p_sys->i_box_plidx]->p_item );
504 playlist_Control( p_sys->p_playlist, PLAYLIST_VIEWPLAY,
505 p_sys->i_current_view,
506 p_sys->pp_plist[p_sys->i_box_plidx]->p_item,
510 p_sys->b_box_plidx_follow = VLC_TRUE;
519 int i_max = p_sys->i_plist_entries;
520 if( p_sys->i_current_view == VIEW_ALL )
521 i_max = p_sys->p_playlist->i_size;
522 if( p_sys->i_box_plidx >= i_max ) p_sys->i_box_plidx = i_max - 1;
523 if( p_sys->i_box_plidx < 0 ) p_sys->i_box_plidx = 0;
524 if( p_sys->i_current_view == VIEW_ALL )
526 if( p_sys->i_box_plidx == p_sys->p_playlist->i_index )
527 p_sys->b_box_plidx_follow = VLC_TRUE;
529 p_sys->b_box_plidx_follow = VLC_FALSE;
533 if( p_sys->pp_plist[p_sys->i_box_plidx]->p_item ==
534 p_sys->p_playlist->status.p_item )
535 p_sys->b_box_plidx_follow = VLC_TRUE;
537 p_sys->b_box_plidx_follow = VLC_FALSE;
542 if( p_sys->i_box_type == BOX_BROWSE )
544 vlc_bool_t b_ret = VLC_TRUE;
545 /* Browser navigation */
549 p_sys->i_box_bidx = 0;
552 p_sys->i_box_bidx = p_sys->i_dir_entries - 1;
561 p_sys->i_box_bidx -= p_sys->i_box_lines;
564 p_sys->i_box_bidx += p_sys->i_box_lines;
566 case '.': /* Toggle show hidden files */
567 p_sys->b_show_hidden_files = ( p_sys->b_show_hidden_files ==
568 VLC_TRUE ? VLC_FALSE : VLC_TRUE );
575 if( p_sys->pp_dir_entries[p_sys->i_box_bidx]->b_file || i_key == ' ' )
577 int i_size_entry = strlen( p_sys->psz_current_dir ) +
578 strlen( p_sys->pp_dir_entries[p_sys->i_box_bidx]->psz_path ) + 2;
579 char *psz_uri = (char *)malloc( sizeof(char)*i_size_entry);
581 sprintf( psz_uri, "%s/%s", p_sys->psz_current_dir, p_sys->pp_dir_entries[p_sys->i_box_bidx]->psz_path );
582 playlist_Add( p_sys->p_playlist, psz_uri,
584 PLAYLIST_APPEND, PLAYLIST_END );
585 p_sys->i_box_type = BOX_PLAYLIST;
590 int i_size_entry = strlen( p_sys->psz_current_dir ) +
591 strlen( p_sys->pp_dir_entries[p_sys->i_box_bidx]->psz_path ) + 2;
592 char *psz_uri = (char *)malloc( sizeof(char)*i_size_entry);
594 sprintf( psz_uri, "%s/%s", p_sys->psz_current_dir, p_sys->pp_dir_entries[p_sys->i_box_bidx]->psz_path );
596 p_sys->psz_current_dir = strdup( psz_uri );
607 if( p_sys->i_box_bidx >= p_sys->i_dir_entries ) p_sys->i_box_bidx = p_sys->i_dir_entries - 1;
608 if( p_sys->i_box_bidx < 0 ) p_sys->i_box_bidx = 0;
612 else if( p_sys->i_box_type == BOX_HELP || p_sys->i_box_type == BOX_INFO )
617 p_sys->i_box_start = 0;
620 p_sys->i_box_start = p_sys->i_box_lines_total - 1;
623 if( p_sys->i_box_start > 0 ) p_sys->i_box_start--;
626 if( p_sys->i_box_start < p_sys->i_box_lines_total - 1 )
628 p_sys->i_box_start++;
632 p_sys->i_box_start -= p_sys->i_box_lines;
633 if( p_sys->i_box_start < 0 ) p_sys->i_box_start = 0;
636 p_sys->i_box_start += p_sys->i_box_lines;
637 if( p_sys->i_box_start >= p_sys->i_box_lines_total )
639 p_sys->i_box_start = p_sys->i_box_lines_total - 1;
646 else if( p_sys->i_box_type == BOX_NONE )
652 ManageSlider( p_intf );
655 p_sys->f_slider = 99.9;
656 ManageSlider( p_intf );
659 p_sys->f_slider += 5.0;
660 if( p_sys->f_slider >= 99.0 ) p_sys->f_slider = 99.0;
661 ManageSlider( p_intf );
664 p_sys->f_slider -= 5.0;
665 if( p_sys->f_slider < 0.0 ) p_sys->f_slider = 0.0;
666 ManageSlider( p_intf );
673 else if( p_sys->i_box_type == BOX_SEARCH && p_sys->psz_search_chain )
676 i_chain_len = strlen( p_sys->psz_search_chain );
684 if( i_chain_len > 0 )
686 p_sys->psz_old_search = strdup( p_sys->psz_search_chain );
688 else if( p_sys->psz_old_search )
690 SearchPlaylist( p_intf, p_sys->psz_old_search );
692 p_sys->i_box_type = BOX_PLAYLIST;
694 case 0x1b: /* Esc. */
695 p_sys->i_box_plidx = p_sys->i_before_search;
696 p_sys->i_box_type = BOX_PLAYLIST;
699 if( i_chain_len > 0 )
701 p_sys->psz_search_chain[ i_chain_len - 1 ] = '\0';
705 if( i_chain_len < SEARCH_CHAIN_SIZE )
707 p_sys->psz_search_chain[ i_chain_len++ ] = i_key;
708 p_sys->psz_search_chain[ i_chain_len ] = 0;
712 if( p_sys->psz_old_search )
714 free( p_sys->psz_old_search );
715 p_sys->psz_old_search = NULL;
717 SearchPlaylist( p_intf, p_sys->psz_search_chain );
720 else if( p_sys->i_box_type == BOX_OPEN && p_sys->psz_open_chain )
722 int i_chain_len = strlen( p_sys->psz_open_chain );
723 playlist_t *p_playlist = p_sys->p_playlist;
732 if( p_playlist && i_chain_len > 0 )
734 playlist_Add( p_playlist, p_sys->psz_open_chain,
735 p_sys->psz_open_chain,
736 PLAYLIST_GO|PLAYLIST_APPEND, PLAYLIST_END );
737 p_sys->b_box_plidx_follow = VLC_TRUE;
739 p_sys->i_box_type = BOX_PLAYLIST;
741 case 0x1b: /* Esc. */
742 p_sys->i_box_type = BOX_PLAYLIST;
745 if( i_chain_len > 0 )
747 p_sys->psz_open_chain[ i_chain_len - 1 ] = '\0';
751 if( i_chain_len < OPEN_CHAIN_SIZE )
753 p_sys->psz_open_chain[ i_chain_len++ ] = i_key;
754 p_sys->psz_open_chain[ i_chain_len ] = 0;
768 p_intf->p_vlc->b_die = VLC_TRUE;
773 if( p_sys->i_box_type == BOX_INFO )
774 p_sys->i_box_type = BOX_NONE;
776 p_sys->i_box_type = BOX_INFO;
777 p_sys->i_box_lines_total = 0;
780 if( p_sys->i_box_type == BOX_LOG )
781 p_sys->i_box_type = BOX_NONE;
783 p_sys->i_box_type = BOX_LOG;
786 if( p_sys->i_box_type == BOX_PLAYLIST )
787 p_sys->i_box_type = BOX_NONE;
789 p_sys->i_box_type = BOX_PLAYLIST;
792 if( p_sys->i_box_type == BOX_BROWSE )
793 p_sys->i_box_type = BOX_NONE;
795 p_sys->i_box_type = BOX_BROWSE;
799 if( p_sys->i_box_type == BOX_HELP )
800 p_sys->i_box_type = BOX_NONE;
802 p_sys->i_box_type = BOX_HELP;
803 p_sys->i_box_lines_total = 0;
806 if( p_sys->i_box_type != BOX_SEARCH )
808 if( p_sys->psz_search_chain == NULL )
812 p_sys->psz_search_chain[0] = '\0';
813 p_sys->b_box_plidx_follow = VLC_FALSE;
814 p_sys->i_before_search = p_sys->i_box_plidx;
815 p_sys->i_box_type = BOX_SEARCH;
819 if( p_sys->i_box_type != BOX_OPEN )
821 if( p_sys->psz_open_chain == NULL )
825 p_sys->psz_open_chain[0] = '\0';
826 p_sys->i_box_type = BOX_OPEN;
832 p_sys->f_slider += 1.0;
833 if( p_sys->f_slider > 99.9 ) p_sys->f_slider = 99.9;
834 ManageSlider( p_intf );
838 p_sys->f_slider -= 1.0;
839 if( p_sys->f_slider < 0.0 ) p_sys->f_slider = 0.0;
840 ManageSlider( p_intf );
846 if( p_intf->p_sys->p_input )
848 vout_thread_t *p_vout;
849 p_vout = vlc_object_find( p_intf->p_sys->p_input,
850 VLC_OBJECT_VOUT, FIND_CHILD );
853 var_Get( p_vout, "fullscreen", &val );
854 val.b_bool = !val.b_bool;
855 var_Set( p_vout, "fullscreen", val );
856 vlc_object_release( p_vout );
860 playlist_t *p_playlist;
861 p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
865 var_Get( p_playlist, "fullscreen", &val );
866 val.b_bool = !val.b_bool;
867 var_Set( p_playlist, "fullscreen", val );
868 vlc_object_release( p_playlist );
880 if( p_intf->p_sys->p_playlist )
882 playlist_Stop( p_intf->p_sys->p_playlist );
893 val.b_bool = VLC_TRUE;
894 var_Set( p_sys->p_input, "prev-title", val );
901 val.b_bool = VLC_TRUE;
902 var_Set( p_sys->p_input, "next-title", val );
909 val.b_bool = VLC_TRUE;
910 var_Set( p_sys->p_input, "prev-chapter", val );
917 val.b_bool = VLC_TRUE;
918 var_Set( p_sys->p_input, "next-chapter", val );
923 if( p_intf->p_sys->p_playlist )
925 playlist_Prev( p_intf->p_sys->p_playlist );
931 if( p_intf->p_sys->p_playlist )
933 playlist_Next( p_intf->p_sys->p_playlist );
939 aout_VolumeUp( p_intf, 1, NULL );
944 aout_VolumeDown( p_intf, 1, NULL );
949 * ^l should clear and redraw the screen
960 static void ManageSlider( intf_thread_t *p_intf )
962 intf_sys_t *p_sys = p_intf->p_sys;
963 input_thread_t *p_input = p_sys->p_input;
966 if( p_input == NULL )
970 var_Get( p_input, "state", &val );
971 if( val.i_int != PLAYING_S )
976 var_Get( p_input, "position", &val );
977 if( p_sys->f_slider == p_sys->f_slider_old )
980 p_sys->f_slider_old = 100 * val.f_float;
984 p_sys->f_slider_old = p_sys->f_slider;
986 val.f_float = p_sys->f_slider / 100.0;
987 var_Set( p_input, "position", val );
991 static void SearchPlaylist( intf_thread_t *p_intf, char *psz_searchstring )
996 intf_sys_t *p_sys = p_intf->p_sys;
997 playlist_t *p_playlist = p_sys->p_playlist;
999 if( p_sys->i_before_search >= 0 )
1001 i_first = p_sys->i_before_search;
1004 if( ( ! psz_searchstring ) || strlen( psz_searchstring ) <= 0 )
1006 p_sys->i_box_plidx = p_sys->i_before_search;
1010 i_max = p_sys->i_current_view == VIEW_ALL ?
1011 p_playlist->i_size : p_sys->i_plist_entries;
1013 i_item = SubSearchPlaylist( p_intf, psz_searchstring, i_first + 1, i_max );
1016 i_item = SubSearchPlaylist( p_intf, psz_searchstring, 0, i_first );
1019 if( i_item < 0 || i_item >= i_max ) return;
1021 p_sys->i_box_plidx = i_item;
1024 static int SubSearchPlaylist( intf_thread_t *p_intf, char *psz_searchstring,
1025 int i_start, int i_stop )
1027 intf_sys_t *p_sys = p_intf->p_sys;
1028 playlist_t *p_playlist = p_sys->p_playlist;
1031 if( p_sys->i_current_view == VIEW_ALL )
1033 for( i = i_start + 1; i < i_stop; i++ )
1035 if( strcasestr( p_playlist->pp_items[i]->input.psz_name,
1036 psz_searchstring ) != NULL
1037 || strcasestr( p_playlist->pp_items[i]->input.psz_uri,
1038 psz_searchstring ) != NULL )
1047 for( i = i_start + 1; i < i_stop; i++ )
1049 if( strcasestr( p_sys->pp_plist[i]->psz_display,
1050 psz_searchstring ) != NULL )
1062 static void mvnprintw( int y, int x, int w, const char *p_fmt, ... )
1068 va_start( vl_args, p_fmt );
1069 vasprintf( &p_buf, p_fmt, vl_args );
1078 if( ( i_len = strlen( p_buf ) ) > w )
1080 int i_cut = i_len - w;
1081 int x1 = i_len/2 - i_cut/2;
1082 int x2 = x1 + i_cut;
1086 memmove( &p_buf[x1], &p_buf[x2], i_len - x2 );
1095 mvprintw( y, x, "%s", p_buf );
1099 mvprintw( y, x, "%s", p_buf );
1100 mvhline( y, x + i_len, ' ', w - i_len );
1104 static void MainBoxWrite( intf_thread_t *p_intf, int l, int x, const char *p_fmt, ... )
1106 intf_sys_t *p_sys = p_intf->p_sys;
1111 if( l < p_sys->i_box_start || l - p_sys->i_box_start >= p_sys->i_box_lines )
1116 va_start( vl_args, p_fmt );
1117 vasprintf( &p_buf, p_fmt, vl_args );
1125 mvnprintw( p_sys->i_box_y + l - p_sys->i_box_start, x, COLS - x - 1, "%s", p_buf );
1128 static void Redraw( intf_thread_t *p_intf, time_t *t_last_refresh )
1130 intf_sys_t *p_sys = p_intf->p_sys;
1131 input_thread_t *p_input = p_sys->p_input;
1139 attrset( A_REVERSE );
1140 mvnprintw( y, 0, COLS, "VLC media player" " (ncurses interface) [ h for help ]" );
1141 attroff( A_REVERSE );
1145 if( p_input && !p_input->b_dead )
1147 char buf1[MSTRTIME_MAX_SIZE];
1148 char buf2[MSTRTIME_MAX_SIZE];
1150 vlc_value_t val_list;
1153 mvnprintw( y++, 0, COLS, " Source : %s",
1154 p_input->input.p_item->psz_uri );
1157 var_Get( p_input, "state", &val );
1158 if( val.i_int == PLAYING_S )
1160 mvnprintw( y++, 0, COLS, " State : Playing" );
1162 else if( val.i_int == PAUSE_S )
1164 mvnprintw( y++, 0, COLS, " State : Paused" );
1170 if( val.i_int != INIT_S && val.i_int != END_S )
1172 audio_volume_t i_volume;
1175 var_Get( p_input, "time", &val );
1176 msecstotimestr( buf1, val.i_time / 1000 );
1178 var_Get( p_input, "length", &val );
1179 msecstotimestr( buf2, val.i_time / 1000 );
1181 mvnprintw( y++, 0, COLS, " Position : %s/%s (%.2f%%)", buf1, buf2, p_sys->f_slider );
1184 aout_VolumeGet( p_intf, &i_volume );
1185 mvnprintw( y++, 0, COLS, " Volume : %i%%", i_volume*200/AOUT_VOLUME_MAX );
1188 if( !var_Get( p_input, "title", &val ) )
1190 var_Change( p_input, "title", VLC_VAR_GETCHOICES, &val_list, NULL );
1191 if( val_list.p_list->i_count > 0 )
1193 mvnprintw( y++, 0, COLS, " Title : %d/%d", val.i_int, val_list.p_list->i_count );
1195 var_Change( p_input, "title", VLC_VAR_FREELIST, &val_list, NULL );
1199 if( !var_Get( p_input, "chapter", &val ) )
1201 var_Change( p_input, "chapter", VLC_VAR_GETCHOICES, &val_list, NULL );
1202 if( val_list.p_list->i_count > 0 )
1204 mvnprintw( y++, 0, COLS, " Chapter : %d/%d", val.i_int, val_list.p_list->i_count );
1206 var_Change( p_input, "chapter", VLC_VAR_FREELIST, &val_list, NULL );
1216 mvnprintw( y++, 0, COLS, "Source: <no current item>" );
1217 DrawEmptyLine( p_sys->w, y++, 0, COLS );
1218 DrawEmptyLine( p_sys->w, y++, 0, COLS );
1219 DrawEmptyLine( p_sys->w, y++, 0, COLS );
1222 DrawBox( p_sys->w, y, 0, 3, COLS, "" );
1223 DrawEmptyLine( p_sys->w, y+1, 1, COLS-2);
1224 DrawLine( p_sys->w, y+1, 1, (int)(p_intf->p_sys->f_slider/100.0 * (COLS -2)) );
1227 p_sys->i_box_y = y + 1;
1228 p_sys->i_box_lines = LINES - y - 2;
1233 if( p_sys->i_box_type == BOX_HELP )
1237 DrawBox( p_sys->w, y++, 0, h, COLS, " Help " );
1239 MainBoxWrite( p_intf, l++, 1, "[Display]" );
1240 MainBoxWrite( p_intf, l++, 1, " h,H Show/Hide help box" );
1241 MainBoxWrite( p_intf, l++, 1, " i Show/Hide info box" );
1242 MainBoxWrite( p_intf, l++, 1, " L Show/Hide messages box" );
1243 MainBoxWrite( p_intf, l++, 1, " P Show/Hide playlist box" );
1244 MainBoxWrite( p_intf, l++, 1, " B Show/Hide filebrowser" );
1245 MainBoxWrite( p_intf, l++, 1, "" );
1247 MainBoxWrite( p_intf, l++, 1, "[Global]" );
1248 MainBoxWrite( p_intf, l++, 1, " q, Q Quit" );
1249 MainBoxWrite( p_intf, l++, 1, " s Stop" );
1250 MainBoxWrite( p_intf, l++, 1, " <space> Pause/Play" );
1251 MainBoxWrite( p_intf, l++, 1, " f Toggle Fullscreen" );
1252 MainBoxWrite( p_intf, l++, 1, " n, p Next/Previous playlist item" );
1253 MainBoxWrite( p_intf, l++, 1, " [, ] Next/Previous title" );
1254 MainBoxWrite( p_intf, l++, 1, " <, > Next/Previous chapter" );
1255 MainBoxWrite( p_intf, l++, 1, " <right> Seek +1%%" );
1256 MainBoxWrite( p_intf, l++, 1, " <left> Seek -1%%" );
1257 MainBoxWrite( p_intf, l++, 1, " a Volume Up" );
1258 MainBoxWrite( p_intf, l++, 1, " z Volume Down" );
1259 MainBoxWrite( p_intf, l++, 1, "" );
1261 MainBoxWrite( p_intf, l++, 1, "[Playlist]" );
1262 MainBoxWrite( p_intf, l++, 1, " r Random" );
1263 MainBoxWrite( p_intf, l++, 1, " l Loop Playlist" );
1264 MainBoxWrite( p_intf, l++, 1, " R Repeat item" );
1265 MainBoxWrite( p_intf, l++, 1, " o Order Playlist by title" );
1266 MainBoxWrite( p_intf, l++, 1, " O Reverse order Playlist by title" );
1267 MainBoxWrite( p_intf, l++, 1, " / Look for an item" );
1268 MainBoxWrite( p_intf, l++, 1, " A Add an entry" );
1269 MainBoxWrite( p_intf, l++, 1, " D, <del> Delete an entry" );
1270 MainBoxWrite( p_intf, l++, 1, " <backspace> Delete an entry" );
1271 MainBoxWrite( p_intf, l++, 1, "" );
1273 MainBoxWrite( p_intf, l++, 1, "[Filebrowser]" );
1274 MainBoxWrite( p_intf, l++, 1, " <enter> Add the selected file to the playlist" );
1275 MainBoxWrite( p_intf, l++, 1, " <space> Add the selected directory to the playlist" );
1276 MainBoxWrite( p_intf, l++, 1, " . Show/Hide hidden files" );
1277 MainBoxWrite( p_intf, l++, 1, "" );
1279 MainBoxWrite( p_intf, l++, 1, "[Boxes]" );
1280 MainBoxWrite( p_intf, l++, 1, " <up>,<down> Navigate through the box line by line" );
1281 MainBoxWrite( p_intf, l++, 1, " <pgup>,<pgdown> Navigate through the box page by page" );
1282 MainBoxWrite( p_intf, l++, 1, "" );
1284 MainBoxWrite( p_intf, l++, 1, "[Player]" );
1285 MainBoxWrite( p_intf, l++, 1, " <up>,<down> Seek +/-5%%" );
1286 MainBoxWrite( p_intf, l++, 1, "" );
1288 MainBoxWrite( p_intf, l++, 1, "[Miscellaneous]" );
1289 MainBoxWrite( p_intf, l++, 1, " Ctrl-l Refresh the screen" );
1291 p_sys->i_box_lines_total = l;
1292 if( p_sys->i_box_start >= p_sys->i_box_lines_total )
1294 p_sys->i_box_start = p_sys->i_box_lines_total - 1;
1297 if( l - p_sys->i_box_start < p_sys->i_box_lines )
1299 y += l - p_sys->i_box_start;
1303 y += p_sys->i_box_lines;
1306 else if( p_sys->i_box_type == BOX_INFO )
1310 DrawBox( p_sys->w, y++, 0, h, COLS, " Information " );
1315 vlc_mutex_lock( &p_input->input.p_item->lock );
1316 for( i = 0; i < p_input->input.p_item->i_categories; i++ )
1318 info_category_t *p_category = p_input->input.p_item->pp_categories[i];
1319 if( y >= y_end ) break;
1320 MainBoxWrite( p_intf, l++, 1, " [%s]", p_category->psz_name );
1321 for( j = 0; j < p_category->i_infos; j++ )
1323 info_t *p_info = p_category->pp_infos[j];
1324 if( y >= y_end ) break;
1325 MainBoxWrite( p_intf, l++, 1, " %s: %s", p_info->psz_name, p_info->psz_value );
1328 vlc_mutex_unlock( &p_input->input.p_item->lock );
1332 MainBoxWrite( p_intf, l++, 1, "No item currently playing" );
1334 p_sys->i_box_lines_total = l;
1335 if( p_sys->i_box_start >= p_sys->i_box_lines_total )
1337 p_sys->i_box_start = p_sys->i_box_lines_total - 1;
1340 if( l - p_sys->i_box_start < p_sys->i_box_lines )
1342 y += l - p_sys->i_box_start;
1346 y += p_sys->i_box_lines;
1349 else if( p_sys->i_box_type == BOX_LOG )
1355 DrawBox( p_sys->w, y++, 0, h, COLS, " Logs " );
1357 i_start = p_intf->p_sys->p_sub->i_start;
1359 vlc_mutex_lock( p_intf->p_sys->p_sub->p_lock );
1360 i_stop = *p_intf->p_sys->p_sub->pi_stop;
1361 vlc_mutex_unlock( p_intf->p_sys->p_sub->p_lock );
1365 static const char *ppsz_type[4] = { "", "error", "warning", "debug" };
1366 if( i_line >= h - 2 )
1372 if( i_stop < 0 ) i_stop += VLC_MSG_QSIZE;
1373 if( i_stop == i_start )
1377 mvnprintw( y + h-2-i_line, 1, COLS - 2, " [%s] %s",
1378 ppsz_type[p_sys->p_sub->p_msg[i_stop].i_type],
1379 p_sys->p_sub->p_msg[i_stop].psz_msg );
1382 vlc_mutex_lock( p_intf->p_sys->p_sub->p_lock );
1383 p_intf->p_sys->p_sub->i_start = i_stop;
1384 vlc_mutex_unlock( p_intf->p_sys->p_sub->p_lock );
1387 else if( p_sys->i_box_type == BOX_BROWSE )
1389 /* Filebrowser box */
1390 int i_start, i_stop;
1392 DrawBox( p_sys->w, y++, 0, h, COLS, " Browse " );
1394 if( p_sys->i_box_bidx >= p_sys->i_dir_entries ) p_sys->i_box_plidx = p_sys->i_dir_entries - 1;
1395 if( p_sys->i_box_bidx < 0 ) p_sys->i_box_bidx = 0;
1397 if( p_sys->i_box_bidx < (h - 2)/2 )
1402 else if( p_sys->i_dir_entries - p_sys->i_box_bidx > (h - 2)/2 )
1404 i_start = p_sys->i_box_bidx - (h - 2)/2;
1405 i_stop = i_start + h - 2;
1409 i_stop = p_sys->i_dir_entries;
1410 i_start = p_sys->i_dir_entries - (h - 2);
1416 if( i_stop > p_sys->i_dir_entries )
1418 i_stop = p_sys->i_dir_entries;
1421 for( i_item = i_start; i_item < i_stop; i_item++ )
1423 vlc_bool_t b_selected = ( p_sys->i_box_bidx == i_item );
1425 if( y >= y_end ) break;
1428 attrset( A_REVERSE );
1430 mvnprintw( y++, 1, COLS - 2, " %c %s", p_sys->pp_dir_entries[i_item]->b_file == VLC_TRUE ? ' ' : '+',
1431 p_sys->pp_dir_entries[i_item]->psz_path );
1434 attroff( A_REVERSE );
1439 else if( ( p_sys->i_box_type == BOX_PLAYLIST ||
1440 p_sys->i_box_type == BOX_SEARCH ||
1441 p_sys->i_box_type == BOX_OPEN ) && p_sys->p_playlist )
1444 playlist_t *p_playlist = p_sys->p_playlist;
1445 int i_start, i_stop, i_max = p_sys->i_plist_entries;
1449 switch( p_sys->i_current_view )
1452 psz_title = strdup( " Playlist (All, unsorted) " );
1453 i_max = p_playlist->i_size;
1456 psz_title = strdup( " Playlist (By category) " );
1459 psz_title = strdup( " Playlist (Manually added) " );
1462 DrawBox( p_sys->w, y++, 0, h, COLS, psz_title );
1464 if( p_sys->i_current_view != VIEW_ALL &&
1465 ( p_sys->b_need_update || p_sys->pp_plist == NULL ) )
1467 PlaylistRebuild( p_intf );
1469 if( p_sys->b_box_plidx_follow )
1471 FindIndex( p_intf );
1474 if( p_sys->i_box_plidx < 0 ) p_sys->i_box_plidx = 0;
1476 if( p_sys->i_box_plidx < (h - 2)/2 )
1481 else if( i_max - p_sys->i_box_plidx > (h - 2)/2 )
1483 i_start = p_sys->i_box_plidx - (h - 2)/2;
1484 i_stop = i_start + h - 2;
1489 i_start = i_max - (h - 2);
1495 if( i_stop > i_max )
1500 if( p_sys->i_current_view == VIEW_ALL )
1503 for( i_item = i_start; i_item < i_stop; i_item++ )
1505 vlc_bool_t b_selected = ( p_sys->i_box_plidx == i_item );
1506 int c = p_playlist->i_index == i_item ? '>' : ' ';
1508 if( y >= y_end ) break;
1511 attrset( A_REVERSE );
1513 if( !strcmp( p_playlist->pp_items[i_item]->input.psz_name,
1514 p_playlist->pp_items[i_item]->input.psz_uri ) )
1516 mvnprintw( y++, 1, COLS - 2, "%c %d - '%s'",
1519 p_playlist->pp_items[i_item]->input.psz_uri );
1523 mvnprintw( y++, 1, COLS - 2, "%c %d - '%s' (%s)",
1526 p_playlist->pp_items[i_item]->input.psz_uri,
1527 p_playlist->pp_items[i_item]->input.psz_name );
1531 attroff( A_REVERSE );
1539 for( i_item = i_start; i_item < i_stop; i_item++ )
1541 vlc_bool_t b_selected = ( p_sys->i_box_plidx == i_item );
1542 int c = ( p_playlist->status.p_item ==
1543 p_sys->pp_plist[i_item]->p_item ) ? '>' : ' ';
1545 if( y >= y_end ) break;
1548 attrset( A_REVERSE );
1550 mvnprintw( y++, 1, COLS - 2, "%c%s", c,
1551 p_sys->pp_plist[i_item]->psz_display );
1554 attroff( A_REVERSE );
1564 if( p_sys->i_box_type == BOX_SEARCH )
1566 DrawEmptyLine( p_sys->w, 7, 1, COLS-2 );
1567 if( p_sys->psz_search_chain )
1569 if( strlen( p_sys->psz_search_chain ) == 0 &&
1570 p_sys->psz_old_search != NULL )
1572 /* Searching next entry */
1573 mvnprintw( 7, 1, COLS-2, "Find: %s", p_sys->psz_old_search );
1577 mvnprintw( 7, 1, COLS-2, "Find: %s", p_sys->psz_search_chain );
1581 if( p_sys->i_box_type == BOX_OPEN )
1583 if( p_sys->psz_open_chain )
1585 DrawEmptyLine( p_sys->w, 7, 1, COLS-2 );
1586 mvnprintw( 7, 1, COLS-2, "Open: %s", p_sys->psz_open_chain );
1592 DrawEmptyLine( p_sys->w, y++, 1, COLS - 2 );
1597 *t_last_refresh = time( 0 );
1600 static void PlaylistRebuild( intf_thread_t *p_intf )
1602 intf_sys_t *p_sys = p_intf->p_sys;
1603 playlist_view_t *p_view;
1604 playlist_t *p_playlist = p_sys->p_playlist;
1606 if( p_playlist == NULL )
1611 vlc_mutex_lock( &p_playlist->object_lock );
1613 p_view = playlist_ViewFind( p_playlist, p_intf->p_sys->i_current_view );
1615 /* First clear the old one */
1616 PlaylistDestroy( p_intf );
1618 /* Build the new one */
1619 PlaylistAddNode( p_intf, p_view->p_root, 0, "" );
1621 p_sys->b_need_update = VLC_FALSE;
1623 vlc_mutex_unlock( &p_playlist->object_lock );
1626 static void PlaylistAddNode( intf_thread_t *p_intf, playlist_item_t *p_node,
1629 intf_sys_t *p_sys = p_intf->p_sys;
1630 playlist_item_t *p_child;
1634 psz_tmp = (char *)malloc( strlen( c ) + 4 );
1635 if( psz_tmp == NULL ) return;
1636 for( k = 0; k < p_node->i_children; k++ )
1638 struct pl_item_t *p_pl_item;
1642 p_child = p_node->pp_children[k];
1643 i_size = strlen( c ) + strlen( p_child->input.psz_name ) + 4;
1644 buff = (char *)malloc( sizeof( char ) * i_size );
1645 p_pl_item = (struct pl_item_t *)malloc( sizeof( struct pl_item_t ) );
1646 if( p_pl_item == NULL || buff == NULL ) return;
1650 sprintf( buff, "%s%c-%s", c, k == p_node->i_children - 1 ?
1651 '`' : '|', p_child->input.psz_name );
1655 sprintf( buff, " %s", p_child->input.psz_name );
1657 p_pl_item->psz_display = strdup( buff );
1658 p_pl_item->p_item = p_child;
1659 INSERT_ELEM( p_sys->pp_plist, p_sys->i_plist_entries,
1660 p_sys->i_plist_entries, p_pl_item );
1664 if( p_child->i_children > 0 )
1666 sprintf( psz_tmp, "%s%c ", c,
1667 k == p_node->i_children - 1 ? ' ' : '|' );
1668 PlaylistAddNode( p_intf, p_child, i,
1669 strlen( c ) ? psz_tmp : " " );
1675 static int PlaylistChanged( vlc_object_t *p_this, const char *psz_variable,
1676 vlc_value_t oval, vlc_value_t nval, void *param )
1678 intf_thread_t *p_intf = (intf_thread_t *)param;
1679 p_intf->p_sys->b_need_update = VLC_TRUE;
1683 static void FindIndex( intf_thread_t *p_intf )
1685 intf_sys_t *p_sys = p_intf->p_sys;
1688 if( p_sys->i_current_view == VIEW_ALL )
1690 p_sys->i_box_plidx = p_sys->p_playlist->i_index;
1692 else if( ( p_sys->i_box_plidx < p_sys->i_plist_entries &&
1693 p_sys->pp_plist[p_sys->i_box_plidx]->p_item !=
1694 p_sys->p_playlist->status.p_item ) )
1696 for( i = 0; i < p_sys->i_plist_entries; i++ )
1698 if( p_sys->pp_plist[i]->p_item ==
1699 p_sys->p_playlist->status.p_item )
1701 p_sys->i_box_plidx = i;
1708 static void PlaylistDestroy( intf_thread_t *p_intf )
1710 intf_sys_t *p_sys = p_intf->p_sys;
1713 for( i = 0; i < p_sys->i_plist_entries; i++ )
1715 struct pl_item_t *p_pl_item = p_sys->pp_plist[i];
1716 free( p_pl_item->psz_display );
1717 REMOVE_ELEM( p_sys->pp_plist, p_sys->i_plist_entries, i );
1720 p_sys->pp_plist = NULL;
1721 p_sys->i_plist_entries = 0;
1724 static void Eject( intf_thread_t *p_intf )
1726 char *psz_device = NULL, *psz_parser, *psz_name;
1729 * Get the active input
1730 * Determine whether we can eject a media, ie it's a DVD, VCD or CD-DA
1731 * If it's neither of these, then return
1734 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1737 if( p_playlist == NULL )
1742 vlc_mutex_lock( &p_playlist->object_lock );
1744 if( p_playlist->i_index < 0 )
1746 vlc_mutex_unlock( &p_playlist->object_lock );
1747 vlc_object_release( p_playlist );
1751 psz_name = p_playlist->pp_items[ p_playlist->i_index ]->input.psz_name;
1755 if( !strncmp(psz_name, "dvd://", 4) )
1757 switch( psz_name[strlen("dvd://")] )
1761 psz_device = config_GetPsz( p_intf, "dvd" );
1764 /* Omit the first MRL-selector characters */
1765 psz_device = strdup( psz_name + strlen("dvd://" ) );
1769 else if( !strncmp(psz_name, VCD_MRL, strlen(VCD_MRL)) )
1771 switch( psz_name[strlen(VCD_MRL)] )
1775 psz_device = config_GetPsz( p_intf, VCD_MRL );
1778 /* Omit the beginning MRL-selector characters */
1779 psz_device = strdup( psz_name + strlen(VCD_MRL) );
1783 else if( !strncmp(psz_name, CDDA_MRL, strlen(CDDA_MRL) ) )
1785 switch( psz_name[strlen(CDDA_MRL)] )
1789 psz_device = config_GetPsz( p_intf, "cd-audio" );
1792 /* Omit the beginning MRL-selector characters */
1793 psz_device = strdup( psz_name + strlen(CDDA_MRL) );
1799 psz_device = strdup( psz_name );
1803 vlc_mutex_unlock( &p_playlist->object_lock );
1804 vlc_object_release( p_playlist );
1806 if( psz_device == NULL )
1811 /* Remove what we have after @ */
1812 psz_parser = psz_device;
1813 for( psz_parser = psz_device ; *psz_parser ; psz_parser++ )
1815 if( *psz_parser == '@' )
1822 /* If there's a stream playing, we aren't allowed to eject ! */
1823 if( p_intf->p_sys->p_input == NULL )
1825 msg_Dbg( p_intf, "ejecting %s", psz_device );
1827 intf_Eject( p_intf, psz_device );
1834 static int comp_dir_entries( const void *pp_dir_entry1,
1835 const void *pp_dir_entry2 )
1837 struct dir_entry_t *p_dir_entry1 = *(struct dir_entry_t**)pp_dir_entry1;
1838 struct dir_entry_t *p_dir_entry2 = *(struct dir_entry_t**)pp_dir_entry2;
1839 if ( p_dir_entry1->b_file == p_dir_entry2->b_file ) {
1840 return strcasecmp( p_dir_entry1->psz_path, p_dir_entry2->psz_path );
1844 return ( p_dir_entry1->b_file ? 1 : -1 );
1848 static void ReadDir( intf_thread_t *p_intf )
1850 intf_sys_t *p_sys = p_intf->p_sys;
1851 DIR * p_current_dir;
1852 struct dirent * p_dir_content;
1855 if( p_sys->psz_current_dir && *p_sys->psz_current_dir )
1858 p_current_dir = opendir( p_sys->psz_current_dir );
1860 if( p_current_dir == NULL )
1862 /* something went bad, get out of here ! */
1864 msg_Warn( p_intf, "cannot open directory `%s' (%s)",
1865 p_sys->psz_current_dir, strerror(errno));
1867 msg_Warn( p_intf, "cannot open directory `%s'", p_sys->psz_current_dir );
1872 /* Clean the old shit */
1873 for( i = 0; i < p_sys->i_dir_entries; i++ )
1875 struct dir_entry_t *p_dir_entry = p_sys->pp_dir_entries[i];
1876 free( p_dir_entry->psz_path );
1877 REMOVE_ELEM( p_sys->pp_dir_entries, p_sys->i_dir_entries, i );
1878 free( p_dir_entry );
1880 p_sys->pp_dir_entries = NULL;
1881 p_sys->i_dir_entries = 0;
1883 /* get the first directory entry */
1884 p_dir_content = readdir( p_current_dir );
1886 /* while we still have entries in the directory */
1887 while( p_dir_content != NULL )
1889 #if defined( S_ISDIR )
1890 struct stat stat_data;
1892 struct dir_entry_t *p_dir_entry;
1893 int i_size_entry = strlen( p_sys->psz_current_dir ) +
1894 strlen( p_dir_content->d_name ) + 2;
1897 if( p_sys->b_show_hidden_files == VLC_FALSE &&
1898 ( strlen( p_dir_content->d_name ) &&
1899 p_dir_content->d_name[0] == '.' ) &&
1900 strcmp( p_dir_content->d_name, ".." ) )
1902 p_dir_content = readdir( p_current_dir );
1906 psz_uri = (char *)malloc( sizeof(char)*i_size_entry);
1907 sprintf( psz_uri, "%s/%s", p_sys->psz_current_dir,
1908 p_dir_content->d_name );
1910 if( !( p_dir_entry = malloc( sizeof( struct dir_entry_t) ) ) )
1916 #if defined( S_ISDIR )
1917 stat( psz_uri, &stat_data );
1918 if( S_ISDIR(stat_data.st_mode) )
1919 #elif defined( DT_DIR )
1920 if( p_dir_content->d_type & DT_DIR )
1925 p_dir_entry->psz_path = strdup( p_dir_content->d_name );
1926 p_dir_entry->b_file = VLC_FALSE;
1927 INSERT_ELEM( p_sys->pp_dir_entries, p_sys->i_dir_entries,
1928 p_sys->i_dir_entries, p_dir_entry );
1932 p_dir_entry->psz_path = strdup( p_dir_content->d_name );
1933 p_dir_entry->b_file = VLC_TRUE;
1934 INSERT_ELEM( p_sys->pp_dir_entries, p_sys->i_dir_entries,
1935 p_sys->i_dir_entries, p_dir_entry );
1939 /* Read next entry */
1940 p_dir_content = readdir( p_current_dir );
1944 qsort( p_sys->pp_dir_entries, p_sys->i_dir_entries,
1945 sizeof(struct dir_entry_t*), &comp_dir_entries );
1947 closedir( p_current_dir );
1952 msg_Dbg( p_intf, "no current dir set" );
1957 static void PlayPause( intf_thread_t *p_intf )
1959 input_thread_t *p_input = p_intf->p_sys->p_input;
1964 var_Get( p_input, "state", &val );
1965 if( val.i_int != PAUSE_S )
1967 val.i_int = PAUSE_S;
1971 val.i_int = PLAYING_S;
1973 var_Set( p_input, "state", val );
1975 else if( p_intf->p_sys->p_playlist )
1977 playlist_Play( p_intf->p_sys->p_playlist );
1981 /****************************************************************************
1983 ****************************************************************************/
1984 static void DrawBox( WINDOW *win, int y, int x, int h, int w, char *title )
1989 if( w > 3 && h > 2 )
1991 if( title == NULL ) title = "";
1992 i_len = strlen( title );
1994 if( i_len > w - 2 ) i_len = w - 2;
1996 mvwaddch( win, y, x, ACS_ULCORNER );
1997 mvwhline( win, y, x+1, ACS_HLINE, ( w-i_len-2)/2 );
1998 mvwprintw( win,y, x+1+(w-i_len-2)/2, "%s", title );
1999 mvwhline( win, y, x+(w-i_len)/2+i_len, ACS_HLINE, w - 1 - ((w-i_len)/2+i_len) );
2000 mvwaddch( win, y, x+w-1,ACS_URCORNER );
2002 for( i = 0; i < h-2; i++ )
2004 mvwaddch( win, y+i+1, x, ACS_VLINE );
2005 mvwaddch( win, y+i+1, x+w-1, ACS_VLINE );
2008 mvwaddch( win, y+h-1, x, ACS_LLCORNER );
2009 mvwhline( win, y+h-1, x+1, ACS_HLINE, w - 2 );
2010 mvwaddch( win, y+h-1, x+w-1, ACS_LRCORNER );
2014 static void DrawEmptyLine( WINDOW *win, int y, int x, int w )
2018 mvhline( y, x, ' ', w );
2022 static void DrawLine( WINDOW *win, int y, int x, int w )
2026 attrset( A_REVERSE );
2027 mvhline( y, x, ' ', w );
2028 attroff( A_REVERSE );