Fix activation of selected entry
[qi-bootmenu.git] / gui.c
1 static void gui_show_error(const char *errstr, ...) {
2 va_list ap;
3
4 va_start(ap, errstr);
5
6 if (gui->error)
7 gui->error(errstr, ap);
8
9 vfprintf(stderr, errstr, ap);
10 fprintf(stderr, "\n");
11 va_end(ap);
12 }
13
14 static void gui_item_clicked(void *data, Evas *evas, Evas_Object *item, void *event) {
15 MenuItem *menu = data;
16 if (gui->select) {
17 gui->select(item);
18 /* flush all changes of the whole canvas to the screen.
19 * normally this would be done once the event handler
20 * returns, however in our case this might never happen
21 * because the menu callback could kexec a kernel.
22 */
23 evas_render(evas);
24 }
25 menu->callback(menu->data);
26 if (gui->deselect)
27 gui->deselect(item);
28 }
29
30 static void poweroff(void *data) {
31 umount_all();
32 system("poweroff");
33 }
34
35 static void boot_nand(void *data) {
36 BootItem *nand = scan_partition((const char *)data);
37 if (!nand) {
38 gui_show_error("No kernel found in NAND Flash");
39 return;
40 }
41
42 boot_kernel(nand);
43 }
44
45 static void gui_bootitem_clicked(void *data) {
46 boot_kernel((BootItem*)data);
47 }
48
49 static bool gui_init(){
50 if (!ecore_init() || !ecore_evas_init())
51 return false;
52
53 /* XXX: fixed dimensions */
54 ee = ecore_evas_new(NULL, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, NULL);
55
56 if (!ee)
57 return false;
58
59 ecore_evas_title_set(ee, APPNAME);
60 ecore_evas_borderless_set(ee, 0);
61 ecore_evas_show(ee);
62
63 evas = ecore_evas_get(ee);
64 if (!evas)
65 return false;
66
67 evas_font_path_append(evas, FONT_PATH);
68
69 return true;
70 }