This is an automated email from the git hooks/post-receive script.

git pushed a commit to branch master
in repository efm2.

View the commit online.

commit 19a0933ef58e66bd1f67f8016d7b9456fcc9603f
Author: Carsten Haitzler (Rasterman) <[email protected]>
AuthorDate: Sat Nov 8 17:38:19 2025 +0000

    open - add load of order file and supply as order-index key
---
 src/backends/default/open.c | 138 ++++++++++++++++++++++++++++++--------------
 1 file changed, 95 insertions(+), 43 deletions(-)

diff --git a/src/backends/default/open.c b/src/backends/default/open.c
index 09eba60..f9e5425 100644
--- a/src/backends/default/open.c
+++ b/src/backends/default/open.c
@@ -18,6 +18,7 @@
 #include <grp.h>
 
 #include "cmd.h"
+#include "eina_hash.h"
 #include "eina_strbuf.h"
 #include "eina_types.h"
 #include "sha.h"
@@ -25,15 +26,6 @@
 #include "thumb_check.h"
 #include "esc.h"
 
-static const char *icon_theme = NULL;
-static const char *config_dir = NULL;
-static const char *home_dir   = NULL;
-static Eina_Bool   auto_exit  = EINA_FALSE;
-static int         child_exes = 0;
-
-static Ecore_File_Monitor *mon       = NULL;
-static Eina_Bool           can_write = EINA_FALSE;
-
 typedef struct
 {
   const char  *path;
@@ -58,7 +50,40 @@ typedef struct
   Ecore_Exe  *exe;
 } Op;
 
-// static Eina_List *op_queue = NULL;
+typedef struct
+{
+  const char          *path;
+  Ecore_Event_Handler *handler_exe_del;
+  Ecore_Event_Handler *handler_exe_data;
+  Ecore_Exe           *exe;
+  Eina_List           *cmd_pending;
+  Eina_List           *timers;
+  Eina_Bool            ready : 1;
+} Sub;
+
+typedef struct
+{
+  Sub              *sub;
+  Eina_Stringshare *name;
+  Ecore_Timer      *timer;
+  double            delay;
+  Eina_Bool         repeat : 1;
+} Sub_Timer;
+
+static Ecore_File_Monitor *mon        = NULL;
+static const char         *icon_theme = NULL;
+static const char         *config_dir = NULL;
+static const char         *home_dir   = NULL;
+static Eina_Hash          *order_hash = NULL;
+static Eina_List          *sub_queue  = NULL;
+static int                 child_exes = 0;
+static Eina_Bool           auto_exit  = EINA_FALSE;
+static Eina_Bool           can_write  = EINA_FALSE;
+// static Eina_List          *op_queue   = NULL;
+
+static Sub       *_sub_open(const char *path, const char *backend);
+static Eina_Bool  _file_add_mod_info(Eina_Strbuf *strbuf, const char *path,
+                                     Eina_Bool delay);
 
 static Eina_Bool
 _cb_auto_exit_timer(void *data EINA_UNUSED)
@@ -95,30 +120,6 @@ _cb_exe_del(void *data EINA_UNUSED, int ev_type EINA_UNUSED,
   return ECORE_CALLBACK_DONE;
 }
 
-typedef struct
-{
-  const char          *path;
-  Ecore_Event_Handler *handler_exe_del;
-  Ecore_Event_Handler *handler_exe_data;
-  Ecore_Exe           *exe;
-  Eina_List           *cmd_pending;
-  Eina_List           *timers;
-  Eina_Bool            ready : 1;
-} Sub;
-
-typedef struct
-{
-  Sub              *sub;
-  Eina_Stringshare *name;
-  Ecore_Timer      *timer;
-  double            delay;
-  Eina_Bool         repeat : 1;
-} Sub_Timer;
-
-static Eina_List *sub_queue = NULL;
-
-static Sub *_sub_open(const char *path, const char *backend);
-
 static Sub *
 _sub_find(const char *path)
 {
@@ -341,8 +342,51 @@ _sub_open(const char *path, const char *backend)
   return sub;
 }
 
