Enlightenment CVS committal

Author  : onefang
Project : e17
Module  : apps/e_utils

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


Modified Files:
        eaps.c eaps.h global.c global.h parse.c parse.h 


Log Message:
* Started to clean up the eap creation.

* Added notes on how best to create an eap.

* Guess at a window class, seems to be correct most of the time.  Wrong 
guesses can be fixed up individually with the eap editors.  Won't overwrite 
a pre existing window class in a pre existing eap.

===================================================================
RCS file: /cvs/e/e17/apps/e_utils/src/bin/e17genmenu/eaps.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -3 -r1.5 -r1.6
--- eaps.c      26 Apr 2006 08:24:48 -0000      1.5
+++ eaps.c      29 Apr 2006 06:05:51 -0000      1.6
@@ -1,16 +1,16 @@
+#include <ctype.h>
 #include "global.h"
 #include "config.h"
 #include "icons.h"
 #include "eaps.h"
 #include "parse.h"
 
-//#define DEBUG 1
+#define DEBUG 1
 
 extern int not_found_count;
 
 static void _write_eap(Eet_File *ef, char *section, char *value);
 
-
 /* Create a .directory.eap for this dir */
 void
 create_dir_eap(char *path, char *cat)
@@ -33,41 +33,90 @@
      }
 }
 
-char *
-get_window_class(char *file)
-{
-   char *tmp, *cls;
-   int i;
-   Eet_File *ef;
-
-   if (!ecore_file_exists(file))
-      return NULL;
+#define EAP_MIN_WIDTH 8
+#define EAP_MIN_HEIGHT 8
 
-   ef = eet_open(file, EET_FILE_MODE_READ);
-   if (!ef)
-      return NULL;
-
-   tmp = eet_read(ef, "app/window/class", &i);
-   if (!tmp)
-     {
-        if (ef)
-           eet_close(ef);
-        return NULL;
-     }
-
-   /* Allocate string for window class */
-   cls = malloc(i + 1);
-   memcpy(cls, tmp, i);
-   cls[i] = 0;
-
-   if (tmp)
-      free(tmp);
-   eet_close(ef);
-
-   if (cls != NULL)
-      return strdup(cls);
-   return NULL;
-}
+#define EAP_EDC_TMPL \
+"images {\n"  \
+"   image: \"%s\" COMP;\n" \
+"}\n" \
+"collections {\n" \
+"   group {\n" \
+"      name: \"icon\";\n" \
+"      max: %d %d;\n" \
+"      parts {\n" \
+"       part {\n" \
+"          name: \"image\";\n" \
+"          type: IMAGE;\n" \
+"          mouse_events: 0;\n" \
+"          description {\n" \
+"             state: \"default\" 0.00;\n" \
+"             visible: 1;\n" \
+"             aspect: 1.00 1.00;\n" \
+"             rel1 {\n" \
+"                relative: 0.00 0.00;\n" \
+"                offset: 0 0;\n" \
+"             }\n" \
+"             rel2 {\n" \
+"                relative: 1.00 1.00;\n" \
+"                offset: -1 -1;\n" \
+"             }\n" \
+"             image {\n" \
+"                normal: \"%s\";\n" \
+"             }\n" \
+"          }\n" \
+"       }\n" \
+"      }\n" \
+"   }\n" \
+"}\n"
+
+#define EAP_EDC_TMPL_EMPTY \
+"images {\n " \
+"}\n" \
+"collections {\n" \
+"}\n"
+
+
+/* How to create the perfect eap.
+ *
+ * /dir/to/icon_name.png
+ * icon size
+ * write EAP_EDC_TMPL to /tmp/temp_file.edc
+ * edje_cc -id /dir/to -fd . /tmp/temp_file.edc 
~/.e/e/applications/all/file.eap
+ *
+ * eet_open ~/.e/e/applications/all/file.eap
+ * app/info/name =  eap->name
+ * app/info/generic = eap->generic
+ * app/info/comments = eap->comment
+ *
+ * app/info/name[lang] =  eap->name->lang
+ * app/info/generic[lang] = eap->generic->lang
+ * app/info/comments[lang] = eap->comment->lang
+ *
+ * app/info/startup_notify = eap->startup
+ * app/info/exe = eap->exec
+ *    Handle the fdo %x replacable params.  Some should be stripped, some 
should be expanded.
+ * app/icon/class
+ *    icon/class is a list of standard icons from the theme that can override 
the icon created above.
+ *    Use (from .desktop) eap name,exe name,categories.  It's case sensitive, 
the reccomendation is to lowercase it.
+ *    It should be most specific to most generic.  firefox,browser,internet 
for instance
+ *
+ * app/window/class
+ *    Guess - exe name vith first letter capitalized.
+ * app/window/name
+ * app/window/title
+ * app/window/role
+ * app/info/wait_exit
+ *    Wait for app to exit before starting next one.
+ * 
+ * Some other stuff from e_apps.c e_app_fields_save()
+ *    get the icon image into an evas then -
+ *    eet_data_image_write(ef, "images/0", 
+ *       ecore_evas_buffer_pixels_get(buf), 
+ *       a->width, a->height, 
+ *       evas_object_image_alpha_get(im), 
+ *       1, 0, 0);
+ */
 
 void
 write_icon(char *file, G_Eap *eap)
