Enlightenment CVS committal

Author  : andreas99
Project : e16
Module  : tools

Dir     : e16/tools/e16menuedit2/src


Modified Files:
        e16menu.c e16menuedit2.c e16menuedit2.h 


Log Message:
- changed code to autodetect file.menu
- now ECONFDIR could be set to define E16 path

===================================================================
RCS file: /cvsroot/enlightenment/e16/tools/e16menuedit2/src/e16menu.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -3 -r1.6 -r1.7
--- e16menu.c   5 Dec 2004 13:55:41 -0000       1.6
+++ e16menu.c   29 Dec 2004 11:09:22 -0000      1.7
@@ -32,7 +32,8 @@
 
 int app_errno;
 char app_errno_str[APP_ERRNO_STR_LEN];
-extern char *emenu_path;
+extern char *epath;
+extern int emenu;
 
 GtkTreeModel *load_menus_from_disk (void)
 {
@@ -50,22 +51,34 @@
                               G_TYPE_STRING,
                               G_TYPE_STRING);
 
-  if (!strcmp (emenu_path, ENLIGHTENMENT_MENU))
-    sprintf (buf, "%s/%s/file.menu", homedir (getuid ()), emenu_path);
-  else if (!strcmp (emenu_path, E16_MENU))
-    sprintf (buf, "%s/%s/%s/file.menu", homedir (getuid ()), emenu_path, 
"menus");
+  if (emenu == EMENU_AUTODETECT)
+  {
+    struct stat stat_buf;
+    gboolean epath_missing = TRUE;
+
+    sprintf (buf, "%s/file.menu", epath);
+    epath_missing = stat (buf, &stat_buf);
+
+    if (epath_missing)
+    {
+      sprintf (buf, "%s/menus/file.menu", epath);
+    }
+  }
+  else if (emenu == EMENU_MENUS)
+  {
+    sprintf (buf, "%s/menus/file.menu", epath);
+  }
   else
   {
-    printf ("unknown menu definition!\n");
+    g_critical ("unknown menu definition!\n");
     exit (1);
   }
 
   menufile = fopen (buf, "r");
   if (!menufile)
   {
-    printf ("hmm. looks like you have some \"issues\" as you don't have\n"
-            "a %s file.\n", buf);
-    gtk_exit (1);
+    g_critical ("hmm. looks like you have some \"issues\" as you don't have\n"
+                "a %s file.\n", buf);
   }
 #ifdef DEBUG
   g_print ("Loading menu: %s\n", buf);
@@ -167,11 +180,11 @@
   char first = 1;
   char s[4096];
   GtkTreeIter sub_iter;
-  
+
   if (!file_to_load)
     return;
   if (file_to_load[0] != '/')
-    sprintf (buf, "%s/%s/%s", homedir (getuid ()), emenu_path, file_to_load);
+    sprintf (buf, "%s/%s", epath, file_to_load);
   else
     sprintf (buf, "%s", file_to_load);
 
