From: Enlightenment C. <no...@cv...> - 2007-11-23 02:26:03
|
Enlightenment CVS committal Author : davemds Project : e17 Module : proto/edje_editor Dir : e17/proto/edje_editor/src/bin Modified Files: inout.c inout.h Log Message: * More work on load/save routines Still waiting to the etk_textview2 ... hisham: have you got some news about it? I have tried the view2, seems good for displaying output, the only thing I haven't found is the scrolling ability... * Some formatting =================================================================== RCS file: /cvs/e/e17/proto/edje_editor/src/bin/inout.c,v retrieving revision 1.6 retrieving revision 1.7 diff -u -3 -r1.6 -r1.7 --- inout.c 22 Nov 2007 21:28:49 -0000 1.6 +++ inout.c 23 Nov 2007 02:26:00 -0000 1.7 @@ -6,7 +6,6 @@ #include "main.h" #include "inout.h" - #define MAIN_EDC_NAME "edje_editor_link.edc" Etk_Widget *Load_TextView; @@ -16,12 +15,11 @@ Etk_Widget *Save_TextView; Ecore_Timer *progress_bar_timer; - -void +void etk_textview_append(Etk_Widget *tv, char *str) { Etk_Textblock_Iter *iter; - if (!tv) return; + if (!tv || !str) return; iter = etk_text_view_cursor_get (ETK_TEXT_VIEW(tv)); etk_textblock_insert_markup(ETK_TEXT_VIEW(tv)->textblock, iter, str, strlen(str)); @@ -39,37 +37,40 @@ Load_Win = etk_window_new(); etk_widget_size_request_set(Load_Win, 400, 300); etk_window_title_set(ETK_WINDOW(Load_Win), "Loading..."); - etk_signal_connect("destroyed", ETK_OBJECT(Load_Win), ETK_CALLBACK(etk_main_quit), NULL); - + etk_signal_connect("destroyed", ETK_OBJECT(Load_Win), + ETK_CALLBACK(etk_main_quit), NULL); + vbox = etk_vbox_new(ETK_FALSE, 0); etk_container_add(ETK_CONTAINER(Load_Win), vbox); label = etk_label_new("<font_size=20><b>Loading file</b></>"); etk_object_properties_set (ETK_OBJECT(label), "xalign",0.5,NULL); etk_box_append(ETK_BOX(vbox), label, ETK_BOX_START, ETK_BOX_NONE, 5); - + //Progress bar Load_ProgBar = etk_progress_bar_new_with_text("Working..."); etk_progress_bar_pulse_step_set(ETK_PROGRESS_BAR(Load_ProgBar), 0.03); etk_box_append(ETK_BOX(vbox), Load_ProgBar, ETK_BOX_START, ETK_BOX_NONE, 5); - + //Text_view Load_TextView = etk_text_view_new (); - //etk_textblock_object_cursor_visible_set(ETK_TEXT_VIEW(LS_TextView)->textblock, ETK_FALSE); //TODO questa riga non funziona scrolled_view = etk_scrolled_view_new(); - etk_scrolled_view_policy_set(ETK_SCROLLED_VIEW(scrolled_view), ETK_POLICY_HIDE, ETK_POLICY_SHOW); + etk_scrolled_view_policy_set(ETK_SCROLLED_VIEW(scrolled_view), + ETK_POLICY_HIDE, ETK_POLICY_SHOW); etk_bin_child_set( ETK_BIN(scrolled_view), Load_TextView); - etk_box_append(ETK_BOX(vbox), scrolled_view, ETK_BOX_START, ETK_BOX_EXPAND_FILL, 5); - + etk_box_append(ETK_BOX(vbox), scrolled_view, + ETK_BOX_START, ETK_BOX_EXPAND_FILL, 5); + //buttons button = etk_button_new_from_stock(ETK_STOCK_DIALOG_CLOSE); etk_box_append(ETK_BOX(vbox), button, ETK_BOX_START, ETK_BOX_NONE, 5); - etk_signal_connect("clicked", ETK_OBJECT(button), ETK_CALLBACK(etk_main_quit), NULL); - + etk_signal_connect("clicked", ETK_OBJECT(button), + ETK_CALLBACK(etk_main_quit), NULL); + etk_widget_show_all(Load_Win); } -void +void create_save_window() { Etk_Widget *Save_Win; @@ -77,37 +78,38 @@ Etk_Widget *scrolled_view; Etk_Widget *button; Etk_Widget *label; - + //Save Win Save_Win = etk_window_new(); etk_widget_size_request_set(Save_Win, 400, 300); etk_window_title_set(ETK_WINDOW(Save_Win), "Saving..."); - //etk_signal_connect("delete_event_signal", ETK_OBJECT(Save_Win), ETK_CALLBACK(NULL), NULL); - + vbox = etk_vbox_new(ETK_FALSE, 0); etk_container_add(ETK_CONTAINER(Save_Win), vbox); - + label = etk_label_new("<font_size=20><b>Saving file</b></>"); etk_object_properties_set (ETK_OBJECT(label), "xalign",0.5,NULL); etk_box_append(ETK_BOX(vbox), label, ETK_BOX_START, ETK_BOX_NONE, 5); - + //Progress bar Save_ProgBar = etk_progress_bar_new_with_text("Working..."); etk_progress_bar_pulse_step_set(ETK_PROGRESS_BAR(Save_ProgBar), 0.03); etk_box_append(ETK_BOX(vbox), Save_ProgBar, ETK_BOX_START, ETK_BOX_NONE, 5); - + //Text_view Save_TextView = etk_text_view_new (); - //etk_textblock_object_cursor_visible_set(ETK_TEXT_VIEW(LS_TextView)->textblock, ETK_FALSE); //TODO questa riga non funziona scrolled_view = etk_scrolled_view_new(); - etk_scrolled_view_policy_set(ETK_SCROLLED_VIEW(scrolled_view), ETK_POLICY_HIDE, ETK_POLICY_SHOW); + etk_scrolled_view_policy_set(ETK_SCROLLED_VIEW(scrolled_view), + ETK_POLICY_HIDE, ETK_POLICY_SHOW); etk_bin_child_set( ETK_BIN(scrolled_view), Save_TextView); - etk_box_append(ETK_BOX(vbox), scrolled_view, ETK_BOX_START, ETK_BOX_EXPAND_FILL, 5); - + etk_box_append(ETK_BOX(vbox), scrolled_view, + ETK_BOX_START, ETK_BOX_EXPAND_FILL, 5); + //buttons button = etk_button_new_from_stock(ETK_STOCK_DIALOG_CLOSE); etk_box_append(ETK_BOX(vbox), button, ETK_BOX_START, ETK_BOX_NONE, 5); - etk_signal_connect_swapped("clicked", ETK_OBJECT(button), ETK_CALLBACK(etk_widget_hide), Save_Win); + etk_signal_connect_swapped("clicked", ETK_OBJECT(button), + ETK_CALLBACK(etk_widget_hide), Save_Win); etk_widget_show_all(Save_Win); } @@ -118,9 +120,9 @@ char bkname[4096]; if (!ecore_file_exists(file_name)) return 0; - + snprintf(bkname,4095,"%s.bkp",file_name); - + if (ecore_file_cp(file_name,bkname)) return TRUE; else @@ -136,24 +138,25 @@ char cmd[2048]; int fd = 0; const char *imgdir, *fontdir; - + create_save_window(); - + //Start progress_bar - progress_bar_timer = - ecore_timer_add(0.025, (int(*)(void *data))etk_progress_bar_pulse, Save_ProgBar); - + progress_bar_timer = ecore_timer_add(0.025, + (int(*)(void *data))etk_progress_bar_pulse, Save_ProgBar); + //backup existing file backup_file(file_name); - + //Create tmp file strcpy(tmpn, "/tmp/edje_editor_tmp.edc-XXXXXX"); fd = mkstemp(tmpn); if (fd < 0) { - snprintf(buf,4096,"<font color=#FF0000><b>Can't create temp file:</b> %s\n<b>Error:</b> %s</font>\n",tmpn,strerror(errno)); + snprintf(buf,4096,"<font color=#FF0000><b>Can't create temp file:</b> %s\n<b>Error:</b> %s</font>\n", + tmpn,strerror(errno)); etk_textview_append(Save_TextView,buf); - stop_bar(Save_ProgBar); + stop_bar(Save_ProgBar,"Error"); return 0; } close(fd); @@ -166,7 +169,8 @@ //Get image and font directory imgdir = engrave_file_image_dir_get(Cur.ef); fontdir = engrave_file_font_dir_get(Cur.ef); - snprintf(buf,4096,"<b>Image dir:</b> %s\n<b>Font dir:</b> %s\n",imgdir,fontdir); + snprintf(buf,4096,"<b>Image dir:</b> %s\n<b>Font dir:</b> %s\n", + imgdir,fontdir); etk_textview_append(Save_TextView,buf); if (imgdir) snprintf(ipart, sizeof(ipart), "-id %s", imgdir); @@ -176,18 +180,21 @@ else fpart[0] = '\0'; //Create edje_cc command line - snprintf(cmd, sizeof(cmd), "edje_cc -v %s %s %s \"%s\"", - ipart, fpart, tmpn, file_name); + snprintf(cmd, sizeof(cmd), "edje_cc -v %s %s %s \"%s\"", + ipart, fpart, tmpn, file_name); snprintf(buf,4096,"<b>Executing: </b>%s\n",cmd); etk_textview_append(Save_TextView, buf); - + //Execute edje_cc through a pipe Ecore_Exe* exe; - ecore_event_handler_add(ECORE_EXE_EVENT_DATA, exe_data, Save_TextView); - ecore_event_handler_add(ECORE_EXE_EVENT_DEL, exe_exit, Save_TextView); + ecore_event_handler_add(ECORE_EXE_EVENT_DATA, pipe_data, Save_TextView); + ecore_event_handler_add(ECORE_EXE_EVENT_ERROR, pipe_data, Save_TextView); + ecore_event_handler_add(ECORE_EXE_EVENT_DEL, save_pipe_exit, Save_TextView); exe = ecore_exe_pipe_run(cmd, - ECORE_EXE_PIPE_READ | ECORE_EXE_PIPE_READ_LINE_BUFFERED,(void*)SAVE_WIN); - + ECORE_EXE_PIPE_READ | ECORE_EXE_PIPE_READ_LINE_BUFFERED | + ECORE_EXE_PIPE_ERROR | ECORE_EXE_PIPE_ERROR_LINE_BUFFERED, + (void*)SAVE_WIN); + return 1; //1 means success } @@ -195,14 +202,14 @@ LoadEDJ(char *file) { create_load_window(); - + ecore_timer_add(0.1,Decompile,file); - + etk_main(); etk_widget_hide(Load_Win); } -int Decompile(void *data) //data is the name of the file to open +int Decompile(void *data)//data is the name of the file to open { char *file = (char*)data; char buf[4096]; @@ -212,8 +219,9 @@ char *ptr; char *work_dir = NULL; - progress_bar_timer = - ecore_timer_add(0.025, (int(*)(void *data))etk_progress_bar_pulse, Load_ProgBar); + progress_bar_timer = ecore_timer_add(0.025, + (int(*)(void *data))etk_progress_bar_pulse, + Load_ProgBar); //TODO Check source integrity (is an edje file?) Cur.open_file_name = strdup(file); @@ -227,24 +235,27 @@ if (mkdtemp(tmpn) == NULL) #endif { - snprintf(buf,4096,"<font color=#FF0000><b>Can't create working dir:</b> %s\n<b>Error:</b> %s</font>\n",tmpn,strerror(errno)); + snprintf(buf,4096,"<font color=#FF0000><b>Can't create working dir:</b> %s\n<b>Error:</b> %s</font>\n", + tmpn,strerror(errno)); etk_textview_append(Load_TextView,buf); - stop_bar(Load_ProgBar); + stop_bar(Load_ProgBar,"Error"); return 0; } work_dir = strdup(tmpn); - + //Change to the working dir snprintf(buf,4096,"<b>Change to working dir:</b> %s\n",work_dir); etk_textview_append(Load_TextView,buf); getcwd(tmpn, sizeof(tmpn)); - if (chdir(work_dir) == -1) { - snprintf(buf,4096,"<font color=#FF0000><b>Can't change to dir:</b> %s\n<b>Error: </b> %s</font>\n",work_dir,strerror(errno)); + if (chdir(work_dir) == -1) + { + snprintf(buf,4096,"<font color=#FF0000><b>Can't change to dir:</b> %s\n<b>Error: </b> %s</font>\n", + work_dir,strerror(errno)); etk_textview_append(Load_TextView, buf); - stop_bar(Load_ProgBar); + stop_bar(Load_ProgBar, "Error"); return 0; } - + //Calculate Cur.source_dir, image_dir, font_dir, main_source_file old_fname = strdup(file); ptr = strstr(old_fname, ".edj"); @@ -255,23 +266,26 @@ Cur.source_dir = strdup(buf); snprintf(buf,4096,"%s/"MAIN_EDC_NAME,Cur.source_dir); Cur.main_source_file = strdup(buf); - + //Execute edje_decc through a pipe snprintf(cmd, 4096, "edje_decc \"%s\" -main-out "MAIN_EDC_NAME, file); snprintf(buf,4096,"<b>Executing: </b>%s\n",cmd); etk_textview_append(Load_TextView, buf); - + Ecore_Exe* exe; - ecore_event_handler_add(ECORE_EXE_EVENT_DATA, exe_data, Load_TextView); - ecore_event_handler_add(ECORE_EXE_EVENT_DEL, exe_exit, NULL); + ecore_event_handler_add(ECORE_EXE_EVENT_DATA, pipe_data, Load_TextView); + ecore_event_handler_add(ECORE_EXE_EVENT_ERROR, pipe_data, Load_TextView); + ecore_event_handler_add(ECORE_EXE_EVENT_DEL, load_pipe_exit, NULL); exe = ecore_exe_pipe_run(cmd, - ECORE_EXE_PIPE_READ | ECORE_EXE_PIPE_READ_LINE_BUFFERED,(void*)LOAD_WIN); - + ECORE_EXE_PIPE_READ | ECORE_EXE_PIPE_READ_LINE_BUFFERED | + ECORE_EXE_PIPE_ERROR | ECORE_EXE_PIPE_ERROR_LINE_BUFFERED, + (void*)LOAD_WIN); + return 0; //Stop executing timer } -int -exe_data(void *data, int ev_type, void *ev) // Data is Load_TextView or Save_TextView +int +pipe_data(void *data, int ev_type, void *ev)//Data is Load_TextView or Save_TextView { Ecore_Exe_Event_Data *e; e = (Ecore_Exe_Event_Data *)ev; @@ -295,62 +309,86 @@ } //etk_textblock_object_yoffset_set(ETK_TEXT_VIEW(LS_TextView)->textblock, -200 ); } - return 1; } -int -exe_exit(void *data, int ev_type, void *ev) // Data is LOAD_WIN or SAVE_WIN +int +save_pipe_exit(void *data, int ev_type, void *ev)//Data is LOAD_WIN or SAVE_WIN { char buf[1024]; Ecore_Exe_Event_Del *e = (Ecore_Exe_Event_Del *)ev; - - if (e->exit_code){ - snprintf(buf,1024,"<font color=#FF0000><b>Error in edje_cc/decc, exit code: </b> %d</font>\n",e->exit_code); + + if (e->exit_code) + { + snprintf(buf,1024, + "<font color=#FF0000><b>Error in edje_cc, exit code: </b> %d</font>\n", + e->exit_code); + stop_bar(Save_ProgBar,"Error"); + } + else + { + snprintf(buf,1024, "<font color=#00AA00><b>Operation completed.</b>\n"); + stop_bar(Save_ProgBar, "Done !!"); + } + + etk_textview_append(Save_TextView,buf); + return 0; +} + +int +load_pipe_exit(void *data, int ev_type, void *ev)//Data is LOAD_WIN or SAVE_WIN +{ + char buf[4096]; + Ecore_Exe_Event_Del *e = (Ecore_Exe_Event_Del *)ev; + + if (e->exit_code) + { + snprintf(buf,sizeof(buf),"<font color=#FF0000><b>Error in edje_decc, exit code: </b> %d</font>\n", + e->exit_code); etk_textview_append(data,buf); - return 1; + stop_bar(Load_ProgBar, "Error"); } - - if (ecore_exe_data_get(e->exe) == (void*)LOAD_WIN) //if Load Win + else { - Cur.ef = engrave_load_edc(Cur.main_source_file, Cur.source_dir, Cur.source_dir); + Cur.ef = engrave_load_edc(Cur.main_source_file, + Cur.source_dir, Cur.source_dir); if (!Cur.ef) { - etk_textview_append(Load_TextView,"<font color=#FF0000><b>Error parsing edc file.</b>\n"); + //TODO catch the engrave error and display it. + etk_textview_append(Load_TextView,"<font color=#FF0000><b>Error parsing edc file. See terminal output for more information.</b></font>\n"); + stop_bar(Load_ProgBar, "Error"); } else { - - etk_textview_append(Load_TextView,"<font color=#00AA00><b>Operation completed.</b>\n"); + etk_textview_append(Load_TextView, + "<font color=#00AA00><b>Operation completed.</b>\n"); - snprintf(buf,1024,"<b>Main source file:</b> %s\n",Cur.main_source_file); + snprintf(buf,sizeof(buf),"<b>Main source file:</b> %s\n", + Cur.main_source_file); etk_textview_append(Load_TextView, buf); - snprintf(buf,1024,"<b>Source dir:</b> %s\n",Cur.source_dir); + snprintf(buf,sizeof(buf),"<b>Source dir:</b> %s\n",Cur.source_dir); etk_textview_append(Load_TextView, buf); - snprintf(buf,1024,"<b>Image dir:</b> %s\n",engrave_file_image_dir_get(Cur.ef)); + snprintf(buf,sizeof(buf),"<b>Image dir:</b> %s\n", + engrave_file_image_dir_get(Cur.ef)); etk_textview_append(Load_TextView, buf); - snprintf(buf,1024,"<b>Font dir:</b> %s</font>\n",engrave_file_font_dir_get(Cur.ef)); + snprintf(buf,sizeof(buf),"<b>Font dir:</b> %s</font>\n", + engrave_file_font_dir_get(Cur.ef)); etk_textview_append(Load_TextView, buf); + + stop_bar(Load_ProgBar, "Done !!"); } - stop_bar(Load_ProgBar); - } - else //SAVE_WIN - { - stop_bar(Save_ProgBar); - etk_textview_append(Save_TextView,"<font color=#00AA00><b>Operation completed.</b>\n"); } - //TODO Check engrave load success return 0; } void -stop_bar(Etk_Widget* pbar) +stop_bar(Etk_Widget* pbar, char *text) { ecore_timer_del(progress_bar_timer); - etk_progress_bar_text_set (ETK_PROGRESS_BAR(pbar), "Done!"); + etk_progress_bar_text_set (ETK_PROGRESS_BAR(pbar), text); etk_progress_bar_fraction_set (ETK_PROGRESS_BAR(pbar), 1.0); } =================================================================== RCS file: /cvs/e/e17/proto/edje_editor/src/bin/inout.h,v retrieving revision 1.2 retrieving revision 1.3 diff -u -3 -r1.2 -r1.3 --- inout.h 11 Aug 2007 19:33:15 -0000 1.2 +++ inout.h 23 Nov 2007 02:26:00 -0000 1.3 @@ -1,8 +1,9 @@ #include "main.h" -void LoadEDJ (char *file); -int SaveEDJ (char *file_name); -int Decompile (void *data); //data is the name of the file to open -int exe_data (void *data, int ev_type, void *ev); -int exe_exit (void *data, int ev_type, void *ev); -void stop_bar (Etk_Widget * pbar); +void LoadEDJ (char *file); +int SaveEDJ (char *file_name); +int Decompile (void *data); //data is the name of the file to open +int pipe_data (void *data, int ev_type, void *ev); +int load_pipe_exit (void *data, int ev_type, void *ev); +int save_pipe_exit (void *data, int ev_type, void *ev); +void stop_bar (Etk_Widget *pbar, char *text); |