Gui deselect menu items if necessary
[qi-bootmenu.git] / qi-bootmenu.c
blob68a3c2e4a881db8e31671edb8d650c04854519fd
1 /*
2 * qi-bootmenu - A kexec based bootloader with an elementary based GUI
4 * Copyright (c) 2009-2010 Marc Andre Tanner <mat@brain-dump.org>
6 * qi-bootmenu shares the basic idea with kexecboot which is written by:
8 * Copyright (c) 2008-2009 Yuri Bushmelev <jay4mail@gmail.com>
9 * Copyright (c) 2008 Thomas Kunze <thommycheck@gmx.de>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2, or (at your option)
14 * any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
23 #include <stdbool.h>
24 #include <stdio.h>
25 #include <string.h>
26 #include <Eina.h>
27 #include <Evas.h>
28 #include <Ecore.h>
29 #include <Ecore_Evas.h>
31 #define countof(arr) (sizeof(arr) / sizeof((arr)[0]))
32 #define sstrlen(str) (sizeof(str) - 1)
34 static void eprint(const char *errstr, ...);
36 #ifdef NDEBUG
37 #define debug(format, args...)
38 #else
39 #define debug eprint
40 #endif
42 #define RGB(r, g, b) r,g,b
44 typedef struct {
45 const char *fs;
46 const char *dev;
47 const char *kernel;
48 const char *cmdline;
49 const char *logo;
50 } BootItem;
52 typedef struct {
53 const char *text;
54 const char *logo;
55 void(*callback)(void*, Evas*, Evas_Object*, void *);
56 void *data;
57 } MenuItem;
59 /* menu actions */
60 static void boot_nand(void *data, Evas *evas, Evas_Object *obj, void *event);
61 static void poweroff(void *data, Evas *evas, Evas_Object *obj, void *event);
63 /* drawing related stuff */
64 static Ecore_Evas *ee;
65 static Evas *evas;
67 typedef struct {
68 char option;
69 void(*show)(Eina_List *systems);
70 void(*select)(Evas_Object *item);
71 void(*deselect)(Evas_Object *item);
72 void(*error)(const char *errstr, va_list ap);
73 } Gui;
75 /* functions available to gui modules */
76 static void gui_bootitem_clicked(void *data, Evas *evas, Evas_Object *item, void *event);
77 static void gui_show_error(const char *errstr, ...);
79 #include "config.h"
81 /* will be used to search the kernel as in {u,z}Image-$MACHINE.bin */
82 static const char *machine = DEFAULT_MACHINE;
84 /* if no option is passed in then use the first entry */
85 static Gui *gui = &guis[0];
87 #include "kexec.c"
88 #include "gui.c"
90 static void eprint(const char *errstr, ...) {
91 va_list ap;
92 va_start(ap, errstr);
93 vfprintf(stderr, errstr, ap);
94 va_end(ap);
97 static void usage() {
98 eprint("usage: qi-bootmenu [-d] [-m ...] [-i ...]\n");
99 exit(1);
102 int main(int argc, char **argv) {
104 Eina_List *dev_ignore = NULL; /* partitions to ignore */
105 bool diag = false;
106 int arg;
107 unsigned int g;
109 if (!eina_init())
110 return 1;
112 for (arg = 1; arg < argc; arg++) {
113 if (argv[arg][0] != '-')
114 usage();
116 switch (argv[arg][1]) {
117 case 'd':
118 diag = true;
119 break;
120 case 'm':
121 if (arg + 1 >= argc)
122 usage();
123 machine = argv[++arg];
124 break;
125 case 'i':
126 if (arg + 1 >= argc)
127 usage();
128 dev_ignore = eina_list_append(dev_ignore, argv[++arg]);
129 break;
130 default:
131 for (g = 0; g < countof(guis); g++) {
132 if (argv[arg][1] == guis[g].option)
133 gui = &guis[g];
135 break;
139 if (diag) {
140 gui->error = NULL;
141 diagnostics(dev_ignore);
142 return 0;
145 if (!gui_init()) {
146 eprint("Couldn't init GUI\n");
147 return 1;
150 /* search for system images to boot and display them */
151 gui->show(scan_system(dev_ignore));
153 debug("entering main loop\n");
155 ecore_main_loop_begin();
157 return 0;