raster pushed a commit to branch master.

http://git.enlightenment.org/apps/rage.git/commit/?id=d682faf9b633ef212754807bf1a711b8d8c4e442

commit d682faf9b633ef212754807bf1a711b8d8c4e442
Author: Carsten Haitzler (Rasterman) <ras...@rasterman.com>
Date:   Mon Mar 22 17:02:35 2021 +0000

    add util funcs (move from browser to be shared) and use from main too
    
    file recursion/listing will now use the same funcs as browser.c did -
    fast extn checks.
---
 src/bin/browser.c   | 71 +++--------------------------------------------------
 src/bin/main.c      |  7 ++----
 src/bin/meson.build |  3 ++-
 src/bin/util.c      | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 src/bin/util.h      |  8 ++++++
 5 files changed, 85 insertions(+), 74 deletions(-)

diff --git a/src/bin/browser.c b/src/bin/browser.c
index b278c9e..f7f76ce 100644
--- a/src/bin/browser.c
+++ b/src/bin/browser.c
@@ -6,6 +6,7 @@
 #include "videothumb.h"
 #include "key.h"
 #include "dnd.h"
+#include "util.h"
 
 typedef struct _Message Message;
 typedef struct _Entry Entry;
@@ -120,72 +121,6 @@ _item_size_get(Evas_Object *win, Evas_Coord *w, Evas_Coord 
*h)
    if (*h < sz) *h = sz;
 }
 
