2007-03-15 00:29:59 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id $
|
|
|
|
*
|
|
|
|
* Copyright (C) 2005 by Kevin Ferrare
|
|
|
|
*
|
|
|
|
* All files in this archive are subject to the GNU General Public License.
|
|
|
|
* See the file COPYING in the source tree root for full license agreement.
|
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2005-11-18 02:07:02 +00:00
|
|
|
#include "yesno.h"
|
2006-01-21 23:43:57 +00:00
|
|
|
#include "system.h"
|
2005-11-18 02:07:02 +00:00
|
|
|
#include "kernel.h"
|
|
|
|
#include "misc.h"
|
|
|
|
#include "lang.h"
|
2006-08-15 12:27:07 +00:00
|
|
|
#include "action.h"
|
2007-08-06 13:08:36 +00:00
|
|
|
#include "talk.h"
|
2005-11-18 02:07:02 +00:00
|
|
|
|
2007-03-15 00:29:59 +00:00
|
|
|
/*
|
|
|
|
* Initializes the yesno asker
|
|
|
|
* - yn : the yesno structure
|
|
|
|
* - main_message : the question the user has to answer
|
|
|
|
* - yes_message : message displayed if answer is 'yes'
|
|
|
|
* - no_message : message displayed if answer is 'no'
|
|
|
|
*/
|
|
|
|
static void gui_yesno_init(struct gui_yesno * yn,
|
2005-11-18 02:07:02 +00:00
|
|
|
struct text_message * main_message,
|
|
|
|
struct text_message * yes_message,
|
|
|
|
struct text_message * no_message)
|
|
|
|
{
|
|
|
|
yn->main_message=main_message;
|
|
|
|
yn->result_message[YESNO_YES]=yes_message;
|
|
|
|
yn->result_message[YESNO_NO]=no_message;
|
|
|
|
yn->display=0;
|
|
|
|
}
|
|
|
|
|
2007-03-15 00:29:59 +00:00
|
|
|
/*
|
|
|
|
* Attach the yesno to a screen
|
|
|
|
* - yn : the yesno structure
|
|
|
|
* - display : the screen to attach
|
|
|
|
*/
|
|
|
|
static void gui_yesno_set_display(struct gui_yesno * yn,
|
2005-11-18 02:07:02 +00:00
|
|
|
struct screen * display)
|
|
|
|
{
|
|
|
|
yn->display=display;
|
|
|
|
}
|
|
|
|
|
2007-03-15 00:29:59 +00:00
|
|
|
/*
|
|
|
|
* Draws the yesno
|
|
|
|
* - yn : the yesno structure
|
|
|
|
*/
|
|
|
|
static void gui_yesno_draw(struct gui_yesno * yn)
|
2005-11-18 02:07:02 +00:00
|
|
|
{
|
|
|
|
struct screen * display=yn->display;
|
|
|
|
int nb_lines, line_shift=0;
|
2007-03-03 13:42:12 +00:00
|
|
|
|
2005-11-18 02:07:02 +00:00
|
|
|
gui_textarea_clear(display);
|
|
|
|
nb_lines=yn->main_message->nb_lines;
|
|
|
|
|
|
|
|
if(nb_lines+3<display->nb_lines)
|
|
|
|
line_shift=1;
|
|
|
|
nb_lines=gui_textarea_put_message(display, yn->main_message, line_shift);
|
|
|
|
|
|
|
|
/* Space remaining for yes / no text ? */
|
|
|
|
if(nb_lines+line_shift+2<=display->nb_lines)
|
|
|
|
{
|
|
|
|
if(nb_lines+line_shift+3<=display->nb_lines)
|
|
|
|
nb_lines++;
|
2007-08-05 19:19:39 +00:00
|
|
|
display->puts(0, nb_lines+line_shift, str(LANG_CONFIRM_WITH_BUTTON));
|
|
|
|
#ifdef HAVE_LCD_BITMAP
|
|
|
|
display->puts(0, nb_lines+line_shift+1, str(LANG_CANCEL_WITH_ANY));
|
|
|
|
#endif
|
2005-11-18 02:07:02 +00:00
|
|
|
}
|
|
|
|
gui_textarea_update(display);
|
|
|
|
}
|
|
|
|
|
2007-03-15 00:29:59 +00:00
|
|
|
/*
|
|
|
|
* Draws the yesno result
|
|
|
|
* - yn : the yesno structure
|
|
|
|
* - result : the result tha must be displayed :
|
|
|
|
* YESNO_NO if no
|
|
|
|
* YESNO_YES if yes
|
|
|
|
*/
|
|
|
|
static bool gui_yesno_draw_result(struct gui_yesno * yn, enum yesno_res result)
|
2005-11-18 02:07:02 +00:00
|
|
|
{
|
|
|
|
struct text_message * message=yn->result_message[result];
|
|
|
|
if(message==NULL)
|
|
|
|
return false;
|
|
|
|
gui_textarea_put_message(yn->display, message, 0);
|
|
|
|
return(true);
|
|
|
|
}
|
2007-08-06 13:08:36 +00:00
|
|
|
|
2006-08-15 12:27:07 +00:00
|
|
|
#include "debug.h"
|
2007-08-06 13:08:36 +00:00
|
|
|
|
|
|
|
/* Processes a text_message whose lines may be virtual pointers
|
|
|
|
representing language / voicefont IDs (see settings.h). Copies out
|
|
|
|
the IDs to the ids array, which is of length maxlen, and replaces
|
|
|
|
the pointers in the text_message with the actual language strings.
|
|
|
|
The ids array is terminated with the TALK_FINAL_ID sentinel
|
|
|
|
element. */
|
|
|
|
static void extract_talk_ids(struct text_message *m, long *ids, int maxlen)
|
|
|
|
{
|
|
|
|
int line, i=0;
|
|
|
|
if(m)
|
|
|
|
for(line=0; line<m->nb_lines; line++) {
|
|
|
|
long id = P2ID((unsigned char *)m->message_lines[line]);
|
|
|
|
if(id>=0 && i<maxlen-1)
|
|
|
|
ids[i++] = id;
|
|
|
|
m->message_lines[line] = (char *)P2STR((unsigned char *)m->message_lines[line]);
|
|
|
|
}
|
|
|
|
ids[i] = TALK_FINAL_ID;
|
|
|
|
}
|
|
|
|
|
2005-11-18 02:07:02 +00:00
|
|
|
enum yesno_res gui_syncyesno_run(struct text_message * main_message,
|
2005-12-05 22:44:42 +00:00
|
|
|
struct text_message * yes_message,
|
|
|
|
struct text_message * no_message)
|
2005-11-18 02:07:02 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
unsigned button;
|
|
|
|
int result=-1;
|
|
|
|
bool result_displayed;
|
|
|
|
struct gui_yesno yn[NB_SCREENS];
|
2007-08-06 13:08:36 +00:00
|
|
|
long voice_ids[5];
|
|
|
|
long talked_tick = 0;
|
|
|
|
/* The text messages may contain virtual pointers to IDs (see
|
|
|
|
settings.h) instead of plain strings. Copy the IDs out so we
|
|
|
|
can speak them, and unwrap the actual language strings. */
|
|
|
|
extract_talk_ids(main_message, voice_ids,
|
|
|
|
sizeof(voice_ids)/sizeof(voice_ids[0]));
|
2005-11-18 02:07:02 +00:00
|
|
|
FOR_NB_SCREENS(i)
|
|
|
|
{
|
|
|
|
gui_yesno_init(&(yn[i]), main_message, yes_message, no_message);
|
|
|
|
gui_yesno_set_display(&(yn[i]), &(screens[i]));
|
|
|
|
gui_yesno_draw(&(yn[i]));
|
|
|
|
}
|
|
|
|
while (result==-1)
|
|
|
|
{
|
2007-08-06 13:08:36 +00:00
|
|
|
/* Repeat the question every 5secs (more or less) */
|
|
|
|
if (talk_menus_enabled()
|
|
|
|
&& (talked_tick==0 || TIME_AFTER(current_tick, talked_tick+HZ*5)))
|
|
|
|
{
|
|
|
|
talked_tick = current_tick;
|
|
|
|
talk_idarray(voice_ids, false);
|
|
|
|
}
|
|
|
|
button = get_action(CONTEXT_YESNOSCREEN, HZ*5);
|
2005-11-18 02:07:02 +00:00
|
|
|
switch (button)
|
|
|
|
{
|
2006-08-15 12:27:07 +00:00
|
|
|
case ACTION_YESNO_ACCEPT:
|
2005-11-18 02:07:02 +00:00
|
|
|
result=YESNO_YES;
|
|
|
|
break;
|
2006-08-17 09:28:04 +00:00
|
|
|
case ACTION_NONE:
|
2007-06-16 11:50:42 +00:00
|
|
|
case SYS_CHARGER_DISCONNECTED:
|
|
|
|
/* ignore some SYS events that can happen */
|
2006-08-17 09:28:04 +00:00
|
|
|
continue;
|
2005-11-18 02:07:02 +00:00
|
|
|
default:
|
|
|
|
if(default_event_handler(button) == SYS_USB_CONNECTED)
|
|
|
|
return(YESNO_USB);
|
2006-08-15 12:27:07 +00:00
|
|
|
result = YESNO_NO;
|
2005-11-18 02:07:02 +00:00
|
|
|
}
|
|
|
|
}
|
2007-08-12 21:59:42 +00:00
|
|
|
|
|
|
|
/* extract_talk_ids also converts ID to STR */
|
2007-08-06 13:08:36 +00:00
|
|
|
extract_talk_ids((result == YESNO_YES) ? yes_message : no_message,
|
|
|
|
voice_ids, sizeof(voice_ids)/sizeof(voice_ids[0]));
|
2007-08-12 21:59:42 +00:00
|
|
|
|
|
|
|
FOR_NB_SCREENS(i)
|
|
|
|
result_displayed=gui_yesno_draw_result(&(yn[i]), result);
|
|
|
|
|
2007-08-06 13:08:36 +00:00
|
|
|
if (talk_menus_enabled())
|
|
|
|
{
|
|
|
|
talk_idarray(voice_ids, false);
|
|
|
|
talk_force_enqueue_next();
|
|
|
|
}
|
2005-11-18 02:07:02 +00:00
|
|
|
if(result_displayed)
|
|
|
|
sleep(HZ);
|
|
|
|
return(result);
|
|
|
|
}
|