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 #ifdef HAVE_NCURSESW_CURSES_H
36 #include <ncursesw/curses.h>
41 #include <vlc_interface.h>
44 #include <vlc_charset.h>
45 #include <vlc_input.h>
46 #include <vlc_playlist.h>
48 #ifdef HAVE_SYS_STAT_H
49 # include <sys/stat.h>
51 #if (!defined( WIN32 ) || defined(__MINGW32__))
52 /* Mingw has its own version of dirent */
57 #define CDDA_MRL "cddax://"
59 #define CDDA_MRL "cdda://"
63 #define VCD_MRL "vcdx://"
65 #define VCD_MRL "vcdx://"
68 #define SEARCH_CHAIN_SIZE 20
69 #define OPEN_CHAIN_SIZE 50
71 /*****************************************************************************
73 *****************************************************************************/
74 static int Open ( vlc_object_t * );
75 static void Close ( vlc_object_t * );
77 static void Run ( intf_thread_t * );
78 static void PlayPause ( intf_thread_t * );
79 static void Eject ( intf_thread_t * );
81 static int HandleKey ( intf_thread_t *, int );
82 static void Redraw ( intf_thread_t *, time_t * );
84 static playlist_item_t *PlaylistGetRoot( intf_thread_t * );
85 static void PlaylistRebuild( intf_thread_t * );
86 static void PlaylistAddNode( intf_thread_t *, playlist_item_t *, int, const char *);
87 static void PlaylistDestroy( intf_thread_t * );
88 static int PlaylistChanged( vlc_object_t *, const char *, vlc_value_t,
89 vlc_value_t, void * );
90 static inline vlc_bool_t PlaylistIsPlaying( intf_thread_t *,
92 static void FindIndex ( intf_thread_t * );
93 static void SearchPlaylist ( intf_thread_t *, char * );
94 static int SubSearchPlaylist( intf_thread_t *, char *, int, int );
96 static void ManageSlider ( intf_thread_t * );
97 static void ReadDir ( intf_thread_t * );
99 /*****************************************************************************
101 *****************************************************************************/
103 #define BROWSE_TEXT N_("Filebrowser starting point")
104 #define BROWSE_LONGTEXT N_( \
105 "This option allows you to specify the directory the ncurses filebrowser " \
106 "will show you initially.")
109 set_shortname( "Ncurses" );
110 set_description( _("Ncurses interface") );
111 set_capability( "interface", 10 );
112 set_category( CAT_INTERFACE );
113 set_subcategory( SUBCAT_INTERFACE_MAIN );
114 set_callbacks( Open, Close );
115 add_shortcut( "curses" );
116 add_directory( "browse-dir", NULL, NULL, BROWSE_TEXT, BROWSE_LONGTEXT, VLC_FALSE );
119 /*****************************************************************************
120 * intf_sys_t: description and status of ncurses interface
121 *****************************************************************************/
145 playlist_item_t *p_item;
150 playlist_t *p_playlist;
151 input_thread_t *p_input;
161 int i_box_lines_total;
164 int i_box_plidx; /* Playlist index */
165 int b_box_plidx_follow;
166 playlist_item_t *p_plnode; /* Playlist node */
167 int i_box_bidx; /* browser index */
171 msg_subscription_t* p_sub; /* message bank subscription */
173 char *psz_search_chain; /* for playlist searching */
174 char *psz_old_search; /* for searching next */
177 char *psz_open_chain;
178 char psz_partial_keys[7];
180 char *psz_current_dir;
182 struct dir_entry_t **pp_dir_entries;
183 vlc_bool_t b_show_hidden_files;
185 int i_current_view; /* playlist view */
186 struct pl_item_t **pp_plist;
188 vlc_bool_t b_need_update; /* for playlist view */
190 int i_verbose; /* stores verbosity level */
193 static void DrawBox( WINDOW *win, int y, int x, int h, int w, const char *title );
194 static void DrawLine( WINDOW *win, int y, int x, int w );
195 static void DrawEmptyLine( WINDOW *win, int y, int x, int w );
197 /*****************************************************************************
198 * Open: initialize and create window
199 *****************************************************************************/
200 static int Open( vlc_object_t *p_this )
202 intf_thread_t *p_intf = (intf_thread_t *)p_this;
206 /* Allocate instance and initialize some members */
207 p_sys = p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
208 p_sys->p_playlist = NULL;
209 p_sys->p_input = NULL;
210 p_sys->f_slider = 0.0;
211 p_sys->f_slider_old = 0.0;
212 p_sys->i_box_type = BOX_PLAYLIST;
213 p_sys->i_box_lines = 0;
214 p_sys->i_box_start= 0;
215 p_sys->i_box_lines_total = 0;
216 p_sys->b_box_plidx_follow = VLC_TRUE;
217 p_sys->b_box_cleared = VLC_FALSE;
218 p_sys->i_box_plidx = 0;
219 p_sys->p_plnode = NULL;
220 p_sys->i_box_bidx = 0;
221 p_sys->p_sub = msg_Subscribe( p_intf, MSG_QUEUE_NORMAL );
222 memset( p_sys->psz_partial_keys, 0, sizeof( p_sys->psz_partial_keys ) );
224 /* Initialize the curses library */
225 p_sys->w = initscr();
226 keypad( p_sys->w, TRUE );
227 /* Don't do NL -> CR/NL */
229 /* Take input chars one at a time */
239 /* exported function */
240 p_intf->pf_run = Run;
242 /* Remember verbosity level */
243 var_Get( p_intf->p_libvlc, "verbose", &val );
244 p_sys->i_verbose = val.i_int;
247 var_Set( p_intf->p_libvlc, "verbose", val );
249 /* Set defaul playlist view */
250 p_sys->i_current_view = VIEW_CATEGORY;
251 p_sys->pp_plist = NULL;
252 p_sys->i_plist_entries = 0;
253 p_sys->b_need_update = VLC_FALSE;
255 /* Initialize search chain */
256 p_sys->psz_search_chain = (char *)malloc( SEARCH_CHAIN_SIZE + 1 );
257 p_sys->psz_old_search = NULL;
258 p_sys->i_before_search = 0;
260 /* Initialize open chain */
261 p_sys->psz_open_chain = (char *)malloc( OPEN_CHAIN_SIZE + 1 );
263 /* Initialize browser options */
264 var_Create( p_intf, "browse-dir", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
265 var_Get( p_intf, "browse-dir", &val);
267 if( val.psz_string && *val.psz_string )
269 p_sys->psz_current_dir = strdup( val.psz_string );
270 free( val.psz_string );
274 p_sys->psz_current_dir = strdup( p_intf->p_libvlc->psz_homedir );
277 p_sys->i_dir_entries = 0;
278 p_sys->pp_dir_entries = NULL;
279 p_sys->b_show_hidden_files = VLC_FALSE;
285 /*****************************************************************************
286 * Close: destroy interface window
287 *****************************************************************************/
288 static void Close( vlc_object_t *p_this )
290 intf_thread_t *p_intf = (intf_thread_t *)p_this;
291 intf_sys_t *p_sys = p_intf->p_sys;
294 var_DelCallback( p_sys->p_playlist, "intf-change", PlaylistChanged,
296 var_DelCallback( p_sys->p_playlist, "item-append", PlaylistChanged,
299 PlaylistDestroy( p_intf );
301 for( i = 0; i < p_sys->i_dir_entries; i++ )
303 struct dir_entry_t *p_dir_entry = p_sys->pp_dir_entries[i];
304 if( p_dir_entry->psz_path ) free( p_dir_entry->psz_path );
305 REMOVE_ELEM( p_sys->pp_dir_entries, p_sys->i_dir_entries, i );
306 if( p_dir_entry ) free( p_dir_entry );
308 p_sys->pp_dir_entries = NULL;
310 if( p_sys->psz_current_dir ) free( p_sys->psz_current_dir );
311 if( p_sys->psz_search_chain ) free( p_sys->psz_search_chain );
312 if( p_sys->psz_old_search ) free( p_sys->psz_old_search );
313 if( p_sys->psz_open_chain ) free( p_sys->psz_open_chain );
317 vlc_object_release( p_sys->p_input );
319 if( p_sys->p_playlist )
321 vlc_object_release( p_sys->p_playlist );
324 /* Close the ncurses interface */
327 msg_Unsubscribe( p_intf, p_sys->p_sub );
329 /* Restores initial verbose setting */
331 val.i_int = p_sys->i_verbose;
332 var_Set( p_intf->p_libvlc, "verbose", val );
334 /* Destroy structure */
338 /*****************************************************************************
339 * Run: ncurses thread
340 *****************************************************************************/
341 static void Run( intf_thread_t *p_intf )
343 intf_sys_t *p_sys = p_intf->p_sys;
346 time_t t_last_refresh;
349 * force drawing the interface for the first time
351 t_last_refresh = ( time( 0 ) - 1);
353 while( !intf_ShouldDie( p_intf ) )
355 msleep( INTF_IDLE_SLEEP );
357 /* Update the input */
358 if( p_sys->p_playlist == NULL )
360 p_sys->p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
362 if( p_sys->p_playlist )
364 var_AddCallback( p_sys->p_playlist, "intf-change",
365 PlaylistChanged, p_intf );
366 var_AddCallback( p_sys->p_playlist, "item-append",
367 PlaylistChanged, p_intf );
370 if( p_sys->p_playlist )
372 vlc_mutex_lock( &p_sys->p_playlist->object_lock );
373 if( p_sys->p_input == NULL )
375 p_sys->p_input = p_sys->p_playlist->p_input;
378 if( !p_sys->p_input->b_dead )
380 vlc_object_yield( p_sys->p_input );
384 else if( p_sys->p_input->b_dead )
386 vlc_object_release( p_sys->p_input );
387 p_sys->p_input = NULL;
388 p_sys->f_slider = p_sys->f_slider_old = 0.0;
389 p_sys->b_box_cleared = VLC_FALSE;
391 vlc_mutex_unlock( &p_sys->p_playlist->object_lock );
394 if( p_sys->b_box_plidx_follow && p_sys->p_playlist->status.p_item )
399 while( ( i_key = getch() ) != -1 )
402 * HandleKey returns 1 if the screen needs to be redrawn
404 if( HandleKey( p_intf, i_key ) )
406 Redraw( p_intf, &t_last_refresh );
410 if( p_sys->f_slider > 0.0001 && !p_sys->b_box_cleared )
413 Redraw( p_intf, &t_last_refresh );
414 p_sys->b_box_cleared = VLC_TRUE;
418 * redraw the screen every second
420 if( (time(0) - t_last_refresh) >= 1 )
422 ManageSlider( p_intf );
423 Redraw( p_intf, &t_last_refresh );
428 /* following functions are local */
430 static char *KeyToUTF8( int i_key, char *psz_part )
432 char *psz_utf8, *psz;
433 int len = strlen( psz_part );
436 /* overflow error - should not happen */
437 memset( psz_part, 0, 6 );
441 psz_part[len] = (char)i_key;
443 psz_utf8 = FromLocaleDup( psz_part );
445 /* Ugly check for incomplete bytes sequences
446 * (in case of non-UTF8 multibyte local encoding) */
447 for( psz = psz_utf8; *psz; psz++ )
448 if( ( *psz == '?' ) && ( *psz_utf8 != '?' ) )
450 /* incomplete bytes sequence detected
451 * (VLC core inserted dummy question marks) */
456 /* Check for incomplete UTF8 bytes sequence */
457 if( EnsureUTF8( psz_utf8 ) == NULL )
463 memset( psz_part, 0, 6 );
467 static inline int RemoveLastUTF8Entity( char *psz, int len )
469 while( len && ( (psz[--len] & 0xc0) == 0x80 ) );
470 /* UTF8 continuation byte */
476 static int HandleKey( intf_thread_t *p_intf, int i_key )
478 intf_sys_t *p_sys = p_intf->p_sys;
481 if( p_sys->i_box_type == BOX_PLAYLIST && p_sys->p_playlist )
483 int b_ret = VLC_TRUE;
484 vlc_bool_t b_box_plidx_follow = VLC_FALSE;
489 /* Playlist Settings */
491 var_Get( p_sys->p_playlist, "random", &val );
492 val.b_bool = !val.b_bool;
493 var_Set( p_sys->p_playlist, "random", val );
496 var_Get( p_sys->p_playlist, "loop", &val );
497 val.b_bool = !val.b_bool;
498 var_Set( p_sys->p_playlist, "loop", val );
501 var_Get( p_sys->p_playlist, "repeat", &val );
502 val.b_bool = !val.b_bool;
503 var_Set( p_sys->p_playlist, "repeat", val );
508 playlist_RecursiveNodeSort( p_sys->p_playlist,
509 PlaylistGetRoot( p_intf ),
510 SORT_TITLE_NODES_FIRST, ORDER_NORMAL );
511 p_sys->b_need_update = VLC_TRUE;
514 playlist_RecursiveNodeSort( p_sys->p_playlist,
515 PlaylistGetRoot( p_intf ),
516 SORT_TITLE_NODES_FIRST, ORDER_REVERSE );
517 p_sys->b_need_update = VLC_TRUE;
522 switch( p_sys->i_current_view )
525 p_sys->i_current_view = VIEW_ONELEVEL;
528 p_sys->i_current_view = VIEW_CATEGORY;
530 //p_sys->b_need_update = VLC_TRUE;
531 PlaylistRebuild( p_intf );
534 /* Playlist navigation */
536 p_sys->i_box_plidx = 0;
539 p_sys->i_box_plidx = p_sys->p_playlist->items.i_size - 1;
542 p_sys->i_box_plidx--;
545 p_sys->i_box_plidx++;
548 p_sys->i_box_plidx -= p_sys->i_box_lines;
551 p_sys->i_box_plidx += p_sys->i_box_lines;
557 playlist_t *p_playlist = p_sys->p_playlist;
558 playlist_item_t *p_item;
560 vlc_mutex_lock( &p_playlist->object_lock );
561 p_item = p_sys->pp_plist[p_sys->i_box_plidx]->p_item;
562 if( p_item->i_children == -1 )
564 playlist_DeleteFromInput( p_playlist,
565 p_item->p_input->i_id, VLC_TRUE );
569 playlist_NodeDelete( p_playlist, p_item,
570 VLC_TRUE , VLC_FALSE );
572 vlc_mutex_unlock( &p_playlist->object_lock );
573 p_sys->b_need_update = VLC_TRUE;
580 if( p_sys->pp_plist[p_sys->i_box_plidx]->p_item->i_children
583 playlist_Control( p_sys->p_playlist, PLAYLIST_VIEWPLAY,
585 p_sys->pp_plist[p_sys->i_box_plidx]->p_item );
589 playlist_Control( p_sys->p_playlist, PLAYLIST_VIEWPLAY,
591 p_sys->pp_plist[p_sys->i_box_plidx]->p_item,
594 b_box_plidx_follow = VLC_TRUE;
603 int i_max = p_sys->i_plist_entries;
604 if( p_sys->i_box_plidx >= i_max ) p_sys->i_box_plidx = i_max - 1;
605 if( p_sys->i_box_plidx < 0 ) p_sys->i_box_plidx = 0;
606 if( PlaylistIsPlaying( p_intf,
607 p_sys->pp_plist[p_sys->i_box_plidx]->p_item ) )
608 b_box_plidx_follow = VLC_TRUE;
609 p_sys->b_box_plidx_follow = b_box_plidx_follow;
613 if( p_sys->i_box_type == BOX_BROWSE )
615 vlc_bool_t b_ret = VLC_TRUE;
616 /* Browser navigation */
620 p_sys->i_box_bidx = 0;
623 p_sys->i_box_bidx = p_sys->i_dir_entries - 1;
632 p_sys->i_box_bidx -= p_sys->i_box_lines;
635 p_sys->i_box_bidx += p_sys->i_box_lines;
637 case '.': /* Toggle show hidden files */
638 p_sys->b_show_hidden_files = ( p_sys->b_show_hidden_files ==
639 VLC_TRUE ? VLC_FALSE : VLC_TRUE );
646 if( p_sys->pp_dir_entries[p_sys->i_box_bidx]->b_file || i_key == ' ' )
648 int i_size_entry = strlen( p_sys->psz_current_dir ) +
649 strlen( p_sys->pp_dir_entries[p_sys->i_box_bidx]->psz_path ) + 2;
650 char *psz_uri = (char *)malloc( sizeof(char)*i_size_entry);
652 sprintf( psz_uri, "%s/%s", p_sys->psz_current_dir, p_sys->pp_dir_entries[p_sys->i_box_bidx]->psz_path );
654 playlist_Add( p_sys->p_playlist, psz_uri,
656 PLAYLIST_APPEND, PLAYLIST_END );
658 p_sys->i_box_type = BOX_PLAYLIST;
663 int i_size_entry = strlen( p_sys->psz_current_dir ) +
664 strlen( p_sys->pp_dir_entries[p_sys->i_box_bidx]->psz_path ) + 2;
665 char *psz_uri = (char *)malloc( sizeof(char)*i_size_entry);
667 sprintf( psz_uri, "%s/%s", p_sys->psz_current_dir, p_sys->pp_dir_entries[p_sys->i_box_bidx]->psz_path );
669 p_sys->psz_current_dir = strdup( psz_uri );
680 if( p_sys->i_box_bidx >= p_sys->i_dir_entries ) p_sys->i_box_bidx = p_sys->i_dir_entries - 1;
681 if( p_sys->i_box_bidx < 0 ) p_sys->i_box_bidx = 0;
685 else if( p_sys->i_box_type == BOX_HELP || p_sys->i_box_type == BOX_INFO )
690 p_sys->i_box_start = 0;
693 p_sys->i_box_start = p_sys->i_box_lines_total - 1;
696 if( p_sys->i_box_start > 0 ) p_sys->i_box_start--;
699 if( p_sys->i_box_start < p_sys->i_box_lines_total - 1 )
701 p_sys->i_box_start++;
705 p_sys->i_box_start -= p_sys->i_box_lines;
706 if( p_sys->i_box_start < 0 ) p_sys->i_box_start = 0;
709 p_sys->i_box_start += p_sys->i_box_lines;
710 if( p_sys->i_box_start >= p_sys->i_box_lines_total )
712 p_sys->i_box_start = p_sys->i_box_lines_total - 1;
719 else if( p_sys->i_box_type == BOX_NONE )
725 ManageSlider( p_intf );
728 p_sys->f_slider = 99.9;
729 ManageSlider( p_intf );
732 p_sys->f_slider += 5.0;
733 if( p_sys->f_slider >= 99.0 ) p_sys->f_slider = 99.0;
734 ManageSlider( p_intf );
737 p_sys->f_slider -= 5.0;
738 if( p_sys->f_slider < 0.0 ) p_sys->f_slider = 0.0;
739 ManageSlider( p_intf );
746 else if( p_sys->i_box_type == BOX_SEARCH && p_sys->psz_search_chain )
749 i_chain_len = strlen( p_sys->psz_search_chain );
757 if( i_chain_len > 0 )
759 p_sys->psz_old_search = strdup( p_sys->psz_search_chain );
761 else if( p_sys->psz_old_search )
763 SearchPlaylist( p_intf, p_sys->psz_old_search );
765 p_sys->i_box_type = BOX_PLAYLIST;
767 case 0x1b: /* Esc. */
768 p_sys->i_box_plidx = p_sys->i_before_search;
769 p_sys->i_box_type = BOX_PLAYLIST;
772 RemoveLastUTF8Entity( p_sys->psz_search_chain, i_chain_len );
776 char *psz_utf8 = KeyToUTF8( i_key, p_sys->psz_partial_keys );
778 if( psz_utf8 != NULL )
780 if( i_chain_len + strlen( psz_utf8 ) < SEARCH_CHAIN_SIZE )
782 strcpy( p_sys->psz_search_chain + i_chain_len,
790 if( p_sys->psz_old_search )
792 free( p_sys->psz_old_search );
793 p_sys->psz_old_search = NULL;
795 SearchPlaylist( p_intf, p_sys->psz_search_chain );
798 else if( p_sys->i_box_type == BOX_OPEN && p_sys->psz_open_chain )
800 int i_chain_len = strlen( p_sys->psz_open_chain );
801 playlist_t *p_playlist = p_sys->p_playlist;
810 if( p_playlist && i_chain_len > 0 )
813 playlist_Add( p_playlist, p_sys->psz_open_chain,
814 p_sys->psz_open_chain,
815 PLAYLIST_GO|PLAYLIST_APPEND, PLAYLIST_END );
817 p_sys->b_box_plidx_follow = VLC_TRUE;
819 p_sys->i_box_type = BOX_PLAYLIST;
821 case 0x1b: /* Esc. */
822 p_sys->i_box_type = BOX_PLAYLIST;
825 RemoveLastUTF8Entity( p_sys->psz_open_chain, i_chain_len );
829 char *psz_utf8 = KeyToUTF8( i_key, p_sys->psz_partial_keys );
831 if( psz_utf8 != NULL )
833 if( i_chain_len + strlen( psz_utf8 ) < OPEN_CHAIN_SIZE )
835 strcpy( p_sys->psz_open_chain + i_chain_len,
853 vlc_object_kill( p_intf->p_libvlc );
858 if( p_sys->i_box_type == BOX_INFO )
859 p_sys->i_box_type = BOX_NONE;
861 p_sys->i_box_type = BOX_INFO;
862 p_sys->i_box_lines_total = 0;
865 if( p_sys->i_box_type == BOX_LOG )
866 p_sys->i_box_type = BOX_NONE;
868 p_sys->i_box_type = BOX_LOG;
871 if( p_sys->i_box_type == BOX_PLAYLIST )
872 p_sys->i_box_type = BOX_NONE;
874 p_sys->i_box_type = BOX_PLAYLIST;
877 if( p_sys->i_box_type == BOX_BROWSE )
878 p_sys->i_box_type = BOX_NONE;
880 p_sys->i_box_type = BOX_BROWSE;
884 if( p_sys->i_box_type == BOX_HELP )
885 p_sys->i_box_type = BOX_NONE;
887 p_sys->i_box_type = BOX_HELP;
888 p_sys->i_box_lines_total = 0;
891 if( p_sys->i_box_type != BOX_SEARCH )
893 if( p_sys->psz_search_chain == NULL )
897 p_sys->psz_search_chain[0] = '\0';
898 p_sys->b_box_plidx_follow = VLC_FALSE;
899 p_sys->i_before_search = p_sys->i_box_plidx;
900 p_sys->i_box_type = BOX_SEARCH;
904 if( p_sys->i_box_type != BOX_OPEN )
906 if( p_sys->psz_open_chain == NULL )
910 p_sys->psz_open_chain[0] = '\0';
911 p_sys->i_box_type = BOX_OPEN;
917 p_sys->f_slider += 1.0;
918 if( p_sys->f_slider > 99.9 ) p_sys->f_slider = 99.9;
919 ManageSlider( p_intf );
923 p_sys->f_slider -= 1.0;
924 if( p_sys->f_slider < 0.0 ) p_sys->f_slider = 0.0;
925 ManageSlider( p_intf );
931 if( p_intf->p_sys->p_input )
933 vout_thread_t *p_vout;
934 p_vout = vlc_object_find( p_intf->p_sys->p_input,
935 VLC_OBJECT_VOUT, FIND_CHILD );
938 var_Get( p_vout, "fullscreen", &val );
939 val.b_bool = !val.b_bool;
940 var_Set( p_vout, "fullscreen", val );
941 vlc_object_release( p_vout );
945 playlist_t *p_playlist;
946 p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
950 var_Get( p_playlist, "fullscreen", &val );
951 val.b_bool = !val.b_bool;
952 var_Set( p_playlist, "fullscreen", val );
953 vlc_object_release( p_playlist );
965 if( p_intf->p_sys->p_playlist )
967 playlist_Stop( p_intf->p_sys->p_playlist );
978 val.b_bool = VLC_TRUE;
979 var_Set( p_sys->p_input, "prev-title", val );
986 val.b_bool = VLC_TRUE;
987 var_Set( p_sys->p_input, "next-title", val );
994 val.b_bool = VLC_TRUE;
995 var_Set( p_sys->p_input, "prev-chapter", val );
1000 if( p_sys->p_input )
1002 val.b_bool = VLC_TRUE;
1003 var_Set( p_sys->p_input, "next-chapter", val );
1008 if( p_intf->p_sys->p_playlist )
1010 playlist_Prev( p_intf->p_sys->p_playlist );
1016 if( p_intf->p_sys->p_playlist )
1018 playlist_Next( p_intf->p_sys->p_playlist );
1024 aout_VolumeUp( p_intf, 1, NULL );
1029 aout_VolumeDown( p_intf, 1, NULL );
1034 * ^l should clear and redraw the screen
1045 static void ManageSlider( intf_thread_t *p_intf )
1047 intf_sys_t *p_sys = p_intf->p_sys;
1048 input_thread_t *p_input = p_sys->p_input;
1051 if( p_input == NULL )
1055 var_Get( p_input, "state", &val );
1056 if( val.i_int != PLAYING_S )
1061 var_Get( p_input, "position", &val );
1062 if( p_sys->f_slider == p_sys->f_slider_old )
1065 p_sys->f_slider_old = 100 * val.f_float;
1069 p_sys->f_slider_old = p_sys->f_slider;
1071 val.f_float = p_sys->f_slider / 100.0;
1072 var_Set( p_input, "position", val );
1076 static void SearchPlaylist( intf_thread_t *p_intf, char *psz_searchstring )
1081 intf_sys_t *p_sys = p_intf->p_sys;
1083 if( p_sys->i_before_search >= 0 )
1085 i_first = p_sys->i_before_search;
1088 if( ( ! psz_searchstring ) || strlen( psz_searchstring ) <= 0 )
1090 p_sys->i_box_plidx = p_sys->i_before_search;
1094 i_max = p_sys->i_plist_entries;
1096 i_item = SubSearchPlaylist( p_intf, psz_searchstring, i_first + 1, i_max );
1099 i_item = SubSearchPlaylist( p_intf, psz_searchstring, 0, i_first );
1102 if( i_item < 0 || i_item >= i_max ) return;
1104 p_sys->i_box_plidx = i_item;
1107 static int SubSearchPlaylist( intf_thread_t *p_intf, char *psz_searchstring,
1108 int i_start, int i_stop )
1110 intf_sys_t *p_sys = p_intf->p_sys;
1113 for( i = i_start + 1; i < i_stop; i++ )
1115 if( strcasestr( p_sys->pp_plist[i]->psz_display,
1116 psz_searchstring ) != NULL )
1127 static void mvnprintw( int y, int x, int w, const char *p_fmt, ... )
1132 #ifdef HAVE_NCURSESW_CURSES_H
1133 size_t i_char_len; /* UCS character length */
1134 size_t i_width; /* Display width */
1135 wchar_t *psz_wide; /* wchar_t representation of p_buf */
1138 va_start( vl_args, p_fmt );
1139 vasprintf( &p_buf, p_fmt, vl_args );
1142 if( ( p_buf == NULL ) || ( w <= 0 ) )
1145 i_len = strlen( p_buf );
1146 #ifdef HAVE_NCURSESW_CURSES_H
1147 psz_wide = (wchar_t *) malloc( sizeof( wchar_t ) * ( i_len + 1 ) );
1149 i_char_len = mbstowcs( psz_wide, p_buf, i_len );
1151 if( i_char_len == -1 ) /* an invalid character was encountered */
1155 i_width = wcswidth( psz_wide, i_char_len );
1156 if( i_width == -1 ) /* a non printable character was encountered */
1163 { /* FIXME: ncursesw: ellipsize psz_wide while keeping the width in mind */
1165 int i_cut = i_len - w;
1166 int x1 = i_len/2 - i_cut/2;
1167 int x2 = x1 + i_cut;
1171 memmove( &p_buf[x1], &p_buf[x2], i_len - x2 );
1180 psz_local = ToLocale( p_buf );
1181 mvprintw( y, x, "%s", psz_local );
1182 LocaleFree( p_buf );
1186 char *psz_local = ToLocale( p_buf );
1187 mvprintw( y, x, "%s", psz_local );
1188 LocaleFree( p_buf );
1189 #ifdef HAVE_NCURSESW_CURSES_H
1190 mvhline( y, x + i_width, ' ', w - i_width );
1192 mvhline( y, x + i_len, ' ', w - i_len );
1196 static void MainBoxWrite( intf_thread_t *p_intf, int l, int x, const char *p_fmt, ... )
1198 intf_sys_t *p_sys = p_intf->p_sys;
1203 if( l < p_sys->i_box_start || l - p_sys->i_box_start >= p_sys->i_box_lines )
1208 va_start( vl_args, p_fmt );
1209 vasprintf( &p_buf, p_fmt, vl_args );
1217 mvnprintw( p_sys->i_box_y + l - p_sys->i_box_start, x, COLS - x - 1, "%s", p_buf );
1220 static void Redraw( intf_thread_t *p_intf, time_t *t_last_refresh )
1222 intf_sys_t *p_sys = p_intf->p_sys;
1223 input_thread_t *p_input = p_sys->p_input;
1231 attrset( A_REVERSE );
1232 mvnprintw( y, 0, COLS, "VLC media player" " (ncurses interface) [ h for help ]" );
1233 attroff( A_REVERSE );
1237 if( p_input && !p_input->b_dead )
1239 char buf1[MSTRTIME_MAX_SIZE];
1240 char buf2[MSTRTIME_MAX_SIZE];
1242 vlc_value_t val_list;
1245 char *psz_uri = input_item_GetURI( input_GetItem( p_input ) );
1246 mvnprintw( y++, 0, COLS, " Source : %s", psz_uri );
1250 var_Get( p_input, "state", &val );
1251 if( val.i_int == PLAYING_S )
1253 mvnprintw( y++, 0, COLS, " State : Playing" );
1255 else if( val.i_int == OPENING_S )
1257 mvnprintw( y++, 0, COLS, " State : Openning/Connecting" );
1259 else if( val.i_int == BUFFERING_S )
1261 mvnprintw( y++, 0, COLS, " State : Buffering" );
1263 else if( val.i_int == PAUSE_S )
1265 mvnprintw( y++, 0, COLS, " State : Paused" );
1271 if( val.i_int != INIT_S && val.i_int != END_S )
1273 audio_volume_t i_volume;
1276 var_Get( p_input, "time", &val );
1277 msecstotimestr( buf1, val.i_time / 1000 );
1279 var_Get( p_input, "length", &val );
1280 msecstotimestr( buf2, val.i_time / 1000 );
1282 mvnprintw( y++, 0, COLS, " Position : %s/%s (%.2f%%)", buf1, buf2, p_sys->f_slider );
1285 aout_VolumeGet( p_intf, &i_volume );
1286 mvnprintw( y++, 0, COLS, " Volume : %i%%", i_volume*200/AOUT_VOLUME_MAX );
1289 if( !var_Get( p_input, "title", &val ) )
1291 var_Change( p_input, "title", VLC_VAR_GETCHOICES, &val_list, NULL );
1292 if( val_list.p_list->i_count > 0 )
1294 mvnprintw( y++, 0, COLS, " Title : %d/%d", val.i_int, val_list.p_list->i_count );
1296 var_Change( p_input, "title", VLC_VAR_FREELIST, &val_list, NULL );
1300 if( !var_Get( p_input, "chapter", &val ) )
1302 var_Change( p_input, "chapter", VLC_VAR_GETCHOICES, &val_list, NULL );
1303 if( val_list.p_list->i_count > 0 )
1305 mvnprintw( y++, 0, COLS, " Chapter : %d/%d", val.i_int, val_list.p_list->i_count );
1307 var_Change( p_input, "chapter", VLC_VAR_FREELIST, &val_list, NULL );
1317 mvnprintw( y++, 0, COLS, "Source: <no current item>" );
1318 DrawEmptyLine( p_sys->w, y++, 0, COLS );
1319 DrawEmptyLine( p_sys->w, y++, 0, COLS );
1320 DrawEmptyLine( p_sys->w, y++, 0, COLS );
1323 DrawBox( p_sys->w, y, 0, 3, COLS, "" );
1324 DrawEmptyLine( p_sys->w, y+1, 1, COLS-2);
1325 DrawLine( p_sys->w, y+1, 1, (int)(p_intf->p_sys->f_slider/100.0 * (COLS -2)) );
1328 p_sys->i_box_y = y + 1;
1329 p_sys->i_box_lines = LINES - y - 2;
1334 if( p_sys->i_box_type == BOX_HELP )
1338 DrawBox( p_sys->w, y++, 0, h, COLS, " Help " );
1340 MainBoxWrite( p_intf, l++, 1, "[Display]" );
1341 MainBoxWrite( p_intf, l++, 1, " h,H Show/Hide help box" );
1342 MainBoxWrite( p_intf, l++, 1, " i Show/Hide info box" );
1343 MainBoxWrite( p_intf, l++, 1, " L Show/Hide messages box" );
1344 MainBoxWrite( p_intf, l++, 1, " P Show/Hide playlist box" );
1345 MainBoxWrite( p_intf, l++, 1, " B Show/Hide filebrowser" );
1346 MainBoxWrite( p_intf, l++, 1, "" );
1348 MainBoxWrite( p_intf, l++, 1, "[Global]" );
1349 MainBoxWrite( p_intf, l++, 1, " q, Q Quit" );
1350 MainBoxWrite( p_intf, l++, 1, " s Stop" );
1351 MainBoxWrite( p_intf, l++, 1, " <space> Pause/Play" );
1352 MainBoxWrite( p_intf, l++, 1, " f Toggle Fullscreen" );
1353 MainBoxWrite( p_intf, l++, 1, " n, p Next/Previous playlist item" );
1354 MainBoxWrite( p_intf, l++, 1, " [, ] Next/Previous title" );
1355 MainBoxWrite( p_intf, l++, 1, " <, > Next/Previous chapter" );
1356 MainBoxWrite( p_intf, l++, 1, " <right> Seek +1%%" );
1357 MainBoxWrite( p_intf, l++, 1, " <left> Seek -1%%" );
1358 MainBoxWrite( p_intf, l++, 1, " a Volume Up" );
1359 MainBoxWrite( p_intf, l++, 1, " z Volume Down" );
1360 MainBoxWrite( p_intf, l++, 1, "" );
1362 MainBoxWrite( p_intf, l++, 1, "[Playlist]" );
1363 MainBoxWrite( p_intf, l++, 1, " r Random" );
1364 MainBoxWrite( p_intf, l++, 1, " l Loop Playlist" );
1365 MainBoxWrite( p_intf, l++, 1, " R Repeat item" );
1366 MainBoxWrite( p_intf, l++, 1, " o Order Playlist by title" );
1367 MainBoxWrite( p_intf, l++, 1, " O Reverse order Playlist by title" );
1368 MainBoxWrite( p_intf, l++, 1, " / Look for an item" );
1369 MainBoxWrite( p_intf, l++, 1, " A Add an entry" );
1370 MainBoxWrite( p_intf, l++, 1, " D, <del> Delete an entry" );
1371 MainBoxWrite( p_intf, l++, 1, " <backspace> Delete an entry" );
1372 MainBoxWrite( p_intf, l++, 1, "" );
1374 MainBoxWrite( p_intf, l++, 1, "[Filebrowser]" );
1375 MainBoxWrite( p_intf, l++, 1, " <enter> Add the selected file to the playlist" );
1376 MainBoxWrite( p_intf, l++, 1, " <space> Add the selected directory to the playlist" );
1377 MainBoxWrite( p_intf, l++, 1, " . Show/Hide hidden files" );
1378 MainBoxWrite( p_intf, l++, 1, "" );
1380 MainBoxWrite( p_intf, l++, 1, "[Boxes]" );
1381 MainBoxWrite( p_intf, l++, 1, " <up>,<down> Navigate through the box line by line" );
1382 MainBoxWrite( p_intf, l++, 1, " <pgup>,<pgdown> Navigate through the box page by page" );
1383 MainBoxWrite( p_intf, l++, 1, "" );
1385 MainBoxWrite( p_intf, l++, 1, "[Player]" );
1386 MainBoxWrite( p_intf, l++, 1, " <up>,<down> Seek +/-5%%" );
1387 MainBoxWrite( p_intf, l++, 1, "" );
1389 MainBoxWrite( p_intf, l++, 1, "[Miscellaneous]" );
1390 MainBoxWrite( p_intf, l++, 1, " Ctrl-l Refresh the screen" );
1392 p_sys->i_box_lines_total = l;
1393 if( p_sys->i_box_start >= p_sys->i_box_lines_total )
1395 p_sys->i_box_start = p_sys->i_box_lines_total - 1;
1398 if( l - p_sys->i_box_start < p_sys->i_box_lines )
1400 y += l - p_sys->i_box_start;
1404 y += p_sys->i_box_lines;
1407 else if( p_sys->i_box_type == BOX_INFO )
1411 DrawBox( p_sys->w, y++, 0, h, COLS, " Information " );
1416 vlc_mutex_lock( &input_GetItem(p_input)->lock );
1417 for( i = 0; i < input_GetItem(p_input)->i_categories; i++ )
1419 info_category_t *p_category = input_GetItem(p_input)->pp_categories[i];
1420 if( y >= y_end ) break;
1421 MainBoxWrite( p_intf, l++, 1, " [%s]", p_category->psz_name );
1422 for( j = 0; j < p_category->i_infos; j++ )
1424 info_t *p_info = p_category->pp_infos[j];
1425 if( y >= y_end ) break;
1426 MainBoxWrite( p_intf, l++, 1, " %s: %s", p_info->psz_name, p_info->psz_value );
1429 vlc_mutex_unlock( &input_GetItem(p_input)->lock );
1433 MainBoxWrite( p_intf, l++, 1, "No item currently playing" );
1435 p_sys->i_box_lines_total = l;
1436 if( p_sys->i_box_start >= p_sys->i_box_lines_total )
1438 p_sys->i_box_start = p_sys->i_box_lines_total - 1;
1441 if( l - p_sys->i_box_start < p_sys->i_box_lines )
1443 y += l - p_sys->i_box_start;
1447 y += p_sys->i_box_lines;
1450 else if( p_sys->i_box_type == BOX_LOG )
1456 DrawBox( p_sys->w, y++, 0, h, COLS, " Logs " );
1458 i_start = p_intf->p_sys->p_sub->i_start;
1460 vlc_mutex_lock( p_intf->p_sys->p_sub->p_lock );
1461 i_stop = *p_intf->p_sys->p_sub->pi_stop;
1462 vlc_mutex_unlock( p_intf->p_sys->p_sub->p_lock );
1466 static const char *ppsz_type[4] = { "", "error", "warning", "debug" };
1467 if( i_line >= h - 2 )
1473 if( i_stop < 0 ) i_stop += VLC_MSG_QSIZE;
1474 if( i_stop == i_start )
1478 mvnprintw( y + h-2-i_line, 1, COLS - 2, " [%s] %s",
1479 ppsz_type[p_sys->p_sub->p_msg[i_stop].i_type],
1480 p_sys->p_sub->p_msg[i_stop].psz_msg );
1483 vlc_mutex_lock( p_intf->p_sys->p_sub->p_lock );
1484 p_intf->p_sys->p_sub->i_start = i_stop;
1485 vlc_mutex_unlock( p_intf->p_sys->p_sub->p_lock );
1488 else if( p_sys->i_box_type == BOX_BROWSE )
1490 /* Filebrowser box */
1491 int i_start, i_stop;
1493 DrawBox( p_sys->w, y++, 0, h, COLS, " Browse " );
1495 if( p_sys->i_box_bidx >= p_sys->i_dir_entries ) p_sys->i_box_plidx = p_sys->i_dir_entries - 1;
1496 if( p_sys->i_box_bidx < 0 ) p_sys->i_box_bidx = 0;
1498 if( p_sys->i_box_bidx < (h - 2)/2 )
1503 else if( p_sys->i_dir_entries - p_sys->i_box_bidx > (h - 2)/2 )
1505 i_start = p_sys->i_box_bidx - (h - 2)/2;
1506 i_stop = i_start + h - 2;
1510 i_stop = p_sys->i_dir_entries;
1511 i_start = p_sys->i_dir_entries - (h - 2);
1517 if( i_stop > p_sys->i_dir_entries )
1519 i_stop = p_sys->i_dir_entries;
1522 for( i_item = i_start; i_item < i_stop; i_item++ )
1524 vlc_bool_t b_selected = ( p_sys->i_box_bidx == i_item );
1526 if( y >= y_end ) break;
1529 attrset( A_REVERSE );
1531 mvnprintw( y++, 1, COLS - 2, " %c %s", p_sys->pp_dir_entries[i_item]->b_file == VLC_TRUE ? ' ' : '+',
1532 p_sys->pp_dir_entries[i_item]->psz_path );
1535 attroff( A_REVERSE );
1540 else if( ( p_sys->i_box_type == BOX_PLAYLIST ||
1541 p_sys->i_box_type == BOX_SEARCH ||
1542 p_sys->i_box_type == BOX_OPEN ) && p_sys->p_playlist )
1545 int i_start, i_stop, i_max = p_sys->i_plist_entries;
1549 switch( p_sys->i_current_view )
1552 psz_title = strdup( " Playlist (All, one level) " );
1555 psz_title = strdup( " Playlist (By category) " );
1558 psz_title = strdup( " Playlist (Manually added) " );
1561 DrawBox( p_sys->w, y++, 0, h, COLS, psz_title );
1563 if( p_sys->b_need_update || p_sys->pp_plist == NULL )
1565 PlaylistRebuild( p_intf );
1567 if( p_sys->b_box_plidx_follow )
1569 FindIndex( p_intf );
1572 if( p_sys->i_box_plidx < 0 ) p_sys->i_box_plidx = 0;
1573 if( p_sys->i_box_plidx < 0 ) p_sys->i_box_plidx = 0;
1574 if( p_sys->i_box_plidx >= i_max ) p_sys->i_box_plidx = i_max - 1;
1576 if( p_sys->i_box_plidx < (h - 2)/2 )
1581 else if( i_max - p_sys->i_box_plidx > (h - 2)/2 )
1583 i_start = p_sys->i_box_plidx - (h - 2)/2;
1584 i_stop = i_start + h - 2;
1589 i_start = i_max - (h - 2);
1595 if( i_stop > i_max )
1600 for( i_item = i_start; i_item < i_stop; i_item++ )
1602 vlc_bool_t b_selected = ( p_sys->i_box_plidx == i_item );
1603 int c = ( PlaylistIsPlaying( p_intf,
1604 p_sys->pp_plist[i_item]->p_item ) ) ? '>' : ' ';
1606 if( y >= y_end ) break;
1609 attrset( A_REVERSE );
1611 mvnprintw( y++, 1, COLS - 2, "%c%s", c,
1612 p_sys->pp_plist[i_item]->psz_display );
1615 attroff( A_REVERSE );
1624 if( p_sys->i_box_type == BOX_SEARCH )
1626 DrawEmptyLine( p_sys->w, 7, 1, COLS-2 );
1627 if( p_sys->psz_search_chain )
1629 if( strlen( p_sys->psz_search_chain ) == 0 &&
1630 p_sys->psz_old_search != NULL )
1632 /* Searching next entry */
1633 mvnprintw( 7, 1, COLS-2, "Find: %s", p_sys->psz_old_search );
1637 mvnprintw( 7, 1, COLS-2, "Find: %s", p_sys->psz_search_chain );
1641 if( p_sys->i_box_type == BOX_OPEN )
1643 if( p_sys->psz_open_chain )
1645 DrawEmptyLine( p_sys->w, 7, 1, COLS-2 );
1646 mvnprintw( 7, 1, COLS-2, "Open: %s", p_sys->psz_open_chain );
1652 DrawEmptyLine( p_sys->w, y++, 1, COLS - 2 );
1657 *t_last_refresh = time( 0 );
1660 static playlist_item_t *PlaylistGetRoot( intf_thread_t *p_intf )
1662 intf_sys_t *p_sys = p_intf->p_sys;
1663 playlist_t *p_playlist = p_sys->p_playlist;
1665 if( p_playlist == NULL )
1670 switch( p_sys->i_current_view )
1673 return p_playlist->p_root_category;
1675 return p_playlist->p_root_onelevel;
1679 static void PlaylistRebuild( intf_thread_t *p_intf )
1681 intf_sys_t *p_sys = p_intf->p_sys;
1682 playlist_t *p_playlist = p_sys->p_playlist;
1684 if( p_playlist == NULL )
1689 vlc_mutex_lock( &p_playlist->object_lock );
1691 /* First clear the old one */
1692 PlaylistDestroy( p_intf );
1694 /* Build the new one */
1695 PlaylistAddNode( p_intf, PlaylistGetRoot( p_intf ), 0, "" );
1697 p_sys->b_need_update = VLC_FALSE;
1699 vlc_mutex_unlock( &p_playlist->object_lock );
1702 static void PlaylistAddNode( intf_thread_t *p_intf, playlist_item_t *p_node,
1703 int i, const char *c )
1705 intf_sys_t *p_sys = p_intf->p_sys;
1706 playlist_item_t *p_child;
1710 psz_tmp = (char *)malloc( strlen( c ) + 4 );
1711 if( psz_tmp == NULL ) return;
1712 for( k = 0; k < p_node->i_children; k++ )
1714 struct pl_item_t *p_pl_item;
1718 p_child = p_node->pp_children[k];
1719 i_size = strlen( c ) + strlen( p_child->p_input->psz_name ) + 4;
1720 buff = (char *)malloc( sizeof( char ) * i_size );
1721 p_pl_item = (struct pl_item_t *)malloc( sizeof( struct pl_item_t ) );
1722 if( p_pl_item == NULL || buff == NULL ) return;
1726 sprintf( buff, "%s%c-%s", c, k == p_node->i_children - 1 ?
1727 '`' : '|', p_child->p_input->psz_name );
1731 sprintf( buff, " %s", p_child->p_input->psz_name );
1733 p_pl_item->psz_display = strdup( buff );
1734 p_pl_item->p_item = p_child;
1735 INSERT_ELEM( p_sys->pp_plist, p_sys->i_plist_entries,
1736 p_sys->i_plist_entries, p_pl_item );
1740 if( p_child->i_children > 0 )
1742 sprintf( psz_tmp, "%s%c ", c,
1743 k == p_node->i_children - 1 ? ' ' : '|' );
1744 PlaylistAddNode( p_intf, p_child, i,
1745 strlen( c ) ? psz_tmp : " " );
1751 static int PlaylistChanged( vlc_object_t *p_this, const char *psz_variable,
1752 vlc_value_t oval, vlc_value_t nval, void *param )
1754 intf_thread_t *p_intf = (intf_thread_t *)param;
1755 p_intf->p_sys->b_need_update = VLC_TRUE;
1760 static inline vlc_bool_t PlaylistIsPlaying( intf_thread_t *p_intf,
1761 playlist_item_t *p_item )
1763 playlist_item_t *p_played_item = p_intf->p_sys->p_playlist->status.p_item;
1764 return( p_item != NULL && p_played_item != NULL &&
1765 p_item->p_input != NULL && p_played_item->p_input != NULL &&
1766 p_item->p_input->i_id == p_played_item->p_input->i_id );
1769 static void FindIndex( intf_thread_t *p_intf )
1771 intf_sys_t *p_sys = p_intf->p_sys;
1774 if( p_sys->i_box_plidx < p_sys->i_plist_entries &&
1775 p_sys->i_box_plidx >= 0 &&
1776 PlaylistIsPlaying( p_intf,
1777 p_sys->pp_plist[p_sys->i_box_plidx]->p_item ) )
1782 for( i = 0; i < p_sys->i_plist_entries; i++ )
1784 if( PlaylistIsPlaying( p_intf, p_sys->pp_plist[i]->p_item ) )
1786 p_sys->i_box_plidx = i;
1792 static void PlaylistDestroy( intf_thread_t *p_intf )
1794 intf_sys_t *p_sys = p_intf->p_sys;
1797 for( i = 0; i < p_sys->i_plist_entries; i++ )
1799 struct pl_item_t *p_pl_item = p_sys->pp_plist[i];
1800 free( p_pl_item->psz_display );
1801 REMOVE_ELEM( p_sys->pp_plist, p_sys->i_plist_entries, i );
1804 p_sys->pp_plist = NULL;
1805 p_sys->i_plist_entries = 0;
1808 static void Eject( intf_thread_t *p_intf )
1810 char *psz_device = NULL, *psz_parser, *psz_name;
1813 * Get the active input
1814 * Determine whether we can eject a media, ie it's a DVD, VCD or CD-DA
1815 * If it's neither of these, then return
1818 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1821 if( p_playlist == NULL )
1826 vlc_mutex_lock( &p_playlist->object_lock );
1828 if( p_playlist->status.p_item == NULL )
1830 vlc_mutex_unlock( &p_playlist->object_lock );
1831 vlc_object_release( p_playlist );
1835 psz_name = p_playlist->status.p_item->p_input->psz_name;
1839 if( !strncmp(psz_name, "dvd://", 4) )
1841 switch( psz_name[strlen("dvd://")] )
1845 psz_device = config_GetPsz( p_intf, "dvd" );
1848 /* Omit the first MRL-selector characters */
1849 psz_device = strdup( psz_name + strlen("dvd://" ) );
1853 else if( !strncmp(psz_name, VCD_MRL, strlen(VCD_MRL)) )
1855 switch( psz_name[strlen(VCD_MRL)] )
1859 psz_device = config_GetPsz( p_intf, VCD_MRL );
1862 /* Omit the beginning MRL-selector characters */
1863 psz_device = strdup( psz_name + strlen(VCD_MRL) );
1867 else if( !strncmp(psz_name, CDDA_MRL, strlen(CDDA_MRL) ) )
1869 switch( psz_name[strlen(CDDA_MRL)] )
1873 psz_device = config_GetPsz( p_intf, "cd-audio" );
1876 /* Omit the beginning MRL-selector characters */
1877 psz_device = strdup( psz_name + strlen(CDDA_MRL) );
1883 psz_device = strdup( psz_name );
1887 vlc_mutex_unlock( &p_playlist->object_lock );
1888 vlc_object_release( p_playlist );
1890 if( psz_device == NULL )
1895 /* Remove what we have after @ */
1896 psz_parser = psz_device;
1897 for( psz_parser = psz_device ; *psz_parser ; psz_parser++ )
1899 if( *psz_parser == '@' )
1906 /* If there's a stream playing, we aren't allowed to eject ! */
1907 if( p_intf->p_sys->p_input == NULL )
1909 msg_Dbg( p_intf, "ejecting %s", psz_device );
1911 intf_Eject( p_intf, psz_device );
1918 static int comp_dir_entries( const void *pp_dir_entry1,
1919 const void *pp_dir_entry2 )
1921 struct dir_entry_t *p_dir_entry1 = *(struct dir_entry_t**)pp_dir_entry1;
1922 struct dir_entry_t *p_dir_entry2 = *(struct dir_entry_t**)pp_dir_entry2;
1923 if ( p_dir_entry1->b_file == p_dir_entry2->b_file ) {
1924 return strcasecmp( p_dir_entry1->psz_path, p_dir_entry2->psz_path );
1928 return ( p_dir_entry1->b_file ? 1 : -1 );
1932 static void ReadDir( intf_thread_t *p_intf )
1934 intf_sys_t *p_sys = p_intf->p_sys;
1938 if( p_sys->psz_current_dir && *p_sys->psz_current_dir )
1943 p_current_dir = utf8_opendir( p_sys->psz_current_dir );
1945 if( p_current_dir == NULL )
1947 /* something went bad, get out of here ! */
1948 msg_Warn( p_intf, "cannot open directory `%s' (%m)",
1949 p_sys->psz_current_dir );
1953 /* Clean the old shit */
1954 for( i = 0; i < p_sys->i_dir_entries; i++ )
1956 struct dir_entry_t *p_dir_entry = p_sys->pp_dir_entries[i];
1957 free( p_dir_entry->psz_path );
1958 REMOVE_ELEM( p_sys->pp_dir_entries, p_sys->i_dir_entries, i );
1959 free( p_dir_entry );
1961 p_sys->pp_dir_entries = NULL;
1962 p_sys->i_dir_entries = 0;
1964 /* while we still have entries in the directory */
1965 while( ( psz_entry = utf8_readdir( p_current_dir ) ) != NULL )
1967 #if defined( S_ISDIR )
1968 struct stat stat_data;
1970 struct dir_entry_t *p_dir_entry;
1971 int i_size_entry = strlen( p_sys->psz_current_dir ) +
1972 strlen( psz_entry ) + 2;
1975 if( p_sys->b_show_hidden_files == VLC_FALSE &&
1976 ( strlen( psz_entry ) && psz_entry[0] == '.' ) &&
1977 strcmp( psz_entry, ".." ) )
1983 psz_uri = (char *)malloc( sizeof(char)*i_size_entry);
1984 sprintf( psz_uri, "%s/%s", p_sys->psz_current_dir, psz_entry );
1986 if( !( p_dir_entry = malloc( sizeof( struct dir_entry_t) ) ) )
1993 #if defined( S_ISDIR )
1994 if( !utf8_stat( psz_uri, &stat_data )
1995 && S_ISDIR(stat_data.st_mode) )
1996 /*#elif defined( DT_DIR )
1997 if( p_dir_content->d_type & DT_DIR )*/
2002 p_dir_entry->psz_path = strdup( psz_entry );
2003 p_dir_entry->b_file = VLC_FALSE;
2004 INSERT_ELEM( p_sys->pp_dir_entries, p_sys->i_dir_entries,
2005 p_sys->i_dir_entries, p_dir_entry );
2009 p_dir_entry->psz_path = strdup( psz_entry );
2010 p_dir_entry->b_file = VLC_TRUE;
2011 INSERT_ELEM( p_sys->pp_dir_entries, p_sys->i_dir_entries,
2012 p_sys->i_dir_entries, p_dir_entry );
2020 qsort( p_sys->pp_dir_entries, p_sys->i_dir_entries,
2021 sizeof(struct dir_entry_t*), &comp_dir_entries );
2023 closedir( p_current_dir );
2028 msg_Dbg( p_intf, "no current dir set" );
2033 static void PlayPause( intf_thread_t *p_intf )
2035 input_thread_t *p_input = p_intf->p_sys->p_input;
2040 var_Get( p_input, "state", &val );
2041 if( val.i_int != PAUSE_S )
2043 val.i_int = PAUSE_S;
2047 val.i_int = PLAYING_S;
2049 var_Set( p_input, "state", val );
2051 else if( p_intf->p_sys->p_playlist )
2053 playlist_Play( p_intf->p_sys->p_playlist );
2057 /****************************************************************************
2059 ****************************************************************************/
2060 static void DrawBox( WINDOW *win, int y, int x, int h, int w, const char *title )
2065 if( w > 3 && h > 2 )
2067 if( title == NULL ) title = "";
2068 i_len = strlen( title );
2070 if( i_len > w - 2 ) i_len = w - 2;
2072 mvwaddch( win, y, x, ACS_ULCORNER );
2073 mvwhline( win, y, x+1, ACS_HLINE, ( w-i_len-2)/2 );
2074 mvwprintw( win,y, x+1+(w-i_len-2)/2, "%s", title );
2075 mvwhline( win, y, x+(w-i_len)/2+i_len, ACS_HLINE, w - 1 - ((w-i_len)/2+i_len) );
2076 mvwaddch( win, y, x+w-1,ACS_URCORNER );
2078 for( i = 0; i < h-2; i++ )
2080 mvwaddch( win, y+i+1, x, ACS_VLINE );
2081 mvwaddch( win, y+i+1, x+w-1, ACS_VLINE );
2084 mvwaddch( win, y+h-1, x, ACS_LLCORNER );
2085 mvwhline( win, y+h-1, x+1, ACS_HLINE, w - 2 );
2086 mvwaddch( win, y+h-1, x+w-1, ACS_LRCORNER );
2090 static void DrawEmptyLine( WINDOW *win, int y, int x, int w )
2094 mvhline( y, x, ' ', w );
2098 static void DrawLine( WINDOW *win, int y, int x, int w )
2102 attrset( A_REVERSE );
2103 mvhline( y, x, ' ', w );
2104 attroff( A_REVERSE );