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 "vcd://"
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 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 */
189 int i_verbose; /* stores verbosity level */
192 static void DrawBox( WINDOW *win, int y, int x, int h, int w, const char *title );
193 static void DrawLine( WINDOW *win, int y, int x, int w );
194 static void DrawEmptyLine( WINDOW *win, int y, int x, int w );
196 /*****************************************************************************
197 * Open: initialize and create window
198 *****************************************************************************/
199 static int Open( vlc_object_t *p_this )
201 intf_thread_t *p_intf = (intf_thread_t *)p_this;
205 /* Allocate instance and initialize some members */
206 p_sys = p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
207 p_sys->p_playlist = NULL;
208 p_sys->p_input = NULL;
209 p_sys->f_slider = 0.0;
210 p_sys->f_slider_old = 0.0;
211 p_sys->i_box_type = BOX_PLAYLIST;
212 p_sys->i_box_lines = 0;
213 p_sys->i_box_start= 0;
214 p_sys->i_box_lines_total = 0;
215 p_sys->b_box_plidx_follow = VLC_TRUE;
216 p_sys->b_box_cleared = VLC_FALSE;
217 p_sys->i_box_plidx = 0;
218 p_sys->i_box_bidx = 0;
219 p_sys->p_sub = msg_Subscribe( p_intf, MSG_QUEUE_NORMAL );
220 memset( p_sys->psz_partial_keys, 0, sizeof( p_sys->psz_partial_keys ) );
222 /* Initialize the curses library */
223 p_sys->w = initscr();
224 keypad( p_sys->w, TRUE );
225 /* Don't do NL -> CR/NL */
227 /* Take input chars one at a time */
237 /* exported function */
238 p_intf->pf_run = Run;
240 /* Remember verbosity level */
241 var_Get( p_intf->p_libvlc, "verbose", &val );
242 p_sys->i_verbose = val.i_int;
245 var_Set( p_intf->p_libvlc, "verbose", val );
247 /* Set defaul playlist view */
248 p_sys->i_current_view = VIEW_CATEGORY;
249 p_sys->pp_plist = NULL;
250 p_sys->i_plist_entries = 0;
251 p_sys->b_need_update = VLC_FALSE;
253 /* Initialize search chain */
254 p_sys->psz_search_chain = (char *)malloc( SEARCH_CHAIN_SIZE + 1 );
255 p_sys->psz_old_search = NULL;
256 p_sys->i_before_search = 0;
258 /* Initialize open chain */
259 p_sys->psz_open_chain = (char *)malloc( OPEN_CHAIN_SIZE + 1 );
261 /* Initialize browser options */
262 var_Create( p_intf, "browse-dir", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
263 var_Get( p_intf, "browse-dir", &val);
265 if( val.psz_string && *val.psz_string )
267 p_sys->psz_current_dir = strdup( val.psz_string );
268 free( val.psz_string );
272 p_sys->psz_current_dir = strdup( p_intf->p_libvlc->psz_homedir );
275 p_sys->i_dir_entries = 0;
276 p_sys->pp_dir_entries = NULL;
277 p_sys->b_show_hidden_files = VLC_FALSE;
283 /*****************************************************************************
284 * Close: destroy interface window
285 *****************************************************************************/
286 static void Close( vlc_object_t *p_this )
288 intf_thread_t *p_intf = (intf_thread_t *)p_this;
289 intf_sys_t *p_sys = p_intf->p_sys;
292 var_DelCallback( p_sys->p_playlist, "intf-change", PlaylistChanged,
294 var_DelCallback( p_sys->p_playlist, "item-append", PlaylistChanged,
297 PlaylistDestroy( p_intf );
299 for( i = 0; i < p_sys->i_dir_entries; i++ )
301 struct dir_entry_t *p_dir_entry = p_sys->pp_dir_entries[i];
302 if( p_dir_entry->psz_path ) free( p_dir_entry->psz_path );
303 REMOVE_ELEM( p_sys->pp_dir_entries, p_sys->i_dir_entries, i );
304 if( p_dir_entry ) free( p_dir_entry );
306 p_sys->pp_dir_entries = NULL;
308 if( p_sys->psz_current_dir ) free( p_sys->psz_current_dir );
309 if( p_sys->psz_search_chain ) free( p_sys->psz_search_chain );
310 if( p_sys->psz_old_search ) free( p_sys->psz_old_search );
311 if( p_sys->psz_open_chain ) free( p_sys->psz_open_chain );
315 vlc_object_release( p_sys->p_input );
317 if( p_sys->p_playlist )
319 vlc_object_release( p_sys->p_playlist );
322 /* Close the ncurses interface */
325 msg_Unsubscribe( p_intf, p_sys->p_sub );
327 /* Restores initial verbose setting */
329 val.i_int = p_sys->i_verbose;
330 var_Set( p_intf->p_libvlc, "verbose", val );
332 /* Destroy structure */
336 /*****************************************************************************
337 * Run: ncurses thread
338 *****************************************************************************/
339 static void Run( intf_thread_t *p_intf )
341 intf_sys_t *p_sys = p_intf->p_sys;
344 time_t t_last_refresh;
347 * force drawing the interface for the first time
349 t_last_refresh = ( time( 0 ) - 1);
351 while( !intf_ShouldDie( p_intf ) )
353 msleep( INTF_IDLE_SLEEP );
355 /* Update the input */
356 if( p_sys->p_playlist == NULL )
358 p_sys->p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
360 if( p_sys->p_playlist )
362 var_AddCallback( p_sys->p_playlist, "intf-change",
363 PlaylistChanged, p_intf );
364 var_AddCallback( p_sys->p_playlist, "item-append",
365 PlaylistChanged, p_intf );
368 if( p_sys->p_playlist )
370 vlc_mutex_lock( &p_sys->p_playlist->object_lock );
371 if( p_sys->p_input == NULL )
373 p_sys->p_input = p_sys->p_playlist->p_input;
376 if( !p_sys->p_input->b_dead )
378 vlc_object_yield( p_sys->p_input );
382 else if( p_sys->p_input->b_dead )
384 vlc_object_release( p_sys->p_input );
385 p_sys->p_input = NULL;
386 p_sys->f_slider = p_sys->f_slider_old = 0.0;
387 p_sys->b_box_cleared = VLC_FALSE;
389 vlc_mutex_unlock( &p_sys->p_playlist->object_lock );
392 if( p_sys->b_box_plidx_follow && p_sys->p_playlist->status.p_item )
397 while( ( i_key = getch() ) != -1 )
400 * HandleKey returns 1 if the screen needs to be redrawn
402 if( HandleKey( p_intf, i_key ) )
404 Redraw( p_intf, &t_last_refresh );
408 if( p_sys->f_slider > 0.0001 && !p_sys->b_box_cleared )
411 Redraw( p_intf, &t_last_refresh );
412 p_sys->b_box_cleared = VLC_TRUE;
416 * redraw the screen every second
418 if( (time(0) - t_last_refresh) >= 1 )
420 ManageSlider( p_intf );
421 Redraw( p_intf, &t_last_refresh );
426 /* following functions are local */
427 static char *KeyToUTF8( int i_key, char *psz_part )
430 int len = strlen( psz_part );
433 /* overflow error - should not happen */
434 memset( psz_part, 0, 6 );
438 psz_part[len] = (char)i_key;
440 #ifdef HAVE_NCURSESW_CURSES_H
441 psz_utf8 = strdup( psz_part );
443 psz_utf8 = FromLocaleDup( psz_part );
445 /* Ugly check for incomplete bytes sequences
446 * (in case of non-UTF8 multibyte local encoding) */
448 for( psz = psz_utf8; *psz; psz++ )
449 if( ( *psz == '?' ) && ( *psz_utf8 != '?' ) )
451 /* incomplete bytes sequence detected
452 * (VLC core inserted dummy question marks) */
457 /* Check for incomplete UTF8 bytes sequence */
458 if( EnsureUTF8( psz_utf8 ) == NULL )
465 memset( psz_part, 0, 6 );
469 static inline int RemoveLastUTF8Entity( char *psz, int len )
471 while( len && ( (psz[--len] & 0xc0) == 0x80 ) );
472 /* UTF8 continuation byte */
478 static int HandleKey( intf_thread_t *p_intf, int i_key )
480 intf_sys_t *p_sys = p_intf->p_sys;
483 if( p_sys->i_box_type == BOX_PLAYLIST && p_sys->p_playlist )
485 int b_ret = VLC_TRUE;
486 vlc_bool_t b_box_plidx_follow = VLC_FALSE;
491 /* Playlist Settings */
493 var_Get( p_sys->p_playlist, "random", &val );
494 val.b_bool = !val.b_bool;
495 var_Set( p_sys->p_playlist, "random", val );
498 var_Get( p_sys->p_playlist, "loop", &val );
499 val.b_bool = !val.b_bool;
500 var_Set( p_sys->p_playlist, "loop", val );
503 var_Get( p_sys->p_playlist, "repeat", &val );
504 val.b_bool = !val.b_bool;
505 var_Set( p_sys->p_playlist, "repeat", val );
510 playlist_RecursiveNodeSort( p_sys->p_playlist,
511 PlaylistGetRoot( p_intf ),
512 SORT_TITLE_NODES_FIRST, ORDER_NORMAL );
513 p_sys->b_need_update = VLC_TRUE;
516 playlist_RecursiveNodeSort( p_sys->p_playlist,
517 PlaylistGetRoot( p_intf ),
518 SORT_TITLE_NODES_FIRST, ORDER_REVERSE );
519 p_sys->b_need_update = VLC_TRUE;
524 switch( p_sys->i_current_view )
527 p_sys->i_current_view = VIEW_ONELEVEL;
530 p_sys->i_current_view = VIEW_CATEGORY;
532 //p_sys->b_need_update = VLC_TRUE;
533 PlaylistRebuild( p_intf );
536 /* Playlist navigation */
538 p_sys->i_box_plidx = 0;
541 p_sys->i_box_plidx = p_sys->p_playlist->items.i_size - 1;
544 p_sys->i_box_plidx--;
547 p_sys->i_box_plidx++;
550 p_sys->i_box_plidx -= p_sys->i_box_lines;
553 p_sys->i_box_plidx += p_sys->i_box_lines;
559 playlist_t *p_playlist = p_sys->p_playlist;
560 playlist_item_t *p_item;
562 vlc_mutex_lock( &p_playlist->object_lock );
563 p_item = p_sys->pp_plist[p_sys->i_box_plidx]->p_item;
564 if( p_item->i_children == -1 )
566 playlist_DeleteFromInput( p_playlist,
567 p_item->p_input->i_id, VLC_TRUE );
571 playlist_NodeDelete( p_playlist, p_item,
572 VLC_TRUE , VLC_FALSE );
574 vlc_mutex_unlock( &p_playlist->object_lock );
575 p_sys->b_need_update = VLC_TRUE;
582 if( p_sys->pp_plist[p_sys->i_box_plidx]->p_item->i_children
585 playlist_item_t *p_item, *p_parent;
587 p_sys->pp_plist[p_sys->i_box_plidx]->p_item;
589 while( p_parent->p_parent )
590 p_parent = p_parent->p_parent;
591 playlist_Control( p_sys->p_playlist, PLAYLIST_VIEWPLAY,
592 VLC_TRUE, p_parent, p_item );
596 playlist_Control( p_sys->p_playlist, PLAYLIST_VIEWPLAY,
598 p_sys->pp_plist[p_sys->i_box_plidx]->p_item,
601 b_box_plidx_follow = VLC_TRUE;
610 int i_max = p_sys->i_plist_entries;
611 if( p_sys->i_box_plidx >= i_max ) p_sys->i_box_plidx = i_max - 1;
612 if( p_sys->i_box_plidx < 0 ) p_sys->i_box_plidx = 0;
613 if( PlaylistIsPlaying( p_intf,
614 p_sys->pp_plist[p_sys->i_box_plidx]->p_item ) )
615 b_box_plidx_follow = VLC_TRUE;
616 p_sys->b_box_plidx_follow = b_box_plidx_follow;
620 if( p_sys->i_box_type == BOX_BROWSE )
622 vlc_bool_t b_ret = VLC_TRUE;
623 /* Browser navigation */
627 p_sys->i_box_bidx = 0;
630 p_sys->i_box_bidx = p_sys->i_dir_entries - 1;
639 p_sys->i_box_bidx -= p_sys->i_box_lines;
642 p_sys->i_box_bidx += p_sys->i_box_lines;
644 case '.': /* Toggle show hidden files */
645 p_sys->b_show_hidden_files = ( p_sys->b_show_hidden_files ==
646 VLC_TRUE ? VLC_FALSE : VLC_TRUE );
653 if( p_sys->pp_dir_entries[p_sys->i_box_bidx]->b_file || i_key == ' ' )
655 int i_size_entry = strlen( p_sys->psz_current_dir ) +
656 strlen( p_sys->pp_dir_entries[p_sys->i_box_bidx]->psz_path ) + 2;
657 char *psz_uri = (char *)malloc( sizeof(char)*i_size_entry);
659 sprintf( psz_uri, "%s/%s", p_sys->psz_current_dir, p_sys->pp_dir_entries[p_sys->i_box_bidx]->psz_path );
661 playlist_item_t *p_parent = p_sys->p_playlist->status.p_node;
662 while( p_parent && p_parent->p_parent )
663 p_parent = p_parent->p_parent;
665 playlist_Add( p_sys->p_playlist, psz_uri, NULL,
666 PLAYLIST_APPEND, PLAYLIST_END,
667 p_parent == p_sys->p_playlist->p_root_onelevel
669 p_sys->i_box_type = BOX_PLAYLIST;
674 int i_size_entry = strlen( p_sys->psz_current_dir ) +
675 strlen( p_sys->pp_dir_entries[p_sys->i_box_bidx]->psz_path ) + 2;
676 char *psz_uri = (char *)malloc( sizeof(char)*i_size_entry);
678 sprintf( psz_uri, "%s/%s", p_sys->psz_current_dir, p_sys->pp_dir_entries[p_sys->i_box_bidx]->psz_path );
680 p_sys->psz_current_dir = strdup( psz_uri );
691 if( p_sys->i_box_bidx >= p_sys->i_dir_entries ) p_sys->i_box_bidx = p_sys->i_dir_entries - 1;
692 if( p_sys->i_box_bidx < 0 ) p_sys->i_box_bidx = 0;
696 else if( p_sys->i_box_type == BOX_HELP || p_sys->i_box_type == BOX_INFO )
701 p_sys->i_box_start = 0;
704 p_sys->i_box_start = p_sys->i_box_lines_total - 1;
707 if( p_sys->i_box_start > 0 ) p_sys->i_box_start--;
710 if( p_sys->i_box_start < p_sys->i_box_lines_total - 1 )
712 p_sys->i_box_start++;
716 p_sys->i_box_start -= p_sys->i_box_lines;
717 if( p_sys->i_box_start < 0 ) p_sys->i_box_start = 0;
720 p_sys->i_box_start += p_sys->i_box_lines;
721 if( p_sys->i_box_start >= p_sys->i_box_lines_total )
723 p_sys->i_box_start = p_sys->i_box_lines_total - 1;
730 else if( p_sys->i_box_type == BOX_NONE )
736 ManageSlider( p_intf );
739 p_sys->f_slider = 99.9;
740 ManageSlider( p_intf );
743 p_sys->f_slider += 5.0;
744 if( p_sys->f_slider >= 99.0 ) p_sys->f_slider = 99.0;
745 ManageSlider( p_intf );
748 p_sys->f_slider -= 5.0;
749 if( p_sys->f_slider < 0.0 ) p_sys->f_slider = 0.0;
750 ManageSlider( p_intf );
757 else if( p_sys->i_box_type == BOX_SEARCH && p_sys->psz_search_chain )
760 i_chain_len = strlen( p_sys->psz_search_chain );
768 if( i_chain_len > 0 )
770 p_sys->psz_old_search = strdup( p_sys->psz_search_chain );
772 else if( p_sys->psz_old_search )
774 SearchPlaylist( p_intf, p_sys->psz_old_search );
776 p_sys->i_box_type = BOX_PLAYLIST;
778 case 0x1b: /* Esc. */
779 p_sys->i_box_plidx = p_sys->i_before_search;
780 p_sys->i_box_type = BOX_PLAYLIST;
783 RemoveLastUTF8Entity( p_sys->psz_search_chain, i_chain_len );
787 char *psz_utf8 = KeyToUTF8( i_key, p_sys->psz_partial_keys );
789 if( psz_utf8 != NULL )
791 if( i_chain_len + strlen( psz_utf8 ) < SEARCH_CHAIN_SIZE )
793 strcpy( p_sys->psz_search_chain + i_chain_len,
801 if( p_sys->psz_old_search )
803 free( p_sys->psz_old_search );
804 p_sys->psz_old_search = NULL;
806 SearchPlaylist( p_intf, p_sys->psz_search_chain );
809 else if( p_sys->i_box_type == BOX_OPEN && p_sys->psz_open_chain )
811 int i_chain_len = strlen( p_sys->psz_open_chain );
812 playlist_t *p_playlist = p_sys->p_playlist;
821 if( p_playlist && i_chain_len > 0 )
823 playlist_item_t *p_parent = p_sys->p_playlist->status.p_node;
824 while( p_parent && p_parent->p_parent )
825 p_parent = p_parent->p_parent;
827 playlist_Add( p_playlist, p_sys->psz_open_chain, NULL,
828 PLAYLIST_APPEND|PLAYLIST_GO, PLAYLIST_END,
829 p_parent == p_sys->p_playlist->p_root_onelevel
831 p_sys->b_box_plidx_follow = VLC_TRUE;
833 p_sys->i_box_type = BOX_PLAYLIST;
835 case 0x1b: /* Esc. */
836 p_sys->i_box_type = BOX_PLAYLIST;
839 RemoveLastUTF8Entity( p_sys->psz_open_chain, i_chain_len );
843 char *psz_utf8 = KeyToUTF8( i_key, p_sys->psz_partial_keys );
845 if( psz_utf8 != NULL )
847 if( i_chain_len + strlen( psz_utf8 ) < OPEN_CHAIN_SIZE )
849 strcpy( p_sys->psz_open_chain + i_chain_len,
867 vlc_object_kill( p_intf->p_libvlc );
872 if( p_sys->i_box_type == BOX_INFO )
873 p_sys->i_box_type = BOX_NONE;
875 p_sys->i_box_type = BOX_INFO;
876 p_sys->i_box_lines_total = 0;
879 if( p_sys->i_box_type == BOX_LOG )
880 p_sys->i_box_type = BOX_NONE;
882 p_sys->i_box_type = BOX_LOG;
885 if( p_sys->i_box_type == BOX_PLAYLIST )
886 p_sys->i_box_type = BOX_NONE;
888 p_sys->i_box_type = BOX_PLAYLIST;
891 if( p_sys->i_box_type == BOX_BROWSE )
892 p_sys->i_box_type = BOX_NONE;
894 p_sys->i_box_type = BOX_BROWSE;
898 if( p_sys->i_box_type == BOX_HELP )
899 p_sys->i_box_type = BOX_NONE;
901 p_sys->i_box_type = BOX_HELP;
902 p_sys->i_box_lines_total = 0;
905 if( p_sys->i_box_type != BOX_SEARCH )
907 if( p_sys->psz_search_chain == NULL )
911 p_sys->psz_search_chain[0] = '\0';
912 p_sys->b_box_plidx_follow = VLC_FALSE;
913 p_sys->i_before_search = p_sys->i_box_plidx;
914 p_sys->i_box_type = BOX_SEARCH;
918 if( p_sys->i_box_type != BOX_OPEN )
920 if( p_sys->psz_open_chain == NULL )
924 p_sys->psz_open_chain[0] = '\0';
925 p_sys->i_box_type = BOX_OPEN;
931 p_sys->f_slider += 1.0;
932 if( p_sys->f_slider > 99.9 ) p_sys->f_slider = 99.9;
933 ManageSlider( p_intf );
937 p_sys->f_slider -= 1.0;
938 if( p_sys->f_slider < 0.0 ) p_sys->f_slider = 0.0;
939 ManageSlider( p_intf );
945 if( p_intf->p_sys->p_input )
947 vout_thread_t *p_vout;
948 p_vout = vlc_object_find( p_intf->p_sys->p_input,
949 VLC_OBJECT_VOUT, FIND_CHILD );
952 var_Get( p_vout, "fullscreen", &val );
953 val.b_bool = !val.b_bool;
954 var_Set( p_vout, "fullscreen", val );
955 vlc_object_release( p_vout );
959 playlist_t *p_playlist;
960 p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
964 var_Get( p_playlist, "fullscreen", &val );
965 val.b_bool = !val.b_bool;
966 var_Set( p_playlist, "fullscreen", val );
967 vlc_object_release( p_playlist );
979 if( p_intf->p_sys->p_playlist )
981 playlist_Stop( p_intf->p_sys->p_playlist );
992 val.b_bool = VLC_TRUE;
993 var_Set( p_sys->p_input, "prev-title", val );
1000 val.b_bool = VLC_TRUE;
1001 var_Set( p_sys->p_input, "next-title", val );
1006 if( p_sys->p_input )
1008 val.b_bool = VLC_TRUE;
1009 var_Set( p_sys->p_input, "prev-chapter", val );
1014 if( p_sys->p_input )
1016 val.b_bool = VLC_TRUE;
1017 var_Set( p_sys->p_input, "next-chapter", val );
1022 if( p_intf->p_sys->p_playlist )
1024 playlist_Prev( p_intf->p_sys->p_playlist );
1030 if( p_intf->p_sys->p_playlist )
1032 playlist_Next( p_intf->p_sys->p_playlist );
1038 aout_VolumeUp( p_intf, 1, NULL );
1043 aout_VolumeDown( p_intf, 1, NULL );
1048 * ^l should clear and redraw the screen
1059 static void ManageSlider( intf_thread_t *p_intf )
1061 intf_sys_t *p_sys = p_intf->p_sys;
1062 input_thread_t *p_input = p_sys->p_input;
1065 if( p_input == NULL )
1069 var_Get( p_input, "state", &val );
1070 if( val.i_int != PLAYING_S )
1075 var_Get( p_input, "position", &val );
1076 if( p_sys->f_slider == p_sys->f_slider_old )
1079 p_sys->f_slider_old = 100 * val.f_float;
1083 p_sys->f_slider_old = p_sys->f_slider;
1085 val.f_float = p_sys->f_slider / 100.0;
1086 var_Set( p_input, "position", val );
1090 static void SearchPlaylist( intf_thread_t *p_intf, char *psz_searchstring )
1095 intf_sys_t *p_sys = p_intf->p_sys;
1097 if( p_sys->i_before_search >= 0 )
1099 i_first = p_sys->i_before_search;
1102 if( ( ! psz_searchstring ) || strlen( psz_searchstring ) <= 0 )
1104 p_sys->i_box_plidx = p_sys->i_before_search;
1108 i_max = p_sys->i_plist_entries;
1110 i_item = SubSearchPlaylist( p_intf, psz_searchstring, i_first + 1, i_max );
1113 i_item = SubSearchPlaylist( p_intf, psz_searchstring, 0, i_first );
1116 if( i_item < 0 || i_item >= i_max ) return;
1118 p_sys->i_box_plidx = i_item;
1121 static int SubSearchPlaylist( intf_thread_t *p_intf, char *psz_searchstring,
1122 int i_start, int i_stop )
1124 intf_sys_t *p_sys = p_intf->p_sys;
1127 for( i = i_start + 1; i < i_stop; i++ )
1129 if( strcasestr( p_sys->pp_plist[i]->psz_display,
1130 psz_searchstring ) != NULL )
1141 static void mvnprintw( int y, int x, int w, const char *p_fmt, ... )
1146 #ifdef HAVE_NCURSESW_CURSES_H
1147 size_t i_char_len; /* UCS character length */
1148 size_t i_width; /* Display width */
1149 wchar_t *psz_wide; /* wchar_t representation of p_buf */
1152 va_start( vl_args, p_fmt );
1153 if( vasprintf( &p_buf, p_fmt, vl_args ) == -1 )
1157 if( ( p_buf == NULL ) || ( w <= 0 ) )
1160 i_len = strlen( p_buf );
1161 #ifdef HAVE_NCURSESW_CURSES_H
1162 psz_wide = (wchar_t *) malloc( sizeof( wchar_t ) * ( i_len + 1 ) );
1164 i_char_len = mbstowcs( psz_wide, p_buf, i_len );
1166 if( i_char_len == (size_t)-1 ) /* an invalid character was encountered */
1170 i_width = wcswidth( psz_wide, i_char_len );
1171 if( i_width == (size_t)-1 ) /* a non printable character was encountered */
1174 if( i_width > (size_t)w )
1178 { /* FIXME: ncursesw: ellipsize psz_wide while keeping the width in mind */
1179 int i_cut = i_len - w;
1180 int x1 = i_len/2 - i_cut/2;
1181 int x2 = x1 + i_cut;
1185 memmove( &p_buf[x1], &p_buf[x2], i_len - x2 );
1194 #ifdef HAVE_NCURSESW_CURSES_H
1195 mvprintw( y, x, "%s", p_buf );
1197 char *psz_local = ToLocale( p_buf );
1198 mvprintw( y, x, "%s", psz_local );
1199 LocaleFree( p_buf );
1204 #ifdef HAVE_NCURSESW_CURSES_H
1205 mvprintw( y, x, "%s", p_buf );
1206 mvhline( y, x + i_width, ' ', w - i_width );
1208 char *psz_local = ToLocale( p_buf );
1209 mvprintw( y, x, "%s", psz_local );
1210 LocaleFree( p_buf );
1211 mvhline( y, x + i_len, ' ', w - i_len );
1215 static void MainBoxWrite( intf_thread_t *p_intf, int l, int x, const char *p_fmt, ... )
1217 intf_sys_t *p_sys = p_intf->p_sys;
1222 if( l < p_sys->i_box_start || l - p_sys->i_box_start >= p_sys->i_box_lines )
1227 va_start( vl_args, p_fmt );
1228 if( vasprintf( &p_buf, p_fmt, vl_args ) == -1 )
1237 mvnprintw( p_sys->i_box_y + l - p_sys->i_box_start, x, COLS - x - 1, "%s", p_buf );
1240 static void Redraw( intf_thread_t *p_intf, time_t *t_last_refresh )
1242 intf_sys_t *p_sys = p_intf->p_sys;
1243 input_thread_t *p_input = p_sys->p_input;
1251 attrset( A_REVERSE );
1252 mvnprintw( y, 0, COLS, "VLC media player" " (ncurses interface) [ h for help ]" );
1253 attroff( A_REVERSE );
1257 if( p_input && !p_input->b_dead )
1259 char buf1[MSTRTIME_MAX_SIZE];
1260 char buf2[MSTRTIME_MAX_SIZE];
1262 vlc_value_t val_list;
1265 char *psz_uri = input_item_GetURI( input_GetItem( p_input ) );
1266 mvnprintw( y++, 0, COLS, " Source : %s", psz_uri );
1270 var_Get( p_input, "state", &val );
1271 if( val.i_int == PLAYING_S )
1273 mvnprintw( y, 0, COLS, " State : Playing" );
1275 else if( val.i_int == OPENING_S )
1277 mvnprintw( y, 0, COLS, " State : Opening/Connecting" );
1279 else if( val.i_int == BUFFERING_S )
1281 mvnprintw( y, 0, COLS, " State : Buffering" );
1283 else if( val.i_int == PAUSE_S )
1285 mvnprintw( y, 0, COLS, " State : Paused" );
1287 char *psz_playlist_state = malloc( 25 );
1288 /* strlen( "[Repeat] [Random] [Loop] ) == 24, + '\0' */
1289 psz_playlist_state[0] = '\0';
1290 if( var_GetBool( p_sys->p_playlist, "repeat" ) )
1291 strcat( psz_playlist_state, "[Repeat] " );
1292 if( var_GetBool( p_sys->p_playlist, "random" ) )
1293 strcat( psz_playlist_state, "[Random] " );
1294 if( var_GetBool( p_sys->p_playlist, "loop" ) )
1295 strcat( psz_playlist_state, "[Loop]" );
1296 mvnprintw( y++, 32, COLS, psz_playlist_state );
1297 free( psz_playlist_state );
1299 if( val.i_int != INIT_S && val.i_int != END_S )
1301 audio_volume_t i_volume;
1304 var_Get( p_input, "time", &val );
1305 msecstotimestr( buf1, val.i_time / 1000 );
1307 var_Get( p_input, "length", &val );
1308 msecstotimestr( buf2, val.i_time / 1000 );
1310 mvnprintw( y++, 0, COLS, " Position : %s/%s (%.2f%%)", buf1, buf2, p_sys->f_slider );
1313 aout_VolumeGet( p_intf, &i_volume );
1314 mvnprintw( y++, 0, COLS, " Volume : %i%%", i_volume*200/AOUT_VOLUME_MAX );
1317 if( !var_Get( p_input, "title", &val ) )
1319 var_Change( p_input, "title", VLC_VAR_GETCHOICES, &val_list, NULL );
1320 if( val_list.p_list->i_count > 0 )
1322 mvnprintw( y++, 0, COLS, " Title : %d/%d", val.i_int, val_list.p_list->i_count );
1324 var_Change( p_input, "title", VLC_VAR_FREELIST, &val_list, NULL );
1328 if( !var_Get( p_input, "chapter", &val ) )
1330 var_Change( p_input, "chapter", VLC_VAR_GETCHOICES, &val_list, NULL );
1331 if( val_list.p_list->i_count > 0 )
1333 mvnprintw( y++, 0, COLS, " Chapter : %d/%d", val.i_int, val_list.p_list->i_count );
1335 var_Change( p_input, "chapter", VLC_VAR_FREELIST, &val_list, NULL );
1345 mvnprintw( y++, 0, COLS, "Source: <no current item>" );
1346 DrawEmptyLine( p_sys->w, y++, 0, COLS );
1347 DrawEmptyLine( p_sys->w, y++, 0, COLS );
1348 DrawEmptyLine( p_sys->w, y++, 0, COLS );
1351 DrawBox( p_sys->w, y, 0, 3, COLS, "" );
1352 DrawEmptyLine( p_sys->w, y+1, 1, COLS-2);
1353 DrawLine( p_sys->w, y+1, 1, (int)(p_intf->p_sys->f_slider/100.0 * (COLS -2)) );
1356 p_sys->i_box_y = y + 1;
1357 p_sys->i_box_lines = LINES - y - 2;
1362 if( p_sys->i_box_type == BOX_HELP )
1366 DrawBox( p_sys->w, y++, 0, h, COLS, " Help " );
1368 MainBoxWrite( p_intf, l++, 1, "[Display]" );
1369 MainBoxWrite( p_intf, l++, 1, " h,H Show/Hide help box" );
1370 MainBoxWrite( p_intf, l++, 1, " i Show/Hide info box" );
1371 MainBoxWrite( p_intf, l++, 1, " L Show/Hide messages box" );
1372 MainBoxWrite( p_intf, l++, 1, " P Show/Hide playlist box" );
1373 MainBoxWrite( p_intf, l++, 1, " B Show/Hide filebrowser" );
1374 MainBoxWrite( p_intf, l++, 1, "" );
1376 MainBoxWrite( p_intf, l++, 1, "[Global]" );
1377 MainBoxWrite( p_intf, l++, 1, " q, Q Quit" );
1378 MainBoxWrite( p_intf, l++, 1, " s Stop" );
1379 MainBoxWrite( p_intf, l++, 1, " <space> Pause/Play" );
1380 MainBoxWrite( p_intf, l++, 1, " f Toggle Fullscreen" );
1381 MainBoxWrite( p_intf, l++, 1, " n, p Next/Previous playlist item" );
1382 MainBoxWrite( p_intf, l++, 1, " [, ] Next/Previous title" );
1383 MainBoxWrite( p_intf, l++, 1, " <, > Next/Previous chapter" );
1384 MainBoxWrite( p_intf, l++, 1, " <right> Seek +1%%" );
1385 MainBoxWrite( p_intf, l++, 1, " <left> Seek -1%%" );
1386 MainBoxWrite( p_intf, l++, 1, " a Volume Up" );
1387 MainBoxWrite( p_intf, l++, 1, " z Volume Down" );
1388 MainBoxWrite( p_intf, l++, 1, "" );
1390 MainBoxWrite( p_intf, l++, 1, "[Playlist]" );
1391 MainBoxWrite( p_intf, l++, 1, " r Random" );
1392 MainBoxWrite( p_intf, l++, 1, " l Loop Playlist" );
1393 MainBoxWrite( p_intf, l++, 1, " R Repeat item" );
1394 MainBoxWrite( p_intf, l++, 1, " o Order Playlist by title" );
1395 MainBoxWrite( p_intf, l++, 1, " O Reverse order Playlist by title" );
1396 MainBoxWrite( p_intf, l++, 1, " / Look for an item" );
1397 MainBoxWrite( p_intf, l++, 1, " A Add an entry" );
1398 MainBoxWrite( p_intf, l++, 1, " D, <del> Delete an entry" );
1399 MainBoxWrite( p_intf, l++, 1, " <backspace> Delete an entry" );
1400 MainBoxWrite( p_intf, l++, 1, "" );
1402 MainBoxWrite( p_intf, l++, 1, "[Filebrowser]" );
1403 MainBoxWrite( p_intf, l++, 1, " <enter> Add the selected file to the playlist" );
1404 MainBoxWrite( p_intf, l++, 1, " <space> Add the selected directory to the playlist" );
1405 MainBoxWrite( p_intf, l++, 1, " . Show/Hide hidden files" );
1406 MainBoxWrite( p_intf, l++, 1, "" );
1408 MainBoxWrite( p_intf, l++, 1, "[Boxes]" );
1409 MainBoxWrite( p_intf, l++, 1, " <up>,<down> Navigate through the box line by line" );
1410 MainBoxWrite( p_intf, l++, 1, " <pgup>,<pgdown> Navigate through the box page by page" );
1411 MainBoxWrite( p_intf, l++, 1, "" );
1413 MainBoxWrite( p_intf, l++, 1, "[Player]" );
1414 MainBoxWrite( p_intf, l++, 1, " <up>,<down> Seek +/-5%%" );
1415 MainBoxWrite( p_intf, l++, 1, "" );
1417 MainBoxWrite( p_intf, l++, 1, "[Miscellaneous]" );
1418 MainBoxWrite( p_intf, l++, 1, " Ctrl-l Refresh the screen" );
1420 p_sys->i_box_lines_total = l;
1421 if( p_sys->i_box_start >= p_sys->i_box_lines_total )
1423 p_sys->i_box_start = p_sys->i_box_lines_total - 1;
1426 if( l - p_sys->i_box_start < p_sys->i_box_lines )
1428 y += l - p_sys->i_box_start;
1432 y += p_sys->i_box_lines;
1435 else if( p_sys->i_box_type == BOX_INFO )
1439 DrawBox( p_sys->w, y++, 0, h, COLS, " Information " );
1444 vlc_mutex_lock( &input_GetItem(p_input)->lock );
1445 for( i = 0; i < input_GetItem(p_input)->i_categories; i++ )
1447 info_category_t *p_category = input_GetItem(p_input)->pp_categories[i];
1448 if( y >= y_end ) break;
1449 MainBoxWrite( p_intf, l++, 1, " [%s]", p_category->psz_name );
1450 for( j = 0; j < p_category->i_infos; j++ )
1452 info_t *p_info = p_category->pp_infos[j];
1453 if( y >= y_end ) break;
1454 MainBoxWrite( p_intf, l++, 1, " %s: %s", p_info->psz_name, p_info->psz_value );
1457 vlc_mutex_unlock( &input_GetItem(p_input)->lock );
1461 MainBoxWrite( p_intf, l++, 1, "No item currently playing" );
1463 p_sys->i_box_lines_total = l;
1464 if( p_sys->i_box_start >= p_sys->i_box_lines_total )
1466 p_sys->i_box_start = p_sys->i_box_lines_total - 1;
1469 if( l - p_sys->i_box_start < p_sys->i_box_lines )
1471 y += l - p_sys->i_box_start;
1475 y += p_sys->i_box_lines;
1478 else if( p_sys->i_box_type == BOX_LOG )
1484 DrawBox( p_sys->w, y++, 0, h, COLS, " Logs " );
1486 i_start = p_intf->p_sys->p_sub->i_start;
1488 vlc_mutex_lock( p_intf->p_sys->p_sub->p_lock );
1489 i_stop = *p_intf->p_sys->p_sub->pi_stop;
1490 vlc_mutex_unlock( p_intf->p_sys->p_sub->p_lock );
1494 static const char *ppsz_type[4] = { "", "error", "warning", "debug" };
1495 if( i_line >= h - 2 )
1501 if( i_stop < 0 ) i_stop += VLC_MSG_QSIZE;
1502 if( i_stop == i_start )
1506 mvnprintw( y + h-2-i_line, 1, COLS - 2, " [%s] %s",
1507 ppsz_type[p_sys->p_sub->p_msg[i_stop].i_type],
1508 p_sys->p_sub->p_msg[i_stop].psz_msg );
1511 vlc_mutex_lock( p_intf->p_sys->p_sub->p_lock );
1512 p_intf->p_sys->p_sub->i_start = i_stop;
1513 vlc_mutex_unlock( p_intf->p_sys->p_sub->p_lock );
1516 else if( p_sys->i_box_type == BOX_BROWSE )
1518 /* Filebrowser box */
1519 int i_start, i_stop;
1521 DrawBox( p_sys->w, y++, 0, h, COLS, " Browse " );
1523 if( p_sys->i_box_bidx >= p_sys->i_dir_entries ) p_sys->i_box_plidx = p_sys->i_dir_entries - 1;
1524 if( p_sys->i_box_bidx < 0 ) p_sys->i_box_bidx = 0;
1526 if( p_sys->i_box_bidx < (h - 2)/2 )
1531 else if( p_sys->i_dir_entries - p_sys->i_box_bidx > (h - 2)/2 )
1533 i_start = p_sys->i_box_bidx - (h - 2)/2;
1534 i_stop = i_start + h - 2;
1538 i_stop = p_sys->i_dir_entries;
1539 i_start = p_sys->i_dir_entries - (h - 2);
1545 if( i_stop > p_sys->i_dir_entries )
1547 i_stop = p_sys->i_dir_entries;
1550 for( i_item = i_start; i_item < i_stop; i_item++ )
1552 vlc_bool_t b_selected = ( p_sys->i_box_bidx == i_item );
1554 if( y >= y_end ) break;
1557 attrset( A_REVERSE );
1559 mvnprintw( y++, 1, COLS - 2, " %c %s", p_sys->pp_dir_entries[i_item]->b_file == VLC_TRUE ? ' ' : '+',
1560 p_sys->pp_dir_entries[i_item]->psz_path );
1563 attroff( A_REVERSE );
1568 else if( ( p_sys->i_box_type == BOX_PLAYLIST ||
1569 p_sys->i_box_type == BOX_SEARCH ||
1570 p_sys->i_box_type == BOX_OPEN ) && p_sys->p_playlist )
1573 int i_start, i_stop, i_max = p_sys->i_plist_entries;
1577 switch( p_sys->i_current_view )
1580 psz_title = strdup( " Playlist (All, one level) " );
1583 psz_title = strdup( " Playlist (By category) " );
1586 psz_title = strdup( " Playlist (Manually added) " );
1589 DrawBox( p_sys->w, y++, 0, h, COLS, psz_title );
1591 if( p_sys->b_need_update || p_sys->pp_plist == NULL )
1593 PlaylistRebuild( p_intf );
1595 if( p_sys->b_box_plidx_follow )
1597 FindIndex( p_intf );
1600 if( p_sys->i_box_plidx < 0 ) p_sys->i_box_plidx = 0;
1601 if( p_sys->i_box_plidx < 0 ) p_sys->i_box_plidx = 0;
1602 if( p_sys->i_box_plidx >= i_max ) p_sys->i_box_plidx = i_max - 1;
1604 if( p_sys->i_box_plidx < (h - 2)/2 )
1609 else if( i_max - p_sys->i_box_plidx > (h - 2)/2 )
1611 i_start = p_sys->i_box_plidx - (h - 2)/2;
1612 i_stop = i_start + h - 2;
1617 i_start = i_max - (h - 2);
1623 if( i_stop > i_max )
1628 for( i_item = i_start; i_item < i_stop; i_item++ )
1630 vlc_bool_t b_selected = ( p_sys->i_box_plidx == i_item );
1631 int c = ( PlaylistIsPlaying( p_intf,
1632 p_sys->pp_plist[i_item]->p_item ) ) ? '>' : ' ';
1634 if( y >= y_end ) break;
1637 attrset( A_REVERSE );
1639 mvnprintw( y++, 1, COLS - 2, "%c%s", c,
1640 p_sys->pp_plist[i_item]->psz_display );
1643 attroff( A_REVERSE );
1652 if( p_sys->i_box_type == BOX_SEARCH )
1654 DrawEmptyLine( p_sys->w, 7, 1, COLS-2 );
1655 if( p_sys->psz_search_chain )
1657 if( strlen( p_sys->psz_search_chain ) == 0 &&
1658 p_sys->psz_old_search != NULL )
1660 /* Searching next entry */
1661 mvnprintw( 7, 1, COLS-2, "Find: %s", p_sys->psz_old_search );
1665 mvnprintw( 7, 1, COLS-2, "Find: %s", p_sys->psz_search_chain );
1669 if( p_sys->i_box_type == BOX_OPEN )
1671 if( p_sys->psz_open_chain )
1673 DrawEmptyLine( p_sys->w, 7, 1, COLS-2 );
1674 mvnprintw( 7, 1, COLS-2, "Open: %s", p_sys->psz_open_chain );
1680 DrawEmptyLine( p_sys->w, y++, 1, COLS - 2 );
1685 *t_last_refresh = time( 0 );
1688 static playlist_item_t *PlaylistGetRoot( intf_thread_t *p_intf )
1690 intf_sys_t *p_sys = p_intf->p_sys;
1691 playlist_t *p_playlist = p_sys->p_playlist;
1693 if( p_playlist == NULL )
1698 switch( p_sys->i_current_view )
1701 return p_playlist->p_root_category;
1703 return p_playlist->p_root_onelevel;
1707 static void PlaylistRebuild( intf_thread_t *p_intf )
1709 intf_sys_t *p_sys = p_intf->p_sys;
1710 playlist_t *p_playlist = p_sys->p_playlist;
1712 if( p_playlist == NULL )
1717 vlc_mutex_lock( &p_playlist->object_lock );
1719 /* First clear the old one */
1720 PlaylistDestroy( p_intf );
1722 /* Build the new one */
1723 PlaylistAddNode( p_intf, PlaylistGetRoot( p_intf ), 0, "" );
1725 p_sys->b_need_update = VLC_FALSE;
1727 vlc_mutex_unlock( &p_playlist->object_lock );
1730 static void PlaylistAddNode( intf_thread_t *p_intf, playlist_item_t *p_node,
1731 int i, const char *c )
1733 intf_sys_t *p_sys = p_intf->p_sys;
1734 playlist_item_t *p_child;
1738 psz_tmp = (char *)malloc( strlen( c ) + 4 );
1739 if( psz_tmp == NULL ) return;
1740 for( k = 0; k < p_node->i_children; k++ )
1742 struct pl_item_t *p_pl_item;
1746 p_child = p_node->pp_children[k];
1747 i_size = strlen( c ) + strlen( p_child->p_input->psz_name ) + 4;
1748 buff = (char *)malloc( sizeof( char ) * i_size );
1749 p_pl_item = (struct pl_item_t *)malloc( sizeof( struct pl_item_t ) );
1750 if( p_pl_item == NULL || buff == NULL ) return;
1754 sprintf( buff, "%s%c-%s", c, k == p_node->i_children - 1 ?
1755 '`' : '|', p_child->p_input->psz_name );
1759 sprintf( buff, " %s", p_child->p_input->psz_name );
1761 p_pl_item->psz_display = strdup( buff );
1762 p_pl_item->p_item = p_child;
1763 INSERT_ELEM( p_sys->pp_plist, p_sys->i_plist_entries,
1764 p_sys->i_plist_entries, p_pl_item );
1768 if( p_child->i_children > 0 )
1770 sprintf( psz_tmp, "%s%c ", c,
1771 k == p_node->i_children - 1 ? ' ' : '|' );
1772 PlaylistAddNode( p_intf, p_child, i,
1773 strlen( c ) ? psz_tmp : " " );
1779 static int PlaylistChanged( vlc_object_t *p_this, const char *psz_variable,
1780 vlc_value_t oval, vlc_value_t nval, void *param )
1782 intf_thread_t *p_intf = (intf_thread_t *)param;
1783 p_intf->p_sys->b_need_update = VLC_TRUE;
1788 static inline vlc_bool_t PlaylistIsPlaying( intf_thread_t *p_intf,
1789 playlist_item_t *p_item )
1791 playlist_item_t *p_played_item = p_intf->p_sys->p_playlist->status.p_item;
1792 return( p_item != NULL && p_played_item != NULL &&
1793 p_item->p_input != NULL && p_played_item->p_input != NULL &&
1794 p_item->p_input->i_id == p_played_item->p_input->i_id );
1797 static void FindIndex( intf_thread_t *p_intf )
1799 intf_sys_t *p_sys = p_intf->p_sys;
1802 if( p_sys->i_box_plidx < p_sys->i_plist_entries &&
1803 p_sys->i_box_plidx >= 0 &&
1804 PlaylistIsPlaying( p_intf,
1805 p_sys->pp_plist[p_sys->i_box_plidx]->p_item ) )
1810 for( i = 0; i < p_sys->i_plist_entries; i++ )
1812 if( PlaylistIsPlaying( p_intf, p_sys->pp_plist[i]->p_item ) )
1814 p_sys->i_box_plidx = i;
1820 static void PlaylistDestroy( intf_thread_t *p_intf )
1822 intf_sys_t *p_sys = p_intf->p_sys;
1825 for( i = 0; i < p_sys->i_plist_entries; i++ )
1827 struct pl_item_t *p_pl_item = p_sys->pp_plist[i];
1828 free( p_pl_item->psz_display );
1829 REMOVE_ELEM( p_sys->pp_plist, p_sys->i_plist_entries, i );
1832 p_sys->pp_plist = NULL;
1833 p_sys->i_plist_entries = 0;
1836 static void Eject( intf_thread_t *p_intf )
1838 char *psz_device = NULL, *psz_parser, *psz_name;
1841 * Get the active input
1842 * Determine whether we can eject a media, ie it's a DVD, VCD or CD-DA
1843 * If it's neither of these, then return
1846 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1849 if( p_playlist == NULL )
1854 vlc_mutex_lock( &p_playlist->object_lock );
1856 if( p_playlist->status.p_item == NULL )
1858 vlc_mutex_unlock( &p_playlist->object_lock );
1859 vlc_object_release( p_playlist );
1863 psz_name = p_playlist->status.p_item->p_input->psz_name;
1867 if( !strncmp(psz_name, "dvd://", 4) )
1869 switch( psz_name[strlen("dvd://")] )
1873 psz_device = config_GetPsz( p_intf, "dvd" );
1876 /* Omit the first MRL-selector characters */
1877 psz_device = strdup( psz_name + strlen("dvd://" ) );
1881 else if( !strncmp(psz_name, VCD_MRL, strlen(VCD_MRL)) )
1883 switch( psz_name[strlen(VCD_MRL)] )
1887 psz_device = config_GetPsz( p_intf, VCD_MRL );
1890 /* Omit the beginning MRL-selector characters */
1891 psz_device = strdup( psz_name + strlen(VCD_MRL) );
1895 else if( !strncmp(psz_name, CDDA_MRL, strlen(CDDA_MRL) ) )
1897 switch( psz_name[strlen(CDDA_MRL)] )
1901 psz_device = config_GetPsz( p_intf, "cd-audio" );
1904 /* Omit the beginning MRL-selector characters */
1905 psz_device = strdup( psz_name + strlen(CDDA_MRL) );
1911 psz_device = strdup( psz_name );
1915 vlc_mutex_unlock( &p_playlist->object_lock );
1916 vlc_object_release( p_playlist );
1918 if( psz_device == NULL )
1923 /* Remove what we have after @ */
1924 psz_parser = psz_device;
1925 for( psz_parser = psz_device ; *psz_parser ; psz_parser++ )
1927 if( *psz_parser == '@' )
1934 /* If there's a stream playing, we aren't allowed to eject ! */
1935 if( p_intf->p_sys->p_input == NULL )
1937 msg_Dbg( p_intf, "ejecting %s", psz_device );
1939 intf_Eject( p_intf, psz_device );
1946 static int comp_dir_entries( const void *pp_dir_entry1,
1947 const void *pp_dir_entry2 )
1949 struct dir_entry_t *p_dir_entry1 = *(struct dir_entry_t**)pp_dir_entry1;
1950 struct dir_entry_t *p_dir_entry2 = *(struct dir_entry_t**)pp_dir_entry2;
1951 if ( p_dir_entry1->b_file == p_dir_entry2->b_file ) {
1952 return strcasecmp( p_dir_entry1->psz_path, p_dir_entry2->psz_path );
1956 return ( p_dir_entry1->b_file ? 1 : -1 );
1960 static void ReadDir( intf_thread_t *p_intf )
1962 intf_sys_t *p_sys = p_intf->p_sys;
1966 if( p_sys->psz_current_dir && *p_sys->psz_current_dir )
1971 p_current_dir = utf8_opendir( p_sys->psz_current_dir );
1973 if( p_current_dir == NULL )
1975 /* something went bad, get out of here ! */
1976 msg_Warn( p_intf, "cannot open directory `%s' (%m)",
1977 p_sys->psz_current_dir );
1981 /* Clean the old shit */
1982 for( i = 0; i < p_sys->i_dir_entries; i++ )
1984 struct dir_entry_t *p_dir_entry = p_sys->pp_dir_entries[i];
1985 free( p_dir_entry->psz_path );
1986 REMOVE_ELEM( p_sys->pp_dir_entries, p_sys->i_dir_entries, i );
1987 free( p_dir_entry );
1989 p_sys->pp_dir_entries = NULL;
1990 p_sys->i_dir_entries = 0;
1992 /* while we still have entries in the directory */
1993 while( ( psz_entry = utf8_readdir( p_current_dir ) ) != NULL )
1995 #if defined( S_ISDIR )
1996 struct stat stat_data;
1998 struct dir_entry_t *p_dir_entry;
1999 int i_size_entry = strlen( p_sys->psz_current_dir ) +
2000 strlen( psz_entry ) + 2;
2003 if( p_sys->b_show_hidden_files == VLC_FALSE &&
2004 ( strlen( psz_entry ) && psz_entry[0] == '.' ) &&
2005 strcmp( psz_entry, ".." ) )
2011 psz_uri = (char *)malloc( sizeof(char)*i_size_entry);
2012 sprintf( psz_uri, "%s/%s", p_sys->psz_current_dir, psz_entry );
2014 if( !( p_dir_entry = malloc( sizeof( struct dir_entry_t) ) ) )
2021 #if defined( S_ISDIR )
2022 if( !utf8_stat( psz_uri, &stat_data )
2023 && S_ISDIR(stat_data.st_mode) )
2024 /*#elif defined( DT_DIR )
2025 if( p_dir_content->d_type & DT_DIR )*/
2030 p_dir_entry->psz_path = strdup( psz_entry );
2031 p_dir_entry->b_file = VLC_FALSE;
2032 INSERT_ELEM( p_sys->pp_dir_entries, p_sys->i_dir_entries,
2033 p_sys->i_dir_entries, p_dir_entry );
2037 p_dir_entry->psz_path = strdup( psz_entry );
2038 p_dir_entry->b_file = VLC_TRUE;
2039 INSERT_ELEM( p_sys->pp_dir_entries, p_sys->i_dir_entries,
2040 p_sys->i_dir_entries, p_dir_entry );
2048 qsort( p_sys->pp_dir_entries, p_sys->i_dir_entries,
2049 sizeof(struct dir_entry_t*), &comp_dir_entries );
2051 closedir( p_current_dir );
2056 msg_Dbg( p_intf, "no current dir set" );
2061 static void PlayPause( intf_thread_t *p_intf )
2063 input_thread_t *p_input = p_intf->p_sys->p_input;
2068 var_Get( p_input, "state", &val );
2069 if( val.i_int != PAUSE_S )
2071 val.i_int = PAUSE_S;
2075 val.i_int = PLAYING_S;
2077 var_Set( p_input, "state", val );
2079 else if( p_intf->p_sys->p_playlist )
2081 playlist_Play( p_intf->p_sys->p_playlist );
2085 /****************************************************************************
2087 ****************************************************************************/
2088 static void DrawBox( WINDOW *win, int y, int x, int h, int w, const char *title )
2093 if( w > 3 && h > 2 )
2095 if( title == NULL ) title = "";
2096 i_len = strlen( title );
2098 if( i_len > w - 2 ) i_len = w - 2;
2100 mvwaddch( win, y, x, ACS_ULCORNER );
2101 mvwhline( win, y, x+1, ACS_HLINE, ( w-i_len-2)/2 );
2102 mvwprintw( win,y, x+1+(w-i_len-2)/2, "%s", title );
2103 mvwhline( win, y, x+(w-i_len)/2+i_len, ACS_HLINE, w - 1 - ((w-i_len)/2+i_len) );
2104 mvwaddch( win, y, x+w-1,ACS_URCORNER );
2106 for( i = 0; i < h-2; i++ )
2108 mvwaddch( win, y+i+1, x, ACS_VLINE );
2109 mvwaddch( win, y+i+1, x+w-1, ACS_VLINE );
2112 mvwaddch( win, y+h-1, x, ACS_LLCORNER );
2113 mvwhline( win, y+h-1, x+1, ACS_HLINE, w - 2 );
2114 mvwaddch( win, y+h-1, x+w-1, ACS_LRCORNER );
2118 static void DrawEmptyLine( WINDOW *win, int y, int x, int w )
2122 mvhline( y, x, ' ', w );
2126 static void DrawLine( WINDOW *win, int y, int x, int w )
2130 attrset( A_REVERSE );
2131 mvhline( y, x, ' ', w );
2132 attroff( A_REVERSE );