[MPlayer-cvslog] r23247 - in trunk: cfg-mplayer.h libmenu/menu_filesel.c

ben subversion at mplayerhq.hu
Mon May 7 18:46:25 CEST 2007


Author: ben
Date: Mon May  7 18:46:24 2007
New Revision: 23247

Log:
new -menu-keepdir option that allows libmenu file browser to always restart browsing from the last place we were instead of current dir

Modified:
   trunk/cfg-mplayer.h
   trunk/libmenu/menu_filesel.c

Modified: trunk/cfg-mplayer.h
==============================================================================
--- trunk/cfg-mplayer.h	(original)
+++ trunk/cfg-mplayer.h	Mon May  7 18:46:24 2007
@@ -70,6 +70,7 @@ extern int WinID;
 
 #ifdef HAVE_MENU
 extern int menu_startup;
+extern int menu_keepdir;
 extern int menu_utf8;
 extern int menu_unicode;
 #ifdef  USE_FRIBIDI
@@ -298,6 +299,7 @@ m_option_t mplayer_opts[]={
 	{"menu-root", &menu_root, CONF_TYPE_STRING, CONF_GLOBAL, 0, 0, NULL},
 	{"menu-cfg", &menu_cfg, CONF_TYPE_STRING, CONF_GLOBAL, 0, 0, NULL},
 	{"menu-startup", &menu_startup, CONF_TYPE_FLAG, CONF_GLOBAL, 0, 1, NULL},
+	{"menu-keepdir", &menu_keepdir, CONF_TYPE_FLAG, CONF_GLOBAL, 0, 1, NULL},
 	{"menu-utf8", &menu_utf8, CONF_TYPE_FLAG, 0, 0, 1, NULL},
 	{"menu-unicode", &menu_unicode, CONF_TYPE_FLAG, 0, 0, 1, NULL},
 #ifdef USE_FRIBIDI

Modified: trunk/libmenu/menu_filesel.c
==============================================================================
--- trunk/libmenu/menu_filesel.c	(original)
+++ trunk/libmenu/menu_filesel.c	Mon May  7 18:46:24 2007
@@ -6,6 +6,7 @@
 #include <string.h>
 #include <sys/types.h>
 #include <sys/stat.h>
+#include <fcntl.h>
 #include <ctype.h>
 #include <unistd.h>
 #include <limits.h>
@@ -26,6 +27,10 @@
 #include "input/input.h"
 #include "osdep/keycodes.h"
 
+#define MENU_KEEP_PATH "/tmp/mp_current_path"
+
+int menu_keepdir = 0;
+
 struct list_entry_s {
   struct list_entry p;
   int d;
@@ -179,6 +184,7 @@ static int open_dir(menu_t* menu,char* a
   struct dirent *dp;
   struct stat st;
   int n;
+  int path_fp;
   char* p = NULL;
   list_entry_t* e;
   DIR* dirp;
@@ -201,6 +207,14 @@ static int open_dir(menu_t* menu,char* a
     return 0;
   }
 
+  if (menu_keepdir) {
+    path_fp = open (MENU_KEEP_PATH, O_CREAT | O_WRONLY | O_TRUNC, 0666);
+    if (path_fp >= 0) {
+      write (path_fp, mpriv->dir, strlen (mpriv->dir));
+      close (path_fp);
+    }
+  }
+
   namelist = (char **) malloc(sizeof(char *));
   extensions = get_extensions(menu);
 
@@ -370,7 +384,7 @@ static void clos(menu_t* menu) {
 }
 
 static int open_fs(menu_t* menu, char* args) {
-  char *path = mpriv->path;
+  char *path = mpriv->path, *freepath = NULL;
   int r = 0;
   char wd[PATH_MAX+1];
   args = NULL; // Warning kill
@@ -380,6 +394,29 @@ static int open_fs(menu_t* menu, char* a
   menu->read_key = read_key;
   menu->close = clos;
 
+  if (menu_keepdir) {
+    if (!path || path[0] == '\0') {
+      struct stat st;
+      int path_fp;
+      
+      path_fp = open (MENU_KEEP_PATH, O_RDONLY);
+      if (path_fp >= 0) {
+        if (!fstat (path_fp, &st) && (st.st_size > 0)) {
+          path = malloc(st.st_size+1);
+          if ((read(path_fp, path, st.st_size) == st.st_size) && path[0] != '\0'){
+            freepath = path;
+            path[st.st_size] = '\0';
+          }
+          else {
+            free(path);
+            path = NULL;
+          }
+        }
+        close (path_fp);
+      }
+    }
+  }
+  
   getcwd(wd,PATH_MAX);
   if(!path || path[0] == '\0') {
     int l = strlen(wd) + 2;
@@ -398,6 +435,9 @@ static int open_fs(menu_t* menu, char* a
   } else
     r = open_dir(menu,path);
 
+  if (freepath)
+    free(freepath);
+  
   return r;
 }
   



More information about the MPlayer-cvslog mailing list