@@ -79,7 +128,7 @@
    Engrave_Part_State *ps;
    Eet_File *ef;
 
-   char *idir, *ifile, *icomp, *exec;
+   char *idir, *ifile;
 
 #ifdef DEBUG
    fprintf(stderr, "\tWriting file %s\t\twith icon (%s) %s\n", file, 
eap->icon, eap->icon_path);
@@ -95,8 +144,7 @@
    eet = engrave_file_new();
    engrave_file_image_dir_set(eet, idir);
 
-   icomp = get_icon_compression();
-   if (!strcmp(icomp, "COMP"))
+   if (!strcmp(get_icon_compression(), "COMP"))
       image = engrave_image_new(ifile, ENGRAVE_IMAGE_TYPE_COMP, 0);
    else
       image = engrave_image_new(ifile, ENGRAVE_IMAGE_TYPE_LOSSY, 0);
@@ -122,81 +170,98 @@
    engrave_edj_output(eet, file);
    engrave_file_free(eet);
 
-//   if (icomp)
-//      free(icomp);
-//   if (idir)
-//      free(idir);
-//   if (ifile)
-//      free(ifile);
-
-   /* FIXME: This is probably why creating eaps takes so long.  
-    * We should just create it right in the first place, rather 
-    * than creating a basic one, then rewriting it several times
-    * each time we find a new little bit of info.
-    */
+   if (idir)
+      free(idir);
+
    ef = eet_open(file, EET_FILE_MODE_READ_WRITE);
    if (ef)