-static Eina_Bool _file_add_mod_info(Eina_Strbuf *strbuf, const char *path,
-                                    Eina_Bool delay);
+static void
+_order_load(const char *path)
+{ // load order file for this dir and store in hash with index in ptr
+  Eina_Strbuf *strbuf;
+  FILE        *f;
+  uintptr_t    index = 1;
+  char         buf[PATH_MAX];
+
+  strbuf = eina_strbuf_new();
+  if (!strbuf) return; // XXX: this is pretty bad if we cant alloc here
+  eina_strbuf_append(strbuf, path);
+  eina_strbuf_append(strbuf, ".efm/.efm.order");
+  if (order_hash)
+    { // old hash - free it
+      eina_hash_free(order_hash);
+      order_hash = NULL;
+    }
+  f = fopen(eina_strbuf_string_get(strbuf), "r");
+  eina_strbuf_free(strbuf);
+  if (!f) return;
+  // new order hash: string -> order index (1, 2, 3, 4 ...)
+  order_hash = eina_hash_string_superfast_new(NULL);
+  while (fgets(buf, sizeof(buf), f))
+    {
+      size_t len = strlen(buf);
+
+      if (len > 0)
+        {
+          if (buf[len - 1] == '\n') buf[len - 1] = 0; // remove newline
+          // store this string file with this sort index
+          eina_hash_add(order_hash, buf, (void *)index);
+          index++;
+        }
+    }
+  fclose(f);
+}
+
+static uintptr_t
+_order_index_get(const char *file)
+{ // get the order inder (1, 2, 3... or 0 if not found)
+  void *ptr = (void *)0;
+
+  if (order_hash) ptr = eina_hash_find(order_hash, file);
+  return (uintptr_t)ptr;
+}
 
 static void
 _strbuf_append_file_escaped(Eina_Strbuf *strbuf, const char *path)
@@ -798,11 +842,13 @@ _file_add_mod_info(Eina_Strbuf *strbuf, const char *path, Eina_Bool delay)
   int             mode;
   struct passwd  *pw;
   struct group   *gr;
-  const char     *mime, *ext, *icon;
+  const char     *mime, *ext, *icon, *file;
   Efreet_Desktop *desktop;
   Eina_Bool       have_label = EINA_FALSE;
+  uintptr_t       order;
 
   if (lstat(path, &st) != 0) return EINA_FALSE;
+  file = ecore_file_file_get(path);
   if ((st.st_mode & S_IFMT) == S_IFLNK)
     {
       struct stat stdst;
@@ -862,12 +908,10 @@ _file_add_mod_info(Eina_Strbuf *strbuf, const char *path, Eina_Bool delay)
                       have_label = EINA_TRUE;
                     }
                   else
-                    cmd_strbuf_append(strbuf, "link-label",
-                                      ecore_file_file_get(path));
+                    cmd_strbuf_append(strbuf, "link-label", file);
                 }
               else
-                cmd_strbuf_append(strbuf, "link-label",
-                                  ecore_file_file_get(path));
+                cmd_strbuf_append(strbuf, "link-label", file);
               pw = getpwuid(stdst.st_uid);
               if (pw) cmd_strbuf_append(strbuf, "link-user", pw->pw_name);
               gr = getgrgid(stdst.st_gid);
@@ -979,10 +1023,10 @@ _file_add_mod_info(Eina_Strbuf *strbuf, const char *path, Eina_Bool delay)
               have_label = EINA_TRUE;
             }
           else if (!have_label)
-            cmd_strbuf_append(strbuf, "label", ecore_file_file_get(path));
+            cmd_strbuf_append(strbuf, "label", file);
         }
       else if (!have_label)
-        cmd_strbuf_append(strbuf, "label", ecore_file_file_get(path));
+        cmd_strbuf_append(strbuf, "label", file);
     }
   pw = getpwuid(st.st_uid);
   if (pw) cmd_strbuf_append(strbuf, "user", pw->pw_name);
@@ -1015,6 +1059,13 @@ _file_add_mod_info(Eina_Strbuf *strbuf, const char *path, Eina_Bool delay)
   // add extra meta keys that might be used for immediate icon/file display
   _file_add_mod_meta_append(path, "xy", "meta.xy", strbuf);
   _file_add_mod_meta_append(path, "wh", "meta.wh", strbuf);
+  // get order index number if any
+  order = _order_index_get(file);
+  if (order > 0)
+    {
+      snprintf(buf, sizeof(buf), "%llu", (unsigned long long)order);
+      cmd_strbuf_append(strbuf, "order-index", buf);
+    }
 
   return EINA_TRUE;
 }
@@ -1150,6 +1201,7 @@ _monitor(const char *path)
   strbuf = cmd_strbuf_new("list-begin");
   cmd_strbuf_print_consume(strbuf);
 
+  _order_load(path);
   mon = ecore_file_monitor_add(path, _cb_mon, NULL);
   it  = eina_file_direct_ls(path);
   if (!it)

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.

Reply via email to