diff options
Diffstat (limited to 'apps')
-rw-r--r-- | apps/plugin.c | 2 | ||||
-rw-r--r-- | apps/plugin.h | 7 | ||||
-rw-r--r-- | apps/plugins/rockpaint.c | 139 | ||||
-rw-r--r-- | apps/plugins/text_viewer/tv_menu.c | 59 |
4 files changed, 43 insertions, 164 deletions
diff --git a/apps/plugin.c b/apps/plugin.c index 1cac280e64..20ff190e37 100644 --- a/apps/plugin.c +++ b/apps/plugin.c | |||
@@ -773,6 +773,8 @@ static const struct plugin_api rockbox_api = { | |||
773 | /* new stuff at the end, sort into place next time | 773 | /* new stuff at the end, sort into place next time |
774 | the API gets incompatible */ | 774 | the API gets incompatible */ |
775 | filetype_get_attr, | 775 | filetype_get_attr, |
776 | browse_context_init, | ||
777 | rockbox_browse, | ||
776 | }; | 778 | }; |
777 | 779 | ||
778 | int plugin_load(const char* plugin, const void* parameter) | 780 | int plugin_load(const char* plugin, const void* parameter) |
diff --git a/apps/plugin.h b/apps/plugin.h index e9e93d00bd..cd53ac6574 100644 --- a/apps/plugin.h +++ b/apps/plugin.h | |||
@@ -149,7 +149,7 @@ void* plugin_get_buffer(size_t *buffer_size); | |||
149 | #define PLUGIN_MAGIC 0x526F634B /* RocK */ | 149 | #define PLUGIN_MAGIC 0x526F634B /* RocK */ |
150 | 150 | ||
151 | /* increase this every time the api struct changes */ | 151 | /* increase this every time the api struct changes */ |
152 | #define PLUGIN_API_VERSION 196 | 152 | #define PLUGIN_API_VERSION 197 |
153 | 153 | ||
154 | /* update this to latest version if a change to the api struct breaks | 154 | /* update this to latest version if a change to the api struct breaks |
155 | backwards compatibility (and please take the opportunity to sort in any | 155 | backwards compatibility (and please take the opportunity to sort in any |
@@ -902,6 +902,11 @@ struct plugin_api { | |||
902 | /* new stuff at the end, sort into place next time | 902 | /* new stuff at the end, sort into place next time |
903 | the API gets incompatible */ | 903 | the API gets incompatible */ |
904 | int (*filetype_get_attr)(const char* file); | 904 | int (*filetype_get_attr)(const char* file); |
905 | void (*browse_context_init)(struct browse_context *browse, | ||
906 | int dirfilter, unsigned flags, | ||
907 | char *title, enum themable_icons icon, | ||
908 | const char *root, const char *selected); | ||
909 | int (*rockbox_browse)(struct browse_context *browse); | ||
905 | }; | 910 | }; |
906 | 911 | ||
907 | /* plugin header */ | 912 | /* plugin header */ |
diff --git a/apps/plugins/rockpaint.c b/apps/plugins/rockpaint.c index fc4621a805..0acbe41aaf 100644 --- a/apps/plugins/rockpaint.c +++ b/apps/plugins/rockpaint.c | |||
@@ -684,136 +684,33 @@ static bool check_extention(const char *filename, const char *ext) | |||
684 | return ( p != NULL && !rb->strcasecmp( p, ext ) ); | 684 | return ( p != NULL && !rb->strcasecmp( p, ext ) ); |
685 | } | 685 | } |
686 | 686 | ||
687 | static const char* browse_get_name_cb(int selected_item, void *data, | 687 | /* only displayes directories and .bmp files */ |
688 | char *buffer, size_t buffer_len) | 688 | static bool callback_show_item(char *name, int attr, struct tree_context *tc) |
689 | { | 689 | { |
690 | int *indexes = (int *) data; | 690 | (void) tc; |
691 | struct entry* dc = tree->dircache; | 691 | if( ( attr & ATTR_DIRECTORY ) || |
692 | struct entry* e = &dc[indexes[selected_item]]; | 692 | ( !(attr & ATTR_DIRECTORY) && check_extention( name, ".bmp" ) ) ) |
693 | (void) buffer; | 693 | { |
694 | (void) buffer_len; | 694 | return true; |
695 | 695 | } | |
696 | return e->name; | 696 | return false; |
697 | } | 697 | } |
698 | 698 | ||
699 | static bool browse( char *dst, int dst_size, const char *start ) | 699 | static bool browse( char *dst, int dst_size, const char *start ) |
700 | { | 700 | { |
701 | struct gui_synclist browse_list; | 701 | struct browse_context browse; |
702 | int item_count = 0, selected, button; | ||
703 | struct tree_context backup; | ||
704 | struct entry *dc, *e; | ||
705 | bool reload = true; | ||
706 | int dirfilter = SHOW_ALL; | ||
707 | int *indexes = (int *) buffer; | ||
708 | size_t bbuf_len, len; | ||
709 | |||
710 | char *a; | ||
711 | |||
712 | rb->strcpy( bbuf, start ); | ||
713 | bbuf_len = rb->strlen(bbuf); | ||
714 | if( bbuf[bbuf_len-1] != '/' ) | ||
715 | { | ||
716 | bbuf[bbuf_len++] = '/'; | ||
717 | bbuf[bbuf_len] = '\0'; | ||
718 | } | ||
719 | bbuf_s[0] = '\0'; | ||
720 | |||
721 | rb->gui_synclist_init(&browse_list, browse_get_name_cb, | ||
722 | (void*) indexes, false, 1, NULL); | ||
723 | 702 | ||
724 | tree = rb->tree_get_context(); | 703 | rb->browse_context_init(&browse, SHOW_ALL, |
725 | backup = *tree; | 704 | BROWSE_SELECTONLY|BROWSE_NO_CONTEXT_MENU, |
726 | dc = tree->dircache; | 705 | NULL, NOICON, start, NULL); |
727 | a = backup.currdir+rb->strlen(backup.currdir)-1; | ||
728 | if( *a != '/' ) | ||
729 | { | ||
730 | *++a = '/'; | ||
731 | } | ||
732 | rb->strcpy( a+1, dc[tree->selected_item].name ); | ||
733 | tree->dirfilter = &dirfilter; | ||
734 | tree->browse = NULL; | ||
735 | while( 1 ) | ||
736 | { | ||
737 | if( reload ) | ||
738 | { | ||
739 | int i; | ||
740 | rb->set_current_file(bbuf); | ||
741 | item_count = 0; | ||
742 | selected = 0; | ||
743 | for( i = 0; i < tree->filesindir ; i++) | ||
744 | { | ||
745 | e = &dc[i]; | ||
746 | /* only displayes directories and .bmp files */ | ||
747 | if( ( e->attr & ATTR_DIRECTORY ) || | ||
748 | ( !(e->attr & ATTR_DIRECTORY) && | ||
749 | check_extention( e->name, ".bmp" ) ) ) | ||
750 | { | ||
751 | if( bbuf_s[0] && !rb->strcmp( e->name, bbuf_s ) ) | ||
752 | selected = item_count; | ||
753 | indexes[item_count++] = i; | ||
754 | } | ||
755 | } | ||
756 | 706 | ||
757 | rb->gui_synclist_set_nb_items(&browse_list,item_count); | 707 | browse.callback_show_item = callback_show_item; |
758 | rb->gui_synclist_select_item(&browse_list, selected); | 708 | browse.buf = dst; |
759 | rb->gui_synclist_set_title(&browse_list, bbuf, NOICON); | 709 | browse.bufsize = dst_size; |
760 | rb->gui_synclist_draw(&browse_list); | ||
761 | reload = false; | ||
762 | } | ||
763 | button = rb->get_action(CONTEXT_LIST,TIMEOUT_BLOCK); | ||
764 | if (rb->gui_synclist_do_button(&browse_list,&button,LIST_WRAP_UNLESS_HELD)) | ||
765 | continue; | ||
766 | switch( button ) | ||
767 | { | ||
768 | case ACTION_STD_CANCEL: | ||
769 | if( !rb->strcmp( bbuf, "/" ) ) | ||
770 | { | ||
771 | *tree = backup; | ||
772 | rb->set_current_file( backup.currdir ); | ||
773 | return false; | ||
774 | } | ||
775 | a = bbuf + bbuf_len - 1; | ||
776 | if( a == bbuf ) break; | ||
777 | while( *a == '/' ) a--; | ||
778 | *(a+1) = '\0'; | ||
779 | while( *a != '/' ) a--; | ||
780 | /* select parent directory */ | ||
781 | rb->strcpy( bbuf_s, ++a ); | ||
782 | *a = '\0'; | ||
783 | bbuf_len = a - bbuf; | ||
784 | reload = true; | ||
785 | break; | ||
786 | 710 | ||
787 | case ACTION_STD_OK: | 711 | rb->rockbox_browse(&browse); |
788 | selected = rb->gui_synclist_get_sel_pos( &browse_list ); | ||
789 | if( selected < 0 || selected >= item_count ) | ||
790 | break; | ||
791 | e = &dc[indexes[selected]]; | ||
792 | if( !( e->attr & ATTR_DIRECTORY ) ) | ||
793 | { | ||
794 | rb->snprintf( dst, dst_size, "%s%s", bbuf, e->name ); | ||
795 | *tree = backup; | ||
796 | rb->set_current_file( backup.currdir ); | ||
797 | return true; | ||
798 | } | ||
799 | len = rb->strlen(e->name); | ||
800 | if( bbuf_len + len + 2 < (int)sizeof(bbuf) ) | ||
801 | { | ||
802 | bbuf_s[0] = '\0'; | ||
803 | rb->strcpy( bbuf+bbuf_len, e->name ); | ||
804 | bbuf_len += len; | ||
805 | bbuf[bbuf_len++] = '/'; | ||
806 | bbuf[bbuf_len] = '\0'; | ||
807 | reload = true; | ||
808 | } | ||
809 | break; | ||
810 | 712 | ||
811 | case ACTION_STD_MENU: | 713 | return (browse.flags & BROWSE_SELECTED); |
812 | *tree = backup; | ||
813 | rb->set_current_file( backup.currdir ); | ||
814 | return false; | ||
815 | } | ||
816 | } | ||
817 | } | 714 | } |
818 | 715 | ||
819 | /*********************************************************************** | 716 | /*********************************************************************** |
diff --git a/apps/plugins/text_viewer/tv_menu.c b/apps/plugins/text_viewer/tv_menu.c index 9be8312732..9e796982d3 100644 --- a/apps/plugins/text_viewer/tv_menu.c +++ b/apps/plugins/text_viewer/tv_menu.c | |||
@@ -216,53 +216,28 @@ static bool tv_statusbar_setting(void) | |||
216 | 216 | ||
217 | static bool tv_font_setting(void) | 217 | static bool tv_font_setting(void) |
218 | { | 218 | { |
219 | int count = 0; | 219 | struct browse_context browse; |
220 | int i = 0; | 220 | char font[MAX_PATH], name[MAX_FILENAME+10]; |
221 | int new_font = 0; | ||
222 | int old_font; | ||
223 | bool res; | ||
224 | unsigned char font_path[MAX_PATH]; | ||
225 | |||
226 | struct tree_context *tree; | ||
227 | struct tree_context backup; | ||
228 | struct entry *dc; | ||
229 | int dirfilter = SHOW_FONT; | ||
230 | |||
231 | tree = rb->tree_get_context(); | ||
232 | backup = *tree; | ||
233 | dc = tree->dircache; | ||
234 | rb->strlcat(backup.currdir, "/", MAX_PATH); | ||
235 | rb->strlcat(backup.currdir, dc[tree->selected_item].name, MAX_PATH); | ||
236 | tree->dirfilter = &dirfilter; | ||
237 | tree->browse = NULL; | ||
238 | rb->snprintf(font_path, MAX_PATH, "%s/", FONT_DIR); | ||
239 | rb->set_current_file(font_path); | ||
240 | count = tree->filesindir; | ||
241 | |||
242 | struct opt_items names[count]; | ||
243 | |||
244 | for (i = 0; i < count; i++) | ||
245 | { | ||
246 | char *p = rb->strrchr(dc[i].name, '.'); | ||
247 | if (p) *p = 0; | ||
248 | if (!rb->strcmp(dc[i].name, new_prefs.font_name)) | ||
249 | new_font = i; | ||
250 | 221 | ||
251 | names[i].string = dc[i].name; | 222 | rb->snprintf(name, sizeof(name), "%s.fnt", new_prefs.font_name); |
252 | names[i].voice_id = -1; | 223 | rb->browse_context_init(&browse, SHOW_FONT, |
253 | } | 224 | BROWSE_SELECTONLY|BROWSE_NO_CONTEXT_MENU, |
225 | "Font", Icon_Menu_setting, FONT_DIR, name); | ||
254 | 226 | ||
255 | old_font = new_font; | 227 | browse.buf = font; |
228 | browse.bufsize = sizeof(font); | ||
256 | 229 | ||
257 | res = rb->set_option("Select Font", &new_font, INT, | 230 | rb->rockbox_browse(&browse); |
258 | names, count, NULL); | ||
259 | 231 | ||
260 | if (new_font != old_font) | 232 | if (browse.flags & BROWSE_SELECTED) |
261 | rb->strlcpy(new_prefs.font_name, names[new_font].string, MAX_PATH); | 233 | { |
234 | char *name = rb->strrchr(font, '/')+1; | ||
235 | char *p = rb->strrchr(name, '.'); | ||
236 | if (p) *p = 0; | ||
237 | rb->strlcpy(new_prefs.font_name, name, MAX_PATH); | ||
238 | } | ||
262 | 239 | ||
263 | *tree = backup; | 240 | return false; |
264 | rb->set_current_file(backup.currdir); | ||
265 | return res; | ||
266 | } | 241 | } |
267 | #endif | 242 | #endif |
268 | 243 | ||