[MPlayer-cvslog] r19497 - in trunk: input/input.c input/input.h libmenu/menu_filesel.c mplayer.c
ben
subversion at mplayerhq.hu
Tue Aug 22 22:55:49 CEST 2006
Author: ben
Date: Tue Aug 22 22:55:49 2006
New Revision: 19497
Modified:
trunk/input/input.c
trunk/input/input.h
trunk/libmenu/menu_filesel.c
trunk/mplayer.c
Log:
added new filter option to menu file browser to only display some files according to extension
Modified: trunk/input/input.c
==============================================================================
--- trunk/input/input.c (original)
+++ trunk/input/input.c Tue Aug 22 22:55:49 2006
@@ -106,6 +106,7 @@
{ MP_CMD_SWITCH_RATIO, "switch_ratio", 0, { {MP_CMD_ARG_FLOAT,{0}}, {-1,{0}} } },
{ MP_CMD_VO_FULLSCREEN, "vo_fullscreen", 0, { {MP_CMD_ARG_INT,{-1}}, {-1,{0}} } },
{ MP_CMD_VO_ONTOP, "vo_ontop", 0, { {MP_CMD_ARG_INT,{-1}}, {-1,{0}} } },
+ { MP_CMD_FILE_FILTER, "file_filter", 1, { { MP_CMD_ARG_INT, {0}}, {-1,{0}}}},
{ MP_CMD_VO_ROOTWIN, "vo_rootwin", 0, { {MP_CMD_ARG_INT,{-1}}, {-1,{0}} } },
{ MP_CMD_VO_BORDER, "vo_border", 0, { {MP_CMD_ARG_INT,{-1}}, {-1,{0}} } },
{ MP_CMD_SCREENSHOT, "screenshot", 0, { {-1,{0}} } },
Modified: trunk/input/input.h
==============================================================================
--- trunk/input/input.h (original)
+++ trunk/input/input.h Tue Aug 22 22:55:49 2006
@@ -71,6 +71,7 @@
#define MP_CMD_GET_PROPERTY 69
#define MP_CMD_OSD_SHOW_PROPERTY_TEXT 70
#define MP_CMD_SEEK_CHAPTER 71
+#define MP_CMD_FILE_FILTER 72
#define MP_CMD_GUI_EVENTS 5000
#define MP_CMD_GUI_LOADFILE 5001
Modified: trunk/libmenu/menu_filesel.c
==============================================================================
--- trunk/libmenu/menu_filesel.c (original)
+++ trunk/libmenu/menu_filesel.c Tue Aug 22 22:55:49 2006
@@ -41,6 +41,7 @@
char* dir_action;
int auto_close;
char** actions;
+ char* filter;
};
static struct menu_priv_s cfg_dflt = {
@@ -52,6 +53,7 @@
"loadfile '%p'",
NULL,
0,
+ NULL,
NULL
};
@@ -65,6 +67,7 @@
{ "dir-action", ST_OFF(dir_action), CONF_TYPE_STRING, 0, 0, 0, NULL },
{ "auto-close", ST_OFF(auto_close), CONF_TYPE_FLAG, 0, 0, 1, NULL },
{ "actions", ST_OFF(actions), CONF_TYPE_STRING_LIST, 0, 0, 0, NULL},
+ { "filter", ST_OFF(filter), CONF_TYPE_STRING, 0, 0, 0, NULL},
{ NULL, NULL, NULL, 0,0,0,NULL }
};
@@ -126,6 +129,51 @@
}
}
+static char **get_extensions(menu_t *menu){
+ char **extensions, ext[32];
+ FILE *fp;
+ int n = 1;
+
+ if (!mpriv->filter)
+ return NULL;
+
+ fp = fopen(mpriv->filter, "r");
+ if(!fp)
+ return NULL;
+
+ extensions = (char **) malloc(sizeof(*extensions));
+ *extensions = NULL;
+
+ while(fgets(ext,sizeof(ext),fp)) {
+ char **l, *e;
+ int s = strlen (ext);
+
+ if(ext[s-1] == '\n') {
+ ext[s-1] = '\0';
+ s--;
+ }
+ e = (char *) malloc(s+1);
+ extensions = (char **) realloc(extensions, ++n * sizeof(*extensions));
+ extensions = (char **) realloc(extensions, ++n * sizeof(*extensions));
+ strcpy (e, ext);
+ for (l=extensions; *l; l++);
+ *l++ = e;
+ *l = NULL;
+ }
+
+ fclose (fp);
+ return extensions;
+}
+
+static void free_extensions(char **extensions){
+ if (extensions) {
+ char **l = extensions;
+ while (*l)
+ free (*l++);
+ free (extensions);
+ }
+}
+
static int open_dir(menu_t* menu,char* args) {
char **namelist, **tp;
struct dirent *dp;
@@ -134,6 +182,8 @@
char* p = NULL;
list_entry_t* e;
DIR* dirp;
+ extern int file_filter;
+ char **extensions, **elem, *ext;
menu_list_init(menu);
@@ -152,11 +202,25 @@
}
namelist = (char **) malloc(sizeof(char *));
+ extensions = get_extensions(menu);
n=0;
while ((dp = readdir(dirp)) != NULL) {
if(dp->d_name[0] == '.' && strcmp(dp->d_name,"..") != 0)
continue;
+ mylstat(args,dp->d_name,&st);
+ if (file_filter && extensions && !S_ISDIR(st.st_mode)) {
+ if((ext = strrchr(dp->d_name,'.')) == NULL)
+ continue;
+ ext++;
+ elem = extensions;
+ do {
+ if (!strcasecmp(ext, *elem))
+ break;
+ } while (*++elem);
+ if (*elem == NULL)
+ continue;
+ }
if(n%20 == 0){ // Get some more mem
if((tp = (char **) realloc(namelist, (n+20) * sizeof (char *)))
== NULL) {
@@ -175,13 +239,13 @@
}
strcpy(namelist[n], dp->d_name);
- mylstat(args,namelist[n],&st);
if(S_ISDIR(st.st_mode))
strcat(namelist[n], "/");
n++;
}
bailout:
+ free_extensions (extensions);
closedir(dirp);
qsort(namelist, n, sizeof(char *), (kill_warn)compare);
Modified: trunk/mplayer.c
==============================================================================
--- trunk/mplayer.c (original)
+++ trunk/mplayer.c Tue Aug 22 22:55:49 2006
@@ -279,6 +279,7 @@
static char* spudec_ifo=NULL;
char* filename=NULL; //"MI2-Trailer.avi";
int forced_subs_only=0;
+int file_filter=1;
// cache2:
int stream_cache_size=-1;
@@ -4450,6 +4451,10 @@
cmd->pausing = 1;
brk_cmd = 1;
} break;
+ case MP_CMD_FILE_FILTER : {
+ file_filter = cmd->args[0].v.i;
+ break;
+ }
case MP_CMD_QUIT : {
exit_player_with_rc(MSGTR_Exit_quit, (cmd->nargs > 0)? cmd->args[0].v.i : 0);
}
More information about the MPlayer-cvslog
mailing list