Commit 09e79a67 authored by Antoine Cellerier's avatar Antoine Cellerier

Add option to use version sort when adding a dir

As mentionned in the long help, this sort guarantees that adding a
directory with files like track-1.ogg track-2.ogg track-10.ogg will
result in files being added in the expected order. This is the default
sort method used by most apps which display directory listings as well
as some media players like rockbox. If it were up to me it would be the
default sort method.

In previous version of vlc, this behavior could be emulated with:
find /media/MUSIC/lossless-to-ogg/Metronomy/ -type f|sort -V|vlc fd/m3u://0
Now you can just use:
vlc /media/MUSIC/lossless-to-ogg/Metronomy/ --directory-version-sort
parent da2ee7c7
......@@ -79,6 +79,7 @@ struct access_sys_t
bool header;
int i_item_count;
char *xspf_ext;
int (*compar)(const char **a, const char **b);
};
/* Select non-hidden files only */
......@@ -96,6 +97,11 @@ static int collate (const char **a, const char **b)
#endif
}
static int version (const char **a, const char **b)
{
return strverscmp (*a, *b);
}
/*****************************************************************************
* Open: open the directory
*****************************************************************************/
......@@ -137,10 +143,16 @@ int DirInit (access_t *p_access, DIR *handle)
free (uri);
goto error;
}
if (var_InheritBool (p_access, "directory-version-sort"))
p_sys->compar = version;
else
p_sys->compar = collate;
root->parent = NULL;
root->handle = handle;
root->uri = uri;
root->filec = vlc_loaddir (handle, &root->filev, visible, collate);
root->filec = vlc_loaddir (handle, &root->filev, visible, p_sys->compar);
if (root->filec < 0)
root->filev = NULL;
root->i = 0;
......@@ -348,7 +360,7 @@ block_t *DirBlock (access_t *p_access)
}
sub->parent = current;
sub->handle = handle;
sub->filec = vlc_loaddir (handle, &sub->filev, visible, collate);
sub->filec = vlc_loaddir (handle, &sub->filev, visible, p_sys->compar);
if (sub->filec < 0)
sub->filev = NULL;
sub->i = 0;
......
......@@ -48,6 +48,13 @@ static const char *const psz_recursive_list_text[] = {
"This is useful if you add directories that contain playlist files " \
"for instance. Use a comma-separated list of extensions." )
#define VERSION_SORT_TEXT N_("Use version sort")
#define VERSION_SORT_LONGTEXT N_( \
"When opening a directory, add items in a natural order. " \
"For example, track-1.ogg track-2.ogg track-10.ogg will be sorted " \
"as expected while the default method would sort them as " \
"track-1.ogg track-10.ogg track-2.ogg." )
vlc_module_begin ()
set_description( N_("File input") )
set_shortname( N_("File") )
......@@ -66,6 +73,8 @@ vlc_module_begin ()
change_string_list( psz_recursive_list, psz_recursive_list_text, 0 )
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_bool( "directory-version-sort", false,
VERSION_SORT_TEXT, VERSION_SORT_LONGTEXT, false );
#ifndef HAVE_FDOPENDIR
add_shortcut( "file", "directory", "dir" )
#else
......
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