text_viewer: callback functions are changed to the function that returns int value.

And the text viewer quits when the problem occurs by callback functions.

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@27172 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Yoshihisa Uchida 2010-06-29 11:05:36 +00:00
parent 7195f3a30c
commit 07d03729ff
13 changed files with 56 additions and 25 deletions

View file

@ -73,6 +73,8 @@ enum plugin_status plugin_start(const void* file)
done = true;
if (res == TV_MENU_RESULT_ATTACHED_USB)
return PLUGIN_USB_CONNECTED;
else if (res == TV_MENU_RESULT_ERROR)
return PLUGIN_ERROR;
}
}
break;

View file

@ -42,7 +42,8 @@ bool tv_init(const unsigned char *file)
return false;
/* load the preferences and bookmark */
tv_load_settings(file);
if (!tv_load_settings(file))
return false;
/* select to read the page */
tv_select_bookmark();

View file

@ -98,15 +98,16 @@ static int tv_find_bookmark(const struct tv_screen_pos *pos)
return -1;
}
static void tv_change_preferences(const struct tv_preferences *oldp)
static int tv_change_preferences(const struct tv_preferences *oldp)
{
int i;
if (oldp == NULL)
return;
for (i = 0; i < bookmark_count; i++)
tv_convert_fpos(bookmarks[i].pos.file_pos, &bookmarks[i].pos);
if (oldp)
{
for (i = 0; i < bookmark_count; i++)
tv_convert_fpos(bookmarks[i].pos.file_pos, &bookmarks[i].pos);
}
return TV_CALLBACK_OK;
}
void tv_init_bookmark(void)

View file

