Commit 50922179 authored by Thomas Guillem's avatar Thomas Guillem
Browse files

move directory-sort option from directory access to directory demux

All readdir access that are used from demux directory can now be sorted like
the directory access.
parent 0b79f865
......@@ -82,7 +82,6 @@ struct access_sys_t
directory *current;
char *ignored_exts;
char mode;
int (*compar) (const char **a, const char **b);
};
/* Select non-hidden files only */
......@@ -91,20 +90,6 @@ static int visible (const char *name)
return name[0] != '.';
}
static int collate (const char **a, const char **b)
{
#ifdef HAVE_STRCOLL
return strcoll (*a, *b);
#else
return strcmp (*a, *b);
#endif
}
static int version (const char **a, const char **b)
{
return strverscmp (*a, *b);
}
/**
* Does the provided URI/path/stuff has one of the extension provided ?
*
......@@ -212,7 +197,7 @@ static bool directory_push (access_sys_t *p_sys, DIR *handle, char *psz_uri)
p_dir->parent = p_sys->current;
p_dir->handle = handle;
p_dir->uri = psz_uri;
p_dir->filec = vlc_loaddir (handle, &p_dir->filev, visible, p_sys->compar);
p_dir->filec = vlc_loaddir (handle, &p_dir->filev, visible, NULL);
if (p_dir->filec < 0)
p_dir->filev = NULL;
p_dir->i = 0;
......@@ -289,17 +274,6 @@ int DirInit (access_t *p_access, DIR *handle)
if (unlikely (p_sys == NULL))
goto error;
char *psz_sort = var_InheritString (p_access, "directory-sort");
if (!psz_sort)
p_sys->compar = collate;
else if (!strcasecmp ( psz_sort, "version"))
p_sys->compar = version;
else if (!strcasecmp (psz_sort, "none"))
p_sys->compar = NULL;
else
p_sys->compar = collate;
free(psz_sort);
char *uri;
if (!strcmp (p_access->psz_access, "fd"))
{
......
......@@ -37,16 +37,6 @@
"This is useful if you add directories that contain playlist files " \
"for instance. Use a comma-separated list of extensions." )
static const char *const psz_sort_list[] = { "collate", "version", "none" };
static const char *const psz_sort_list_text[] = {
N_("Sort alphabetically according to the current language's collation rules."),
N_("Sort items in a natural order (for example: 1.ogg 2.ogg 10.ogg). This method does not take the current language's collation rules into account."),
N_("Do not sort the items.") };
#define SORT_TEXT N_("Directory sort order")
#define SORT_LONGTEXT N_( \
"Define the sort algorithm used when adding items from a directory." )
vlc_module_begin ()
set_description( N_("File input") )
set_shortname( N_("File") )
......@@ -62,8 +52,6 @@ vlc_module_begin ()
set_capability( "access", 55 )
add_string( "ignore-filetypes", "m3u,db,nfo,ini,jpg,jpeg,ljpg,gif,png,pgm,pgmyuv,pbm,pam,tga,bmp,pnm,xpm,xcf,pcx,tif,tiff,lbm,sfv,txt,sub,idx,srt,cue,ssa",
IGNORE_TEXT, IGNORE_LONGTEXT, false )
add_string( "directory-sort", "collate", SORT_TEXT, SORT_LONGTEXT, false )
change_string_list( psz_sort_list, psz_sort_list_text )
#ifndef HAVE_FDOPENDIR
add_shortcut( "file", "directory", "dir" )
#else
......
......@@ -33,6 +33,11 @@
#include "playlist.h"
struct demux_sys_t
{
bool b_dir_sorted;
};
/*****************************************************************************
* Local prototypes
*****************************************************************************/
......@@ -44,30 +49,70 @@ int Import_Dir ( vlc_object_t *p_this)
demux_t *p_demux = (demux_t *)p_this;
bool b_is_dir = false;
bool b_dir_sorted = false;
int i_err = stream_Control( p_demux->s, STREAM_IS_DIRECTORY, &b_is_dir,
NULL, NULL );
&b_dir_sorted, NULL );
if ( !( i_err == VLC_SUCCESS && b_is_dir ) )
return VLC_EGENERIC;
p_demux->pf_control = Control;
p_demux->pf_demux = Demux;
msg_Dbg( p_demux, "reading directory content" );
STANDARD_DEMUX_INIT_MSG( "reading directory content" );
p_demux->p_sys->b_dir_sorted = b_dir_sorted;
return VLC_SUCCESS;
}
void Close_Dir ( vlc_object_t *p_this )
{
VLC_UNUSED(p_this);
demux_t *p_demux = (demux_t *)p_this;
free( p_demux->p_sys );
}
static int compar_type( input_item_t *p1, input_item_t *p2 )
{
if( p1->i_type != p2->i_type )
{
if( p1->i_type == ITEM_TYPE_DIRECTORY )
return -1;
if( p2->i_type == ITEM_TYPE_DIRECTORY )
return 1;
}
return 0;
}
static int compar_collate( input_item_t *p1, input_item_t *p2 )
{
int i_ret = compar_type( p1, p2 );
if( i_ret != 0 )
return i_ret;
#ifdef HAVE_STRCOLL
return strcoll( p1->psz_name, p2->psz_name );
#else
return strcmp( p1->psz_name, p2->psz_name );
#endif
}
static int compar_version( input_item_t *p1, input_item_t *p2 )
{
int i_ret = compar_type( p1, p2 );
if( i_ret != 0 )
return i_ret;
return strverscmp( p1->psz_name, p2->psz_name );
}
static int Demux( demux_t *p_demux )
{
int i_ret = VLC_SUCCESS;
input_item_t *p_input = GetCurrentItem(p_demux);
input_item_node_t *p_node = input_item_node_Create( p_input );
input_item_t *p_input;
input_item_node_t *p_node;
input_item_t *p_item;
p_input = GetCurrentItem( p_demux );
p_node = input_item_node_Create( p_input );
input_item_Release(p_input);
while( !i_ret && ( p_item = stream_ReadDir( p_demux->s ) ) )
......@@ -92,9 +137,25 @@ skip_item:
msg_Warn( p_demux, "unable to read directory" );
input_item_node_Delete( p_node );
return i_ret;
} else
}
if( !p_demux->p_sys->b_dir_sorted )
{
input_item_node_PostAndDelete( p_node );
return VLC_SUCCESS;
input_item_compar_cb compar_cb = NULL;
char *psz_sort = var_InheritString( p_demux, "directory-sort" );
if( psz_sort )
{
if( !strcasecmp( psz_sort, "version" ) )
compar_cb = compar_version;
else if( strcasecmp( psz_sort, "none" ) )
compar_cb = compar_collate;
}
free( psz_sort );
if( compar_cb )
input_item_node_Sort( p_node, compar_cb );
}
input_item_node_PostAndDelete( p_node );
return VLC_SUCCESS;
}
......@@ -51,6 +51,16 @@
#define SKIP_ADS_LONGTEXT N_( "Use playlist options usually used to prevent " \
"ads skipping to detect ads and prevent adding them to the playlist." )
static const char *const psz_sort_list[] = { "collate", "version", "none" };
static const char *const psz_sort_list_text[] = {
N_("Sort alphabetically according to the current language's collation rules."),
N_("Sort items in a natural order (for example: 1.ogg 2.ogg 10.ogg). This method does not take the current language's collation rules into account."),
N_("Do not sort the items.") };
#define SORT_TEXT N_("Directory sort order")
#define SORT_LONGTEXT N_( \
"Define the sort algorithm used when adding items from a directory." )
vlc_module_begin ()
add_shortcut( "playlist" )
set_category( CAT_INPUT )
......@@ -145,6 +155,8 @@ vlc_module_begin ()
add_shortcut( "playlist", "directory" )
set_capability( "demux", 10 )
set_callbacks( Import_Dir, Close_Dir )
add_string( "directory-sort", "collate", SORT_TEXT, SORT_LONGTEXT, false )
change_string_list( psz_sort_list, psz_sort_list_text )
vlc_module_end ()
int Control(demux_t *demux, int query, va_list args)
......
Supports Markdown
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