Enlightenment CVS committal

Author  : onefang
Project : e17
Module  : apps/e_utils

Dir     : e17/apps/e_utils/src/bin/e17genmenu/src/bin


Modified Files:
        Makefile.am dumb_list.c dumb_list.h fdo_paths.c fdo_paths.h 
        global.c global.h main.c menus.c parse.c 
Added Files:
        fdo_menus.c fdo_menus.h 


Log Message:
The very first commit of something that will convert fdo menus to E17 .eaps
and order files.  This has just barely enough code to generate a small subset
of the full fdo menus.  As I add more code, more of the menu spec will be 
catered for, and the subset will gradually grow.  Soon enough we will have
a ful limplementation that does a full conversion.

===================================================================
RCS file: 
/cvsroot/enlightenment/e17/apps/e_utils/src/bin/e17genmenu/src/bin/Makefile.am,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -3 -r1.4 -r1.5
--- Makefile.am 7 Feb 2006 17:59:20 -0000       1.4
+++ Makefile.am 9 Feb 2006 09:34:11 -0000       1.5
@@ -16,10 +16,12 @@
 bin_PROGRAMS = e17genmenu
 
 e17genmenu_SOURCES = main.c global.c menus.c parse.c eaps.c icons.c \
-       category.c order.c sort.c fdo_paths.c dumb_list.c xmlame.c
+       category.c order.c sort.c fdo_menus.c fdo_paths.c dumb_list.c \
+       xmlame.c
 
 noinst_HEADERS = global.h menus.h parse.h eaps.h icons.h \
-       category.h order.h sort.h fdo_paths.h dumb_list.h xmlame.h
+       category.h order.h sort.h fdo_menus.h fdo_paths.h \
+       dumb_list.h xmlame.h
 
 e17genmenu_LDADD = @EET_LIBS@ @ECORE_LIBS@ @ENGRAVE_LIBS@
 
===================================================================
RCS file: 
/cvsroot/enlightenment/e17/apps/e_utils/src/bin/e17genmenu/src/bin/dumb_list.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -3 -r1.3 -r1.4
--- dumb_list.c 8 Feb 2006 23:13:29 -0000       1.3
+++ dumb_list.c 9 Feb 2006 09:34:11 -0000       1.4
@@ -5,6 +5,8 @@
 
 #include "dumb_list.h"
 
