1
mirror of https://code.videolan.org/videolan/vlc synced 2024-09-04 09:11:33 +02:00

* modules/gui/ncurses.c: Filebrowser enhancements:

- sorting
  - show/hide hidden files (with '.')
This commit is contained in:
Yoann Peronneau 2005-09-14 00:43:57 +00:00
parent 7a704aeaf3
commit b0e0bc12ee

View File

@ -164,6 +164,7 @@ struct intf_sys_t
char *psz_current_dir;
int i_dir_entries;
struct dir_entry_t **pp_dir_entries;
vlc_bool_t b_show_hidden_files;
int i_current_view; /* playlist view */
struct pl_item_t **pp_plist;
@ -253,6 +254,7 @@ static int Open( vlc_object_t *p_this )
p_sys->i_dir_entries = 0;
p_sys->pp_dir_entries = NULL;
p_sys->b_show_hidden_files = VLC_FALSE;
ReadDir( p_intf );
return VLC_SUCCESS;
@ -561,6 +563,11 @@ static int HandleKey( intf_thread_t *p_intf, int i_key )
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:
@ -1266,6 +1273,7 @@ static void Redraw( intf_thread_t *p_intf, time_t *t_last_refresh )
MainBoxWrite( p_intf, l++, 1, "[Filebrowser]" );
MainBoxWrite( p_intf, l++, 1, " <enter> Add the selected file to the playlist" );
MainBoxWrite( p_intf, l++, 1, " <space> Add the selected directory to the playlist" );
MainBoxWrite( p_intf, l++, 1, " . Show/Hide hidden files" );
MainBoxWrite( p_intf, l++, 1, "" );
MainBoxWrite( p_intf, l++, 1, "[Boxes]" );
@ -1419,7 +1427,7 @@ static void Redraw( intf_thread_t *p_intf, time_t *t_last_refresh )
{
attrset( A_REVERSE );
}
mvnprintw( y++, 1, COLS - 2, "%c %s", p_sys->pp_dir_entries[i_item]->b_file == VLC_TRUE ? '-' : '+',
mvnprintw( y++, 1, COLS - 2, " %c %s", p_sys->pp_dir_entries[i_item]->b_file == VLC_TRUE ? ' ' : '+',
p_sys->pp_dir_entries[i_item]->psz_path );
if( b_selected )
{
@ -1823,6 +1831,20 @@ static void Eject( intf_thread_t *p_intf )
return;
}
static int comp_dir_entries( const void *pp_dir_entry1,
const void *pp_dir_entry2 )
{
struct dir_entry_t *p_dir_entry1 = *(struct dir_entry_t**)pp_dir_entry1;
struct dir_entry_t *p_dir_entry2 = *(struct dir_entry_t**)pp_dir_entry2;
if ( p_dir_entry1->b_file == p_dir_entry2->b_file ) {
return strcasecmp( p_dir_entry1->psz_path, p_dir_entry2->psz_path );
}
else
{
return ( p_dir_entry1->b_file ? 1 : -1 );
}
}
static void ReadDir( intf_thread_t *p_intf )
{
intf_sys_t *p_sys = p_intf->p_sys;
@ -1870,8 +1892,18 @@ static void ReadDir( intf_thread_t *p_intf )
struct dir_entry_t *p_dir_entry;
int i_size_entry = strlen( p_sys->psz_current_dir ) +
strlen( p_dir_content->d_name ) + 2;
char *psz_uri = (char *)malloc( sizeof(char)*i_size_entry);
char *psz_uri;
if( p_sys->b_show_hidden_files == VLC_FALSE &&
( strlen( p_dir_content->d_name ) &&
p_dir_content->d_name[0] == '.' ) &&
strcmp( p_dir_content->d_name, ".." ) )
{
p_dir_content = readdir( p_current_dir );
continue;
}
psz_uri = (char *)malloc( sizeof(char)*i_size_entry);
sprintf( psz_uri, "%s/%s", p_sys->psz_current_dir,
p_dir_content->d_name );
@ -1907,6 +1939,11 @@ static void ReadDir( intf_thread_t *p_intf )
/* Read next entry */
p_dir_content = readdir( p_current_dir );
}
/* Sort */
qsort( p_sys->pp_dir_entries, p_sys->i_dir_entries,
sizeof(struct dir_entry_t*), &comp_dir_entries );
closedir( p_current_dir );
return;
}