1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2005 by Kevin Ferrare
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
29 * Initializes the yesno asker
30 * - yn : the yesno structure
31 * - main_message : the question the user has to answer
32 * - yes_message : message displayed if answer is 'yes'
33 * - no_message : message displayed if answer is 'no'
35 static void gui_yesno_init(struct gui_yesno
* yn
,
36 struct text_message
* main_message
,
37 struct text_message
* yes_message
,
38 struct text_message
* no_message
)
40 yn
->main_message
=main_message
;
41 yn
->result_message
[YESNO_YES
]=yes_message
;
42 yn
->result_message
[YESNO_NO
]=no_message
;
47 * Attach the yesno to a screen
48 * - yn : the yesno structure
49 * - display : the screen to attach
51 static void gui_yesno_set_display(struct gui_yesno
* yn
,
52 struct screen
* display
)
59 * - yn : the yesno structure
61 static void gui_yesno_draw(struct gui_yesno
* yn
)
63 struct screen
* display
=yn
->display
;
64 int nb_lines
, line_shift
=0;
66 gui_textarea_clear(display
);
67 nb_lines
=yn
->main_message
->nb_lines
;
69 if(nb_lines
+3<display
->nb_lines
)
71 nb_lines
=gui_textarea_put_message(display
, yn
->main_message
, line_shift
);
73 /* Space remaining for yes / no text ? */
74 if(nb_lines
+line_shift
+2<=display
->nb_lines
)
76 if(nb_lines
+line_shift
+3<=display
->nb_lines
)
78 display
->puts(0, nb_lines
+line_shift
, str(LANG_CONFIRM_WITH_BUTTON
));
79 #ifdef HAVE_LCD_BITMAP
80 display
->puts(0, nb_lines
+line_shift
+1, str(LANG_CANCEL_WITH_ANY
));
83 gui_textarea_update(display
);
87 * Draws the yesno result
88 * - yn : the yesno structure
89 * - result : the result tha must be displayed :
93 static bool gui_yesno_draw_result(struct gui_yesno
* yn
, enum yesno_res result
)
95 struct text_message
* message
=yn
->result_message
[result
];
98 gui_textarea_put_message(yn
->display
, message
, 0);
104 enum yesno_res
gui_syncyesno_run(struct text_message
* main_message
,
105 struct text_message
* yes_message
,
106 struct text_message
* no_message
)
111 bool result_displayed
;
112 struct gui_yesno yn
[NB_SCREENS
];
113 long talked_tick
= 0;
116 gui_yesno_init(&(yn
[i
]), main_message
, yes_message
, no_message
);
117 gui_yesno_set_display(&(yn
[i
]), &(screens
[i
]));
118 gui_yesno_draw(&(yn
[i
]));
122 /* Repeat the question every 5secs (more or less) */
123 if (global_settings
.talk_menu
124 && (talked_tick
==0 || TIME_AFTER(current_tick
, talked_tick
+HZ
*5)))
126 talked_tick
= current_tick
;
127 talk_text_message(main_message
, false);
129 button
= get_action(CONTEXT_YESNOSCREEN
, HZ
*5);
132 case ACTION_YESNO_ACCEPT
:
136 case SYS_CHARGER_DISCONNECTED
:
137 /* ignore some SYS events that can happen */
140 if(default_event_handler(button
) == SYS_USB_CONNECTED
)
147 result_displayed
=gui_yesno_draw_result(&(yn
[i
]), result
);
149 if (global_settings
.talk_menu
)
151 talk_text_message((result
== YESNO_YES
) ? yes_message
152 : no_message
, false);
153 talk_force_enqueue_next();