/*============================================================================* * Global * *============================================================================*/ Efl_Egueb_IO_Request * efl_egueb_io_request_new(Egueb_Dom_String *location, const Efl_Egueb_IO_Request_Descriptor *descriptor, void *data) { Efl_Egueb_IO_Request *thiz; const char *filename; if (!location) return NULL; filename = egueb_dom_string_chars_get(location); thiz = calloc(1, sizeof(Efl_Egueb_IO_Request)); thiz->descriptor = descriptor; thiz->data = data; if (!strncmp(filename, "file://", 7)) { Enesim_Stream *s; s = enesim_stream_file_new(filename + 7, "r"); if (s) { DBG("Data '%s' loaded correctly", filename); thiz->in_event = EINA_TRUE; if (thiz->descriptor->completion) thiz->descriptor->completion(thiz, s); enesim_stream_unref(s); thiz->in_event = EINA_FALSE; } } else if (!strncmp(filename, "http://", 7)) { thiz->conn = ecore_con_url_new(filename); thiz->binbuf = eina_binbuf_new(); ecore_event_handler_add(ECORE_CON_EVENT_URL_COMPLETE, _efl_egueb_io_request_url_completion_cb, thiz); ecore_event_handler_add(ECORE_CON_EVENT_URL_DATA, _efl_egueb_io_request_url_data_cb, thiz); ecore_con_url_get(thiz->conn); } else { WRN("Unsupported schema '%s'", filename); free(thiz); thiz = NULL; goto done; } if (thiz->destroy) { efl_egueb_io_request_free(thiz); return NULL; } done: return thiz; }
static Eina_Bool _file_load_data_get(const char *file, Enesim_Stream **data, const char **mime) { Enesim_Stream *d; const char *m; d = enesim_stream_file_new(file, "rb"); if (!d) return EINA_FALSE; m = enesim_image_mime_data_from(d); if (!m) { enesim_stream_unref(d); return EINA_FALSE; } enesim_stream_reset(d); *mime = m; *data = d; return EINA_TRUE; }
static Eina_Bool _file_save_data_get(const char *file, Enesim_Stream **data, const char **mime) { Enesim_Stream *d; const char *m; const char *ext; ext = _enesim_image_file_get_extension(file); if (!ext) return EINA_FALSE; d = enesim_stream_file_new(file, "wb"); if (!d) return EINA_FALSE; m = enesim_image_mime_extension_from(ext); if (!m) { enesim_stream_unref(d); return EINA_FALSE; } *mime = m; *data = d; return EINA_TRUE; }
int main (int argc, char *argv[]) { GtkWidget *window; GtkWidget *w; Enesim_Stream *s; Egueb_Dom_Node *doc = NULL; gegueb_init(); s = enesim_stream_file_new(argv[1], "rb"); if (!s) { printf("Failed to read file %s\n", argv[1]); return -1; } egueb_dom_parser_parse(s, &doc); if (!doc) { printf("Failed to parse file %s\n", argv[1]); return -1; } gtk_init(&argc, &argv); window = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_window_set_title(GTK_WINDOW(window), "Gegueb Viewer"); g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(destroy), NULL); w = gegueb_widget_new(); g_object_set(w, "document", doc, NULL); gtk_container_add(GTK_CONTAINER (window), w); gtk_widget_show(w); gtk_widget_show(window); gtk_main (); return 0; }
int main(int argc, char *argv[]) { Efl_Egueb_Window_Viewer thiz; Egueb_Dom_Window *w; Egueb_Dom_Node *doc = NULL; Egueb_Dom_Event_Target *et; Enesim_Stream *s; Eina_Bool free_file = EINA_FALSE; char *short_options = "hw:e:"; struct option long_options[] = { { "help", 1, 0, 'h' }, { "width", 1, 0, 'w' }, { "height", 1, 0, 'e' }, }; int option; int ret; char *filename; int width; int height; int fps; struct stat st; /* default options */ width = -1; height = -1; fps = 30; if (!efl_egueb_init()) goto efl_egueb_failed; while ((ret = getopt_long(argc, argv, short_options, long_options, &option)) != -1) { switch (ret) { case 'h': help(argv[0]); return 0; case 'w': width = atoi(optarg); break; case 'e': height = atoi(optarg); break; default: break; } } if (argc - 1 != optind) { help(argv[0]); return 0; } filename = argv[optind]; if (stat(filename, &st) < 0) { printf("No SVG files found\n"); help(argv[0]); goto done; } /* sanitize the filename */ if (*filename != '.' && *filename != '/') { char wd[PATH_MAX]; if (!getcwd(wd, PATH_MAX)) goto done; if (asprintf(&filename, "%s/%s", wd, filename) < 0) goto done; free_file = EINA_TRUE; } s = enesim_stream_file_new(filename, "rb"); if (!s) { printf("Failed to read file %s\n", filename); help(argv[0]); goto read_error; } egueb_dom_parser_parse(s, &doc); thiz.file = filename; thiz.width = width; thiz.height = height; w = efl_egueb_window_auto_new(doc, 0, 0, width, height); if (!w) goto shutdown_efl_egueb; et = EGUEB_DOM_EVENT_TARGET(w); egueb_dom_event_target_event_listener_add(et, EGUEB_DOM_EVENT_WINDOW_CLOSE, _efl_egueb_window_close_cb, EINA_TRUE, NULL); ecore_main_loop_begin(); egueb_dom_window_unref(w); efl_egueb_shutdown(); return 0; shutdown_efl_egueb: efl_egueb_shutdown(); efl_egueb_failed: read_error: if (free_file) free(filename); done: return -1; }
int main(int argc, char **argv) { Egueb_Dom_Node *mydocument; Egueb_Dom_Node *root = NULL; Egueb_Dom_Node *clone = NULL; Egueb_Dom_Node *node = NULL; Egueb_Dom_Node *new_node; Enesim_Stream *im; if (argc < 2) help(); mylib_init(); mydocument = mydocument_new(); im = enesim_stream_file_new(argv[1], "r+"); egueb_dom_parser_parse(im, &mydocument); root = egueb_dom_document_document_element_get(mydocument); /* check the tree that we have parsed */ printf("[testing] original tree\n"); myelement_dump(root, EINA_TRUE); /* clone the root element deeply */ printf("[testing] Cloned tree\n"); clone = egueb_dom_node_clone(root, EINA_TRUE, EINA_TRUE, NULL); myelement_dump(clone, EINA_TRUE); /* given that the clone is live, modify the root element * and check if the cloned element has the same value */ printf("[testing] Modifying the original node\n"); myelement_prop1_set(root, egueb_dom_string_new_with_chars("modifying")); /* check the new state */ printf("[testing] Cloned tree\n"); myelement_dump(clone, EINA_TRUE); /* remove the last node from the original tree */ printf("[testing] Removing the last node from the original tree\n"); node = egueb_dom_node_child_last_get(root); egueb_dom_node_child_remove(root, node, NULL); myelement_dump(clone, EINA_TRUE); /* append the node again */ printf("[testing] Adding the last node from the original tree\n"); egueb_dom_node_child_append(root, egueb_dom_node_ref(node), NULL); myelement_dump(clone, EINA_TRUE); printf("[testing] Adding the previois las node before the current last node in the original tree\n"); new_node = myelement_new(); myelement_prop1_set(new_node, egueb_dom_string_new_with_chars("new node")); egueb_dom_node_insert_before(root, new_node, node, NULL); egueb_dom_node_unref(node); myelement_dump(clone, EINA_TRUE); myelement_dump(root, EINA_TRUE); /* destroy the clone */ printf("[testing] Destroy the clone tree\n"); egueb_dom_node_unref(clone); /* destroy the root and the document */ printf("[testing] Modifying the original node after the clone deletion\n"); myelement_prop1_set(root, egueb_dom_string_new_with_chars("modifying")); egueb_dom_node_unref(root); printf("[testing] Destroy the original tree %d\n", egueb_dom_node_ref_get(root)); /* destroy the whole document */ egueb_dom_node_unref(mydocument); mylib_shutdown(); return 0; }