-   {
-        /* Set Eap Values. Trap For Name Not Being Set */
+     {
+        /* FIXME: if there is no name, strip the path and extension of the eap 
file name and use that. */
         if (eap->name != NULL)
            _write_eap(ef, "app/info/name", eap->name);
-        else if (eap->eap_name != NULL)
-           _write_eap(ef, "app/info/name", eap->eap_name);
-
         if (eap->generic != NULL)
            _write_eap(ef, "app/info/generic", eap->generic);
         if (eap->comment != NULL)
            _write_eap(ef, "app/info/comments", eap->comment);
 
-        /* Parse Exec string for %'s that messup eap write */
-        exec = NULL;
         if (eap->exec != NULL)
           {
-             exec = parse_exec(eap->exec);
-             if (exec != NULL)
-               {
-                  _write_eap(ef, "app/info/exe", exec);
-                  _write_eap(ef, "app/icon/class", exec);
-               }
+            /* FIXME: Handle the fdo %x replacable params.  Some should be 
stripped, some should be expanded. */
+             _write_eap(ef, "app/info/exe", eap->exec);
           }
 
         if (eap->startup != NULL)
            _write_eap(ef, "app/info/startup_notify", eap->startup);
+
+        if (eap->window_class == NULL)
+       {
+           int i;
+          char *tmp;
+
+           /* Try reading it from the existing eap. */
+           tmp = eet_read(ef, "app/window/class", &i);
+          if (tmp)
+            {
+                eap->window_class = malloc(i + 1);
+                if (eap->window_class)
+                 {
+                     memcpy(eap->window_class, tmp, i);
+                     eap->window_class[i] = 0;
+                 }
+               free(tmp);
+            }
+       }
+        if ((eap->window_class == NULL) && (eap->exec != NULL))
+         {
+            char *tmp;
+
+            /* Guess - exe name with first letter capitalized. */
+             tmp = strdup(eap->exec);
+            if (tmp)
+              {
+                 char *p;
+
+                 p = tmp;
+                 while ((*p != '\0') && (*p != ' '))
+                   {
+                      *p = tolower(*p);
+                      p++;
+                   }
+                 *p = '\0';
+                 p = ecore_file_get_file(tmp);  /* In case the exe included a 
path. */
+                 *p = toupper(*p);
+                  eap->window_class = strdup(p);
+                 free(tmp);
+              }
+         }
         if (eap->window_class != NULL)
            _write_eap(ef, "app/window/class", eap->window_class);
-      eet_close(ef);
-   }
+
+        eet_close(ef);
+     }
 }
 
 
 static void
 _write_eap(Eet_File *ef, char *section, char *value)
 {
-   int i;
+   if ((!value) || (value[0] == '\0'))
+      eet_delete(ef, section);
+   else
+     {
+        int i = 0;
 
 #ifdef DEBUG
-   fprintf(stderr, "\t\t%s:%s\n", strdup(section), strdup(value));
+        fprintf(stderr, "\t\t%s:%s\n", section, value);
 #endif
-
-   if (!strcmp(section, "app/info/startup_notify"))
-     {
-        if (!value)
-           eet_delete(ef, section);
-        if (value)
+        if (!strcmp(section, "app/info/startup_notify"))
           {
              i = atoi(value);
-             eet_write(ef, strdup(section), &i, 1, 0);
-          }
-     }
-   else
-     {
-        if (!value)
-           eet_delete(ef, section);
-        if (value)
-          {
-             i = eet_write(ef, strdup(section), strdup(value), strlen(value), 
0);
-             if (i == 0)
-                fprintf(stderr, "Failed To Write %s To %s\n", value, section);
+             i = eet_write(ef, section, &i, 1, 0);
           }
+        else
+             i = eet_write(ef, section, value, strlen(value), 0);
+        if (i == 0)
+           fprintf(stderr, "Failed to write %s to %s\n", value, section);
      }
 }
===================================================================
RCS file: /cvs/e/e17/apps/e_utils/src/bin/e17genmenu/eaps.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -3 -r1.2 -r1.3
--- eaps.h      26 Apr 2006 01:44:06 -0000      1.2
+++ eaps.h      29 Apr 2006 06:05:51 -0000      1.3
@@ -8,7 +8,6 @@
 #include <Engrave.h>
 
 void create_dir_eap(char *path, char *cat);
-char *get_window_class(char *file);
 void write_icon(char *file, G_Eap *eap);
 
 #endif
===================================================================
RCS file: /cvs/e/e17/apps/e_utils/src/bin/e17genmenu/global.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -3 -r1.2 -r1.3
--- global.c    9 Mar 2006 03:06:25 -0000       1.2
+++ global.c    29 Apr 2006 06:05:51 -0000      1.3
@@ -86,28 +86,28 @@
    for (i = 1; i < argc; i++)
      {
         if ((strncmp(argv[i], "--lossy", 11) == 0) || (strncmp(argv[i], "-l", 
2) == 0))
-           return strdup("LOSSY");
+           return "LOSSY";
      }
-   return strdup("COMP");
+   return "COMP";
 }
 
 char *
 get_eap_name(char *file)
 {
-   char *tmp, *tmp2;
+   char *tmp2;
    char eap[MAX_PATH];
 
-   tmp2 = ecore_file_get_file(strdup(file));
+   tmp2 = strdup(ecore_file_get_file(file));
    if (!tmp2)
       return NULL;
 
-   tmp = strdup(tmp2);
    if (strrchr(tmp2, '.') != NULL)
      {
-        tmp = strtok(tmp2, ".");
-        snprintf(eap, sizeof(eap), "%s.eap", tmp);
+        snprintf(eap, sizeof(eap), "%s.eap", strtok(tmp2, "."));
+       free(tmp2);
         return strdup(eap);
      }
+   free(tmp2);
    return NULL;
 }
 
