summaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
authorKevin Ferrare <kevin@rockbox.org>2005-11-18 02:07:02 +0000
committerKevin Ferrare <kevin@rockbox.org>2005-11-18 02:07:02 +0000
commit8719f0913a0f2d8a90e9ecbc7c0e5336369af6be (patch)
treeb336928b98e48a15d0d1c176105fa21ac557b7c9 /apps
parentec0a8a749bbc3aa25bf4c136352725bd9d2532b5 (diff)
downloadrockbox-8719f0913a0f2d8a90e9ecbc7c0e5336369af6be.tar.gz
rockbox-8719f0913a0f2d8a90e9ecbc7c0e5336369af6be.zip
generic multi-screen support for yes/no screens (like the one when reseting settings or when firmware has changed)
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@7951 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps')
-rw-r--r--apps/SOURCES1
-rw-r--r--apps/gui/textarea.c12
-rw-r--r--apps/gui/textarea.h16
-rw-r--r--apps/gui/yesno.c96
-rw-r--r--apps/gui/yesno.h91
-rw-r--r--apps/settings_menu.c58
-rw-r--r--apps/tree.c41
-rw-r--r--apps/tree.h22
8 files changed, 250 insertions, 87 deletions
diff --git a/apps/SOURCES b/apps/SOURCES
index 67e09ed53d..dc93eeebbc 100644
--- a/apps/SOURCES
+++ b/apps/SOURCES
@@ -41,6 +41,7 @@ gui/statusbar.c
41gui/gwps.c 41gui/gwps.c
42gui/gwps-common.c 42gui/gwps-common.c
43gui/textarea.c 43gui/textarea.c
44gui/yesno.c
44 45
45#ifdef HAVE_LCD_CHARCELLS 46#ifdef HAVE_LCD_CHARCELLS
46player/icons.c 47player/icons.c
diff --git a/apps/gui/textarea.c b/apps/gui/textarea.c
index d8e730fdc2..d73f20d0e7 100644
--- a/apps/gui/textarea.c
+++ b/apps/gui/textarea.c
@@ -41,6 +41,18 @@ void gui_textarea_update(struct screen * display)
41} 41}
42#endif 42#endif
43 43
44int gui_textarea_put_message(struct screen * display,
45 struct text_message * message,
46 int ystart)
47{
48 int i;
49 gui_textarea_clear(display);
50 for(i=0;i<message->nb_lines && i+ystart<display->nb_lines;i++)
51 display->puts(0, i+ystart, message->message_lines[i]);
52 gui_textarea_update(display);
53 return(i);
54}
55
44void gui_textarea_update_nblines(struct screen * display) 56void gui_textarea_update_nblines(struct screen * display)
45{ 57{
46#ifdef HAVE_LCD_BITMAP 58#ifdef HAVE_LCD_BITMAP
diff --git a/apps/gui/textarea.h b/apps/gui/textarea.h
index 5249aed7a5..b1af1a5aba 100644
--- a/apps/gui/textarea.h
+++ b/apps/gui/textarea.h
@@ -23,6 +23,12 @@
23#include "settings.h" 23#include "settings.h"
24#include "statusbar.h" 24#include "statusbar.h"
25 25
26struct text_message
27{
28 char **message_lines;
29 int nb_lines;
30};
31
26/* 32/*
27 * Clears the area in the screen in which text can be displayed 33 * Clears the area in the screen in which text can be displayed
28 * and sets the y margin properly 34 * and sets the y margin properly
@@ -46,6 +52,16 @@ extern void gui_textarea_update(struct screen * display);
46#endif 52#endif
47 53
48/* 54/*
55 * Displays message lines on the given screen
56 * - display : the screen structure
57 * - message : the lines to display
58 * - ystart : the lineon which we start displaying
59 * returns : the number of lines effectively displayed
60 */
61extern int gui_textarea_put_message(struct screen * display,
62 struct text_message * message,
63 int ystart);
64/*
49 * Compute the number of text lines the display can draw with the current font 65 * Compute the number of text lines the display can draw with the current font
50 * Also updates the char height and width 66 * Also updates the char height and width
51 * - display : the screen structure 67 * - display : the screen structure
diff --git a/apps/gui/yesno.c b/apps/gui/yesno.c
new file mode 100644
index 0000000000..65f81aaf3e
--- /dev/null
+++ b/apps/gui/yesno.c
@@ -0,0 +1,96 @@
1#include "yesno.h"
2#include "kernel.h"
3#include "misc.h"
4#include "lang.h"
5
6void gui_yesno_init(struct gui_yesno * yn,
7 struct text_message * main_message,
8 struct text_message * yes_message,
9 struct text_message * no_message)
10{
11 yn->main_message=main_message;
12 yn->result_message[YESNO_YES]=yes_message;
13 yn->result_message[YESNO_NO]=no_message;
14 yn->display=0;
15}
16
17void gui_yesno_set_display(struct gui_yesno * yn,
18 struct screen * display)
19{
20 yn->display=display;
21}
22
23void gui_yesno_draw(struct gui_yesno * yn)
24{
25 struct screen * display=yn->display;
26 int nb_lines, line_shift=0;
27#ifdef HAS_LCD_BITMAP
28 screen_set_xmargin(display, 0);
29#endif
30 gui_textarea_clear(display);
31 nb_lines=yn->main_message->nb_lines;
32
33 if(nb_lines+3<display->nb_lines)
34 line_shift=1;
35 nb_lines=gui_textarea_put_message(display, yn->main_message, line_shift);
36
37 /* Space remaining for yes / no text ? */
38 if(nb_lines+line_shift+2<=display->nb_lines)
39 {
40 if(nb_lines+line_shift+3<=display->nb_lines)
41 nb_lines++;
42 display->puts(0, nb_lines+line_shift, str(LANG_CONFIRM_WITH_PLAY_RECORDER));
43 display->puts(0, nb_lines+line_shift+1, str(LANG_CANCEL_WITH_ANY_RECORDER));
44 }
45 gui_textarea_update(display);
46}
47
48bool gui_yesno_draw_result(struct gui_yesno * yn, enum yesno_res result)
49{
50 struct text_message * message=yn->result_message[result];
51 if(message==NULL)
52 return false;
53 gui_textarea_put_message(yn->display, message, 0);
54 return(true);
55}
56
57enum yesno_res gui_syncyesno_run(struct text_message * main_message,
58 struct text_message * yes_message,
59 struct text_message * no_message)
60{
61 int i;
62 unsigned button;
63 int result=-1;
64 bool result_displayed;
65 struct gui_yesno yn[NB_SCREENS];
66 FOR_NB_SCREENS(i)
67 {
68 gui_yesno_init(&(yn[i]), main_message, yes_message, no_message);
69 gui_yesno_set_display(&(yn[i]), &(screens[i]));
70 gui_yesno_draw(&(yn[i]));
71 }
72 while (result==-1)
73 {
74 button = button_get(true);
75 switch (button)
76 {
77 case YESNO_OK:
78#ifdef TREE_RC_RUN
79 case YESNO_RC_OK:
80#endif
81 result=YESNO_YES;
82 break;
83
84 default:
85 if(default_event_handler(button) == SYS_USB_CONNECTED)
86 return(YESNO_USB);
87 if(!(button & BUTTON_REL))
88 result=YESNO_NO;
89 }
90 }
91 FOR_NB_SCREENS(i)
92 result_displayed=gui_yesno_draw_result(&(yn[i]), result);
93 if(result_displayed)
94 sleep(HZ);
95 return(result);
96}
diff --git a/apps/gui/yesno.h b/apps/gui/yesno.h
new file mode 100644
index 0000000000..ac6500daf8
--- /dev/null
+++ b/apps/gui/yesno.h
@@ -0,0 +1,91 @@
1#ifndef _GUI_YESNO_H_
2#define _GUI_YESNO_H_
3
4#include "screen_access.h"
5#include "textarea.h"
6
7#if (CONFIG_KEYPAD == IRIVER_H100_PAD) || \
8 (CONFIG_KEYPAD == IRIVER_H300_PAD)
9#define YESNO_OK BUTTON_SELECT
10#define YESNO_RC_OK BUTTON_RC_MENU
11
12#elif CONFIG_KEYPAD == RECORDER_PAD
13#define YESNO_OK BUTTON_PLAY
14#define YESNO_RC_OK BUTTON_RC_PLAY
15
16#elif CONFIG_KEYPAD == PLAYER_PAD
17#define YESNO_OK BUTTON_PLAY
18#define YESNO_RC_OK BUTTON_RC_PLAY
19
20#elif CONFIG_KEYPAD == ONDIO_PAD
21#define YESNO_OK BUTTON_RIGHT
22
23#elif CONFIG_KEYPAD == GMINI100_PAD
24#define YESNO_OK BUTTON_PLAY
25
26#elif (CONFIG_KEYPAD == IPOD_4G_PAD) || (CONFIG_KEYPAD == IPOD_NANO_PAD)
27#define YESNO_OK BUTTON_RIGHT
28#endif
29enum yesno_res
30{
31 YESNO_YES,
32 YESNO_NO,
33 YESNO_USB
34};
35
36struct gui_yesno
37{
38 struct text_message * main_message;
39 struct text_message * result_message[2];
40
41 struct screen * display;
42};
43
44/*
45 * Initializes the yesno asker
46 * - yn : the yesno structure
47 * - main_message : the question the user has to answer
48 * - yes_message : message displayed if answer is 'yes'
49 * - no_message : message displayed if answer is 'no'
50 */
51extern void gui_yesno_init(struct gui_yesno * yn,
52 struct text_message * main_message,
53 struct text_message * yes_message,
54 struct text_message * no_message);
55
56/*
57 * Attach the yesno to a screen
58 * - yn : the yesno structure
59 * - display : the screen to attach
60 */
61extern void gui_yesno_set_display(struct gui_yesno * yn,
62 struct screen * display);
63
64/*
65 * Draws the yesno
66 * - yn : the yesno structure
67 */
68extern void gui_yesno_draw(struct gui_yesno * yn);
69
70/*
71 * Draws the yesno result
72 * - yn : the yesno structure
73 * - result : the result tha must be displayed :
74 * YESNO_NO if no
75 * YESNO_YES if yes
76 */
77extern bool gui_yesno_draw_result(struct gui_yesno * yn, enum yesno_res result);
78
79/*
80 * Runs the yesno asker :
81 * it will display the 'main_message' question, and wait for user keypress
82 * PLAY means yes, other keys means no
83 * - main_message : the question the user has to answer
84 * - yes_message : message displayed if answer is 'yes'
85 * - no_message : message displayed if answer is 'no'
86 */
87extern enum yesno_res gui_syncyesno_run(
88 struct text_message * main_message,
89 struct text_message * yes_message,
90 struct text_message * no_message);
91#endif /* _GUI_YESNO_H_ */
diff --git a/apps/settings_menu.c b/apps/settings_menu.c
index 8695177a00..82c25af433 100644
--- a/apps/settings_menu.c
+++ b/apps/settings_menu.c
@@ -52,6 +52,7 @@
52#include "dir.h" 52#include "dir.h"
53#include "dircache.h" 53#include "dircache.h"
54#include "splash.h" 54#include "splash.h"
55#include "yesno.h"
55 56
56#ifdef HAVE_LCD_BITMAP 57#ifdef HAVE_LCD_BITMAP
57#include "peakmeter.h" 58#include "peakmeter.h"
@@ -1428,49 +1429,24 @@ static bool bookmark_settings_menu(void)
1428} 1429}
1429static bool reset_settings(void) 1430static bool reset_settings(void)
1430{ 1431{
1431 bool done=false; 1432 char *lines[]={str(LANG_RESET_ASK_RECORDER)};
1432 int line; 1433 char *yes_lines[]={str(LANG_RESET_DONE_SETTING), str(LANG_RESET_DONE_CLEAR)};
1433 int button; 1434 char *no_lines[]={yes_lines[0], str(LANG_RESET_DONE_CANCEL)};
1434 1435 struct text_message message={lines, 1};
1435 lcd_clear_display(); 1436 struct text_message yes_message={yes_lines, 2};
1437 struct text_message no_message={no_lines, 2};
1436 1438
1437#ifdef HAVE_LCD_CHARCELLS 1439 switch(gui_syncyesno_run(&message, &yes_message, &no_message))
1438 line = 0; 1440 {
1439#else 1441 case YESNO_YES:
1440 line = 1; 1442 settings_reset();
1441 lcd_puts(0,0,str(LANG_RESET_ASK_RECORDER)); 1443 settings_apply();
1442#endif 1444 break;
1443 lcd_puts(0,line,str(LANG_RESET_CONFIRM)); 1445 case YESNO_NO:
1444 lcd_puts(0,line+1,str(LANG_RESET_CANCEL)); 1446 break;
1445 1447 case YESNO_USB:
1446 lcd_update(); 1448 return true;
1447
1448 while(!done) {
1449 button = button_get(true);
1450 switch(button) {
1451 case SETTINGS_OK:
1452 settings_reset();
1453 settings_apply();
1454 lcd_clear_display();
1455 lcd_puts(0,1,str(LANG_RESET_DONE_CLEAR));
1456 done = true;
1457 break;
1458
1459 case SETTINGS_CANCEL:
1460 lcd_clear_display();
1461 lcd_puts(0,1,str(LANG_RESET_DONE_CANCEL));
1462 done = true;
1463 break;
1464
1465 default:
1466 if(default_event_handler(button) == SYS_USB_CONNECTED)
1467 return true;
1468 }
1469 } 1449 }
1470
1471 lcd_puts(0,0,str(LANG_RESET_DONE_SETTING));
1472 lcd_update();
1473 sleep(HZ);
1474 return false; 1450 return false;
1475} 1451}
1476 1452
diff --git a/apps/tree.c b/apps/tree.c
index 39980b1b81..284fdcbdc7 100644
--- a/apps/tree.c
+++ b/apps/tree.c
@@ -61,6 +61,7 @@
61#include "recorder/recording.h" 61#include "recorder/recording.h"
62#include "rtc.h" 62#include "rtc.h"
63#include "dircache.h" 63#include "dircache.h"
64#include "yesno.h"
64 65
65/* gui api */ 66/* gui api */
66#include "list.h" 67#include "list.h"
@@ -561,47 +562,17 @@ static bool dirbrowse(void)
561 while(1) { 562 while(1) {
562 struct entry *dircache = tc.dircache; 563 struct entry *dircache = tc.dircache;
563 bool restore = false; 564 bool restore = false;
564
565 button = button_get_w_tmo(HZ/5);
566#ifdef BOOTFILE 565#ifdef BOOTFILE
567 if (boot_changed) { 566 if (boot_changed) {
568 bool stop = false; 567 char *lines[]={str(LANG_BOOT_CHANGED), str(LANG_REBOOT_NOW)};
569 unsigned int button; 568 struct text_message message={lines, 2};
570 int i; 569 if(gui_syncyesno_run(&message, NULL, NULL)==YESNO_YES)
571 FOR_NB_SCREENS(i) 570 rolo_load("/" BOOTFILE);
572 {
573 gui_textarea_clear(&screens[i]);
574 screens[i].puts(0,0,str(LANG_BOOT_CHANGED));
575 screens[i].puts(0,1,str(LANG_REBOOT_NOW));
576#ifdef HAVE_LCD_BITMAP
577 screens[i].puts(0,3,str(LANG_CONFIRM_WITH_PLAY_RECORDER));
578 screens[i].puts(0,4,str(LANG_CANCEL_WITH_ANY_RECORDER));
579 gui_textarea_update(&screens[i]);
580#endif
581 }
582 while (!stop) {
583 button = button_get(true);
584 switch (button) {
585 case TREE_RUN:
586#ifdef TREE_RC_RUN
587 case TREE_RC_RUN:
588#endif
589 rolo_load("/" BOOTFILE);
590 stop = true;
591 break;
592
593 default:
594 if(default_event_handler(button) ||
595 (button & BUTTON_REL))
596 stop = true;
597 break;
598 }
599 }
600
601 restore = true; 571 restore = true;
602 boot_changed = false; 572 boot_changed = false;
603 } 573 }
604#endif 574#endif
575 button = button_get_w_tmo(HZ/5);
605 need_update = gui_synclist_do_button(&tree_lists, button); 576 need_update = gui_synclist_do_button(&tree_lists, button);
606 577
607 switch ( button ) { 578 switch ( button ) {
diff --git a/apps/tree.h b/apps/tree.h
index 55dfc562b9..aa7571acdc 100644
--- a/apps/tree.h
+++ b/apps/tree.h
@@ -46,18 +46,18 @@
46#define TREE_QUICK (BUTTON_MODE | BUTTON_REPEAT) 46#define TREE_QUICK (BUTTON_MODE | BUTTON_REPEAT)
47 47
48/* Remote keys */ 48/* Remote keys */
49#define TREE_RC_NEXT BUTTON_RC_FF 49#define TREE_RC_NEXT BUTTON_RC_FF
50#define TREE_RC_PREV BUTTON_RC_REW 50#define TREE_RC_PREV BUTTON_RC_REW
51#define TREE_RC_PGUP BUTTON_RC_SOURCE 51#define TREE_RC_PGUP BUTTON_RC_SOURCE
52#define TREE_RC_PGDN BUTTON_RC_BITRATE 52#define TREE_RC_PGDN BUTTON_RC_BITRATE
53#define TREE_RC_EXIT BUTTON_RC_STOP 53#define TREE_RC_EXIT BUTTON_RC_STOP
54#define TREE_RC_RUN (BUTTON_RC_MENU | BUTTON_REL) 54#define TREE_RC_RUN (BUTTON_RC_MENU | BUTTON_REL)
55#define TREE_RC_RUN_PRE BUTTON_RC_MENU 55#define TREE_RC_RUN_PRE BUTTON_RC_MENU
56#define TREE_RC_MENU ( BUTTON_RC_MODE | BUTTON_REL) 56#define TREE_RC_MENU (BUTTON_RC_MODE | BUTTON_REL)
57#define TREE_RC_MENU_PRE BUTTON_RC_MODE 57#define TREE_RC_MENU_PRE BUTTON_RC_MODE
58#define TREE_RC_WPS (BUTTON_RC_ON | BUTTON_REL) 58#define TREE_RC_WPS (BUTTON_RC_ON | BUTTON_REL)
59#define TREE_RC_WPS_PRE BUTTON_RC_ON 59#define TREE_RC_WPS_PRE BUTTON_RC_ON
60#define TREE_RC_CONTEXT (BUTTON_RC_ON | BUTTON_REPEAT) 60#define TREE_RC_CONTEXT (BUTTON_RC_ON | BUTTON_REPEAT)
61 61
62#elif CONFIG_KEYPAD == RECORDER_PAD 62#elif CONFIG_KEYPAD == RECORDER_PAD
63#define TREE_NEXT BUTTON_DOWN 63#define TREE_NEXT BUTTON_DOWN