Make kbd_input() show a cancel splash to indicate user abort better and for better consistency all over the place. Change checking for its return value (style-wise) at some places too.

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@22269 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Thomas Martitz 2009-08-12 14:38:25 +00:00
parent 345920fe7e
commit 18e40e0f4c
11 changed files with 26 additions and 21 deletions

View file

@ -112,6 +112,7 @@ int kbd_input(char* text, int buflen)
unsigned char *utf8; unsigned char *utf8;
int button, lastbutton = 0; int button, lastbutton = 0;
int ret;
editpos = utf8length(text); editpos = utf8length(text);
@ -185,7 +186,7 @@ int kbd_input(char* text, int buflen)
switch (button) switch (button)
{ {
case BUTTON_STOP: /* abort */ case BUTTON_STOP: /* abort */
return -1; ret = -1; done = true;
break; break;
case BUTTON_MENU: /* page flip */ case BUTTON_MENU: /* page flip */
@ -245,7 +246,7 @@ int kbd_input(char* text, int buflen)
case BUTTON_PLAY | BUTTON_REPEAT: case BUTTON_PLAY | BUTTON_REPEAT:
/* accepts what was entered and continues */ /* accepts what was entered and continues */
done = true; ret = 0; done = true;
break; break;
case BUTTON_PLAY | BUTTON_REL: case BUTTON_PLAY | BUTTON_REL:
@ -304,6 +305,8 @@ int kbd_input(char* text, int buflen)
lastbutton = button; lastbutton = button;
} }
return 0; if (ret < 0)
splash(HZ/2, ID2P(LANG_CANCEL));
return ret;
} }

View file

@ -802,7 +802,7 @@ bool search_playlist(void)
if (!playlist_viewer_init(&viewer, 0, false)) if (!playlist_viewer_init(&viewer, 0, false))
return ret; return ret;
if (kbd_input(search_str, sizeof(search_str)) == -1) if (kbd_input(search_str, sizeof(search_str)) < 0)
return ret; return ret;
lcd_clear_display(); lcd_clear_display();
playlist_count = playlist_amount_ex(viewer.playlist); playlist_count = playlist_amount_ex(viewer.playlist);

View file