@ -349,7 +349,7 @@ static bool tv_set_font(const unsigned char *font)
}
#endif
static void tv_change_preferences(const struct tv_preferences *oldp)
static int tv_change_preferences(const struct tv_preferences *oldp)
{
#ifdef HAVE_LCD_BITMAP
static bool font_changing = false;
@ -363,10 +363,18 @@ static void tv_change_preferences(const struct tv_preferences *oldp)
{
if (!tv_set_font(preferences->font_name))
{
/*
* tv_set_font(rb->global_settings->font_file) doesn't fail usually.
* if it fails, a fatal problem occurs in Rockbox.
*/
if (!rb->strcmp(preferences->font_name, rb->global_settings->font_file))
return TV_CALLBACK_ERROR;
font_changing = true;
tv_copy_preferences(&new_prefs);
rb->strlcpy(new_prefs.font_name, font_str, MAX_PATH);
tv_set_preferences(&new_prefs);
return (tv_set_preferences(&new_prefs))? TV_CALLBACK_STOP : TV_CALLBACK_ERROR;
}
col_width = 2 * rb->font_get_width(preferences->font, ' ');
font_changing = false;
@ -375,6 +383,7 @@ static void tv_change_preferences(const struct tv_preferences *oldp)
(void)oldp;
#endif
tv_change_viewport();
return TV_CALLBACK_OK;
}
bool tv_init_display(unsigned char **buf, size_t *size)

View file

@ -366,7 +366,8 @@ unsigned tv_display_menu(void)
case 1: /* change settings */
tv_copy_preferences(&new_prefs);
result = tv_options_menu();
tv_set_preferences(&new_prefs);
if (!tv_set_preferences(&new_prefs))
result = TV_MENU_RESULT_ERROR;
break;
case 2: /* playback control */
playback_control(NULL);

View file

@ -28,6 +28,7 @@ enum {
TV_MENU_RESULT_EXIT_MENU,
TV_MENU_RESULT_EXIT_PLUGIN,
TV_MENU_RESULT_ATTACHED_USB,
TV_MENU_RESULT_ERROR,
};
/*

View file

@ -73,7 +73,7 @@ static off_t tv_get_fpos(int page)
return 0;
}
static void tv_change_preferences(const struct tv_preferences *oldp)
static int tv_change_preferences(const struct tv_preferences *oldp)
{
(void)oldp;
@ -83,6 +83,7 @@ static void tv_change_preferences(const struct tv_preferences *oldp)
max_page = TV_MAX_PAGE - 1;
tv_set_fpos(cur_pos.page, 0);
tv_seek(0, SEEK_SET);
return TV_CALLBACK_OK;
}
bool tv_init_pager(unsigned char **buf, size_t *size)

View file

@ -31,11 +31,12 @@ const struct tv_preferences * const preferences = &prefs;
static int listner_count = 0;
#define TV_MAX_LISTNERS 5
static void (*listners[TV_MAX_LISTNERS])(const struct tv_preferences *oldp);
static int (*listners[TV_MAX_LISTNERS])(const struct tv_preferences *oldp);
static void tv_notify_change_preferences(const struct tv_preferences *oldp)
static bool tv_notify_change_preferences(const struct tv_preferences *oldp)
{
int i;
int res = TV_CALLBACK_OK;
/*
* the following items do not check.
@ -65,11 +66,13 @@ static void tv_notify_change_preferences(const struct tv_preferences *oldp)
{
/* callback functions are called as FILO */
for (i = listner_count - 1; i >= 0; i--)
listners[i](oldp);
if ((res = listners[i](oldp)) != TV_CALLBACK_OK)
break;
}
return (res != TV_CALLBACK_ERROR);
}
void tv_set_preferences(const struct tv_preferences *new_prefs)
bool tv_set_preferences(const struct tv_preferences *new_prefs)
{
static struct tv_preferences old_prefs;
struct tv_preferences *oldp = NULL;
@ -80,7 +83,7 @@ void tv_set_preferences(const struct tv_preferences *new_prefs)
is_initialized = true;
rb->memcpy(&prefs, new_prefs, sizeof(struct tv_preferences));
tv_notify_change_preferences(oldp);
return tv_notify_change_preferences(oldp);
}
void tv_copy_preferences(struct tv_preferences *copy_prefs)
@ -118,7 +121,7 @@ void tv_set_default_preferences(struct tv_preferences *p)
p->file_name[0] = '\0';
}
void tv_add_preferences_change_listner(void (*listner)(const struct tv_preferences *oldp))
void tv_add_preferences_change_listner(int (*listner)(const struct tv_preferences *oldp))
{
if (listner_count < TV_MAX_LISTNERS)
listners[listner_count++] = listner;

View file

@ -23,6 +23,12 @@
#ifndef PLUGIN_TEXT_VIEWER_PREFERENCES_H
#define PLUGIN_TEXT_VIEWER_PREFERENCES_H
enum {
TV_CALLBACK_OK,
TV_CALLBACK_STOP,
TV_CALLBACK_ERROR,
};
/* scrollbar_mode */
enum {
SB_OFF = 0,
@ -129,8 +135,12 @@ extern const struct tv_preferences * const preferences;
*
* [In] new_prefs
* new preferences
*
* return
* true success
* false error
*/
void tv_set_preferences(const struct tv_preferences *new_prefs);
bool tv_set_preferences(const struct tv_preferences *new_prefs);
/*
* copy the preferences
@ -154,6 +164,6 @@ void tv_set_default_preferences(struct tv_preferences *p);
* [In] listner
* the function to be executed when the current preferences is changed
*/
void tv_add_preferences_change_listner(void (*listner)(const struct tv_preferences *oldp));
void tv_add_preferences_change_listner(int (*listner)(const struct tv_preferences *oldp));
#endif

View file

@ -132,7 +132,7 @@ void tv_seek(off_t offset, int whence)
}
}
static void tv_change_preferences(const struct tv_preferences *oldp)
static int tv_change_preferences(const struct tv_preferences *oldp)
{
unsigned char bom[BOM_SIZE];
int cur_start_file_pos = start_file_pos;
@ -151,7 +151,7 @@ static void tv_change_preferences(const struct tv_preferences *oldp)
fd = rb->open(preferences->file_name, O_RDONLY);
if (fd < 0)
return;
return TV_CALLBACK_ERROR;
}
/*
@ -168,6 +168,7 @@ static void tv_change_preferences(const struct tv_preferences *oldp)
file_size = rb->filesize(fd) - start_file_pos;
tv_seek(cur_file_pos + cur_start_file_pos - start_file_pos, SEEK_SET);
return TV_CALLBACK_OK;
}
bool tv_init_reader(unsigned char **buf, size_t *size)

View file

@ -417,7 +417,7 @@ bool tv_save_global_settings(const struct tv_preferences *prefs)
* ----------------------------------------------------------------------------
*/
void tv_load_settings(const unsigned char *file_name)
bool tv_load_settings(const unsigned char *file_name)
{
unsigned char buf[MAX_PATH+2];
unsigned int fcount;
@ -470,7 +470,7 @@ void tv_load_settings(const unsigned char *file_name)
tv_set_default_preferences(&prefs);
}
rb->strlcpy(prefs.file_name, file_name, MAX_PATH);
tv_set_preferences(&prefs);
return tv_set_preferences(&prefs);
}
static bool tv_copy_settings(int sfd, int dfd, int size)

View file

@ -59,7 +59,7 @@ bool tv_save_global_settings(const struct tv_preferences *prefs);
* true success
* false failure
*/
void tv_load_settings(const unsigned char *file_name);
bool tv_load_settings(const unsigned char *file_name);
/*
* save the settings at each file

View file

@ -102,7 +102,7 @@ bool tv_traverse_lines(void)
return res;
}
static void tv_change_preferences(const struct tv_preferences *oldp)
static int tv_change_preferences(const struct tv_preferences *oldp)
{
bool need_vertical_scrollbar = false;
@ -131,6 +131,7 @@ static void tv_change_preferences(const struct tv_preferences *oldp)
cur_column = 0;
tv_set_read_conditions(preferences->windows, window_width);
return TV_CALLBACK_OK;
}
bool tv_init_window(unsigned char **buf, size_t *size)