1 /*****************************************************************************
2 * ncurses.c : NCurses interface for vlc
3 *****************************************************************************
4 * Copyright © 2001-2007 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>
11 * Rafaël Carré <funman@videolanorg>
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
26 *****************************************************************************/
29 * Note that when we use wide characters (and link with libncursesw),
30 * we assume that an UTF8 locale is used (or compatible, such as ASCII).
31 * Other characters encodings are not supported.
34 /*****************************************************************************
36 *****************************************************************************/
41 #include <vlc_common.h>
42 #include <vlc_plugin.h>
45 # define _XOPEN_SOURCE_EXTENDED 1
51 #include <vlc_interface.h>
54 #include <vlc_charset.h>
55 #include <vlc_input.h>
57 #include <vlc_playlist.h>
62 #ifdef HAVE_SYS_STAT_H
63 # include <sys/stat.h>
65 #if (!defined( WIN32 ) || defined(__MINGW32__))
66 /* Mingw has its own version of dirent */
70 #define SEARCH_CHAIN_SIZE 20
71 #define OPEN_CHAIN_SIZE 50
73 /*****************************************************************************
75 *****************************************************************************/
76 static int Open ( vlc_object_t * );
77 static void Close ( vlc_object_t * );
79 static void Run ( intf_thread_t * );
80 static void PlayPause ( intf_thread_t * );
81 static void Eject ( intf_thread_t * );
83 static int HandleKey ( intf_thread_t *, int );
84 static void Redraw ( intf_thread_t *, time_t * );
86 static playlist_item_t *PlaylistGetRoot( intf_thread_t * );
87 static void PlaylistRebuild( intf_thread_t * );
88 static void PlaylistAddNode( intf_thread_t *, playlist_item_t *, int, const char *);
89 static void PlaylistDestroy( intf_thread_t * );
90 static int PlaylistChanged( vlc_object_t *, const char *, vlc_value_t,
91 vlc_value_t, void * );
92 static inline bool PlaylistIsPlaying( playlist_t *, playlist_item_t * );
93 static void FindIndex ( intf_thread_t *, playlist_t * );
94 static void SearchPlaylist ( intf_thread_t *, char * );
95 static int SubSearchPlaylist( intf_thread_t *, char *, int, int );
97 static void ManageSlider ( intf_thread_t * );
98 static void ReadDir ( intf_thread_t * );
100 static void start_color_and_pairs ( intf_thread_t * );
102 /*****************************************************************************
104 *****************************************************************************/
106 #define BROWSE_TEXT N_("Filebrowser starting point")
107 #define BROWSE_LONGTEXT N_( \
108 "This option allows you to specify the directory the ncurses filebrowser " \
109 "will show you initially.")
112 set_shortname( "Ncurses" )
113 set_description( N_("Ncurses interface") )
114 set_capability( "interface", 10 )
115 set_category( CAT_INTERFACE )
116 set_subcategory( SUBCAT_INTERFACE_MAIN )
117 set_callbacks( Open, Close )
118 add_shortcut( "curses" )
119 add_directory( "browse-dir", NULL, NULL, BROWSE_TEXT, BROWSE_LONGTEXT, false )
122 /*****************************************************************************
123 * intf_sys_t: description and status of ncurses interface
124 *****************************************************************************/
167 playlist_item_t *p_item;
172 input_thread_t *p_input;
173 playlist_t *p_playlist;
176 bool b_color_started;
186 int i_box_lines_total;
189 int i_box_plidx; /* Playlist index */
190 int b_box_plidx_follow;
191 int i_box_bidx; /* browser index */
193 playlist_item_t *p_node; /* current node */
197 msg_subscription_t* p_sub; /* message bank subscription */
199 char *psz_search_chain; /* for playlist searching */
200 char *psz_old_search; /* for searching next */
203 char *psz_open_chain;
204 #ifndef HAVE_NCURSESW
205 char psz_partial_keys[7];
208 char *psz_current_dir;
210 struct dir_entry_t **pp_dir_entries;
211 bool b_show_hidden_files;
213 int i_current_view; /* playlist view */
214 struct pl_item_t **pp_plist;
216 bool b_need_update; /* for playlist view */
219 static void DrawBox( WINDOW *win, int y, int x, int h, int w, const char *title, bool b_color );
220 static void DrawLine( WINDOW *win, int y, int x, int w );
221 static void DrawEmptyLine( WINDOW *win, int y, int x, int w );
223 /*****************************************************************************
224 * Open: initialize and create window
225 *****************************************************************************/
226 static int Open( vlc_object_t *p_this )
228 intf_thread_t *p_intf = (intf_thread_t *)p_this;
231 /* Allocate instance and initialize some members */
232 p_sys = p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
235 p_sys->p_node = NULL;
236 p_sys->p_input = NULL;
237 p_sys->f_slider = 0.0;
238 p_sys->f_slider_old = 0.0;
239 p_sys->i_box_type = BOX_PLAYLIST;
240 p_sys->i_box_lines = 0;
241 p_sys->i_box_start= 0;
242 p_sys->i_box_lines_total = 0;
243 p_sys->b_box_plidx_follow = true;
244 p_sys->b_box_cleared = false;
245 p_sys->i_box_plidx = 0;
246 p_sys->i_box_bidx = 0;
247 // FIXME p_sys->p_sub = msg_Subscribe( p_intf );
248 p_sys->b_color = var_CreateGetBool( p_intf, "color" );
249 p_sys->b_color_started = false;
251 #ifndef HAVE_NCURSESW
252 memset( p_sys->psz_partial_keys, 0, sizeof( p_sys->psz_partial_keys ) );
255 /* Initialize the curses library */
256 p_sys->w = initscr();
259 start_color_and_pairs( p_intf );
261 keypad( p_sys->w, TRUE );
262 /* Don't do NL -> CR/NL */
264 /* Take input chars one at a time */
268 /* Invisible cursor */
270 /* Non blocking wgetch() */
271 wtimeout( p_sys->w, 0 );
275 /* exported function */
276 p_intf->pf_run = Run;
278 /* Stop printing errors to the console */
279 freopen( "/dev/null", "wb", stderr );
281 /* Set defaul playlist view */
282 p_sys->i_current_view = VIEW_CATEGORY;
283 p_sys->pp_plist = NULL;
284 p_sys->i_plist_entries = 0;
285 p_sys->b_need_update = false;
287 /* Initialize search chain */
288 p_sys->psz_search_chain = malloc( SEARCH_CHAIN_SIZE + 1 );
289 p_sys->psz_old_search = NULL;
290 p_sys->i_before_search = 0;
292 /* Initialize open chain */
293 p_sys->psz_open_chain = malloc( OPEN_CHAIN_SIZE + 1 );
295 /* Initialize browser options */
296 char* psz_tmp = var_CreateGetString( p_intf, "browse-dir" );
297 if( psz_tmp && *psz_tmp )
298 p_sys->psz_current_dir = psz_tmp;
301 p_sys->psz_current_dir = config_GetUserDir( VLC_HOME_DIR );
305 p_sys->i_dir_entries = 0;
306 p_sys->pp_dir_entries = NULL;
307 p_sys->b_show_hidden_files = false;
313 /*****************************************************************************
314 * Close: destroy interface window
315 *****************************************************************************/
316 static void Close( vlc_object_t *p_this )
318 intf_thread_t *p_intf = (intf_thread_t *)p_this;
319 intf_sys_t *p_sys = p_intf->p_sys;
321 PlaylistDestroy( p_intf );
323 while( p_sys->i_dir_entries )
325 struct dir_entry_t *p_dir_entry = p_sys->pp_dir_entries[0];
326 free( p_dir_entry->psz_path );
327 REMOVE_ELEM( p_sys->pp_dir_entries, p_sys->i_dir_entries, 0 );
330 p_sys->pp_dir_entries = NULL;
332 free( p_sys->psz_current_dir );
333 free( p_sys->psz_search_chain );
334 free( p_sys->psz_old_search );
335 free( p_sys->psz_open_chain );
339 vlc_object_release( p_sys->p_input );
341 pl_Release( p_intf );
343 /* Close the ncurses interface */
346 // FIXME msg_Unsubscribe( p_intf, p_sys->p_sub );
348 /* Destroy structure */
352 /*****************************************************************************
353 * Run: ncurses thread
354 *****************************************************************************/
355 static void Run( intf_thread_t *p_intf )
357 intf_sys_t *p_sys = p_intf->p_sys;
358 playlist_t *p_playlist = pl_Hold( p_intf );
359 p_sys->p_playlist = p_playlist;
362 time_t t_last_refresh;
363 int canc = vlc_savecancel();
366 * force drawing the interface for the first time
368 t_last_refresh = ( time( 0 ) - 1);
370 * force building of the playlist array
372 PlaylistRebuild( p_intf );
373 var_AddCallback( p_playlist, "intf-change", PlaylistChanged, p_intf );
374 var_AddCallback( p_playlist, "playlist-item-append", PlaylistChanged, p_intf );
376 while( vlc_object_alive( p_intf ) )
378 msleep( INTF_IDLE_SLEEP );
380 /* Update the input */
381 if( p_sys->p_input == NULL )
383 p_sys->p_input = playlist_CurrentInput( p_playlist );
385 else if( p_sys->p_input->b_dead )
387 vlc_object_release( p_sys->p_input );
388 p_sys->p_input = NULL;
389 p_sys->f_slider = p_sys->f_slider_old = 0.0;
390 p_sys->b_box_cleared = false;
394 if( p_sys->b_box_plidx_follow && playlist_CurrentPlayingItem(p_playlist) )
397 FindIndex( p_intf, p_playlist );
402 while( ( i_key = wgetch( p_sys->w ) ) != -1 )
405 * HandleKey returns 1 if the screen needs to be redrawn
407 if( HandleKey( p_intf, i_key ) )
409 Redraw( p_intf, &t_last_refresh );
413 if( p_sys->f_slider > 0.0001 && !p_sys->b_box_cleared )
416 Redraw( p_intf, &t_last_refresh );
417 p_sys->b_box_cleared = true;
421 * redraw the screen every second
423 if( (time(0) - t_last_refresh) >= 1 )
425 ManageSlider( p_intf );
426 Redraw( p_intf, &t_last_refresh );
429 var_DelCallback( p_playlist, "intf-change", PlaylistChanged, p_intf );
430 var_DelCallback( p_playlist, "playlist-item-append", PlaylistChanged, p_intf );
431 vlc_restorecancel( canc );
434 /* following functions are local */
435 static void start_color_and_pairs( intf_thread_t *p_intf )
437 assert( p_intf->p_sys->b_color && !p_intf->p_sys->b_color_started );
441 p_intf->p_sys->b_color = false;
442 msg_Warn( p_intf, "Terminal doesn't support colors" );
448 /* Available colors: BLACK RED GREEN YELLOW BLUE MAGENTA CYAN WHITE */
450 /* untested, in all my terminals, !can_change_color() --funman */
451 if( can_change_color() )
452 init_color( COLOR_YELLOW, 960, 500, 0 ); /* YELLOW -> ORANGE */
455 init_pair( C_TITLE, COLOR_YELLOW, COLOR_BLACK );
457 /* jamaican playlist */
458 init_pair( C_PLAYLIST_1, COLOR_GREEN, COLOR_BLACK );
459 init_pair( C_PLAYLIST_2, COLOR_YELLOW, COLOR_BLACK );
460 init_pair( C_PLAYLIST_3, COLOR_RED, COLOR_BLACK );
462 /* used in DrawBox() */
463 init_pair( C_BOX, COLOR_CYAN, COLOR_BLACK );
464 /* Source, State, Position, Volume, Chapters, etc...*/
465 init_pair( C_STATUS, COLOR_BLUE, COLOR_BLACK );
467 /* VLC messages, keep the order from highest priority to lowest */
470 init_pair( C_INFO, COLOR_BLACK, COLOR_WHITE );
472 init_pair( C_ERROR, COLOR_RED, COLOR_BLACK );
474 init_pair( C_WARNING, COLOR_YELLOW, COLOR_BLACK );
476 init_pair( C_DEBUG, COLOR_WHITE, COLOR_BLACK );
478 /* Category title (help, info, metadata) */
479 init_pair( C_CATEGORY, COLOR_MAGENTA, COLOR_BLACK );
481 /* Folder (BOX_BROWSE) */
482 init_pair( C_FOLDER, COLOR_RED, COLOR_BLACK );
484 p_intf->p_sys->b_color_started = true;
487 #ifndef HAVE_NCURSESW
488 static char *KeyToUTF8( int i_key, char *psz_part )
491 int len = strlen( psz_part );
494 /* overflow error - should not happen */
495 memset( psz_part, 0, 6 );
499 psz_part[len] = (char)i_key;
501 psz_utf8 = FromLocaleDup( psz_part );
503 /* Ugly check for incomplete bytes sequences
504 * (in case of non-UTF8 multibyte local encoding) */
506 for( psz = psz_utf8; *psz; psz++ )
507 if( ( *psz == '?' ) && ( *psz_utf8 != '?' ) )
509 /* incomplete bytes sequence detected
510 * (VLC core inserted dummy question marks) */
515 /* Check for incomplete UTF8 bytes sequence */
516 if( EnsureUTF8( psz_utf8 ) == NULL )
522 memset( psz_part, 0, 6 );
527 static inline int RemoveLastUTF8Entity( char *psz, int len )
529 while( len && ( (psz[--len] & 0xc0) == 0x80 ) );
530 /* UTF8 continuation byte */
536 static int HandleKey( intf_thread_t *p_intf, int i_key )
538 intf_sys_t *p_sys = p_intf->p_sys;
541 playlist_t *p_playlist = pl_Hold( p_intf );
543 if( p_sys->i_box_type == BOX_PLAYLIST )
546 bool b_box_plidx_follow = false;
550 /* Playlist Settings */
552 var_ToggleBool( p_playlist, "random" );
555 var_ToggleBool( p_playlist, "loop" );
558 var_ToggleBool( p_playlist, "repeat" );
563 playlist_RecursiveNodeSort( p_playlist,
564 PlaylistGetRoot( p_intf ),
565 SORT_TITLE_NODES_FIRST, ORDER_NORMAL );
566 p_sys->b_need_update = true;
569 playlist_RecursiveNodeSort( p_playlist,
570 PlaylistGetRoot( p_intf ),
571 SORT_TITLE_NODES_FIRST, ORDER_REVERSE );
572 p_sys->b_need_update = true;
577 switch( p_sys->i_current_view )
580 p_sys->i_current_view = VIEW_ONELEVEL;
583 p_sys->i_current_view = VIEW_CATEGORY;
585 //p_sys->b_need_update = true;
586 PlaylistRebuild( p_intf );
589 /* Playlist navigation */
591 FindIndex( p_intf, p_playlist );
594 p_sys->i_box_plidx = 0;
597 /* workaround for FreeBSD + xterm:
598 * see http://www.nabble.com/curses-vs.-xterm-key-mismatch-t3574377.html */
602 p_sys->i_box_plidx = p_playlist->items.i_size - 1;
605 p_sys->i_box_plidx--;
608 p_sys->i_box_plidx++;
611 p_sys->i_box_plidx -= p_sys->i_box_lines;
614 p_sys->i_box_plidx += p_sys->i_box_lines;
621 playlist_item_t *p_item;
624 p_item = p_sys->pp_plist[p_sys->i_box_plidx]->p_item;
625 if( p_item->i_children == -1 )
627 playlist_DeleteFromInput( p_playlist,
628 p_item->p_input, pl_Locked );
632 playlist_NodeDelete( p_playlist, p_item,
636 PlaylistRebuild( p_intf );
643 if( !p_sys->pp_plist[p_sys->i_box_plidx] )
648 if( p_sys->pp_plist[p_sys->i_box_plidx]->p_item->i_children
651 playlist_item_t *p_item, *p_parent;
653 p_sys->pp_plist[p_sys->i_box_plidx]->p_item;
656 p_parent = p_playlist->p_root_onelevel;
657 while( p_parent->p_parent )
658 p_parent = p_parent->p_parent;
659 playlist_Control( p_playlist, PLAYLIST_VIEWPLAY,
660 pl_Unlocked, p_parent, p_item );
662 else if( p_sys->pp_plist[p_sys->i_box_plidx]->p_item->i_children
664 { /* We only want to set the current node */
665 playlist_Stop( p_playlist );
666 p_sys->p_node = p_sys->pp_plist[p_sys->i_box_plidx]->p_item;
670 p_sys->p_node = p_sys->pp_plist[p_sys->i_box_plidx]->p_item;
671 playlist_Control( p_playlist, PLAYLIST_VIEWPLAY, pl_Unlocked,
672 p_sys->pp_plist[p_sys->i_box_plidx]->p_item, NULL );
674 b_box_plidx_follow = true;
683 int i_max = p_sys->i_plist_entries;
684 if( p_sys->i_box_plidx >= i_max ) p_sys->i_box_plidx = i_max - 1;
685 if( p_sys->i_box_plidx < 0 ) p_sys->i_box_plidx = 0;
688 if( PlaylistIsPlaying( p_playlist,
689 p_sys->pp_plist[p_sys->i_box_plidx]->p_item ) )
690 b_box_plidx_follow = true;
692 p_sys->b_box_plidx_follow = b_box_plidx_follow;
696 if( p_sys->i_box_type == BOX_BROWSE )
699 /* Browser navigation */
703 p_sys->i_box_bidx = 0;
709 p_sys->i_box_bidx = p_sys->i_dir_entries - 1;
718 p_sys->i_box_bidx -= p_sys->i_box_lines;
721 p_sys->i_box_bidx += p_sys->i_box_lines;
723 case '.': /* Toggle show hidden files */
724 p_sys->b_show_hidden_files = ( p_sys->b_show_hidden_files ==
725 true ? false : true );
733 if( p_sys->pp_dir_entries[p_sys->i_box_bidx]->b_file || i_key == ' ' )
736 if( asprintf( &psz_uri, "%s://%s/%s",
737 p_sys->pp_dir_entries[p_sys->i_box_bidx]->b_file ?
738 "file" : "directory",
739 p_sys->psz_current_dir,
740 p_sys->pp_dir_entries[p_sys->i_box_bidx]->psz_path
746 playlist_item_t *p_parent = p_sys->p_node;
750 p_parent = playlist_CurrentPlayingItem(p_playlist) ? playlist_CurrentPlayingItem(p_playlist)->p_parent : NULL;
753 p_parent = p_playlist->p_local_onelevel;
756 while( p_parent->p_parent && p_parent->p_parent->p_parent )
757 p_parent = p_parent->p_parent;
759 playlist_Add( p_playlist, psz_uri, NULL, PLAYLIST_APPEND,
762 p_playlist->p_local_onelevel->p_input
765 p_sys->i_box_type = BOX_PLAYLIST;
770 if( asprintf( &(p_sys->psz_current_dir), "%s/%s", p_sys->psz_current_dir,
771 p_sys->pp_dir_entries[p_sys->i_box_bidx]->psz_path ) != -1 )
781 if( p_sys->i_box_bidx >= p_sys->i_dir_entries ) p_sys->i_box_bidx = p_sys->i_dir_entries - 1;
782 if( p_sys->i_box_bidx < 0 ) p_sys->i_box_bidx = 0;
786 else if( p_sys->i_box_type == BOX_HELP || p_sys->i_box_type == BOX_INFO ||
787 p_sys->i_box_type == BOX_META || p_sys->i_box_type == BOX_STATS ||
788 p_sys->i_box_type == BOX_OBJECTS )
793 p_sys->i_box_start = 0;
799 p_sys->i_box_start = p_sys->i_box_lines_total - 1;
802 if( p_sys->i_box_start > 0 ) p_sys->i_box_start--;
805 if( p_sys->i_box_start < p_sys->i_box_lines_total - 1 )
807 p_sys->i_box_start++;
811 p_sys->i_box_start -= p_sys->i_box_lines;
812 if( p_sys->i_box_start < 0 ) p_sys->i_box_start = 0;
815 p_sys->i_box_start += p_sys->i_box_lines;
816 if( p_sys->i_box_start >= p_sys->i_box_lines_total )
818 p_sys->i_box_start = p_sys->i_box_lines_total - 1;
825 else if( p_sys->i_box_type == BOX_NONE )
831 ManageSlider( p_intf );
837 p_sys->f_slider = 99.9;
838 ManageSlider( p_intf );
841 p_sys->f_slider += 5.0;
842 if( p_sys->f_slider >= 99.0 ) p_sys->f_slider = 99.0;
843 ManageSlider( p_intf );
846 p_sys->f_slider -= 5.0;
847 if( p_sys->f_slider < 0.0 ) p_sys->f_slider = 0.0;
848 ManageSlider( p_intf );
855 else if( p_sys->i_box_type == BOX_SEARCH && p_sys->psz_search_chain )
857 int i_chain_len = strlen( p_sys->psz_search_chain );
867 if( i_chain_len > 0 )
869 p_sys->psz_old_search = strdup( p_sys->psz_search_chain );
871 else if( p_sys->psz_old_search )
873 SearchPlaylist( p_intf, p_sys->psz_old_search );
875 p_sys->i_box_type = BOX_PLAYLIST;
878 /* Alt+key combinations return 2 keys in the terminal keyboard:
879 * ESC, and the 2nd key.
880 * If some other key is available immediately (where immediately
881 * means after wgetch() 1 second delay ), that means that the
882 * ESC key was not pressed.
884 * man 3X curs_getch says:
886 * Use of the escape key by a programmer for a single
887 * character function is discouraged, as it will cause a delay
888 * of up to one second while the keypad code looks for a
889 * following function-key sequence.
892 if( wgetch( p_sys->w ) != ERR )
897 p_sys->i_box_plidx = p_sys->i_before_search;
898 p_sys->i_box_type = BOX_PLAYLIST;
902 RemoveLastUTF8Entity( p_sys->psz_search_chain, i_chain_len );
907 if( i_chain_len + 1 < SEARCH_CHAIN_SIZE )
909 p_sys->psz_search_chain[i_chain_len] = (char) i_key;
910 p_sys->psz_search_chain[i_chain_len + 1] = '\0';
913 char *psz_utf8 = KeyToUTF8( i_key, p_sys->psz_partial_keys );
915 if( psz_utf8 != NULL )
917 if( i_chain_len + strlen( psz_utf8 ) < SEARCH_CHAIN_SIZE )
919 strcpy( p_sys->psz_search_chain + i_chain_len,
928 free( p_sys->psz_old_search );
929 p_sys->psz_old_search = NULL;
930 SearchPlaylist( p_intf, p_sys->psz_search_chain );
933 else if( p_sys->i_box_type == BOX_OPEN && p_sys->psz_open_chain )
935 int i_chain_len = strlen( p_sys->psz_open_chain );
946 if( i_chain_len > 0 )
948 playlist_item_t *p_parent = p_sys->p_node;
952 p_parent = playlist_CurrentPlayingItem(p_playlist) ? playlist_CurrentPlayingItem(p_playlist)->p_parent : NULL;
954 p_parent = p_playlist->p_local_onelevel;
956 while( p_parent->p_parent && p_parent->p_parent->p_parent )
957 p_parent = p_parent->p_parent;
960 playlist_Add( p_playlist, p_sys->psz_open_chain, NULL,
961 PLAYLIST_APPEND|PLAYLIST_GO, PLAYLIST_END,
963 p_playlist->p_local_onelevel->p_input
966 p_sys->b_box_plidx_follow = true;
968 p_sys->i_box_type = BOX_PLAYLIST;
971 if( wgetch( p_sys->w ) != ERR )
976 p_sys->i_box_type = BOX_PLAYLIST;
980 RemoveLastUTF8Entity( p_sys->psz_open_chain, i_chain_len );
985 if( i_chain_len + 1 < OPEN_CHAIN_SIZE )
987 p_sys->psz_open_chain[i_chain_len] = (char) i_key;
988 p_sys->psz_open_chain[i_chain_len + 1] = '\0';
991 char *psz_utf8 = KeyToUTF8( i_key, p_sys->psz_partial_keys );
993 if( psz_utf8 != NULL )
995 if( i_chain_len + strlen( psz_utf8 ) < OPEN_CHAIN_SIZE )
997 strcpy( p_sys->psz_open_chain + i_chain_len,
1012 case 0x1b: /* ESC */
1013 if( wgetch( p_sys->w ) != ERR )
1021 libvlc_Quit( p_intf->p_libvlc );
1027 if( p_sys->i_box_type == BOX_INFO )
1028 p_sys->i_box_type = BOX_NONE;
1030 p_sys->i_box_type = BOX_INFO;
1031 p_sys->i_box_lines_total = 0;
1034 if( p_sys->i_box_type == BOX_META )
1035 p_sys->i_box_type = BOX_NONE;
1037 p_sys->i_box_type = BOX_META;
1038 p_sys->i_box_lines_total = 0;
1041 if( p_sys->i_box_type == BOX_LOG )
1042 p_sys->i_box_type = BOX_NONE;
1044 p_sys->i_box_type = BOX_LOG;
1047 if( p_sys->i_box_type == BOX_PLAYLIST )
1048 p_sys->i_box_type = BOX_NONE;
1050 p_sys->i_box_type = BOX_PLAYLIST;
1053 if( p_sys->i_box_type == BOX_BROWSE )
1054 p_sys->i_box_type = BOX_NONE;
1056 p_sys->i_box_type = BOX_BROWSE;
1059 if( p_sys->i_box_type == BOX_OBJECTS )
1060 p_sys->i_box_type = BOX_NONE;
1062 p_sys->i_box_type = BOX_OBJECTS;
1065 if( p_sys->i_box_type == BOX_STATS )
1066 p_sys->i_box_type = BOX_NONE;
1068 p_sys->i_box_type = BOX_STATS;
1071 p_sys->b_color = !p_sys->b_color;
1072 if( p_sys->b_color && !p_sys->b_color_started )
1073 start_color_and_pairs( p_intf );
1077 if( p_sys->i_box_type == BOX_HELP )
1078 p_sys->i_box_type = BOX_NONE;
1080 p_sys->i_box_type = BOX_HELP;
1081 p_sys->i_box_lines_total = 0;
1084 if( p_sys->i_box_type != BOX_SEARCH )
1086 if( p_sys->psz_search_chain )
1088 p_sys->psz_search_chain[0] = '\0';
1089 p_sys->b_box_plidx_follow = false;
1090 p_sys->i_before_search = p_sys->i_box_plidx;
1091 p_sys->i_box_type = BOX_SEARCH;
1095 case 'A': /* Open */
1096 if( p_sys->i_box_type != BOX_OPEN )
1098 if( p_sys->psz_open_chain )
1100 p_sys->psz_open_chain[0] = '\0';
1101 p_sys->i_box_type = BOX_OPEN;
1108 p_sys->f_slider += 1.0;
1109 if( p_sys->f_slider > 99.9 ) p_sys->f_slider = 99.9;
1110 ManageSlider( p_intf );
1114 p_sys->f_slider -= 1.0;
1115 if( p_sys->f_slider < 0.0 ) p_sys->f_slider = 0.0;
1116 ManageSlider( p_intf );
1119 /* Common control */
1122 if( p_intf->p_sys->p_input )
1124 vout_thread_t *p_vout;
1125 p_vout = vlc_object_find( p_intf->p_sys->p_input,
1126 VLC_OBJECT_VOUT, FIND_CHILD );
1129 var_ToggleBool( p_vout, "fullscreen" );
1130 vlc_object_release( p_vout );
1134 var_ToggleBool( p_playlist, "fullscreen" );
1142 PlayPause( p_intf );
1146 playlist_Stop( p_playlist );
1154 if( p_sys->p_input )
1155 var_TriggerCallback( p_sys->p_input, "prev-title" );
1159 if( p_sys->p_input )
1160 var_TriggerCallback( p_sys->p_input, "next-title" );
1164 if( p_sys->p_input )
1165 var_TriggerCallback( p_sys->p_input, "prev-chapter" );
1169 if( p_sys->p_input )
1170 var_TriggerCallback( p_sys->p_input, "next-chapter" );
1174 playlist_Prev( p_playlist );
1179 playlist_Next( p_playlist );
1184 aout_VolumeUp( p_playlist, 1, NULL );
1189 aout_VolumeDown( p_playlist, 1, NULL );
1194 * ^l should clear and redraw the screen
1206 pl_Release( p_intf );
1210 static void ManageSlider( intf_thread_t *p_intf )
1212 intf_sys_t *p_sys = p_intf->p_sys;
1213 input_thread_t *p_input = p_sys->p_input;
1216 if( p_input == NULL )
1220 var_Get( p_input, "state", &val );
1221 if( val.i_int != PLAYING_S )
1226 var_Get( p_input, "position", &val );
1227 if( p_sys->f_slider == p_sys->f_slider_old )
1230 p_sys->f_slider_old = 100 * val.f_float;
1234 p_sys->f_slider_old = p_sys->f_slider;
1236 val.f_float = p_sys->f_slider / 100.0;
1237 var_Set( p_input, "position", val );
1241 static void SearchPlaylist( intf_thread_t *p_intf, char *psz_searchstring )
1246 intf_sys_t *p_sys = p_intf->p_sys;
1248 if( p_sys->i_before_search >= 0 )
1250 i_first = p_sys->i_before_search;
1253 if( ( ! psz_searchstring ) || strlen( psz_searchstring ) <= 0 )
1255 p_sys->i_box_plidx = p_sys->i_before_search;
1259 i_max = p_sys->i_plist_entries;
1261 i_item = SubSearchPlaylist( p_intf, psz_searchstring, i_first + 1, i_max );
1264 i_item = SubSearchPlaylist( p_intf, psz_searchstring, 0, i_first );
1267 if( i_item < 0 || i_item >= i_max ) return;
1269 p_sys->i_box_plidx = i_item;
1272 static int SubSearchPlaylist( intf_thread_t *p_intf, char *psz_searchstring,
1273 int i_start, int i_stop )
1275 intf_sys_t *p_sys = p_intf->p_sys;
1278 for( i = i_start + 1; i < i_stop; i++ )
1280 if( strcasestr( p_sys->pp_plist[i]->psz_display,
1281 psz_searchstring ) != NULL )
1292 static void mvnprintw( int y, int x, int w, const char *p_fmt, ... )
1301 va_start( vl_args, p_fmt );
1302 if( vasprintf( &p_buf, p_fmt, vl_args ) == -1 )
1306 i_len = strlen( p_buf );
1308 #ifdef HAVE_NCURSESW
1309 wchar_t psz_wide[i_len + 1];
1311 EnsureUTF8( p_buf );
1312 size_t i_char_len = mbstowcs( psz_wide, p_buf, i_len );
1314 size_t i_width; /* number of columns */
1316 if( i_char_len == (size_t)-1 )
1317 /* an invalid character was encountered */
1324 i_width = wcswidth( psz_wide, i_char_len );
1325 if( i_width == (size_t)-1 )
1327 /* a non printable character was encountered */
1331 for( i = 0 ; i < i_char_len ; i++ )
1333 i_cwidth = wcwidth( psz_wide[i] );
1334 if( i_cwidth != -1 )
1335 i_width += i_cwidth;
1339 if( i_width > (size_t)w )
1341 int i_total_width = 0;
1343 while( i_total_width < w )
1345 i_total_width += wcwidth( psz_wide[i] );
1346 if( w > 7 && i_total_width >= w/2 )
1349 psz_wide[i+1] = '.';
1350 i_total_width -= wcwidth( psz_wide[i] ) - 2;
1353 /* we require this check only if at least one character
1354 * 4 or more columns wide exists (which i doubt) */
1355 psz_wide[i-1] = '.';
1356 i_total_width -= wcwidth( psz_wide[i-1] ) - 1;
1359 /* find the widest string */
1360 int j, i_2nd_width = 0;
1361 for( j = i_char_len - 1; i_2nd_width < w - i_total_width; j-- )
1362 i_2nd_width += wcwidth( psz_wide[j] );
1364 /* we already have i_total_width columns filled, and we can't
1365 * have more than w columns */
1366 if( i_2nd_width > w - i_total_width )
1369 wmemmove( &psz_wide[i+2], &psz_wide[j+1], i_char_len - j - 1 );
1370 psz_wide[i + 2 + i_char_len - j - 1] = '\0';
1375 if( w <= 7 ) /* we don't add the '...' else we lose too much chars */
1378 size_t i_wlen = wcslen( psz_wide ) * 6 + 1; /* worst case */
1379 char psz_ellipsized[i_wlen];
1380 wcstombs( psz_ellipsized, psz_wide, i_wlen );
1381 mvprintw( y, x, "%s", psz_ellipsized );
1385 mvprintw( y, x, "%s", p_buf );
1386 mvhline( y, x + i_width, ' ', w - i_width );
1392 int i_cut = i_len - w;
1393 int x1 = i_len/2 - i_cut/2;
1394 int x2 = x1 + i_cut;
1398 memmove( &p_buf[x1], &p_buf[x2], i_len - x2 );
1407 char *psz_local = ToLocale( p_buf );
1408 mvprintw( y, x, "%s", psz_local );
1409 LocaleFree( p_buf );
1413 char *psz_local = ToLocale( p_buf );
1414 mvprintw( y, x, "%s", psz_local );
1415 LocaleFree( p_buf );
1416 mvhline( y, x + i_len, ' ', w - i_len );
1421 static void MainBoxWrite( intf_thread_t *p_intf, int l, int x, const char *p_fmt, ... )
1423 intf_sys_t *p_sys = p_intf->p_sys;
1428 if( l < p_sys->i_box_start || l - p_sys->i_box_start >= p_sys->i_box_lines )
1433 va_start( vl_args, p_fmt );
1434 if( vasprintf( &p_buf, p_fmt, vl_args ) == -1 )
1438 mvnprintw( p_sys->i_box_y + l - p_sys->i_box_start, x, COLS - x - 1, "%s", p_buf );
1442 static void DumpObject( intf_thread_t *p_intf, int *l, vlc_object_t *p_obj, int i_level )
1444 char *psz_name = vlc_object_get_name( p_obj );
1447 MainBoxWrite( p_intf, (*l)++, 1 + 2 * i_level, "%s \"%s\" (%p)",
1448 p_obj->psz_object_type, psz_name, p_obj );
1452 MainBoxWrite( p_intf, (*l)++, 1 + 2 * i_level, "%s (%o)",
1453 p_obj->psz_object_type, p_obj );
1455 vlc_list_t *list = vlc_list_children( p_obj );
1456 for( int i = 0; i < list->i_count ; i++ )
1458 MainBoxWrite( p_intf, *l, 1 + 2 * i_level,
1459 i == list->i_count - 1 ? "`-" : "|-" );
1460 DumpObject( p_intf, l, list->p_values[i].p_object, i_level + 1 );
1462 vlc_list_release( list );
1465 static void Redraw( intf_thread_t *p_intf, time_t *t_last_refresh )
1467 intf_sys_t *p_sys = p_intf->p_sys;
1468 input_thread_t *p_input = p_sys->p_input;
1469 playlist_t *p_playlist = pl_Hold( p_intf );
1475 attrset( A_REVERSE );
1476 int i_len = strlen( "VLC media player "PACKAGE_VERSION );
1477 int mid = ( COLS - i_len ) / 2;
1480 int i_size = ( COLS > i_len + 1 ) ? COLS : i_len + 1;
1481 char psz_title[i_size];
1482 memset( psz_title, ' ', mid );
1483 if( p_sys->b_color )
1484 wcolor_set( p_sys->w, C_TITLE, NULL );
1485 snprintf( &psz_title[mid], i_size, "VLC media player "PACKAGE_VERSION );
1486 mvnprintw( y, 0, COLS, "%s", psz_title );
1487 attroff( A_REVERSE );
1490 if( p_sys->b_color )
1491 wcolor_set( p_sys->w, C_STATUS, NULL );
1495 if( asprintf( &psz_state, "%s%s%s",
1496 var_GetBool( p_playlist, "repeat" ) ? _( "[Repeat] " ) : "",
1497 var_GetBool( p_playlist, "random" ) ? _( "[Random] " ) : "",
1498 var_GetBool( p_playlist, "loop" ) ? _( "[Loop]" ) : "" ) == -1 )
1501 if( p_input && !p_input->b_dead )
1503 char buf1[MSTRTIME_MAX_SIZE];
1504 char buf2[MSTRTIME_MAX_SIZE];
1508 char *psz_uri = input_item_GetURI( input_GetItem( p_input ) );
1509 mvnprintw( y++, 0, COLS, _(" Source : %s"), psz_uri );
1513 var_Get( p_input, "state", &val );
1514 if( val.i_int == PLAYING_S )
1516 mvnprintw( y++, 0, COLS, _(" State : Playing %s"), psz_state );
1518 else if( val.i_int == OPENING_S )
1520 mvnprintw( y++, 0, COLS, _(" State : Opening/Connecting %s"), psz_state );
1522 else if( val.i_int == PAUSE_S )
1524 mvnprintw( y++, 0, COLS, _(" State : Paused %s"), psz_state );
1527 if( val.i_int != INIT_S && val.i_int != END_S )
1529 audio_volume_t i_volume;
1532 var_Get( p_input, "time", &val );
1533 msecstotimestr( buf1, val.i_time / 1000 );
1535 var_Get( p_input, "length", &val );
1536 msecstotimestr( buf2, val.i_time / 1000 );
1538 mvnprintw( y++, 0, COLS, _(" Position : %s/%s (%.2f%%)"), buf1, buf2, p_sys->f_slider );
1541 aout_VolumeGet( p_playlist, &i_volume );
1542 mvnprintw( y++, 0, COLS, _(" Volume : %i%%"), i_volume*200/AOUT_VOLUME_MAX );
1545 if( !var_Get( p_input, "title", &val ) )
1547 int i_title_count = var_CountChoices( p_input, "title" );
1548 if( i_title_count > 0 )
1549 mvnprintw( y++, 0, COLS, _(" Title : %d/%d"), val.i_int, i_title_count );
1553 if( !var_Get( p_input, "chapter", &val ) )
1555 int i_chapter_count = var_CountChoices( p_input, "chapter" );
1556 if( i_chapter_count > 0 )
1557 mvnprintw( y++, 0, COLS, _(" Chapter : %d/%d"), val.i_int, i_chapter_count );
1567 mvnprintw( y++, 0, COLS, _(" Source: <no current item> %s"), psz_state );
1568 DrawEmptyLine( p_sys->w, y++, 0, COLS );
1569 mvnprintw( y++, 0, COLS, _(" [ h for help ]") );
1570 DrawEmptyLine( p_sys->w, y++, 0, COLS );
1573 if( p_sys->b_color )
1574 wcolor_set( p_sys->w, C_DEFAULT, NULL );
1576 DrawBox( p_sys->w, y, 0, 3, COLS, "", p_sys->b_color );
1577 DrawEmptyLine( p_sys->w, y+1, 1, COLS-2);
1578 DrawLine( p_sys->w, y+1, 1, (int)(p_intf->p_sys->f_slider/100.0 * (COLS -2)) );
1581 p_sys->i_box_y = y + 1;
1582 p_sys->i_box_lines = LINES - y - 2;
1587 if( p_sys->i_box_type == BOX_HELP )
1591 DrawBox( p_sys->w, y++, 0, h, COLS, _(" Help "), p_sys->b_color );
1593 if( p_sys->b_color )
1594 wcolor_set( p_sys->w, C_CATEGORY, NULL );
1595 MainBoxWrite( p_intf, l++, 1, _("[Display]") );
1596 if( p_sys->b_color )
1597 wcolor_set( p_sys->w, C_DEFAULT, NULL );
1598 MainBoxWrite( p_intf, l++, 1, _(" h,H Show/Hide help box") );
1599 MainBoxWrite( p_intf, l++, 1, _(" i Show/Hide info box") );
1600 MainBoxWrite( p_intf, l++, 1, _(" m Show/Hide metadata box") );
1601 MainBoxWrite( p_intf, l++, 1, _(" L Show/Hide messages box") );
1602 MainBoxWrite( p_intf, l++, 1, _(" P Show/Hide playlist box") );
1603 MainBoxWrite( p_intf, l++, 1, _(" B Show/Hide filebrowser") );
1604 MainBoxWrite( p_intf, l++, 1, _(" x Show/Hide objects box") );
1605 MainBoxWrite( p_intf, l++, 1, _(" S Show/Hide statistics box" ) );
1606 MainBoxWrite( p_intf, l++, 1, _(" c Switch color on/off") );
1607 MainBoxWrite( p_intf, l++, 1, _(" Esc Close Add/Search entry") );
1608 MainBoxWrite( p_intf, l++, 1, "" );
1610 if( p_sys->b_color )
1611 wcolor_set( p_sys->w, C_CATEGORY, NULL );
1612 MainBoxWrite( p_intf, l++, 1, _("[Global]") );
1613 if( p_sys->b_color )
1614 wcolor_set( p_sys->w, C_DEFAULT, NULL );
1615 MainBoxWrite( p_intf, l++, 1, _(" q, Q, Esc Quit") );
1616 MainBoxWrite( p_intf, l++, 1, _(" s Stop") );
1617 MainBoxWrite( p_intf, l++, 1, _(" <space> Pause/Play") );
1618 MainBoxWrite( p_intf, l++, 1, _(" f Toggle Fullscreen") );
1619 MainBoxWrite( p_intf, l++, 1, _(" n, p Next/Previous playlist item") );
1620 MainBoxWrite( p_intf, l++, 1, _(" [, ] Next/Previous title") );
1621 MainBoxWrite( p_intf, l++, 1, _(" <, > Next/Previous chapter") );
1622 MainBoxWrite( p_intf, l++, 1, _(" <right> Seek +1%%") );
1623 MainBoxWrite( p_intf, l++, 1, _(" <left> Seek -1%%") );
1624 MainBoxWrite( p_intf, l++, 1, _(" a Volume Up") );
1625 MainBoxWrite( p_intf, l++, 1, _(" z Volume Down") );
1626 MainBoxWrite( p_intf, l++, 1, "" );
1628 if( p_sys->b_color )
1629 wcolor_set( p_sys->w, C_CATEGORY, NULL );
1630 MainBoxWrite( p_intf, l++, 1, _("[Playlist]") );
1631 if( p_sys->b_color )
1632 wcolor_set( p_sys->w, C_DEFAULT, NULL );
1633 MainBoxWrite( p_intf, l++, 1, _(" r Toggle Random playing") );
1634 MainBoxWrite( p_intf, l++, 1, _(" l Toggle Loop Playlist") );
1635 MainBoxWrite( p_intf, l++, 1, _(" R Toggle Repeat item") );
1636 MainBoxWrite( p_intf, l++, 1, _(" o Order Playlist by title") );
1637 MainBoxWrite( p_intf, l++, 1, _(" O Reverse order Playlist by title") );
1638 MainBoxWrite( p_intf, l++, 1, _(" g Go to the current playing item") );
1639 MainBoxWrite( p_intf, l++, 1, _(" / Look for an item") );
1640 MainBoxWrite( p_intf, l++, 1, _(" A Add an entry") );
1641 MainBoxWrite( p_intf, l++, 1, _(" D, <del> Delete an entry") );
1642 MainBoxWrite( p_intf, l++, 1, _(" <backspace> Delete an entry") );
1643 MainBoxWrite( p_intf, l++, 1, _(" e Eject (if stopped)") );
1644 MainBoxWrite( p_intf, l++, 1, "" );
1646 if( p_sys->b_color )
1647 wcolor_set( p_sys->w, C_CATEGORY, NULL );
1648 MainBoxWrite( p_intf, l++, 1, _("[Filebrowser]") );
1649 if( p_sys->b_color )
1650 wcolor_set( p_sys->w, C_DEFAULT, NULL );
1651 MainBoxWrite( p_intf, l++, 1, _(" <enter> Add the selected file to the playlist") );
1652 MainBoxWrite( p_intf, l++, 1, _(" <space> Add the selected directory to the playlist") );
1653 MainBoxWrite( p_intf, l++, 1, _(" . Show/Hide hidden files") );
1654 MainBoxWrite( p_intf, l++, 1, "" );
1656 if( p_sys->b_color )
1657 wcolor_set( p_sys->w, C_CATEGORY, NULL );
1658 MainBoxWrite( p_intf, l++, 1, _("[Boxes]") );
1659 if( p_sys->b_color )
1660 wcolor_set( p_sys->w, C_DEFAULT, NULL );
1661 MainBoxWrite( p_intf, l++, 1, _(" <up>,<down> Navigate through the box line by line") );
1662 MainBoxWrite( p_intf, l++, 1, _(" <pgup>,<pgdown> Navigate through the box page by page") );
1663 MainBoxWrite( p_intf, l++, 1, "" );
1665 if( p_sys->b_color )
1666 wcolor_set( p_sys->w, C_CATEGORY, NULL );
1667 MainBoxWrite( p_intf, l++, 1, _("[Player]") );
1668 if( p_sys->b_color )
1669 wcolor_set( p_sys->w, C_DEFAULT, NULL );
1670 MainBoxWrite( p_intf, l++, 1, _(" <up>,<down> Seek +/-5%%") );
1671 MainBoxWrite( p_intf, l++, 1, "" );
1673 if( p_sys->b_color )
1674 wcolor_set( p_sys->w, C_CATEGORY, NULL );
1675 MainBoxWrite( p_intf, l++, 1, _("[Miscellaneous]") );
1676 if( p_sys->b_color )
1677 wcolor_set( p_sys->w, C_DEFAULT, NULL );
1678 MainBoxWrite( p_intf, l++, 1, _(" Ctrl-l Refresh the screen") );
1680 p_sys->i_box_lines_total = l;
1681 if( p_sys->i_box_start >= p_sys->i_box_lines_total )
1683 p_sys->i_box_start = p_sys->i_box_lines_total - 1;
1686 if( l - p_sys->i_box_start < p_sys->i_box_lines )
1688 y += l - p_sys->i_box_start;
1692 y += p_sys->i_box_lines;
1695 else if( p_sys->i_box_type == BOX_INFO )
1699 DrawBox( p_sys->w, y++, 0, h, COLS, _(" Information "), p_sys->b_color );
1704 vlc_mutex_lock( &input_GetItem(p_input)->lock );
1705 for( i = 0; i < input_GetItem(p_input)->i_categories; i++ )
1707 info_category_t *p_category = input_GetItem(p_input)->pp_categories[i];
1708 if( y >= y_end ) break;
1709 if( p_sys->b_color )
1710 wcolor_set( p_sys->w, C_CATEGORY, NULL );
1711 MainBoxWrite( p_intf, l++, 1, _(" [%s]"), p_category->psz_name );
1712 if( p_sys->b_color )
1713 wcolor_set( p_sys->w, C_DEFAULT, NULL );
1714 for( j = 0; j < p_category->i_infos; j++ )
1716 info_t *p_info = p_category->pp_infos[j];
1717 if( y >= y_end ) break;
1718 MainBoxWrite( p_intf, l++, 1, _(" %s: %s"), p_info->psz_name, p_info->psz_value );
1721 vlc_mutex_unlock( &input_GetItem(p_input)->lock );
1725 MainBoxWrite( p_intf, l++, 1, _("No item currently playing") );
1727 p_sys->i_box_lines_total = l;
1728 if( p_sys->i_box_start >= p_sys->i_box_lines_total )
1730 p_sys->i_box_start = p_sys->i_box_lines_total - 1;
1733 if( l - p_sys->i_box_start < p_sys->i_box_lines )
1735 y += l - p_sys->i_box_start;
1739 y += p_sys->i_box_lines;
1742 else if( p_sys->i_box_type == BOX_META )
1747 DrawBox( p_sys->w, y++, 0, h, COLS, _("Meta-information"),
1753 input_item_t *p_item = input_GetItem( p_input );
1754 vlc_mutex_lock( &p_item->lock );
1755 for( i=0; i<VLC_META_TYPE_COUNT; i++ )
1757 if( y >= y_end ) break;
1758 char *psz_meta = vlc_meta_Get( p_item->p_meta, i );
1759 if( psz_meta && *psz_meta )
1761 const char *psz_meta_title;
1765 psz_meta_title = VLC_META_TITLE; break;
1767 psz_meta_title = VLC_META_ARTIST; break;
1769 psz_meta_title = VLC_META_GENRE ; break;
1771 psz_meta_title = VLC_META_COPYRIGHT; break;
1773 psz_meta_title = VLC_META_ALBUM; break;
1775 psz_meta_title = VLC_META_TRACK_NUMBER; break;
1777 psz_meta_title = VLC_META_DESCRIPTION; break;
1779 psz_meta_title = VLC_META_RATING; break;
1781 psz_meta_title = VLC_META_DATE; break;
1783 psz_meta_title = VLC_META_SETTING; break;
1785 psz_meta_title = VLC_META_URL; break;
1787 psz_meta_title = VLC_META_LANGUAGE; break;
1789 psz_meta_title = VLC_META_NOW_PLAYING; break;
1791 psz_meta_title = VLC_META_PUBLISHER; break;
1793 psz_meta_title = VLC_META_ENCODED_BY; break;
1795 psz_meta_title = VLC_META_ART_URL; break;
1797 psz_meta_title = VLC_META_TRACKID; break;
1799 psz_meta_title = ""; break;
1801 if( p_sys->b_color )
1802 wcolor_set( p_sys->w, C_CATEGORY, NULL );
1803 MainBoxWrite( p_intf, l++, 1, " [%s]", psz_meta_title );
1804 if( p_sys->b_color )
1805 wcolor_set( p_sys->w, C_DEFAULT, NULL );
1806 MainBoxWrite( p_intf, l++, 1, " %s", psz_meta );
1809 vlc_mutex_unlock( &p_item->lock );
1813 MainBoxWrite( p_intf, l++, 1, _("No item currently playing") );
1815 p_sys->i_box_lines_total = l;
1816 if( p_sys->i_box_start >= p_sys->i_box_lines_total )
1818 p_sys->i_box_start = p_sys->i_box_lines_total - 1;
1821 if( l - p_sys->i_box_start < p_sys->i_box_lines )
1823 y += l - p_sys->i_box_start;
1827 y += p_sys->i_box_lines;
1830 else if( p_sys->i_box_type == BOX_LOG )
1832 #warning Deprecated API
1838 DrawBox( p_sys->w, y++, 0, h, COLS, _(" Logs "), p_sys->b_color );
1841 i_start = p_intf->p_sys->p_sub->i_start;
1843 vlc_mutex_lock( p_intf->p_sys->p_sub->p_lock );
1844 i_stop = *p_intf->p_sys->p_sub->pi_stop;
1845 vlc_mutex_unlock( p_intf->p_sys->p_sub->p_lock );
1849 static const char *ppsz_type[4] = { "", "error", "warning", "debug" };
1850 if( i_line >= h - 2 )
1856 if( i_stop < 0 ) i_stop += VLC_MSG_QSIZE;
1857 if( i_stop == i_start )
1861 if( p_sys->b_color )
1862 wcolor_set( p_sys->w,
1863 p_sys->p_sub->p_msg[i_stop].i_type + C_INFO,
1865 mvnprintw( y + h-2-i_line, 1, COLS - 2, " [%s] %s",
1866 ppsz_type[p_sys->p_sub->p_msg[i_stop].i_type],
1867 p_sys->p_sub->p_msg[i_stop].psz_msg );
1868 if( p_sys->b_color )
1869 wcolor_set( p_sys->w, C_DEFAULT, NULL );
1872 vlc_mutex_lock( p_intf->p_sys->p_sub->p_lock );
1873 p_intf->p_sys->p_sub->i_start = i_stop;
1874 vlc_mutex_unlock( p_intf->p_sys->p_sub->p_lock );
1878 else if( p_sys->i_box_type == BOX_BROWSE )
1880 /* Filebrowser box */
1881 int i_start, i_stop;
1883 DrawBox( p_sys->w, y++, 0, h, COLS, _(" Browse "), p_sys->b_color );
1885 if( p_sys->i_box_bidx >= p_sys->i_dir_entries ) p_sys->i_box_plidx = p_sys->i_dir_entries - 1;
1886 if( p_sys->i_box_bidx < 0 ) p_sys->i_box_bidx = 0;
1888 if( p_sys->i_box_bidx < (h - 2)/2 )
1893 else if( p_sys->i_dir_entries - p_sys->i_box_bidx > (h - 2)/2 )
1895 i_start = p_sys->i_box_bidx - (h - 2)/2;
1896 i_stop = i_start + h - 2;
1900 i_stop = p_sys->i_dir_entries;
1901 i_start = p_sys->i_dir_entries - (h - 2);
1907 if( i_stop > p_sys->i_dir_entries )
1909 i_stop = p_sys->i_dir_entries;
1912 for( i_item = i_start; i_item < i_stop; i_item++ )
1914 bool b_selected = ( p_sys->i_box_bidx == i_item );
1916 if( y >= y_end ) break;
1919 attrset( A_REVERSE );
1921 if( p_sys->b_color && !p_sys->pp_dir_entries[i_item]->b_file )
1922 wcolor_set( p_sys->w, C_FOLDER, NULL );
1923 mvnprintw( y++, 1, COLS - 2, " %c %s", p_sys->pp_dir_entries[i_item]->b_file == true ? ' ' : '+',
1924 p_sys->pp_dir_entries[i_item]->psz_path );
1925 if( p_sys->b_color && !p_sys->pp_dir_entries[i_item]->b_file )
1926 wcolor_set( p_sys->w, C_DEFAULT, NULL );
1930 attroff( A_REVERSE );
1935 else if( p_sys->i_box_type == BOX_OBJECTS )
1938 DrawBox( p_sys->w, y++, 0, h, COLS, _(" Objects "), p_sys->b_color );
1939 DumpObject( p_intf, &l, VLC_OBJECT( p_intf->p_libvlc ), 0 );
1941 p_sys->i_box_lines_total = l;
1942 if( p_sys->i_box_start >= p_sys->i_box_lines_total )
1943 p_sys->i_box_start = p_sys->i_box_lines_total - 1;
1945 if( l - p_sys->i_box_start < p_sys->i_box_lines )
1946 y += l - p_sys->i_box_start;
1948 y += p_sys->i_box_lines;
1950 else if( p_sys->i_box_type == BOX_STATS )
1952 DrawBox( p_sys->w, y++, 0, h, COLS, _(" Stats "), p_sys->b_color );
1956 input_item_t *p_item = input_GetItem( p_input );
1958 vlc_mutex_lock( &p_item->lock );
1959 vlc_mutex_lock( &p_item->p_stats->lock );
1966 i_video = i_audio = 1;
1968 for( i = 0; i < p_item->i_es ; i++ )
1970 i_audio += ( p_item->es[i]->i_cat == AUDIO_ES );
1971 i_video += ( p_item->es[i]->i_cat == VIDEO_ES );
1976 #define SHOW_ACS(x,c) \
1977 if(l >= p_sys->i_box_start && l - p_sys->i_box_start < p_sys->i_box_lines) \
1978 mvaddch( p_sys->i_box_y - p_sys->i_box_start + l, x, c )
1981 if( p_sys->b_color ) wcolor_set( p_sys->w, C_CATEGORY, NULL );
1982 MainBoxWrite( p_intf, l, 1, _("+-[Incoming]"));
1983 SHOW_ACS( 1, ACS_ULCORNER ); SHOW_ACS( 2, ACS_HLINE ); l++;
1984 if( p_sys->b_color ) wcolor_set( p_sys->w, C_DEFAULT, NULL );
1985 MainBoxWrite( p_intf, l, 1, _("| input bytes read : %8.0f kB"),
1986 (float)(p_item->p_stats->i_read_bytes)/1000 );
1987 SHOW_ACS( 1, ACS_VLINE ); l++;
1988 MainBoxWrite( p_intf, l, 1, _("| input bitrate : %6.0f kb/s"),
1989 (float)(p_item->p_stats->f_input_bitrate)*8000 );
1990 MainBoxWrite( p_intf, l, 1, _("| demux bytes read : %8.0f kB"),
1991 (float)(p_item->p_stats->i_demux_read_bytes)/1000 );
1992 SHOW_ACS( 1, ACS_VLINE ); l++;
1993 MainBoxWrite( p_intf, l, 1, _("| demux bitrate : %6.0f kb/s"),
1994 (float)(p_item->p_stats->f_demux_bitrate)*8000 );
1995 SHOW_ACS( 1, ACS_VLINE ); l++;
1996 DrawEmptyLine( p_sys->w, p_sys->i_box_y + l - p_sys->i_box_start, 1, COLS - 2 );
1997 SHOW_ACS( 1, ACS_VLINE ); l++;
2002 if( p_sys->b_color ) wcolor_set( p_sys->w, C_CATEGORY, NULL );
2003 MainBoxWrite( p_intf, l, 1, _("+-[Video Decoding]"));
2004 SHOW_ACS( 1, ACS_LTEE ); SHOW_ACS( 2, ACS_HLINE ); l++;
2005 if( p_sys->b_color ) wcolor_set( p_sys->w, C_DEFAULT, NULL );
2006 MainBoxWrite( p_intf, l, 1, _("| video decoded : %5i"),
2007 p_item->p_stats->i_decoded_video );
2008 SHOW_ACS( 1, ACS_VLINE ); l++;
2009 MainBoxWrite( p_intf, l, 1, _("| frames displayed : %5i"),
2010 p_item->p_stats->i_displayed_pictures );
2011 SHOW_ACS( 1, ACS_VLINE ); l++;
2012 MainBoxWrite( p_intf, l, 1, _("| frames lost : %5i"),
2013 p_item->p_stats->i_lost_pictures );
2014 SHOW_ACS( 1, ACS_VLINE ); l++;
2015 DrawEmptyLine( p_sys->w, p_sys->i_box_y + l - p_sys->i_box_start, 1, COLS - 2 );
2016 SHOW_ACS( 1, ACS_VLINE ); l++;
2021 if( p_sys->b_color ) wcolor_set( p_sys->w, C_CATEGORY, NULL );
2022 MainBoxWrite( p_intf, l, 1, _("+-[Audio Decoding]"));
2023 SHOW_ACS( 1, ACS_LTEE ); SHOW_ACS( 2, ACS_HLINE ); l++;
2024 if( p_sys->b_color ) wcolor_set( p_sys->w, C_DEFAULT, NULL );
2025 MainBoxWrite( p_intf, l, 1, _("| audio decoded : %5i"),
2026 p_item->p_stats->i_decoded_audio );
2027 SHOW_ACS( 1, ACS_VLINE ); l++;
2028 MainBoxWrite( p_intf, l, 1, _("| buffers played : %5i"),
2029 p_item->p_stats->i_played_abuffers );
2030 SHOW_ACS( 1, ACS_VLINE ); l++;
2031 MainBoxWrite( p_intf, l, 1, _("| buffers lost : %5i"),
2032 p_item->p_stats->i_lost_abuffers );
2033 SHOW_ACS( 1, ACS_VLINE ); l++;
2034 DrawEmptyLine( p_sys->w, p_sys->i_box_y + l - p_sys->i_box_start, 1, COLS - 2 );
2035 SHOW_ACS( 1, ACS_VLINE ); l++;
2038 if( p_sys->b_color ) wcolor_set( p_sys->w, C_CATEGORY, NULL );
2039 MainBoxWrite( p_intf, l, 1, _("+-[Streaming]"));
2040 SHOW_ACS( 1, ACS_LTEE ); SHOW_ACS( 2, ACS_HLINE ); l++;
2041 if( p_sys->b_color ) wcolor_set( p_sys->w, C_DEFAULT, NULL );
2042 MainBoxWrite( p_intf, l, 1, _("| packets sent : %5i"), p_item->p_stats->i_sent_packets );
2043 SHOW_ACS( 1, ACS_VLINE ); l++;
2044 MainBoxWrite( p_intf, l, 1, _("| bytes sent : %8.0f kB"),
2045 (float)(p_item->p_stats->i_sent_bytes)/1000 );
2046 SHOW_ACS( 1, ACS_VLINE ); l++;
2047 MainBoxWrite( p_intf, l, 1, _("\\ sending bitrate : %6.0f kb/s"),
2048 (float)(p_item->p_stats->f_send_bitrate*8)*1000 );
2049 SHOW_ACS( 1, ACS_LLCORNER ); l++;
2050 if( p_sys->b_color ) wcolor_set( p_sys->w, C_DEFAULT, NULL );
2054 p_sys->i_box_lines_total = l;
2055 if( p_sys->i_box_start >= p_sys->i_box_lines_total )
2056 p_sys->i_box_start = p_sys->i_box_lines_total - 1;
2058 if( l - p_sys->i_box_start < p_sys->i_box_lines )
2059 y += l - p_sys->i_box_start;
2061 y += p_sys->i_box_lines;
2063 vlc_mutex_unlock( &p_item->p_stats->lock );
2064 vlc_mutex_unlock( &p_item->lock );
2068 else if( p_sys->i_box_type == BOX_PLAYLIST ||
2069 p_sys->i_box_type == BOX_SEARCH ||
2070 p_sys->i_box_type == BOX_OPEN )
2073 int i_start, i_stop, i_max = p_sys->i_plist_entries;
2077 switch( p_sys->i_current_view )
2080 psz_title = strdup( _(" Playlist (All, one level) ") );
2083 psz_title = strdup( _(" Playlist (By category) ") );
2086 psz_title = strdup( _(" Playlist (Manually added) ") );
2089 DrawBox( p_sys->w, y++, 0, h, COLS, psz_title, p_sys->b_color );
2092 if( p_sys->b_need_update || p_sys->pp_plist == NULL )
2094 PlaylistRebuild( p_intf );
2096 if( p_sys->b_box_plidx_follow )
2098 FindIndex( p_intf, p_playlist );
2101 if( p_sys->i_box_plidx < 0 ) p_sys->i_box_plidx = 0;
2102 if( p_sys->i_box_plidx < 0 ) p_sys->i_box_plidx = 0;
2103 if( p_sys->i_box_plidx >= i_max ) p_sys->i_box_plidx = i_max - 1;
2105 if( p_sys->i_box_plidx < (h - 2)/2 )
2110 else if( i_max - p_sys->i_box_plidx > (h - 2)/2 )
2112 i_start = p_sys->i_box_plidx - (h - 2)/2;
2113 i_stop = i_start + h - 2;
2118 i_start = i_max - (h - 2);
2124 if( i_stop > i_max )
2129 for( i_item = i_start; i_item < i_stop; i_item++ )
2131 bool b_selected = ( p_sys->i_box_plidx == i_item );
2132 playlist_item_t *p_item = p_sys->pp_plist[i_item]->p_item;
2133 playlist_item_t *p_node = p_sys->p_node;
2135 input_thread_t *p_input2 = playlist_CurrentInput( p_playlist );
2139 playlist_item_t *p_current_playing_item = playlist_CurrentPlayingItem(p_playlist);
2140 if( ( p_node && p_item->p_input == p_node->p_input ) ||
2141 ( !p_node && p_input2 && p_current_playing_item &&
2142 p_item->p_input == p_current_playing_item->p_input ) )
2144 else if( p_item == p_node || ( p_item != p_node &&
2145 PlaylistIsPlaying( p_playlist, p_item ) ) )
2150 vlc_object_release( p_input2 );
2152 if( y >= y_end ) break;
2155 attrset( A_REVERSE );
2157 if( p_sys->b_color )
2158 wcolor_set( p_sys->w, i_item % 3 + C_PLAYLIST_1, NULL );
2159 mvnprintw( y++, 1, COLS - 2, "%c%s", c,
2160 p_sys->pp_plist[i_item]->psz_display );
2161 if( p_sys->b_color )
2162 wcolor_set( p_sys->w, C_DEFAULT, NULL );
2165 attroff( A_REVERSE );
2174 if( p_sys->i_box_type == BOX_SEARCH )
2176 DrawEmptyLine( p_sys->w, 7, 1, COLS-2 );
2177 if( p_sys->psz_search_chain )
2179 if( strlen( p_sys->psz_search_chain ) == 0 &&
2180 p_sys->psz_old_search != NULL )
2182 /* Searching next entry */
2183 mvnprintw( 7, 1, COLS-2, _("Find: %s"), p_sys->psz_old_search );
2187 mvnprintw( 7, 1, COLS-2, _("Find: %s"), p_sys->psz_search_chain );
2191 if( p_sys->i_box_type == BOX_OPEN )
2193 if( p_sys->psz_open_chain )
2195 DrawEmptyLine( p_sys->w, 7, 1, COLS-2 );
2196 mvnprintw( 7, 1, COLS-2, _("Open: %s"), p_sys->psz_open_chain );
2202 DrawEmptyLine( p_sys->w, y++, 1, COLS - 2 );
2207 *t_last_refresh = time( 0 );
2208 pl_Release( p_intf );
2211 static playlist_item_t *PlaylistGetRoot( intf_thread_t *p_intf )
2213 intf_sys_t *p_sys = p_intf->p_sys;
2214 playlist_t *p_playlist = pl_Hold( p_intf );
2215 playlist_item_t *p_item;
2217 switch( p_sys->i_current_view )
2220 p_item = p_playlist->p_root_category;
2223 p_item = p_playlist->p_root_onelevel;
2225 pl_Release( p_intf );
2229 static void PlaylistRebuild( intf_thread_t *p_intf )
2231 intf_sys_t *p_sys = p_intf->p_sys;
2232 playlist_t *p_playlist = pl_Hold( p_intf );
2236 /* First clear the old one */
2237 PlaylistDestroy( p_intf );
2239 /* Build the new one */
2240 PlaylistAddNode( p_intf, PlaylistGetRoot( p_intf ), 0, "" );
2242 p_sys->b_need_update = false;
2246 pl_Release( p_intf );
2249 static void PlaylistAddNode( intf_thread_t *p_intf, playlist_item_t *p_node,
2250 int i, const char *c )
2252 intf_sys_t *p_sys = p_intf->p_sys;
2253 playlist_item_t *p_child;
2256 for( k = 0; k < p_node->i_children; k++ )
2259 p_child = p_node->pp_children[k];
2260 char *psz_name = input_item_GetTitleFbName( p_child->p_input );
2264 if( asprintf( &psz_display, "%s%c-%s", c,
2265 k == p_node->i_children - 1 ? '`' : '|', psz_name ) == -1 )
2270 if( asprintf( &psz_display, " %s", psz_name ) == -1 )
2274 struct pl_item_t *p_pl_item = malloc( sizeof( struct pl_item_t ) );
2277 p_pl_item->psz_display = psz_display;
2278 p_pl_item->p_item = p_child;
2279 INSERT_ELEM( p_sys->pp_plist, p_sys->i_plist_entries,
2280 p_sys->i_plist_entries, p_pl_item );
2283 if( p_child->i_children > 0 )
2286 if( asprintf( &psz_tmp, "%s%c ", c,
2287 k == p_node->i_children - 1 ? ' ' : '|' ) == -1 )
2289 PlaylistAddNode( p_intf, p_child, i,
2290 strlen( c ) ? psz_tmp : " " );
2296 static int PlaylistChanged( vlc_object_t *p_this, const char *psz_variable,
2297 vlc_value_t oval, vlc_value_t nval, void *param )
2299 VLC_UNUSED(p_this); VLC_UNUSED(psz_variable);
2300 VLC_UNUSED(oval); VLC_UNUSED(nval);
2301 intf_thread_t *p_intf = (intf_thread_t *)param;
2302 playlist_t *p_playlist = pl_Hold( p_intf );
2303 p_intf->p_sys->b_need_update = true;
2304 p_intf->p_sys->p_node = playlist_CurrentPlayingItem(p_playlist) ? playlist_CurrentPlayingItem(p_playlist)->p_parent : NULL;
2305 pl_Release( p_intf );
2310 /* This function have to be called with the playlist locked */
2311 static inline bool PlaylistIsPlaying( playlist_t *p_playlist,
2312 playlist_item_t *p_item )
2314 playlist_item_t *p_played_item = playlist_CurrentPlayingItem( p_playlist );
2315 return( p_item != NULL && p_played_item != NULL &&
2316 p_item->p_input != NULL && p_played_item->p_input != NULL &&
2317 p_item->p_input->i_id == p_played_item->p_input->i_id );
2320 static void FindIndex( intf_thread_t *p_intf, playlist_t *p_playlist )
2322 intf_sys_t *p_sys = p_intf->p_sys;
2325 if( p_sys->i_box_plidx < p_sys->i_plist_entries && p_sys->i_box_plidx >= 0 )
2327 playlist_item_t *p_item = p_sys->pp_plist[p_sys->i_box_plidx]->p_item;
2329 if( ( p_item->i_children == 0 && p_item == p_sys->p_node ) ||
2330 PlaylistIsPlaying( p_playlist, p_item ) )
2337 for( i = 0; i < p_sys->i_plist_entries; i++ )
2339 playlist_item_t *p_item = p_sys->pp_plist[i]->p_item;
2340 if( ( p_item->i_children == 0 && p_item == p_sys->p_node ) ||
2341 PlaylistIsPlaying( p_playlist, p_sys->pp_plist[i]->p_item ) )
2343 p_sys->i_box_plidx = i;
2350 static void PlaylistDestroy( intf_thread_t *p_intf )
2352 intf_sys_t *p_sys = p_intf->p_sys;
2354 while( p_sys->i_plist_entries )
2356 struct pl_item_t *p_pl_item = p_sys->pp_plist[0];
2357 free( p_pl_item->psz_display );
2358 REMOVE_ELEM( p_sys->pp_plist, p_sys->i_plist_entries, 0 );
2361 p_sys->pp_plist = NULL;
2364 static void Eject( intf_thread_t *p_intf )
2366 char *psz_device = NULL, *psz_parser, *psz_name;
2369 * Get the active input
2370 * Determine whether we can eject a media, ie it's a DVD, VCD or CD-DA
2371 * If it's neither of these, then return
2374 playlist_t * p_playlist = pl_Hold( p_intf );
2377 if( playlist_CurrentPlayingItem(p_playlist) == NULL )
2380 pl_Release( p_intf );
2384 psz_name = playlist_CurrentPlayingItem(p_playlist)->p_input->psz_name;
2388 if( !strncmp(psz_name, "dvd://", 6) )
2390 switch( psz_name[6] )
2394 psz_device = config_GetPsz( p_intf, "dvd" );
2397 /* Omit the first MRL-selector characters */
2398 psz_device = strdup( psz_name + strlen("dvd://" ) );
2402 else if( !strncmp(psz_name, "vcd://", 6) )
2404 switch( psz_name[6] )
2408 psz_device = config_GetPsz( p_intf, "vcd" );
2411 /* Omit the beginning MRL-selector characters */
2412 psz_device = strdup( psz_name + 6 );
2416 else if( !strncmp(psz_name, "cdda://", 7 ) )
2418 switch( psz_name[7] )
2422 psz_device = config_GetPsz( p_intf, "cd-audio" );
2425 /* Omit the beginning MRL-selector characters */
2426 psz_device = strdup( psz_name + 7 );
2432 psz_device = strdup( psz_name );
2438 if( psz_device == NULL )
2440 pl_Release( p_intf );
2444 /* Remove what we have after @ */
2445 for( psz_parser = psz_device ; *psz_parser ; psz_parser++ )
2447 if( *psz_parser == '@' )
2454 /* If there's a stream playing, we aren't allowed to eject ! */
2455 if( p_intf->p_sys->p_input == NULL )
2457 msg_Dbg( p_intf, "ejecting %s", psz_device );
2459 intf_Eject( p_intf, psz_device );
2463 pl_Release( p_intf );
2467 static int comp_dir_entries( const void *pp_dir_entry1,
2468 const void *pp_dir_entry2 )
2470 struct dir_entry_t *p_dir_entry1 = *(struct dir_entry_t**)pp_dir_entry1;
2471 struct dir_entry_t *p_dir_entry2 = *(struct dir_entry_t**)pp_dir_entry2;
2472 if ( p_dir_entry1->b_file == p_dir_entry2->b_file ) {
2473 return strcasecmp( p_dir_entry1->psz_path, p_dir_entry2->psz_path );
2477 return ( p_dir_entry1->b_file ? 1 : -1 );
2481 static void ReadDir( intf_thread_t *p_intf )
2483 intf_sys_t *p_sys = p_intf->p_sys;
2487 if( p_sys->psz_current_dir && *p_sys->psz_current_dir )
2492 p_current_dir = vlc_opendir( p_sys->psz_current_dir );
2494 if( p_current_dir == NULL )
2496 /* something went bad, get out of here ! */
2497 msg_Warn( p_intf, "cannot open directory `%s' (%m)",
2498 p_sys->psz_current_dir );
2502 /* Clean the old shit */
2503 for( i = 0; i < p_sys->i_dir_entries; i++ )
2505 struct dir_entry_t *p_dir_entry = p_sys->pp_dir_entries[i];
2506 free( p_dir_entry->psz_path );
2507 REMOVE_ELEM( p_sys->pp_dir_entries, p_sys->i_dir_entries, i );
2508 free( p_dir_entry );
2510 p_sys->pp_dir_entries = NULL;
2511 p_sys->i_dir_entries = 0;
2513 /* while we still have entries in the directory */
2514 while( ( psz_entry = vlc_readdir( p_current_dir ) ) != NULL )
2516 #if defined( S_ISDIR )
2517 struct stat stat_data;
2519 struct dir_entry_t *p_dir_entry;
2522 if( p_sys->b_show_hidden_files == false &&
2523 ( strlen( psz_entry ) && psz_entry[0] == '.' ) &&
2524 strcmp( psz_entry, ".." ) )
2530 if( asprintf( &psz_uri, "%s/%s", p_sys->psz_current_dir,
2537 if( !( p_dir_entry = malloc( sizeof( struct dir_entry_t) ) ) )
2544 #if defined( S_ISDIR )
2545 if( !vlc_stat( psz_uri, &stat_data )
2546 && S_ISDIR(stat_data.st_mode) )
2547 /*#elif defined( DT_DIR )
2548 if( p_dir_content->d_type & DT_DIR )*/
2553 p_dir_entry->psz_path = strdup( psz_entry );
2554 p_dir_entry->b_file = false;
2555 INSERT_ELEM( p_sys->pp_dir_entries, p_sys->i_dir_entries,
2556 p_sys->i_dir_entries, p_dir_entry );
2560 p_dir_entry->psz_path = strdup( psz_entry );
2561 p_dir_entry->b_file = true;
2562 INSERT_ELEM( p_sys->pp_dir_entries, p_sys->i_dir_entries,
2563 p_sys->i_dir_entries, p_dir_entry );
2571 qsort( p_sys->pp_dir_entries, p_sys->i_dir_entries,
2572 sizeof(struct dir_entry_t*), &comp_dir_entries );
2574 closedir( p_current_dir );
2579 msg_Dbg( p_intf, "no current dir set" );
2584 static void PlayPause( intf_thread_t *p_intf )
2586 input_thread_t *p_input = p_intf->p_sys->p_input;
2587 playlist_t *p_playlist = pl_Hold( p_intf );
2592 var_Get( p_input, "state", &val );
2593 if( val.i_int != PAUSE_S )
2595 val.i_int = PAUSE_S;
2599 val.i_int = PLAYING_S;
2601 var_Set( p_input, "state", val );
2604 playlist_Play( p_playlist );
2606 pl_Release( p_intf );
2609 /****************************************************************************
2611 ****************************************************************************/
2612 static void DrawBox( WINDOW *win, int y, int x, int h, int w, const char *title, bool b_color )
2617 if( w > 3 && h > 2 )
2620 wcolor_set( win, C_BOX, NULL );
2621 if( title == NULL ) title = "";
2622 i_len = strlen( title );
2624 if( i_len > w - 2 ) i_len = w - 2;
2626 mvwaddch( win, y, x, ACS_ULCORNER );
2627 mvwhline( win, y, x+1, ACS_HLINE, ( w-i_len-2)/2 );
2628 mvwprintw( win,y, x+1+(w-i_len-2)/2, "%s", title );
2629 mvwhline( win, y, x+(w-i_len)/2+i_len, ACS_HLINE, w - 1 - ((w-i_len)/2+i_len) );
2630 mvwaddch( win, y, x+w-1,ACS_URCORNER );
2632 for( i = 0; i < h-2; i++ )
2634 mvwaddch( win, y+i+1, x, ACS_VLINE );
2635 mvwaddch( win, y+i+1, x+w-1, ACS_VLINE );
2638 mvwaddch( win, y+h-1, x, ACS_LLCORNER );
2639 mvwhline( win, y+h-1, x+1, ACS_HLINE, w - 2 );
2640 mvwaddch( win, y+h-1, x+w-1, ACS_LRCORNER );
2642 wcolor_set( win, C_DEFAULT, NULL );
2646 static void DrawEmptyLine( WINDOW *win, int y, int x, int w )
2650 mvwhline( win, y, x, ' ', w );
2654 static void DrawLine( WINDOW *win, int y, int x, int w )
2658 attrset( A_REVERSE );
2659 mvwhline( win, y, x, ' ', w );
2660 attroff( A_REVERSE );