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 */
35 #include <ncursesw/curses.h>
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, ... )
1128 size_t i_char_len; /* UCS character length */
1129 size_t i_width; /* Display width */
1130 wchar_t *psz_wide; /* wchar_t representation of p_buf */
1132 va_start( vl_args, p_fmt );
1133 vasprintf( &p_buf, p_fmt, vl_args );
1136 if( ( p_buf == NULL ) || ( w <= 0 ) )
1139 i_len = strlen( p_buf );
1140 psz_wide = (wchar_t *) malloc( sizeof( wchar_t ) * ( i_len + 1 ) );
1142 i_char_len = mbstowcs( psz_wide, p_buf, i_len );
1144 if( i_char_len == -1 ) /* an invalid character was encountered */
1148 i_width = wcswidth( psz_wide, i_char_len );
1149 if( i_width == -1 ) /* a non printable character was encountered */
1154 { /* FIXME: ellipsize psz_wide while keeping the width in mind */
1156 int i_cut = i_len - w;
1157 int x1 = i_len/2 - i_cut/2;
1158 int x2 = x1 + i_cut;
1162 memmove( &p_buf[x1], &p_buf[x2], i_len - x2 );
1171 psz_local = ToLocale( p_buf );
1172 mvprintw( y, x, "%s", psz_local );
1173 LocaleFree( p_buf );
1177 char *psz_local = ToLocale( p_buf );
1178 mvprintw( y, x, "%s", psz_local );
1179 LocaleFree( p_buf );
1180 mvhline( y, x + i_width, ' ', w - i_width );
1183 static void MainBoxWrite( intf_thread_t *p_intf, int l, int x, const char *p_fmt, ... )
1185 intf_sys_t *p_sys = p_intf->p_sys;
1190 if( l < p_sys->i_box_start || l - p_sys->i_box_start >= p_sys->i_box_lines )
1195 va_start( vl_args, p_fmt );
1196 vasprintf( &p_buf, p_fmt, vl_args );
1204 mvnprintw( p_sys->i_box_y + l - p_sys->i_box_start, x, COLS - x - 1, "%s", p_buf );
1207 static void Redraw( intf_thread_t *p_intf, time_t *t_last_refresh )
1209 intf_sys_t *p_sys = p_intf->p_sys;
1210 input_thread_t *p_input = p_sys->p_input;
1218 attrset( A_REVERSE );
1219 mvnprintw( y, 0, COLS, "VLC media player" " (ncurses interface) [ h for help ]" );
1220 attroff( A_REVERSE );
1224 if( p_input && !p_input->b_dead )
1226 char buf1[MSTRTIME_MAX_SIZE];
1227 char buf2[MSTRTIME_MAX_SIZE];
1229 vlc_value_t val_list;
1232 char *psz_uri = input_item_GetURI( input_GetItem( p_input ) );
1233 mvnprintw( y++, 0, COLS, " Source : %s", psz_uri );
1237 var_Get( p_input, "state", &val );
1238 if( val.i_int == PLAYING_S )
1240 mvnprintw( y++, 0, COLS, " State : Playing" );
1242 else if( val.i_int == OPENING_S )
1244 mvnprintw( y++, 0, COLS, " State : Openning/Connecting" );
1246 else if( val.i_int == BUFFERING_S )
1248 mvnprintw( y++, 0, COLS, " State : Buffering" );
1250 else if( val.i_int == PAUSE_S )
1252 mvnprintw( y++, 0, COLS, " State : Paused" );
1258 if( val.i_int != INIT_S && val.i_int != END_S )
1260 audio_volume_t i_volume;
1263 var_Get( p_input, "time", &val );
1264 msecstotimestr( buf1, val.i_time / 1000 );
1266 var_Get( p_input, "length", &val );
1267 msecstotimestr( buf2, val.i_time / 1000 );
1269 mvnprintw( y++, 0, COLS, " Position : %s/%s (%.2f%%)", buf1, buf2, p_sys->f_slider );
1272 aout_VolumeGet( p_intf, &i_volume );
1273 mvnprintw( y++, 0, COLS, " Volume : %i%%", i_volume*200/AOUT_VOLUME_MAX );
1276 if( !var_Get( p_input, "title", &val ) )
1278 var_Change( p_input, "title", VLC_VAR_GETCHOICES, &val_list, NULL );
1279 if( val_list.p_list->i_count > 0 )
1281 mvnprintw( y++, 0, COLS, " Title : %d/%d", val.i_int, val_list.p_list->i_count );
1283 var_Change( p_input, "title", VLC_VAR_FREELIST, &val_list, NULL );
1287 if( !var_Get( p_input, "chapter", &val ) )
1289 var_Change( p_input, "chapter", VLC_VAR_GETCHOICES, &val_list, NULL );
1290 if( val_list.p_list->i_count > 0 )
1292 mvnprintw( y++, 0, COLS, " Chapter : %d/%d", val.i_int, val_list.p_list->i_count );
1294 var_Change( p_input, "chapter", VLC_VAR_FREELIST, &val_list, NULL );
1304 mvnprintw( y++, 0, COLS, "Source: <no current item>" );
1305 DrawEmptyLine( p_sys->w, y++, 0, COLS );
1306 DrawEmptyLine( p_sys->w, y++, 0, COLS );
1307 DrawEmptyLine( p_sys->w, y++, 0, COLS );
1310 DrawBox( p_sys->w, y, 0, 3, COLS, "" );
1311 DrawEmptyLine( p_sys->w, y+1, 1, COLS-2);
1312 DrawLine( p_sys->w, y+1, 1, (int)(p_intf->p_sys->f_slider/100.0 * (COLS -2)) );
1315 p_sys->i_box_y = y + 1;
1316 p_sys->i_box_lines = LINES - y - 2;
1321 if( p_sys->i_box_type == BOX_HELP )
1325 DrawBox( p_sys->w, y++, 0, h, COLS, " Help " );
1327 MainBoxWrite( p_intf, l++, 1, "[Display]" );
1328 MainBoxWrite( p_intf, l++, 1, " h,H Show/Hide help box" );
1329 MainBoxWrite( p_intf, l++, 1, " i Show/Hide info box" );
1330 MainBoxWrite( p_intf, l++, 1, " L Show/Hide messages box" );
1331 MainBoxWrite( p_intf, l++, 1, " P Show/Hide playlist box" );
1332 MainBoxWrite( p_intf, l++, 1, " B Show/Hide filebrowser" );
1333 MainBoxWrite( p_intf, l++, 1, "" );
1335 MainBoxWrite( p_intf, l++, 1, "[Global]" );
1336 MainBoxWrite( p_intf, l++, 1, " q, Q Quit" );
1337 MainBoxWrite( p_intf, l++, 1, " s Stop" );
1338 MainBoxWrite( p_intf, l++, 1, " <space> Pause/Play" );
1339 MainBoxWrite( p_intf, l++, 1, " f Toggle Fullscreen" );
1340 MainBoxWrite( p_intf, l++, 1, " n, p Next/Previous playlist item" );
1341 MainBoxWrite( p_intf, l++, 1, " [, ] Next/Previous title" );
1342 MainBoxWrite( p_intf, l++, 1, " <, > Next/Previous chapter" );
1343 MainBoxWrite( p_intf, l++, 1, " <right> Seek +1%%" );
1344 MainBoxWrite( p_intf, l++, 1, " <left> Seek -1%%" );
1345 MainBoxWrite( p_intf, l++, 1, " a Volume Up" );
1346 MainBoxWrite( p_intf, l++, 1, " z Volume Down" );
1347 MainBoxWrite( p_intf, l++, 1, "" );
1349 MainBoxWrite( p_intf, l++, 1, "[Playlist]" );
1350 MainBoxWrite( p_intf, l++, 1, " r Random" );
1351 MainBoxWrite( p_intf, l++, 1, " l Loop Playlist" );
1352 MainBoxWrite( p_intf, l++, 1, " R Repeat item" );
1353 MainBoxWrite( p_intf, l++, 1, " o Order Playlist by title" );
1354 MainBoxWrite( p_intf, l++, 1, " O Reverse order Playlist by title" );
1355 MainBoxWrite( p_intf, l++, 1, " / Look for an item" );
1356 MainBoxWrite( p_intf, l++, 1, " A Add an entry" );
1357 MainBoxWrite( p_intf, l++, 1, " D, <del> Delete an entry" );
1358 MainBoxWrite( p_intf, l++, 1, " <backspace> Delete an entry" );
1359 MainBoxWrite( p_intf, l++, 1, "" );
1361 MainBoxWrite( p_intf, l++, 1, "[Filebrowser]" );
1362 MainBoxWrite( p_intf, l++, 1, " <enter> Add the selected file to the playlist" );
1363 MainBoxWrite( p_intf, l++, 1, " <space> Add the selected directory to the playlist" );
1364 MainBoxWrite( p_intf, l++, 1, " . Show/Hide hidden files" );
1365 MainBoxWrite( p_intf, l++, 1, "" );
1367 MainBoxWrite( p_intf, l++, 1, "[Boxes]" );
1368 MainBoxWrite( p_intf, l++, 1, " <up>,<down> Navigate through the box line by line" );
1369 MainBoxWrite( p_intf, l++, 1, " <pgup>,<pgdown> Navigate through the box page by page" );
1370 MainBoxWrite( p_intf, l++, 1, "" );
1372 MainBoxWrite( p_intf, l++, 1, "[Player]" );
1373 MainBoxWrite( p_intf, l++, 1, " <up>,<down> Seek +/-5%%" );
1374 MainBoxWrite( p_intf, l++, 1, "" );
1376 MainBoxWrite( p_intf, l++, 1, "[Miscellaneous]" );
1377 MainBoxWrite( p_intf, l++, 1, " Ctrl-l Refresh the screen" );
1379 p_sys->i_box_lines_total = l;
1380 if( p_sys->i_box_start >= p_sys->i_box_lines_total )
1382 p_sys->i_box_start = p_sys->i_box_lines_total - 1;
1385 if( l - p_sys->i_box_start < p_sys->i_box_lines )
1387 y += l - p_sys->i_box_start;
1391 y += p_sys->i_box_lines;
1394 else if( p_sys->i_box_type == BOX_INFO )
1398 DrawBox( p_sys->w, y++, 0, h, COLS, " Information " );
1403 vlc_mutex_lock( &input_GetItem(p_input)->lock );
1404 for( i = 0; i < input_GetItem(p_input)->i_categories; i++ )
1406 info_category_t *p_category = input_GetItem(p_input)->pp_categories[i];
1407 if( y >= y_end ) break;
1408 MainBoxWrite( p_intf, l++, 1, " [%s]", p_category->psz_name );
1409 for( j = 0; j < p_category->i_infos; j++ )
1411 info_t *p_info = p_category->pp_infos[j];
1412 if( y >= y_end ) break;
1413 MainBoxWrite( p_intf, l++, 1, " %s: %s", p_info->psz_name, p_info->psz_value );
1416 vlc_mutex_unlock( &input_GetItem(p_input)->lock );
1420 MainBoxWrite( p_intf, l++, 1, "No item currently playing" );
1422 p_sys->i_box_lines_total = l;
1423 if( p_sys->i_box_start >= p_sys->i_box_lines_total )
1425 p_sys->i_box_start = p_sys->i_box_lines_total - 1;
1428 if( l - p_sys->i_box_start < p_sys->i_box_lines )
1430 y += l - p_sys->i_box_start;
1434 y += p_sys->i_box_lines;
1437 else if( p_sys->i_box_type == BOX_LOG )
1443 DrawBox( p_sys->w, y++, 0, h, COLS, " Logs " );
1445 i_start = p_intf->p_sys->p_sub->i_start;
1447 vlc_mutex_lock( p_intf->p_sys->p_sub->p_lock );
1448 i_stop = *p_intf->p_sys->p_sub->pi_stop;
1449 vlc_mutex_unlock( p_intf->p_sys->p_sub->p_lock );
1453 static const char *ppsz_type[4] = { "", "error", "warning", "debug" };
1454 if( i_line >= h - 2 )
1460 if( i_stop < 0 ) i_stop += VLC_MSG_QSIZE;
1461 if( i_stop == i_start )
1465 mvnprintw( y + h-2-i_line, 1, COLS - 2, " [%s] %s",
1466 ppsz_type[p_sys->p_sub->p_msg[i_stop].i_type],
1467 p_sys->p_sub->p_msg[i_stop].psz_msg );
1470 vlc_mutex_lock( p_intf->p_sys->p_sub->p_lock );
1471 p_intf->p_sys->p_sub->i_start = i_stop;
1472 vlc_mutex_unlock( p_intf->p_sys->p_sub->p_lock );
1475 else if( p_sys->i_box_type == BOX_BROWSE )
1477 /* Filebrowser box */
1478 int i_start, i_stop;
1480 DrawBox( p_sys->w, y++, 0, h, COLS, " Browse " );
1482 if( p_sys->i_box_bidx >= p_sys->i_dir_entries ) p_sys->i_box_plidx = p_sys->i_dir_entries - 1;
1483 if( p_sys->i_box_bidx < 0 ) p_sys->i_box_bidx = 0;
1485 if( p_sys->i_box_bidx < (h - 2)/2 )
1490 else if( p_sys->i_dir_entries - p_sys->i_box_bidx > (h - 2)/2 )
1492 i_start = p_sys->i_box_bidx - (h - 2)/2;
1493 i_stop = i_start + h - 2;
1497 i_stop = p_sys->i_dir_entries;
1498 i_start = p_sys->i_dir_entries - (h - 2);
1504 if( i_stop > p_sys->i_dir_entries )
1506 i_stop = p_sys->i_dir_entries;
1509 for( i_item = i_start; i_item < i_stop; i_item++ )
1511 vlc_bool_t b_selected = ( p_sys->i_box_bidx == i_item );
1513 if( y >= y_end ) break;
1516 attrset( A_REVERSE );
1518 mvnprintw( y++, 1, COLS - 2, " %c %s", p_sys->pp_dir_entries[i_item]->b_file == VLC_TRUE ? ' ' : '+',
1519 p_sys->pp_dir_entries[i_item]->psz_path );
1522 attroff( A_REVERSE );
1527 else if( ( p_sys->i_box_type == BOX_PLAYLIST ||
1528 p_sys->i_box_type == BOX_SEARCH ||
1529 p_sys->i_box_type == BOX_OPEN ) && p_sys->p_playlist )
1532 int i_start, i_stop, i_max = p_sys->i_plist_entries;
1536 switch( p_sys->i_current_view )
1539 psz_title = strdup( " Playlist (All, one level) " );
1542 psz_title = strdup( " Playlist (By category) " );
1545 psz_title = strdup( " Playlist (Manually added) " );
1548 DrawBox( p_sys->w, y++, 0, h, COLS, psz_title );
1550 if( p_sys->b_need_update || p_sys->pp_plist == NULL )
1552 PlaylistRebuild( p_intf );
1554 if( p_sys->b_box_plidx_follow )
1556 FindIndex( p_intf );
1559 if( p_sys->i_box_plidx < 0 ) p_sys->i_box_plidx = 0;
1560 if( p_sys->i_box_plidx < 0 ) p_sys->i_box_plidx = 0;
1561 if( p_sys->i_box_plidx >= i_max ) p_sys->i_box_plidx = i_max - 1;
1563 if( p_sys->i_box_plidx < (h - 2)/2 )
1568 else if( i_max - p_sys->i_box_plidx > (h - 2)/2 )
1570 i_start = p_sys->i_box_plidx - (h - 2)/2;
1571 i_stop = i_start + h - 2;
1576 i_start = i_max - (h - 2);
1582 if( i_stop > i_max )
1587 for( i_item = i_start; i_item < i_stop; i_item++ )
1589 vlc_bool_t b_selected = ( p_sys->i_box_plidx == i_item );
1590 int c = ( PlaylistIsPlaying( p_intf,
1591 p_sys->pp_plist[i_item]->p_item ) ) ? '>' : ' ';
1593 if( y >= y_end ) break;
1596 attrset( A_REVERSE );
1598 mvnprintw( y++, 1, COLS - 2, "%c%s", c,
1599 p_sys->pp_plist[i_item]->psz_display );
1602 attroff( A_REVERSE );
1611 if( p_sys->i_box_type == BOX_SEARCH )
1613 DrawEmptyLine( p_sys->w, 7, 1, COLS-2 );
1614 if( p_sys->psz_search_chain )
1616 if( strlen( p_sys->psz_search_chain ) == 0 &&
1617 p_sys->psz_old_search != NULL )
1619 /* Searching next entry */
1620 mvnprintw( 7, 1, COLS-2, "Find: %s", p_sys->psz_old_search );
1624 mvnprintw( 7, 1, COLS-2, "Find: %s", p_sys->psz_search_chain );
1628 if( p_sys->i_box_type == BOX_OPEN )
1630 if( p_sys->psz_open_chain )
1632 DrawEmptyLine( p_sys->w, 7, 1, COLS-2 );
1633 mvnprintw( 7, 1, COLS-2, "Open: %s", p_sys->psz_open_chain );
1639 DrawEmptyLine( p_sys->w, y++, 1, COLS - 2 );
1644 *t_last_refresh = time( 0 );
1647 static playlist_item_t *PlaylistGetRoot( intf_thread_t *p_intf )
1649 intf_sys_t *p_sys = p_intf->p_sys;
1650 playlist_t *p_playlist = p_sys->p_playlist;
1652 if( p_playlist == NULL )
1657 switch( p_sys->i_current_view )
1660 return p_playlist->p_root_category;
1662 return p_playlist->p_root_onelevel;
1666 static void PlaylistRebuild( intf_thread_t *p_intf )
1668 intf_sys_t *p_sys = p_intf->p_sys;
1669 playlist_t *p_playlist = p_sys->p_playlist;
1671 if( p_playlist == NULL )
1676 vlc_mutex_lock( &p_playlist->object_lock );
1678 /* First clear the old one */
1679 PlaylistDestroy( p_intf );
1681 /* Build the new one */
1682 PlaylistAddNode( p_intf, PlaylistGetRoot( p_intf ), 0, "" );
1684 p_sys->b_need_update = VLC_FALSE;
1686 vlc_mutex_unlock( &p_playlist->object_lock );
1689 static void PlaylistAddNode( intf_thread_t *p_intf, playlist_item_t *p_node,
1690 int i, const char *c )
1692 intf_sys_t *p_sys = p_intf->p_sys;
1693 playlist_item_t *p_child;
1697 psz_tmp = (char *)malloc( strlen( c ) + 4 );
1698 if( psz_tmp == NULL ) return;
1699 for( k = 0; k < p_node->i_children; k++ )
1701 struct pl_item_t *p_pl_item;
1705 p_child = p_node->pp_children[k];
1706 i_size = strlen( c ) + strlen( p_child->p_input->psz_name ) + 4;
1707 buff = (char *)malloc( sizeof( char ) * i_size );
1708 p_pl_item = (struct pl_item_t *)malloc( sizeof( struct pl_item_t ) );
1709 if( p_pl_item == NULL || buff == NULL ) return;
1713 sprintf( buff, "%s%c-%s", c, k == p_node->i_children - 1 ?
1714 '`' : '|', p_child->p_input->psz_name );
1718 sprintf( buff, " %s", p_child->p_input->psz_name );
1720 p_pl_item->psz_display = strdup( buff );
1721 p_pl_item->p_item = p_child;
1722 INSERT_ELEM( p_sys->pp_plist, p_sys->i_plist_entries,
1723 p_sys->i_plist_entries, p_pl_item );
1727 if( p_child->i_children > 0 )
1729 sprintf( psz_tmp, "%s%c ", c,
1730 k == p_node->i_children - 1 ? ' ' : '|' );
1731 PlaylistAddNode( p_intf, p_child, i,
1732 strlen( c ) ? psz_tmp : " " );
1738 static int PlaylistChanged( vlc_object_t *p_this, const char *psz_variable,
1739 vlc_value_t oval, vlc_value_t nval, void *param )
1741 intf_thread_t *p_intf = (intf_thread_t *)param;
1742 p_intf->p_sys->b_need_update = VLC_TRUE;
1747 static inline vlc_bool_t PlaylistIsPlaying( intf_thread_t *p_intf,
1748 playlist_item_t *p_item )
1750 playlist_item_t *p_played_item = p_intf->p_sys->p_playlist->status.p_item;
1751 return( p_item != NULL && p_played_item != NULL &&
1752 p_item->p_input != NULL && p_played_item->p_input != NULL &&
1753 p_item->p_input->i_id == p_played_item->p_input->i_id );
1756 static void FindIndex( intf_thread_t *p_intf )
1758 intf_sys_t *p_sys = p_intf->p_sys;
1761 if( p_sys->i_box_plidx < p_sys->i_plist_entries &&
1762 p_sys->i_box_plidx >= 0 &&
1763 PlaylistIsPlaying( p_intf,
1764 p_sys->pp_plist[p_sys->i_box_plidx]->p_item ) )
1769 for( i = 0; i < p_sys->i_plist_entries; i++ )
1771 if( PlaylistIsPlaying( p_intf, p_sys->pp_plist[i]->p_item ) )
1773 p_sys->i_box_plidx = i;
1779 static void PlaylistDestroy( intf_thread_t *p_intf )
1781 intf_sys_t *p_sys = p_intf->p_sys;
1784 for( i = 0; i < p_sys->i_plist_entries; i++ )
1786 struct pl_item_t *p_pl_item = p_sys->pp_plist[i];
1787 free( p_pl_item->psz_display );
1788 REMOVE_ELEM( p_sys->pp_plist, p_sys->i_plist_entries, i );
1791 p_sys->pp_plist = NULL;
1792 p_sys->i_plist_entries = 0;
1795 static void Eject( intf_thread_t *p_intf )
1797 char *psz_device = NULL, *psz_parser, *psz_name;
1800 * Get the active input
1801 * Determine whether we can eject a media, ie it's a DVD, VCD or CD-DA
1802 * If it's neither of these, then return
1805 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1808 if( p_playlist == NULL )
1813 vlc_mutex_lock( &p_playlist->object_lock );
1815 if( p_playlist->status.p_item == NULL )
1817 vlc_mutex_unlock( &p_playlist->object_lock );
1818 vlc_object_release( p_playlist );
1822 psz_name = p_playlist->status.p_item->p_input->psz_name;
1826 if( !strncmp(psz_name, "dvd://", 4) )
1828 switch( psz_name[strlen("dvd://")] )
1832 psz_device = config_GetPsz( p_intf, "dvd" );
1835 /* Omit the first MRL-selector characters */
1836 psz_device = strdup( psz_name + strlen("dvd://" ) );
1840 else if( !strncmp(psz_name, VCD_MRL, strlen(VCD_MRL)) )
1842 switch( psz_name[strlen(VCD_MRL)] )
1846 psz_device = config_GetPsz( p_intf, VCD_MRL );
1849 /* Omit the beginning MRL-selector characters */
1850 psz_device = strdup( psz_name + strlen(VCD_MRL) );
1854 else if( !strncmp(psz_name, CDDA_MRL, strlen(CDDA_MRL) ) )
1856 switch( psz_name[strlen(CDDA_MRL)] )
1860 psz_device = config_GetPsz( p_intf, "cd-audio" );
1863 /* Omit the beginning MRL-selector characters */
1864 psz_device = strdup( psz_name + strlen(CDDA_MRL) );
1870 psz_device = strdup( psz_name );
1874 vlc_mutex_unlock( &p_playlist->object_lock );
1875 vlc_object_release( p_playlist );
1877 if( psz_device == NULL )
1882 /* Remove what we have after @ */
1883 psz_parser = psz_device;
1884 for( psz_parser = psz_device ; *psz_parser ; psz_parser++ )
1886 if( *psz_parser == '@' )
1893 /* If there's a stream playing, we aren't allowed to eject ! */
1894 if( p_intf->p_sys->p_input == NULL )
1896 msg_Dbg( p_intf, "ejecting %s", psz_device );
1898 intf_Eject( p_intf, psz_device );
1905 static int comp_dir_entries( const void *pp_dir_entry1,
1906 const void *pp_dir_entry2 )
1908 struct dir_entry_t *p_dir_entry1 = *(struct dir_entry_t**)pp_dir_entry1;
1909 struct dir_entry_t *p_dir_entry2 = *(struct dir_entry_t**)pp_dir_entry2;
1910 if ( p_dir_entry1->b_file == p_dir_entry2->b_file ) {
1911 return strcasecmp( p_dir_entry1->psz_path, p_dir_entry2->psz_path );
1915 return ( p_dir_entry1->b_file ? 1 : -1 );
1919 static void ReadDir( intf_thread_t *p_intf )
1921 intf_sys_t *p_sys = p_intf->p_sys;
1925 if( p_sys->psz_current_dir && *p_sys->psz_current_dir )
1930 p_current_dir = utf8_opendir( p_sys->psz_current_dir );
1932 if( p_current_dir == NULL )
1934 /* something went bad, get out of here ! */
1936 msg_Warn( p_intf, "cannot open directory `%s' (%s)",
1937 p_sys->psz_current_dir, strerror(errno));
1939 msg_Warn( p_intf, "cannot open directory `%s'", p_sys->psz_current_dir );
1944 /* Clean the old shit */
1945 for( i = 0; i < p_sys->i_dir_entries; i++ )
1947 struct dir_entry_t *p_dir_entry = p_sys->pp_dir_entries[i];
1948 free( p_dir_entry->psz_path );
1949 REMOVE_ELEM( p_sys->pp_dir_entries, p_sys->i_dir_entries, i );
1950 free( p_dir_entry );
1952 p_sys->pp_dir_entries = NULL;
1953 p_sys->i_dir_entries = 0;
1955 /* while we still have entries in the directory */
1956 while( ( psz_entry = utf8_readdir( p_current_dir ) ) != NULL )
1958 #if defined( S_ISDIR )
1959 struct stat stat_data;
1961 struct dir_entry_t *p_dir_entry;
1962 int i_size_entry = strlen( p_sys->psz_current_dir ) +
1963 strlen( psz_entry ) + 2;
1966 if( p_sys->b_show_hidden_files == VLC_FALSE &&
1967 ( strlen( psz_entry ) && psz_entry[0] == '.' ) &&
1968 strcmp( psz_entry, ".." ) )
1974 psz_uri = (char *)malloc( sizeof(char)*i_size_entry);
1975 sprintf( psz_uri, "%s/%s", p_sys->psz_current_dir, psz_entry );
1977 if( !( p_dir_entry = malloc( sizeof( struct dir_entry_t) ) ) )
1984 #if defined( S_ISDIR )
1985 if( !utf8_stat( psz_uri, &stat_data )
1986 && S_ISDIR(stat_data.st_mode) )
1987 /*#elif defined( DT_DIR )
1988 if( p_dir_content->d_type & DT_DIR )*/
1993 p_dir_entry->psz_path = strdup( psz_entry );
1994 p_dir_entry->b_file = VLC_FALSE;
1995 INSERT_ELEM( p_sys->pp_dir_entries, p_sys->i_dir_entries,
1996 p_sys->i_dir_entries, p_dir_entry );
2000 p_dir_entry->psz_path = strdup( psz_entry );
2001 p_dir_entry->b_file = VLC_TRUE;
2002 INSERT_ELEM( p_sys->pp_dir_entries, p_sys->i_dir_entries,
2003 p_sys->i_dir_entries, p_dir_entry );
2011 qsort( p_sys->pp_dir_entries, p_sys->i_dir_entries,
2012 sizeof(struct dir_entry_t*), &comp_dir_entries );
2014 closedir( p_current_dir );
2019 msg_Dbg( p_intf, "no current dir set" );
2024 static void PlayPause( intf_thread_t *p_intf )
2026 input_thread_t *p_input = p_intf->p_sys->p_input;
2031 var_Get( p_input, "state", &val );
2032 if( val.i_int != PAUSE_S )
2034 val.i_int = PAUSE_S;
2038 val.i_int = PLAYING_S;
2040 var_Set( p_input, "state", val );
2042 else if( p_intf->p_sys->p_playlist )
2044 playlist_Play( p_intf->p_sys->p_playlist );
2048 /****************************************************************************
2050 ****************************************************************************/
2051 static void DrawBox( WINDOW *win, int y, int x, int h, int w, const char *title )
2056 if( w > 3 && h > 2 )
2058 if( title == NULL ) title = "";
2059 i_len = strlen( title );
2061 if( i_len > w - 2 ) i_len = w - 2;
2063 mvwaddch( win, y, x, ACS_ULCORNER );
2064 mvwhline( win, y, x+1, ACS_HLINE, ( w-i_len-2)/2 );
2065 mvwprintw( win,y, x+1+(w-i_len-2)/2, "%s", title );
2066 mvwhline( win, y, x+(w-i_len)/2+i_len, ACS_HLINE, w - 1 - ((w-i_len)/2+i_len) );
2067 mvwaddch( win, y, x+w-1,ACS_URCORNER );
2069 for( i = 0; i < h-2; i++ )
2071 mvwaddch( win, y+i+1, x, ACS_VLINE );
2072 mvwaddch( win, y+i+1, x+w-1, ACS_VLINE );
2075 mvwaddch( win, y+h-1, x, ACS_LLCORNER );
2076 mvwhline( win, y+h-1, x+1, ACS_HLINE, w - 2 );
2077 mvwaddch( win, y+h-1, x+w-1, ACS_LRCORNER );
2081 static void DrawEmptyLine( WINDOW *win, int y, int x, int w )
2085 mvhline( y, x, ' ', w );
2089 static void DrawLine( WINDOW *win, int y, int x, int w )
2093 attrset( A_REVERSE );
2094 mvhline( y, x, ' ', w );
2095 attroff( A_REVERSE );