From 2cdf332f01bf3a9904f8322596bb81740ea3fe6b Mon Sep 17 00:00:00 2001 From: Yoshihisa Uchida Date: Fri, 2 Jul 2010 12:16:47 +0000 Subject: text viewer: for tv_action and tv_bookmark, the prototype of the initializer is the same arguments as other modules. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@27243 a1c6a512-1295-4272-9138-f99709370657 --- apps/plugins/text_viewer/text_viewer.c | 12 +++++++++- apps/plugins/text_viewer/tv_action.c | 43 ++++++++++++++++++++-------------- apps/plugins/text_viewer/tv_action.h | 23 ++++++++++++++---- apps/plugins/text_viewer/tv_bookmark.c | 11 ++++++++- apps/plugins/text_viewer/tv_bookmark.h | 19 +++++++++++++-- 5 files changed, 83 insertions(+), 25 deletions(-) (limited to 'apps/plugins/text_viewer') diff --git a/apps/plugins/text_viewer/text_viewer.c b/apps/plugins/text_viewer/text_viewer.c index e5f3160bb6..ca5cf70d36 100644 --- a/apps/plugins/text_viewer/text_viewer.c +++ b/apps/plugins/text_viewer/text_viewer.c @@ -35,13 +35,23 @@ enum plugin_status plugin_start(const void* file) long old_tick; bool done = false; bool display_update = true; + size_t size; + unsigned char *plugin_buf; old_tick = *rb->current_tick; if (!file) return PLUGIN_ERROR; - if (!tv_init(file)) { + /* get the plugin buffer */ + plugin_buf = rb->plugin_get_buffer(&size); + + if (!tv_init_action(&plugin_buf, &size)) { + rb->splash(HZ, "Error initialize"); + return PLUGIN_ERROR; + } + + if (!tv_load_file(file)) { rb->splash(HZ, "Error opening file"); return PLUGIN_ERROR; } diff --git a/apps/plugins/text_viewer/tv_action.c b/apps/plugins/text_viewer/tv_action.c index b8542daafe..c95ece0649 100644 --- a/apps/plugins/text_viewer/tv_action.c +++ b/apps/plugins/text_viewer/tv_action.c @@ -28,26 +28,23 @@ #include "tv_settings.h" #include "tv_window.h" -bool tv_init(const unsigned char *file) +bool tv_init_action(unsigned char **buf, size_t *size) { - size_t size; - - /* get the plugin buffer */ - unsigned char *buf = rb->plugin_get_buffer(&size); - - tv_init_bookmark(); + /* initialize bookmarks and window modules */ + return tv_init_bookmark(buf, size) && tv_init_window(buf, size); +} - /* initialize modules */ - if (!tv_init_window(&buf, &size)) - return false; +static void tv_finalize_action(void) +{ + /* save preference and bookmarks */ + if (!tv_save_settings()) + rb->splash(HZ, "Can't save preferences and bookmarks"); - /* load the preferences and bookmark */ - if (!tv_load_settings(file)) - return false; + /* finalize bookmark modules */ + tv_finalize_bookmark(); - /* select to read the page */ - tv_select_bookmark(); - return true; + /* finalize window modules */ + tv_finalize_window(); } void tv_exit(void *parameter) @@ -59,7 +56,19 @@ void tv_exit(void *parameter) rb->splash(HZ, "Can't save preferences and bookmarks"); /* finalize modules */ - tv_finalize_window(); + tv_finalize_action(); +} + +bool tv_load_file(const unsigned char *file) +{ + /* load the preferences and bookmark */ + if (!tv_load_settings(file)) + return false; + + /* select to read the page */ + tv_select_bookmark(); + + return true; } void tv_draw(void) diff --git a/apps/plugins/text_viewer/tv_action.h b/apps/plugins/text_viewer/tv_action.h index f774f07422..fba008dbe9 100644 --- a/apps/plugins/text_viewer/tv_action.h +++ b/apps/plugins/text_viewer/tv_action.h @@ -42,16 +42,19 @@ enum }; /* - * initialize modules + * initialize the action module * - * [In] file - * read file name + * [In/Out] buf + * the start pointer of the buffer + * + * [In/Out] size + * buffer size * * return * true initialize success * false initialize failure */ -bool tv_init(const unsigned char *file); +bool tv_init_action(unsigned char **buf, size_t *bufsize); /* * finalize modules @@ -61,6 +64,18 @@ bool tv_init(const unsigned char *file); */ void tv_exit(void *parameter); +/* + * load the file + * + * [In] file + * read file name + * + * return + * true load success + * false load failure + */ +bool tv_load_file(const unsigned char *file); + /* draw the current page */ void tv_draw(void); diff --git a/apps/plugins/text_viewer/tv_bookmark.c b/apps/plugins/text_viewer/tv_bookmark.c index 7e38d766ec..c6574dbb6f 100644 --- a/apps/plugins/text_viewer/tv_bookmark.c +++ b/apps/plugins/text_viewer/tv_bookmark.c @@ -110,9 +110,18 @@ static int tv_change_preferences(const struct tv_preferences *oldp) return TV_CALLBACK_OK; } -void tv_init_bookmark(void) +bool tv_init_bookmark(unsigned char **buf, size_t *size) { + (void)buf; + (void)size; + tv_add_preferences_change_listner(tv_change_preferences); + return true; +} + +void tv_finalize_bookmark(void) +{ + /* no-operation function */ } int tv_get_bookmark_positions(struct tv_screen_pos *pos_array) diff --git a/apps/plugins/text_viewer/tv_bookmark.h b/apps/plugins/text_viewer/tv_bookmark.h index d61af41620..b0b91077d4 100644 --- a/apps/plugins/text_viewer/tv_bookmark.h +++ b/apps/plugins/text_viewer/tv_bookmark.h @@ -30,8 +30,23 @@ /* Maximum amount of register possible bookmarks */ #define TV_MAX_BOOKMARKS 16 -/* initialize the bookmark module */ -void tv_init_bookmark(void); +/* + * initialize the bookmark module + * + * [In/Out] buf + * the start pointer of the buffer + * + * [In/Out] size + * buffer size + * + * return + * true initialize success + * false initialize failure + */ +bool tv_init_bookmark(unsigned char **buf, size_t *size); + +/* finalize the bookmark module */ +void tv_finalize_bookmark(void); /* * get the positions which registered bookmarks -- cgit v1.2.3