The next step. B-)
authorDavid Walter Seikel <onefang@gmail.com>
Tue, 22 Aug 2006 00:56:03 +0000 (00:56 +0000)
committerDavid Walter Seikel <onefang@gmail.com>
Tue, 22 Aug 2006 00:56:03 +0000 (00:56 +0000)
Converts fdo menus to directories full of .order files at startup if
there is no applications/menu/all/.order file.  This is the last big
peice of the puzzle.

Lots of tweaking, optimising, cleaning, polishing, and general making
this stuff live well with the rest of E to go.

SVN revision: 25029

src/bin/Makefile.am
src/bin/e_fdo_menu_to_order.c [new file with mode: 0644]
src/bin/e_fdo_menu_to_order.h [new file with mode: 0644]
src/bin/e_includes.h
src/bin/e_main.c

index 715b2f9..c070a5c 100644 (file)
@@ -174,7 +174,8 @@ e_widget_color_well.h \
 e_int_config_wallpaper.h \
 e_int_config_wallpaper_import.h \
 e_int_config_wallpaper_gradient.h \
-e_color_dialog.h 
+e_color_dialog.h  \
+e_fdo_menu_to_order.h
 
 enlightenment_src = \
 e_user.c \
@@ -325,6 +326,7 @@ e_int_config_wallpaper.c \
 e_int_config_wallpaper_import.c \
 e_int_config_wallpaper_gradient.c \
 e_color_dialog.c \
+e_fdo_menu_to_order.c \
 $(ENLIGHTENMENTHEADERS)
 
 enlightenment_SOURCES = \
