legacy/experimental/ecdb/trunk/src/ecdb_gui.c

539 lines
16 KiB
C
Raw Normal View History

/* vim: set sw=3 ts=3 sts=3 expandtab: */
2008-06-06 03:02:27 +00:00
#include "ecdb.h"
2009-02-05 04:11:22 +00:00
static void ecdb_handle_typebuf(Evas_Object *gui, Ewl_Widget *fl);
static void ecdb_cb_welcome_page_buttons_clicked(void *data, Evas_Object *o,
2009-02-19 04:40:53 +00:00
const char *emission, const char *source);
2009-02-05 04:11:22 +00:00
static void ecdb_filelist_show(Ecdb_Page *page);
static void ecdb_welcome_page_hide_finished(void *data, Evas_Object *o,
const char *emission,
const char *source);
static void _page_del(void *data, Evas *e, Evas_Object *obj, void *ev);
static void _filelist_del(Ewl_Widget *w, void *ev_data, void *data);
2009-02-19 04:40:53 +00:00
static void ecdb_welcome_page_show_about(void *data, Evas_Object *o,
const char *emission, const char *source);
static void
ecdb_welcome_page_show_about(void *data __UNUSED__, Evas_Object *o __UNUSED__,
const char *emission __UNUSED__,
const char *source __UNUSED__)
{
ecdb_about_show();
}
static void
_filelist_del(Ewl_Widget *w, void *ev_data __UNUSED__, void *data __UNUSED__)
{
Ewl_Filelist_Filter *f;
f = ewl_filelist_filter_get(EWL_FILELIST(w));
if (f)
{
if (f->extension)
free(f->extension);
free(f);
}
}
static void
_page_del(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
void *ev __UNUSED__)
{
Ecdb_Page *page;
page = data;
if (!page)
return;
free(page);
}
2009-02-05 04:11:22 +00:00
/* XXX These need to be fixed when Ecdb_Page become the swallow,
* whereas it is the actual gui as well
*/
static void
2008-08-04 23:28:43 +00:00
ecdb_cb_enter(Ecore_Evas *ee)
{
2009-02-05 04:11:22 +00:00
edje_object_signal_emit(em->page->gui, "ecdb,window,enter", "ecdb");
2008-08-04 23:28:43 +00:00
}
static void
2008-08-04 23:28:43 +00:00
ecdb_cb_leave(Ecore_Evas *ee)
2008-06-06 03:02:27 +00:00
{
2009-02-05 04:11:22 +00:00
edje_object_signal_emit(em->page->gui, "ecdb,window,exit", "ecdb");
2008-06-06 03:02:27 +00:00
}
static void
2008-08-04 23:28:43 +00:00
ecdb_cb_resize(Ecore_Evas *ee)
{
2008-12-09 05:47:59 +00:00
int w, h;
ecore_evas_geometry_get(ee, NULL, NULL, &w, &h);
2009-02-05 04:11:22 +00:00
evas_object_resize(em->page->gui, w, h);
2008-08-04 23:28:43 +00:00
}
2008-08-06 23:09:30 +00:00
static void
2008-08-07 04:09:47 +00:00
_cb_filelist_mouse_down(void *data, Evas *e __UNUSED__, Evas_Object *eo,
2008-12-09 05:47:59 +00:00
void *ev_data __UNUSED__)
2008-08-06 23:09:30 +00:00
{
2009-02-05 04:11:22 +00:00
Ecdb_Page *page = data;
evas_object_focus_set(eo, 1);
2009-02-05 04:11:22 +00:00
edje_object_signal_emit(page->gui, "ecdb,filelist_overlay,deactivate",
"ecdb");
edje_object_part_text_set(page->gui, "filelist_overlay_text", NULL);
2008-08-07 04:09:47 +00:00
2008-08-06 23:09:30 +00:00
}
static void
2008-08-07 04:09:47 +00:00
_cb_filelist_key_down(void *data, Evas *e __UNUSED__,
2008-12-09 05:47:59 +00:00
Evas_Object *eo __UNUSED__, void *ev_data)
2008-08-06 23:09:30 +00:00
{
2008-12-09 05:47:59 +00:00
Evas_Event_Key_Down *ek = ev_data;
2009-02-05 04:11:22 +00:00
Ecdb_Page *page = data;
2008-12-09 05:47:59 +00:00
if (!strcmp(ek->key, "Escape"))
{
2009-02-05 04:11:22 +00:00
edje_object_signal_emit(page->gui, "ecdb,filelist_overlay,deactivate",
"ecdb");
edje_object_part_text_set(page->gui, "filelist_overlay_text", NULL);
2008-12-09 05:47:59 +00:00
}
else if (!strcmp(ek->key, "Return"))
{
2009-02-05 04:11:22 +00:00
ecdb_handle_typebuf(page->gui, evas_object_data_get(page->filelist,
"filelist"));
2008-12-09 05:47:59 +00:00
}
else if (!strcmp(ek->key, "BackSpace"))
{
int len;
const char *t;
char *text;
2009-02-05 04:11:22 +00:00
t = edje_object_part_text_get(page->gui, "filelist_overlay_text");
2008-12-09 05:47:59 +00:00
text = (t) ? (strdup(t)) : NULL;
if ((!text) || (!*text)) return;
len = strlen(text);
text = realloc(text, len);
text[len - 1] = '\0';
if (len == 1)
{
2009-02-05 04:11:22 +00:00
edje_object_signal_emit(page->gui, "ecdb,filelist_overlay,deactivate",
2008-12-09 05:47:59 +00:00
"ecdb");
}
2009-02-05 04:11:22 +00:00
edje_object_part_text_set(page->gui, "filelist_overlay_text", text);
2008-12-09 05:47:59 +00:00
FREE(text);
}
else
{
int len;
const char *t, *append;
char *text;
2009-02-05 04:11:22 +00:00
t = edje_object_part_text_get(page->gui, "filelist_overlay_text");
2008-12-09 05:47:59 +00:00
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
{
if (text)
free(text);
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)
{
2009-02-05 04:11:22 +00:00
edje_object_signal_emit(page->gui, "ecdb,filelist_overlay,activate",
"ecdb");
2008-12-09 05:47:59 +00:00
}
2009-02-05 04:11:22 +00:00
edje_object_part_text_set(page->gui, "filelist_overlay_text", text);
2008-12-09 05:47:59 +00:00
FREE(text);
}
2008-08-06 23:09:30 +00:00
}
2008-08-04 23:28:43 +00:00
int
ecdb_create_main_gui(void)
{
2008-12-09 05:47:59 +00:00
Evas_Coord mw, mh;
const char *scale, *engine;
2008-12-09 05:47:59 +00:00
engine = getenv("ECDB_ENGINE");
if (engine)
{
if (!strcmp(engine, "gl"))
em->main_win_ee = ecore_evas_gl_x11_new(0, 0, 0, 0, 255, 255);
else if (!strcmp(engine, "xr"))
em->main_win_ee = ecore_evas_xrender_x11_new(0, 0, 0, 0, 255, 255);
else if (!strcmp(engine, "x11"))
em->main_win_ee = ecore_evas_software_x11_new(0, 0, 0, 0, 255, 255);
}
else
{
em->main_win_ee = ecore_evas_software_x11_new(0, 0, 0, 0, 255, 255);
}
2008-12-09 05:47:59 +00:00
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_avoid_damage_set(em->main_win_ee, 1);
ecore_x_dnd_aware_set(ecore_evas_software_x11_window_get(em->main_win_ee),
1);
ecore_x_dnd_type_set(ecore_evas_software_x11_window_get(em->main_win_ee),
"*", 1);
ecore_evas_callback_delete_request_set(em->main_win_ee, ecdb_shutdown);
ecore_evas_callback_destroy_set(em->main_win_ee, ecdb_shutdown);
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);
/* Make this configurable at some point */
ecdb_set_main_theme(NULL);
scale = getenv("ECDB_SCALE");
em->scalef = (scale) ? atof(scale) : 1.0;
edje_scale_set(em->scalef);
2008-12-09 05:47:59 +00:00
2009-02-05 04:11:22 +00:00
em->page = calloc(1, sizeof(Ecdb_Page));
em->page->gui = edje_object_add(ecore_evas_get(em->main_win_ee));
edje_object_file_set(em->page->gui, em->theme_path, "ecdb/window");
2009-02-19 04:40:53 +00:00
edje_object_signal_callback_add(em->page->gui, "ecdb/about/show",
"ecdb", ecdb_welcome_page_show_about, NULL);
2009-02-05 04:11:22 +00:00
edje_object_size_min_get(em->page->gui, &mw, &mh);
2008-12-09 05:47:59 +00:00
if (mw <= 0) mw = 400;
if (mh <= 0) mh = 300;
mw = (int)((float)mw * em->scalef);
mh = (int)((float)mh * em->scalef);
2009-02-05 04:11:22 +00:00
evas_object_resize(em->page->gui, mw, mh);
2008-12-09 05:47:59 +00:00
ecore_evas_resize(em->main_win_ee, mw, mh);
ecore_evas_size_min_set(em->main_win_ee, mw, mh);
evas_object_event_callback_add(em->page->gui, EVAS_CALLBACK_DEL, _page_del,
em->page);
2009-02-05 04:11:22 +00:00
evas_object_move(em->page->gui, 0, 0);
evas_object_show(em->page->gui);
2008-12-09 05:47:59 +00:00
2009-02-05 04:11:22 +00:00
ecdb_welcome_page_show(em->page);
2008-12-09 05:47:59 +00:00
return TRUE;
2008-08-04 23:28:43 +00:00
}
2008-09-24 18:52:11 +00:00
/* This needs some work. Where should user themes go? */
2008-08-04 23:28:43 +00:00
void
ecdb_set_main_theme(const char *theme_name)
2008-08-04 23:28:43 +00:00
{
2008-12-09 05:47:59 +00:00
if (!theme_name)
{
snprintf(em->theme_path, PATH_MAX, "%s/%s", PACKAGE_DATA_DIR,
"themes/default.edj");
evas_font_path_append(ecore_evas_get(em->main_win_ee),
PACKAGE_DATA_DIR"/font");
}
2008-06-21 02:51:16 +00:00
}
void
2009-02-05 04:11:22 +00:00
ecdb_handle_typebuf(Evas_Object *gui, Ewl_Widget *fl)
{
2008-12-09 05:47:59 +00:00
Ewl_Filelist_Filter *filter;
const char *ext;
if (!(ext = edje_object_part_text_get(gui, "filelist_overlay_text")))
{
return;
}
/* Check for a 'cd' first */
if (!ecdb_match_keyword(ext, "cd", 2))
{
char *dir;
/* What to do about multi-word directories? */
dir = ecdb_strip_string(ext);
if (dir)
2008-12-09 05:47:59 +00:00
{
if (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
{
/* Try to concate it to our current directory */
char path[PATH_MAX];
snprintf(path, PATH_MAX, "%s/%s", ewl_filelist_directory_get
2008-12-09 05:47:59 +00:00
(EWL_FILELIST(fl)), dir);
if (ecore_file_exists(path))
{
ewl_filelist_directory_set(EWL_FILELIST(fl), path);
}
}
2008-12-09 05:47:59 +00:00
FREE(dir);
}
edje_object_signal_emit(gui, "ecdb,filelist_overlay,deactivate", "ecdb");
2008-12-09 05:47:59 +00:00
edje_object_part_text_set(gui, "filelist_overlay_text", NULL);
return;
}
else if (!ecdb_match_keyword(ext, "exit", 4))
{
/* This creates an ewl error... */
ecore_event_add(ECORE_EVENT_SIGNAL_EXIT, NULL, NULL, NULL);
return;
}
filter = ewl_filelist_filter_get(EWL_FILELIST(fl));
if (!filter)
{
filter = calloc(sizeof(Ewl_Filelist_Filter), 1);
}
else
2008-12-09 05:47:59 +00:00
{
if (filter->extension)
2008-12-09 05:47:59 +00:00
{
if (strcmp(filter->extension, ext))
{
FREE(filter->extension);
}
else
{
return;
}
2008-12-09 05:47:59 +00:00
}
}
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);
}
2008-09-19 16:24:47 +00:00
static void
ecdb_cb_welcome_page_buttons_clicked(void *data, Evas_Object *o,
2009-02-05 04:11:22 +00:00
const char *emission __UNUSED__,
const char *source)
{
2009-02-05 04:11:22 +00:00
Ecdb_Page *page = data;
2008-12-09 05:47:59 +00:00
if (!strcmp(source, "ecdb/burn_data"))
{
2009-02-05 04:11:22 +00:00
edje_object_signal_emit(o, "ecdb,welcome_page,hide", "ecdb");
ecdb_burn_data_page_show(page);
ecdb_filelist_show(page);
}
else if (!strcmp(source, "ecdb/erase"))
{
2009-02-05 04:11:22 +00:00
edje_object_signal_emit(o, "ecdb,welcome_page,hide", "ecdb");
ecdb_erase_page_show(page);
}
else if (!strcmp(source, "ecdb/burn_image"))
{
2009-02-05 04:11:22 +00:00
ecdb_filelist_show(page);
edje_object_signal_emit(o, "ecdb,welcome_page,hide", "ecdb");
ecdb_burn_image_page_show(page);
}
2009-02-05 04:11:22 +00:00
else if (o)
{
2009-02-05 04:11:22 +00:00
edje_object_signal_emit(page->gui, "ecdb,filelist,hide", "ecdb");
}
2008-12-09 05:47:59 +00:00
printf("Action: %s\n", source);
}
void
2009-02-05 04:11:22 +00:00
ecdb_welcome_page_show(Ecdb_Page *page)
{
2009-02-05 04:11:22 +00:00
if (!page->welcome)
2008-12-09 05:47:59 +00:00
{
Evas_Object *b;
2008-12-09 05:47:59 +00:00
Evas_Coord x, y, w, h;
2009-02-05 04:11:22 +00:00
page->welcome = edje_object_add(ecore_evas_get(em->main_win_ee));
edje_object_file_set(page->welcome, em->theme_path, "ecdb/welcome_page");
edje_object_part_geometry_get(page->gui, "active_area", &x, &y, &w, &h);
evas_object_move(page->welcome, x, y);
evas_object_resize(page->welcome, w, h);
edje_object_part_swallow(page->gui, "action_area", page->welcome);
edje_object_signal_callback_add(page->welcome, "mouse,clicked,1",
"ecdb/*", ecdb_cb_welcome_page_buttons_clicked, page);
edje_object_signal_callback_add(page->welcome, "hide,finished",
"welcome_page", ecdb_welcome_page_hide_finished,
page->gui);
evas_object_show(page->welcome);
2008-12-09 05:47:59 +00:00
int i;
char *labels[] = {"Burn Data CD", "Burn Audio CD", "Burn Image",
"Erase Re-writable Disc"};
char *ids[] = {"ecdb/burn_data", "ecdb/burn_audio", "ecdb/burn_image",
"ecdb/erase"};
for (i = 0; i < 4; i++)
{
2009-02-05 04:11:22 +00:00
b = ecdb_button_add(page->welcome, ids[i]);
ecdb_button_label_set(b, labels[i]);
evas_object_show(b);
ecdb_button_icon_set(b, ids[i]);
}
2008-12-09 05:47:59 +00:00
}
2009-02-05 04:11:22 +00:00
else if (edje_object_part_swallow_get(page->gui, "action_area") !=
page->welcome)
2008-12-09 05:47:59 +00:00
{
/* All that is needed here? */
2009-02-05 04:11:22 +00:00
edje_object_part_swallow(page->gui, "action_area", page->welcome);
evas_object_show(page->welcome);
2008-12-09 05:47:59 +00:00
}
2009-02-05 04:11:22 +00:00
edje_object_signal_emit(page->gui, "ecdb,welcome_page,show", "ecdb");
edje_object_signal_emit(page->welcome, "ecdb,welcome_page,show", "ecdb");
}
static void
2009-02-05 04:11:22 +00:00
ecdb_filelist_show(Ecdb_Page *page)
{
2009-02-05 04:11:22 +00:00
if (!page->filelist)
2008-12-09 05:47:59 +00:00
{
Evas_Coord x, y, w, h;
Ewl_Widget *embed, *filelist;
embed = ewl_embed_new();
ewl_object_fill_policy_set(EWL_OBJECT(embed), EWL_FLAG_FILL_ALL);
2009-02-05 04:11:22 +00:00
page->filelist = ewl_embed_canvas_set(EWL_EMBED(embed),
2008-12-09 05:47:59 +00:00
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_container_child_append(EWL_CONTAINER(embed), filelist);
ewl_callback_prepend(EWL_WIDGET(filelist), EWL_CALLBACK_DESTROY,
_filelist_del, NULL);
2008-12-09 05:47:59 +00:00
ewl_filelist_directory_set(EWL_FILELIST(filelist), getenv("HOME"));
ewl_widget_show(filelist);
2009-02-05 04:11:22 +00:00
edje_object_part_geometry_get(page->gui, "filelist", &x, &y, &w, &h);
evas_object_move(page->filelist, x, y);
evas_object_resize(page->filelist, w, h);
edje_object_part_swallow(page->gui, "filelist", page->filelist);
evas_object_event_callback_add(page->filelist, EVAS_CALLBACK_MOUSE_DOWN,
_cb_filelist_mouse_down, page);
evas_object_event_callback_add(page->filelist, EVAS_CALLBACK_KEY_DOWN,
_cb_filelist_key_down, page);
evas_object_data_set(page->filelist, "filelist", filelist);
evas_object_show(page->filelist);
2008-12-09 05:47:59 +00:00
}
/* Assume here that it is the active projects job to hide itself and
* call this show function
*/
2009-02-05 04:11:22 +00:00
else if (edje_object_part_swallow_get(page->gui, "filelist") !=
page->filelist)
2008-12-09 05:47:59 +00:00
{
/* Is this all that is neccessary? */
2009-02-05 04:11:22 +00:00
edje_object_part_swallow(page->gui, "filelist", page->filelist);
evas_object_show(page->filelist);
2008-12-09 05:47:59 +00:00
}
2009-02-05 04:11:22 +00:00
edje_object_signal_emit(page->gui, "ecdb,filelist,visible", "ecdb");
edje_object_signal_emit(page->filelist, "ecdb,filelist,visible", "ecdb");
2008-09-24 18:52:11 +00:00
}
/* Hurrah! Fancyness */
2009-02-05 04:11:22 +00:00
static void
ecdb_welcome_page_hide_finished(void *data, Evas_Object *o,
const char *emission __UNUSED__,
const char *source __UNUSED__)
2008-11-06 19:04:00 +00:00
{
2009-02-05 04:11:22 +00:00
Evas_Object *gui;
2008-12-09 05:47:59 +00:00
2009-02-05 04:11:22 +00:00
gui = data;
edje_object_part_unswallow(gui, o);
evas_object_hide(o);
2008-11-06 19:04:00 +00:00
}
void
ecdb_gui_combo_header_from_drive(Evas_Object *c, const char *name, void *data,
Evas_Object *obj, int sel)
{
Evas_Object *ret;
Ecdb_Drive_Info *drive;
ret = ecdb_label_add(c, name);
drive = eina_list_nth(em->drives, sel);
ecdb_label_text_set(ret, drive->product);
evas_object_show(ret);
}
void
ecdb_gui_combo_header_from_speeds(Evas_Object *c, const char *name, void *data,
Evas_Object *obj, int sel)
{
Evas_Object *ret;
Ecdb_Drive_Info *drive;
char buf[1024];
drive = data;
if (!drive)
return;
ret = ecdb_label_add(c, name);
snprintf(buf, sizeof(buf), "%d", ecdb_speed_convert(drive, sel));
ecdb_label_text_set(ret, buf);
evas_object_show(ret);
}