ajwillia-ms pushed a commit to branch master.

http://git.enlightenment.org/tools/edi.git/commit/?id=032d7e5963e3ea8de4e9a02ab149d34b799d3949

commit 032d7e5963e3ea8de4e9a02ab149d34b799d3949
Author: Andy Williams <[email protected]>
Date:   Sat Jan 17 17:04:26 2015 +0000

    Move project creation to our Edi library.
    
    Move to ecore_exe from fork/wait as it is more portable
---
 src/bin/welcome/edi_welcome.c | 31 +++++++++++------------
 src/lib/Edi.h                 |  1 +
 src/lib/Makefile.am           |  4 ++-
 src/lib/edi_builder.c         |  1 -
 src/lib/edi_create.c          | 57 +++++++++++++++++++++++++++++++++++++++++++
 src/lib/edi_create.h          | 52 +++++++++++++++++++++++++++++++++++++++
 6 files changed, 127 insertions(+), 19 deletions(-)

diff --git a/src/bin/welcome/edi_welcome.c b/src/bin/welcome/edi_welcome.c
index 1a6c758..10e18bb 100644
--- a/src/bin/welcome/edi_welcome.c
+++ b/src/bin/welcome/edi_welcome.c
@@ -9,9 +9,6 @@
 
 #include "edi_private.h"
 
-#include <stdlib.h>
-#include <sys/wait.h>
-
 #define _EDI_WELCOME_PROJECT_NEW_TABLE_WIDTH 4
 
 static Evas_Object *_welcome_window;
@@ -190,10 +187,22 @@ _edi_welcome_project_new_input_row_add(const char *text, 
const char *placeholder
 }
 
 static void