diff --git a/src/bin/e_fdo_menu_to_order.c b/src/bin/e_fdo_menu_to_order.c
new file mode 100644 (file)
index 0000000..4560e98
--- /dev/null
@@ -0,0 +1,237 @@
+/* This file currently lives in two places, the source code for E and the source code for e_utils e17genmenu
+ *
+ * It will soon go away from e17genmenu.  It still needs to be cleaned up to E coding specs.
+ *
+ * The standard includes will be replaced with "e.h" when this is no longer needed for e17genmenu.
+ *
+ * FIXME: .order file usage in here and in e_apps.c need to be reviewed.
+ */
+
+#include "config.h"
+#include "e_fdo_menu_to_order.h"
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <limits.h>
+#include <string.h>
+#include <Ecore.h>
+#include <Ecore_Desktop.h>
+#include <Ecore_File.h>
+
+//#define DEBUG 1
+
+//extern int menu_count, item_count;
+
+static int _e_menu_make_apps(const void *data, Ecore_Desktop_Tree * tree, int element, int level);
+static void _e_menu_dump_each_hash_node(void *value, void *user_data);
+static int _e_search_list(Ecore_List *list, const char *search);
+
+
+void
+e_fdo_menu_to_order()
+{
+   char *menu_file;
+
+    /* Find the main menu file. */
+    menu_file = ecore_desktop_paths_file_find(ecore_desktop_paths_menus, "applications.menu", -1, NULL, NULL);
+    if (menu_file)
+      {
+         char *path;
+
+         path = ecore_file_get_dir(menu_file);
+         if (path)
+           {
+              Ecore_Desktop_Tree *menus;
+
+              /* convert the xml into menus */
+              menus = ecore_desktop_menu_get(menu_file);
+              if (menus)
+                {
+                   /* create the .eap and order files from the menu */
+                   ecore_desktop_tree_foreach(menus, 0, _e_menu_make_apps, path);
+                }
+              free(path);
+           }
+      }
+}
+
+static int
+_e_menu_make_apps(const void *data, Ecore_Desktop_Tree * tree, int element, int level)
+{
+   if (tree->elements[element].type == ECORE_DESKTOP_TREE_ELEMENT_TYPE_STRING)
+     {
+        if (strncmp((char *)tree->elements[element].element, "<MENU ", 6) == 0)
+          {
+             char *path;
+             Ecore_Hash *apps;
+
+#ifdef DEBUG
+             char *name;
+
+             name = (char *)tree->elements[element].element;
+             printf("MAKING MENU - %s \t\t%s\n", path, name);
+#endif
+             path = (char *)tree->elements[element + 1].element;
+//             pool = (Ecore_Hash *) tree->elements[element + 2].element;
+             apps = (Ecore_Hash *) tree->elements[element + 4].element;
+//             menu_count++;
+             ecore_hash_for_each_node(apps, _e_menu_dump_each_hash_node, &path[11]);
+          }
+     }
+   return 0;
+}
+
+static void
+_e_menu_dump_each_hash_node(void *value, void *user_data)
+{
+   Ecore_Hash_Node *node;
+   Ecore_Desktop *desktop;
+   char *file, *path;
+
+   path = (char *)user_data;
+   node = (Ecore_Hash_Node *) value;
+   file = (char *)node->value;
+#ifdef DEBUG
+   printf("MAKING MENU ITEM %s -> %s\n", path, file);
+#endif
+//   item_count++;
+   desktop = ecore_desktop_get(file, NULL);
+   /* Check If We Process */
+   if ((!desktop->type) || (!strcmp(desktop->type, "Application")))
+      {
+         char order_path[PATH_MAX];
+         int length;
+         char *buff;
+         char buffer[PATH_MAX], path2[PATH_MAX];
+         FILE *f;
+         Ecore_List *list = NULL;
+
+         snprintf(order_path, sizeof(order_path), "%s/.e/e/applications/menu/all/%s", ecore_desktop_home_get(), path);
+         if (!ecore_file_exists(order_path))
+            {
+               const char *cat;
+
+               ecore_file_mkpath(order_path);
+// FIXME: If we create a dir, we should add it to the parents .order file.
+              cat = ecore_file_get_file(order_path);
+              if (cat)
+                 {
+// FIXME: What to do about .directory.eap's when .desktop takes over?
+//                   create_dir_eap(order_path, cat);
+                 }
+            }
+
+          snprintf(path2, sizeof(path2), "%s/.order", order_path);
+
+#ifdef DEBUG
+          fprintf(stderr, "Modifying Order File %s\n", path2);
+#endif
+
+          list = ecore_list_new();
+         ecore_list_set_free_cb(list, free);
+
+          /* Stat .order; Create If Not Found */
+          if (!ecore_file_exists(path2))
+            {
+               FILE *f2;
+
+#ifdef DEBUG
+               fprintf(stderr, "Creating Order File %s\n", path2);
+#endif
+
+               f2 = fopen(path2, "w");
+               if (!f2)
+               {
+                  fprintf(stderr, "ERROR: Cannot Create Order File %s\n", path2);
+                  exit(-1);
+               }
+               fclose(f2);
+               /* If We Had To Create This Order Then Just Add The file */
+               if (!ecore_list_append(list, file))
+                 {
+                    fprintf(stderr, "ERROR: Ecore List Append Failed !!\n");
+                    return;
+                 }
+            }
+          else
+            {
+               /* Open .order File For Parsing */
+               f = fopen(path2, "r");
+               if (!f)
+                 {
+                    fprintf(stderr, "ERROR: Cannot Open Order File %s \n", path2);
+                    exit(-1);
+                 }
+
+               /* Read All Entries From Existing Order File, Store In List For Sorting */
+               while (fgets(buffer, sizeof(buffer), f) != NULL)
+                 {
+                    /* Strip New Line Char */
+                    if (buffer[(length = strlen(buffer) - 1)] == '\n')
+                       buffer[length] = '\0';
+                    if (!_e_search_list(list, buffer))
+                      {
+                         if (!ecore_list_append(list, strdup(buffer)))
+                           {
+                              fprintf(stderr, "ERROR: Ecore List Append Failed !!\n");
+                              return;
+                           }
+                      }
+                 }
+               fclose(f);
+               buffer[0] = (char)0;
+
+               /* Add This file To List Of Existing ? */
+               if (!_e_search_list(list, file))
+                 {
+                    if (!ecore_list_append(list, file))
+                      {
+                         fprintf(stderr, "ERROR: Ecore List Append Failed !!\n");
+                         return;
+                      }
+                 }
+            }
+
+#ifdef DEBUG
+          fprintf(stderr, "Rewriting Order %s\n", path2);
+#endif
+
+          f = fopen(path2, "w");
+          if (!f)
+            {
+               fprintf(stderr, "ERROR: Cannot Open Order File %s \n", path2);
+               if (list)
+                  ecore_list_destroy(list);
+               return;
+            }
+
+          ecore_list_goto_first(list);
+          while ((buff = ecore_list_next(list)) != NULL)
+            {
+               snprintf(buffer, sizeof(buffer), "%s\n", buff);
+               if (buffer != NULL)
+                  fwrite(buffer, sizeof(char), strlen(buffer), f);
+            }
+          fclose(f);
+
+          if (list)
+             ecore_list_destroy(list);
+     }
+}
+
+
+static int
+_e_search_list(Ecore_List *list, const char *search)
+{
+   char *tmp;
+
+   if (!search) return 0;
+   if (!list) return 0;
+   ecore_list_goto_first(list);
+   while ((tmp = (char *)ecore_list_next(list)) != NULL)
+     {
+        if (!strcmp(tmp, search))
+           return 1;
+     }
+   return 0;
+}
diff --git a/src/bin/e_fdo_menu_to_order.h b/src/bin/e_fdo_menu_to_order.h
new file mode 100644 (file)
index 0000000..0ff9041
--- /dev/null
@@ -0,0 +1,6 @@
+#ifndef E_FDO_MENU_TO_ORDER_H
+#define E_FDO_MENU_TO_ORDER_H
+
+void e_fdo_menu_to_order(void);
+
+#endif
index f37625a..9954f53 100644 (file)
 #include "e_widget_color_well.h"
 #include "e_widget_csel.h"
 #include "e_color_dialog.h"
+#include "e_fdo_menu_to_order.h"
index 8446f44..375a1fb 100644 (file)
@@ -877,6 +877,16 @@ _e_main_dirs_init(void)
                 homedir);
        system(buf);
      }
+   /* FIXME: THIS is a hack to get people started!!!
+    * Soon to be replaced with fancy background converting and resyncing code.
+    * Currently this is likely to be done each time E is started up on some systems.
+    * On the other hand, some of those systems wont have FDO menus, so this should not take long.
+    */
+   snprintf(buf, sizeof(buf), "%s/.e/e/applications/menu/all/.order", homedir);
+   if (!ecore_file_exists(buf))
+     {
+        e_fdo_menu_to_order();
+     }
    /* FIXME: THIS is to get people started - shoudl be in a wizard */
    snprintf(buf, sizeof(buf), "%s/.e/e/fileman/favorites", homedir);
    if (!ecore_file_exists(buf))