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 *****************************************************************************/
30 #include <stdlib.h> /* malloc(), free() */
32 #include <errno.h> /* ENOMEM */
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, 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 */
187 static void DrawBox( WINDOW *win, int y, int x, int h, int w, const char *title );
188 static void DrawLine( WINDOW *win, int y, int x, int w );
189 static void DrawEmptyLine( WINDOW *win, int y, int x, int w );
191 /*****************************************************************************
192 * Open: initialize and create window
193 *****************************************************************************/
194 static int Open( vlc_object_t *p_this )
196 intf_thread_t *p_intf = (intf_thread_t *)p_this;
200 /* Allocate instance and initialize some members */
201 p_sys = p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
202 p_sys->p_playlist = NULL;
203 p_sys->p_input = NULL;
204 p_sys->f_slider = 0.0;
205 p_sys->f_slider_old = 0.0;
206 p_sys->i_box_type = BOX_PLAYLIST;
207 p_sys->i_box_lines = 0;
208 p_sys->i_box_start= 0;
209 p_sys->i_box_lines_total = 0;
210 p_sys->b_box_plidx_follow = VLC_TRUE;
211 p_sys->b_box_cleared = VLC_FALSE;
212 p_sys->i_box_plidx = 0;
213 p_sys->p_plnode = NULL;
214 p_sys->i_box_bidx = 0;
215 p_sys->p_sub = msg_Subscribe( p_intf, MSG_QUEUE_NORMAL );
216 memset( p_sys->psz_partial_keys, 0, sizeof( p_sys->psz_partial_keys ) );
218 /* Initialize the curses library */
219 p_sys->w = initscr();
220 keypad( p_sys->w, TRUE );
221 /* Don't do NL -> CR/NL */
223 /* Take input chars one at a time */
233 /* exported function */
234 p_intf->pf_run = Run;
238 var_Set( p_intf->p_vlc, "verbose", val );
240 /* Set defaul playlist view */
241 p_sys->i_current_view = VIEW_CATEGORY;
242 p_sys->pp_plist = NULL;
243 p_sys->i_plist_entries = 0;
244 p_sys->b_need_update = VLC_FALSE;
246 /* Initialize search chain */
247 p_sys->psz_search_chain = (char *)malloc( SEARCH_CHAIN_SIZE + 1 );
248 p_sys->psz_old_search = NULL;
249 p_sys->i_before_search = 0;
251 /* Initialize open chain */
252 p_sys->psz_open_chain = (char *)malloc( OPEN_CHAIN_SIZE + 1 );
254 /* Initialize browser options */
255 var_Create( p_intf, "browse-dir", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
256 var_Get( p_intf, "browse-dir", &val);
258 if( val.psz_string && *val.psz_string )
260 p_sys->psz_current_dir = strdup( val.psz_string );
261 free( val.psz_string );
265 p_sys->psz_current_dir = strdup( p_intf->p_vlc->psz_homedir );
268 p_sys->i_dir_entries = 0;
269 p_sys->pp_dir_entries = NULL;
270 p_sys->b_show_hidden_files = VLC_FALSE;
276 /*****************************************************************************
277 * Close: destroy interface window
278 *****************************************************************************/
279 static void Close( vlc_object_t *p_this )
281 intf_thread_t *p_intf = (intf_thread_t *)p_this;
282 intf_sys_t *p_sys = p_intf->p_sys;
285 var_DelCallback( p_sys->p_playlist, "intf-change", PlaylistChanged,
287 var_DelCallback( p_sys->p_playlist, "item-append", PlaylistChanged,
290 PlaylistDestroy( p_intf );
292 for( i = 0; i < p_sys->i_dir_entries; i++ )
294 struct dir_entry_t *p_dir_entry = p_sys->pp_dir_entries[i];
295 if( p_dir_entry->psz_path ) free( p_dir_entry->psz_path );
296 REMOVE_ELEM( p_sys->pp_dir_entries, p_sys->i_dir_entries, i );
297 if( p_dir_entry ) free( p_dir_entry );
299 p_sys->pp_dir_entries = NULL;
301 if( p_sys->psz_current_dir ) free( p_sys->psz_current_dir );
302 if( p_sys->psz_search_chain ) free( p_sys->psz_search_chain );
303 if( p_sys->psz_old_search ) free( p_sys->psz_old_search );
304 if( p_sys->psz_open_chain ) free( p_sys->psz_open_chain );
308 vlc_object_release( p_sys->p_input );
310 if( p_sys->p_playlist )
312 vlc_object_release( p_sys->p_playlist );
315 /* Close the ncurses interface */
318 msg_Unsubscribe( p_intf, p_sys->p_sub );
320 /* Destroy structure */
324 /*****************************************************************************
325 * Run: ncurses thread
326 *****************************************************************************/
327 static void Run( intf_thread_t *p_intf )
329 intf_sys_t *p_sys = p_intf->p_sys;
332 time_t t_last_refresh;
335 * force drawing the interface for the first time
337 t_last_refresh = ( time( 0 ) - 1);
339 while( !p_intf->b_die )
341 msleep( INTF_IDLE_SLEEP );
343 /* Update the input */
344 if( p_sys->p_playlist == NULL )
346 p_sys->p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
348 if( p_sys->p_playlist )
350 var_AddCallback( p_sys->p_playlist, "intf-change",
351 PlaylistChanged, p_intf );
352 var_AddCallback( p_sys->p_playlist, "item-append",
353 PlaylistChanged, p_intf );
356 if( p_sys->p_playlist )
358 vlc_mutex_lock( &p_sys->p_playlist->object_lock );
359 if( p_sys->p_input == NULL )
361 p_sys->p_input = p_sys->p_playlist->p_input;
364 if( !p_sys->p_input->b_dead )
366 vlc_object_yield( p_sys->p_input );
370 else if( p_sys->p_input->b_dead )
372 vlc_object_release( p_sys->p_input );
373 p_sys->p_input = NULL;
374 p_sys->f_slider = p_sys->f_slider_old = 0.0;
375 p_sys->b_box_cleared = VLC_FALSE;
377 vlc_mutex_unlock( &p_sys->p_playlist->object_lock );
380 if( p_sys->b_box_plidx_follow && p_sys->p_playlist->status.p_item )
385 while( ( i_key = getch() ) != -1 )
388 * HandleKey returns 1 if the screen needs to be redrawn
390 if( HandleKey( p_intf, i_key ) )
392 Redraw( p_intf, &t_last_refresh );
396 if( p_sys->f_slider > 0.0001 && !p_sys->b_box_cleared )
399 Redraw( p_intf, &t_last_refresh );
400 p_sys->b_box_cleared = VLC_TRUE;
404 * redraw the screen every second
406 if( (time(0) - t_last_refresh) >= 1 )
408 ManageSlider( p_intf );
409 Redraw( p_intf, &t_last_refresh );
414 /* following functions are local */
416 static char *KeyToUTF8( int i_key, char *psz_part )
418 char *psz_utf8, *psz;
419 int len = strlen( psz_part );
422 /* overflow error - should not happen */
423 memset( psz_part, 0, 6 );
427 psz_part[len] = (char)i_key;
429 psz_utf8 = FromLocaleDup( psz_part );
431 /* Ugly check for incomplete bytes sequences
432 * (in case of non-UTF8 multibyte local encoding) */
433 for( psz = psz_utf8; *psz; psz++ )
434 if( ( *psz == '?' ) && ( *psz_utf8 != '?' ) )
436 /* incomplete bytes sequence detected
437 * (VLC core inserted dummy question marks) */
442 /* Check for incomplete UTF8 bytes sequence */
443 if( EnsureUTF8( psz_utf8 ) == NULL )
449 memset( psz_part, 0, 6 );
453 static inline int RemoveLastUTF8Entity( char *psz, int len )
455 while( len && ( (psz[--len] & 0xc0) == 0x80 ) );
456 /* UTF8 continuation byte */
462 static int HandleKey( intf_thread_t *p_intf, int i_key )
464 intf_sys_t *p_sys = p_intf->p_sys;
467 if( p_sys->i_box_type == BOX_PLAYLIST && p_sys->p_playlist )
469 int b_ret = VLC_TRUE;
470 vlc_bool_t b_box_plidx_follow = VLC_FALSE;
475 /* Playlist Settings */
477 var_Get( p_sys->p_playlist, "random", &val );
478 val.b_bool = !val.b_bool;
479 var_Set( p_sys->p_playlist, "random", val );
482 var_Get( p_sys->p_playlist, "loop", &val );
483 val.b_bool = !val.b_bool;
484 var_Set( p_sys->p_playlist, "loop", val );
487 var_Get( p_sys->p_playlist, "repeat", &val );
488 val.b_bool = !val.b_bool;
489 var_Set( p_sys->p_playlist, "repeat", val );
494 playlist_RecursiveNodeSort( p_sys->p_playlist,
495 PlaylistGetRoot( p_intf ),
496 SORT_TITLE_NODES_FIRST, ORDER_NORMAL );
497 p_sys->b_need_update = VLC_TRUE;
500 playlist_RecursiveNodeSort( p_sys->p_playlist,
501 PlaylistGetRoot( p_intf ),
502 SORT_TITLE_NODES_FIRST, ORDER_REVERSE );
503 p_sys->b_need_update = VLC_TRUE;
508 switch( p_sys->i_current_view )
511 p_sys->i_current_view = VIEW_ONELEVEL;
514 p_sys->i_current_view = VIEW_CATEGORY;
516 //p_sys->b_need_update = VLC_TRUE;
517 PlaylistRebuild( p_intf );
520 /* Playlist navigation */
522 p_sys->i_box_plidx = 0;
525 p_sys->i_box_plidx = p_sys->p_playlist->i_size - 1;
528 p_sys->i_box_plidx--;
531 p_sys->i_box_plidx++;
534 p_sys->i_box_plidx -= p_sys->i_box_lines;
537 p_sys->i_box_plidx += p_sys->i_box_lines;
543 playlist_t *p_playlist = p_sys->p_playlist;
544 playlist_item_t *p_item;
546 vlc_mutex_lock( &p_playlist->object_lock );
547 p_item = p_sys->pp_plist[p_sys->i_box_plidx]->p_item;
548 if( p_item->i_children == -1 )
550 playlist_DeleteFromItemId( p_playlist, p_item->i_id );
554 playlist_NodeDelete( p_playlist, p_item,
555 VLC_TRUE , VLC_FALSE );
557 vlc_mutex_unlock( &p_playlist->object_lock );
558 p_sys->b_need_update = VLC_TRUE;
565 if( p_sys->pp_plist[p_sys->i_box_plidx]->p_item->i_children
568 playlist_Control( p_sys->p_playlist, PLAYLIST_VIEWPLAY,
570 p_sys->pp_plist[p_sys->i_box_plidx]->p_item );
574 playlist_Control( p_sys->p_playlist, PLAYLIST_VIEWPLAY,
575 p_sys->pp_plist[p_sys->i_box_plidx]->p_item,
578 b_box_plidx_follow = VLC_TRUE;
587 int i_max = p_sys->i_plist_entries;
588 if( p_sys->i_box_plidx >= i_max ) p_sys->i_box_plidx = i_max - 1;
589 if( p_sys->i_box_plidx < 0 ) p_sys->i_box_plidx = 0;
590 if( PlaylistIsPlaying( p_intf,
591 p_sys->pp_plist[p_sys->i_box_plidx]->p_item ) )
592 b_box_plidx_follow = VLC_TRUE;
593 p_sys->b_box_plidx_follow = b_box_plidx_follow;
597 if( p_sys->i_box_type == BOX_BROWSE )
599 vlc_bool_t b_ret = VLC_TRUE;
600 /* Browser navigation */
604 p_sys->i_box_bidx = 0;
607 p_sys->i_box_bidx = p_sys->i_dir_entries - 1;
616 p_sys->i_box_bidx -= p_sys->i_box_lines;
619 p_sys->i_box_bidx += p_sys->i_box_lines;
621 case '.': /* Toggle show hidden files */
622 p_sys->b_show_hidden_files = ( p_sys->b_show_hidden_files ==
623 VLC_TRUE ? VLC_FALSE : VLC_TRUE );
630 if( p_sys->pp_dir_entries[p_sys->i_box_bidx]->b_file || i_key == ' ' )
632 int i_size_entry = strlen( p_sys->psz_current_dir ) +
633 strlen( p_sys->pp_dir_entries[p_sys->i_box_bidx]->psz_path ) + 2;
634 char *psz_uri = (char *)malloc( sizeof(char)*i_size_entry);
636 sprintf( psz_uri, "%s/%s", p_sys->psz_current_dir, p_sys->pp_dir_entries[p_sys->i_box_bidx]->psz_path );
638 playlist_Add( p_sys->p_playlist, psz_uri,
640 PLAYLIST_APPEND, PLAYLIST_END );
642 p_sys->i_box_type = BOX_PLAYLIST;
647 int i_size_entry = strlen( p_sys->psz_current_dir ) +
648 strlen( p_sys->pp_dir_entries[p_sys->i_box_bidx]->psz_path ) + 2;
649 char *psz_uri = (char *)malloc( sizeof(char)*i_size_entry);
651 sprintf( psz_uri, "%s/%s", p_sys->psz_current_dir, p_sys->pp_dir_entries[p_sys->i_box_bidx]->psz_path );
653 p_sys->psz_current_dir = strdup( psz_uri );
664 if( p_sys->i_box_bidx >= p_sys->i_dir_entries ) p_sys->i_box_bidx = p_sys->i_dir_entries - 1;
665 if( p_sys->i_box_bidx < 0 ) p_sys->i_box_bidx = 0;
669 else if( p_sys->i_box_type == BOX_HELP || p_sys->i_box_type == BOX_INFO )
674 p_sys->i_box_start = 0;
677 p_sys->i_box_start = p_sys->i_box_lines_total - 1;
680 if( p_sys->i_box_start > 0 ) p_sys->i_box_start--;
683 if( p_sys->i_box_start < p_sys->i_box_lines_total - 1 )
685 p_sys->i_box_start++;
689 p_sys->i_box_start -= p_sys->i_box_lines;
690 if( p_sys->i_box_start < 0 ) p_sys->i_box_start = 0;
693 p_sys->i_box_start += p_sys->i_box_lines;
694 if( p_sys->i_box_start >= p_sys->i_box_lines_total )
696 p_sys->i_box_start = p_sys->i_box_lines_total - 1;
703 else if( p_sys->i_box_type == BOX_NONE )
709 ManageSlider( p_intf );
712 p_sys->f_slider = 99.9;
713 ManageSlider( p_intf );
716 p_sys->f_slider += 5.0;
717 if( p_sys->f_slider >= 99.0 ) p_sys->f_slider = 99.0;
718 ManageSlider( p_intf );
721 p_sys->f_slider -= 5.0;
722 if( p_sys->f_slider < 0.0 ) p_sys->f_slider = 0.0;
723 ManageSlider( p_intf );
730 else if( p_sys->i_box_type == BOX_SEARCH && p_sys->psz_search_chain )
733 i_chain_len = strlen( p_sys->psz_search_chain );
741 if( i_chain_len > 0 )
743 p_sys->psz_old_search = strdup( p_sys->psz_search_chain );
745 else if( p_sys->psz_old_search )
747 SearchPlaylist( p_intf, p_sys->psz_old_search );
749 p_sys->i_box_type = BOX_PLAYLIST;
751 case 0x1b: /* Esc. */
752 p_sys->i_box_plidx = p_sys->i_before_search;
753 p_sys->i_box_type = BOX_PLAYLIST;
756 RemoveLastUTF8Entity( p_sys->psz_search_chain, i_chain_len );
760 char *psz_utf8 = KeyToUTF8( i_key, p_sys->psz_partial_keys );
762 if( psz_utf8 != NULL )
764 if( i_chain_len + strlen( psz_utf8 ) < SEARCH_CHAIN_SIZE )
766 strcpy( p_sys->psz_search_chain + i_chain_len,
774 if( p_sys->psz_old_search )
776 free( p_sys->psz_old_search );
777 p_sys->psz_old_search = NULL;
779 SearchPlaylist( p_intf, p_sys->psz_search_chain );
782 else if( p_sys->i_box_type == BOX_OPEN && p_sys->psz_open_chain )
784 int i_chain_len = strlen( p_sys->psz_open_chain );
785 playlist_t *p_playlist = p_sys->p_playlist;
794 if( p_playlist && i_chain_len > 0 )
797 playlist_Add( p_playlist, p_sys->psz_open_chain,
798 p_sys->psz_open_chain,
799 PLAYLIST_GO|PLAYLIST_APPEND, PLAYLIST_END );
801 p_sys->b_box_plidx_follow = VLC_TRUE;
803 p_sys->i_box_type = BOX_PLAYLIST;
805 case 0x1b: /* Esc. */
806 p_sys->i_box_type = BOX_PLAYLIST;
809 RemoveLastUTF8Entity( p_sys->psz_open_chain, i_chain_len );
813 char *psz_utf8 = KeyToUTF8( i_key, p_sys->psz_partial_keys );
815 if( psz_utf8 != NULL )
817 if( i_chain_len + strlen( psz_utf8 ) < OPEN_CHAIN_SIZE )
819 strcpy( p_sys->psz_open_chain + i_chain_len,
837 p_intf->p_vlc->b_die = VLC_TRUE;
842 if( p_sys->i_box_type == BOX_INFO )
843 p_sys->i_box_type = BOX_NONE;
845 p_sys->i_box_type = BOX_INFO;
846 p_sys->i_box_lines_total = 0;
849 if( p_sys->i_box_type == BOX_LOG )
850 p_sys->i_box_type = BOX_NONE;
852 p_sys->i_box_type = BOX_LOG;
855 if( p_sys->i_box_type == BOX_PLAYLIST )
856 p_sys->i_box_type = BOX_NONE;
858 p_sys->i_box_type = BOX_PLAYLIST;
861 if( p_sys->i_box_type == BOX_BROWSE )
862 p_sys->i_box_type = BOX_NONE;
864 p_sys->i_box_type = BOX_BROWSE;
868 if( p_sys->i_box_type == BOX_HELP )
869 p_sys->i_box_type = BOX_NONE;
871 p_sys->i_box_type = BOX_HELP;
872 p_sys->i_box_lines_total = 0;
875 if( p_sys->i_box_type != BOX_SEARCH )
877 if( p_sys->psz_search_chain == NULL )
881 p_sys->psz_search_chain[0] = '\0';
882 p_sys->b_box_plidx_follow = VLC_FALSE;
883 p_sys->i_before_search = p_sys->i_box_plidx;
884 p_sys->i_box_type = BOX_SEARCH;
888 if( p_sys->i_box_type != BOX_OPEN )
890 if( p_sys->psz_open_chain == NULL )
894 p_sys->psz_open_chain[0] = '\0';
895 p_sys->i_box_type = BOX_OPEN;
901 p_sys->f_slider += 1.0;
902 if( p_sys->f_slider > 99.9 ) p_sys->f_slider = 99.9;
903 ManageSlider( p_intf );
907 p_sys->f_slider -= 1.0;
908 if( p_sys->f_slider < 0.0 ) p_sys->f_slider = 0.0;
909 ManageSlider( p_intf );
915 if( p_intf->p_sys->p_input )
917 vout_thread_t *p_vout;
918 p_vout = vlc_object_find( p_intf->p_sys->p_input,
919 VLC_OBJECT_VOUT, FIND_CHILD );
922 var_Get( p_vout, "fullscreen", &val );
923 val.b_bool = !val.b_bool;
924 var_Set( p_vout, "fullscreen", val );
925 vlc_object_release( p_vout );
929 playlist_t *p_playlist;
930 p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
934 var_Get( p_playlist, "fullscreen", &val );
935 val.b_bool = !val.b_bool;
936 var_Set( p_playlist, "fullscreen", val );
937 vlc_object_release( p_playlist );
949 if( p_intf->p_sys->p_playlist )
951 playlist_Stop( p_intf->p_sys->p_playlist );
962 val.b_bool = VLC_TRUE;
963 var_Set( p_sys->p_input, "prev-title", val );
970 val.b_bool = VLC_TRUE;
971 var_Set( p_sys->p_input, "next-title", val );
978 val.b_bool = VLC_TRUE;
979 var_Set( p_sys->p_input, "prev-chapter", val );
986 val.b_bool = VLC_TRUE;
987 var_Set( p_sys->p_input, "next-chapter", val );
992 if( p_intf->p_sys->p_playlist )
994 playlist_Prev( p_intf->p_sys->p_playlist );
1000 if( p_intf->p_sys->p_playlist )
1002 playlist_Next( p_intf->p_sys->p_playlist );
1008 aout_VolumeUp( p_intf, 1, NULL );
1013 aout_VolumeDown( p_intf, 1, NULL );
1018 * ^l should clear and redraw the screen
1029 static void ManageSlider( intf_thread_t *p_intf )
1031 intf_sys_t *p_sys = p_intf->p_sys;
1032 input_thread_t *p_input = p_sys->p_input;
1035 if( p_input == NULL )
1039 var_Get( p_input, "state", &val );
1040 if( val.i_int != PLAYING_S )
1045 var_Get( p_input, "position", &val );
1046 if( p_sys->f_slider == p_sys->f_slider_old )
1049 p_sys->f_slider_old = 100 * val.f_float;
1053 p_sys->f_slider_old = p_sys->f_slider;
1055 val.f_float = p_sys->f_slider / 100.0;
1056 var_Set( p_input, "position", val );
1060 static void SearchPlaylist( intf_thread_t *p_intf, char *psz_searchstring )
1065 intf_sys_t *p_sys = p_intf->p_sys;
1067 if( p_sys->i_before_search >= 0 )
1069 i_first = p_sys->i_before_search;
1072 if( ( ! psz_searchstring ) || strlen( psz_searchstring ) <= 0 )
1074 p_sys->i_box_plidx = p_sys->i_before_search;
1078 i_max = p_sys->i_plist_entries;
1080 i_item = SubSearchPlaylist( p_intf, psz_searchstring, i_first + 1, i_max );
1083 i_item = SubSearchPlaylist( p_intf, psz_searchstring, 0, i_first );
1086 if( i_item < 0 || i_item >= i_max ) return;
1088 p_sys->i_box_plidx = i_item;
1091 static int SubSearchPlaylist( intf_thread_t *p_intf, char *psz_searchstring,
1092 int i_start, int i_stop )
1094 intf_sys_t *p_sys = p_intf->p_sys;
1097 for( i = i_start + 1; i < i_stop; i++ )
1099 if( strcasestr( p_sys->pp_plist[i]->psz_display,
1100 psz_searchstring ) != NULL )
1111 static void mvnprintw( int y, int x, int w, const char *p_fmt, ... )
1117 va_start( vl_args, p_fmt );
1118 vasprintf( &p_buf, p_fmt, vl_args );
1127 if( ( i_len = strlen( p_buf ) ) > w )
1130 int i_cut = i_len - w;
1131 int x1 = i_len/2 - i_cut/2;
1132 int x2 = x1 + i_cut;
1136 memmove( &p_buf[x1], &p_buf[x2], i_len - x2 );
1145 psz_local = ToLocale( p_buf );
1146 mvprintw( y, x, "%s", psz_local );
1147 LocaleFree( p_buf );
1151 char *psz_local = ToLocale( p_buf );
1152 mvprintw( y, x, "%s", psz_local );
1153 LocaleFree( p_buf );
1154 mvhline( y, x + i_len, ' ', w - i_len );
1158 static void MainBoxWrite( intf_thread_t *p_intf, int l, int x, const char *p_fmt, ... )
1160 intf_sys_t *p_sys = p_intf->p_sys;
1165 if( l < p_sys->i_box_start || l - p_sys->i_box_start >= p_sys->i_box_lines )
1170 va_start( vl_args, p_fmt );
1171 vasprintf( &p_buf, p_fmt, vl_args );
1179 mvnprintw( p_sys->i_box_y + l - p_sys->i_box_start, x, COLS - x - 1, "%s", p_buf );
1182 static void Redraw( intf_thread_t *p_intf, time_t *t_last_refresh )
1184 intf_sys_t *p_sys = p_intf->p_sys;
1185 input_thread_t *p_input = p_sys->p_input;
1193 attrset( A_REVERSE );
1194 mvnprintw( y, 0, COLS, "VLC media player" " (ncurses interface) [ h for help ]" );
1195 attroff( A_REVERSE );
1199 if( p_input && !p_input->b_dead )
1201 char buf1[MSTRTIME_MAX_SIZE];
1202 char buf2[MSTRTIME_MAX_SIZE];
1204 vlc_value_t val_list;
1207 mvnprintw( y++, 0, COLS, " Source : %s",
1208 p_input->input.p_item->psz_uri );
1211 var_Get( p_input, "state", &val );
1212 if( val.i_int == PLAYING_S )
1214 mvnprintw( y++, 0, COLS, " State : Playing" );
1216 else if( val.i_int == PAUSE_S )
1218 mvnprintw( y++, 0, COLS, " State : Paused" );
1224 if( val.i_int != INIT_S && val.i_int != END_S )
1226 audio_volume_t i_volume;
1229 var_Get( p_input, "time", &val );
1230 msecstotimestr( buf1, val.i_time / 1000 );
1232 var_Get( p_input, "length", &val );
1233 msecstotimestr( buf2, val.i_time / 1000 );
1235 mvnprintw( y++, 0, COLS, " Position : %s/%s (%.2f%%)", buf1, buf2, p_sys->f_slider );
1238 aout_VolumeGet( p_intf, &i_volume );
1239 mvnprintw( y++, 0, COLS, " Volume : %i%%", i_volume*200/AOUT_VOLUME_MAX );
1242 if( !var_Get( p_input, "title", &val ) )
1244 var_Change( p_input, "title", VLC_VAR_GETCHOICES, &val_list, NULL );
1245 if( val_list.p_list->i_count > 0 )
1247 mvnprintw( y++, 0, COLS, " Title : %d/%d", val.i_int, val_list.p_list->i_count );
1249 var_Change( p_input, "title", VLC_VAR_FREELIST, &val_list, NULL );
1253 if( !var_Get( p_input, "chapter", &val ) )
1255 var_Change( p_input, "chapter", VLC_VAR_GETCHOICES, &val_list, NULL );
1256 if( val_list.p_list->i_count > 0 )
1258 mvnprintw( y++, 0, COLS, " Chapter : %d/%d", val.i_int, val_list.p_list->i_count );
1260 var_Change( p_input, "chapter", VLC_VAR_FREELIST, &val_list, NULL );
1270 mvnprintw( y++, 0, COLS, "Source: <no current item>" );
1271 DrawEmptyLine( p_sys->w, y++, 0, COLS );
1272 DrawEmptyLine( p_sys->w, y++, 0, COLS );
1273 DrawEmptyLine( p_sys->w, y++, 0, COLS );
1276 DrawBox( p_sys->w, y, 0, 3, COLS, "" );
1277 DrawEmptyLine( p_sys->w, y+1, 1, COLS-2);
1278 DrawLine( p_sys->w, y+1, 1, (int)(p_intf->p_sys->f_slider/100.0 * (COLS -2)) );
1281 p_sys->i_box_y = y + 1;
1282 p_sys->i_box_lines = LINES - y - 2;
1287 if( p_sys->i_box_type == BOX_HELP )
1291 DrawBox( p_sys->w, y++, 0, h, COLS, " Help " );
1293 MainBoxWrite( p_intf, l++, 1, "[Display]" );
1294 MainBoxWrite( p_intf, l++, 1, " h,H Show/Hide help box" );
1295 MainBoxWrite( p_intf, l++, 1, " i Show/Hide info box" );
1296 MainBoxWrite( p_intf, l++, 1, " L Show/Hide messages box" );
1297 MainBoxWrite( p_intf, l++, 1, " P Show/Hide playlist box" );
1298 MainBoxWrite( p_intf, l++, 1, " B Show/Hide filebrowser" );
1299 MainBoxWrite( p_intf, l++, 1, "" );
1301 MainBoxWrite( p_intf, l++, 1, "[Global]" );
1302 MainBoxWrite( p_intf, l++, 1, " q, Q Quit" );
1303 MainBoxWrite( p_intf, l++, 1, " s Stop" );
1304 MainBoxWrite( p_intf, l++, 1, " <space> Pause/Play" );
1305 MainBoxWrite( p_intf, l++, 1, " f Toggle Fullscreen" );
1306 MainBoxWrite( p_intf, l++, 1, " n, p Next/Previous playlist item" );
1307 MainBoxWrite( p_intf, l++, 1, " [, ] Next/Previous title" );
1308 MainBoxWrite( p_intf, l++, 1, " <, > Next/Previous chapter" );
1309 MainBoxWrite( p_intf, l++, 1, " <right> Seek +1%%" );
1310 MainBoxWrite( p_intf, l++, 1, " <left> Seek -1%%" );
1311 MainBoxWrite( p_intf, l++, 1, " a Volume Up" );
1312 MainBoxWrite( p_intf, l++, 1, " z Volume Down" );
1313 MainBoxWrite( p_intf, l++, 1, "" );
1315 MainBoxWrite( p_intf, l++, 1, "[Playlist]" );
1316 MainBoxWrite( p_intf, l++, 1, " r Random" );
1317 MainBoxWrite( p_intf, l++, 1, " l Loop Playlist" );
1318 MainBoxWrite( p_intf, l++, 1, " R Repeat item" );
1319 MainBoxWrite( p_intf, l++, 1, " o Order Playlist by title" );
1320 MainBoxWrite( p_intf, l++, 1, " O Reverse order Playlist by title" );
1321 MainBoxWrite( p_intf, l++, 1, " / Look for an item" );
1322 MainBoxWrite( p_intf, l++, 1, " A Add an entry" );
1323 MainBoxWrite( p_intf, l++, 1, " D, <del> Delete an entry" );
1324 MainBoxWrite( p_intf, l++, 1, " <backspace> Delete an entry" );
1325 MainBoxWrite( p_intf, l++, 1, "" );
1327 MainBoxWrite( p_intf, l++, 1, "[Filebrowser]" );
1328 MainBoxWrite( p_intf, l++, 1, " <enter> Add the selected file to the playlist" );
1329 MainBoxWrite( p_intf, l++, 1, " <space> Add the selected directory to the playlist" );
1330 MainBoxWrite( p_intf, l++, 1, " . Show/Hide hidden files" );
1331 MainBoxWrite( p_intf, l++, 1, "" );
1333 MainBoxWrite( p_intf, l++, 1, "[Boxes]" );
1334 MainBoxWrite( p_intf, l++, 1, " <up>,<down> Navigate through the box line by line" );
1335 MainBoxWrite( p_intf, l++, 1, " <pgup>,<pgdown> Navigate through the box page by page" );
1336 MainBoxWrite( p_intf, l++, 1, "" );
1338 MainBoxWrite( p_intf, l++, 1, "[Player]" );
1339 MainBoxWrite( p_intf, l++, 1, " <up>,<down> Seek +/-5%%" );
1340 MainBoxWrite( p_intf, l++, 1, "" );
1342 MainBoxWrite( p_intf, l++, 1, "[Miscellaneous]" );
1343 MainBoxWrite( p_intf, l++, 1, " Ctrl-l Refresh the screen" );
1345 p_sys->i_box_lines_total = l;
1346 if( p_sys->i_box_start >= p_sys->i_box_lines_total )
1348 p_sys->i_box_start = p_sys->i_box_lines_total - 1;
1351 if( l - p_sys->i_box_start < p_sys->i_box_lines )
1353 y += l - p_sys->i_box_start;
1357 y += p_sys->i_box_lines;
1360 else if( p_sys->i_box_type == BOX_INFO )
1364 DrawBox( p_sys->w, y++, 0, h, COLS, " Information " );
1369 vlc_mutex_lock( &p_input->input.p_item->lock );
1370 for( i = 0; i < p_input->input.p_item->i_categories; i++ )
1372 info_category_t *p_category = p_input->input.p_item->pp_categories[i];
1373 if( y >= y_end ) break;
1374 MainBoxWrite( p_intf, l++, 1, " [%s]", p_category->psz_name );
1375 for( j = 0; j < p_category->i_infos; j++ )
1377 info_t *p_info = p_category->pp_infos[j];
1378 if( y >= y_end ) break;
1379 MainBoxWrite( p_intf, l++, 1, " %s: %s", p_info->psz_name, p_info->psz_value );
1382 vlc_mutex_unlock( &p_input->input.p_item->lock );
1386 MainBoxWrite( p_intf, l++, 1, "No item currently playing" );
1388 p_sys->i_box_lines_total = l;
1389 if( p_sys->i_box_start >= p_sys->i_box_lines_total )
1391 p_sys->i_box_start = p_sys->i_box_lines_total - 1;
1394 if( l - p_sys->i_box_start < p_sys->i_box_lines )
1396 y += l - p_sys->i_box_start;
1400 y += p_sys->i_box_lines;
1403 else if( p_sys->i_box_type == BOX_LOG )
1409 DrawBox( p_sys->w, y++, 0, h, COLS, " Logs " );
1411 i_start = p_intf->p_sys->p_sub->i_start;
1413 vlc_mutex_lock( p_intf->p_sys->p_sub->p_lock );
1414 i_stop = *p_intf->p_sys->p_sub->pi_stop;
1415 vlc_mutex_unlock( p_intf->p_sys->p_sub->p_lock );
1419 static const char *ppsz_type[4] = { "", "error", "warning", "debug" };
1420 if( i_line >= h - 2 )
1426 if( i_stop < 0 ) i_stop += VLC_MSG_QSIZE;
1427 if( i_stop == i_start )
1431 mvnprintw( y + h-2-i_line, 1, COLS - 2, " [%s] %s",
1432 ppsz_type[p_sys->p_sub->p_msg[i_stop].i_type],
1433 p_sys->p_sub->p_msg[i_stop].psz_msg );
1436 vlc_mutex_lock( p_intf->p_sys->p_sub->p_lock );
1437 p_intf->p_sys->p_sub->i_start = i_stop;
1438 vlc_mutex_unlock( p_intf->p_sys->p_sub->p_lock );
1441 else if( p_sys->i_box_type == BOX_BROWSE )
1443 /* Filebrowser box */
1444 int i_start, i_stop;
1446 DrawBox( p_sys->w, y++, 0, h, COLS, " Browse " );
1448 if( p_sys->i_box_bidx >= p_sys->i_dir_entries ) p_sys->i_box_plidx = p_sys->i_dir_entries - 1;
1449 if( p_sys->i_box_bidx < 0 ) p_sys->i_box_bidx = 0;
1451 if( p_sys->i_box_bidx < (h - 2)/2 )
1456 else if( p_sys->i_dir_entries - p_sys->i_box_bidx > (h - 2)/2 )
1458 i_start = p_sys->i_box_bidx - (h - 2)/2;
1459 i_stop = i_start + h - 2;
1463 i_stop = p_sys->i_dir_entries;
1464 i_start = p_sys->i_dir_entries - (h - 2);
1470 if( i_stop > p_sys->i_dir_entries )
1472 i_stop = p_sys->i_dir_entries;
1475 for( i_item = i_start; i_item < i_stop; i_item++ )
1477 vlc_bool_t b_selected = ( p_sys->i_box_bidx == i_item );
1479 if( y >= y_end ) break;
1482 attrset( A_REVERSE );
1484 mvnprintw( y++, 1, COLS - 2, " %c %s", p_sys->pp_dir_entries[i_item]->b_file == VLC_TRUE ? ' ' : '+',
1485 p_sys->pp_dir_entries[i_item]->psz_path );
1488 attroff( A_REVERSE );
1493 else if( ( p_sys->i_box_type == BOX_PLAYLIST ||
1494 p_sys->i_box_type == BOX_SEARCH ||
1495 p_sys->i_box_type == BOX_OPEN ) && p_sys->p_playlist )
1498 int i_start, i_stop, i_max = p_sys->i_plist_entries;
1502 switch( p_sys->i_current_view )
1505 psz_title = strdup( " Playlist (All, one level) " );
1508 psz_title = strdup( " Playlist (By category) " );
1511 psz_title = strdup( " Playlist (Manually added) " );
1514 DrawBox( p_sys->w, y++, 0, h, COLS, psz_title );
1516 if( p_sys->b_need_update || p_sys->pp_plist == NULL )
1518 PlaylistRebuild( p_intf );
1520 if( p_sys->b_box_plidx_follow )
1522 FindIndex( p_intf );
1525 if( p_sys->i_box_plidx < 0 ) p_sys->i_box_plidx = 0;
1526 if( p_sys->i_box_plidx < 0 ) p_sys->i_box_plidx = 0;
1527 if( p_sys->i_box_plidx >= i_max ) p_sys->i_box_plidx = i_max - 1;
1529 if( p_sys->i_box_plidx < (h - 2)/2 )
1534 else if( i_max - p_sys->i_box_plidx > (h - 2)/2 )
1536 i_start = p_sys->i_box_plidx - (h - 2)/2;
1537 i_stop = i_start + h - 2;
1542 i_start = i_max - (h - 2);
1548 if( i_stop > i_max )
1553 for( i_item = i_start; i_item < i_stop; i_item++ )
1555 vlc_bool_t b_selected = ( p_sys->i_box_plidx == i_item );
1556 int c = ( PlaylistIsPlaying( p_intf,
1557 p_sys->pp_plist[i_item]->p_item ) ) ? '>' : ' ';
1559 if( y >= y_end ) break;
1562 attrset( A_REVERSE );
1564 mvnprintw( y++, 1, COLS - 2, "%c%s", c,
1565 p_sys->pp_plist[i_item]->psz_display );
1568 attroff( A_REVERSE );
1577 if( p_sys->i_box_type == BOX_SEARCH )
1579 DrawEmptyLine( p_sys->w, 7, 1, COLS-2 );
1580 if( p_sys->psz_search_chain )
1582 if( strlen( p_sys->psz_search_chain ) == 0 &&
1583 p_sys->psz_old_search != NULL )
1585 /* Searching next entry */
1586 mvnprintw( 7, 1, COLS-2, "Find: %s", p_sys->psz_old_search );
1590 mvnprintw( 7, 1, COLS-2, "Find: %s", p_sys->psz_search_chain );
1594 if( p_sys->i_box_type == BOX_OPEN )
1596 if( p_sys->psz_open_chain )
1598 DrawEmptyLine( p_sys->w, 7, 1, COLS-2 );
1599 mvnprintw( 7, 1, COLS-2, "Open: %s", p_sys->psz_open_chain );
1605 DrawEmptyLine( p_sys->w, y++, 1, COLS - 2 );
1610 *t_last_refresh = time( 0 );
1613 static playlist_item_t *PlaylistGetRoot( intf_thread_t *p_intf )
1615 intf_sys_t *p_sys = p_intf->p_sys;
1616 playlist_t *p_playlist = p_sys->p_playlist;
1618 if( p_playlist == NULL )
1623 switch( p_sys->i_current_view )
1626 return p_playlist->p_root_category;
1628 return p_playlist->p_root_onelevel;
1632 static void PlaylistRebuild( intf_thread_t *p_intf )
1634 intf_sys_t *p_sys = p_intf->p_sys;
1635 playlist_t *p_playlist = p_sys->p_playlist;
1637 if( p_playlist == NULL )
1642 vlc_mutex_lock( &p_playlist->object_lock );
1644 /* First clear the old one */
1645 PlaylistDestroy( p_intf );
1647 /* Build the new one */
1648 PlaylistAddNode( p_intf, PlaylistGetRoot( p_intf ), 0, "" );
1650 p_sys->b_need_update = VLC_FALSE;
1652 vlc_mutex_unlock( &p_playlist->object_lock );
1655 static void PlaylistAddNode( intf_thread_t *p_intf, playlist_item_t *p_node,
1658 intf_sys_t *p_sys = p_intf->p_sys;
1659 playlist_item_t *p_child;
1663 psz_tmp = (char *)malloc( strlen( c ) + 4 );
1664 if( psz_tmp == NULL ) return;
1665 for( k = 0; k < p_node->i_children; k++ )
1667 struct pl_item_t *p_pl_item;
1671 p_child = p_node->pp_children[k];
1672 i_size = strlen( c ) + strlen( p_child->p_input->psz_name ) + 4;
1673 buff = (char *)malloc( sizeof( char ) * i_size );
1674 p_pl_item = (struct pl_item_t *)malloc( sizeof( struct pl_item_t ) );
1675 if( p_pl_item == NULL || buff == NULL ) return;
1679 sprintf( buff, "%s%c-%s", c, k == p_node->i_children - 1 ?
1680 '`' : '|', p_child->p_input->psz_name );
1684 sprintf( buff, " %s", p_child->p_input->psz_name );
1686 p_pl_item->psz_display = strdup( buff );
1687 p_pl_item->p_item = p_child;
1688 INSERT_ELEM( p_sys->pp_plist, p_sys->i_plist_entries,
1689 p_sys->i_plist_entries, p_pl_item );
1693 if( p_child->i_children > 0 )
1695 sprintf( psz_tmp, "%s%c ", c,
1696 k == p_node->i_children - 1 ? ' ' : '|' );
1697 PlaylistAddNode( p_intf, p_child, i,
1698 strlen( c ) ? psz_tmp : " " );
1704 static int PlaylistChanged( vlc_object_t *p_this, const char *psz_variable,
1705 vlc_value_t oval, vlc_value_t nval, void *param )
1707 intf_thread_t *p_intf = (intf_thread_t *)param;
1708 p_intf->p_sys->b_need_update = VLC_TRUE;
1713 static inline vlc_bool_t PlaylistIsPlaying( intf_thread_t *p_intf,
1714 playlist_item_t *p_item )
1716 playlist_item_t *p_played_item = p_intf->p_sys->p_playlist->status.p_item;
1717 return( p_item != NULL && p_played_item != NULL &&
1718 p_item->p_input != NULL && p_played_item->p_input != NULL &&
1719 p_item->p_input->i_id == p_played_item->p_input->i_id );
1722 static void FindIndex( intf_thread_t *p_intf )
1724 intf_sys_t *p_sys = p_intf->p_sys;
1727 if( p_sys->i_box_plidx < p_sys->i_plist_entries &&
1728 p_sys->i_box_plidx >= 0 &&
1729 PlaylistIsPlaying( p_intf,
1730 p_sys->pp_plist[p_sys->i_box_plidx]->p_item ) )
1735 for( i = 0; i < p_sys->i_plist_entries; i++ )
1737 if( PlaylistIsPlaying( p_intf, p_sys->pp_plist[i]->p_item ) )
1739 p_sys->i_box_plidx = i;
1745 static void PlaylistDestroy( intf_thread_t *p_intf )
1747 intf_sys_t *p_sys = p_intf->p_sys;
1750 for( i = 0; i < p_sys->i_plist_entries; i++ )
1752 struct pl_item_t *p_pl_item = p_sys->pp_plist[i];
1753 free( p_pl_item->psz_display );
1754 REMOVE_ELEM( p_sys->pp_plist, p_sys->i_plist_entries, i );
1757 p_sys->pp_plist = NULL;
1758 p_sys->i_plist_entries = 0;
1761 static void Eject( intf_thread_t *p_intf )
1763 char *psz_device = NULL, *psz_parser, *psz_name;
1766 * Get the active input
1767 * Determine whether we can eject a media, ie it's a DVD, VCD or CD-DA
1768 * If it's neither of these, then return
1771 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1774 if( p_playlist == NULL )
1779 vlc_mutex_lock( &p_playlist->object_lock );
1781 if( p_playlist->status.p_item == NULL )
1783 vlc_mutex_unlock( &p_playlist->object_lock );
1784 vlc_object_release( p_playlist );
1788 psz_name = p_playlist->status.p_item->p_input->psz_name;
1792 if( !strncmp(psz_name, "dvd://", 4) )
1794 switch( psz_name[strlen("dvd://")] )
1798 psz_device = config_GetPsz( p_intf, "dvd" );
1801 /* Omit the first MRL-selector characters */
1802 psz_device = strdup( psz_name + strlen("dvd://" ) );
1806 else if( !strncmp(psz_name, VCD_MRL, strlen(VCD_MRL)) )
1808 switch( psz_name[strlen(VCD_MRL)] )
1812 psz_device = config_GetPsz( p_intf, VCD_MRL );
1815 /* Omit the beginning MRL-selector characters */
1816 psz_device = strdup( psz_name + strlen(VCD_MRL) );
1820 else if( !strncmp(psz_name, CDDA_MRL, strlen(CDDA_MRL) ) )
1822 switch( psz_name[strlen(CDDA_MRL)] )
1826 psz_device = config_GetPsz( p_intf, "cd-audio" );
1829 /* Omit the beginning MRL-selector characters */
1830 psz_device = strdup( psz_name + strlen(CDDA_MRL) );
1836 psz_device = strdup( psz_name );
1840 vlc_mutex_unlock( &p_playlist->object_lock );
1841 vlc_object_release( p_playlist );
1843 if( psz_device == NULL )
1848 /* Remove what we have after @ */
1849 psz_parser = psz_device;
1850 for( psz_parser = psz_device ; *psz_parser ; psz_parser++ )
1852 if( *psz_parser == '@' )
1859 /* If there's a stream playing, we aren't allowed to eject ! */
1860 if( p_intf->p_sys->p_input == NULL )
1862 msg_Dbg( p_intf, "ejecting %s", psz_device );
1864 intf_Eject( p_intf, psz_device );
1871 static int comp_dir_entries( const void *pp_dir_entry1,
1872 const void *pp_dir_entry2 )
1874 struct dir_entry_t *p_dir_entry1 = *(struct dir_entry_t**)pp_dir_entry1;
1875 struct dir_entry_t *p_dir_entry2 = *(struct dir_entry_t**)pp_dir_entry2;
1876 if ( p_dir_entry1->b_file == p_dir_entry2->b_file ) {
1877 return strcasecmp( p_dir_entry1->psz_path, p_dir_entry2->psz_path );
1881 return ( p_dir_entry1->b_file ? 1 : -1 );
1885 static void ReadDir( intf_thread_t *p_intf )
1887 intf_sys_t *p_sys = p_intf->p_sys;
1891 if( p_sys->psz_current_dir && *p_sys->psz_current_dir )
1893 const char *psz_entry;
1896 p_current_dir = utf8_opendir( p_sys->psz_current_dir );
1898 if( p_current_dir == NULL )
1900 /* something went bad, get out of here ! */
1902 msg_Warn( p_intf, "cannot open directory `%s' (%s)",
1903 p_sys->psz_current_dir, strerror(errno));
1905 msg_Warn( p_intf, "cannot open directory `%s'", p_sys->psz_current_dir );
1910 /* Clean the old shit */
1911 for( i = 0; i < p_sys->i_dir_entries; i++ )
1913 struct dir_entry_t *p_dir_entry = p_sys->pp_dir_entries[i];
1914 free( p_dir_entry->psz_path );
1915 REMOVE_ELEM( p_sys->pp_dir_entries, p_sys->i_dir_entries, i );
1916 free( p_dir_entry );
1918 p_sys->pp_dir_entries = NULL;
1919 p_sys->i_dir_entries = 0;
1921 /* get the first directory entry */
1922 psz_entry = utf8_readdir( p_current_dir );
1924 /* while we still have entries in the directory */
1925 while( psz_entry != NULL )
1927 #if defined( S_ISDIR )
1928 struct stat stat_data;
1930 struct dir_entry_t *p_dir_entry;
1931 int i_size_entry = strlen( p_sys->psz_current_dir ) +
1932 strlen( psz_entry ) + 2;
1935 if( p_sys->b_show_hidden_files == VLC_FALSE &&
1936 ( strlen( psz_entry ) && psz_entry[0] == '.' ) &&
1937 strcmp( psz_entry, ".." ) )
1939 LocaleFree( psz_entry );
1940 psz_entry = utf8_readdir( p_current_dir );
1944 psz_uri = (char *)malloc( sizeof(char)*i_size_entry);
1945 sprintf( psz_uri, "%s/%s", p_sys->psz_current_dir, psz_entry );
1947 if( !( p_dir_entry = malloc( sizeof( struct dir_entry_t) ) ) )
1953 #if defined( S_ISDIR )
1954 utf8_stat( psz_uri, &stat_data );
1955 if( S_ISDIR(stat_data.st_mode) )
1956 /*#elif defined( DT_DIR )
1957 if( p_dir_content->d_type & DT_DIR )*/
1962 p_dir_entry->psz_path = strdup( psz_entry );
1963 p_dir_entry->b_file = VLC_FALSE;
1964 INSERT_ELEM( p_sys->pp_dir_entries, p_sys->i_dir_entries,
1965 p_sys->i_dir_entries, p_dir_entry );
1969 p_dir_entry->psz_path = strdup( psz_entry );
1970 p_dir_entry->b_file = VLC_TRUE;
1971 INSERT_ELEM( p_sys->pp_dir_entries, p_sys->i_dir_entries,
1972 p_sys->i_dir_entries, p_dir_entry );
1976 LocaleFree( psz_entry );
1977 /* Read next entry */
1978 psz_entry = utf8_readdir( p_current_dir );
1982 qsort( p_sys->pp_dir_entries, p_sys->i_dir_entries,
1983 sizeof(struct dir_entry_t*), &comp_dir_entries );
1985 closedir( p_current_dir );
1990 msg_Dbg( p_intf, "no current dir set" );
1995 static void PlayPause( intf_thread_t *p_intf )
1997 input_thread_t *p_input = p_intf->p_sys->p_input;
2002 var_Get( p_input, "state", &val );
2003 if( val.i_int != PAUSE_S )
2005 val.i_int = PAUSE_S;
2009 val.i_int = PLAYING_S;
2011 var_Set( p_input, "state", val );
2013 else if( p_intf->p_sys->p_playlist )
2015 playlist_Play( p_intf->p_sys->p_playlist );
2019 /****************************************************************************
2021 ****************************************************************************/
2022 static void DrawBox( WINDOW *win, int y, int x, int h, int w, const char *title )
2027 if( w > 3 && h > 2 )
2029 if( title == NULL ) title = "";
2030 i_len = strlen( title );
2032 if( i_len > w - 2 ) i_len = w - 2;
2034 mvwaddch( win, y, x, ACS_ULCORNER );
2035 mvwhline( win, y, x+1, ACS_HLINE, ( w-i_len-2)/2 );
2036 mvwprintw( win,y, x+1+(w-i_len-2)/2, "%s", title );
2037 mvwhline( win, y, x+(w-i_len)/2+i_len, ACS_HLINE, w - 1 - ((w-i_len)/2+i_len) );
2038 mvwaddch( win, y, x+w-1,ACS_URCORNER );
2040 for( i = 0; i < h-2; i++ )
2042 mvwaddch( win, y+i+1, x, ACS_VLINE );
2043 mvwaddch( win, y+i+1, x+w-1, ACS_VLINE );
2046 mvwaddch( win, y+h-1, x, ACS_LLCORNER );
2047 mvwhline( win, y+h-1, x+1, ACS_HLINE, w - 2 );
2048 mvwaddch( win, y+h-1, x+w-1, ACS_LRCORNER );
2052 static void DrawEmptyLine( WINDOW *win, int y, int x, int w )
2056 mvhline( y, x, ' ', w );
2060 static void DrawLine( WINDOW *win, int y, int x, int w )
2064 attrset( A_REVERSE );
2065 mvhline( y, x, ' ', w );
2066 attroff( A_REVERSE );