1 /*****************************************************************************
2 * ncurses.c : NCurses plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2001-2006 the VideoLAN team
7 * Authors: Sam Hocevar <sam@zoy.org>
8 * Laurent Aimar <fenrir@via.ecp.fr>
9 * Yoann Peronneau <yoann@videolan.org>
10 * Derk-Jan Hartman <hartman at videolan dot org>
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
25 *****************************************************************************/
27 /*****************************************************************************
29 *****************************************************************************/
30 #include <stdlib.h> /* malloc(), free() */
32 #include <errno.h> /* ENOMEM */
44 #ifdef HAVE_SYS_STAT_H
45 # include <sys/stat.h>
47 #if (!defined( WIN32 ) || defined(__MINGW32__))
48 /* Mingw has its own version of dirent */
53 #define CDDA_MRL "cddax://"
55 #define CDDA_MRL "cdda://"
59 #define VCD_MRL "vcdx://"
61 #define VCD_MRL "vcdx://"
64 #define SEARCH_CHAIN_SIZE 20
65 #define OPEN_CHAIN_SIZE 50
67 /*****************************************************************************
69 *****************************************************************************/
70 static int Open ( vlc_object_t * );
71 static void Close ( vlc_object_t * );
73 static void Run ( intf_thread_t * );
74 static void PlayPause ( intf_thread_t * );
75 static void Eject ( intf_thread_t * );
77 static int HandleKey ( intf_thread_t *, int );
78 static void Redraw ( intf_thread_t *, time_t * );
79 static void PlaylistRebuild( intf_thread_t * );
80 static void PlaylistAddNode( intf_thread_t *, playlist_item_t *, int, char *);
81 static void PlaylistDestroy( intf_thread_t * );
82 static int PlaylistChanged( vlc_object_t *, const char *, vlc_value_t,
83 vlc_value_t, void * );
84 static void FindIndex ( intf_thread_t * );
85 static void SearchPlaylist ( intf_thread_t *, char * );
86 static int SubSearchPlaylist( intf_thread_t *, char *, int, int );
87 static void ManageSlider ( intf_thread_t * );
88 static void ReadDir ( intf_thread_t * );
90 /*****************************************************************************
92 *****************************************************************************/
94 #define BROWSE_TEXT N_("Filebrowser starting point")
95 #define BROWSE_LONGTEXT N_( \
96 "This option allows you to specify the directory the ncurses filebrowser " \
97 "will show you initially.")
100 set_shortname( "Ncurses" );
101 set_description( _("Ncurses interface") );
102 set_capability( "interface", 10 );
103 set_category( CAT_INTERFACE );
104 set_subcategory( SUBCAT_INTERFACE_MAIN );
105 set_callbacks( Open, Close );
106 add_shortcut( "curses" );
107 add_directory( "browse-dir", NULL, NULL, BROWSE_TEXT, BROWSE_LONGTEXT, VLC_FALSE );
110 /*****************************************************************************
111 * intf_sys_t: description and status of ncurses interface
112 *****************************************************************************/
131 playlist_item_t *p_item;
136 playlist_t *p_playlist;
137 input_thread_t *p_input;
147 int i_box_lines_total;
150 int i_box_plidx; /* Playlist index */
151 int b_box_plidx_follow;
152 playlist_item_t *p_plnode; /* Playlist node */
153 int i_box_bidx; /* browser index */
157 msg_subscription_t* p_sub; /* message bank subscription */
159 char *psz_search_chain; /* for playlist searching */
160 char *psz_old_search; /* for searching next */
163 char *psz_open_chain;
164 char psz_partial_keys[7];
166 char *psz_current_dir;
168 struct dir_entry_t **pp_dir_entries;
169 vlc_bool_t b_show_hidden_files;
171 int i_current_view; /* playlist view */
172 struct pl_item_t **pp_plist;
174 vlc_bool_t b_need_update; /* for playlist view */
177 static void DrawBox( WINDOW *win, int y, int x, int h, int w, const char *title );
178 static void DrawLine( WINDOW *win, int y, int x, int w );
179 static void DrawEmptyLine( WINDOW *win, int y, int x, int w );
181 /*****************************************************************************
182 * Open: initialize and create window
183 *****************************************************************************/
184 static int Open( vlc_object_t *p_this )
186 intf_thread_t *p_intf = (intf_thread_t *)p_this;
190 /* Allocate instance and initialize some members */
191 p_sys = p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
192 p_sys->p_playlist = NULL;
193 p_sys->p_input = NULL;
194 p_sys->f_slider = 0.0;
195 p_sys->f_slider_old = 0.0;
196 p_sys->i_box_type = BOX_PLAYLIST;
197 p_sys->i_box_lines = 0;
198 p_sys->i_box_start= 0;
199 p_sys->i_box_lines_total = 0;
200 p_sys->b_box_plidx_follow = VLC_TRUE;
201 p_sys->b_box_cleared = VLC_FALSE;
202 p_sys->i_box_plidx = 0;
203 p_sys->p_plnode = NULL;
204 p_sys->i_box_bidx = 0;
205 p_sys->p_sub = msg_Subscribe( p_intf, MSG_QUEUE_NORMAL );
206 memset( p_sys->psz_partial_keys, 0, sizeof( p_sys->psz_partial_keys ) );
208 /* Initialize the curses library */
209 p_sys->w = initscr();
210 keypad( p_sys->w, TRUE );
211 /* Don't do NL -> CR/NL */
213 /* Take input chars one at a time */
223 /* exported function */
224 p_intf->pf_run = Run;
228 var_Set( p_intf->p_vlc, "verbose", val );
230 /* Set defaul playlist view */
231 p_sys->i_current_view = VIEW_CATEGORY;
232 p_sys->pp_plist = NULL;
233 p_sys->i_plist_entries = 0;
234 p_sys->b_need_update = VLC_FALSE;
236 /* Initialize search chain */
237 p_sys->psz_search_chain = (char *)malloc( SEARCH_CHAIN_SIZE + 1 );
238 p_sys->psz_old_search = NULL;
239 p_sys->i_before_search = 0;
241 /* Initialize open chain */
242 p_sys->psz_open_chain = (char *)malloc( OPEN_CHAIN_SIZE + 1 );
244 /* Initialize browser options */
245 var_Create( p_intf, "browse-dir", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
246 var_Get( p_intf, "browse-dir", &val);
248 if( val.psz_string && *val.psz_string )
250 p_sys->psz_current_dir = strdup( val.psz_string );
251 free( val.psz_string );
255 p_sys->psz_current_dir = strdup( p_intf->p_vlc->psz_homedir );
258 p_sys->i_dir_entries = 0;
259 p_sys->pp_dir_entries = NULL;
260 p_sys->b_show_hidden_files = VLC_FALSE;
266 /*****************************************************************************
267 * Close: destroy interface window
268 *****************************************************************************/
269 static void Close( vlc_object_t *p_this )
271 intf_thread_t *p_intf = (intf_thread_t *)p_this;
272 intf_sys_t *p_sys = p_intf->p_sys;
275 var_DelCallback( p_sys->p_playlist, "intf-change", PlaylistChanged,
277 var_DelCallback( p_sys->p_playlist, "item-append", PlaylistChanged,
280 PlaylistDestroy( p_intf );
282 for( i = 0; i < p_sys->i_dir_entries; i++ )
284 struct dir_entry_t *p_dir_entry = p_sys->pp_dir_entries[i];
285 if( p_dir_entry->psz_path ) free( p_dir_entry->psz_path );
286 REMOVE_ELEM( p_sys->pp_dir_entries, p_sys->i_dir_entries, i );
287 if( p_dir_entry ) free( p_dir_entry );
289 p_sys->pp_dir_entries = NULL;
291 if( p_sys->psz_current_dir ) free( p_sys->psz_current_dir );
292 if( p_sys->psz_search_chain ) free( p_sys->psz_search_chain );
293 if( p_sys->psz_old_search ) free( p_sys->psz_old_search );
294 if( p_sys->psz_open_chain ) free( p_sys->psz_open_chain );
298 vlc_object_release( p_sys->p_input );
300 if( p_sys->p_playlist )
302 vlc_object_release( p_sys->p_playlist );
305 /* Close the ncurses interface */
308 msg_Unsubscribe( p_intf, p_sys->p_sub );
310 /* Destroy structure */
314 /*****************************************************************************
315 * Run: ncurses thread
316 *****************************************************************************/
317 static void Run( intf_thread_t *p_intf )
319 intf_sys_t *p_sys = p_intf->p_sys;
322 time_t t_last_refresh;
325 * force drawing the interface for the first time
327 t_last_refresh = ( time( 0 ) - 1);
329 while( !p_intf->b_die )
331 msleep( INTF_IDLE_SLEEP );
333 /* Update the input */
334 if( p_sys->p_playlist == NULL )
336 p_sys->p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
338 if( p_sys->p_playlist )
340 var_AddCallback( p_sys->p_playlist, "intf-change",
341 PlaylistChanged, p_intf );
342 var_AddCallback( p_sys->p_playlist, "item-append",
343 PlaylistChanged, p_intf );
346 if( p_sys->p_playlist )
348 vlc_mutex_lock( &p_sys->p_playlist->object_lock );
349 if( p_sys->p_input == NULL )
351 p_sys->p_input = p_sys->p_playlist->p_input;
354 if( !p_sys->p_input->b_dead )
356 vlc_object_yield( p_sys->p_input );
360 else if( p_sys->p_input->b_dead )
362 vlc_object_release( p_sys->p_input );
363 p_sys->p_input = NULL;
364 p_sys->f_slider = p_sys->f_slider_old = 0.0;
365 p_sys->b_box_cleared = VLC_FALSE;
367 vlc_mutex_unlock( &p_sys->p_playlist->object_lock );
370 if( p_sys->b_box_plidx_follow && p_sys->p_playlist->i_index >= 0 )
375 while( ( i_key = getch()) != -1 )
378 * HandleKey returns 1 if the screen needs to be redrawn
380 if( HandleKey( p_intf, i_key ) )
382 Redraw( p_intf, &t_last_refresh );
386 if( p_sys->f_slider > 0.0001 && !p_sys->b_box_cleared )
389 Redraw( p_intf, &t_last_refresh );
390 p_sys->b_box_cleared = VLC_TRUE;
394 * redraw the screen every second
396 if( (time(0) - t_last_refresh) >= 1 )
398 ManageSlider( p_intf );
399 Redraw( p_intf, &t_last_refresh );
404 /* following functions are local */
406 static char *KeyToUTF8( int i_key, char *psz_part )
408 char *psz_utf8, *psz;
409 int len = strlen( psz_part );
412 /* overflow error - should not happen */
413 memset( psz_part, 0, 6 );
417 psz_part[len] = (char)i_key;
419 psz_utf8 = FromLocaleDup( psz_part );
421 /* Ugly check for incomplete bytes sequences
422 * (in case of non-UTF8 multibyte local encoding) */
423 for( psz = psz_utf8; *psz; psz++ )
424 if( ( *psz == '?' ) && ( *psz_utf8 != '?' ) )
426 /* incomplete bytes sequence detected
427 * (VLC core inserted dummy question marks) */
432 /* Check for incomplete UTF8 bytes sequence */
433 if( EnsureUTF8( psz_utf8 ) == NULL )
439 memset( psz_part, 0, 6 );
443 static inline int RemoveLastUTF8Entity( char *psz, int len )
445 while( len && ( (psz[--len] & 0xc0) == 0x80 ) );
446 /* UTF8 continuation byte */
452 static int HandleKey( intf_thread_t *p_intf, int i_key )
454 intf_sys_t *p_sys = p_intf->p_sys;
457 if( p_sys->i_box_type == BOX_PLAYLIST && p_sys->p_playlist )
459 int b_ret = VLC_TRUE;
464 /* Playlist Settings */
466 var_Get( p_sys->p_playlist, "random", &val );
467 val.b_bool = !val.b_bool;
468 var_Set( p_sys->p_playlist, "random", val );
471 var_Get( p_sys->p_playlist, "loop", &val );
472 val.b_bool = !val.b_bool;
473 var_Set( p_sys->p_playlist, "loop", val );
476 var_Get( p_sys->p_playlist, "repeat", &val );
477 val.b_bool = !val.b_bool;
478 var_Set( p_sys->p_playlist, "repeat", val );
483 playlist_Sort( p_sys->p_playlist, SORT_TITLE, ORDER_NORMAL );
486 playlist_Sort( p_sys->p_playlist, SORT_TITLE, ORDER_REVERSE );
491 switch( p_sys->i_current_view )
494 p_sys->i_current_view = VIEW_ALL;
497 p_sys->i_current_view = VIEW_CATEGORY;
499 PlaylistRebuild( p_intf );
503 /* Playlist navigation */
505 p_sys->i_box_plidx = 0;
508 p_sys->i_box_plidx = p_sys->p_playlist->i_size - 1;
511 p_sys->i_box_plidx--;
514 p_sys->i_box_plidx++;
517 p_sys->i_box_plidx -= p_sys->i_box_lines;
520 p_sys->i_box_plidx += p_sys->i_box_lines;
526 int i_item = p_sys->p_playlist->i_index;
528 playlist_LockDelete( p_sys->p_playlist, p_sys->i_box_plidx );
529 if( i_item < p_sys->p_playlist->i_size &&
530 i_item != p_sys->p_playlist->i_index )
532 playlist_Goto( p_sys->p_playlist, i_item );
539 if( p_sys->i_current_view == VIEW_ALL )
541 playlist_Goto( p_sys->p_playlist, p_sys->i_box_plidx );
545 if( p_sys->pp_plist[p_sys->i_box_plidx]->p_item->i_children
548 playlist_Control( p_sys->p_playlist, PLAYLIST_ITEMPLAY,
549 p_sys->pp_plist[p_sys->i_box_plidx]->p_item );
553 playlist_Control( p_sys->p_playlist, PLAYLIST_VIEWPLAY,
554 p_sys->i_current_view,
555 p_sys->pp_plist[p_sys->i_box_plidx]->p_item,
559 p_sys->b_box_plidx_follow = VLC_TRUE;
568 int i_max = p_sys->i_plist_entries;
569 if( p_sys->i_current_view == VIEW_ALL )
570 i_max = p_sys->p_playlist->i_size;
571 if( p_sys->i_box_plidx >= i_max ) p_sys->i_box_plidx = i_max - 1;
572 if( p_sys->i_box_plidx < 0 ) p_sys->i_box_plidx = 0;
573 if( p_sys->i_current_view == VIEW_ALL )
575 if( p_sys->i_box_plidx == p_sys->p_playlist->i_index )
576 p_sys->b_box_plidx_follow = VLC_TRUE;
578 p_sys->b_box_plidx_follow = VLC_FALSE;
582 if( p_sys->pp_plist[p_sys->i_box_plidx]->p_item ==
583 p_sys->p_playlist->status.p_item )
584 p_sys->b_box_plidx_follow = VLC_TRUE;
586 p_sys->b_box_plidx_follow = VLC_FALSE;
591 if( p_sys->i_box_type == BOX_BROWSE )
593 vlc_bool_t b_ret = VLC_TRUE;
594 /* Browser navigation */
598 p_sys->i_box_bidx = 0;
601 p_sys->i_box_bidx = p_sys->i_dir_entries - 1;
610 p_sys->i_box_bidx -= p_sys->i_box_lines;
613 p_sys->i_box_bidx += p_sys->i_box_lines;
615 case '.': /* Toggle show hidden files */
616 p_sys->b_show_hidden_files = ( p_sys->b_show_hidden_files ==
617 VLC_TRUE ? VLC_FALSE : VLC_TRUE );
624 if( p_sys->pp_dir_entries[p_sys->i_box_bidx]->b_file || i_key == ' ' )
626 int i_size_entry = strlen( p_sys->psz_current_dir ) +
627 strlen( p_sys->pp_dir_entries[p_sys->i_box_bidx]->psz_path ) + 2;
628 char *psz_uri = (char *)malloc( sizeof(char)*i_size_entry);
630 sprintf( psz_uri, "%s/%s", p_sys->psz_current_dir, p_sys->pp_dir_entries[p_sys->i_box_bidx]->psz_path );
631 playlist_Add( p_sys->p_playlist, psz_uri,
633 PLAYLIST_APPEND, PLAYLIST_END );
634 p_sys->i_box_type = BOX_PLAYLIST;
639 int i_size_entry = strlen( p_sys->psz_current_dir ) +
640 strlen( p_sys->pp_dir_entries[p_sys->i_box_bidx]->psz_path ) + 2;
641 char *psz_uri = (char *)malloc( sizeof(char)*i_size_entry);
643 sprintf( psz_uri, "%s/%s", p_sys->psz_current_dir, p_sys->pp_dir_entries[p_sys->i_box_bidx]->psz_path );
645 p_sys->psz_current_dir = strdup( psz_uri );
656 if( p_sys->i_box_bidx >= p_sys->i_dir_entries ) p_sys->i_box_bidx = p_sys->i_dir_entries - 1;
657 if( p_sys->i_box_bidx < 0 ) p_sys->i_box_bidx = 0;
661 else if( p_sys->i_box_type == BOX_HELP || p_sys->i_box_type == BOX_INFO )
666 p_sys->i_box_start = 0;
669 p_sys->i_box_start = p_sys->i_box_lines_total - 1;
672 if( p_sys->i_box_start > 0 ) p_sys->i_box_start--;
675 if( p_sys->i_box_start < p_sys->i_box_lines_total - 1 )
677 p_sys->i_box_start++;
681 p_sys->i_box_start -= p_sys->i_box_lines;
682 if( p_sys->i_box_start < 0 ) p_sys->i_box_start = 0;
685 p_sys->i_box_start += p_sys->i_box_lines;
686 if( p_sys->i_box_start >= p_sys->i_box_lines_total )
688 p_sys->i_box_start = p_sys->i_box_lines_total - 1;
695 else if( p_sys->i_box_type == BOX_NONE )
701 ManageSlider( p_intf );
704 p_sys->f_slider = 99.9;
705 ManageSlider( p_intf );
708 p_sys->f_slider += 5.0;
709 if( p_sys->f_slider >= 99.0 ) p_sys->f_slider = 99.0;
710 ManageSlider( p_intf );
713 p_sys->f_slider -= 5.0;
714 if( p_sys->f_slider < 0.0 ) p_sys->f_slider = 0.0;
715 ManageSlider( p_intf );
722 else if( p_sys->i_box_type == BOX_SEARCH && p_sys->psz_search_chain )
725 i_chain_len = strlen( p_sys->psz_search_chain );
733 if( i_chain_len > 0 )
735 p_sys->psz_old_search = strdup( p_sys->psz_search_chain );
737 else if( p_sys->psz_old_search )
739 SearchPlaylist( p_intf, p_sys->psz_old_search );
741 p_sys->i_box_type = BOX_PLAYLIST;
743 case 0x1b: /* Esc. */
744 p_sys->i_box_plidx = p_sys->i_before_search;
745 p_sys->i_box_type = BOX_PLAYLIST;
748 RemoveLastUTF8Entity( p_sys->psz_search_chain, i_chain_len );
752 char *psz_utf8 = KeyToUTF8( i_key, p_sys->psz_partial_keys );
754 if( psz_utf8 != NULL )
756 if( i_chain_len + strlen( psz_utf8 ) < SEARCH_CHAIN_SIZE )
758 strcpy( p_sys->psz_search_chain + i_chain_len,
766 if( p_sys->psz_old_search )
768 free( p_sys->psz_old_search );
769 p_sys->psz_old_search = NULL;
771 SearchPlaylist( p_intf, p_sys->psz_search_chain );
774 else if( p_sys->i_box_type == BOX_OPEN && p_sys->psz_open_chain )
776 int i_chain_len = strlen( p_sys->psz_open_chain );
777 playlist_t *p_playlist = p_sys->p_playlist;
786 if( p_playlist && i_chain_len > 0 )
788 playlist_Add( p_playlist, p_sys->psz_open_chain,
789 p_sys->psz_open_chain,
790 PLAYLIST_GO|PLAYLIST_APPEND, PLAYLIST_END );
791 p_sys->b_box_plidx_follow = VLC_TRUE;
793 p_sys->i_box_type = BOX_PLAYLIST;
795 case 0x1b: /* Esc. */
796 p_sys->i_box_type = BOX_PLAYLIST;
799 RemoveLastUTF8Entity( p_sys->psz_open_chain, i_chain_len );
803 char *psz_utf8 = KeyToUTF8( i_key, p_sys->psz_partial_keys );
805 if( psz_utf8 != NULL )
807 if( i_chain_len + strlen( psz_utf8 ) < OPEN_CHAIN_SIZE )
809 strcpy( p_sys->psz_open_chain + i_chain_len,
827 p_intf->p_vlc->b_die = VLC_TRUE;
832 if( p_sys->i_box_type == BOX_INFO )
833 p_sys->i_box_type = BOX_NONE;
835 p_sys->i_box_type = BOX_INFO;
836 p_sys->i_box_lines_total = 0;
839 if( p_sys->i_box_type == BOX_LOG )
840 p_sys->i_box_type = BOX_NONE;
842 p_sys->i_box_type = BOX_LOG;
845 if( p_sys->i_box_type == BOX_PLAYLIST )
846 p_sys->i_box_type = BOX_NONE;
848 p_sys->i_box_type = BOX_PLAYLIST;
851 if( p_sys->i_box_type == BOX_BROWSE )
852 p_sys->i_box_type = BOX_NONE;
854 p_sys->i_box_type = BOX_BROWSE;
858 if( p_sys->i_box_type == BOX_HELP )
859 p_sys->i_box_type = BOX_NONE;
861 p_sys->i_box_type = BOX_HELP;
862 p_sys->i_box_lines_total = 0;
865 if( p_sys->i_box_type != BOX_SEARCH )
867 if( p_sys->psz_search_chain == NULL )
871 p_sys->psz_search_chain[0] = '\0';
872 p_sys->b_box_plidx_follow = VLC_FALSE;
873 p_sys->i_before_search = p_sys->i_box_plidx;
874 p_sys->i_box_type = BOX_SEARCH;
878 if( p_sys->i_box_type != BOX_OPEN )
880 if( p_sys->psz_open_chain == NULL )
884 p_sys->psz_open_chain[0] = '\0';
885 p_sys->i_box_type = BOX_OPEN;
891 p_sys->f_slider += 1.0;
892 if( p_sys->f_slider > 99.9 ) p_sys->f_slider = 99.9;
893 ManageSlider( p_intf );
897 p_sys->f_slider -= 1.0;
898 if( p_sys->f_slider < 0.0 ) p_sys->f_slider = 0.0;
899 ManageSlider( p_intf );
905 if( p_intf->p_sys->p_input )
907 vout_thread_t *p_vout;
908 p_vout = vlc_object_find( p_intf->p_sys->p_input,
909 VLC_OBJECT_VOUT, FIND_CHILD );
912 var_Get( p_vout, "fullscreen", &val );
913 val.b_bool = !val.b_bool;
914 var_Set( p_vout, "fullscreen", val );
915 vlc_object_release( p_vout );
919 playlist_t *p_playlist;
920 p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
924 var_Get( p_playlist, "fullscreen", &val );
925 val.b_bool = !val.b_bool;
926 var_Set( p_playlist, "fullscreen", val );
927 vlc_object_release( p_playlist );
939 if( p_intf->p_sys->p_playlist )
941 playlist_Stop( p_intf->p_sys->p_playlist );
952 val.b_bool = VLC_TRUE;
953 var_Set( p_sys->p_input, "prev-title", val );
960 val.b_bool = VLC_TRUE;
961 var_Set( p_sys->p_input, "next-title", val );
968 val.b_bool = VLC_TRUE;
969 var_Set( p_sys->p_input, "prev-chapter", val );
976 val.b_bool = VLC_TRUE;
977 var_Set( p_sys->p_input, "next-chapter", val );
982 if( p_intf->p_sys->p_playlist )
984 playlist_Prev( p_intf->p_sys->p_playlist );
990 if( p_intf->p_sys->p_playlist )
992 playlist_Next( p_intf->p_sys->p_playlist );
998 aout_VolumeUp( p_intf, 1, NULL );
1003 aout_VolumeDown( p_intf, 1, NULL );
1008 * ^l should clear and redraw the screen
1019 static void ManageSlider( intf_thread_t *p_intf )
1021 intf_sys_t *p_sys = p_intf->p_sys;
1022 input_thread_t *p_input = p_sys->p_input;
1025 if( p_input == NULL )
1029 var_Get( p_input, "state", &val );
1030 if( val.i_int != PLAYING_S )
1035 var_Get( p_input, "position", &val );
1036 if( p_sys->f_slider == p_sys->f_slider_old )
1039 p_sys->f_slider_old = 100 * val.f_float;
1043 p_sys->f_slider_old = p_sys->f_slider;
1045 val.f_float = p_sys->f_slider / 100.0;
1046 var_Set( p_input, "position", val );
1050 static void SearchPlaylist( intf_thread_t *p_intf, char *psz_searchstring )
1055 intf_sys_t *p_sys = p_intf->p_sys;
1056 playlist_t *p_playlist = p_sys->p_playlist;
1058 if( p_sys->i_before_search >= 0 )
1060 i_first = p_sys->i_before_search;
1063 if( ( ! psz_searchstring ) || strlen( psz_searchstring ) <= 0 )
1065 p_sys->i_box_plidx = p_sys->i_before_search;
1069 i_max = p_sys->i_current_view == VIEW_ALL ?
1070 p_playlist->i_size : p_sys->i_plist_entries;
1072 i_item = SubSearchPlaylist( p_intf, psz_searchstring, i_first + 1, i_max );
1075 i_item = SubSearchPlaylist( p_intf, psz_searchstring, 0, i_first );
1078 if( i_item < 0 || i_item >= i_max ) return;
1080 p_sys->i_box_plidx = i_item;
1083 static int SubSearchPlaylist( intf_thread_t *p_intf, char *psz_searchstring,
1084 int i_start, int i_stop )
1086 intf_sys_t *p_sys = p_intf->p_sys;
1087 playlist_t *p_playlist = p_sys->p_playlist;
1090 if( p_sys->i_current_view == VIEW_ALL )
1092 for( i = i_start + 1; i < i_stop; i++ )
1094 if( strcasestr( p_playlist->pp_items[i]->input.psz_name,
1095 psz_searchstring ) != NULL
1096 || strcasestr( p_playlist->pp_items[i]->input.psz_uri,
1097 psz_searchstring ) != NULL )
1106 for( i = i_start + 1; i < i_stop; i++ )
1108 if( strcasestr( p_sys->pp_plist[i]->psz_display,
1109 psz_searchstring ) != NULL )
1121 static void mvnprintw( int y, int x, int w, const char *p_fmt, ... )
1127 va_start( vl_args, p_fmt );
1128 vasprintf( &p_buf, p_fmt, vl_args );
1137 if( ( i_len = strlen( p_buf ) ) > w )
1140 int i_cut = i_len - w;
1141 int x1 = i_len/2 - i_cut/2;
1142 int x2 = x1 + i_cut;
1146 memmove( &p_buf[x1], &p_buf[x2], i_len - x2 );
1155 psz_local = ToLocale( p_buf );
1156 mvprintw( y, x, "%s", psz_local );
1157 LocaleFree( p_buf );
1161 char *psz_local = ToLocale( p_buf );
1162 mvprintw( y, x, "%s", psz_local );
1163 LocaleFree( p_buf );
1164 mvhline( y, x + i_len, ' ', w - i_len );
1168 static void MainBoxWrite( intf_thread_t *p_intf, int l, int x, const char *p_fmt, ... )
1170 intf_sys_t *p_sys = p_intf->p_sys;
1175 if( l < p_sys->i_box_start || l - p_sys->i_box_start >= p_sys->i_box_lines )
1180 va_start( vl_args, p_fmt );
1181 vasprintf( &p_buf, p_fmt, vl_args );
1189 mvnprintw( p_sys->i_box_y + l - p_sys->i_box_start, x, COLS - x - 1, "%s", p_buf );
1192 static void Redraw( intf_thread_t *p_intf, time_t *t_last_refresh )
1194 intf_sys_t *p_sys = p_intf->p_sys;
1195 input_thread_t *p_input = p_sys->p_input;
1203 attrset( A_REVERSE );
1204 mvnprintw( y, 0, COLS, "VLC media player" " (ncurses interface) [ h for help ]" );
1205 attroff( A_REVERSE );
1209 if( p_input && !p_input->b_dead )
1211 char buf1[MSTRTIME_MAX_SIZE];
1212 char buf2[MSTRTIME_MAX_SIZE];
1214 vlc_value_t val_list;
1217 mvnprintw( y++, 0, COLS, " Source : %s",
1218 p_input->input.p_item->psz_uri );
1221 var_Get( p_input, "state", &val );
1222 if( val.i_int == PLAYING_S )
1224 mvnprintw( y++, 0, COLS, " State : Playing" );
1226 else if( val.i_int == PAUSE_S )
1228 mvnprintw( y++, 0, COLS, " State : Paused" );
1234 if( val.i_int != INIT_S && val.i_int != END_S )
1236 audio_volume_t i_volume;
1239 var_Get( p_input, "time", &val );
1240 msecstotimestr( buf1, val.i_time / 1000 );
1242 var_Get( p_input, "length", &val );
1243 msecstotimestr( buf2, val.i_time / 1000 );
1245 mvnprintw( y++, 0, COLS, " Position : %s/%s (%.2f%%)", buf1, buf2, p_sys->f_slider );
1248 aout_VolumeGet( p_intf, &i_volume );
1249 mvnprintw( y++, 0, COLS, " Volume : %i%%", i_volume*200/AOUT_VOLUME_MAX );
1252 if( !var_Get( p_input, "title", &val ) )
1254 var_Change( p_input, "title", VLC_VAR_GETCHOICES, &val_list, NULL );
1255 if( val_list.p_list->i_count > 0 )
1257 mvnprintw( y++, 0, COLS, " Title : %d/%d", val.i_int, val_list.p_list->i_count );
1259 var_Change( p_input, "title", VLC_VAR_FREELIST, &val_list, NULL );
1263 if( !var_Get( p_input, "chapter", &val ) )
1265 var_Change( p_input, "chapter", VLC_VAR_GETCHOICES, &val_list, NULL );
1266 if( val_list.p_list->i_count > 0 )
1268 mvnprintw( y++, 0, COLS, " Chapter : %d/%d", val.i_int, val_list.p_list->i_count );
1270 var_Change( p_input, "chapter", VLC_VAR_FREELIST, &val_list, NULL );
1280 mvnprintw( y++, 0, COLS, "Source: <no current item>" );
1281 DrawEmptyLine( p_sys->w, y++, 0, COLS );
1282 DrawEmptyLine( p_sys->w, y++, 0, COLS );
1283 DrawEmptyLine( p_sys->w, y++, 0, COLS );
1286 DrawBox( p_sys->w, y, 0, 3, COLS, "" );
1287 DrawEmptyLine( p_sys->w, y+1, 1, COLS-2);
1288 DrawLine( p_sys->w, y+1, 1, (int)(p_intf->p_sys->f_slider/100.0 * (COLS -2)) );
1291 p_sys->i_box_y = y + 1;
1292 p_sys->i_box_lines = LINES - y - 2;
1297 if( p_sys->i_box_type == BOX_HELP )
1301 DrawBox( p_sys->w, y++, 0, h, COLS, " Help " );
1303 MainBoxWrite( p_intf, l++, 1, "[Display]" );
1304 MainBoxWrite( p_intf, l++, 1, " h,H Show/Hide help box" );
1305 MainBoxWrite( p_intf, l++, 1, " i Show/Hide info box" );
1306 MainBoxWrite( p_intf, l++, 1, " L Show/Hide messages box" );
1307 MainBoxWrite( p_intf, l++, 1, " P Show/Hide playlist box" );
1308 MainBoxWrite( p_intf, l++, 1, " B Show/Hide filebrowser" );
1309 MainBoxWrite( p_intf, l++, 1, "" );
1311 MainBoxWrite( p_intf, l++, 1, "[Global]" );
1312 MainBoxWrite( p_intf, l++, 1, " q, Q Quit" );
1313 MainBoxWrite( p_intf, l++, 1, " s Stop" );
1314 MainBoxWrite( p_intf, l++, 1, " <space> Pause/Play" );
1315 MainBoxWrite( p_intf, l++, 1, " f Toggle Fullscreen" );
1316 MainBoxWrite( p_intf, l++, 1, " n, p Next/Previous playlist item" );
1317 MainBoxWrite( p_intf, l++, 1, " [, ] Next/Previous title" );
1318 MainBoxWrite( p_intf, l++, 1, " <, > Next/Previous chapter" );
1319 MainBoxWrite( p_intf, l++, 1, " <right> Seek +1%%" );
1320 MainBoxWrite( p_intf, l++, 1, " <left> Seek -1%%" );
1321 MainBoxWrite( p_intf, l++, 1, " a Volume Up" );
1322 MainBoxWrite( p_intf, l++, 1, " z Volume Down" );
1323 MainBoxWrite( p_intf, l++, 1, "" );
1325 MainBoxWrite( p_intf, l++, 1, "[Playlist]" );
1326 MainBoxWrite( p_intf, l++, 1, " r Random" );
1327 MainBoxWrite( p_intf, l++, 1, " l Loop Playlist" );
1328 MainBoxWrite( p_intf, l++, 1, " R Repeat item" );
1329 MainBoxWrite( p_intf, l++, 1, " o Order Playlist by title" );
1330 MainBoxWrite( p_intf, l++, 1, " O Reverse order Playlist by title" );
1331 MainBoxWrite( p_intf, l++, 1, " / Look for an item" );
1332 MainBoxWrite( p_intf, l++, 1, " A Add an entry" );
1333 MainBoxWrite( p_intf, l++, 1, " D, <del> Delete an entry" );
1334 MainBoxWrite( p_intf, l++, 1, " <backspace> Delete an entry" );
1335 MainBoxWrite( p_intf, l++, 1, "" );
1337 MainBoxWrite( p_intf, l++, 1, "[Filebrowser]" );
1338 MainBoxWrite( p_intf, l++, 1, " <enter> Add the selected file to the playlist" );
1339 MainBoxWrite( p_intf, l++, 1, " <space> Add the selected directory to the playlist" );
1340 MainBoxWrite( p_intf, l++, 1, " . Show/Hide hidden files" );
1341 MainBoxWrite( p_intf, l++, 1, "" );
1343 MainBoxWrite( p_intf, l++, 1, "[Boxes]" );
1344 MainBoxWrite( p_intf, l++, 1, " <up>,<down> Navigate through the box line by line" );
1345 MainBoxWrite( p_intf, l++, 1, " <pgup>,<pgdown> Navigate through the box page by page" );
1346 MainBoxWrite( p_intf, l++, 1, "" );
1348 MainBoxWrite( p_intf, l++, 1, "[Player]" );
1349 MainBoxWrite( p_intf, l++, 1, " <up>,<down> Seek +/-5%%" );
1350 MainBoxWrite( p_intf, l++, 1, "" );
1352 MainBoxWrite( p_intf, l++, 1, "[Miscellaneous]" );
1353 MainBoxWrite( p_intf, l++, 1, " Ctrl-l Refresh the screen" );
1355 p_sys->i_box_lines_total = l;
1356 if( p_sys->i_box_start >= p_sys->i_box_lines_total )
1358 p_sys->i_box_start = p_sys->i_box_lines_total - 1;
1361 if( l - p_sys->i_box_start < p_sys->i_box_lines )
1363 y += l - p_sys->i_box_start;
1367 y += p_sys->i_box_lines;
1370 else if( p_sys->i_box_type == BOX_INFO )
1374 DrawBox( p_sys->w, y++, 0, h, COLS, " Information " );
1379 vlc_mutex_lock( &p_input->input.p_item->lock );
1380 for( i = 0; i < p_input->input.p_item->i_categories; i++ )
1382 info_category_t *p_category = p_input->input.p_item->pp_categories[i];
1383 if( y >= y_end ) break;
1384 MainBoxWrite( p_intf, l++, 1, " [%s]", p_category->psz_name );
1385 for( j = 0; j < p_category->i_infos; j++ )
1387 info_t *p_info = p_category->pp_infos[j];
1388 if( y >= y_end ) break;
1389 MainBoxWrite( p_intf, l++, 1, " %s: %s", p_info->psz_name, p_info->psz_value );
1392 vlc_mutex_unlock( &p_input->input.p_item->lock );
1396 MainBoxWrite( p_intf, l++, 1, "No item currently playing" );
1398 p_sys->i_box_lines_total = l;
1399 if( p_sys->i_box_start >= p_sys->i_box_lines_total )
1401 p_sys->i_box_start = p_sys->i_box_lines_total - 1;
1404 if( l - p_sys->i_box_start < p_sys->i_box_lines )
1406 y += l - p_sys->i_box_start;
1410 y += p_sys->i_box_lines;
1413 else if( p_sys->i_box_type == BOX_LOG )
1419 DrawBox( p_sys->w, y++, 0, h, COLS, " Logs " );
1421 i_start = p_intf->p_sys->p_sub->i_start;
1423 vlc_mutex_lock( p_intf->p_sys->p_sub->p_lock );
1424 i_stop = *p_intf->p_sys->p_sub->pi_stop;
1425 vlc_mutex_unlock( p_intf->p_sys->p_sub->p_lock );
1429 static const char *ppsz_type[4] = { "", "error", "warning", "debug" };
1430 if( i_line >= h - 2 )
1436 if( i_stop < 0 ) i_stop += VLC_MSG_QSIZE;
1437 if( i_stop == i_start )
1441 mvnprintw( y + h-2-i_line, 1, COLS - 2, " [%s] %s",
1442 ppsz_type[p_sys->p_sub->p_msg[i_stop].i_type],
1443 p_sys->p_sub->p_msg[i_stop].psz_msg );
1446 vlc_mutex_lock( p_intf->p_sys->p_sub->p_lock );
1447 p_intf->p_sys->p_sub->i_start = i_stop;
1448 vlc_mutex_unlock( p_intf->p_sys->p_sub->p_lock );
1451 else if( p_sys->i_box_type == BOX_BROWSE )
1453 /* Filebrowser box */
1454 int i_start, i_stop;
1456 DrawBox( p_sys->w, y++, 0, h, COLS, " Browse " );
1458 if( p_sys->i_box_bidx >= p_sys->i_dir_entries ) p_sys->i_box_plidx = p_sys->i_dir_entries - 1;
1459 if( p_sys->i_box_bidx < 0 ) p_sys->i_box_bidx = 0;
1461 if( p_sys->i_box_bidx < (h - 2)/2 )
1466 else if( p_sys->i_dir_entries - p_sys->i_box_bidx > (h - 2)/2 )
1468 i_start = p_sys->i_box_bidx - (h - 2)/2;
1469 i_stop = i_start + h - 2;
1473 i_stop = p_sys->i_dir_entries;
1474 i_start = p_sys->i_dir_entries - (h - 2);
1480 if( i_stop > p_sys->i_dir_entries )
1482 i_stop = p_sys->i_dir_entries;
1485 for( i_item = i_start; i_item < i_stop; i_item++ )
1487 vlc_bool_t b_selected = ( p_sys->i_box_bidx == i_item );
1489 if( y >= y_end ) break;
1492 attrset( A_REVERSE );
1494 mvnprintw( y++, 1, COLS - 2, " %c %s", p_sys->pp_dir_entries[i_item]->b_file == VLC_TRUE ? ' ' : '+',
1495 p_sys->pp_dir_entries[i_item]->psz_path );
1498 attroff( A_REVERSE );
1503 else if( ( p_sys->i_box_type == BOX_PLAYLIST ||
1504 p_sys->i_box_type == BOX_SEARCH ||
1505 p_sys->i_box_type == BOX_OPEN ) && p_sys->p_playlist )
1508 playlist_t *p_playlist = p_sys->p_playlist;
1509 int i_start, i_stop, i_max = p_sys->i_plist_entries;
1513 switch( p_sys->i_current_view )
1516 psz_title = strdup( " Playlist (All, unsorted) " );
1517 i_max = p_playlist->i_size;
1520 psz_title = strdup( " Playlist (By category) " );
1523 psz_title = strdup( " Playlist (Manually added) " );
1526 DrawBox( p_sys->w, y++, 0, h, COLS, psz_title );
1528 if( p_sys->i_current_view != VIEW_ALL &&
1529 ( p_sys->b_need_update || p_sys->pp_plist == NULL ) )
1531 PlaylistRebuild( p_intf );
1533 if( p_sys->b_box_plidx_follow )
1535 FindIndex( p_intf );
1538 if( p_sys->i_box_plidx < 0 ) p_sys->i_box_plidx = 0;
1540 if( p_sys->i_box_plidx < (h - 2)/2 )
1545 else if( i_max - p_sys->i_box_plidx > (h - 2)/2 )
1547 i_start = p_sys->i_box_plidx - (h - 2)/2;
1548 i_stop = i_start + h - 2;
1553 i_start = i_max - (h - 2);
1559 if( i_stop > i_max )
1564 if( p_sys->i_current_view == VIEW_ALL )
1567 for( i_item = i_start; i_item < i_stop; i_item++ )
1569 vlc_bool_t b_selected = ( p_sys->i_box_plidx == i_item );
1570 int c = p_playlist->i_index == i_item ? '>' : ' ';
1572 if( y >= y_end ) break;
1575 attrset( A_REVERSE );
1577 if( !strcmp( p_playlist->pp_items[i_item]->input.psz_name,
1578 p_playlist->pp_items[i_item]->input.psz_uri ) )
1580 mvnprintw( y++, 1, COLS - 2, "%c %d - '%s'",
1583 p_playlist->pp_items[i_item]->input.psz_uri );
1587 mvnprintw( y++, 1, COLS - 2, "%c %d - '%s' (%s)",
1590 p_playlist->pp_items[i_item]->input.psz_uri,
1591 p_playlist->pp_items[i_item]->input.psz_name );
1595 attroff( A_REVERSE );
1603 for( i_item = i_start; i_item < i_stop; i_item++ )
1605 vlc_bool_t b_selected = ( p_sys->i_box_plidx == i_item );
1606 int c = ( p_playlist->status.p_item ==
1607 p_sys->pp_plist[i_item]->p_item ) ? '>' : ' ';
1609 if( y >= y_end ) break;
1612 attrset( A_REVERSE );
1614 mvnprintw( y++, 1, COLS - 2, "%c%s", c,
1615 p_sys->pp_plist[i_item]->psz_display );
1618 attroff( A_REVERSE );
1628 if( p_sys->i_box_type == BOX_SEARCH )
1630 DrawEmptyLine( p_sys->w, 7, 1, COLS-2 );
1631 if( p_sys->psz_search_chain )
1633 if( strlen( p_sys->psz_search_chain ) == 0 &&
1634 p_sys->psz_old_search != NULL )
1636 /* Searching next entry */
1637 mvnprintw( 7, 1, COLS-2, "Find: %s", p_sys->psz_old_search );
1641 mvnprintw( 7, 1, COLS-2, "Find: %s", p_sys->psz_search_chain );
1645 if( p_sys->i_box_type == BOX_OPEN )
1647 if( p_sys->psz_open_chain )
1649 DrawEmptyLine( p_sys->w, 7, 1, COLS-2 );
1650 mvnprintw( 7, 1, COLS-2, "Open: %s", p_sys->psz_open_chain );
1656 DrawEmptyLine( p_sys->w, y++, 1, COLS - 2 );
1661 *t_last_refresh = time( 0 );
1664 static void PlaylistRebuild( intf_thread_t *p_intf )
1666 intf_sys_t *p_sys = p_intf->p_sys;
1667 playlist_view_t *p_view;
1668 playlist_t *p_playlist = p_sys->p_playlist;
1670 if( p_playlist == NULL )
1675 vlc_mutex_lock( &p_playlist->object_lock );
1677 p_view = playlist_ViewFind( p_playlist, p_intf->p_sys->i_current_view );
1679 /* First clear the old one */
1680 PlaylistDestroy( p_intf );
1682 /* Build the new one */
1683 PlaylistAddNode( p_intf, p_view->p_root, 0, "" );
1685 p_sys->b_need_update = VLC_FALSE;
1687 vlc_mutex_unlock( &p_playlist->object_lock );
1690 static void PlaylistAddNode( intf_thread_t *p_intf, playlist_item_t *p_node,
1693 intf_sys_t *p_sys = p_intf->p_sys;
1694 playlist_item_t *p_child;
1698 psz_tmp = (char *)malloc( strlen( c ) + 4 );
1699 if( psz_tmp == NULL ) return;
1700 for( k = 0; k < p_node->i_children; k++ )
1702 struct pl_item_t *p_pl_item;
1706 p_child = p_node->pp_children[k];
1707 i_size = strlen( c ) + strlen( p_child->input.psz_name ) + 4;
1708 buff = (char *)malloc( sizeof( char ) * i_size );
1709 p_pl_item = (struct pl_item_t *)malloc( sizeof( struct pl_item_t ) );
1710 if( p_pl_item == NULL || buff == NULL ) return;
1714 sprintf( buff, "%s%c-%s", c, k == p_node->i_children - 1 ?
1715 '`' : '|', p_child->input.psz_name );
1719 sprintf( buff, " %s", p_child->input.psz_name );
1721 p_pl_item->psz_display = strdup( buff );
1722 p_pl_item->p_item = p_child;
1723 INSERT_ELEM( p_sys->pp_plist, p_sys->i_plist_entries,
1724 p_sys->i_plist_entries, p_pl_item );
1728 if( p_child->i_children > 0 )
1730 sprintf( psz_tmp, "%s%c ", c,
1731 k == p_node->i_children - 1 ? ' ' : '|' );
1732 PlaylistAddNode( p_intf, p_child, i,
1733 strlen( c ) ? psz_tmp : " " );
1739 static int PlaylistChanged( vlc_object_t *p_this, const char *psz_variable,
1740 vlc_value_t oval, vlc_value_t nval, void *param )
1742 intf_thread_t *p_intf = (intf_thread_t *)param;
1743 p_intf->p_sys->b_need_update = VLC_TRUE;
1747 static void FindIndex( intf_thread_t *p_intf )
1749 intf_sys_t *p_sys = p_intf->p_sys;
1752 if( p_sys->i_current_view == VIEW_ALL )
1754 p_sys->i_box_plidx = p_sys->p_playlist->i_index;
1756 else if( ( p_sys->i_box_plidx < p_sys->i_plist_entries &&
1757 p_sys->pp_plist[p_sys->i_box_plidx]->p_item !=
1758 p_sys->p_playlist->status.p_item ) )
1760 for( i = 0; i < p_sys->i_plist_entries; i++ )
1762 if( p_sys->pp_plist[i]->p_item ==
1763 p_sys->p_playlist->status.p_item )
1765 p_sys->i_box_plidx = i;
1772 static void PlaylistDestroy( intf_thread_t *p_intf )
1774 intf_sys_t *p_sys = p_intf->p_sys;
1777 for( i = 0; i < p_sys->i_plist_entries; i++ )
1779 struct pl_item_t *p_pl_item = p_sys->pp_plist[i];
1780 free( p_pl_item->psz_display );
1781 REMOVE_ELEM( p_sys->pp_plist, p_sys->i_plist_entries, i );
1784 p_sys->pp_plist = NULL;
1785 p_sys->i_plist_entries = 0;
1788 static void Eject( intf_thread_t *p_intf )
1790 char *psz_device = NULL, *psz_parser, *psz_name;
1793 * Get the active input
1794 * Determine whether we can eject a media, ie it's a DVD, VCD or CD-DA
1795 * If it's neither of these, then return
1798 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1801 if( p_playlist == NULL )
1806 vlc_mutex_lock( &p_playlist->object_lock );
1808 if( p_playlist->i_index < 0 )
1810 vlc_mutex_unlock( &p_playlist->object_lock );
1811 vlc_object_release( p_playlist );
1815 psz_name = p_playlist->pp_items[ p_playlist->i_index ]->input.psz_name;
1819 if( !strncmp(psz_name, "dvd://", 4) )
1821 switch( psz_name[strlen("dvd://")] )
1825 psz_device = config_GetPsz( p_intf, "dvd" );
1828 /* Omit the first MRL-selector characters */
1829 psz_device = strdup( psz_name + strlen("dvd://" ) );
1833 else if( !strncmp(psz_name, VCD_MRL, strlen(VCD_MRL)) )
1835 switch( psz_name[strlen(VCD_MRL)] )
1839 psz_device = config_GetPsz( p_intf, VCD_MRL );
1842 /* Omit the beginning MRL-selector characters */
1843 psz_device = strdup( psz_name + strlen(VCD_MRL) );
1847 else if( !strncmp(psz_name, CDDA_MRL, strlen(CDDA_MRL) ) )
1849 switch( psz_name[strlen(CDDA_MRL)] )
1853 psz_device = config_GetPsz( p_intf, "cd-audio" );
1856 /* Omit the beginning MRL-selector characters */
1857 psz_device = strdup( psz_name + strlen(CDDA_MRL) );
1863 psz_device = strdup( psz_name );
1867 vlc_mutex_unlock( &p_playlist->object_lock );
1868 vlc_object_release( p_playlist );
1870 if( psz_device == NULL )
1875 /* Remove what we have after @ */
1876 psz_parser = psz_device;
1877 for( psz_parser = psz_device ; *psz_parser ; psz_parser++ )
1879 if( *psz_parser == '@' )
1886 /* If there's a stream playing, we aren't allowed to eject ! */
1887 if( p_intf->p_sys->p_input == NULL )
1889 msg_Dbg( p_intf, "ejecting %s", psz_device );
1891 intf_Eject( p_intf, psz_device );
1898 static int comp_dir_entries( const void *pp_dir_entry1,
1899 const void *pp_dir_entry2 )
1901 struct dir_entry_t *p_dir_entry1 = *(struct dir_entry_t**)pp_dir_entry1;
1902 struct dir_entry_t *p_dir_entry2 = *(struct dir_entry_t**)pp_dir_entry2;
1903 if ( p_dir_entry1->b_file == p_dir_entry2->b_file ) {
1904 return strcasecmp( p_dir_entry1->psz_path, p_dir_entry2->psz_path );
1908 return ( p_dir_entry1->b_file ? 1 : -1 );
1912 static void ReadDir( intf_thread_t *p_intf )
1914 intf_sys_t *p_sys = p_intf->p_sys;
1915 DIR * p_current_dir;
1918 if( p_sys->psz_current_dir && *p_sys->psz_current_dir )
1920 const char *psz_entry;
1923 p_current_dir = utf8_opendir( p_sys->psz_current_dir );
1925 if( p_current_dir == NULL )
1927 /* something went bad, get out of here ! */
1929 msg_Warn( p_intf, "cannot open directory `%s' (%s)",
1930 p_sys->psz_current_dir, strerror(errno));
1932 msg_Warn( p_intf, "cannot open directory `%s'", p_sys->psz_current_dir );
1937 /* Clean the old shit */
1938 for( i = 0; i < p_sys->i_dir_entries; i++ )
1940 struct dir_entry_t *p_dir_entry = p_sys->pp_dir_entries[i];
1941 free( p_dir_entry->psz_path );
1942 REMOVE_ELEM( p_sys->pp_dir_entries, p_sys->i_dir_entries, i );
1943 free( p_dir_entry );
1945 p_sys->pp_dir_entries = NULL;
1946 p_sys->i_dir_entries = 0;
1948 /* get the first directory entry */
1949 psz_entry = utf8_readdir( p_current_dir );
1951 /* while we still have entries in the directory */
1952 while( psz_entry != NULL )
1954 #if defined( S_ISDIR )
1955 struct stat stat_data;
1957 struct dir_entry_t *p_dir_entry;
1958 int i_size_entry = strlen( p_sys->psz_current_dir ) +
1959 strlen( psz_entry ) + 2;
1962 if( p_sys->b_show_hidden_files == VLC_FALSE &&
1963 ( strlen( psz_entry ) && psz_entry[0] == '.' ) &&
1964 strcmp( psz_entry, ".." ) )
1966 LocaleFree( psz_entry );
1967 psz_entry = utf8_readdir( p_current_dir );
1971 psz_uri = (char *)malloc( sizeof(char)*i_size_entry);
1972 sprintf( psz_uri, "%s/%s", p_sys->psz_current_dir, psz_entry );
1974 if( !( p_dir_entry = malloc( sizeof( struct dir_entry_t) ) ) )
1980 #if defined( S_ISDIR )
1981 utf8_stat( psz_uri, &stat_data );
1982 if( S_ISDIR(stat_data.st_mode) )
1983 /*#elif defined( DT_DIR )
1984 if( p_dir_content->d_type & DT_DIR )*/
1989 p_dir_entry->psz_path = strdup( psz_entry );
1990 p_dir_entry->b_file = VLC_FALSE;
1991 INSERT_ELEM( p_sys->pp_dir_entries, p_sys->i_dir_entries,
1992 p_sys->i_dir_entries, p_dir_entry );
1996 p_dir_entry->psz_path = strdup( psz_entry );
1997 p_dir_entry->b_file = VLC_TRUE;
1998 INSERT_ELEM( p_sys->pp_dir_entries, p_sys->i_dir_entries,
1999 p_sys->i_dir_entries, p_dir_entry );
2003 LocaleFree( psz_entry );
2004 /* Read next entry */
2005 psz_entry = utf8_readdir( p_current_dir );
2009 qsort( p_sys->pp_dir_entries, p_sys->i_dir_entries,
2010 sizeof(struct dir_entry_t*), &comp_dir_entries );
2012 closedir( p_current_dir );
2017 msg_Dbg( p_intf, "no current dir set" );
2022 static void PlayPause( intf_thread_t *p_intf )
2024 input_thread_t *p_input = p_intf->p_sys->p_input;
2029 var_Get( p_input, "state", &val );
2030 if( val.i_int != PAUSE_S )
2032 val.i_int = PAUSE_S;
2036 val.i_int = PLAYING_S;
2038 var_Set( p_input, "state", val );
2040 else if( p_intf->p_sys->p_playlist )
2042 playlist_Play( p_intf->p_sys->p_playlist );
2046 /****************************************************************************
2048 ****************************************************************************/
2049 static void DrawBox( WINDOW *win, int y, int x, int h, int w, const char *title )
2054 if( w > 3 && h > 2 )
2056 if( title == NULL ) title = "";
2057 i_len = strlen( title );
2059 if( i_len > w - 2 ) i_len = w - 2;
2061 mvwaddch( win, y, x, ACS_ULCORNER );
2062 mvwhline( win, y, x+1, ACS_HLINE, ( w-i_len-2)/2 );
2063 mvwprintw( win,y, x+1+(w-i_len-2)/2, "%s", title );
2064 mvwhline( win, y, x+(w-i_len)/2+i_len, ACS_HLINE, w - 1 - ((w-i_len)/2+i_len) );
2065 mvwaddch( win, y, x+w-1,ACS_URCORNER );
2067 for( i = 0; i < h-2; i++ )
2069 mvwaddch( win, y+i+1, x, ACS_VLINE );
2070 mvwaddch( win, y+i+1, x+w-1, ACS_VLINE );
2073 mvwaddch( win, y+h-1, x, ACS_LLCORNER );
2074 mvwhline( win, y+h-1, x+1, ACS_HLINE, w - 2 );
2075 mvwaddch( win, y+h-1, x+w-1, ACS_LRCORNER );
2079 static void DrawEmptyLine( WINDOW *win, int y, int x, int w )
2083 mvhline( y, x, ' ', w );
2087 static void DrawLine( WINDOW *win, int y, int x, int w )
2091 attrset( A_REVERSE );
2092 mvhline( y, x, ' ', w );
2093 attroff( A_REVERSE );