yakov pushed a commit to branch master.

http://git.enlightenment.org/tools/erigo.git/commit/?id=5d73d2fb09681ae750277046eb01b04c8b9956f3

commit 5d73d2fb09681ae750277046eb01b04c8b9956f3
Author: Yakov Goldberg <[email protected]>
Date:   Mon Jan 19 11:09:50 2015 +0200

    Resources: save relative path for resources which are in project folder
---
 src/lib/generator.c      |  4 +--
 src/lib/gui_parser.c     | 92 ++++++++++++++++++++++++++++++++++++++++--------
 src/lib/json_generator.c | 27 ++++++++++++--
 3 files changed, 105 insertions(+), 18 deletions(-)

diff --git a/src/lib/generator.c b/src/lib/generator.c
index fa799b1..3f14094 100644
--- a/src/lib/generator.c
+++ b/src/lib/generator.c
@@ -865,8 +865,8 @@ _ctx_generate(Global_Gen_Context *gl_ctx)
      }
 
    eina_strbuf_append_printf(gl_ctx->h_buf,
-         "#ifndef _%s_h\n"
-         "#define _%s_h\n", h_macro, h_macro);
+         "#ifndef _%s_\n"
+         "#define _%s_\n", h_macro, h_macro);
    free(h_macro);
    h_macro = NULL;
 
diff --git a/src/lib/gui_parser.c b/src/lib/gui_parser.c
index e62e0ab..6a9deba 100644
--- a/src/lib/gui_parser.c
+++ b/src/lib/gui_parser.c
@@ -806,39 +806,103 @@ _resource_parse(Gui_Context *gui_ctx, Eina_Json_Value 
*res_js)
              Eina_Iterator *it = eina_json_object_iterator_new(tmp);
              EINA_ITERATOR_FOREACH(it, j)
                {
-                  const char *id = NULL, *value = NULL, *edc_path = NULL;
+                  const char *id = NULL, *value = NULL;
                   id = eina_json_pair_name_get(j);
                   Eina_Json_Value *cur = eina_json_pair_value_get(j);
+
+                  Gui_Resource *gui_res = gui_context_resource_new(gui_ctx, 
res_type, id);
+                  if (!gui_res)
+                    {
+                       ERR("Cannot create RESOURCE: type: %s, id: %s", 
section_name, id);
+                       continue;
+                    }
+
                   if (res_type == RESOURCE_EDJE)
                     {
                        Eina_Json_Value *edc_val = eina_json_array_nth_get(cur, 
1);
+                       const char *edc_path = NULL;
                        if (eina_json_type_get(edc_val) != 
EINA_JSON_TYPE_STRING)
                          {
                             ERR("Json Value is not string");
+                            resource_del(gui_res);
+                            continue;
                          }
-                       else
+                       edc_path = eina_json_string_get(edc_val);
+                       /* by default set edc path empty but not NULL (legacy 
issue) */
+                       resource_edc_path_set(gui_res, "");
+                       if (edc_path && strlen(edc_path))
                          {
-                            edc_path = eina_json_string_get(edc_val);
+                            /* If path starts with / this is absolute path. */
+                            if (*edc_path == '/')
+                              {
+                                 resource_edc_path_set(gui_res, edc_path);
+                              }
+                            /* ...if not, add project path in the beginning. */
+                            else
+                              {
+                                 char val[PATH_MAX];
+                                 sprintf(val, "%s/%s", 
gui_context_project_path_get(gui_ctx), edc_path);
+                                 resource_value_set(gui_res, val);
+                                 resource_edc_path_set(gui_res, val);
+                              }
                          }
                        cur = eina_json_array_nth_get(cur, 0);
+
+                       if (eina_json_type_get(cur) != EINA_JSON_TYPE_STRING)
+                         {
+                            ERR("Json Value is not string");
+                            resource_del(gui_res);
+                            continue;
+                         }
+
+                       value = eina_json_string_get(cur);
+                       if (*value == '/')
+                         {
+                            resource_value_set(gui_res, value);
+                            resource_edj_path_set(gui_res, value);
+                         }
+                       /* ...if not, add project path in the beginning. */
+                       else
+                         {
+                            char val[PATH_MAX];
+                            sprintf(val, "%s/%s", 
gui_context_project_path_get(gui_ctx), value);
+                            resource_value_set(gui_res, val);
+                            resource_edj_path_set(gui_res, val);
+                         }
                     }
-                  if (eina_json_type_get(cur) != EINA_JSON_TYPE_STRING)
+                  else if (res_type == RESOURCE_IMAGE)
                     {
-                       ERR("Json Value is not string");
+                       if (eina_json_type_get(cur) != EINA_JSON_TYPE_STRING)
+                         {
+                            ERR("Json Value is not string");
+                            resource_del(gui_res);
+                            continue;
+                         }
+                       value = eina_json_string_get(cur);
+                       /* If path starts with / this is absolute path. */
+                       if (*value == '/')
+                         {
+                            resource_value_set(gui_res, value);
+                         }
+                       /* ...if not, add project path in the beginning. */
+                       else
+                         {
+                            char val[PATH_MAX];
+                            sprintf(val, "%s/%s", 
gui_context_project_path_get(gui_ctx), value);
+                            resource_value_set(gui_res, val);
+                         }
                     }
                   else
                     {
+                       if (eina_json_type_get(cur) != EINA_JSON_TYPE_STRING)
+                         {
+                            ERR("Json Value is not string");
+                            resource_del(gui_res);
+                            continue;
+                         }
                        value = eina_json_string_get(cur);
+                       resource_value_set(gui_res, value);
                     }
-                  Gui_Resource *gui_res = gui_context_resource_new(gui_ctx, 
res_type, id);
-                  if (!gui_res)
-                    {
-                       ERR("Cannot create RESOURCE: type: %s, id: %s", 
section_name, id);
-                       continue;
-                    }
-                  resource_value_set(gui_res, value);
-                  if (res_type == RESOURCE_EDJE) 
resource_edj_path_set(gui_res, value);
-                  if (edc_path) resource_edc_path_set(gui_res, edc_path);
                }
              eina_iterator_free(it);
           }