@@ -273,8 +286,7 @@
   if (!g_path_is_absolute (params))
   {
     /* Tarnation! A relative path */
-    realfile = g_strjoin ("/", homedir (getuid ()),
-                          emenu_path, params, NULL);
+    realfile = g_strjoin (epath, params, NULL);
   }
   else
   {
@@ -303,7 +315,7 @@
     if (has_child)
     {
 #ifdef WRITE_FILE      
-      menu_ptr2 = fopen (menu_file[depth], "w");   
+      menu_ptr2 = fopen (menu_file[depth], "w");
       if (menu_ptr2 == NULL)
       {
         printf ("Couldn't save menu to: %s\n", menu_file[depth]);
@@ -318,7 +330,7 @@
 #else
       g_print ("write header to: \"%s\"\n", menu_file[depth]);
 #endif /* !WRITE_FILE */    
-      
+
       sprintf (buffer, "\"%s\"\t%s\tmenu\t\"%s\"\n",
                description[0] == '\0' ? "NULL" : description,
                icon[0] == '\0' ? "NULL" : icon,
@@ -356,7 +368,7 @@
       printf ("Couldn't save menu to: %s\n", menu_file[depth]);
     }
 #endif /*WRITE_FILE */
-  
+
     sprintf (buffer, "\"%s\"\n", description);
 #ifdef WRITE_FILE  
     fprintf (menu_ptr2, "%s", g_locale_from_utf8 (buffer,
===================================================================
RCS file: /cvsroot/enlightenment/e16/tools/e16menuedit2/src/e16menuedit2.c,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -3 -r1.18 -r1.19
--- e16menuedit2.c      5 Dec 2004 13:55:41 -0000       1.18
+++ e16menuedit2.c      29 Dec 2004 11:09:22 -0000      1.19
@@ -37,7 +37,8 @@
 int librsvg_cmp;
 char *browser;
 char *glade_file;
-char *emenu_path;
+char *epath;
+int emenu;
 
 int main (int argc, char *argv[])
 {
@@ -62,7 +63,11 @@
   textdomain (PACKAGE);
 #endif
 
+  /* set log level for app exit */
+  g_log_set_always_fatal (G_LOG_LEVEL_ERROR | G_LOG_LEVEL_CRITICAL);
+
   parse_options (argc, argv);
+
   gtk_init (&argc, &argv);
 
   for (i = 0; i < MAX_RECURSION; i++)
@@ -119,10 +124,10 @@
   }
 
   g_free (filename_properties);
-  
+
   gtk_main ();
 
-  free (emenu_path);
+  free (epath);
   g_free (glade_file);
 
   return 0;
@@ -191,30 +196,47 @@
 {
   poptContext context;
   int option;
-  char *emenu = NULL;
-  char *e_version_current;
-  int e_version_cmp;
-  char e_version[] = "0.16.8";
+  epath = NULL;
+  struct stat buf;
+  gboolean epath_missing = TRUE;
+  char *tmp;
+  
+  emenu = EMENU_AUTODETECT;
 
   struct poptOption options[] =
     {
-      {"emenu", 'e', POPT_ARG_STRING,
-        &emenu, ARG_EMENU,
-        "Enlightenment menu dir (enlightenment or e16).",
-        NULL},
+      {"menus", 'm', POPT_ARG_NONE, NULL, ARG_MENUS,
+       "Force search of file.menu in 'menus' subdirecory of enlightenment"
+       "configuration direcory. If not given e16menuedit2 try to auto detect 
it.",
+       NULL},
       {"version", 'v', POPT_ARG_NONE, NULL, ARG_VERSION, "show version", NULL},
       POPT_AUTOHELP {NULL, '\0', 0, NULL, 0}
     };
 
-  context = poptGetContext ("popt1", argc, (const char **) argv, options, 0);
+  /* get E path */
+  tmp = getenv ("ECONFDIR");
+  epath = g_strdup_printf (tmp);
+  
+  if (!epath)
+  {
+    epath = g_strdup_printf ("%s/%s", homedir (getuid ()),
+                                  ENLIGHTENMENT_PATH);
+  }
+  epath_missing = stat (epath, &buf);
+  if (epath_missing)
+  {
+    g_critical ("The direcory %s seems not to be a E16 conf path!\n", epath);
+  }
 
+  context = poptGetContext ("popt1", argc, (const char **) argv, options, 0);
+  
   /* start option handling */
   while ((option = poptGetNextOpt (context)) > 0)
-  {
+  {  
     switch (option)
     {
-    case ARG_EMENU:
-      g_print ("emenu case\n");
+    case ARG_MENUS:
+      emenu = EMENU_MENUS;
       break;
     case ARG_VERSION:
       show_version ();
@@ -223,43 +245,6 @@
     }
   }
 
-  if (emenu == NULL)
-  {
-    e_version_current = e16_version ();
-    e_version_cmp = version_cmp (e_version_current, e_version);
-    free (e_version_current);
-
-    if (e_version_cmp >= 0)
-    {
-      emenu_path = malloc (strlen (E16_MENU) + 1);
-      strcpy (emenu_path, E16_MENU);
-    }
-    else
-    {
-      emenu_path = malloc (strlen (ENLIGHTENMENT_MENU) + 1);
-      strcpy (emenu_path, ENLIGHTENMENT_MENU);
-    }
-  }
-  else
-  {
-    if (!strcmp (emenu, "enlightenment"))
-    {
-      emenu_path = malloc (strlen (ENLIGHTENMENT_MENU) + 1);
-      strcpy (emenu_path, ENLIGHTENMENT_MENU);
-    }
-    else if (!strcmp (emenu, "e16"))
-    {
-      emenu_path = malloc (strlen (E16_MENU) + 1);
-      strcpy (emenu_path, E16_MENU);
-    }
-    else
-    {
-      g_print ("Sorry, the parameter 'emenu' has only state 'enlightenment'\n"
-               "for old menu structure and 'e16' for new direcory structure\n"
-              "in '.e16/menus' for E16 > 0.16.8.\n");
-      exit (0);
-    }
-  }
 }
 
 void show_version ()
===================================================================
RCS file: /cvsroot/enlightenment/e16/tools/e16menuedit2/src/e16menuedit2.h,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -3 -r1.8 -r1.9
--- e16menuedit2.h      5 Dec 2004 11:12:51 -0000       1.8
+++ e16menuedit2.h      29 Dec 2004 11:09:22 -0000      1.9
@@ -42,8 +42,8 @@
 #define APP_HOME ".e16menuedit2"
 #define ICON_DIR "icons"
 #define DEBUG_OUTPUT printf ("(%s, %d): ", __FILE__, __LINE__);
-#define ENLIGHTENMENT_MENU ".enlightenment"
-#define E16_MENU ".e16"
+#define ENLIGHTENMENT_PATH ".enlightenment"
+#define E16_PATH ".e16"
 
 void print_statusbar (const gchar *format, ...);
 gboolean browser_func (GtkTreeModel *model, GtkTreePath *path,
@@ -53,8 +53,14 @@
 
 enum
 {
-  ARG_EMENU,
+  ARG_MENUS = 1,
   ARG_VERSION
 };
 
+enum
+{
+  EMENU_AUTODETECT,
+  EMENU_MENUS
+};
+
 #endif /* _E16MENUEDIT_H */




-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now. 
http://productguide.itmanagersjournal.com/
_______________________________________________
enlightenment-cvs mailing list
enlightenment-cvs@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs

Reply via email to