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 @@
* ncurses.c : NCurses plugin for vlc
*****************************************************************************
* 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>
* Laurent Aimar <fenrir@via.ecp.fr>
*
* 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
......@@ -55,20 +56,11 @@ static int Open ( vlc_object_t * );
static void Close ( vlc_object_t * );
static void Run ( intf_thread_t * );
static void FullScreen ( intf_thread_t * );
static void Play ( intf_thread_t * );
static void Stop ( intf_thread_t * );
static void Next ( intf_thread_t * );
static void PlayPause ( 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 void Redraw ( intf_thread_t *, time_t * );
static int PrintFullLine ( const char *p_fmt, ... );
static void ManageSlider ( intf_thread_t * );
/*****************************************************************************
......@@ -84,35 +76,63 @@ vlc_module_end();
/*****************************************************************************
* intf_sys_t: description and status of ncurses interface
*****************************************************************************/
enum
{
BOX_NONE,
BOX_HELP,
BOX_INFO,
BOX_LOG,
BOX_PLAYLIST
};
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;
float f_slider_state;
float f_slider_state_old;
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;
msg_subscription_t* p_sub; /* message bank subscription */
};
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
*****************************************************************************/
static int Open( vlc_object_t *p_this )
{
intf_thread_t *p_intf = (intf_thread_t *)p_this;
intf_sys_t *p_sys;
/* Allocate instance and initialize some members */
p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
if( p_intf->p_sys == NULL )
{
msg_Err( p_intf, "out of memory" );
return VLC_ENOMEM;
}
p_intf->p_sys->p_input = NULL;
p_intf->pf_run = Run;
p_sys = p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
p_sys->p_playlist = NULL;
p_sys->p_input = NULL;
p_sys->f_slider = 0.0;
p_sys->f_slider_old = 0.0;
p_sys->i_box_type = BOX_PLAYLIST;
p_sys->i_box_lines = 0;
p_sys->i_box_start= 0;
p_sys->i_box_lines_total = 0;
p_sys->b_box_cleared = VLC_FALSE;
p_sys->p_sub = msg_Subscribe( p_intf );
/* Initialize the curses library */
initscr();
p_sys->w = initscr();
keypad( p_sys->w, TRUE );
/* Don't do NL -> CR/NL */
nonl();
/* Take input chars one at a time */
......@@ -125,6 +145,9 @@ static int Open( vlc_object_t *p_this )
clear();
/* exported function */
p_intf->pf_run = Run;
return VLC_SUCCESS;
}
......@@ -134,17 +157,24 @@ static int Open( vlc_object_t *p_this )
static void Close( vlc_object_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 */
endwin();
msg_Unsubscribe( p_intf, p_sys->p_sub );
/* Destroy structure */
free( p_intf->p_sys );
free( p_sys );
}
/*****************************************************************************
......@@ -152,7 +182,9 @@ static void Close( vlc_object_t *p_this )
*****************************************************************************/
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;
/*
......@@ -165,18 +197,33 @@ static void Run( intf_thread_t *p_intf )
msleep( INTF_IDLE_SLEEP );
/* Update the input */
if( p_intf->p_sys->p_input == NULL )
if( p_sys->p_playlist == NULL )
{
p_sys->p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, 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_intf->p_sys->p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT,
p_sys->p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT,
FIND_ANYWHERE );
}
else if( p_intf->p_sys->p_input->b_dead )
p_sys->b_box_cleared = VLC_FALSE;
}
else if( p_sys->p_input->b_dead )
{
vlc_object_release( p_intf->p_sys->p_input );
p_intf->p_sys->p_input = NULL;
vlc_object_release( p_sys->p_input );
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
......@@ -186,6 +233,13 @@ static void Run( intf_thread_t *p_intf )
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
......@@ -202,31 +256,209 @@ static void Run( intf_thread_t *p_intf )
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 )
{
case 'q':
case 'Q':
case 0x1b: /* Esc */
p_intf->b_die = 1;
return 0;
case 'f':
FullScreen( p_intf );
/* Box switching */
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;
case 'p':
Play( p_intf );
/* Navigation */
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;
case ' ':
Pause( p_intf );
case KEY_LEFT:
p_sys->f_slider -= 5.0;
if( p_sys->f_slider < 0.0 ) p_sys->f_slider = 0.0;
ManageSlider ( p_intf );
return 1;
case 's':
Stop( p_intf );
/* Common control */
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;
case 'n':
Next( p_intf );
case 's':
if( p_intf->p_sys->p_playlist )
{
playlist_Stop( p_intf->p_sys->p_playlist );
}
return 1;
case 'e':
......@@ -234,30 +466,51 @@ static int HandleKey( intf_thread_t *p_intf, int i_key )
return 1;
case '[':
PrevTitle( p_intf );
if( p_sys->p_input )
{
val.b_bool = VLC_TRUE;
var_Set( p_sys->p_input, "prev-title", val );
}
break;
case ']':
NextTitle( p_intf );
if( p_sys->p_input )
{
val.b_bool = VLC_TRUE;
var_Set( p_sys->p_input, "next-title", val );
}
break;
case '<':
PrevChapter( p_intf );
if( p_sys->p_input )
{
val.b_bool = VLC_TRUE;
var_Set( p_sys->p_input, "prev-chapter", val );
}
break;
case '>':
NextChapter( p_intf );
break;
case KEY_RIGHT:
p_intf->p_sys->f_slider_state += 100;
ManageSlider ( p_intf );
if( p_sys->p_input )
{
val.b_bool = VLC_TRUE;
var_Set( p_sys->p_input, "next-chapter", val );
}
break;
case KEY_LEFT:
p_intf->p_sys->f_slider_state--;
ManageSlider ( p_intf );
break;
case 'p':
if( p_intf->p_sys->p_playlist )
{
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
......@@ -267,16 +520,45 @@ static int HandleKey( intf_thread_t *p_intf, int i_key )
return 1;
default:
break;
return 0;
}
}
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;
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;
char * p_buf = NULL;
char *p_buf = NULL;
int i_len;
va_start ( vl_args, p_fmt );
......@@ -285,89 +567,373 @@ static int PrintFullLine ( const char *p_fmt, ... )
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 );
/*
* make sure we don't exceed the border on the right side
*/
if ( i_len > COLS )
if( i_len > x2 )
{
memmove( &p_buf[x1], &p_buf[x2], i_len - x2 );
}
p_buf[w] = '\0';
if( w > 7 )
{
p_buf[COLS] = '\0';
i_len = COLS;
printw( "%s", p_buf );
p_buf[w/2-1] = '.';
p_buf[w/2 ] = '.';
p_buf[w/2+1] = '.';
}
mvprintw( y, x, "%s", p_buf );
}
else
{
printw( "%s", p_buf );
hline( ' ', COLS - i_len );
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;
char *p_buf = NULL;
if( l < p_sys->i_box_start || l - p_sys->i_box_start >= p_sys->i_box_lines )
{
return;
}
free ( p_buf );
va_start ( vl_args, p_fmt );
vasprintf ( &p_buf, p_fmt, vl_args );
va_end ( vl_args );
if( p_buf == NULL )
{
return;
}
return i_len;
mvnprintw( p_sys->i_box_y + l - p_sys->i_box_start, x, COLS - x - 1, "%s", p_buf );
}
static void
Redraw ( intf_thread_t *p_intf, time_t *t_last_refresh )
static void 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 );
PrintFullLine( VOUT_TITLE " (ncurses interface)" );
mvnprintw( y, 0, COLS, VOUT_TITLE " (ncurses interface) [ h for help ]" );
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++;
move ( row, 0 );
/* Source */
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 )
{
PrintFullLine ( " DVD Chapter:%3d DVD Title:%3d",
p_intf->p_sys->p_input->stream.p_selected_area->i_part,
p_intf->p_sys->p_input->stream.p_selected_area->i_id );
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 );
row++;
mvaddch ( row, 0, ACS_ULCORNER );
mvhline ( row, 1, ACS_HLINE, COLS-2 );
mvaddch ( row, COLS-1, ACS_URCORNER );
var_Get( p_input, "length", &val );
msecstotimestr( buf2, val.i_time / 1000 );
row++;
mvaddch ( row, 0, ACS_VLINE );
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 );
mvnprintw( y++, 0, COLS, " Position : %s/%s (%.2f%%)", buf1, buf2, p_sys->f_slider );
row++;
mvaddch ( row, 0, ACS_LLCORNER );
mvhline ( row, 1, ACS_HLINE, COLS-2 );
mvaddch ( row, COLS-1, ACS_LRCORNER );
/* 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 );
}
refresh();
/* 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
{
mvnprintw( y++, 0, COLS, "Source: <no current item>" );
DrawEmptyLine( p_sys->w, y++, 0, COLS );
DrawEmptyLine( p_sys->w, y++, 0, COLS );
}
*t_last_refresh = time( 0 );
}
DrawBox( p_sys->w, y, 0, 3, COLS, "" );
DrawEmptyLine( p_sys->w, y+1, 1, COLS-2);
DrawLine( p_sys->w, y+1, 1, (int)(p_intf->p_sys->f_slider/100.0 * (COLS -2)) );
y += 3;
static void FullScreen( intf_thread_t *p_intf )
{
vout_thread_t *p_vout;
p_sys->i_box_y = y + 1;
p_sys->i_box_lines = LINES - y - 2;
p_vout = vlc_object_find( p_intf->p_sys->p_input,
VLC_OBJECT_VOUT, FIND_CHILD );
if( p_vout == NULL )
h = LINES - y;
y_end = y + h - 1;
if( p_sys->i_box_type == BOX_HELP )
{
return;
/* 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;
}
p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
vlc_object_release( p_vout );
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 " );
if( p_input )
{
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;
vlc_mutex_lock( p_intf->p_sys->p_sub->p_lock );
i_stop = *p_intf->p_sys->p_sub->pi_stop;
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 )
{
/* 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++;
}
while( y < y_end )
{
DrawEmptyLine( p_sys->w, y++, 1, COLS - 2 );
}
refresh();
*t_last_refresh = time( 0 );
}
static void Eject ( intf_thread_t *p_intf )
......@@ -480,193 +1046,77 @@ static void Eject ( intf_thread_t *p_intf )
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,
FIND_ANYWHERE );
if( p_playlist )
{
vlc_mutex_lock( &p_playlist->object_lock );
input_thread_t *p_input = p_intf->p_sys->p_input;
vlc_value_t val;
if( p_playlist->i_size )
if( p_input )
{
vlc_mutex_unlock( &p_playlist->object_lock );
playlist_Play( p_playlist );
vlc_object_release( p_playlist );
var_Get( p_input, "state", &val );
if( val.i_int != PAUSE_S )
{
val.i_int = PAUSE_S;
}
else
{
vlc_mutex_unlock( &p_playlist->object_lock );
vlc_object_release( p_playlist );
val.i_int = PLAYING_S;
}
var_Set( p_input, "state", val );
}
}
static void Pause ( intf_thread_t *p_intf )
{
if( p_intf->p_sys->p_input == NULL )
else if( p_intf->p_sys->p_playlist )
{
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 )
{
input_area_t * p_area;
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];
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 ManageSlider ( intf_thread_t *p_intf )
/****************************************************************************
*
****************************************************************************/
static void DrawBox( WINDOW *win, int y, int x, int h, int w, char *title )
{
if( p_intf->p_sys->p_input != NULL )
{
vlc_mutex_lock( &p_intf->p_sys->p_input->stream.stream_lock );
if( p_intf->p_sys->p_input->stream.b_seekable &&
p_intf->p_sys->p_input->stream.control.i_status == PLAYING_S )
{
float newvalue = p_intf->p_sys->f_slider_state;
#define p_area p_intf->p_sys->p_input->stream.p_selected_area
int i;
int i_len;
/* 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 )
if( w > 3 && h > 2 )
{
/* 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 );
}
}
if( title == NULL ) title = "";
i_len = strlen( title );
static void PrevTitle ( intf_thread_t *p_intf )
{
input_area_t * p_area;
int i_id;
if( i_len > w - 2 ) i_len = w - 2;
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;
mvwaddch( win, y, x, ACS_ULCORNER );
mvwhline( win, y, x+1, ACS_HLINE, ( w-i_len-2)/2 );
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) );
mvwaddch( win, y, x+w-1,ACS_URCORNER );
if ( i_id > 0 )
for( i = 0; i < h-2; i++ )
{
p_area = p_intf->p_sys->p_input->stream.pp_areas[i_id];
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 );
mvwaddch( win, y+i+1, x, ACS_VLINE );
mvwaddch( win, y+i+1, x+w-1, ACS_VLINE );
}
vlc_mutex_unlock( &p_intf->p_sys->p_input->stream.stream_lock );
}
static void NextTitle ( intf_thread_t *p_intf )
{
input_area_t * p_area;
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];
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 );
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 );
}
vlc_mutex_unlock( &p_intf->p_sys->p_input->stream.stream_lock );
}
static void PrevChapter ( intf_thread_t *p_intf )
static void DrawEmptyLine( WINDOW *win, int y, int x, int w )
{
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 )
if( w > 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 );
mvhline( y, x, ' ', w );
}
vlc_mutex_unlock( &p_intf->p_sys->p_input->stream.stream_lock );
}
static void NextChapter( intf_thread_t *p_intf )
static void DrawLine( WINDOW *win, int y, int x, int w )
{
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 )
if( w > 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 );
attrset( A_REVERSE );
mvhline( y, x, ' ', w );
attroff ( A_REVERSE );
}
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