@ -568,7 +568,7 @@ static void add_memo(struct shown *shown, int type)
{ {
bool saved = false; bool saved = false;
if (rb->kbd_input(memos[memos_in_memory].message, if (rb->kbd_input(memos[memos_in_memory].message,
sizeof memos[memos_in_memory].message) != -1) sizeof memos[memos_in_memory].message) == 0)
{ {
if (rb->strlen(memos[memos_in_memory].message)) if (rb->strlen(memos[memos_in_memory].message))
{ {
@ -634,7 +634,7 @@ static bool edit_memo(int change, struct shown *shown)
case 1: /* edit */ case 1: /* edit */
if(rb->kbd_input(memos[pointer_array[change]].message, if(rb->kbd_input(memos[pointer_array[change]].message,
sizeof memos[pointer_array[change]].message) != -1) sizeof memos[pointer_array[change]].message) == 0)
save_memo(pointer_array[change],true,shown); save_memo(pointer_array[change],true,shown);
return false; return false;

View file

@ -190,12 +190,12 @@ static void add_entry(int selected_item)
rb->splash(HZ, "Enter title"); rb->splash(HZ, "Enter title");
pw_list.entries[i].title[0] = '\0'; pw_list.entries[i].title[0] = '\0';
if (rb->kbd_input(pw_list.entries[i].title, FIELD_LEN)) if (rb->kbd_input(pw_list.entries[i].title, FIELD_LEN) < 0)
return; return;
rb->splash(HZ, "Enter name"); rb->splash(HZ, "Enter name");
pw_list.entries[i].name[0] = '\0'; pw_list.entries[i].name[0] = '\0';
if (rb->kbd_input(pw_list.entries[i].name, FIELD_LEN)) if (rb->kbd_input(pw_list.entries[i].name, FIELD_LEN) < 0)
{ {
pw_list.entries[i].title[0] = '\0'; pw_list.entries[i].title[0] = '\0';
return; return;
@ -203,7 +203,7 @@ static void add_entry(int selected_item)
rb->splash(HZ, "Enter password"); rb->splash(HZ, "Enter password");
pw_list.entries[i].password[0] = '\0'; pw_list.entries[i].password[0] = '\0';
if (rb->kbd_input(pw_list.entries[i].password, FIELD_LEN)) if (rb->kbd_input(pw_list.entries[i].password, FIELD_LEN) < 0)
{ {
pw_list.entries[i].title[0] = '\0'; pw_list.entries[i].title[0] = '\0';
pw_list.entries[i].name[0] = '\0'; pw_list.entries[i].name[0] = '\0';
@ -508,11 +508,11 @@ static int enter_pw(char *pw_buf, size_t buflen, bool new_pw)
if (new_pw) if (new_pw)
{ {
rb->splash(HZ, "Enter new master password"); rb->splash(HZ, "Enter new master password");
if (rb->kbd_input(buf[0], sizeof(buf[0]))) if (rb->kbd_input(buf[0], sizeof(buf[0])) < 0)
return -1; return -1;
rb->splash(HZ, "Confirm master password"); rb->splash(HZ, "Confirm master password");
if (rb->kbd_input(buf[1], sizeof(buf[1]))) if (rb->kbd_input(buf[1], sizeof(buf[1])) < 0)
return -1; return -1;
if (rb->strcmp(buf[0], buf[1])) if (rb->strcmp(buf[0], buf[1]))
@ -529,7 +529,7 @@ static int enter_pw(char *pw_buf, size_t buflen, bool new_pw)
} }
rb->splash(HZ, "Enter master password"); rb->splash(HZ, "Enter master password");
if (rb->kbd_input(pw_buf, buflen)) if (rb->kbd_input(pw_buf, buflen) < 0)
return -1; return -1;
hash_pw(&pwhash); hash_pw(&pwhash);
return 0; return 0;

View file

@ -227,7 +227,7 @@ static bool do_slot(size_t slot_id, bool is_load) {
/* if we're saving to a slot, then get a brief description */ /* if we're saving to a slot, then get a brief description */
if (!is_load) if (!is_load)
if (rb->kbd_input(desc_buf, 20) || !strlen(desc_buf)) if (rb->kbd_input(desc_buf, 20) || !strlen(desc_buf) < 0)
{ {
strlcpy(desc_buf, "Untitled", 20); strlcpy(desc_buf, "Untitled", 20);
} }

View file

@ -182,10 +182,9 @@ bool save_changes(int overwrite)
if (newfile || !overwrite) if (newfile || !overwrite)
{ {
if(rb->kbd_input(filename,MAX_PATH)) if(rb->kbd_input(filename,MAX_PATH) < 0)
{ {
newfile = true; newfile = true;
rb->splash(HZ, "Cancelled");
return false; return false;
} }
} }

View file

@ -297,6 +297,7 @@ int kbd_input(char* text, int buflen)
unsigned short ch; unsigned short ch;
unsigned char *utf8; unsigned char *utf8;
bool cur_blink = true; /* Cursor on/off flag */ bool cur_blink = true; /* Cursor on/off flag */
int ret;
#ifdef KBD_MORSE_INPUT #ifdef KBD_MORSE_INPUT
bool morse_reading = false; bool morse_reading = false;
unsigned char morse_code = 0; unsigned char morse_code = 0;
@ -779,7 +780,7 @@ int kbd_input(char* text, int buflen)
global_settings.buttonbar=buttonbar_config; global_settings.buttonbar=buttonbar_config;
#endif #endif
viewportmanager_set_statusbar(oldbars); viewportmanager_set_statusbar(oldbars);
return -1; ret = -1; done = true;
break; break;
case ACTION_KBD_PAGE_FLIP: case ACTION_KBD_PAGE_FLIP:
@ -1000,6 +1001,7 @@ int kbd_input(char* text, int buflen)
case ACTION_KBD_DONE: case ACTION_KBD_DONE:
/* accepts what was entered and continues */ /* accepts what was entered and continues */
ret = 0;
done = true; done = true;
break; break;
@ -1249,5 +1251,7 @@ int kbd_input(char* text, int buflen)
screens[l].setfont(FONT_UI); screens[l].setfont(FONT_UI);
viewportmanager_set_statusbar(oldbars); viewportmanager_set_statusbar(oldbars);
return 0; if (ret < 0)
splash(HZ/2, ID2P(LANG_CANCEL));
return ret;
} }

View file

@ -652,7 +652,6 @@ bool settings_save_config(int options)
break; break;
} }
else { else {
splash(HZ, ID2P(LANG_CANCEL));
return false; return false;
} }
} }

View file

@ -1483,7 +1483,7 @@ int tagtree_enter(struct tree_context* c)
else else
{ {
rc = kbd_input(searchstring, SEARCHSTR_SIZE); rc = kbd_input(searchstring, SEARCHSTR_SIZE);
if (rc == -1 || !searchstring[0]) if (rc < 0 || !searchstring[0])
{ {
tagtree_exit(c); tagtree_exit(c);
return 0; return 0;

View file

@ -739,7 +739,7 @@ Misc
int kbd_input(char *buffer, int buflen); int kbd_input(char *buffer, int buflen);
Prompt for a string to be stored in buffer which is of length buflen. Prompt for a string to be stored in buffer which is of length buflen.
Return FALSE upon success. Return 0 upon success, negative on failure.
struct tm *get_time(void); struct tm *get_time(void);

View file

@ -851,7 +851,7 @@ int kbd_input(char* buffer, int buflen)
\group misc \group misc
\param buffer \param buffer
\param buflen \param buflen
\return FALSE upon success \return 0 upon success, negative upon failure
\description Prompt for a string to be stored in =buffer= which is of length =buflen= \description Prompt for a string to be stored in =buffer= which is of length =buflen=
void lcd_bitmap(const fb_data *src, int x, int y, int width, int height) void lcd_bitmap(const fb_data *src, int x, int y, int width, int height)