rimmed pushed a commit to branch master.

http://git.enlightenment.org/tools/eflete.git/commit/?id=925df07ea0889b58a20e8b4987f9bad9ce6c92b0

commit 925df07ea0889b58a20e8b4987f9bad9ce6c92b0
Author: Vyacheslav Reutskiy <v.reuts...@samsung.com>
Date:   Wed Jul 29 13:56:34 2015 +0300

    Eflete: add option for import edj file from command line
    
    @feature
    
    Change-Id: I9ac9ae882edd14945074459e53dd3008dad5d218
---
 src/bin/main.c | 129 ++++++++++++++++++++++++++++++++++++++++++++++++++++-----
 1 file changed, 119 insertions(+), 10 deletions(-)

diff --git a/src/bin/main.c b/src/bin/main.c
index 15f9c1a..4e5da68 100644
--- a/src/bin/main.c
+++ b/src/bin/main.c
@@ -18,8 +18,15 @@
  */
 
 #include <Ecore_Getopt.h>
+#include <regex.h>
 #include "main_window.h"
 
+static char *open = NULL;
+static char *import_edj = NULL;
+static char *pro_name = NULL;
+static char *pro_path = NULL;
+static Eina_Bool pro_replace = false;
+
 static const Ecore_Getopt options = {
    PACKAGE_NAME,
    "%prog [options]",
@@ -31,6 +38,10 @@ static const Ecore_Getopt options = {
    EINA_TRUE,
    {
       ECORE_GETOPT_STORE_STR('o', "open", N_("Eflete project file")),
+      ECORE_GETOPT_STORE_STR(0, "import-edj", N_("Import the edj file as new 
project")),
+      ECORE_GETOPT_STORE_STR(0, "name", N_("Name for new project that would be 
created in import process")),
+      ECORE_GETOPT_STORE_STR(0, "path", N_("Path for project")),
+      ECORE_GETOPT_STORE_TRUE(0, "replace", N_("Replace existing project")),
       ECORE_GETOPT_VERSION  ('v', "version"),
       ECORE_GETOPT_COPYRIGHT('c', "copyright"),
       ECORE_GETOPT_LICENSE  ('l', "license"),
@@ -39,15 +50,76 @@ static const Ecore_Getopt options = {
    }
 };
 
+void
+_import_end(void *data __UNUSED__, PM_Project_Result result)
+{
+   Project *pro;
+   App_Data *ap;
+
+   ap = app_data_get();
+
+   if (result == PM_PROJECT_SUCCESS)
+     {
+        pro = pm_project_thread_project_get(ap->pr_thread);
+        ap->project = pro;
+
+        wm_widgets_list_objects_load(pro->widgets,
+                                     evas_object_evas_get(ap->win),
+                                     pro->mmap_file);
+        wm_layouts_list_objects_load(pro->layouts,
+                                     evas_object_evas_get(ap->win),
+                                     pro->mmap_file);
+        wm_styles_build_alias(pro->widgets,
+                              pro->layouts);
+
+        blocks_show(ap);
+
+        if (!eina_inlist_count(ap->project->widgets))
+          ui_widget_list_tab_activate(ui_block_widget_list_get(ap), 1);
+
+        STATUSBAR_PROJECT_PATH(ap, ap->project->pro_path);
+        STATUSBAR_PROJECT_SAVE_TIME_UPDATE(ap);
+
+        NOTIFY_INFO(3, _("Project '%s' is opened."), pro->name);
+     }
+     evas_object_show(ap->win);
+}
+
+Eina_Bool
+_message_print(void *data __UNUSED__, Eina_Stringshare *progress_string)
+{
+   fprintf(stdout, "%s\n", progress_string);
+   return true;
+}
+
+static void
+_import_edj(void *data __UNUSED__)
+{
+   /* Ugly hack, but we need to do this.
+    * When we try to import edj file while ecore main loop not fully started
+    * we get a freeze. So for use the ecore and eina threads in the project
+    * manager need to itarate the main loop for initialize it.
+    * DO NOT DELETE: whith out iterate import from command line not worked! */
+   ecore_main_loop_iterate();
+
+   App_Data *ap = app_data_get();
+   ap->pr_thread = pm_project_import_edj(pro_name, pro_path, import_edj,
+                                         _message_print, _import_end, NULL);
+
+}
+
 EAPI_MAIN int
 elm_main(int argc, char **argv)
 {
-   char *open = NULL;
    Eina_Bool info_only = false;
-   int args;
+   Eina_Stringshare *pro_folder;
 
    Ecore_Getopt_Value values[] = {
      ECORE_GETOPT_VALUE_STR(open),
+     ECORE_GETOPT_VALUE_STR(import_edj),
+     ECORE_GETOPT_VALUE_STR(pro_name),
+     ECORE_GETOPT_VALUE_STR(pro_path),
+     ECORE_GETOPT_VALUE_BOOL(pro_replace),
      ECORE_GETOPT_VALUE_BOOL(info_only),
      ECORE_GETOPT_VALUE_BOOL(info_only),
      ECORE_GETOPT_VALUE_BOOL(info_only),
@@ -63,13 +135,7 @@ elm_main(int argc, char **argv)
    enventor_init(argc, argv);
 #endif
 
-   args = ecore_getopt_parse(&options, values, argc, argv);
-   if (args < 0)
-     {
-        ERR("Could not parse command line options.");
-        info_only = true;
-     }
-
+   ecore_getopt_parse(&options, values, argc, argv);
    if (!info_only)
      {
 #ifdef HAVE_CONFIG_H
@@ -84,7 +150,6 @@ elm_main(int argc, char **argv)
              app_shutdown();
              return -1;
           }
-        evas_object_show(ap->win);
 
         if (open)
           {
@@ -104,6 +169,7 @@ elm_main(int argc, char **argv)
 
                   if (!eina_inlist_count(ap->project->widgets))
                     ui_widget_list_tab_activate(ui_block_widget_list_get(ap), 
1);
+                  evas_object_show(ap->win);
                }
              else
                {
@@ -111,6 +177,49 @@ elm_main(int argc, char **argv)
                   return 1;
                }
           }
+        if (import_edj)
+          {
+            if (!ecore_file_exists(import_edj))
+              {
+                 fprintf(stderr, N_("ERROR: cann't find file: '%s'.\n"), 
import_edj);
+                 return -1;
+              }
+            if (!pro_name)
+              {
+                 fprintf(stderr, N_("ERROR: missing name for imported 
project.\n"));
+                 fprintf(stderr, N_("ERROR: invalid options found. See 
--help.\n"));
+                 return -1;
+              }
+            else
+              {
+                 regex_t regex;
+                 regcomp(&regex, NAME_REGEX, REG_EXTENDED | REG_NOSUB);
+                 if (regexec(&regex, pro_name, (size_t)0, NULL, 0))
+                   {
+                      fprintf(stderr, N_("ERROR: invalid name. Name can 
contain only next characters: a-zA-z0-9_.\n"));
+                      return -1;
+                   }
+                 regfree(&regex);
+              }
+            if (!pro_path) pro_path = eina_file_path_sanitize(".");
+            pro_folder = eina_stringshare_printf("%s/%s", pro_path, pro_name);
+            if (ecore_file_exists(pro_folder))
+              {
+                 if (!pro_replace)
+                   {
+                      fprintf(stderr, N_("ERROR: can't import file '%s'. 
Project '%s' exist.\n"),
+                              import_edj, pro_folder);
+                      fprintf(stderr, N_("ERROR: to replace existing project 
use option '--replace'.\n"));
+                      fprintf(stderr, N_("ERROR: invalid options found. See 
--help.\n"));
+                      return -1;
+                   }
+                 else  ecore_file_recursive_rm(pro_folder);
+              }
+            ecore_job_add(_import_edj, NULL);
+            eina_stringshare_del(pro_folder); pro_folder = NULL;
+          }
+        else evas_object_show(ap->win);
+
         elm_run();
 #ifdef HAVE_ENVENTOR
         enventor_shutdown();

-- 


Reply via email to