===================================================================
RCS file: /cvs/e/e17/apps/e_utils/src/bin/e17genmenu/global.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -3 -r1.3 -r1.4
--- global.h    26 Apr 2006 01:44:06 -0000      1.3
+++ global.h    29 Apr 2006 06:05:51 -0000      1.4
@@ -16,6 +16,7 @@
 typedef struct _G_Eap G_Eap;
 struct _G_Eap
 {
+   char *desktop_file;
    char *eap_name;
    char *name;
    char *generic;
@@ -24,6 +25,7 @@
    char *exec;
    char *icon;
    char *icon_path;
+   char *icon_class;
    char *startup;
    char *type;
    char *window_class;
===================================================================
RCS file: /cvs/e/e17/apps/e_utils/src/bin/e17genmenu/parse.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -3 -r1.5 -r1.6
--- parse.c     26 Apr 2006 08:24:48 -0000      1.5
+++ parse.c     29 Apr 2006 06:05:51 -0000      1.6
@@ -98,46 +98,21 @@
    return strdup(p);
 }
 
-char *
-parse_exec(char *exec)
-{
-   char *token;
-
-   token = strdup(exec);
-   /* Strip Caption From Exec */
-   if (strstr(token, "caption") != NULL)
-     {
-        token = strdup(token);
-        token = strtok(token, " ");
-     }
-
-   /* Strip %U from Exec */
-   if (strstr(token, "%") != NULL)
-     {
-        token = strdup(token);
-        token = strtok(token, " ");
-     }
-   return strdup(token);
-}
-
 void
 parse_desktop_file(char *app, char *menu_path)
 {
-   char *home, *eap_name;
+   char *home;
    G_Eap *eap;
    Desktop *desktop;
 
    home = get_home();
-   eap_name = get_eap_name(app);
 
 #ifdef DEBUG
    fprintf(stderr, "Parsing Desktop File %s\n", app);
 #endif
 
    eap = calloc(1, sizeof(G_Eap));
-   eap->eap_name = strdup(eap_name);
-   if (eap_name)
-      free(eap_name);
+   eap->eap_name = get_eap_name(app);
 
    desktop = parse_desktop_ini_file(app);
    if ((desktop) && (desktop->group))
@@ -230,8 +205,6 @@
    overwrite = get_overwrite();
 
    snprintf(path, sizeof(path), "%s" EAPPDIR "/%s", home, eap->eap_name);
-   if (eap->window_class == NULL)
-      eap->window_class = get_window_class(path);
 
    if (eap->icon != NULL)
       eap->icon_path = find_icon(eap->icon);
@@ -262,7 +235,7 @@
 void
 parse_debian_file(char *file)
 {
-   char *eap_name, *name, *generic, *comment, *exec, *category, *icon;
+   char *name, *generic, *comment, *exec, *category, *icon;
    char buffer[MAX_PATH];
    int overwrite, length;
    FILE *f;
@@ -272,7 +245,6 @@
       return;
 
    overwrite = get_overwrite();
-   eap_name = get_eap_name(file);
 
 #ifdef DEBUG
    fprintf(stderr, "Parsing Debian File %s\n", file);
@@ -286,7 +258,7 @@
      }
 
    eap = calloc(1, sizeof(G_Eap));
-   eap->eap_name = eap_name;
+   eap->eap_name = get_eap_name(file);
    *buffer = 0;
    while (fgets(buffer, sizeof(buffer), f) != NULL)
      {
===================================================================
RCS file: /cvs/e/e17/apps/e_utils/src/bin/e17genmenu/parse.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -3 -r1.1 -r1.2
--- parse.h     7 Mar 2006 21:58:24 -0000       1.1
+++ parse.h     29 Apr 2006 06:05:51 -0000      1.2
@@ -20,7 +20,6 @@
 
 /* Function Prototypes */
 char *get_t(char *icon);
-char *parse_exec(char *exec);
 char *parse_buffer(char *b, char *section);
 void parse_desktop_file(char *app, char *menu_path);
 void parse_debian_file(char *file);




-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
enlightenment-cvs mailing list
enlightenment-cvs@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs

Reply via email to