-static Eina_Bool
-_video_ok(const char *path)
-{
-   const char *exts[] =
-     {
-        ".asf", ".avi", ".bdm", ".bdmv", ".clpi", ".cpi", ".dv", ".fla",
-        ".flv", ".m1v", ".m2t", ".m2v", ".m4v", ".mkv", ".mov", ".mp2",
-        ".mp2ts", ".mp4", ".mpe", ".mpeg", ".mpg", ".mpl", ".mpls", ".mts",
-        ".mxf", ".nut", ".nuv", ".ogg", ".ogm", ".ogv", ".qt", ".rm", ".rmj",
-        ".rmm", ".rms", ".rmvb", ".rmx", ".rv", ".swf", ".ts", ".weba",
-        ".webm", ".wmv", ".3g2", ".3gp", ".3gp2", ".3gpp", ".3gpp2", ".3p2",
-        ".264",
-        NULL
-     };
-   int i;
-   const char *ext = strrchr(path, '.');
-   if (!ext) return EINA_FALSE;
-   for (i = 0; exts[i]; i++)
-     {
-        if (!strcasecmp(ext, exts[i])) return EINA_TRUE;
-     }
-   return EINA_FALSE;
-}
-
-static Eina_Bool
-_audio_ok(const char *path)
-{
-   const char *exts[] =
-     {
-        ".mp3", ".m4a", ".oga", ".aac", ".flac", ".wav",
-        NULL
-     };
-   int i;
-   const char *ext = strrchr(path, '.');
-   if (!ext) return EINA_FALSE;
-   for (i = 0; exts[i]; i++)
-     {
-        if (!strcasecmp(ext, exts[i])) return EINA_TRUE;
-     }
-   return EINA_FALSE;
-}
-
-static char *
-_videos_dir_get(void)
-{
-   char buf[PATH_MAX];
-   const char *vids, *home;
-   char *vidsreal = NULL, *homereal = NULL;
-
-   vids = efreet_videos_dir_get();
-   if (vids) vidsreal = ecore_file_realpath(vids);
-   home = eina_environment_home_get();
-   if (home) homereal = ecore_file_realpath(home);
-   if ((vidsreal) && (homereal))
-     {
-        if (!strcmp(vidsreal, homereal)) vids = NULL;
-     }
-   free(vidsreal);
-   free(homereal);
-   if (vids)
-     snprintf(buf, sizeof(buf), "%s", vids);
-   else
-     snprintf(buf, sizeof(buf), "%s/Videos", eina_environment_home_get());
-   return strdup(buf);
-}
-
 static void
 _fill_message(Ecore_Thread *th, Type type, Entry *entry)
 {
@@ -241,7 +176,7 @@ _fill_scan(Ecore_Thread *th, Entry *parent, const char *dir)
                     }
                   else
                     {
-                       if (_video_ok(file) || _audio_ok(file))
+                       if (util_video_ok(file) || util_audio_ok(file))
                          {
                             eina_lock_take(&(entry->lock));
                             entry->files = eina_list_append
@@ -817,7 +752,7 @@ _fill(Evas_Object *win)
    dir_entry = NULL;
    fdat = malloc(sizeof(Fill_Data));
    if (!fdat) return;
-   fdat->videos = _videos_dir_get();
+   fdat->videos = util_videos_dir_get();
    fdat->win = win;
    eina_semaphore_new(&step_sema, 0);
    fill_thread = ecore_thread_feedback_run(_fill_thread, _fill_feedback,
diff --git a/src/bin/main.c b/src/bin/main.c
index 1cfe68a..9c8a2f1 100644
--- a/src/bin/main.c
+++ b/src/bin/main.c
@@ -6,6 +6,7 @@
 #include "browser.h"
 #include "config.h"
 #include "mpris.h"
+#include "util.h"
 
 #define DEPTH_DEFAULT 99
 
@@ -121,7 +122,6 @@ _cb_feedback_recursion(void *data, Ecore_Thread *thread 
EINA_UNUSED, void *msg)
 {
    Recursion_Data *recursion;
    Eina_List *list;
-   const char *mime;
    const char *path;
    Eina_Bool update_content = EINA_FALSE;
 
@@ -130,10 +130,7 @@ _cb_feedback_recursion(void *data, Ecore_Thread *thread 
EINA_UNUSED, void *msg)
 
    EINA_LIST_FREE(list, path)
      {
-        mime = efreet_mime_type_get(path);
-        if ((!mime) ||
-            (!strncmp(mime, "audio/", 6)) ||
-            (!strncmp(mime, "video/", 6)))
+        if (util_video_ok(path) || util_audio_ok(path))
          {
             update_content = EINA_TRUE;
             win_list_hide(recursion->win);
diff --git a/src/bin/meson.build b/src/bin/meson.build
index 73f3a98..e32e072 100644
--- a/src/bin/meson.build
+++ b/src/bin/meson.build
@@ -14,7 +14,8 @@ executable('rage', [
     'videothumb.c', 'videothumb.h',
     'albumart.c',   'albumart.h',
     'browser.c',    'browser.h',
-    'mpris.c',      'mpris.h'
+    'mpris.c',      'mpris.h',
+    'util.c',       'util.h'
   ],
   include_directories: inc,
   dependencies       : deps,
diff --git a/src/bin/util.c b/src/bin/util.c
new file mode 100644
index 0000000..2316307
--- /dev/null
+++ b/src/bin/util.c
@@ -0,0 +1,70 @@
+#include <Elementary.h>
+#include "main.h"
+#include "util.h"
+
+Eina_Bool
+util_video_ok(const char *path)
+{
+   const char *exts[] =
+     {
+        ".asf", ".avi", ".bdm", ".bdmv", ".clpi", ".cpi", ".dv", ".fla",
+        ".flv", ".m1v", ".m2t", ".m2v", ".m4v", ".mkv", ".mov", ".mp2",
+        ".mp2ts", ".mp4", ".mpe", ".mpeg", ".mpg", ".mpl", ".mpls", ".mts",
+        ".mxf", ".nut", ".nuv", ".ogg", ".ogm", ".ogv", ".qt", ".rm", ".rmj",
+        ".rmm", ".rms", ".rmvb", ".rmx", ".rv", ".swf", ".ts", ".weba",
+        ".webm", ".wmv", ".3g2", ".3gp", ".3gp2", ".3gpp", ".3gpp2", ".3p2",
+        ".264",
+        NULL
+     };
+   int i;
+   const char *ext = strrchr(path, '.');
+   if (!ext) return EINA_FALSE;
+   for (i = 0; exts[i]; i++)
+     {
+        if (!strcasecmp(ext, exts[i])) return EINA_TRUE;
+     }
+   return EINA_FALSE;
+}
+
+Eina_Bool
+util_audio_ok(const char *path)
+{
+   const char *exts[] =
+     {
+        ".mp3", ".m4a", ".oga", ".aac", ".flac", ".wav",
+        NULL
+     };
+   int i;
+   const char *ext = strrchr(path, '.');
+   if (!ext) return EINA_FALSE;
+   for (i = 0; exts[i]; i++)
+     {
+        if (!strcasecmp(ext, exts[i])) return EINA_TRUE;
+     }
+   return EINA_FALSE;
+}
+
+char *
+util_videos_dir_get(void)
+{
+   char buf[PATH_MAX];
+   const char *vids, *home;
+   char *vidsreal = NULL, *homereal = NULL;
+
+   vids = efreet_videos_dir_get();
+   if (vids) vidsreal = ecore_file_realpath(vids);
+   home = eina_environment_home_get();
+   if (home) homereal = ecore_file_realpath(home);
+   if ((vidsreal) && (homereal))
+     {
+        if (!strcmp(vidsreal, homereal)) vids = NULL;
+     }
+   free(vidsreal);
+   free(homereal);
+   if (vids)
+     snprintf(buf, sizeof(buf), "%s", vids);
+   else
+     snprintf(buf, sizeof(buf), "%s/Videos", eina_environment_home_get());
+   return strdup(buf);
+}
+
diff --git a/src/bin/util.h b/src/bin/util.h
new file mode 100644
index 0000000..cd933db
--- /dev/null
+++ b/src/bin/util.h
@@ -0,0 +1,8 @@
+#ifndef _UTIL_H__
+#define _UTIL_H__ 1
+
+Eina_Bool  util_video_ok(const char *path);
+Eina_Bool  util_audio_ok(const char *path);
+char      *util_videos_dir_get(void);
+
+#endif

-- 


Reply via email to