summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apps/plugins/text_viewer/text_viewer.c12
-rw-r--r--apps/plugins/text_viewer/tv_action.c43
-rw-r--r--apps/plugins/text_viewer/tv_action.h23
-rw-r--r--apps/plugins/text_viewer/tv_bookmark.c11
-rw-r--r--apps/plugins/text_viewer/tv_bookmark.h19
5 files changed, 83 insertions, 25 deletions
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)
35 long old_tick; 35 long old_tick;
36 bool done = false; 36 bool done = false;
37 bool display_update = true; 37 bool display_update = true;
38 size_t size;
39 unsigned char *plugin_buf;
38 40
39 old_tick = *rb->current_tick; 41 old_tick = *rb->current_tick;
40 42
41 if (!file) 43 if (!file)
42 return PLUGIN_ERROR; 44 return PLUGIN_ERROR;
43 45
44 if (!tv_init(file)) { 46 /* get the plugin buffer */
47 plugin_buf = rb->plugin_get_buffer(&size);
48
49 if (!tv_init_action(&plugin_buf, &size)) {
50 rb->splash(HZ, "Error initialize");
51 return PLUGIN_ERROR;
52 }
53
54 if (!tv_load_file(file)) {
45 rb->splash(HZ, "Error opening file"); 55 rb->splash(HZ, "Error opening file");
46 return PLUGIN_ERROR; 56 return PLUGIN_ERROR;
47 } 57 }
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 @@
28#include "tv_settings.h" 28#include "tv_settings.h"
29#include "tv_window.h" 29#include "tv_window.h"
30 30
31bool tv_init(const unsigned char *file) 31bool tv_init_action(unsigned char **buf, size_t *size)
32{ 32{
33 size_t size; 33 /* initialize bookmarks and window modules */
34 34 return tv_init_bookmark(buf, size) && tv_init_window(buf, size);
35 /* get the plugin buffer */ 35}
36 unsigned char *buf = rb->plugin_get_buffer(&size);
37
38 tv_init_bookmark();
39 36
40 /* initialize modules */ 37static void tv_finalize_action(void)
41 if (!tv_init_window(&buf, &size)) 38{
42 return false; 39 /* save preference and bookmarks */
40 if (!tv_save_settings())
41 rb->splash(HZ, "Can't save preferences and bookmarks");
43 42
44 /* load the preferences and bookmark */ 43 /* finalize bookmark modules */
45 if (!tv_load_settings(file)) 44 tv_finalize_bookmark();
46 return false;
47 45
48 /* select to read the page */ 46 /* finalize window modules */
49 tv_select_bookmark(); 47 tv_finalize_window();
50 return true;
51} 48}
52 49
53void tv_exit(void *parameter) 50void tv_exit(void *parameter)
@@ -59,7 +56,19 @@ void tv_exit(void *parameter)
59 rb->splash(HZ, "Can't save preferences and bookmarks"); 56 rb->splash(HZ, "Can't save preferences and bookmarks");
60 57
61 /* finalize modules */ 58 /* finalize modules */
62 tv_finalize_window(); 59 tv_finalize_action();
60}
61
62bool tv_load_file(const unsigned char *file)
63{
64 /* load the preferences and bookmark */
65 if (!tv_load_settings(file))
66 return false;
67
68 /* select to read the page */
69 tv_select_bookmark();
70
71 return true;
63} 72}
64 73
65void tv_draw(void) 74void 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
42}; 42};
43 43
44/* 44/*
45 * initialize modules 45 * initialize the action module
46 * 46 *
47 * [In] file 47 * [In/Out] buf
48 * read file name 48 * the start pointer of the buffer
49 *
50 * [In/Out] size
51 * buffer size
49 * 52 *
50 * return 53 * return
51 * true initialize success 54 * true initialize success
52 * false initialize failure 55 * false initialize failure
53 */ 56 */
54bool tv_init(const unsigned char *file); 57bool tv_init_action(unsigned char **buf, size_t *bufsize);
55 58
56/* 59/*
57 * finalize modules 60 * finalize modules
@@ -61,6 +64,18 @@ bool tv_init(const unsigned char *file);
61 */ 64 */
62void tv_exit(void *parameter); 65void tv_exit(void *parameter);
63 66
67/*
68 * load the file
69 *
70 * [In] file
71 * read file name
72 *
73 * return
74 * true load success
75 * false load failure
76 */
77bool tv_load_file(const unsigned char *file);
78
64/* draw the current page */ 79/* draw the current page */
65void tv_draw(void); 80void tv_draw(void);
66 81
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)
110 return TV_CALLBACK_OK; 110 return TV_CALLBACK_OK;
111} 111}
112 112
113void tv_init_bookmark(void) 113bool tv_init_bookmark(unsigned char **buf, size_t *size)
114{ 114{
115 (void)buf;
116 (void)size;
117
115 tv_add_preferences_change_listner(tv_change_preferences); 118 tv_add_preferences_change_listner(tv_change_preferences);
119 return true;
120}
121
122void tv_finalize_bookmark(void)
123{
124 /* no-operation function */
116} 125}
117 126
118int tv_get_bookmark_positions(struct tv_screen_pos *pos_array) 127int 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 @@
30/* Maximum amount of register possible bookmarks */ 30/* Maximum amount of register possible bookmarks */
31#define TV_MAX_BOOKMARKS 16 31#define TV_MAX_BOOKMARKS 16
32 32
33/* initialize the bookmark module */ 33/*
34void tv_init_bookmark(void); 34 * initialize the bookmark module
35 *
36 * [In/Out] buf
37 * the start pointer of the buffer
38 *
39 * [In/Out] size
40 * buffer size
41 *
42 * return
43 * true initialize success
44 * false initialize failure
45 */
46bool tv_init_bookmark(unsigned char **buf, size_t *size);
47
48/* finalize the bookmark module */
49void tv_finalize_bookmark(void);
35 50
36/* 51/*
37 * get the positions which registered bookmarks 52 * get the positions which registered bookmarks