2007-03-15 00:29:59 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
2008-05-14 08:52:19 +00:00
|
|
|
* $Id$
|
2007-03-15 00:29:59 +00:00
|
|
|
*
|
|
|
|
* Copyright (C) 2005 by Kevin Ferrare
|
|
|
|
*
|
2008-06-28 18:10:04 +00:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
2007-03-15 00:29:59 +00:00
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
2008-05-29 11:13:46 +00:00
|
|
|
#include "config.h"
|
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"
|
2008-05-29 11:13:46 +00:00
|
|
|
#include "settings.h"
|
2008-05-11 13:39:22 +00:00
|
|
|
#include "viewport.h"
|
2021-08-29 20:15:34 +00:00
|
|
|
#include "appevents.h"
|
2005-11-18 02:07:02 +00:00
|
|
|
|
|
|
|
|
2008-05-11 13:39:22 +00:00
|
|
|
struct gui_yesno
|
2005-11-18 02:07:02 +00:00
|
|
|
{
|
2008-05-11 13:39:22 +00:00
|
|
|
const struct text_message * main_message;
|
|
|
|
const struct text_message * result_message[2];
|
2020-10-26 16:38:22 +00:00
|
|
|
|
2008-05-11 13:39:22 +00:00
|
|
|
struct viewport *vp;
|
|
|
|
struct screen * display;
|
|
|
|
};
|
2008-05-29 11:13:46 +00:00
|
|
|
|
|
|
|
static void talk_text_message(const struct text_message * message, bool enqueue)
|
|
|
|
{
|
|
|
|
int line;
|
|
|
|
if(message)
|
|
|
|
{
|
|
|
|
for(line=0; line<message->nb_lines; line++)
|
|
|
|
{
|
|
|
|
long id = P2ID((unsigned char *)message->message_lines[line]);
|
|
|
|
if(id>=0)
|
|
|
|
{
|
|
|
|
talk_id(id, enqueue);
|
|
|
|
enqueue = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-05-11 13:39:22 +00:00
|
|
|
static int put_message(struct screen *display,
|
|
|
|
const struct text_message * message,
|
|
|
|
int start, int max_y)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for(i=0; i<message->nb_lines && i+start<max_y; i++)
|
|
|
|
{
|
2020-10-26 16:38:22 +00:00
|
|
|
display->puts_scroll(0, i+start,
|
2008-05-11 13:39:22 +00:00
|
|
|
P2STR((unsigned char *)message->message_lines[i]));
|
|
|
|
}
|
|
|
|
return i;
|
2005-11-18 02:07:02 +00:00
|
|
|
}
|
2020-10-26 16:38:22 +00:00
|
|
|
|
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;
|
2008-05-11 13:39:22 +00:00
|
|
|
struct viewport *vp = yn->vp;
|
|
|
|
int nb_lines, vp_lines, line_shift=0;
|
2020-10-07 06:01:35 +00:00
|
|
|
struct viewport *last_vp;
|
2007-03-03 13:42:12 +00:00
|
|
|
|
2020-10-07 06:01:35 +00:00
|
|
|
last_vp = display->set_viewport(vp);
|
2008-05-11 13:59:27 +00:00
|
|
|
display->clear_viewport();
|
2008-05-11 13:39:22 +00:00
|
|
|
nb_lines = yn->main_message->nb_lines;
|
|
|
|
vp_lines = viewport_get_nb_lines(vp);
|
2005-11-18 02:07:02 +00:00
|
|
|
|
2008-05-11 13:39:22 +00:00
|
|
|
if(nb_lines+3< vp_lines)
|
2005-11-18 02:07:02 +00:00
|
|
|
line_shift=1;
|
2020-10-26 16:38:22 +00:00
|
|
|
|
2008-05-11 13:39:22 +00:00
|
|
|
line_shift += put_message(display, yn->main_message,
|
|
|
|
line_shift, vp_lines);
|
2010-08-26 10:20:16 +00:00
|
|
|
#ifdef HAVE_TOUCHSCREEN
|
|
|
|
if (display->screen_type == SCREEN_MAIN)
|
|
|
|
{
|
|
|
|
int w,h;
|
|
|
|
int rect_w = vp->width/2, rect_h = vp->height/2;
|
|
|
|
int old_pattern = vp->fg_pattern;
|
|
|
|
vp->fg_pattern = LCD_RGBPACK(0,255,0);
|
|
|
|
display->drawrect(0, rect_h, rect_w, rect_h);
|
|
|
|
display->getstringsize(str(LANG_SET_BOOL_YES), &w, &h);
|
|
|
|
display->putsxy((rect_w-w)/2, rect_h+(rect_h-h)/2, str(LANG_SET_BOOL_YES));
|
|
|
|
vp->fg_pattern = LCD_RGBPACK(255,0,0);
|
|
|
|
display->drawrect(rect_w, rect_h, rect_w, rect_h);
|
|
|
|
display->getstringsize(str(LANG_SET_BOOL_NO), &w, &h);
|
|
|
|
display->putsxy(rect_w + (rect_w-w)/2, rect_h+(rect_h-h)/2, str(LANG_SET_BOOL_NO));
|
|
|
|
vp->fg_pattern = old_pattern;
|
|
|
|
}
|
|
|
|
#else
|
2005-11-18 02:07:02 +00:00
|
|
|
/* Space remaining for yes / no text ? */
|
2008-05-11 13:39:22 +00:00
|
|
|
if(line_shift+2 <= vp_lines)
|
2005-11-18 02:07:02 +00:00
|
|
|
{
|
2008-05-11 13:39:22 +00:00
|
|
|
if(line_shift+3 <= vp_lines)
|
|
|
|
line_shift++;
|
|
|
|
display->puts(0, line_shift, str(LANG_CONFIRM_WITH_BUTTON));
|
|
|
|
display->puts(0, line_shift+1, str(LANG_CANCEL_WITH_ANY));
|
2005-11-18 02:07:02 +00:00
|
|
|
}
|
2010-08-26 10:20:16 +00:00
|
|
|
#endif
|
2008-05-11 13:39:22 +00:00
|
|
|
display->update_viewport();
|
2020-10-07 06:01:35 +00:00
|
|
|
display->set_viewport(last_vp);
|
2005-11-18 02:07:02 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2008-04-26 09:30:24 +00:00
|
|
|
const struct text_message * message=yn->result_message[result];
|
2008-05-11 13:39:22 +00:00
|
|
|
struct viewport *vp = yn->vp;
|
|
|
|
struct screen * display=yn->display;
|
2005-11-18 02:07:02 +00:00
|
|
|
if(message==NULL)
|
|
|
|
return false;
|
2020-10-07 06:01:35 +00:00
|
|
|
struct viewport *last_vp = display->set_viewport(vp);
|
2008-05-11 13:59:27 +00:00
|
|
|
display->clear_viewport();
|
2008-05-11 13:39:22 +00:00
|
|
|
put_message(yn->display, message, 0, viewport_get_nb_lines(vp));
|
|
|
|
display->update_viewport();
|
2020-10-07 06:01:35 +00:00
|
|
|
display->set_viewport(last_vp);
|
2005-11-18 02:07:02 +00:00
|
|
|
return(true);
|
|
|
|
}
|
2007-08-06 13:08:36 +00:00
|
|
|
|
2021-08-29 20:15:34 +00:00
|
|
|
static void gui_yesno_ui_update(unsigned short id, void *event_data, void *user_data)
|
|
|
|
{
|
|
|
|
(void)id;
|
|
|
|
(void)event_data;
|
|
|
|
|
|
|
|
struct gui_yesno* yn = (struct gui_yesno*)user_data;
|
|
|
|
FOR_NB_SCREENS(i)
|
|
|
|
gui_yesno_draw(&yn[i]);
|
|
|
|
}
|
|
|
|
|
2008-04-26 09:30:24 +00:00
|
|
|
enum yesno_res gui_syncyesno_run(const struct text_message * main_message,
|
|
|
|
const struct text_message * yes_message,
|
|
|
|
const struct text_message * no_message)
|
2005-11-18 02:07:02 +00:00
|
|
|
{
|
2008-12-31 05:59:26 +00:00
|
|
|
int button;
|
2005-11-18 02:07:02 +00:00
|
|
|
int result=-1;
|
|
|
|
bool result_displayed;
|
|
|
|
struct gui_yesno yn[NB_SCREENS];
|
2008-05-11 13:39:22 +00:00
|
|
|
struct viewport vp[NB_SCREENS];
|
2007-08-06 13:08:36 +00:00
|
|
|
long talked_tick = 0;
|
2005-11-18 02:07:02 +00:00
|
|
|
FOR_NB_SCREENS(i)
|
|
|
|
{
|
2008-05-11 13:39:22 +00:00
|
|
|
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];
|
2010-02-08 05:11:32 +00:00
|
|
|
viewportmanager_theme_enable(i, true, yn[i].vp);
|
2013-04-03 14:33:23 +00:00
|
|
|
screens[i].scroll_stop();
|
2005-11-18 02:07:02 +00:00
|
|
|
gui_yesno_draw(&(yn[i]));
|
|
|
|
}
|
2012-07-18 08:25:32 +00:00
|
|
|
|
2021-08-10 20:27:28 +00:00
|
|
|
#ifdef HAVE_TOUCHSCREEN
|
|
|
|
/* switch to point mode because that's more intuitive */
|
2021-08-29 20:15:34 +00:00
|
|
|
enum touchscreen_mode old_mode = touchscreen_get_mode();
|
2021-08-10 20:27:28 +00:00
|
|
|
touchscreen_set_mode(TOUCHSCREEN_POINT);
|
|
|
|
#endif
|
|
|
|
|
2011-12-28 05:55:05 +00:00
|
|
|
/* make sure to eat any extranous keypresses */
|
2012-07-18 08:25:32 +00:00
|
|
|
action_wait_for_release();
|
2020-11-05 19:20:07 +00:00
|
|
|
button_clear_queue();
|
2012-07-18 08:25:32 +00:00
|
|
|
|
2021-08-29 20:15:34 +00:00
|
|
|
/* hook into UI update events to avoid the dialog disappearing
|
|
|
|
* in case the skin decides to do a full refresh */
|
|
|
|
add_event_ex(GUI_EVENT_NEED_UI_UPDATE, false, gui_yesno_ui_update, &yn[0]);
|
|
|
|
|
2005-11-18 02:07:02 +00:00
|
|
|
while (result==-1)
|
|
|
|
{
|
2007-08-06 13:08:36 +00:00
|
|
|
/* Repeat the question every 5secs (more or less) */
|
2007-10-19 15:31:42 +00:00
|
|
|
if (global_settings.talk_menu
|
2007-08-06 13:08:36 +00:00
|
|
|
&& (talked_tick==0 || TIME_AFTER(current_tick, talked_tick+HZ*5)))
|
|
|
|
{
|
|
|
|
talked_tick = current_tick;
|
2007-11-07 01:37:00 +00:00
|
|
|
talk_text_message(main_message, false);
|
2007-08-06 13:08:36 +00:00
|
|
|
}
|
|
|
|
button = get_action(CONTEXT_YESNOSCREEN, HZ*5);
|
2005-11-18 02:07:02 +00:00
|
|
|
switch (button)
|
|
|
|
{
|
2010-08-26 10:20:16 +00:00
|
|
|
#ifdef HAVE_TOUCHSCREEN
|
|
|
|
case ACTION_TOUCHSCREEN:
|
|
|
|
{
|
|
|
|
short int x, y;
|
2012-08-15 20:49:01 +00:00
|
|
|
if (action_get_touchscreen_press_in_vp(&x, &y, yn[0].vp) == BUTTON_REL)
|
2010-08-26 10:20:16 +00:00
|
|
|
{
|
|
|
|
if (y > yn[0].vp->height/2)
|
|
|
|
{
|
|
|
|
if (x <= yn[0].vp->width/2)
|
|
|
|
result = YESNO_YES;
|
|
|
|
else
|
|
|
|
result = YESNO_NO;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
#endif
|
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:
|
2021-05-16 20:01:26 +00:00
|
|
|
case ACTION_UNKNOWN:
|
2007-06-16 11:50:42 +00:00
|
|
|
case SYS_CHARGER_DISCONNECTED:
|
2011-05-07 08:08:49 +00:00
|
|
|
case SYS_BATTERY_UPDATE:
|
2021-05-16 20:01:26 +00:00
|
|
|
case SYS_TIMEOUT:
|
|
|
|
#if CONFIG_CHARGING
|
|
|
|
case SYS_CHARGER_CONNECTED:
|
|
|
|
#endif
|
2007-06-16 11:50:42 +00:00
|
|
|
/* 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:
|
2021-08-10 20:27:28 +00:00
|
|
|
if(default_event_handler(button) == SYS_USB_CONNECTED) {
|
2021-08-29 20:15:34 +00:00
|
|
|
result = YESNO_USB;
|
|
|
|
goto exit;
|
2021-08-10 20:27:28 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
|
|
FOR_NB_SCREENS(i)
|
|
|
|
result_displayed=gui_yesno_draw_result(&(yn[i]), result);
|
|
|
|
|
2007-10-19 15:31:42 +00:00
|
|
|
if (global_settings.talk_menu)
|
2007-08-06 13:08:36 +00:00
|
|
|
{
|
2020-10-26 16:38:22 +00:00
|
|
|
talk_text_message((result == YESNO_YES) ? yes_message
|
2007-11-07 01:37:00 +00:00
|
|
|
: no_message, false);
|
2007-08-06 13:08:36 +00:00
|
|
|
talk_force_enqueue_next();
|
|
|
|
}
|
2005-11-18 02:07:02 +00:00
|
|
|
if(result_displayed)
|
|
|
|
sleep(HZ);
|
2009-09-05 18:10:41 +00:00
|
|
|
|
2010-02-08 05:11:32 +00:00
|
|
|
FOR_NB_SCREENS(i)
|
|
|
|
{
|
2013-04-03 14:33:23 +00:00
|
|
|
screens[i].scroll_stop_viewport(yn[i].vp);
|
2010-02-08 05:11:32 +00:00
|
|
|
viewportmanager_theme_undo(i, true);
|
|
|
|
}
|
2012-07-18 08:25:32 +00:00
|
|
|
|
2021-08-29 20:15:34 +00:00
|
|
|
exit:
|
|
|
|
remove_event_ex(GUI_EVENT_NEED_UI_UPDATE, gui_yesno_ui_update, &yn[0]);
|
|
|
|
#ifdef HAVE_TOUCHSCREEN
|
|
|
|
touchscreen_set_mode(old_mode);
|
|
|
|
#endif
|
|
|
|
return result;
|
2005-11-18 02:07:02 +00:00
|
|
|
}
|
2011-07-21 06:40:01 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* Function to manipulate all yesno dialogues.
|
|
|
|
This function needs the output text as an argument. */
|
|
|
|
bool yesno_pop(const char* text)
|
|
|
|
{
|
|
|
|
const char *lines[]={text};
|
|
|
|
const struct text_message message={lines, 1};
|
|
|
|
bool ret = (gui_syncyesno_run(&message,NULL,NULL)== YESNO_YES);
|
|
|
|
FOR_NB_SCREENS(i)
|
|
|
|
screens[i].clear_viewport();
|
|
|
|
return ret;
|
|
|
|
}
|