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 */
36 # define _XOPEN_SOURCE_EXTENDED 1
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;
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->pp_plist[p_sys->i_box_plidx] )
587 if( p_sys->pp_plist[p_sys->i_box_plidx]->p_item->i_children
590 playlist_item_t *p_item, *p_parent;
592 p_sys->pp_plist[p_sys->i_box_plidx]->p_item;
595 p_parent = p_sys->p_playlist->p_root_onelevel;
596 while( p_parent->p_parent )
597 p_parent = p_parent->p_parent;
598 playlist_Control( p_sys->p_playlist, PLAYLIST_VIEWPLAY,
599 VLC_TRUE, p_parent, p_item );
603 playlist_Control( p_sys->p_playlist, PLAYLIST_VIEWPLAY,
605 p_sys->pp_plist[p_sys->i_box_plidx]->p_item,
608 b_box_plidx_follow = VLC_TRUE;
617 int i_max = p_sys->i_plist_entries;
618 if( p_sys->i_box_plidx >= i_max ) p_sys->i_box_plidx = i_max - 1;
619 if( p_sys->i_box_plidx < 0 ) p_sys->i_box_plidx = 0;
620 if( PlaylistIsPlaying( p_intf,
621 p_sys->pp_plist[p_sys->i_box_plidx]->p_item ) )
622 b_box_plidx_follow = VLC_TRUE;
623 p_sys->b_box_plidx_follow = b_box_plidx_follow;
627 if( p_sys->i_box_type == BOX_BROWSE )
629 vlc_bool_t b_ret = VLC_TRUE;
630 /* Browser navigation */
634 p_sys->i_box_bidx = 0;
637 p_sys->i_box_bidx = p_sys->i_dir_entries - 1;
646 p_sys->i_box_bidx -= p_sys->i_box_lines;
649 p_sys->i_box_bidx += p_sys->i_box_lines;
651 case '.': /* Toggle show hidden files */
652 p_sys->b_show_hidden_files = ( p_sys->b_show_hidden_files ==
653 VLC_TRUE ? VLC_FALSE : VLC_TRUE );
660 if( p_sys->pp_dir_entries[p_sys->i_box_bidx]->b_file || i_key == ' ' )
662 int i_size_entry = strlen( p_sys->psz_current_dir ) +
663 strlen( p_sys->pp_dir_entries[p_sys->i_box_bidx]->psz_path ) + 2;
664 char *psz_uri = (char *)malloc( sizeof(char)*i_size_entry);
666 sprintf( psz_uri, "%s/%s", p_sys->psz_current_dir, p_sys->pp_dir_entries[p_sys->i_box_bidx]->psz_path );
668 playlist_item_t *p_parent = p_sys->p_playlist->status.p_node;
670 p_parent = p_sys->p_playlist->p_root_onelevel;
672 while( p_parent->p_parent )
673 p_parent = p_parent->p_parent;
675 playlist_Add( p_sys->p_playlist, psz_uri, NULL,
676 PLAYLIST_APPEND, PLAYLIST_END,
677 p_parent == p_sys->p_playlist->p_root_onelevel
679 p_sys->i_box_type = BOX_PLAYLIST;
684 int i_size_entry = strlen( p_sys->psz_current_dir ) +
685 strlen( p_sys->pp_dir_entries[p_sys->i_box_bidx]->psz_path ) + 2;
686 char *psz_uri = (char *)malloc( sizeof(char)*i_size_entry);
688 sprintf( psz_uri, "%s/%s", p_sys->psz_current_dir, p_sys->pp_dir_entries[p_sys->i_box_bidx]->psz_path );
690 p_sys->psz_current_dir = strdup( psz_uri );
701 if( p_sys->i_box_bidx >= p_sys->i_dir_entries ) p_sys->i_box_bidx = p_sys->i_dir_entries - 1;
702 if( p_sys->i_box_bidx < 0 ) p_sys->i_box_bidx = 0;
706 else if( p_sys->i_box_type == BOX_HELP || p_sys->i_box_type == BOX_INFO )
711 p_sys->i_box_start = 0;
714 p_sys->i_box_start = p_sys->i_box_lines_total - 1;
717 if( p_sys->i_box_start > 0 ) p_sys->i_box_start--;
720 if( p_sys->i_box_start < p_sys->i_box_lines_total - 1 )
722 p_sys->i_box_start++;
726 p_sys->i_box_start -= p_sys->i_box_lines;
727 if( p_sys->i_box_start < 0 ) p_sys->i_box_start = 0;
730 p_sys->i_box_start += p_sys->i_box_lines;
731 if( p_sys->i_box_start >= p_sys->i_box_lines_total )
733 p_sys->i_box_start = p_sys->i_box_lines_total - 1;
740 else if( p_sys->i_box_type == BOX_NONE )
746 ManageSlider( p_intf );
749 p_sys->f_slider = 99.9;
750 ManageSlider( p_intf );
753 p_sys->f_slider += 5.0;
754 if( p_sys->f_slider >= 99.0 ) p_sys->f_slider = 99.0;
755 ManageSlider( p_intf );
758 p_sys->f_slider -= 5.0;
759 if( p_sys->f_slider < 0.0 ) p_sys->f_slider = 0.0;
760 ManageSlider( p_intf );
767 else if( p_sys->i_box_type == BOX_SEARCH && p_sys->psz_search_chain )
770 i_chain_len = strlen( p_sys->psz_search_chain );
778 if( i_chain_len > 0 )
780 p_sys->psz_old_search = strdup( p_sys->psz_search_chain );
782 else if( p_sys->psz_old_search )
784 SearchPlaylist( p_intf, p_sys->psz_old_search );
786 p_sys->i_box_type = BOX_PLAYLIST;
788 case 0x1b: /* Esc. */
789 p_sys->i_box_plidx = p_sys->i_before_search;
790 p_sys->i_box_type = BOX_PLAYLIST;
793 RemoveLastUTF8Entity( p_sys->psz_search_chain, i_chain_len );
797 char *psz_utf8 = KeyToUTF8( i_key, p_sys->psz_partial_keys );
799 if( psz_utf8 != NULL )
801 if( i_chain_len + strlen( psz_utf8 ) < SEARCH_CHAIN_SIZE )
803 strcpy( p_sys->psz_search_chain + i_chain_len,
811 if( p_sys->psz_old_search )
813 free( p_sys->psz_old_search );
814 p_sys->psz_old_search = NULL;
816 SearchPlaylist( p_intf, p_sys->psz_search_chain );
819 else if( p_sys->i_box_type == BOX_OPEN && p_sys->psz_open_chain )
821 int i_chain_len = strlen( p_sys->psz_open_chain );
822 playlist_t *p_playlist = p_sys->p_playlist;
831 if( p_playlist && i_chain_len > 0 )
833 playlist_item_t *p_parent = p_sys->p_playlist->status.p_node;
835 p_parent = p_sys->p_playlist->p_root_onelevel;
837 while( p_parent->p_parent )
838 p_parent = p_parent->p_parent;
840 playlist_Add( p_playlist, p_sys->psz_open_chain, NULL,
841 PLAYLIST_APPEND|PLAYLIST_GO, PLAYLIST_END,
842 p_parent == p_sys->p_playlist->p_root_onelevel
844 p_sys->b_box_plidx_follow = VLC_TRUE;
846 p_sys->i_box_type = BOX_PLAYLIST;
848 case 0x1b: /* Esc. */
849 p_sys->i_box_type = BOX_PLAYLIST;
852 RemoveLastUTF8Entity( p_sys->psz_open_chain, i_chain_len );
856 char *psz_utf8 = KeyToUTF8( i_key, p_sys->psz_partial_keys );
858 if( psz_utf8 != NULL )
860 if( i_chain_len + strlen( psz_utf8 ) < OPEN_CHAIN_SIZE )
862 strcpy( p_sys->psz_open_chain + i_chain_len,
880 vlc_object_kill( p_intf->p_libvlc );
885 if( p_sys->i_box_type == BOX_INFO )
886 p_sys->i_box_type = BOX_NONE;
888 p_sys->i_box_type = BOX_INFO;
889 p_sys->i_box_lines_total = 0;
892 if( p_sys->i_box_type == BOX_LOG )
893 p_sys->i_box_type = BOX_NONE;
895 p_sys->i_box_type = BOX_LOG;
898 if( p_sys->i_box_type == BOX_PLAYLIST )
899 p_sys->i_box_type = BOX_NONE;
901 p_sys->i_box_type = BOX_PLAYLIST;
904 if( p_sys->i_box_type == BOX_BROWSE )
905 p_sys->i_box_type = BOX_NONE;
907 p_sys->i_box_type = BOX_BROWSE;
911 if( p_sys->i_box_type == BOX_HELP )
912 p_sys->i_box_type = BOX_NONE;
914 p_sys->i_box_type = BOX_HELP;
915 p_sys->i_box_lines_total = 0;
918 if( p_sys->i_box_type != BOX_SEARCH )
920 if( p_sys->psz_search_chain == NULL )
924 p_sys->psz_search_chain[0] = '\0';
925 p_sys->b_box_plidx_follow = VLC_FALSE;
926 p_sys->i_before_search = p_sys->i_box_plidx;
927 p_sys->i_box_type = BOX_SEARCH;
931 if( p_sys->i_box_type != BOX_OPEN )
933 if( p_sys->psz_open_chain == NULL )
937 p_sys->psz_open_chain[0] = '\0';
938 p_sys->i_box_type = BOX_OPEN;
944 p_sys->f_slider += 1.0;
945 if( p_sys->f_slider > 99.9 ) p_sys->f_slider = 99.9;
946 ManageSlider( p_intf );
950 p_sys->f_slider -= 1.0;
951 if( p_sys->f_slider < 0.0 ) p_sys->f_slider = 0.0;
952 ManageSlider( p_intf );
958 if( p_intf->p_sys->p_input )
960 vout_thread_t *p_vout;
961 p_vout = vlc_object_find( p_intf->p_sys->p_input,
962 VLC_OBJECT_VOUT, FIND_CHILD );
965 var_Get( p_vout, "fullscreen", &val );
966 val.b_bool = !val.b_bool;
967 var_Set( p_vout, "fullscreen", val );
968 vlc_object_release( p_vout );
972 playlist_t *p_playlist;
973 p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
977 var_Get( p_playlist, "fullscreen", &val );
978 val.b_bool = !val.b_bool;
979 var_Set( p_playlist, "fullscreen", val );
980 vlc_object_release( p_playlist );
992 if( p_intf->p_sys->p_playlist )
994 playlist_Stop( p_intf->p_sys->p_playlist );
1003 if( p_sys->p_input )
1005 val.b_bool = VLC_TRUE;
1006 var_Set( p_sys->p_input, "prev-title", val );
1011 if( p_sys->p_input )
1013 val.b_bool = VLC_TRUE;
1014 var_Set( p_sys->p_input, "next-title", val );
1019 if( p_sys->p_input )
1021 val.b_bool = VLC_TRUE;
1022 var_Set( p_sys->p_input, "prev-chapter", val );
1027 if( p_sys->p_input )
1029 val.b_bool = VLC_TRUE;
1030 var_Set( p_sys->p_input, "next-chapter", val );
1035 if( p_intf->p_sys->p_playlist )
1037 playlist_Prev( p_intf->p_sys->p_playlist );
1043 if( p_intf->p_sys->p_playlist )
1045 playlist_Next( p_intf->p_sys->p_playlist );
1051 aout_VolumeUp( p_intf, 1, NULL );
1056 aout_VolumeDown( p_intf, 1, NULL );
1061 * ^l should clear and redraw the screen
1072 static void ManageSlider( intf_thread_t *p_intf )
1074 intf_sys_t *p_sys = p_intf->p_sys;
1075 input_thread_t *p_input = p_sys->p_input;
1078 if( p_input == NULL )
1082 var_Get( p_input, "state", &val );
1083 if( val.i_int != PLAYING_S )
1088 var_Get( p_input, "position", &val );
1089 if( p_sys->f_slider == p_sys->f_slider_old )
1092 p_sys->f_slider_old = 100 * val.f_float;
1096 p_sys->f_slider_old = p_sys->f_slider;
1098 val.f_float = p_sys->f_slider / 100.0;
1099 var_Set( p_input, "position", val );
1103 static void SearchPlaylist( intf_thread_t *p_intf, char *psz_searchstring )
1108 intf_sys_t *p_sys = p_intf->p_sys;
1110 if( p_sys->i_before_search >= 0 )
1112 i_first = p_sys->i_before_search;
1115 if( ( ! psz_searchstring ) || strlen( psz_searchstring ) <= 0 )
1117 p_sys->i_box_plidx = p_sys->i_before_search;
1121 i_max = p_sys->i_plist_entries;
1123 i_item = SubSearchPlaylist( p_intf, psz_searchstring, i_first + 1, i_max );
1126 i_item = SubSearchPlaylist( p_intf, psz_searchstring, 0, i_first );
1129 if( i_item < 0 || i_item >= i_max ) return;
1131 p_sys->i_box_plidx = i_item;
1134 static int SubSearchPlaylist( intf_thread_t *p_intf, char *psz_searchstring,
1135 int i_start, int i_stop )
1137 intf_sys_t *p_sys = p_intf->p_sys;
1140 for( i = i_start + 1; i < i_stop; i++ )
1142 if( strcasestr( p_sys->pp_plist[i]->psz_display,
1143 psz_searchstring ) != NULL )
1154 static void mvnprintw( int y, int x, int w, const char *p_fmt, ... )
1159 #ifdef HAVE_NCURSESW
1160 size_t i_char_len; /* UCS character length */
1161 size_t i_width; /* Display width */
1162 wchar_t *psz_wide; /* wchar_t representation of p_buf */
1165 va_start( vl_args, p_fmt );
1166 if( vasprintf( &p_buf, p_fmt, vl_args ) == -1 )
1170 if( ( p_buf == NULL ) || ( w <= 0 ) )
1173 i_len = strlen( p_buf );
1174 #ifdef HAVE_NCURSESW
1175 psz_wide = (wchar_t *) malloc( sizeof( wchar_t ) * ( i_len + 1 ) );
1177 i_char_len = mbstowcs( psz_wide, p_buf, i_len );
1179 if( i_char_len == (size_t)-1 ) /* an invalid character was encountered */
1183 i_width = wcswidth( psz_wide, i_char_len );
1184 if( i_width == (size_t)-1 ) /* a non printable character was encountered */
1187 if( i_width > (size_t)w )
1191 { /* FIXME: ncursesw: ellipsize psz_wide while keeping the width in mind */
1192 int i_cut = i_len - w;
1193 int x1 = i_len/2 - i_cut/2;
1194 int x2 = x1 + i_cut;
1198 memmove( &p_buf[x1], &p_buf[x2], i_len - x2 );
1207 #ifdef HAVE_NCURSESW
1208 mvprintw( y, x, "%s", p_buf );
1210 char *psz_local = ToLocale( p_buf );
1211 mvprintw( y, x, "%s", psz_local );
1212 LocaleFree( p_buf );
1217 #ifdef HAVE_NCURSESW
1218 mvprintw( y, x, "%s", p_buf );
1219 mvhline( y, x + i_width, ' ', w - i_width );
1221 char *psz_local = ToLocale( p_buf );
1222 mvprintw( y, x, "%s", psz_local );
1223 LocaleFree( p_buf );
1224 mvhline( y, x + i_len, ' ', w - i_len );
1228 static void MainBoxWrite( intf_thread_t *p_intf, int l, int x, const char *p_fmt, ... )
1230 intf_sys_t *p_sys = p_intf->p_sys;
1235 if( l < p_sys->i_box_start || l - p_sys->i_box_start >= p_sys->i_box_lines )
1240 va_start( vl_args, p_fmt );
1241 if( vasprintf( &p_buf, p_fmt, vl_args ) == -1 )
1250 mvnprintw( p_sys->i_box_y + l - p_sys->i_box_start, x, COLS - x - 1, "%s", p_buf );
1253 static void Redraw( intf_thread_t *p_intf, time_t *t_last_refresh )
1255 intf_sys_t *p_sys = p_intf->p_sys;
1256 input_thread_t *p_input = p_sys->p_input;
1264 attrset( A_REVERSE );
1265 mvnprintw( y, 0, COLS, "VLC media player" " (ncurses interface) [ h for help ]" );
1266 attroff( A_REVERSE );
1270 if( p_input && !p_input->b_dead )
1272 char buf1[MSTRTIME_MAX_SIZE];
1273 char buf2[MSTRTIME_MAX_SIZE];
1275 vlc_value_t val_list;
1278 char *psz_uri = input_item_GetURI( input_GetItem( p_input ) );
1279 mvnprintw( y++, 0, COLS, " Source : %s", psz_uri );
1283 var_Get( p_input, "state", &val );
1284 if( val.i_int == PLAYING_S )
1286 mvnprintw( y, 0, COLS, " State : Playing" );
1288 else if( val.i_int == OPENING_S )
1290 mvnprintw( y, 0, COLS, " State : Opening/Connecting" );
1292 else if( val.i_int == BUFFERING_S )
1294 mvnprintw( y, 0, COLS, " State : Buffering" );
1296 else if( val.i_int == PAUSE_S )
1298 mvnprintw( y, 0, COLS, " State : Paused" );
1300 char *psz_playlist_state = malloc( 25 );
1301 /* strlen( "[Repeat] [Random] [Loop] ) == 24, + '\0' */
1302 psz_playlist_state[0] = '\0';
1303 if( var_GetBool( p_sys->p_playlist, "repeat" ) )
1304 strcat( psz_playlist_state, "[Repeat] " );
1305 if( var_GetBool( p_sys->p_playlist, "random" ) )
1306 strcat( psz_playlist_state, "[Random] " );
1307 if( var_GetBool( p_sys->p_playlist, "loop" ) )
1308 strcat( psz_playlist_state, "[Loop]" );
1309 mvnprintw( y++, 32, COLS, psz_playlist_state );
1310 free( psz_playlist_state );
1312 if( val.i_int != INIT_S && val.i_int != END_S )
1314 audio_volume_t i_volume;
1317 var_Get( p_input, "time", &val );
1318 msecstotimestr( buf1, val.i_time / 1000 );
1320 var_Get( p_input, "length", &val );
1321 msecstotimestr( buf2, val.i_time / 1000 );
1323 mvnprintw( y++, 0, COLS, " Position : %s/%s (%.2f%%)", buf1, buf2, p_sys->f_slider );
1326 aout_VolumeGet( p_intf, &i_volume );
1327 mvnprintw( y++, 0, COLS, " Volume : %i%%", i_volume*200/AOUT_VOLUME_MAX );
1330 if( !var_Get( p_input, "title", &val ) )
1332 var_Change( p_input, "title", VLC_VAR_GETCHOICES, &val_list, NULL );
1333 if( val_list.p_list->i_count > 0 )
1335 mvnprintw( y++, 0, COLS, " Title : %d/%d", val.i_int, val_list.p_list->i_count );
1337 var_Change( p_input, "title", VLC_VAR_FREELIST, &val_list, NULL );
1341 if( !var_Get( p_input, "chapter", &val ) )
1343 var_Change( p_input, "chapter", VLC_VAR_GETCHOICES, &val_list, NULL );
1344 if( val_list.p_list->i_count > 0 )
1346 mvnprintw( y++, 0, COLS, " Chapter : %d/%d", val.i_int, val_list.p_list->i_count );
1348 var_Change( p_input, "chapter", VLC_VAR_FREELIST, &val_list, NULL );
1358 mvnprintw( y++, 0, COLS, "Source: <no current item>" );
1359 DrawEmptyLine( p_sys->w, y++, 0, COLS );
1360 DrawEmptyLine( p_sys->w, y++, 0, COLS );
1361 DrawEmptyLine( p_sys->w, y++, 0, COLS );
1364 DrawBox( p_sys->w, y, 0, 3, COLS, "" );
1365 DrawEmptyLine( p_sys->w, y+1, 1, COLS-2);
1366 DrawLine( p_sys->w, y+1, 1, (int)(p_intf->p_sys->f_slider/100.0 * (COLS -2)) );
1369 p_sys->i_box_y = y + 1;
1370 p_sys->i_box_lines = LINES - y - 2;
1375 if( p_sys->i_box_type == BOX_HELP )
1379 DrawBox( p_sys->w, y++, 0, h, COLS, " Help " );
1381 MainBoxWrite( p_intf, l++, 1, "[Display]" );
1382 MainBoxWrite( p_intf, l++, 1, " h,H Show/Hide help box" );
1383 MainBoxWrite( p_intf, l++, 1, " i Show/Hide info box" );
1384 MainBoxWrite( p_intf, l++, 1, " L Show/Hide messages box" );
1385 MainBoxWrite( p_intf, l++, 1, " P Show/Hide playlist box" );
1386 MainBoxWrite( p_intf, l++, 1, " B Show/Hide filebrowser" );
1387 MainBoxWrite( p_intf, l++, 1, "" );
1389 MainBoxWrite( p_intf, l++, 1, "[Global]" );
1390 MainBoxWrite( p_intf, l++, 1, " q, Q Quit" );
1391 MainBoxWrite( p_intf, l++, 1, " s Stop" );
1392 MainBoxWrite( p_intf, l++, 1, " <space> Pause/Play" );
1393 MainBoxWrite( p_intf, l++, 1, " f Toggle Fullscreen" );
1394 MainBoxWrite( p_intf, l++, 1, " n, p Next/Previous playlist item" );
1395 MainBoxWrite( p_intf, l++, 1, " [, ] Next/Previous title" );
1396 MainBoxWrite( p_intf, l++, 1, " <, > Next/Previous chapter" );
1397 MainBoxWrite( p_intf, l++, 1, " <right> Seek +1%%" );
1398 MainBoxWrite( p_intf, l++, 1, " <left> Seek -1%%" );
1399 MainBoxWrite( p_intf, l++, 1, " a Volume Up" );
1400 MainBoxWrite( p_intf, l++, 1, " z Volume Down" );
1401 MainBoxWrite( p_intf, l++, 1, "" );
1403 MainBoxWrite( p_intf, l++, 1, "[Playlist]" );
1404 MainBoxWrite( p_intf, l++, 1, " r Random" );
1405 MainBoxWrite( p_intf, l++, 1, " l Loop Playlist" );
1406 MainBoxWrite( p_intf, l++, 1, " R Repeat item" );
1407 MainBoxWrite( p_intf, l++, 1, " o Order Playlist by title" );
1408 MainBoxWrite( p_intf, l++, 1, " O Reverse order Playlist by title" );
1409 MainBoxWrite( p_intf, l++, 1, " / Look for an item" );
1410 MainBoxWrite( p_intf, l++, 1, " A Add an entry" );
1411 MainBoxWrite( p_intf, l++, 1, " D, <del> Delete an entry" );
1412 MainBoxWrite( p_intf, l++, 1, " <backspace> Delete an entry" );
1413 MainBoxWrite( p_intf, l++, 1, "" );
1415 MainBoxWrite( p_intf, l++, 1, "[Filebrowser]" );
1416 MainBoxWrite( p_intf, l++, 1, " <enter> Add the selected file to the playlist" );
1417 MainBoxWrite( p_intf, l++, 1, " <space> Add the selected directory to the playlist" );
1418 MainBoxWrite( p_intf, l++, 1, " . Show/Hide hidden files" );
1419 MainBoxWrite( p_intf, l++, 1, "" );
1421 MainBoxWrite( p_intf, l++, 1, "[Boxes]" );
1422 MainBoxWrite( p_intf, l++, 1, " <up>,<down> Navigate through the box line by line" );
1423 MainBoxWrite( p_intf, l++, 1, " <pgup>,<pgdown> Navigate through the box page by page" );
1424 MainBoxWrite( p_intf, l++, 1, "" );
1426 MainBoxWrite( p_intf, l++, 1, "[Player]" );
1427 MainBoxWrite( p_intf, l++, 1, " <up>,<down> Seek +/-5%%" );
1428 MainBoxWrite( p_intf, l++, 1, "" );
1430 MainBoxWrite( p_intf, l++, 1, "[Miscellaneous]" );
1431 MainBoxWrite( p_intf, l++, 1, " Ctrl-l Refresh the screen" );
1433 p_sys->i_box_lines_total = l;
1434 if( p_sys->i_box_start >= p_sys->i_box_lines_total )
1436 p_sys->i_box_start = p_sys->i_box_lines_total - 1;
1439 if( l - p_sys->i_box_start < p_sys->i_box_lines )
1441 y += l - p_sys->i_box_start;
1445 y += p_sys->i_box_lines;
1448 else if( p_sys->i_box_type == BOX_INFO )
1452 DrawBox( p_sys->w, y++, 0, h, COLS, " Information " );
1457 vlc_mutex_lock( &input_GetItem(p_input)->lock );
1458 for( i = 0; i < input_GetItem(p_input)->i_categories; i++ )
1460 info_category_t *p_category = input_GetItem(p_input)->pp_categories[i];
1461 if( y >= y_end ) break;
1462 MainBoxWrite( p_intf, l++, 1, " [%s]", p_category->psz_name );
1463 for( j = 0; j < p_category->i_infos; j++ )
1465 info_t *p_info = p_category->pp_infos[j];
1466 if( y >= y_end ) break;
1467 MainBoxWrite( p_intf, l++, 1, " %s: %s", p_info->psz_name, p_info->psz_value );
1470 vlc_mutex_unlock( &input_GetItem(p_input)->lock );
1474 MainBoxWrite( p_intf, l++, 1, "No item currently playing" );
1476 p_sys->i_box_lines_total = l;
1477 if( p_sys->i_box_start >= p_sys->i_box_lines_total )
1479 p_sys->i_box_start = p_sys->i_box_lines_total - 1;
1482 if( l - p_sys->i_box_start < p_sys->i_box_lines )
1484 y += l - p_sys->i_box_start;
1488 y += p_sys->i_box_lines;
1491 else if( p_sys->i_box_type == BOX_LOG )
1497 DrawBox( p_sys->w, y++, 0, h, COLS, " Logs " );
1499 i_start = p_intf->p_sys->p_sub->i_start;
1501 vlc_mutex_lock( p_intf->p_sys->p_sub->p_lock );
1502 i_stop = *p_intf->p_sys->p_sub->pi_stop;
1503 vlc_mutex_unlock( p_intf->p_sys->p_sub->p_lock );
1507 static const char *ppsz_type[4] = { "", "error", "warning", "debug" };
1508 if( i_line >= h - 2 )
1514 if( i_stop < 0 ) i_stop += VLC_MSG_QSIZE;
1515 if( i_stop == i_start )
1519 mvnprintw( y + h-2-i_line, 1, COLS - 2, " [%s] %s",
1520 ppsz_type[p_sys->p_sub->p_msg[i_stop].i_type],
1521 p_sys->p_sub->p_msg[i_stop].psz_msg );
1524 vlc_mutex_lock( p_intf->p_sys->p_sub->p_lock );
1525 p_intf->p_sys->p_sub->i_start = i_stop;
1526 vlc_mutex_unlock( p_intf->p_sys->p_sub->p_lock );
1529 else if( p_sys->i_box_type == BOX_BROWSE )
1531 /* Filebrowser box */
1532 int i_start, i_stop;
1534 DrawBox( p_sys->w, y++, 0, h, COLS, " Browse " );
1536 if( p_sys->i_box_bidx >= p_sys->i_dir_entries ) p_sys->i_box_plidx = p_sys->i_dir_entries - 1;
1537 if( p_sys->i_box_bidx < 0 ) p_sys->i_box_bidx = 0;
1539 if( p_sys->i_box_bidx < (h - 2)/2 )
1544 else if( p_sys->i_dir_entries - p_sys->i_box_bidx > (h - 2)/2 )
1546 i_start = p_sys->i_box_bidx - (h - 2)/2;
1547 i_stop = i_start + h - 2;
1551 i_stop = p_sys->i_dir_entries;
1552 i_start = p_sys->i_dir_entries - (h - 2);
1558 if( i_stop > p_sys->i_dir_entries )
1560 i_stop = p_sys->i_dir_entries;
1563 for( i_item = i_start; i_item < i_stop; i_item++ )
1565 vlc_bool_t b_selected = ( p_sys->i_box_bidx == i_item );
1567 if( y >= y_end ) break;
1570 attrset( A_REVERSE );
1572 mvnprintw( y++, 1, COLS - 2, " %c %s", p_sys->pp_dir_entries[i_item]->b_file == VLC_TRUE ? ' ' : '+',
1573 p_sys->pp_dir_entries[i_item]->psz_path );
1576 attroff( A_REVERSE );
1581 else if( ( p_sys->i_box_type == BOX_PLAYLIST ||
1582 p_sys->i_box_type == BOX_SEARCH ||
1583 p_sys->i_box_type == BOX_OPEN ) && p_sys->p_playlist )
1586 int i_start, i_stop, i_max = p_sys->i_plist_entries;
1590 switch( p_sys->i_current_view )
1593 psz_title = strdup( " Playlist (All, one level) " );
1596 psz_title = strdup( " Playlist (By category) " );
1599 psz_title = strdup( " Playlist (Manually added) " );
1602 DrawBox( p_sys->w, y++, 0, h, COLS, psz_title );
1604 if( p_sys->b_need_update || p_sys->pp_plist == NULL )
1606 PlaylistRebuild( p_intf );
1608 if( p_sys->b_box_plidx_follow )
1610 FindIndex( p_intf );
1613 if( p_sys->i_box_plidx < 0 ) p_sys->i_box_plidx = 0;
1614 if( p_sys->i_box_plidx < 0 ) p_sys->i_box_plidx = 0;
1615 if( p_sys->i_box_plidx >= i_max ) p_sys->i_box_plidx = i_max - 1;
1617 if( p_sys->i_box_plidx < (h - 2)/2 )
1622 else if( i_max - p_sys->i_box_plidx > (h - 2)/2 )
1624 i_start = p_sys->i_box_plidx - (h - 2)/2;
1625 i_stop = i_start + h - 2;
1630 i_start = i_max - (h - 2);
1636 if( i_stop > i_max )
1641 for( i_item = i_start; i_item < i_stop; i_item++ )
1643 vlc_bool_t b_selected = ( p_sys->i_box_plidx == i_item );
1644 int c = ( PlaylistIsPlaying( p_intf,
1645 p_sys->pp_plist[i_item]->p_item ) ) ? '>' : ' ';
1647 if( y >= y_end ) break;
1650 attrset( A_REVERSE );
1652 mvnprintw( y++, 1, COLS - 2, "%c%s", c,
1653 p_sys->pp_plist[i_item]->psz_display );
1656 attroff( A_REVERSE );
1665 if( p_sys->i_box_type == BOX_SEARCH )
1667 DrawEmptyLine( p_sys->w, 7, 1, COLS-2 );
1668 if( p_sys->psz_search_chain )
1670 if( strlen( p_sys->psz_search_chain ) == 0 &&
1671 p_sys->psz_old_search != NULL )
1673 /* Searching next entry */
1674 mvnprintw( 7, 1, COLS-2, "Find: %s", p_sys->psz_old_search );
1678 mvnprintw( 7, 1, COLS-2, "Find: %s", p_sys->psz_search_chain );
1682 if( p_sys->i_box_type == BOX_OPEN )
1684 if( p_sys->psz_open_chain )
1686 DrawEmptyLine( p_sys->w, 7, 1, COLS-2 );
1687 mvnprintw( 7, 1, COLS-2, "Open: %s", p_sys->psz_open_chain );
1693 DrawEmptyLine( p_sys->w, y++, 1, COLS - 2 );
1698 *t_last_refresh = time( 0 );
1701 static playlist_item_t *PlaylistGetRoot( intf_thread_t *p_intf )
1703 intf_sys_t *p_sys = p_intf->p_sys;
1704 playlist_t *p_playlist = p_sys->p_playlist;
1706 if( p_playlist == NULL )
1711 switch( p_sys->i_current_view )
1714 return p_playlist->p_root_category;
1716 return p_playlist->p_root_onelevel;
1720 static void PlaylistRebuild( intf_thread_t *p_intf )
1722 intf_sys_t *p_sys = p_intf->p_sys;
1723 playlist_t *p_playlist = p_sys->p_playlist;
1725 if( p_playlist == NULL )
1730 vlc_mutex_lock( &p_playlist->object_lock );
1732 /* First clear the old one */
1733 PlaylistDestroy( p_intf );
1735 /* Build the new one */
1736 PlaylistAddNode( p_intf, PlaylistGetRoot( p_intf ), 0, "" );
1738 p_sys->b_need_update = VLC_FALSE;
1740 vlc_mutex_unlock( &p_playlist->object_lock );
1743 static void PlaylistAddNode( intf_thread_t *p_intf, playlist_item_t *p_node,
1744 int i, const char *c )
1746 intf_sys_t *p_sys = p_intf->p_sys;
1747 playlist_item_t *p_child;
1751 psz_tmp = (char *)malloc( strlen( c ) + 4 );
1752 if( psz_tmp == NULL ) return;
1753 for( k = 0; k < p_node->i_children; k++ )
1755 struct pl_item_t *p_pl_item;
1759 p_child = p_node->pp_children[k];
1760 i_size = strlen( c ) + strlen( p_child->p_input->psz_name ) + 4;
1761 buff = (char *)malloc( sizeof( char ) * i_size );
1762 p_pl_item = (struct pl_item_t *)malloc( sizeof( struct pl_item_t ) );
1763 if( p_pl_item == NULL || buff == NULL ) return;
1767 sprintf( buff, "%s%c-%s", c, k == p_node->i_children - 1 ?
1768 '`' : '|', p_child->p_input->psz_name );
1772 sprintf( buff, " %s", p_child->p_input->psz_name );
1774 p_pl_item->psz_display = strdup( buff );
1775 p_pl_item->p_item = p_child;
1776 INSERT_ELEM( p_sys->pp_plist, p_sys->i_plist_entries,
1777 p_sys->i_plist_entries, p_pl_item );
1781 if( p_child->i_children > 0 )
1783 sprintf( psz_tmp, "%s%c ", c,
1784 k == p_node->i_children - 1 ? ' ' : '|' );
1785 PlaylistAddNode( p_intf, p_child, i,
1786 strlen( c ) ? psz_tmp : " " );
1792 static int PlaylistChanged( vlc_object_t *p_this, const char *psz_variable,
1793 vlc_value_t oval, vlc_value_t nval, void *param )
1795 intf_thread_t *p_intf = (intf_thread_t *)param;
1796 p_intf->p_sys->b_need_update = VLC_TRUE;
1801 static inline vlc_bool_t PlaylistIsPlaying( intf_thread_t *p_intf,
1802 playlist_item_t *p_item )
1804 playlist_item_t *p_played_item = p_intf->p_sys->p_playlist->status.p_item;
1805 return( p_item != NULL && p_played_item != NULL &&
1806 p_item->p_input != NULL && p_played_item->p_input != NULL &&
1807 p_item->p_input->i_id == p_played_item->p_input->i_id );
1810 static void FindIndex( intf_thread_t *p_intf )
1812 intf_sys_t *p_sys = p_intf->p_sys;
1815 if( p_sys->i_box_plidx < p_sys->i_plist_entries &&
1816 p_sys->i_box_plidx >= 0 &&
1817 PlaylistIsPlaying( p_intf,
1818 p_sys->pp_plist[p_sys->i_box_plidx]->p_item ) )
1823 for( i = 0; i < p_sys->i_plist_entries; i++ )
1825 if( PlaylistIsPlaying( p_intf, p_sys->pp_plist[i]->p_item ) )
1827 p_sys->i_box_plidx = i;
1833 static void PlaylistDestroy( intf_thread_t *p_intf )
1835 intf_sys_t *p_sys = p_intf->p_sys;
1838 for( i = 0; i < p_sys->i_plist_entries; i++ )
1840 struct pl_item_t *p_pl_item = p_sys->pp_plist[i];
1841 free( p_pl_item->psz_display );
1842 REMOVE_ELEM( p_sys->pp_plist, p_sys->i_plist_entries, i );
1845 p_sys->pp_plist = NULL;
1846 p_sys->i_plist_entries = 0;
1849 static void Eject( intf_thread_t *p_intf )
1851 char *psz_device = NULL, *psz_parser, *psz_name;
1854 * Get the active input
1855 * Determine whether we can eject a media, ie it's a DVD, VCD or CD-DA
1856 * If it's neither of these, then return
1859 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1862 if( p_playlist == NULL )
1867 vlc_mutex_lock( &p_playlist->object_lock );
1869 if( p_playlist->status.p_item == NULL )
1871 vlc_mutex_unlock( &p_playlist->object_lock );
1872 vlc_object_release( p_playlist );
1876 psz_name = p_playlist->status.p_item->p_input->psz_name;
1880 if( !strncmp(psz_name, "dvd://", 4) )
1882 switch( psz_name[strlen("dvd://")] )
1886 psz_device = config_GetPsz( p_intf, "dvd" );
1889 /* Omit the first MRL-selector characters */
1890 psz_device = strdup( psz_name + strlen("dvd://" ) );
1894 else if( !strncmp(psz_name, VCD_MRL, strlen(VCD_MRL)) )
1896 switch( psz_name[strlen(VCD_MRL)] )
1900 psz_device = config_GetPsz( p_intf, VCD_MRL );
1903 /* Omit the beginning MRL-selector characters */
1904 psz_device = strdup( psz_name + strlen(VCD_MRL) );
1908 else if( !strncmp(psz_name, CDDA_MRL, strlen(CDDA_MRL) ) )
1910 switch( psz_name[strlen(CDDA_MRL)] )
1914 psz_device = config_GetPsz( p_intf, "cd-audio" );
1917 /* Omit the beginning MRL-selector characters */
1918 psz_device = strdup( psz_name + strlen(CDDA_MRL) );
1924 psz_device = strdup( psz_name );
1928 vlc_mutex_unlock( &p_playlist->object_lock );
1929 vlc_object_release( p_playlist );
1931 if( psz_device == NULL )
1936 /* Remove what we have after @ */
1937 psz_parser = psz_device;
1938 for( psz_parser = psz_device ; *psz_parser ; psz_parser++ )
1940 if( *psz_parser == '@' )
1947 /* If there's a stream playing, we aren't allowed to eject ! */
1948 if( p_intf->p_sys->p_input == NULL )
1950 msg_Dbg( p_intf, "ejecting %s", psz_device );
1952 intf_Eject( p_intf, psz_device );
1959 static int comp_dir_entries( const void *pp_dir_entry1,
1960 const void *pp_dir_entry2 )
1962 struct dir_entry_t *p_dir_entry1 = *(struct dir_entry_t**)pp_dir_entry1;
1963 struct dir_entry_t *p_dir_entry2 = *(struct dir_entry_t**)pp_dir_entry2;
1964 if ( p_dir_entry1->b_file == p_dir_entry2->b_file ) {
1965 return strcasecmp( p_dir_entry1->psz_path, p_dir_entry2->psz_path );
1969 return ( p_dir_entry1->b_file ? 1 : -1 );
1973 static void ReadDir( intf_thread_t *p_intf )
1975 intf_sys_t *p_sys = p_intf->p_sys;
1979 if( p_sys->psz_current_dir && *p_sys->psz_current_dir )
1984 p_current_dir = utf8_opendir( p_sys->psz_current_dir );
1986 if( p_current_dir == NULL )
1988 /* something went bad, get out of here ! */
1989 msg_Warn( p_intf, "cannot open directory `%s' (%m)",
1990 p_sys->psz_current_dir );
1994 /* Clean the old shit */
1995 for( i = 0; i < p_sys->i_dir_entries; i++ )
1997 struct dir_entry_t *p_dir_entry = p_sys->pp_dir_entries[i];
1998 free( p_dir_entry->psz_path );
1999 REMOVE_ELEM( p_sys->pp_dir_entries, p_sys->i_dir_entries, i );
2000 free( p_dir_entry );
2002 p_sys->pp_dir_entries = NULL;
2003 p_sys->i_dir_entries = 0;
2005 /* while we still have entries in the directory */
2006 while( ( psz_entry = utf8_readdir( p_current_dir ) ) != NULL )
2008 #if defined( S_ISDIR )
2009 struct stat stat_data;
2011 struct dir_entry_t *p_dir_entry;
2012 int i_size_entry = strlen( p_sys->psz_current_dir ) +
2013 strlen( psz_entry ) + 2;
2016 if( p_sys->b_show_hidden_files == VLC_FALSE &&
2017 ( strlen( psz_entry ) && psz_entry[0] == '.' ) &&
2018 strcmp( psz_entry, ".." ) )
2024 psz_uri = (char *)malloc( sizeof(char)*i_size_entry);
2025 sprintf( psz_uri, "%s/%s", p_sys->psz_current_dir, psz_entry );
2027 if( !( p_dir_entry = malloc( sizeof( struct dir_entry_t) ) ) )
2034 #if defined( S_ISDIR )
2035 if( !utf8_stat( psz_uri, &stat_data )
2036 && S_ISDIR(stat_data.st_mode) )
2037 /*#elif defined( DT_DIR )
2038 if( p_dir_content->d_type & DT_DIR )*/
2043 p_dir_entry->psz_path = strdup( psz_entry );
2044 p_dir_entry->b_file = VLC_FALSE;
2045 INSERT_ELEM( p_sys->pp_dir_entries, p_sys->i_dir_entries,
2046 p_sys->i_dir_entries, p_dir_entry );
2050 p_dir_entry->psz_path = strdup( psz_entry );
2051 p_dir_entry->b_file = VLC_TRUE;
2052 INSERT_ELEM( p_sys->pp_dir_entries, p_sys->i_dir_entries,
2053 p_sys->i_dir_entries, p_dir_entry );
2061 qsort( p_sys->pp_dir_entries, p_sys->i_dir_entries,
2062 sizeof(struct dir_entry_t*), &comp_dir_entries );
2064 closedir( p_current_dir );
2069 msg_Dbg( p_intf, "no current dir set" );
2074 static void PlayPause( intf_thread_t *p_intf )
2076 input_thread_t *p_input = p_intf->p_sys->p_input;
2081 var_Get( p_input, "state", &val );
2082 if( val.i_int != PAUSE_S )
2084 val.i_int = PAUSE_S;
2088 val.i_int = PLAYING_S;
2090 var_Set( p_input, "state", val );
2092 else if( p_intf->p_sys->p_playlist )
2094 playlist_Play( p_intf->p_sys->p_playlist );
2098 /****************************************************************************
2100 ****************************************************************************/
2101 static void DrawBox( WINDOW *win, int y, int x, int h, int w, const char *title )
2106 if( w > 3 && h > 2 )
2108 if( title == NULL ) title = "";
2109 i_len = strlen( title );
2111 if( i_len > w - 2 ) i_len = w - 2;
2113 mvwaddch( win, y, x, ACS_ULCORNER );
2114 mvwhline( win, y, x+1, ACS_HLINE, ( w-i_len-2)/2 );
2115 mvwprintw( win,y, x+1+(w-i_len-2)/2, "%s", title );
2116 mvwhline( win, y, x+(w-i_len)/2+i_len, ACS_HLINE, w - 1 - ((w-i_len)/2+i_len) );
2117 mvwaddch( win, y, x+w-1,ACS_URCORNER );
2119 for( i = 0; i < h-2; i++ )
2121 mvwaddch( win, y+i+1, x, ACS_VLINE );
2122 mvwaddch( win, y+i+1, x+w-1, ACS_VLINE );
2125 mvwaddch( win, y+h-1, x, ACS_LLCORNER );
2126 mvwhline( win, y+h-1, x+1, ACS_HLINE, w - 2 );
2127 mvwaddch( win, y+h-1, x+w-1, ACS_LRCORNER );
2131 static void DrawEmptyLine( WINDOW *win, int y, int x, int w )
2135 mvhline( y, x, ' ', w );
2139 static void DrawLine( WINDOW *win, int y, int x, int w )
2143 attrset( A_REVERSE );
2144 mvhline( y, x, ' ', w );
2145 attroff( A_REVERSE );