Commit 5e57cc0c authored by Rémi Duraffort's avatar Rémi Duraffort

ncurses: factorize (no need to use a macro here).

parent 4d17b40d
...@@ -549,18 +549,7 @@ static int HandleKey( intf_thread_t *p_intf, int i_key ) ...@@ -549,18 +549,7 @@ static int HandleKey( intf_thread_t *p_intf, int i_key )
{ {
intf_sys_t *p_sys = p_intf->p_sys; intf_sys_t *p_sys = p_intf->p_sys;
vlc_value_t val; vlc_value_t val;
int i_ret = 1;
#define ReturnTrue \
do { \
pl_Release( p_intf ); \
return 1; \
} while(0)
#define ReturnFalse \
do { \
pl_Release( p_intf ); \
return 0; \
} while(0)
playlist_t *p_playlist = pl_Hold( p_intf ); playlist_t *p_playlist = pl_Hold( p_intf );
...@@ -577,17 +566,17 @@ static int HandleKey( intf_thread_t *p_intf, int i_key ) ...@@ -577,17 +566,17 @@ static int HandleKey( intf_thread_t *p_intf, int i_key )
var_Get( p_playlist, "random", &val ); var_Get( p_playlist, "random", &val );
val.b_bool = !val.b_bool; val.b_bool = !val.b_bool;
var_Set( p_playlist, "random", val ); var_Set( p_playlist, "random", val );
ReturnTrue; goto end;
case 'l': case 'l':
var_Get( p_playlist, "loop", &val ); var_Get( p_playlist, "loop", &val );
val.b_bool = !val.b_bool; val.b_bool = !val.b_bool;
var_Set( p_playlist, "loop", val ); var_Set( p_playlist, "loop", val );
ReturnTrue; goto end;
case 'R': case 'R':
var_Get( p_playlist, "repeat", &val ); var_Get( p_playlist, "repeat", &val );
val.b_bool = !val.b_bool; val.b_bool = !val.b_bool;
var_Set( p_playlist, "repeat", val ); var_Set( p_playlist, "repeat", val );
ReturnTrue; goto end;
/* Playlist sort */ /* Playlist sort */
case 'o': case 'o':
...@@ -595,13 +584,13 @@ static int HandleKey( intf_thread_t *p_intf, int i_key ) ...@@ -595,13 +584,13 @@ static int HandleKey( intf_thread_t *p_intf, int i_key )
PlaylistGetRoot( p_intf ), PlaylistGetRoot( p_intf ),
SORT_TITLE_NODES_FIRST, ORDER_NORMAL ); SORT_TITLE_NODES_FIRST, ORDER_NORMAL );
p_sys->b_need_update = true; p_sys->b_need_update = true;
ReturnTrue; goto end;
case 'O': case 'O':
playlist_RecursiveNodeSort( p_playlist, playlist_RecursiveNodeSort( p_playlist,
PlaylistGetRoot( p_intf ), PlaylistGetRoot( p_intf ),
SORT_TITLE_NODES_FIRST, ORDER_REVERSE ); SORT_TITLE_NODES_FIRST, ORDER_REVERSE );
p_sys->b_need_update = true; p_sys->b_need_update = true;
ReturnTrue; goto end;
/* Playlist view */ /* Playlist view */
case 'v': case 'v':
...@@ -615,7 +604,7 @@ static int HandleKey( intf_thread_t *p_intf, int i_key ) ...@@ -615,7 +604,7 @@ static int HandleKey( intf_thread_t *p_intf, int i_key )
} }
//p_sys->b_need_update = true; //p_sys->b_need_update = true;
PlaylistRebuild( p_intf ); PlaylistRebuild( p_intf );
ReturnTrue; goto end;
/* Playlist navigation */ /* Playlist navigation */
case 'g': case 'g':
...@@ -721,7 +710,7 @@ static int HandleKey( intf_thread_t *p_intf, int i_key ) ...@@ -721,7 +710,7 @@ static int HandleKey( intf_thread_t *p_intf, int i_key )
b_box_plidx_follow = true; b_box_plidx_follow = true;
PL_UNLOCK; PL_UNLOCK;
p_sys->b_box_plidx_follow = b_box_plidx_follow; p_sys->b_box_plidx_follow = b_box_plidx_follow;
ReturnTrue; goto end;
} }
} }
if( p_sys->i_box_type == BOX_BROWSE ) if( p_sys->i_box_type == BOX_BROWSE )
...@@ -804,7 +793,7 @@ static int HandleKey( intf_thread_t *p_intf, int i_key ) ...@@ -804,7 +793,7 @@ static int HandleKey( intf_thread_t *p_intf, int i_key )
{ {
if( p_sys->i_box_bidx >= p_sys->i_dir_entries ) p_sys->i_box_bidx = p_sys->i_dir_entries - 1; if( p_sys->i_box_bidx >= p_sys->i_dir_entries ) p_sys->i_box_bidx = p_sys->i_dir_entries - 1;
if( p_sys->i_box_bidx < 0 ) p_sys->i_box_bidx = 0; if( p_sys->i_box_bidx < 0 ) p_sys->i_box_bidx = 0;
ReturnTrue; goto end;
} }
} }
else if( p_sys->i_box_type == BOX_HELP || p_sys->i_box_type == BOX_INFO || else if( p_sys->i_box_type == BOX_HELP || p_sys->i_box_type == BOX_INFO ||
...@@ -815,33 +804,33 @@ static int HandleKey( intf_thread_t *p_intf, int i_key ) ...@@ -815,33 +804,33 @@ static int HandleKey( intf_thread_t *p_intf, int i_key )
{ {
case KEY_HOME: case KEY_HOME:
p_sys->i_box_start = 0; p_sys->i_box_start = 0;
ReturnTrue; goto end;
#ifdef __FreeBSD__ #ifdef __FreeBSD__
case KEY_SELECT: case KEY_SELECT:
#endif #endif
case KEY_END: case KEY_END:
p_sys->i_box_start = p_sys->i_box_lines_total - 1; p_sys->i_box_start = p_sys->i_box_lines_total - 1;
ReturnTrue; goto end;
case KEY_UP: case KEY_UP:
if( p_sys->i_box_start > 0 ) p_sys->i_box_start--; if( p_sys->i_box_start > 0 ) p_sys->i_box_start--;
ReturnTrue; goto end;
case KEY_DOWN: case KEY_DOWN:
if( p_sys->i_box_start < p_sys->i_box_lines_total - 1 ) if( p_sys->i_box_start < p_sys->i_box_lines_total - 1 )
{ {
p_sys->i_box_start++; p_sys->i_box_start++;
} }
ReturnTrue; goto end;
case KEY_PPAGE: case KEY_PPAGE:
p_sys->i_box_start -= p_sys->i_box_lines; p_sys->i_box_start -= p_sys->i_box_lines;
if( p_sys->i_box_start < 0 ) p_sys->i_box_start = 0; if( p_sys->i_box_start < 0 ) p_sys->i_box_start = 0;
ReturnTrue; goto end;
case KEY_NPAGE: case KEY_NPAGE:
p_sys->i_box_start += p_sys->i_box_lines; p_sys->i_box_start += p_sys->i_box_lines;
if( p_sys->i_box_start >= p_sys->i_box_lines_total ) 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_sys->i_box_start = p_sys->i_box_lines_total - 1;
} }
ReturnTrue; goto end;
default: default:
break; break;
} }
...@@ -853,24 +842,24 @@ static int HandleKey( intf_thread_t *p_intf, int i_key ) ...@@ -853,24 +842,24 @@ static int HandleKey( intf_thread_t *p_intf, int i_key )
case KEY_HOME: case KEY_HOME:
p_sys->f_slider = 0; p_sys->f_slider = 0;
ManageSlider( p_intf ); ManageSlider( p_intf );
ReturnTrue; goto end;
#ifdef __FreeBSD__ #ifdef __FreeBSD__
case KEY_SELECT: case KEY_SELECT:
#endif #endif
case KEY_END: case KEY_END:
p_sys->f_slider = 99.9; p_sys->f_slider = 99.9;
ManageSlider( p_intf ); ManageSlider( p_intf );
ReturnTrue; goto end;
case KEY_UP: case KEY_UP:
p_sys->f_slider += 5.0; p_sys->f_slider += 5.0;
if( p_sys->f_slider >= 99.0 ) p_sys->f_slider = 99.0; if( p_sys->f_slider >= 99.0 ) p_sys->f_slider = 99.0;
ManageSlider( p_intf ); ManageSlider( p_intf );
ReturnTrue; goto end;
case KEY_DOWN: case KEY_DOWN:
p_sys->f_slider -= 5.0; p_sys->f_slider -= 5.0;
if( p_sys->f_slider < 0.0 ) p_sys->f_slider = 0.0; if( p_sys->f_slider < 0.0 ) p_sys->f_slider = 0.0;
ManageSlider( p_intf ); ManageSlider( p_intf );
ReturnTrue; goto end;
default: default:
break; break;
...@@ -884,7 +873,7 @@ static int HandleKey( intf_thread_t *p_intf, int i_key ) ...@@ -884,7 +873,7 @@ static int HandleKey( intf_thread_t *p_intf, int i_key )
case KEY_CLEAR: case KEY_CLEAR:
case 0x0c: /* ^l */ case 0x0c: /* ^l */
clear(); clear();
ReturnTrue; goto end;
case KEY_ENTER: case KEY_ENTER:
case '\r': case '\r':
case '\n': case '\n':
...@@ -897,7 +886,7 @@ static int HandleKey( intf_thread_t *p_intf, int i_key ) ...@@ -897,7 +886,7 @@ static int HandleKey( intf_thread_t *p_intf, int i_key )
SearchPlaylist( p_intf, p_sys->psz_old_search ); SearchPlaylist( p_intf, p_sys->psz_old_search );
} }
p_sys->i_box_type = BOX_PLAYLIST; p_sys->i_box_type = BOX_PLAYLIST;
ReturnTrue; goto end;
case 0x1b: /* ESC */ case 0x1b: /* ESC */
/* Alt+key combinations return 2 keys in the terminal keyboard: /* Alt+key combinations return 2 keys in the terminal keyboard:
* ESC, and the 2nd key. * ESC, and the 2nd key.
...@@ -914,10 +903,13 @@ static int HandleKey( intf_thread_t *p_intf, int i_key ) ...@@ -914,10 +903,13 @@ static int HandleKey( intf_thread_t *p_intf, int i_key )
* *
*/ */
if( wgetch( p_sys->w ) != ERR ) if( wgetch( p_sys->w ) != ERR )
ReturnFalse; {
i_ret = 0;
goto end;
}
p_sys->i_box_plidx = p_sys->i_before_search; p_sys->i_box_plidx = p_sys->i_before_search;
p_sys->i_box_type = BOX_PLAYLIST; p_sys->i_box_type = BOX_PLAYLIST;
ReturnTrue; goto end;
case KEY_BACKSPACE: case KEY_BACKSPACE:
case 0x7f: case 0x7f:
RemoveLastUTF8Entity( p_sys->psz_search_chain, i_chain_len ); RemoveLastUTF8Entity( p_sys->psz_search_chain, i_chain_len );
...@@ -949,7 +941,7 @@ static int HandleKey( intf_thread_t *p_intf, int i_key ) ...@@ -949,7 +941,7 @@ static int HandleKey( intf_thread_t *p_intf, int i_key )
free( p_sys->psz_old_search ); free( p_sys->psz_old_search );
p_sys->psz_old_search = NULL; p_sys->psz_old_search = NULL;
SearchPlaylist( p_intf, p_sys->psz_search_chain ); SearchPlaylist( p_intf, p_sys->psz_search_chain );
ReturnTrue; goto end;
} }
else if( p_sys->i_box_type == BOX_OPEN && p_sys->psz_open_chain ) else if( p_sys->i_box_type == BOX_OPEN && p_sys->psz_open_chain )
{ {
...@@ -960,7 +952,7 @@ static int HandleKey( intf_thread_t *p_intf, int i_key ) ...@@ -960,7 +952,7 @@ static int HandleKey( intf_thread_t *p_intf, int i_key )
case KEY_CLEAR: case KEY_CLEAR:
case 0x0c: /* ^l */ case 0x0c: /* ^l */
clear(); clear();
ReturnTrue; break;
case KEY_ENTER: case KEY_ENTER:
case '\r': case '\r':
case '\n': case '\n':
...@@ -985,12 +977,15 @@ static int HandleKey( intf_thread_t *p_intf, int i_key ) ...@@ -985,12 +977,15 @@ static int HandleKey( intf_thread_t *p_intf, int i_key )
p_sys->b_box_plidx_follow = true; p_sys->b_box_plidx_follow = true;
} }
p_sys->i_box_type = BOX_PLAYLIST; p_sys->i_box_type = BOX_PLAYLIST;
ReturnTrue; break;
case 0x1b: /* ESC */ case 0x1b: /* ESC */
if( wgetch( p_sys->w ) != ERR ) if( wgetch( p_sys->w ) != ERR )
ReturnFalse; {
i_ret = 0;
break;
}
p_sys->i_box_type = BOX_PLAYLIST; p_sys->i_box_type = BOX_PLAYLIST;
ReturnTrue; break;
case KEY_BACKSPACE: case KEY_BACKSPACE:
case 0x7f: case 0x7f:
RemoveLastUTF8Entity( p_sys->psz_open_chain, i_chain_len ); RemoveLastUTF8Entity( p_sys->psz_open_chain, i_chain_len );
...@@ -1016,10 +1011,9 @@ static int HandleKey( intf_thread_t *p_intf, int i_key ) ...@@ -1016,10 +1011,9 @@ static int HandleKey( intf_thread_t *p_intf, int i_key )
free( psz_utf8 ); free( psz_utf8 );
} }
#endif #endif
break;
} }
} }
ReturnTrue; goto end;
} }
...@@ -1028,12 +1022,16 @@ static int HandleKey( intf_thread_t *p_intf, int i_key ) ...@@ -1028,12 +1022,16 @@ static int HandleKey( intf_thread_t *p_intf, int i_key )
{ {
case 0x1b: /* ESC */ case 0x1b: /* ESC */
if( wgetch( p_sys->w ) != ERR ) if( wgetch( p_sys->w ) != ERR )
ReturnFalse; {
i_ret = 0;
break;
}
case 'q': case 'q':
case 'Q': case 'Q':
case KEY_EXIT: case KEY_EXIT:
libvlc_Quit( p_intf->p_libvlc ); libvlc_Quit( p_intf->p_libvlc );
ReturnFalse; i_ret = 0;
break;
/* Box switching */ /* Box switching */
case 'i': case 'i':
...@@ -1042,49 +1040,49 @@ static int HandleKey( intf_thread_t *p_intf, int i_key ) ...@@ -1042,49 +1040,49 @@ static int HandleKey( intf_thread_t *p_intf, int i_key )
else else
p_sys->i_box_type = BOX_INFO; p_sys->i_box_type = BOX_INFO;
p_sys->i_box_lines_total = 0; p_sys->i_box_lines_total = 0;
ReturnTrue; break;
case 'm': case 'm':
if( p_sys->i_box_type == BOX_META ) if( p_sys->i_box_type == BOX_META )
p_sys->i_box_type = BOX_NONE; p_sys->i_box_type = BOX_NONE;
else else
p_sys->i_box_type = BOX_META; p_sys->i_box_type = BOX_META;
p_sys->i_box_lines_total = 0; p_sys->i_box_lines_total = 0;
ReturnTrue; break;
case 'L': case 'L':
if( p_sys->i_box_type == BOX_LOG ) if( p_sys->i_box_type == BOX_LOG )
p_sys->i_box_type = BOX_NONE; p_sys->i_box_type = BOX_NONE;
else else
p_sys->i_box_type = BOX_LOG; p_sys->i_box_type = BOX_LOG;
ReturnTrue; break;
case 'P': case 'P':
if( p_sys->i_box_type == BOX_PLAYLIST ) if( p_sys->i_box_type == BOX_PLAYLIST )
p_sys->i_box_type = BOX_NONE; p_sys->i_box_type = BOX_NONE;
else else
p_sys->i_box_type = BOX_PLAYLIST; p_sys->i_box_type = BOX_PLAYLIST;
ReturnTrue; break;
case 'B': case 'B':
if( p_sys->i_box_type == BOX_BROWSE ) if( p_sys->i_box_type == BOX_BROWSE )
p_sys->i_box_type = BOX_NONE; p_sys->i_box_type = BOX_NONE;
else else
p_sys->i_box_type = BOX_BROWSE; p_sys->i_box_type = BOX_BROWSE;
ReturnTrue; break;
case 'x': case 'x':
if( p_sys->i_box_type == BOX_OBJECTS ) if( p_sys->i_box_type == BOX_OBJECTS )
p_sys->i_box_type = BOX_NONE; p_sys->i_box_type = BOX_NONE;
else else
p_sys->i_box_type = BOX_OBJECTS; p_sys->i_box_type = BOX_OBJECTS;
ReturnTrue; break;
case 'S': case 'S':
if( p_sys->i_box_type == BOX_STATS ) if( p_sys->i_box_type == BOX_STATS )
p_sys->i_box_type = BOX_NONE; p_sys->i_box_type = BOX_NONE;
else else
p_sys->i_box_type = BOX_STATS; p_sys->i_box_type = BOX_STATS;
ReturnTrue; break;
case 'c': case 'c':
p_sys->b_color = !p_sys->b_color; p_sys->b_color = !p_sys->b_color;
if( p_sys->b_color && !p_sys->b_color_started ) if( p_sys->b_color && !p_sys->b_color_started )
start_color_and_pairs( p_intf ); start_color_and_pairs( p_intf );
ReturnTrue; break;
case 'h': case 'h':
case 'H': case 'H':
if( p_sys->i_box_type == BOX_HELP ) if( p_sys->i_box_type == BOX_HELP )
...@@ -1092,40 +1090,42 @@ static int HandleKey( intf_thread_t *p_intf, int i_key ) ...@@ -1092,40 +1090,42 @@ static int HandleKey( intf_thread_t *p_intf, int i_key )
else else
p_sys->i_box_type = BOX_HELP; p_sys->i_box_type = BOX_HELP;
p_sys->i_box_lines_total = 0; p_sys->i_box_lines_total = 0;
ReturnTrue; break;
case '/': case '/':
if( p_sys->i_box_type != BOX_SEARCH ) if( p_sys->i_box_type != BOX_SEARCH )
{ {
if( p_sys->psz_search_chain == NULL ) if( p_sys->psz_search_chain )
ReturnTrue; {
p_sys->psz_search_chain[0] = '\0'; p_sys->psz_search_chain[0] = '\0';
p_sys->b_box_plidx_follow = false; p_sys->b_box_plidx_follow = false;
p_sys->i_before_search = p_sys->i_box_plidx; p_sys->i_before_search = p_sys->i_box_plidx;
p_sys->i_box_type = BOX_SEARCH; p_sys->i_box_type = BOX_SEARCH;
}
} }
ReturnTrue; break;
case 'A': /* Open */ case 'A': /* Open */
if( p_sys->i_box_type != BOX_OPEN ) if( p_sys->i_box_type != BOX_OPEN )
{ {
if( p_sys->psz_open_chain == NULL ) if( p_sys->psz_open_chain )
ReturnTrue; {
p_sys->psz_open_chain[0] = '\0'; p_sys->psz_open_chain[0] = '\0';
p_sys->i_box_type = BOX_OPEN; p_sys->i_box_type = BOX_OPEN;
}
} }
ReturnTrue; break;
/* Navigation */ /* Navigation */
case KEY_RIGHT: case KEY_RIGHT:
p_sys->f_slider += 1.0; p_sys->f_slider += 1.0;
if( p_sys->f_slider > 99.9 ) p_sys->f_slider = 99.9; if( p_sys->f_slider > 99.9 ) p_sys->f_slider = 99.9;
ManageSlider( p_intf ); ManageSlider( p_intf );
ReturnTrue; break;
case KEY_LEFT: case KEY_LEFT:
p_sys->f_slider -= 1.0; p_sys->f_slider -= 1.0;
if( p_sys->f_slider < 0.0 ) p_sys->f_slider = 0.0; if( p_sys->f_slider < 0.0 ) p_sys->f_slider = 0.0;
ManageSlider( p_intf ); ManageSlider( p_intf );
ReturnTrue; break;
/* Common control */ /* Common control */
case 'f': case 'f':
...@@ -1149,60 +1149,61 @@ static int HandleKey( intf_thread_t *p_intf, int i_key ) ...@@ -1149,60 +1149,61 @@ static int HandleKey( intf_thread_t *p_intf, int i_key )
var_Set( p_playlist, "fullscreen", val ); var_Set( p_playlist, "fullscreen", val );
} }
} }
ReturnFalse; i_ret = 0;
break;
} }
case ' ': case ' ':
PlayPause( p_intf ); PlayPause( p_intf );
ReturnTrue; break;
case 's': case 's':
playlist_Stop( p_playlist ); playlist_Stop( p_playlist );
ReturnTrue; break;
case 'e': case 'e':
Eject( p_intf ); Eject( p_intf );
ReturnTrue; break;
case '[': case '[':
if( p_sys->p_input ) if( p_sys->p_input )
var_SetVoid( p_sys->p_input, "prev-title" ); var_SetVoid( p_sys->p_input, "prev-title" );
ReturnTrue; break;
case ']': case ']':
if( p_sys->p_input ) if( p_sys->p_input )
var_SetVoid( p_sys->p_input, "next-title" ); var_SetVoid( p_sys->p_input, "next-title" );
ReturnTrue; break;
case '<': case '<':
if( p_sys->p_input ) if( p_sys->p_input )
var_SetVoid( p_sys->p_input, "prev-chapter" ); var_SetVoid( p_sys->p_input, "prev-chapter" );
ReturnTrue; break;
case '>': case '>':
if( p_sys->p_input ) if( p_sys->p_input )
var_SetVoid( p_sys->p_input, "next-chapter" ); var_SetVoid( p_sys->p_input, "next-chapter" );
ReturnTrue; break;
case 'p': case 'p':
playlist_Prev( p_playlist ); playlist_Prev( p_playlist );
clear(); clear();
ReturnTrue; break;
case 'n': case 'n':
playlist_Next( p_playlist ); playlist_Next( p_playlist );
clear(); clear();
ReturnTrue; break;
case 'a': case 'a':
aout_VolumeUp( p_playlist, 1, NULL ); aout_VolumeUp( p_playlist, 1, NULL );
clear(); clear();
ReturnTrue; break;
case 'z': case 'z':
aout_VolumeDown( p_playlist, 1, NULL ); aout_VolumeDown( p_playlist, 1, NULL );
clear(); clear();
ReturnTrue; break;
/* /*
* ^l should clear and redraw the screen * ^l should clear and redraw the screen
...@@ -1210,13 +1211,15 @@ static int HandleKey( intf_thread_t *p_intf, int i_key ) ...@@ -1210,13 +1211,15 @@ static int HandleKey( intf_thread_t *p_intf, int i_key )
case KEY_CLEAR: case KEY_CLEAR:
case 0x0c: /* ^l */ case 0x0c: /* ^l */
clear(); clear();
ReturnTrue; break;
default: default:
ReturnFalse; i_ret = 0;
} }
#undef ReturnFalse
#undef ReturnTrue end:
pl_Release( p_intf );
return i_ret;
} }
static void ManageSlider( intf_thread_t *p_intf ) static void ManageSlider( intf_thread_t *p_intf )
......
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