Add -i option to ignore certain partitions
[qi-bootmenu/guyou.git] / gui.c
blobca0907cf2d9c085680d9e8d4dba2d3ab6f677dea
1 #include <stdbool.h>
2 #include <Eina.h>
3 #include <Evas.h>
4 #include <Ecore.h>
5 #include <Ecore_Evas.h>
6 #include "config.h"
7 #include "kexec.h"
8 #include "util.h"
10 /* XXX: replace hardcoded values with runtime information */
11 #define SCREEN_WIDTH 480
12 #define SCREEN_HEIGHT 640
14 /* drawing related stuff */
15 static Ecore_Evas *ee;
16 static Evas *evas;
18 static void poweroff(void *data, Evas *evas, Evas_Object *obj, void *event);
19 static void bootitem_clicked(void *data, Evas *evas, Evas_Object *item, void *event);
21 typedef struct {
22 const char *text;
23 const char *logo;
24 void(*callback)(void*, Evas*, Evas_Object*, void *);
25 } MenuItem;
27 MenuItem menu[] = {
28 { "Power Off", POWEROFF_LOGO, poweroff },
31 #include "gui-list.c"
32 #include "gui-grid.c"
34 typedef struct {
35 char option;
36 void(*show)(Eina_List *systems);
37 void(*select)(Evas_Object *item);
38 } Gui;
40 Gui guis[] = {
41 { 'l', gui_list, gui_list_select_item },
42 { 'g', gui_grid, NULL },
45 /* if no option is passed in then use the first entry */
46 static Gui *gui = &guis[0];
48 static void poweroff(void *data, Evas *evas, Evas_Object *item, void *event) {
49 if (gui->select)
50 gui->select(item);
51 system("poweroff");
54 static void bootitem_clicked(void *data, Evas *evas, Evas_Object *item, void *event) {
55 if (gui->select)
56 gui->select(item);
57 boot_kernel((BootItem*)data);
58 /* XXX: shouldn't be reached, display an error message? */
61 static bool gui_init(){
62 if (!ecore_init() || !ecore_evas_init())
63 return false;
65 /* XXX: fixed dimensions */
66 ee = ecore_evas_new(NULL, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, NULL);
68 if (!ee)
69 return false;
71 ecore_evas_title_set(ee, APPNAME);
72 ecore_evas_borderless_set(ee, 0);
73 ecore_evas_show(ee);
75 evas = ecore_evas_get(ee);
76 if (!evas)
77 return false;
79 evas_font_path_append(evas, FONT_PATH);
81 return true;
84 int gui_show(int argc, char **argv, Eina_List *dev_ignore) {
86 int arg, g;
88 for (arg = 1; arg < argc; arg++) {
89 if (argv[arg][0] != '-')
90 continue;
91 for (g = 0; g < countof(guis); g++) {
92 if (argv[arg][1] == guis[g].option)
93 gui = &guis[g];
97 if (!gui_init()) {
98 eprint("Couldn't init GUI\n");
99 return 1;
102 /* search for system images to boot and display them */
103 gui->show(scan_system(dev_ignore));
105 ecore_main_loop_begin();
107 return 0;