+static void dumb_list_dump_each_hash_node(void *value, void *user_data);
+
 
 /** Split a list of paths into a Dumb_List.
  *
@@ -124,6 +126,15 @@
    return list;
 }
 
+Dumb_List *
+dumb_list_add_hash(Dumb_List *list, Ecore_Hash *element)
+{
+   list->elements = (Dumb_List_Element *) realloc(list->elements, (list->size 
+ 1) * sizeof(Dumb_List_Element));
+   list->elements[list->size].element = element;
+   list->elements[list->size++].type = DUMB_LIST_ELEMENT_TYPE_HASH;
+   return list;
+}
+
 int
 dumb_list_exist(Dumb_List *list, char *element)
 {
@@ -144,6 +155,20 @@
 }
 
 void
+dumb_list_foreach(Dumb_List *list, int level, void (*func) (const void *data, 
Dumb_List *list, int element, int level), const void *data)
+{
+   int i;
+
+   for (i = 0; i < list->size; i++)
+      {
+         if (list->elements[i].type == DUMB_LIST_ELEMENT_TYPE_LIST)
+           dumb_list_foreach((Dumb_List *) list->elements[i].element, level + 
1, func, data);
+        else
+           func(data, list, i, level);
+      }
+}
+
+void
 dumb_list_dump(Dumb_List *list, int level)
 {
    int i;
@@ -169,6 +194,16 @@
                  }
                  break;
 
+              case DUMB_LIST_ELEMENT_TYPE_HASH :
+                 {
+                    int lev;
+
+                     lev = level + 1;
+                    printf("HASH ELEMENT TYPE\n");
+                     ecore_hash_for_each_node((Ecore_Hash *) 
list->elements[i].element, dumb_list_dump_each_hash_node, &lev);
+                 }
+                 break;
+
               default :
                  {
                     printf("UNKNOWN ELEMENT TYPE!\n");
@@ -178,6 +213,19 @@
       }
 }
 
+static void dumb_list_dump_each_hash_node(void *value, void *user_data)
+{
+   Ecore_Hash_Node *node;
+   int level;
+   int j;
+
+   node = (Ecore_Hash_Node *) value;
+   level = *((int *) user_data);
+   for (j = 0; j < level; j++)
+      printf(".");
+   printf("%s = %s\n", (char *) node->key, (char *) node->value);
+}
+
 void
 dumb_list_del(Dumb_List * list)
 {
@@ -187,6 +235,8 @@
       {
          if (list->elements[i].type == DUMB_LIST_ELEMENT_TYPE_LIST)
             dumb_list_del((Dumb_List *) list->elements[i].element);
+         else if (list->elements[i].type == DUMB_LIST_ELEMENT_TYPE_HASH)
+          ecore_hash_destroy((Ecore_Hash *) list->elements[i].element);
       }
 
    E_FREE(list->elements);
===================================================================
RCS file: 
/cvsroot/enlightenment/e17/apps/e_utils/src/bin/e17genmenu/src/bin/dumb_list.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -3 -r1.3 -r1.4
--- dumb_list.h 8 Feb 2006 23:13:30 -0000       1.3
+++ dumb_list.h 9 Feb 2006 09:34:11 -0000       1.4
@@ -7,12 +7,14 @@
 #define E_NEW_BIG(s, n) (s *)malloc(n * sizeof(s))
 #define E_FREE(p) { if (p) {free(p); p = NULL;} }
 
+#include <Ecore_Data.h>
+
 
 enum _Dumb_List_Element_Type
 {
-
    DUMB_LIST_ELEMENT_TYPE_STRING = 1,
    DUMB_LIST_ELEMENT_TYPE_LIST = 2,
+   DUMB_LIST_ELEMENT_TYPE_HASH = 3,
 };
 typedef enum _Dumb_List_Element_Type Dumb_List_Element_Type;
 
@@ -42,7 +44,9 @@
    Dumb_List *dumb_list_add(Dumb_List *list, char *element);
    Dumb_List *dumb_list_extend(Dumb_List *list, char *element);
    Dumb_List *dumb_list_add_child(Dumb_List *list, Dumb_List *element);
+   Dumb_List *dumb_list_add_hash(Dumb_List *list, Ecore_Hash *element);
    int dumb_list_exist(Dumb_List *list, char *element);
+   void dumb_list_foreach(Dumb_List *list, int level, void (*func) (const void 
*data, Dumb_List *list, int element, int level), const void *data);
    void dumb_list_dump(Dumb_List *list, int level);
    void dumb_list_del(Dumb_List *list);
 
===================================================================
RCS file: 
/cvsroot/enlightenment/e17/apps/e_utils/src/bin/e17genmenu/src/bin/fdo_paths.c,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -3 -r1.12 -r1.13
--- fdo_paths.c 7 Feb 2006 16:34:55 -0000       1.12
+++ fdo_paths.c 9 Feb 2006 09:34:11 -0000       1.13
@@ -1,3 +1,7 @@
+/*
+ * This conforms with the freedesktop.org XDG Base Directory Specification 
version 0.6
+ */
+
 #include <dirent.h>
 #include <string.h>             //string funcs
 #include <stdio.h>
@@ -28,17 +32,8 @@
 static void _fdo_paths_exec_config(char *home, Dumb_List * extras,
                                    char *cmd);
 
-static char *_fdo_paths_recursive_search(char *path, char *d,
-                                         int (*func) (const void *data,
-                                                      char *path),
-                                         const void *data);
-
 static int _fdo_paths_cb_exe_exit(void *data, int type, void *event);
 
-/*
- * This conforms with XDG Base Directory Specification version 0.6
- */
-
 void
 fdo_paths_init()
 {
@@ -134,7 +129,7 @@
                    break;
           }
         else if (sub)
-           path = _fdo_paths_recursive_search(paths->elements[i].element, 
file, func, data);
+           path = fdo_paths_recursive_search(paths->elements[i].element, file, 
func, data);
         if (path && (!func))
            break;
      }
@@ -376,8 +371,8 @@
      }
 }
 
