Move project creation to our Edi library.

Move to ecore_exe from fork/wait as it is more portable
This commit is contained in:
Andy Williams 2015-01-17 17:04:26 +00:00
parent f9ba2d3edf
commit 032d7e5963
6 changed files with 127 additions and 19 deletions

View File

@ -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;
@ -189,11 +186,23 @@ _edi_welcome_project_new_input_row_add(const char *text, const char *placeholder
_create_inputs[row] = input;
}
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

View File

@ -34,6 +34,7 @@
extern "C" {
#endif
#include <edi_create.h>
#include <edi_builder.h>
#include <edi_path.h>

View File

@ -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@

View File

@ -3,7 +3,6 @@
#endif
#include "Edi.h"
#include "edi_builder.h"
#include "edi_private.h"

57
src/lib/edi_create.c Normal file
View File

@ -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);
}

52
src/lib/edi_create.h Normal file
View File

@ -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_ */