diff --git a/src/lib/json_generator.c b/src/lib/json_generator.c
index 183d203..2b3abbb 100644
--- a/src/lib/json_generator.c
+++ b/src/lib/json_generator.c
@@ -143,11 +143,34 @@ _resources_json_generate(const Gui_Context *ctx)
                 case RESOURCE_EDJE:
                     {
                        Eina_Json_Value *ar = eina_json_array_new();
-                       eina_json_array_append(ar, 
eina_json_string_new(resource_edj_path_get(res))); /* EDJ path */
-                       eina_json_array_append(ar, 
eina_json_string_new(resource_edc_path_get(res))); /* EDC path */
+                       value = resource_edj_path_get(res);
+                       /* If path is in PROJECT folder, save only relative 
path. */
+                       if (value && strstr(value, 
gui_context_project_path_get(ctx)))
+                         {
+                            value += strlen(gui_context_project_path_get(ctx)) 
+ 1;
+                         }
+                       eina_json_array_append(ar, 
eina_json_string_new(value)); /* EDJ path */
+
+                       value = resource_edc_path_get(res);
+                       /* If path is in PROJECT folder, save only relative 
path. */
+                       if (value && strstr(value, 
gui_context_project_path_get(ctx)))
+                         {
+                            value += strlen(gui_context_project_path_get(ctx)) 
+ 1;
+                         }
+                       eina_json_array_append(ar, 
eina_json_string_new(value)); /* EDC path */
                        eina_json_object_append(sub_obj, res_name, ar);
                        break;
                     }
+                case RESOURCE_IMAGE:
+                    {
+                       /* If path is in PROJECT folder, save only relative 
path. */
+                       if (strstr(value, gui_context_project_path_get(ctx)))
+                         {
+                            value += strlen(gui_context_project_path_get(ctx)) 
+ 1;
+                         }
+                       eina_json_object_append(sub_obj, res_name, 
eina_json_string_new(value));
+                       break;
+                    }
                 default:
                     {
                        eina_json_object_append(sub_obj, res_name, 
eina_json_string_new(value));

-- 


Reply via email to