-static char *
-_fdo_paths_recursive_search(char *path, char *file,
+char *
+fdo_paths_recursive_search(char *path, char *file,
                             int (*func) (const void *data, char *path),
                             const void *data)
 {
@@ -405,19 +400,28 @@
                          {
                             sprintf(info_text, "%s%s/", path, script->d_name);
                             fpath =
-                               _fdo_paths_recursive_search(info_text, file,
+                               fdo_paths_recursive_search(info_text, file,
                                                            func, data);
                          }
                     }
                   else
                     {
-                       if (strcmp(basename(info_text), file) == 0)
-                         {
-                            fpath = strdup(info_text);
-                            if (func)
-                               if (func(data, path))
-                                  break;
-                         }
+                      if (file)
+                         {
+                             if (strcmp(basename(info_text), file) == 0)
+                               {
+                                  fpath = strdup(info_text);
+                                  if (func)
+                                     if (func(data, path))
+                                        break;
+                               }
+                         }
+                      else
+                         {
+                              if (func)
+                                 if (func(data, info_text))
+                                    break;
+                         }
                     }
                   if (fpath && (!func))
                      break;
===================================================================
RCS file: 
/cvsroot/enlightenment/e17/apps/e_utils/src/bin/e17genmenu/src/bin/fdo_paths.h,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -3 -r1.7 -r1.8
--- fdo_paths.h 7 Feb 2006 17:44:18 -0000       1.7
+++ fdo_paths.h 9 Feb 2006 09:34:11 -0000       1.8
@@ -25,6 +25,7 @@
 
    void fdo_paths_init();
    char *fdo_paths_search_for_file(Fdo_Paths_Type type, char *file, int sub, 
int (*func) (const void *data, char *path), const void *data);
+   char *fdo_paths_recursive_search(char *path, char *d, int (*func) (const 
void *data, char *path), const void *data);
    void fdo_paths_shutdown();
 
 # ifdef __cplusplus
===================================================================
RCS file: 
/cvsroot/enlightenment/e17/apps/e_utils/src/bin/e17genmenu/src/bin/global.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -3 -r1.6 -r1.7
--- global.c    3 Feb 2006 05:50:38 -0000       1.6
+++ global.c    9 Feb 2006 09:34:11 -0000       1.7
@@ -64,6 +64,21 @@
    return 0;
 }
 
+int
+get_fdo()
+{
+   int i, argc;
+   char **argv;
+
+   ecore_app_args_get(&argc, &argv);
+   for (i = 1; i < argc; i++)
+     {
+        if ((!strcmp(argv[i], "-f")) || (!strcmp(argv[i], "--fdo")))
+           return 1;
+     }
+   return 0;
+}
+
 char *
 get_icon_compression()
 {
===================================================================
RCS file: 
/cvsroot/enlightenment/e17/apps/e_utils/src/bin/e17genmenu/src/bin/global.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -3 -r1.2 -r1.3
--- global.h    31 Jan 2006 22:04:17 -0000      1.2
+++ global.h    9 Feb 2006 09:34:11 -0000       1.3
@@ -32,6 +32,7 @@
 char *get_home(void);
 char *get_desktop_dir(void);
 int get_overwrite(void);
+int get_fdo(void);
 char *get_eap_name(char *file);
 char *get_icon_size(void);
 char *get_icon_theme(void);
===================================================================
RCS file: 
/cvsroot/enlightenment/e17/apps/e_utils/src/bin/e17genmenu/src/bin/main.c,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -3 -r1.15 -r1.16
--- main.c      8 Feb 2006 23:13:30 -0000       1.15
+++ main.c      9 Feb 2006 09:34:11 -0000       1.16
@@ -4,6 +4,7 @@
 #include "parse.h"
 #include "icons.h"
 #include "sort.h"
+#include "fdo_menus.h"
 #include "fdo_paths.h"
 #include "xmlame.h"
 
@@ -59,10 +60,18 @@
          menu_xml = xmlame_get(path);;
         if (menu_xml)
            {
+              Dumb_List *menus = NULL;
+
+              /* convert the xml into menus */
+              menus = fdo_menus_get(path, menu_xml);
                dumb_list_dump(menu_xml, 0);
                printf("\n\n");
-              /* convert the xml into a menu */
-              /* create the .eap and order files from the menu */
+              if (menus)
+                 {
+                     dumb_list_dump(menus, 0);
+                     printf("\n\n");
+                    /* create the .eap and order files from the menu */
+                 }
            }
          free(path);
 
@@ -131,6 +140,7 @@
       (" -d=<dir> | --desktop-dir=<dir>\tCreate eaps for .desktop files in 
<dir>\n");
    printf(" -o | --overwrite\tOverwrite Eaps\n");
    printf(" -m | --mapping\tGenerate Mapping File\n");
+   printf(" -f | --fdo\tGenerate menus from fdo files\n");
    printf(" -h | --help\t\tShow this help screen\n");
 
    /* Stop E Stuff */
@@ -152,7 +162,7 @@
                 _e17genmenu_help();
              if ((strstr(argv[i], "--backup")) || (strstr(argv[i], "-b")))
                 _e17genmenu_backup();
-             if ((strstr(argv[i], "--fdo")) || (strstr(argv[i], "-f")))
+             if ((strstr(argv[i], "--test")) || (strstr(argv[i], "-z")))
                 _e17genmenu_test_fdo_paths();
           }
      }
===================================================================
RCS file: 
/cvsroot/enlightenment/e17/apps/e_utils/src/bin/e17genmenu/src/bin/menus.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -3 -r1.5 -r1.6
--- menus.c     4 Feb 2006 00:36:48 -0000       1.5
+++ menus.c     9 Feb 2006 09:34:11 -0000       1.6
@@ -1,26 +1,65 @@
 #include "global.h"
 #include "config.h"
+#include "fdo_menus.h"
+#include "fdo_paths.h"
 #include "parse.h"
 #include "menus.h"
+#include "xmlame.h"
+
+static void _menu_make_apps(const void *data, Dumb_List *list, int element, 
int level);
+static void _menu_dump_each_hash_node(void *value, void *user_data);
+
 
 void
 make_menus()
 {
    char *d;
 
-   d = get_desktop_dir();
-   if (d)
-      check_for_dirs(strdup(d));
-
-   if (!d)
-     {
-        /* Check desktop files in these directories */
-        check_for_dirs(GNOME_DIRS);
-        check_for_dirs(KDE_DIRS);
-        check_for_dirs(DEBIAN_DIRS);
-     }
-   if (d)
-      free(d);
+   if (get_fdo())
+      {
+         char *menu = "applications.menu";
+         char *menu_file;
+
+         /* First, find the main menu file. */
+         menu_file = fdo_paths_search_for_file(FDO_PATHS_TYPE_MENU, menu, 1, 
NULL, NULL);
+         if (menu_file)
+            {
+              char *path;
+              Dumb_List *menu_xml = NULL;
+
+               path = ecore_file_get_dir(menu_file);
+               menu_xml = xmlame_get(menu_file);;
+              if ((menu_xml) && (path))
+                 {
+                    Dumb_List *menus = NULL;
+
+                    /* convert the xml into menus */
+                    menus = fdo_menus_get(menu_file, menu_xml);
+                    if (menus)
+                       {
+                          /* create the .eap and order files from the menu */
+                           dumb_list_foreach(menu_xml, 0, _menu_make_apps, 
path);
+                       }
+                 }
+               E_FREE(path);
+            }
+      }
+   else
+      {
+         d = get_desktop_dir();
+         if (d)
+            check_for_dirs(strdup(d));
+
+         if (!d)
+           {
+              /* Check desktop files in these directories */
+              check_for_dirs(GNOME_DIRS);
+              check_for_dirs(KDE_DIRS);
+              check_for_dirs(DEBIAN_DIRS);
+           }
+         if (d)
+            free(d);
+      }
 }
 
 void
@@ -96,3 +135,33 @@
    if (file)
       free(file);
 }
