summaryrefslogtreecommitdiff
path: root/apps/plugins
diff options
context:
space:
mode:
authorRafaël Carré <rafael.carre@gmail.com>2010-06-23 13:56:08 +0000
committerRafaël Carré <rafael.carre@gmail.com>2010-06-23 13:56:08 +0000
commit59fd2b24bd7ad8ff0c18f66ffbf83f7ceefa9d55 (patch)
treeab90153c1106641d5973f43b727611d983d7a70f /apps/plugins
parentcf9bba710297617f01c37b613b5ab9fcd97733e3 (diff)
FS#11399 by me: fix r26998 for text_viewer
Restore the old behaviour: - preferences must be read-write for tv_preferences.c , read-only for all other modules -> use pointer to const struct - init functions must get the plugin buffer + its size as arguments for easily adding new functions -> use pointer to buffer pointer and size to make allocation easier - preferences meaning is private to each file and must not be known by tv_preferences.c -> move tv_check_header_and_footer() back in tv_window.c; also avoid chaining 3 times the callbacks by calling tv_set_preferences() only once if more than one preference needs changing git-svn-id: svn://svn.rockbox.org/rockbox/trunk@27089 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/plugins')
-rw-r--r--apps/plugins/text_viewer/tv_action.c7
-rw-r--r--apps/plugins/text_viewer/tv_pager.c4
-rw-r--r--apps/plugins/text_viewer/tv_pager.h8
-rw-r--r--apps/plugins/text_viewer/tv_preferences.c26
-rw-r--r--apps/plugins/text_viewer/tv_preferences.h4
-rw-r--r--apps/plugins/text_viewer/tv_reader.c16
-rw-r--r--apps/plugins/text_viewer/tv_reader.h8
-rw-r--r--apps/plugins/text_viewer/tv_text_processor.c7
-rw-r--r--apps/plugins/text_viewer/tv_text_processor.h11
-rw-r--r--apps/plugins/text_viewer/tv_text_reader.c6
-rw-r--r--apps/plugins/text_viewer/tv_text_reader.h8
-rw-r--r--apps/plugins/text_viewer/tv_window.c54
-rw-r--r--apps/plugins/text_viewer/tv_window.h8
13 files changed, 115 insertions, 52 deletions
diff --git a/apps/plugins/text_viewer/tv_action.c b/apps/plugins/text_viewer/tv_action.c
index 546ee99842..88338feb1e 100644
--- a/apps/plugins/text_viewer/tv_action.c
+++ b/apps/plugins/text_viewer/tv_action.c
@@ -30,10 +30,15 @@
bool tv_init(const unsigned char *file)
{
+ size_t size;
+
+ /* get the plugin buffer */
+ unsigned char *buf = rb->plugin_get_buffer(&size);
+
tv_init_bookmark();
/* initialize modules */
- if (!tv_init_window())
+ if (!tv_init_window(&buf, &size))
return false;
/* load the preferences and bookmark */
diff --git a/apps/plugins/text_viewer/tv_pager.c b/apps/plugins/text_viewer/tv_pager.c
index 0c109530f8..e7016c7fef 100644
--- a/apps/plugins/text_viewer/tv_pager.c
+++ b/apps/plugins/text_viewer/tv_pager.c
@@ -85,7 +85,7 @@ static void tv_change_preferences(const struct tv_preferences *oldp)
tv_seek(0, SEEK_SET);
}
-bool tv_init_pager(void)
+bool tv_init_pager(unsigned char **buf, size_t *size)
{
tv_set_screen_pos(&cur_pos);
tv_add_preferences_change_listner(tv_change_preferences);
@@ -95,7 +95,7 @@ bool tv_init_pager(void)
line_pos[0] = 0;
- return tv_init_reader();
+ return tv_init_reader(buf, size);
}
void tv_finalize_pager(void)
diff --git a/apps/plugins/text_viewer/tv_pager.h b/apps/plugins/text_viewer/tv_pager.h
index ec1de24b5a..27795a1637 100644
--- a/apps/plugins/text_viewer/tv_pager.h
+++ b/apps/plugins/text_viewer/tv_pager.h
@@ -30,11 +30,17 @@
/*
* initialize the pager 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_pager(void);
+bool tv_init_pager(unsigned char **buf, size_t *bufsize);
/* finalize the pager module */
void tv_finalize_pager(void);
diff --git a/apps/plugins/text_viewer/tv_preferences.c b/apps/plugins/text_viewer/tv_preferences.c
index b1045fba7d..ec59dd89a8 100644
--- a/apps/plugins/text_viewer/tv_preferences.c
+++ b/apps/plugins/text_viewer/tv_preferences.c
@@ -23,9 +23,10 @@
#include "plugin.h"
#include "tv_preferences.h"
-/* global preferences */
+
static struct tv_preferences prefs;
-struct tv_preferences *preferences = &prefs;
+/* read-only preferences pointer, for access by other files */
+const struct tv_preferences * const preferences = &prefs;
static int listner_count = 0;
@@ -66,24 +67,6 @@ static void tv_notify_change_preferences(const struct tv_preferences *oldp)
}
}
-static void tv_check_header_and_footer(void)
-{
- if (rb->global_settings->statusbar != STATUSBAR_TOP)
- {
- if (preferences->header_mode == HD_SBAR)
- preferences->header_mode = HD_NONE;
- else if (preferences->header_mode == HD_BOTH)
- preferences->header_mode = HD_PATH;
- }
- if (rb->global_settings->statusbar != STATUSBAR_BOTTOM)
- {
- if (preferences->footer_mode == FT_SBAR)
- preferences->footer_mode = FT_NONE;
- else if (preferences->footer_mode == FT_BOTH)
- preferences->footer_mode = FT_PAGE;
- }
-}
-
void tv_set_preferences(const struct tv_preferences *new_prefs)
{
static struct tv_preferences old_prefs;
@@ -94,8 +77,7 @@ void tv_set_preferences(const struct tv_preferences *new_prefs)
tv_copy_preferences((oldp = &old_prefs));
is_initialized = true;
- rb->memcpy(preferences, new_prefs, sizeof(struct tv_preferences));
- tv_check_header_and_footer();
+ rb->memcpy(&prefs, new_prefs, sizeof(struct tv_preferences));
tv_notify_change_preferences(oldp);
}
diff --git a/apps/plugins/text_viewer/tv_preferences.h b/apps/plugins/text_viewer/tv_preferences.h
index 906f5c5f16..7705a1673a 100644
--- a/apps/plugins/text_viewer/tv_preferences.h
+++ b/apps/plugins/text_viewer/tv_preferences.h
@@ -122,9 +122,9 @@ struct tv_preferences {
};
/*
- * global pointer to the preferences
+ * global pointer to the preferences (read-only)
*/
-extern struct tv_preferences *preferences;
+extern const struct tv_preferences * const preferences;
/*
* change the preferences
diff --git a/apps/plugins/text_viewer/tv_reader.c b/apps/plugins/text_viewer/tv_reader.c
index 4e91af9f98..8403c305af 100644
--- a/apps/plugins/text_viewer/tv_reader.c
+++ b/apps/plugins/text_viewer/tv_reader.c
@@ -170,18 +170,18 @@ static void tv_change_preferences(const struct tv_preferences *oldp)
tv_seek(cur_file_pos + cur_start_file_pos - start_file_pos, SEEK_SET);
}
-bool tv_init_reader(void)
+bool tv_init_reader(unsigned char **buf, size_t *size)
{
- size_t size;
-
- /* get the plugin buffer */
- reader_buffer = rb->plugin_get_buffer(&size);
-
- if (size < 2 * TV_MIN_BLOCK_SIZE)
+ if (*size < 2 * TV_MIN_BLOCK_SIZE)
return false;
- block_size = size / 2;
+ block_size = *size / 2;
buffer_size = 2 * block_size;
+ reader_buffer = *buf;
+
+ *buf += buffer_size;
+ *size -= buffer_size;
+
tv_add_preferences_change_listner(tv_change_preferences);
return true;
diff --git a/apps/plugins/text_viewer/tv_reader.h b/apps/plugins/text_viewer/tv_reader.h
index 2ee0b828ab..0b079edddb 100644
--- a/apps/plugins/text_viewer/tv_reader.h
+++ b/apps/plugins/text_viewer/tv_reader.h
@@ -28,11 +28,17 @@
/*
* initialize the reader module
*
+ * [In/Out] buf
+ * the start pointer of the buffer
+ *
+ * [In/Out] size
+ * enabled buffer size
+ *
* return
* true initialize success
* false initialize failure
*/
-bool tv_init_reader(void);
+bool tv_init_reader(unsigned char **buf, size_t *bufsize);
/* finalize the reader module */
void tv_finalize_reader(void);
diff --git a/apps/plugins/text_viewer/tv_text_processor.c b/apps/plugins/text_viewer/tv_text_processor.c
index f9a2fad1f2..3ad388e6c5 100644
--- a/apps/plugins/text_viewer/tv_text_processor.c
+++ b/apps/plugins/text_viewer/tv_text_processor.c
@@ -544,11 +544,16 @@ int tv_create_formed_text(const unsigned char *src, ssize_t bufsize,
return size;
}
-void tv_init_text_processor(void)
+bool tv_init_text_processor(unsigned char **buf, size_t *size)
{
+ /* unused : no need for dynamic buffer yet */
+ (void)buf;
+ (void)size;
+
text_type = TV_TEXT_UNKNOWN;
expand_extra_line = false;
is_break_line = false;
+ return true;
}
void tv_set_creation_conditions(int blocks, int width)
diff --git a/apps/plugins/text_viewer/tv_text_processor.h b/apps/plugins/text_viewer/tv_text_processor.h
index 8a9de9075b..33e6a021f9 100644
--- a/apps/plugins/text_viewer/tv_text_processor.h
+++ b/apps/plugins/text_viewer/tv_text_processor.h
@@ -26,8 +26,17 @@
/*
* initialize the text processor module
*
+ * [In/Out] buf
+ * the start pointer of the buffer
+ *
+ * [In/Out] size
+ * enabled buffer size
+ *
+ * return
+ * true initialize success
+ * false initialize failure
*/
-void tv_init_text_processor(void);
+bool tv_init_text_processor(unsigned char **buf, size_t *bufsize);
/*
* set the processing conditions
diff --git a/apps/plugins/text_viewer/tv_text_reader.c b/apps/plugins/text_viewer/tv_text_reader.c
index 53c8f6738f..ec1c138df0 100644
--- a/apps/plugins/text_viewer/tv_text_reader.c
+++ b/apps/plugins/text_viewer/tv_text_reader.c
@@ -29,11 +29,9 @@
static int get_block;
static bool get_double_blocks;
-bool tv_init_text_reader(void)
+bool tv_init_text_reader(unsigned char **buf, size_t *size)
{
- tv_init_text_processor();
-
- return tv_init_pager();
+ return tv_init_text_processor(buf, size) && tv_init_pager(buf, size);
}
void tv_finalize_text_reader(void)
diff --git a/apps/plugins/text_viewer/tv_text_reader.h b/apps/plugins/text_viewer/tv_text_reader.h
index 50059c8b3c..5162892f4b 100644
--- a/apps/plugins/text_viewer/tv_text_reader.h
+++ b/apps/plugins/text_viewer/tv_text_reader.h
@@ -26,11 +26,17 @@
/*
* initialize the text reader module
*
+ * [In/Out] buf
+ * the start pointer of the buffer
+ *
+ * [In/Out] size
+ * enabled buffer size
+ *
* return
* true initialize success
* false initialize failure
*/
-bool tv_init_text_reader(void);
+bool tv_init_text_reader(unsigned char **buf, size_t *bufsize);
/* finalize the text reader module */
void tv_finalize_text_reader(void);
diff --git a/apps/plugins/text_viewer/tv_window.c b/apps/plugins/text_viewer/tv_window.c
index c733d5a088..f1f2033ef1 100644
--- a/apps/plugins/text_viewer/tv_window.c
+++ b/apps/plugins/text_viewer/tv_window.c
@@ -67,6 +67,40 @@ static bool tv_set_font(const unsigned char *font)
return true;
}
+static bool tv_check_header_and_footer(struct tv_preferences *new_prefs)
+{
+ bool change_prefs = false;
+
+ if (rb->global_settings->statusbar != STATUSBAR_TOP)
+ {
+ if (new_prefs->header_mode == HD_SBAR)
+ {
+ new_prefs->header_mode = HD_NONE;
+ change_prefs = true;
+ }
+ else if (new_prefs->header_mode == HD_BOTH)
+ {
+ new_prefs->header_mode = HD_PATH;
+ change_prefs = true;
+ }
+ }
+ if (rb->global_settings->statusbar != STATUSBAR_BOTTOM)
+ {
+ if (new_prefs->footer_mode == FT_SBAR)
+ {
+ new_prefs->footer_mode = FT_NONE;
+ change_prefs = true;
+ }
+ else if (new_prefs->footer_mode == FT_BOTH)
+ {
+ new_prefs->footer_mode = FT_PAGE;
+ change_prefs = true;
+ }
+ }
+
+ return change_prefs;
+}
+
static void tv_show_header(void)
{
unsigned header_mode = header_mode;
@@ -259,6 +293,9 @@ static void tv_change_preferences(const struct tv_preferences *oldp)
#ifdef HAVE_LCD_BITMAP
static bool font_changing = false;
const unsigned char *font_str;
+ bool change_prefs = false;
+ struct tv_preferences new_prefs;
+ tv_copy_preferences(&new_prefs);
font_str = (oldp && !font_changing)? oldp->font_name : rb->global_settings->font_file;
@@ -268,14 +305,17 @@ static void tv_change_preferences(const struct tv_preferences *oldp)
font_changing = true;
if (!tv_set_font(preferences->font_name))
{
- struct tv_preferences new_prefs;
- tv_copy_preferences(&new_prefs);
-
rb->strlcpy(new_prefs.font_name, font_str, MAX_PATH);
- tv_set_preferences(&new_prefs);
- return;
+ change_prefs = true;
}
}
+
+ if (tv_check_header_and_footer(&new_prefs) || change_prefs)
+ {
+ tv_set_preferences(&new_prefs);
+ return;
+ }
+
font_changing = false;
/* calculates display lines */
@@ -319,10 +359,10 @@ static void tv_change_preferences(const struct tv_preferences *oldp)
tv_set_read_conditions(preferences->windows, window_width);
}
-bool tv_init_window(void)
+bool tv_init_window(unsigned char **buf, size_t *size)
{
tv_add_preferences_change_listner(tv_change_preferences);
- return tv_init_text_reader();
+ return tv_init_text_reader(buf, size);
}
void tv_finalize_window(void)
diff --git a/apps/plugins/text_viewer/tv_window.h b/apps/plugins/text_viewer/tv_window.h
index abf475ae2d..14eeb0820d 100644
--- a/apps/plugins/text_viewer/tv_window.h
+++ b/apps/plugins/text_viewer/tv_window.h
@@ -26,11 +26,17 @@
/*
* initialize the window module
*
+ * [In/Out] buf
+ * the start pointer of the buffer
+ *
+ * [In/Out] size
+ * enabled buffer size
+ *
* return
* true initialize success
* false initialize failure
*/
-bool tv_init_window(void);
+bool tv_init_window(unsigned char **buf, size_t *bufsize);
/* finalize the window module */
void tv_finalize_window(void);