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 /* Processes a text_message whose lines may be virtual pointers
105 representing language / voicefont IDs (see settings.h). Copies out
106 the IDs to the ids array, which is of length maxlen, and replaces
107 the pointers in the text_message with the actual language strings.
108 The ids array is terminated with the TALK_FINAL_ID sentinel
110 static void extract_talk_ids(struct text_message
*m
, long *ids
, int maxlen
)
114 for(line
=0; line
<m
->nb_lines
; line
++) {
115 long id
= P2ID((unsigned char *)m
->message_lines
[line
]);
116 if(id
>=0 && i
<maxlen
-1)
118 m
->message_lines
[line
] = (char *)P2STR((unsigned char *)m
->message_lines
[line
]);
120 ids
[i
] = TALK_FINAL_ID
;
123 enum yesno_res
gui_syncyesno_run(struct text_message
* main_message
,
124 struct text_message
* yes_message
,
125 struct text_message
* no_message
)
130 bool result_displayed
;
131 struct gui_yesno yn
[NB_SCREENS
];
133 long talked_tick
= 0;
134 /* The text messages may contain virtual pointers to IDs (see
135 settings.h) instead of plain strings. Copy the IDs out so we
136 can speak them, and unwrap the actual language strings. */
137 extract_talk_ids(main_message
, voice_ids
,
138 sizeof(voice_ids
)/sizeof(voice_ids
[0]));
141 gui_yesno_init(&(yn
[i
]), main_message
, yes_message
, no_message
);
142 gui_yesno_set_display(&(yn
[i
]), &(screens
[i
]));
143 gui_yesno_draw(&(yn
[i
]));
147 /* Repeat the question every 5secs (more or less) */
148 if (global_settings
.talk_menu
149 && (talked_tick
==0 || TIME_AFTER(current_tick
, talked_tick
+HZ
*5)))
151 talked_tick
= current_tick
;
152 talk_idarray(voice_ids
, false);
154 button
= get_action(CONTEXT_YESNOSCREEN
, HZ
*5);
157 case ACTION_YESNO_ACCEPT
:
161 case SYS_CHARGER_DISCONNECTED
:
162 /* ignore some SYS events that can happen */
165 if(default_event_handler(button
) == SYS_USB_CONNECTED
)
171 /* extract_talk_ids also converts ID to STR */
172 extract_talk_ids((result
== YESNO_YES
) ? yes_message
: no_message
,
173 voice_ids
, sizeof(voice_ids
)/sizeof(voice_ids
[0]));
176 result_displayed
=gui_yesno_draw_result(&(yn
[i
]), result
);
178 if (global_settings
.talk_menu
)
180 talk_idarray(voice_ids
, false);
181 talk_force_enqueue_next();