+_edi_welcome_project_new_create_done_cb(const char *path, Eina_Bool success)
+{
+   if (!success)
+     {
+        ERR("Unable to create project at path %s", path);
+
+        return;
+     }
+
+   _edi_welcome_project_open(path, EINA_TRUE);
+}
+
+static void
 _edi_welcome_project_new_create_cb(void *data EINA_UNUSED, Evas_Object *obj 
EINA_UNUSED, void *event_info EINA_UNUSED)
 {
    const char *path, *name, *user, *email, *url;
-   char script[PATH_MAX], fullpath[PATH_MAX];
 
    path = elm_fileselector_path_get(_create_inputs[0]);
    name = elm_object_text_get(_create_inputs[1]);
@@ -201,19 +210,7 @@ _edi_welcome_project_new_create_cb(void *data EINA_UNUSED, 
Evas_Object *obj EINA
    user = elm_object_text_get(_create_inputs[3]);
    email = elm_object_text_get(_create_inputs[4]);
 
-   snprintf(script, sizeof(script), "%s/skeleton/eflprj", 
elm_app_data_dir_get());
-   snprintf(fullpath, sizeof(fullpath), "%s/%s", path, name);
-   int pid = fork();
-
-   if (pid == 0)
-     {
-        printf("Creating project \"%s\" at path %s for %s<%s>\n", name, 
fullpath, user, email);
-
-        execlp(script, script, fullpath, name, user, email, url, NULL);
-        exit(0);
-     }
-   waitpid(pid, NULL, 0);
-   _edi_welcome_project_open(fullpath, EINA_TRUE);
+   edi_create_project(path, name, url, user, email, 
_edi_welcome_project_new_create_done_cb);
 }
 
 static void
diff --git a/src/lib/Edi.h b/src/lib/Edi.h
index aff9918..b1e5330 100644
--- a/src/lib/Edi.h
+++ b/src/lib/Edi.h
@@ -34,6 +34,7 @@
 extern "C" {
 #endif
 
+#include <edi_create.h>
 #include <edi_builder.h>
 #include <edi_path.h>
 
diff --git a/src/lib/Makefile.am b/src/lib/Makefile.am
index 03684f1..27e9be4 100644
--- a/src/lib/Makefile.am
+++ b/src/lib/Makefile.am
@@ -12,13 +12,15 @@ lib_LTLIBRARIES = libedi.la
 
 includes_HEADERS = \
 edi_builder.h \
+edi_create.h \
 edi_path.h \
 Edi.h
 includesdir = $(includedir)/edi-@VMAJ@
 
 libedi_la_SOURCES = \
-edi_path.c \
 edi_builder.c \
+edi_create.c \
+edi_path.c \
 edi.c
 libedi_la_LIBADD = @EFL_LIBS@ -lm
 libedi_la_LDFLAGS = -no-undefined @EFL_LTLIBRARY_FLAGS@
diff --git a/src/lib/edi_builder.c b/src/lib/edi_builder.c
index eebeedc..3e66687 100644
--- a/src/lib/edi_builder.c
+++ b/src/lib/edi_builder.c
@@ -3,7 +3,6 @@
 #endif
 
 #include "Edi.h"
-#include "edi_builder.h"
 
 #include "edi_private.h"
 
diff --git a/src/lib/edi_create.c b/src/lib/edi_create.c
new file mode 100644
index 0000000..406e692
--- /dev/null
+++ b/src/lib/edi_create.c
@@ -0,0 +1,57 @@
+#ifdef HAVE_CONFIG
+# include "config.h"
+#endif
+
+#include <stdlib.h>
+#include <sys/wait.h>
+
+#include "Edi.h"
+
+#include "edi_private.h"
+
+static Eina_Bool
+_edi_create_project_done(void *data, int type EINA_UNUSED, void *event 
EINA_UNUSED)
+{
+   Edi_Create *create;
+
+   create = (Edi_Create *)data;
+
+   ecore_event_handler_del(create->handler); 
+   create->callback(create->path, EINA_TRUE);
+   free(create->path);
+   free(data);
+
+   return ECORE_CALLBACK_DONE; // or ECORE_CALLBACK_PASS_ON
+}
+
+EAPI void
+edi_create_project(const char *path, const char *name, const char *url,
+                   const char *user, const char *email, Edi_Create_Cb func)
+{
+   char script[PATH_MAX], fullpath[PATH_MAX];
+   char *cmd;
+   int cmdlen;
+   Edi_Create *data;
+   Ecore_Event_Handler *handler;
+
+   data = calloc(1, sizeof(Edi_Create));
+   handler = ecore_event_handler_add(ECORE_EXE_EVENT_DEL, 
_edi_create_project_done, data); 
+   snprintf(script, sizeof(script), "%s/skeleton/eflprj", 
elm_app_data_dir_get()
+);
+   snprintf(fullpath, sizeof(fullpath), "%s/%s", path, name);
+
+   data->path = strdup(fullpath);
+   data->callback = func;
+   data->handler = handler;
+
+   cmdlen = strlen(script) + 19 + strlen(path) + strlen(name) + strlen(url) + 
strlen(user) + strlen(email);
+   cmd = malloc(sizeof(char) * cmdlen);
+   snprintf(cmd, cmdlen, "%s \"%s\" \"%s\" \"%s\" \"%s\" \"%s\"",
+            script, fullpath, name, user, email, url);
+
+   INF("Creating project \"%s\" at path %s for %s<%s>\n", name, fullpath, 
user, email);
+   ecore_exe_run(cmd, data);
+   free(cmd);
+}
+
+
diff --git a/src/lib/edi_create.h b/src/lib/edi_create.h
new file mode 100644
index 0000000..80c3eee
--- /dev/null
+++ b/src/lib/edi_create.h
@@ -0,0 +1,52 @@
+#ifndef EDI_CREATE_H_
+# define EDI_CREATE_H_
+
+#include <Elementary.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @file
+ * @brief These routines are used for creating new projects.
+ */
+
+typedef void (*Edi_Create_Cb)(const char *path, Eina_Bool success);
+
+typedef struct _Edi_Create
+{
+   char *path;
+
+   Edi_Create_Cb callback;
+   Ecore_Event_Handler *handler;
+} Edi_Create;
+
+/**
+ * @brief Main builder management
+ * @defgroup Creation
+ *
+ * @{
+ *
+ * Functions of project creation from skeletons.
+ *
+ */
+
+/**
+ * Create a new standard EFL project.
+ *
+ * @ingroup Creation
+ */
+EAPI void
+edi_create_project(const char *path, const char *name, const char *url,        
 
+                   const char *user, const char *email, Edi_Create_Cb func);
+
+/**
+ * @}
+ */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* EDI_CREATE_H_ */

-- 


Reply via email to