📄 ncurses.c
字号:
/* Ugly check for incomplete bytes sequences * (in case of non-UTF8 multibyte local encoding) */ for( psz = psz_utf8; *psz; psz++ ) if( ( *psz == '?' ) && ( *psz_utf8 != '?' ) ) { /* incomplete bytes sequence detected * (VLC core inserted dummy question marks) */ free( psz_utf8 ); return NULL; } /* Check for incomplete UTF8 bytes sequence */ if( EnsureUTF8( psz_utf8 ) == NULL ) { free( psz_utf8 ); return NULL; } memset( psz_part, 0, 6 ); return psz_utf8;}static inline int RemoveLastUTF8Entity( char *psz, int len ){ while( len && ( (psz[--len] & 0xc0) == 0x80 ) ); /* UTF8 continuation byte */ psz[len] = '\0'; return len;}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 ) { int b_ret = VLC_TRUE; switch( i_key ) { vlc_value_t val; /* Playlist Settings */ case 'r': var_Get( p_sys->p_playlist, "random", &val ); val.b_bool = !val.b_bool; var_Set( p_sys->p_playlist, "random", val ); return 1; case 'l': var_Get( p_sys->p_playlist, "loop", &val ); val.b_bool = !val.b_bool; var_Set( p_sys->p_playlist, "loop", val ); return 1; case 'R': var_Get( p_sys->p_playlist, "repeat", &val ); val.b_bool = !val.b_bool; var_Set( p_sys->p_playlist, "repeat", val ); return 1; /* Playlist sort */ case 'o': playlist_Sort( p_sys->p_playlist, SORT_TITLE, ORDER_NORMAL ); return 1; case 'O': playlist_Sort( p_sys->p_playlist, SORT_TITLE, ORDER_REVERSE ); return 1; /* Playlist view */ case 'v': switch( p_sys->i_current_view ) { case VIEW_CATEGORY: p_sys->i_current_view = VIEW_ALL; break; default: p_sys->i_current_view = VIEW_CATEGORY; } PlaylistRebuild( p_intf ); FindIndex( p_intf ); return 1; /* Playlist navigation */ case KEY_HOME: p_sys->i_box_plidx = 0; break; case KEY_END: p_sys->i_box_plidx = p_sys->p_playlist->i_size - 1; break; case KEY_UP: p_sys->i_box_plidx--; break; case KEY_DOWN: p_sys->i_box_plidx++; break; case KEY_PPAGE: p_sys->i_box_plidx -= p_sys->i_box_lines; break; case KEY_NPAGE: p_sys->i_box_plidx += p_sys->i_box_lines; break; case 'D': case KEY_BACKSPACE: case KEY_DC: { int i_item = p_sys->p_playlist->i_index; playlist_LockDelete( p_sys->p_playlist, p_sys->i_box_plidx ); if( i_item < p_sys->p_playlist->i_size && i_item != p_sys->p_playlist->i_index ) { playlist_Goto( p_sys->p_playlist, i_item ); } break; } case KEY_ENTER: case 0x0d: if( p_sys->i_current_view == VIEW_ALL ) { playlist_Goto( p_sys->p_playlist, p_sys->i_box_plidx ); } else { if( p_sys->pp_plist[p_sys->i_box_plidx]->p_item->i_children == -1 ) { playlist_Control( p_sys->p_playlist, PLAYLIST_ITEMPLAY, p_sys->pp_plist[p_sys->i_box_plidx]->p_item ); } else { playlist_Control( p_sys->p_playlist, PLAYLIST_VIEWPLAY, p_sys->i_current_view, p_sys->pp_plist[p_sys->i_box_plidx]->p_item, NULL ); } } p_sys->b_box_plidx_follow = VLC_TRUE; break; default: b_ret = VLC_FALSE; break; } if( b_ret ) { int i_max = p_sys->i_plist_entries; if( p_sys->i_current_view == VIEW_ALL ) i_max = p_sys->p_playlist->i_size; if( p_sys->i_box_plidx >= i_max ) p_sys->i_box_plidx = i_max - 1; if( p_sys->i_box_plidx < 0 ) p_sys->i_box_plidx = 0; if( p_sys->i_current_view == VIEW_ALL ) { if( p_sys->i_box_plidx == p_sys->p_playlist->i_index ) p_sys->b_box_plidx_follow = VLC_TRUE; else p_sys->b_box_plidx_follow = VLC_FALSE; } else { if( p_sys->pp_plist[p_sys->i_box_plidx]->p_item == p_sys->p_playlist->status.p_item ) p_sys->b_box_plidx_follow = VLC_TRUE; else p_sys->b_box_plidx_follow = VLC_FALSE; } return 1; } } if( p_sys->i_box_type == BOX_BROWSE ) { vlc_bool_t b_ret = VLC_TRUE; /* Browser navigation */ switch( i_key ) { case KEY_HOME: p_sys->i_box_bidx = 0; break; case KEY_END: p_sys->i_box_bidx = p_sys->i_dir_entries - 1; break; case KEY_UP: p_sys->i_box_bidx--; break; case KEY_DOWN: p_sys->i_box_bidx++; break; case KEY_PPAGE: p_sys->i_box_bidx -= p_sys->i_box_lines; break; case KEY_NPAGE: p_sys->i_box_bidx += p_sys->i_box_lines; break; case '.': /* Toggle show hidden files */ p_sys->b_show_hidden_files = ( p_sys->b_show_hidden_files == VLC_TRUE ? VLC_FALSE : VLC_TRUE ); ReadDir( p_intf ); break; case KEY_ENTER: case 0x0d: case ' ': if( p_sys->pp_dir_entries[p_sys->i_box_bidx]->b_file || i_key == ' ' ) { int i_size_entry = strlen( p_sys->psz_current_dir ) + strlen( p_sys->pp_dir_entries[p_sys->i_box_bidx]->psz_path ) + 2; char *psz_uri = (char *)malloc( sizeof(char)*i_size_entry); sprintf( psz_uri, "%s/%s", p_sys->psz_current_dir, p_sys->pp_dir_entries[p_sys->i_box_bidx]->psz_path ); playlist_Add( p_sys->p_playlist, psz_uri, psz_uri, PLAYLIST_APPEND, PLAYLIST_END ); p_sys->i_box_type = BOX_PLAYLIST; free( psz_uri ); } else { int i_size_entry = strlen( p_sys->psz_current_dir ) + strlen( p_sys->pp_dir_entries[p_sys->i_box_bidx]->psz_path ) + 2; char *psz_uri = (char *)malloc( sizeof(char)*i_size_entry); sprintf( psz_uri, "%s/%s", p_sys->psz_current_dir, p_sys->pp_dir_entries[p_sys->i_box_bidx]->psz_path ); p_sys->psz_current_dir = strdup( psz_uri ); ReadDir( p_intf ); free( psz_uri ); } break; default: b_ret = VLC_FALSE; break; } if( b_ret ) { 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; return 1; } } 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 += 5.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 -= 5.0; if( p_sys->f_slider < 0.0 ) p_sys->f_slider = 0.0; ManageSlider( p_intf ); return 1; default: break; } } else if( p_sys->i_box_type == BOX_SEARCH && p_sys->psz_search_chain ) { int i_chain_len; i_chain_len = strlen( p_sys->psz_search_chain ); switch( i_key ) { case 0x0c: /* ^l */ clear(); return 1; case KEY_ENTER: case 0x0d: if( i_chain_len > 0 ) { p_sys->psz_old_search = strdup( p_sys->psz_search_chain ); } else if( p_sys->psz_old_search ) { SearchPlaylist( p_intf, p_sys->psz_old_search ); } p_sys->i_box_type = BOX_PLAYLIST; return 1; case 0x1b: /* Esc. */ p_sys->i_box_plidx = p_sys->i_before_search; p_sys->i_box_type = BOX_PLAYLIST; return 1; case KEY_BACKSPACE: RemoveLastUTF8Entity( p_sys->psz_search_chain, i_chain_len ); break; default: { char *psz_utf8 = KeyToUTF8( i_key, p_sys->psz_partial_keys ); if( psz_utf8 != NULL ) { if( i_chain_len + strlen( psz_utf8 ) < SEARCH_CHAIN_SIZE ) { strcpy( p_sys->psz_search_chain + i_chain_len, psz_utf8 ); } free( psz_utf8 ); } break; } } if( p_sys->psz_old_search ) { free( p_sys->psz_old_search ); p_sys->psz_old_search = NULL; } SearchPlaylist( p_intf, p_sys->psz_search_chain ); return 1; } else if( p_sys->i_box_type == BOX_OPEN && p_sys->psz_open_chain ) { int i_chain_len = strlen( p_sys->psz_open_chain ); playlist_t *p_playlist = p_sys->p_playlist; switch( i_key ) { case 0x0c: /* ^l */ clear(); return 1; case KEY_ENTER: case 0x0d: if( p_playlist && i_chain_len > 0 ) { playlist_Add( p_playlist, p_sys->psz_open_chain, p_sys->psz_open_chain, PLAYLIST_GO|PLAYLIST_APPEND, PLAYLIST_END ); p_sys->b_box_plidx_follow = VLC_TRUE; } p_sys->i_box_type = BOX_PLAYLIST; return 1; case 0x1b: /* Esc. */ p_sys->i_box_type = BOX_PLAYLIST; return 1; case KEY_BACKSPACE: RemoveLastUTF8Entity( p_sys->psz_open_chain, i_chain_len ); break; default: { char *psz_utf8 = KeyToUTF8( i_key, p_sys->psz_partial_keys ); if( psz_utf8 != NULL ) { if( i_chain_len + strlen( psz_utf8 ) < OPEN_CHAIN_SIZE ) { strcpy( p_sys->psz_open_chain + i_chain_len, psz_utf8 ); } free( psz_utf8 ); } break; } } return 1; } /* Common keys */ switch( i_key ) { case 'q': case 'Q': case 0x1b: /* Esc */ p_intf->p_vlc->b_die = VLC_TRUE; return 0; /* 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;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -