Commit b0e0bc12 authored by yoann's avatar yoann
Browse files

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

  - sorting
  - show/hide hidden files (with '.')
parent 7a704aea
......@@ -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;
}
......
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