1 /*****************************************************************************
2 * ncurses.c : NCurses plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2001-2006 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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
25 *****************************************************************************/
27 /*****************************************************************************
29 *****************************************************************************/
32 #include <errno.h> /* ENOMEM */
37 #include <vlc_interface.h>
40 #include <vlc_charset.h>
41 #include <vlc_input.h>
42 #include <vlc_playlist.h>
44 #ifdef HAVE_SYS_STAT_H
45 # include <sys/stat.h>
47 #if (!defined( WIN32 ) || defined(__MINGW32__))
48 /* Mingw has its own version of dirent */
53 #define CDDA_MRL "cddax://"
55 #define CDDA_MRL "cdda://"
59 #define VCD_MRL "vcdx://"
61 #define VCD_MRL "vcdx://"
64 #define SEARCH_CHAIN_SIZE 20
65 #define OPEN_CHAIN_SIZE 50
67 /*****************************************************************************
69 *****************************************************************************/
70 static int Open ( vlc_object_t * );
71 static void Close ( vlc_object_t * );
73 static void Run ( intf_thread_t * );
74 static void PlayPause ( intf_thread_t * );
75 static void Eject ( intf_thread_t * );
77 static int HandleKey ( intf_thread_t *, int );
78 static void Redraw ( intf_thread_t *, time_t * );
80 static playlist_item_t *PlaylistGetRoot( intf_thread_t * );
81 static void PlaylistRebuild( intf_thread_t * );
82 static void PlaylistAddNode( intf_thread_t *, playlist_item_t *, int, const char *);
83 static void PlaylistDestroy( intf_thread_t * );
84 static int PlaylistChanged( vlc_object_t *, const char *, vlc_value_t,
85 vlc_value_t, void * );
86 static inline vlc_bool_t PlaylistIsPlaying( intf_thread_t *,
88 static void FindIndex ( intf_thread_t * );
89 static void SearchPlaylist ( intf_thread_t *, char * );
90 static int SubSearchPlaylist( intf_thread_t *, char *, int, int );
92 static void ManageSlider ( intf_thread_t * );
93 static void ReadDir ( intf_thread_t * );
95 /*****************************************************************************
97 *****************************************************************************/
99 #define BROWSE_TEXT N_("Filebrowser starting point")
100 #define BROWSE_LONGTEXT N_( \
101 "This option allows you to specify the directory the ncurses filebrowser " \
102 "will show you initially.")
105 set_shortname( "Ncurses" );
106 set_description( _("Ncurses interface") );
107 set_capability( "interface", 10 );
108 set_category( CAT_INTERFACE );
109 set_subcategory( SUBCAT_INTERFACE_MAIN );
110 set_callbacks( Open, Close );
111 add_shortcut( "curses" );
112 add_directory( "browse-dir", NULL, NULL, BROWSE_TEXT, BROWSE_LONGTEXT, VLC_FALSE );
115 /*****************************************************************************
116 * intf_sys_t: description and status of ncurses interface
117 *****************************************************************************/
141 playlist_item_t *p_item;
146 playlist_t *p_playlist;
147 input_thread_t *p_input;
157 int i_box_lines_total;
160 int i_box_plidx; /* Playlist index */
161 int b_box_plidx_follow;
162 playlist_item_t *p_plnode; /* Playlist node */
163 int i_box_bidx; /* browser index */
167 msg_subscription_t* p_sub; /* message bank subscription */
169 char *psz_search_chain; /* for playlist searching */
170 char *psz_old_search; /* for searching next */
173 char *psz_open_chain;
174 char psz_partial_keys[7];
176 char *psz_current_dir;
178 struct dir_entry_t **pp_dir_entries;
179 vlc_bool_t b_show_hidden_files;
181 int i_current_view; /* playlist view */
182 struct pl_item_t **pp_plist;
184 vlc_bool_t b_need_update; /* for playlist view */
186 int i_verbose; /* stores verbosity level */
189 static void DrawBox( WINDOW *win, int y, int x, int h, int w, const char *title );
190 static void DrawLine( WINDOW *win, int y, int x, int w );
191 static void DrawEmptyLine( WINDOW *win, int y, int x, int w );
193 /*****************************************************************************
194 * Open: initialize and create window
195 *****************************************************************************/
196 static int Open( vlc_object_t *p_this )
198 intf_thread_t *p_intf = (intf_thread_t *)p_this;
202 /* Allocate instance and initialize some members */
203 p_sys = p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
204 p_sys->p_playlist = NULL;
205 p_sys->p_input = NULL;
206 p_sys->f_slider = 0.0;
207 p_sys->f_slider_old = 0.0;
208 p_sys->i_box_type = BOX_PLAYLIST;
209 p_sys->i_box_lines = 0;
210 p_sys->i_box_start= 0;
211 p_sys->i_box_lines_total = 0;
212 p_sys->b_box_plidx_follow = VLC_TRUE;
213 p_sys->b_box_cleared = VLC_FALSE;
214 p_sys->i_box_plidx = 0;
215 p_sys->p_plnode = NULL;
216 p_sys->i_box_bidx = 0;
217 p_sys->p_sub = msg_Subscribe( p_intf, MSG_QUEUE_NORMAL );
218 memset( p_sys->psz_partial_keys, 0, sizeof( p_sys->psz_partial_keys ) );
220 /* Initialize the curses library */
221 p_sys->w = initscr();
222 keypad( p_sys->w, TRUE );
223 /* Don't do NL -> CR/NL */
225 /* Take input chars one at a time */
235 /* exported function */
236 p_intf->pf_run = Run;
238 /* Remember verbosity level */
239 var_Get( p_intf->p_libvlc, "verbose", &val );
240 p_sys->i_verbose = val.i_int;
243 var_Set( p_intf->p_libvlc, "verbose", val );
245 /* Set defaul playlist view */
246 p_sys->i_current_view = VIEW_CATEGORY;
247 p_sys->pp_plist = NULL;
248 p_sys->i_plist_entries = 0;
249 p_sys->b_need_update = VLC_FALSE;
251 /* Initialize search chain */
252 p_sys->psz_search_chain = (char *)malloc( SEARCH_CHAIN_SIZE + 1 );
253 p_sys->psz_old_search = NULL;
254 p_sys->i_before_search = 0;
256 /* Initialize open chain */
257 p_sys->psz_open_chain = (char *)malloc( OPEN_CHAIN_SIZE + 1 );
259 /* Initialize browser options */
260 var_Create( p_intf, "browse-dir", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
261 var_Get( p_intf, "browse-dir", &val);
263 if( val.psz_string && *val.psz_string )
265 p_sys->psz_current_dir = strdup( val.psz_string );
266 free( val.psz_string );
270 p_sys->psz_current_dir = strdup( p_intf->p_libvlc->psz_homedir );
273 p_sys->i_dir_entries = 0;
274 p_sys->pp_dir_entries = NULL;
275 p_sys->b_show_hidden_files = VLC_FALSE;
281 /*****************************************************************************
282 * Close: destroy interface window
283 *****************************************************************************/
284 static void Close( vlc_object_t *p_this )
286 intf_thread_t *p_intf = (intf_thread_t *)p_this;
287 intf_sys_t *p_sys = p_intf->p_sys;
290 var_DelCallback( p_sys->p_playlist, "intf-change", PlaylistChanged,
292 var_DelCallback( p_sys->p_playlist, "item-append", PlaylistChanged,
295 PlaylistDestroy( p_intf );
297 for( i = 0; i < p_sys->i_dir_entries; i++ )
299 struct dir_entry_t *p_dir_entry = p_sys->pp_dir_entries[i];
300 if( p_dir_entry->psz_path ) free( p_dir_entry->psz_path );
301 REMOVE_ELEM( p_sys->pp_dir_entries, p_sys->i_dir_entries, i );
302 if( p_dir_entry ) free( p_dir_entry );
304 p_sys->pp_dir_entries = NULL;
306 if( p_sys->psz_current_dir ) free( p_sys->psz_current_dir );
307 if( p_sys->psz_search_chain ) free( p_sys->psz_search_chain );
308 if( p_sys->psz_old_search ) free( p_sys->psz_old_search );
309 if( p_sys->psz_open_chain ) free( p_sys->psz_open_chain );
313 vlc_object_release( p_sys->p_input );
315 if( p_sys->p_playlist )
317 vlc_object_release( p_sys->p_playlist );
320 /* Close the ncurses interface */
323 msg_Unsubscribe( p_intf, p_sys->p_sub );
325 /* Restores initial verbose setting */
327 val.i_int = p_sys->i_verbose;
328 var_Set( p_intf->p_libvlc, "verbose", val );
330 /* Destroy structure */
334 /*****************************************************************************
335 * Run: ncurses thread
336 *****************************************************************************/
337 static void Run( intf_thread_t *p_intf )
339 intf_sys_t *p_sys = p_intf->p_sys;
342 time_t t_last_refresh;
345 * force drawing the interface for the first time
347 t_last_refresh = ( time( 0 ) - 1);
349 while( !intf_ShouldDie( p_intf ) )
351 msleep( INTF_IDLE_SLEEP );
353 /* Update the input */
354 if( p_sys->p_playlist == NULL )
356 p_sys->p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
358 if( p_sys->p_playlist )
360 var_AddCallback( p_sys->p_playlist, "intf-change",
361 PlaylistChanged, p_intf );
362 var_AddCallback( p_sys->p_playlist, "item-append",
363 PlaylistChanged, p_intf );
366 if( p_sys->p_playlist )
368 vlc_mutex_lock( &p_sys->p_playlist->object_lock );
369 if( p_sys->p_input == NULL )
371 p_sys->p_input = p_sys->p_playlist->p_input;
374 if( !p_sys->p_input->b_dead )
376 vlc_object_yield( p_sys->p_input );
380 else if( p_sys->p_input->b_dead )
382 vlc_object_release( p_sys->p_input );
383 p_sys->p_input = NULL;
384 p_sys->f_slider = p_sys->f_slider_old = 0.0;
385 p_sys->b_box_cleared = VLC_FALSE;
387 vlc_mutex_unlock( &p_sys->p_playlist->object_lock );
390 if( p_sys->b_box_plidx_follow && p_sys->p_playlist->status.p_item )
395 while( ( i_key = getch() ) != -1 )
398 * HandleKey returns 1 if the screen needs to be redrawn
400 if( HandleKey( p_intf, i_key ) )
402 Redraw( p_intf, &t_last_refresh );
406 if( p_sys->f_slider > 0.0001 && !p_sys->b_box_cleared )
409 Redraw( p_intf, &t_last_refresh );
410 p_sys->b_box_cleared = VLC_TRUE;
414 * redraw the screen every second
416 if( (time(0) - t_last_refresh) >= 1 )
418 ManageSlider( p_intf );
419 Redraw( p_intf, &t_last_refresh );
424 /* following functions are local */
426 static char *KeyToUTF8( int i_key, char *psz_part )
428 char *psz_utf8, *psz;
429 int len = strlen( psz_part );
432 /* overflow error - should not happen */
433 memset( psz_part, 0, 6 );
437 psz_part[len] = (char)i_key;
439 psz_utf8 = FromLocaleDup( psz_part );
441 /* Ugly check for incomplete bytes sequences
442 * (in case of non-UTF8 multibyte local encoding) */
443 for( psz = psz_utf8; *psz; psz++ )
444 if( ( *psz == '?' ) && ( *psz_utf8 != '?' ) )
446 /* incomplete bytes sequence detected
447 * (VLC core inserted dummy question marks) */
452 /* Check for incomplete UTF8 bytes sequence */
453 if( EnsureUTF8( psz_utf8 ) == NULL )
459 memset( psz_part, 0, 6 );
463 static inline int RemoveLastUTF8Entity( char *psz, int len )
465 while( len && ( (psz[--len] & 0xc0) == 0x80 ) );
466 /* UTF8 continuation byte */
472 static int HandleKey( intf_thread_t *p_intf, int i_key )
474 intf_sys_t *p_sys = p_intf->p_sys;
477 if( p_sys->i_box_type == BOX_PLAYLIST && p_sys->p_playlist )
479 int b_ret = VLC_TRUE;
480 vlc_bool_t b_box_plidx_follow = VLC_FALSE;
485 /* Playlist Settings */
487 var_Get( p_sys->p_playlist, "random", &val );
488 val.b_bool = !val.b_bool;
489 var_Set( p_sys->p_playlist, "random", val );
492 var_Get( p_sys->p_playlist, "loop", &val );
493 val.b_bool = !val.b_bool;
494 var_Set( p_sys->p_playlist, "loop", val );
497 var_Get( p_sys->p_playlist, "repeat", &val );
498 val.b_bool = !val.b_bool;
499 var_Set( p_sys->p_playlist, "repeat", val );
504 playlist_RecursiveNodeSort( p_sys->p_playlist,
505 PlaylistGetRoot( p_intf ),
506 SORT_TITLE_NODES_FIRST, ORDER_NORMAL );
507 p_sys->b_need_update = VLC_TRUE;
510 playlist_RecursiveNodeSort( p_sys->p_playlist,
511 PlaylistGetRoot( p_intf ),
512 SORT_TITLE_NODES_FIRST, ORDER_REVERSE );
513 p_sys->b_need_update = VLC_TRUE;
518 switch( p_sys->i_current_view )
521 p_sys->i_current_view = VIEW_ONELEVEL;
524 p_sys->i_current_view = VIEW_CATEGORY;
526 //p_sys->b_need_update = VLC_TRUE;
527 PlaylistRebuild( p_intf );
530 /* Playlist navigation */
532 p_sys->i_box_plidx = 0;
535 p_sys->i_box_plidx = p_sys->p_playlist->items.i_size - 1;
538 p_sys->i_box_plidx--;
541 p_sys->i_box_plidx++;
544 p_sys->i_box_plidx -= p_sys->i_box_lines;
547 p_sys->i_box_plidx += p_sys->i_box_lines;
553 playlist_t *p_playlist = p_sys->p_playlist;
554 playlist_item_t *p_item;
556 vlc_mutex_lock( &p_playlist->object_lock );
557 p_item = p_sys->pp_plist[p_sys->i_box_plidx]->p_item;
558 if( p_item->i_children == -1 )
560 playlist_DeleteFromInput( p_playlist,
561 p_item->p_input->i_id, VLC_TRUE );
565 playlist_NodeDelete( p_playlist, p_item,
566 VLC_TRUE , VLC_FALSE );
568 vlc_mutex_unlock( &p_playlist->object_lock );
569 p_sys->b_need_update = VLC_TRUE;
576 if( p_sys->pp_plist[p_sys->i_box_plidx]->p_item->i_children
579 playlist_Control( p_sys->p_playlist, PLAYLIST_VIEWPLAY,
581 p_sys->pp_plist[p_sys->i_box_plidx]->p_item );
585 playlist_Control( p_sys->p_playlist, PLAYLIST_VIEWPLAY,
587 p_sys->pp_plist[p_sys->i_box_plidx]->p_item,
590 b_box_plidx_follow = VLC_TRUE;
599 int i_max = p_sys->i_plist_entries;
600 if( p_sys->i_box_plidx >= i_max ) p_sys->i_box_plidx = i_max - 1;
601 if( p_sys->i_box_plidx < 0 ) p_sys->i_box_plidx = 0;
602 if( PlaylistIsPlaying( p_intf,
603 p_sys->pp_plist[p_sys->i_box_plidx]->p_item ) )
604 b_box_plidx_follow = VLC_TRUE;
605 p_sys->b_box_plidx_follow = b_box_plidx_follow;
609 if( p_sys->i_box_type == BOX_BROWSE )
611 vlc_bool_t b_ret = VLC_TRUE;
612 /* Browser navigation */
616 p_sys->i_box_bidx = 0;
619 p_sys->i_box_bidx = p_sys->i_dir_entries - 1;
628 p_sys->i_box_bidx -= p_sys->i_box_lines;
631 p_sys->i_box_bidx += p_sys->i_box_lines;
633 case '.': /* Toggle show hidden files */
634 p_sys->b_show_hidden_files = ( p_sys->b_show_hidden_files ==
635 VLC_TRUE ? VLC_FALSE : VLC_TRUE );
642 if( p_sys->pp_dir_entries[p_sys->i_box_bidx]->b_file || i_key == ' ' )
644 int i_size_entry = strlen( p_sys->psz_current_dir ) +
645 strlen( p_sys->pp_dir_entries[p_sys->i_box_bidx]->psz_path ) + 2;
646 char *psz_uri = (char *)malloc( sizeof(char)*i_size_entry);
648 sprintf( psz_uri, "%s/%s", p_sys->psz_current_dir, p_sys->pp_dir_entries[p_sys->i_box_bidx]->psz_path );
650 playlist_Add( p_sys->p_playlist, psz_uri,
652 PLAYLIST_APPEND, PLAYLIST_END );
654 p_sys->i_box_type = BOX_PLAYLIST;
659 int i_size_entry = strlen( p_sys->psz_current_dir ) +
660 strlen( p_sys->pp_dir_entries[p_sys->i_box_bidx]->psz_path ) + 2;
661 char *psz_uri = (char *)malloc( sizeof(char)*i_size_entry);
663 sprintf( psz_uri, "%s/%s", p_sys->psz_current_dir, p_sys->pp_dir_entries[p_sys->i_box_bidx]->psz_path );
665 p_sys->psz_current_dir = strdup( psz_uri );
676 if( p_sys->i_box_bidx >= p_sys->i_dir_entries ) p_sys->i_box_bidx = p_sys->i_dir_entries - 1;
677 if( p_sys->i_box_bidx < 0 ) p_sys->i_box_bidx = 0;
681 else if( p_sys->i_box_type == BOX_HELP || p_sys->i_box_type == BOX_INFO )
686 p_sys->i_box_start = 0;
689 p_sys->i_box_start = p_sys->i_box_lines_total - 1;
692 if( p_sys->i_box_start > 0 ) p_sys->i_box_start--;
695 if( p_sys->i_box_start < p_sys->i_box_lines_total - 1 )
697 p_sys->i_box_start++;
701 p_sys->i_box_start -= p_sys->i_box_lines;
702 if( p_sys->i_box_start < 0 ) p_sys->i_box_start = 0;
705 p_sys->i_box_start += p_sys->i_box_lines;
706 if( p_sys->i_box_start >= p_sys->i_box_lines_total )
708 p_sys->i_box_start = p_sys->i_box_lines_total - 1;
715 else if( p_sys->i_box_type == BOX_NONE )
721 ManageSlider( p_intf );
724 p_sys->f_slider = 99.9;
725 ManageSlider( p_intf );
728 p_sys->f_slider += 5.0;
729 if( p_sys->f_slider >= 99.0 ) p_sys->f_slider = 99.0;
730 ManageSlider( p_intf );
733 p_sys->f_slider -= 5.0;
734 if( p_sys->f_slider < 0.0 ) p_sys->f_slider = 0.0;
735 ManageSlider( p_intf );
742 else if( p_sys->i_box_type == BOX_SEARCH && p_sys->psz_search_chain )
745 i_chain_len = strlen( p_sys->psz_search_chain );
753 if( i_chain_len > 0 )
755 p_sys->psz_old_search = strdup( p_sys->psz_search_chain );
757 else if( p_sys->psz_old_search )
759 SearchPlaylist( p_intf, p_sys->psz_old_search );
761 p_sys->i_box_type = BOX_PLAYLIST;
763 case 0x1b: /* Esc. */
764 p_sys->i_box_plidx = p_sys->i_before_search;
765 p_sys->i_box_type = BOX_PLAYLIST;
768 RemoveLastUTF8Entity( p_sys->psz_search_chain, i_chain_len );
772 char *psz_utf8 = KeyToUTF8( i_key, p_sys->psz_partial_keys );
774 if( psz_utf8 != NULL )
776 if( i_chain_len + strlen( psz_utf8 ) < SEARCH_CHAIN_SIZE )
778 strcpy( p_sys->psz_search_chain + i_chain_len,
786 if( p_sys->psz_old_search )
788 free( p_sys->psz_old_search );
789 p_sys->psz_old_search = NULL;
791 SearchPlaylist( p_intf, p_sys->psz_search_chain );
794 else if( p_sys->i_box_type == BOX_OPEN && p_sys->psz_open_chain )
796 int i_chain_len = strlen( p_sys->psz_open_chain );
797 playlist_t *p_playlist = p_sys->p_playlist;
806 if( p_playlist && i_chain_len > 0 )
809 playlist_Add( p_playlist, p_sys->psz_open_chain,
810 p_sys->psz_open_chain,
811 PLAYLIST_GO|PLAYLIST_APPEND, PLAYLIST_END );
813 p_sys->b_box_plidx_follow = VLC_TRUE;
815 p_sys->i_box_type = BOX_PLAYLIST;
817 case 0x1b: /* Esc. */
818 p_sys->i_box_type = BOX_PLAYLIST;
821 RemoveLastUTF8Entity( p_sys->psz_open_chain, i_chain_len );
825 char *psz_utf8 = KeyToUTF8( i_key, p_sys->psz_partial_keys );
827 if( psz_utf8 != NULL )
829 if( i_chain_len + strlen( psz_utf8 ) < OPEN_CHAIN_SIZE )
831 strcpy( p_sys->psz_open_chain + i_chain_len,
849 vlc_object_kill( p_intf->p_libvlc );
854 if( p_sys->i_box_type == BOX_INFO )
855 p_sys->i_box_type = BOX_NONE;
857 p_sys->i_box_type = BOX_INFO;
858 p_sys->i_box_lines_total = 0;
861 if( p_sys->i_box_type == BOX_LOG )
862 p_sys->i_box_type = BOX_NONE;
864 p_sys->i_box_type = BOX_LOG;
867 if( p_sys->i_box_type == BOX_PLAYLIST )
868 p_sys->i_box_type = BOX_NONE;
870 p_sys->i_box_type = BOX_PLAYLIST;
873 if( p_sys->i_box_type == BOX_BROWSE )
874 p_sys->i_box_type = BOX_NONE;
876 p_sys->i_box_type = BOX_BROWSE;
880 if( p_sys->i_box_type == BOX_HELP )
881 p_sys->i_box_type = BOX_NONE;
883 p_sys->i_box_type = BOX_HELP;
884 p_sys->i_box_lines_total = 0;
887 if( p_sys->i_box_type != BOX_SEARCH )
889 if( p_sys->psz_search_chain == NULL )
893 p_sys->psz_search_chain[0] = '\0';
894 p_sys->b_box_plidx_follow = VLC_FALSE;
895 p_sys->i_before_search = p_sys->i_box_plidx;
896 p_sys->i_box_type = BOX_SEARCH;
900 if( p_sys->i_box_type != BOX_OPEN )
902 if( p_sys->psz_open_chain == NULL )
906 p_sys->psz_open_chain[0] = '\0';
907 p_sys->i_box_type = BOX_OPEN;
913 p_sys->f_slider += 1.0;
914 if( p_sys->f_slider > 99.9 ) p_sys->f_slider = 99.9;
915 ManageSlider( p_intf );
919 p_sys->f_slider -= 1.0;
920 if( p_sys->f_slider < 0.0 ) p_sys->f_slider = 0.0;
921 ManageSlider( p_intf );
927 if( p_intf->p_sys->p_input )
929 vout_thread_t *p_vout;
930 p_vout = vlc_object_find( p_intf->p_sys->p_input,
931 VLC_OBJECT_VOUT, FIND_CHILD );
934 var_Get( p_vout, "fullscreen", &val );
935 val.b_bool = !val.b_bool;
936 var_Set( p_vout, "fullscreen", val );
937 vlc_object_release( p_vout );
941 playlist_t *p_playlist;
942 p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
946 var_Get( p_playlist, "fullscreen", &val );
947 val.b_bool = !val.b_bool;
948 var_Set( p_playlist, "fullscreen", val );
949 vlc_object_release( p_playlist );
961 if( p_intf->p_sys->p_playlist )
963 playlist_Stop( p_intf->p_sys->p_playlist );
974 val.b_bool = VLC_TRUE;
975 var_Set( p_sys->p_input, "prev-title", val );
982 val.b_bool = VLC_TRUE;
983 var_Set( p_sys->p_input, "next-title", val );
990 val.b_bool = VLC_TRUE;
991 var_Set( p_sys->p_input, "prev-chapter", val );
998 val.b_bool = VLC_TRUE;
999 var_Set( p_sys->p_input, "next-chapter", val );
1004 if( p_intf->p_sys->p_playlist )
1006 playlist_Prev( p_intf->p_sys->p_playlist );
1012 if( p_intf->p_sys->p_playlist )
1014 playlist_Next( p_intf->p_sys->p_playlist );
1020 aout_VolumeUp( p_intf, 1, NULL );
1025 aout_VolumeDown( p_intf, 1, NULL );
1030 * ^l should clear and redraw the screen
1041 static void ManageSlider( intf_thread_t *p_intf )
1043 intf_sys_t *p_sys = p_intf->p_sys;
1044 input_thread_t *p_input = p_sys->p_input;
1047 if( p_input == NULL )
1051 var_Get( p_input, "state", &val );
1052 if( val.i_int != PLAYING_S )
1057 var_Get( p_input, "position", &val );
1058 if( p_sys->f_slider == p_sys->f_slider_old )
1061 p_sys->f_slider_old = 100 * val.f_float;
1065 p_sys->f_slider_old = p_sys->f_slider;
1067 val.f_float = p_sys->f_slider / 100.0;
1068 var_Set( p_input, "position", val );
1072 static void SearchPlaylist( intf_thread_t *p_intf, char *psz_searchstring )
1077 intf_sys_t *p_sys = p_intf->p_sys;
1079 if( p_sys->i_before_search >= 0 )
1081 i_first = p_sys->i_before_search;
1084 if( ( ! psz_searchstring ) || strlen( psz_searchstring ) <= 0 )
1086 p_sys->i_box_plidx = p_sys->i_before_search;
1090 i_max = p_sys->i_plist_entries;
1092 i_item = SubSearchPlaylist( p_intf, psz_searchstring, i_first + 1, i_max );
1095 i_item = SubSearchPlaylist( p_intf, psz_searchstring, 0, i_first );
1098 if( i_item < 0 || i_item >= i_max ) return;
1100 p_sys->i_box_plidx = i_item;
1103 static int SubSearchPlaylist( intf_thread_t *p_intf, char *psz_searchstring,
1104 int i_start, int i_stop )
1106 intf_sys_t *p_sys = p_intf->p_sys;
1109 for( i = i_start + 1; i < i_stop; i++ )
1111 if( strcasestr( p_sys->pp_plist[i]->psz_display,
1112 psz_searchstring ) != NULL )
1123 static void mvnprintw( int y, int x, int w, const char *p_fmt, ... )
1129 va_start( vl_args, p_fmt );
1130 vasprintf( &p_buf, p_fmt, vl_args );
1139 if( ( i_len = strlen( p_buf ) ) > w )
1142 int i_cut = i_len - w;
1143 int x1 = i_len/2 - i_cut/2;
1144 int x2 = x1 + i_cut;
1148 memmove( &p_buf[x1], &p_buf[x2], i_len - x2 );
1157 psz_local = ToLocale( p_buf );
1158 mvprintw( y, x, "%s", psz_local );
1159 LocaleFree( p_buf );
1163 char *psz_local = ToLocale( p_buf );
1164 mvprintw( y, x, "%s", psz_local );
1165 LocaleFree( p_buf );
1166 mvhline( y, x + i_len, ' ', w - i_len );
1170 static void MainBoxWrite( intf_thread_t *p_intf, int l, int x, const char *p_fmt, ... )
1172 intf_sys_t *p_sys = p_intf->p_sys;
1177 if( l < p_sys->i_box_start || l - p_sys->i_box_start >= p_sys->i_box_lines )
1182 va_start( vl_args, p_fmt );
1183 vasprintf( &p_buf, p_fmt, vl_args );
1191 mvnprintw( p_sys->i_box_y + l - p_sys->i_box_start, x, COLS - x - 1, "%s", p_buf );
1194 static void Redraw( intf_thread_t *p_intf, time_t *t_last_refresh )
1196 intf_sys_t *p_sys = p_intf->p_sys;
1197 input_thread_t *p_input = p_sys->p_input;
1205 attrset( A_REVERSE );
1206 mvnprintw( y, 0, COLS, "VLC media player" " (ncurses interface) [ h for help ]" );
1207 attroff( A_REVERSE );
1211 if( p_input && !p_input->b_dead )
1213 char buf1[MSTRTIME_MAX_SIZE];
1214 char buf2[MSTRTIME_MAX_SIZE];
1216 vlc_value_t val_list;
1219 char *psz_uri = input_item_GetURI( input_GetItem( p_input ) );
1220 mvnprintw( y++, 0, COLS, " Source : %s", psz_uri );
1224 var_Get( p_input, "state", &val );
1225 if( val.i_int == PLAYING_S )
1227 mvnprintw( y++, 0, COLS, " State : Playing" );
1229 else if( val.i_int == OPENING_S )
1231 mvnprintw( y++, 0, COLS, " State : Openning/Connecting" );
1233 else if( val.i_int == BUFFERING_S )
1235 mvnprintw( y++, 0, COLS, " State : Buffering" );
1237 else if( val.i_int == PAUSE_S )
1239 mvnprintw( y++, 0, COLS, " State : Paused" );
1245 if( val.i_int != INIT_S && val.i_int != END_S )
1247 audio_volume_t i_volume;
1250 var_Get( p_input, "time", &val );
1251 msecstotimestr( buf1, val.i_time / 1000 );
1253 var_Get( p_input, "length", &val );
1254 msecstotimestr( buf2, val.i_time / 1000 );
1256 mvnprintw( y++, 0, COLS, " Position : %s/%s (%.2f%%)", buf1, buf2, p_sys->f_slider );
1259 aout_VolumeGet( p_intf, &i_volume );
1260 mvnprintw( y++, 0, COLS, " Volume : %i%%", i_volume*200/AOUT_VOLUME_MAX );
1263 if( !var_Get( p_input, "title", &val ) )
1265 var_Change( p_input, "title", VLC_VAR_GETCHOICES, &val_list, NULL );
1266 if( val_list.p_list->i_count > 0 )
1268 mvnprintw( y++, 0, COLS, " Title : %d/%d", val.i_int, val_list.p_list->i_count );
1270 var_Change( p_input, "title", VLC_VAR_FREELIST, &val_list, NULL );
1274 if( !var_Get( p_input, "chapter", &val ) )
1276 var_Change( p_input, "chapter", VLC_VAR_GETCHOICES, &val_list, NULL );
1277 if( val_list.p_list->i_count > 0 )
1279 mvnprintw( y++, 0, COLS, " Chapter : %d/%d", val.i_int, val_list.p_list->i_count );
1281 var_Change( p_input, "chapter", VLC_VAR_FREELIST, &val_list, NULL );
1291 mvnprintw( y++, 0, COLS, "Source: <no current item>" );
1292 DrawEmptyLine( p_sys->w, y++, 0, COLS );
1293 DrawEmptyLine( p_sys->w, y++, 0, COLS );
1294 DrawEmptyLine( p_sys->w, y++, 0, COLS );
1297 DrawBox( p_sys->w, y, 0, 3, COLS, "" );
1298 DrawEmptyLine( p_sys->w, y+1, 1, COLS-2);
1299 DrawLine( p_sys->w, y+1, 1, (int)(p_intf->p_sys->f_slider/100.0 * (COLS -2)) );
1302 p_sys->i_box_y = y + 1;
1303 p_sys->i_box_lines = LINES - y - 2;
1308 if( p_sys->i_box_type == BOX_HELP )
1312 DrawBox( p_sys->w, y++, 0, h, COLS, " Help " );
1314 MainBoxWrite( p_intf, l++, 1, "[Display]" );
1315 MainBoxWrite( p_intf, l++, 1, " h,H Show/Hide help box" );
1316 MainBoxWrite( p_intf, l++, 1, " i Show/Hide info box" );
1317 MainBoxWrite( p_intf, l++, 1, " L Show/Hide messages box" );
1318 MainBoxWrite( p_intf, l++, 1, " P Show/Hide playlist box" );
1319 MainBoxWrite( p_intf, l++, 1, " B Show/Hide filebrowser" );
1320 MainBoxWrite( p_intf, l++, 1, "" );
1322 MainBoxWrite( p_intf, l++, 1, "[Global]" );
1323 MainBoxWrite( p_intf, l++, 1, " q, Q Quit" );
1324 MainBoxWrite( p_intf, l++, 1, " s Stop" );
1325 MainBoxWrite( p_intf, l++, 1, " <space> Pause/Play" );
1326 MainBoxWrite( p_intf, l++, 1, " f Toggle Fullscreen" );
1327 MainBoxWrite( p_intf, l++, 1, " n, p Next/Previous playlist item" );
1328 MainBoxWrite( p_intf, l++, 1, " [, ] Next/Previous title" );
1329 MainBoxWrite( p_intf, l++, 1, " <, > Next/Previous chapter" );
1330 MainBoxWrite( p_intf, l++, 1, " <right> Seek +1%%" );
1331 MainBoxWrite( p_intf, l++, 1, " <left> Seek -1%%" );
1332 MainBoxWrite( p_intf, l++, 1, " a Volume Up" );
1333 MainBoxWrite( p_intf, l++, 1, " z Volume Down" );
1334 MainBoxWrite( p_intf, l++, 1, "" );
1336 MainBoxWrite( p_intf, l++, 1, "[Playlist]" );
1337 MainBoxWrite( p_intf, l++, 1, " r Random" );
1338 MainBoxWrite( p_intf, l++, 1, " l Loop Playlist" );
1339 MainBoxWrite( p_intf, l++, 1, " R Repeat item" );
1340 MainBoxWrite( p_intf, l++, 1, " o Order Playlist by title" );
1341 MainBoxWrite( p_intf, l++, 1, " O Reverse order Playlist by title" );
1342 MainBoxWrite( p_intf, l++, 1, " / Look for an item" );
1343 MainBoxWrite( p_intf, l++, 1, " A Add an entry" );
1344 MainBoxWrite( p_intf, l++, 1, " D, <del> Delete an entry" );
1345 MainBoxWrite( p_intf, l++, 1, " <backspace> Delete an entry" );
1346 MainBoxWrite( p_intf, l++, 1, "" );
1348 MainBoxWrite( p_intf, l++, 1, "[Filebrowser]" );
1349 MainBoxWrite( p_intf, l++, 1, " <enter> Add the selected file to the playlist" );
1350 MainBoxWrite( p_intf, l++, 1, " <space> Add the selected directory to the playlist" );
1351 MainBoxWrite( p_intf, l++, 1, " . Show/Hide hidden files" );
1352 MainBoxWrite( p_intf, l++, 1, "" );
1354 MainBoxWrite( p_intf, l++, 1, "[Boxes]" );
1355 MainBoxWrite( p_intf, l++, 1, " <up>,<down> Navigate through the box line by line" );
1356 MainBoxWrite( p_intf, l++, 1, " <pgup>,<pgdown> Navigate through the box page by page" );
1357 MainBoxWrite( p_intf, l++, 1, "" );
1359 MainBoxWrite( p_intf, l++, 1, "[Player]" );
1360 MainBoxWrite( p_intf, l++, 1, " <up>,<down> Seek +/-5%%" );
1361 MainBoxWrite( p_intf, l++, 1, "" );
1363 MainBoxWrite( p_intf, l++, 1, "[Miscellaneous]" );
1364 MainBoxWrite( p_intf, l++, 1, " Ctrl-l Refresh the screen" );
1366 p_sys->i_box_lines_total = l;
1367 if( p_sys->i_box_start >= p_sys->i_box_lines_total )
1369 p_sys->i_box_start = p_sys->i_box_lines_total - 1;
1372 if( l - p_sys->i_box_start < p_sys->i_box_lines )
1374 y += l - p_sys->i_box_start;
1378 y += p_sys->i_box_lines;
1381 else if( p_sys->i_box_type == BOX_INFO )
1385 DrawBox( p_sys->w, y++, 0, h, COLS, " Information " );
1390 vlc_mutex_lock( &input_GetItem(p_input)->lock );
1391 for( i = 0; i < input_GetItem(p_input)->i_categories; i++ )
1393 info_category_t *p_category = input_GetItem(p_input)->pp_categories[i];
1394 if( y >= y_end ) break;
1395 MainBoxWrite( p_intf, l++, 1, " [%s]", p_category->psz_name );
1396 for( j = 0; j < p_category->i_infos; j++ )
1398 info_t *p_info = p_category->pp_infos[j];
1399 if( y >= y_end ) break;
1400 MainBoxWrite( p_intf, l++, 1, " %s: %s", p_info->psz_name, p_info->psz_value );
1403 vlc_mutex_unlock( &input_GetItem(p_input)->lock );
1407 MainBoxWrite( p_intf, l++, 1, "No item currently playing" );
1409 p_sys->i_box_lines_total = l;
1410 if( p_sys->i_box_start >= p_sys->i_box_lines_total )
1412 p_sys->i_box_start = p_sys->i_box_lines_total - 1;
1415 if( l - p_sys->i_box_start < p_sys->i_box_lines )
1417 y += l - p_sys->i_box_start;
1421 y += p_sys->i_box_lines;
1424 else if( p_sys->i_box_type == BOX_LOG )
1430 DrawBox( p_sys->w, y++, 0, h, COLS, " Logs " );
1432 i_start = p_intf->p_sys->p_sub->i_start;
1434 vlc_mutex_lock( p_intf->p_sys->p_sub->p_lock );
1435 i_stop = *p_intf->p_sys->p_sub->pi_stop;
1436 vlc_mutex_unlock( p_intf->p_sys->p_sub->p_lock );
1440 static const char *ppsz_type[4] = { "", "error", "warning", "debug" };
1441 if( i_line >= h - 2 )
1447 if( i_stop < 0 ) i_stop += VLC_MSG_QSIZE;
1448 if( i_stop == i_start )
1452 mvnprintw( y + h-2-i_line, 1, COLS - 2, " [%s] %s",
1453 ppsz_type[p_sys->p_sub->p_msg[i_stop].i_type],
1454 p_sys->p_sub->p_msg[i_stop].psz_msg );
1457 vlc_mutex_lock( p_intf->p_sys->p_sub->p_lock );
1458 p_intf->p_sys->p_sub->i_start = i_stop;
1459 vlc_mutex_unlock( p_intf->p_sys->p_sub->p_lock );
1462 else if( p_sys->i_box_type == BOX_BROWSE )
1464 /* Filebrowser box */
1465 int i_start, i_stop;
1467 DrawBox( p_sys->w, y++, 0, h, COLS, " Browse " );
1469 if( p_sys->i_box_bidx >= p_sys->i_dir_entries ) p_sys->i_box_plidx = p_sys->i_dir_entries - 1;
1470 if( p_sys->i_box_bidx < 0 ) p_sys->i_box_bidx = 0;
1472 if( p_sys->i_box_bidx < (h - 2)/2 )
1477 else if( p_sys->i_dir_entries - p_sys->i_box_bidx > (h - 2)/2 )
1479 i_start = p_sys->i_box_bidx - (h - 2)/2;
1480 i_stop = i_start + h - 2;
1484 i_stop = p_sys->i_dir_entries;
1485 i_start = p_sys->i_dir_entries - (h - 2);
1491 if( i_stop > p_sys->i_dir_entries )
1493 i_stop = p_sys->i_dir_entries;
1496 for( i_item = i_start; i_item < i_stop; i_item++ )
1498 vlc_bool_t b_selected = ( p_sys->i_box_bidx == i_item );
1500 if( y >= y_end ) break;
1503 attrset( A_REVERSE );
1505 mvnprintw( y++, 1, COLS - 2, " %c %s", p_sys->pp_dir_entries[i_item]->b_file == VLC_TRUE ? ' ' : '+',
1506 p_sys->pp_dir_entries[i_item]->psz_path );
1509 attroff( A_REVERSE );
1514 else if( ( p_sys->i_box_type == BOX_PLAYLIST ||
1515 p_sys->i_box_type == BOX_SEARCH ||
1516 p_sys->i_box_type == BOX_OPEN ) && p_sys->p_playlist )
1519 int i_start, i_stop, i_max = p_sys->i_plist_entries;
1523 switch( p_sys->i_current_view )
1526 psz_title = strdup( " Playlist (All, one level) " );
1529 psz_title = strdup( " Playlist (By category) " );
1532 psz_title = strdup( " Playlist (Manually added) " );
1535 DrawBox( p_sys->w, y++, 0, h, COLS, psz_title );
1537 if( p_sys->b_need_update || p_sys->pp_plist == NULL )
1539 PlaylistRebuild( p_intf );
1541 if( p_sys->b_box_plidx_follow )
1543 FindIndex( p_intf );
1546 if( p_sys->i_box_plidx < 0 ) p_sys->i_box_plidx = 0;
1547 if( p_sys->i_box_plidx < 0 ) p_sys->i_box_plidx = 0;
1548 if( p_sys->i_box_plidx >= i_max ) p_sys->i_box_plidx = i_max - 1;
1550 if( p_sys->i_box_plidx < (h - 2)/2 )
1555 else if( i_max - p_sys->i_box_plidx > (h - 2)/2 )
1557 i_start = p_sys->i_box_plidx - (h - 2)/2;
1558 i_stop = i_start + h - 2;
1563 i_start = i_max - (h - 2);
1569 if( i_stop > i_max )
1574 for( i_item = i_start; i_item < i_stop; i_item++ )
1576 vlc_bool_t b_selected = ( p_sys->i_box_plidx == i_item );
1577 int c = ( PlaylistIsPlaying( p_intf,
1578 p_sys->pp_plist[i_item]->p_item ) ) ? '>' : ' ';
1580 if( y >= y_end ) break;
1583 attrset( A_REVERSE );
1585 mvnprintw( y++, 1, COLS - 2, "%c%s", c,
1586 p_sys->pp_plist[i_item]->psz_display );
1589 attroff( A_REVERSE );
1598 if( p_sys->i_box_type == BOX_SEARCH )
1600 DrawEmptyLine( p_sys->w, 7, 1, COLS-2 );
1601 if( p_sys->psz_search_chain )
1603 if( strlen( p_sys->psz_search_chain ) == 0 &&
1604 p_sys->psz_old_search != NULL )
1606 /* Searching next entry */
1607 mvnprintw( 7, 1, COLS-2, "Find: %s", p_sys->psz_old_search );
1611 mvnprintw( 7, 1, COLS-2, "Find: %s", p_sys->psz_search_chain );
1615 if( p_sys->i_box_type == BOX_OPEN )
1617 if( p_sys->psz_open_chain )
1619 DrawEmptyLine( p_sys->w, 7, 1, COLS-2 );
1620 mvnprintw( 7, 1, COLS-2, "Open: %s", p_sys->psz_open_chain );
1626 DrawEmptyLine( p_sys->w, y++, 1, COLS - 2 );
1631 *t_last_refresh = time( 0 );
1634 static playlist_item_t *PlaylistGetRoot( intf_thread_t *p_intf )
1636 intf_sys_t *p_sys = p_intf->p_sys;
1637 playlist_t *p_playlist = p_sys->p_playlist;
1639 if( p_playlist == NULL )
1644 switch( p_sys->i_current_view )
1647 return p_playlist->p_root_category;
1649 return p_playlist->p_root_onelevel;
1653 static void PlaylistRebuild( intf_thread_t *p_intf )
1655 intf_sys_t *p_sys = p_intf->p_sys;
1656 playlist_t *p_playlist = p_sys->p_playlist;
1658 if( p_playlist == NULL )
1663 vlc_mutex_lock( &p_playlist->object_lock );
1665 /* First clear the old one */
1666 PlaylistDestroy( p_intf );
1668 /* Build the new one */
1669 PlaylistAddNode( p_intf, PlaylistGetRoot( p_intf ), 0, "" );
1671 p_sys->b_need_update = VLC_FALSE;
1673 vlc_mutex_unlock( &p_playlist->object_lock );
1676 static void PlaylistAddNode( intf_thread_t *p_intf, playlist_item_t *p_node,
1677 int i, const char *c )
1679 intf_sys_t *p_sys = p_intf->p_sys;
1680 playlist_item_t *p_child;
1684 psz_tmp = (char *)malloc( strlen( c ) + 4 );
1685 if( psz_tmp == NULL ) return;
1686 for( k = 0; k < p_node->i_children; k++ )
1688 struct pl_item_t *p_pl_item;
1692 p_child = p_node->pp_children[k];
1693 i_size = strlen( c ) + strlen( p_child->p_input->psz_name ) + 4;
1694 buff = (char *)malloc( sizeof( char ) * i_size );
1695 p_pl_item = (struct pl_item_t *)malloc( sizeof( struct pl_item_t ) );
1696 if( p_pl_item == NULL || buff == NULL ) return;
1700 sprintf( buff, "%s%c-%s", c, k == p_node->i_children - 1 ?
1701 '`' : '|', p_child->p_input->psz_name );
1705 sprintf( buff, " %s", p_child->p_input->psz_name );
1707 p_pl_item->psz_display = strdup( buff );
1708 p_pl_item->p_item = p_child;
1709 INSERT_ELEM( p_sys->pp_plist, p_sys->i_plist_entries,
1710 p_sys->i_plist_entries, p_pl_item );
1714 if( p_child->i_children > 0 )
1716 sprintf( psz_tmp, "%s%c ", c,
1717 k == p_node->i_children - 1 ? ' ' : '|' );
1718 PlaylistAddNode( p_intf, p_child, i,
1719 strlen( c ) ? psz_tmp : " " );
1725 static int PlaylistChanged( vlc_object_t *p_this, const char *psz_variable,
1726 vlc_value_t oval, vlc_value_t nval, void *param )
1728 intf_thread_t *p_intf = (intf_thread_t *)param;
1729 p_intf->p_sys->b_need_update = VLC_TRUE;
1734 static inline vlc_bool_t PlaylistIsPlaying( intf_thread_t *p_intf,
1735 playlist_item_t *p_item )
1737 playlist_item_t *p_played_item = p_intf->p_sys->p_playlist->status.p_item;
1738 return( p_item != NULL && p_played_item != NULL &&
1739 p_item->p_input != NULL && p_played_item->p_input != NULL &&
1740 p_item->p_input->i_id == p_played_item->p_input->i_id );
1743 static void FindIndex( intf_thread_t *p_intf )
1745 intf_sys_t *p_sys = p_intf->p_sys;
1748 if( p_sys->i_box_plidx < p_sys->i_plist_entries &&
1749 p_sys->i_box_plidx >= 0 &&
1750 PlaylistIsPlaying( p_intf,
1751 p_sys->pp_plist[p_sys->i_box_plidx]->p_item ) )
1756 for( i = 0; i < p_sys->i_plist_entries; i++ )
1758 if( PlaylistIsPlaying( p_intf, p_sys->pp_plist[i]->p_item ) )
1760 p_sys->i_box_plidx = i;
1766 static void PlaylistDestroy( intf_thread_t *p_intf )
1768 intf_sys_t *p_sys = p_intf->p_sys;
1771 for( i = 0; i < p_sys->i_plist_entries; i++ )
1773 struct pl_item_t *p_pl_item = p_sys->pp_plist[i];
1774 free( p_pl_item->psz_display );
1775 REMOVE_ELEM( p_sys->pp_plist, p_sys->i_plist_entries, i );
1778 p_sys->pp_plist = NULL;
1779 p_sys->i_plist_entries = 0;
1782 static void Eject( intf_thread_t *p_intf )
1784 char *psz_device = NULL, *psz_parser, *psz_name;
1787 * Get the active input
1788 * Determine whether we can eject a media, ie it's a DVD, VCD or CD-DA
1789 * If it's neither of these, then return
1792 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1795 if( p_playlist == NULL )
1800 vlc_mutex_lock( &p_playlist->object_lock );
1802 if( p_playlist->status.p_item == NULL )
1804 vlc_mutex_unlock( &p_playlist->object_lock );
1805 vlc_object_release( p_playlist );
1809 psz_name = p_playlist->status.p_item->p_input->psz_name;
1813 if( !strncmp(psz_name, "dvd://", 4) )
1815 switch( psz_name[strlen("dvd://")] )
1819 psz_device = config_GetPsz( p_intf, "dvd" );
1822 /* Omit the first MRL-selector characters */
1823 psz_device = strdup( psz_name + strlen("dvd://" ) );
1827 else if( !strncmp(psz_name, VCD_MRL, strlen(VCD_MRL)) )
1829 switch( psz_name[strlen(VCD_MRL)] )
1833 psz_device = config_GetPsz( p_intf, VCD_MRL );
1836 /* Omit the beginning MRL-selector characters */
1837 psz_device = strdup( psz_name + strlen(VCD_MRL) );
1841 else if( !strncmp(psz_name, CDDA_MRL, strlen(CDDA_MRL) ) )
1843 switch( psz_name[strlen(CDDA_MRL)] )
1847 psz_device = config_GetPsz( p_intf, "cd-audio" );
1850 /* Omit the beginning MRL-selector characters */
1851 psz_device = strdup( psz_name + strlen(CDDA_MRL) );
1857 psz_device = strdup( psz_name );
1861 vlc_mutex_unlock( &p_playlist->object_lock );
1862 vlc_object_release( p_playlist );
1864 if( psz_device == NULL )
1869 /* Remove what we have after @ */
1870 psz_parser = psz_device;
1871 for( psz_parser = psz_device ; *psz_parser ; psz_parser++ )
1873 if( *psz_parser == '@' )
1880 /* If there's a stream playing, we aren't allowed to eject ! */
1881 if( p_intf->p_sys->p_input == NULL )
1883 msg_Dbg( p_intf, "ejecting %s", psz_device );
1885 intf_Eject( p_intf, psz_device );
1892 static int comp_dir_entries( const void *pp_dir_entry1,
1893 const void *pp_dir_entry2 )
1895 struct dir_entry_t *p_dir_entry1 = *(struct dir_entry_t**)pp_dir_entry1;
1896 struct dir_entry_t *p_dir_entry2 = *(struct dir_entry_t**)pp_dir_entry2;
1897 if ( p_dir_entry1->b_file == p_dir_entry2->b_file ) {
1898 return strcasecmp( p_dir_entry1->psz_path, p_dir_entry2->psz_path );
1902 return ( p_dir_entry1->b_file ? 1 : -1 );
1906 static void ReadDir( intf_thread_t *p_intf )
1908 intf_sys_t *p_sys = p_intf->p_sys;
1912 if( p_sys->psz_current_dir && *p_sys->psz_current_dir )
1917 p_current_dir = utf8_opendir( p_sys->psz_current_dir );
1919 if( p_current_dir == NULL )
1921 /* something went bad, get out of here ! */
1923 msg_Warn( p_intf, "cannot open directory `%s' (%s)",
1924 p_sys->psz_current_dir, strerror(errno));
1926 msg_Warn( p_intf, "cannot open directory `%s'", p_sys->psz_current_dir );
1931 /* Clean the old shit */
1932 for( i = 0; i < p_sys->i_dir_entries; i++ )
1934 struct dir_entry_t *p_dir_entry = p_sys->pp_dir_entries[i];
1935 free( p_dir_entry->psz_path );
1936 REMOVE_ELEM( p_sys->pp_dir_entries, p_sys->i_dir_entries, i );
1937 free( p_dir_entry );
1939 p_sys->pp_dir_entries = NULL;
1940 p_sys->i_dir_entries = 0;
1942 /* while we still have entries in the directory */
1943 while( ( psz_entry = utf8_readdir( p_current_dir ) ) != NULL )
1945 #if defined( S_ISDIR )
1946 struct stat stat_data;
1948 struct dir_entry_t *p_dir_entry;
1949 int i_size_entry = strlen( p_sys->psz_current_dir ) +
1950 strlen( psz_entry ) + 2;
1953 if( p_sys->b_show_hidden_files == VLC_FALSE &&
1954 ( strlen( psz_entry ) && psz_entry[0] == '.' ) &&
1955 strcmp( psz_entry, ".." ) )
1961 psz_uri = (char *)malloc( sizeof(char)*i_size_entry);
1962 sprintf( psz_uri, "%s/%s", p_sys->psz_current_dir, psz_entry );
1964 if( !( p_dir_entry = malloc( sizeof( struct dir_entry_t) ) ) )
1971 #if defined( S_ISDIR )
1972 if( !utf8_stat( psz_uri, &stat_data )
1973 && S_ISDIR(stat_data.st_mode) )
1974 /*#elif defined( DT_DIR )
1975 if( p_dir_content->d_type & DT_DIR )*/
1980 p_dir_entry->psz_path = strdup( psz_entry );
1981 p_dir_entry->b_file = VLC_FALSE;
1982 INSERT_ELEM( p_sys->pp_dir_entries, p_sys->i_dir_entries,
1983 p_sys->i_dir_entries, p_dir_entry );
1987 p_dir_entry->psz_path = strdup( psz_entry );
1988 p_dir_entry->b_file = VLC_TRUE;
1989 INSERT_ELEM( p_sys->pp_dir_entries, p_sys->i_dir_entries,
1990 p_sys->i_dir_entries, p_dir_entry );
1998 qsort( p_sys->pp_dir_entries, p_sys->i_dir_entries,
1999 sizeof(struct dir_entry_t*), &comp_dir_entries );
2001 closedir( p_current_dir );
2006 msg_Dbg( p_intf, "no current dir set" );
2011 static void PlayPause( intf_thread_t *p_intf )
2013 input_thread_t *p_input = p_intf->p_sys->p_input;
2018 var_Get( p_input, "state", &val );
2019 if( val.i_int != PAUSE_S )
2021 val.i_int = PAUSE_S;
2025 val.i_int = PLAYING_S;
2027 var_Set( p_input, "state", val );
2029 else if( p_intf->p_sys->p_playlist )
2031 playlist_Play( p_intf->p_sys->p_playlist );
2035 /****************************************************************************
2037 ****************************************************************************/
2038 static void DrawBox( WINDOW *win, int y, int x, int h, int w, const char *title )
2043 if( w > 3 && h > 2 )
2045 if( title == NULL ) title = "";
2046 i_len = strlen( title );
2048 if( i_len > w - 2 ) i_len = w - 2;
2050 mvwaddch( win, y, x, ACS_ULCORNER );
2051 mvwhline( win, y, x+1, ACS_HLINE, ( w-i_len-2)/2 );
2052 mvwprintw( win,y, x+1+(w-i_len-2)/2, "%s", title );
2053 mvwhline( win, y, x+(w-i_len)/2+i_len, ACS_HLINE, w - 1 - ((w-i_len)/2+i_len) );
2054 mvwaddch( win, y, x+w-1,ACS_URCORNER );
2056 for( i = 0; i < h-2; i++ )
2058 mvwaddch( win, y+i+1, x, ACS_VLINE );
2059 mvwaddch( win, y+i+1, x+w-1, ACS_VLINE );
2062 mvwaddch( win, y+h-1, x, ACS_LLCORNER );
2063 mvwhline( win, y+h-1, x+1, ACS_HLINE, w - 2 );
2064 mvwaddch( win, y+h-1, x+w-1, ACS_LRCORNER );
2068 static void DrawEmptyLine( WINDOW *win, int y, int x, int w )
2072 mvhline( y, x, ' ', w );
2076 static void DrawLine( WINDOW *win, int y, int x, int w )
2080 attrset( A_REVERSE );
2081 mvhline( y, x, ' ', w );
2082 attroff( A_REVERSE );