+
+static void
+_menu_make_apps(const void *data, Dumb_List *list, int element, int level)
+{
+   char *path;
+
+   path = (char *) data;
+   if (list->elements[element].type == DUMB_LIST_ELEMENT_TYPE_STRING)
+      {
+         if (strcmp((char *) list->elements[element].element, "<AppDir") == 0)
+           {
+               element++;
+               if ((list->size > element) && (list->elements[element].type == 
DUMB_LIST_ELEMENT_TYPE_HASH))
+                 {
+                     ecore_hash_for_each_node((Ecore_Hash *) 
list->elements[element].element, _menu_dump_each_hash_node, NULL);
+                 }
+           }
+      }
+}
+
+static void
+_menu_dump_each_hash_node(void *value, void *user_data)
+{
+   Ecore_Hash_Node *node;
+   char *file;
+
+   node = (Ecore_Hash_Node *) value;
+   file = (char *) node->value;
+   parse_desktop_file(strdup(file));
+}
===================================================================
RCS file: 
/cvsroot/enlightenment/e17/apps/e_utils/src/bin/e17genmenu/src/bin/parse.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -3 -r1.8 -r1.9
--- parse.c     3 Feb 2006 21:28:36 -0000       1.8
+++ parse.c     9 Feb 2006 09:34:11 -0000       1.9
@@ -378,6 +378,7 @@
 {
    Ecore_Hash *result;
 
+   /* FIXME: this should probably be optimised by caching the results, then 
looking in the cache first. */
    result = ecore_hash_new(ecore_str_hash, ecore_str_compare);
    if (result)
      {




-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642
_______________________________________________
enlightenment-cvs mailing list
enlightenment-cvs@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs

Reply via email to