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 *****************************************************************************/
31 #include <stdlib.h> /* malloc(), free() */
33 #include <errno.h> /* ENOMEM */
40 #include <vlc_interface.h>
43 #include <vlc_charset.h>
44 #include <vlc_input.h>
45 #include <vlc_playlist.h>
47 #ifdef HAVE_SYS_STAT_H
48 # include <sys/stat.h>
50 #if (!defined( WIN32 ) || defined(__MINGW32__))
51 /* Mingw has its own version of dirent */
56 #define CDDA_MRL "cddax://"
58 #define CDDA_MRL "cdda://"
62 #define VCD_MRL "vcdx://"
64 #define VCD_MRL "vcdx://"
67 #define SEARCH_CHAIN_SIZE 20
68 #define OPEN_CHAIN_SIZE 50
70 /*****************************************************************************
72 *****************************************************************************/
73 static int Open ( vlc_object_t * );
74 static void Close ( vlc_object_t * );
76 static void Run ( intf_thread_t * );
77 static void PlayPause ( intf_thread_t * );
78 static void Eject ( intf_thread_t * );
80 static int HandleKey ( intf_thread_t *, int );
81 static void Redraw ( intf_thread_t *, time_t * );
83 static playlist_item_t *PlaylistGetRoot( intf_thread_t * );
84 static void PlaylistRebuild( intf_thread_t * );
85 static void PlaylistAddNode( intf_thread_t *, playlist_item_t *, int, const char *);
86 static void PlaylistDestroy( intf_thread_t * );
87 static int PlaylistChanged( vlc_object_t *, const char *, vlc_value_t,
88 vlc_value_t, void * );
89 static inline vlc_bool_t PlaylistIsPlaying( intf_thread_t *,
91 static void FindIndex ( intf_thread_t * );
92 static void SearchPlaylist ( intf_thread_t *, char * );
93 static int SubSearchPlaylist( intf_thread_t *, char *, int, int );
95 static void ManageSlider ( intf_thread_t * );
96 static void ReadDir ( intf_thread_t * );
98 /*****************************************************************************
100 *****************************************************************************/
102 #define BROWSE_TEXT N_("Filebrowser starting point")
103 #define BROWSE_LONGTEXT N_( \
104 "This option allows you to specify the directory the ncurses filebrowser " \
105 "will show you initially.")
108 set_shortname( "Ncurses" );
109 set_description( _("Ncurses interface") );
110 set_capability( "interface", 10 );
111 set_category( CAT_INTERFACE );
112 set_subcategory( SUBCAT_INTERFACE_MAIN );
113 set_callbacks( Open, Close );
114 add_shortcut( "curses" );
115 add_directory( "browse-dir", NULL, NULL, BROWSE_TEXT, BROWSE_LONGTEXT, VLC_FALSE );
118 /*****************************************************************************
119 * intf_sys_t: description and status of ncurses interface
120 *****************************************************************************/
144 playlist_item_t *p_item;
149 playlist_t *p_playlist;
150 input_thread_t *p_input;
160 int i_box_lines_total;
163 int i_box_plidx; /* Playlist index */
164 int b_box_plidx_follow;
165 playlist_item_t *p_plnode; /* Playlist node */
166 int i_box_bidx; /* browser index */
170 msg_subscription_t* p_sub; /* message bank subscription */
172 char *psz_search_chain; /* for playlist searching */
173 char *psz_old_search; /* for searching next */
176 char *psz_open_chain;
177 char psz_partial_keys[7];
179 char *psz_current_dir;
181 struct dir_entry_t **pp_dir_entries;
182 vlc_bool_t b_show_hidden_files;
184 int i_current_view; /* playlist view */
185 struct pl_item_t **pp_plist;
187 vlc_bool_t b_need_update; /* for playlist view */
190 static void DrawBox( WINDOW *win, int y, int x, int h, int w, const char *title );
191 static void DrawLine( WINDOW *win, int y, int x, int w );
192 static void DrawEmptyLine( WINDOW *win, int y, int x, int w );
194 /*****************************************************************************
195 * Open: initialize and create window
196 *****************************************************************************/
197 static int Open( vlc_object_t *p_this )
199 intf_thread_t *p_intf = (intf_thread_t *)p_this;
203 /* Allocate instance and initialize some members */
204 p_sys = p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
205 p_sys->p_playlist = NULL;
206 p_sys->p_input = NULL;
207 p_sys->f_slider = 0.0;
208 p_sys->f_slider_old = 0.0;
209 p_sys->i_box_type = BOX_PLAYLIST;
210 p_sys->i_box_lines = 0;
211 p_sys->i_box_start= 0;
212 p_sys->i_box_lines_total = 0;
213 p_sys->b_box_plidx_follow = VLC_TRUE;
214 p_sys->b_box_cleared = VLC_FALSE;
215 p_sys->i_box_plidx = 0;
216 p_sys->p_plnode = NULL;
217 p_sys->i_box_bidx = 0;
218 p_sys->p_sub = msg_Subscribe( p_intf, MSG_QUEUE_NORMAL );
219 memset( p_sys->psz_partial_keys, 0, sizeof( p_sys->psz_partial_keys ) );
221 /* Initialize the curses library */
222 p_sys->w = initscr();
223 keypad( p_sys->w, TRUE );
224 /* Don't do NL -> CR/NL */
226 /* Take input chars one at a time */
236 /* exported function */
237 p_intf->pf_run = Run;
241 var_Set( p_intf->p_libvlc, "verbose", val );
243 /* Set defaul playlist view */
244 p_sys->i_current_view = VIEW_CATEGORY;
245 p_sys->pp_plist = NULL;
246 p_sys->i_plist_entries = 0;
247 p_sys->b_need_update = VLC_FALSE;
249 /* Initialize search chain */
250 p_sys->psz_search_chain = (char *)malloc( SEARCH_CHAIN_SIZE + 1 );
251 p_sys->psz_old_search = NULL;
252 p_sys->i_before_search = 0;
254 /* Initialize open chain */
255 p_sys->psz_open_chain = (char *)malloc( OPEN_CHAIN_SIZE + 1 );
257 /* Initialize browser options */
258 var_Create( p_intf, "browse-dir", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
259 var_Get( p_intf, "browse-dir", &val);
261 if( val.psz_string && *val.psz_string )
263 p_sys->psz_current_dir = strdup( val.psz_string );
264 free( val.psz_string );
268 p_sys->psz_current_dir = strdup( p_intf->p_libvlc->psz_homedir );
271 p_sys->i_dir_entries = 0;
272 p_sys->pp_dir_entries = NULL;
273 p_sys->b_show_hidden_files = VLC_FALSE;
279 /*****************************************************************************
280 * Close: destroy interface window
281 *****************************************************************************/
282 static void Close( vlc_object_t *p_this )
284 intf_thread_t *p_intf = (intf_thread_t *)p_this;
285 intf_sys_t *p_sys = p_intf->p_sys;
288 var_DelCallback( p_sys->p_playlist, "intf-change", PlaylistChanged,
290 var_DelCallback( p_sys->p_playlist, "item-append", PlaylistChanged,
293 PlaylistDestroy( p_intf );
295 for( i = 0; i < p_sys->i_dir_entries; i++ )
297 struct dir_entry_t *p_dir_entry = p_sys->pp_dir_entries[i];
298 if( p_dir_entry->psz_path ) free( p_dir_entry->psz_path );
299 REMOVE_ELEM( p_sys->pp_dir_entries, p_sys->i_dir_entries, i );
300 if( p_dir_entry ) free( p_dir_entry );
302 p_sys->pp_dir_entries = NULL;
304 if( p_sys->psz_current_dir ) free( p_sys->psz_current_dir );
305 if( p_sys->psz_search_chain ) free( p_sys->psz_search_chain );
306 if( p_sys->psz_old_search ) free( p_sys->psz_old_search );
307 if( p_sys->psz_open_chain ) free( p_sys->psz_open_chain );
311 vlc_object_release( p_sys->p_input );
313 if( p_sys->p_playlist )
315 vlc_object_release( p_sys->p_playlist );
318 /* Close the ncurses interface */
321 msg_Unsubscribe( p_intf, p_sys->p_sub );
323 /* Destroy structure */
327 /*****************************************************************************
328 * Run: ncurses thread
329 *****************************************************************************/
330 static void Run( intf_thread_t *p_intf )
332 intf_sys_t *p_sys = p_intf->p_sys;
335 time_t t_last_refresh;
338 * force drawing the interface for the first time
340 t_last_refresh = ( time( 0 ) - 1);
342 while( !intf_ShouldDie( p_intf ) )
344 msleep( INTF_IDLE_SLEEP );
346 /* Update the input */
347 if( p_sys->p_playlist == NULL )
349 p_sys->p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
351 if( p_sys->p_playlist )
353 var_AddCallback( p_sys->p_playlist, "intf-change",
354 PlaylistChanged, p_intf );
355 var_AddCallback( p_sys->p_playlist, "item-append",
356 PlaylistChanged, p_intf );
359 if( p_sys->p_playlist )
361 vlc_mutex_lock( &p_sys->p_playlist->object_lock );
362 if( p_sys->p_input == NULL )
364 p_sys->p_input = p_sys->p_playlist->p_input;
367 if( !p_sys->p_input->b_dead )
369 vlc_object_yield( p_sys->p_input );
373 else if( p_sys->p_input->b_dead )
375 vlc_object_release( p_sys->p_input );
376 p_sys->p_input = NULL;
377 p_sys->f_slider = p_sys->f_slider_old = 0.0;
378 p_sys->b_box_cleared = VLC_FALSE;
380 vlc_mutex_unlock( &p_sys->p_playlist->object_lock );
383 if( p_sys->b_box_plidx_follow && p_sys->p_playlist->status.p_item )
388 while( ( i_key = getch() ) != -1 )
391 * HandleKey returns 1 if the screen needs to be redrawn
393 if( HandleKey( p_intf, i_key ) )
395 Redraw( p_intf, &t_last_refresh );
399 if( p_sys->f_slider > 0.0001 && !p_sys->b_box_cleared )
402 Redraw( p_intf, &t_last_refresh );
403 p_sys->b_box_cleared = VLC_TRUE;
407 * redraw the screen every second
409 if( (time(0) - t_last_refresh) >= 1 )
411 ManageSlider( p_intf );
412 Redraw( p_intf, &t_last_refresh );
417 /* following functions are local */
419 static char *KeyToUTF8( int i_key, char *psz_part )
421 char *psz_utf8, *psz;
422 int len = strlen( psz_part );
425 /* overflow error - should not happen */
426 memset( psz_part, 0, 6 );
430 psz_part[len] = (char)i_key;
432 psz_utf8 = FromLocaleDup( psz_part );
434 /* Ugly check for incomplete bytes sequences
435 * (in case of non-UTF8 multibyte local encoding) */
436 for( psz = psz_utf8; *psz; psz++ )
437 if( ( *psz == '?' ) && ( *psz_utf8 != '?' ) )
439 /* incomplete bytes sequence detected
440 * (VLC core inserted dummy question marks) */
445 /* Check for incomplete UTF8 bytes sequence */
446 if( EnsureUTF8( psz_utf8 ) == NULL )
452 memset( psz_part, 0, 6 );
456 static inline int RemoveLastUTF8Entity( char *psz, int len )
458 while( len && ( (psz[--len] & 0xc0) == 0x80 ) );
459 /* UTF8 continuation byte */
465 static int HandleKey( intf_thread_t *p_intf, int i_key )
467 intf_sys_t *p_sys = p_intf->p_sys;
470 if( p_sys->i_box_type == BOX_PLAYLIST && p_sys->p_playlist )
472 int b_ret = VLC_TRUE;
473 vlc_bool_t b_box_plidx_follow = VLC_FALSE;
478 /* Playlist Settings */
480 var_Get( p_sys->p_playlist, "random", &val );
481 val.b_bool = !val.b_bool;
482 var_Set( p_sys->p_playlist, "random", val );
485 var_Get( p_sys->p_playlist, "loop", &val );
486 val.b_bool = !val.b_bool;
487 var_Set( p_sys->p_playlist, "loop", val );
490 var_Get( p_sys->p_playlist, "repeat", &val );
491 val.b_bool = !val.b_bool;
492 var_Set( p_sys->p_playlist, "repeat", val );
497 playlist_RecursiveNodeSort( p_sys->p_playlist,
498 PlaylistGetRoot( p_intf ),
499 SORT_TITLE_NODES_FIRST, ORDER_NORMAL );
500 p_sys->b_need_update = VLC_TRUE;
503 playlist_RecursiveNodeSort( p_sys->p_playlist,
504 PlaylistGetRoot( p_intf ),
505 SORT_TITLE_NODES_FIRST, ORDER_REVERSE );
506 p_sys->b_need_update = VLC_TRUE;
511 switch( p_sys->i_current_view )
514 p_sys->i_current_view = VIEW_ONELEVEL;
517 p_sys->i_current_view = VIEW_CATEGORY;
519 //p_sys->b_need_update = VLC_TRUE;
520 PlaylistRebuild( p_intf );
523 /* Playlist navigation */
525 p_sys->i_box_plidx = 0;
528 p_sys->i_box_plidx = p_sys->p_playlist->items.i_size - 1;
531 p_sys->i_box_plidx--;
534 p_sys->i_box_plidx++;
537 p_sys->i_box_plidx -= p_sys->i_box_lines;
540 p_sys->i_box_plidx += p_sys->i_box_lines;
546 playlist_t *p_playlist = p_sys->p_playlist;
547 playlist_item_t *p_item;
549 vlc_mutex_lock( &p_playlist->object_lock );
550 p_item = p_sys->pp_plist[p_sys->i_box_plidx]->p_item;
551 if( p_item->i_children == -1 )
553 playlist_DeleteFromInput( p_playlist,
554 p_item->p_input->i_id, VLC_TRUE );
558 playlist_NodeDelete( p_playlist, p_item,
559 VLC_TRUE , VLC_FALSE );
561 vlc_mutex_unlock( &p_playlist->object_lock );
562 p_sys->b_need_update = VLC_TRUE;
569 if( p_sys->pp_plist[p_sys->i_box_plidx]->p_item->i_children
572 playlist_Control( p_sys->p_playlist, PLAYLIST_VIEWPLAY,
574 p_sys->pp_plist[p_sys->i_box_plidx]->p_item );
578 playlist_Control( p_sys->p_playlist, PLAYLIST_VIEWPLAY,
580 p_sys->pp_plist[p_sys->i_box_plidx]->p_item,
583 b_box_plidx_follow = VLC_TRUE;
592 int i_max = p_sys->i_plist_entries;
593 if( p_sys->i_box_plidx >= i_max ) p_sys->i_box_plidx = i_max - 1;
594 if( p_sys->i_box_plidx < 0 ) p_sys->i_box_plidx = 0;
595 if( PlaylistIsPlaying( p_intf,
596 p_sys->pp_plist[p_sys->i_box_plidx]->p_item ) )
597 b_box_plidx_follow = VLC_TRUE;
598 p_sys->b_box_plidx_follow = b_box_plidx_follow;
602 if( p_sys->i_box_type == BOX_BROWSE )
604 vlc_bool_t b_ret = VLC_TRUE;
605 /* Browser navigation */
609 p_sys->i_box_bidx = 0;
612 p_sys->i_box_bidx = p_sys->i_dir_entries - 1;
621 p_sys->i_box_bidx -= p_sys->i_box_lines;
624 p_sys->i_box_bidx += p_sys->i_box_lines;
626 case '.': /* Toggle show hidden files */
627 p_sys->b_show_hidden_files = ( p_sys->b_show_hidden_files ==
628 VLC_TRUE ? VLC_FALSE : VLC_TRUE );
635 if( p_sys->pp_dir_entries[p_sys->i_box_bidx]->b_file || i_key == ' ' )
637 int i_size_entry = strlen( p_sys->psz_current_dir ) +
638 strlen( p_sys->pp_dir_entries[p_sys->i_box_bidx]->psz_path ) + 2;
639 char *psz_uri = (char *)malloc( sizeof(char)*i_size_entry);
641 sprintf( psz_uri, "%s/%s", p_sys->psz_current_dir, p_sys->pp_dir_entries[p_sys->i_box_bidx]->psz_path );
643 playlist_Add( p_sys->p_playlist, psz_uri,
645 PLAYLIST_APPEND, PLAYLIST_END );
647 p_sys->i_box_type = BOX_PLAYLIST;
652 int i_size_entry = strlen( p_sys->psz_current_dir ) +
653 strlen( p_sys->pp_dir_entries[p_sys->i_box_bidx]->psz_path ) + 2;
654 char *psz_uri = (char *)malloc( sizeof(char)*i_size_entry);
656 sprintf( psz_uri, "%s/%s", p_sys->psz_current_dir, p_sys->pp_dir_entries[p_sys->i_box_bidx]->psz_path );
658 p_sys->psz_current_dir = strdup( psz_uri );
669 if( p_sys->i_box_bidx >= p_sys->i_dir_entries ) p_sys->i_box_bidx = p_sys->i_dir_entries - 1;
670 if( p_sys->i_box_bidx < 0 ) p_sys->i_box_bidx = 0;
674 else if( p_sys->i_box_type == BOX_HELP || p_sys->i_box_type == BOX_INFO )
679 p_sys->i_box_start = 0;
682 p_sys->i_box_start = p_sys->i_box_lines_total - 1;
685 if( p_sys->i_box_start > 0 ) p_sys->i_box_start--;
688 if( p_sys->i_box_start < p_sys->i_box_lines_total - 1 )
690 p_sys->i_box_start++;
694 p_sys->i_box_start -= p_sys->i_box_lines;
695 if( p_sys->i_box_start < 0 ) p_sys->i_box_start = 0;
698 p_sys->i_box_start += p_sys->i_box_lines;
699 if( p_sys->i_box_start >= p_sys->i_box_lines_total )
701 p_sys->i_box_start = p_sys->i_box_lines_total - 1;
708 else if( p_sys->i_box_type == BOX_NONE )
714 ManageSlider( p_intf );
717 p_sys->f_slider = 99.9;
718 ManageSlider( p_intf );
721 p_sys->f_slider += 5.0;
722 if( p_sys->f_slider >= 99.0 ) p_sys->f_slider = 99.0;
723 ManageSlider( p_intf );
726 p_sys->f_slider -= 5.0;
727 if( p_sys->f_slider < 0.0 ) p_sys->f_slider = 0.0;
728 ManageSlider( p_intf );
735 else if( p_sys->i_box_type == BOX_SEARCH && p_sys->psz_search_chain )
738 i_chain_len = strlen( p_sys->psz_search_chain );
746 if( i_chain_len > 0 )
748 p_sys->psz_old_search = strdup( p_sys->psz_search_chain );
750 else if( p_sys->psz_old_search )
752 SearchPlaylist( p_intf, p_sys->psz_old_search );
754 p_sys->i_box_type = BOX_PLAYLIST;
756 case 0x1b: /* Esc. */
757 p_sys->i_box_plidx = p_sys->i_before_search;
758 p_sys->i_box_type = BOX_PLAYLIST;
761 RemoveLastUTF8Entity( p_sys->psz_search_chain, i_chain_len );
765 char *psz_utf8 = KeyToUTF8( i_key, p_sys->psz_partial_keys );
767 if( psz_utf8 != NULL )
769 if( i_chain_len + strlen( psz_utf8 ) < SEARCH_CHAIN_SIZE )
771 strcpy( p_sys->psz_search_chain + i_chain_len,
779 if( p_sys->psz_old_search )
781 free( p_sys->psz_old_search );
782 p_sys->psz_old_search = NULL;
784 SearchPlaylist( p_intf, p_sys->psz_search_chain );
787 else if( p_sys->i_box_type == BOX_OPEN && p_sys->psz_open_chain )
789 int i_chain_len = strlen( p_sys->psz_open_chain );
790 playlist_t *p_playlist = p_sys->p_playlist;
799 if( p_playlist && i_chain_len > 0 )
802 playlist_Add( p_playlist, p_sys->psz_open_chain,
803 p_sys->psz_open_chain,
804 PLAYLIST_GO|PLAYLIST_APPEND, PLAYLIST_END );
806 p_sys->b_box_plidx_follow = VLC_TRUE;
808 p_sys->i_box_type = BOX_PLAYLIST;
810 case 0x1b: /* Esc. */
811 p_sys->i_box_type = BOX_PLAYLIST;
814 RemoveLastUTF8Entity( p_sys->psz_open_chain, i_chain_len );
818 char *psz_utf8 = KeyToUTF8( i_key, p_sys->psz_partial_keys );
820 if( psz_utf8 != NULL )
822 if( i_chain_len + strlen( psz_utf8 ) < OPEN_CHAIN_SIZE )
824 strcpy( p_sys->psz_open_chain + i_chain_len,
842 vlc_object_kill( p_intf->p_libvlc );
847 if( p_sys->i_box_type == BOX_INFO )
848 p_sys->i_box_type = BOX_NONE;
850 p_sys->i_box_type = BOX_INFO;
851 p_sys->i_box_lines_total = 0;
854 if( p_sys->i_box_type == BOX_LOG )
855 p_sys->i_box_type = BOX_NONE;
857 p_sys->i_box_type = BOX_LOG;
860 if( p_sys->i_box_type == BOX_PLAYLIST )
861 p_sys->i_box_type = BOX_NONE;
863 p_sys->i_box_type = BOX_PLAYLIST;
866 if( p_sys->i_box_type == BOX_BROWSE )
867 p_sys->i_box_type = BOX_NONE;
869 p_sys->i_box_type = BOX_BROWSE;
873 if( p_sys->i_box_type == BOX_HELP )
874 p_sys->i_box_type = BOX_NONE;
876 p_sys->i_box_type = BOX_HELP;
877 p_sys->i_box_lines_total = 0;
880 if( p_sys->i_box_type != BOX_SEARCH )
882 if( p_sys->psz_search_chain == NULL )
886 p_sys->psz_search_chain[0] = '\0';
887 p_sys->b_box_plidx_follow = VLC_FALSE;
888 p_sys->i_before_search = p_sys->i_box_plidx;
889 p_sys->i_box_type = BOX_SEARCH;
893 if( p_sys->i_box_type != BOX_OPEN )
895 if( p_sys->psz_open_chain == NULL )
899 p_sys->psz_open_chain[0] = '\0';
900 p_sys->i_box_type = BOX_OPEN;
906 p_sys->f_slider += 1.0;
907 if( p_sys->f_slider > 99.9 ) p_sys->f_slider = 99.9;
908 ManageSlider( p_intf );
912 p_sys->f_slider -= 1.0;
913 if( p_sys->f_slider < 0.0 ) p_sys->f_slider = 0.0;
914 ManageSlider( p_intf );
920 if( p_intf->p_sys->p_input )
922 vout_thread_t *p_vout;
923 p_vout = vlc_object_find( p_intf->p_sys->p_input,
924 VLC_OBJECT_VOUT, FIND_CHILD );
927 var_Get( p_vout, "fullscreen", &val );
928 val.b_bool = !val.b_bool;
929 var_Set( p_vout, "fullscreen", val );
930 vlc_object_release( p_vout );
934 playlist_t *p_playlist;
935 p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
939 var_Get( p_playlist, "fullscreen", &val );
940 val.b_bool = !val.b_bool;
941 var_Set( p_playlist, "fullscreen", val );
942 vlc_object_release( p_playlist );
954 if( p_intf->p_sys->p_playlist )
956 playlist_Stop( p_intf->p_sys->p_playlist );
967 val.b_bool = VLC_TRUE;
968 var_Set( p_sys->p_input, "prev-title", val );
975 val.b_bool = VLC_TRUE;
976 var_Set( p_sys->p_input, "next-title", val );
983 val.b_bool = VLC_TRUE;
984 var_Set( p_sys->p_input, "prev-chapter", val );
991 val.b_bool = VLC_TRUE;
992 var_Set( p_sys->p_input, "next-chapter", val );
997 if( p_intf->p_sys->p_playlist )
999 playlist_Prev( p_intf->p_sys->p_playlist );
1005 if( p_intf->p_sys->p_playlist )
1007 playlist_Next( p_intf->p_sys->p_playlist );
1013 aout_VolumeUp( p_intf, 1, NULL );
1018 aout_VolumeDown( p_intf, 1, NULL );
1023 * ^l should clear and redraw the screen
1034 static void ManageSlider( intf_thread_t *p_intf )
1036 intf_sys_t *p_sys = p_intf->p_sys;
1037 input_thread_t *p_input = p_sys->p_input;
1040 if( p_input == NULL )
1044 var_Get( p_input, "state", &val );
1045 if( val.i_int != PLAYING_S )
1050 var_Get( p_input, "position", &val );
1051 if( p_sys->f_slider == p_sys->f_slider_old )
1054 p_sys->f_slider_old = 100 * val.f_float;
1058 p_sys->f_slider_old = p_sys->f_slider;
1060 val.f_float = p_sys->f_slider / 100.0;
1061 var_Set( p_input, "position", val );
1065 static void SearchPlaylist( intf_thread_t *p_intf, char *psz_searchstring )
1070 intf_sys_t *p_sys = p_intf->p_sys;
1072 if( p_sys->i_before_search >= 0 )
1074 i_first = p_sys->i_before_search;
1077 if( ( ! psz_searchstring ) || strlen( psz_searchstring ) <= 0 )
1079 p_sys->i_box_plidx = p_sys->i_before_search;
1083 i_max = p_sys->i_plist_entries;
1085 i_item = SubSearchPlaylist( p_intf, psz_searchstring, i_first + 1, i_max );
1088 i_item = SubSearchPlaylist( p_intf, psz_searchstring, 0, i_first );
1091 if( i_item < 0 || i_item >= i_max ) return;
1093 p_sys->i_box_plidx = i_item;
1096 static int SubSearchPlaylist( intf_thread_t *p_intf, char *psz_searchstring,
1097 int i_start, int i_stop )
1099 intf_sys_t *p_sys = p_intf->p_sys;
1102 for( i = i_start + 1; i < i_stop; i++ )
1104 if( strcasestr( p_sys->pp_plist[i]->psz_display,
1105 psz_searchstring ) != NULL )
1116 static void mvnprintw( int y, int x, int w, const char *p_fmt, ... )
1122 va_start( vl_args, p_fmt );
1123 vasprintf( &p_buf, p_fmt, vl_args );
1132 if( ( i_len = strlen( p_buf ) ) > w )
1135 int i_cut = i_len - w;
1136 int x1 = i_len/2 - i_cut/2;
1137 int x2 = x1 + i_cut;
1141 memmove( &p_buf[x1], &p_buf[x2], i_len - x2 );
1150 psz_local = ToLocale( p_buf );
1151 mvprintw( y, x, "%s", psz_local );
1152 LocaleFree( p_buf );
1156 char *psz_local = ToLocale( p_buf );
1157 mvprintw( y, x, "%s", psz_local );
1158 LocaleFree( p_buf );
1159 mvhline( y, x + i_len, ' ', w - i_len );
1163 static void MainBoxWrite( intf_thread_t *p_intf, int l, int x, const char *p_fmt, ... )
1165 intf_sys_t *p_sys = p_intf->p_sys;
1170 if( l < p_sys->i_box_start || l - p_sys->i_box_start >= p_sys->i_box_lines )
1175 va_start( vl_args, p_fmt );
1176 vasprintf( &p_buf, p_fmt, vl_args );
1184 mvnprintw( p_sys->i_box_y + l - p_sys->i_box_start, x, COLS - x - 1, "%s", p_buf );
1187 static void Redraw( intf_thread_t *p_intf, time_t *t_last_refresh )
1189 intf_sys_t *p_sys = p_intf->p_sys;
1190 input_thread_t *p_input = p_sys->p_input;
1198 attrset( A_REVERSE );
1199 mvnprintw( y, 0, COLS, "VLC media player" " (ncurses interface) [ h for help ]" );
1200 attroff( A_REVERSE );
1204 if( p_input && !p_input->b_dead )
1206 char buf1[MSTRTIME_MAX_SIZE];
1207 char buf2[MSTRTIME_MAX_SIZE];
1209 vlc_value_t val_list;
1212 mvnprintw( y++, 0, COLS, " Source : %s",
1213 input_GetItem(p_input)->psz_uri );
1216 var_Get( p_input, "state", &val );
1217 if( val.i_int == PLAYING_S )
1219 mvnprintw( y++, 0, COLS, " State : Playing" );
1221 else if( val.i_int == OPENING_S )
1223 mvnprintw( y++, 0, COLS, " State : Openning/Connecting" );
1225 else if( val.i_int == BUFFERING_S )
1227 mvnprintw( y++, 0, COLS, " State : Buffering" );
1229 else if( val.i_int == PAUSE_S )
1231 mvnprintw( y++, 0, COLS, " State : Paused" );
1237 if( val.i_int != INIT_S && val.i_int != END_S )
1239 audio_volume_t i_volume;
1242 var_Get( p_input, "time", &val );
1243 msecstotimestr( buf1, val.i_time / 1000 );
1245 var_Get( p_input, "length", &val );
1246 msecstotimestr( buf2, val.i_time / 1000 );
1248 mvnprintw( y++, 0, COLS, " Position : %s/%s (%.2f%%)", buf1, buf2, p_sys->f_slider );
1251 aout_VolumeGet( p_intf, &i_volume );
1252 mvnprintw( y++, 0, COLS, " Volume : %i%%", i_volume*200/AOUT_VOLUME_MAX );
1255 if( !var_Get( p_input, "title", &val ) )
1257 var_Change( p_input, "title", VLC_VAR_GETCHOICES, &val_list, NULL );
1258 if( val_list.p_list->i_count > 0 )
1260 mvnprintw( y++, 0, COLS, " Title : %d/%d", val.i_int, val_list.p_list->i_count );
1262 var_Change( p_input, "title", VLC_VAR_FREELIST, &val_list, NULL );
1266 if( !var_Get( p_input, "chapter", &val ) )
1268 var_Change( p_input, "chapter", VLC_VAR_GETCHOICES, &val_list, NULL );
1269 if( val_list.p_list->i_count > 0 )
1271 mvnprintw( y++, 0, COLS, " Chapter : %d/%d", val.i_int, val_list.p_list->i_count );
1273 var_Change( p_input, "chapter", VLC_VAR_FREELIST, &val_list, NULL );
1283 mvnprintw( y++, 0, COLS, "Source: <no current item>" );
1284 DrawEmptyLine( p_sys->w, y++, 0, COLS );
1285 DrawEmptyLine( p_sys->w, y++, 0, COLS );
1286 DrawEmptyLine( p_sys->w, y++, 0, COLS );
1289 DrawBox( p_sys->w, y, 0, 3, COLS, "" );
1290 DrawEmptyLine( p_sys->w, y+1, 1, COLS-2);
1291 DrawLine( p_sys->w, y+1, 1, (int)(p_intf->p_sys->f_slider/100.0 * (COLS -2)) );
1294 p_sys->i_box_y = y + 1;
1295 p_sys->i_box_lines = LINES - y - 2;
1300 if( p_sys->i_box_type == BOX_HELP )
1304 DrawBox( p_sys->w, y++, 0, h, COLS, " Help " );
1306 MainBoxWrite( p_intf, l++, 1, "[Display]" );
1307 MainBoxWrite( p_intf, l++, 1, " h,H Show/Hide help box" );
1308 MainBoxWrite( p_intf, l++, 1, " i Show/Hide info box" );
1309 MainBoxWrite( p_intf, l++, 1, " L Show/Hide messages box" );
1310 MainBoxWrite( p_intf, l++, 1, " P Show/Hide playlist box" );
1311 MainBoxWrite( p_intf, l++, 1, " B Show/Hide filebrowser" );
1312 MainBoxWrite( p_intf, l++, 1, "" );
1314 MainBoxWrite( p_intf, l++, 1, "[Global]" );
1315 MainBoxWrite( p_intf, l++, 1, " q, Q Quit" );
1316 MainBoxWrite( p_intf, l++, 1, " s Stop" );
1317 MainBoxWrite( p_intf, l++, 1, " <space> Pause/Play" );
1318 MainBoxWrite( p_intf, l++, 1, " f Toggle Fullscreen" );
1319 MainBoxWrite( p_intf, l++, 1, " n, p Next/Previous playlist item" );
1320 MainBoxWrite( p_intf, l++, 1, " [, ] Next/Previous title" );
1321 MainBoxWrite( p_intf, l++, 1, " <, > Next/Previous chapter" );
1322 MainBoxWrite( p_intf, l++, 1, " <right> Seek +1%%" );
1323 MainBoxWrite( p_intf, l++, 1, " <left> Seek -1%%" );
1324 MainBoxWrite( p_intf, l++, 1, " a Volume Up" );
1325 MainBoxWrite( p_intf, l++, 1, " z Volume Down" );
1326 MainBoxWrite( p_intf, l++, 1, "" );
1328 MainBoxWrite( p_intf, l++, 1, "[Playlist]" );
1329 MainBoxWrite( p_intf, l++, 1, " r Random" );
1330 MainBoxWrite( p_intf, l++, 1, " l Loop Playlist" );
1331 MainBoxWrite( p_intf, l++, 1, " R Repeat item" );
1332 MainBoxWrite( p_intf, l++, 1, " o Order Playlist by title" );
1333 MainBoxWrite( p_intf, l++, 1, " O Reverse order Playlist by title" );
1334 MainBoxWrite( p_intf, l++, 1, " / Look for an item" );
1335 MainBoxWrite( p_intf, l++, 1, " A Add an entry" );
1336 MainBoxWrite( p_intf, l++, 1, " D, <del> Delete an entry" );
1337 MainBoxWrite( p_intf, l++, 1, " <backspace> Delete an entry" );
1338 MainBoxWrite( p_intf, l++, 1, "" );
1340 MainBoxWrite( p_intf, l++, 1, "[Filebrowser]" );
1341 MainBoxWrite( p_intf, l++, 1, " <enter> Add the selected file to the playlist" );
1342 MainBoxWrite( p_intf, l++, 1, " <space> Add the selected directory to the playlist" );
1343 MainBoxWrite( p_intf, l++, 1, " . Show/Hide hidden files" );
1344 MainBoxWrite( p_intf, l++, 1, "" );
1346 MainBoxWrite( p_intf, l++, 1, "[Boxes]" );
1347 MainBoxWrite( p_intf, l++, 1, " <up>,<down> Navigate through the box line by line" );
1348 MainBoxWrite( p_intf, l++, 1, " <pgup>,<pgdown> Navigate through the box page by page" );
1349 MainBoxWrite( p_intf, l++, 1, "" );
1351 MainBoxWrite( p_intf, l++, 1, "[Player]" );
1352 MainBoxWrite( p_intf, l++, 1, " <up>,<down> Seek +/-5%%" );
1353 MainBoxWrite( p_intf, l++, 1, "" );
1355 MainBoxWrite( p_intf, l++, 1, "[Miscellaneous]" );
1356 MainBoxWrite( p_intf, l++, 1, " Ctrl-l Refresh the screen" );
1358 p_sys->i_box_lines_total = l;
1359 if( p_sys->i_box_start >= p_sys->i_box_lines_total )
1361 p_sys->i_box_start = p_sys->i_box_lines_total - 1;
1364 if( l - p_sys->i_box_start < p_sys->i_box_lines )
1366 y += l - p_sys->i_box_start;
1370 y += p_sys->i_box_lines;
1373 else if( p_sys->i_box_type == BOX_INFO )
1377 DrawBox( p_sys->w, y++, 0, h, COLS, " Information " );
1382 vlc_mutex_lock( &input_GetItem(p_input)->lock );
1383 for( i = 0; i < input_GetItem(p_input)->i_categories; i++ )
1385 info_category_t *p_category = input_GetItem(p_input)->pp_categories[i];
1386 if( y >= y_end ) break;
1387 MainBoxWrite( p_intf, l++, 1, " [%s]", p_category->psz_name );
1388 for( j = 0; j < p_category->i_infos; j++ )
1390 info_t *p_info = p_category->pp_infos[j];
1391 if( y >= y_end ) break;
1392 MainBoxWrite( p_intf, l++, 1, " %s: %s", p_info->psz_name, p_info->psz_value );
1395 vlc_mutex_unlock( &input_GetItem(p_input)->lock );
1399 MainBoxWrite( p_intf, l++, 1, "No item currently playing" );
1401 p_sys->i_box_lines_total = l;
1402 if( p_sys->i_box_start >= p_sys->i_box_lines_total )
1404 p_sys->i_box_start = p_sys->i_box_lines_total - 1;
1407 if( l - p_sys->i_box_start < p_sys->i_box_lines )
1409 y += l - p_sys->i_box_start;
1413 y += p_sys->i_box_lines;
1416 else if( p_sys->i_box_type == BOX_LOG )
1422 DrawBox( p_sys->w, y++, 0, h, COLS, " Logs " );
1424 i_start = p_intf->p_sys->p_sub->i_start;
1426 vlc_mutex_lock( p_intf->p_sys->p_sub->p_lock );
1427 i_stop = *p_intf->p_sys->p_sub->pi_stop;
1428 vlc_mutex_unlock( p_intf->p_sys->p_sub->p_lock );
1432 static const char *ppsz_type[4] = { "", "error", "warning", "debug" };
1433 if( i_line >= h - 2 )
1439 if( i_stop < 0 ) i_stop += VLC_MSG_QSIZE;
1440 if( i_stop == i_start )
1444 mvnprintw( y + h-2-i_line, 1, COLS - 2, " [%s] %s",
1445 ppsz_type[p_sys->p_sub->p_msg[i_stop].i_type],
1446 p_sys->p_sub->p_msg[i_stop].psz_msg );
1449 vlc_mutex_lock( p_intf->p_sys->p_sub->p_lock );
1450 p_intf->p_sys->p_sub->i_start = i_stop;
1451 vlc_mutex_unlock( p_intf->p_sys->p_sub->p_lock );
1454 else if( p_sys->i_box_type == BOX_BROWSE )
1456 /* Filebrowser box */
1457 int i_start, i_stop;
1459 DrawBox( p_sys->w, y++, 0, h, COLS, " Browse " );
1461 if( p_sys->i_box_bidx >= p_sys->i_dir_entries ) p_sys->i_box_plidx = p_sys->i_dir_entries - 1;
1462 if( p_sys->i_box_bidx < 0 ) p_sys->i_box_bidx = 0;
1464 if( p_sys->i_box_bidx < (h - 2)/2 )
1469 else if( p_sys->i_dir_entries - p_sys->i_box_bidx > (h - 2)/2 )
1471 i_start = p_sys->i_box_bidx - (h - 2)/2;
1472 i_stop = i_start + h - 2;
1476 i_stop = p_sys->i_dir_entries;
1477 i_start = p_sys->i_dir_entries - (h - 2);
1483 if( i_stop > p_sys->i_dir_entries )
1485 i_stop = p_sys->i_dir_entries;
1488 for( i_item = i_start; i_item < i_stop; i_item++ )
1490 vlc_bool_t b_selected = ( p_sys->i_box_bidx == i_item );
1492 if( y >= y_end ) break;
1495 attrset( A_REVERSE );
1497 mvnprintw( y++, 1, COLS - 2, " %c %s", p_sys->pp_dir_entries[i_item]->b_file == VLC_TRUE ? ' ' : '+',
1498 p_sys->pp_dir_entries[i_item]->psz_path );
1501 attroff( A_REVERSE );
1506 else if( ( p_sys->i_box_type == BOX_PLAYLIST ||
1507 p_sys->i_box_type == BOX_SEARCH ||
1508 p_sys->i_box_type == BOX_OPEN ) && p_sys->p_playlist )
1511 int i_start, i_stop, i_max = p_sys->i_plist_entries;
1515 switch( p_sys->i_current_view )
1518 psz_title = strdup( " Playlist (All, one level) " );
1521 psz_title = strdup( " Playlist (By category) " );
1524 psz_title = strdup( " Playlist (Manually added) " );
1527 DrawBox( p_sys->w, y++, 0, h, COLS, psz_title );
1529 if( p_sys->b_need_update || p_sys->pp_plist == NULL )
1531 PlaylistRebuild( p_intf );
1533 if( p_sys->b_box_plidx_follow )
1535 FindIndex( p_intf );
1538 if( p_sys->i_box_plidx < 0 ) p_sys->i_box_plidx = 0;
1539 if( p_sys->i_box_plidx < 0 ) p_sys->i_box_plidx = 0;
1540 if( p_sys->i_box_plidx >= i_max ) p_sys->i_box_plidx = i_max - 1;
1542 if( p_sys->i_box_plidx < (h - 2)/2 )
1547 else if( i_max - p_sys->i_box_plidx > (h - 2)/2 )
1549 i_start = p_sys->i_box_plidx - (h - 2)/2;
1550 i_stop = i_start + h - 2;
1555 i_start = i_max - (h - 2);
1561 if( i_stop > i_max )
1566 for( i_item = i_start; i_item < i_stop; i_item++ )
1568 vlc_bool_t b_selected = ( p_sys->i_box_plidx == i_item );
1569 int c = ( PlaylistIsPlaying( p_intf,
1570 p_sys->pp_plist[i_item]->p_item ) ) ? '>' : ' ';
1572 if( y >= y_end ) break;
1575 attrset( A_REVERSE );
1577 mvnprintw( y++, 1, COLS - 2, "%c%s", c,
1578 p_sys->pp_plist[i_item]->psz_display );
1581 attroff( A_REVERSE );
1590 if( p_sys->i_box_type == BOX_SEARCH )
1592 DrawEmptyLine( p_sys->w, 7, 1, COLS-2 );
1593 if( p_sys->psz_search_chain )
1595 if( strlen( p_sys->psz_search_chain ) == 0 &&
1596 p_sys->psz_old_search != NULL )
1598 /* Searching next entry */
1599 mvnprintw( 7, 1, COLS-2, "Find: %s", p_sys->psz_old_search );
1603 mvnprintw( 7, 1, COLS-2, "Find: %s", p_sys->psz_search_chain );
1607 if( p_sys->i_box_type == BOX_OPEN )
1609 if( p_sys->psz_open_chain )
1611 DrawEmptyLine( p_sys->w, 7, 1, COLS-2 );
1612 mvnprintw( 7, 1, COLS-2, "Open: %s", p_sys->psz_open_chain );
1618 DrawEmptyLine( p_sys->w, y++, 1, COLS - 2 );
1623 *t_last_refresh = time( 0 );
1626 static playlist_item_t *PlaylistGetRoot( intf_thread_t *p_intf )
1628 intf_sys_t *p_sys = p_intf->p_sys;
1629 playlist_t *p_playlist = p_sys->p_playlist;
1631 if( p_playlist == NULL )
1636 switch( p_sys->i_current_view )
1639 return p_playlist->p_root_category;
1641 return p_playlist->p_root_onelevel;
1645 static void PlaylistRebuild( intf_thread_t *p_intf )
1647 intf_sys_t *p_sys = p_intf->p_sys;
1648 playlist_t *p_playlist = p_sys->p_playlist;
1650 if( p_playlist == NULL )
1655 vlc_mutex_lock( &p_playlist->object_lock );
1657 /* First clear the old one */
1658 PlaylistDestroy( p_intf );
1660 /* Build the new one */
1661 PlaylistAddNode( p_intf, PlaylistGetRoot( p_intf ), 0, "" );
1663 p_sys->b_need_update = VLC_FALSE;
1665 vlc_mutex_unlock( &p_playlist->object_lock );
1668 static void PlaylistAddNode( intf_thread_t *p_intf, playlist_item_t *p_node,
1669 int i, const char *c )
1671 intf_sys_t *p_sys = p_intf->p_sys;
1672 playlist_item_t *p_child;
1676 psz_tmp = (char *)malloc( strlen( c ) + 4 );
1677 if( psz_tmp == NULL ) return;
1678 for( k = 0; k < p_node->i_children; k++ )
1680 struct pl_item_t *p_pl_item;
1684 p_child = p_node->pp_children[k];
1685 i_size = strlen( c ) + strlen( p_child->p_input->psz_name ) + 4;
1686 buff = (char *)malloc( sizeof( char ) * i_size );
1687 p_pl_item = (struct pl_item_t *)malloc( sizeof( struct pl_item_t ) );
1688 if( p_pl_item == NULL || buff == NULL ) return;
1692 sprintf( buff, "%s%c-%s", c, k == p_node->i_children - 1 ?
1693 '`' : '|', p_child->p_input->psz_name );
1697 sprintf( buff, " %s", p_child->p_input->psz_name );
1699 p_pl_item->psz_display = strdup( buff );
1700 p_pl_item->p_item = p_child;
1701 INSERT_ELEM( p_sys->pp_plist, p_sys->i_plist_entries,
1702 p_sys->i_plist_entries, p_pl_item );
1706 if( p_child->i_children > 0 )
1708 sprintf( psz_tmp, "%s%c ", c,
1709 k == p_node->i_children - 1 ? ' ' : '|' );
1710 PlaylistAddNode( p_intf, p_child, i,
1711 strlen( c ) ? psz_tmp : " " );
1717 static int PlaylistChanged( vlc_object_t *p_this, const char *psz_variable,
1718 vlc_value_t oval, vlc_value_t nval, void *param )
1720 intf_thread_t *p_intf = (intf_thread_t *)param;
1721 p_intf->p_sys->b_need_update = VLC_TRUE;
1726 static inline vlc_bool_t PlaylistIsPlaying( intf_thread_t *p_intf,
1727 playlist_item_t *p_item )
1729 playlist_item_t *p_played_item = p_intf->p_sys->p_playlist->status.p_item;
1730 return( p_item != NULL && p_played_item != NULL &&
1731 p_item->p_input != NULL && p_played_item->p_input != NULL &&
1732 p_item->p_input->i_id == p_played_item->p_input->i_id );
1735 static void FindIndex( intf_thread_t *p_intf )
1737 intf_sys_t *p_sys = p_intf->p_sys;
1740 if( p_sys->i_box_plidx < p_sys->i_plist_entries &&
1741 p_sys->i_box_plidx >= 0 &&
1742 PlaylistIsPlaying( p_intf,
1743 p_sys->pp_plist[p_sys->i_box_plidx]->p_item ) )
1748 for( i = 0; i < p_sys->i_plist_entries; i++ )
1750 if( PlaylistIsPlaying( p_intf, p_sys->pp_plist[i]->p_item ) )
1752 p_sys->i_box_plidx = i;
1758 static void PlaylistDestroy( intf_thread_t *p_intf )
1760 intf_sys_t *p_sys = p_intf->p_sys;
1763 for( i = 0; i < p_sys->i_plist_entries; i++ )
1765 struct pl_item_t *p_pl_item = p_sys->pp_plist[i];
1766 free( p_pl_item->psz_display );
1767 REMOVE_ELEM( p_sys->pp_plist, p_sys->i_plist_entries, i );
1770 p_sys->pp_plist = NULL;
1771 p_sys->i_plist_entries = 0;
1774 static void Eject( intf_thread_t *p_intf )
1776 char *psz_device = NULL, *psz_parser, *psz_name;
1779 * Get the active input
1780 * Determine whether we can eject a media, ie it's a DVD, VCD or CD-DA
1781 * If it's neither of these, then return
1784 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1787 if( p_playlist == NULL )
1792 vlc_mutex_lock( &p_playlist->object_lock );
1794 if( p_playlist->status.p_item == NULL )
1796 vlc_mutex_unlock( &p_playlist->object_lock );
1797 vlc_object_release( p_playlist );
1801 psz_name = p_playlist->status.p_item->p_input->psz_name;
1805 if( !strncmp(psz_name, "dvd://", 4) )
1807 switch( psz_name[strlen("dvd://")] )
1811 psz_device = config_GetPsz( p_intf, "dvd" );
1814 /* Omit the first MRL-selector characters */
1815 psz_device = strdup( psz_name + strlen("dvd://" ) );
1819 else if( !strncmp(psz_name, VCD_MRL, strlen(VCD_MRL)) )
1821 switch( psz_name[strlen(VCD_MRL)] )
1825 psz_device = config_GetPsz( p_intf, VCD_MRL );
1828 /* Omit the beginning MRL-selector characters */
1829 psz_device = strdup( psz_name + strlen(VCD_MRL) );
1833 else if( !strncmp(psz_name, CDDA_MRL, strlen(CDDA_MRL) ) )
1835 switch( psz_name[strlen(CDDA_MRL)] )
1839 psz_device = config_GetPsz( p_intf, "cd-audio" );
1842 /* Omit the beginning MRL-selector characters */
1843 psz_device = strdup( psz_name + strlen(CDDA_MRL) );
1849 psz_device = strdup( psz_name );
1853 vlc_mutex_unlock( &p_playlist->object_lock );
1854 vlc_object_release( p_playlist );
1856 if( psz_device == NULL )
1861 /* Remove what we have after @ */
1862 psz_parser = psz_device;
1863 for( psz_parser = psz_device ; *psz_parser ; psz_parser++ )
1865 if( *psz_parser == '@' )
1872 /* If there's a stream playing, we aren't allowed to eject ! */
1873 if( p_intf->p_sys->p_input == NULL )
1875 msg_Dbg( p_intf, "ejecting %s", psz_device );
1877 intf_Eject( p_intf, psz_device );
1884 static int comp_dir_entries( const void *pp_dir_entry1,
1885 const void *pp_dir_entry2 )
1887 struct dir_entry_t *p_dir_entry1 = *(struct dir_entry_t**)pp_dir_entry1;
1888 struct dir_entry_t *p_dir_entry2 = *(struct dir_entry_t**)pp_dir_entry2;
1889 if ( p_dir_entry1->b_file == p_dir_entry2->b_file ) {
1890 return strcasecmp( p_dir_entry1->psz_path, p_dir_entry2->psz_path );
1894 return ( p_dir_entry1->b_file ? 1 : -1 );
1898 static void ReadDir( intf_thread_t *p_intf )
1900 intf_sys_t *p_sys = p_intf->p_sys;
1904 if( p_sys->psz_current_dir && *p_sys->psz_current_dir )
1909 p_current_dir = utf8_opendir( p_sys->psz_current_dir );
1911 if( p_current_dir == NULL )
1913 /* something went bad, get out of here ! */
1915 msg_Warn( p_intf, "cannot open directory `%s' (%s)",
1916 p_sys->psz_current_dir, strerror(errno));
1918 msg_Warn( p_intf, "cannot open directory `%s'", p_sys->psz_current_dir );
1923 /* Clean the old shit */
1924 for( i = 0; i < p_sys->i_dir_entries; i++ )
1926 struct dir_entry_t *p_dir_entry = p_sys->pp_dir_entries[i];
1927 free( p_dir_entry->psz_path );
1928 REMOVE_ELEM( p_sys->pp_dir_entries, p_sys->i_dir_entries, i );
1929 free( p_dir_entry );
1931 p_sys->pp_dir_entries = NULL;
1932 p_sys->i_dir_entries = 0;
1934 /* get the first directory entry */
1935 psz_entry = utf8_readdir( p_current_dir );
1937 /* while we still have entries in the directory */
1938 while( psz_entry != NULL )
1940 #if defined( S_ISDIR )
1941 struct stat stat_data;
1943 struct dir_entry_t *p_dir_entry;
1944 int i_size_entry = strlen( p_sys->psz_current_dir ) +
1945 strlen( psz_entry ) + 2;
1948 if( p_sys->b_show_hidden_files == VLC_FALSE &&
1949 ( strlen( psz_entry ) && psz_entry[0] == '.' ) &&
1950 strcmp( psz_entry, ".." ) )
1953 psz_entry = utf8_readdir( p_current_dir );
1957 psz_uri = (char *)malloc( sizeof(char)*i_size_entry);
1958 sprintf( psz_uri, "%s/%s", p_sys->psz_current_dir, psz_entry );
1960 if( !( p_dir_entry = malloc( sizeof( struct dir_entry_t) ) ) )
1966 #if defined( S_ISDIR )
1967 utf8_stat( psz_uri, &stat_data );
1968 if( S_ISDIR(stat_data.st_mode) )
1969 /*#elif defined( DT_DIR )
1970 if( p_dir_content->d_type & DT_DIR )*/
1975 p_dir_entry->psz_path = strdup( psz_entry );
1976 p_dir_entry->b_file = VLC_FALSE;
1977 INSERT_ELEM( p_sys->pp_dir_entries, p_sys->i_dir_entries,
1978 p_sys->i_dir_entries, p_dir_entry );
1982 p_dir_entry->psz_path = strdup( psz_entry );
1983 p_dir_entry->b_file = VLC_TRUE;
1984 INSERT_ELEM( p_sys->pp_dir_entries, p_sys->i_dir_entries,
1985 p_sys->i_dir_entries, p_dir_entry );
1990 /* Read next entry */
1991 psz_entry = utf8_readdir( p_current_dir );
1995 qsort( p_sys->pp_dir_entries, p_sys->i_dir_entries,
1996 sizeof(struct dir_entry_t*), &comp_dir_entries );
1998 closedir( p_current_dir );
2003 msg_Dbg( p_intf, "no current dir set" );
2008 static void PlayPause( intf_thread_t *p_intf )
2010 input_thread_t *p_input = p_intf->p_sys->p_input;
2015 var_Get( p_input, "state", &val );
2016 if( val.i_int != PAUSE_S )
2018 val.i_int = PAUSE_S;
2022 val.i_int = PLAYING_S;
2024 var_Set( p_input, "state", val );
2026 else if( p_intf->p_sys->p_playlist )
2028 playlist_Play( p_intf->p_sys->p_playlist );
2032 /****************************************************************************
2034 ****************************************************************************/
2035 static void DrawBox( WINDOW *win, int y, int x, int h, int w, const char *title )
2040 if( w > 3 && h > 2 )
2042 if( title == NULL ) title = "";
2043 i_len = strlen( title );
2045 if( i_len > w - 2 ) i_len = w - 2;
2047 mvwaddch( win, y, x, ACS_ULCORNER );
2048 mvwhline( win, y, x+1, ACS_HLINE, ( w-i_len-2)/2 );
2049 mvwprintw( win,y, x+1+(w-i_len-2)/2, "%s", title );
2050 mvwhline( win, y, x+(w-i_len)/2+i_len, ACS_HLINE, w - 1 - ((w-i_len)/2+i_len) );
2051 mvwaddch( win, y, x+w-1,ACS_URCORNER );
2053 for( i = 0; i < h-2; i++ )
2055 mvwaddch( win, y+i+1, x, ACS_VLINE );
2056 mvwaddch( win, y+i+1, x+w-1, ACS_VLINE );
2059 mvwaddch( win, y+h-1, x, ACS_LLCORNER );
2060 mvwhline( win, y+h-1, x+1, ACS_HLINE, w - 2 );
2061 mvwaddch( win, y+h-1, x+w-1, ACS_LRCORNER );
2065 static void DrawEmptyLine( WINDOW *win, int y, int x, int w )
2069 mvhline( y, x, ' ', w );
2073 static void DrawLine( WINDOW *win, int y, int x, int w )
2077 attrset( A_REVERSE );
2078 mvhline( y, x, ' ', w );
2079 attroff( A_REVERSE );