X-Git-Url: http://git.ozlabs.org/?p=petitboot;a=blobdiff_plain;f=ui%2Fncurses%2Fps3-cui.c;h=f4c9841459547bc7abca4c897549fd349efb5305;hp=f166c8830cf54a748080e4205e853344c5940df1;hb=ea0a5877530a801713c80963c918c0a6f4072d8a;hpb=53aa807ae41e48fd71653c2d00083a44a8bca14c diff --git a/ui/ncurses/ps3-cui.c b/ui/ncurses/ps3-cui.c index f166c88..f4c9841 100644 --- a/ui/ncurses/ps3-cui.c +++ b/ui/ncurses/ps3-cui.c @@ -21,9 +21,7 @@ /* * TODO * removable media event - * resize after video mode change * ncurses mouse support - * timeout */ #if defined(HAVE_CONFIG_H) @@ -36,6 +34,7 @@ #include #include #include +#include #include "log/log.h" #include "talloc/talloc.h" @@ -53,7 +52,8 @@ static void print_usage(void) { print_version(); printf( -"Usage: pb-cui [-h, --help] [-l, --log log-file] [-V, --version]\n"); +"Usage: pb-cui [-h, --help] [-l, --log log-file] [-r, --reset-defaults]\n" +" [-t, --timeout] [-V, --version]\n"); } /** @@ -69,6 +69,8 @@ enum opt_value {opt_undef = 0, opt_yes, opt_no}; struct opts { enum opt_value show_help; const char *log_file; + enum opt_value reset_defaults; + enum opt_value use_timeout; enum opt_value show_version; }; @@ -79,12 +81,14 @@ struct opts { static int opts_parse(struct opts *opts, int argc, char *argv[]) { static const struct option long_options[] = { - {"help", no_argument, NULL, 'h'}, - {"log", required_argument, NULL, 'l'}, - {"version", no_argument, NULL, 'V'}, - { NULL, 0, NULL, 0}, + {"help", no_argument, NULL, 'h'}, + {"log", required_argument, NULL, 'l'}, + {"reset-defaults", no_argument, NULL, 'r'}, + {"timeout", no_argument, NULL, 't'}, + {"version", no_argument, NULL, 'V'}, + { NULL, 0, NULL, 0}, }; - static const char short_options[] = "hl:V"; + static const char short_options[] = "hl:trV"; static const struct opts default_values = { .log_file = "pb-cui.log", }; @@ -105,6 +109,12 @@ static int opts_parse(struct opts *opts, int argc, char *argv[]) case 'l': opts->log_file = optarg; break; + case 't': + opts->use_timeout = opt_yes; + break; + case 'r': + opts->reset_defaults = opt_yes; + break; case 'V': opts->show_version = opt_yes; break; @@ -114,7 +124,7 @@ static int opts_parse(struct opts *opts, int argc, char *argv[]) } } - return 0; + return optind != argc; } /** @@ -282,6 +292,21 @@ static int ps3_hot_key(struct pmenu __attribute__((unused)) *menu, return c; } +/** + * ps3_timer_update - Timer callback. + */ + +static void ps3_timer_update(struct ui_timer *timer, unsigned int timeout) +{ + struct ps3_cui *ps3 = ps3_from_cui(cui_from_timer(timer)); + + //FIXME: make scr:timer. + // nc_scr_timer_update(&ps3.mm->scr, timeout); + + nc_scr_status_printf(&ps3->mm->scr, + "Welcome to Petitboot (timeout %u sec)", timeout); +} + /** * ps3_mm_init - Setup the main menu instance. */ @@ -291,8 +316,7 @@ static struct pmenu *ps3_mm_init(struct ps3_cui *ps3_cui) int result; struct pmenu *m; struct pmenu_item *i; - static const char *const bgo[] = - {"/usr/sbin/ps3-boot-game-os-NOT", NULL}; + static const char *const bgo[] = {"/usr/sbin/ps3-boot-game-os", NULL}; m = pmenu_init(ps3_cui->cui, 3, cui_on_exit); @@ -302,7 +326,12 @@ static struct pmenu *ps3_mm_init(struct ps3_cui *ps3_cui) } m->hot_key = ps3_hot_key; +#if defined(DEBUG) + m->scr.frame.title = talloc_strdup(m, + "Petitboot PS3 (ver " PACKAGE_VERSION ")"); +#else m->scr.frame.title = talloc_strdup(m, "Petitboot PS3"); +#endif m->scr.frame.help = talloc_strdup(m, "ESC=exit, Enter=accept, E,e=edit"); m->scr.frame.status = talloc_strdup(m, "Welcome to Petitboot"); @@ -434,6 +463,10 @@ static void sig_handler(int signum) DBGS("%d\n", signum); switch (signum) { + case SIGALRM: + if (ps3.cui) + ui_timer_sigalrm(&ps3.cui->timer); + break; case SIGWINCH: if (ps3.cui) cui_resize(ps3.cui); @@ -491,8 +524,9 @@ int main(int argc, char *argv[]) pb_log("--- pb-cui ---\n"); sa.sa_handler = sig_handler; - result = sigaction(SIGINT, &sa, NULL); + result = sigaction(SIGALRM, &sa, NULL); result += sigaction(SIGHUP, &sa, NULL); + result += sigaction(SIGINT, &sa, NULL); result += sigaction(SIGTERM, &sa, NULL); result += sigaction(SIGWINCH, &sa, NULL); @@ -501,7 +535,10 @@ int main(int argc, char *argv[]) return EXIT_FAILURE; } - ps3.dirty_values = ps3_flash_get_values(&ps3.values); + ps3.values = ps3_flash_defaults; + + if (opts.reset_defaults != opt_yes) + ps3.dirty_values = ps3_flash_get_values(&ps3.values); result = ps3_get_video_mode(&mode); @@ -523,6 +560,14 @@ int main(int argc, char *argv[]) ps3.mm = ps3_mm_init(&ps3); ps3.svm = ps3_svm_init(&ps3); + if (opts.use_timeout != opt_yes + || ps3.values.timeout == ps3_timeout_forever) + ui_timer_disable(&ps3.cui->timer); + else { + ps3.cui->timer.update_display = ps3_timer_update; + ui_timer_init(&ps3.cui->timer, ps3.values.timeout); + } + cui_result = cui_run(ps3.cui, ps3.mm, ps3.values.default_item); pmenu_delete(ps3.mm);