#include "ecdb.h" static void ecdb_handle_typebuf(Evas_Object *gui); static void ecdb_cb_welcome_page(void *data, Evas_Object *o, const char *emission, const char *source); static void ecdb_cb_enter(Ecore_Evas *ee) { Evas_Object *gui; gui = evas_object_name_find(ecore_evas_get(ee), "gui"); edje_object_signal_emit(gui, "ecdb,window,enter", "ecdb"); } static void ecdb_cb_leave(Ecore_Evas *ee) { Evas_Object *gui; gui = evas_object_name_find(ecore_evas_get(ee), "gui"); edje_object_signal_emit(gui, "ecdb,window,exit", "ecdb"); } static void ecdb_cb_resize(Ecore_Evas *ee) { int w, h; Evas_Object *gui; ecore_evas_geometry_get(ee, NULL, NULL, &w, &h); gui = evas_object_name_find(ecore_evas_get(ee), "gui"); evas_object_resize(gui, w, h); } static void _cb_filelist_mouse_in(Ewl_Widget *w __UNUSED__, void *ev __UNUSED__, void *data) { Evas_Object *gui = data; edje_object_signal_emit(gui, "ecdb,filelist,in", "ecdb"); } static void _cb_filelist_mouse_out(Ewl_Widget *w __UNUSED__, void *ev __UNUSED__, void *data) { Evas_Object *gui = data; edje_object_signal_emit(gui, "ecdb,filelist,out", "ecdb"); } static void _cb_filelist_mouse_down(void *data, Evas *e __UNUSED__, Evas_Object *eo, void *ev_data __UNUSED__) { Evas_Object *gui = data; evas_object_focus_set(eo, TRUE); edje_object_signal_emit(gui, "ecdb,filelist_overlay,deactivate", "ecdb"); edje_object_part_text_set(gui, "filelist_overlay_text", NULL); } static void _cb_filelist_key_down(void *data, Evas *e __UNUSED__, Evas_Object *eo __UNUSED__, void *ev_data) { Evas_Event_Key_Down *ek = ev_data; Evas_Object *gui = data; if (!strcmp(ek->key, "Escape")) { edje_object_signal_emit(gui, "ecdb,filelist_overlay,deactivate", "ecdb"); edje_object_part_text_set(gui, "filelist_overlay_text", NULL); } else if (!strcmp(ek->key, "Return")) { ecdb_handle_typebuf(gui); } else if (!strcmp(ek->key, "BackSpace")) { int len; const char *t; char *text; t = edje_object_part_text_get(gui, "filelist_overlay_text"); text = (t) ? (strdup(t)) : NULL; if ((!text) || (!*text)) return; len = strlen(text); text = realloc(text, len); text[len - 1] = '\0'; if (len == 1) edje_object_signal_emit(gui, "ecdb,filelist_overlay,deactivate", "ecdb"); edje_object_part_text_set(gui, "filelist_overlay_text", text); FREE(text); } else { int len; const char *t, *append; char *text; t = edje_object_part_text_get(gui, "filelist_overlay_text"); text = (t) ? (strdup(t)) : NULL; if ((text) && (strlen(text) >= PATH_MAX)) return; if ((ek->string) && (*ek->string) && (!ek->string[1])) append = ek->string; else if ((ek->keyname) && (*ek->keyname) && (!ek->key[1])) append = ek->keyname; else return; if (!text) text = strdup(append); else { len = strlen(text) + 2; text = realloc(text, len); ecore_strlcat(text, append, len); } /* Avoid sending the same signal twice... seems to skip the * transition in that case */ if (strlen(text) == 1) edje_object_signal_emit(gui, "ecdb,filelist_overlay,activate", "ecdb"); edje_object_part_text_set(gui, "filelist_overlay_text", text); free(text); } } int ecdb_create_main_gui(void) { Evas_Object *gui, *swallow; Ewl_Widget *embed, *filelist; Evas_Coord x, y, w, h; em->main_win_ee = ecore_evas_software_x11_new(0, 0, 0, 0, 255, 255); if (!em->main_win_ee) { printf("Cannot create main window!\n"); return FALSE; } ecore_evas_title_set(em->main_win_ee, "ECDB"); ecore_evas_name_class_set(em->main_win_ee, "ECDB", "ECDB"); ecore_evas_callback_delete_request_set(em->main_win_ee, ecdb_shutdown); ecore_evas_callback_destroy_set(em->main_win_ee, ecdb_shutdown); ecore_event_handler_add(ECORE_EVENT_SIGNAL_EXIT, ecdb_shutdown, NULL); ecore_evas_callback_mouse_in_set(em->main_win_ee, ecdb_cb_enter); ecore_evas_callback_mouse_out_set(em->main_win_ee, ecdb_cb_leave); ecore_evas_callback_resize_set(em->main_win_ee, ecdb_cb_resize); edje_frametime_set(1.0 / 60.0); ecore_evas_show(em->main_win_ee); gui = edje_object_add(ecore_evas_get(em->main_win_ee)); evas_object_name_set(gui, "gui"); evas_object_move(gui, 0, 0); evas_object_show(gui); ecdb_set_main_theme(NULL, "ecdb/window"); /* Set up the filelist swallow */ embed = ewl_embed_new(); ewl_object_fill_policy_set(EWL_OBJECT(embed), EWL_FLAG_FILL_ALL); swallow = ewl_embed_canvas_set(EWL_EMBED(embed), ecore_evas_get(em->main_win_ee), (void *)(long) ecore_evas_software_x11_window_get (em->main_win_ee)); ewl_embed_focus_set(EWL_EMBED(embed), TRUE); ewl_widget_show(embed); filelist = ewl_filelist_new(); ewl_widget_name_set(EWL_WIDGET(filelist), "main_filelist"); ewl_container_child_append(EWL_CONTAINER(embed), filelist); ewl_filelist_directory_set(EWL_FILELIST(filelist), getenv("HOME")); ewl_callback_append(filelist, EWL_CALLBACK_MOUSE_IN, _cb_filelist_mouse_in, gui); ewl_callback_append(filelist, EWL_CALLBACK_MOUSE_OUT, _cb_filelist_mouse_out, gui); ewl_widget_show(filelist); edje_object_part_geometry_get(gui, "filelist", &x, &y, &w, &h); evas_object_move(swallow, x, y); evas_object_resize(swallow, x, y); edje_object_part_swallow(gui, "filelist", swallow); evas_object_event_callback_add(swallow, EVAS_CALLBACK_MOUSE_DOWN, _cb_filelist_mouse_down, gui); evas_object_event_callback_add(swallow, EVAS_CALLBACK_KEY_DOWN, _cb_filelist_key_down, gui); evas_object_show(swallow); // Set up the welcome page Evas_Object *welcome_page; welcome_page = edje_object_add(ecore_evas_get(em->main_win_ee)); evas_object_name_set(welcome_page, "welcome_page"); edje_object_file_set(welcome_page, em->theme_path, "ecdb/welcome_page"); edje_object_part_geometry_get(gui, "active_area", &x, &y, &w, &h); evas_object_move(welcome_page, x, y); evas_object_resize(welcome_page, w, h); edje_object_part_swallow(gui, "action_area", welcome_page); edje_object_signal_callback_add(welcome_page, "selected", "b*", ecdb_cb_welcome_page, NULL); evas_object_show(welcome_page); /* Buttons next, do properly next */ Evas_Object *b; int i; char *names[] = {"b1","b2","b3","b4"}; char *labels[] = {"Burn Data CD", "Burn Audio CD", "Copy Disc", "Erase Re-writable disc"}; char *icons[] = {"drive_optical.png", "audio.png", "iso.png", "clear.png"}; for (i = 0; i < 4; i++) { b = edje_object_add(ecore_evas_get(em->main_win_ee)); evas_object_name_set(b, names[i]); edje_object_file_set(b, em->theme_path, "ecdb/button"); edje_object_part_geometry_get(welcome_page, names[i], &x, &y, &w, &h); edje_object_part_text_set(b, "label", labels[i]); ecdb_button_icon_swallow(ecore_evas_get(em->main_win_ee), b, icons[i]); evas_object_move(b, x, y); evas_object_resize(b, w, h); edje_object_part_swallow(welcome_page, names[i], b); evas_object_show(b); } return TRUE; } int ecdb_create_data_tab(void) { printf("Creating data tab\n"); return TRUE; } void ecdb_set_main_theme(const char *theme_name, const char *group) { Evas_Coord mw, mh; Evas_Object *gui; gui = evas_object_name_find(ecore_evas_get(em->main_win_ee), "gui"); if ((!group) || (!gui)) { printf("Fail on group or object!\n"); return; } if (!theme_name) { snprintf(em->theme_path, PATH_MAX, "%s/%s", PACKAGE_DATA_DIR, "themes/default.edj"); if (!edje_object_file_set(gui, em->theme_path, group)) { printf("Error setting default theme: %s\n", em->theme_path); return; } evas_font_path_append(ecore_evas_get(em->main_win_ee), PACKAGE_DATA_DIR"/font"); } else if (!edje_object_file_set(gui, theme_name, group)) { printf("Error setting theme to: %s\n", theme_name); return; } edje_object_size_min_get(gui, &mw, &mh); if ((mw <= 0) && (mh <= 0)) { mw = 255; mh = 255; } evas_object_resize(gui, mw, mh); ecore_evas_resize(em->main_win_ee, mw, mh); ecore_evas_size_min_set(em->main_win_ee, mw, mh); } void ecdb_handle_typebuf(Evas_Object *gui) { Ewl_Widget *fl; Ewl_Filelist_Filter *filter; const char *ext; if (!(ext = edje_object_part_text_get(gui, "filelist_overlay_text"))) return; fl = ewl_widget_name_find("main_filelist"); /* Check for a 'cd' first */ if (!ecdb_match_keyword(ext, "cd", 2)) { char *dir; dir = ecdb_strip_next_argument(ext); if ((dir) && (dir[0] == '/')) { if (ecore_file_exists(dir)) ewl_filelist_directory_set(EWL_FILELIST(fl), dir); } else if (dir[0] == '~') { char path[PATH_MAX]; snprintf(path, PATH_MAX, "%s%s", getenv("HOME"), &dir[1]); if (ecore_file_exists(path)) ewl_filelist_directory_set(EWL_FILELIST(fl), path); } else if (dir) { /* Try to concate it to our current directory */ char path[PATH_MAX]; snprintf(path, PATH_MAX, "%s/%s", ewl_filelist_directory_get (EWL_FILELIST(fl)), dir); if (ecore_file_exists(path)) ewl_filelist_directory_set(EWL_FILELIST(fl), path); } if (dir) free(dir); edje_object_signal_emit(gui, "ecdb,filelist_overlay," "deactivate", "ecdb"); edje_object_part_text_set(gui, "filelist_overlay_text", NULL); return; } filter = ewl_filelist_filter_get(EWL_FILELIST(fl)); if (!filter) filter = calloc(sizeof(Ewl_Filelist_Filter), 1); if (filter->extension) { if (strcmp(filter->extension, ext)) { FREE(filter->extension); } else return; } filter->extension = strdup(ext); ewl_filelist_filter_set(EWL_FILELIST(fl), filter); ewl_filelist_refresh(EWL_FILELIST(fl)); edje_object_signal_emit(gui, "ecdb,filelist_overlay,deactivate", "ecdb"); edje_object_part_text_set(gui, "filelist_overlay_text", NULL); } static void ecdb_cb_welcome_page(void *data, Evas_Object *o, const char *emission, const char *source) { printf("callback from %s\n", source); printf("callback %s\n", emission); }