summaryrefslogtreecommitdiff
path: root/apps/plugins/shortcuts/shortcuts_view.c
diff options
context:
space:
mode:
authorWilliam Wilgus <wilgus.william@gmail.com>2020-07-31 22:45:10 -0400
committerWilliam Wilgus <wilgus.william@gmail.com>2020-08-17 10:15:14 -0400
commit35502834423049b319fde41ff305b48de67d2d51 (patch)
tree00d638d9348cd38f15cf6d341e700bc36153b3f8 /apps/plugins/shortcuts/shortcuts_view.c
parentd553bb1149800daf16dcb92bc0608fe6248e1dab (diff)
downloadrockbox-35502834423049b319fde41ff305b48de67d2d51.tar.gz
rockbox-35502834423049b319fde41ff305b48de67d2d51.zip
Add open_plugin to core
open_plugin allows arbitrary plugins to be called in hotkey and start screen replaces PictureFlow Integration shortcuts menu plays plugins now too rather than store paths and parameters in the settings that reside in memory instead entries in a file are searched by hash. after all, the plugin has to be loaded from disk anyways ---------------------------------------------------------------------------- shortcut_viewer.rock-- can now call plugins rather than taking you to them in the browser ----------------------------------------------------------------------------- Added a new option to menus: F_CB_ON_SELECT_ONLY instead of option callback every time a item is accessed F_CB_ON_SELECT_ONLY fires callback only when item is selected ----------------------------------------------------------------------------- Added manual entries ----------------------------------------------------------------------------- Change-Id: I078b57b1d2b4dd633c89212c1082fcbc1b516e6a
Diffstat (limited to 'apps/plugins/shortcuts/shortcuts_view.c')
-rw-r--r--apps/plugins/shortcuts/shortcuts_view.c74
1 files changed, 56 insertions, 18 deletions
diff --git a/apps/plugins/shortcuts/shortcuts_view.c b/apps/plugins/shortcuts/shortcuts_view.c
index cfc9d8d746..f4c4b58bc1 100644
--- a/apps/plugins/shortcuts/shortcuts_view.c
+++ b/apps/plugins/shortcuts/shortcuts_view.c
@@ -22,7 +22,7 @@
22 22
23#include "shortcuts.h" 23#include "shortcuts.h"
24 24
25 25#define LOOP_EXIT 1
26 26
27enum sc_list_action_type 27enum sc_list_action_type
28{ 28{
@@ -35,7 +35,6 @@ enum sc_list_action_type
35 35
36static char *link_filename; 36static char *link_filename;
37static bool user_file; 37static bool user_file;
38static bool usb_connected = false;
39 38
40enum sc_list_action_type draw_sc_list(struct gui_synclist *gui_sc); 39enum sc_list_action_type draw_sc_list(struct gui_synclist *gui_sc);
41 40
@@ -43,10 +42,10 @@ enum sc_list_action_type draw_sc_list(struct gui_synclist *gui_sc);
43static const char* build_sc_list(int selected_item, void *data, 42static const char* build_sc_list(int selected_item, void *data,
44 char *buffer, size_t buffer_len); 43 char *buffer, size_t buffer_len);
45 44
46/* Returns true iff we should leave the main loop */ 45/* Returns LOOP_EXIT iff we should leave the main loop */
47bool list_sc(void); 46int list_sc(void);
48 47
49bool goto_entry(char *file_or_dir); 48int goto_entry(char *file_or_dir);
50bool ends_with(char *str, char *suffix); 49bool ends_with(char *str, char *suffix);
51 50
52 51
@@ -104,7 +103,7 @@ static const char* build_sc_list(int selected_item, void *data,
104} 103}
105 104
106 105
107bool list_sc(void) 106int list_sc(void)
108{ 107{
109 int selected_item = 0; 108 int selected_item = 0;
110 enum sc_list_action_type action = SCLA_NONE; 109 enum sc_list_action_type action = SCLA_NONE;
@@ -122,8 +121,7 @@ bool list_sc(void)
122 /* Draw the prepared widget to the LCD now */ 121 /* Draw the prepared widget to the LCD now */
123 action = draw_sc_list(&gui_sc); 122 action = draw_sc_list(&gui_sc);
124 if (action == SCLA_USB) { 123 if (action == SCLA_USB) {
125 usb_connected = true; 124 return PLUGIN_USB_CONNECTED;
126 return true;
127 } 125 }
128 126
129 /* which item do we action? */ 127 /* which item do we action? */
@@ -132,7 +130,7 @@ bool list_sc(void)
132 if (!is_valid_index(&sc_file, selected_item)) { 130 if (!is_valid_index(&sc_file, selected_item)) {
133 /* This should never happen */ 131 /* This should never happen */
134 rb->splash(HZ*2, "Bad entry selected!"); 132 rb->splash(HZ*2, "Bad entry selected!");
135 return true; 133 return PLUGIN_ERROR;
136 } 134 }
137 135
138 /* perform the following actions if the user "selected" 136 /* perform the following actions if the user "selected"
@@ -145,13 +143,13 @@ bool list_sc(void)
145 rb->splashf(HZ, "Deleting %s", sc_file.entries[selected_item].disp); 143 rb->splashf(HZ, "Deleting %s", sc_file.entries[selected_item].disp);
146 remove_entry(&sc_file, selected_item); 144 remove_entry(&sc_file, selected_item);
147 dump_sc_file(&sc_file, link_filename); 145 dump_sc_file(&sc_file, link_filename);
148 return (sc_file.entry_cnt == 0); 146 return (sc_file.entry_cnt == 0)? LOOP_EXIT : PLUGIN_OK;
149 default: 147 default:
150 return true; 148 return LOOP_EXIT;
151 } 149 }
152} 150}
153 151
154 152#if 0
155bool goto_entry(char *file_or_dir) 153bool goto_entry(char *file_or_dir)
156{ 154{
157 DEBUGF("Trying to go to '%s'...\n", file_or_dir); 155 DEBUGF("Trying to go to '%s'...\n", file_or_dir);
@@ -181,7 +179,46 @@ bool goto_entry(char *file_or_dir)
181 rb->set_current_file(file_or_dir); 179 rb->set_current_file(file_or_dir);
182 return true; 180 return true;
183} 181}
182#endif
183
184int goto_entry(char *file_or_dir)
185{
186 DEBUGF("Trying to go to '%s'...\n", file_or_dir);
187
188 bool is_dir = ends_with(file_or_dir, PATH_SEPARATOR);
189 bool exists;
190 char *what;
191 if (is_dir) {
192 what = "Directory";
193 exists = rb->dir_exists(file_or_dir);
194 } else {
195 what = "File";
196 exists = rb->file_exists(file_or_dir);
197 }
184 198
199 if (!exists) {
200 rb->splashf(HZ*2, "%s %s no longer exists on disk", what, file_or_dir);
201 return PLUGIN_ERROR;
202 }
203
204 int len = rb->strlen(file_or_dir);
205 if(!is_dir && len > 5 && rb->strcasecmp(&(file_or_dir[len-5]), ".rock") == 0)
206 {
207 return rb->plugin_open(file_or_dir, NULL);
208 }
209 else
210 {
211 /* Set the browsers dirfilter to the global setting
212 * This is required in case the plugin was launched
213 * from the plugins browser, in which case the
214 * dirfilter is set to only display .rock files */
215 rb->set_dirfilter(rb->global_settings->dirfilter);
216
217 /* Change directory to the entry selected by the user */
218 rb->set_current_file(file_or_dir);
219 }
220 return PLUGIN_OK;
221}
185 222
186bool ends_with(char *string, char *suffix) 223bool ends_with(char *string, char *suffix)
187{ 224{
@@ -195,7 +232,7 @@ bool ends_with(char *string, char *suffix)
195 232
196enum plugin_status plugin_start(const void* void_parameter) 233enum plugin_status plugin_start(const void* void_parameter)
197{ 234{
198 bool leave_loop; 235 int ret;
199 236
200 /* This is a viewer, so a parameter must have been specified */ 237 /* This is a viewer, so a parameter must have been specified */
201 if (void_parameter == NULL) { 238 if (void_parameter == NULL) {
@@ -219,8 +256,7 @@ enum plugin_status plugin_start(const void* void_parameter)
219 /* if there's only one entry in the user .link file, 256 /* if there's only one entry in the user .link file,
220 * go straight to it without displaying the menu 257 * go straight to it without displaying the menu
221 * thus allowing 'quick links' */ 258 * thus allowing 'quick links' */
222 goto_entry(sc_file.entries[0].path); 259 return goto_entry(sc_file.entries[0].path);
223 return PLUGIN_OK;
224 } 260 }
225 261
226 FOR_NB_SCREENS(i) 262 FOR_NB_SCREENS(i)
@@ -228,11 +264,13 @@ enum plugin_status plugin_start(const void* void_parameter)
228 264
229 do { 265 do {
230 /* Display a menu to choose between the entries */ 266 /* Display a menu to choose between the entries */
231 leave_loop = list_sc(); 267 ret = list_sc();
232 } while (!leave_loop); 268 } while (ret == PLUGIN_OK);
269 if (ret == LOOP_EXIT)
270 ret = PLUGIN_OK;
233 271
234 FOR_NB_SCREENS(i) 272 FOR_NB_SCREENS(i)
235 rb->viewportmanager_theme_undo(i, false); 273 rb->viewportmanager_theme_undo(i, false);
236 274
237 return usb_connected ? PLUGIN_USB_CONNECTED : PLUGIN_OK; 275 return ret;
238} 276}