bool alarm_screen(void) { int h, m; bool done = false; struct tm *tm; int togo; int button; bool update = true; bool hour_wrapped = false; struct viewport vp[NB_SCREENS]; rtc_get_alarm(&h, &m); /* After a battery change the RTC values are out of range */ if (m > 60 || h > 24) { m = 0; h = 12; } else { m = m / 5 * 5; /* 5 min accuracy should be enough */ } FOR_NB_SCREENS(i) { viewport_set_defaults(&vp[i], i); } while(!done) { if(update) { FOR_NB_SCREENS(i) { screens[i].set_viewport(&vp[i]); screens[i].clear_viewport(); screens[i].puts(0, 4, str(LANG_ALARM_MOD_KEYS)); } /* Talk when entering the wakeup screen */ speak_time(h, m, true, true); update = false; } FOR_NB_SCREENS(i) { screens[i].set_viewport(&vp[i]); screens[i].putsf(0, 1, str(LANG_ALARM_MOD_TIME)); screens[i].putsf(0, 2, "%02d:%02d", h, m); screens[i].update_viewport(); screens[i].set_viewport(NULL); } button = get_action(CONTEXT_SETTINGS,HZ); switch(button) { case ACTION_STD_OK: /* prevent that an alarm occurs in the shutdown procedure */ /* accept alarms only if they are in 2 minutes or more */ tm = get_time(); togo = (m + h * 60 - tm->tm_min - tm->tm_hour * 60 + 1440) % 1440; if (togo > 1) { rtc_init(); rtc_set_alarm(h,m); rtc_enable_alarm(true); if (global_settings.talk_menu) { talk_id(LANG_ALARM_MOD_TIME_TO_GO, true); talk_value(togo / 60, UNIT_HOUR, true); talk_value(togo % 60, UNIT_MIN, true); talk_force_enqueue_next(); } splashf(HZ*2, str(LANG_ALARM_MOD_TIME_TO_GO), togo / 60, togo % 60); done = true; } else { splash(HZ, ID2P(LANG_ALARM_MOD_ERROR)); update = true; } break; /* inc(m) */ case ACTION_SETTINGS_INC: case ACTION_SETTINGS_INCREPEAT: m += 5; if (m == 60) { h += 1; m = 0; hour_wrapped = true; } if (h == 24) h = 0; speak_time(h, m, hour_wrapped, false); break; /* dec(m) */ case ACTION_SETTINGS_DEC: case ACTION_SETTINGS_DECREPEAT: m -= 5; if (m == -5) { h -= 1; m = 55; hour_wrapped = true; } if (h == -1) h = 23; speak_time(h, m, hour_wrapped, false); break; /* inc(h) */ case ACTION_STD_NEXT: case ACTION_STD_NEXTREPEAT: h = (h+1) % 24; if (global_settings.talk_menu) talk_value(h, UNIT_HOUR, false); break; /* dec(h) */ case ACTION_STD_PREV: case ACTION_STD_PREVREPEAT: h = (h+23) % 24; if (global_settings.talk_menu) talk_value(h, UNIT_HOUR, false); break; case ACTION_STD_CANCEL: rtc_enable_alarm(false); splash(HZ*2, ID2P(LANG_ALARM_MOD_DISABLE)); done = true; break; case ACTION_NONE: hour_wrapped = false; break; default: if(default_event_handler(button) == SYS_USB_CONNECTED) { rtc_enable_alarm(false); return true; } break; } } return false; }
enum yesno_res gui_syncyesno_run(const struct text_message * main_message, const struct text_message * yes_message, const struct text_message * no_message) { int i; int button; int result=-1; bool result_displayed; struct gui_yesno yn[NB_SCREENS]; struct viewport vp[NB_SCREENS]; long talked_tick = 0; FOR_NB_SCREENS(i) { yn[i].main_message=main_message; yn[i].result_message[YESNO_YES]=yes_message; yn[i].result_message[YESNO_NO]=no_message; yn[i].display=&screens[i]; yn[i].vp = &vp[i]; viewportmanager_theme_enable(i, true, yn[i].vp); screens[i].stop_scroll(); gui_yesno_draw(&(yn[i])); } while (result==-1) { /* Repeat the question every 5secs (more or less) */ if (global_settings.talk_menu && (talked_tick==0 || TIME_AFTER(current_tick, talked_tick+HZ*5))) { talked_tick = current_tick; talk_text_message(main_message, false); } button = get_action(CONTEXT_YESNOSCREEN, HZ*5); switch (button) { case ACTION_YESNO_ACCEPT: result=YESNO_YES; break; case ACTION_NONE: case SYS_CHARGER_DISCONNECTED: /* ignore some SYS events that can happen */ continue; default: if(default_event_handler(button) == SYS_USB_CONNECTED) return(YESNO_USB); result = YESNO_NO; } } FOR_NB_SCREENS(i) result_displayed=gui_yesno_draw_result(&(yn[i]), result); if (global_settings.talk_menu) { talk_text_message((result == YESNO_YES) ? yes_message : no_message, false); talk_force_enqueue_next(); } if(result_displayed) sleep(HZ); FOR_NB_SCREENS(i) { screens[i].scroll_stop(yn[i].vp); viewportmanager_theme_undo(i, true); } return(result); }
enum yesno_res gui_syncyesno_run(const struct text_message * main_message, const struct text_message * yes_message, const struct text_message * no_message) { int button; int result=-1; bool result_displayed; struct gui_yesno yn[NB_SCREENS]; struct viewport vp[NB_SCREENS]; long talked_tick = 0; FOR_NB_SCREENS(i) { yn[i].main_message=main_message; yn[i].result_message[YESNO_YES]=yes_message; yn[i].result_message[YESNO_NO]=no_message; yn[i].display=&screens[i]; yn[i].vp = &vp[i]; #ifdef HAVE_LCD_CHARCELLS /* Quick fix. Viewports should really be enabled proper for charcell */ viewport_set_defaults(yn[i].vp, i); #else viewportmanager_theme_enable(i, true, yn[i].vp); #endif screens[i].stop_scroll(); gui_yesno_draw(&(yn[i])); } /* make sure to eat any extranous keypresses */ while (get_action(CONTEXT_STD+99, TIMEOUT_NOBLOCK)) action_wait_for_release(); while (result==-1) { /* Repeat the question every 5secs (more or less) */ if (global_settings.talk_menu && (talked_tick==0 || TIME_AFTER(current_tick, talked_tick+HZ*5))) { talked_tick = current_tick; talk_text_message(main_message, false); } button = get_action(CONTEXT_YESNOSCREEN, HZ*5); switch (button) { #ifdef HAVE_TOUCHSCREEN case ACTION_TOUCHSCREEN: { short int x, y; if (action_get_touchscreen_press_in_vp(&x, &y, yn[0].vp) == BUTTON_TOUCHSCREEN) { if (y > yn[0].vp->height/2) { if (x <= yn[0].vp->width/2) result = YESNO_YES; else result = YESNO_NO; } } } break; #endif case ACTION_YESNO_ACCEPT: result=YESNO_YES; break; case ACTION_NONE: case SYS_CHARGER_DISCONNECTED: case SYS_BATTERY_UPDATE: /* ignore some SYS events that can happen */ continue; default: if(default_event_handler(button) == SYS_USB_CONNECTED) return(YESNO_USB); result = YESNO_NO; } } FOR_NB_SCREENS(i) result_displayed=gui_yesno_draw_result(&(yn[i]), result); if (global_settings.talk_menu) { talk_text_message((result == YESNO_YES) ? yes_message : no_message, false); talk_force_enqueue_next(); } if(result_displayed) sleep(HZ); FOR_NB_SCREENS(i) { screens[i].scroll_stop(yn[i].vp); viewportmanager_theme_undo(i, true); } return(result); }
int do_shortcut_menu(void *ignored) { (void)ignored; struct simplelist_info list; struct shortcut *sc; int done = GO_TO_PREVIOUS; if (first_handle == 0) shortcuts_init(); simplelist_info_init(&list, P2STR(ID2P(LANG_SHORTCUTS)), shortcut_count, NULL); list.get_name = shortcut_menu_get_name; list.action_callback = shortcut_menu_get_action; if (global_settings.show_icons) list.get_icon = shortcut_menu_get_icon; list.title_icon = Icon_Bookmark; if (global_settings.talk_menu) list.get_talk = shortcut_menu_speak_item; push_current_activity(ACTIVITY_SHORTCUTSMENU); while (done == GO_TO_PREVIOUS) { if (simplelist_show_list(&list)) break; /* some error happened?! */ if (list.selection == -1) break; else { sc = get_shortcut(list.selection); if (!sc) continue; switch (sc->type) { case SHORTCUT_PLAYLISTMENU: if (!file_exists(sc->u.path)) { splash(HZ, ID2P(LANG_NO_FILES)); break; } else { onplay_show_playlist_menu(sc->u.path); } break; case SHORTCUT_FILE: if (!file_exists(sc->u.path)) { splash(HZ, ID2P(LANG_NO_FILES)); break; } /* else fall through */ case SHORTCUT_BROWSER: { struct browse_context browse; browse_context_init(&browse, global_settings.dirfilter, 0, NULL, NOICON, sc->u.path, NULL); if (sc->type == SHORTCUT_FILE) browse.flags |= BROWSE_RUNFILE; done = rockbox_browse(&browse); } break; case SHORTCUT_SETTING: do_setting_screen(sc->u.setting, sc->name[0] ? sc->name : P2STR(ID2P(sc->u.setting->lang_id)),NULL); break; case SHORTCUT_DEBUGITEM: run_debug_screen(sc->u.path); break; case SHORTCUT_SHUTDOWN: #if CONFIG_CHARGING if (charger_inserted()) charging_splash(); else #endif sys_poweroff(); break; case SHORTCUT_TIME: #if CONFIG_RTC if (sc->u.timedata.talktime) { talk_timedate(); talk_force_enqueue_next(); } else #endif { char timer_buf[10]; set_sleep_timer(sc->u.timedata.sleep_timeout * 60); splashf(HZ, "%s (%s)", str(LANG_SLEEP_TIMER), sleep_timer_formatter(timer_buf, sizeof(timer_buf), sc->u.timedata.sleep_timeout, NULL)); } break; case SHORTCUT_UNDEFINED: default: break; } } } pop_current_activity(); return done; }