diff options
-rw-r--r-- | apps/plugins/text_viewer/text_viewer.c | 2 | ||||
-rw-r--r-- | apps/plugins/text_viewer/tv_action.c | 3 | ||||
-rw-r--r-- | apps/plugins/text_viewer/tv_bookmark.c | 13 | ||||
-rw-r--r-- | apps/plugins/text_viewer/tv_display.c | 13 | ||||
-rw-r--r-- | apps/plugins/text_viewer/tv_menu.c | 3 | ||||
-rw-r--r-- | apps/plugins/text_viewer/tv_menu.h | 1 | ||||
-rw-r--r-- | apps/plugins/text_viewer/tv_pager.c | 3 | ||||
-rw-r--r-- | apps/plugins/text_viewer/tv_preferences.c | 15 | ||||
-rw-r--r-- | apps/plugins/text_viewer/tv_preferences.h | 14 | ||||
-rw-r--r-- | apps/plugins/text_viewer/tv_reader.c | 5 | ||||
-rw-r--r-- | apps/plugins/text_viewer/tv_settings.c | 4 | ||||
-rw-r--r-- | apps/plugins/text_viewer/tv_settings.h | 2 | ||||
-rw-r--r-- | apps/plugins/text_viewer/tv_window.c | 3 |
13 files changed, 56 insertions, 25 deletions
diff --git a/apps/plugins/text_viewer/text_viewer.c b/apps/plugins/text_viewer/text_viewer.c index 4817710cb3..db370f5f73 100644 --- a/apps/plugins/text_viewer/text_viewer.c +++ b/apps/plugins/text_viewer/text_viewer.c | |||
@@ -73,6 +73,8 @@ enum plugin_status plugin_start(const void* file) | |||
73 | done = true; | 73 | done = true; |
74 | if (res == TV_MENU_RESULT_ATTACHED_USB) | 74 | if (res == TV_MENU_RESULT_ATTACHED_USB) |
75 | return PLUGIN_USB_CONNECTED; | 75 | return PLUGIN_USB_CONNECTED; |
76 | else if (res == TV_MENU_RESULT_ERROR) | ||
77 | return PLUGIN_ERROR; | ||
76 | } | 78 | } |
77 | } | 79 | } |
78 | break; | 80 | break; |
diff --git a/apps/plugins/text_viewer/tv_action.c b/apps/plugins/text_viewer/tv_action.c index 2549709a5f..5226d90049 100644 --- a/apps/plugins/text_viewer/tv_action.c +++ b/apps/plugins/text_viewer/tv_action.c | |||
@@ -42,7 +42,8 @@ bool tv_init(const unsigned char *file) | |||
42 | return false; | 42 | return false; |
43 | 43 | ||
44 | /* load the preferences and bookmark */ | 44 | /* load the preferences and bookmark */ |
45 | tv_load_settings(file); | 45 | if (!tv_load_settings(file)) |
46 | return false; | ||
46 | 47 | ||
47 | /* select to read the page */ | 48 | /* select to read the page */ |
48 | tv_select_bookmark(); | 49 | tv_select_bookmark(); |
diff --git a/apps/plugins/text_viewer/tv_bookmark.c b/apps/plugins/text_viewer/tv_bookmark.c index d569ed8d11..7e38d766ec 100644 --- a/apps/plugins/text_viewer/tv_bookmark.c +++ b/apps/plugins/text_viewer/tv_bookmark.c | |||
@@ -98,15 +98,16 @@ static int tv_find_bookmark(const struct tv_screen_pos *pos) | |||
98 | return -1; | 98 | return -1; |
99 | } | 99 | } |
100 | 100 | ||
101 | static void tv_change_preferences(const struct tv_preferences *oldp) | 101 | static int tv_change_preferences(const struct tv_preferences *oldp) |
102 | { | 102 | { |
103 | int i; | 103 | int i; |
104 | 104 | ||
105 | if (oldp == NULL) | 105 | if (oldp) |
106 | return; | 106 | { |
107 | 107 | for (i = 0; i < bookmark_count; i++) | |
108 | for (i = 0; i < bookmark_count; i++) | 108 | tv_convert_fpos(bookmarks[i].pos.file_pos, &bookmarks[i].pos); |
109 | tv_convert_fpos(bookmarks[i].pos.file_pos, &bookmarks[i].pos); | 109 | } |
110 | return TV_CALLBACK_OK; | ||
110 | } | 111 | } |
111 | 112 | ||
112 | void tv_init_bookmark(void) | 113 | void tv_init_bookmark(void) |
diff --git a/apps/plugins/text_viewer/tv_display.c b/apps/plugins/text_viewer/tv_display.c index 59b4bdf437..c59765ebbe 100644 --- a/apps/plugins/text_viewer/tv_display.c +++ b/apps/plugins/text_viewer/tv_display.c | |||
@@ -349,7 +349,7 @@ static bool tv_set_font(const unsigned char *font) | |||
349 | } | 349 | } |
350 | #endif | 350 | #endif |
351 | 351 | ||
352 | static void tv_change_preferences(const struct tv_preferences *oldp) | 352 | static int tv_change_preferences(const struct tv_preferences *oldp) |
353 | { | 353 | { |
354 | #ifdef HAVE_LCD_BITMAP | 354 | #ifdef HAVE_LCD_BITMAP |
355 | static bool font_changing = false; | 355 | static bool font_changing = false; |
@@ -363,10 +363,18 @@ static void tv_change_preferences(const struct tv_preferences *oldp) | |||
363 | { | 363 | { |
364 | if (!tv_set_font(preferences->font_name)) | 364 | if (!tv_set_font(preferences->font_name)) |
365 | { | 365 | { |
366 | /* | ||
367 | * tv_set_font(rb->global_settings->font_file) doesn't fail usually. | ||
368 | * if it fails, a fatal problem occurs in Rockbox. | ||
369 | */ | ||
370 | if (!rb->strcmp(preferences->font_name, rb->global_settings->font_file)) | ||
371 | return TV_CALLBACK_ERROR; | ||
372 | |||
366 | font_changing = true; | 373 | font_changing = true; |
367 | tv_copy_preferences(&new_prefs); | 374 | tv_copy_preferences(&new_prefs); |
368 | rb->strlcpy(new_prefs.font_name, font_str, MAX_PATH); | 375 | rb->strlcpy(new_prefs.font_name, font_str, MAX_PATH); |
369 | tv_set_preferences(&new_prefs); | 376 | |
377 | return (tv_set_preferences(&new_prefs))? TV_CALLBACK_STOP : TV_CALLBACK_ERROR; | ||
370 | } | 378 | } |
371 | col_width = 2 * rb->font_get_width(preferences->font, ' '); | 379 | col_width = 2 * rb->font_get_width(preferences->font, ' '); |
372 | font_changing = false; | 380 | font_changing = false; |
@@ -375,6 +383,7 @@ static void tv_change_preferences(const struct tv_preferences *oldp) | |||
375 | (void)oldp; | 383 | (void)oldp; |
376 | #endif | 384 | #endif |
377 | tv_change_viewport(); | 385 | tv_change_viewport(); |
386 | return TV_CALLBACK_OK; | ||
378 | } | 387 | } |
379 | 388 | ||
380 | bool tv_init_display(unsigned char **buf, size_t *size) | 389 | bool tv_init_display(unsigned char **buf, size_t *size) |
diff --git a/apps/plugins/text_viewer/tv_menu.c b/apps/plugins/text_viewer/tv_menu.c index 2e3a26d785..7e706eb06a 100644 --- a/apps/plugins/text_viewer/tv_menu.c +++ b/apps/plugins/text_viewer/tv_menu.c | |||
@@ -366,7 +366,8 @@ unsigned tv_display_menu(void) | |||
366 | case 1: /* change settings */ | 366 | case 1: /* change settings */ |
367 | tv_copy_preferences(&new_prefs); | 367 | tv_copy_preferences(&new_prefs); |
368 | result = tv_options_menu(); | 368 | result = tv_options_menu(); |
369 | tv_set_preferences(&new_prefs); | 369 | if (!tv_set_preferences(&new_prefs)) |
370 | result = TV_MENU_RESULT_ERROR; | ||
370 | break; | 371 | break; |
371 | case 2: /* playback control */ | 372 | case 2: /* playback control */ |
372 | playback_control(NULL); | 373 | playback_control(NULL); |
diff --git a/apps/plugins/text_viewer/tv_menu.h b/apps/plugins/text_viewer/tv_menu.h index 0db5051192..42da8b09cf 100644 --- a/apps/plugins/text_viewer/tv_menu.h +++ b/apps/plugins/text_viewer/tv_menu.h | |||
@@ -28,6 +28,7 @@ enum { | |||
28 | TV_MENU_RESULT_EXIT_MENU, | 28 | TV_MENU_RESULT_EXIT_MENU, |
29 | TV_MENU_RESULT_EXIT_PLUGIN, | 29 | TV_MENU_RESULT_EXIT_PLUGIN, |
30 | TV_MENU_RESULT_ATTACHED_USB, | 30 | TV_MENU_RESULT_ATTACHED_USB, |
31 | TV_MENU_RESULT_ERROR, | ||
31 | }; | 32 | }; |
32 | 33 | ||
33 | /* | 34 | /* |
diff --git a/apps/plugins/text_viewer/tv_pager.c b/apps/plugins/text_viewer/tv_pager.c index e7016c7fef..a91d9d91ab 100644 --- a/apps/plugins/text_viewer/tv_pager.c +++ b/apps/plugins/text_viewer/tv_pager.c | |||
@@ -73,7 +73,7 @@ static off_t tv_get_fpos(int page) | |||
73 | return 0; | 73 | return 0; |
74 | } | 74 | } |
75 | 75 | ||
76 | static void tv_change_preferences(const struct tv_preferences *oldp) | 76 | static int tv_change_preferences(const struct tv_preferences *oldp) |
77 | { | 77 | { |
78 | (void)oldp; | 78 | (void)oldp; |
79 | 79 | ||
@@ -83,6 +83,7 @@ static void tv_change_preferences(const struct tv_preferences *oldp) | |||
83 | max_page = TV_MAX_PAGE - 1; | 83 | max_page = TV_MAX_PAGE - 1; |
84 | tv_set_fpos(cur_pos.page, 0); | 84 | tv_set_fpos(cur_pos.page, 0); |
85 | tv_seek(0, SEEK_SET); | 85 | tv_seek(0, SEEK_SET); |
86 | return TV_CALLBACK_OK; | ||
86 | } | 87 | } |
87 | 88 | ||
88 | bool tv_init_pager(unsigned char **buf, size_t *size) | 89 | bool tv_init_pager(unsigned char **buf, size_t *size) |
diff --git a/apps/plugins/text_viewer/tv_preferences.c b/apps/plugins/text_viewer/tv_preferences.c index 924cedb0d0..7d4fd3c2e3 100644 --- a/apps/plugins/text_viewer/tv_preferences.c +++ b/apps/plugins/text_viewer/tv_preferences.c | |||
@@ -31,11 +31,12 @@ const struct tv_preferences * const preferences = &prefs; | |||
31 | static int listner_count = 0; | 31 | static int listner_count = 0; |
32 | 32 | ||
33 | #define TV_MAX_LISTNERS 5 | 33 | #define TV_MAX_LISTNERS 5 |
34 | static void (*listners[TV_MAX_LISTNERS])(const struct tv_preferences *oldp); | 34 | static int (*listners[TV_MAX_LISTNERS])(const struct tv_preferences *oldp); |
35 | 35 | ||
36 | static void tv_notify_change_preferences(const struct tv_preferences *oldp) | 36 | static bool tv_notify_change_preferences(const struct tv_preferences *oldp) |
37 | { | 37 | { |
38 | int i; | 38 | int i; |
39 | int res = TV_CALLBACK_OK; | ||
39 | 40 | ||
40 | /* | 41 | /* |
41 | * the following items do not check. | 42 | * the following items do not check. |
@@ -65,11 +66,13 @@ static void tv_notify_change_preferences(const struct tv_preferences *oldp) | |||
65 | { | 66 | { |
66 | /* callback functions are called as FILO */ | 67 | /* callback functions are called as FILO */ |
67 | for (i = listner_count - 1; i >= 0; i--) | 68 | for (i = listner_count - 1; i >= 0; i--) |
68 | listners[i](oldp); | 69 | if ((res = listners[i](oldp)) != TV_CALLBACK_OK) |
70 | break; | ||
69 | } | 71 | } |
72 | return (res != TV_CALLBACK_ERROR); | ||
70 | } | 73 | } |
71 | 74 | ||
72 | void tv_set_preferences(const struct tv_preferences *new_prefs) | 75 | bool tv_set_preferences(const struct tv_preferences *new_prefs) |
73 | { | 76 | { |
74 | static struct tv_preferences old_prefs; | 77 | static struct tv_preferences old_prefs; |
75 | struct tv_preferences *oldp = NULL; | 78 | struct tv_preferences *oldp = NULL; |
@@ -80,7 +83,7 @@ void tv_set_preferences(const struct tv_preferences *new_prefs) | |||
80 | is_initialized = true; | 83 | is_initialized = true; |
81 | 84 | ||
82 | rb->memcpy(&prefs, new_prefs, sizeof(struct tv_preferences)); | 85 | rb->memcpy(&prefs, new_prefs, sizeof(struct tv_preferences)); |
83 | tv_notify_change_preferences(oldp); | 86 | return tv_notify_change_preferences(oldp); |
84 | } | 87 | } |
85 | 88 | ||
86 | void tv_copy_preferences(struct tv_preferences *copy_prefs) | 89 | void tv_copy_preferences(struct tv_preferences *copy_prefs) |
@@ -118,7 +121,7 @@ void tv_set_default_preferences(struct tv_preferences *p) | |||
118 | p->file_name[0] = '\0'; | 121 | p->file_name[0] = '\0'; |
119 | } | 122 | } |
120 | 123 | ||
121 | void tv_add_preferences_change_listner(void (*listner)(const struct tv_preferences *oldp)) | 124 | void tv_add_preferences_change_listner(int (*listner)(const struct tv_preferences *oldp)) |
122 | { | 125 | { |
123 | if (listner_count < TV_MAX_LISTNERS) | 126 | if (listner_count < TV_MAX_LISTNERS) |
124 | listners[listner_count++] = listner; | 127 | listners[listner_count++] = listner; |
diff --git a/apps/plugins/text_viewer/tv_preferences.h b/apps/plugins/text_viewer/tv_preferences.h index d1ba7f25b4..42d6fb4887 100644 --- a/apps/plugins/text_viewer/tv_preferences.h +++ b/apps/plugins/text_viewer/tv_preferences.h | |||
@@ -23,6 +23,12 @@ | |||
23 | #ifndef PLUGIN_TEXT_VIEWER_PREFERENCES_H | 23 | #ifndef PLUGIN_TEXT_VIEWER_PREFERENCES_H |
24 | #define PLUGIN_TEXT_VIEWER_PREFERENCES_H | 24 | #define PLUGIN_TEXT_VIEWER_PREFERENCES_H |
25 | 25 | ||
26 | enum { | ||
27 | TV_CALLBACK_OK, | ||
28 | TV_CALLBACK_STOP, | ||
29 | TV_CALLBACK_ERROR, | ||
30 | }; | ||
31 | |||
26 | /* scrollbar_mode */ | 32 | /* scrollbar_mode */ |
27 | enum { | 33 | enum { |
28 | SB_OFF = 0, | 34 | SB_OFF = 0, |
@@ -129,8 +135,12 @@ extern const struct tv_preferences * const preferences; | |||
129 | * | 135 | * |
130 | * [In] new_prefs | 136 | * [In] new_prefs |
131 | * new preferences | 137 | * new preferences |
138 | * | ||
139 | * return | ||
140 | * true success | ||
141 | * false error | ||
132 | */ | 142 | */ |
133 | void tv_set_preferences(const struct tv_preferences *new_prefs); | 143 | bool tv_set_preferences(const struct tv_preferences *new_prefs); |
134 | 144 | ||
135 | /* | 145 | /* |
136 | * copy the preferences | 146 | * copy the preferences |
@@ -154,6 +164,6 @@ void tv_set_default_preferences(struct tv_preferences *p); | |||
154 | * [In] listner | 164 | * [In] listner |
155 | * the function to be executed when the current preferences is changed | 165 | * the function to be executed when the current preferences is changed |
156 | */ | 166 | */ |
157 | void tv_add_preferences_change_listner(void (*listner)(const struct tv_preferences *oldp)); | 167 | void tv_add_preferences_change_listner(int (*listner)(const struct tv_preferences *oldp)); |
158 | 168 | ||
159 | #endif | 169 | #endif |
diff --git a/apps/plugins/text_viewer/tv_reader.c b/apps/plugins/text_viewer/tv_reader.c index 8403c305af..b94dc17f65 100644 --- a/apps/plugins/text_viewer/tv_reader.c +++ b/apps/plugins/text_viewer/tv_reader.c | |||
@@ -132,7 +132,7 @@ void tv_seek(off_t offset, int whence) | |||
132 | } | 132 | } |
133 | } | 133 | } |
134 | 134 | ||
135 | static void tv_change_preferences(const struct tv_preferences *oldp) | 135 | static int tv_change_preferences(const struct tv_preferences *oldp) |
136 | { | 136 | { |
137 | unsigned char bom[BOM_SIZE]; | 137 | unsigned char bom[BOM_SIZE]; |
138 | int cur_start_file_pos = start_file_pos; | 138 | int cur_start_file_pos = start_file_pos; |
@@ -151,7 +151,7 @@ static void tv_change_preferences(const struct tv_preferences *oldp) | |||
151 | 151 | ||
152 | fd = rb->open(preferences->file_name, O_RDONLY); | 152 | fd = rb->open(preferences->file_name, O_RDONLY); |
153 | if (fd < 0) | 153 | if (fd < 0) |
154 | return; | 154 | return TV_CALLBACK_ERROR; |
155 | } | 155 | } |
156 | 156 | ||
157 | /* | 157 | /* |
@@ -168,6 +168,7 @@ static void tv_change_preferences(const struct tv_preferences *oldp) | |||
168 | 168 | ||
169 | file_size = rb->filesize(fd) - start_file_pos; | 169 | file_size = rb->filesize(fd) - start_file_pos; |
170 | tv_seek(cur_file_pos + cur_start_file_pos - start_file_pos, SEEK_SET); | 170 | tv_seek(cur_file_pos + cur_start_file_pos - start_file_pos, SEEK_SET); |
171 | return TV_CALLBACK_OK; | ||
171 | } | 172 | } |
172 | 173 | ||
173 | bool tv_init_reader(unsigned char **buf, size_t *size) | 174 | bool tv_init_reader(unsigned char **buf, size_t *size) |
diff --git a/apps/plugins/text_viewer/tv_settings.c b/apps/plugins/text_viewer/tv_settings.c index 56c0bbe7ce..0b1fe20271 100644 --- a/apps/plugins/text_viewer/tv_settings.c +++ b/apps/plugins/text_viewer/tv_settings.c | |||
@@ -417,7 +417,7 @@ bool tv_save_global_settings(const struct tv_preferences *prefs) | |||
417 | * ---------------------------------------------------------------------------- | 417 | * ---------------------------------------------------------------------------- |
418 | */ | 418 | */ |
419 | 419 | ||
420 | void tv_load_settings(const unsigned char *file_name) | 420 | bool tv_load_settings(const unsigned char *file_name) |
421 | { | 421 | { |
422 | unsigned char buf[MAX_PATH+2]; | 422 | unsigned char buf[MAX_PATH+2]; |
423 | unsigned int fcount; | 423 | unsigned int fcount; |
@@ -470,7 +470,7 @@ void tv_load_settings(const unsigned char *file_name) | |||
470 | tv_set_default_preferences(&prefs); | 470 | tv_set_default_preferences(&prefs); |
471 | } | 471 | } |
472 | rb->strlcpy(prefs.file_name, file_name, MAX_PATH); | 472 | rb->strlcpy(prefs.file_name, file_name, MAX_PATH); |
473 | tv_set_preferences(&prefs); | 473 | return tv_set_preferences(&prefs); |
474 | } | 474 | } |
475 | 475 | ||
476 | static bool tv_copy_settings(int sfd, int dfd, int size) | 476 | static bool tv_copy_settings(int sfd, int dfd, int size) |
diff --git a/apps/plugins/text_viewer/tv_settings.h b/apps/plugins/text_viewer/tv_settings.h index c2218e7d9f..65b31ecd69 100644 --- a/apps/plugins/text_viewer/tv_settings.h +++ b/apps/plugins/text_viewer/tv_settings.h | |||
@@ -59,7 +59,7 @@ bool tv_save_global_settings(const struct tv_preferences *prefs); | |||
59 | * true success | 59 | * true success |
60 | * false failure | 60 | * false failure |
61 | */ | 61 | */ |
62 | void tv_load_settings(const unsigned char *file_name); | 62 | bool tv_load_settings(const unsigned char *file_name); |
63 | 63 | ||
64 | /* | 64 | /* |
65 | * save the settings at each file | 65 | * save the settings at each file |
diff --git a/apps/plugins/text_viewer/tv_window.c b/apps/plugins/text_viewer/tv_window.c index 9e35b49c6d..05214fab13 100644 --- a/apps/plugins/text_viewer/tv_window.c +++ b/apps/plugins/text_viewer/tv_window.c | |||
@@ -102,7 +102,7 @@ bool tv_traverse_lines(void) | |||
102 | return res; | 102 | return res; |
103 | } | 103 | } |
104 | 104 | ||
105 | static void tv_change_preferences(const struct tv_preferences *oldp) | 105 | static int tv_change_preferences(const struct tv_preferences *oldp) |
106 | { | 106 | { |
107 | bool need_vertical_scrollbar = false; | 107 | bool need_vertical_scrollbar = false; |
108 | 108 | ||
@@ -131,6 +131,7 @@ static void tv_change_preferences(const struct tv_preferences *oldp) | |||
131 | cur_column = 0; | 131 | cur_column = 0; |
132 | 132 | ||
133 | tv_set_read_conditions(preferences->windows, window_width); | 133 | tv_set_read_conditions(preferences->windows, window_width); |
134 | return TV_CALLBACK_OK; | ||
134 | } | 135 | } |
135 | 136 | ||
136 | bool tv_init_window(unsigned char **buf, size_t *size) | 137 | bool tv_init_window(unsigned char **buf, size_t *size) |