Commit 63aac9bf authored by Laurent Aimar's avatar Laurent Aimar

* ncurses: added and updated a lot of fonctionnalities. (Playlist browser,

 time, informations and help display).
parent e1f5cdc4
...@@ -2,9 +2,10 @@ ...@@ -2,9 +2,10 @@
* ncurses.c : NCurses plugin for vlc * ncurses.c : NCurses plugin for vlc
***************************************************************************** *****************************************************************************
* Copyright (C) 2001, 2002, 2003 VideoLAN * Copyright (C) 2001, 2002, 2003 VideoLAN
* $Id: ncurses.c,v 1.6 2003/12/22 14:32:56 sam Exp $ * $Id: ncurses.c,v 1.7 2004/01/08 16:28:37 fenrir Exp $
* *
* Authors: Sam Hocevar <sam@zoy.org> * Authors: Sam Hocevar <sam@zoy.org>
* Laurent Aimar <fenrir@via.ecp.fr>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
...@@ -55,20 +56,11 @@ static int Open ( vlc_object_t * ); ...@@ -55,20 +56,11 @@ static int Open ( vlc_object_t * );
static void Close ( vlc_object_t * ); static void Close ( vlc_object_t * );
static void Run ( intf_thread_t * ); static void Run ( intf_thread_t * );
static void FullScreen ( intf_thread_t * ); static void PlayPause ( intf_thread_t * );
static void Play ( intf_thread_t * );
static void Stop ( intf_thread_t * );
static void Next ( intf_thread_t * );
static void Eject ( intf_thread_t * ); static void Eject ( intf_thread_t * );
static void Pause ( intf_thread_t * );
static void PrevTitle ( intf_thread_t * );
static void NextTitle ( intf_thread_t * );
static void PrevChapter ( intf_thread_t * );
static void NextChapter ( intf_thread_t * );
static int HandleKey ( intf_thread_t *, int ); static int HandleKey ( intf_thread_t *, int );
static void Redraw ( intf_thread_t *, time_t * ); static void Redraw ( intf_thread_t *, time_t * );
static int PrintFullLine ( const char *p_fmt, ... );
static void ManageSlider ( intf_thread_t * ); static void ManageSlider ( intf_thread_t * );
/***************************************************************************** /*****************************************************************************
...@@ -84,35 +76,63 @@ vlc_module_end(); ...@@ -84,35 +76,63 @@ vlc_module_end();
/***************************************************************************** /*****************************************************************************
* intf_sys_t: description and status of ncurses interface * intf_sys_t: description and status of ncurses interface
*****************************************************************************/ *****************************************************************************/
enum
{
BOX_NONE,
BOX_HELP,
BOX_INFO,
BOX_LOG,
BOX_PLAYLIST
};
struct intf_sys_t struct intf_sys_t
{ {
input_thread_t * p_input; playlist_t *p_playlist;
input_thread_t *p_input;
float f_slider;
float f_slider_old;
WINDOW *w;
int i_box_type;
int i_box_y;
int i_box_lines;
int i_box_lines_total;
int i_box_start;
int b_box_cleared;
float f_slider_state; msg_subscription_t* p_sub; /* message bank subscription */
float f_slider_state_old;
}; };
static void DrawBox( WINDOW *win, int y, int x, int h, int w, char *title );
static void DrawLine( WINDOW *win, int y, int x, int w );
static void DrawEmptyLine( WINDOW *win, int y, int x, int w );
/***************************************************************************** /*****************************************************************************
* Open: initialize and create window * Open: initialize and create window
*****************************************************************************/ *****************************************************************************/
static int Open( vlc_object_t *p_this ) static int Open( vlc_object_t *p_this )
{ {
intf_thread_t *p_intf = (intf_thread_t *)p_this; intf_thread_t *p_intf = (intf_thread_t *)p_this;
intf_sys_t *p_sys;
/* Allocate instance and initialize some members */ /* Allocate instance and initialize some members */
p_intf->p_sys = malloc( sizeof( intf_sys_t ) ); p_sys = p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
if( p_intf->p_sys == NULL ) p_sys->p_playlist = NULL;
{ p_sys->p_input = NULL;
msg_Err( p_intf, "out of memory" ); p_sys->f_slider = 0.0;
return VLC_ENOMEM; p_sys->f_slider_old = 0.0;
} p_sys->i_box_type = BOX_PLAYLIST;
p_sys->i_box_lines = 0;
p_intf->p_sys->p_input = NULL; p_sys->i_box_start= 0;
p_sys->i_box_lines_total = 0;
p_intf->pf_run = Run; p_sys->b_box_cleared = VLC_FALSE;
p_sys->p_sub = msg_Subscribe( p_intf );
/* Initialize the curses library */ /* Initialize the curses library */
initscr(); p_sys->w = initscr();
keypad( p_sys->w, TRUE );
/* Don't do NL -> CR/NL */ /* Don't do NL -> CR/NL */
nonl(); nonl();
/* Take input chars one at a time */ /* Take input chars one at a time */
...@@ -125,6 +145,9 @@ static int Open( vlc_object_t *p_this ) ...@@ -125,6 +145,9 @@ static int Open( vlc_object_t *p_this )
clear(); clear();
/* exported function */
p_intf->pf_run = Run;
return VLC_SUCCESS; return VLC_SUCCESS;
} }
...@@ -134,17 +157,24 @@ static int Open( vlc_object_t *p_this ) ...@@ -134,17 +157,24 @@ static int Open( vlc_object_t *p_this )
static void Close( vlc_object_t *p_this ) static void Close( vlc_object_t *p_this )
{ {
intf_thread_t *p_intf = (intf_thread_t *)p_this; intf_thread_t *p_intf = (intf_thread_t *)p_this;
intf_sys_t *p_sys = p_intf->p_sys;
if( p_intf->p_sys->p_input ) if( p_sys->p_input )
{
vlc_object_release( p_sys->p_input );
}
if( p_sys->p_playlist )
{ {
vlc_object_release( p_intf->p_sys->p_input ); vlc_object_release( p_sys->p_playlist );
} }
/* Close the ncurses interface */ /* Close the ncurses interface */
endwin(); endwin();
msg_Unsubscribe( p_intf, p_sys->p_sub );
/* Destroy structure */ /* Destroy structure */
free( p_intf->p_sys ); free( p_sys );
} }
/***************************************************************************** /*****************************************************************************
...@@ -152,7 +182,9 @@ static void Close( vlc_object_t *p_this ) ...@@ -152,7 +182,9 @@ static void Close( vlc_object_t *p_this )
*****************************************************************************/ *****************************************************************************/
static void Run( intf_thread_t *p_intf ) static void Run( intf_thread_t *p_intf )
{ {
signed char i_key; intf_sys_t *p_sys = p_intf->p_sys;
int i_key;
time_t t_last_refresh; time_t t_last_refresh;
/* /*
...@@ -165,18 +197,33 @@ static void Run( intf_thread_t *p_intf ) ...@@ -165,18 +197,33 @@ static void Run( intf_thread_t *p_intf )
msleep( INTF_IDLE_SLEEP ); msleep( INTF_IDLE_SLEEP );
/* Update the input */ /* Update the input */
if( p_intf->p_sys->p_input == NULL ) if( p_sys->p_playlist == NULL )
{ {
p_intf->p_sys->p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT, p_sys->p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
FIND_ANYWHERE ); }
if( p_sys->p_input == NULL )
{
if( p_sys->p_playlist )
{
p_sys->p_input = vlc_object_find( p_sys->p_playlist,
VLC_OBJECT_INPUT,FIND_CHILD );
}
else
{
p_sys->p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT,
FIND_ANYWHERE );
}
p_sys->b_box_cleared = VLC_FALSE;
} }
else if( p_intf->p_sys->p_input->b_dead ) else if( p_sys->p_input->b_dead )
{ {
vlc_object_release( p_intf->p_sys->p_input ); vlc_object_release( p_sys->p_input );
p_intf->p_sys->p_input = NULL; p_sys->p_input = NULL;
p_sys->f_slider = p_sys->f_slider_old = 0.0;
p_sys->b_box_cleared = VLC_FALSE;
} }
while( (i_key = getch()) != -1 ) while( ( i_key = getch()) != -1 )
{ {
/* /*
* HandleKey returns 1 if the screen needs to be redrawn * HandleKey returns 1 if the screen needs to be redrawn
...@@ -186,6 +233,13 @@ static void Run( intf_thread_t *p_intf ) ...@@ -186,6 +233,13 @@ static void Run( intf_thread_t *p_intf )
Redraw( p_intf, &t_last_refresh ); Redraw( p_intf, &t_last_refresh );
} }
} }
/* Hack */
if( p_sys->f_slider > 0.0001 && !p_sys->b_box_cleared )
{
clear();
Redraw( p_intf, &t_last_refresh );
p_sys->b_box_cleared = VLC_TRUE;
}
/* /*
* redraw the screen every second * redraw the screen every second
...@@ -202,31 +256,209 @@ static void Run( intf_thread_t *p_intf ) ...@@ -202,31 +256,209 @@ static void Run( intf_thread_t *p_intf )
static int HandleKey( intf_thread_t *p_intf, int i_key ) static int HandleKey( intf_thread_t *p_intf, int i_key )
{ {
intf_sys_t *p_sys = p_intf->p_sys;
vlc_value_t val;
if( p_sys->i_box_type == BOX_PLAYLIST && p_sys->p_playlist )
{
switch( i_key )
{
/* Playlist sort */
case 'r':
playlist_Sort( p_sys->p_playlist, SORT_RANDOM, SORT_NORMAL );
return 1;
case 'o':
playlist_Sort( p_sys->p_playlist, SORT_TITLE, SORT_NORMAL );
return 1;
case 'O':
playlist_Sort( p_sys->p_playlist, SORT_TITLE, SORT_REVERSE );
return 1;
/* Playlist navigation */
case KEY_HOME:
playlist_Goto( p_sys->p_playlist, 0 );
return 1;
case KEY_END:
playlist_Goto( p_sys->p_playlist, p_sys->p_playlist->i_size - 1 );
return 1;
case KEY_UP:
playlist_Prev( p_sys->p_playlist );
return 1;
case KEY_DOWN:
playlist_Next( p_sys->p_playlist );
return 1;
case KEY_PPAGE:
{
int i_item = p_sys->p_playlist->i_index - p_sys->i_box_lines;
if( i_item < 0 ) i_item = 0;
playlist_Goto( p_sys->p_playlist, i_item );
return 1;
}
case KEY_NPAGE:
{
int i_item = p_sys->p_playlist->i_index + p_sys->i_box_lines;
if( i_item >= p_sys->p_playlist->i_size ) i_item = p_sys->p_playlist->i_size - 1;
if( i_item > 0 )
{
playlist_Goto( p_sys->p_playlist, i_item );
}
return 1;
}
case KEY_BACKSPACE:
playlist_Delete( p_sys->p_playlist, p_sys->p_playlist->i_index );
return 1;
case KEY_DC:
{
int i_item = p_sys->p_playlist->i_index;
playlist_Delete( p_sys->p_playlist, p_sys->p_playlist->i_index );
if( i_item < p_sys->p_playlist->i_size )
{
playlist_Goto( p_sys->p_playlist, i_item );
}
return 1;
}
default:
break;
}
}
else if( p_sys->i_box_type == BOX_HELP || p_sys->i_box_type == BOX_INFO )
{
switch( i_key )
{
case KEY_HOME:
p_sys->i_box_start = 0;
return 1;
case KEY_END:
p_sys->i_box_start = p_sys->i_box_lines_total - 1;
return 1;
case KEY_UP:
if( p_sys->i_box_start > 0 ) p_sys->i_box_start--;
return 1;
case KEY_DOWN:
if( p_sys->i_box_start < p_sys->i_box_lines_total - 1 )
{
p_sys->i_box_start++;
}
return 1;
case KEY_PPAGE:
p_sys->i_box_start -= p_sys->i_box_lines;
if( p_sys->i_box_start < 0 ) p_sys->i_box_start = 0;
return 1;
case KEY_NPAGE:
p_sys->i_box_start += p_sys->i_box_lines;
if( p_sys->i_box_start >= p_sys->i_box_lines_total )
{
p_sys->i_box_start = p_sys->i_box_lines_total - 1;
}
return 1;
default:
break;
}
}
else if( p_sys->i_box_type == BOX_NONE )
{
switch( i_key )
{
case KEY_HOME:
p_sys->f_slider = 0;
ManageSlider ( p_intf );
return 1;
case KEY_END:
p_sys->f_slider = 99.9;
ManageSlider ( p_intf );
return 1;
case KEY_UP:
p_sys->f_slider += 20.0;
if( p_sys->f_slider >= 99.0 ) p_sys->f_slider = 99.0;
ManageSlider ( p_intf );
return 1;
case KEY_DOWN:
p_sys->f_slider -= 20.0;
if( p_sys->f_slider < 0.0 ) p_sys->f_slider = 0.0;
ManageSlider ( p_intf );
return 1;
default:
break;
}
}
/* Common keys */
switch( i_key ) switch( i_key )
{ {
case 'q': case 'q':
case 'Q': case 'Q':
case 0x1b: /* Esc */
p_intf->b_die = 1; p_intf->b_die = 1;
return 0; return 0;
case 'f': /* Box switching */
FullScreen( p_intf ); case 'i':
if( p_sys->i_box_type == BOX_INFO )
p_sys->i_box_type = BOX_NONE;
else
p_sys->i_box_type = BOX_INFO;
p_sys->i_box_lines_total = 0;
return 1;
case 'l':
if( p_sys->i_box_type == BOX_LOG )
p_sys->i_box_type = BOX_NONE;
else
p_sys->i_box_type = BOX_LOG;
return 1;
case 'P':
if( p_sys->i_box_type == BOX_PLAYLIST )
p_sys->i_box_type = BOX_NONE;
else
p_sys->i_box_type = BOX_PLAYLIST;
return 1;
case 'h':
case 'H':
if( p_sys->i_box_type == BOX_HELP )
p_sys->i_box_type = BOX_NONE;
else
p_sys->i_box_type = BOX_HELP;
p_sys->i_box_lines_total = 0;
return 1; return 1;
case 'p': /* Navigation */
Play( p_intf ); case KEY_RIGHT:
p_sys->f_slider += 5.0;
if( p_sys->f_slider > 99.9 ) p_sys->f_slider = 99.9;
ManageSlider ( p_intf );
return 1; return 1;
case ' ': case KEY_LEFT:
Pause( p_intf ); p_sys->f_slider -= 5.0;
if( p_sys->f_slider < 0.0 ) p_sys->f_slider = 0.0;
ManageSlider ( p_intf );
return 1; return 1;
case 's': /* Common control */
Stop( p_intf ); case 'f':
{
vout_thread_t *p_vout;
p_vout = vlc_object_find( p_intf->p_sys->p_input,
VLC_OBJECT_VOUT, FIND_CHILD );
if( p_vout )
{
p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
vlc_object_release( p_vout );
}
return 0;
}
case ' ':
PlayPause( p_intf );
return 1; return 1;
case 'n': case 's':
Next( p_intf ); if( p_intf->p_sys->p_playlist )
{
playlist_Stop( p_intf->p_sys->p_playlist );
}
return 1; return 1;
case 'e': case 'e':
...@@ -234,30 +466,51 @@ static int HandleKey( intf_thread_t *p_intf, int i_key ) ...@@ -234,30 +466,51 @@ static int HandleKey( intf_thread_t *p_intf, int i_key )
return 1; return 1;
case '[': case '[':
PrevTitle( p_intf ); if( p_sys->p_input )
{
val.b_bool = VLC_TRUE;
var_Set( p_sys->p_input, "prev-title", val );
}
break; break;
case ']': case ']':
NextTitle( p_intf ); if( p_sys->p_input )
{
val.b_bool = VLC_TRUE;
var_Set( p_sys->p_input, "next-title", val );
}
break; break;
case '<': case '<':
PrevChapter( p_intf ); if( p_sys->p_input )
{
val.b_bool = VLC_TRUE;
var_Set( p_sys->p_input, "prev-chapter", val );
}
break; break;
case '>': case '>':
NextChapter( p_intf ); if( p_sys->p_input )
break; {
val.b_bool = VLC_TRUE;
case KEY_RIGHT: var_Set( p_sys->p_input, "next-chapter", val );
p_intf->p_sys->f_slider_state += 100; }
ManageSlider ( p_intf );
break; break;
case KEY_LEFT: case 'p':
p_intf->p_sys->f_slider_state--; if( p_intf->p_sys->p_playlist )
ManageSlider ( p_intf ); {
break; playlist_Prev( p_intf->p_sys->p_playlist );
}
clear();
return 1;
case 'n':
if( p_intf->p_sys->p_playlist )
{
playlist_Next( p_intf->p_sys->p_playlist );
}
clear();
return 1;
/* /*
* ^l should clear and redraw the screen * ^l should clear and redraw the screen
...@@ -267,17 +520,46 @@ static int HandleKey( intf_thread_t *p_intf, int i_key ) ...@@ -267,17 +520,46 @@ static int HandleKey( intf_thread_t *p_intf, int i_key )
return 1; return 1;
default: default:
break; return 0;
}
}
static void ManageSlider ( intf_thread_t *p_intf )
{
intf_sys_t *p_sys = p_intf->p_sys;
input_thread_t *p_input = p_sys->p_input;
vlc_value_t val;
if( p_input == NULL )
{
return;
}
var_Get( p_input, "state", &val );
if( val.i_int != PLAYING_S )
{
return;
}
var_Get( p_input, "position", &val );
if( p_sys->f_slider == p_sys->f_slider_old )
{
p_sys->f_slider =
p_sys->f_slider_old = 100 * val.f_float;
} }
else
{
p_sys->f_slider_old = p_sys->f_slider;
return 0; val.f_float = p_sys->f_slider / 100.0;
var_Set( p_input, "position", val );
}
} }
static int PrintFullLine ( const char *p_fmt, ... ) static void mvnprintw( int y, int x, int w, const char *p_fmt, ... )
{ {
va_list vl_args; va_list vl_args;
char * p_buf = NULL; char *p_buf = NULL;
int i_len; int i_len;
va_start ( vl_args, p_fmt ); va_start ( vl_args, p_fmt );
vasprintf ( &p_buf, p_fmt, vl_args ); vasprintf ( &p_buf, p_fmt, vl_args );
...@@ -285,89 +567,373 @@ static int PrintFullLine ( const char *p_fmt, ... ) ...@@ -285,89 +567,373 @@ static int PrintFullLine ( const char *p_fmt, ... )
if ( p_buf == NULL ) if ( p_buf == NULL )
{ {
return -1; return;
} }
if( w > 0 )
{
if( ( i_len = strlen( p_buf ) ) > w )
{
int i_cut = i_len - w;
int x1 = i_len/2 - i_cut/2;
int x2 = x1 + i_cut;
i_len = strlen( p_buf ); if( i_len > x2 )
{
memmove( &p_buf[x1], &p_buf[x2], i_len - x2 );
}
p_buf[w] = '\0';
if( w > 7 )
{
p_buf[w/2-1] = '.';
p_buf[w/2 ] = '.';
p_buf[w/2+1] = '.';
}
mvprintw( y, x, "%s", p_buf );
}
else
{
mvprintw( y, x, "%s", p_buf );
mvhline( y, x + i_len, ' ', w - i_len );
}
}
}
static void MainBoxWrite( intf_thread_t *p_intf, int l, int x, const char *p_fmt, ... )
{
intf_sys_t *p_sys = p_intf->p_sys;
/* va_list vl_args;
* make sure we don't exceed the border on the right side char *p_buf = NULL;
*/
if ( i_len > COLS ) if( l < p_sys->i_box_start || l - p_sys->i_box_start >= p_sys->i_box_lines )
{ {
p_buf[COLS] = '\0'; return;
i_len = COLS;
printw( "%s", p_buf );
} }
else
va_start ( vl_args, p_fmt );
vasprintf ( &p_buf, p_fmt, vl_args );
va_end ( vl_args );
if( p_buf == NULL )
{ {
printw( "%s", p_buf ); return;
hline( ' ', COLS - i_len );
} }
free ( p_buf ); mvnprintw( p_sys->i_box_y + l - p_sys->i_box_start, x, COLS - x - 1, "%s", p_buf );
return i_len;
} }
static void static void Redraw ( intf_thread_t *p_intf, time_t *t_last_refresh )
Redraw ( intf_thread_t *p_intf, time_t *t_last_refresh )
{ {
int row = 0; intf_sys_t *p_sys = p_intf->p_sys;
input_thread_t *p_input = p_sys->p_input;
int y = 0;
int h;
int y_end;
move ( row, 0 ); //clear();
/* Title */
attrset ( A_REVERSE ); attrset ( A_REVERSE );
PrintFullLine( VOUT_TITLE " (ncurses interface)" ); mvnprintw( y, 0, COLS, VOUT_TITLE " (ncurses interface) [ h for help ]" );
attroff ( A_REVERSE ); attroff ( A_REVERSE );
y += 2;
row++; /* Infos */
if( p_input && !p_input->b_dead )
{
char buf1[MSTRTIME_MAX_SIZE];
char buf2[MSTRTIME_MAX_SIZE];
vlc_value_t val;
vlc_value_t val_list;
row++; /* Source */
move ( row, 0 ); mvnprintw( y++, 0, COLS, " Source : %s", p_input->psz_source );
if ( p_intf->p_sys->p_input != NULL ) /* State */
var_Get( p_input, "state", &val );
if( val.i_int == PLAYING_S )
{
mvnprintw( y++, 0, COLS, " State : Playing" );
}
else if( val.i_int == PAUSE_S )
{
mvnprintw( y++, 0, COLS, " State : Paused" );
}
else
{
y++;
}
if( val.i_int != INIT_S && val.i_int != END_S )
{
/* Position */
var_Get( p_input, "time", &val );
msecstotimestr( buf1, val.i_time / 1000 );
var_Get( p_input, "length", &val );
msecstotimestr( buf2, val.i_time / 1000 );
mvnprintw( y++, 0, COLS, " Position : %s/%s (%.2f%%)", buf1, buf2, p_sys->f_slider );
/* Title */
if( !var_Get( p_input, "title", &val ) )
{
var_Change( p_input, "title", VLC_VAR_GETCHOICES, &val_list, NULL );
if( val_list.p_list->i_count > 0 )
{
mvnprintw( y++, 0, COLS, " Title : %d/%d", val.i_int, val_list.p_list->i_count );
}
var_Change( p_input, "title", VLC_VAR_FREELIST, &val_list, NULL );
}
/* Chapter */
if( !var_Get( p_input, "chapter", &val ) )
{
var_Change( p_input, "chapter", VLC_VAR_GETCHOICES, &val_list, NULL );
if( val_list.p_list->i_count > 0 )
{
mvnprintw( y++, 0, COLS, " Chapter : %d/%d", val.i_int, val_list.p_list->i_count );
}
var_Change( p_input, "chapter", VLC_VAR_FREELIST, &val_list, NULL );
}
}
else
{
y++;
}
}
else
{ {
PrintFullLine ( " DVD Chapter:%3d DVD Title:%3d", mvnprintw( y++, 0, COLS, "Source: <no current item>" );
p_intf->p_sys->p_input->stream.p_selected_area->i_part, DrawEmptyLine( p_sys->w, y++, 0, COLS );
p_intf->p_sys->p_input->stream.p_selected_area->i_id ); DrawEmptyLine( p_sys->w, y++, 0, COLS );
} }
row++; DrawBox( p_sys->w, y, 0, 3, COLS, "" );
mvaddch ( row, 0, ACS_ULCORNER ); DrawEmptyLine( p_sys->w, y+1, 1, COLS-2);
mvhline ( row, 1, ACS_HLINE, COLS-2 ); DrawLine( p_sys->w, y+1, 1, (int)(p_intf->p_sys->f_slider/100.0 * (COLS -2)) );
mvaddch ( row, COLS-1, ACS_URCORNER ); y += 3;
row++; p_sys->i_box_y = y + 1;
mvaddch ( row, 0, ACS_VLINE ); p_sys->i_box_lines = LINES - y - 2;
attrset ( A_REVERSE );
mvhline ( row, 1, ' ', ( (int) p_intf->p_sys->f_slider_state % COLS-2) );
attroff ( A_REVERSE );
mvaddch ( row, COLS-1, ACS_VLINE );
row++; h = LINES - y;
mvaddch ( row, 0, ACS_LLCORNER ); y_end = y + h - 1;
mvhline ( row, 1, ACS_HLINE, COLS-2 );
mvaddch ( row, COLS-1, ACS_LRCORNER );
refresh(); if( p_sys->i_box_type == BOX_HELP )
{
/* Help box */
int l = 0;
DrawBox( p_sys->w, y++, 0, h, COLS, " Help " );
MainBoxWrite( p_intf, l++, 1, "[Display]" );
MainBoxWrite( p_intf, l++, 1, " h,H Show/Hide help box" );
MainBoxWrite( p_intf, l++, 1, " i Show/Hide informations box" );
MainBoxWrite( p_intf, l++, 1, " l Show/Hide logs box" );
MainBoxWrite( p_intf, l++, 1, " P Show/Hide playlist box" );
MainBoxWrite( p_intf, l++, 1, "" );
MainBoxWrite( p_intf, l++, 1, "[Global]" );
MainBoxWrite( p_intf, l++, 1, " q, Q Quit" );
MainBoxWrite( p_intf, l++, 1, " s Stop" );
MainBoxWrite( p_intf, l++, 1, " <space> Pause/Play" );
MainBoxWrite( p_intf, l++, 1, " n, p Next/Previous item" );
MainBoxWrite( p_intf, l++, 1, " [, ] Next/Previous title" );
MainBoxWrite( p_intf, l++, 1, " <, > Next/Previous title" );
MainBoxWrite( p_intf, l++, 1, " <right> Seek +5%%" );
MainBoxWrite( p_intf, l++, 1, " <left> Seek -5%%" );
MainBoxWrite( p_intf, l++, 1, "" );
MainBoxWrite( p_intf, l++, 1, "[Playlist]" );
MainBoxWrite( p_intf, l++, 1, " r Randomize playlist" );
MainBoxWrite( p_intf, l++, 1, " o Order Playlist" );
MainBoxWrite( p_intf, l++, 1, " O Reverse order Playlist" );
MainBoxWrite( p_intf, l++, 1, " <del> Delete an entry" );
MainBoxWrite( p_intf, l++, 1, " <backspace> Delete an entry" );
MainBoxWrite( p_intf, l++, 1, "" );
MainBoxWrite( p_intf, l++, 1, "[Boxes]" );
MainBoxWrite( p_intf, l++, 1, " <up>,<down> Navigate through the box line by line" );
MainBoxWrite( p_intf, l++, 1, " <pgup>,<pgdown> Navigate through the box page by page" );
MainBoxWrite( p_intf, l++, 1, "" );
MainBoxWrite( p_intf, l++, 1, "[Player]" );
MainBoxWrite( p_intf, l++, 1, " <up>,<down> Seek +/-20%%" );
MainBoxWrite( p_intf, l++, 1, "" );
MainBoxWrite( p_intf, l++, 1, "[Miscellaneous]" );
MainBoxWrite( p_intf, l++, 1, " Ctrl-L Refresh the screen" );
p_sys->i_box_lines_total = l;
if( p_sys->i_box_start >= p_sys->i_box_lines_total )
{
p_sys->i_box_start = p_sys->i_box_lines_total - 1;
}
*t_last_refresh = time( 0 ); if( l - p_sys->i_box_start < p_sys->i_box_lines )
} {
y += l - p_sys->i_box_start;
}
else
{
y += p_sys->i_box_lines;
}
}
else if( p_sys->i_box_type == BOX_INFO )
{
/* Info box */
int l = 0;
DrawBox( p_sys->w, y++, 0, h, COLS, " Informations " );
static void FullScreen( intf_thread_t *p_intf ) if( p_input )
{ {
vout_thread_t *p_vout; input_info_category_t * p_category;
input_info_t * p_info;
vlc_mutex_lock( &p_input->stream.stream_lock );
p_category = p_input->stream.p_info;
while ( p_category )
{
if( y >= y_end ) break;
MainBoxWrite( p_intf, l++, 1, " [%s]", p_category->psz_name );
p_info = p_category->p_info;
while ( p_info )
{
if( y >= y_end ) break;
MainBoxWrite( p_intf, l++, 1, " %s: %s", p_info->psz_name, p_info->psz_value );
p_info = p_info->p_next;
}
p_category = p_category->p_next;
}
vlc_mutex_unlock( &p_input->stream.stream_lock );
}
else
{
MainBoxWrite( p_intf, l++, 1, "No item currently playing" );
}
p_sys->i_box_lines_total = l;
if( p_sys->i_box_start >= p_sys->i_box_lines_total )
{
p_sys->i_box_start = p_sys->i_box_lines_total - 1;
}
if( l - p_sys->i_box_start < p_sys->i_box_lines )
{
y += l - p_sys->i_box_start;
}
else
{
y += p_sys->i_box_lines;
}
}
else if( p_sys->i_box_type == BOX_LOG )
{
int i_line = 0;
int i_stop;
int i_start;
DrawBox( p_sys->w, y++, 0, h, COLS, " Logs " );
i_start = p_intf->p_sys->p_sub->i_start;
p_vout = vlc_object_find( p_intf->p_sys->p_input, vlc_mutex_lock( p_intf->p_sys->p_sub->p_lock );
VLC_OBJECT_VOUT, FIND_CHILD ); i_stop = *p_intf->p_sys->p_sub->pi_stop;
if( p_vout == NULL ) vlc_mutex_unlock( p_intf->p_sys->p_sub->p_lock );
for( ;; )
{
static const char *ppsz_type[4] = { "", "error", "warning", "debug" };
if( i_line >= h - 2 )
{
break;
}
i_stop--;
i_line++;
if( i_stop < 0 ) i_stop += VLC_MSG_QSIZE;
if( i_stop == i_start )
{
break;
}
mvnprintw( y + h-2-i_line, 1, COLS - 2, " [%s] %s",
ppsz_type[p_sys->p_sub->p_msg[i_stop].i_type],
p_sys->p_sub->p_msg[i_stop].psz_msg );
}
vlc_mutex_lock( p_intf->p_sys->p_sub->p_lock );
p_intf->p_sys->p_sub->i_start = i_stop;
vlc_mutex_unlock( p_intf->p_sys->p_sub->p_lock );
y = y_end;
}
else if( p_sys->i_box_type == BOX_PLAYLIST && p_sys->p_playlist )
{ {
return; /* Playlist box */
playlist_t *p_playlist = p_sys->p_playlist;
int i_start, i_stop;
int i_item;
DrawBox( p_sys->w, y++, 0, h, COLS, " Playlist " );
if( p_playlist->i_index < (h - 2)/2 )
{
i_start = 0;
i_stop = h - 2;
}
else if( p_playlist->i_size - p_playlist->i_index > (h - 2)/2 )
{
i_start = p_playlist->i_index - (h - 2)/2;
i_stop = i_start + h - 2;
}
else
{
i_stop = p_playlist->i_size;
i_start = p_playlist->i_size - (h - 2);
}
if( i_start < 0 )
{
i_start = 0;
}
if( i_stop > p_playlist->i_size )
{
i_stop = p_playlist->i_size;
}
for( i_item = i_start; i_item < i_stop; i_item++ )
{
vlc_bool_t b_selected = ( p_playlist->i_index == i_item );
if( y >= y_end ) break;
if( b_selected )
{
attrset( A_REVERSE );
}
if( !strcmp( p_playlist->pp_items[i_item]->psz_name, p_playlist->pp_items[i_item]->psz_uri ) )
{
mvnprintw( y++, 1, COLS - 2, " %d - '%s'",
i_item,
p_playlist->pp_items[i_item]->psz_uri );
}
else
{
mvnprintw( y++, 1, COLS - 2, " %d - '%s' (%s)",
i_item,
p_playlist->pp_items[i_item]->psz_uri,
p_playlist->pp_items[i_item]->psz_name );
}
if( b_selected )
{
attroff ( A_REVERSE );
}
}
}
else
{
y++;
} }
p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE; while( y < y_end )
vlc_object_release( p_vout ); {
DrawEmptyLine( p_sys->w, y++, 1, COLS - 2 );
}
refresh();
*t_last_refresh = time( 0 );
} }
static void Eject ( intf_thread_t *p_intf ) static void Eject ( intf_thread_t *p_intf )
...@@ -480,193 +1046,77 @@ static void Eject ( intf_thread_t *p_intf ) ...@@ -480,193 +1046,77 @@ static void Eject ( intf_thread_t *p_intf )
return; return;
} }
static void Play ( intf_thread_t *p_intf ) static void PlayPause ( intf_thread_t *p_intf )
{ {
playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, input_thread_t *p_input = p_intf->p_sys->p_input;
FIND_ANYWHERE ); vlc_value_t val;
if( p_playlist )
{
vlc_mutex_lock( &p_playlist->object_lock );
if( p_playlist->i_size ) if( p_input )
{
var_Get( p_input, "state", &val );
if( val.i_int != PAUSE_S )
{ {
vlc_mutex_unlock( &p_playlist->object_lock ); val.i_int = PAUSE_S;
playlist_Play( p_playlist );
vlc_object_release( p_playlist );
} }
else else
{ {
vlc_mutex_unlock( &p_playlist->object_lock ); val.i_int = PLAYING_S;
vlc_object_release( p_playlist );
} }
var_Set( p_input, "state", val );
} }
} else if( p_intf->p_sys->p_playlist )
static void Pause ( intf_thread_t *p_intf )
{
if( p_intf->p_sys->p_input == NULL )
{ {
return; playlist_Play( p_intf->p_sys->p_playlist );
}
input_SetStatus( p_intf->p_sys->p_input, INPUT_STATUS_PAUSE );
return;
}
static void Stop ( intf_thread_t *p_intf )
{
playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
FIND_ANYWHERE );
if( p_playlist == NULL )
{
return;
} }
playlist_Stop( p_playlist );
vlc_object_release( p_playlist );
return;
} }
static void Next ( intf_thread_t *p_intf ) /****************************************************************************
*
****************************************************************************/
static void DrawBox( WINDOW *win, int y, int x, int h, int w, char *title )
{ {
input_area_t * p_area; int i;
int i_id; int i_len;
vlc_mutex_lock( &p_intf->p_sys->p_input->stream.stream_lock ); if( w > 3 && h > 2 )
i_id = p_intf->p_sys->p_input->stream.p_selected_area->i_id + 1;
if ( i_id < p_intf->p_sys->p_input->stream.i_area_nb )
{ {
p_area = p_intf->p_sys->p_input->stream.pp_areas[i_id]; if( title == NULL ) title = "";
vlc_mutex_unlock( &p_intf->p_sys->p_input->stream.stream_lock ); i_len = strlen( title );
input_ChangeArea( p_intf->p_sys->p_input, p_area );
input_SetStatus( p_intf->p_sys->p_input, INPUT_STATUS_PLAY );
}
vlc_mutex_unlock( &p_intf->p_sys->p_input->stream.stream_lock ); if( i_len > w - 2 ) i_len = w - 2;
}
static void ManageSlider ( intf_thread_t *p_intf ) mvwaddch( win, y, x, ACS_ULCORNER );
{ mvwhline( win, y, x+1, ACS_HLINE, ( w-i_len-2)/2 );
if( p_intf->p_sys->p_input != NULL ) mvwprintw( win,y, x+1+(w-i_len-2)/2, "%s", title );
{ mvwhline( win, y, x+(w-i_len)/2+i_len, ACS_HLINE, w - 1 - ((w-i_len)/2+i_len) );
vlc_mutex_lock( &p_intf->p_sys->p_input->stream.stream_lock ); mvwaddch( win, y, x+w-1,ACS_URCORNER );
if( p_intf->p_sys->p_input->stream.b_seekable && for( i = 0; i < h-2; i++ )
p_intf->p_sys->p_input->stream.control.i_status == PLAYING_S )
{ {
float newvalue = p_intf->p_sys->f_slider_state; mvwaddch( win, y+i+1, x, ACS_VLINE );
mvwaddch( win, y+i+1, x+w-1, ACS_VLINE );
#define p_area p_intf->p_sys->p_input->stream.p_selected_area
/* If the user hasn't touched the slider since the last time,
* then the input can safely change it */
if( newvalue == p_intf->p_sys->f_slider_state_old )
{
/* Update the value */
p_intf->p_sys->f_slider_state =
p_intf->p_sys->f_slider_state_old =
( 100 * p_area->i_tell ) / p_area->i_size;
}
/* Otherwise, send message to the input if the user has
* finished dragging the slider */
else
{
off_t i_seek = ( newvalue * p_area->i_size ) / 100;
/* release the lock to be able to seek */
vlc_mutex_unlock( &p_intf->p_sys->p_input->stream.stream_lock );
input_Seek( p_intf, i_seek, INPUT_SEEK_SET );
vlc_mutex_lock( &p_intf->p_sys->p_input->stream.stream_lock );
/* Update the old value */
p_intf->p_sys->f_slider_state_old = newvalue;
}
# undef p_area
} }
vlc_mutex_unlock( &p_intf->p_sys->p_input->stream.stream_lock ); mvwaddch( win, y+h-1, x, ACS_LLCORNER );
mvwhline( win, y+h-1, x+1, ACS_HLINE, w - 2 );
mvwaddch( win, y+h-1, x+w-1, ACS_LRCORNER );
} }
} }
static void PrevTitle ( intf_thread_t *p_intf ) static void DrawEmptyLine( WINDOW *win, int y, int x, int w )
{ {
input_area_t * p_area; if( w > 0 )
int i_id;
vlc_mutex_lock( &p_intf->p_sys->p_input->stream.stream_lock );
i_id = p_intf->p_sys->p_input->stream.p_selected_area->i_id - 1;
if ( i_id > 0 )
{ {
p_area = p_intf->p_sys->p_input->stream.pp_areas[i_id]; mvhline( y, x, ' ', w );
vlc_mutex_unlock( &p_intf->p_sys->p_input->stream.stream_lock );
input_ChangeArea( p_intf->p_sys->p_input, p_area );
input_SetStatus( p_intf->p_sys->p_input, INPUT_STATUS_PLAY );
} }
vlc_mutex_unlock( &p_intf->p_sys->p_input->stream.stream_lock );
} }
static void NextTitle ( intf_thread_t *p_intf ) static void DrawLine( WINDOW *win, int y, int x, int w )
{ {
input_area_t * p_area; if( w > 0 )
int i_id;
vlc_mutex_lock( &p_intf->p_sys->p_input->stream.stream_lock );
i_id = p_intf->p_sys->p_input->stream.p_selected_area->i_id + 1;
if ( i_id < p_intf->p_sys->p_input->stream.i_area_nb )
{ {
p_area = p_intf->p_sys->p_input->stream.pp_areas[i_id]; attrset( A_REVERSE );
vlc_mutex_unlock( &p_intf->p_sys->p_input->stream.stream_lock ); mvhline( y, x, ' ', w );
attroff ( A_REVERSE );
input_ChangeArea( p_intf->p_sys->p_input, p_area );
input_SetStatus( p_intf->p_sys->p_input, INPUT_STATUS_PLAY );
} }
vlc_mutex_unlock( &p_intf->p_sys->p_input->stream.stream_lock );
}
static void PrevChapter ( intf_thread_t *p_intf )
{
input_area_t * p_area;
vlc_mutex_lock( &p_intf->p_sys->p_input->stream.stream_lock );
p_area = p_intf->p_sys->p_input->stream.p_selected_area;
if ( p_area->i_part > 0 )
{
p_area->i_part--;
vlc_mutex_unlock( &p_intf->p_sys->p_input->stream.stream_lock );
input_ChangeArea( p_intf->p_sys->p_input, p_area );
input_SetStatus( p_intf->p_sys->p_input, INPUT_STATUS_PLAY );
}
vlc_mutex_unlock( &p_intf->p_sys->p_input->stream.stream_lock );
} }
static void NextChapter( intf_thread_t *p_intf )
{
input_area_t * p_area;
vlc_mutex_lock( &p_intf->p_sys->p_input->stream.stream_lock );
p_area = p_intf->p_sys->p_input->stream.p_selected_area;
if ( p_area->i_part < p_area->i_part_nb )
{
p_area->i_part++;
vlc_mutex_unlock( &p_intf->p_sys->p_input->stream.stream_lock );
input_ChangeArea( p_intf->p_sys->p_input, p_area );
input_SetStatus( p_intf->p_sys->p_input, INPUT_STATUS_PLAY );
}
vlc_mutex_unlock( &p_intf->p_sys->p_input->stream.stream_lock );
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment